Repository navigation
Commit 50015d8
fix(objectql)!: the registry fold merges validation rules by name; a tenant's same-named copy carries only its message and active, and a changed condition is reported at load, never run (#28445)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoSvkSSxNZcoCwT3AFsNcUvy)_
Fixes #27949 (the load-path half of ruling B; the save-door refusal is a
follow-up card the seat files, `Blocked-by:` this PR).
Clause-②: no (narrowing)
Metadata-protocol: none
Ruling-ref: 6545641964 (letter B, maintainer 「同意」 2026-10-31T15:47Z),
under ruling 6524229156 (letter C′, maintainer 「同意」 2026-10-30T13:40Z).
## 维护者速读
- 改了什么:同一对象里的校验规则按 `name` 合并,不再把各层的规则数组拼接。租户覆盖层里与包内规则同名的副本只取它的 `message`
和 `active`,条件和类型始终用包里的;不同名的规则照旧叠加。加载时发现副本改了条件或类型,只记一条 `error`
日志并照包的规则执行,不抛错。ADR-0029 D9.2a 加一段带日期的说明。
- 为什么改:租户在 Studio
里改写扩展包某条规则的提示语后,旧折叠会让两条同名规则同时生效,被拒的写入会报两句话;同时租户复制的规则会冻结住,包里后来的修复到不了租户。
- 风险与回滚:改了条件的租户副本不再执行自己的条件,改由包的条件判定(启动日志点名该规则);升级不会因存量数据失败。没有任何键的增删。回滚即
revert 本 PR。
- 先看:`packages/objectql/src/registry.ts` 的 `mergeValidationsByName` 与
`withPackagedOwnerRules`、`reportChangedRuleCopies`(只报告不拒绝);`docs/adr/0029-…md`
的 D9.2a 说明。
- 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run
--maxWorkers=2 src/registry-validation-rule-by-name.test.ts`,预期 14
个用例全绿。
- 需要你做的:本 PR 改了 `docs/adr/**`(Tier H),合约复审通过后请用 os-zhuang 批准。
## What changes
**The fold merges `validations` by name**
(`packages/objectql/src/registry.ts`). A validation rule's identity
within an object is its `name`, so `mergeObjectDefinitions` no longer
concatenates the arrays. `mergeValidationsByName` lets a later layer's
rule replace every earlier rule of its name, and adds a rule of a new
name. Rules of different names stay additive, as ADR-0029 D9.2a
protects. Between two code layers, the later layer's same-named rule
replaces the earlier one, the way a field does.
**What a tenant's copy carries.** When the fold's base is a tenant
overlay (or a runtime-authored owner), `tenantRuleSettings` reads each
rule's `message` and `active` by name, first copy wins. The packaged
rule runs with those two keys and nothing else from the copy:
- `withPackagedOwnerRules` replaces a copy of the packaged OWNER's rule
with the owner's rule plus the copy's `message` / `active`, so a later
package fix to that rule reaches the tenant.
- An extension's rule is merged the same way through
`mergeValidationsByName`.
- `active: false` on the copy switches the rule off.
- A rule the overlay leaves out stays out, as D9.2's replace has always
meant.
**Load path: report, never refuse (ruling B).**
`reportChangedRuleCopies` compares each tenant copy with the packaged
rule set (`packagedRules`). The comparison reads omitted keys at the
schema defaults, so a parse that stamped `events` / `priority` /
`severity` is not a change. A copy that changes anything beyond
`message` and `active` is named once per registry at `error`
(`validation_rule_copy_changed`), with its consequence and the ruling's
prescription. The fold has already run the package's rule. Nothing
throws, so a package upgrade never fails a boot on stored data.
**Predicate for the save door.**
`SchemaRegistry.tenantRuleCopyRefusal(name, body)` returns
`ValidationRuleCopyRefusedError` (`INVALID_METADATA`, 422, `objectName`,
`ruleName`, `changedKeys` with `type` first, the prescription in the
message) for a body that changes a packaged rule's condition or type,
and `null` otherwise. Nothing calls it yet. Wiring it into the metadata
save door is the follow-up card. Under B, `registerObject` needs no
build-time refusal, and this PR adds none.
**Idempotence (#8027).** `subtractExtenderContributions` no longer
subtracts `validations`. The by-name merge already replaces every base
copy of an extender's rule name, so a folded base re-folds to itself.
Subtracting first would also strip the tenant's `message` / `active` off
a reworded copy before the fold reads them. `getPackagedObjectBase`
serves the packaged rules merged by name the same way.
**ADR-0029 D9.2a** gains a dated note recording both rulings: rules of
different names add; a same-named rule merges by name with the condition
owned by the package; the loud refusal sits at the save door; the load
path only reports.
**Changeset** `.changeset/27949-validation-rules-merge-by-name.md`:
`@objectstack/objectql` `patch` (ruling A: `Metadata-protocol: none`
grades every entry `patch`), carrying the BREAKING banner and the
ADR-0087 `not-required` disposition.
**Tests.**
- New `registry-validation-rule-by-name.test.ts` has 14 cases in five
blocks: a reworded copy is one rule; a changed condition or type is
refused by the predicate and never runs at load; `active: false`
deactivates; different names add; and re-folding is idempotent,
including a legacy row stored while the fold still appended.
- `engine-validation-tenant-rewrite.test.ts` changes one expectation.
The extension rule is now served and refused once, with the tenant's
sentence, on every header (before: the tenant's copy plus the translated
original).
## Tests
All on head `e5e62b28` (seat 4's `2a499b92` merged with `main`
`630b4078`, then the ruling-B changeset and ADR alignment).
- `pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2`:
Test Files 507/507, Tests 9847/9847.
- `pnpm --filter @objectstack/objectql typecheck`: exit 0
(`check:test-typecheck: OK`, debt held).
<details><summary>12 one-time ablations (each through
scripts/ablation-replace.mjs, restored to the HEAD blob, git diff HEAD
empty after each)</summary>
Run: `pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2
src/registry-validation-rule-by-name.test.ts
src/engine-validation-tenant-rewrite.test.ts` (18 cases). The suite
imports `./registry.js` from source, so no dist rebuild is involved.
Every mutation went red:
| # | mutation in `registry.ts` | red |
|:--|:--|:--|
| A01 | `mergeValidationsByName` concatenates again | 8 failed / 18 |
| A02 | the tenant's `message` is not read | 8 failed |
| A03 | the tenant's `active` is not read | 1 failed (`active: false`
deactivates) |
| A04 | `tenantRuleSettings` answers `undefined` | 7 failed |
| A05 | `withPackagedOwnerRules` is a no-op (owner copy keeps its own
condition) | 1 failed (a package fix reaches the tenant) |
| A06 | the tenant copy's condition is carried into the fold | 2 failed
(owner fix; changed condition never runs) |
| A07 | `tenantRuleCopyRefusal` never refuses | 2 failed (condition,
type) |
| A08 | `packagedRules` skips extension rules | 5 failed |
| A09 | schema defaults not applied before comparing | 1 failed (stamped
defaults change nothing) |
| A10 | the load report is not called | 1 failed (reported once) |
| A11 | the report's once-per-registry guard removed | 1 failed
(reported once) |
| A12 | tenant settings take the last copy, not the first | 1 failed
(legacy appended row) |
The first runs of A05, A06 and A08 were refused by the tool as no-ops
(the replacement text was already counted in the file). They were
re-anchored with distinct replacement text and re-run, and the numbers
above come from those re-runs.
</details>
## Acceptance notes
- `tenantRuleCopyRefusal` has no caller in this PR, on purpose: ruling B
puts the refusal at the save door (follow-up card behind the
`protocol.ts` serial queue on #6367).
- A copy stored before a package upgrade changed the rule cannot be told
apart from one the tenant changed. That is why the load path reports and
runs the package's rule instead of refusing.
- The predicate compares every key except `message`, `active` and
`_`-prefixed loader stamps, so it is stricter than "condition or type":
any package-owned key (for example `fields`, `events`, `severity`)
counts as a change. That matches C′'s "everything else is the
package's".
- The commit subjects carry `!` from seat 4's commit. The changeset
level follows `Metadata-protocol: none` (patch) under ruling A, and the
BREAKING banner stays in its body.
## Verification
<details><summary>Derived gates: 70 derived, 70 run, 70 exit 0</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` on `e5e62b28c3` derived 70 commands over 5
paths (759 changed lines). Each ran with stdin from `/dev/null`, its
exit captured by redirect before any pipe. All 70 exit 0, after a full
workspace build (`turbo run build`, dts on, excluding docs and
`@object-ui/*`). `dispatch-gates --ran`: `70 derived famil(ies)
accounted for — 70 run, 0 NOT-MEASURED`, exit 0.
Scoped lint, using the root `lint` script's command over
`packages/objectql`: exit 0.
Full dogfood (owed by the `(narrowing)` arm) runs once on this head; its
result is in the os-dev report on the card.
</details>
Tier H by path (`docs/adr/0029-…`). It stays a draft until the contract
review and the governed approval are on record; the seat lands it.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibx3A7AeHSnSr39oxaV)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 80a9f99 commit 50015d8
5 files changed
Lines changed: 705 additions & 54 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
543 | 579 | | |
544 | 580 | | |
545 | 581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
| |||
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
280 | 278 | | |
281 | 279 | | |
282 | 280 | | |
| |||
0 commit comments