This commit is contained in:
Wu Shuwen 2026-09-13 15:31:33 +08:00 committed by GitHub
commit 39fa04b83a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,40 @@
import { describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
runChildProcess: vi.fn(),
}));
vi.mock("../utils.js", async (importOriginal) => ({
...(await importOriginal<typeof import("../utils.js")>()),
runChildProcess: mocks.runChildProcess,
}));
import { execute } from "./execute.js";
describe("process adapter execution", () => {
it("fails when a child is terminated by a signal with no exit code", async () => {
mocks.runChildProcess.mockResolvedValueOnce({
exitCode: null,
signal: "SIGTERM",
timedOut: false,
stdout: "",
stderr: "",
});
const result = await execute({
runId: "signal-test",
agent: { id: "agent", companyId: "company" },
config: { command: process.execPath },
onLog: async () => {},
onMeta: async () => {},
} as any);
expect(result).toMatchObject({
exitCode: null,
signal: "SIGTERM",
timedOut: false,
});
expect(result.errorMessage).toContain("SIGTERM");
expect(result.resultJson).toEqual({ stdout: "", stderr: "" });
});
});

View File

@ -80,6 +80,19 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
};
}
if (proc.signal) {
return {
exitCode: proc.exitCode,
signal: proc.signal,
timedOut: false,
errorMessage: `Process terminated by signal ${proc.signal}`,
resultJson: {
stdout: proc.stdout,
stderr: proc.stderr,
},
};
}
if ((proc.exitCode ?? 0) !== 0) {
return {
exitCode: proc.exitCode,