fix(cli): resolve status version from package root and surface cache status HTTP errors (#15148) (#15850)

Validated with scripts/release/merge-train.sh --fast (train tip 57a1c7a2, 20 PRs): static gates and the changed node:test files green. Only inherited base-red remains, reproduced on the pure tip: translation drift of docs/reference/ENVIRONMENT.md, 3 autoCombo vitest 5s timeouts (#15106), agent-skills-sync drift (#15306).
This commit is contained in:
Diego Rodrigues de Sa e Souza 2026-10-08 09:11:53 -03:00 • committed by GitHub
parent 3a586b0ad0
commit 36e92b2a31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 78 additions and 6 deletions

View file

@ -40,7 +40,11 @@ export async function runCacheStatusCommand(opts = {}) {
acceptNotOk: true,
});
if (!res.ok) {
console.log("Cache stats not available.");
const hint =
res.status === 401 || res.status === 403
? " (authentication required: run `omniroute auth login` or set OMNIROUTE_API_KEY)"
: "";
console.log(`Cache stats not available (HTTP ${res.status})${hint}.`);
return 0;
}

View file

@ -4,14 +4,24 @@ import { t } from "../i18n.mjs";
import path from "node:path";
import fs from "node:fs";
import os from "node:os";
import { fileURLToPath } from "node:url";
// Resolve package.json from this file's location (global/npx installs run with an
// arbitrary cwd), walking up to the first manifest that carries a version.
function getPackageVersion() {
try {
const pkg = JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf-8"));
return pkg.version || "unknown";
} catch {
return "unknown";
let dir = path.dirname(fileURLToPath(import.meta.url));
for (let i = 0; i < 6; i++) {
try {
const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf-8"));
if (pkg.version) return pkg.version;
} catch {
// keep walking up
}
const parent = path.dirname(dir);
if (parent === dir) break;
dir = parent;
}
return "unknown";
}
function formatBytes(bytes) {

View file

@ -0,0 +1 @@
- fix(cli): `omniroute status` resolves its version from the package location instead of cwd (no more "unknown" on global installs), and `omniroute cache status` reports the real HTTP status instead of "not available" (#15148)

View file

@ -0,0 +1,57 @@
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
// Issue #15148: `omniroute status` read package.json from process.cwd(), so global/npx
// installs (cwd != package root) always printed "Version: unknown".
test("omniroute status resolves the version when cwd is not the package root", async () => {
const cwd = process.cwd();
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-status-cwd-"));
const lines: string[] = [];
const origLog = console.log;
try {
const { runStatusCommand } = await import("../../bin/cli/commands/status.mjs");
process.chdir(tmp);
console.log = (...a: unknown[]) => void lines.push(a.join(" "));
await runStatusCommand({ output: "json" });
} finally {
console.log = origLog;
process.chdir(cwd);
fs.rmSync(tmp, { recursive: true, force: true });
}
const status = JSON.parse(lines.join("\n"));
const pkg = JSON.parse(fs.readFileSync(path.resolve(cwd, "package.json"), "utf8"));
assert.equal(status.version, pkg.version);
});
test("omniroute cache status surfaces the HTTP status instead of 'not available'", async () => {
const http = await import("node:http");
const server = http.createServer((req, res) => {
res.statusCode = req.url?.startsWith("/api/cache/stats") ? 401 : 200;
res.setHeader("content-type", "application/json");
res.end("{}");
});
await new Promise<void>((r) => server.listen(0, "127.0.0.1", () => r()));
const port = (server.address() as { port: number }).port;
const prev = { ...process.env };
process.env.OMNIROUTE_BASE_URL = `http://127.0.0.1:${port}`;
const out: string[] = [];
const origLog = console.log;
const origErr = console.error;
try {
const { runCacheStatusCommand } = await import("../../bin/cli/commands/cache.mjs");
console.log = (...a: unknown[]) => void out.push(a.join(" "));
console.error = (...a: unknown[]) => void out.push(a.join(" "));
await runCacheStatusCommand({});
} finally {
console.log = origLog;
console.error = origErr;
process.env = prev;
server.close();
}
const text = out.join("\n");
assert.match(text, /401/);
});