@tiangong-lca/cli 0.0.24 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +66 -5
  2. package/dist/src/cli.js +484 -5
  3. package/dist/src/cli.js.map +1 -1
  4. package/dist/src/lib/dataset-maintenance-alias-request.js +99 -0
  5. package/dist/src/lib/dataset-maintenance-alias-request.js.map +1 -0
  6. package/dist/src/lib/dataset-maintenance-apply.js +12 -367
  7. package/dist/src/lib/dataset-maintenance-apply.js.map +1 -1
  8. package/dist/src/lib/dataset-maintenance-protected-artifacts.js +100 -0
  9. package/dist/src/lib/dataset-maintenance-protected-artifacts.js.map +1 -0
  10. package/dist/src/lib/dataset-maintenance-protected-before.js +284 -0
  11. package/dist/src/lib/dataset-maintenance-protected-before.js.map +1 -0
  12. package/dist/src/lib/dataset-maintenance-protected-contract.js +918 -0
  13. package/dist/src/lib/dataset-maintenance-protected-contract.js.map +1 -0
  14. package/dist/src/lib/dataset-maintenance-protected-freeze.js +230 -0
  15. package/dist/src/lib/dataset-maintenance-protected-freeze.js.map +1 -0
  16. package/dist/src/lib/dataset-maintenance-protected-preparation.js +524 -0
  17. package/dist/src/lib/dataset-maintenance-protected-preparation.js.map +1 -0
  18. package/dist/src/lib/dataset-maintenance-protected-run.js +667 -0
  19. package/dist/src/lib/dataset-maintenance-protected-run.js.map +1 -0
  20. package/dist/src/lib/dataset-maintenance-protected-seal.js +160 -0
  21. package/dist/src/lib/dataset-maintenance-protected-seal.js.map +1 -0
  22. package/dist/src/lib/dataset-maintenance-protected-toolchain.js +86 -0
  23. package/dist/src/lib/dataset-maintenance-protected-toolchain.js.map +1 -0
  24. package/dist/src/lib/dataset-maintenance-protected-verify.js +435 -0
  25. package/dist/src/lib/dataset-maintenance-protected-verify.js.map +1 -0
  26. package/dist/src/lib/dataset-maintenance-remote.js +116 -2
  27. package/dist/src/lib/dataset-maintenance-remote.js.map +1 -1
  28. package/package.json +1 -1
@@ -0,0 +1,435 @@
1
+ import { loadMaintenanceDesiredPayload } from './dataset-maintenance-alias-request.js';
2
+ import { isJsonObject, maintenanceRowKey, sha256Json, snapshotRemoteRow, } from './dataset-maintenance-contract.js';
3
+ import { PROTECTED_EXECUTION_COUNTS, parseProtectedDerivativeSnapshot, } from './dataset-maintenance-protected-contract.js';
4
+ import { maintenanceProjectedReferenceFingerprint } from './dataset-maintenance-plan.js';
5
+ import { isSnapshotCompletenessCompatible } from './dataset-maintenance-pagination.js';
6
+ import { fetchMaintenanceAccountRows, fetchMaintenanceDerivativeSnapshot, fetchMaintenanceDerivativeTargetRows, } from './dataset-maintenance-remote.js';
7
+ const SHA256 = /^[a-f0-9]{64}$/u;
8
+ function issue(code, message, details) {
9
+ return { code, message, ...(details === undefined ? {} : { details }) };
10
+ }
11
+ function requiredString(value) {
12
+ return typeof value === 'string' && value.trim() ? value : null;
13
+ }
14
+ export function inspectProtectedLiveDerivative(row) {
15
+ const raw = row.raw;
16
+ const jsonOrdered = isJsonObject(raw.json_ordered) ? raw.json_ordered : null;
17
+ const extractedText = requiredString(raw.extracted_text);
18
+ const extractedMd = requiredString(raw.extracted_md);
19
+ const embeddingAt = requiredString(raw.embedding_ft_at);
20
+ if (row.state_code !== 0 ||
21
+ !jsonOrdered ||
22
+ !extractedText ||
23
+ !extractedMd ||
24
+ raw.embedding_ft === null ||
25
+ raw.embedding_ft === undefined ||
26
+ !embeddingAt ||
27
+ !Number.isFinite(Date.parse(embeddingAt))) {
28
+ return null;
29
+ }
30
+ return {
31
+ table: row.table,
32
+ id: row.id,
33
+ version: row.version,
34
+ user_id: row.user_id,
35
+ state_code: 0,
36
+ json_ordered_sha256: sha256Json(jsonOrdered),
37
+ extracted_text_present: true,
38
+ extracted_md_present: true,
39
+ embedding_ft_present: true,
40
+ embedding_ft_at: embeddingAt,
41
+ };
42
+ }
43
+ function expectedFinalRows(options) {
44
+ const rows = new Map(options.rows.map((row) => [maintenanceRowKey(row), { ...row }]));
45
+ for (const action of options.plan.actions) {
46
+ const current = rows.get(maintenanceRowKey(action));
47
+ if (current) {
48
+ rows.set(maintenanceRowKey(action), {
49
+ ...current,
50
+ json_ordered: loadMaintenanceDesiredPayload(options.planDir, action),
51
+ });
52
+ }
53
+ }
54
+ return [...rows.values()].sort((left, right) => maintenanceRowKey(left).localeCompare(maintenanceRowKey(right)));
55
+ }
56
+ function verifyStatusStructure(options) {
57
+ const { identity, proof } = options;
58
+ const issues = [];
59
+ const notAdmitted = proof.execution_status === 'not_admitted';
60
+ const dispatchCountValid = proof.dispatch_count === 1 ||
61
+ (proof.dispatch_count === 0 &&
62
+ (proof.execution_status === 'failed' || proof.execution_status === 'indeterminate'));
63
+ if ((notAdmitted && (proof.attempt_count !== 0 || proof.dispatch_count !== 0)) ||
64
+ (!notAdmitted && (proof.attempt_count !== 1 || !dispatchCountValid))) {
65
+ issues.push(issue('PROTECTED_ATTEMPT_DISPATCH_COUNT_INVALID', 'Database did not prove the one-attempt, at-most-one-dispatch execution policy.', { attempt_count: proof.attempt_count, dispatch_count: proof.dispatch_count }));
66
+ }
67
+ if (proof.plan_sha256 !== identity.plan_sha256 || proof.operation_id !== identity.operation_id) {
68
+ issues.push(issue('PROTECTED_EXECUTION_IDENTITY_MISMATCH', 'Database status does not round-trip the sealed plan identity.'));
69
+ }
70
+ const categoryMatches = (proof.status === 'passed' && proof.execution_status === 'completed') ||
71
+ (proof.status === 'failed' &&
72
+ (proof.execution_status === 'failed' || proof.execution_status === 'completed')) ||
73
+ (proof.status === 'indeterminate' &&
74
+ (proof.execution_status === 'not_admitted' || proof.execution_status === 'indeterminate')) ||
75
+ (proof.status === 'pending' &&
76
+ ['dispatching', 'dispatched', 'running', 'derivatives_pending'].includes(proof.execution_status));
77
+ if (!categoryMatches) {
78
+ issues.push(issue('PROTECTED_STATUS_CATEGORY_INVALID', 'Database status category is inconsistent with its execution ledger state.', { status: proof.status, execution_status: proof.execution_status }));
79
+ }
80
+ if (!notAdmitted) {
81
+ const gateNames = proof.gates.map((gate) => gate.gate);
82
+ const receiptHashes = proof.gates.map((gate) => gate.receipt_sha256);
83
+ const gateClosureValid = proof.gate_count === 3 &&
84
+ proof.gates.length === 3 &&
85
+ new Set(gateNames).size === 3 &&
86
+ new Set(receiptHashes).size === 3 &&
87
+ proof.gates.every((gate) => gate.observed_sha256 === gate.expected_sha256 && gate.status === 'passed');
88
+ if (!gateClosureValid) {
89
+ issues.push(issue('PROTECTED_GATE_CLOSURE_INVALID', 'Database did not round-trip three unique server-captured gate receipts.', proof.gates));
90
+ }
91
+ }
92
+ return issues;
93
+ }
94
+ function verifyAuditClosure(proof) {
95
+ const audit = proof.primary_readback;
96
+ const closure = audit?.closure;
97
+ let closureHashMatches = false;
98
+ if (isJsonObject(closure) && typeof closure.live_closure_proof_sha256 === 'string') {
99
+ const proofMaterial = { ...closure };
100
+ const closureSha256 = String(proofMaterial.live_closure_proof_sha256);
101
+ delete proofMaterial.ok;
102
+ delete proofMaterial.row_count;
103
+ delete proofMaterial.exchange_count;
104
+ delete proofMaterial.live_closure_proof_sha256;
105
+ closureHashMatches = sha256Json(proofMaterial) === closureSha256;
106
+ }
107
+ if (!audit ||
108
+ audit.row_count !== PROTECTED_EXECUTION_COUNTS.action_count ||
109
+ audit.exchange_count !== PROTECTED_EXECUTION_COUNTS.exchange_count ||
110
+ audit.alias_audit_count !== PROTECTED_EXECUTION_COUNTS.audit_count ||
111
+ audit.live_closure_proof !== true ||
112
+ !isJsonObject(closure) ||
113
+ closure.schema_version !== 'dataset-alias-primary-closure.v1' ||
114
+ closure.ok !== true ||
115
+ closure.actor_user_id !== proof.actor_user_id ||
116
+ closure.batch_count !== PROTECTED_EXECUTION_COUNTS.batch_count ||
117
+ closure.action_count !== PROTECTED_EXECUTION_COUNTS.action_count ||
118
+ closure.distinct_action_count !== PROTECTED_EXECUTION_COUNTS.action_count ||
119
+ closure.flowproperty_count !== PROTECTED_EXECUTION_COUNTS.flowproperty_count ||
120
+ closure.flow_count !== PROTECTED_EXECUTION_COUNTS.flow_count ||
121
+ closure.process_count !== PROTECTED_EXECUTION_COUNTS.process_count ||
122
+ closure.support_reference_count !== 6 ||
123
+ closure.flowproperty_support_count !== 2 ||
124
+ closure.unitgroup_support_count !== 2 ||
125
+ closure.source_unitgroup_support_count !== 2 ||
126
+ closure.invalid_action_count !== 0 ||
127
+ closure.invalid_support_count !== 0 ||
128
+ !Array.isArray(closure.action_evidence) ||
129
+ closure.action_evidence.length !== PROTECTED_EXECUTION_COUNTS.action_count ||
130
+ closure.action_evidence.some((entry) => !isJsonObject(entry)) ||
131
+ !Array.isArray(closure.support_evidence) ||
132
+ closure.support_evidence.length !== 6 ||
133
+ closure.support_evidence.some((entry) => !isJsonObject(entry)) ||
134
+ closure.row_count !== PROTECTED_EXECUTION_COUNTS.action_count ||
135
+ closure.exchange_count !== PROTECTED_EXECUTION_COUNTS.exchange_count ||
136
+ closure.live_closure_proof !== true ||
137
+ !closureHashMatches) {
138
+ return [
139
+ issue('PROTECTED_AUDIT_CLOSURE_INVALID', 'Terminal execution did not prove the exact 52-row, 59-exchange, 55-audit primary closure.', audit),
140
+ ];
141
+ }
142
+ return [];
143
+ }
144
+ function terminalTargetKey(target) {
145
+ return `${target.table}\u0000${target.id}\u0000${target.version}`;
146
+ }
147
+ function verifyTerminalTargets(options) {
148
+ const issues = [];
149
+ const batch = options.proof.derivative_readback;
150
+ if (batch.proof_level !== 'causal_terminal' || batch.proof_deferred !== false) {
151
+ return [
152
+ issue('PROTECTED_DERIVATIVE_TARGET_CLOSURE_INVALID', 'Terminal proof must use the full causal-terminal evidence level.'),
153
+ ];
154
+ }
155
+ const targets = batch.targets;
156
+ const keys = targets.map(terminalTargetKey);
157
+ if (batch.schema_version !== 'dataset-derivative-rebuild-batch-status.v1' ||
158
+ batch.batch_id !== options.identity.request_id ||
159
+ batch.status !== 'completed' ||
160
+ batch.code !== 'DERIVATIVE_BATCH_COMPLETED' ||
161
+ batch.causal_terminal_proof !== true ||
162
+ batch.target_count !== PROTECTED_EXECUTION_COUNTS.derivative_target_count ||
163
+ batch.flow_count !== PROTECTED_EXECUTION_COUNTS.flow_count ||
164
+ batch.process_count !== PROTECTED_EXECUTION_COUNTS.process_count ||
165
+ batch.completed_count !== PROTECTED_EXECUTION_COUNTS.derivative_target_count ||
166
+ batch.nonterminal_count !== 0 ||
167
+ batch.failed_count !== 0 ||
168
+ batch.invalid_proof_count !== 0 ||
169
+ targets.length !== PROTECTED_EXECUTION_COUNTS.derivative_target_count ||
170
+ new Set(keys).size !== PROTECTED_EXECUTION_COUNTS.derivative_target_count ||
171
+ new Set(targets.map((target) => target.ordinal)).size !==
172
+ PROTECTED_EXECUTION_COUNTS.derivative_target_count) {
173
+ return [
174
+ issue('PROTECTED_DERIVATIVE_TARGET_CLOSURE_INVALID', 'Terminal proof must contain exactly 50 unique derivative targets.'),
175
+ ];
176
+ }
177
+ const frozen = new Map(options.identity.derivative_targets.map((target) => [terminalTargetKey(target), target]));
178
+ for (const [index, target] of targets.entries()) {
179
+ const expected = frozen.get(terminalTargetKey(target));
180
+ if (!expected ||
181
+ target.ordinal !== index + 1 ||
182
+ target.request_id === options.identity.request_id ||
183
+ target.source_baseline_snapshot_sha256 !== expected.baseline_snapshot_sha256) {
184
+ issues.push(issue('PROTECTED_DERIVATIVE_TARGET_IDENTITY_MISMATCH', 'Terminal derivative proof contains a foreign or changed target.', { table: target.table, id: target.id, version: target.version }));
185
+ continue;
186
+ }
187
+ if (target.status !== 'completed' ||
188
+ !target.phase ||
189
+ !target.completed_snapshot_sha256 ||
190
+ !SHA256.test(target.expected_snapshot_sha256) ||
191
+ !SHA256.test(target.completed_snapshot_sha256) ||
192
+ target.completed_snapshot_sha256 === target.expected_snapshot_sha256 ||
193
+ !target.primary_matches ||
194
+ !target.terminal_snapshot_matches ||
195
+ !target.proposals_committed ||
196
+ !target.derivative_fresh ||
197
+ !target.lifecycle_complete ||
198
+ !target.terminal_audit_present ||
199
+ Object.values(target.residue).some((count) => count !== 0) ||
200
+ !target.causal_terminal_proof) {
201
+ issues.push(issue('PROTECTED_DERIVATIVE_TARGET_NOT_TERMINAL', 'Derivative target lacks causal completed/live equality or retains queue, failure, or fence state.', { table: target.table, id: target.id, version: target.version }));
202
+ }
203
+ }
204
+ return issues;
205
+ }
206
+ function verifyFinalAccountRows(options) {
207
+ const issues = [];
208
+ if (!options.plan.snapshot_completeness ||
209
+ !isSnapshotCompletenessCompatible(options.completeness, options.plan.snapshot_completeness, Object.keys(options.plan.snapshot_completeness.entity_counts))) {
210
+ issues.push(issue('PROTECTED_FINAL_SNAPSHOT_INCOMPLETE', 'Final RLS account scan does not prove the same complete table census as the plan.'));
211
+ return issues;
212
+ }
213
+ const expectedKeys = new Set([
214
+ ...options.plan.actions.map(maintenanceRowKey),
215
+ ...options.plan.protected_rows.map(maintenanceRowKey),
216
+ ]);
217
+ const actualKeys = new Set(options.rows.map(maintenanceRowKey));
218
+ if (expectedKeys.size !== actualKeys.size ||
219
+ [...expectedKeys].some((key) => !actualKeys.has(key))) {
220
+ issues.push(issue('PROTECTED_FINAL_ACCOUNT_CENSUS_DRIFT', 'Final RLS account rows contain missing or unexpected entities.'));
221
+ }
222
+ const current = new Map(options.rows.map((row) => [maintenanceRowKey(row), row]));
223
+ for (const protectedRow of options.plan.protected_rows) {
224
+ const row = current.get(maintenanceRowKey(protectedRow));
225
+ if (!row || snapshotRemoteRow(row).row_sha256 !== protectedRow.row_sha256) {
226
+ issues.push(issue('PROTECTED_ROW_DRIFT', 'A protected non-action row changed.', protectedRow));
227
+ }
228
+ }
229
+ for (const action of options.plan.actions) {
230
+ const row = current.get(maintenanceRowKey(action));
231
+ const desired = loadMaintenanceDesiredPayload(options.planDir, action);
232
+ if (!row ||
233
+ row.user_id !== action.expected_user_id ||
234
+ row.state_code !== 0 ||
235
+ sha256Json(row.json_ordered) !== sha256Json(desired) ||
236
+ row.model_id !== action.before?.model_id ||
237
+ row.rule_verification !== action.before?.rule_verification) {
238
+ issues.push(issue('PROTECTED_ACTION_READBACK_MISMATCH', 'An action row does not match the desired owner-draft payload.', { action_id: action.action_id }));
239
+ }
240
+ }
241
+ const projected = expectedFinalRows({
242
+ plan: options.plan,
243
+ planDir: options.planDir,
244
+ rows: options.rows,
245
+ });
246
+ if (sha256Json(maintenanceProjectedReferenceFingerprint(projected)) !==
247
+ options.plan.projected_reference_sha256) {
248
+ issues.push(issue('PROTECTED_REFERENCE_CLOSURE_MISMATCH', 'Final reference closure does not match the frozen projected closure.'));
249
+ }
250
+ return issues;
251
+ }
252
+ function matchLiveTargets(options) {
253
+ const proofs = new Map(options.proofs.map((proof) => [terminalTargetKey(proof), proof]));
254
+ const snapshots = new Map(options.snapshots.map((snapshot) => [terminalTargetKey(snapshot), snapshot]));
255
+ const live = new Map(options.live.map((row) => [terminalTargetKey(row), row]));
256
+ const actions = new Map(options.plan.actions.map((action) => [maintenanceRowKey(action), action]));
257
+ const issues = [];
258
+ const expectedKeys = new Set(options.identity.derivative_targets.map(terminalTargetKey));
259
+ const liveKeys = options.live.map(terminalTargetKey);
260
+ const snapshotKeys = options.snapshots.map(terminalTargetKey);
261
+ if (liveKeys.length !== expectedKeys.size ||
262
+ new Set(liveKeys).size !== expectedKeys.size ||
263
+ snapshotKeys.length !== expectedKeys.size ||
264
+ new Set(snapshotKeys).size !== expectedKeys.size ||
265
+ [...expectedKeys].some((key) => !live.has(key) || !snapshots.has(key))) {
266
+ issues.push(issue('PROTECTED_DERIVATIVE_LIVE_SET_MISMATCH', 'Independent derivative rows and snapshots must be unique and exactly match all 50 frozen targets.'));
267
+ }
268
+ for (const target of options.identity.derivative_targets) {
269
+ const key = terminalTargetKey(target);
270
+ const row = live.get(key);
271
+ const proof = proofs.get(key);
272
+ const snapshot = snapshots.get(key);
273
+ const action = actions.get(key);
274
+ if (!row ||
275
+ !proof ||
276
+ !snapshot ||
277
+ !action?.desired_payload ||
278
+ row.user_id !== options.identity.actor.user_id ||
279
+ row.state_code !== 0 ||
280
+ snapshot.user_id !== options.identity.actor.user_id ||
281
+ snapshot.state_code !== 0 ||
282
+ row.json_ordered_sha256 !== action.desired_payload.sha256 ||
283
+ snapshot.json_ordered_sha256 !== row.json_ordered_sha256 ||
284
+ snapshot.snapshot_sha256 !== proof.completed_snapshot_sha256 ||
285
+ !snapshot.extracted_md_sha256 ||
286
+ !snapshot.embedding_ft_sha256 ||
287
+ !snapshot.embedding_ft_at) {
288
+ issues.push(issue('PROTECTED_DERIVATIVE_LIVE_MISMATCH', 'Independent RLS derivative readback does not match the terminal database proof.', { table: target.table, id: target.id, version: target.version }));
289
+ }
290
+ }
291
+ return issues;
292
+ }
293
+ async function fetchProtectedDerivativeSnapshots(options) {
294
+ const snapshots = [];
295
+ const targets = options.identity.derivative_targets;
296
+ for (let offset = 0; offset < targets.length; offset += 5) {
297
+ const chunk = targets.slice(offset, offset + 5);
298
+ snapshots.push(...(await Promise.all(chunk.map(async (target) => parseProtectedDerivativeSnapshot(await fetchMaintenanceDerivativeSnapshot({
299
+ context: options.context,
300
+ table: target.table,
301
+ id: target.id,
302
+ version: target.version,
303
+ }), {
304
+ table: target.table,
305
+ id: target.id,
306
+ version: target.version,
307
+ userId: target.user_id,
308
+ })))));
309
+ }
310
+ return snapshots;
311
+ }
312
+ async function verifyProtectedExecutionWithDependencies(options, dependencies) {
313
+ const { fetchAccountRows, fetchDerivativeRows, fetchSnapshots } = dependencies;
314
+ const structuralIssues = verifyStatusStructure({
315
+ identity: options.identity,
316
+ proof: options.proof,
317
+ });
318
+ if (structuralIssues.length) {
319
+ return {
320
+ status: options.proof.status === 'indeterminate' ? 'indeterminate' : 'failed',
321
+ issues: structuralIssues,
322
+ account_readback: null,
323
+ derivative_readback: null,
324
+ };
325
+ }
326
+ if (options.proof.execution_status === 'not_admitted') {
327
+ return {
328
+ status: 'indeterminate',
329
+ issues: [
330
+ issue('PROTECTED_EXECUTION_NOT_FOUND', 'The server has a protected preflight but no admitted execution; admission must not be retried.'),
331
+ ],
332
+ account_readback: null,
333
+ derivative_readback: null,
334
+ };
335
+ }
336
+ if (options.proof.status === 'pending') {
337
+ return { status: 'pending', issues: [], account_readback: null, derivative_readback: null };
338
+ }
339
+ if (options.proof.status === 'indeterminate') {
340
+ return {
341
+ status: 'indeterminate',
342
+ issues: [
343
+ issue('PROTECTED_EXECUTION_INDETERMINATE', 'Database reported an indeterminate terminal execution; admission must not be retried.', options.proof.failure),
344
+ ],
345
+ account_readback: null,
346
+ derivative_readback: null,
347
+ };
348
+ }
349
+ if (options.proof.status === 'failed') {
350
+ return {
351
+ status: 'failed',
352
+ issues: [
353
+ issue('PROTECTED_EXECUTION_FAILED', 'Database reported a definitive protected execution failure.', options.proof.failure),
354
+ ],
355
+ account_readback: null,
356
+ derivative_readback: null,
357
+ };
358
+ }
359
+ const issues = [
360
+ ...verifyAuditClosure(options.proof),
361
+ ...verifyTerminalTargets({ identity: options.identity, proof: options.proof }),
362
+ ];
363
+ if (issues.length) {
364
+ return { status: 'failed', issues, account_readback: null, derivative_readback: null };
365
+ }
366
+ const account = await fetchAccountRows({
367
+ context: options.context,
368
+ userId: options.identity.actor.user_id,
369
+ pageSize: options.pageSize,
370
+ });
371
+ issues.push(...verifyFinalAccountRows({
372
+ plan: options.plan,
373
+ planDir: options.planDir,
374
+ rows: account.rows,
375
+ completeness: account.completeness,
376
+ }));
377
+ const derivative = await fetchDerivativeRows({
378
+ context: options.context,
379
+ targets: options.identity.derivative_targets,
380
+ });
381
+ const live = derivative.rows.map(inspectProtectedLiveDerivative);
382
+ if (live.some((row) => row === null)) {
383
+ issues.push(issue('PROTECTED_DERIVATIVE_LIVE_INVALID', 'A live derivative row lacks primary JSON, extracted markdown, embedding, or timestamps.'));
384
+ }
385
+ const validLive = live.filter((row) => row !== null);
386
+ const snapshots = await fetchSnapshots({
387
+ context: options.context,
388
+ identity: options.identity,
389
+ });
390
+ if (validLive.length === PROTECTED_EXECUTION_COUNTS.derivative_target_count) {
391
+ const terminalProofs = options.proof.derivative_readback.proof_level === 'causal_terminal'
392
+ ? options.proof.derivative_readback.targets
393
+ : [];
394
+ issues.push(...matchLiveTargets({
395
+ proofs: terminalProofs,
396
+ live: validLive,
397
+ snapshots,
398
+ plan: options.plan,
399
+ identity: options.identity,
400
+ }));
401
+ }
402
+ return {
403
+ status: issues.length ? 'failed' : 'passed',
404
+ issues,
405
+ account_readback: {
406
+ rows: account.rows,
407
+ source_urls: account.source_urls,
408
+ completeness: account.completeness,
409
+ },
410
+ derivative_readback: {
411
+ rows: validLive,
412
+ snapshots,
413
+ source_urls: derivative.source_urls,
414
+ },
415
+ };
416
+ }
417
+ export async function verifyProtectedExecution(options) {
418
+ return verifyProtectedExecutionWithDependencies(options, {
419
+ fetchAccountRows: fetchMaintenanceAccountRows,
420
+ fetchDerivativeRows: fetchMaintenanceDerivativeTargetRows,
421
+ fetchSnapshots: fetchProtectedDerivativeSnapshots,
422
+ });
423
+ }
424
+ export const __testInternals = {
425
+ expectedFinalRows,
426
+ fetchProtectedDerivativeSnapshots,
427
+ inspectProtectedLiveDerivative,
428
+ matchLiveTargets,
429
+ verifyAuditClosure,
430
+ verifyFinalAccountRows,
431
+ verifyStatusStructure,
432
+ verifyTerminalTargets,
433
+ verifyProtectedExecutionWithDependencies,
434
+ };
435
+ //# sourceMappingURL=dataset-maintenance-protected-verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset-maintenance-protected-verify.js","sourceRoot":"","sources":["../../../src/lib/dataset-maintenance-protected-verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,iBAAiB,GAGlB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,GAMjC,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,wCAAwC,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAE,gCAAgC,EAAE,MAAM,qC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E,iCAAiC;KAClD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,iBAAiB;IACjB,iCAAiC;IACjC,8BAA8B;IAC9B,gBAAgB;IAChB,kBAAkB;IAClB,sBAAsB;IACtB,qBAAqB;IACrB,qBAAqB;IACrB,wCAAwC;CACzC,CAAC","sourcesContent":["import { loadMaintenanceDesiredPayload } from './dataset-maintenance-alias-request.js';\nimport {\n isJsonObject,\n maintenanceRowKey,\n sha256Json,\n snapshotRemoteRow,\n type DatasetMaintenancePlan,\n type DatasetMaintenanceRemoteRow,\n} from './dataset-maintenance-contract.js';\nimport {\n PROTECTED_EXECUTION_COUNTS,\n parseProtectedDerivativeSnapshot,\n type ProtectedDerivativeSnapshot,\n type ProtectedExecutionIdentity,\n type ProtectedExecutionStatusProof,\n type ProtectedReportStatus,\n type ProtectedTerminalTargetProof,\n} from './dataset-maintenance-protected-contract.js';\nimport { maintenanceProjectedReferenceFingerprint } from './dataset-maintenance-plan.js';\nimport { isSnapshotCompletenessCompatible } from './dataset-maintenance-pagination.js';\nimport {\n fetchMaintenanceAccountRows,\n fetchMaintenanceDerivativeSnapshot,\n fetchMaintenanceDerivativeTargetRows,\n type DatasetMaintenanceDerivativeRemoteRow,\n type DatasetMaintenanceRemoteContext,\n} from './dataset-maintenance-remote.js';\n\nconst SHA256 = /^[a-f0-9]{64}$/u;\n\nexport type ProtectedVerificationIssue = {\n code: string;\n message: string;\n details?: unknown;\n};\n\nexport type ProtectedLiveDerivativeReadback = {\n table: 'flows' | 'processes';\n id: string;\n version: string;\n user_id: string;\n state_code: 0;\n json_ordered_sha256: string;\n extracted_text_present: true;\n extracted_md_present: true;\n embedding_ft_present: true;\n embedding_ft_at: string;\n};\n\nexport type ProtectedVerificationResult = {\n status: ProtectedReportStatus;\n issues: ProtectedVerificationIssue[];\n account_readback: {\n rows: DatasetMaintenanceRemoteRow[];\n source_urls: string[];\n completeness: unknown;\n } | null;\n derivative_readback: {\n rows: ProtectedLiveDerivativeReadback[];\n snapshots: ProtectedDerivativeSnapshot[];\n source_urls: string[];\n } | null;\n};\n\nfunction issue(code: string, message: string, details?: unknown): ProtectedVerificationIssue {\n return { code, message, ...(details === undefined ? {} : { details }) };\n}\n\nfunction requiredString(value: unknown): string | null {\n return typeof value === 'string' && value.trim() ? value : null;\n}\n\nexport function inspectProtectedLiveDerivative(\n row: DatasetMaintenanceDerivativeRemoteRow,\n): ProtectedLiveDerivativeReadback | null {\n const raw = row.raw;\n const jsonOrdered = isJsonObject(raw.json_ordered) ? raw.json_ordered : null;\n const extractedText = requiredString(raw.extracted_text);\n const extractedMd = requiredString(raw.extracted_md);\n const embeddingAt = requiredString(raw.embedding_ft_at);\n if (\n row.state_code !== 0 ||\n !jsonOrdered ||\n !extractedText ||\n !extractedMd ||\n raw.embedding_ft === null ||\n raw.embedding_ft === undefined ||\n !embeddingAt ||\n !Number.isFinite(Date.parse(embeddingAt))\n ) {\n return null;\n }\n return {\n table: row.table,\n id: row.id,\n version: row.version,\n user_id: row.user_id,\n state_code: 0 as const,\n json_ordered_sha256: sha256Json(jsonOrdered),\n extracted_text_present: true,\n extracted_md_present: true,\n embedding_ft_present: true,\n embedding_ft_at: embeddingAt,\n };\n}\n\nfunction expectedFinalRows(options: {\n plan: DatasetMaintenancePlan;\n planDir: string;\n rows: DatasetMaintenanceRemoteRow[];\n}): DatasetMaintenanceRemoteRow[] {\n const rows = new Map(options.rows.map((row) => [maintenanceRowKey(row), { ...row }]));\n for (const action of options.plan.actions) {\n const current = rows.get(maintenanceRowKey(action));\n if (current) {\n rows.set(maintenanceRowKey(action), {\n ...current,\n json_ordered: loadMaintenanceDesiredPayload(options.planDir, action),\n });\n }\n }\n return [...rows.values()].sort((left, right) =>\n maintenanceRowKey(left).localeCompare(maintenanceRowKey(right)),\n );\n}\n\nfunction verifyStatusStructure(options: {\n identity: ProtectedExecutionIdentity;\n proof: ProtectedExecutionStatusProof;\n}): ProtectedVerificationIssue[] {\n const { identity, proof } = options;\n const issues: ProtectedVerificationIssue[] = [];\n const notAdmitted = proof.execution_status === 'not_admitted';\n const dispatchCountValid =\n proof.dispatch_count === 1 ||\n (proof.dispatch_count === 0 &&\n (proof.execution_status === 'failed' || proof.execution_status === 'indeterminate'));\n if (\n (notAdmitted && (proof.attempt_count !== 0 || proof.dispatch_count !== 0)) ||\n (!notAdmitted && (proof.attempt_count !== 1 || !dispatchCountValid))\n ) {\n issues.push(\n issue(\n 'PROTECTED_ATTEMPT_DISPATCH_COUNT_INVALID',\n 'Database did not prove the one-attempt, at-most-one-dispatch execution policy.',\n { attempt_count: proof.attempt_count, dispatch_count: proof.dispatch_count },\n ),\n );\n }\n if (proof.plan_sha256 !== identity.plan_sha256 || proof.operation_id !== identity.operation_id) {\n issues.push(\n issue(\n 'PROTECTED_EXECUTION_IDENTITY_MISMATCH',\n 'Database status does not round-trip the sealed plan identity.',\n ),\n );\n }\n const categoryMatches =\n (proof.status === 'passed' && proof.execution_status === 'completed') ||\n (proof.status === 'failed' &&\n (proof.execution_status === 'failed' || proof.execution_status === 'completed')) ||\n (proof.status === 'indeterminate' &&\n (proof.execution_status === 'not_admitted' || proof.execution_status === 'indeterminate')) ||\n (proof.status === 'pending' &&\n ['dispatching', 'dispatched', 'running', 'derivatives_pending'].includes(\n proof.execution_status,\n ));\n if (!categoryMatches) {\n issues.push(\n issue(\n 'PROTECTED_STATUS_CATEGORY_INVALID',\n 'Database status category is inconsistent with its execution ledger state.',\n { status: proof.status, execution_status: proof.execution_status },\n ),\n );\n }\n if (!notAdmitted) {\n const gateNames = proof.gates.map((gate) => gate.gate);\n const receiptHashes = proof.gates.map((gate) => gate.receipt_sha256);\n const gateClosureValid =\n proof.gate_count === 3 &&\n proof.gates.length === 3 &&\n new Set(gateNames).size === 3 &&\n new Set(receiptHashes).size === 3 &&\n proof.gates.every(\n (gate) => gate.observed_sha256 === gate.expected_sha256 && gate.status === 'passed',\n );\n if (!gateClosureValid) {\n issues.push(\n issue(\n 'PROTECTED_GATE_CLOSURE_INVALID',\n 'Database did not round-trip three unique server-captured gate receipts.',\n proof.gates,\n ),\n );\n }\n }\n return issues;\n}\n\nfunction verifyAuditClosure(proof: ProtectedExecutionStatusProof): ProtectedVerificationIssue[] {\n const audit = proof.primary_readback;\n const closure = audit?.closure;\n let closureHashMatches = false;\n if (isJsonObject(closure) && typeof closure.live_closure_proof_sha256 === 'string') {\n const proofMaterial = { ...closure };\n const closureSha256 = String(proofMaterial.live_closure_proof_sha256);\n delete proofMaterial.ok;\n delete proofMaterial.row_count;\n delete proofMaterial.exchange_count;\n delete proofMaterial.live_closure_proof_sha256;\n closureHashMatches = sha256Json(proofMaterial) === closureSha256;\n }\n if (\n !audit ||\n audit.row_count !== PROTECTED_EXECUTION_COUNTS.action_count ||\n audit.exchange_count !== PROTECTED_EXECUTION_COUNTS.exchange_count ||\n audit.alias_audit_count !== PROTECTED_EXECUTION_COUNTS.audit_count ||\n audit.live_closure_proof !== true ||\n !isJsonObject(closure) ||\n closure.schema_version !== 'dataset-alias-primary-closure.v1' ||\n closure.ok !== true ||\n closure.actor_user_id !== proof.actor_user_id ||\n closure.batch_count !== PROTECTED_EXECUTION_COUNTS.batch_count ||\n closure.action_count !== PROTECTED_EXECUTION_COUNTS.action_count ||\n closure.distinct_action_count !== PROTECTED_EXECUTION_COUNTS.action_count ||\n closure.flowproperty_count !== PROTECTED_EXECUTION_COUNTS.flowproperty_count ||\n closure.flow_count !== PROTECTED_EXECUTION_COUNTS.flow_count ||\n closure.process_count !== PROTECTED_EXECUTION_COUNTS.process_count ||\n closure.support_reference_count !== 6 ||\n closure.flowproperty_support_count !== 2 ||\n closure.unitgroup_support_count !== 2 ||\n closure.source_unitgroup_support_count !== 2 ||\n closure.invalid_action_count !== 0 ||\n closure.invalid_support_count !== 0 ||\n !Array.isArray(closure.action_evidence) ||\n closure.action_evidence.length !== PROTECTED_EXECUTION_COUNTS.action_count ||\n closure.action_evidence.some((entry) => !isJsonObject(entry)) ||\n !Array.isArray(closure.support_evidence) ||\n closure.support_evidence.length !== 6 ||\n closure.support_evidence.some((entry) => !isJsonObject(entry)) ||\n closure.row_count !== PROTECTED_EXECUTION_COUNTS.action_count ||\n closure.exchange_count !== PROTECTED_EXECUTION_COUNTS.exchange_count ||\n closure.live_closure_proof !== true ||\n !closureHashMatches\n ) {\n return [\n issue(\n 'PROTECTED_AUDIT_CLOSURE_INVALID',\n 'Terminal execution did not prove the exact 52-row, 59-exchange, 55-audit primary closure.',\n audit,\n ),\n ];\n }\n return [];\n}\n\nfunction terminalTargetKey(target: { table: string; id: string; version: string }): string {\n return `${target.table}\\u0000${target.id}\\u0000${target.version}`;\n}\n\nfunction verifyTerminalTargets(options: {\n identity: ProtectedExecutionIdentity;\n proof: ProtectedExecutionStatusProof;\n}): ProtectedVerificationIssue[] {\n const issues: ProtectedVerificationIssue[] = [];\n const batch = options.proof.derivative_readback;\n if (batch.proof_level !== 'causal_terminal' || batch.proof_deferred !== false) {\n return [\n issue(\n 'PROTECTED_DERIVATIVE_TARGET_CLOSURE_INVALID',\n 'Terminal proof must use the full causal-terminal evidence level.',\n ),\n ];\n }\n const targets = batch.targets;\n const keys = targets.map(terminalTargetKey);\n if (\n batch.schema_version !== 'dataset-derivative-rebuild-batch-status.v1' ||\n batch.batch_id !== options.identity.request_id ||\n batch.status !== 'completed' ||\n batch.code !== 'DERIVATIVE_BATCH_COMPLETED' ||\n batch.causal_terminal_proof !== true ||\n batch.target_count !== PROTECTED_EXECUTION_COUNTS.derivative_target_count ||\n batch.flow_count !== PROTECTED_EXECUTION_COUNTS.flow_count ||\n batch.process_count !== PROTECTED_EXECUTION_COUNTS.process_count ||\n batch.completed_count !== PROTECTED_EXECUTION_COUNTS.derivative_target_count ||\n batch.nonterminal_count !== 0 ||\n batch.failed_count !== 0 ||\n batch.invalid_proof_count !== 0 ||\n targets.length !== PROTECTED_EXECUTION_COUNTS.derivative_target_count ||\n new Set(keys).size !== PROTECTED_EXECUTION_COUNTS.derivative_target_count ||\n new Set(targets.map((target) => target.ordinal)).size !==\n PROTECTED_EXECUTION_COUNTS.derivative_target_count\n ) {\n return [\n issue(\n 'PROTECTED_DERIVATIVE_TARGET_CLOSURE_INVALID',\n 'Terminal proof must contain exactly 50 unique derivative targets.',\n ),\n ];\n }\n const frozen = new Map(\n options.identity.derivative_targets.map((target) => [terminalTargetKey(target), target]),\n );\n for (const [index, target] of targets.entries()) {\n const expected = frozen.get(terminalTargetKey(target));\n if (\n !expected ||\n target.ordinal !== index + 1 ||\n target.request_id === options.identity.request_id ||\n target.source_baseline_snapshot_sha256 !== expected.baseline_snapshot_sha256\n ) {\n issues.push(\n issue(\n 'PROTECTED_DERIVATIVE_TARGET_IDENTITY_MISMATCH',\n 'Terminal derivative proof contains a foreign or changed target.',\n { table: target.table, id: target.id, version: target.version },\n ),\n );\n continue;\n }\n if (\n target.status !== 'completed' ||\n !target.phase ||\n !target.completed_snapshot_sha256 ||\n !SHA256.test(target.expected_snapshot_sha256) ||\n !SHA256.test(target.completed_snapshot_sha256) ||\n target.completed_snapshot_sha256 === target.expected_snapshot_sha256 ||\n !target.primary_matches ||\n !target.terminal_snapshot_matches ||\n !target.proposals_committed ||\n !target.derivative_fresh ||\n !target.lifecycle_complete ||\n !target.terminal_audit_present ||\n Object.values(target.residue).some((count) => count !== 0) ||\n !target.causal_terminal_proof\n ) {\n issues.push(\n issue(\n 'PROTECTED_DERIVATIVE_TARGET_NOT_TERMINAL',\n 'Derivative target lacks causal completed/live equality or retains queue, failure, or fence state.',\n { table: target.table, id: target.id, version: target.version },\n ),\n );\n }\n }\n return issues;\n}\n\nfunction verifyFinalAccountRows(options: {\n plan: DatasetMaintenancePlan;\n planDir: string;\n rows: DatasetMaintenanceRemoteRow[];\n completeness: unknown;\n}): ProtectedVerificationIssue[] {\n const issues: ProtectedVerificationIssue[] = [];\n if (\n !options.plan.snapshot_completeness ||\n !isSnapshotCompletenessCompatible(\n options.completeness,\n options.plan.snapshot_completeness,\n Object.keys(options.plan.snapshot_completeness.entity_counts),\n )\n ) {\n issues.push(\n issue(\n 'PROTECTED_FINAL_SNAPSHOT_INCOMPLETE',\n 'Final RLS account scan does not prove the same complete table census as the plan.',\n ),\n );\n return issues;\n }\n const expectedKeys = new Set([\n ...options.plan.actions.map(maintenanceRowKey),\n ...options.plan.protected_rows.map(maintenanceRowKey),\n ]);\n const actualKeys = new Set(options.rows.map(maintenanceRowKey));\n if (\n expectedKeys.size !== actualKeys.size ||\n [...expectedKeys].some((key) => !actualKeys.has(key))\n ) {\n issues.push(\n issue(\n 'PROTECTED_FINAL_ACCOUNT_CENSUS_DRIFT',\n 'Final RLS account rows contain missing or unexpected entities.',\n ),\n );\n }\n const current = new Map(options.rows.map((row) => [maintenanceRowKey(row), row]));\n for (const protectedRow of options.plan.protected_rows) {\n const row = current.get(maintenanceRowKey(protectedRow));\n if (!row || snapshotRemoteRow(row).row_sha256 !== protectedRow.row_sha256) {\n issues.push(\n issue('PROTECTED_ROW_DRIFT', 'A protected non-action row changed.', protectedRow),\n );\n }\n }\n for (const action of options.plan.actions) {\n const row = current.get(maintenanceRowKey(action));\n const desired = loadMaintenanceDesiredPayload(options.planDir, action);\n if (\n !row ||\n row.user_id !== action.expected_user_id ||\n row.state_code !== 0 ||\n sha256Json(row.json_ordered) !== sha256Json(desired) ||\n row.model_id !== action.before?.model_id ||\n row.rule_verification !== action.before?.rule_verification\n ) {\n issues.push(\n issue(\n 'PROTECTED_ACTION_READBACK_MISMATCH',\n 'An action row does not match the desired owner-draft payload.',\n { action_id: action.action_id },\n ),\n );\n }\n }\n const projected = expectedFinalRows({\n plan: options.plan,\n planDir: options.planDir,\n rows: options.rows,\n });\n if (\n sha256Json(maintenanceProjectedReferenceFingerprint(projected)) !==\n options.plan.projected_reference_sha256\n ) {\n issues.push(\n issue(\n 'PROTECTED_REFERENCE_CLOSURE_MISMATCH',\n 'Final reference closure does not match the frozen projected closure.',\n ),\n );\n }\n return issues;\n}\n\nfunction matchLiveTargets(options: {\n proofs: ProtectedTerminalTargetProof[];\n live: ProtectedLiveDerivativeReadback[];\n snapshots: ProtectedDerivativeSnapshot[];\n plan: DatasetMaintenancePlan;\n identity: ProtectedExecutionIdentity;\n}): ProtectedVerificationIssue[] {\n const proofs = new Map(options.proofs.map((proof) => [terminalTargetKey(proof), proof]));\n const snapshots = new Map(\n options.snapshots.map((snapshot) => [terminalTargetKey(snapshot), snapshot]),\n );\n const live = new Map(options.live.map((row) => [terminalTargetKey(row), row]));\n const actions = new Map(\n options.plan.actions.map((action) => [maintenanceRowKey(action), action]),\n );\n const issues: ProtectedVerificationIssue[] = [];\n const expectedKeys = new Set(options.identity.derivative_targets.map(terminalTargetKey));\n const liveKeys = options.live.map(terminalTargetKey);\n const snapshotKeys = options.snapshots.map(terminalTargetKey);\n if (\n liveKeys.length !== expectedKeys.size ||\n new Set(liveKeys).size !== expectedKeys.size ||\n snapshotKeys.length !== expectedKeys.size ||\n new Set(snapshotKeys).size !== expectedKeys.size ||\n [...expectedKeys].some((key) => !live.has(key) || !snapshots.has(key))\n ) {\n issues.push(\n issue(\n 'PROTECTED_DERIVATIVE_LIVE_SET_MISMATCH',\n 'Independent derivative rows and snapshots must be unique and exactly match all 50 frozen targets.',\n ),\n );\n }\n for (const target of options.identity.derivative_targets) {\n const key = terminalTargetKey(target);\n const row = live.get(key);\n const proof = proofs.get(key);\n const snapshot = snapshots.get(key);\n const action = actions.get(key);\n if (\n !row ||\n !proof ||\n !snapshot ||\n !action?.desired_payload ||\n row.user_id !== options.identity.actor.user_id ||\n row.state_code !== 0 ||\n snapshot.user_id !== options.identity.actor.user_id ||\n snapshot.state_code !== 0 ||\n row.json_ordered_sha256 !== action.desired_payload.sha256 ||\n snapshot.json_ordered_sha256 !== row.json_ordered_sha256 ||\n snapshot.snapshot_sha256 !== proof.completed_snapshot_sha256 ||\n !snapshot.extracted_md_sha256 ||\n !snapshot.embedding_ft_sha256 ||\n !snapshot.embedding_ft_at\n ) {\n issues.push(\n issue(\n 'PROTECTED_DERIVATIVE_LIVE_MISMATCH',\n 'Independent RLS derivative readback does not match the terminal database proof.',\n { table: target.table, id: target.id, version: target.version },\n ),\n );\n }\n }\n return issues;\n}\n\nasync function fetchProtectedDerivativeSnapshots(options: {\n context: DatasetMaintenanceRemoteContext;\n identity: ProtectedExecutionIdentity;\n}): Promise<ProtectedDerivativeSnapshot[]> {\n const snapshots: ProtectedDerivativeSnapshot[] = [];\n const targets = options.identity.derivative_targets;\n for (let offset = 0; offset < targets.length; offset += 5) {\n const chunk = targets.slice(offset, offset + 5);\n snapshots.push(\n ...(await Promise.all(\n chunk.map(async (target) =>\n parseProtectedDerivativeSnapshot(\n await fetchMaintenanceDerivativeSnapshot({\n context: options.context,\n table: target.table,\n id: target.id,\n version: target.version,\n }),\n {\n table: target.table,\n id: target.id,\n version: target.version,\n userId: target.user_id,\n },\n ),\n ),\n )),\n );\n }\n return snapshots;\n}\n\ntype ProtectedVerificationDependencies = {\n fetchAccountRows: typeof fetchMaintenanceAccountRows;\n fetchDerivativeRows: typeof fetchMaintenanceDerivativeTargetRows;\n fetchSnapshots: typeof fetchProtectedDerivativeSnapshots;\n};\n\nasync function verifyProtectedExecutionWithDependencies(\n options: {\n plan: DatasetMaintenancePlan;\n planDir: string;\n identity: ProtectedExecutionIdentity;\n proof: ProtectedExecutionStatusProof;\n context: DatasetMaintenanceRemoteContext;\n pageSize?: number;\n },\n dependencies: ProtectedVerificationDependencies,\n): Promise<ProtectedVerificationResult> {\n const { fetchAccountRows, fetchDerivativeRows, fetchSnapshots } = dependencies;\n const structuralIssues = verifyStatusStructure({\n identity: options.identity,\n proof: options.proof,\n });\n if (structuralIssues.length) {\n return {\n status: options.proof.status === 'indeterminate' ? 'indeterminate' : 'failed',\n issues: structuralIssues,\n account_readback: null,\n derivative_readback: null,\n };\n }\n if (options.proof.execution_status === 'not_admitted') {\n return {\n status: 'indeterminate',\n issues: [\n issue(\n 'PROTECTED_EXECUTION_NOT_FOUND',\n 'The server has a protected preflight but no admitted execution; admission must not be retried.',\n ),\n ],\n account_readback: null,\n derivative_readback: null,\n };\n }\n if (options.proof.status === 'pending') {\n return { status: 'pending', issues: [], account_readback: null, derivative_readback: null };\n }\n if (options.proof.status === 'indeterminate') {\n return {\n status: 'indeterminate',\n issues: [\n issue(\n 'PROTECTED_EXECUTION_INDETERMINATE',\n 'Database reported an indeterminate terminal execution; admission must not be retried.',\n options.proof.failure,\n ),\n ],\n account_readback: null,\n derivative_readback: null,\n };\n }\n if (options.proof.status === 'failed') {\n return {\n status: 'failed',\n issues: [\n issue(\n 'PROTECTED_EXECUTION_FAILED',\n 'Database reported a definitive protected execution failure.',\n options.proof.failure,\n ),\n ],\n account_readback: null,\n derivative_readback: null,\n };\n }\n\n const issues = [\n ...verifyAuditClosure(options.proof),\n ...verifyTerminalTargets({ identity: options.identity, proof: options.proof }),\n ];\n if (issues.length) {\n return { status: 'failed', issues, account_readback: null, derivative_readback: null };\n }\n const account = await fetchAccountRows({\n context: options.context,\n userId: options.identity.actor.user_id,\n pageSize: options.pageSize,\n });\n issues.push(\n ...verifyFinalAccountRows({\n plan: options.plan,\n planDir: options.planDir,\n rows: account.rows,\n completeness: account.completeness,\n }),\n );\n const derivative = await fetchDerivativeRows({\n context: options.context,\n targets: options.identity.derivative_targets,\n });\n const live = derivative.rows.map(inspectProtectedLiveDerivative);\n if (live.some((row) => row === null)) {\n issues.push(\n issue(\n 'PROTECTED_DERIVATIVE_LIVE_INVALID',\n 'A live derivative row lacks primary JSON, extracted markdown, embedding, or timestamps.',\n ),\n );\n }\n const validLive = live.filter((row): row is ProtectedLiveDerivativeReadback => row !== null);\n const snapshots = await fetchSnapshots({\n context: options.context,\n identity: options.identity,\n });\n if (validLive.length === PROTECTED_EXECUTION_COUNTS.derivative_target_count) {\n const terminalProofs =\n options.proof.derivative_readback.proof_level === 'causal_terminal'\n ? options.proof.derivative_readback.targets\n : [];\n issues.push(\n ...matchLiveTargets({\n proofs: terminalProofs,\n live: validLive,\n snapshots,\n plan: options.plan,\n identity: options.identity,\n }),\n );\n }\n return {\n status: issues.length ? 'failed' : 'passed',\n issues,\n account_readback: {\n rows: account.rows,\n source_urls: account.source_urls,\n completeness: account.completeness,\n },\n derivative_readback: {\n rows: validLive,\n snapshots,\n source_urls: derivative.source_urls,\n },\n };\n}\n\nexport async function verifyProtectedExecution(options: {\n plan: DatasetMaintenancePlan;\n planDir: string;\n identity: ProtectedExecutionIdentity;\n proof: ProtectedExecutionStatusProof;\n context: DatasetMaintenanceRemoteContext;\n pageSize?: number;\n}): Promise<ProtectedVerificationResult> {\n return verifyProtectedExecutionWithDependencies(options, {\n fetchAccountRows: fetchMaintenanceAccountRows,\n fetchDerivativeRows: fetchMaintenanceDerivativeTargetRows,\n fetchSnapshots: fetchProtectedDerivativeSnapshots,\n });\n}\n\nexport const __testInternals = {\n expectedFinalRows,\n fetchProtectedDerivativeSnapshots,\n inspectProtectedLiveDerivative,\n matchLiveTargets,\n verifyAuditClosure,\n verifyFinalAccountRows,\n verifyStatusStructure,\n verifyTerminalTargets,\n verifyProtectedExecutionWithDependencies,\n};\n"]}