Files
PaperClipAI/tests/runner-e2e/antigravity-journey-browser.smoke.ts
T
DottaandPaperclip ebed7f5237 test(evals): protect Antigravity setup and two-turn delivery (#18190)
## Thinking Path

> - Paperclip manages agents and their work.
> - A provider integration must work through ordinary agent setup and
task controls.
> - The recorded Antigravity walkthrough exposed setup, delivery, and
continuation failures.
> - A repeatable check must verify real work and retain failed attempts.
> - This pull request converts all 47 recorded steps into one fixed
Product E2E journey.
> - Maintainers can rerun the case and inspect independent delivery,
cleanup, and accounting evidence.

## Linked Issues or Issue Description

Builds on merged #18187, #18188, and #18189, and consumes the shared
repairs from merged #18230 and the equivalent manual-policy declaration
from #18222. Refs #18214 for the CI task wrapper. Refs #12503 and #14938
for related legacy adapter work.

**Agent or provider**

Google Antigravity native Runner with a saved managed Google
subscription and the exact Low model.

**Why this adapter is useful**

A user must be able to add an agent, connect its account, and receive
real task results across a follow-up. Picker visibility alone is
insufficient.

**How the agent is invoked**

A fixed Playwright driver uses ordinary product controls. The agent runs
through native ACP. Independent checks use public APIs, actual
downloads, owned process observations, and native lifetime fences.

## What Changed

- Register one explicit-only case:
`antigravity-agent-journey.runner-antigravity.local.saved-subscription-two-turn`.
- Map all 47 source steps and declare saved-account prerequisites,
finite limits, and same-host macOS ARM64 scope.
- Create an agent through the ordinary picker, connect the saved
account, select Low, run Test, and wait for readiness. Save an
instruction marker, deliver a file, and update it through an ordinary
follow-up.
- Require each run's visible completed file activity, exact downloaded
bytes, committed Done result, same tagged conversation, distinct
physical owner birth, released lease, and free native fences. Verify
reload persistence.
- Stop failed native runs that still own a retry. Replay an existing
Stop with its durable request identity and wait for the matching audited
acknowledgement. A terminal reservation without a native intent remains
unconfirmed.
- Keep private evidence in the existing result, report, dashboard, and
accounting pipeline. Retain the paused QA agent and financial history
while preserving the shared account and budget policies.
- Journal only the ordinary wizard's future ID, target, name, intended
harness and expected creator before forwarding its POST unchanged. Bind
the response and interrupted recovery to exact identity reads; a pending
404 stays unconfirmed.
- Serialize private resource snapshots through temporary-file fsync,
atomic rename and directory fsync. Abort forwarding on storage failure
and preserve legacy receipts. If later journal or diagnostic writes
fail, retain the primary error, always close the browser, and attempt
the ordinary failed report.
- Add production-component browser controls and harden task-menu
readiness, alias selection, scroll restoration, failure packaging, and
one hermetic auth-test budget.
- Wait for the existing GitHub recovery fixture to register its next
deadline before asserting the original range; preserve its
nested-transaction and zero-request checks. In the decision-expiry
fixture, verify the exact saved expiry separately from the earlier
global wake of another queue.

## Verification

- Fresh registered acceptance passed on eval source
`9060f3cd01b7c3445ecdf703d72e9cf30fe42b59` and merged serving product
`61bd4ac6919c2309f766a25e62273b074cee3261`. It completed ordinary setup
and two turns with native `.5` and `gemini-3.8-flash-low`. All 16
matchers, 14 checkpoints, and cleanup passed in **165,613 ms**. Actual
downloads were **61 bytes** and **119 bytes**. Both turns passed their
own run-bound browser activity checks and reload persistence.
- Independent read-back confirms Done, a paused retained agent, the same
connected saved default account, and no active owned run. Both accepted
results have the same full tagged conversation and distinct primary
process births. All 21 observed processes retired; both leases released
and all three native fences were free after each turn. The selected `.5`
checkpoints also showed equal agent/backend session IDs; this is an
observed case requirement, not a generic ACP invariant.
- Receipts report 339,273 input tokens, 7,224 output tokens, and 202,846
cached input tokens. Subscription prices are unavailable. Billing
coverage remains incomplete, not free.
- The normal report CLI passed. All 310 files from nine original
attempts and two separate recoveries retained their hashes. The twelve
current screenshots are byte-identical, and 194 local report links are
contained and valid. The eight earlier reports were copied without
regeneration.
- Delivery source `1bf4fb04df04710b82844b3c9355767f46b5f68f` branches
from `d3f2a60e795fc60d64c8b19d1eed4d48657d5492` and merges cleanly with
current master `1d571de5f9f886d66e520800baec8fc2f67d0948`. All 41 prior
`c8b332` authored file blobs remain identical; the 42nd path is the
decision-expiry fixture contract correction. Creation ownership, the
strict durable writer, and the ordinary successful workflow remain
unchanged. Of 43 measured file blobs, 30 remain identical. The
Antigravity oracle, artifact, billing and report gates and its
suite-specific validation block remain unchanged. The actual retained
agent matches its original creator; its original request `setupId` was
not captured and is not reconstructed.
- Later master changes include model-visible workspace guidance and
rejected-terminal-report handling. Their bounded source assessment is
separate: the first actual finish failed, then a same-turn replacement
was accepted and committed. Later read-only results match both original
native-result hashes, and the complete event catalogs have no
`session.failed` event. Master #18228 also expands detection of explicit
JSON file requests. The measured create/update-and-attach `.txt` task
already required publication under both parsers; the publication
validation gate itself is unchanged. Master #18240 changes remote
workspace cache staging and adds an OpenCode index refresh. The selected
local lane returns before those paths. Master #18213 adds optional
numeric turn timing and trace boundaries. Its selected Antigravity
model, text, IDs, result and retirement semantics remain unchanged in
the bounded source review. Local diagnostic rows and awaits can change
event ordinals and latency; the oracle checks relative semantic order.
Collector coverage and latency improvement remain outside this proof.
This does not claim that the whole current runtime is byte-identical to
serving `61bd`, or relabel the measured result as a new run.
- The adopted upstream cache controls passed 3/3 with pinned real Turbo.
Forced work disables local and remote reads and writes; ordinary work
reuses local results. The original genuine-pnpm/Turbo controls remain
historical to `9060`'s earlier write-only policy. The duplicate cache
patch is superseded by #18230. Its qualification-only pnpm addition is
removed because the adopted upstream controls do not require it.
- The E2E typecheck, map checks and 277-control replay are carried from
the unchanged eval source paths. That replay passed, including the 183
Antigravity controls, catalog/connection checks and the separate
product-journey validator. The carried creation controls include 91
config/recovery cases. The final launcher suite passed 19/19, including
five real campaign finalization fault cases; the report suite passed
7/7. These final checks did not rerun the earlier 277-control group. The
canonical production-component browser spec passed in 27.4 s under its
unchanged 60 s limit before the replay. Four paused-composer cases and
the product base's build/typecheck plus 376 focused regressions were
verified earlier.
- The shipped wizard and actual API client cover persistence before
forwarding, lost response JSON, foreign/malformed requests, wrong
response identity/creator and cleanup-error preservation. Real
filesystem controls failed 5/5 before the writer repair and passed 5/5
afterward, preserving the old journal on partial-write, temporary-file
sync and rename faults. Three persistent-sync campaign controls failed
before the finalization repair and passed afterward. All five final
campaign fault cases preserve the primary failure, cleanup failure,
usage and failed report while attempting browser closure. The strict
journal still blocks the next mutation. These are provider-free
ownership controls; the Google task proof remains the original `9060` →
`61bd` acceptance.
- The decision restart check passed in the local 20-case fixture run. A
current-source real-PostgreSQL rollback control reproduced the exact
90,000 ms earlier global wake: the old equality rejected it, while the
exact durable expiry and new future-wake bound passed. The original 60 s
open-state, exact-timestamp, continuation and quiet checks remain. The
broader local run was **FAILED: 19 passed / 1 failed**, with a 15 s
timeout and a 30 s cleanup timeout in an unchanged timestamp-pagination
case. That case passed in canonical `c8b332` CI; the local timeout cause
remains inconclusive. An extra local server typecheck failed against
stale cached Runner declarations; it did not check this excluded test
file. Both limits remain recorded for fresh canonical CI.
- A broader local GitHub recovery group passed 21/22. Its unchanged
pagination case observed an unexpected config request; the log does not
establish the cause. That result remains retained, and fresh
current-head CI is the final broader gate.

- Exact delivery-head CI completed with 55 successes, two skips, and one
optional neutral review. Required `ci / verify` and `ci / e2e`, build,
typecheck, and Runner checks passed. Fresh Greptile is 5/5 with zero
unresolved threads. Optional Paperclip is neutral 4/5; its carried
recommendations are dispositioned against the public Stop contract and
selected live identity evidence.

Seven earlier converted attempts retain their failed grades and partial
evidence. Historical Paid8 and its later read-only per-run UI
observation remain separate from the fresh acceptance above. Unknown
prices and the older partial startup accounting remain explicit. Full
lineage and raw evidence remain private in the normal report bundle.

## Risks

- This case requires an authorized saved personal default Google
subscription and finite operator candidate admission. It does not test
fresh OAuth or establish global qualification.
- The physical observer supports a same-host loopback macOS ARM64
target. Cloud, Linux, and other models remain outside this case.
- A known-cost stop cannot cap missing prices or in-flight subscription
charges. Existing operator policies remain unchanged.
- Raw account/native identities stay private. Missing retirement proof
keeps resources retained. The selected cleanup mode does not test agent
purge.

## Model Used

OpenAI Codex (GPT-6). The host did not expose the exact model revision
or context limit. The model used tools for code edits, tests, browser
automation, and review.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-29 19:51:32 -05:00

391 lines
38 KiB
TypeScript

/** Credential-free calibration of the measured selectors in a real browser.
* Synthetic loopback HTML is deliberately not live Antigravity qualification. */
import { createServer } from "node:http";
import { captureAntigravityAgentDraft } from "./antigravity-journey-flow.js";
import { ANTIGRAVITY_JOURNEY_EXECUTION } from "./antigravity-journey-cases.js";
import type { AntigravityJourneyResources } from "./antigravity-journey-fixtures.js";
import { chromium, type Page } from "@playwright/test";
import assert from "node:assert/strict";
import { build } from "esbuild";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { assertAntigravityCleanComposer, assertAntigravityFileActivity, assertAntigravityReady, assertAntigravityTaskDone, inspectAntigravityArtifact, openAntigravityAgentFromRoster, openAntigravityCreatedTask, selectAntigravityFromOrdinaryPicker } from "./antigravity-journey-ui.js";
const agent = "Antigravity QA synthetic", model = "gemini-3.8-flash-low";
const artifactId = "11111111-1111-4111-8111-111111111111", followupId = "22222222-2222-4222-8222-222222222222";
const artifactBytes = Buffer.from("A".repeat(60) + "\n");
const followupBytes = Buffer.concat([artifactBytes, Buffer.from("B".repeat(57) + "\n")]);
const fixtures: Record<string, string> = {
"task-uuid": `<aside><a href="/ANT/issues/synthetic-issue-id">Created task</a><a hidden href="/ANT/issues/ANT-42">Hidden duplicate</a><a href="/ANT/issues/other-id">Other task</a></aside>`,
"task-identifier": `<aside><a href="/ANT/issues/ANT-42">Created task</a><a href="/ANT/issues/ANT-41">Other task</a></aside>`,
"task-duplicate": `<aside><a href="/ANT/issues/ANT-41">Other task first</a><a href="/ANT/issues/synthetic-issue-id">Created task</a><a href="/ANT/issues/ANT-42">Same task identifier</a></aside>`,
"task-repeated": `<aside><a href="/ANT/issues/ANT-41">Other task first</a><a href="/ANT/issues/ANT-42">Recent task</a><a href="/ANT/issues/ANT-42">Project recent task</a></aside>`,
"task-other-only": `<aside><a href="/ANT/issues/ANT-41">Other task</a></aside>`,
"task-hidden": `<aside><a hidden href="/ANT/issues/ANT-42">Created task</a><a href="/ANT/issues/ANT-41">Other task</a></aside>`,
"ANT/issues/synthetic-issue-id": `<main>Created task UUID</main>`,
"ANT/issues/ANT-42": `<main>Created task identifier</main>`,
dashboard: `<aside><a href="/roster">Agents</a><a href="/wrong-agent">An older agent</a></aside><nav aria-label="breadcrumb"><a href="/roster">Agents</a></nav><main>Ready confirmation after closing composer</main>`,
roster: `<aside><a href="/roster">Agents</a><a href="/wrong-agent">${agent}</a></aside><main><div role="toolbar" aria-label="Agents controls"><input aria-label="Search agents"></div><a href="/wrong-agent"><span>${agent} older</span>Engineer idle</a><a href="/owned-agent"><span>${agent}</span>Engineer idle</a><a hidden href="/wrong-agent"><span>${agent}</span>Engineer idle</a></main>`,
"owned-agent": `<main><h1>${agent}</h1></main>`,
picker: `<div role="dialog" aria-labelledby="picker"><h2 id="picker">Choose an adapter</h2><label><input type="radio" name="adapter">Google Antigravity Candidate</label><details><summary>Advanced</summary><label><input type="radio" name="adapter">Other harness</label></details><button>Configure agent</button></div><div hidden><label><input type="radio">Google Antigravity Candidate</label></div>`,
"advanced-only": `<div role="dialog" aria-labelledby="picker"><h2 id="picker">Choose an adapter</h2><details open><summary>Advanced</summary><label><input type="radio">Google Antigravity Candidate</label></details><button>Configure agent</button></div>`,
ready: `<div hidden><h2>Finishing agent setup</h2><button disabled>Assign ${agent} a Task</button></div><h2>Your agent is ready</h2><button>Assign ${agent} a Task</button>`,
"narrative-ready": `<p>The assistant says Your agent is ready.</p><h2>Finishing agent setup</h2><button disabled>Assign ${agent} a Task</button>`,
done: `<div hidden data-testid="issue-detail-header"><button aria-label="Change status (current: Todo)">Todo</button></div><div data-testid="issue-detail-header"><button aria-label="Change status (current: Done)"><svg><title>Done</title></svg></button></div><div role="menu" hidden>Done</div><p>Earlier task: Todo</p>`,
"done-scrolled": `<nav aria-label="breadcrumb"><span aria-current="page"><svg role="img" aria-label="Done"><title>Done</title></svg>Current task</span></nav><div id="thread" style="height:200px;overflow:auto"><div data-testid="issue-detail-header" style="height:1000px"><button aria-label="Change status (current: Done)">Done</button></div><div style="height:1000px">Restored latest messages and open file viewer</div></div><script>document.getElementById('thread').scrollTop=2000</script>`,
"wrong-current-breadcrumb": `<nav aria-label="breadcrumb"><a><svg role="img" aria-label="Done"><title>Done</title></svg>Older task</a><span aria-current="page"><svg role="img" aria-label="Todo"><title>Todo</title></svg>Current task</span></nav><div data-testid="issue-detail-header"><button aria-label="Change status (current: Done)">Done</button></div>`,
"hidden-breadcrumb-done": `<nav aria-label="breadcrumb"><span aria-current="page"><svg style="display:none" role="img" aria-label="Done"><title>Done</title></svg><svg role="img" aria-label="Todo"><title>Todo</title></svg>Current task</span></nav><div data-testid="issue-detail-header"><button aria-label="Change status (current: Done)">Done</button></div>`,
"narrative-done": `<div data-testid="issue-detail-header"><button aria-label="Change status (current: Todo)"><svg><title>Done</title></svg></button></div><div hidden><button aria-label="Change status (current: Done)">Done</button></div><p>The task is Done</p>`,
composer: `<div role="dialog" aria-labelledby="composer"><h2 id="composer">New task</h2><button aria-label="Select assignee">${agent}</button><button aria-label="Select model and effort"><span data-testid="task-chat-composer-model-label">${model}</span></button><div hidden data-testid="new-issue-paused-assignee-note">paused</div></div><div data-testid="new-issue-paused-assignee-note">unrelated paused agent</div>`,
"paused-composer": `<div role="dialog" aria-labelledby="composer"><h2 id="composer">New task</h2><button aria-label="Select assignee">${agent}</button><button aria-label="Select model and effort"><span data-testid="task-chat-composer-model-label">${model}</span></button><div data-testid="new-issue-paused-assignee-note">paused</div></div>`,
"wrong-model": `<div role="dialog" aria-labelledby="composer"><h2 id="composer">New task</h2><button aria-label="Select assignee">${agent}</button><button aria-label="Select model and effort"><span data-testid="task-chat-composer-model-label">gemini-3.8-flash-high</span></button><p>${model}</p></div>`,
};
export async function runAntigravityBrowserCalibration(page: Page) {
// The activity calibration bundles the shipped adapter and React renderer.
// No hand-authored activity markup can accidentally validate invented copy.
const activityBundle = await build({ stdin: { loader: "tsx", resolveDir: path.resolve(import.meta.dirname, "../../ui"), contents: `
import React from 'react';
import { createRoot } from 'react-dom/client';
import { TaskChatRunnerActivityGroup } from './src/components/task-chat/TaskChatRunnerActivityGroup';
import { buildTurnTimelineRows, transcriptToTaskChatItems } from './src/components/task-chat/transcript-adapter';
const route = new URL(location.href).pathname.slice(1);
const legacy = route.startsWith('legacy-'), scenario = route.replace(/^legacy-/, '');
const target = scenario === 'wrong-target-activity' ? 'backup/antigravity-proof.txt' : 'antigravity-proof.txt';
const event = (operation, status, executionId, name = 'client_' + operation + '_file') => ({
kind: 'provider_activity', ts: '2026-10-29T00:00:00Z', family: 'tool_execution',
eventType: status === 'running' ? 'tool.execution.started' : 'tool.execution.completed', status,
title: 'Tool execution', summary: 'Native file operation',
payload: { name, operation, target, status, executionId, transport: 'builtin' },
});
const entries = [event('edit', 'completed', 'edit'), event('read', 'completed', 'read'),
event('execute', 'failed', 'finish', 'paperclip_paperclip_finish')];
if (scenario === 'failed-read-activity') entries.unshift(event('read', 'failed', 'failed-read'));
if (scenario === 'interrupted-edit-activity') entries.unshift(event('edit', 'interrupted', 'interrupted-edit'));
if (scenario === 'running-read-activity') entries.unshift(event('read', 'running', 'running-read'));
if (scenario === 'pending-read-activity') entries.unshift(event('read', 'pending', 'pending-read'));
if (scenario === 'failed-renderer-activity') entries.unshift({ ...event('read', 'completed', 'failed-renderer'), status: 'failed' });
if (scenario === 'interrupted-renderer-activity') entries.unshift({ ...event('edit', 'completed', 'interrupted-renderer'), status: 'interrupted' });
if (scenario === 'write-activity') entries[0] = event('write', 'completed', 'write');
const running = legacy && ['running-read-activity', 'pending-read-activity'].includes(scenario);
const transcriptOf = values => legacy ? values.flatMap(entry => {
const { operation, target, executionId } = entry.payload;
const call = { kind: 'tool_call', ts: entry.ts, toolUseId: executionId,
name: operation === 'read' ? 'Running client_view_file' : operation === 'edit' ? 'exec_command' : operation === 'write' ? 'write' : 'paperclip_paperclip_finish',
input: { operation, target } };
if (['interrupted', 'pending'].includes(entry.status)) return [call];
return [call, { kind: 'tool_result', ts: entry.ts, toolUseId: executionId, isError: entry.status === 'failed',
delta: entry.status === 'running', content: entry.status === 'failed' ? 'Operation rejected' : 'Synthetic actual tool result' }];
}) : values;
const phases = (values, runId, active = false) => buildTurnTimelineRows(
transcriptToTaskChatItems(transcriptOf(values), { runId, agentName: 'Synthetic agent', running: active }), active,
).filter(item => item.kind === 'activity_phase');
const runId = scenario === 'stale-first-only-activity' ? 'synthetic-run-old' : 'synthetic-run';
const current = phases(entries, runId, running);
const older = scenario === 'current-run-mixed-activity'
? phases([event('read', 'failed', 'old-read'), event('edit', 'failed', 'old-edit')], 'synthetic-run-old') : [];
createRoot(document.getElementById('activity-root')).render(<>{[...older, ...current].map(item =>
<TaskChatRunnerActivityGroup key={item.id} item={item} />)}</>);
` }, bundle: true, write: false, format: "iife", platform: "browser", jsx: "automatic", tsconfig: path.resolve(import.meta.dirname, "../../ui/tsconfig.json"),
define: { "process.env.NODE_ENV": '"production"', "import.meta.env": "{}" }, logLevel: "silent" });
// The artifact controls and text viewer are the shipped components. Their
// friendly work-product title deliberately differs from the actual filename.
const artifactBundle = await build({ stdin: { loader: "tsx", resolveDir: path.resolve(import.meta.dirname, "../../ui"), contents: `
import React, { useState } from 'react';
import { createRoot } from 'react-dom/client';
import { RichWorkProductCard } from './src/components/task-chat/RichWorkProductCard';
import { ArtifactRow } from './src/components/artifacts/v1/ArtifactRow';
import { TextAttachmentContext } from './src/context/TextAttachmentContext';
import { TextAttachmentPreview } from './src/components/task-side-panel/TaskAttachmentPanel';
const route = new URL(location.href).pathname.slice(1), currentId = ${JSON.stringify(artifactId)}, secondId = ${JSON.stringify(followupId)};
const wrongId = '33333333-3333-4333-8333-333333333333';
const first = ${JSON.stringify(artifactBytes.toString('utf8'))}, second = ${JSON.stringify(followupBytes.toString('utf8'))};
const bytes = id => id === secondId ? second : first;
const product = (id, size = bytes(id).length) => ({ id: 'product-' + id, companyId: 'synthetic-company', issueId: 'synthetic-issue',
type: 'artifact', provider: 'paperclip', externalId: id, title: 'Prepared proof file', status: 'active', reviewState: 'none',
healthStatus: 'unknown', createdAt: '2026-10-29T00:00:00Z', updatedAt: '2026-10-29T00:00:00Z',
metadata: { attachmentId: id, originalFilename: 'antigravity-proof.txt', contentType: 'text/plain', byteSize: size,
contentPath: '/api/attachments/' + id + '/content', openPath: '/api/attachments/' + id + '/content', downloadPath: '/api/attachments/' + id + '/content?download=1' } });
function ArtifactCalibration() {
const [selected, setSelected] = useState(null);
const open = (id, title) => setSelected({ id: route === 'artifact-wrong-viewer-id' ? wrongId : id, title });
const render = (id, size) => <RichWorkProductCard workProduct={product(id, size)} href={'/api/attachments/' + id + '/content'} variant={route === 'artifact-compact' ? 'compact' : 'card'} />;
const row = <ArtifactRow subject={{ kind: 'file', title: 'Prepared proof file', filename: 'antigravity-proof.txt', sizeLabel: '61 B' }}
onClick={() => open(route === 'artifact-button-wrong-id' ? wrongId : currentId, 'antigravity-proof.txt')} />;
return <main><TextAttachmentContext.Provider value={open}>
{route.startsWith('artifact-button') ? <>{row}{route === 'artifact-button-duplicate' ? row : null}</> :
route === 'artifact-hidden' ? <><div hidden>{render(currentId)}</div>{render(wrongId)}</> :
route === 'artifact-followup' ? <>{render(currentId)}{render(secondId)}</> :
<>{render(currentId, route === 'artifact-wrong-size' ? 119 : 61)}{route === 'artifact-duplicate' ? render(currentId) : null}</>}
{selected ? <div hidden={route === 'artifact-hidden-viewer'}><TextAttachmentPreview title={selected.title}
text={route === 'artifact-wrong-preview' ? 'Wrong file bytes' : bytes(selected.id)} markdown={false}
downloadUrl={'/api/attachments/' + selected.id + '/content?download=1'} /></div> : null}
</TextAttachmentContext.Provider></main>;
}
createRoot(document.getElementById('artifact-root')).render(<ArtifactCalibration />);
` }, bundle: true, write: false, format: "iife", platform: "browser", jsx: "automatic", tsconfig: path.resolve(import.meta.dirname, "../../ui/tsconfig.json"),
loader: { ".svg": "dataurl" }, define: { "process.env.NODE_ENV": '"production"', "import.meta.env": "{}" }, logLevel: "silent" });
// Render the shipped wizard and actual agentsApi: only the selected-company
// context is fixed. All draft creation crosses the real browser POST boundary.
const creationCompanyId = "33333333-3333-4333-8333-333333333333", creatorUserId = "synthetic-user";
const creationName = "Antigravity QA 0123456789ab";
const creationBundle = await build({ stdin: { loader: "tsx", resolveDir: path.resolve(import.meta.dirname, "../../ui"), contents: `
import React from 'react';
import { createRoot } from 'react-dom/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { AgentBasicsDialog } from './src/components/new-agent/AgentBasicsDialog';
const cache = new QueryClient({ defaultOptions: { queries: { retry: false } } });
createRoot(document.getElementById('creation-root')).render(<QueryClientProvider client={cache}>
<AgentBasicsDialog open onClose={() => {}} onContinue={() => {}} />
</QueryClientProvider>);
` }, bundle: true, write: false, format: "iife", platform: "browser", jsx: "automatic", tsconfig: path.resolve(import.meta.dirname, "../../ui/tsconfig.json"),
loader: { ".svg": "dataurl" }, define: { "process.env.NODE_ENV": '"production"', "import.meta.env": "{}" }, logLevel: "silent",
plugins: [{ name: "selected-company-calibration", setup(build) {
build.onResolve({ filter: /CompanyContext$/ }, () => ({ path: "selected-company", namespace: "calibration" }));
build.onLoad({ filter: /.*/, namespace: "calibration" }, () => ({ contents: `export const useCompany = () => ({ selectedCompanyId: '${creationCompanyId}' });`, loader: "js" }));
} }] });
let persistedCreation: Record<string, unknown> | undefined;
let creationMode: "normal" | "lost-response" | "wrong-response-id" | "foreign-response-creator" | "malformed-response" = "normal";
const receivedCreatePaths: string[] = [];
const creationRequests: Array<{ body: Record<string, any>; raw: string; durableBeforeForward: boolean }> = [];
const server = createServer(async (request, response) => {
const name = new URL(request.url ?? "/", "http://localhost").pathname.slice(1);
if (request.method === "POST" && /^api\/companies\/[^/]+\/agents$/u.test(name)) receivedCreatePaths.push(name);
if (name === "creation-client.js") { response.writeHead(200, { "Content-Type": "text/javascript" }).end(creationBundle.outputFiles[0]!.text); return; }
if (name === "creation") { response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }).end('<!doctype html><html><body><div id="creation-root"></div><script src="/creation-client.js"></script></body></html>'); return; }
if (name === "api/instance/settings/experimental") { response.writeHead(200, { "Content-Type": "application/json" }).end(JSON.stringify({ enableNativeRunner: true })); return; }
if (name === "api/adapters") { response.writeHead(200, { "Content-Type": "application/json" }).end(JSON.stringify([{ type: "paperclip_runner", loaded: true, candidateHarnesses: [{ agent: "antigravity", model }] }])); return; }
if (name === `api/companies/${creationCompanyId}/agents`) {
if (request.method === "POST") {
let raw = ""; for await (const chunk of request) raw += chunk;
const body = JSON.parse(raw);
const expected = { setupId: body.setupId, companyId: creationCompanyId, agentName: body.name, provider: "antigravity", creatorUserId, origin: `http://${request.headers.host}` };
creationRequests.push({ body, raw, durableBeforeForward: persistedCreation != null && Object.keys(persistedCreation).length === 6 && Object.entries(expected).every(([key, value]) => persistedCreation![key] === value) });
// Simulate a committed row whose response is lost, without re-sending
// the POST or invoking any agent/provider work.
if (creationMode === "lost-response") {
response.writeHead(201, { "Content-Type": "application/json", "Content-Length": "1000" });
response.flushHeaders(); response.write('{"id":');
setTimeout(() => response.destroy(), 25); return;
}
if (creationMode === "malformed-response") { response.writeHead(201, { "Content-Type": "application/json" }).end("{"); return; }
response.writeHead(201, { "Content-Type": "application/json" }).end(JSON.stringify({ ...body, id: creationMode === "wrong-response-id" ? artifactId : body.setupId,
companyId: creationCompanyId, createdByUserId: creationMode === "foreign-response-creator" ? "another-user" : creatorUserId, lifecycleState: "draft" })); return;
}
response.writeHead(200, { "Content-Type": "application/json" }).end(JSON.stringify([{ id: followupId, companyId: creationCompanyId, role: "ceo", status: "idle" }])); return;
}
if (/^api\/attachments\/[^/]+\/content$/u.test(name)) {
const referer = String(request.headers.referer ?? "");
const bytes = referer.includes("artifact-bad-download") ? Buffer.from("C".repeat(artifactBytes.length)) : name.includes(followupId) ? followupBytes : artifactBytes;
response.writeHead(200, { "Content-Type": "text/plain", "Content-Disposition": 'attachment; filename="antigravity-proof.txt"' }).end(bytes); return;
}
if (name === "artifact-client.js") { response.writeHead(200, { "Content-Type": "text/javascript" }).end(artifactBundle.outputFiles[0]!.text); return; }
if (name.startsWith("artifact")) {
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }).end('<!doctype html><html><body><div id="artifact-root"></div><script src="/artifact-client.js"></script></body></html>'); return;
}
if (name === "activity-client.js") { response.writeHead(200, { "Content-Type": "text/javascript" }).end(activityBundle.outputFiles[0]!.text); return; }
if (name.endsWith("activity")) {
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }).end(`<!doctype html><html><head><style>svg{width:14px;height:14px}button{display:block}</style></head><body><button onclick="document.getElementById('activity-root').hidden=false;this.remove()">More messages</button><div id="activity-root" hidden></div><p>The file work succeeded; unrelated task failed.</p><script src="/activity-client.js"></script></body></html>`); return;
}
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }).end(`<!doctype html><html><body>${fixtures[name] ?? "missing fixture"}</body></html>`);
});
await new Promise<void>(resolve => server.listen(0, "127.0.0.1", resolve));
const origin = `http://127.0.0.1:${(server.address() as { port: number }).port}`;
let removeCreationObserver: (() => void) | undefined;
try {
const visit = async (fixture: string) => page.goto(`${origin}/${fixture}`);
const creationResources = (): AntigravityJourneyResources => ({ version: 1, executionId: ANTIGRAVITY_JOURNEY_EXECUTION, origin, companyId: creationCompanyId,
environmentId: artifactId, connectionId: followupId, agentName: creationName, runIds: [], processes: {}, retained: false, setupProbe: "not_started" });
const beginCreation = async () => {
await visit("creation");
const dialog = page.getByRole("dialog", { name: "Meet your next agent", exact: true });
await dialog.getByRole("textbox", { name: "Agent name", exact: true }).fill(creationName);
return () => dialog.getByRole("button", { name: "Choose adapter", exact: true }).click();
};
const originalPostBodies: string[] = [];
const observeCreation = (request: import("@playwright/test").Request) => {
if (request.method() === "POST" && new URL(request.url()).pathname === `/api/companies/${creationCompanyId}/agents`) originalPostBodies.push(request.postData()!);
};
page.on("request", observeCreation); removeCreationObserver = () => page.off("request", observeCreation);
const owned = creationResources(), submit = await beginCreation();
let writes = 0;
const draft = await captureAntigravityAgentDraft(page, owned, async () => { writes++; persistedCreation = structuredClone((owned as any).agentCreationRequest); }, submit, creatorUserId);
assert.equal(writes, 1, "persist the safe creation identity once before network forwarding");
assert.equal(creationRequests.length, 1);
assert.equal(creationRequests[0]!.durableBeforeForward, true, "creation witness must be durable before the server receives the unchanged POST");
assert.deepEqual((owned as any).agentCreationRequest, { setupId: draft.id, companyId: creationCompanyId, agentName: creationName, provider: "antigravity", creatorUserId, origin });
assert.equal(creationRequests[0]!.raw, originalPostBodies[0], "forward the original UI POST body without mutation");
assert.equal(creationRequests[0]!.body.setupId, draft.id);
assert.equal(creationRequests[0]!.body.metadata.setupAdapterPending, true);
assert.equal(creationRequests[0]!.body.runtimeConfig.heartbeat.enabled, false);
assert.equal(JSON.stringify(persistedCreation).includes("runtimeConfig"), false);
await page.getByRole("dialog", { name: "Choose an adapter", exact: true }).waitFor({ state: "visible" });
await page.locator('input[type="radio"][value="antigravity_runtime"]').waitFor({ state: "attached" });
// A storage barrier proves that request forwarding joins the durable write.
const gateOwned = creationResources(), gateSubmit = await beginCreation(), beforeGate = creationRequests.length;
let releaseWrite!: () => void, enteredWrite!: () => void;
const writeGate = new Promise<void>(resolve => { releaseWrite = resolve; });
const writeEntered = new Promise<void>(resolve => { enteredWrite = resolve; });
const gated = captureAntigravityAgentDraft(page, gateOwned, async () => {
enteredWrite(); await writeGate; persistedCreation = structuredClone((gateOwned as any).agentCreationRequest);
}, gateSubmit, creatorUserId);
try { await writeEntered; assert.equal(creationRequests.length, beforeGate, "do not forward while persistence is blocked"); }
finally { releaseWrite(); }
await gated;
assert.equal(creationRequests.at(-1)!.durableBeforeForward, true);
assert.equal(creationRequests.at(-1)!.raw, originalPostBodies.at(-1));
const storageOwned = creationResources(), storageSubmit = await beginCreation(), beforeStorageFailure = creationRequests.length;
const storageError = new Error("synthetic creation receipt storage unavailable");
await assert.rejects(captureAntigravityAgentDraft(page, storageOwned, async () => { throw storageError; }, storageSubmit, creatorUserId), error => error === storageError);
assert.equal(creationRequests.length, beforeStorageFailure, "failed persistence must abort before any server commit");
for (const mode of ["wrong-response-id", "foreign-response-creator", "malformed-response"] as const) {
creationMode = mode; persistedCreation = undefined;
const wrong = creationResources(), wrongSubmit = await beginCreation();
await assert.rejects(captureAntigravityAgentDraft(page, wrong, async () => { persistedCreation = structuredClone((wrong as any).agentCreationRequest); }, wrongSubmit, creatorUserId));
assert.equal(creationRequests.at(-1)!.durableBeforeForward, true);
assert.equal((wrong as any).agentCreationRequest.setupId, creationRequests.at(-1)!.body.setupId);
assert.equal(wrong.agentId, undefined, "an untrusted response cannot replace the exact request identity");
}
creationMode = "lost-response"; persistedCreation = undefined;
const lost = creationResources(), lostSubmit = await beginCreation(), beforeLost = creationRequests.length;
page.setDefaultTimeout(1500);
try {
await assert.rejects(captureAntigravityAgentDraft(page, lost, async () => { persistedCreation = structuredClone((lost as any).agentCreationRequest); }, lostSubmit, creatorUserId));
assert.equal(creationRequests.length, beforeLost + 1, "a lost response must not replay creation");
assert.equal(creationRequests.at(-1)!.durableBeforeForward, true);
assert.equal((lost as any).agentCreationRequest.setupId, creationRequests.at(-1)!.body.setupId);
assert.equal(lost.agentId, undefined);
} finally { page.setDefaultTimeout(10000); }
creationMode = "normal";
for (const patch of [{ setupId: "not-a-uuid" }, { name: "Existing user agent" }, { setupId: undefined }, { company: artifactId }]) {
const malformed = creationResources(); const before: number = receivedCreatePaths.length;
let malformedWrites = 0;
await assert.rejects(captureAntigravityAgentDraft(page, malformed, async () => { malformedWrites++; }, async () => {
await page.evaluate(({ route, body }) => { void fetch(route, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }).catch(() => {}); },
{ route: `/api/companies/${"company" in patch ? patch.company : creationCompanyId}/agents`, body: { setupId: artifactId, name: creationName, ...patch } });
}, creatorUserId));
assert.equal(malformedWrites, 0); assert.equal(receivedCreatePaths.length, before, "reject an invalid create identity before forwarding");
assert.equal((malformed as any).agentCreationRequest, undefined);
}
// A durable subset must never absorb unrelated fields from an outgoing body.
const privateBodyOwned = creationResources(); let privateWrite: string | undefined;
await captureAntigravityAgentDraft(page, privateBodyOwned, async () => {
persistedCreation = structuredClone((privateBodyOwned as any).agentCreationRequest); privateWrite = JSON.stringify(privateBodyOwned);
}, async () => {
await page.evaluate(({ route, body }) => { void fetch(route, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }).catch(() => {}); },
{ route: `/api/companies/${creationCompanyId}/agents`, body: { setupId: artifactId, name: creationName, runtimeConfig: { env: { SYNTHETIC_PRIVATE_VALUE: "must-never-be-persisted" } } } });
}, creatorUserId);
assert.equal(privateWrite!.includes("must-never-be-persisted"), false);
assert.equal(creationRequests.at(-1)!.body.runtimeConfig.env.SYNTHETIC_PRIVATE_VALUE, "must-never-be-persisted", "the original request still forwards unchanged");
const submitError = new Error("synthetic ordinary submit failure");
await assert.rejects(captureAntigravityAgentDraft(page, creationResources(), async () => {}, async () => { throw submitError; }, creatorUserId), error => error === submitError);
const abortedOwned = creationResources(), abortSubmit = await beginCreation(), beforeAbort = creationRequests.length;
const abortError = new Error("synthetic route abort cleanup failure");
const failingAbortPage = new Proxy(page, { get(target, key) {
if (key === "route") return (url: any, handler: any) => target.route(url, (route, request) => handler(new Proxy(route, { get(owner, operation) {
if (operation === "abort") return async (...args: any[]) => { await owner.abort(...args); throw abortError; };
const value = Reflect.get(owner, operation); return typeof value === "function" ? value.bind(owner) : value;
} }), request));
if (key === "unroute") return (url: any) => target.unroute(url);
const value = Reflect.get(target, key); return typeof value === "function" ? value.bind(target) : value;
} });
await assert.rejects(captureAntigravityAgentDraft(failingAbortPage, abortedOwned, async () => { throw storageError; }, abortSubmit, creatorUserId), error => error === storageError);
assert.equal(creationRequests.length, beforeAbort, "an abort-cleanup error cannot forward an unjournaled create");
const teardownError = new Error("synthetic route teardown failure");
const failingTeardownPage = new Proxy(page, { get(target, key) {
if (key === "unroute") return async () => { throw teardownError; };
const value = Reflect.get(target, key); return typeof value === "function" ? value.bind(target) : value;
} });
try {
await assert.rejects(captureAntigravityAgentDraft(failingTeardownPage, creationResources(), async () => {}, async () => { throw submitError; }, creatorUserId), error => error === submitError);
} finally { await page.unrouteAll({ behavior: "wait" }); }
const teardownOwned = creationResources(), teardownSubmit = await beginCreation();
try {
await assert.rejects(captureAntigravityAgentDraft(failingTeardownPage, teardownOwned, async () => {
persistedCreation = structuredClone((teardownOwned as any).agentCreationRequest);
}, teardownSubmit, creatorUserId), error => error === teardownError);
assert.equal(creationRequests.at(-1)!.durableBeforeForward, true);
assert.equal((teardownOwned as any).agentCreationRequest.setupId, creationRequests.at(-1)!.body.setupId);
} finally { await page.unrouteAll({ behavior: "wait" }); }
// After every error, a new ordinary wizard request still passes exactly one
// interceptor. This also detects a leaked route from the failed attempt.
const afterFailure = creationResources(), afterSubmit = await beginCreation(); let afterWrites = 0;
await captureAntigravityAgentDraft(page, afterFailure, async () => { afterWrites++; persistedCreation = structuredClone((afterFailure as any).agentCreationRequest); }, afterSubmit, creatorUserId);
assert.equal(afterWrites, 1); assert.equal(creationRequests.at(-1)!.durableBeforeForward, true);
removeCreationObserver(); removeCreationObserver = undefined;
await visit("dashboard"); await openAntigravityAgentFromRoster(page, agent, 300);
assert.equal(new URL(page.url()).pathname, "/owned-agent");
for (const fixture of ["artifact", "artifact-compact", "artifact-button-row"]) {
await visit(fixture); try { await inspectAntigravityArtifact(page, artifactId, artifactBytes, 1000); } catch (error) { throw new Error(`${fixture}: ${await page.locator("body").innerText()}`, { cause: error }); }
}
await visit("artifact-followup"); await inspectAntigravityArtifact(page, followupId, followupBytes, 1000);
for (const fixture of ["artifact-hidden", "artifact-duplicate", "artifact-wrong-size", "artifact-wrong-viewer-id", "artifact-wrong-preview", "artifact-hidden-viewer", "artifact-button-wrong-id", "artifact-button-duplicate"]) {
await visit(fixture); await assert.rejects(inspectAntigravityArtifact(page, artifactId, artifactBytes, 300), fixture);
}
await visit("artifact-bad-download");
await assert.rejects(inspectAntigravityArtifact(page, artifactId, artifactBytes, 1000), /browser_download_bytes_mismatch/u);
for (const [fixture, target] of [["task-uuid", "synthetic-issue-id"], ["task-identifier", "ANT-42"], ["task-duplicate", "synthetic-issue-id"], ["task-repeated", "ANT-42"]]) {
await visit(fixture); await openAntigravityCreatedTask(page, { id: "synthetic-issue-id", identifier: "ANT-42" }, 300);
assert.equal(new URL(page.url()).pathname, '/ANT/issues/' + target);
}
for (const fixture of ["task-hidden", "task-other-only"]) {
await visit(fixture); await assert.rejects(openAntigravityCreatedTask(page, { id: "synthetic-issue-id", identifier: "ANT-42" }, 300), fixture);
}
await visit("picker"); await selectAntigravityFromOrdinaryPicker(page, 300);
assert.equal(await page.getByRole("radio", { name: "Google Antigravity Candidate", exact: true }).isChecked(), true);
await visit("advanced-only"); await assert.rejects(selectAntigravityFromOrdinaryPicker(page, 300));
await visit("ready"); await assertAntigravityReady(page, agent, 300);
await visit("narrative-ready"); await assert.rejects(assertAntigravityReady(page, agent, 300));
await visit("done"); await assertAntigravityTaskDone(page, 300);
await visit("done-scrolled");
const restoredScroll = await page.locator("#thread").evaluate(node => node.scrollTop);
assert.ok(restoredScroll > 0, "Done regression must start at a restored nonzero scroll position");
await assertAntigravityTaskDone(page, 300);
assert.equal(await page.locator("#thread").evaluate(node => node.scrollTop), restoredScroll);
for (const fixture of ["narrative-done", "wrong-current-breadcrumb", "hidden-breadcrumb-done"]) {
await visit(fixture); await assert.rejects(assertAntigravityTaskDone(page, 300), fixture);
}
await visit("composer"); await assertAntigravityCleanComposer(page, agent, model, 300);
await visit("paused-composer"); await assert.rejects(assertAntigravityCleanComposer(page, agent, model, 300));
await visit("wrong-model"); await assert.rejects(assertAntigravityCleanComposer(page, agent, model, 300));
for (const fixture of ["stale-first-only-activity", "legacy-stale-first-only-activity"]) {
await visit(fixture); await assert.rejects(assertAntigravityFileActivity(page, "synthetic-run", 1000), fixture);
}
await visit("activity"); await assertAntigravityFileActivity(page, "synthetic-run", 1000);
await visit("write-activity"); await assertAntigravityFileActivity(page, "synthetic-run", 1000);
for (const fixture of ["current-run-mixed-activity", "legacy-current-run-mixed-activity"]) {
await visit(fixture); await assertAntigravityFileActivity(page, "synthetic-run", 1000);
}
for (const fixture of ["failed-read-activity", "interrupted-edit-activity", "running-read-activity", "failed-renderer-activity", "interrupted-renderer-activity", "wrong-target-activity"]) {
await visit(fixture);
let rejected = false;
try { await assertAntigravityFileActivity(page, "synthetic-run", 300); } catch { rejected = true; }
assert.ok(rejected, `${fixture}: ${await page.locator("body").innerText()}`);
}
for (const fixture of ["legacy-activity", "legacy-write-activity"]) {
await visit(fixture); await assertAntigravityFileActivity(page, "synthetic-run", 1000);
assert.equal(await page.locator('[data-activity-family="tool_execution"]').count(), 0);
}
for (const fixture of ["legacy-failed-read-activity", "legacy-interrupted-edit-activity", "legacy-running-read-activity", "legacy-pending-read-activity", "legacy-wrong-target-activity"]) {
await visit(fixture);
let rejected = false;
try { await assertAntigravityFileActivity(page, "synthetic-run", 300); } catch { rejected = true; }
assert.ok(rejected, `${fixture}: ${await page.locator("body").innerText()}`);
}
console.log("PASS Antigravity browser calibration: production AgentBasicsDialog/agentsApi safe creation witness durable before unchanged POST, persistence gate/failure, lost201-body recovery identity, malformed/foreign request and response rejection, no raw-body/env persistence, abort/unroute primary-error preservation; production rich/compact artifact cards and rows, exact attachment viewer/download identity+61/119B, hidden/duplicate/wrong-ID/size/bytes rejection, both task sidebar layouts; More messages plus production transcript adapter/activity renderer for canonical provider activity and native legacy tool calls/results; exact run-bound completed read/edit/write, stale-first-only rejection/current-run mixed-history acceptance, exact target, failed/interrupted/running/pending rejection and unrelated failed finish");
} finally {
removeCreationObserver?.();
await new Promise<void>((resolve, reject) => server.close(error => error ? reject(error) : resolve()));
}
}
// Keep the documented standalone entry while the canonical support spec uses
// Playwright's existing page/browser lifecycle instead of launching a second runner.
if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
const browser = await chromium.launch({ headless: true });
try {
await runAntigravityBrowserCalibration(await browser.newPage());
} finally {
await browser.close();
}
}