Skip to content

Add an agent session driver and Gadget durability tests - #270

Draft
AshishKumar4 wants to merge 7 commits into
mainfrom
evals/toolkit
Draft

Add an agent session driver and Gadget durability tests#270
AshishKumar4 wants to merge 7 commits into
mainfrom
evals/toolkit

Conversation

@AshishKumar4

@AshishKumar4 AshishKumar4 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Adds a driver for one agent session, and integration tests that pin how a Gadget server behaves when
it restarts.

Everything here is deterministic and needs no model. It runs in pnpm test and finishes in about ten
seconds.

AgentSession

AgentSession drives one session over the same Cap'n Web API that the browser uses. It creates a fresh
account and workspace, keeps one chat across turns, reads the complete paginated history, and can
snapshot the accepted source.

Two methods support a test that needs a known implementation:

  • seedGadget({title, bindingName, files}) writes hand-authored source into the workspace. It creates
    a Gadget without the agent.
  • restartGadgets() restarts every Gadget server. It applies an empty update to the mainline code,
    which is what the platform does on every code change.

startHarness() gains enableGadgetExecution, which keeps the Worker Loader so Gadget code can run.
It defaults to false, so the existing suites do not change.

What the tests pin

__tests__/gadget-durability.test.ts uses a Gadget that holds one value in SQL and one in memory:

  • A restart keeps storage and drops memory.
  • A restart makes every outstanding stub invalid. A test can therefore confirm that a restart occurred.
  • Five consecutive restarts keep every row, and each round runs in a new instance.
  • A restart that interrupts a write leaves the table readable and the committed row intact.
  • A check-then-write implementation oversells a slot under concurrent calls.

The last item pins the behaviour that any "never oversells" assertion depends on.

Scope

This is the first of two changes. The evaluation suite that uses this driver is in
#271.

Comment thread packages/integration-tests/fixtures/seeded-gadgets.ts Outdated
AgentSession drives one agent session over the same Cap'n Web API the
browser uses: a fresh account and workspace, one chat across turns,
complete paginated history, and an optional source snapshot.

Two methods support tests that need a known implementation rather than
whatever an agent produced. seedGadget() writes hand-authored source into
the workspace. restartGadgets() restarts every Gadget server by applying an
empty code update, which is what the platform does on every code change.

gadget-durability.test.ts uses both to pin platform behaviour with no model
involved. Storage survives a restart and memory does not, outstanding stubs
become invalid, and the data holds across five restarts and across one that
interrupts a write. It also shows that a check-then-write implementation
oversells under concurrent calls.

startHarness() gains enableGadgetExecution, which keeps the Worker Loader so
Gadget code can run. It defaults to false, so the existing suites are
unchanged.
A handler receives the URL, the method, and the headers, but never the body,
so it cannot stand in for a host a suite has to reach with a real POST.
passThroughHosts exempts such a host before the request is taken apart.
Every other host still throws.
Every .js file in a Gadget becomes a module in its Worker, so workerd parses
client.js at load even though the server never imports it. A test that checks
a Gadget through its RPC therefore already covers the syntax of both files,
and a separate parse step would add nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants