mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:40:44 +00:00
test(process): share shimmed windows success assertions
This commit is contained in:
@@ -90,6 +90,26 @@ function expectCmdWrappedInvocation(params: {
|
||||
expect(params.captured[2].windowsVerbatimArguments).toBe(true);
|
||||
}
|
||||
|
||||
async function expectShimmedWindowsCommandWithoutExitCodeSucceeds(params?: { killed?: boolean }) {
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
||||
const child = createMockChild({
|
||||
closeCode: null,
|
||||
exitCode: null,
|
||||
});
|
||||
child.killed = params?.killed ?? false;
|
||||
|
||||
spawnMock.mockImplementation(() => child);
|
||||
|
||||
try {
|
||||
const result = await runCommandWithTimeout(["npm", "--version"], { timeoutMs: 1000 });
|
||||
expect(result.code).toBe(0);
|
||||
expect(result.signal).toBeNull();
|
||||
expect(result.termination).toBe("exit");
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
}
|
||||
|
||||
describe("windows command wrapper behavior", () => {
|
||||
beforeAll(async () => {
|
||||
({ runCommandWithTimeout, runExec } = await import("./exec.js"));
|
||||
@@ -237,42 +257,11 @@ describe("windows command wrapper behavior", () => {
|
||||
});
|
||||
|
||||
it("treats shimmed Windows commands without a reported exit code as success when they close cleanly", async () => {
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
||||
const child = createMockChild({
|
||||
closeCode: null,
|
||||
exitCode: null,
|
||||
});
|
||||
|
||||
spawnMock.mockImplementation(() => child);
|
||||
|
||||
try {
|
||||
const result = await runCommandWithTimeout(["npm", "--version"], { timeoutMs: 1000 });
|
||||
expect(result.code).toBe(0);
|
||||
expect(result.signal).toBeNull();
|
||||
expect(result.termination).toBe("exit");
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
await expectShimmedWindowsCommandWithoutExitCodeSucceeds();
|
||||
});
|
||||
|
||||
it("treats shimmed Windows commands without a reported exit code as success even when child.killed is true", async () => {
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
||||
const child = createMockChild({
|
||||
closeCode: null,
|
||||
exitCode: null,
|
||||
});
|
||||
child.killed = true;
|
||||
|
||||
spawnMock.mockImplementation(() => child);
|
||||
|
||||
try {
|
||||
const result = await runCommandWithTimeout(["npm", "--version"], { timeoutMs: 1000 });
|
||||
expect(result.code).toBe(0);
|
||||
expect(result.signal).toBeNull();
|
||||
expect(result.termination).toBe("exit");
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
await expectShimmedWindowsCommandWithoutExitCodeSucceeds({ killed: true });
|
||||
});
|
||||
|
||||
it("uses cmd.exe wrapper with windowsVerbatimArguments in runExec for .cmd shims", async () => {
|
||||
|
||||
Reference in New Issue
Block a user