fix(server): report failing scripts via run.finished only (#4)

A non-zero exit is a normal result (a failed check shows as a cross), not an execution error; publishing run.error showed an error banner for every failed check.
This commit is contained in:
Florian Schmidt
2026-11-16 00:21:17 +01:00
parent d10b2114df
commit b50d49b790
2 changed files with 9 additions and 1 deletions
-1
View File
@@ -121,7 +121,6 @@ export async function executeRun({ config, hub, runId, request, step, rendered,
if (rendered.local) exitCode = await localExec(workdir, rendered.script, env, step.attrs.sudo, timeout, output); if (rendered.local) exitCode = await localExec(workdir, rendered.script, env, step.attrs.sudo, timeout, output);
else exitCode = await exec(client!, `cd ${shellQuote(remoteDir!)} && ${step.attrs.sudo ? "sudo -n " : ""}bash -euo pipefail -s`, scriptInput(rendered.script, env), timeout, output); else exitCode = await exec(client!, `cd ${shellQuote(remoteDir!)} && ${step.attrs.sudo ? "sudo -n " : ""}bash -euo pipefail -s`, scriptInput(rendered.script, env), timeout, output);
streams.stdout.end(); streams.stderr.end(); streams.stdout.end(); streams.stderr.end();
if (exitCode !== 0) hub.publish({ type: "run.error", runId, message: clean(`Script exited with code ${exitCode}`) });
if (captureTooLarge) throw new Error("Captured output exceeds 1 MiB"); if (captureTooLarge) throw new Error("Captured output exceeds 1 MiB");
if (exitCode === 0) { if (exitCode === 0) {
for (const name of rendered.artifacts) { for (const name of rendered.artifacts) {
+9
View File
@@ -119,6 +119,15 @@ describe("SSH with a deterministic in-process server", () => {
expect(JSON.parse(audit).script).toBe(r.script); expect(JSON.parse(audit).script).toBe(r.script);
expect(audit + JSON.stringify(events)).not.toContain("secret'word"); expect(audit + JSON.stringify(events)).not.toContain("secret'word");
}); });
it("reports a failing script only through run.finished, not as a run.error", async () => {
// A failing check is a normal result (❌), not a transport/execution error.
const { config, host, fp } = await sshFixture();
const hub = new EventsHub(); const events: ServerEvent[] = []; hub.subscribe(e => events.push(e));
const r = rendered(); r.script = "FAIL";
await executeRun({ config, hub, runId: randomUUID(), request: { ...request(), acceptHostKey: fp }, step: step(), rendered: r, host, env: {} });
expect(events.at(-1)).toMatchObject({ type: "run.finished", exitCode: 7 });
expect(events.some(e => e.type === "run.error")).toBe(false);
});
it("emits TOFU events and a failed audited result", async () => { it("emits TOFU events and a failed audited result", async () => {
const { config, host, fp } = await sshFixture(); const hub = new EventsHub(); const events: ServerEvent[] = []; hub.subscribe(e => events.push(e)); const { config, host, fp } = await sshFixture(); const hub = new EventsHub(); const events: ServerEvent[] = []; hub.subscribe(e => events.push(e));
await executeRun({ config, hub, runId: randomUUID(), request: request(), step: step(), rendered: rendered(), host, env: {} }); await executeRun({ config, hub, runId: randomUUID(), request: request(), step: step(), rendered: rendered(), host, env: {} });