mirror of
https://github.com/hypit-ai/hypit.git
synced 2026-11-17 23:34:00 +08:00
Three assertions described the platform they were written on rather than the behaviour they were checking: a CLI profile argument asserted back verbatim though the CLI resolves it, a venv path matched with hardcoded forward slashes though the deployment already branches on the platform to build it, and an external interpreter compared against a literal string. The stand-in interpreter that answers through a shebang is genuinely POSIX-only and now skips on Windows with that as the reason. It would report the interpreter down, which is the state the test exists to tell a mismatch from.
108 lines
3.8 KiB
TypeScript
108 lines
3.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { resolve } from "node:path";
|
|
import test from "node:test";
|
|
|
|
import { runCli } from "../src/main.js";
|
|
import type { CliDistribution } from "../src/distribution.js";
|
|
import type { CliManagedProgramReport, CliRuntimeController } from "../src/runtime-port.js";
|
|
|
|
const io = { write: () => {} };
|
|
|
|
function controller(
|
|
path: string,
|
|
calls: string[],
|
|
reports: readonly CliManagedProgramReport[] = [],
|
|
): CliRuntimeController {
|
|
const worker = { state: "stopped" as const, profile: path, logPath: "/tmp/worker.log" };
|
|
return {
|
|
profile: path,
|
|
dataRoot: "/tmp",
|
|
worker: {
|
|
up: async () => worker,
|
|
status: async () => worker,
|
|
logs: async () => ({ path: worker.logPath, text: "" }),
|
|
down: async () => worker,
|
|
},
|
|
programs: {
|
|
up: async (options) => {
|
|
calls.push(`up ${path} ${JSON.stringify(options)}`);
|
|
return { dataRoot: "/tmp", programs: reports };
|
|
},
|
|
down: async () => { calls.push(`down ${path}`); return { dataRoot: "/tmp", programs: reports }; },
|
|
report: async () => { calls.push(`report ${path}`); return { dataRoot: "/tmp", programs: reports }; },
|
|
},
|
|
};
|
|
}
|
|
|
|
function distribution(calls: string[], reports: readonly CliManagedProgramReport[] = []): CliDistribution {
|
|
return {
|
|
bootstrapPackages: [],
|
|
openRuntimeHost: async (path: string) => ({
|
|
profile: path,
|
|
controller: async () => controller(path, calls, reports),
|
|
}),
|
|
} as unknown as CliDistribution;
|
|
}
|
|
|
|
test("programs dispatches lifecycle through the selected Runtime Controller", async () => {
|
|
const calls: string[] = [];
|
|
await runCli(["programs", "up", "/p/hypit.runtime.json", "--max-wait-ms", "1000"], io, distribution(calls));
|
|
await runCli(["programs", "down", "/p/hypit.runtime.json"], io, distribution(calls));
|
|
await runCli(["programs", "status", "/p/hypit.runtime.json"], io, distribution(calls));
|
|
// The CLI resolves the profile it is given, and what resolving produces is the platform's own
|
|
// spelling. Asserting the argument back verbatim would only be asserting that this is POSIX.
|
|
const profile = resolve("/p/hypit.runtime.json");
|
|
assert.deepEqual(calls, [
|
|
`up ${profile} {"maxWaitMs":1000}`,
|
|
`down ${profile}`,
|
|
`report ${profile}`,
|
|
]);
|
|
});
|
|
|
|
test("programs accepts only up, down and status", async () => {
|
|
await assert.rejects(
|
|
runCli(["programs", "restart", "/p/hypit.runtime.json"], io, distribution([])),
|
|
/programs takes up, down or status/u,
|
|
);
|
|
});
|
|
|
|
test("waiting belongs only to programs up", async () => {
|
|
await assert.rejects(
|
|
runCli(["programs", "status", "/p/hypit.runtime.json", "--max-wait-ms", "1000"], io, distribution([])),
|
|
/--max-wait-ms applies to programs up/u,
|
|
);
|
|
});
|
|
|
|
test("program status may report down without failing the observation", async () => {
|
|
let output = "";
|
|
let exitCode: number | undefined;
|
|
await runCli(["programs", "status", "/project/hypit.runtime.json"], {
|
|
write(text) { output += text; },
|
|
setExitCode(code) { exitCode = code; },
|
|
}, distribution([], [{
|
|
id: "speech-evidence.local",
|
|
instances: ["speech.primary"],
|
|
state: { state: "down", detail: "not running" },
|
|
}]));
|
|
assert.equal(exitCode, undefined);
|
|
assert.match(output, /speech-evidence\.local: down/u);
|
|
});
|
|
|
|
test("runtime up validates the Runtime before it starts Programs", async () => {
|
|
const calls: string[] = [];
|
|
const base = distribution(calls);
|
|
const selected = {
|
|
...base,
|
|
openRuntimeHost: async (path: string) => ({
|
|
profile: path,
|
|
controller: async () => controller(path, calls),
|
|
createRuntime: async () => { throw new Error("Runtime Profile conflict"); },
|
|
}),
|
|
} as unknown as CliDistribution;
|
|
await assert.rejects(
|
|
runCli(["runtime", "up", "/p/hypit.runtime.json"], io, selected),
|
|
/Runtime Profile conflict/u,
|
|
);
|
|
assert.deepEqual(calls, []);
|
|
});
|