Skip to content

Commit e71c70e

Browse files
test(app-shell): spell the __proto__ instrument fixture as a computed key (#6544)
`fields: { __proto__: … }` in an object literal is the Annex B.3.1 prototype setter: it sets `[[Prototype]]` and creates no own key, so the instrument assertion was parsing `fields: {}` and asserting an empty field map is legal. It would have stayed green if `ObjectSchema` began refusing the name. Spell the fixture `['__proto__']` so it carries the key it claims to, and pin the literal-versus-computed distinction as an executable control rather than a comment, mirroring `MetadataFieldsPage.fieldsMapKeying.test.tsx`. The two request-byte assertions are honest already — they read `JSON.parse` output, where `__proto__` is an own property — and keep their assertions; one comment records why that provenance is what makes them honest. Claude-Session: https://claude.ai/code/session_011SfZeFWrhGLHmfq61xbz4q Co-authored-by: Claude <noreply@anthropic.com>
1 parent b49f9a1 commit e71c70e

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
---
3+
4+
Test-only (objectui#6524): the `__proto__` instrument fixture in
5+
`MetadataService.objectPayloadFieldsMap.test.ts` was spelled as a plain object
6+
literal, which per Annex B.3.1 sets the prototype instead of adding a key — so
7+
the assertion parsed an empty `fields` map and would have stayed green if the
8+
spec began refusing the name. Respelled as a computed key and pinned with the
9+
literal-versus-computed control. No published behaviour changes.

‎packages/app-shell/src/services/MetadataService.objectPayloadFieldsMap.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,17 @@ describe('the instrument', () => {
152152
it('keys the record with a snake_case rule — `__proto__` is a LEGAL field name', () => {
153153
// Which is why `toFieldsMap` builds through `Object.fromEntries`: plain
154154
// assignment would invoke the prototype setter and drop the field silently.
155-
expect(ObjectSchema.safeParse({ name: 'account', label: 'Account', fields: { __proto__: { type: 'text', label: 'P' } } }).success).toBe(true);
155+
//
156+
// The fixture below spells the key `['__proto__']` DELIBERATELY, and the
157+
// two controls are why (objectui#6524). Per Annex B.3.1 a PLAIN
158+
// `{ __proto__: v }` inside an object literal SETS THE PROTOTYPE and adds
159+
// no own key, so the plainly-spelled fixture this test used to carry handed
160+
// `fields: {}` to the schema: green, and green forever, even if the spec
161+
// began refusing the name. Only the computed form reaches the key rule this
162+
// test claims to pin.
163+
expect(Object.keys({ __proto__: { type: 'text', label: 'P' } })).toEqual([]);
164+
expect(Object.keys({ ['__proto__']: { type: 'text', label: 'P' } })).toEqual(['__proto__']);
165+
expect(ObjectSchema.safeParse({ name: 'account', label: 'Account', fields: { ['__proto__']: { type: 'text', label: 'P' } } }).success).toBe(true);
156166
expect(issuesOf(ObjectSchema.safeParse({ name: 'account', label: 'Account', fields: { firstName: { type: 'text', label: 'F' } } }))).toEqual([
157167
'invalid_key @ fields.firstName',
158168
]);
@@ -359,6 +369,9 @@ describe('objectui#6240 · a field with no name FAILS LOUDLY, and nothing is sen
359369
{ name: 'amount', type: 'number', label: 'Amount' },
360370
]);
361371
expect(Object.keys(fieldsOf(puts))).toEqual(['__proto__', 'amount']);
372+
// Honest ONLY because `fieldsOf` reads `JSON.parse` of the captured bytes,
373+
// where `__proto__` is an own property: a refactor that built this object
374+
// from a literal instead would turn the read below into a prototype read.
362375
expect(fieldsOf(puts).__proto__).toMatchObject({ type: 'text', label: 'Proto' });
363376
});
364377
});

0 commit comments

Comments
 (0)