Skip to content

Commit 4e9ae35

Browse files
committed
test: verify strict header prevents proxy
New test: strict header returns 503 even in record mode. Updated recorder test for new strict-before-proxy semantics. CHANGELOG updated with strict-before-proxy fix.
1 parent 09cfa0e commit 4e9ae35

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixed
66

7+
- **Strict mode checked before proxy attempt** — in `--proxy-only` mode, the `X-AIMock-Strict` header had no effect because `proxyAndRecord()` returned before the strict check. Now all 17 handlers check strict mode first: when strict + no fixture → 503 immediately, no proxy attempt
78
- **Helper utilities and error serialization** — hardened helper functions and error serialization paths for correctness and robustness
89
- **Journal and fixture-loader correctness** — fixed journal entry handling and fixture-loader edge cases
910
- **WebSocket handler consistency and strict-mode journal** — aligned WebSocket handler behavior and ensured strict-mode journal entries are recorded correctly

src/__tests__/recorder.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ describe("recorder strict mode", () => {
692692
expect(body.error.message).toBe("Strict mode: no fixture matched");
693693
});
694694

695-
it("record + strict: proxy succeeds when upstream is available", async () => {
695+
it("record + strict: strict blocks proxy even when upstream is available", async () => {
696696
await setupUpstreamAndRecorder([
697697
{
698698
match: { userMessage: "hello" },
@@ -714,14 +714,15 @@ describe("recorder strict mode", () => {
714714
record: { providers: { openai: upstream!.url }, fixturePath: tmpDir },
715715
});
716716

717+
// Strict mode now takes precedence over proxy — returns 503
717718
const resp = await post(`${recorder.url}/v1/chat/completions`, {
718719
model: "gpt-4",
719720
messages: [{ role: "user", content: "hello" }],
720721
});
721722

722-
expect(resp.status).toBe(200);
723+
expect(resp.status).toBe(503);
723724
const body = JSON.parse(resp.body);
724-
expect(body.choices[0].message.content).toBe("world");
725+
expect(body.error.message).toBe("Strict mode: no fixture matched");
725726
});
726727
});
727728

src/__tests__/strict-header.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,19 @@ describe("X-AIMock-Strict header integration", () => {
219219
expect(entries.length).toBe(1);
220220
expect(entries[0].response.strictOverride).toBe(false);
221221
});
222+
223+
it("strict header prevents proxy in record mode", async () => {
224+
server = await createServer([], {
225+
port: 0,
226+
record: {
227+
providers: { openai: "https://api.openai.com" },
228+
},
229+
});
230+
const res = await httpPost(`${server.url}/v1/chat/completions`, chatRequest("anything"), {
231+
"X-AIMock-Strict": "true",
232+
});
233+
expect(res.status).toBe(503);
234+
const body = JSON.parse(res.body);
235+
expect(body.error.message).toBe("Strict mode: no fixture matched");
236+
});
222237
});

0 commit comments

Comments
 (0)