Skip to content

Commit bfa139b

Browse files
committed
test(lint): pin the object_extension door's reading of a tied or outranked name, and state it beside the build's tie exception
Claude-Session: https://claude.ai/code/session_01FEkQ5mAXtyZgMs9QwfQzXE Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7c2eeb8 commit bfa139b

6 files changed

Lines changed: 53 additions & 17 deletions

File tree

‎.changeset/33153-extension-formula-cycle.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ Skills-docs: none owed — this PR edits `content/docs/deployment/validating-met
1717

1818
**Now:** the cycle is found on the target as served (its declared fields with every kept extension's fields folded in), and each member an extension adds is refused with the object's own verdict and sentence (at the door, a name the target already serves included: the written definition is the one served) (`expression-invalid`), located at the entry: `object 'TARGET' · objectExtensions[0] · field 'FIELD' expression` (`packages[j].manifest.` prefixed in a built artifact). It runs at the `object_extension` door (`422 INVALID_METADATA`) as in `os build`.
1919

20-
**Unchanged:** a cycle among the object's own formulas, at the same location; a member the target declares on a cycle an extension closes keeps its location at the object, named once; a draft save (never gated); a stored row (judged only when it is published again). At the extension door a cycle among the target's own formulas, or a sibling package's, is not charged to the extension write, and a formula that only reads a cycle is not refused. A field two packages' extensions add at the same priority is not judged, since which definition the registry serves is registration order, so a cycle through it is not found.
20+
**Unchanged:** a cycle among the object's own formulas, at the same location; a member the target declares on a cycle an extension closes keeps its location at the object, named once; a draft save (never gated); a stored row (judged only when it is published again). At the extension door a cycle among the target's own formulas, or a sibling package's, is not charged to the extension write, and a formula that only reads a cycle is not refused. In `os build` on an object the stack declares, a field two packages' extensions add at the same priority is not judged, since which definition the registry serves is registration order, so a cycle through it is not found there; on an object the stack does not declare, the later entry's definition is judged. The publish door judges the written entry's own definition of every field it adds, whatever priority another package's extension adds the same field at, so it can refuse a tie, or an entry another package outranks, that `os build` lets through.
2121

2222
**Fix:** before building or publishing again, break the cycle: have one formula on it read stored fields, or formulas that do not read it back.

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,11 @@ through another formula, is refused as one the object declares is (#33153):
623623
the cycle is found on the target as served, each member the entry adds is
624624
located at the entry (`object 'TARGET' · objectExtensions[0] · field 'FIELD'
625625
expression`), and in `os build` a member the target declares keeps its
626-
location at the object. At the door the written entry's fields are served over
627-
the target, so a name the target already serves is refused at the entry too.
626+
location at the object. The door judges the written entry's own definition of
627+
every field it adds, so a name the target already serves is refused at the
628+
entry too, whatever priority another package's extension adds it at; `os build`
629+
judges the definition the registry serves, and on a declared object leaves out
630+
a field two packages add at the same priority.
628631

629632
**Declared enforcement that cannot run** is two rows for the mirror-image
630633
reason, and #4716 is where it split. That heading covers four rule ids, and

‎packages/lint/src/formula-cycle-issues.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export function formulaCycleIssues(
9898
* elsewhere. The build passes the names the authored target declares (the
9999
* object walk locates those at the object, so a cycle closing through a
100100
* declared formula keeps that location); the `object_extension` door passes
101-
* none, since the written entry's fields are served over everything the
102-
* target served before the write.
101+
* none, since it judges the written entry's own definition of every name the
102+
* entry adds, over everything the target served before the write.
103103
*/
104104
export function extensionFormulaLoci(
105105
target: string,

‎packages/lint/src/runtime-gate.object-formula-cycle.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,30 @@ describe('#33153 — formula cycles an object extension adds, at the object_exte
196196
]);
197197
});
198198

199+
it('the door judges the written entry\'s own definition whatever a sibling\'s priority: a tie and an outranked entry are refused there, though the build lets both through (#33494)', () => {
200+
// The door's live target carries the sibling's `s__c` as a plain field,
201+
// with no priority, and folds the written entry over it.
202+
const served = target({ s__c: { type: 'number', label: 'Sibling' } });
203+
const sibling = (priority: number) => ({ ...extension({ s__c: { type: 'number', label: 'Sibling' } }), priority });
204+
const written = (priority: number) => ({ ...extension({ s__c: formula('record.s__c * 2') }), priority });
205+
const twoPackages = (siblingPriority: number, writtenPriority: number) => ({
206+
objects: [target()],
207+
packages: [
208+
{ manifest: { objectExtensions: [sibling(siblingPriority)] } },
209+
{ manifest: { objectExtensions: [written(writtenPriority)] } },
210+
],
211+
});
212+
213+
for (const [label, siblingPriority, writtenPriority] of [['a tie', 200, 200], ['outranked', 300, 200]] as const) {
214+
const door = cycleFindings(gateExtension(written(writtenPriority), [served]).errors);
215+
expect(door.map((f) => f.where), `${label}: ${dump(door)}`).toEqual([extWhere('s__c')]);
216+
// The build drops the tied name on a declared target, and serves the
217+
// outranking sibling's number: neither leaves a cycle to name.
218+
const built = build(twoPackages(siblingPriority, writtenPriority));
219+
expect(built, `${label}: ${dump(built)}`).toEqual([]);
220+
}
221+
});
222+
199223
it('a sibling package\'s stored cycle, and a formula that only reads a cycle, are not the extension write\'s to answer for', () => {
200224
const served = target({ s_x: formula('record.s_y + 1'), s_y: formula('record.s_x + 1') });
201225
const result = gateExtension(extension({ e__c: formula('record.s_x * 2') }), [served]);

‎packages/lint/src/validate-expressions.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,13 +4187,18 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression
41874187
// the object walk's, located at the object: a cycle closing through a
41884188
// declared formula keeps that location and is named once. On the door's
41894189
// one pass `base` is the target as served BEFORE the write (other
4190-
// packages' published extension fields included) and the object walk does
4191-
// not run, while the written entry, its sole extension, is folded over it,
4192-
// so every name the entry adds is served from the entry's own record: none
4193-
// is left out there, a name the target already serves included. A member
4194-
// the target or a sibling package stored is never a name the entry adds,
4195-
// so the target's own cycle, a sibling's, and a formula that only reads a
4196-
// cycle are not this write's to answer for.
4190+
// packages' published extension fields included, carried as plain fields
4191+
// with no priority) and the object walk does not run, while the written
4192+
// entry, its sole extension, is folded over it. So the door judges the
4193+
// written entry's own definition of every name it adds, a name the target
4194+
// already serves included, and none is left out there. Where a sibling
4195+
// package adds the same name at the same priority (a tie, which the build
4196+
// drops on a declared target) or at a higher one (the build serves the
4197+
// sibling's), the door can refuse a cycle the build lets through; making
4198+
// the door read the build's winner is #33494. A member the target or a
4199+
// sibling package stored is never a name the entry adds, so the target's
4200+
// own cycle, a sibling's, and a formula that only reads a cycle are not
4201+
// this write's to answer for.
41974202
const ownNames = new Set(base && !extensionWrite ? fieldEntries(base).map(([n]) => n) : []);
41984203
issues.push(...formulaCycleIssues(target, fieldDefs, extensionFormulaLoci(target, entries, ownNames)));
41994204
}

‎packages/spec/src/migrations/entries/semantic/18.object-extension-formula-cycle-refused.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ export const entry: SemanticMigration = {
3030
+ 'such a cycle among an object\'s declared formulas only, so one an extension adds was accepted and showed only '
3131
+ 'when records were read. It is now refused with the verdict and the sentence the object\'s own cycle gets '
3232
+ '(`expression-invalid`; at the door `422 INVALID_METADATA`), on each member the extension adds, located at the '
33-
+ 'entry; a member the object declares keeps its location at the object. One exception: a field two packages\' '
34-
+ 'extensions add at the same priority is not judged, since which definition the registry serves is registration '
35-
+ 'order, so a cycle through such a field is not found.',
33+
+ 'entry; a member the object declares keeps its location at the object. In `os build` one exception holds on '
34+
+ 'an object the stack declares: a field two packages\' extensions add at the same priority is not judged, since '
35+
+ 'which definition the registry serves is registration order, so a cycle through such a field is not found '
36+
+ 'there (on an object the stack does not declare the later entry\'s definition is judged). The publish door '
37+
+ 'judges the written entry\'s own definition of every field it adds, whatever priority another package\'s '
38+
+ 'extension adds the same field at, so it can refuse a tie, or an entry another package outranks, that `os '
39+
+ 'build` lets through.',
3640
acceptanceCriteria:
3741
'`os build` reports no `expression-invalid` finding naming a formula cycle at an `objectExtensions` entry, and '
3842
+ 'publishing each such extension again answers 200 with no such issue. Each of its formulas reads a computed '
39-
+ 'value on every row, save a cycle through a field two packages add at the same priority, which neither door '
40-
+ 'judges.',
43+
+ 'value on every row, save, in `os build` on a declared object, a cycle through a field two packages add at the '
44+
+ 'same priority, which the build does not judge.',
4145
};

0 commit comments

Comments
 (0)