@tiangong-lca/foundry 0.1.17 → 0.1.19
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.
- package/README.md +23 -7
- package/docs/architecture.md +15 -3
- package/docs/foundry-task-contracts.md +27 -3
- package/docs/package-distribution-contract.md +45 -13
- package/docs/public-runtime-contract.md +85 -5
- package/docs/runtime-context-contract.md +22 -4
- package/docs/task-authorization-contract.md +15 -3
- package/docs/workspace-migration-contract.md +5 -3
- package/package-dist/assets/foundry-package-descriptor.json +541 -177
- package/package-dist/scripts/foundry-facade.d.ts +5 -0
- package/package-dist/scripts/foundry-facade.js +261 -16
- package/package-dist/scripts/foundry-runtime.d.ts +2 -2
- package/package-dist/scripts/lib/bundle-sample-utils.d.ts +4 -4
- package/package-dist/scripts/lib/bundle-source-context.d.ts +6 -4
- package/package-dist/scripts/lib/bundle-source-context.js +10 -8
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +18 -6
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +72 -1
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +123 -3
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +11 -1
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +65 -9
- package/package-dist/scripts/lib/foundry-assessment-producer.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-assessment-producer.js +167 -0
- package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -1
- package/package-dist/scripts/lib/foundry-command-metadata.js +6 -1
- package/package-dist/scripts/lib/foundry-curation-queue.d.ts +73 -0
- package/package-dist/scripts/lib/foundry-curation-queue.js +261 -0
- package/package-dist/scripts/lib/foundry-decision-owners.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-decision-owners.js +15 -7
- package/package-dist/scripts/lib/foundry-edge-draft-admission.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-edge-draft-admission.js +94 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.d.ts +47 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.js +268 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.js +154 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.d.ts +51 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.js +184 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.d.ts +21 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +120 -0
- package/package-dist/scripts/lib/foundry-edge-session.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-edge-session.js +69 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.d.ts +69 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.js +245 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.d.ts +115 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.js +259 -0
- package/package-dist/scripts/lib/foundry-edge-support.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-edge-support.js +188 -0
- package/package-dist/scripts/lib/foundry-execution-admission.d.ts +4 -2
- package/package-dist/scripts/lib/foundry-execution-admission.js +28 -3
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.d.ts +30 -0
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.js +102 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.js +126 -13
- package/package-dist/scripts/lib/foundry-identity-stage-input.d.ts +24 -0
- package/package-dist/scripts/lib/foundry-identity-stage-input.js +122 -0
- package/package-dist/scripts/lib/foundry-identity-stage-state.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-identity-stage-state.js +48 -0
- package/package-dist/scripts/lib/foundry-installed-entry.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-installed-entry.js +173 -0
- package/package-dist/scripts/lib/foundry-managed-adoption.d.ts +12 -0
- package/package-dist/scripts/lib/foundry-managed-adoption.js +108 -0
- package/package-dist/scripts/lib/foundry-managed-authentication.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-managed-authentication.js +28 -0
- package/package-dist/scripts/lib/foundry-managed-host.js +14 -2
- package/package-dist/scripts/lib/foundry-migration-transfer-io.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-migration-transfer-io.js +27 -3
- package/package-dist/scripts/lib/foundry-operation-result.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-operation-result.js +1 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +16 -16
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +34 -7
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +20 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +42 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-package-contract.js +10 -2
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +96 -3
- package/package-dist/scripts/lib/foundry-process-mass-balance.d.ts +64 -0
- package/package-dist/scripts/lib/foundry-process-mass-balance.js +224 -0
- package/package-dist/scripts/lib/foundry-process-qa.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-process-qa.js +423 -0
- package/package-dist/scripts/lib/foundry-quality-review-context.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-quality-review-context.js +18 -0
- package/package-dist/scripts/lib/foundry-quality-review-input.d.ts +48 -0
- package/package-dist/scripts/lib/foundry-quality-review-input.js +284 -0
- package/package-dist/scripts/lib/foundry-quality-review-lineage.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-quality-review-lineage.js +123 -0
- package/package-dist/scripts/lib/foundry-quality-review.d.ts +112 -0
- package/package-dist/scripts/lib/foundry-quality-review.js +487 -0
- package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
- package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.js +18 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.js +22 -2
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
- package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
- package/package-dist/scripts/lib/foundry-task-authorization.d.ts +2 -1
- package/package-dist/scripts/lib/foundry-task-authorization.js +32 -11
- package/package-dist/scripts/lib/foundry-task-registration.js +4 -5
- package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.d.ts +28 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.js +250 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption.d.ts +60 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption.js +549 -0
- package/package-dist/scripts/lib/foundry-task-store.d.ts +4 -1
- package/package-dist/scripts/lib/foundry-task-store.js +113 -4
- package/package-dist/scripts/lib/foundry-task-types.d.ts +2 -1
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.d.ts +76 -0
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.js +237 -0
- package/package-dist/scripts/lib/foundry-typed-context.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-typed-context.js +79 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.d.ts +166 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.js +226 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.js +59 -0
- package/package-dist/scripts/lib/foundry-validation-reference-context.d.ts +8 -0
- package/package-dist/scripts/lib/foundry-validation-reference-context.js +115 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +165 -34
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +99 -5
- package/package-dist/scripts/lib/foundry-workflow-child-failure.d.ts +44 -0
- package/package-dist/scripts/lib/foundry-workflow-child-failure.js +439 -0
- package/package-dist/scripts/lib/foundry-workflow-context.js +92 -22
- package/package-dist/scripts/lib/foundry-workflow-execution.js +54 -5
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +64 -3
- package/package-dist/scripts/lib/foundry-workflow-identity-recovery.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-recovery.js +450 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.d.ts +9 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +717 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.js +26 -11
- package/package-dist/scripts/lib/foundry-workflow-io.d.ts +7 -1
- package/package-dist/scripts/lib/foundry-workflow-io.js +102 -16
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
- package/package-dist/scripts/lib/foundry-workflow-repair.js +53 -2
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +65 -31
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-workflow-state.js +165 -22
- package/package-dist/scripts/lib/identity-preflight-artifacts.d.ts +4 -7
- package/package-dist/scripts/lib/identity-preflight-artifacts.js +18 -5
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +6 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +92 -13
- package/package-dist/scripts/lib/identity-preflight-recovery-proof.d.ts +78 -0
- package/package-dist/scripts/lib/identity-preflight-recovery-proof.js +415 -0
- package/package-dist/scripts/lib/import-curation/curation-cleanup.d.ts +9 -1
- package/package-dist/scripts/lib/import-curation/curation-cleanup.js +39 -2
- package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/curation-gate.js +19 -1
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.js +11 -2
- package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.js +4 -1
- package/package-dist/scripts/package-entry.js +2 -3
- package/package-dist/scripts/public-api.d.ts +5 -0
- package/package-dist/scripts/public-api.js +2 -0
- package/package-dist/scripts/runtime-entry.d.ts +2 -0
- package/package-dist/scripts/runtime-entry.js +42 -15
- package/package.json +6 -2
- package/specs/schemas/foundry-identity-stage-input.schema.json +47 -0
- package/specs/schemas/foundry-managed-adoption.schema.json +40 -0
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-operation-result.schema.json +1 -0
- package/specs/schemas/foundry-package-descriptor.schema.json +6 -2
- package/specs/schemas/foundry-quality-review-draft.schema.json +271 -0
- package/specs/schemas/foundry-quality-review-input.schema.json +271 -0
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { createFileArtifactFact, createFoundryCommandSpec } from "./foundry-command-spec.js";
|
|
5
|
+
import { sha256Json, sha256Text, stableJson, parseFreshIntentBoundAuthReceipt, } from "./identity-preflight-proof.js";
|
|
6
|
+
/** Compare retained executable dependencies with the independent current/transition inventory. */
|
|
7
|
+
export function verifyRetainedIdentityCliInventory(value, bin) {
|
|
8
|
+
if (value.role !== "current_retained_cli_inventory" ||
|
|
9
|
+
!path.isAbsolute(value.root) ||
|
|
10
|
+
fs.realpathSync(value.root) !== value.root ||
|
|
11
|
+
fs.realpathSync(bin) !== path.join(value.root, "bin/tiangong-lca.js") ||
|
|
12
|
+
!Array.isArray(value.files) ||
|
|
13
|
+
value.files.length < 1 ||
|
|
14
|
+
value.files.length > 10_000 ||
|
|
15
|
+
sha256Text(JSON.stringify(value.files)) !== value.content_sha256 ||
|
|
16
|
+
new Set(value.files.map((file) => file.path)).size !== value.files.length)
|
|
17
|
+
throw new Error("Retained CLI inventory is invalid.");
|
|
18
|
+
for (const fact of value.files) {
|
|
19
|
+
const file = path.resolve(value.root, fact.path);
|
|
20
|
+
if (path.isAbsolute(fact.path) ||
|
|
21
|
+
!file.startsWith(value.root + path.sep) ||
|
|
22
|
+
fs.realpathSync(file) !== file)
|
|
23
|
+
throw new Error("Retained CLI inventory path changed.");
|
|
24
|
+
readIdentityRecoveryFact({ ...fact, path: file });
|
|
25
|
+
}
|
|
26
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(value.root, "package.json"), "utf8"));
|
|
27
|
+
if (pkg.name !== "@tiangong-lca/cli" || pkg.version !== value.package_version)
|
|
28
|
+
throw new Error("Retained CLI package identity changed.");
|
|
29
|
+
}
|
|
30
|
+
/** Current readback of a retained executable; it does not claim a query-time runtime capture. */
|
|
31
|
+
export function observeRetainedIdentityExecutable(file) {
|
|
32
|
+
let fd;
|
|
33
|
+
try {
|
|
34
|
+
if (!path.isAbsolute(file) || fs.realpathSync(file) !== file)
|
|
35
|
+
return null;
|
|
36
|
+
fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
37
|
+
const before = fs.fstatSync(fd, { bigint: true });
|
|
38
|
+
if (!before.isFile() || before.size < 1n || before.size > 256n * 1024n * 1024n)
|
|
39
|
+
return null;
|
|
40
|
+
const bytes = fs.readFileSync(fd), after = fs.fstatSync(fd, { bigint: true });
|
|
41
|
+
if (before.dev !== after.dev ||
|
|
42
|
+
before.ino !== after.ino ||
|
|
43
|
+
before.size !== after.size ||
|
|
44
|
+
before.mtimeNs !== after.mtimeNs ||
|
|
45
|
+
before.ctimeNs !== after.ctimeNs ||
|
|
46
|
+
BigInt(bytes.length) !== after.size)
|
|
47
|
+
return null;
|
|
48
|
+
return {
|
|
49
|
+
path: file,
|
|
50
|
+
bytes: bytes.length,
|
|
51
|
+
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
if (fd !== undefined)
|
|
59
|
+
fs.closeSync(fd);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function object(value) {
|
|
63
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
64
|
+
}
|
|
65
|
+
const hash = /^[0-9a-f]{64}$/u;
|
|
66
|
+
/** Read only the exact named regular original evidence; never discover reports or reconstruct attempts. */
|
|
67
|
+
export function readIdentityRecoveryFact(fact) {
|
|
68
|
+
const fd = fs.openSync(fact.path, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
69
|
+
try {
|
|
70
|
+
const stat = fs.fstatSync(fd);
|
|
71
|
+
if (!stat.isFile() || stat.size !== fact.bytes || stat.size > 8 * 1024 * 1024)
|
|
72
|
+
throw new Error("Recovery evidence changed.");
|
|
73
|
+
const bytes = fs.readFileSync(fd);
|
|
74
|
+
if (createHash("sha256").update(bytes).digest("hex") !== fact.sha256)
|
|
75
|
+
throw new Error("Recovery evidence changed.");
|
|
76
|
+
return bytes;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
fs.closeSync(fd);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function validateIdentityPreflightRecoveryEvidence(value, input) {
|
|
83
|
+
const fail = () => ({ ok: false, code: "identity_preflight_recovery_invalid" });
|
|
84
|
+
if (!object(value) ||
|
|
85
|
+
value.schema !== "tiangong-foundry.identity-preflight-recovery.v1" ||
|
|
86
|
+
value.new_cli_execution !== false ||
|
|
87
|
+
typeof value.task_id !== "string" ||
|
|
88
|
+
typeof value.actor_id !== "string" ||
|
|
89
|
+
!object(value.binding) ||
|
|
90
|
+
value.binding.schema !== "tiangong-foundry.identity-preflight-binding.v1" ||
|
|
91
|
+
!object(value.original) ||
|
|
92
|
+
!object(value.current_owner_interpretation_auth))
|
|
93
|
+
return fail();
|
|
94
|
+
if (typeof input.expectedRetainedCliContentSha256 !== "string" ||
|
|
95
|
+
!hash.test(input.expectedRetainedCliContentSha256) ||
|
|
96
|
+
!object(value.current_retained_cli_inventory) ||
|
|
97
|
+
value.current_retained_cli_inventory.content_sha256 !== input.expectedRetainedCliContentSha256)
|
|
98
|
+
return fail();
|
|
99
|
+
const { proof_sha256, ...scope } = value;
|
|
100
|
+
if (proof_sha256 !== sha256Json(scope))
|
|
101
|
+
return fail();
|
|
102
|
+
const binding = value.binding, original = value.original, auth = value.current_owner_interpretation_auth;
|
|
103
|
+
if (!object(binding.dataset) ||
|
|
104
|
+
!object(binding.request) ||
|
|
105
|
+
!object(binding.command) ||
|
|
106
|
+
!object(binding.cli) ||
|
|
107
|
+
!object(binding.account) ||
|
|
108
|
+
!object(binding.relevant_input_hashes))
|
|
109
|
+
return fail();
|
|
110
|
+
const { binding_sha256, ...bindingScope } = binding;
|
|
111
|
+
if (binding_sha256 !== sha256Json(bindingScope) ||
|
|
112
|
+
value.binding_sha256 !== binding_sha256 ||
|
|
113
|
+
binding.cli.package_name !== "@tiangong-lca/cli" ||
|
|
114
|
+
!["0.1.22", "0.1.27", "0.1.28"].includes(String(binding.cli.package_version)) ||
|
|
115
|
+
typeof binding.cli.package_integrity !== "string" ||
|
|
116
|
+
!/^sha256-[0-9a-f]{64}$/u.test(binding.cli.package_integrity) ||
|
|
117
|
+
binding.dataset.type !== input.datasetType ||
|
|
118
|
+
binding.dataset.id !== input.datasetId ||
|
|
119
|
+
binding.dataset.version !== input.datasetVersion ||
|
|
120
|
+
binding.dataset.target_sha256 !== input.targetSha256)
|
|
121
|
+
return fail();
|
|
122
|
+
if (original.attempt !== 1 ||
|
|
123
|
+
original.status !== "failed" ||
|
|
124
|
+
original.failure_code !== "identity_preflight_cli_exit_nonzero" ||
|
|
125
|
+
original.cli_exit_code !== 1 ||
|
|
126
|
+
!object(original.producer_auth) ||
|
|
127
|
+
typeof original.producer_auth.captured_at_utc !== "string" ||
|
|
128
|
+
!object(original.facts))
|
|
129
|
+
return fail();
|
|
130
|
+
for (const account of [original.producer_auth, auth]) {
|
|
131
|
+
if (account.project_ref !== binding.account.project_ref ||
|
|
132
|
+
account.user_id !== binding.account.user_id ||
|
|
133
|
+
typeof account.receipt_scope_sha256 !== "string" ||
|
|
134
|
+
!hash.test(account.receipt_scope_sha256))
|
|
135
|
+
return fail();
|
|
136
|
+
}
|
|
137
|
+
if ((input.expectedProjectRef && input.expectedProjectRef !== binding.account.project_ref) ||
|
|
138
|
+
(input.expectedUserId && input.expectedUserId !== binding.account.user_id))
|
|
139
|
+
return fail();
|
|
140
|
+
const prepared = Date.parse(String(original.batch_prepared_at_utc)), query = Date.parse(String(original.query_generated_at_utc)), completed = Date.parse(String(original.batch_completed_at_utc)), interpreted = Date.parse(String(value.recovered_at_utc)), admitted = Date.parse(String(auth.captured_at_utc));
|
|
141
|
+
if (![prepared, query, completed, interpreted, admitted].every(Number.isFinite) ||
|
|
142
|
+
query < prepared ||
|
|
143
|
+
completed < query ||
|
|
144
|
+
interpreted < completed ||
|
|
145
|
+
admitted > interpreted ||
|
|
146
|
+
interpreted - admitted > 300_000)
|
|
147
|
+
return fail();
|
|
148
|
+
if (input.requestText === null || input.reportText === null)
|
|
149
|
+
return fail();
|
|
150
|
+
try {
|
|
151
|
+
const request = JSON.parse(input.requestText), report = JSON.parse(input.reportText);
|
|
152
|
+
if (!object(request) ||
|
|
153
|
+
!object(report) ||
|
|
154
|
+
binding.request.bytes_sha256 !== sha256Text(input.requestText) ||
|
|
155
|
+
binding.request.canonical_sha256 !== sha256Json(request) ||
|
|
156
|
+
sha256Text(JSON.stringify(request.target)) !== input.targetSha256 ||
|
|
157
|
+
report.schema_version !== 1 ||
|
|
158
|
+
report.kind !== input.datasetType ||
|
|
159
|
+
report.status !== "needs_review" ||
|
|
160
|
+
report.decision !== "manual_review" ||
|
|
161
|
+
report.next_action !== "queue_manual_review" ||
|
|
162
|
+
report.generated_at_utc !== original.query_generated_at_utc ||
|
|
163
|
+
!object(report.target) ||
|
|
164
|
+
report.target.id !== input.datasetId ||
|
|
165
|
+
report.target.version !== input.datasetVersion ||
|
|
166
|
+
!Array.isArray(report.candidates) ||
|
|
167
|
+
!Array.isArray(report.candidate_sources) ||
|
|
168
|
+
!Array.isArray(report.findings) ||
|
|
169
|
+
!Array.isArray(report.blockers) ||
|
|
170
|
+
report.blockers.length ||
|
|
171
|
+
Object.hasOwn(report, "error") ||
|
|
172
|
+
(Object.hasOwn(report, "errors") &&
|
|
173
|
+
(!Array.isArray(report.errors) || report.errors.length)) ||
|
|
174
|
+
(Object.hasOwn(report, "ok") && report.ok !== true))
|
|
175
|
+
return fail();
|
|
176
|
+
const texts = new Map();
|
|
177
|
+
const facts = original.facts;
|
|
178
|
+
for (const key of [
|
|
179
|
+
"stage",
|
|
180
|
+
"run",
|
|
181
|
+
"results",
|
|
182
|
+
"preparation",
|
|
183
|
+
"audit",
|
|
184
|
+
"request",
|
|
185
|
+
"stdout",
|
|
186
|
+
"stderr",
|
|
187
|
+
"report",
|
|
188
|
+
"producer_receipt",
|
|
189
|
+
"producer_plan",
|
|
190
|
+
"job",
|
|
191
|
+
"index",
|
|
192
|
+
"source_file",
|
|
193
|
+
"assessment",
|
|
194
|
+
"auth_receipt",
|
|
195
|
+
]) {
|
|
196
|
+
const fact = original.facts[key];
|
|
197
|
+
if (!object(fact) ||
|
|
198
|
+
typeof fact.path !== "string" ||
|
|
199
|
+
!Number.isSafeInteger(fact.bytes) ||
|
|
200
|
+
typeof fact.sha256 !== "string" ||
|
|
201
|
+
!hash.test(fact.sha256))
|
|
202
|
+
return fail();
|
|
203
|
+
texts.set(key, readIdentityRecoveryFact(fact).toString("utf8"));
|
|
204
|
+
}
|
|
205
|
+
if (texts.get("request") !== input.requestText ||
|
|
206
|
+
texts.get("report") !== input.reportText ||
|
|
207
|
+
texts.get("stderr") !== "" ||
|
|
208
|
+
stableJson(JSON.parse(texts.get("stdout"))) !== stableJson(report))
|
|
209
|
+
return fail();
|
|
210
|
+
const run = JSON.parse(texts.get("run")), stage = JSON.parse(texts.get("stage")), plan = JSON.parse(texts.get("producer_plan")), receipt = JSON.parse(texts.get("producer_receipt")), job = JSON.parse(texts.get("job"));
|
|
211
|
+
if (!object(run) ||
|
|
212
|
+
!object(stage) ||
|
|
213
|
+
!object(plan) ||
|
|
214
|
+
!object(receipt) ||
|
|
215
|
+
!object(job) ||
|
|
216
|
+
run.status !== "failed" ||
|
|
217
|
+
run.command !== "dataset-identity-preflight-run" ||
|
|
218
|
+
run.generated_at_utc !== original.batch_completed_at_utc ||
|
|
219
|
+
stage.schema !== "tiangong-foundry.identity-stage.v1" ||
|
|
220
|
+
stage.status !== "blocked" ||
|
|
221
|
+
plan.command !== "dataset-workflow-identity" ||
|
|
222
|
+
receipt.status !== "completed" ||
|
|
223
|
+
job.task_id !== value.task_id ||
|
|
224
|
+
job.actor_id !== value.actor_id ||
|
|
225
|
+
plan.job_sha256 !== facts.job.sha256 ||
|
|
226
|
+
receipt.job_sha256 !== plan.job_sha256 ||
|
|
227
|
+
!object(receipt.plan) ||
|
|
228
|
+
receipt.plan.sha256 !== facts.producer_plan.sha256 ||
|
|
229
|
+
!Array.isArray(receipt.outputs))
|
|
230
|
+
return fail();
|
|
231
|
+
const options = run.runtime_options;
|
|
232
|
+
if (!object(options) ||
|
|
233
|
+
!object(options.cli) ||
|
|
234
|
+
!object(options.auth_receipt) ||
|
|
235
|
+
options.cli.package !== `@tiangong-lca/cli@${String(binding.cli.package_version)}` ||
|
|
236
|
+
options.auth_receipt.project_ref !== original.producer_auth.project_ref ||
|
|
237
|
+
options.auth_receipt.user_id !== original.producer_auth.user_id ||
|
|
238
|
+
options.auth_receipt.receipt_scope_sha256 !== original.producer_auth.receipt_scope_sha256 ||
|
|
239
|
+
!object(stage.account) ||
|
|
240
|
+
stage.account.project_ref !== binding.account.project_ref ||
|
|
241
|
+
stage.account.user_id !== binding.account.user_id ||
|
|
242
|
+
!Array.isArray(run.results))
|
|
243
|
+
return fail();
|
|
244
|
+
const originalReceipt = parseFreshIntentBoundAuthReceipt(JSON.parse(texts.get("auth_receipt")), {
|
|
245
|
+
nowMs: prepared,
|
|
246
|
+
maxAgeMs: 300_000,
|
|
247
|
+
expectedProjectRef: String(binding.account.project_ref),
|
|
248
|
+
expectedUserId: String(binding.account.user_id),
|
|
249
|
+
});
|
|
250
|
+
if (originalReceipt.receipt_scope_sha256 !== original.producer_auth.receipt_scope_sha256 ||
|
|
251
|
+
originalReceipt.captured_at_utc !== original.producer_auth.captured_at_utc ||
|
|
252
|
+
originalReceipt.cli.package_name !== binding.cli.package_name ||
|
|
253
|
+
originalReceipt.cli.package_version !== binding.cli.package_version)
|
|
254
|
+
return fail();
|
|
255
|
+
const observed = value.current_retained_runtime_observation;
|
|
256
|
+
if (!object(observed) ||
|
|
257
|
+
observed.role !== "current_retained_runtime_observation" ||
|
|
258
|
+
observed.observed_at_utc !== value.recovered_at_utc ||
|
|
259
|
+
!object(observed.original_executable) ||
|
|
260
|
+
typeof observed.qualified_node_sha256 !== "string" ||
|
|
261
|
+
!hash.test(observed.qualified_node_sha256) ||
|
|
262
|
+
observed.original_executable.path !== options.cli.executable)
|
|
263
|
+
return fail();
|
|
264
|
+
const executable = observeRetainedIdentityExecutable(String(observed.original_executable.path));
|
|
265
|
+
if (!object(value.current_retained_cli_inventory) ||
|
|
266
|
+
value.current_retained_cli_inventory.package_version !== binding.cli.package_version ||
|
|
267
|
+
!Array.isArray(options.cli.args_prefix) ||
|
|
268
|
+
typeof options.cli.args_prefix[0] !== "string")
|
|
269
|
+
return fail();
|
|
270
|
+
verifyRetainedIdentityCliInventory(value.current_retained_cli_inventory, options.cli.args_prefix[0]);
|
|
271
|
+
if (!executable ||
|
|
272
|
+
executable.bytes !== observed.original_executable.bytes ||
|
|
273
|
+
executable.sha256 !== observed.original_executable.sha256 ||
|
|
274
|
+
executable.sha256 !== observed.qualified_node_sha256)
|
|
275
|
+
return fail();
|
|
276
|
+
const result = run.results.find((row) => object(row) &&
|
|
277
|
+
row.dataset_type === input.datasetType &&
|
|
278
|
+
row.dataset_id === input.datasetId &&
|
|
279
|
+
row.dataset_version === input.datasetVersion);
|
|
280
|
+
if (!object(result) ||
|
|
281
|
+
result.status !== "failed" ||
|
|
282
|
+
result.failure_code !== original.failure_code ||
|
|
283
|
+
result.cli_exit_code !== 1 ||
|
|
284
|
+
result.attempt !== 1 ||
|
|
285
|
+
result.attempts !== 1 ||
|
|
286
|
+
result.binding_sha256 !== binding_sha256 ||
|
|
287
|
+
result.request_bytes_sha256 !== binding.request.bytes_sha256 ||
|
|
288
|
+
result.report_status !== "needs_review" ||
|
|
289
|
+
result.decision !== "manual_review")
|
|
290
|
+
return fail();
|
|
291
|
+
const indexRows = texts
|
|
292
|
+
.get("index")
|
|
293
|
+
.trim()
|
|
294
|
+
.split(/\r?\n/u)
|
|
295
|
+
.map((line) => JSON.parse(line));
|
|
296
|
+
const selected = indexRows.filter((row) => object(row) &&
|
|
297
|
+
row.dataset_type === input.datasetType &&
|
|
298
|
+
row.dataset_id === input.datasetId &&
|
|
299
|
+
row.dataset_version === input.datasetVersion);
|
|
300
|
+
if (selected.length !== 1 || !object(selected[0]))
|
|
301
|
+
return fail();
|
|
302
|
+
const assessment = JSON.parse(texts.get("assessment"));
|
|
303
|
+
if (typeof original.producer_base !== "string" ||
|
|
304
|
+
!path.isAbsolute(original.producer_base) ||
|
|
305
|
+
!object(assessment) ||
|
|
306
|
+
assessment.owner_base !== original.producer_base ||
|
|
307
|
+
assessment.schema !== "tiangong-foundry.assessment-stage.v1")
|
|
308
|
+
return fail();
|
|
309
|
+
const row = selected[0], taskRoot = path.dirname(facts.job.path), resolve = (locator) => typeof locator === "string" ? path.resolve(String(original.producer_base), locator) : null;
|
|
310
|
+
// Absolute fact paths are confined to this original task and must match its registered producer outputs.
|
|
311
|
+
if (Object.values(facts).some((fact) => !path.isAbsolute(fact.path) || !fact.path.startsWith(taskRoot + path.sep)))
|
|
312
|
+
return fail();
|
|
313
|
+
if (resolve(row.request_file) !== facts.request.path ||
|
|
314
|
+
resolve(row.expected_report_file) !== facts.report.path ||
|
|
315
|
+
resolve(row.source_file) !== facts.source_file.path ||
|
|
316
|
+
binding.relevant_input_hashes.source_file !== facts.source_file.sha256 ||
|
|
317
|
+
row.request_bytes_sha256 !== binding.request.bytes_sha256 ||
|
|
318
|
+
row.target_sha256 !== input.targetSha256 ||
|
|
319
|
+
row.request_json_sha256 !== sha256Text(JSON.stringify(request)) ||
|
|
320
|
+
report.input_path !== facts.request.path ||
|
|
321
|
+
report.out_dir !== resolve(row.output_dir) ||
|
|
322
|
+
!object(report.files) ||
|
|
323
|
+
report.files.identity_decision !== facts.report.path)
|
|
324
|
+
return fail();
|
|
325
|
+
const semanticArgv = [
|
|
326
|
+
input.datasetType,
|
|
327
|
+
"identity-preflight",
|
|
328
|
+
"--json",
|
|
329
|
+
"--timeout-ms",
|
|
330
|
+
String(options.timeout_ms),
|
|
331
|
+
];
|
|
332
|
+
const argv = [
|
|
333
|
+
input.datasetType,
|
|
334
|
+
"identity-preflight",
|
|
335
|
+
"--input",
|
|
336
|
+
facts.request.path,
|
|
337
|
+
"--out-dir",
|
|
338
|
+
String(report.out_dir),
|
|
339
|
+
"--json",
|
|
340
|
+
"--timeout-ms",
|
|
341
|
+
String(options.timeout_ms),
|
|
342
|
+
];
|
|
343
|
+
if (stableJson(binding.command.semantic_argv) !== stableJson(semanticArgv) ||
|
|
344
|
+
!/^[1-9][0-9]*$/u.test(String(options.timeout_ms)) ||
|
|
345
|
+
options.max_attempts !== 1 ||
|
|
346
|
+
options.retry_failed !== null ||
|
|
347
|
+
!Array.isArray(options.cli.args_prefix) ||
|
|
348
|
+
options.cli.args_prefix.length !== 1 ||
|
|
349
|
+
typeof options.cli.args_prefix[0] !== "string" ||
|
|
350
|
+
`sha256-${sha256Text(fs.readFileSync(options.cli.args_prefix[0], "utf8"))}` !==
|
|
351
|
+
binding.cli.package_integrity ||
|
|
352
|
+
result.executable !== options.cli.executable ||
|
|
353
|
+
result.cli_package !== options.cli.package ||
|
|
354
|
+
stableJson(result.cli_args) !== stableJson(argv) ||
|
|
355
|
+
resolve(result.request_file) !== facts.request.path ||
|
|
356
|
+
resolve(result.report_file) !== facts.report.path ||
|
|
357
|
+
resolve(result.stdout_log) !== facts.stdout.path ||
|
|
358
|
+
resolve(result.stderr_log) !== facts.stderr.path)
|
|
359
|
+
return fail();
|
|
360
|
+
const spec = createFoundryCommandSpec({
|
|
361
|
+
executable: String(options.cli.executable),
|
|
362
|
+
argv: [...options.cli.args_prefix, ...argv],
|
|
363
|
+
binding: {
|
|
364
|
+
artifacts: [
|
|
365
|
+
createFileArtifactFact({
|
|
366
|
+
role: "identity_preflight_request",
|
|
367
|
+
path: String(row.request_file),
|
|
368
|
+
filePath: facts.request.path,
|
|
369
|
+
}),
|
|
370
|
+
],
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
if (stableJson(result.command_spec) !== stableJson(spec) ||
|
|
374
|
+
stableJson(run.results) !==
|
|
375
|
+
stableJson(texts
|
|
376
|
+
.get("results")
|
|
377
|
+
.trim()
|
|
378
|
+
.split(/\r?\n/u)
|
|
379
|
+
.map((line) => JSON.parse(line))))
|
|
380
|
+
return fail();
|
|
381
|
+
const preparation = JSON.parse(texts.get("preparation")), audit = JSON.parse(texts.get("audit"));
|
|
382
|
+
if (!object(preparation) ||
|
|
383
|
+
preparation.status !== "ready" ||
|
|
384
|
+
preparation.generated_at_utc !== original.batch_prepared_at_utc ||
|
|
385
|
+
!object(audit) ||
|
|
386
|
+
audit.status !== "passed" ||
|
|
387
|
+
!Array.isArray(audit.blockers) ||
|
|
388
|
+
audit.blockers.length)
|
|
389
|
+
return fail();
|
|
390
|
+
for (const key of [
|
|
391
|
+
"stage",
|
|
392
|
+
"run",
|
|
393
|
+
"results",
|
|
394
|
+
"preparation",
|
|
395
|
+
"audit",
|
|
396
|
+
"request",
|
|
397
|
+
"stdout",
|
|
398
|
+
"stderr",
|
|
399
|
+
"report",
|
|
400
|
+
"index",
|
|
401
|
+
"auth_receipt",
|
|
402
|
+
]) {
|
|
403
|
+
const fact = original.facts[key];
|
|
404
|
+
if (!receipt.outputs.some((item) => object(item) &&
|
|
405
|
+
item.sha256 === fact.sha256 &&
|
|
406
|
+
item.bytes === fact.bytes &&
|
|
407
|
+
path.resolve(taskRoot, String(item.path)) === fact.path))
|
|
408
|
+
return fail();
|
|
409
|
+
}
|
|
410
|
+
return { ok: true, binding: binding };
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
return fail();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
@@ -20,6 +20,14 @@ interface CurationCleanupOptions extends JsonRecord {
|
|
|
20
20
|
interface CurationCleanupArgs {
|
|
21
21
|
repoRoot?: string;
|
|
22
22
|
options?: CurationCleanupOptions;
|
|
23
|
+
processValidationReferences?: {
|
|
24
|
+
rows: readonly unknown[];
|
|
25
|
+
files: readonly {
|
|
26
|
+
path: string;
|
|
27
|
+
bytes: number;
|
|
28
|
+
sha256: string;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
23
31
|
io?: {
|
|
24
32
|
nowIso?: () => string;
|
|
25
33
|
fileExists: typeof fileExists;
|
|
@@ -28,5 +36,5 @@ interface CurationCleanupArgs {
|
|
|
28
36
|
writeText: typeof writeText;
|
|
29
37
|
};
|
|
30
38
|
}
|
|
31
|
-
export declare function runDatasetCurationCleanup({ repoRoot, options, io, }?: CurationCleanupArgs): JsonRecord;
|
|
39
|
+
export declare function runDatasetCurationCleanup({ repoRoot, options, processValidationReferences, io, }?: CurationCleanupArgs): JsonRecord;
|
|
32
40
|
export {};
|
|
@@ -2,6 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import { datasetTypeFromOptions, datasetTypePlural } from "./internal/dataset-types.js";
|
|
3
3
|
import { datasetIdentity } from "./internal/dataset-payload.js";
|
|
4
4
|
import { sha256Json } from "./internal/hash-utils.js";
|
|
5
|
+
import { projectFoundryValidationReferences } from "../foundry-validation-reference-context.js";
|
|
5
6
|
import { annualSupplyFieldPath, applyDeterministicSourceExchangeCompletenessProofs, buildSourceRowsByIdentity, ensureFoundryTraceNamespaces, externalizeImportTraceMetadata, normalizeAnnualSupplyEvidence, normalizeDateTimeMetadata, sanitizeFoundryTraceEvidenceLocators, } from "./internal/prewrite-cleanup.js";
|
|
6
7
|
import { fileExists, jsonLines, nowIso, readRows, repoRelativePath, resolveRepoPath, writeJson, writeText, } from "./internal/runtime-io.js";
|
|
7
8
|
function dateTimeBlockersFromError(error) {
|
|
@@ -13,13 +14,15 @@ function dateTimeBlockersFromError(error) {
|
|
|
13
14
|
}
|
|
14
15
|
return record.blockers.filter((blocker) => Boolean(blocker) && typeof blocker === "object" && !Array.isArray(blocker));
|
|
15
16
|
}
|
|
16
|
-
export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {}) {
|
|
17
|
+
export function runDatasetCurationCleanup({ repoRoot, options = {}, processValidationReferences, io, } = {}) {
|
|
17
18
|
const readInputRows = io?.readRows ?? readRows;
|
|
18
19
|
const hasFile = io?.fileExists ?? fileExists;
|
|
19
20
|
const writeReport = io?.writeJson ?? writeJson;
|
|
20
21
|
const writeRows = io?.writeText ?? writeText;
|
|
21
22
|
const capturedAt = io?.nowIso ?? nowIso;
|
|
22
23
|
const datasetType = datasetTypeFromOptions(options);
|
|
24
|
+
if (processValidationReferences && datasetType !== "process")
|
|
25
|
+
throw new Error("Selected Flow validation evidence belongs only to Process cleanup.");
|
|
23
26
|
if (options.help) {
|
|
24
27
|
return {
|
|
25
28
|
schema_version: 2,
|
|
@@ -53,6 +56,18 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
53
56
|
const sourceRowsByKey = sourceRows.length > 0 ? buildSourceRowsByIdentity(sourceRows) : null;
|
|
54
57
|
const rows = readInputRows(rowsFile);
|
|
55
58
|
const cleanedRows = rows.map((row) => JSON.parse(JSON.stringify(row)));
|
|
59
|
+
// Supplemental validation evidence is not candidate metadata. In particular, a
|
|
60
|
+
// complete referenced Flow must retain its exact body across recursive cleanup.
|
|
61
|
+
const validationContexts = cleanedRows.map((value) => {
|
|
62
|
+
if (datasetType !== "process" || !value || typeof value !== "object" || Array.isArray(value))
|
|
63
|
+
return null;
|
|
64
|
+
const row = value;
|
|
65
|
+
if (!Object.hasOwn(row, "semantic_context"))
|
|
66
|
+
return null;
|
|
67
|
+
const context = { value: row.semantic_context };
|
|
68
|
+
delete row.semantic_context;
|
|
69
|
+
return context;
|
|
70
|
+
});
|
|
56
71
|
let normalizedDateTimeValues = 0;
|
|
57
72
|
const invalidDateTimeBlockers = [];
|
|
58
73
|
cleanedRows.forEach((cleaned, rowIndex) => {
|
|
@@ -167,6 +182,10 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
167
182
|
redactedFoundryTraceEvidenceLocators += sanitizeFoundryTraceEvidenceLocators(cleaned);
|
|
168
183
|
addedFoundryTraceNamespaces += ensureFoundryTraceNamespaces(cleaned);
|
|
169
184
|
});
|
|
185
|
+
validationContexts.forEach((context, index) => {
|
|
186
|
+
if (context)
|
|
187
|
+
cleanedRows[index].semantic_context = context.value;
|
|
188
|
+
});
|
|
170
189
|
// Bound only after every other cleanup transform has run, so the output hash describes the
|
|
171
190
|
// exact unwrapped payload the caller will write, with no row metadata mixed in.
|
|
172
191
|
const annualSupplyEvidenceGaps = pendingAnnualSupplyGaps.map((pending) => {
|
|
@@ -184,7 +203,12 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
184
203
|
output_payload_sha256: sha256Json(outputIdentity.payload),
|
|
185
204
|
};
|
|
186
205
|
});
|
|
187
|
-
|
|
206
|
+
// Project only after cleanup, so selected reference bodies never enter its
|
|
207
|
+
// recursive candidate transforms. All later owners use this same final file.
|
|
208
|
+
const finalRows = processValidationReferences
|
|
209
|
+
? projectFoundryValidationReferences(cleanedRows, processValidationReferences.rows)
|
|
210
|
+
: cleanedRows;
|
|
211
|
+
writeRows(outFile, jsonLines(finalRows));
|
|
188
212
|
const report = {
|
|
189
213
|
schema_version: 2,
|
|
190
214
|
generated_at_utc: capturedAt(),
|
|
@@ -194,6 +218,19 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
194
218
|
remote_write_mode: "read-only",
|
|
195
219
|
rows_file: repoRelativePath(root, rowsFile),
|
|
196
220
|
cleaned_rows_file: repoRelativePath(root, outFile),
|
|
221
|
+
...(processValidationReferences
|
|
222
|
+
? {
|
|
223
|
+
process_validation_references: {
|
|
224
|
+
files: processValidationReferences.files,
|
|
225
|
+
rows: finalRows.map((row, rowIndex) => ({
|
|
226
|
+
row_index: rowIndex,
|
|
227
|
+
input_payload_sha256: sha256Json(datasetIdentity(cleanedRows[rowIndex], rowIndex, datasetType).payload),
|
|
228
|
+
output_payload_sha256: sha256Json(datasetIdentity(row, rowIndex, datasetType).payload),
|
|
229
|
+
flow_documents_sha256: sha256Json(row.semantic_context.flow_documents),
|
|
230
|
+
})),
|
|
231
|
+
},
|
|
232
|
+
}
|
|
233
|
+
: {}),
|
|
197
234
|
counts: {
|
|
198
235
|
rows: cleanedRows.length,
|
|
199
236
|
blockers: 0,
|
|
@@ -45,6 +45,7 @@ interface CurationGateArgs {
|
|
|
45
45
|
cliValidation?: {
|
|
46
46
|
report: string;
|
|
47
47
|
exit: number;
|
|
48
|
+
input?: import("../foundry-runtime-context.ts").FoundryInputFact;
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
51
|
export declare function runDatasetCurationGate({ repoRoot, options, routeAction, requireIdentityPreflight, cliValidation, }?: CurationGateArgs): JsonRecord;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { reviewedFoundryQualityFindings } from "../foundry-quality-review.js";
|
|
3
4
|
import { readPreparationCliEvidence, preparationValidationActions, preparationValidationEvidence, } from "../foundry-preparation-cli-validation.js";
|
|
4
5
|
import * as curationGateWorkflow from "./internal/curation-gate-workflow.js";
|
|
5
6
|
const { authoringQueueRowsForIdentity, buildIdentityPreflightAuthoringContext, buildQueueAuthoringContext, classificationQueueActionItem, classificationQueueRowStillNeedsAuthoring, collectBundledSchemaContextFiles, collectContextDirFiles, collectExplicitContextFiles, collectProfileSemanticActionItems, contextFileDetails, datasetIdentity, datasetTypeFromOptions, datasetTypePlural, ensureArray, entityIdFromFinding, fileExists, fullContextAiCompletionRequirement, fullContextGateItems, identityDecisionApplyContextDecisionsForIdentity, identityDecisionApplyReportOptionValues, identityKey, identityPreflightAuthoringActionItems, identityPreflightGateItems, jsonLines, locationQueueActionItem, locationQueueRowStillNeedsAuthoring, mapRowsByIdentity, nowIso, profileFor, qaFindingCode, qaFindingCurationAction, readAuthoringQueueContext, readCanonicalSupportRewriteContext, readClassificationDecisionApplyContext, readCleanupTransformContext, readContextFiles, readCurationQueueContext, readIdentityDecisionApplyContexts, readIdentityPreflightContext, readIdentityReferenceRewriteContext, readJson, readJsonArtifactsIfOption, readJsonIfOption, readQaFindings, readRows, readSourceContactRewriteContext, readText, readUnresolvedExchangeExternalizationContext, repoRelativePath, resolveRepoPath, sanitizeFileName, schemaIssueCurationAction, sha256Text, unresolvedExchangeExternalizationRowsForIdentity, writeJson, writeText, } = curationGateWorkflow;
|
|
@@ -55,6 +56,9 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
|
|
|
55
56
|
const schemaReport = readJson(schemaReportPath);
|
|
56
57
|
const qaReport = readJson(qaReportPath);
|
|
57
58
|
const qaFindings = readQaFindings(root, qaReport, qaReportPath, datasetType);
|
|
59
|
+
const qualityReviews = options.qualityReview && datasetType === "process"
|
|
60
|
+
? reviewedFoundryQualityFindings(options.qualityReview, rowsFile, qaReport, qaFindings, options.cleanupReport)
|
|
61
|
+
: [];
|
|
58
62
|
const profileContext = readContextFiles(root, profile.docs.map((filePath) => [
|
|
59
63
|
"profile",
|
|
60
64
|
filePath,
|
|
@@ -174,7 +178,11 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
|
|
|
174
178
|
const schemaIssues = ensureArray(schemaRow?.issues);
|
|
175
179
|
const entityQaFindings = qaFindingsById.get(identity.id) ?? [];
|
|
176
180
|
const waivedFindings = entityQaFindings.filter((finding) => waivedQaCodes.has(qaFindingCode(finding)));
|
|
177
|
-
const
|
|
181
|
+
const reviewedFindings = qualityReviews.filter((review) => review.row_index === index &&
|
|
182
|
+
review.id === identity.id &&
|
|
183
|
+
review.version === identity.version);
|
|
184
|
+
const actionableQaFindings = entityQaFindings.filter((finding) => !waivedQaCodes.has(qaFindingCode(finding)) &&
|
|
185
|
+
!reviewedFindings.some((review) => review.finding === finding));
|
|
178
186
|
const schemaActionItems = schemaIssues.map((issue) => schemaIssueCurationAction(issue));
|
|
179
187
|
const qaActionItems = actionableQaFindings.map((finding) => qaFindingCurationAction(finding, datasetType));
|
|
180
188
|
const semanticActionItems = collectProfileSemanticActionItems({
|
|
@@ -306,6 +314,7 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
|
|
|
306
314
|
}
|
|
307
315
|
: {}),
|
|
308
316
|
qa_findings: entityQaFindings,
|
|
317
|
+
...(reviewedFindings.length ? { reviewed_findings: reviewedFindings } : {}),
|
|
309
318
|
waived_findings: waivedFindings.map((finding) => ({
|
|
310
319
|
...finding,
|
|
311
320
|
waiver_basis: profile.waiverReasons?.[qaFindingCode(finding)] ?? null,
|
|
@@ -389,6 +398,12 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
|
|
|
389
398
|
qa_finding_count: entityQaFindings.length,
|
|
390
399
|
...(datasetType === "process" ? { process_qa_finding_count: entityQaFindings.length } : {}),
|
|
391
400
|
waived_finding_count: waivedFindings.length,
|
|
401
|
+
...(reviewedFindings.length
|
|
402
|
+
? {
|
|
403
|
+
reviewed_finding_count: reviewedFindings.length,
|
|
404
|
+
quality_review_receipt_sha256: reviewedFindings[0].receipt_sha256,
|
|
405
|
+
}
|
|
406
|
+
: {}),
|
|
392
407
|
action_item_count: actionItems.length,
|
|
393
408
|
identity_action_item_count: identityPreflightActionItems.length,
|
|
394
409
|
identity_decision_apply_count: identityDecisionApplyRows.length,
|
|
@@ -432,6 +447,9 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
|
|
|
432
447
|
}
|
|
433
448
|
: {}),
|
|
434
449
|
qa_report: repoRelativePath(root, qaReportPath),
|
|
450
|
+
...(qualityReviews.length
|
|
451
|
+
? { quality_review_receipt_sha256: qualityReviews[0].receipt_sha256 }
|
|
452
|
+
: {}),
|
|
435
453
|
policy: {
|
|
436
454
|
cli_qa_role: "deterministic_qa_report_only",
|
|
437
455
|
...(cliValidation
|
|
@@ -6,7 +6,7 @@ import { asText, directoryExists, ensureArray, fileExists, readJson, readText, r
|
|
|
6
6
|
function asJsonRecord(value) {
|
|
7
7
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8
8
|
}
|
|
9
|
-
export const tidasSchemaSearchRoots = ["@tiangong-lca/cli@0.
|
|
9
|
+
export const tidasSchemaSearchRoots = ["@tiangong-lca/cli@0.4.0/assets/tidas-schemas"];
|
|
10
10
|
export function tidasSchemaPath(repoRoot, schemaFile) {
|
|
11
11
|
void repoRoot;
|
|
12
12
|
const candidate = path.join(resolveInstalledTiangongLcaCliPackage().schemaDir, schemaFile);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { validateIdentityPreflightEvidence } from "../../identity-preflight-proof.js";
|
|
3
|
+
import { validateIdentityPreflightRecoveryEvidence } from "../../identity-preflight-recovery-proof.js";
|
|
3
4
|
import { readJsonLinesIfExists, resolveArtifactPath } from "./artifact-inputs.js";
|
|
4
5
|
import { dataSetInformation, datasetRoot, identityFreshnessIdentityKey, } from "./dataset-payload.js";
|
|
5
6
|
import { sha256Json } from "./hash-utils.js";
|
|
@@ -51,7 +52,9 @@ export function readIdentityPreflightIndexRow(repoRoot, indexPath, row) {
|
|
|
51
52
|
const resultPath = identityPreflightResultFile(repoRoot, indexPath, row);
|
|
52
53
|
const result = resultPath ? readJsonIfExists(resultPath) : null;
|
|
53
54
|
const resultText = resultPath && fileExists(resultPath) ? readText(resultPath) : null;
|
|
54
|
-
const executionManifestPath = resolveArtifactPath(repoRoot, asText(typedRow.
|
|
55
|
+
const executionManifestPath = resolveArtifactPath(repoRoot, asText(typedRow.recovery_manifest_file ??
|
|
56
|
+
typedRow.execution_manifest_file ??
|
|
57
|
+
typedRow.executionManifestFile), baseDir) ??
|
|
55
58
|
(resultPath
|
|
56
59
|
? path.join(path.dirname(resultPath), "foundry-identity-preflight-execution.json")
|
|
57
60
|
: null);
|
|
@@ -61,7 +64,13 @@ export function readIdentityPreflightIndexRow(repoRoot, indexPath, row) {
|
|
|
61
64
|
const targetSha256 = typedRow.target_sha256 ??
|
|
62
65
|
typedRow.targetSha256 ??
|
|
63
66
|
(request ? sha256Json(request.target ?? null) : null);
|
|
64
|
-
const
|
|
67
|
+
const validateEvidence = typedRow.recovery_manifest_file
|
|
68
|
+
? validateIdentityPreflightRecoveryEvidence
|
|
69
|
+
: validateIdentityPreflightEvidence;
|
|
70
|
+
const executionEvidence = validateEvidence(executionManifest, {
|
|
71
|
+
...(typedRow.recovery_manifest_file
|
|
72
|
+
? { expectedRetainedCliContentSha256: asText(typedRow.recovery_cli_content_sha256) }
|
|
73
|
+
: {}),
|
|
65
74
|
requestText,
|
|
66
75
|
reportText: resultText,
|
|
67
76
|
datasetType,
|
|
@@ -444,7 +444,10 @@ export function buildReferenceClosureBlockers({ repoRoot, rows, datasetType, rem
|
|
|
444
444
|
const blockers = [];
|
|
445
445
|
const seen = new Set();
|
|
446
446
|
rows.forEach((row, rowIndex) => {
|
|
447
|
-
|
|
447
|
+
// Supplemental validation documents stay bound to the row envelope, but
|
|
448
|
+
// business closure follows the same payload used by the write candidate.
|
|
449
|
+
const payload = datasetIdentity(row, rowIndex, datasetType).payload;
|
|
450
|
+
for (const ref of collectDatasetReferences(payload)) {
|
|
448
451
|
if (!ref.table) {
|
|
449
452
|
const key = `unsupported\u0000${rowIndex}\u0000${ref.id}\u0000${ref.path}`;
|
|
450
453
|
if (seen.has(key))
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
void runFoundryPublicCommand(process.argv, {}, receiveFoundryManagedHost);
|
|
2
|
+
import { runFoundryInstalledCommand } from "./lib/foundry-installed-entry.js";
|
|
3
|
+
void runFoundryInstalledCommand();
|