mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +03:00
* fix(doctor): resolve two false-positive WARNs (#6162) The `omniroute doctor` command reported two warnings on healthy installs even though the underlying checks actually passed. Both came from the doctor probing state that already worked; they looked like bugs but users couldn't tell without manual digging. Issue 1 — Server liveness HTTP 401 /api/health and /api/health/degradation both require the management token. Doctor called them without auth → 401 → WARN, even when the Next.js server was clearly alive and listening. Fix: probe the configured health endpoint first; on 401/403, fall back to a publicly served static asset (/favicon.ico) to confirm the server is alive. WARN now only fires when both probes fail. Issue 2 — CLI Tools '@/shared' import tool-detector.ts (and 3 other cli-helper files) import @/shared/... aliases that resolve via tsconfig.json paths. The CLI ships raw TS source (no compile step) and runs through tsx, but tsx does not honor tsconfig paths at runtime, and tsconfig-paths only hooks CJS Module._resolveFilename while doctor uses ESM `import()`. Fix: replace @/shared/... with relative imports in the 4 cli-helper files. This is the same pattern these files already use for ./config- generator/* imports. No new dependency, no architectural change, and the fix doesn't regress Next.js itself which keeps using @/shared. Verified on v3.8.43 (Node v24.17, Windows 11): Before: 7 ok, 2 warning(s), 0 failure(s) After: 8 ok, N warning(s), 0 failure(s) where N accurately reflects which CLI tools are installed and configured for OmniRoute (e.g. Hermes Agent installed but not pointed at 20128 → 2 real warnings, not 1 false-positive). Refs #6162 * fix(doctor): derive fallback URL from primary URL via new URL() Per Gemini code-assist review feedback: the previous fallback constructed the /favicon.ico URL from defaults (127.0.0.1:PORT) which ignored custom host/port/protocol configurations supplied via: - OMNIROUTE_DOCTOR_LIVENESS_URL - OMNIROUTE_DOCTOR_HOST - --liveness-url / --host CLI flags Parse the primary URL with new URL() to preserve protocol, host, port, and subpaths. The previous default-based fallback remains as a catch-all for invalid primary URLs. * test(doctor): add regression tests for #6162 fixes Two new test files lock the fix and satisfy the PR Test Policy gate ("production code change without tests"): - tests/unit/cli-helper-tool-detector-paths-6162.test.ts Locks the @/shared → relative imports fix across all 4 cli-helper files. Asserts (a) no @/shared alias remains in the cli-helper sources, and (b) each file is importable at runtime via tsx/ESM, which would have thrown "Cannot find package '@/shared'" before the fix. - tests/unit/cli-doctor-liveness-fallback-6162.test.ts Locks the /favicon.ico fallback in doctor.mjs. Asserts the fallback probe exists, derives its URL from the primary URL via new URL() (per Gemini review feedback), and that the buggy 'Server responded with HTTP 401' WARN path is gone. Both tests use only node:test + node:assert/strict so they slot into the existing 'test' and 'test:unit' scripts with no extra config. * test(doctor): fix primary.ok regex in fallback test The earlier regex /primary\.ok\s*\?/ required a '?' immediately after, but the actual doctor.mjs code uses a multi-line if-block: if (primary.ok) { return ok(...); } Use /\bprimary\.ok\b/ instead so the assertion matches the existing branching. --------- Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
66 lines
2.8 KiB
TypeScript
66 lines
2.8 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync, existsSync } from "node:fs";
|
|
import { join, dirname } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
// Regression test for #6162 (liveness portion): `omniroute doctor` reported
|
|
// "Server liveness: Server responded with HTTP 401" on healthy installs
|
|
// because /api/health and /api/health/degradation both require the management
|
|
// token. The doctor called them without auth → 401 → WARN, even when the
|
|
// Next.js server was clearly alive and listening.
|
|
//
|
|
// Fix: probe the configured health endpoint first; on 401/403, fall back to
|
|
// a publicly served static asset (/favicon.ico) to confirm the server is
|
|
// alive. WARN now only fires when both probes fail.
|
|
//
|
|
// This regression test asserts:
|
|
// 1. The current doctor.mjs source contains the fallback logic.
|
|
// 2. The fallback derives its URL from the primary URL via `new URL()`
|
|
// so custom host/port/protocol are preserved (Gemini code-assist review).
|
|
|
|
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
const DOCTOR_SRC = join(ROOT, "bin/cli/commands/doctor.mjs");
|
|
|
|
test("doctor.mjs must exist", () => {
|
|
assert.ok(existsSync(DOCTOR_SRC), "bin/cli/commands/doctor.mjs should exist");
|
|
});
|
|
|
|
test("doctor.mjs implements a /favicon.ico fallback for unauthenticated liveness (#6162)", () => {
|
|
const content = readFileSync(DOCTOR_SRC, "utf8");
|
|
|
|
assert.ok(
|
|
content.includes("/favicon.ico"),
|
|
"doctor.mjs must include /favicon.ico as a fallback probe (fix for #6162)"
|
|
);
|
|
|
|
// The probe order matters: try the configured health endpoint first, then
|
|
// fall back. Locking the order prevents future refactors from regressing
|
|
// back to "always report WARN on 401".
|
|
assert.ok(
|
|
/\bprimary\.ok\b/.test(content),
|
|
"doctor.mjs must branch on `primary.ok` to decide whether to fall back to /favicon.ico"
|
|
);
|
|
});
|
|
|
|
test("doctor.mjs derives fallback URL from primary URL via new URL() (Gemini review)", () => {
|
|
const content = readFileSync(DOCTOR_SRC, "utf8");
|
|
|
|
assert.ok(
|
|
content.includes("new URL("),
|
|
"doctor.mjs must derive the fallback URL from the primary URL via `new URL()` to preserve protocol/host/port (Gemini review feedback on PR #6163)"
|
|
);
|
|
});
|
|
|
|
test("doctor.mjs no longer reports WARN on HTTP 401/403 alone", () => {
|
|
const content = readFileSync(DOCTOR_SRC, "utf8");
|
|
|
|
// Old (buggy) line was:
|
|
// return warn("Server liveness", `Server responded with HTTP ${response.status}`, { url });
|
|
// This asserted immediately on !response.ok without considering auth.
|
|
// The fix should NOT contain that exact phrase anymore.
|
|
assert.ok(
|
|
!content.includes("`Server responded with HTTP ${response.status}`"),
|
|
"doctor.mjs must not contain the buggy 'Server responded with HTTP ${response.status}' warn message (would be hit on auth-required 401)"
|
|
);
|
|
}); |