refactor(pocket-pi): typecheck the pi-full harness against pi's real API - #6
Merged
Merged
Conversation
The session harness read globalThis.PiFull as `any`, so its createAgentSession/ ModelRuntime/SessionManager/session calls weren't validated against pi's actual types — a pi bump that changed those signatures would only blow up in a runtime test. Now entry.ts exports `PiFullApi` (= the real, pi-typed PiFull object) and the harness scripts cast globalThis.PiFull to it, so tsc checks them against pi's API. A signature-changing bump now fails the typecheck at build time. Turning it on immediately paid off — the typecheck flagged: - a dead `event.type === "error"` branch in the driver: pi has no "error" event; errors arrive as an assistant message with stopReason "error" (already handled). Removed it. - test-probe messages that don't match pi's Message shape, and reads of message fields not on the public union — deliberate loose test usages, now explicit casts rather than silent `any`. Runtime behavior unchanged: full suite green (23 + 8 ignored, incl. real gpt-5.6 turn "pocket pi lives"); tsc + clippy clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
The one type-safety investment worth making (from the discussion on #4): the session harness read
globalThis.PiFullasany, so itscreateAgentSession/ModelRuntime/SessionManager/session calls weren't validated against pi's real types. A pi bump that changed those signatures would only surface in a runtime test.Now
entry.tsexportsPiFullApi(the real, pi-typedPiFullobject) and the harness scripts castglobalThis.PiFullto it — sotscchecks the harness against pi's actual API. A signature-changing bump now fails the typecheck at build time.Turning it on immediately paid off. It flagged:
event.type === "error"branch in the driver — pi has no"error"event; errors arrive as an assistant message withstopReason: "error"(already handled). Removed.Messageshape, and reads of fields not on the public message union — deliberate loose test usages, now explicit casts instead of silentany.Scope is exactly the harness (the code with real integration logic); the runtime polyfills stay transpile-only, as discussed. Runtime behavior unchanged — full suite green (incl. real gpt-5.6 turn);
tsc+clippyclean.🤖 Generated with Claude Code