fix: 回填 result envelope failureKind

This commit is contained in:
AgentRun Codex
2026-06-11 09:42:36 +08:00
parent a3c8138172
commit b4c48b724d
3 changed files with 77 additions and 4 deletions
+35
View File
@@ -58,6 +58,41 @@ async function assertLongResultUsesTerminalAssistant(client: ManagerClient, stor
const finalResponse = result.finalResponse as JsonRecord;
assert.equal(finalResponse.text, "final terminal assistant");
assert.equal(finalResponse.seq, finalAssistant.seq);
const failureRun = store.createRun({
tenantId: "unidesk",
projectId: "pikasTech/agentrun",
workspaceRef: { kind: "host-path", path: "/tmp/agentrun-selftest" },
providerId: "G14",
backendProfile: "codex",
executionPolicy: {
sandbox: "workspace-write",
approval: "never",
timeoutMs: 1000,
network: "none",
secretScope: { allowCredentialEcho: false, providerCredentials: [] },
},
traceSink: null,
});
const failureCommand = store.createCommand(failureRun.id, { type: "turn", payload: { prompt: "exercise runner job result failureKind" }, idempotencyKey: "manager-result-runner-job-failure" });
store.saveRunnerJob({
runId: failureRun.id,
commandId: failureCommand.id,
payloadHash: "runner-job-failure-hash",
attemptId: "attempt_runner_job_failure",
runnerId: "runner_runner_job_failure",
namespace: "agentrun-v01",
jobName: "agentrun-v01-runner-job-failure",
managerUrl: "http://127.0.0.1",
image: "runner-image",
sourceCommit: "self-test",
serviceAccountName: null,
result: { terminalStatus: "failed", failureKind: "provider-http-error", runner: { logPath: "/tmp/runner.log" } },
});
const runnerJobFailureResult = await client.get(`/api/v1/runs/${encodeURIComponent(failureRun.id)}/result?commandId=${encodeURIComponent(failureCommand.id)}`) as JsonRecord;
assert.equal(runnerJobFailureResult.failureKind, "provider-http-error");
const runnerJobFailureCommandResult = await client.get(`/api/v1/runs/${encodeURIComponent(failureRun.id)}/commands/${encodeURIComponent(failureCommand.id)}/result`) as JsonRecord;
assert.equal(runnerJobFailureCommandResult.failureKind, "provider-http-error");
}
export default selfTest;
+8
View File
@@ -394,6 +394,10 @@ async function runFailureDoesNotTerminalRunCase(options: { client: ManagerClient
assert.equal(["claimed", "running"].includes(String(run.status)), true, "command failure must keep the reusable run/session non-terminal");
assert.equal(run.terminalStatus, null);
assert.equal(run.failureKind, null);
const runEnvelope = await options.client.get(`/api/v1/runs/${item.runId}/result?commandId=${item.commandId}`) as JsonRecord;
assert.equal(runEnvelope.failureKind, "provider-http-error", "run result must inherit terminal command failureKind even when reusable run stays non-terminal");
const commandEnvelope = await options.client.get(`/api/v1/runs/${item.runId}/commands/${item.commandId}/result`) as JsonRecord;
assert.equal(commandEnvelope.failureKind, "provider-http-error", "command result must expose provider HTTP failureKind from terminal command/events");
}
async function runFailureCase(options: { client: ManagerClient; managerUrl: string; context: SelfTestContext; mode: string; expectedStatus: TerminalStatus; expectedFailureKind: FailureKind; timeoutMs?: number; expectRetryError?: boolean }): Promise<void> {
@@ -509,6 +513,10 @@ async function runSpawnFailureCase(options: { client: ManagerClient; managerUrl:
assert.ok(events.items?.some((event) => event.type === "error"), "spawn failure");
const command = await options.client.get(`/api/v1/runs/${item.runId}/commands/${item.commandId}`) as { state?: string };
assert.equal(command.state, "failed", "spawn failure");
const commandEnvelope = await options.client.get(`/api/v1/runs/${item.runId}/commands/${item.commandId}/result`) as JsonRecord;
assert.equal(commandEnvelope.failureKind, "backend-spawn-failed", "spawn failure command result kind");
const runEnvelope = await options.client.get(`/api/v1/runs/${item.runId}/result?commandId=${item.commandId}`) as JsonRecord;
assert.equal(runEnvelope.failureKind, "backend-spawn-failed", "spawn failure run result kind");
assertNoSecretLeak(events);
}