Repository navigation
Replace the registry's tenant binding with opaque string extension keys (ADR-083 §3) - #3423
Conversation
Automated pragmatic-code-review (medium depth)Review Type: Initial Review (PR #3423 @ Requirements Check
Other Rust consumers: none missed. Findings
No Critical or Important findings. Recommendation: APPROVE |
mstomar125
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment because GitHub blocks self-approval). The full findings are in the review comment above: no Critical or Important findings, and 3 optional nits.
Address-reviewThe review was APPROVE with no Critical or Important findings. All three nits are addressed in 7cedf3a:
Skipped: none. Verification after the change:
Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: only error-message text and a test doc comment changed. There is no logic change, and every affected test still catches its mutations. |
7cedf3a to
90b3892
Compare
DatabaseEntry drops bound_tenant_schema and bound_tenant_collection, and its flattened extension keys become a BTreeMap<String, String>. A non-string value fails the registry load with an error naming the key. DatabaseManager::set_bound_tenant is replaced by set_extensions, which writes every (key, Option<value>) entry in one mutate_and_save, removes a key on None, refuses the keys the registry defines and fails an unknown id as not found. DatabaseInfo drops fields 8 and 9; the desktop DTO and the tray fixtures follow. Part of #3412 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
90b3892 to
47cd818
Compare
Part of #3412
Slice S3 of the one-pass strip: the database registry. Per ADR-083 §3, the registry's tenant binding becomes opaque extension keys. This PR does the Rust half; slice S4 removes the TypeScript
boundTenant*fields and the Settings badge.Acceptance (quoted from the slice)
DatabaseEntryhas nobound_tenant_*fields,set_bound_tenantis gone, and onlyset_extensionsand the opaqueextensionsmap remain, throughDatabaseInfo, the DTO and the store. Core's frontend reads no key from it. You complete the Rust half. Slice S4 removes the TS boundTenant* fields and the badge; say so in the PR.DatabaseEntry,DatabaseManager,DatabaseInfo,listing_to_info, the app-libDatabaseEntryDTO andto_entry. Slice S4 removes the TSboundTenant*fields from the database store and the "Syncs to tenant" badge. Until S4 lands, the DTO no longer sends those fields, so the store readsundefinedfor them.extensions: BTreeMap<String, String>, still flattened beside the defined fields. Chosen: reject. An entry carrying a non-string value fails the registry load withextension key `<key>` has a value of type <type>, but registry extension keys hold strings only. Reasons: nothing in core writes a non-string value (set_extensionstakes strings), so one can only come from a hand edit. Dropping it would also erase it from the file on the next save without anyone seeing why. A malformed registry already fails the load today. This is documented on the field, anda_non_string_extension_value_fails_the_registry_loadcovers integer, float, boolean, datetime, array and table.pub async fn set_extensions(&self, id: &DatabaseId, entries: &[(String, Option<String>)]) -> Result<...>. Shape the signature like the existing mutators. It writes all entries in one save through mutate_and_save; None removes a key. A failed save leaves the previous registry live. Success notifies subscribe_changes subscribers. An unknown id fails not-found. A key the registry defines itself (id, name, path, created_at, last_opened_at) is rejected before anything is written.pub async fn set_extensions(&self, id: &DatabaseId, entries: &[(String, Option<String>)]) -> Result<()>, the same shape asrenameandset_default. The defined keys live inDEFINED_ENTRY_KEYS, and a test pins that list to the keys a fully populated entry serializes. A key from that list is refused, whether it is being set or removed, before the lock is taken. Entries apply in order, so a repeated key ends with its last value.reserved. extensions = 10 already exists.reservedline is added. The comment onextensions = 10no longer says "Only string values are carried", because every value is now a string.Files
packages/daemon/src/services/database_manager.rs: the entry,DEFINED_ENTRY_KEYS,deserialize_string_extensions,set_extensions, and the tests.packages/daemon/src/services/database_service.rs:listing_to_infocopies the map,string_extensionsis gone, and the test is replaced.packages/proto/proto/database_service.proto:DatabaseInfofields 8 and 9.packages/desktop-app/app-lib/src/commands/database.rs: the DTO's two binding fields,to_entry, and a new DTO test.packages/daemon/src/tray.rs: the registry fixture, and thebound_fragment test (deleted). Outside the listed lines, a minimal compile fix:extension_keys_add_no_markerinsertedtoml::Values and now inserts strings.db listprinter (packages/cli/src/commands/database.rs) readsDatabaseInfofield by field and never read 8 or 9.Tests
Deleted:
set_bound_tenant_mirrors_persists_and_clears,set_bound_tenant_rolls_back_when_save_fails,registry_round_trips_entry_keys_it_does_not_define(it kept integer and datetime values),listing_to_info_carries_string_extensions_only(integer and boolean values), and the tray'sa_recorded_binding_adds_no_marker.Added:
set_extensions_writes_every_entry_in_one_save,set_extensions_none_removes_a_key,set_extensions_for_an_unknown_id_is_not_found,set_extensions_rejects_each_key_the_registry_defines,set_extensions_rolls_back_when_save_fails(reusesbreak_registry_persistence; covers notify-on-success-only),set_extensions_round_trips_keys_that_need_quoting,extension_keys_round_trip_through_load_and_save,a_non_string_extension_value_fails_the_registry_load, anddefined_entry_keys_match_the_serialized_entry.a_rename_keeps_extension_keysnow uses a fixture with only string values.listing_to_info_carries_the_extensions_map.the_dto_serializes_only_registry_fields_and_extensionschecks the exact camelCase key set, plus a fragment needle (["ten", "ant"].concat()) that still fails if someone adds a binding key and updates the expected list.Mutation checks
Each mutation was applied alone, the targeted tests were run, and the file was restored. All 20 were caught.
set_extensionssaves once per entryset_extensions_writes_every_entry_in_one_saveNonedoes not remove the keyset_extensions_none_removes_a_keyfind_or_errdropped (unknown id accepted)set_extensions_for_an_unknown_id_is_not_foundset_extensions_rejects_each_key_the_registry_definesNone)set_extensions_rejects_each_key_the_registry_defineslast_opened_atmissing fromDEFINED_ENTRY_KEYSset_extensions_rejects_each_key_the_registry_defines,defined_entry_keys_match_the_serialized_entryset_extensions_rejects_each_key_the_registry_definesmutate_and_saveswaps the live registry before savingset_extensions_rolls_back_when_save_fails(and the other rollback tests)mutate_and_savenotifies before saving (so also on failure)set_extensions_rolls_back_when_save_failsmutate_and_savedoes not notify on successset_extensions_rolls_back_when_save_fails,set_extensions_writes_every_entry_in_one_saveextensionsskipped on serializeextension_keys_round_trip_through_load_and_save(and others)a_non_string_extension_value_fails_the_registry_loada_non_string_extension_value_fails_the_registry_loadlisting_to_infosends an empty maplisting_to_info_carries_the_extensions_maprename_all = "camelCase"the_dto_serializes_only_registry_fields_and_extensionsthe_dto_serializes_only_registry_fields_and_extensionsthe_dto_serializes_only_registry_fields_and_extensionsto_entrydrops the mapto_entry_passes_extensions_throughextension_keys_add_no_markerRegistry::savewrites a dotted key bareset_extensions_round_trips_keys_that_need_quoting(the load then fails:extension key `ext` has a value of type table)Verification
git grep -nP 'bound_?[tT]enant|set_bound_tenant|toml::Table' -- packages/daemon packages/proto packages/desktop-app/app-lib packages/cli→ 0reservedline added todatabase_service.protogit grep -nP 'pub async fn set_extensions' -- packages/daemon→ 1git grep -niP tenant -- packages/daemon/src/services packages/proto/proto/database_service.proto packages/desktop-app/app-lib/src/commands/database.rs→ 0cargo clippy -D warnings --all-targetsclean fornodespace-daemon,nodespace-app-lib,nodespace-cliandnodespace-proto;bun run quality:fixexits 0bun run scripts/check-pro-boundary.tspassesbun run test:changed: passed (scoped to rust + scripts), on the original head and again after the review fixesRatchet
bun run scripts/check-pro-boundary.ts --changed: every marker is 0 in the changed files, so this PR adds no Pro lines.BASELINESis not edited (S5 rewrites the checker).Registry reset
Delete
~/.nodespace/databases.tomlon dev machines. Oldbound_tenant_*lines would load as plain extension keys, and any non-string value now fails the load, so the file is not carried forward. Database files are unaffected; re-register them or let the daemon create a new default.Extension API (for S4's release notes)
DatabaseManager::set_bound_tenantis replaced byDatabaseManager::set_extensions(id, &[(key, Option<value>)]).DatabaseEntry.extensionsis retyped to a string→string map (BTreeMap<String, String>), and thebound_tenant_*fields are removed.DatabaseInfofields 8 and 9 (bound_tenant_schema,bound_tenant_collection) are removed, with no reserved numbers.EXTENSION_API_VERSIONis S4's to bump.🤖 Generated with Claude Code