refactor: dedupe cli config cron and install flows

This commit is contained in:
Peter Steinberger
2026-03-02 19:48:38 +00:00
parent 9d30159fcd
commit b1c30f0ba9
80 changed files with 1379 additions and 2027 deletions

View File

@@ -41,6 +41,28 @@ function createMockChild(params?: { code?: number; signal?: NodeJS.Signals | nul
return child;
}
type SpawnCall = [string, string[], Record<string, unknown>];
type ExecCall = [
string,
string[],
Record<string, unknown>,
(err: Error | null, stdout: string, stderr: string) => void,
];
function expectCmdWrappedInvocation(params: {
captured: SpawnCall | ExecCall | undefined;
expectedComSpec: string;
}) {
if (!params.captured) {
throw new Error("expected command wrapper to be called");
}
expect(params.captured[0]).toBe(params.expectedComSpec);
expect(params.captured[1].slice(0, 3)).toEqual(["/d", "/s", "/c"]);
expect(params.captured[1][3]).toContain("pnpm.cmd --version");
expect(params.captured[2].windowsVerbatimArguments).toBe(true);
}
describe("windows command wrapper behavior", () => {
afterEach(() => {
spawnMock.mockReset();
@@ -59,16 +81,8 @@ describe("windows command wrapper behavior", () => {
try {
const result = await runCommandWithTimeout(["pnpm", "--version"], { timeoutMs: 1000 });
expect(result.code).toBe(0);
const captured = spawnMock.mock.calls[0] as
| [string, string[], Record<string, unknown>]
| undefined;
if (!captured) {
throw new Error("spawn mock was not called");
}
expect(captured[0]).toBe(expectedComSpec);
expect(captured[1].slice(0, 3)).toEqual(["/d", "/s", "/c"]);
expect(captured[1][3]).toContain("pnpm.cmd --version");
expect(captured[2].windowsVerbatimArguments).toBe(true);
const captured = spawnMock.mock.calls[0] as SpawnCall | undefined;
expectCmdWrappedInvocation({ captured, expectedComSpec });
} finally {
platformSpy.mockRestore();
}
@@ -91,21 +105,8 @@ describe("windows command wrapper behavior", () => {
try {
await runExec("pnpm", ["--version"], 1000);
const captured = execFileMock.mock.calls[0] as
| [
string,
string[],
Record<string, unknown>,
(err: Error | null, stdout: string, stderr: string) => void,
]
| undefined;
if (!captured) {
throw new Error("execFile mock was not called");
}
expect(captured[0]).toBe(expectedComSpec);
expect(captured[1].slice(0, 3)).toEqual(["/d", "/s", "/c"]);
expect(captured[1][3]).toContain("pnpm.cmd --version");
expect(captured[2].windowsVerbatimArguments).toBe(true);
const captured = execFileMock.mock.calls[0] as ExecCall | undefined;
expectCmdWrappedInvocation({ captured, expectedComSpec });
} finally {
platformSpy.mockRestore();
}