Skip to content

Commit 9d3a09c

Browse files
committed
chore(plugin-audit,metadata-protocol): gate hygiene for the content-hash family (#21207)
Record the new pinned engine doubles in the engine-double ledger, read the decision-audit code column through an operator-form predicate (a read, not a stamp), and mark the persisted audit vocabulary in the new pins. Claude-Session: https://claude.ai/code/session_01VvcEokUG1tvVxkceYfR5XB Co-authored-by: Claude <noreply@anthropic.com>
1 parent 27b5332 commit 9d3a09c

5 files changed

Lines changed: 46 additions & 8 deletions

File tree

‎packages/metadata-protocol/src/protocol.served-content-hash.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ describe('[#21207] inbound version tokens are compared in keyed form', () => {
299299
await p.saveMetaItem({ ...ref, item: viewBody('v2'), parentVersion: v1.version } as any);
300300
await rejection(() => p.saveMetaItem({ ...ref, item: viewBody('lost'), parentVersion: v1.version } as any));
301301

302-
const denials = h.auditRows.filter((a) => a.code === 'metadata_conflict');
302+
const denials = h.auditRows.filter((a) => a.code === 'metadata_conflict'); // adr0112-ok: D6b persisted audit column
303303
expect(denials).toHaveLength(1);
304304
const note = String(denials[0]!.note);
305305
expect(note).not.toMatch(SHA256);

‎packages/plugins/plugin-audit/src/audit-writers.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,7 +2371,9 @@ describe('[#21207] stored metadata copies carry no content hash', () => {
23712371
await fire('afterUpdate', {
23722372
object: 'sys_metadata_audit',
23732373
input: { id: 'd-1', data: { note: 'expected parent (withheld) but current is (withheld)' } },
2374+
// adr0112-ok: D6b persisted audit column
23742375
previous: { id: 'd-1', code: 'metadata_conflict', note: `expected parent ${PARENT} but current is ${HASH}` },
2376+
// adr0112-ok: D6b persisted audit column
23752377
result: { id: 'd-1', code: 'metadata_conflict', note: 'expected parent (withheld) but current is (withheld)' },
23762378
session: {},
23772379
});

‎packages/plugins/plugin-audit/src/stored-metadata-body-migration.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export function withheldStoredHashTokens(text: string): string {
100100
export const METADATA_DECISION_AUDIT_OBJECT = 'sys_metadata_audit';
101101

102102
/** The persisted code of an optimistic-concurrency refusal's decision-audit row. */
103+
// adr0112-ok: D6b — the persisted audit column's own vocabulary, not a wire code
103104
const CONFLICT_NOTE_CODE = 'metadata_conflict';
104105

105106
/** The conflict note's one sentence, as every writer of it has spelled it. */
@@ -404,7 +405,10 @@ export async function migrateStoredMetadataBodyCopies(
404405
const copiedObjects = [...STORED_METADATA_BODY_OBJECTS, METADATA_DECISION_AUDIT_OBJECT];
405406
const tables: ReadonlyArray<{ object: string; where: Record<string, unknown> }> = [
406407
...STORED_METADATA_BODY_AUDIT_OBJECTS.map((object) => ({ object, where: { object_name: { $in: copiedObjects } } })),
407-
{ object: METADATA_DECISION_AUDIT_OBJECT, where: { code: CONFLICT_NOTE_CODE } },
408+
// A PREDICATE on the persisted `code` column (ADR-0112 D6b, the audit
409+
// column's own vocabulary), written in operator form: it reads rows by the
410+
// code they carry and stamps none.
411+
{ object: METADATA_DECISION_AUDIT_OBJECT, where: { code: { $eq: CONFLICT_NOTE_CODE } } },
408412
];
409413
for (const { object, where } of tables) {
410414
report.byObject[object] = { scanned: 0, rewritten: 0 };

‎packages/plugins/plugin-audit/src/stored-metadata-hash-migration.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const metaSnapshot = () => ({ id: 'm1', name: 'v', type: 'view', scope: 'platfor
3535
const historySnapshot = () => ({ id: 'h1', name: 'v', type: 'view', metadata: view('one'), checksum: HASH, previous_checksum: PARENT });
3636
const conflictNote = `expected parent ${PARENT} but current is ${HASH}`;
3737
const WITHHELD_NOTE = 'expected parent (withheld) but current is (withheld)';
38+
/** The decision-audit `code` column's own vocabulary (ADR-0112 D6b), not an error code. */
39+
const CONFLICT_CODE = 'metadata_conflict'; // adr0112-ok: D6b persisted audit column
3840

3941
describe('planAuditRowPatch / planActivityRowPatch — the hash columns leave the copy', () => {
4042
it('a sys_metadata create snapshot loses its checksum, and nothing else', () => {
@@ -83,22 +85,22 @@ describe('planAuditRowPatch / planActivityRowPatch — the hash columns leave th
8385

8486
describe('planDecisionNotePatch — the decision-audit note and its copies', () => {
8587
it('withholds both hashes of a conflict note', () => {
86-
const patch = planDecisionNotePatch('sys_metadata_audit', { id: 'd1', code: 'metadata_conflict', note: conflictNote });
88+
const patch = planDecisionNotePatch('sys_metadata_audit', { id: 'd1', code: CONFLICT_CODE, note: conflictNote });
8789
expect(patch).toEqual({ note: WITHHELD_NOTE });
8890
});
8991

9092
it('keeps a null side as null', () => {
91-
const patch = planDecisionNotePatch('sys_metadata_audit', { id: 'd2', code: 'metadata_conflict', note: `expected parent null but current is ${HASH}` });
93+
const patch = planDecisionNotePatch('sys_metadata_audit', { id: 'd2', code: CONFLICT_CODE, note: `expected parent null but current is ${HASH}` });
9294
expect(patch).toEqual({ note: 'expected parent null but current is (withheld)' });
9395
});
9496

9597
it('leaves every other note alone, and is idempotent', () => {
9698
expect(planDecisionNotePatch('sys_metadata_audit', { id: 'd3', code: 'ok', note: 'restored from version 2' })).toBeNull();
97-
expect(planDecisionNotePatch('sys_metadata_audit', { id: 'd4', code: 'metadata_conflict', note: WITHHELD_NOTE })).toBeNull();
99+
expect(planDecisionNotePatch('sys_metadata_audit', { id: 'd4', code: CONFLICT_CODE, note: WITHHELD_NOTE })).toBeNull();
98100
});
99101

100102
it('rewrites the ledger and activity copies of a conflict note', () => {
101-
const snapshot = { id: 'd1', type: 'view', name: 'v', operation: 'save', outcome: 'denied', code: 'metadata_conflict', note: conflictNote };
103+
const snapshot = { id: 'd1', type: 'view', name: 'v', operation: 'save', outcome: 'denied', code: CONFLICT_CODE, note: conflictNote };
102104
const audit = planDecisionNotePatch('sys_audit_log', {
103105
id: 'a5', object_name: 'sys_metadata_audit', record_id: 'd1', new_value: JSON.stringify(snapshot), old_value: null,
104106
});
@@ -139,12 +141,12 @@ describe('migrateStoredMetadataBodyCopies — the content-hash copies (driven)',
139141
sys_metadata: [{ id: 'm1', type: 'view', name: 'v' }],
140142
sys_audit_log: [
141143
{ id: 'a1', object_name: 'sys_metadata', record_id: 'm1', new_value: JSON.stringify(metaSnapshot()), old_value: null },
142-
{ id: 'a2', object_name: 'sys_metadata_audit', record_id: 'd1', new_value: JSON.stringify({ id: 'd1', code: 'metadata_conflict', note: conflictNote }), old_value: null },
144+
{ id: 'a2', object_name: 'sys_metadata_audit', record_id: 'd1', new_value: JSON.stringify({ id: 'd1', code: CONFLICT_CODE, note: conflictNote }), old_value: null },
143145
{ id: 'a3', object_name: 'file_blob', record_id: 'f1', new_value: JSON.stringify({ id: 'f1', checksum: HASH }), old_value: null },
144146
],
145147
sys_activity: [{ id: 'ac1', object_name: 'sys_metadata_history', record_id: 'h1', metadata: JSON.stringify({ old: null, new: historySnapshot() }) }],
146148
sys_metadata_audit: [
147-
{ id: 'd1', code: 'metadata_conflict', note: conflictNote },
149+
{ id: 'd1', code: CONFLICT_CODE, note: conflictNote },
148150
{ id: 'd2', code: 'ok', note: 'active' },
149151
],
150152
});

‎scripts/engine-double-contract.pinned.json‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@
486486
"verb": "update",
487487
"pinned": 1
488488
},
489+
{
490+
"file": "packages/metadata-protocol/src/protocol.data-door-stored-content-hash.test.ts",
491+
"verb": "findOne",
492+
"pinned": 2
493+
},
489494
{
490495
"file": "packages/metadata-protocol/src/protocol.data-door-stored-metadata-redaction.test.ts",
491496
"verb": "findOne",
@@ -1331,6 +1336,21 @@
13311336
"verb": "update",
13321337
"pinned": 1
13331338
},
1339+
{
1340+
"file": "packages/metadata-protocol/src/protocol.served-content-hash.test.ts",
1341+
"verb": "delete",
1342+
"pinned": 1
1343+
},
1344+
{
1345+
"file": "packages/metadata-protocol/src/protocol.served-content-hash.test.ts",
1346+
"verb": "findOne",
1347+
"pinned": 1
1348+
},
1349+
{
1350+
"file": "packages/metadata-protocol/src/protocol.served-content-hash.test.ts",
1351+
"verb": "update",
1352+
"pinned": 1
1353+
},
13341354
{
13351355
"file": "packages/metadata-protocol/src/protocol.stored-conversions.test.ts",
13361356
"verb": "delete",
@@ -2491,6 +2511,16 @@
24912511
"verb": "update",
24922512
"pinned": 1
24932513
},
2514+
{
2515+
"file": "packages/plugins/plugin-audit/src/stored-metadata-hash-migration.test.ts",
2516+
"verb": "findOne",
2517+
"pinned": 1
2518+
},
2519+
{
2520+
"file": "packages/plugins/plugin-audit/src/stored-metadata-hash-migration.test.ts",
2521+
"verb": "update",
2522+
"pinned": 1
2523+
},
24942524
{
24952525
"file": "packages/plugins/plugin-auth/src/accept-invitation-adopt-membership.test.ts",
24962526
"verb": "delete",

0 commit comments

Comments
 (0)