Skip to content

Commit 96d897b

Browse files
committed
test(metadata-protocol): a stored row's package is its column's
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5mBUwWJMnLUdKBYraT
1 parent 4735e7b commit 96d897b

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// [#28594] `storedOverlayEntries` serves a stored row's `_packageId` from the
4+
// row's `package_id` COLUMN, never from its body: a body stamp is replaced by
5+
// the column's package, or dropped when the row is bound to no package. Every
6+
// reader of the list (the connector materializer judging whose root a file ref
7+
// reads among them) asks an item's owner of `_packageId`.
8+
9+
import { describe, it, expect } from 'vitest';
10+
import { storedOverlayEntries } from './protocol-stored-overlay-reads.js';
11+
12+
const host = { convertStoredItem: (_type: string, body: unknown) => body };
13+
const parse = (records: any[]) => storedOverlayEntries.call(host, { type: 'connector' }, records);
14+
const row = (body: Record<string, unknown>, packageId: string | null) => ({
15+
type: 'connector', name: String(body.name), metadata: JSON.stringify(body), package_id: packageId,
16+
});
17+
18+
describe('#28594 — a stored row\'s package is its column\'s', () => {
19+
it('a body stamp on a row bound to no package is dropped', () => {
20+
const [entry] = parse([row({ name: 'a', _packageId: 'com.acme.host' }, null)]);
21+
expect(entry!.packageId).toBeUndefined();
22+
expect(entry!.data).not.toHaveProperty('_packageId');
23+
});
24+
25+
it('a body stamp naming another package is replaced by the column\'s', () => {
26+
const [entry] = parse([row({ name: 'a', _packageId: 'com.acme.host' }, 'com.acme.authored')]);
27+
expect(entry!.packageId).toBe('com.acme.authored');
28+
expect(entry!.data._packageId).toBe('com.acme.authored');
29+
});
30+
31+
it('control: a body with no stamp is stamped from its column, and an agreeing stamp is kept', () => {
32+
const [bound, agreeing, unbound] = parse([
33+
row({ name: 'a' }, 'com.acme.authored'),
34+
row({ name: 'b', _packageId: 'com.acme.authored' }, 'com.acme.authored'),
35+
row({ name: 'c' }, null),
36+
]);
37+
expect(bound!.data._packageId).toBe('com.acme.authored');
38+
expect(agreeing!.data._packageId).toBe('com.acme.authored');
39+
expect(unbound!.data).not.toHaveProperty('_packageId');
40+
});
41+
42+
it('a row whose metadata is an object is not written: the served body is a copy', () => {
43+
const body = { name: 'a', _packageId: 'com.acme.host' };
44+
const [entry] = parse([{ type: 'connector', name: 'a', metadata: body, package_id: null }]);
45+
expect(entry!.data).not.toHaveProperty('_packageId');
46+
expect(body._packageId).toBe('com.acme.host');
47+
});
48+
});

0 commit comments

Comments
 (0)