Files
OmniRoute/tests/unit/cli/ready-timeout.test.ts
Koosha Paridehpour fc111dc196 feat(cli): make startup readiness budget configurable (#13369) (#13433)
The CLI readiness budget is configurable through `OMNIROUTE_READY_TIMEOUT_MS` or `omniroute serve --ready-timeout <ms>` (default unchanged at 60s). The timeout warning prints the budget it actually used and suggests a larger value, for slow cold starts such as Windows (#13369). Documented in `ENVIRONMENT.md` and `TROUBLESHOOTING.md`, with 11 resolver cases.

Validated in one consolidated batch of this series (37 PRs boarded together on `release/v3.8.51`): `typecheck:core`, `check:open-sse-typecheck` and `check:dashboard-typecheck` clean; ESLint clean on every changed file; file-size, complexity, cognitive-complexity, changelog-integrity, docs-counts, docs-sync and migration-numbering gates green (only the pre-existing `open-sse/utils/stream.ts` file-size red remains, inherited from the base); 3,743 focused `node:test` cases plus 34 vitest cases green.

Thanks @KooshaPari!
2026-09-14 23:24:46 -03:00

72 lines
2.4 KiB
TypeScript

import { test, describe, beforeEach } from "node:test";
import assert from "node:assert/strict";
import { resolveReadyTimeoutMs } from "../../../bin/cli/utils/pid.mjs";
describe("resolveReadyTimeoutMs", () => {
const savedEnv = process.env.OMNIROUTE_READY_TIMEOUT_MS;
beforeEach(() => {
// Reset env between tests
if (savedEnv === undefined) {
delete process.env.OMNIROUTE_READY_TIMEOUT_MS;
} else {
process.env.OMNIROUTE_READY_TIMEOUT_MS = savedEnv;
}
});
test("returns 60000 by default (no env, no override)", () => {
delete process.env.OMNIROUTE_READY_TIMEOUT_MS;
assert.equal(resolveReadyTimeoutMs(), 60_000);
});
test("honours explicit override when provided", () => {
delete process.env.OMNIROUTE_READY_TIMEOUT_MS;
assert.equal(resolveReadyTimeoutMs({ timeoutMs: 120_000 }), 120_000);
});
test("explicit override wins over env var", () => {
process.env.OMNIROUTE_READY_TIMEOUT_MS = "300000";
assert.equal(resolveReadyTimeoutMs({ timeoutMs: 90_000 }), 90_000);
});
test("reads OMNIROUTE_READY_TIMEOUT_MS env var", () => {
process.env.OMNIROUTE_READY_TIMEOUT_MS = "180000";
assert.equal(resolveReadyTimeoutMs(), 180_000);
});
test("falls back to default when env var is non-numeric", () => {
process.env.OMNIROUTE_READY_TIMEOUT_MS = "not-a-number";
assert.equal(resolveReadyTimeoutMs(), 60_000);
});
test("falls back to default when env var is zero", () => {
process.env.OMNIROUTE_READY_TIMEOUT_MS = "0";
assert.equal(resolveReadyTimeoutMs(), 60_000);
});
test("falls back to default when env var is negative", () => {
process.env.OMNIROUTE_READY_TIMEOUT_MS = "-5000";
assert.equal(resolveReadyTimeoutMs(), 60_000);
});
test("falls back to default when override is zero", () => {
delete process.env.OMNIROUTE_READY_TIMEOUT_MS;
assert.equal(resolveReadyTimeoutMs({ timeoutMs: 0 }), 60_000);
});
test("falls back to default when override is negative", () => {
delete process.env.OMNIROUTE_READY_TIMEOUT_MS;
assert.equal(resolveReadyTimeoutMs({ timeoutMs: -1 }), 60_000);
});
test("accepts fractional seconds as milliseconds", () => {
process.env.OMNIROUTE_READY_TIMEOUT_MS = "65536";
assert.equal(resolveReadyTimeoutMs(), 65_536);
});
test("handles empty string env var as unset", () => {
process.env.OMNIROUTE_READY_TIMEOUT_MS = "";
assert.equal(resolveReadyTimeoutMs(), 60_000);
});
});