Repository navigation
Add @bb/plugin-sdk/testing - #517
Merged
SawyerHood merged 3 commits intoJul 6, 2026
Merged
Conversation
createFakePluginHost() returns a bb satisfying BbPluginApi backed by real better-sqlite3 :memory: storage, in-memory kv with the host's 256KB cap, host-ported registration validation/error shapes, and a recordable bb.sdk stub with threads.spawn plugin attribution. The harness drives rpc/http/cli, services and schedules (no timers), settings saves (onChange), thread lifecycle events, agent tools, and dispose (hooks LIFO, stale handles throw). @bb/plugin-sdk/testing/app tests a plugin's app.tsx without the bb host: installTestPluginRuntime() fills globalThis.__bbPluginRuntime.pluginSdkApp, loadPluginApp() captures typed slot registrations with the app's own validation, and renderSlot() mounts a slot with mock rpc/realtime/settings/ context/navigate/composer backends over Testing Library + jsdom. Co-Authored-By: Claude Fable 5 <[email protected]>
slack-bot server.test.ts covers the webhook flow end to end against createFakePluginHost: URL-verification handshake, signature rejection, first-mention spawn (recorded with plugin attribution) + kv mapping, follow-up send, unconfigured 503 + needs-configuration, and the thread.idle reply posted back to Slack. notes app.test.tsx renders the nav panel via loadPluginApp/renderSlot: rpc-backed tree, realtime-driven refetch, toPluginPanel deep links, and note creation over rpc. Example plugin packages gain test scripts and vitest configs; the root vitest project discovery now includes examples/plugins so the suites are not silently skipped. Co-Authored-By: Claude Fable 5 <[email protected]>
Testing section now leads with the official harness (backend createFakePluginHost patterns, frontend loadPluginApp/renderSlot patterns, the thunk-import constraint) and points at the example tests; the live bb-plugin-dev loop keeps its own subsection. Notes that the testing subpaths are workspace-only for V1 (not in the scaffold's bundled dts). Co-Authored-By: Claude Fable 5 <[email protected]>
SawyerHood
deleted the
bb/bb-plugin-sdk-testing-module-separate-pr-thr_bff8ubf7dq
branch
July 6, 2026 20:19
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 official test harness for bb plugins, as two new (additive) subpath exports of
@bb/plugin-sdk. No existing plugin-sdk APIs change.@bb/plugin-sdk/testing— backend fake hostbbsatisfiesBbPluginApi; semantics are ported fromapps/server/src/services/plugins/plugin-api.tswherever a plugin can observe them: registration name validation and error messages, the kv 256KB cap, append-onlystorage.migrate, settings descriptor validation + effective-value resolution, rpc/realtime JSON round-tripping, cron validation via cron-parser, reserved CLI/tool names,threads.spawnplugin attribution, and the dispose order (services aborted → hooks LIFO → sqlite closed → stale handle throwsPluginContextStaleError). Storage is real better-sqlite3:memory:(one shared handle, like the host's shared file) — never a mocked db.harnessdrives and inspects it:setSettings(values)— validates like the settings route, firesonChangewith(next, prev)callRpc(method, input?)/runCli(argv, ctx?)/fetchHttp(method, path, init?)— host-faithful invocation (JSON round trips, exit-code normalization, real Hono context; a throwing route yields the host's 500{ ok: false, error: "plugin route failed: …" })runService(name)→{ controller: AbortController, done }(synchronous start, no timers;NeedsConfigurationErrorby name → recorded, not a crash) andrunSchedule(name)emitThreadEvent(event, payload)— typed againstPluginThreadEventPayloads, returns caught handler errorscallAgentTool(name, input, ctx?)— parse (zod) + execute with default contextsdk.calls/sdk.callsTo(path)/sdk.stub(path, fn)— everybb.sdkcall recorded; unstubbed methods throw naming the exact path to stublogEntries,realtimeSignals,needsConfigurationMessages,registrations(routes, rpc methods, services, schedules, cli, agent tools, thread actions, mention providers),dispose()makeThreadResponse(overrides?)— complete deterministicThreadResponsefixture (typecheck fails here if the contract grows)@bb/plugin-sdk/testing/app— frontend harnessinstallTestPluginRuntime()fillsglobalThis.__bbPluginRuntime.pluginSdkAppwith asatisfies PluginSdkApptest implementation (the same seambb plugin buildshims).loadPluginApp(() => import("./app"))installs the runtime before the plugin module evaluates (it binds the runtime at import time), runssetupagainst a collector ported fromapps/app/src/lib/plugin-app-definition.ts(same validation, same messages,chromedefault filled), and returns typed registrations.renderSlot(registration, props, { rpc, settings, context })mounts the component via Testing Library + jsdom with mock hook backends and returns the render result plusrpcCalls,emitRealtime(channel, payload),navigateCalls, and a composer log (quotes/mentions/focusCount).Proof tests
examples/plugins/slack-bot/server.test.ts(7 tests): URL-verification handshake, signature rejection, first mention → signed webhook → kv mapping → recordedthreads.spawnwithorigin: "plugin"attribution, follow-upthreads.send, unconfigured 503 + needs-configuration, andthread.idleposting the answer back to the Slack thread (global fetch stubbed).examples/plugins/notes/app.test.tsx(4 tests): slot registrations, nav-panel tree over rpc, realtime-driven refetch,toPluginPaneldeep links, and note creation over rpc.packages/plugin-sdk/src/testing/__tests__(25 tests): kv cap, append-only migrations, settings onChange/no-op/unset, rpc & http & cli semantics, service abort + NeedsConfigurationError, cron validation, thread events, sdk recording/attribution/late stubs, zod agent tools, dispose order + stale-handle poisoning, realtime normalization.Example packages gain
testscripts + vitest configs, and rootvitest.config.tsproject discovery now includesexamples/pluginsso the suites aren't silently skipped.Docs & scope decisions
SKILL.mdTesting section rewritten around the harness with copy-pasteable patterns (host-loop guidance kept as a subsection);packages/plugin-sdk/README.mddocuments the subpaths..d.tsfor scaffolded plugins (V1 is workspace/in-repo consumers only — the harness runtime-imports better-sqlite3/hono/cron-parser/react, which standalone scaffolds don't carry). Documented in the README, the skill, and the module docblock.RESERVED_BB_CLI_COMMANDS,RESERVED_AGENT_TOOL_NAMES) are duplicated from the server with pointer comments (the contract package cannot importapps/server); both are already hand-maintained lists there.Validation
turbo run typecheck --filter=@bb/plugin-sdk --filter=@bb/server --filter=@bb/app✓ (includes the bundled-dts staleness check)turbo run test --filter=@bb/plugin-sdk --filter=bb-plugin-slack-bot --filter=bb-plugin-notes✓ 36/36apps/serverplugin-authoring-docs.test.ts(skill durability) ✓ 9/9🤖 Generated with Claude Code