Repository navigation
feat(sdk): offline spawn/tool e2e on Node and Bun — M3 close-out (#1111) - #1122
Merged
Merged
Conversation
Exercise the product spawn() against a same-checkout mecated driven by --mock-script fixtures, on both Node and Bun, and close out M3. The suites cover the tool round trip, a throwing handler, read-only and mutating dispatch, a responder-less query denial, the real Go MCP client handshake, the absence of any TCP listener, runtime-directory removal, lifetime-pipe shutdown after an abrupt parent death, retainSession, and a real mecated startup failure. AC10.13 pins a known limitation: the root capability set is minted from the process-wide catalog, so a per-session client MCP tool is absent from it and the default --authority-evaluator local denies the call after the permission ask has been allowed. The remaining fixtures select the no-op evaluator so the suite proves the SDK half rather than re-proving that denial. Fixing it needs RootAuthority to carry the session's client MCP tool names, which is production server work outside this plan. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Samuele Verzi <[email protected]>
Four-axis panel review of sdk/31..sdk/40 against main. The findings below
were raised against earlier scenarios but are fixed here because the stack
merges as a unit and rebasing nine dependent branches to place each fix in
its originating PR would cost more than it buys.
Blocker — a rejected spawn() held the event loop for the whole readiness
window. Promise.race does not cancel its loser, so after a child exited
early the ready-file poll kept real 20ms timers alive: a CLI that caught the
failure sat there for 30 seconds before Node could exit. The scheduler seam
now carries an AbortSignal (as the watch.ts sibling already did) and the
race aborts it in a finally. Measured 5019ms before, 6ms after.
Security — the SDK-owned listener flags were guarded only in their
double-dash spelling, but mecated parses with Go's flag package, where
-flag, --flag and -flag=v are equivalent and the last occurrence wins.
spawn({args:["-http-addr","0.0.0.0:8080"]}) therefore replaced an SDK-owned
value and opened the unauthenticated HTTP surface. The guard now normalises
the spelling before matching.
Security — PATH resolution mapped empty and relative entries onto the
working directory, so a co-located mecated could be launched with the
caller's inherited credentials. Absolute entries only, matching Go's own
removal of that behaviour from os/exec in 1.19.
The e2e tree was outside tsconfig's include, so tsc never saw it. Seven call
sites still passed the `workspace` option that ADR 0291 removed from
CreateSessionOptions; the property was silently dropped at runtime while the
tests read as though they bound a workspace. The tree is now type-checked
and those arguments are gone.
The `.` entrypoint purity guard was a regex denylist naming four specifiers
and missing dynamic imports, so node:crypto and node:net would have passed.
It is now an allowlist over statement-anchored specifiers.
AC10.9 was confounded: its read-only half ran --posture auto, which allows
every tool, so the assertion held regardless of the readOnly flag. Both
halves now run the same default posture and the test asserts what readOnly
actually controls — two calls overlapping in the concurrent read batch —
while recording that readOnlyHint steers dispatch, not permissions.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Samuele Verzi <[email protected]>
The readiness-poll fix left the same leak on the shutdown path. stopProcess races the child's exit against a SIGTERM grace timer, and Promise.race does not cancel its loser, so a child that exits promptly still left a non-unref'd 3s timer holding the event loop. Measured against a real daemon: close() resolved at +6ms while the process could not exit until +3007ms. An SDK-backed CLI paid that tail on every clean shutdown. Both stop bounds now abort their scheduler sleep in a finally, and the regression test is mutation-checked. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Samuele Verzi <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Samuele Verzi <[email protected]>
6 of 13 tasks
kantord
added a commit
that referenced
this pull request
Sep 16, 2026
sdk/typescript/e2e/tool.e2e.test.ts had a test deliberately asserting the OLD (buggy) denial as correct, with a comment explicitly saying "so the eventual RootAuthority widening has a failing test to flip" (introduced in #1111/#1122, M3 close-out). The previous two commits are exactly that widening, so CI's offline SDK e2e caught it: this test still expected the call denied. Updated it to assert the tool is now actually invoked and its real result reaches the model, using the same fixture/assertions as the file's existing happy-path test, still under the real "local" evaluator (not noop) so it keeps exercising the authorization path, not just mount+dispatch. Verified locally against a same-checkout mecated build. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the M3 milestone of the TypeScript SDK (parent #821) with the offline
end-to-end proof that the product surface —
spawn(),query(),client.tool()and the loopback MCP host — works against a same-checkout
mecatedon bothNode and Bun, plus the milestone's documentation close-out.
The suites drive the public API, not M1's hand-rolled daemon harness. That is
the point: everything below Scenario 10 is proven against an injected
Transport,so this is the first place the SDK's own launcher, ready-file barrier, lifetime
descriptor, disposal order and hand-written MCP subset meet the real Go
implementation.
sdk/typescript/e2e/spawn.e2e.test.tsande2e/tool.e2e.test.ts, driven by--mock-scriptfixtures undere2e/fixtures/.e2e/fixtures/runtime-helper.mjsimports the builtpackage, so Bun exercises the published ESM shape rather than Vitest's transform.
landed,docs/architecture.mdanddocs/design/IMPLEMENTATION-NOTES.mdcompleted, and a shortspawn()/tool()section added to
user-docs/.Closes #1111
Related: #821 — do not close; M4 (browser/BFF, examples, platform matrix) remains.
Design: ADR 0292.
Plan:
docs/acceptance/sdk-typescript-local.md(Scenario 10).This is the top of the stack and targets
sdk/39-parity(#1099). No scenariostacks on top of it.
Acceptance criteria
task ac-trace-strict:docs/acceptance/sdk-typescript-local.md [landed] — 104 ACs · 0 failure(s).AC10.12 — CI job composition
The
sdkjob runs the new suites on Node and the Bun leg genuinely runs; it isnot recorded as deferred.
.github/workflows/ci.ymlpinsoven-sh/setup-bun(SHA-pinned,
bun-version: '1.4.1'), andtask sdk:e2epreflightstest -x "$BUN_BIN" || command -v bun || exit 1. There is noskipIfand notry/catchswallow anywhere in the suites, so a missing or broken Bun turns thestep red rather than silently reducing coverage.
The two Bun deferrals the plan carried are now resolved and recorded as such:
Bun inherits the fourth stdio entry, and the lifetime descriptor works without the
mkfifo(1)dance because the server-enabler pre-PR widenedcheckLifetimePipeFDto admit a connected stream socket.
lifetimePipe: falsewas not needed.Known limitation — callback tools are denied under the default authority evaluator
Found while writing these tests, on the real wire:
mintRootAuthority(internal/app/root_authority.go) mints the root capability setfrom the process-wide
assets.rootCatalog, andService.RootAuthorityis afunc(session.SessionKind) session.Authoritythat never sees a session'smcp_serversadditions. A client MCP tool therefore mounts into the per-sessioncatalog but is absent from the capability set, and the default
--authority-evaluator localdenies the call after the permission ask has alreadybeen allowed.
spawn()does not pass the flag, so every default SDK deploymenthits this: M3's callback tools are wire-complete but not usable end-to-end yet.
Fixing it means widening
RootAuthorityto carry the session's client MCP toolnames — production
internal/adapter/server/work, outside this plan's edit surface.Rather than hide it:
--authority-evaluator noop, so the suite proves the SDKhalf (host handshake, dispatch, schema validation, refusals, ask routing) instead
of silently re-proving the denial;
to flip rather than a silent behaviour change;
docs/architecture.md, inIMPLEMENTATION-NOTES.md, and in theuser-docs/callback-tool section so a reader is not led into it.
Panel review
Ran a four-axis panel (Spec / Standards / Test adequacy / Domain: security,
architecture, DevOps, library-reuse, duplication) over the assembled stack
sdk/31..sdk/40vsmain. Spec reported no blockers and verified all 96vitest:proof tokens decode to titles present byte-for-byte. One blocker and several
important findings were fixed here — they belong to earlier scenarios, but the stack
merges as a unit and rebasing nine dependent branches to place each fix in its
originating PR would cost more than it buys. Called out so reviewers of those PRs
know to look here:
spawn()hung Node for the whole readiness window.Promise.racedoes not cancel its loser, so after a child exited early theready-file poll kept real 20 ms timers alive. A CLI that caught the failure sat
there for 30 s before the process could exit. The scheduler seam now carries an
AbortSignal(as thewatch.tssibling already did) and the race aborts it in afinally. Measured 5019 ms before, 6 ms after; regression test mutation-checked(1888 → 5 polls).
stopProcessraces the child's exitagainst a SIGTERM grace timer; a child that exited promptly still left a 3 s
non-unref'd timer armed. Measured against a real daemon:
close()resolved at+6 ms while the process could not exit until +3007 ms — an SDK-backed CLI paid
that tail on every clean shutdown. Both stop bounds now abort their sleep;
mutation-checked.
mecatedparses with Go's
flagpackage, where-flag,--flagand-flag=vareequivalent and the last occurrence wins, so
spawn({ args: ["-http-addr", "0.0.0.0:8080"] })replaced an SDK-owned value andopened the unauthenticated HTTP surface. The guard now normalises the spelling;
tested as a table over all five flags × four spellings.
directory (CWE-426), so a co-located
mecatedcould be launched with the caller'sinherited credentials. Absolute entries only, matching Go's removal of the same
behaviour from
os/execin 1.19.e2e/tree was outsidetsconfigincludeand had already rotted. Sevencall sites still passed the
workspaceoption ADR 0291 removed fromCreateSessionOptions; the property was dropped at runtime while the tests read asthough they bound a workspace. The tree is now type-checked — which matters
precisely because this PR makes the e2e suite a CI gate and triples its size.
.entrypoint purity guard did not guard. It was a regex denylist namingfour specifiers and missing dynamic imports, so
node:crypto/node:netwould havepassed. Now an allowlist over statement-anchored specifiers; verified by planting
import { randomBytes } from "node:crypto"insrc/client.tsand watching it fail.--posture auto, which allowsevery tool, so
expect(asks).toEqual([])held regardless of thereadOnlyflag —it would have passed with
readOnly: false. Both halves now run the same defaultposture and the test asserts what
readOnlyactually controls: two callsoverlapping in the concurrent read batch. Mutation-checked. The AC text was
corrected too —
readOnlyHintsteers dispatch, not permissions.Type of change
close-out, with panel-review fixes to the stack below it
Test plan
Required baseline
task lint)task test)go run ./cmd/mecademo)Conditional checks
task docs) — 317 documents, 3053 references, 0 brokentask site:build)task api:check)engine/changeSDK gates:
task sdk:install sdk:lint sdk:typecheck sdk:test sdk:build sdk:pack sdk:api:check— 33 files, 183 tests.
task sdk:e2e(with Bun 1.4.1) — 9 files, 26 tests.task ac-trace-strict— 0 failures.Manual: reproduced the readiness-poll hang before the fix (process exited after
5019 ms) and confirmed 6 ms after; reproduced the authority denial on the real wire
with the default evaluator.
Does this introduce a user-facing change?
Yes —
user-docs/building/deployment/grpc-http.mddocumentsspawn(),query()andclient.tool()for Node and Bun, including the callback-tool authority limitationabove. The two
src/spawn.tssecurity fixes also tightenspawn(): an SDK-ownedlistener flag is now refused in every spelling, and PATH lookup ignores empty and
relative entries.
Special notes for reviewers
Follow-ups deliberately not taken here, with the panel's reasoning:
RootAuthorityto carry a session's client MCP tool names. The real fixfor the limitation above; needs production
internal/adapter/server/changes.http: trueopens an unauthenticated loopback listener. Any local user canreach it; the SDK never passes
--auth-token. Documented, not yet mitigated —minting a token needs the SDK's own client to send it.
spawnInternaltest seam is hand-faked in six suites and the diagnosticsobserver guard is written four times. Both are real duplication; deferred as a
test-side refactor rather than widening this PR's blast radius.
sessions.fork()silently drops the callback tool set (the server passesnilclient MCP for a successor). Worth a loud refusal.
AbortSignal.prototype.throwIfAborted,events.oncefor thelisten/error race,
for awaitfor the bounded body read, lazy tool-host start forzero-tool clients.