041a19f060
* feat: add service-managed self-update * chore: add temporary self-update test scripts * chore: simplify temporary script markdown fences * chore: run frontend in temporary self-update scripts * fix: show self-update job progress after apply * chore: add real npm self-update test script * fix: isolate npm self-update prefix * fix: detect npm service installs from bin shim * chore: reset service before real npm update test * chore: expand real npm status diagnostics * fix: preserve service home during self-update * fix(cli): tee self-update helper output to a log file * fix(cli): avoid launchd bootstrap race when reloading the macOS service * fix(backend): run macOS self-update helper once via transient launchd plist * fix(web): show self-update progress and lock the apply button until the update lands * fix(cli): reinstall via the kandev wrapper on Homebrew self-update * chore: remove temp self-update test scripts * fix(web): drop unused apply path from useUpdates hook * fix(backend): snapshot install state once in apply preflight * docs: align self-update docs with transient LaunchAgent flow * chore(release): run cli bundle from apps workspace root * fix(backend): guard against concurrent self-update applies * fix(backend): check scheme and helper paths in self-update apply * fix(backend): drop duplicate binary name from npx manual command * fix(cli): allow --help for service self-update without --intent * fix(cli): harden self-update dir perms and darwin uid resolution * fix(web): set required POST fields last in applyUpdate * docs: use JSON body notation for the apply endpoint * fix(backend): expire self-update guard so a stuck helper cannot wedge apply * refactor(cli): collapse redundant writeSync branch in self-update log
124 lines
4.3 KiB
TypeScript
124 lines
4.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { ParseError } from "../args";
|
|
import { parseServiceArgs } from "./args";
|
|
|
|
describe("parseServiceArgs", () => {
|
|
it("returns showHelp when invoked with no args", () => {
|
|
const r = parseServiceArgs([]);
|
|
expect(r.showHelp).toBe(true);
|
|
});
|
|
|
|
it("returns showHelp on --help with no action", () => {
|
|
expect(parseServiceArgs(["--help"]).showHelp).toBe(true);
|
|
expect(parseServiceArgs(["-h"]).showHelp).toBe(true);
|
|
});
|
|
|
|
it("parses each valid action", () => {
|
|
for (const action of [
|
|
"install",
|
|
"uninstall",
|
|
"start",
|
|
"stop",
|
|
"restart",
|
|
"status",
|
|
"logs",
|
|
"config",
|
|
] as const) {
|
|
expect(parseServiceArgs([action]).action).toBe(action);
|
|
}
|
|
});
|
|
|
|
it("throws ParseError on unknown action", () => {
|
|
expect(() => parseServiceArgs(["nope"])).toThrow(ParseError);
|
|
expect(() => parseServiceArgs(["nope"])).toThrow(/unknown service action/);
|
|
});
|
|
|
|
it("parses --system on install", () => {
|
|
expect(parseServiceArgs(["install", "--system"]).system).toBe(true);
|
|
expect(parseServiceArgs(["install"]).system).toBeUndefined();
|
|
});
|
|
|
|
it("parses --port", () => {
|
|
expect(parseServiceArgs(["install", "--port", "9000"]).port).toBe(9000);
|
|
expect(parseServiceArgs(["install", "--port=9000"]).port).toBe(9000);
|
|
});
|
|
|
|
it("rejects invalid --port values", () => {
|
|
expect(() => parseServiceArgs(["install", "--port=abc"])).toThrow(/must be an integer/);
|
|
expect(() => parseServiceArgs(["install", "--port=0"])).toThrow(/between 1 and 65535/);
|
|
expect(() => parseServiceArgs(["install", "--port=65536"])).toThrow(/between 1 and 65535/);
|
|
});
|
|
|
|
it("parses --home-dir", () => {
|
|
expect(parseServiceArgs(["install", "--home-dir", "/srv/kandev"]).homeDir).toBe("/srv/kandev");
|
|
expect(parseServiceArgs(["install", "--home-dir=/srv/kandev"]).homeDir).toBe("/srv/kandev");
|
|
});
|
|
|
|
it("rejects empty --home-dir", () => {
|
|
expect(() => parseServiceArgs(["install", "--home-dir="])).toThrow(/--home-dir requires/);
|
|
});
|
|
|
|
it("parses --no-boot-start", () => {
|
|
expect(parseServiceArgs(["install", "--no-boot-start"]).noBootStart).toBe(true);
|
|
});
|
|
|
|
it("parses --follow on logs", () => {
|
|
expect(parseServiceArgs(["logs", "-f"]).follow).toBe(true);
|
|
expect(parseServiceArgs(["logs", "--follow"]).follow).toBe(true);
|
|
});
|
|
|
|
it("throws ParseError on unknown flag", () => {
|
|
expect(() => parseServiceArgs(["install", "--nope"])).toThrow(/unknown flag/);
|
|
});
|
|
|
|
it("rejects --follow for actions other than logs", () => {
|
|
expect(() => parseServiceArgs(["start", "--follow"])).toThrow(
|
|
/--follow only applies to 'kandev service logs'/,
|
|
);
|
|
expect(() => parseServiceArgs(["status", "-f"])).toThrow(
|
|
/--follow only applies to 'kandev service logs'/,
|
|
);
|
|
// happy path
|
|
expect(parseServiceArgs(["logs", "-f"]).follow).toBe(true);
|
|
});
|
|
|
|
it("rejects install-only flags on non-install actions", () => {
|
|
expect(() => parseServiceArgs(["stop", "--port=9000"])).toThrow(
|
|
/--port only applies to 'kandev service install'/,
|
|
);
|
|
expect(() => parseServiceArgs(["restart", "--home-dir=/x"])).toThrow(
|
|
/--home-dir only applies to 'kandev service install'/,
|
|
);
|
|
expect(() => parseServiceArgs(["status", "--no-boot-start"])).toThrow(
|
|
/--no-boot-start only applies to 'kandev service install'/,
|
|
);
|
|
// happy path
|
|
expect(parseServiceArgs(["install", "--port=9000"]).port).toBe(9000);
|
|
});
|
|
|
|
it("parses hidden self-update helper flags", () => {
|
|
const args = parseServiceArgs(["self-update", "--intent", "/tmp/intent.json", "--dry-run"]);
|
|
expect(args.action).toBe("self-update");
|
|
expect(args.intent).toBe("/tmp/intent.json");
|
|
expect(args.dryRun).toBe(true);
|
|
});
|
|
|
|
it("requires --intent for self-update", () => {
|
|
expect(() => parseServiceArgs(["self-update"])).toThrow(/requires --intent/);
|
|
});
|
|
|
|
it("allows --help for self-update without --intent", () => {
|
|
const r = parseServiceArgs(["self-update", "--help"]);
|
|
expect(r.action).toBe("self-update");
|
|
expect(r.showHelp).toBe(true);
|
|
});
|
|
|
|
it("rejects self-update-only flags elsewhere", () => {
|
|
expect(() => parseServiceArgs(["install", "--intent=/tmp/intent.json"])).toThrow(
|
|
/--intent only applies/,
|
|
);
|
|
expect(() => parseServiceArgs(["install", "--dry-run"])).toThrow(/--dry-run only applies/);
|
|
});
|
|
});
|