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
+31 -1
View File
@@ -2,7 +2,8 @@ import { readFile } from "node:fs/promises";
import { startManagerServer } from "../../src/mgr/server.js";
import { ManagerClient } from "../../src/mgr/client.js";
import { runOnce } from "../../src/runner/run-once.js";
import type { JsonRecord, JsonValue } from "../../src/common/types.js";
import { renderRunnerJobDryRun } from "../../src/runner/k8s-job.js";
import type { JsonRecord, JsonValue, RunRecord } from "../../src/common/types.js";
import { AgentRunError, errorToJson } from "../../src/common/errors.js";
import type { RunnerOnceOptions } from "../../src/runner/run-once.js";
@@ -58,9 +59,37 @@ async function dispatch(args: ParsedArgs): Promise<JsonValue> {
if (codexHome) options.codexHome = codexHome;
return runOnce(options) as unknown as JsonValue;
}
if (group === "runner" && command === "job") return renderRunnerJob(args);
throw new AgentRunError("schema-invalid", `unsupported command: ${args.positional.join(" ")}`, { httpStatus: 2 });
}
async function renderRunnerJob(args: ParsedArgs): Promise<JsonRecord> {
if (args.flags.get("dry-run") !== true) throw new AgentRunError("schema-invalid", "runner job only supports --dry-run in v0.1", { httpStatus: 2 });
const runId = flag(args, "run-id", "");
const commandId = flag(args, "command-id", "");
const image = flag(args, "image", "");
if (!runId) throw new AgentRunError("schema-invalid", "runner job requires --run-id", { httpStatus: 2 });
if (!commandId) throw new AgentRunError("schema-invalid", "runner job requires --command-id", { httpStatus: 2 });
if (!image) throw new AgentRunError("schema-invalid", "runner job requires --image", { httpStatus: 2 });
const run = await client(args).get(`/api/v1/runs/${encodeURIComponent(runId)}`) as RunRecord;
const options = {
run,
commandId,
image,
managerUrl: managerUrl(args),
namespace: optionalFlag(args, "namespace") ?? "agentrun-v01",
};
const attemptId = optionalFlag(args, "attempt-id");
const runnerId = optionalFlag(args, "runner-id");
const sourceCommit = optionalFlag(args, "source-commit");
return renderRunnerJobDryRun({
...options,
...(attemptId ? { attemptId } : {}),
...(runnerId ? { runnerId } : {}),
...(sourceCommit ? { sourceCommit } : {}),
});
}
async function startServer(args: ParsedArgs): Promise<JsonRecord> {
const port = Number(flag(args, "port", "8080"));
const host = flag(args, "host", "0.0.0.0");
@@ -123,6 +152,7 @@ function help(): JsonRecord {
"commands create <runId> --type turn --json-file <payload.json>",
"commands show <commandId> --run-id <runId>",
"runner start --run-id <runId>",
"runner job --dry-run --run-id <runId> --command-id <commandId> --image <image>",
"backends list",
"server start|status",
],