Multiplayer agent harness for work.
Delete core tests that read src/ text (#2241)
Regan Bellbe1aeeab9f93
diff --git a/scripts/aws/ecs-blue-green-drill.ts b/scripts/aws/ecs-blue-green-drill.tsindex 5522a7415..c2f5e7e2c 100644--- a/scripts/aws/ecs-blue-green-drill.ts+++ b/scripts/aws/ecs-blue-green-drill.ts@@ -273,7 +273,7 @@ function rollbackActiveDeployment(config: QmConfig, arn: string): void {awsText(config, ["ecs", "stop-service-deployment", "--service-deployment-arn", arn, "--stop-type", "ROLLBACK"]);}-export async function main(argv = process.argv.slice(2)): Promise<void> {+async function main(argv = process.argv.slice(2)): Promise<void> {const args = parseArgs(argv);const { config } = loadConfigAt(args.configPath);const aws = requireAwsConfig(config);diff --git a/scripts/aws/rds-restore-drill.ts b/scripts/aws/rds-restore-drill.tsindex 348cf133d..b726f2e55 100644--- a/scripts/aws/rds-restore-drill.ts+++ b/scripts/aws/rds-restore-drill.ts@@ -244,7 +244,7 @@ function deleteDrill(config: QmConfig, identifier: string): void {awsText(config, ["rds", "wait", "db-instance-deleted", "--db-instance-identifier", identifier]);}-export async function main(argv = process.argv.slice(2)): Promise<void> {+async function main(argv = process.argv.slice(2)): Promise<void> {const args = parseArgs(argv);const { config } = loadConfigAt(args.configPath);assertAwsCaller(config);diff --git a/src/harness/opencode-harness.ts b/src/harness/opencode-harness.tsindex d2d4ab639..ed413999c 100644--- a/src/harness/opencode-harness.ts+++ b/src/harness/opencode-harness.ts@@ -56,7 +56,7 @@ import { countTokens } from "../util/tokens.ts";const OPENCODE_VERSION = "1.18.31";const OPENCODE_IDLE_WAIT_MS = 30 * 60_000;-export const OPENCODE_STARTUP_TIMEOUT_MS = 90_000;+const OPENCODE_STARTUP_TIMEOUT_MS = 90_000;function customProviderNpm(protocol: CustomProviderProtocol): string {const api = customProviderApi(protocol);@@ -137,7 +137,7 @@ type Runtime = {close(): Promise<void>;};-export function bridgeToolName(name: string): string {+function bridgeToolName(name: string): string {if (name === "execute") return "workspace_execute";if (name === "read") return "workspace_read";if (name === "write") return "workspace_write";diff --git a/test/aws-recovery-drills.test.ts b/test/aws-recovery-drills.test.tsindex 8caf7c6a0..1b46b37ed 100644--- a/test/aws-recovery-drills.test.ts+++ b/test/aws-recovery-drills.test.ts@@ -1,6 +1,5 @@import { test } from "node:test";import assert from "node:assert/strict";-import { readFileSync } from "node:fs";import { brokenTaskDefinition } from "../scripts/aws/ecs-blue-green-drill.ts";import { validateDrillIdentifier, verifyScript } from "../scripts/aws/rds-restore-drill.ts";@@ -30,23 +29,6 @@ test("restore verification uses the task secret but replaces only its private hoassert.throws(() => verifyScript("restore; echo compromised"));});-test("temporary restore drills do not create their own automated backup chain", () => {- const source = readFileSync(new URL("../scripts/aws/rds-restore-drill.ts", import.meta.url), "utf8");- assert.match(source, /"--backup-retention-period",\s*"0"/);-});--test("database recovery drills restore the deployment manifest point, not an ad hoc snapshot", () => {- const source = readFileSync(new URL("../scripts/aws/rds-restore-drill.ts", import.meta.url), "utf8");- assert.match(source, /deployment\/current/);- assert.match(source, /dbRestorePoint/);- assert.match(source, /restore-db-instance-to-point-in-time/);- assert.match(source, /--source-db-instance-identifier/);- assert.match(source, /--restore-time/);- assert.match(source, /EarliestRestorableTime/);- assert.match(source, /LatestRestorableTime/);- assert.doesNotMatch(source, /restore-db-instance-from-db-snapshot|--db-snapshot-identifier/);-});-test("blue/green drill preserves the deployed task contract and breaks only core health", () => {const source = {taskDefinitionArn: "arn:task:1",@@ -92,15 +74,3 @@ test("blue/green drill preserves the deployed task contract and breaks only core});assert.deepEqual(containers[1], source.containerDefinitions[1]);});--test("blue/green recovery trusts the native rollback verdict, not the stale legacy deployment list", () => {- const source = readFileSync(new URL("../scripts/aws/ecs-blue-green-drill.ts", import.meta.url), "utf8");- assert.match(source, /await waitForRollback/);- assert.match(source, /await waitForHealthyService/);- assert.match(source, /assertSettledHealthyBlueGreen/);- assert.match(source, /failed task set has not finished draining/);- assert.match(source, /baseline is not fully settled/);- assert.match(source, /no successful circuit-breaker-enabled rollback candidate/);- assert.match(source, /restoring the original task definition/);- assert.doesNotMatch(source, /"wait", "services-stable"/);-});diff --git a/test/codex-harness.test.ts b/test/codex-harness.test.tsindex ad7986da2..b8bb07f6a 100644--- a/test/codex-harness.test.ts+++ b/test/codex-harness.test.ts@@ -2060,7 +2060,11 @@ test("Codex steers extracted documents into the active turn without copying cont}assert.equal(entries.filter((entry) => entry.type === "user").length, 1, "turn/steer acceptance is not intake");await running;- assert.equal(entries.filter((entry) => entry.type === "user").length, 2);+ const intake = entries.filter((entry) => entry.type === "user");+ assert.deepEqual(+ intake.map((entry) => (entry.payload as { steered?: boolean }).steered),+ [undefined, true],+ );assert.equal((await signals.pending("steer-document-run")).length, 0);assert.match(readFileSync(capture, "utf8"), /STEER-PRIVATE-492/);assert.doesNotMatch(JSON.stringify(tape), /STEER-PRIVATE-492/);diff --git a/test/migration-policy.test.ts b/test/migration-policy.test.tsindex 459fa622a..08430f20a 100644--- a/test/migration-policy.test.ts+++ b/test/migration-policy.test.ts@@ -1,25 +1,9 @@import assert from "node:assert/strict";-import { readFileSync } from "node:fs";import test from "node:test";import { createPostgresDirectoryStore } from "../src/directory/postgres-directory-store.ts";import { createPostgresRunStore } from "../src/runs/postgres-run-store.ts";import { createPostgresSessionStore } from "../src/sessions/postgres-session-store.ts";-const core = readFileSync(new URL("../src/index.ts", import.meta.url), "utf8");-const worker = readFileSync(new URL("../src/runs/worker-main.ts", import.meta.url), "utf8");--test("core applies every registered migration before listening", () => {- const migrate = core.indexOf("await migrateRegisteredPgSchemas");- const listen = core.indexOf("server.listen");- assert.ok(migrate > -1 && listen > migrate);-});--test("workers apply every registered migration before claiming runs", () => {- const migrate = worker.indexOf("await migrateRegisteredPgSchemas");- const start = worker.indexOf("runtime.start");- assert.ok(migrate > -1 && start > migrate);-});-test("released session migrations still match their pinned source checksums", () => {assert.doesNotThrow(() => createPostgresSessionStore("postgres://migration-pin.invalid"));});diff --git a/test/opencode-harness.test.ts b/test/opencode-harness.test.tsindex 09b6f1a73..48823641e 100644--- a/test/opencode-harness.test.ts+++ b/test/opencode-harness.test.ts@@ -577,7 +577,11 @@ test("OpenCode includes steered PDF and extracted documents without copying echoassert.equal(entries.filter((entry) => entry.type === "user").length, 1, "queued input is not model intake");writeFileSync(capturePath + ".release", "continue");await running;- assert.equal(entries.filter((entry) => entry.type === "user").length, 2);+ const intake = entries.filter((entry) => entry.type === "user");+ assert.deepEqual(+ intake.map((entry) => (entry.payload as { steered?: boolean }).steered),+ [undefined, true],+ );assert.equal((await signals.pending(turn.runId)).length, 0);const sent = readFileSync(capturePath, "utf8");assert.ok(sent.includes(pdf));diff --git a/test/opencode-plugin-history.test.ts b/test/opencode-plugin-history.test.tsnew file mode 100644index 000000000..c9a8cbae2--- /dev/null+++ b/test/opencode-plugin-history.test.ts@@ -0,0 +1,19 @@+import { test } from "node:test";+import assert from "node:assert/strict";+import { needsHistoryImport } from "../src/harness/opencode-plugin.ts";++test("OpenCode plugin imports empty history only on the first model step", () => {+ const user = { info: { id: "user", role: "user", sessionID: "session" }, parts: [] };+ const assistant = { info: { id: "assistant", role: "assistant", sessionID: "session" }, parts: [] };+ assert.equal(needsHistoryImport([user], []), true);+ assert.equal(needsHistoryImport([user, assistant], []), false);+});++test("OpenCode plugin recognizes imported non-empty history", () => {+ const user = { info: { id: "user", role: "user", sessionID: "session" }, parts: [] };+ const prior = { info: { id: "prior", role: "assistant", sessionID: "session" }, parts: [] };+ const toolStep = { info: { id: "tool-step", role: "assistant", sessionID: "session" }, parts: [] };+ assert.equal(needsHistoryImport([user], [prior]), true);+ assert.equal(needsHistoryImport([prior, user], [prior]), false);+ assert.equal(needsHistoryImport([user, toolStep], [prior]), false);+});diff --git a/test/opencode-plugin-source.test.ts b/test/opencode-plugin-source.test.tsdeleted file mode 100644index dadd2d0bd..000000000--- a/test/opencode-plugin-source.test.ts+++ /dev/null@@ -1,73 +0,0 @@-import { test } from "node:test";-import assert from "node:assert/strict";-import { readFileSync } from "node:fs";-import { needsHistoryImport } from "../src/harness/opencode-plugin.ts";--const source = readFileSync(new URL("../src/harness/opencode-plugin.ts", import.meta.url), "utf8");-const harnessSource = readFileSync(new URL("../src/harness/opencode-harness.ts", import.meta.url), "utf8");--test("OpenCode plugin discovers and registers bridged TypeBox tools", () => {- assert.match(source, /requiredEnv\("OPENCODE_BRIDGE_URL"\)/);- assert.match(source, /requiredEnv\("OPENCODE_BRIDGE_SECRET"\)/);- assert.match(source, /HTTP loopback URL/);- assert.match(source, /request<BridgeTool\[\] \| \{ tools: BridgeTool\[\] \}>\("definitions"\)/);- assert.match(source, /args: argumentShape\(tool\.schema, definition\.parameters\)/);- assert.match(source, /schema\.anyOf \?\? schema\.oneOf/);- assert.match(source, /required\.has\(name\) \? value : value\.optional\(\)/);- assert.match(source, /z\.record\(z\.string\(\), jsonSchemaToZod/);-});--test("OpenCode plugin forwards calls and honors bridge termination", () => {- assert.match(source, /request<ToolResponse>\(`session\/\$\{encodeURIComponent\(context\.sessionID\)\}\/tool`, \{/);- assert.match(source, /tool: definition\.name, sessionID: context\.sessionID, callID, args/);- assert.match(source, /if \(result\.terminate\)/);- assert.match(source, /client\.session\.abort\(\{ path: \{ id: context\.sessionID \} \}\)\.catch/);- assert.match(source, /return result\.output/);-});--test("OpenCode plugin replaces core context without dropping the live user message", () => {- assert.match(source, /Object\.assign\(output\.headers, context\.proxyHeaders \?\? \{\}\)/);- assert.match(source, /output\.system\.splice\(0, output\.system\.length, context\.systemPrompt\)/);- assert.match(source, /currentLastUser = output\.messages\.findLast/);- assert.match(- source,- /output\.messages\.splice\(0, output\.messages\.length, \.\.\.\(history \?\? \[\]\), currentLastUser\)/,- );- assert.doesNotMatch(source, /"permission\.ask"/);-});--test("OpenCode plugin imports empty history only on the first model step", () => {- const user = { info: { id: "user", role: "user", sessionID: "session" }, parts: [] };- const assistant = { info: { id: "assistant", role: "assistant", sessionID: "session" }, parts: [] };- assert.equal(needsHistoryImport([user], []), true);- assert.equal(needsHistoryImport([user, assistant], []), false);-});--test("OpenCode plugin recognizes imported non-empty history", () => {- const user = { info: { id: "user", role: "user", sessionID: "session" }, parts: [] };- const prior = { info: { id: "prior", role: "assistant", sessionID: "session" }, parts: [] };- const toolStep = { info: { id: "tool-step", role: "assistant", sessionID: "session" }, parts: [] };- assert.equal(needsHistoryImport([user], [prior]), true);- assert.equal(needsHistoryImport([prior, user], [prior]), false);- assert.equal(needsHistoryImport([user, toolStep], [prior]), false);-});--test("OpenCode prompt disables bridged tools absent from this turn", () => {- assert.match(- harnessSource,- /\.\.\.bridgedTools\(definitionRef, \{ \.\.\.harnessToolOptions\(opts\), surfaceTools: false \}\)/,- );- assert.match(harnessSource, /Object\.fromEntries\(definitions\.map\(\(tool\) => \[tool\.name, false\]\)\)/);- assert.match(harnessSource, /for \(const tool of tools\) enabled\[bridgeToolName\(tool\.name\)\] = true/);-});--test("OpenCode observes cancellation before runtime startup, session creation, and prompt dispatch", () => {- const runPrompt = harnessSource.slice(- harnessSource.indexOf("const runPrompt ="),- harnessSource.indexOf("const single ="),- );- const guards = [...runPrompt.matchAll(/if \(turn\.cancel\?\.aborted\)/g)].map((match) => match.index ?? -1);- const prompt = runPrompt.indexOf("rt.client.session.prompt({");- assert.ok(guards.length >= 3);- assert.ok(guards.every((index) => index < prompt));-});diff --git a/test/prompt-tool-names.test.ts b/test/prompt-tool-names.test.tsdeleted file mode 100644index 6650578ad..000000000--- a/test/prompt-tool-names.test.ts+++ /dev/null@@ -1,31 +0,0 @@-import { test } from "node:test";-import assert from "node:assert/strict";-import { readFileSync } from "node:fs";-import { join } from "node:path";--const PROTOCOLS = join(import.meta.dirname, "..", "src", "resolution", "protocols");-const FRAME_FILES = ["shared-core.md", "mode-conversation.md", "mode-autonomous.md", "mode-fallback.md"];--const toolSource = readFileSync(join(import.meta.dirname, "..", "src", "harness", "agent-tools.ts"), "utf8");--const KNOWN_ACTIONS = new Set(["post", "react", "edit", "delete", "read_thread", "search", "whats_new"]);--function registeredToolNames(): Set<string> {- const names = new Set<string>(KNOWN_ACTIONS);- for (const m of toolSource.matchAll(/name:\s*"([a-z_]+)"/g)) names.add(m[1]!);- names.add("slack");- return names;-}--test("every tool/action the mode frames name in prose is a real registered tool or surface action", () => {- const registered = registeredToolNames();- const offenders: string[] = [];- for (const file of FRAME_FILES) {- const text = readFileSync(join(PROTOCOLS, file), "utf8");- for (const m of text.matchAll(/`([a-z_]+)`\s+(?:tool|action)/g)) {- const name = m[1]!;- if (!registered.has(name)) offenders.push(`${file}: names \`${name}\` as a tool/action, which is not registered`);- }- }- assert.deepEqual(offenders, [], `prompt frames name tools/actions that don't exist:\n${offenders.join("\n")}`);-});diff --git a/test/steer-entry-flag.test.ts b/test/steer-replay.test.tssimilarity index 56%rename from test/steer-entry-flag.test.tsrename to test/steer-replay.test.tsindex 4a906bd81..7a7c4d16d 100644--- a/test/steer-entry-flag.test.ts+++ b/test/steer-replay.test.ts@@ -1,27 +1,9 @@import { test } from "node:test";import assert from "node:assert/strict";-import { readFileSync } from "node:fs";import { turnAtSeq } from "../src/core/turn-resume.ts";import type { SessionEntry } from "../src/types.ts";-const HARNESSES = ["claude-harness.ts", "codex-harness.ts", "opencode-harness.ts", "pi-harness.ts"];--function source(file: string): string {- return readFileSync(new URL(`../src/harness/${file}`, import.meta.url), "utf8");-}--test("every harness still flags the mid-turn message it persists", () => {- assert.match(source("harness-shared.ts"), /steered: true/);- for (const file of HARNESSES) {- assert.match(- source(file),- /recordSteerIntake/,- `${file} no longer stamps steered:true — a requeued run will re-answer a turn this harness steered`,- );- }-});--test("an unflagged mid-turn message is what breaks the replay, which is why the flag matters", () => {+test("a steered mid-turn message does not hide the turn's answer", () => {const ent = (type: SessionEntry["type"], payload: unknown, seq: number): SessionEntry => ({sessionId: "s",seq,