diff --git a/tests/runner-e2e/product-journeys/AGENT-SETTINGS.md b/tests/runner-e2e/product-journeys/AGENT-SETTINGS.md index aa848f1daef..4d10052d3e3 100644 --- a/tests/runner-e2e/product-journeys/AGENT-SETTINGS.md +++ b/tests/runner-e2e/product-journeys/AGENT-SETTINGS.md @@ -60,5 +60,9 @@ The first contains closed IDs, hashes, the synthetic reference, checks, and both matched board-save receipts. Each receipt includes its audit ID, actor, agent entity, entry path, content hash, and save source. It does not contain raw instruction files, account bindings, or provider payloads. +The last task observation retains the created task ID, requested run IDs and +observed run status/native phase before checking for a failed run. It survives +a failed run or detail read without satisfying any result check. Missing run +details remain absent; the diagnostic does not invent a completed run or output. Discovery and local controls do not qualify a staging run. The daily plan may admit this case only after a genuine staging pass and reviewed source merge. diff --git a/tests/runner-e2e/product-journeys/agent-settings-flow.test.ts b/tests/runner-e2e/product-journeys/agent-settings-flow.test.ts index 4569b771fbf..69381c3d3e7 100644 --- a/tests/runner-e2e/product-journeys/agent-settings-flow.test.ts +++ b/tests/runner-e2e/product-journeys/agent-settings-flow.test.ts @@ -5,6 +5,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import type { JourneyContext, JourneyEvidence, TargetSession } from "./types.js"; import { settingsEvidenceFixture } from "./agent-settings-test-fixture.js"; import { settingsTaskPrompt } from "./agent-settings-evidence.js"; +import { ConnectionFailure } from "../connection-config.js"; const controls = vi.hoisted(() => ({ createTask: vi.fn(), openDocument: vi.fn() })); vi.mock("../user-actions.js", () => ({ createTaskThroughUi: controls.createTask })); @@ -113,7 +114,7 @@ async function fixture(nativeFailure = false, unscopedActivity = false, delayedR const session = { async own(resource: any) { owns.push(resource); } } as TargetSession; const evidence: JourneyEvidence = { outcome: "passed", startingState: "recipe", phases: [], checks: [], resourceDisposition: "retained", privacy: "private" }; const directory = await mkdtemp(path.join(os.tmpdir(), "qa-settings-flow-")); directories.push(directory); - return { context, session, evidence, directory, saves, savedPaths, selectedPaths, availablePaths, owns, apiWrites, activityReads, unrelatedActivity, original: f.original, + return { context, session, evidence, directory, api, saves, savedPaths, selectedPaths, availablePaths, owns, apiWrites, activityReads, unrelatedActivity, original: f.original, currentContent: () => content, options: { directory, deadlineAt: Date.now() + 30000 } }; } @@ -146,6 +147,8 @@ describe("agent settings production-surface orchestration", () => { expect(artifact).not.toContain(f.original); expect(artifact).not.toContain("adapterConfig"); expect(artifact).not.toContain("must-not-be-retained"); const saved = JSON.parse(artifact); expect(saved.checks.every((row: any) => row.passed)).toBe(true); + expect(saved.taskObservation).toEqual({ issueId: "task", runIds: ["run"], + runs: [{ id: "run", status: "succeeded", nativePhase: "committed" }] }); expect(saved.checkpoints.original.contentHash).toBe(saved.checkpoints.restored.contentHash); expect(saved.saveAudits).toEqual({ saved: { id: "save", companyId: "company", actorType: "user", actorId: "user", agentId: null, runId: null, action: "agent.files_updated", entityType: "agent", entityId: "agent", path: "AGENTS.md", @@ -174,7 +177,48 @@ describe("agent settings production-surface orchestration", () => { const f = await fixture(true); await expect(runAgentSettings(f.context, f.session, "campaign-1", f.evidence, f.options)).rejects.toThrow("agent_settings_native_run_failed"); expect(f.saves).toHaveLength(1); expect(f.currentContent()).not.toBe(f.original); - expect(JSON.parse(await readFile(path.join(f.directory, "agent-settings-observations.json"), "utf8")).checks.every((row: any) => row.passed)).toBe(false); + const artifact = await readFile(path.join(f.directory, "agent-settings-observations.json"), "utf8"); + const saved = JSON.parse(artifact); + expect(saved.issueId).toBe("task"); + expect(saved.runIds).toEqual(["run"]); + expect(saved.taskObservation).toMatchObject({ issueId: "task", runs: [{ id: "run", status: "failed", nativePhase: "committed" }] }); + expect(saved.documentId).toBeNull(); + expect(saved.checks.every((row: any) => row.passed)).toBe(false); + expect(artifact).not.toContain(f.original); + expect(artifact).not.toContain("runnerProfileJson"); + expect(artifact).not.toContain("resultJson"); expect(f.apiWrites).toEqual([]); }); + it("retains the requested run identity if its detail read fails without claiming a completed task", async () => { + const f = await fixture(); + const get = f.api.get.bind(f.api); + f.api.get = async route => { + if (route === "/api/heartbeat-runs/run") throw new ConnectionFailure("api_status_403"); + return get(route); + }; + await expect(runAgentSettings(f.context, f.session, "campaign-1", f.evidence, f.options)).rejects.toThrow("api_status_403"); + const saved = JSON.parse(await readFile(path.join(f.directory, "agent-settings-observations.json"), "utf8")); + expect(saved.taskObservation).toEqual({ issueId: "task", runIds: ["run"], runs: [] }); + expect(saved.issueId).toBe("task"); expect(saved.runIds).toEqual(["run"]); + expect(saved.documentId).toBeNull(); expect(saved.documentRevisionId).toBeNull(); + expect(saved.checks.filter((row: any) => row.passed).map((row: any) => row.id)) + .toEqual(["agent-settings-browser-save", "agent-settings-reload-persisted"]); + expect(f.saves).toHaveLength(1); expect(f.apiWrites).toEqual([]); + }); + it("keeps failure identity while excluding raw run data from the retained file", async () => { + const f = await fixture(true); + const get = f.api.get.bind(f.api); + f.api.get = async route => { + const value = await get(route); + return route === "/api/heartbeat-runs/run" ? { ...value, error: "private-error-marker", + stdoutExcerpt: "private-output-marker", contextSnapshot: { instructions: "private-instructions-marker" }, + resultJson: { privatePayload: "private-result-marker" } } : value; + }; + await expect(runAgentSettings(f.context, f.session, "campaign-1", f.evidence, f.options)).rejects.toThrow("agent_settings_native_run_failed"); + const artifact = await readFile(path.join(f.directory, "agent-settings-observations.json"), "utf8"); + for (const marker of ["private-error-marker", "private-output-marker", "private-instructions-marker", "private-result-marker"]) + expect(artifact).not.toContain(marker); + expect(JSON.parse(artifact).taskObservation.runs).toEqual([{ id: "run", status: "failed", nativePhase: "committed" }]); + expect(f.saves).toHaveLength(1); expect(f.apiWrites).toEqual([]); + }); }); diff --git a/tests/runner-e2e/product-journeys/agent-settings-flow.ts b/tests/runner-e2e/product-journeys/agent-settings-flow.ts index 5480ebc163c..9334db7359b 100644 --- a/tests/runner-e2e/product-journeys/agent-settings-flow.ts +++ b/tests/runner-e2e/product-journeys/agent-settings-flow.ts @@ -24,6 +24,7 @@ export async function runAgentSettings(context: JourneyContext, session: TargetS agentId: agent.id, agentName: agent.name, provider: agent.provider, model: agent.model, environmentId: context.environmentId, reference: randomBytes(16).toString("hex") }; const observations: AgentSettingsEvidence = {}; + let taskObservation: { issueId: string; runIds: string[]; runs: Array<{ id: string; status: string; nativePhase: string | null }> } | null = null; const read = createObservedReader(context.api, options.deadlineAt), agentRoute = `/api/agents/${agent.id}`; const agentRunsRoute = `/api/companies/${scope.companyId}/heartbeat-runs?agentId=${agent.id}&limit=100`; const activityRoute = `/api/companies/${scope.companyId}/activity?entityType=agent&entityId=${agent.id}&limit=200`; @@ -113,6 +114,7 @@ export async function runAgentSettings(context: JourneyContext, session: TargetS const task = await createTaskThroughUi({ page: context.page, origin: context.api.origin, issuePrefix: context.company.issuePrefix, agentName: agent.name, title, prompt: settingsTaskPrompt, workMode: "standard", requireExplicitTitle: true, beforeDispatch: () => session.own({ kind: "issue", name: title, journeyId: id }) }); + taskObservation = { issueId: task.issueId, runIds: [], runs: [] }; await session.own({ kind: "issue", name: title, id: task.issueId, journeyId: id }); const route = `/api/issues/${task.issueId}`, documentRoute = `${route}/documents/${settingsDocumentKey}`; const state = await waitFor(options.deadlineAt, async () => { @@ -120,7 +122,14 @@ export async function runAgentSettings(context: JourneyContext, session: TargetS read.get(route), read.get(`${route}/runs`), read.get(`${route}/interactions`), ]); if (!Array.isArray(summaries) || summaries.length > 1 || !Array.isArray(interactions)) throw new JourneyError("failed", "agent_settings_run_coverage_mismatch"); - const runs = await Promise.all(summaries.map(row => read.get(`/api/heartbeat-runs/${row.runId}`))); + const point = taskObservation!; + point.runIds = summaries.map(row => row.runId); + point.runs = []; + const runs = await Promise.all(summaries.map(async row => { + const run = await read.get(`/api/heartbeat-runs/${row.runId}`); + point.runs.push({ id: row.runId, status: run.status, nativePhase: run.nativePhase ?? null }); + return run; + })); if (runs.some(run => ["failed", "cancelled", "timed_out"].includes(run.status))) throw new JourneyError("failed", "agent_settings_native_run_failed"); return { issue, runs, interactions }; }, point => point.issue.status === "done" && point.runs.length === 1 && point.runs[0]!.status === "succeeded" @@ -163,7 +172,7 @@ export async function runAgentSettings(context: JourneyContext, session: TargetS independentlyComputedHash: typeof point.file.content === "string" ? instructionDigest(point.file.content) : null, revisionId: point.file.revision?.id ?? null, runIds: point.runs.map(row => row.id ?? row.runId) } : null]; })), - issueId: observations.task?.issue.id ?? null, runIds: observations.task?.runs.map(row => row.id) ?? [], + issueId: taskObservation?.issueId ?? null, runIds: taskObservation?.runIds ?? [], taskObservation, documentId: observations.task?.document.id ?? null, documentRevisionId: observations.task?.revision.id ?? null, saveAudits: { saved: matchedBoardSaveAudit(observations.saved, observations.original, scope), restored: matchedBoardSaveAudit(observations.restored, observations.afterWork, scope) },