feat: add OMP runtime support

This commit is contained in:
Jeff Scott Ward
2026-06-26 12:49:58 -04:00
parent 4605a4f1d8
commit 84a485d62e
26 changed files with 639 additions and 83 deletions
+37 -4
View File
@@ -2,9 +2,11 @@ import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { commandWithVersionCheck, isCliEntrypoint } from "./cli.js";
import { agentCommandForChecks, commandWithVersionCheck, isCliEntrypoint } from "./cli.js";
const originalShell = process.env["SHELL"];
const originalPiWebConfig = process.env["PI_WEB_CONFIG"];
const originalPiWebAgentCommand = process.env["PI_WEB_AGENT_COMMAND"];
afterEach(() => {
if (originalShell === undefined) {
@@ -12,25 +14,56 @@ afterEach(() => {
} else {
process.env["SHELL"] = originalShell;
}
if (originalPiWebConfig === undefined) {
delete process.env["PI_WEB_CONFIG"];
} else {
process.env["PI_WEB_CONFIG"] = originalPiWebConfig;
}
if (originalPiWebAgentCommand === undefined) {
delete process.env["PI_WEB_AGENT_COMMAND"];
} else {
process.env["PI_WEB_AGENT_COMMAND"] = originalPiWebAgentCommand;
}
});
describe("commandWithVersionCheck", () => {
it("emits a POSIX subshell group for bash", () => {
process.env["SHELL"] = "/bin/bash";
expect(commandWithVersionCheck("npm")).toBe("command -v npm && (npm --version 2>&1 || true)");
expect(commandWithVersionCheck("npm")).toBe("command -v 'npm' && ('npm' --version 2>&1 || true)");
});
it("emits a POSIX subshell group for zsh", () => {
process.env["SHELL"] = "/bin/zsh";
expect(commandWithVersionCheck("pi")).toBe("command -v pi && (pi --version 2>&1 || true)");
expect(commandWithVersionCheck("pi")).toBe("command -v 'pi' && ('pi' --version 2>&1 || true)");
});
it("uses fish begin/end grouping instead of a POSIX subshell", () => {
process.env["SHELL"] = "/usr/local/bin/fish";
const command = commandWithVersionCheck("npm");
expect(command).toBe("command -v npm && begin; npm --version 2>&1 || true; end");
expect(command).toBe("command -v 'npm' && begin; 'npm' --version 2>&1 || true; end");
expect(command).not.toContain("(");
});
it("shell-quotes command words", () => {
process.env["SHELL"] = "/bin/bash";
expect(commandWithVersionCheck("/tmp/agent's/omp")).toBe("command -v '/tmp/agent'\\''s/omp' && ('/tmp/agent'\\''s/omp' --version 2>&1 || true)");
});
});
describe("agentCommandForChecks", () => {
it("reads the configured agent command for doctor checks", () => {
const dir = mkdtempSync(join(tmpdir(), "pi-web-cli-test-"));
try {
const configPath = join(dir, "config.json");
writeFileSync(configPath, `${JSON.stringify({ agent: { command: "omp" } })}\n`);
process.env["PI_WEB_CONFIG"] = configPath;
delete process.env["PI_WEB_AGENT_COMMAND"];
expect(agentCommandForChecks()).toBe("omp");
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
});
describe("isCliEntrypoint", () => {