feat(examples): add runnable Node.js SDK examples under examples/sdk/ - #1469
Conversation
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
|
|
P1 — the drift guard does not satisfy the issue requirement for the actual client-api.md snippets. It only parses the Public subpath API manifest and compares imported symbol names, so every example can typecheck while a code snippet in the docs has drifted or no longer compiles. Make the docs snippets import/include these examples, or extract and compile the documented TypeScript snippets in the guard. |
|
Good catch — fixed in 0da436c. Added Running this against the current doc surfaced three real, pre-existing snippet bugs unrelated to the new examples, which I fixed as part of this:
It also surfaced two gaps that look like genuine, pre-existing product/API questions rather than doc typos, so I didn't fix them unilaterally — allowlisted in
Happy to open follow-up issues for both if you'd rather track them separately from this PR. Generated by Claude Code |
|
Review blocker — the new snippet compiler still does not prove the contract required by #1463.
All checks are green, but the drift acceptance guard remains porous, so this is not ready yet. |
|
All three addressed in 0cb6fd0: 1. Stubbing hole ( 2.
3. Raw All gates green: Generated by Claude Code |
|
Re-reviewed exact head |
|
Fixed in 59ea285 — renamed the stray Generated by Claude Code |
|
Re-reviewed exact head 59ea285. The remaining stale reloadRemoteMetro prose reference is corrected to the actual public reloadMetro name. The delta is docs-only, the substantive guard fixes remain intact, and all exact-head checks are green. Ready for human review. |
examples/test-app is a fixture and the repo's only prior examples/ content; the real SDK usage patterns lived only in website/docs/docs/client-api.md with no runnable script anywhere. Adds four standalone, typechecked examples covering the minimum surface from #1463: root client session (create -> open -> snapshot/tap -> close with typed error handling), agent-device/metro (normalizeBaseUrl/resolveRuntimeTransport), agent-device/contracts (centerOfRect on a snapshot node), and agent-device/batch (runBatch for a custom transport). Each imports the published `agent-device/...` subpaths rather than relative src/ paths. examples/sdk/tsconfig.json path-maps those subpaths to src/sdk/ so `pnpm typecheck` (now also run against this tsconfig) checks the examples in CI without a prior build, workspace link, or publish step. Running an example for real still resolves `agent-device` as a self-referencing package after `pnpm build`. src/__tests__/client-api-examples-drift.test.ts guards the examples against drifting from client-api.md's subpath API manifest in both directions, picked up automatically by the existing unit-core vitest project (no new script or workflow needed). examples/README.md indexes the new examples and notes that test-app/ remains a fixture, not an example; it is not renamed or moved. Refs #1463
Fallow flagged the four examples/sdk/*.ts files as unused files (not reachable from any entry point) and three functions as high complexity. - Register the examples as manual entry points in .fallowrc.json, matching how other standalone scripts (scripts/patch-xcuitest-runner-icon.ts, scripts/runner-request-count/run.ts) are already declared. - Reduce complexity in client-session.ts and contracts-result.ts by extracting device-resolution/error-reporting and rect-assertion helpers out of main(). - Reduce complexity in the drift guard's parseSubpathManifest by splitting bullet-matching and backtick-name extraction into their own functions. Verified: pnpm check:fallow --base <PR base sha> now reports no issues, and pnpm check:tooling / pnpm test:unit stay green. Refs #1463
…l manifest Addresses review feedback on #1463's drift guard: the existing guard only parsed the doc's "Public subpath API" bullet manifest and compared imported symbol names, so a fenced ```ts snippet could drift or stop compiling without the guard noticing. Added test/integration/client-api-doc-snippets.test.ts, which extracts every fenced ```ts block from client-api.md and typechecks it against the real agent-device/* sources (reusing examples/sdk/tsconfig.json's existing paths mapping, read via `tsc --showConfig` so there's one source of truth). Free identifiers that continue a `client`/`snapshot` from an earlier snippet are stubbed — typed against the real SDK return type, not `any`, so continuation snippets still get real checking. Lives in the Node integration lane (test/integration/*.test.ts), not vitest's unit-core: it spawns a real tsc Program, well past the unit suite's 2.5s budget. Running this check against the existing doc surfaced real, pre-existing snippet bugs (unrelated to the new examples), fixed here: - "sessions.artifacts": `result.cloudArtifacts` accessed without narrowing the `CloudArtifactsResult | DaemonArtifactsResult` union first. - "Device cloud sessions": `platform`/`device` were passed into the client constructor config, which doesn't accept them; moved to the `apps.open()` call where those fields actually belong. - "Android ADB providers": the inline `exec` handler had no parameter types, so it failed under strict/noImplicitAny; annotated with the real `AndroidAdbExecutorOptions` type. Two further gaps the check surfaced are pre-existing product/API-surface questions out of scope for this PR (not the new examples), so they're allowlisted in KNOWN_DOC_GAPS with comments rather than silently patched: - "Remote Metro helpers" documents prepareRemoteMetro/reloadRemoteMetro/ stopMetroTunnel/resolveRemoteConfigProfile as public, but none of them are exported from agent-device/metro or agent-device/remote-config today. - "Web sessions"/audio probe pass `platform` to `observability.network()`/ `.audio()`, but NetworkOptions/AudioOptions have no `platform` field even though the CLI's network/audio commands accept `--platform`. Refs #1463
…essed gaps Addresses the second round of review feedback on #1463's drift guard: 1. stubFreeNamesAndRecompile auto-stubbed every "Cannot find name" as `any`, so a typo like `cliet.apps.open()` would silently pass on the second compile. It now only stubs identifiers in an explicit allowlist (KNOWN_FREE_NAME_STUB_TYPES) — the real SDK-derived continuations (`client`, `androidClient`, `snapshot`) plus the doc's own invented host-glue names, each typed precisely rather than loosely. Anything else is left as a real compile failure. Added a regression test that feeds a `cliet` typo through the guard and asserts it fails. 2. KNOWN_DOC_GAPS filtered six real compiler errors out of the final assertion while the test claimed every snippet compiles. Investigated both and fixed the actual contracts instead of suppressing them: - `prepareMetroRuntime`/`reloadMetro` (src/metro/client-metro.ts) and `stopMetroTunnel` (src/metro/metro.ts) already existed and matched the doc's described workflow almost exactly (same result shape) but were never re-exported from `agent-device/metro`; same for `resolveRemoteConfigProfile` and `agent-device/remote-config`. Added the four exports and fixed the doc's stale function names (`prepareRemoteMetro`/`reloadRemoteMetro`) and one stale field name (`profileKey` -> `companionProfileKey` on the prepare call) to match. - `NetworkOptions`/`AudioOptions` (src/contracts/client-observability.ts) had no `platform` field even though the CLI's `network`/`audio` commands accept `--platform` for the same use case, and the client methods already forward the options object to the daemon generically (`executeCommand('network'|'audio', options)`) — so this was a type gap, not a runtime one. Switched both from AgentDeviceRequestOverrides to DeviceCommandBaseOptions (matching PerfOptions' existing pattern), closing the gap for real instead of stripping `platform` from the doc. - The "Android installFromSource()" snippet was missing its `createAgentDeviceClient` import outright; added it. KNOWN_DOC_GAPS is gone — every fenced snippet now compiles for real, and the test's assertion matches what it claims. 3. Switched the raw `execFileSync` calls to `runCmdSync` from src/utils/exec.ts, per AGENTS.md's process-execution invariant (this is a .ts integration test, not a packaging fixture that needs to stay dependency-free). Refs #1463
The prose right after the Remote Metro helpers snippet still named the old function; the compile guard only checks the fenced snippet, not surrounding prose, so it didn't catch this leftover from the prior rename. Refs #1463
59ea285 to
8bd5db9
Compare
Summary
examples/sdk/with four standalone, typechecked Node.js scripts covering the minimum surface from chore: examples/test-app is a fixture, not an example — rename or add real SDK examples #1463: root client session (createAgentDeviceClient→ open → snapshot/tap → close, with typed error handling viaAppError/isAgentDeviceError/normalizeAgentDeviceError),agent-device/metro(normalizeBaseUrl/resolveRuntimeTransport),agent-device/contracts(centerOfRecton a snapshot node), andagent-device/batch(runBatchfor a custom transport). Each example imports the publishedagent-device/...subpaths (not relativesrc/paths) and has a top comment stating what it demonstrates and its prerequisites.examples/sdk/tsconfig.jsonpath-maps those subpaths tosrc/sdk/sopnpm typecheck(now also run against this tsconfig) checks the examples in CI without a prior build, workspace link, or publish step — no new CI workflow needed. Running an example for real still resolvesagent-deviceas a self-referencing package afterpnpm build.src/__tests__/client-api-examples-drift.test.tsguards the examples against drifting fromwebsite/docs/docs/client-api.md's subpath API manifest, in both directions. It's picked up automatically by the existingunit-corevitest project (src/**/*.test.ts), sopnpm test:unitalready runs it.examples/README.md(new) indexes the examples and notes thatexamples/test-app/is a fixture, not an example. Per the issue's maintainer decision,examples/test-appis not renamed or moved.Test plan
pnpm check:tooling(lint, both typecheck lanes, layering, depgraph, production-exports, mcp-metadata, build, bundle-owner-files) — greenpnpm test:unit— 524 test files / 4663 tests passed, including the new drift-guard testpnpm format:checkon the new files — cleanRefs #1463
🤖 Generated with Claude Code
https://claude.ai/code/session_01HDEZF6hT2iSB4ysCU8pos7
Generated by Claude Code