Skip to content

Commit 2f31768

Browse files
committed
test(objectql): a kept own ref leaves the column out of the statement
Claude-Session: https://claude.ai/code/session_01L6bhgUCizoYWQVJWjhdR6F Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3c7504c commit 2f31768

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎packages/objectql/src/secret-field-own-ref-write.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function makeDriver() {
3535
return (row[k] ?? null) === (v ?? null);
3636
});
3737
const copy = (r: Row | undefined) => (r == null ? r : { ...r });
38+
/** The payload of every record statement, in order: which columns a write actually rewrote. */
39+
const statements: Array<{ object: string; data: Row }> = [];
3840
let n = 0;
3941
const driver: any = {
4042
name: 'memory', version: '0.0.0', supports: {},
@@ -52,11 +54,13 @@ function makeDriver() {
5254
return copy(row);
5355
},
5456
async update(o: string, id: string, data: Row) {
57+
statements.push({ object: o, data: { ...data } });
5558
const row = { ...storeFor(o).get(String(id)), ...data, id };
5659
storeFor(o).set(String(id), row);
5760
return copy(row);
5861
},
5962
async updateMany(o: string, ast: any, data: Row) {
63+
statements.push({ object: o, data: { ...data } });
6064
let k = 0;
6165
for (const [id, row] of storeFor(o)) {
6266
if (!matches(row, ast?.where)) continue;
@@ -71,7 +75,11 @@ function makeDriver() {
7175
async bulkUpdate() { return []; }, async bulkDelete() {},
7276
async beginTransaction() { return {}; }, async commit() {}, async rollback() {},
7377
};
74-
return { driver, rowsOf: (o: string) => Array.from(storeFor(o).values()) };
78+
return {
79+
driver,
80+
rowsOf: (o: string) => Array.from(storeFor(o).values()),
81+
lastStatement: (o: string) => [...statements].reverse().find((s) => s.object === o)?.data,
82+
};
7583
}
7684

7785
function makeCrypto(): ICryptoProvider & { encrypts: () => number } {
@@ -208,6 +216,9 @@ describe('[#27582] a non-system write may only seal a new value or keep its own
208216
const before = secrets().map((s) => s.id);
209217
await engine.update(VAULT, { id: 'r1', name: 'renamed', token: own }, USER);
210218
expect(stored('r1')).toMatchObject({ name: 'renamed', token: own });
219+
// Kept, not rewritten: the statement leaves the column alone, as for the echoed mask.
220+
expect(d.lastStatement(VAULT)).toMatchObject({ name: 'renamed' });
221+
expect(d.lastStatement(VAULT)).not.toHaveProperty('token');
211222
expect(secrets().map((s) => s.id)).toEqual(before);
212223
expect(await engine.resolveSecretField(VAULT, 'r1', 'token')).toBe('mine');
213224
});
@@ -282,6 +293,7 @@ describe('[#27582] a non-system write may only seal a new value or keep its own
282293
expect(refOf('r2')).toBe(shared);
283294
await engine.update(VAULT, { name: 'renamed', token: shared }, multi({ tier: 'gold' }));
284295
expect(d.rowsOf(VAULT).map((r) => [r.name, r.token])).toEqual([['renamed', shared], ['renamed', shared]]);
296+
expect(d.lastStatement(VAULT)).not.toHaveProperty('token');
285297
expect(await engine.resolveSecretField(VAULT, 'r2', 'token')).toBe('shared');
286298
});
287299

0 commit comments

Comments
 (0)