Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions docs/chaos-testing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ <h2 id="seeded-chaos">Reproducible Chaos (Seeds)</h2>
<h3>Replaying a failed run</h3>
<p>
A seeded chaos hit records its coordinates in its journal entry as
<code>chaosSeed</code>, <code>chaosKey</code> and <code>chaosOccurrence</code>. It also
sends them on the response as <code>x-aimock-chaos-seed</code>,
<code>chaosOrigin</code> (<code>seed</code>, <code>key</code>, <code>occurrence</code>).
It also sends them on the response as <code>x-aimock-chaos-seed</code>,
<code>x-aimock-chaos-key</code> and <code>x-aimock-chaos-occurrence</code>, but only when
the response headers were not sent yet. A <code>disconnect</code> sends no headers: before
the headers it destroys the socket, and in the middle of a stream the headers were already
Expand Down Expand Up @@ -585,20 +585,19 @@ <h2>Journal Tracking</h2>
ordinary one for whatever the request then received.
</p>
<p>
A <a href="#seeded-chaos">seeded</a> chaos hit also adds three fields next to
<code>chaosAction</code>, so you can replay it. An unseeded hit never has them.
A <a href="#seeded-chaos">seeded</a> chaos hit also adds a <code>chaosOrigin</code> object
next to <code>chaosAction</code>, so you can replay it. An unseeded hit never has it. It
has three fields:
</p>
<ul>
<li>
<code>chaosSeed</code> (string): the effective seed (from the header, else the fixture,
else the server).
<code>seed</code> (string): the effective seed (from the header, else the fixture, else
the server).
</li>
<li><code>key</code> (string): the request&apos;s identity key, 16 hex characters.</li>
<li>
<code>chaosKey</code> (string): the request&apos;s identity key, 16 hex characters.
</li>
<li>
<code>chaosOccurrence</code> (number): which occurrence of that key the request was
under that seed and testId, starting at 0.
<code>occurrence</code> (number): which occurrence of that key the request was under
that seed and testId, starting at 0.
</li>
</ul>

Expand Down
8 changes: 5 additions & 3 deletions etc/aimock-a2a.import.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-a2a.require.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-agui.import.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-agui.require.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-index.import.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-index.require.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-jest.import.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-jest.require.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-mcp.import.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-mcp.require.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-vector.import.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-vector.require.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-vitest.import.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions etc/aimock-vitest.require.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/__tests__/chaos-seed-core-fixes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe("finding 1: a reported seed replays byte-for-byte through the seed head
expect(reply.headers[SEED_HEADER]).toBe("run");
expect(instance.journal.getAll().at(-1)?.response).toMatchObject({
chaosAction: "drop",
chaosSeed: "run",
chaosOrigin: { seed: "run" },
});
// It is the very verdict a plain `run` header gives.
const plain = await chat(await start({ chaos: { dropRate: 1 } }), { [SEED_HEADER]: "run" });
Expand Down Expand Up @@ -233,9 +233,8 @@ describe("finding 2: an unseeded verdict never inherits a seeded origin", () =>
expect(reply.headers[OCCURRENCE_HEADER]).toBeUndefined();
const entry = journal.getAll()[0];
expect(entry?.response.chaosAction).toBe("drop");
expect(entry?.response).not.toHaveProperty("chaosOrigin");
expect(entry?.response).not.toHaveProperty("chaosSeed");
expect(entry?.response).not.toHaveProperty("chaosKey");
expect(entry?.response).not.toHaveProperty("chaosOccurrence");
expect(randomCalls).toBe(1);
expect(jitterAfter).toBeUndefined();
expect(originAfter).toBeUndefined();
Expand Down Expand Up @@ -266,7 +265,7 @@ describe("finding 2: an unseeded verdict never inherits a seeded origin", () =>
expect(action).toBe("drop");
expect(reply.status).toBe(500);
expect(reply.headers[SEED_HEADER]).toBeUndefined();
expect(journal.getAll()[0]?.response).not.toHaveProperty("chaosSeed");
expect(journal.getAll()[0]?.response).not.toHaveProperty("chaosOrigin");
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/chaos-seed-key-fixes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe("the key does not depend on X-AIMock-Context", () => {
"x-aimock-context": "ctx-a",
});
const entry = instance.journal.getLast();
expect(entry?.response.chaosKey).toBe(
expect(entry?.response.chaosOrigin?.key).toBe(
chaosKeyFor({ method: "POST", path: "/v1/messages", body: JSON.parse(MESSAGES_BODY) }),
);
});
Expand Down
28 changes: 23 additions & 5 deletions src/__tests__/chaos-seed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,30 @@ describe("seeded chaos: reporting on a chaos hit", () => {
expect(probe.headers[KEY_HEADER]).toMatch(/^[0-9a-f]{16}$/);
expect(probe.headers[OCCURRENCE_HEADER]).toBe("0");
const entry = instance.journal.getAll().at(-1);
expect(entry?.response).toMatchObject({
chaosAction: "drop",
chaosSeed: "report",
chaosKey: probe.headers[KEY_HEADER],
chaosOccurrence: 0,
expect(entry?.response.chaosAction).toBe("drop");
expect(entry?.response.chaosOrigin).toEqual({
seed: "report",
key: probe.headers[KEY_HEADER],
occurrence: 0,
});
expect(entry?.response).not.toHaveProperty("chaosSeed");
expect(entry?.response).not.toHaveProperty("chaosKey");
expect(entry?.response).not.toHaveProperty("chaosOccurrence");
});

it("an unseeded chaos hit journals no chaosOrigin", async () => {
const instance = await createServer(structuredClone(FIXTURES), {
port: 0,
chaos: { dropRate: 1 },
});
servers.push(instance);
const probe = await chat(instance.url, "alpha");
expect(probe.outcome).toBe("drop");
expect(probe.headers[SEED_HEADER]).toBeUndefined();
const entry = instance.journal.getAll().at(-1);
expect(entry?.response.chaosAction).toBe("drop");
expect(entry?.response).not.toHaveProperty("chaosOrigin");
expect(entry?.response).not.toHaveProperty("chaosSeed");
});

it("keys the request by its body, not by headers", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/chaos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ export function applyChaosAction(
// a committed head cannot take new headers) and in the journal entry. An
// unseeded verdict has no origin, so its response and entry are unchanged.
const originFields = origin
? { chaosSeed: origin.seed, chaosKey: origin.key, chaosOccurrence: origin.occurrence }
? { chaosOrigin: { seed: origin.seed, key: origin.key, occurrence: origin.occurrence } }
: {};
if (origin && !res.headersSent) {
res.setHeader(CHAOS_SEED_HEADER, origin.seed);
Expand Down
6 changes: 2 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1415,11 +1415,9 @@ export interface JournalEntry {
* Where a SEEDED `chaosAction` came from, so a failure seen in the journal can be
* replayed: the effective seed, the request identity key and the occurrence of
* that key. Present only when the request resolved a chaos seed; an unseeded
* chaos entry never carries them.
* chaos entry never carries it.
*/
chaosSeed?: string;
chaosKey?: string;
chaosOccurrence?: number;
chaosOrigin?: { seed: string; key: string; occurrence: number };
/** Full prepared fault output; interrupted delivery is recorded separately above. */
misbehavior?: MisbehaviorSummary;
/** When the X-AIMock-Strict header overrode the server default. */
Expand Down
Loading