Files
OmniRoute/tests/unit/mitm-targets-route.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

38 lines
1.5 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { routeConnection } from "../../src/mitm/targets/index.ts";
test("routeConnection — default bypass (bank) wins over target match", () => {
const r = routeConnection("my.bank.example", []);
assert.equal(r.kind, "bypass");
});
test("routeConnection — user bypass glob beats target", () => {
const r = routeConnection("api.githubcopilot.com", ["*githubcopilot*"]);
assert.equal(r.kind, "bypass");
});
test("routeConnection — known target returns target route", () => {
const r = routeConnection("api.githubcopilot.com", []);
assert.equal(r.kind, "target");
if (r.kind === "target") assert.equal(r.target.id, "copilot");
});
test("routeConnection — unknown host returns passthrough", () => {
const r = routeConnection("example.com", []);
assert.equal(r.kind, "passthrough");
});
test("routeConnection — empty hostname returns passthrough", () => {
const r = routeConnection("", []);
assert.equal(r.kind, "passthrough");
});
test("routeConnection — precedence: bypass > target > passthrough", () => {
// Default bypass (bank) takes precedence even if we add the host to the
// copilot target hypothetically — here we just exercise the three branches.
assert.equal(routeConnection("acme.bank.com", []).kind, "bypass");
assert.equal(routeConnection("api.zed.dev", []).kind, "target");
assert.equal(routeConnection("unrelated.example", []).kind, "passthrough");
});