chore: integrate v0.1 component branches
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { openAgentRunStoreFromEnv } from "../../mgr/store.js";
|
||||
import { postgresMigrationContract } from "../../mgr/postgres-store.js";
|
||||
import { redactText } from "../../common/redaction.js";
|
||||
import { AgentRunError } from "../../common/errors.js";
|
||||
import type { SelfTestCase } from "../harness.js";
|
||||
|
||||
const selfTest: SelfTestCase = async () => {
|
||||
assert.equal(redactText("Authorization: Bearer abc123"), "Authorization: Bearer REDACTED");
|
||||
assert.equal(redactText('{"token":"test-token-material"}').includes("test-token-material"), false);
|
||||
await assert.rejects(
|
||||
() => openAgentRunStoreFromEnv({}),
|
||||
(error) => error instanceof AgentRunError && error.failureKind === "infra-failed" && error.message.includes("DATABASE_URL is required"),
|
||||
);
|
||||
const postgresContract = postgresMigrationContract();
|
||||
assert.equal(postgresContract.latestMigrationId, "001_v01_initial_durable_store");
|
||||
assert.ok(Array.isArray(postgresContract.requiredTables));
|
||||
assert.ok(postgresContract.requiredTables.includes("agentrun_schema_migrations"));
|
||||
assert.ok(postgresContract.requiredTables.includes("agentrun_runs"));
|
||||
assert.ok(postgresContract.requiredTables.includes("agentrun_events"));
|
||||
return { name: "redaction-postgres", tests: ["redaction", "postgres-store-contract"] };
|
||||
};
|
||||
|
||||
export default selfTest;
|
||||
@@ -0,0 +1,23 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { startManagerServer } from "../../mgr/server.js";
|
||||
import { MemoryAgentRunStore } from "../../mgr/store.js";
|
||||
import { ManagerClient } from "../../mgr/client.js";
|
||||
import type { SelfTestCase } from "../harness.js";
|
||||
|
||||
const selfTest: SelfTestCase = async () => {
|
||||
const server = await startManagerServer({ port: 0, host: "127.0.0.1", sourceCommit: "self-test", store: new MemoryAgentRunStore() });
|
||||
try {
|
||||
const client = new ManagerClient(server.baseUrl);
|
||||
const health = await client.get("/health/readiness") as { database?: { adapter?: string; reachable?: boolean; migrationReady?: boolean; failureKind?: string | null }; secretRefs?: { valuesPrinted?: boolean } };
|
||||
assert.equal(health.database?.adapter, "memory-self-test");
|
||||
assert.equal(health.database?.reachable, true);
|
||||
assert.equal(health.database?.migrationReady, true);
|
||||
assert.equal(health.database?.failureKind, null);
|
||||
assert.equal(health.secretRefs?.valuesPrinted, false);
|
||||
return { name: "manager-memory", tests: ["manager-memory-lifecycle"] };
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.server.close(() => resolve()));
|
||||
}
|
||||
};
|
||||
|
||||
export default selfTest;
|
||||
@@ -0,0 +1,32 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { startManagerServer } from "../../mgr/server.js";
|
||||
import { MemoryAgentRunStore } from "../../mgr/store.js";
|
||||
import { ManagerClient } from "../../mgr/client.js";
|
||||
import { renderRunnerJobDryRun } from "../../runner/k8s-job.js";
|
||||
import type { RunRecord } from "../../common/types.js";
|
||||
import { assertNoSecretLeak, createRunWithCommand, type SelfTestCase } from "../harness.js";
|
||||
|
||||
const selfTest: SelfTestCase = async (context) => {
|
||||
const server = await startManagerServer({ port: 0, host: "127.0.0.1", sourceCommit: "self-test", store: new MemoryAgentRunStore() });
|
||||
try {
|
||||
const client = new ManagerClient(server.baseUrl);
|
||||
const item = await createRunWithCommand(client, context, "job smoke", "selftest-job-render", 15_000);
|
||||
const rendered = renderRunnerJobDryRun({
|
||||
run: await client.get(`/api/v1/runs/${item.runId}`) as RunRecord,
|
||||
commandId: item.commandId,
|
||||
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");
|
||||
assertNoSecretLeak(rendered);
|
||||
return { name: "runner-k8s-job", tests: ["runner-k8s-job-dry-run"] };
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.server.close(() => resolve()));
|
||||
}
|
||||
};
|
||||
|
||||
export default selfTest;
|
||||
@@ -0,0 +1,71 @@
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import os from "node:os";
|
||||
import { startManagerServer } from "../../mgr/server.js";
|
||||
import { MemoryAgentRunStore } from "../../mgr/store.js";
|
||||
import { ManagerClient } from "../../mgr/client.js";
|
||||
import { runOnce } from "../../runner/run-once.js";
|
||||
import type { FailureKind, JsonRecord, TerminalStatus } from "../../common/types.js";
|
||||
import { assertNoSecretLeak, createRunWithCommand, type SelfTestCase, type SelfTestContext } from "../harness.js";
|
||||
|
||||
const selfTest: SelfTestCase = async (context) => {
|
||||
const server = await startManagerServer({ port: 0, host: "127.0.0.1", sourceCommit: "self-test", store: new MemoryAgentRunStore() });
|
||||
try {
|
||||
const client = new ManagerClient(server.baseUrl);
|
||||
const happy = await createRunWithCommand(client, context, "hello", "selftest-turn", 15_000);
|
||||
const result = await runOnce({ managerUrl: server.baseUrl, runId: happy.runId, codexCommand: context.fakeCodexCommand, codexArgs: context.fakeCodexArgs, codexHome: context.codexHome, env: { CODEX_HOME: context.codexHome } });
|
||||
assert.equal(result.terminalStatus, "completed");
|
||||
assert.equal(typeof (result.runner as { id?: unknown }).id, "string");
|
||||
const events = await client.get(`/api/v1/runs/${happy.runId}/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")));
|
||||
assertNoSecretLeak(events);
|
||||
const finalRun = await client.get(`/api/v1/runs/${happy.runId}`) as { terminalStatus?: string };
|
||||
assert.equal(finalRun.terminalStatus, "completed");
|
||||
|
||||
await runFailureCase({ client, managerUrl: server.baseUrl, context, mode: "missing-turn-result", expectedStatus: "failed", expectedFailureKind: "backend-response-invalid" });
|
||||
await runFailureCase({ client, managerUrl: server.baseUrl, context, mode: "invalid-json", expectedStatus: "failed", expectedFailureKind: "backend-json-parse-error" });
|
||||
await runFailureCase({ client, managerUrl: server.baseUrl, context, mode: "missing-terminal", expectedStatus: "failed", expectedFailureKind: "backend-timeout", timeoutMs: 500 });
|
||||
await runSpawnFailureCase({ client, managerUrl: server.baseUrl, context });
|
||||
|
||||
return { name: "codex-stdio", tests: ["runner-lease-heartbeat", "codex-stdio-fake-turn", "codex-stdio-missing-turn-result", "codex-stdio-invalid-json", "codex-stdio-timeout", "codex-stdio-spawn-failure"] };
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.server.close(() => resolve()));
|
||||
}
|
||||
};
|
||||
|
||||
async function runFailureCase(options: { client: ManagerClient; managerUrl: string; context: SelfTestContext; mode: string; expectedStatus: TerminalStatus; expectedFailureKind: FailureKind; timeoutMs?: number }): Promise<void> {
|
||||
const item = await createRunWithCommand(options.client, options.context, `failure ${options.mode}`, `selftest-${options.mode}`, options.timeoutMs ?? 3_000);
|
||||
const result = await runOnce({
|
||||
managerUrl: options.managerUrl,
|
||||
runId: item.runId,
|
||||
codexCommand: options.context.fakeCodexCommand,
|
||||
codexArgs: options.context.fakeCodexArgs,
|
||||
codexHome: options.context.codexHome,
|
||||
env: { CODEX_HOME: options.context.codexHome, AGENTRUN_FAKE_CODEX_MODE: options.mode },
|
||||
}) as JsonRecord;
|
||||
assert.equal(result.terminalStatus, options.expectedStatus, options.mode);
|
||||
assert.equal(result.failureKind, options.expectedFailureKind, options.mode);
|
||||
const events = await options.client.get(`/api/v1/runs/${item.runId}/events?afterSeq=0&limit=100`) as { items?: Array<{ type: string; payload: unknown }> };
|
||||
assert.ok(events.items?.some((event) => event.type === "error"), options.mode);
|
||||
assertNoSecretLeak(events);
|
||||
}
|
||||
|
||||
async function runSpawnFailureCase(options: { client: ManagerClient; managerUrl: string; context: SelfTestContext }): Promise<void> {
|
||||
const item = await createRunWithCommand(options.client, options.context, "failure spawn", "selftest-spawn-failure", 3_000);
|
||||
const result = await runOnce({
|
||||
managerUrl: options.managerUrl,
|
||||
runId: item.runId,
|
||||
codexCommand: path.join(os.tmpdir(), `agentrun-missing-codex-${process.pid}`),
|
||||
codexArgs: [],
|
||||
codexHome: options.context.codexHome,
|
||||
env: { CODEX_HOME: options.context.codexHome },
|
||||
}) as JsonRecord;
|
||||
assert.equal(result.terminalStatus, "failed", "spawn failure");
|
||||
assert.equal(result.failureKind, "backend-spawn-failed", "spawn failure");
|
||||
const events = await options.client.get(`/api/v1/runs/${item.runId}/events?afterSeq=0&limit=100`) as { items?: Array<{ type: string; payload: unknown }> };
|
||||
assert.ok(events.items?.some((event) => event.type === "error"), "spawn failure");
|
||||
assertNoSecretLeak(events);
|
||||
}
|
||||
|
||||
export default selfTest;
|
||||
@@ -0,0 +1,82 @@
|
||||
import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
import { ManagerClient } from "../mgr/client.js";
|
||||
import type { JsonRecord } from "../common/types.js";
|
||||
|
||||
export interface SelfTestContext {
|
||||
root: string;
|
||||
tmp: string;
|
||||
codexHome: string;
|
||||
workspace: string;
|
||||
fakeCodexPath: string;
|
||||
fakeCodexCommand: string;
|
||||
fakeCodexArgs: string[];
|
||||
cleanup(): Promise<void>;
|
||||
}
|
||||
|
||||
export interface SelfTestResult {
|
||||
name?: string;
|
||||
tests?: string[];
|
||||
}
|
||||
|
||||
export type SelfTestCase = (context: SelfTestContext) => Promise<SelfTestResult> | SelfTestResult;
|
||||
|
||||
export async function createSelfTestContext(root: string): Promise<SelfTestContext> {
|
||||
const tmp = await mkdtemp(path.join(os.tmpdir(), "agentrun-selftest-"));
|
||||
const codexHome = path.join(tmp, "codex-home");
|
||||
const workspace = path.join(tmp, "workspace");
|
||||
await mkdir(codexHome, { recursive: true });
|
||||
await mkdir(workspace, { recursive: true });
|
||||
await writeFile(path.join(codexHome, "auth.json"), JSON.stringify({ token: "test-token-material" }));
|
||||
await writeFile(path.join(codexHome, "config.toml"), "model = \"gpt-test\"\n");
|
||||
await writeFile(path.join(workspace, "README.md"), "self-test workspace\n");
|
||||
const fakeCodexPath = path.join(root, "src/selftest/fake-codex-app-server.ts");
|
||||
return {
|
||||
root,
|
||||
tmp,
|
||||
codexHome,
|
||||
workspace,
|
||||
fakeCodexPath,
|
||||
fakeCodexCommand: process.env.AGENTRUN_SELFTEST_CODEX_COMMAND ?? defaultFakeCommand(),
|
||||
fakeCodexArgs: process.env.AGENTRUN_SELFTEST_CODEX_ARGS ? JSON.parse(process.env.AGENTRUN_SELFTEST_CODEX_ARGS) as string[] : defaultFakeArgs(fakeCodexPath),
|
||||
cleanup: () => rm(tmp, { recursive: true, force: true }),
|
||||
};
|
||||
}
|
||||
|
||||
export async function createRunWithCommand(client: ManagerClient, context: Pick<SelfTestContext, "workspace" | "codexHome">, prompt: string, idempotencyKey: string, timeoutMs: number): Promise<{ runId: string; commandId: string }> {
|
||||
const run = await client.post("/api/v1/runs", {
|
||||
tenantId: "unidesk",
|
||||
projectId: "pikasTech/unidesk",
|
||||
workspaceRef: { kind: "host-path", path: context.workspace },
|
||||
providerId: "G14",
|
||||
backendProfile: "codex",
|
||||
executionPolicy: {
|
||||
sandbox: "workspace-write",
|
||||
approval: "never",
|
||||
timeoutMs,
|
||||
network: "default",
|
||||
secretScope: { allowCredentialEcho: false, providerCredentials: [{ profile: "codex", secretRef: { name: "agentrun-v01-provider-codex", keys: ["auth.json", "config.toml"], mountPath: context.codexHome } }] },
|
||||
},
|
||||
traceSink: null,
|
||||
}) as { id: string };
|
||||
const command = await client.post(`/api/v1/runs/${run.id}/commands`, { type: "turn", payload: { prompt }, idempotencyKey }) as { id: string };
|
||||
const duplicate = await client.post(`/api/v1/runs/${run.id}/commands`, { type: "turn", payload: { prompt }, idempotencyKey }) as { id: string };
|
||||
assert.equal(duplicate.id, command.id);
|
||||
return { runId: run.id, commandId: command.id };
|
||||
}
|
||||
|
||||
export function assertNoSecretLeak(value: unknown): void {
|
||||
const text = JSON.stringify(value);
|
||||
assert.equal(text.includes("test-token-material"), false);
|
||||
assert.equal(text.includes("Bearer test-token"), false);
|
||||
}
|
||||
|
||||
function defaultFakeCommand(): string {
|
||||
return process.versions.bun ? process.execPath : "npx";
|
||||
}
|
||||
|
||||
function defaultFakeArgs(fakePath: string): string[] {
|
||||
return process.versions.bun ? [fakePath] : ["tsx", fakePath];
|
||||
}
|
||||
+20
-172
@@ -1,180 +1,28 @@
|
||||
import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import { readdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import assert from "node:assert/strict";
|
||||
import { startManagerServer } from "../mgr/server.js";
|
||||
import { MemoryAgentRunStore, openAgentRunStoreFromEnv } from "../mgr/store.js";
|
||||
import { postgresMigrationContract } from "../mgr/postgres-store.js";
|
||||
import { ManagerClient } from "../mgr/client.js";
|
||||
import { runOnce } from "../runner/run-once.js";
|
||||
import { redactText } from "../common/redaction.js";
|
||||
import { AgentRunError } from "../common/errors.js";
|
||||
import type { FailureKind, JsonRecord, TerminalStatus } from "../common/types.js";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { createSelfTestContext, type SelfTestCase, type SelfTestResult } from "./harness.js";
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const tmp = await mkdtemp(path.join(os.tmpdir(), "agentrun-selftest-"));
|
||||
const root = path.resolve(import.meta.dirname, "../..");
|
||||
const casesDir = path.join(root, "src/selftest/cases");
|
||||
const context = await createSelfTestContext(root);
|
||||
|
||||
try {
|
||||
const codexHome = path.join(tmp, "codex-home");
|
||||
const workspace = path.join(tmp, "workspace");
|
||||
await mkdir(codexHome, { recursive: true });
|
||||
await mkdir(workspace, { recursive: true });
|
||||
await writeFile(path.join(codexHome, "auth.json"), JSON.stringify({ token: "test-token-material" }));
|
||||
await writeFile(path.join(codexHome, "config.toml"), "model = \"gpt-test\"\n");
|
||||
await writeFile(path.join(workspace, "README.md"), "self-test workspace\n");
|
||||
const caseFiles = (await readdir(casesDir))
|
||||
.filter((file) => file.endsWith(".ts") && !file.endsWith(".d.ts"))
|
||||
.sort();
|
||||
const results: SelfTestResult[] = [];
|
||||
|
||||
assert.equal(redactText("Authorization: Bearer abc123"), "Authorization: Bearer REDACTED");
|
||||
assert.equal(redactText('{"token":"test-token-material"}').includes("test-token-material"), false);
|
||||
await assert.rejects(
|
||||
() => openAgentRunStoreFromEnv({}),
|
||||
(error) => error instanceof AgentRunError && error.failureKind === "infra-failed" && error.message.includes("DATABASE_URL is required"),
|
||||
);
|
||||
const postgresContract = postgresMigrationContract();
|
||||
assert.equal(postgresContract.latestMigrationId, "001_v01_initial_durable_store");
|
||||
assert.ok(Array.isArray(postgresContract.requiredTables));
|
||||
assert.ok(postgresContract.requiredTables.includes("agentrun_schema_migrations"));
|
||||
assert.ok(postgresContract.requiredTables.includes("agentrun_runs"));
|
||||
assert.ok(postgresContract.requiredTables.includes("agentrun_events"));
|
||||
|
||||
const server = await startManagerServer({ port: 0, host: "127.0.0.1", sourceCommit: "self-test", store: new MemoryAgentRunStore() });
|
||||
try {
|
||||
const client = new ManagerClient(server.baseUrl);
|
||||
const health = await client.get("/health/readiness") as { database?: { adapter?: string; reachable?: boolean; migrationReady?: boolean; failureKind?: string | null }; secretRefs?: { valuesPrinted?: boolean } };
|
||||
assert.equal(health.database?.adapter, "memory-self-test");
|
||||
assert.equal(health.database?.reachable, true);
|
||||
assert.equal(health.database?.migrationReady, true);
|
||||
assert.equal(health.database?.failureKind, null);
|
||||
assert.equal(health.secretRefs?.valuesPrinted, false);
|
||||
|
||||
const fakePath = path.join(root, "src/selftest/fake-codex-app-server.ts");
|
||||
const fakeCommand = process.env.AGENTRUN_SELFTEST_CODEX_COMMAND ?? defaultFakeCommand();
|
||||
const fakeArgs = process.env.AGENTRUN_SELFTEST_CODEX_ARGS ? JSON.parse(process.env.AGENTRUN_SELFTEST_CODEX_ARGS) as string[] : defaultFakeArgs(fakePath);
|
||||
|
||||
const happy = await createRunWithCommand(client, workspace, codexHome, "hello", "selftest-turn", 15_000);
|
||||
const result = await runOnce({ managerUrl: server.baseUrl, runId: happy.runId, codexCommand: fakeCommand, codexArgs: fakeArgs, codexHome, env: { CODEX_HOME: codexHome } });
|
||||
assert.equal(result.terminalStatus, "completed");
|
||||
const events = await client.get(`/api/v1/runs/${happy.runId}/events?afterSeq=0&limit=100`) as { items?: Array<{ type: string; payload: unknown }> };
|
||||
assert.ok(events.items?.some((event) => event.type === "assistant_message"));
|
||||
assertNoSecretLeak(events);
|
||||
const finalRun = await client.get(`/api/v1/runs/${happy.runId}`) as { terminalStatus?: string };
|
||||
assert.equal(finalRun.terminalStatus, "completed");
|
||||
|
||||
await runFailureCase({
|
||||
client,
|
||||
managerUrl: server.baseUrl,
|
||||
workspace,
|
||||
codexHome,
|
||||
fakeCommand,
|
||||
fakeArgs,
|
||||
mode: "missing-turn-result",
|
||||
expectedStatus: "failed",
|
||||
expectedFailureKind: "backend-response-invalid",
|
||||
});
|
||||
await runFailureCase({
|
||||
client,
|
||||
managerUrl: server.baseUrl,
|
||||
workspace,
|
||||
codexHome,
|
||||
fakeCommand,
|
||||
fakeArgs,
|
||||
mode: "invalid-json",
|
||||
expectedStatus: "failed",
|
||||
expectedFailureKind: "backend-json-parse-error",
|
||||
});
|
||||
await runFailureCase({
|
||||
client,
|
||||
managerUrl: server.baseUrl,
|
||||
workspace,
|
||||
codexHome,
|
||||
fakeCommand,
|
||||
fakeArgs,
|
||||
mode: "missing-terminal",
|
||||
expectedStatus: "failed",
|
||||
expectedFailureKind: "backend-timeout",
|
||||
timeoutMs: 500,
|
||||
});
|
||||
await runSpawnFailureCase({
|
||||
client,
|
||||
managerUrl: server.baseUrl,
|
||||
workspace,
|
||||
codexHome,
|
||||
});
|
||||
|
||||
console.log(JSON.stringify({ ok: true, tests: ["manager-memory-lifecycle", "codex-stdio-fake-turn", "codex-stdio-missing-turn-result", "codex-stdio-invalid-json", "codex-stdio-timeout", "codex-stdio-spawn-failure", "postgres-store-contract", "redaction"], runId: happy.runId }));
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.server.close(() => resolve()));
|
||||
for (const file of caseFiles) {
|
||||
const moduleUrl = pathToFileURL(path.join(casesDir, file)).href;
|
||||
const imported = await import(moduleUrl) as { default?: SelfTestCase; selfTest?: SelfTestCase };
|
||||
const selfTest = imported.default ?? imported.selfTest;
|
||||
if (typeof selfTest !== "function") throw new Error(`self-test case ${file} must export default or selfTest function`);
|
||||
const result = await selfTest(context);
|
||||
results.push({ name: result.name ?? file.replace(/\.ts$/u, ""), tests: result.tests ?? [] });
|
||||
}
|
||||
|
||||
console.log(JSON.stringify({ ok: true, cases: results, tests: results.flatMap((result) => result.tests) }));
|
||||
} finally {
|
||||
await rm(tmp, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
function defaultFakeCommand(): string {
|
||||
return process.versions.bun ? process.execPath : "npx";
|
||||
}
|
||||
|
||||
function defaultFakeArgs(fakePath: string): string[] {
|
||||
return process.versions.bun ? [fakePath] : ["tsx", fakePath];
|
||||
}
|
||||
|
||||
async function createRunWithCommand(client: ManagerClient, workspace: string, codexHome: string, prompt: string, idempotencyKey: string, timeoutMs: number): Promise<{ runId: string; commandId: string }> {
|
||||
const run = await client.post("/api/v1/runs", {
|
||||
tenantId: "unidesk",
|
||||
projectId: "pikasTech/unidesk",
|
||||
workspaceRef: { kind: "host-path", path: workspace },
|
||||
providerId: "G14",
|
||||
backendProfile: "codex",
|
||||
executionPolicy: {
|
||||
sandbox: "workspace-write",
|
||||
approval: "never",
|
||||
timeoutMs,
|
||||
network: "default",
|
||||
secretScope: { allowCredentialEcho: false, providerCredentials: [{ profile: "codex", secretRef: { name: "agentrun-v01-provider-codex", keys: ["auth.json", "config.toml"], mountPath: codexHome } }] },
|
||||
},
|
||||
traceSink: null,
|
||||
}) as { id: string };
|
||||
const command = await client.post(`/api/v1/runs/${run.id}/commands`, { type: "turn", payload: { prompt }, idempotencyKey }) as { id: string };
|
||||
const duplicate = await client.post(`/api/v1/runs/${run.id}/commands`, { type: "turn", payload: { prompt }, idempotencyKey }) as { id: string };
|
||||
assert.equal(duplicate.id, command.id);
|
||||
return { runId: run.id, commandId: command.id };
|
||||
}
|
||||
|
||||
async function runFailureCase(options: { client: ManagerClient; managerUrl: string; workspace: string; codexHome: string; fakeCommand: string; fakeArgs: string[]; mode: string; expectedStatus: TerminalStatus; expectedFailureKind: FailureKind; timeoutMs?: number }): Promise<void> {
|
||||
const item = await createRunWithCommand(options.client, options.workspace, options.codexHome, `failure ${options.mode}`, `selftest-${options.mode}`, options.timeoutMs ?? 3_000);
|
||||
const result = await runOnce({
|
||||
managerUrl: options.managerUrl,
|
||||
runId: item.runId,
|
||||
codexCommand: options.fakeCommand,
|
||||
codexArgs: options.fakeArgs,
|
||||
codexHome: options.codexHome,
|
||||
env: { CODEX_HOME: options.codexHome, AGENTRUN_FAKE_CODEX_MODE: options.mode },
|
||||
}) as JsonRecord;
|
||||
assert.equal(result.terminalStatus, options.expectedStatus, options.mode);
|
||||
assert.equal(result.failureKind, options.expectedFailureKind, options.mode);
|
||||
const events = await options.client.get(`/api/v1/runs/${item.runId}/events?afterSeq=0&limit=100`) as { items?: Array<{ type: string; payload: unknown }> };
|
||||
assert.ok(events.items?.some((event) => event.type === "error"), options.mode);
|
||||
assertNoSecretLeak(events);
|
||||
}
|
||||
|
||||
async function runSpawnFailureCase(options: { client: ManagerClient; managerUrl: string; workspace: string; codexHome: string }): Promise<void> {
|
||||
const item = await createRunWithCommand(options.client, options.workspace, options.codexHome, "failure spawn", "selftest-spawn-failure", 3_000);
|
||||
const result = await runOnce({
|
||||
managerUrl: options.managerUrl,
|
||||
runId: item.runId,
|
||||
codexCommand: path.join(os.tmpdir(), `agentrun-missing-codex-${process.pid}`),
|
||||
codexArgs: [],
|
||||
codexHome: options.codexHome,
|
||||
env: { CODEX_HOME: options.codexHome },
|
||||
}) as JsonRecord;
|
||||
assert.equal(result.terminalStatus, "failed", "spawn failure");
|
||||
assert.equal(result.failureKind, "backend-spawn-failed", "spawn failure");
|
||||
const events = await options.client.get(`/api/v1/runs/${item.runId}/events?afterSeq=0&limit=100`) as { items?: Array<{ type: string; payload: unknown }> };
|
||||
assert.ok(events.items?.some((event) => event.type === "error"), "spawn failure");
|
||||
assertNoSecretLeak(events);
|
||||
}
|
||||
|
||||
function assertNoSecretLeak(value: unknown): void {
|
||||
const text = JSON.stringify(value);
|
||||
assert.equal(text.includes("test-token-material"), false);
|
||||
assert.equal(text.includes("Bearer test-token"), false);
|
||||
await context.cleanup();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user