Skip to content

Commit 1d19acf

Browse files
fix(objectql): withhold a disabled extender's rules from the packaged object base (#38622)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9St4eUWHFcCKuRUrCZPperJ)_ Fixes #34217 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:启用的扩展包里的校验规则提示,在中文等非默认语言下重新显示译文;停用包的同名规则不再顶替它。 - 为什么做:「停用就该全部消失」的延续——此前字段已修,这次补上校验规则这一半。 - 出错会怎样:最坏是某条规则提示退回源语言显示,不影响数据与校验本身;直接回滚这次改动即可。 - 要你做什么:无。 ## What changes - `getPackagedObjectBase` (`packages/objectql/src/registry-platform-global.ts`) now drops a disabled package's `extend` contributors ONCE, before every widening read: the `extended` test, `packagedRules`, the added fields and the placed tabs. Before, only the added fields and the tabs filtered `isPackageDisabled`, so the rule half still merged a disabled later extender's same-name rule over the enabled one, while the served fold withholds it. The added-fields and tabs reads are byte-for-byte the same filter as before, now applied at one place. - The `getPackagedObjectBase` docblock in `packages/objectql/src/registry.ts` said the rule half "still reads every code extender, disabled ones included"; that sentence became false with this change and is rewritten (same line count, the facade's). - `packagedRules` itself is untouched: it stays a pure function of the caller's list, as `packagedAddedFields` is. - Pin: a new top-level `describe` in `packages/rest/src/meta-object-field-patch-i18n.test.ts`, beside the disabled added-field case it mirrors (same real `SchemaRegistry` harness). The rule-side file the card names (`meta-object-validation-message-i18n.test.ts`) mocks the protocol and has no registry, so it cannot hold this pin. ## Tests - New case: an enabled extender (priority 200) and a later disabled one (priority 300) ship a rule `needs_title`. Asserts the served rule message, the packaged base's rule message (both the enabled one's), and that the zh-CN item read translates it. - Red before the fix, on the built dist at `5e8988fc` (pin committed, fix not): `AssertionError: expected [ 'Disabled says.' ] to deeply equal [ 'A task needs a title.' ]`, `Tests 1 failed | 18 passed (19)`. Green after the fix plus a rebuild of objectql: `Test Files 2 passed (2)`, `Tests 22 passed (22)` (with the validation-message file alongside). - `@objectstack/objectql`: `typecheck` exit 0, full `vitest run` `Test Files 641 passed (641)`, `Tests 14544 passed (14544)`. `@objectstack/rest`: `typecheck` exit 0. ## Acceptance notes - `tenantRuleCopyRefusal` (`registry-object-registration.ts`) reads `packagedRules` over the raw contributor list too, and shares the defect: measured on the built dist (same shape as the pin, rule `r1`), a tenant copy of the SERVED rule changing only its `message` is refused (`INVALID_METADATA`, "this copy changes `condition`"), and a copy carrying the disabled rule's condition is accepted. Not fixed here: the same filter would also stop reserving a rule name only the disabled package ships, so a tenant could save a rule of that name with its own condition while the package is off. That is a behaviour change the card does not rule on; it is reported to the seat as a separate finding. - `reportChangedRuleCopies` is called with the contributors of the fold it runs in. The served folds pass `withholdDisabledExtensions(...).kept`; the storage fold (`resolveStorageObject`) folds every contributor, disabled ones included, and its rule judgment matches the rules that fold merges. Not touched. - The refused-write side (`engine-validation-messages`' `packagedRuleLookup`) reads the same base, so it follows the fix. Read in the code, not measured with its own test. ## Verification Read first: `packages/objectql/src/registry-platform-global.ts` (the `contributors` filter at the top of `getPackagedObjectBase`), then the new `describe` at the end of the test file. Two-minute check: `pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2 src/meta-object-field-patch-i18n.test.ts` after building objectql. Expected: `Tests 19 passed (19)`. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmRar3Kkg6SpwVgaaVE)_ <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmRar3Kkg6SpwVgaaVE --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent eec2bc3 commit 1d19acf

4 files changed

Lines changed: 61 additions & 10 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
fix(objectql): a disabled package's validation rule no longer stands as the packaged rule of the object it extends
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`SchemaRegistry.getPackagedObjectBase` built the packaged rule set from every code extender of the object, a disabled package included, while the served object withholds a disabled package's extension. Where an enabled extender and a later, disabled one both ship a rule of one name, the base carried the disabled rule while the served object carried the enabled one, so the enabled rule's `message` read as rewritten by the tenant: `/meta` served it in the source language under every other locale, and a refused write quoted it untranslated. The base now leaves a disabled package's extensions out of its rules as it already did for its fields and tabs, so the enabled rule's message is translated again. Nothing to change in your metadata.

‎packages/objectql/src/registry-platform-global.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,24 +525,23 @@ export class PlatformGlobalFacet {
525525
const owner = this.getPackagedObjectOwner(name);
526526
if (!owner) return undefined;
527527
const fqn = this.resolveObjectKey(name);
528-
const contributors = (fqn === undefined ? undefined : this.objectContributors.get(fqn)) ?? [];
528+
// A disabled package's extension is withheld from the served fold, so it
529+
// adds nothing the served object carries: its rule and its field are no
530+
// packaged ones. Filtered once, here, for every widening read below.
531+
const contributors = ((fqn === undefined ? undefined : this.objectContributors.get(fqn)) ?? [])
532+
.filter((c) => !(c.ownership === 'extend' && this.isPackageDisabled(c.packageId)));
529533
// [ADR-0029 D9.2a, 2026-10-30 note] By name, as the fold merges them: an
530534
// extender's rule of a name the owner already ships is one rule, not two.
531535
const extended = contributors.some((c) =>
532536
c.ownership === 'extend' && isCodeArtifactBody(c.definition)
533537
&& Array.isArray(c.definition.validations) && c.definition.validations.length > 0);
534-
// A disabled package's extension is withheld from the served fold, so it
535-
// adds nothing the served object carries; its field is no packaged one.
536-
const addedFields = packagedAddedFields(
537-
owner.definition,
538-
contributors.filter((c) => !(c.ownership === 'extend' && this.isPackageDisabled(c.packageId))),
539-
);
538+
const addedFields = packagedAddedFields(owner.definition, contributors);
540539
// [#36528] The record-page tabs a code extender's list placement (`place`)
541540
// splices into the owner's `relatedLists`, as the fold splices them, with
542541
// the same filter as the added fields; only the lists pass is read off.
543542
const placedLists = packagedPlacedRelatedLists(
544543
owner.definition,
545-
contributors.filter((c) => c.ownership === 'extend' && isCodeArtifactBody(c.definition) && !this.isPackageDisabled(c.packageId)),
544+
contributors.filter((c) => c.ownership === 'extend' && isCodeArtifactBody(c.definition)),
546545
(child) => {
547546
const childKey = this.resolveObjectKey(child);
548547
const childOwner = childKey === undefined ? undefined : this.getObjectOwner(childKey);

‎packages/objectql/src/registry.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,8 +3660,8 @@ export class SchemaRegistry {
36603660
* the owner's keys — takes back the case #8037 filed. A tenant overlay and an
36613661
* extension of tenant provenance (`_provenance: 'org'`) add nothing here:
36623662
* their fields stay authored after the fact. Nor does a disabled package's
3663-
* extension, which the served fold withholds. (The rule half, `packagedRules`,
3664-
* still reads every code extender, disabled ones included.)
3663+
* extension, which the served fold withholds: neither its fields nor its rules
3664+
* (a disabled later extender's same-name rule leaves the enabled one packaged).
36653665
*
36663666
* Returns the owner's definition BY REFERENCE when no code extender ships a
36673667
* rule, adds a field or places a list, and `undefined` exactly where

‎packages/rest/src/meta-object-field-patch-i18n.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,45 @@ describe('[#33952] a patched slot reads the patching package\'s own translations
345345
expect(src.asked).toEqual([]);
346346
});
347347
});
348+
349+
describe('a disabled later extender\'s same-name validation rule is withheld from the packaged base as from the fold', () => {
350+
// The rule-side twin of the disabled added-field case above. The base's
351+
// rule set is the one a translated rule message is compared with: a base
352+
// that kept the disabled package's rule read the enabled rule's message as
353+
// diverged from its packaged baseline, and the message stayed in the source
354+
// language under zh-CN.
355+
const DEP_PKG = 'com.example.carbon';
356+
const LATER_PKG = 'com.example.later';
357+
const RULE = { type: 'script', name: 'needs_title', condition: 'record.title == null' };
358+
const ENABLED_SAYS = 'A task needs a title.';
359+
const ZH = '任务需要标题。';
360+
const rulesI18n = {
361+
...i18nService,
362+
getTranslations: (locale: string) => {
363+
const out: Record<string, any> = structuredClone(BUNDLE[locale]);
364+
if (locale === 'zh-CN') out.objects[OBJ]._validations = { needs_title: { message: ZH } };
365+
return out;
366+
},
367+
};
368+
369+
function withDisabledLater(): SchemaRegistry {
370+
const reg = registry(false);
371+
reg.registerObject({ name: OBJ, validations: [{ ...RULE, message: ENABLED_SAYS }] } as any, DEP_PKG, undefined, 'extend', 200);
372+
reg.installPackage({ id: LATER_PKG, name: 'later', version: '1.0.0' } as any, 'code');
373+
reg.registerObject({ name: OBJ, validations: [{ ...RULE, message: 'Disabled says.' }] } as any, LATER_PKG, undefined, 'extend', 300);
374+
reg.disablePackage(LATER_PKG);
375+
return reg;
376+
}
377+
378+
const messagesOf = (doc: any) => doc.validations.map((r: any) => r.message);
379+
380+
it('the base carries the enabled rule the fold serves, and the zh-CN read translates it', async () => {
381+
const reg = withDisabledLater();
382+
// The premise: the fold serves the enabled extender's rule.
383+
expect(messagesOf(served(reg))).toEqual([ENABLED_SAYS]);
384+
expect(messagesOf(reg.getPackagedObjectBase(OBJ))).toEqual([ENABLED_SAYS]);
385+
const src = { ...sources(reg, 'zh-CN'), resolveI18nService: async () => rulesI18n };
386+
const out: any = await translateMetaDocument(src, 'object', served(reg));
387+
expect(messagesOf(out)).toEqual([ZH]);
388+
});
389+
});

0 commit comments

Comments
 (0)