Files
OmniRoute/tests/unit/mitm-handler-kiro.test.ts
diegosouzapw 1196d08aad test(mitm): handlers + targets + detection unit tests (F3)
- mitm-handler-base: hookBufferStart returns InterceptedRequest with
  sanitized headers, extractSourceModel parses body.model, writeError
  emits JSON with sanitized message (Hard Rule #12).
- mitm-handler-<id>: nine per-agent happy-path tests (antigravity,
  kiro, copilot, codex, cursor, zed, claude-code, open-code) exercise
  full intercept() with mocked fetch via _mitmHandlerHarness.ts;
  asserts mapped model is forwarded and AgentBridge correlation
  headers are present. Trae test confirms intercept() rejects with a
  structured error.
- mitm-targets-resolve: ALL_TARGETS contains 9 entries; resolveTarget
  is case-insensitive and returns null for unknown hosts.
- mitm-targets-route: bypass > target > passthrough precedence
  validated against representative hostnames.
- mitm-detection: DETECTORS covers every AgentId; detectAgent never
  throws and returns DetectionResult-shaped objects for all probes.
2026-05-27 22:33:56 -03:00

21 lines
822 B
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { KiroHandler } from "../../src/mitm/handlers/kiro.ts";
import { runHandler } from "./_mitmHandlerHarness.ts";
test("kiro handler — forwards Anthropic-style body to OmniRoute /v1/messages", async () => {
const r = await runHandler(
new KiroHandler(),
{ model: "claude-3.5-sonnet", messages: [{ role: "user", content: "hi" }] },
"claude-sonnet-4.5",
{ upstreamBody: "event: message_start\n\n" }
);
assert.ok(r.fetchCalled);
assert.equal(r.status, 200);
// Router URL must point at /v1/messages for the Anthropic path.
assert.ok(r.fetchUrl?.endsWith("/v1/messages"));
// Body must have been rewritten with mapped model.
const sent = JSON.parse(r.fetchBody);
assert.equal(sent.model, "claude-sonnet-4.5");
});