Skip to content

Add settings-section and database settings-slot extension points - #3392

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3312-settings-extension-points
Sep 30, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3312-settings-extension-points

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3312

Adds the settings extension points from ADR-082 §2.2 (proposed) so that Account, "Add synced database…" and the per-database sync badge can later move out of core. With nothing registered, Settings renders exactly as before.

What changed

  • Registry (plugins/ui-extensions.ts, .svelte.ts). New types SettingsSectionContribution, SettingsSlot, SettingsSlotContribution; NodespaceExtension gains settingsSections? and settingsSlots?. The registry gains settingsSections() (registration order) and settingsSlotFor(slot) (descending priority, ties in registration order). The reactive wrapper gains getActiveSettingsSections() and getActiveSettingsSlot(slot), both filtered through isContributionActive. The new types are in one delimited block so the Add the virtual:nodespace-extensions build entry and the extension-api import alias #3311 rebase stays small.
  • settings-categories.ts (new). Core's category list as data (CORE_SETTINGS_CATEGORIES, with the Labs gates moved over verbatim) plus settingsCategories(), isSettingsCategoryVisible(id) and findSettingsSection(id). The four steps follow the issue: start from the full core list so a hidden anchor keeps its place; drop sections whose id collides with a core id or an earlier section (logged); insert each section after its after (same-anchor sections by priority, then registration order; absent or unknown after goes before About); drop hidden core entries and sections whose when() is false or throws.
  • Sidebar renders settingsCategories(), keyed by category.key.
  • Pane. The fallback effect is now if (!isSettingsCategoryVisible(activeCategory)) activeCategory = 'database'. That covers the Labs gates, an unknown or unregistered id (which used to render an empty pane), and a section whose when() turns false while open. A contributed section mounts through ExtensionOutlet, keyed by the section key, with a navigate prop. The AccountSettings branch is untouched.
  • database-settings.svelte mounts database.actions after the existing header buttons and database.row (with { databaseId }) inside each row's left column. The slot lookups are $derived once per render, not once per row. The Pro button, explainer, badge and dialog are untouched.
  • Fixture (tests/fixtures/test-extension): a section (id, label, after, priority options), a header action, row content, and a throwing row component.

Deviations from the issue text

  • settingsSlotFor and getActiveSettingsSlot are one generic signature (S extends SettingsSlot, returning Keyed<Extract<SettingsSlotContribution, { slot: S }>>[]) rather than one overload per slot. Call sites are typed identically, and a new slot needs no new overload.
  • A section that names itself in after, or sits on an after cycle, is listed before About instead of being lost, and is logged. The issue does not cover this case; without handling, such a section would silently never appear.
  • Collision and cycle warnings are logged once per section key. The sidebar, the pane's effect and the section lookup each rebuild the list, so logging on every build would repeat the warning.
  • byPriority is now exported from ui-extensions.ts so the category list orders same-anchor sections by the registry's own rule.
  • Sections anchored to Labs and sections with no anchor share the slot before About; anchored ones come first (after: 'labs', then unanchored), each group in priority then registration order.
  • The fixture's createTestExtension takes a second options argument for the section, and there is a small shared test helper (tests/helpers/labs-flags.ts) that sets every Labs flag generically.

For #3311: SettingsSectionContribution, SettingsSlot, SettingsSlotContribution and SettingsSlotContributionFor are exported from ui-extensions.ts and belong in the extension-api type re-exports once both land.

Pro-boundary ratchet

bun run scripts/check-pro-boundary.ts exits 0. No count rises above its ceiling and no baseline is raised. Marker lines this change removes and adds:

marker main this branch change
cloudBindState 203 202 pane labsFlags.syncEnabled check removed (-1), sidebar Account line removed (-1), settings-categories.ts Account entry added (+1)
proWording -1: a sidebar comment that named the Pro surface is gone

The one added marker line, visible: () => labsFlags.syncEnabled in settings-categories.ts, is class 3 (a planned move that adds no behaviour: it is the sidebar's existing Account gate, split into the data module). It is deleted together with the Account entry by #3325. Its tests use a generic set-all-flags helper, so no test line adds a marker.

BASELINES are not lowered in this PR. The edit to scripts/check-pro-boundary.ts was blocked by the permission classifier in the session that produced this change, so the ceilings are untouched. The check passes as is; the printed notice lists the tightening to paste (cloudBindState: 202, cloudSyncHooks: 0, proWording: 279 at the time of writing; the last two also include reductions already merged by other changes).

Tests

  • settings-categories.test.ts (34 tests): core order with all Labs flags on and off, each flag independently, placement by after (core anchor, section anchor, hidden core anchor, hidden section anchor, unknown anchor, no anchor, after: 'about'), priority and registration-order ties, priority not moving a section across anchors, id collisions (core, hidden core, earlier section, dropped section not anchoring), warn-once, self-anchor and cycles, when() false and throwing, isSettingsCategoryVisible, findSettingsSection.
  • settings-extension-sections.test.ts (14): sidebar position and label, hidden while when() is false and reactive, selection by click and by initialCategory, active highlight, working navigate('database'), fallback for an unregistered id and for a when() that is false initially or turns false while open, core-id collision.
  • database-settings-extensions.test.ts (9): header action renders once and only while visible, row content once per database with that row's id and inside that row, follows the list, nothing when there are no contributors, a throwing row component removes only its own outlet.
  • ui-extensions.test.ts (+13): registration, keys, duplicate ids across lists, key conflicts, malformed input, ordering, when() never evaluated by lookups, and the active accessors.
  • Unchanged and passing: settings-pane-labs-gating, settings-pane-account-gating, settings-sidebar-labs-gating, settings-sidebar-account-gating, database-settings, and test:free-users.

Mutation check: 37 mutations applied one at a time to the source, each run against the covering tests and reverted. 36 were killed. One survived and is an equivalent mutant: removing {#key activeSection.key} in the pane changes nothing observable, because ExtensionOutlet re-derives its load promise whenever the section it reads changes. The key stays for parity with the collection viewer host. Mutations covered every registry lookup and filter, each step of settingsCategories (collision rules, anchor resolution, priority, hidden anchors, cycle handling and its warning, warn-once), the pane's fallback effect, section dispatch and navigate, the sidebar's active marker, and the two database slot outlets including the row's databaseId.

bun run test:changed (frontend + browser tiers) passes; quality:fix is clean (0 errors, 0 warnings).

Not done: the manual dev:tauri check (Settings categories, database list, and the app menu's Integrations entry). There is no GUI in this environment; the Integrations path is an existing core id and is unaffected by the new fallback.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code review: PR #3392 (closes #3312)

Review Type

Initial Review (medium depth). I read the diff against origin/main (one commit, d5367ef4), traced the placement algorithm by hand against adversarial inputs, and ran these narrowly, one at a time: settings-categories.test.ts (34 pass), settings-extension-sections.test.ts (14 pass), database-settings-extensions.test.ts (9 pass), the five pre-existing gating/database-settings tests plus ui-extensions.test.ts (62 pass), free-user-guardrail.test.ts (9 pass), eslint on every changed file (clean), and the Pro-boundary ratchet in both modes. I did not run svelte-check or the full test:changed tier (shared machine); I am relying on the PR's statement for those.

Requirements Check (issue #3312)

Settings sections

  • ✅ A registered section appears at its after position (after Database with after: 'database', before About with no after). Covered at unit level and in the pane test.
  • ✅ It renders when selected by click and by settingsStore.initialCategory, and it receives a working navigate (navigate('database') is asserted end to end).
  • ✅ The pane falls back to Database for an unknown or unregistered id, and when the open section's when() turns false. A hidden or unknown contributed section never renders even for one tick, because activeSection comes from findSettingsSection, which only returns listed sections.
  • ✅ A section whose id collides with a core id or an earlier section is dropped and logged (unit tests for both cases; pane test for the core case).

Database slots

  • ✅ database.actions renders once in the header, and only while when() holds.
  • ✅ database.row renders once per database with that row's databaseId (asserted via row:<id>, data-database-id, and containment in the correct row column).
  • ✅ A throwing row component removes only its own outlet; both rows, their buttons and the healthy contribution still render.

No behaviour change

  • ✅ With nothing registered, the sidebar, pane and database list are unchanged. The five named tests (settings-pane-labs-gating, settings-pane-account-gating, settings-sidebar-labs-gating, settings-sidebar-account-gating, database-settings) are untouched by the diff and pass.
  • ⚠️ test:changed / quality:fix: not independently re-run by me beyond eslint and the targeted vitest runs above (test:free-users passes). The PR reports both clean.
  • ❌ / ⚠️ Ratchet: bun run scripts/check-pro-boundary.ts exits 0 and the PR body's accounting is accurate (see below), but the criterion "BASELINES equal the printed counts, with reductions lowered" is not met (issue step 8 was deliberately skipped). Under the current CLAUDE.md ("A count below its baseline does not fail ... tighten when convenient") this is non-blocking, but it is an explicit acceptance criterion, so it is tracked below.

Step 7 (fixture): ✅ flags section, databaseActions, databaseRow; id/label/after/priority options; the three components; plus a throwing row component for the isolation test.
Manual dev:tauri check: not done (stated in the PR). I verified by reading the callers that every current initialCategory writer passes a listed core id (integrations, ai-models, database, and the nav-badge database), so nothing regresses through the new fallback.

Ratchet accounting (verified). Added/removed diff lines matching marker patterns: cloudBindState -1 (pane check) -1 (sidebar Account line) +1 (settings-categories.ts:40) = net -1 (203 to 202); proWording -1 (removed sidebar comment). No test or fixture line adds a marker (--changed lists hits only in database-settings.svelte and settings-categories.ts, and the database-settings.svelte hits are pre-existing, untouched Pro markup). The class-3 claim for the one added syncEnabled line is correct and it is named for deletion by #3325. The printed counts (cloudBindState: 202, cloudSyncHooks: 0, proWording: 279) match the PR body.

Code Review Findings

I found no correctness bugs in the placement algorithm. Details of what I checked, so the author does not have to redo it:

  • No section lost or duplicated. Every kept section has exactly one anchor, so it lands in exactly one bucket (a core id, another section's id, or null). After cycle breaking every chain ends at a core id or null, so placeSection reaches every section once.
  • Recursion terminates. anchorsOf follows after chains with a seen set and breaks at next === s. I traced self-anchor, 2-cycle, tail-into-cycle (tail visited before and after the cycle members), and a mixed graph; all end with the first-registered cycle member moved to "before About" and the rest hanging off it. The cycle test expectations match my trace.
  • Hidden anchors keep their place. placeSection pushes the section with shown: false and still recurses into its children; the final filter runs last. Same for a hidden core anchor.
  • Collisions. Core wins, first-registered wins, a dropped section cannot anchor another (byId/known are built from kept sections only), and after: '<colliding id>' binds to the core/first-registered entry.
  • Reactivity. Every core visible() and every section's when() is evaluated on every call (no short-circuit), so $derived/$effect callers subscribe to all of them. warnOnce only touches a plain Set and the logger is non-reactive, so no state write happens inside a derived.
  • Pane. The fallback $effect converges (Database has no visible), no loop. navigate is a stable function, so the outlet's props object does not churn. activeSection is derived from the same list as the sidebar, so sidebar and pane cannot disagree.
  • Database page. {#each databases as db (db.id)} is keyed and ExtensionOutlet's loaded derived depends only on load, so a list refresh that replaces DatabaseInfo objects does not remount row content. The slot lookups are derived once per render, as specified.

🟡 Important

  1. Acceptance criterion not met: BASELINES not lowered. scripts/check-pro-boundary.ts is unchanged, so headroom remains (cloudBindState 203 vs actual 202, cloudSyncHooks 4 vs 0, proWording 281 vs 279). The check passes and the CLAUDE.md wording makes lowering optional, so I am not blocking on it, but it leaves the acceptance checkbox unticked and one line of syncEnabled headroom that this PR itself created. Suggested fix: the main agent (not the authoring session that hit the classifier) pastes the printed BASELINES block, or at minimum cloudBindState: 202, in this PR or an immediate follow-up, and notes on Add settings-section and database settings-slot extension points #3312 which. If parallel removal PRs are in flight and rebase churn is a concern, deferring is defensible under CLAUDE.md; just record the decision on the issue.
  2. No live verification of the Settings sidebar/pane/database render path. This PR rewrites how the sidebar list and pane dispatch are produced. The tests are good, but the issue lists a manual check (categories and database list unchanged; app menu Integrations still opens Integrations) and it was skipped. Suggested: a quick run-app browser pass of Settings (order and labels with Labs flags off, then on; Databases page; open Integrations from the app menu) before merge, or hand it to the user's next real-device pass.

🟢 Suggestions / Nits

  1. Cycle handling is logged but the logging is not asserted. 📁 settings-categories.ts:116-121 and the "anchor cycles" describe in settings-categories.test.ts. The PR body states cycles are logged; only the collision path asserts log.warn. Deleting the cycle warnOnce would survive the suite. Fix: add expect(log.warn).toHaveBeenCalledWith(expect.stringContaining('cycle'), expect.objectContaining({ key: 'ext/selfish' })) to the self-anchor and 2-cycle tests. Use a distinct extension id per test (see next item).
  2. Module-level warnedKeys is a latent test-isolation trap. 📁 settings-categories.ts:64-71. It is never cleared, so a later test that reuses an extension id and section id and asserts log.warn will silently get no warning (the existing tests avoid this only by using unique ids such as collides-core, collides-once). It is also process-lifetime state: a section that is fixed and then re-broken in one session does not log again. Not worth new production API; add a one-line comment above warnedKeys and above the tests' register helper saying "warn-once state persists per process: use a unique extension id in any test that asserts a warning", or key the state off the registry (e.g. clear it in the same place tests unregister). Nit-level.
  3. Design contract to record in ADR-082 §2.3: after: 'labs' sections precede unanchored sections regardless of priority. 📁 settings-categories.ts:167-176, test "lists sections anchored to Labs before those with no anchor". This is the natural result of "unanchored means immediately before About" being implemented as a separate bucket, and it is documented in the PR, but under the alternative reading (unanchored is equivalent to after: 'labs') a priority-10 unanchored section would sort before a priority-0 after: 'labs' one. Delete the Pro Account section, workspace-members card and tenant-admission calls #3325/Move the Pro account, admission and synced-database settings out of core #3327 will depend on this, so state the rule in the ADR text.
  4. Nit: the 'about' coupling is implicit. 📁 settings-categories.ts:50-51,168. Unanchored sections are only emitted when the loop reaches the core entry with id about; if that entry is ever removed or renamed, they vanish silently. The CORE_ALL equality test currently guards it. Optional: emit the null bucket after the loop when no about entry exists, or say in the FALLBACK_BEFORE_ID comment that removing About requires revisiting this.
  5. Nit: byPriority is now exported but still sorts in place. 📁 ui-extensions.ts:132-135. Its own doc does not mention it mutates its argument; the new caller has to remember to copy first (byPriority([...]) at settings-categories.ts:155). Since it is now shared, either make it non-mutating ([...list].sort(...), which lets the caller drop the copy) or note "sorts list in place" in the doc.
  6. Nit: docs that are now slightly stale.
    • 📁 ui-extensions.ts:28 still says "Lookups return contributions in descending priority", but settingsSections() deliberately returns registration order. Add "except settingsSections(), which the Settings category list orders by after".
    • 📁 extension-outlet.svelte:4-5 describes the app shell and node viewers as the hosts; the Settings pane and Databases page now use it too.
  7. Nit: settingsSlotFor's return cast. 📁 ui-extensions.ts:329. The generic signature is a reasonable deviation from per-slot overloads (call sites are typed identically and getActiveSettingsSlot inherits it). The comment explains the cast, but a local type predicate, (c): c is Keyed<SettingsSlotContributionFor<S>> => c.slot === slot in a .filter, would keep the narrowing next to the runtime check it depends on instead of asserting on the return value.
  8. Nit: no test for switching directly between two contributed sections (A to B without passing through a core pane). The PR calls removal of {#key activeSection.key} an equivalent mutant; that is plausible (the outlet re-derives its load promise), but no test would tell you if that stopped being true. Optional.

What is done well

  • The four-step algorithm from the issue is implemented literally, with the cycle/self-anchor hardening the issue did not ask for and sensible documentation of every deviation in the PR body.
  • Placement tests assert full ordered id lists (not just membership), including the hidden-anchor, unknown-anchor, after: 'about', priority-does-not-cross-anchors and dropped-section-cannot-anchor cases. Component tests assert both the positive outcome and the removed alternative (for example queryByText('Databases') is null once the section shows), and the fallback tests would render an empty pane on main, so they exercise the new effect.
  • The Pro-boundary accounting in the PR body is accurate, and the one added marker line is correctly classified and scheduled for deletion.
  • No #NNNN in comments, no console.*, no any, no lint suppression, no new Pro/tenant/nodespace-sync wording in added lines. The Account gating and its comment moved verbatim.

Recommendation

APPROVE (non-blocking follow-ups: items 1 and 2 should be settled before or right after merge; the rest are optional polish). No correctness, security or architectural defects found.

@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.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary for the pragmatic review of this PR

Addressed in f1be33d5, skipped, or left for the coordinator:

Addressed

  • 3 (cycle logging not asserted): the self-anchor and 2-cycle tests now assert the warning, each with its own extension id. Mutation check: deleting the cycle warnOnce call fails 2 tests.
  • 4 (warn-once state lives for the process): comments on warnedKeys and on the test register helper say a test that asserts a warning uses an extension id no other test uses. No production API added.
  • 5 (labs-anchored vs unanchored ordering contract): documented in the settingsCategories doc comment and the FALLBACK_BEFORE_ID comment. Recording it in the ADR text is a nodespace-docs change and is left for whoever owns that ADR.
  • 6 (implicit about coupling): FALLBACK_BEFORE_ID comment now says it must name a core entry; the existing core-order test guards it.
  • 7 (byPriority mutates): doc now says it sorts in place and returns the list; the new caller keeps its defensive copy.
  • 8 (stale docs): the registry header notes that settingsSections() keeps registration order; the ExtensionOutlet header lists the Settings pane and Databases page as hosts.

Skipped, with reasons

  • 9 (type predicate instead of the return cast in settingsSlotFor): both are the same trust assertion; the cast already carries an explanatory comment and the predicate would add a helper for no safety gain. Revisit if a third slot kind makes the cast harder to justify.
  • 10 (test for switching directly between two contributed sections): no mutation of this PR's code can fail such a test (ExtensionOutlet re-derives its load promise when the section it reads changes), and the outlet's own tests cover a changed load. Revisit if the pane stops routing sections through ExtensionOutlet.

Not done here

  • 1 (lower BASELINES in scripts/check-pro-boundary.ts): the edit was denied by the permission classifier in this session, so I have not attempted it by another route. The check exits 0. The printed block at the time of writing is cloudBindState: 202, cloudSyncHooks: 0, proWording: 279. This needs someone with the permission to paste it, in this PR or right after.
  • 2 (live run-app pass of Settings and the Databases page): not run. It needs the daemon built and running on a shared machine with a browser, which was out of the narrow-build budget. The component tests cover the render paths; a real-device pass of Settings, Databases and the app menu's Integrations entry is still open.

After the changes: quality:fix clean (0 errors, 0 warnings), test:changed passes (frontend and browser tiers), settings and plugin tests pass (445 tests), the push check including the ratchet passed.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The follow-up commit changes comments and documentation and adds two test assertions. It touches no production logic. The one behavioural claim (cycle warning) is backed by a mutation check.

mstomar125 and others added 2 commits September 30, 2026 14:08
Extensions can now contribute a Settings sidebar category and its pane
(placed by `after`, receiving `navigate`) and content for the Databases
page: `database.actions` in the header and `database.row` inside each
database row (receiving `databaseId`).

- ui-extensions: SettingsSectionContribution, SettingsSlot,
  SettingsSlotContribution, `settingsSections` / `settingsSlots` on
  NodespaceExtension, and the `settingsSections()` / `settingsSlotFor(slot)`
  lookups; reactive `getActiveSettingsSections()` / `getActiveSettingsSlot()`.
- settings-categories.ts holds core's category list as data plus
  `settingsCategories()`, `isSettingsCategoryVisible()` and
  `findSettingsSection()`: core ids win over section ids, the first
  registered section wins among sections, sections sit after their anchor
  (a hidden anchor keeps its place) and otherwise before About, and a
  section anchored to itself or into a cycle is listed before About.
- The sidebar renders that list; the pane falls back to Database whenever
  the active category is not listed and mounts a contributed section through
  the isolated ExtensionOutlet.
- database-settings mounts the two slots.
- The test-extension fixture gains a section, a header action and row
  content (plus a throwing row).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…hosts

- Assert the warning for a self-anchored section and for an anchor cycle,
  using an extension id per test since warn-once state lives for the process.
- Document that unanchored sections follow sections anchored to the entry
  above About, that byPriority sorts in place, that settingsSections() keeps
  registration order, and that the outlet is also hosted by Settings.

Co-Authored-By: Claude Sonnet 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.

Add settings-section and database settings-slot extension points

1 participant