Skip to content

Publish the extension host API: services, ui and testing entries, version policy - #3409

Merged
mstomar125 merged 3 commits into
mainfrom
issue-3315-extension-host-api
Oct 1, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-3315-extension-host-api

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3315

Summary

Completes the host API that extension code imports from core (ADR-082 §2.6, §7), at EXTENSION_API_VERSION 1.0, with a recorded surface snapshot and a boundary guard.

@nodespace/extension-api (src/lib/extension-api/index.ts)

  • Registration: EXTENSION_API_VERSION and the registry types, now including ExtensionLifecycle.
  • databases (ExtensionDatabases): read-through getters activeDatabaseId, activeDatabase, list, error over databaseStore's $state, so they are reactive inside a derivation. Methods create(name, path?), switchTo(id) and refreshDatabaseSettings() delegate. The DatabaseInfo type is re-exported.
  • nodes: getNode(id) (reactive sharedNodeStore read; documented as not pinning), fetchNode(id) and createNode(input) (via backendAdapter).
  • collections.reload() and schemas.reload(), over collectionsData.loadCollections() and schemasData.loadSchemas().
  • onDaemonReconnect, createLogger, toError, isCommandError, CommandError, and the provisional DATABASE_SETTINGS_NODE_ID.
  • The module doc holds the compatibility policy (what is versioned, major/minor/none, process, "core never imports the host API").

@nodespace/extension-api/ui: Button, Badge, Input, Card and its six parts, Dialog as a namespace, focusTrap.

@nodespace/extension-api/testing: mockTauriCore, plus render, screen, fireEvent, waitFor and cleanup from @testing-library/svelte. The module doc says it is test-only, and that the rune mocks and setup files come from core's vitest.config.ts.

Checks

  • extension-api-surface.test.ts + extension-api-surface.json: the export lists of every entry (every .ts file in src/lib/extension-api/, since the alias makes each one importable) and a SHA-256 over the API's type declarations, recorded at 1.0. Sources are read through the TypeScript syntax tree (typescript is already a devDependency). It fails on export *, on a surface change without a version change, on a removal or rename with only a minor bump, on a version that went backwards, and on a bump that was not re-recorded (it prints the command). Re-record: UPDATE_EXTENSION_API_SURFACE=1 bun run --cwd packages/desktop-app test src/tests/extension-api. Re-recording refuses a missing bump and a minor bump for a removal. Whether a changed type needs major or minor is review's call: the hash records only that a declaration changed.
  • extension-api-boundary.test.ts: no .ts/.svelte under src/lib (outside the host API) or src/routes imports the host API by either alias or by a relative path; the host API imports no edition-specific module (needles built from fragments); only /testing reaches test code; the fixture extension reaches core only through the host API.
  • The fixture extension (src/tests/fixtures/test-extension/) now imports its types only from @nodespace/extension-api, so svelte-check fails on an incompatible type change.

Docs: one line in src/lib/plugins/index.ts; one sentence in CLAUDE.md.

Deviations from the issue (and why)

  1. Facades test filename. It is extension-api-facades.svelte.test.ts, not .test.ts. Reactivity is checked inside a real $effect.root/$derived, which needs the Svelte compiler; core compiles runes only in *.svelte.test.ts.
  2. Hash scope. The issue says "exported declarations of plugins/ui-extensions.ts and src/lib/extension-api/*.ts". The hash instead covers:
    • every declaration in src/lib/extension-api/*.ts, exported or not. The issue lists the entries' exports exactly, so the nodes, collections and schemas facades are typed by non-exported interfaces (ExtensionNodes, ExtensionReloadable). Hashing only exported ones would let nodes.createNode be retyped silently;
    • the registry declarations the API reaches: exported by an entry, or mentioned by a covered declaration, transitively. Keyed<C>, which only hosts use, is excluded, so changing it doesn't demand a bump (policy: "none: anything not reachable through the API").
      Not hashed (gap, by the issue's scope): types re-exported from other core modules (DatabaseInfo, CommandError, and Node/CreateNodeInput behind nodes), plus value signatures and component props. In particular, Move Pro-owned data out of core's data model (ADR-083) #3345's planned removal of the two binding fields from DatabaseInfo will not trip the snapshot; under the policy that is a major change, so review has to apply it. Pulling re-exported declarations into the hash is a small extension of apiTypeDeclarations() if wanted later.
  3. Dialog members are recorded as Dialog.<member> in the ui entry list, so removing a dialog part is caught too, not only the namespace name.
  4. Two extra registration types stay exported: SettingsSlotContributionFor and CollectionTreeRootsContribution (added by Add settings-section and database settings-slot extension points #3312/Add the collectionTreeRoots extension point to the sidebar collection tree #3314, after the issue's list was written).
  5. Entries are derived from the directory, not hard-coded, so a new file there is recorded (or fails) like any other surface change. The source parsing uses the TypeScript syntax tree rather than regexes, so comments, strings and regex literals never confuse it.
  6. nodes.createNode takes CreateNodeInput, not the adapter's wider CreateNodeInput | Node.
  7. Pin guard exemption. shared-node-store-pin-guard.test.ts scans every non-test file for sharedNodeStore.getNode(, so lib/extension-api/index.ts gets a REACHABLE_WITHOUT_PIN entry with its reason: a pass-through read whose doc says it does not pin; the settings singleton it exists for is pinned centrally by refreshDatabaseSettings(), which core runs on every load and switch.
  8. Build test. nodespace-extensions-plugin.test.ts pinned the barrel's runtime keys to ['EXTENSION_API_VERSION']. The list now lives only in the surface snapshot; the build test checks that the alias resolves to the registry's EXTENSION_API_VERSION, and ExtensionLifecycle was added to its type-equality checks.
  9. BASELINES not pasted. Per the epic's standing instruction, BASELINES are not lowered in parallel PRs (Drive every Pro-boundary ratchet count to zero and make the check a hard ban #3371 tightens them).

Pro-boundary ratchet

bun run scripts/check-pro-boundary.ts exits 0. Delta is 0 for every marker: the new files have no hits, and --changed lists only four pre-existing lines in shared-node-store-pin-guard.test.ts, none added here. BASELINES unchanged.

Tests

New: extension-api-surface.test.ts (27), extension-api-facades.svelte.test.ts (7), extension-api-boundary.test.ts (9). Updated: nodespace-extensions-plugin.test.ts, shared-node-store-pin-guard.test.ts.

Mutation checks (each applied alone, target test run, file restored; all 26 fail as expected):

Mutation Fails
Export added to index.ts, no bump surface (message names index: extra, asks for a bump)
Optional field added to Contribution in ui-extensions.ts, no bump surface ("a type declaration changed")
reload() facade type changed, no bump surface
toError renamed + minor bump only surface (removal needs major)
Minor bump, snapshot not re-recorded surface (prints the re-record command)
export * in ui.ts surface
New src/lib/extension-api/extra.ts exporting foo, no bump surface (added extra: foo)
Every registry declaration hashed, reachable or not surface (Keyed must be excluded)
Naive comment stripping before parsing surface (declaration after a /\/*$/ regex literal)
Dynamic import() ignored by the import scan boundary (import-scanning test)
Whole .svelte file parsed instead of its <script> blocks boundary (script-block test)
Dotfiles not skipped among host API entries surface (entry-discovery test)
A non-.ts file in the host API directory accepted surface (entry-discovery test)
A merged interface's earlier block overwritten surface (merged-interface test)
A core store imports $lib/extension-api boundary
A core store imports ../extension-api/ui boundary
index.ts imports the membership store boundary
ui.ts imports ./testing boundary
Fixture imports $lib/plugins/ui-extensions boundary
databases.create drops path facades
databases.error getter returns a stale value facades
databases.activeDatabase read wrapped in untrack facades (reactivity)
nodes.getNode read wrapped in untrack facades (reactivity)
schemas.reload calls the collections loader facades
nodes.fetchNode reads the cache instead of the daemon facades
Pin-guard exemption removed pin guard

Also checked by hand: with a change and no bump, UPDATE_EXTENSION_API_SURFACE=1 fails and leaves the snapshot untouched; with a minor bump, it re-records and a normal run then passes.

Verification

  • bun run test:changed (frontend tier): passed — frontend 311 files / 5649 tests (baseline 308 / 5606), Chromium browser tier passed
  • bun run --cwd packages/desktop-app test src/tests/extension-api: 43 passed
  • bun run --cwd packages/desktop-app test:free-users: 9 passed
  • bun run --cwd packages/desktop-app quality:fix: eslint clean, design tokens clean, svelte-check 0 errors / 0 warnings
  • bun run scripts/check-pro-boundary.ts: exit 0

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review: PR #3409 (closes #3315)

Review Type: Initial Review

Scope reviewed: git diff origin/main...HEAD (1 commit, 15 files, +1362/-13). I read the three entries, the facades, source-scan.ts, extension-api-surface.ts, all three new test files, the snapshot, the fixture and the pin-guard and build-test edits. I also read the backing stores and services (database.svelte.ts, backend-adapter.ts, shared-node-store.svelte.ts, ui-extensions.ts, components/ui/dialog/index.ts) and ADR-082 §2.6 and §7.

Verification I re-ran:

  • bun run --cwd packages/desktop-app test src/tests/extension-api: 36/36 passed in 7.4s. The tests themselves take 81ms, and the boundary scan of src/lib takes 39ms, so the 5s timeout is not a risk.
  • shared-node-store-pin-guard.test.ts and nodespace-extensions-plugin.test.ts: 28/28 passed.
  • bun run scripts/check-pro-boundary.ts: exit 0.
  • I probed the parser with a scratch script outside the repo. The results are under finding 2.

Requirements Check

Surface

  • ✅ The three entries export exactly the surface in the issue.
  • ✅ EXTENSION_API_VERSION is { major: 1, minor: 0 }, and the snapshot is recorded at 1.0.
  • ✅ Facades delegate to the stores, and reads through them are reactive.
    • Every facade is a one-line delegation.
    • Getters read databaseStore's $state fields and its activeDatabase getter.
    • Reactivity is tested inside a real $effect.root/$derived, which is why the file is .svelte.test.ts.
    • I checked the signatures and doc claims against the store. switchTo no-ops for the active id and for unknown ids. create(name, path?) resolves to DatabaseInfo | null. refreshDatabaseSettings(): void pins, then reads in the background.

Checks that must fail when they should

  • ✅ The snapshot test fails on an added, removed or renamed export, or a changed registry type, without a bump. The PR body lists the mutations, and the surfaceProblems unit tests cover each row of the issue's table.
    • One caveat: a type change with only a minor bump is accepted. The issue's table does not require otherwise, but the docs over-claim (finding 3).
  • ✅ The boundary guard fails if a core module imports the host API. This was checked by mutation, for both alias imports and relative-path imports.

Everything else unchanged

  • ✅ No core module imports the host API. The guard is green.
  • ✅ test:changed, test:free-users and quality:fix pass, per the PR body. I re-ran only the targeted suites listed above.
  • ⚠️ check-pro-boundary.ts exits 0 (verified), but BASELINES were not pasted. The deviation is sound: this PR adds 0 markers, and lowering the baselines in parallel PRs causes conflicts that Drive every Pro-boundary ratchet count to zero and make the check a hard ban #3371 owns.

Deviations listed in the PR body: all 8 are sound.


Code Review Findings

🟡 Important

1. The entry list is maintained by hand. Any other file in src/lib/extension-api/ is importable as an entry but is outside the export snapshot.
📁 packages/desktop-app/src/tests/extension-api/extension-api-surface.ts:25-33, :71-77

  • What the alias allows. The alias maps the directory (svelte.config.js: "@nodespace/extension-api": "src/lib/extension-api", plus the Vitest aliases). Every .ts file in it is therefore reachable as @nodespace/extension-api/<name>. ADR-082 §2.6 lets Pro import "@nodespace/extension-api and its entries".
  • What the snapshot reads. currentSurface() reads export names only from the 3 files hard-coded in ENTRY_FILES. apiTypeDeclarations() does read every file in the directory, but it only hashes interface and type declarations.
  • Input that gets through. Add src/lib/extension-api/sync.ts containing only export const foo = .... No entry list changes and the hash does not change, so the surface test passes at 1.0. A new importable API entry ships unversioned and unrecorded, which is exactly what this check exists to prevent.
  • Recommendation. Add one assertion that the .ts basenames in HOST_API_DIR equal the basenames of Object.values(ENTRY_FILES). Alternatively, derive ENTRY_FILES from the directory. It is about 5 lines. A deliberate helper module would then need to live outside the aliased directory, which is also the right place for it.
  • Principle: fail closed. The guard's enumeration must cover everything the alias makes reachable.

🟢 Suggestions

2. The hand-written parser has a silent-drop path that its own doc says it does not have. The TypeScript compiler API would be smaller and exact.
📁 packages/desktop-app/src/tests/extension-api/source-scan.ts:16-60 (stripComments), :137-202

  • Overall. The parser works for every file it scans today. The cross-check against runtime keys (reads the %s entry's runtime exports correctly) is a good backstop for value exports, and most misparses throw.

  • The doc claim. The doc says "a quote that would mislead it ends up unterminated, which throws rather than silently dropping code". That holds for quotes. It does not hold for /* or // inside a regex literal.

  • Probe (verified with a scratch script, outside the repo). Run typeDeclarations on the source below. It returns only ["Shown"]: Hidden disappears from the hash without any error.

    const trim = (s: string) => s.replace(/\/*$/, '');
    export interface Hidden { x: number }
    /** doc */
    export interface Shown { y: string }
  • Why this matters. The scanned set includes plugins/ui-extensions.ts, a 458-line runtime module, and the recursion into components/ui/dialog/index.ts. Both are ordinary core files that people will edit without thinking about this scanner.

  • Recommendation. At minimum, correct the doc so it names the regex-literal limitation.

    • Better: typescript (~5.6) is already a devDependency. ts.createSourceFile(...) plus a walk over ExportDeclaration, InterfaceDeclaration, TypeAliasDeclaration and ImportDeclaration gives exact export lists and specifiers.
    • ts.createPrinter({ removeComments: true }).printNode(...) gives formatting-independent declaration text.
    • That replaces stripComments, declarationEnd and normalizeDeclaration, roughly 150 lines, along with all their edge cases.
  • Principle: don't hand-roll a parser when a real one is already a dependency.

3. A type change with only a minor bump is accepted, and the docs read as if it were enforced.
📁 packages/desktop-app/src/tests/extension-api/extension-api-surface.ts:137-141, :184-192; extension-api-surface.test.ts:11; message at extension-api-surface.ts:168-170

  • What is enforced. surfaceProblems requires a major bump only for name removals. A typesHash change with a minor bump returns only not-recorded, so it re-records cleanly.
  • Example. Retype ExtensionLifecycle.onDatabaseActivated?(databaseId: string) to (databaseId: number) and bump to 1.1. The test passes, and the re-record writes the snapshot.
  • Why that is acceptable. An aggregate hash cannot tell a new optional field (minor) from a retype (major), and the issue's table does not ask for this.
  • What over-claims. The test header says "Re-recording refuses a missing or too-small bump". The failure message says "major for a removal, rename or type change". Together they suggest the tool enforces this; for type changes, only review does.
  • Recommendation.
    • (a) Reword: a type change is accepted with any bump, and the reviewer judges minor vs major.
    • (b) Record per-declaration hashes (types: Record<name, sha>) instead of one typesHash.
  • What (b) gains. The failure can then name which declaration changed; today it says only "a type declaration changed" across about 15 declarations. The snapshot diff in the PR also shows the reviewer exactly what to judge. A declaration that disappears could additionally be treated as removal-needs-major.
  • Principle: when enforcement is delegated to humans, give them the precise pointer.

4. Keyed<C> is hashed although it is not part of the API.
📁 packages/desktop-app/src/lib/plugins/ui-extensions.ts:181-182; extension-api-surface.ts:60-61

  • apiTypeDeclarations() hashes every exported declaration in ui-extensions.ts. That includes Keyed<C>, which is host-internal: the barrel does not re-export it and no API type references it.
  • An internal change to it would therefore demand an EXTENSION_API_VERSION bump. That contradicts the policy's "none: anything not reachable through the API".
  • Recommendation: filter the registry's declarations to the names exportedNames(ENTRY_FILES.index) lists, or make Keyed non-exported or move it. Low impact today, but a false positive trains people to bump without thinking.

5. Nit: the index entry's runtime export list is now asserted in two places.
📁 packages/desktop-app/src/tests/build/nodespace-extensions-plugin.test.ts:236-252

Every future addition must update both this hard-coded list and the surface snapshot. That test's job is to check that the alias resolves and exposes the registration API. expect(api).toHaveProperty('EXTENSION_API_VERSION') would suffice, and the snapshot would own the full list.

Checked and fine (no action)

  • Architecture.
    • Facades are thin and stateless.
    • index.ts → stores → extension-lifecycle → ui-extensions forms no cycle back to the host API, and the root-layout registration test passes.
    • testing.ts reaching into src/tests is held by the guard: only /testing may reach test code, and no app module imports it.
  • Boundary predicates.
    • The edition needles are built from fragments and match every current edition-specific module: pro-plugin, pro-sync-variant, pro-sync, pro-relogin-*, first-pro-consent-*, membership, membership-service.
    • The negative cases cover likely false positives (project-node, property-forms).
    • The line-based comment skipping is adequate for import statements; its failure mode is a loud false positive.
  • Surface logic.
    • Re-recording cannot hide an unversioned name change, a removal with only a minor bump, or a version regression.
    • Two parallel 1.0 to 1.1 additions that merge cleanly still land as a single 1.1, which is semver-correct.
  • Ratchet. No new markers. membership.svelte alone matches no marker pattern.
  • Fixture. It uses every contribution kind and both hooks through @nodespace/extension-api, so svelte-check guards type compatibility as intended.
  • Docs. The policy text matches ADR-082 §7 and the issue's section 4. The CLAUDE.md and plugins/index.ts lines are present.

Recommendation: REQUEST CHANGES

The work is solid and well tested, and the PR is unusually candid about its gaps. The one should-fix is finding 1: the check that makes every API change deliberate does not see a new file in the aliased directory. The fix is about 5 lines. Findings 2 and 3 are at minimum doc corrections, because both docs currently over-state what the tooling guarantees. Findings 4 and 5 are optional.

🤖 Automated pragmatic-code-review (Claude Code)

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review (round 1)

All five findings addressed in 93d138b.

🟡 1. A new file in the host API directory escaped the snapshot: fixed.

  • hostApiEntries() now derives the entries from the directory: every .ts file there is an entry, since the alias makes it importable as @nodespace/extension-api/<name>. Anything else in the directory throws.
  • diffSurfaces compares the union of recorded and current entry names, so a new extra.ts with export const foo fails as added extra: foo until it is bumped and re-recorded.
  • A new test, "checks the runtime exports of every entry", fails until the runtime cross-check gets a static import for the new entry.
  • Mutation-checked: creating src/lib/extension-api/extra.ts fails the surface test.

🟢 2. The hand parser could silently drop declarations: fixed with the TypeScript syntax tree, as suggested.

  • source-scan.ts now uses ts.createSourceFile. Export lists come from ExportDeclaration and the export modifiers, and declaration text from ts.createPrinter({ removeComments: true }), which gives canonical text whatever the formatting.
  • Import specifiers come from walking ImportDeclaration, ExportDeclaration, import() calls and ImportTypeNode. I checked ts.preProcessFile and did not use it: its lexical scan missed an import that followed a regex literal on the same line.
  • This removes the comment stripper, the brace matcher and the normalizer.
  • The boundary scan of all of src/lib parses only files containing extension-api; every way to name the host API contains it. It stays at about 50ms.
  • New regression tests:
    • the /\/*$/ case: a declaration after a regex literal is still hashed;
    • imports are read from the syntax tree, not from comments, strings or a regex literal;
    • only a .svelte file's <script> blocks count.
  • Each was mutation-checked: naive comment stripping, ignoring dynamic imports, and parsing the whole .svelte file each fail.

🟢 3. Docs implied type changes were held to major: reworded.

  • The test header, the surfaceProblems doc and the policy section of index.ts now say what the check does. It fails on a change without a bump and on a removal or rename without a major bump. Whether a changed type needs major or minor is review's call, because the hash records only that a declaration changed.
  • Per-declaration hashes are skipped. The issue specifies a single typesHash, and a name-level diff would not settle major vs minor either. Worth revisiting if the "which type changed" message becomes a real pain point.

🟢 4. Keyed<C> was hashed: fixed.

  • apiTypeDeclarations() now covers every declaration in the host API's files, plus each registry declaration the API reaches: exported by an entry, or mentioned by a covered declaration, transitively.
  • Keyed, which only hosts use, is out. A new test asserts that NodespaceExtension and the non-exported ExtensionNodes are covered and Keyed is not.
  • Mutation-checked: hashing every registry declaration fails that test.

Nit 5. Duplicate runtime list: fixed. nodespace-extensions-plugin.test.ts now checks only that the alias resolves and that EXTENSION_API_VERSION is the registry's own value, and points at the surface snapshot for the list.

Also found while re-verifying. Three synthetic surfaceProblems cases passed the live EXTENSION_API_VERSION, so a later legitimate bump would have broken them. They now use the fixture's fixed 1.0. I checked this by bumping to 1.1: only the real snapshot check fails, and it asks for a re-record.

Snapshot. Re-recorded fresh at 1.0. The entries are identical; typesHash changed because the declaration text now comes from the printer and Keyed is out.

Verification: extension-api suite 41/41; quality:fix clean (svelte-check 0/0); ratchet exit 0, no new markers; all 23 mutations fail as expected; test:changed passed (frontend 311 files / 5647 tests, Chromium tier passed).

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: The parsing layer was rewritten on the TypeScript compiler API, and both the hash scope and how entries are found changed. These are non-trivial logic changes to the checks themselves.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review: PR #3409 (closes #3315)

Review Type: Re-Review

Scope: only the new commit 93d138b6 (git diff 762158d4..93d138b6, 7 files, +302/-262), read against round 1 and the address-review summary.

Previous Review Summary

  • Recommendations: 5 (🟡 1, 🟢 2–4, Nit 5)
  • Addressed: 5
  • Not addressed: 0. Finding 3's per-declaration hashes were declined with a sound reason: the issue specifies a single typesHash, and a name-level diff would not settle major vs minor either. The doc correction, which was the minimum ask, is done.
  • New issues: 2, both Nit

Verification I re-ran at 93d138b6

  • Tests: test src/tests/extension-api plus nodespace-extensions-plugin.test.ts all pass, 67/67 in 4.2s. Surface 25, boundary 9, facades 7, build 26. The surface tests run in 52ms and the boundary tests in 28ms, so there is no timeout risk.

  • Ratchet: bun run scripts/check-pro-boundary.ts exits 0. The added lines contain no marker words.

  • Probe: I ran a scratch script against the new scanner, outside the repo and deleted afterwards. hostApiEntries() gives index, testing, ui. apiTypeDeclarations() covers exactly these 14 declarations:

    • ChromeContribution, ChromeSlot, CollectionTreeRootsContribution, Contribution
    • ExtensionDatabases, ExtensionLifecycle, ExtensionNodes, ExtensionReloadable
    • NodespaceExtension
    • SettingsSectionContribution, SettingsSlot, SettingsSlotContribution, SettingsSlotContributionFor
    • ViewerTabContribution

    Keyed and the internal RegisteredExtension are out.


Round-1 findings

✅ 🟡 1. Entries are now derived from the directory.

  • hostApiEntries() (extension-api-surface.ts:35-50) treats every .ts file in src/lib/extension-api/ as an entry and refuses anything else, including subdirectories. Its listing is sorted, so a re-recorded snapshot is the same on every machine.
  • diffSurfaces (:148-159) now compares the union of recorded and current entry names. A new value-only file therefore fails as added extra: foo, and a deleted entry file fails as a removal that needs a major bump.
  • The new test checks the runtime exports of every entry makes the runtime cross-check grow with the directory, so the check now covers everything the alias can import.

✅ 🟢 2. source-scan.ts now reads the TypeScript syntax tree.

  • Exports come from ExportDeclaration and from export modifiers.
    • Both export * and export * as throw.
    • An unknown export form, such as export import or export namespace, throws instead of being skipped silently.
  • Declaration text comes from ts.createPrinter({ removeComments: true }). The comment stripper, brace matcher and normalizer are gone, and with them the silent-drop path from round 1.
    • The /\/*$/ case now has a regression test (extension-api-surface.test.ts, "sees a declaration that follows a regex literal…").
  • Import specifiers come from walking the tree. The walk covers ImportDeclaration, ExportDeclaration, import() calls and ImportTypeNode.
    • New tests check that comments, strings, a regex literal and .svelte markup do not count as imports.
    • Rejecting ts.preProcessFile because of its lexical gap is the right call.
  • The 'extension-api' prefilter (extension-api-boundary.test.ts:64-70, :84-85) is sound.
    • Every string specifier that isHostApi can match contains that substring, whether it is an alias or a relative path.
    • The prefilter tests the raw file text, so it checks a superset of what the parser reads.

✅ 🟢 3. The docs now match what the check enforces.

  • The test header, the surfaceProblems doc (extension-api-surface.ts:169-177) and the policy section of index.ts all say the same thing. The check enforces a bump for any change, and a major bump for a removal or rename. Whether a changed type is major or minor is the reviewer's call.
  • The unversioned-change message still says "major for a … type change". That is guidance that follows the policy, not a claim that the check enforces it, so it is fine.

✅ 🟢 4. The hash only covers registry types the API can reach.

  • apiTypeDeclarations() (:78-100) starts from every declaration in the host API's files and every name the entries export, then follows identifier references through the registry.
  • A side benefit: a non-exported registry type that an API type references is now covered, which the old exported-only filter missed.
  • The identifier-based reference set includes property names, so it can only include too much, never too little. That is the safe direction.
  • The new test pins the boundary: NodespaceExtension and ExtensionNodes are in, Keyed is out.

✅ Nit 5. The duplicated runtime-key list is gone from nodespace-extensions-plugin.test.ts.

Also fixed in this commit, and correct: the synthetic surfaceProblems cases no longer read the live EXTENSION_API_VERSION. A future legitimate bump would otherwise have broken unit tests that have nothing to do with it.


New findings (both Nit, optional)

Nit A. hostApiEntries() throws on editor and OS dotfiles.
📁 packages/desktop-app/src/tests/extension-api/extension-api-surface.ts:40-46

  • Any non-.ts entry in the directory throws. That includes a vim swap file (.index.ts.swp) while index.ts is open, and a Finder .DS_Store.
  • The surface test then fails locally with "the host API directory holds only .ts entries". The failure is loud and never reaches CI, since neither file is committed, but it is a confusing local red.
  • Recommendation: skip names that start with . before the check.

Nit B. Declaration merging keeps only the last block.
📁 packages/desktop-app/src/tests/extension-api/source-scan.ts:142

  • typeDeclarations stores declarations in a map keyed by name, so a second interface X { … } in the same file overwrites the first.
  • Verified: for export interface A { a: string } followed by export interface A { b: number }, the result is only interface A { b: number; }. An edit to the first block would then not change the hash.
  • Nobody in the registry or host API uses declaration merging today. The concrete risk is someone adding a hook to ExtensionLifecycle by appending a second interface ExtensionLifecycle block.
  • Recommendation: concatenate texts and merge references when the name is already present, or throw on a duplicate within a file, as already happens across files.

Checked and fine

  • Format sensitivity. The printer keeps quote style and parentheses, so 'a' vs "a" or (string)[] vs string[] changes the hash. That errs toward too many failures, never too few, and Prettier already fixes the quote style.
  • .svelte scripts. Parsing them as ScriptKind.TS is fine. The TypeScript parser recovers from errors, and the prefilter reads the raw file text, so markup that mentions extension-api is still scanned.
  • Dependency. typescript (~5.6.2) is a devDependency of packages/desktop-app, and this is test-only code.

Recommendation: APPROVE

All five round-1 findings are resolved. The parser rewrite removes the class of edge cases that worried me rather than patching them one at a time, and each fix comes with a regression test. Both new items are optional Nits.

🤖 Automated pragmatic-code-review (Claude Code)

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review (round 2)

The re-review came back APPROVE with two optional nits. Both are addressed in 8a13d30.

Nit A. hostApiEntries() threw on dotfiles: fixed.

  • Names starting with . (an editor swap file, a Finder .DS_Store) are now skipped.
  • hostApiEntries takes the directory as a parameter (defaulting to the host API directory), so a new test can run against a temp directory. The test covers two things: dotfiles are skipped, and a non-.ts file is still refused. The refusal path had no test before.
  • Mutation-checked:
    • dropping the dotfile filter fails the new test;
    • turning the refusal into a continue fails it too.

Nit B. Merged interfaces hashed only their last block: fixed.

  • typeDeclarations now joins same-name blocks in source order and unions their references.
  • New test: changing the first of two interface X blocks changes the hash.
  • Mutation-checked: going back to overwriting fails it.

No interface in the API uses merging today, so the recorded snapshot is unchanged.

Verification: extension-api suite 43/43; quality:fix clean (svelte-check 0/0); ratchet exit 0; test:changed passed (frontend 311 files / 5649 tests, Chromium tier passed).

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Two small, local changes to test helpers, each with its own test and mutation check. Production code is unchanged, the snapshot is unchanged, and the reviewer had already approved the logic around them.

mstomar125 and others added 3 commits October 1, 2026 10:07
…sion policy (closes #3315)

@nodespace/extension-api gains ExtensionLifecycle and read-through facades:
databases (getters over databaseStore's state plus create, switchTo and
refreshDatabaseSettings), nodes (getNode, fetchNode, createNode),
collections.reload and schemas.reload, and re-exports of onDaemonReconnect,
createLogger, toError, isCommandError, CommandError, DatabaseInfo and
DATABASE_SETTINGS_NODE_ID. Its module doc holds the compatibility policy.
New /ui (Button, Badge, Input, Card parts, Dialog namespace, focusTrap) and
/testing (mockTauriCore, testing-library helpers) entries.

extension-api-surface.test.ts records each entry's export names and a hash
of the API's type declarations at 1.0, and fails on export *, an unversioned
change, a removal with only a minor bump, a version regression, or a bump
that was not re-recorded. extension-api-boundary.test.ts keeps core modules
off the host API, the host API off edition-specific modules, test code
behind /testing, and the fixture extension on the host API. The fixture now
takes its types from the barrel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ve entries from the directory

- source-scan.ts parses with ts.createSourceFile: export lists from export
  declarations and modifiers, declaration text from the printer without
  comments, import specifiers from import/export declarations, import()
  calls and import types. A regex literal can no longer hide a declaration
  or an import.
- Every .ts file in src/lib/extension-api is an entry, so a new one is
  recorded or fails like any other surface change.
- The types hash covers the host API's own declarations and the registry
  declarations the API reaches, so a host-only type no longer demands a bump.
- Docs say what the check enforces: a bump for any change, a major one for a
  removal or rename; major vs minor for a changed type is review's call.
- Synthetic surfaceProblems cases use fixed versions, not the live one.
- The build test no longer duplicates the snapshot's export list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…k of a merged interface

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Publish the extension host API: services, ui and testing entries, version policy

1 participant