Files
OmniRoute/tests/unit/chipotle-executor.test.ts
Paijo 7cfabfc5c9 perf(executors): lazy-load the executor registry — defer class imports + construction to first use (#11220) (#11421)
Validated in a combined 3-PR batch worktree off release/v3.8.51 tip (a sibling PR from the same author, #11495, was held out — a typecheck error in zai-web.ts only reproduced with this PR + #11495 boarded together, and cleared without #11495; isolated this PR alone confirmed clean on its own too, so the interaction belonged to #11495's side — see its comment).
- Golden lock: executor-map-golden.test.ts — passes byte-identical (same keys, classes, provider identities, dispatch guards)
- Focused tests part of batch's 94/94 node:test run
- typecheck:core, file-size, changelog-integrity, complexity, cognitive-complexity — all OK
- Full-repo lint: 228 pre-existing dashboard react-hooks/* findings, unrelated to this diff

Thanks for the measured, careful methodology here — the golden-lock contract plus the isolated DATA_DIR benchmarking make this an easy PR to trust despite the wide surface (72 files).
2026-08-25 18:22:46 -03:00

78 lines
2.7 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert";
import {
ChipotleExecutor,
randomServerId,
randomSessionId,
} from "../../open-sse/executors/chipotle.ts";
const executor = new ChipotleExecutor();
describe("ChipotleExecutor", () => {
it("buildHeaders returns static headers", () => {
const headers = (executor as any).buildHeaders({});
assert.strictEqual(headers["Content-Type"], "application/json");
});
it("buildUrl returns Amelia endpoint", () => {
const url = executor.buildUrl("pepper-1", false);
const parsed = new URL(url);
assert.strictEqual(parsed.hostname, "amelia.chipotle.com");
});
// Regression guard for the node:crypto import — randomInt is NOT on the Web
// Crypto global, so a bare `crypto.randomInt` would throw at WS-connect time.
it("randomServerId yields a 3-digit numeric string (crypto.randomInt available)", () => {
for (let i = 0; i < 50; i++) {
const id = randomServerId();
assert.match(id, /^\d{3}$/, `expected 3 digits, got "${id}"`);
assert.ok(Number(id) >= 0 && Number(id) <= 999);
}
});
it("randomSessionId yields 32 hex chars (crypto.randomUUID available)", () => {
const id = randomSessionId();
assert.match(id, /^[0-9a-f]{32}$/, `expected 32 hex chars, got "${id}"`);
assert.notStrictEqual(randomSessionId(), randomSessionId());
});
it("transformRequest passes model through", () => {
const result = (executor as any).transformRequest(
"pepper-1",
{ model: "pepper-1", messages: [{ role: "user", content: "hi" }] },
false,
);
assert.strictEqual(result.model, "pepper-1");
});
it("returns 499 on pre-aborted signal", async () => {
const controller = new AbortController();
controller.abort(new Error("cancelled"));
const result = await executor.execute({
model: "pepper-1",
body: { messages: [{ role: "user", content: "hi" }], stream: false },
stream: false,
signal: controller.signal,
credentials: {},
log: { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} },
});
assert.strictEqual((result as any).response.status, 499);
});
it("is registered in executor index", async () => {
const { getExecutor } = await import("../../open-sse/executors/index.ts");
const exec = await getExecutor("chipotle");
assert.ok(exec, "chipotle executor should be registered");
assert.ok(exec instanceof ChipotleExecutor);
});
it("pepper alias works", async () => {
const { getExecutor } = await import("../../open-sse/executors/index.ts");
const exec = await getExecutor("pepper");
assert.ok(exec, "pepper alias should be registered");
assert.ok(exec instanceof ChipotleExecutor);
});
});