Skip to content

Add the collectionTreeRoots extension point to the sidebar collection tree - #3402

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3314-collection-tree-roots
Oct 1, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3314-collection-tree-roots

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the collection-tree roots extension point from ADR-082 §2.2. An extension can name collections that the sidebar collection tree treats as invisible containers. Core unions every extension's roots with its own current root. With no extension registered, the tree is unchanged.

Closes #3314

Changes

src/lib/plugins/ui-extensions.ts

  • NodespaceExtension.collectionTreeRoots?: CollectionTreeRootsContribution, where CollectionTreeRootsContribution = () => readonly string[].
    • The doc states it is presentation only, and that it is evaluated inside a derivation, so it must read only reactive sources and have no side effects (ADR-049).
  • UiExtensionRegistry.collectionTreeRoots(): ReadonlySet<string>:
    • Returns the union of every extension's roots, in registration order.
    • Calls each contributor on every lookup, with no caching, so a derivation that calls it re-runs when the state the contributor reads changes.
    • A contributor that throws counts as empty. It is logged with log.warn once, and not again until it next returns normally (ADR-082 §2.4). The logged-once state is a per-registry WeakSet of extensions, mirroring warnedKeys in the reactive wrapper.
    • Non-string entries are ignored.
    • The function is called as a method of its extension (contribute.call(extension)), so a method-style contributor that reads this works.
  • The module doc now describes the new extension point.

src/lib/stores/collections.svelte.ts

  • buildCollectionsTree(collections, locallyCreatedIds, pendingIds, rootCollectionIds: ReadonlySet<string> = new Set([ROOT_COLLECTION_ID])).
    • Parents are filtered with !rootCollectionIds.has(p).
    • Top-level rows are filtered with !rootCollectionIds.has(c.id).
    • Its doc is updated.
  • The collectionsTree getter passes new Set([boundRoot || ROOT_COLLECTION_ID, ...uiExtensionRegistry.collectionTreeRoots()]), with the comment the issue asks for.
  • It imports the plain registry (ui-extensions.ts), not the reactive wrapper, so the store does not pull in the wrapper's transitional built-in import.
  • ROOT_COLLECTION_ID, the boundTenantCollection read and the databaseStore import are kept for Remove the tenant-binding root fallback from the collections tree #3330.

src/lib/extension-api/index.ts: exports the CollectionTreeRootsContribution type alongside the other contribution types.

Fixture (src/tests/fixtures/test-extension/)

  • The fixture's collectionTreeRoots returns testExtensionFlags.collectionTreeRoots (reactive, default []).
  • createTestExtension({ collectionTreeRoots }) overrides it through the existing overrides parameter.
  • resetTestExtension() clears the flag.

Where this goes beyond the issue

  • Malformed contributors. Throw-safety also covers a contributor that returns something other than an array (null, a string, a Set, an array-like), a collectionTreeRoots that is not a function, and a getter that throws. Each counts as empty and is logged once, the same as a throw. A string return would otherwise have added its characters as root ids.
  • Exported type alias. The issue only names the field. The alias keeps the barrel's type surface the same as the other contribution kinds, and the build-entry test asserts that the barrel's type equals the host's.
  • One extra tree test. It checks that the legacy root is not hidden when it is absent from the set, which is the behaviour Remove the tenant-binding root fallback from the collections tree #3330 relies on when it empties the default.

Pro-boundary ratchet

bun run scripts/check-pro-boundary.ts exits 0. BASELINES are unchanged: this PR doesn't lower them, as the epic directs, and it raises no count above its baseline.

Delta against main. Two markers rise by one each:

  • cloudBindState: 201 → 202 (baseline 203)
  • tenantWording: 453 → 454 (baseline 463)

Every other marker is unchanged. Both rises come from one test-only line in src/tests/stores/collections.test.ts:

const database = { id: 'bound-db', boundTenantCollection: BOUND_ROOT } as DatabaseInfo;

Class 2 (a fix to Pro code not yet moved).

  • The line is test coverage for core's transitional root read, databaseStore.activeDatabase?.boundTenantCollection in the collectionsTree getter. This PR reshapes that line and the review asked for it to be tested.
  • Per its doc comment, that read covers the per-install root a fresh install mints, so it is the path the sidebar takes today.
  • Remove the tenant-binding root fallback from the collections tree #3330 deletes the read, and this test with it.
  • The fixture names only the two fields the getter reads, so the test adds one marker line, not two. The other marker hits in changed files are pre-existing lines in collections.svelte.ts that Remove the tenant-binding root fallback from the collections tree #3330 also removes; the one reflowed doc comment keeps its count.

Tests

src/tests/plugins/ui-extensions.test.ts, new describe "UiExtensionRegistry collection-tree roots" (22 cases):

  • empty with no extension, and empty when no extension contributes;
  • union in registration order, with duplicates collapsed;
  • unregistering drops an extension's roots;
  • non-string entries are ignored;
  • the contributor is called on every lookup;
  • the contributor is called as a method;
  • a throwing contributor counts as empty while the others still contribute;
  • it is logged once however often it is read, and again only after a normal return in between;
  • each failing extension is logged separately;
  • malformed returns, a non-function and a throwing getter each count as empty;
  • when()/load() are never evaluated;
  • the fixture contributes nothing until its flag is set, contributes the flag's ids, and accepts an override.

src/tests/stores/collections.test.ts

  • The four explicit 4th arguments become new Set([...]).
  • New buildCollectionsTree cases: two roots are both hidden (as parents and as rows); with an empty set a container shows as an ordinary row with its member collections nested; the legacy root is not hidden when it is absent from the set.
  • New describe "collectionsTree unions extension collection-tree roots":
    • with no extension, the tree equals the unextended tree;
    • ext-root is hidden and its members are top-level (a nested child stays nested);
    • core's root stays hidden alongside it;
    • the tree follows the fixture flag on each read;
    • a throwing contributor leaves the tree intact;
    • unregistering restores the previous tree;
    • with an active database whose root is set, that root and the extension root are both hidden, and the legacy root becomes an ordinary row. This one was added after review.

src/tests/stores/collections-tree-roots.svelte.test.ts (added after review): reads collectionsTree inside a real $effect.root / $derived, as the sidebar does. It checks that the derivation re-runs when the state the extension's collectionTreeRoots reads changes, and again when it changes back. eslint.config.js gains rune globals for src/tests/**/*.svelte.test.ts, where Svelte compiles runes.

src/tests/build/nodespace-extensions-plugin.test.ts: expectTypeOf that the barrel's CollectionTreeRootsContribution equals the host's.

Mutation check (every new test)

29 mutations, each caught by at least one new test. Each test file was restored after every run, and every new test is the target of at least one mutation.

# Mutation Caught by
M1 first non-empty contributor wins instead of a union union order; throwing contributor; logs-again
M2 the catch rethrows throw/malformed cases; the store's "throwing contributor" test
M3 log on every failure (drop the once-guard) logs once; malformed cases
M4 never clear the failing flag on a normal return logs again only after a normal return
M5 drop the Array.isArray guard string / Set returns
M6 keep non-string entries ignores non-strings
M7 call without this called as a method
M8 memoize the result per registry called on every lookup; fixture flag; store follows/hides/restores
M10 reverse registration order union order; throwing contributor
M11 the getter ignores extension roots store hides/follows/restores
M12 the getter drops core's root store: no-extension, core root stays hidden, throwing contributor
M13 / M14 parent / row filter honours only the first root two roots; store hides/follows
M15 the default set is empty store: no-extension; throwing contributor
M16 the fixture ignores its flag fixture flag; store hides/follows/restores
M17 / M18 row / parent filter ignores roots two roots; existing root-node test; store cases
M19 one shared failing flag for all extensions logs each failing extension separately
M20 read the property outside the try throwing getter
M21 evaluate the when() of chrome contributions never evaluates when()/load()
M22 the fixture default overrides the override fixture override
M23 an empty set drops every parent empty set nests members
M24 always hide the legacy root too legacy root not hidden when absent
M25 unregistered extensions keep contributing store cases (restores, matches unextended tree)
M26 empty-registry sentinel empty with no extension
M27 a non-contributor adds a sentinel empty when none contribute; union; fixture
M28 the getter ignores the active database's root (always uses the legacy root) active-database root + extension root
M29 the contributor call is wrapped in untrack (imperative reads still correct) only the real-derivation test
T1 drop CollectionTreeRootsContribution from the barrel svelte-check error at the expectTypeOf line

Commands run

  • bunx vitest run src/tests/stores/collections.test.ts src/tests/plugins src/tests/build/nodespace-extensions-plugin.test.ts: 14 files, 429 tests passed
  • bun run test (full frontend suite): 307 files, 5604 tests passed
  • bun run test:changed: frontend Happy-DOM and Chromium passed (rust/skill/scripts not reached), at both commits
  • 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 (delta above)

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Automated pragmatic-code-review (medium): APPROVE

Review Type: Initial Review. HEAD reviewed: 264952b1.

Requirements Check (#3314)

Registry

  • ✅ uiExtensionRegistry.collectionTreeRoots() returns the union of every extension's roots, in registration order. Tests cover order, duplicates and unregister.
  • ✅ It returns an empty set when no extension contributes.
  • ✅ It survives a throwing contributor and logs it once. The once-guard is a per-registry WeakSet, cleared on the next normal return. Tests cover the single log, a re-log after recovery, and per-extension logging.

Tree

  • ✅ buildCollectionsTree takes ReadonlySet<string>, defaulting to {ROOT_COLLECTION_ID}. It filters both parents and top-level rows. Existing callers are unchanged, and the four explicit arguments are now Sets.
  • ✅ collectionsData.collectionsTree hides core's current root together with every extension root. The databaseStore import, the boundTenantCollection read and ROOT_COLLECTION_ID are kept for Remove the tenant-binding root fallback from the collections tree #3330.
  • ✅ With no extension registered the tree is unchanged: the getter equals buildCollectionsTree(collections).

Checks

  • ✅ Targeted vitest: 124 passed.
  • ✅ The ratchet has no count above its baseline, and BASELINES are untouched, as the epic directs.

📝 Deviations (all judged sound)

  • The CollectionTreeRootsContribution alias, guarded by the barrel's type-equality test.
  • Malformed contributors (non-array, non-function, throwing getter) count as empty and are logged once. This follows ADR-082 §2.4, and the guard stops a string return from adding single characters as ids.
  • The fixture override goes through the existing overrides parameter.
  • The extra "legacy root not hidden when absent" test.

There are no #NNNN references in code, no console, no suppressions, and no new Pro wording.

Findings

🔴 Critical: none.

🟡 Important (non-blocking)

  • 📁 src/tests/stores/collections.test.ts (new describe), against src/lib/stores/collections.svelte.ts:163-171.
    • No test drives the getter's boundRoot branch together with an extension root.
    • Every getter test runs with no active database, so a regression that drops the per-install bound root, such as new Set([ROOT_COLLECTION_ID, ...ext]), would pass.
    • Fix: add a test with an active database whose boundTenantCollection is set, plus an extension root, and assert that both are hidden.

🟢 Suggestions

  • The tests show that two imperative reads differ. They don't show that a real Svelte derivation re-runs when the state the contributor reads changes. A .svelte.ts test using $effect.root and flushSync would pin this down (optional). Registration itself is non-reactive, as with every other lookup. That is safe today, because registerExtensions runs synchronously in the root layout before the sidebar mounts.
  • Nit: the class doc ("Pure data + lookups, no reactivity", "Lookups never evaluate when") is slightly stale now that collectionTreeRoots() calls extension code and keeps failure state.
  • Nit: private failingTreeRoots is declared mid-class; conventionally it sits beside extensions.
  • Nit: the module doc's shape listing { id, apiVersion, chrome?, ... } omits collectionTreeRoots?. This is pre-existing drift; it already omits lifecycle? and debugDump?.

Verified safe

  • Performance: one Set and one call per contributor per derivation run, cached by the sidebar's $derived.
  • Fallback: extension roots can only add to the hidden set.
  • Import graph: the store imports the plain registry, not the wrapper.
  • Test isolation: the new tests clean up in afterEach.
  • Security: extensions are build-time and trusted.

Recommendation: APPROVE. The 🟡 is a worthwhile small addition in this PR.

@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: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above; one 🟡 (bound-root + extension-root getter test) to be addressed in this PR.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary (commit 0554f30d)

Addressed 4 of 5 recommendations; 1 skipped with a reason.

✅ 🟡 Test the getter's bound-root branch together with an extension root

  • New test in collections.test.ts. It sets an active database whose root is set, plus the fixture extension root.
  • It asserts that both roots are hidden, that their members are top-level, and that the legacy root becomes an ordinary row holding hr.
  • Mutation M28 (the getter always uses the legacy root) fails exactly this test.
  • Ratchet. The fixture names only the two fields the getter reads, { id, boundTenantCollection } as DatabaseInfo. The test therefore adds one marker line, not two: cloudBindState 201 → 202 and tenantWording 453 → 454, both under baseline.

✅ 🟢 Prove a real derivation re-runs

  • New src/tests/stores/collections-tree-roots.svelte.test.ts. It reads collectionsTree inside a real $effect.root / $derived and checks the derivation re-runs on each flip of the state the contributor reads.
  • Mutation M29 wraps the contributor call in untrack. That leaves every imperative read correct, and it fails only this test. So the test exercises real Svelte tracking, not the test setup's rune mocks.
  • eslint.config.js gains rune globals for src/tests/**/*.svelte.test.ts, the pattern where Svelte compiles runes; no test file used runes before.

✅ Nit: class doc

The UiExtensionRegistry doc now names collectionTreeRoots() as the one lookup that runs extension code, so a caller's derivation tracks what that code reads.

✅ Nit: field placement

failingTreeRoots now sits beside extensions at the top of the class.

⏭️ Nit: module-doc shape listing (skipped)

  • The listing { id, apiVersion, chrome?, viewerTabs?, settingsSections?, settingsSlots? } enumerates contribution lists, and the sentence goes on to say each item carries id / when / load.
  • collectionTreeRoots is a function, not such a list, so adding it there would mislead.
  • It already has its own module-doc paragraph, the same way lifecycle and debugDump do.

Checks at 0554f30d

  • 3 affected test files: 126 passed.
  • bun run test:changed: frontend Happy-DOM and Chromium passed.
  • quality:fix: eslint clean, svelte-check 0 errors / 0 warnings.
  • Ratchet: exit 0.
  • Push gate: passed.

Re-Review Decision

Decision: RE-REVIEW NEEDED (narrow: commit 0554f30d only)

Rationale: The fixes are mostly tests and docs. But they add a tooling config change (eslint.config.js) and change the ratchet delta from zero to +1 on two markers, and the first review saw neither. Core PRs get a re-review, so a narrow pass over this commit confirms both.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Automated pragmatic-code-review (medium), re-review of 0554f30d: APPROVE

Previous review: 5 recommendations (1 🟡, 1 🟢, 3 nits).

  • Addressed: 4: the 🟡 bound-root test, the 🟢 real-derivation test, the class-doc nit and the field-placement nit.
  • Not addressed: 1: the module-doc shape-listing nit. The skip reason is accepted: that listing enumerates contribution lists whose items carry id / when / load. collectionTreeRoots is a function and has its own module-doc paragraph, as lifecycle and debugDump do.
  • New issues above nit level: 0

Checks on this commit

  • vitest on the two changed test files: 62 passed.
  • eslint on the changed files and the config: 0 errors.
  • check-pro-boundary.ts: exit 0.

Findings

🔴 Critical: none.

🟡 Important: none.

  • collections.test.ts:916-951 covers the getter's boundRoot || ROOT_COLLECTION_ID branch together with an extension root. Each regression named in the first review fails it: dropping the bound root, always using the legacy root, or dropping the extension roots when a root is bound.
  • The partial { id, boundTenantCollection } as DatabaseInfo fixture names the field openly and omits only fields the getter never reads.
  • databaseStore state is restored in try/finally.

🟢 Suggestions (optional)

  • Nit: collections-tree-roots.svelte.test.ts:37-41. afterEach resets the registry and flags but not collectionsData. There is no cross-file leak: per-file module isolation holds under singleFork, and the effect root is stopped in finally. Resetting it would only be hygiene for a future second test.
  • Ratchet (optional). The delta is confirmed as exactly +1 cloudBindState (201→202) and +1 tenantWording (453→454), both from line 919 and both under baseline. Class 2 is the nearest class and is declared with the quoted line. tenantWording could be made net-zero by trimming a nearby marker line; cloudBindState has no cheap offset. Not blocking.

Verified safe

  • Real reactivity. *.svelte.test.ts compiles runes for real. The repo's rune mocks have no $effect.root and would throw, so a passing test proves real compilation. testExtensionFlags is a real $state proxy. The M29 (untrack) reasoning holds, and cleanup is correct.
  • eslint block. --print-config differs from a normal test file only by the three rune globals. It matches only src/tests/**/*.svelte.test.ts, and flat config merges the globals with the test block.
  • ui-extensions.ts doc and field move. Both are accurate. collectionTreeRoots() is the only lookup that runs extension code.

Recommendation: APPROVE.

@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 of 0554f30: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the re-review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary (re-review of 0554f30d)

The re-review is APPROVE with no findings above nit level. Both optional items are skipped, so there are no code changes and no new commits.

⏭️ Nit: reset collectionsData in collections-tree-roots.svelte.test.ts's afterEach (skipped)

  • The file has a single test, and the re-review confirmed there is no leak: source modules are re-evaluated per file under singleFork, and the effect root is stopped in finally.
  • The reset would only matter for a second test in this file. Revisit if one is added.

⏭️ Optional: make tenantWording net-zero (skipped)

  • The only offsets on offer mean rewording lines unrelated to this change: an existing test title, (public/legacy tenant), and a doc comment whose meaning names that case.
  • Changing them to move a line counter would be cosmetic churn, and cloudBindState has no offset anyway.
  • The +1 on each marker is declared in the PR body as class 2, with the quoted line. Remove the tenant-binding root fallback from the collections tree #3330 deletes the read and this test line together.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: No code changed in this round, and both reviews are APPROVE. The PR is ready for the coordinator's merge gate.

mstomar125 and others added 2 commits October 1, 2026 09:06
… tree

An extension can name collections that the sidebar collection tree treats
as invisible containers (ADR-082 §2.2). NodespaceExtension gains an
optional collectionTreeRoots() function, and UiExtensionRegistry gains
collectionTreeRoots(), which returns the union of every extension's roots
in registration order. It calls each contributor on every lookup, so a
caller inside a derivation follows the reactive state that contributor
reads. A contributor that throws, returns something other than an array,
or is not a function counts as empty and is logged once until it next
returns normally (ADR-082 §2.4). Non-string entries are ignored.

buildCollectionsTree now takes a set of root ids, defaulting to
{ROOT_COLLECTION_ID}, and hides each one both as a parent and as a row.
The collectionsTree getter passes core's current root together with every
extension root, reading the plain registry so the store does not import
the reactive wrapper. With no extension registered the tree is unchanged.

The test extension fixture contributes testExtensionFlags.collectionTreeRoots
by default, and createTestExtension({ collectionTreeRoots }) overrides it.
The extension-api barrel exports CollectionTreeRootsContribution.

Closes #3314

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- collections.test.ts: a getter test with an active database whose root is
  set and an extension root, asserting both are hidden and the legacy root
  becomes an ordinary row. The fixture database carries only the two fields
  the getter reads.
- collections-tree-roots.svelte.test.ts: reads collectionsTree inside a real
  $effect.root/$derived and checks it re-runs when the state the extension's
  collectionTreeRoots reads changes, and again when it changes back.
- eslint.config.js: rune globals for src/tests/**/*.svelte.test.ts, where
  Svelte compiles runes.
- ui-extensions.ts: the class doc names collectionTreeRoots() as the one
  lookup that runs extension code, and failingTreeRoots sits beside
  extensions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3314-collection-tree-roots branch from 0554f30 to f3b13fc Compare October 1, 2026 07:06
@mstomar125
mstomar125 merged commit 4cd8a8b into main Oct 1, 2026
@mstomar125
mstomar125 deleted the issue-3314-collection-tree-roots branch October 1, 2026 07:06
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.

Add the collectionTreeRoots extension point to the sidebar collection tree

1 participant