Repository navigation
Replace DatabaseSettingsNode Pro fields and accessors with a generic settings accessor - #3378
Conversation
mstomar125
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (medium): APPROVE (posted as a comment, since GitHub blocks self-approval).
Review Type: Initial Review. Commit a428e0b9, 6 files. Reviewer read the full diff, the issue, the PR body and the write path in crud.rs, and ran --lib database_settings first_core_declared (16/16) and --test it database_settings_extension_keys_test:: person_seed_test:: (13/13).
Requirements Check (issue acceptance criteria)
- ✅ Grep 1 (
bound_?[tT]enant|get_sync_enabled|...overpackages/core) prints nothing. The daemon'sset_bound_tenantis its own registry-mirror method, not aNodeServiceaccessor. - ✅ Grep 2 (
sync_?[eE]nabled|auth_?[sS]tatusoverpackages/core) prints exactly the two allowed doc lines. - ✅ A fresh database seeds the singleton with
json!({})and the owner edge;database_settings()is empty. - ✅ A legacy-shape database opens: owner edge repaired, values read back unchanged, singleton still
version == 1,plugin:examplemerges alongside, an out-of-range legacy write is refused by the stored declaration, the stored schema keeps its four fields.seed_core_schemas_if_neededonly creates missing schema nodes and never rewrites a stored one. No migration, backfill or lazy-upgrade code in the diff. - ✅
merge_database_settingsis public, keeps siblings and rejects core-declared keys (helper test plus seam test, which also proves nothing is written). ⚠️ Ratchet criterion cannot be met yet:scripts/check-pro-boundary.tsis not onmain(open PR #3376). That script is a one-way ratchet in this respect: landing order causes no gate failure, only a stale ceiling to lower. Disclosed in the PR body.- ✅ Tests and clippy pass.
Focus items
- Accessors, guard, helper: no defects.
first_core_declared_keymatches the issue's signature. The guard runs before the singleton lookup and before any write. Error variants are right: guard rejection isInvalidUpdate, missing singleton or non-object bucket or root isInitializationError, schema validation failure isValidationFailed.nullis stored asnull. The privatemerge_database_settings_rejectingseam is justified: with the compiled list empty, guard wiring and "rejection writes nothing" are otherwise unobservable, at the cost of one private function. - Equivalent-mutant claim verified.
mergegoes throughupdate_nodetoupdate_with_version_check_returning_node_in_tx, which runsdeep_merge_namespaced_properties(per-field insert when both sides are objects), so clearing the bucket in memory cannot drop stored siblings. The read-modify-write is still needed for the expected version and the non-object check. The substitute mutations are adequate; each is killed by a named test. - Outside
packages/core: nothing breaks. No Rust caller outside core calls the removed accessors;default_metadata()has no runtime consumer;flatten_namespaced_propertiesis schema-free; frontend raw-key reads treat an absent key like the old seeded default; other core schemas already havefields: vec![], so the zero-field validation path is well trodden. - Tests. None pass regardless of the code except the issue-mandated regression guard
database_settings_accepts_namespaced_extension_keys. No flakiness risk. The owner-edge test asserts thehas_roleedge itself; the version-unchanged assertion detects a rewrite on open; the stored-versus-compiled guard is pinned by the later"a"write. - Leftovers in
packages/core: none beyond the excluded doc lines. No#NNNNreferences,allow(,deprecatedor migration code in the added lines.
Findings
- 🟢 Suggestion:
tests/it/database_settings_extension_keys_test.rs:201-207,stored_declaration_still_validates_legacy_keysasserts onlyrefused.is_err(). AssertingNodeServiceError::ValidationFailedwould make "the stored declaration, not core's guard, refused it" explicit. - 🟢 Suggestion (no action): the
merge_database_settingsdoc'sVersionConflictpromise is inherited fromupdate_nodeand untested here; the issue did not ask for a test.
No Critical or Important findings.
Recommendation: APPROVE
a428e0b to
d254fe8
Compare
Address-review summaryAddressed: 1 of 2 suggestions. Skipped: 1. Commits: 1 (
Also: the PR body's ratchet table is updated to the current base ( Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: The only change since the reviewed commit is one test assertion tightened (no production code touched), plus a rebase onto main commits that do not touch |
…settings accessor Core no longer declares, seeds, validates or reads the database-settings bucket keys. The singleton stays as the anchor for database-level configuration and the owner has_role edge; extensions keep namespaced keys in its bucket through NodeService::database_settings and the public NodeService::merge_database_settings. merge_database_settings rejects keys the compiled database-settings definition declares (none today). The guard reads the compiled definition, not the stored schema node, because a database created by an older build still declares the retired fields there. Existing databases keep their stored values and stored schema declaration untouched; a legacy-shape integration test covers opening, merging alongside and validating against them. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Both the stored enum validation and core's key guard return InvalidUpdate, so the test asserts on the enum-validation message to make clear that the stored declaration, not the guard, refused the out-of-range value. Co-Authored-By: Claude Sonnet 5 <[email protected]>
d254fe8 to
7165654
Compare
Closes #3340
Part of the Pro/core boundary epic. Carries out ADR-083 section 1 (proposed, decision 1-A), ahead of the ADR merging.
What changed
database-settingscore schema declares no fields (fields: vec![]). Module doc and schema comment reworded: the singleton is the anchor for database-level configuration and the ownerhas_roleedge.DatabaseSettingsNodeBehavior::validatereturnsOk(()); thedefault_metadataoverride is gone. No-children, no-markdown and not-embedded are unchanged.json!({}). The owner-edge repair logic is untouched.NodeService::database_settings()(returns the bucket as stored; empty map when the singleton or bucket is absent;InitializationErrorwhen the bucket is not an object) and a now-publicNodeService::merge_database_settings(entries)(one versionedupdate_node,nullstored asnull, no key ever deleted, missing singleton isInitializationError, concurrent change is the ordinaryVersionConflict).merge_database_settingsrejects, withInvalidUpdateand no write, any entry whose key the compileddatabase-settingsdefinition declares. It reads the compiled definition, not the stored schema node, because a database created by an older build still declares the retired fields there and a stored-schema guard would reject the Pro daemon's own writes. The compiled list is empty today, so nothing is rejected yet.Existing databases (no migration)
The repo forbids data migrations, and the issue specifies none: keys already in a bucket stay inert to core, and the stored
database-settingsschema node keeps declaring its old fields becauseseed_core_schemas_if_needednever rewrites a stored core schema. The compatibility handling is therefore (a) the guard reading the compiled definition, and (b) a legacy-shape integration test that seeds a database the way an older build left it (genericlegacy_*key names, so core keeps no Pro key names) and asserts it opens, the owner edge is repaired, the values are read back unchanged and never rewritten (singleton stays at its original version), extension keys merge alongside, an out-of-range write to a still-declared legacy key is refused by the stored declaration, and the stored schema node keeps its four fields.Deviations from the issue text
merge_database_settingscomputes the compiled declared list and delegates to a privatemerge_database_settings_rejecting(declared, entries). The issue's pure-helper test proves the matching logic but cannot show the guard is wired into the merge, since the compiled list is empty. With the seam,test_merge_database_settings_rejects_declared_key_and_writes_nothingproves a rejection writes nothing (including a clean sibling entry in the same call).InitializationError, non-object bucket isInitializationErrorfor both read and merge, and the legacy owner-edge test asserts thehas_roleedge itself (get_local_personfalls back to the first person, so resolving the person alone would not prove the repair).scripts/check-pro-boundary.tsis not on main yet (its PR is open). See the delta below; whichever PR lands second must reconcileBASELINES.Ratchet delta
Measured by running the ratchet script from the open ratchet PR's worktree against
origin/main(faf64e3b) and against this branch (informational; the script is not on main yet).The other eight markers are unchanged by this PR. When the ratchet script lands on main, lower those four values in
BASELINESto the branch counts above.Acceptance grep
git grep -n -E 'bound_?[tT]enant|get_sync_enabled|set_sync_enabled|get_auth_status|set_auth_status' -- packages/coreprints nothing.git grep -n -E 'sync_?[eE]nabled|auth_?[sS]tatus' -- packages/coreprints only the two doc lines the follow-up docs rewording owns (seed_local_person_if_needednote and thePersonNodeBehaviordoc).set_bound_tenant/bound_tenant_*hits inpackages/daemon/.../database_manager.rsbelong to the daemon's own registry mirror, a separate item, and are notNodeServiceaccessors.Verification
bun run test:changed: scripts tier and the full Rust workspace nextest pass (run before the final two rebases onto main and the review-fix commit, which touches one test assertion).cargo fmt -p nodespace-core -- --checkandcargo clippy -p nodespace-core --all-targets -- -D warnings -D clippy::unused-async: clean.ittests: pass.NODESPACE_HOME(never~/.nodespace). The pre-change daemon build created a database (singleton bucket{"auth_status":"local","sync_enabled":false}, stored schema declaring 4 fields); I then wrote populated Pro values (sync_enabled: true,auth_status: connected, a tenant binding) into that bucket via sqlite. The daemon built from this branch opened it with no error, no warning and no incompatible-database message, served the singleton with all four values intact through the CLI, and afterwards the singleton was byte-identical at version 1 with the stored schema still declaring 4 fields. Against a copy of the same database,set_local_person_identitysaved the identity (the call the onboarding RPC delegates to),get_local_personresolved it,merge_database_settingsmergedplugin:examplealongside the four values, and an out-of-range write to a legacy key was still refused.Mutation checks
Each new test was checked by applying a mutation, confirming the test fails, and reverting.
None(guard no-op)test_first_core_declared_key_rejects_declared_keys,test_merge_database_settings_rejects_declared_key_and_writes_nothingtest_merge_database_settings_rejects_declared_key_and_writes_nothingstored_declaration_still_validates_legacy_keystest_merge_database_settings_keeps_other_keys,test_merge_database_settings_writes_every_entry_of_one_callnulldeletes the keytest_merge_database_settings_keeps_other_keysdatabase_settings()ignores the stored bucketkeeps_other_keysand three legacy integration testsdatabase_settings()swallows a non-object bucket / merge replaces ita_bucket_that_is_not_an_object_is_an_initialization_errortest_merge_database_settings_missing_singleton_is_initialization_errortest_seed_database_settings_singleton_with_owner_edgepersonpropertyperson_seed_tests::fresh_install_seeds_exactly_one_local_personlegacy_database_opens_and_repairs_the_owner_edgelegacy_values_are_neither_read_nor_rewritten_by_core,extension_keys_merge_alongside_legacy_valuesstored_schema_node_keeps_its_declared_fields,stored_declaration_still_validates_legacy_keystest_create_second_database_settings_is_nooptest_database_settings_schema_declares_no_fieldsplugin:keysdatabase_settings_accepts_namespaced_extension_keysOne mutation the issue asks for cannot be killed: "stop preserving sibling keys".
update_nodedeep-merges within a namespace bucket (deep_merge_namespaced_properties), so clearing the bucket before inserting inmerge_database_settingsstill leaves the stored siblings in place. That is an equivalent mutant: sibling preservation is guaranteed by the storage layer as well as by the read-modify-write. The read-modify-write is kept because the non-object-bucket check needs the read, and the mutations above (wrong bucket, first entry only, update dropped, null deletes) do exercise the merge contract.🤖 Generated with Claude Code