1a88ab3199
The v0.8 milestone: installable on any Debian-based server via docker (Gitea registry image, honest sandbox degrade), deb (amd64+arm64, advisory postinst), and arch-aware binary — with release consistency enforced by pre-commit hooks + Gitea Actions (3-runner fleet on CT 113, machine-made releases with the full 8-asset matrix + registry image), the CLI carrying the full suite (guide, channel-aware doctor), and the admin runbook (deploy/README.md, evidence-backed recipes). ---ci--- phase: 6 milestone: v0.8 status: complete requirements: covered: [REQ-8-001, REQ-8-002, REQ-8-003, REQ-8-004, REQ-8-005] partial: [] ---/ci---
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { run } from "../src/index.ts";
|
|
import { testCtx } from "./helpers.ts";
|
|
|
|
|
|
|
|
test("dispatch: --help exits 0 and prints usage", async () => {
|
|
const ctx = testCtx();
|
|
const code = await run(["--help"], ctx);
|
|
assert.equal(code, 0);
|
|
assert.ok(ctx.out().includes("Usage:"));
|
|
assert.ok(ctx.out().includes("doctor"));
|
|
});
|
|
|
|
test("dispatch: -h behaves like --help", async () => {
|
|
const ctx = testCtx();
|
|
assert.equal(await run(["-h"], ctx), 0);
|
|
});
|
|
|
|
test("dispatch: --version prints NEXTCRAFT_VERSION override", async () => {
|
|
const env = { ...process.env, NEXTCRAFT_VERSION: "v9.9.9-test" };
|
|
const ctx = testCtx({ env });
|
|
const code = await run(["--version"], ctx);
|
|
assert.equal(code, 0);
|
|
assert.ok(ctx.out().includes("v9.9.9-test"));
|
|
});
|
|
|
|
test("dispatch: no command exits 2 with usage on stderr", async () => {
|
|
const ctx = testCtx();
|
|
assert.equal(await run([], ctx), 2);
|
|
assert.ok(ctx.err().includes("Usage:") || ctx.out().includes("Usage:") || ctx.err().includes("nextcraft"));
|
|
});
|
|
|
|
test("dispatch: unknown command exits 2", async () => {
|
|
const ctx = testCtx();
|
|
const code = await run(["frobnicate"], ctx);
|
|
assert.equal(code, 2);
|
|
assert.ok(ctx.err().includes("unknown command: frobnicate"));
|
|
});
|
|
|
|
test("dispatch: unknown flag exits 2", async () => {
|
|
const ctx = testCtx();
|
|
assert.equal(await run(["doctor", "--bogus"], ctx), 2);
|
|
});
|
|
|
|
test("dispatch: doctor routes to the doctor command", async () => {
|
|
const ctx = testCtx({
|
|
env: { ...process.env, PATH: "/usr/fake-bin" } as Record<string, string | undefined>,
|
|
exists: (p: string) => p === "/usr/fake-bin/pnpm",
|
|
spawn: async (cmd, args) => {
|
|
if (cmd === "which") return { code: 0, signal: null, timedOut: false, stdout: "", stderr: "" };
|
|
if ((cmd === "pnpm" || cmd.endsWith("/pnpm")) && args[0] === "--version") return r("10.0.0\n");
|
|
if (cmd === "python3" && args[0] === "--version") return r("Python 3.11.2\n");
|
|
if (cmd === "git" && args[0] === "--version") return r("git version 2.39.2\n");
|
|
return { code: 0, signal: null, timedOut: false, stdout: "", stderr: "" };
|
|
},
|
|
});
|
|
const code = await run(["doctor"], ctx);
|
|
assert.equal(code, 0);
|
|
assert.ok(ctx.out().includes("All checks passed"));
|
|
});
|
|
|
|
const r = (stdout: string) => ({ code: 0, signal: null, timedOut: false, stdout, stderr: "" });
|