test(platform): traffic 상한·JSON 구조 예산의 경계와 취소된 owner signal을 시험한다 #85
@@ -69,6 +69,19 @@ describe("createExecutionContext", () => {
|
||||
expect(direct.cancellation.signal.aborted).toBe(true);
|
||||
});
|
||||
|
||||
it("starts cancelled when the owner signal is already aborted", () => {
|
||||
const owner = new AbortController();
|
||||
owner.abort();
|
||||
const context = createExecutionContext({
|
||||
interactionId: "interaction-8",
|
||||
deadlineMs: 1_000,
|
||||
traffic: TRAFFIC,
|
||||
signal: owner.signal,
|
||||
});
|
||||
|
||||
expect(context.cancellation.signal.aborted).toBe(true);
|
||||
});
|
||||
|
||||
it("detaches from a long-lived owner signal when the interaction completes (Q-6.9-7)", () => {
|
||||
const owner = new AbortController();
|
||||
const remove = vi.spyOn(owner.signal, "removeEventListener");
|
||||
|
||||
@@ -50,10 +50,24 @@ describe("createTrafficRuntime", () => {
|
||||
["maxConcurrentRequests", 0],
|
||||
["maxQueuedRequests", Number.NaN],
|
||||
["maxPhysicalRequests", 65],
|
||||
["maxRetries", 17],
|
||||
["maxConcurrentRequests", 17],
|
||||
["maxQueuedRequests", 257],
|
||||
] as const)("rejects %s=%s", (key, value) => {
|
||||
expect(() => defineTrafficBudget({ ...POLICY, [key]: value })).toThrow(
|
||||
new RegExp(key),
|
||||
);
|
||||
});
|
||||
|
||||
it("accepts every hard ceiling itself", () => {
|
||||
// Literal values on purpose: a test that imports the ceilings would follow
|
||||
// a raised constant instead of catching it.
|
||||
const atCeiling = {
|
||||
maxPhysicalRequests: 64,
|
||||
maxRetries: 16,
|
||||
maxConcurrentRequests: 16,
|
||||
maxQueuedRequests: 256,
|
||||
};
|
||||
expect(defineTrafficBudget(atCeiling)).toEqual(atCeiling);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,6 +101,78 @@ describe("validateJsonStructure", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkJsonStructure at and one above each ceiling", () => {
|
||||
it("counts total nodes up to maxItems", () => {
|
||||
// Short arrays keep the length guard out of the way: only the node count can fire.
|
||||
const budget = { ...BUDGET, maxItems: 5 };
|
||||
expect(checkJsonStructure([[1], [2]], budget)).toEqual({ ok: true, nodes: 5 });
|
||||
expect(checkJsonStructure([[1], [2, 3]], budget)).toMatchObject({
|
||||
ok: false,
|
||||
violation: "too-many-items",
|
||||
detail: expect.stringMatching(/nodes/),
|
||||
});
|
||||
});
|
||||
|
||||
it("allows nesting up to maxDepth", () => {
|
||||
const budget = { ...BUDGET, maxDepth: 3 };
|
||||
expect(checkJsonStructure([[[1]]], budget)).toMatchObject({ ok: true });
|
||||
expect(checkJsonStructure([[[[1]]]], budget)).toMatchObject({
|
||||
ok: false,
|
||||
violation: "too-deep",
|
||||
});
|
||||
});
|
||||
|
||||
it("allows string values up to maxStringLength", () => {
|
||||
const budget = { ...BUDGET, maxStringLength: 4 };
|
||||
expect(checkJsonStructure(["abcd"], budget)).toMatchObject({ ok: true });
|
||||
expect(checkJsonStructure(["abcde"], budget)).toMatchObject({
|
||||
ok: false,
|
||||
violation: "string-too-long",
|
||||
});
|
||||
});
|
||||
|
||||
it("allows object keys up to maxStringLength", () => {
|
||||
const budget = { ...BUDGET, maxStringLength: 4 };
|
||||
expect(checkJsonStructure({ abcd: 1 }, budget)).toMatchObject({ ok: true });
|
||||
expect(checkJsonStructure({ abcde: 1 }, budget)).toEqual({
|
||||
ok: false,
|
||||
violation: "string-too-long",
|
||||
detail: "object key too long",
|
||||
});
|
||||
});
|
||||
|
||||
// A container is itself a node, so one with exactly maxItems children always
|
||||
// trips the node count. The width guards must fire only above the ceiling,
|
||||
// before the children are walked; `detail` tells the two apart.
|
||||
it("leaves an array of exactly maxItems to the node count", () => {
|
||||
const budget = { ...BUDGET, maxItems: 3 };
|
||||
expect(checkJsonStructure([1, 2, 3], budget)).toMatchObject({
|
||||
ok: false,
|
||||
violation: "too-many-items",
|
||||
detail: expect.stringMatching(/nodes/),
|
||||
});
|
||||
expect(checkJsonStructure([1, 2, 3, 4], budget)).toMatchObject({
|
||||
ok: false,
|
||||
violation: "too-many-items",
|
||||
detail: expect.stringMatching(/array/),
|
||||
});
|
||||
});
|
||||
|
||||
it("leaves an object of exactly maxItems keys to the node count", () => {
|
||||
const budget = { ...BUDGET, maxItems: 3 };
|
||||
expect(checkJsonStructure({ a: 1, b: 2, c: 3 }, budget)).toMatchObject({
|
||||
ok: false,
|
||||
violation: "too-many-items",
|
||||
detail: expect.stringMatching(/nodes/),
|
||||
});
|
||||
expect(checkJsonStructure({ a: 1, b: 2, c: 3, d: 4 }, budget)).toMatchObject({
|
||||
ok: false,
|
||||
violation: "too-many-items",
|
||||
detail: expect.stringMatching(/object/),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("response structure budget in the V3 executor", () => {
|
||||
const TEST_QUERY = TEST_LIST_HTTP_CONTRACT as InstalledHttpContract<
|
||||
unknown,
|
||||
|
||||
Reference in New Issue
Block a user