feat: 补充 runner Job dry-run 骨架

This commit is contained in:
Codex
2026-05-29 11:45:18 +08:00
parent a240122039
commit d236cfee61
12 changed files with 418 additions and 36 deletions
+9 -1
View File
@@ -6,6 +6,7 @@ import assert from "node:assert/strict";
import { startManagerServer } from "../mgr/server.js";
import { ManagerClient } from "../mgr/client.js";
import { runOnce } from "../runner/run-once.js";
import { renderRunnerJobDryRun } from "../runner/k8s-job.js";
import { redactText } from "../common/redaction.js";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
@@ -45,18 +46,25 @@ try {
const command = await client.post(`/api/v1/runs/${run.id}/commands`, { type: "turn", payload: { prompt: "hello" }, idempotencyKey: "selftest-turn" }) as { id: string };
const duplicate = await client.post(`/api/v1/runs/${run.id}/commands`, { type: "turn", payload: { prompt: "hello" }, idempotencyKey: "selftest-turn" }) as { id: string };
assert.equal(duplicate.id, command.id);
const rendered = renderRunnerJobDryRun({ run: await client.get(`/api/v1/runs/${run.id}`) as never, commandId: command.id, managerUrl: server.baseUrl, image: "127.0.0.1:5000/agentrun/agentrun-mgr@sha256:1111111111111111111111111111111111111111111111111111111111111111", attemptId: "attempt_selftest", sourceCommit: "self-test" });
assert.equal(rendered.dryRun, true);
assert.equal(rendered.mutation, false);
assert.equal((rendered.jobIdentity as { serviceAccountName?: string }).serviceAccountName, "agentrun-v01-runner");
assert.equal(JSON.stringify(rendered).includes("test-token-material"), false);
const fakePath = path.join(root, "src/selftest/fake-codex-app-server.ts");
const fakeCommand = process.env.AGENTRUN_SELFTEST_CODEX_COMMAND ?? process.execPath;
const fakeArgs = process.env.AGENTRUN_SELFTEST_CODEX_ARGS ? JSON.parse(process.env.AGENTRUN_SELFTEST_CODEX_ARGS) as string[] : [fakePath];
const result = await runOnce({ managerUrl: server.baseUrl, runId: run.id, codexCommand: fakeCommand, codexArgs: fakeArgs, codexHome, env: { CODEX_HOME: codexHome } });
assert.equal(result.terminalStatus, "completed");
assert.equal(typeof (result.runner as { id?: unknown }).id, "string");
const events = await client.get(`/api/v1/runs/${run.id}/events?afterSeq=0&limit=100`) as { items?: Array<{ type: string; payload: unknown }> };
assert.ok(events.items?.some((event) => event.type === "assistant_message"));
assert.ok(events.items?.some((event) => event.type === "backend_status" && JSON.stringify(event.payload).includes("run-claimed")));
assert.equal(JSON.stringify(events).includes("test-token-material"), false);
assert.equal(JSON.stringify(events).includes("Bearer test-token"), false);
const finalRun = await client.get(`/api/v1/runs/${run.id}`) as { terminalStatus?: string };
assert.equal(finalRun.terminalStatus, "completed");
console.log(JSON.stringify({ ok: true, tests: ["manager-memory-lifecycle", "codex-stdio-fake-turn", "redaction"], runId: run.id }));
console.log(JSON.stringify({ ok: true, tests: ["manager-memory-lifecycle", "runner-lease-heartbeat", "runner-k8s-job-dry-run", "codex-stdio-fake-turn", "redaction"], runId: run.id, jobName: (rendered.jobIdentity as { name?: string }).name }));
} finally {
await new Promise<void>((resolve) => server.server.close(() => resolve()));
}