@tiangong-lca/foundry 0.1.18 → 0.1.20
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 +5 -3
- package/docs/architecture.md +5 -3
- package/docs/foundry-task-contracts.md +2 -0
- package/docs/package-distribution-contract.md +10 -8
- package/docs/public-runtime-contract.md +53 -3
- package/docs/runtime-context-contract.md +7 -3
- package/docs/task-authorization-contract.md +2 -0
- package/package-dist/assets/foundry-package-descriptor.json +374 -136
- package/package-dist/scripts/foundry-facade.d.ts +6 -0
- package/package-dist/scripts/foundry-facade.js +38 -0
- package/package-dist/scripts/foundry-runtime.d.ts +3 -2
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +3 -1
- package/package-dist/scripts/lib/final-delivery-manifest.d.ts +40 -0
- package/package-dist/scripts/lib/final-delivery-manifest.js +145 -0
- package/package-dist/scripts/lib/final-delivery-review.d.ts +37 -0
- package/package-dist/scripts/lib/final-delivery-review.js +108 -0
- 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/native-draft-handoff.js +4 -3
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +9 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +37 -8
- package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -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-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 +24 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +209 -0
- package/package-dist/scripts/lib/foundry-edge-session.d.ts +32 -0
- package/package-dist/scripts/lib/foundry-edge-session.js +203 -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 +24 -2
- 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 +68 -2
- package/package-dist/scripts/lib/foundry-interaction-input.js +2 -2
- package/package-dist/scripts/lib/foundry-managed-authentication.js +1 -1
- 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 +21 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +61 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-package-contract.js +8 -2
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +71 -0
- 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-repair-census.d.ts +82 -0
- package/package-dist/scripts/lib/foundry-repair-census.js +574 -0
- package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
- package/package-dist/scripts/lib/foundry-repair-scope.d.ts +15 -2
- package/package-dist/scripts/lib/foundry-repair-scope.js +62 -10
- 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 +19 -1
- 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-scientific-repair.d.ts +38 -0
- package/package-dist/scripts/lib/foundry-scientific-repair.js +438 -0
- package/package-dist/scripts/lib/foundry-semantic-input.js +1 -1
- package/package-dist/scripts/lib/foundry-task-input-preparation.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-task-input-preparation.js +160 -0
- package/package-dist/scripts/lib/foundry-task-registration.js +19 -1
- package/package-dist/scripts/lib/foundry-task-types.d.ts +2 -0
- 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-workflow-assessment.js +67 -29
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +82 -1
- package/package-dist/scripts/lib/foundry-workflow-context.js +59 -18
- package/package-dist/scripts/lib/foundry-workflow-execution.js +57 -5
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +27 -3
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +202 -161
- package/package-dist/scripts/lib/foundry-workflow-identity.js +16 -10
- package/package-dist/scripts/lib/foundry-workflow-io.js +27 -6
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
- package/package-dist/scripts/lib/foundry-workflow-repair.d.ts +5 -0
- package/package-dist/scripts/lib/foundry-workflow-repair.js +204 -2
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +41 -21
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +1 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +19 -12
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package-dist/scripts/public-api.d.ts +6 -0
- package/package-dist/scripts/runtime-entry.js +15 -6
- package/package.json +5 -2
- package/specs/schemas/foundry-interaction-draft.schema.json +323 -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 +5 -2
- package/specs/schemas/foundry-scientific-repair.schema.json +66 -0
- package/specs/schemas/foundry-semantic-draft.schema.json +50 -0
- package/specs/schemas/foundry-task-start.schema.json +10 -2
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -13,6 +13,7 @@ import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
|
13
13
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
14
14
|
import { recoverFoundryWorkflowIdentity } from "./foundry-workflow-identity-recovery.js";
|
|
15
15
|
import { assertNoPendingFoundryIdentityStage } from "./foundry-identity-stage-state.js";
|
|
16
|
+
import { runFoundryEdgeIdentityPreflight } from "./foundry-edge-identity-preflight.js";
|
|
16
17
|
/** Run the existing read-only owner first; the local transaction only records its captured evidence. */
|
|
17
18
|
export async function runFoundryWorkflowIdentity(context, qualified, entries, authentication = { mode: "oauth" }) {
|
|
18
19
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
@@ -90,21 +91,26 @@ export async function runFoundryWorkflowIdentity(context, qualified, entries, au
|
|
|
90
91
|
});
|
|
91
92
|
continue;
|
|
92
93
|
}
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
const runDir = path.join(outDir, "run");
|
|
95
|
+
const edgeResult = qualified.cli.expectation.package_version === "0.4.0"
|
|
96
|
+
? await runFoundryEdgeIdentityPreflight(context, qualified, authentication, set.type, index, runDir)
|
|
97
|
+
: null;
|
|
98
|
+
const result = edgeResult ??
|
|
99
|
+
workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightRun({
|
|
100
|
+
index,
|
|
101
|
+
outDir: runDir,
|
|
102
|
+
authReceipt: receipt,
|
|
103
|
+
expectedProjectRef: context.accountIntent.projectRef,
|
|
104
|
+
expectedUserId: context.accountIntent.userId,
|
|
105
|
+
maxAttempts: 1,
|
|
106
|
+
timeoutMs: 60_000,
|
|
107
|
+
})));
|
|
102
108
|
if (!["completed", "completed_with_identity_findings"].includes(String(result.status)))
|
|
103
109
|
blockers.push({ code: "identity_preflight_failed", type: set.type, report: result });
|
|
104
110
|
sets.push({
|
|
105
111
|
type: set.type,
|
|
106
112
|
rows: set.file,
|
|
107
|
-
index,
|
|
113
|
+
index: edgeResult?.index ?? index,
|
|
108
114
|
status: result.status,
|
|
109
115
|
report: workflowObject(result.files).report,
|
|
110
116
|
});
|
|
@@ -5,7 +5,7 @@ import { randomUUID } from "node:crypto";
|
|
|
5
5
|
import { FoundryContextError, assertFoundryWorkspaceWrite, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
6
6
|
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
7
7
|
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
8
|
-
import {
|
|
8
|
+
import { withFoundryIsolatedLocalCliEnvironment } from "./foundry-runtime-environment.js";
|
|
9
9
|
import { bindWorkflowChildExecution, workflowChildFailure, WorkflowChildFailure, } from "./foundry-workflow-child-failure.js";
|
|
10
10
|
export function createWorkflowDirectory(context, prefix) {
|
|
11
11
|
assertFoundryWorkspaceWrite(context);
|
|
@@ -64,7 +64,18 @@ export function runWorkflowLocalCli(context, qualified, temporary, argv) {
|
|
|
64
64
|
return result.report;
|
|
65
65
|
}
|
|
66
66
|
export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
67
|
-
const
|
|
67
|
+
const typedDatasetValidation = qualified.cli.expectation.package_version === "0.4.0" &&
|
|
68
|
+
argv[0] === "dataset" &&
|
|
69
|
+
["flow", "process", "model"].includes(argv[1]) &&
|
|
70
|
+
argv[argv.indexOf("--checks") + 1] === "schema,business" &&
|
|
71
|
+
argv[2] === "validate";
|
|
72
|
+
const typedPatch = qualified.cli.expectation.package_version === "0.4.0" &&
|
|
73
|
+
argv[0] === "dataset" &&
|
|
74
|
+
["flow", "process", "model", "contact", "source", "unitgroup", "flowproperty"].includes(argv[1]) &&
|
|
75
|
+
argv[2] === "patch";
|
|
76
|
+
const local = typedDatasetValidation ||
|
|
77
|
+
typedPatch ||
|
|
78
|
+
(argv[0] === "dataset" && argv[1] === "validate") ||
|
|
68
79
|
(argv[0] === "qa" && ["flow", "process", "lifecyclemodel"].includes(argv[1])) ||
|
|
69
80
|
(argv[0] === "dataset" && argv[1] === "curation-queue" && argv[2] === "build") ||
|
|
70
81
|
(argv[0] === "dataset" &&
|
|
@@ -76,14 +87,14 @@ export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
|
76
87
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
77
88
|
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
78
89
|
const execution = bindWorkflowChildExecution(context, qualified, cli.binPath, argv);
|
|
79
|
-
const child = spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
90
|
+
const child = withFoundryIsolatedLocalCliEnvironment(temporary, (env) => spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
80
91
|
cwd: context.workspaceRoot,
|
|
81
|
-
env
|
|
92
|
+
env,
|
|
82
93
|
encoding: "utf8",
|
|
83
94
|
shell: false,
|
|
84
95
|
timeout: 120_000,
|
|
85
96
|
maxBuffer: 8 * 1024 * 1024,
|
|
86
|
-
});
|
|
97
|
+
}));
|
|
87
98
|
const kind = child.error
|
|
88
99
|
? "spawn_error"
|
|
89
100
|
: child.signal
|
|
@@ -104,7 +115,17 @@ export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
|
104
115
|
}
|
|
105
116
|
if (!report || typeof report !== "object" || Array.isArray(report))
|
|
106
117
|
throw workflowChildFailure(execution, child, "invalid_report");
|
|
107
|
-
|
|
118
|
+
const envelope = report;
|
|
119
|
+
const patchError = typedPatch &&
|
|
120
|
+
envelope.status === "failed" &&
|
|
121
|
+
envelope.outcome === "invalid_input" &&
|
|
122
|
+
typeof envelope.error === "object" &&
|
|
123
|
+
envelope.error !== null &&
|
|
124
|
+
Object.hasOwn(envelope.error, "code") &&
|
|
125
|
+
Object.hasOwn(envelope.error, "message");
|
|
126
|
+
if (("error" in report &&
|
|
127
|
+
!((typedDatasetValidation || typedPatch) && report.error === null) &&
|
|
128
|
+
!patchError) ||
|
|
108
129
|
!("status" in report) ||
|
|
109
130
|
typeof report.status !== "string" ||
|
|
110
131
|
!report.status.trim())
|
|
@@ -15,6 +15,7 @@ import { sha256Json } from "./identity-preflight-proof.js";
|
|
|
15
15
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
16
16
|
import { datasetIdentity, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
|
|
17
17
|
import { bundleRowTypes } from "./bundle-row-types.js";
|
|
18
|
+
import { createFoundryEdgeActor } from "./foundry-edge-session.js";
|
|
18
19
|
function invalid(message) {
|
|
19
20
|
throw new FoundryContextError("reference_evidence_invalid", message);
|
|
20
21
|
}
|
|
@@ -133,7 +134,10 @@ export async function verifyFoundryReferences(context, qualified, entries, authe
|
|
|
133
134
|
const scope = current.scope;
|
|
134
135
|
if (!scope)
|
|
135
136
|
invalid("No current canonical reference partition exists.");
|
|
136
|
-
|
|
137
|
+
const typed = qualified.cli.expectation.package_version === "0.4.0";
|
|
138
|
+
const actor = typed ? await createFoundryEdgeActor(context, qualified, authentication) : null;
|
|
139
|
+
if (!actor)
|
|
140
|
+
verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
137
141
|
for (const fact of scope.sources)
|
|
138
142
|
readFoundryInput(context, fact.path);
|
|
139
143
|
const output = resolveFoundryOutput(context, `outputs/reference-verification/${randomUUID()}`);
|
|
@@ -142,7 +146,102 @@ export async function verifyFoundryReferences(context, qualified, entries, authe
|
|
|
142
146
|
fs.writeFileSync(input, scope.targets
|
|
143
147
|
.map((item) => JSON.stringify({ "@type": item.table, "@refObjectId": item.id, "@version": item.version }))
|
|
144
148
|
.join("\n") + "\n", { mode: 0o600 });
|
|
145
|
-
const inputFact = captureFoundryInput(input)
|
|
149
|
+
const inputFact = captureFoundryInput(input);
|
|
150
|
+
const publish = (command, blockers, reportFact, checksFact) => {
|
|
151
|
+
if (captureFoundryInput(input).sha256 !== inputFact.sha256)
|
|
152
|
+
invalid("Reference query changed during verification.");
|
|
153
|
+
for (const fact of scope.sources)
|
|
154
|
+
readFoundryInput(context, fact.path);
|
|
155
|
+
return runFoundryTaskOperation(context, {
|
|
156
|
+
command: "dataset-workflow-reference-verify",
|
|
157
|
+
options: { scope: scope.sha256, nonce: path.basename(output) },
|
|
158
|
+
validateCurrent(index) {
|
|
159
|
+
if (foundryReferenceScope(context, index)?.sha256 !== scope.sha256)
|
|
160
|
+
invalid("Reference scope changed during verification.");
|
|
161
|
+
},
|
|
162
|
+
}, (operation) => {
|
|
163
|
+
registerWorkflowStageFiles(context, operation, output);
|
|
164
|
+
const result = {
|
|
165
|
+
schema: "tiangong-foundry.reference-verification.v1",
|
|
166
|
+
status: blockers.length ? "unresolved" : "verified",
|
|
167
|
+
scope_sha256: scope.sha256,
|
|
168
|
+
targets: scope.targets,
|
|
169
|
+
input: inputFact,
|
|
170
|
+
report: reportFact,
|
|
171
|
+
checks: checksFact,
|
|
172
|
+
command,
|
|
173
|
+
blockers,
|
|
174
|
+
};
|
|
175
|
+
operation.writeJson(path.join(output, "foundry-reference-verification.json"), result);
|
|
176
|
+
return result;
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
if (actor) {
|
|
180
|
+
const endpoint = "app_dataset_verify_remote";
|
|
181
|
+
const requests = [];
|
|
182
|
+
const checks = [];
|
|
183
|
+
const blockers = [];
|
|
184
|
+
for (let offset = 0; offset < scope.targets.length; offset += 200) {
|
|
185
|
+
const targets = scope.targets.slice(offset, offset + 200);
|
|
186
|
+
const request = {
|
|
187
|
+
rootPolicy: "existing",
|
|
188
|
+
references: targets.map((target) => ({
|
|
189
|
+
...target,
|
|
190
|
+
role: "reference",
|
|
191
|
+
requirePayload: true,
|
|
192
|
+
})),
|
|
193
|
+
};
|
|
194
|
+
try {
|
|
195
|
+
const response = workflowObject(await actor.post(endpoint, request));
|
|
196
|
+
requests.push({ request, response });
|
|
197
|
+
const report = workflowObject(response.data);
|
|
198
|
+
const counts = workflowObject(report.counts);
|
|
199
|
+
const rows = Array.isArray(report.checks) ? report.checks.map(workflowObject) : [];
|
|
200
|
+
if (response.command !== "dataset_verify_remote" ||
|
|
201
|
+
response.ok !== true ||
|
|
202
|
+
report.status !== "passed_remote_verification" ||
|
|
203
|
+
report.root_policy !== request.rootPolicy ||
|
|
204
|
+
!Array.isArray(report.blockers) ||
|
|
205
|
+
report.blockers.length ||
|
|
206
|
+
counts.blockers !== 0 ||
|
|
207
|
+
counts.references !== targets.length ||
|
|
208
|
+
rows.length !== targets.length)
|
|
209
|
+
blockers.push({ code: "reference_verification_incomplete", offset });
|
|
210
|
+
targets.forEach((target, index) => {
|
|
211
|
+
const check = rows[index];
|
|
212
|
+
if (!check ||
|
|
213
|
+
check.index !== index ||
|
|
214
|
+
check.role !== "reference" ||
|
|
215
|
+
check.id !== target.id ||
|
|
216
|
+
check.table !== target.table ||
|
|
217
|
+
check.version !== target.version ||
|
|
218
|
+
check.status !== "ok" ||
|
|
219
|
+
check.exact_version !== target.version ||
|
|
220
|
+
check.latest_version !== target.version ||
|
|
221
|
+
check.payload_present !== true)
|
|
222
|
+
blockers.push({ code: "canonical_reference_not_verified", target });
|
|
223
|
+
});
|
|
224
|
+
checks.push(...rows);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
blockers.push({
|
|
228
|
+
code: error instanceof FoundryContextError ? error.code : "reference_edge_failed",
|
|
229
|
+
offset,
|
|
230
|
+
});
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const report = path.join(output, "edge-reference-verification.json");
|
|
235
|
+
const checksFile = path.join(output, "checks.jsonl");
|
|
236
|
+
fs.writeFileSync(report, JSON.stringify({ identity: actor.receipt, requests }) + "\n", {
|
|
237
|
+
mode: 0o600,
|
|
238
|
+
});
|
|
239
|
+
fs.writeFileSync(checksFile, checks.map((check) => JSON.stringify(check) + "\n").join(""), {
|
|
240
|
+
mode: 0o600,
|
|
241
|
+
});
|
|
242
|
+
return publish({ transport: "edge", endpoint }, blockers, captureFoundryInput(report), captureFoundryInput(checksFile));
|
|
243
|
+
}
|
|
244
|
+
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
146
245
|
const command = createFoundryCommandSpec({
|
|
147
246
|
executable: process.execPath,
|
|
148
247
|
argv: [
|
|
@@ -232,33 +331,7 @@ export async function verifyFoundryReferences(context, qualified, entries, authe
|
|
|
232
331
|
}
|
|
233
332
|
if (run.error || run.signal || run.status !== 0)
|
|
234
333
|
blockers.push({ code: "reference_cli_failed", exit_code: run.status });
|
|
235
|
-
|
|
236
|
-
invalid("Reference query changed during verification.");
|
|
237
|
-
for (const fact of scope.sources)
|
|
238
|
-
readFoundryInput(context, fact.path);
|
|
239
|
-
return runFoundryTaskOperation(context, {
|
|
240
|
-
command: "dataset-workflow-reference-verify",
|
|
241
|
-
options: { scope: scope.sha256, nonce: path.basename(output) },
|
|
242
|
-
validateCurrent(index) {
|
|
243
|
-
if (foundryReferenceScope(context, index)?.sha256 !== scope.sha256)
|
|
244
|
-
invalid("Reference scope changed during verification.");
|
|
245
|
-
},
|
|
246
|
-
}, (operation) => {
|
|
247
|
-
registerWorkflowStageFiles(context, operation, output);
|
|
248
|
-
const result = {
|
|
249
|
-
schema: "tiangong-foundry.reference-verification.v1",
|
|
250
|
-
status: blockers.length ? "unresolved" : "verified",
|
|
251
|
-
scope_sha256: scope.sha256,
|
|
252
|
-
targets: scope.targets,
|
|
253
|
-
input: inputFact,
|
|
254
|
-
report: reportFact,
|
|
255
|
-
checks: checksFact,
|
|
256
|
-
command,
|
|
257
|
-
blockers,
|
|
258
|
-
};
|
|
259
|
-
operation.writeJson(path.join(output, "foundry-reference-verification.json"), result);
|
|
260
|
-
return result;
|
|
261
|
-
});
|
|
334
|
+
return publish(command, blockers, reportFact, checksFact);
|
|
262
335
|
}
|
|
263
336
|
finally {
|
|
264
337
|
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
@@ -12,6 +12,7 @@ export interface FoundryRepairSelectionFacts {
|
|
|
12
12
|
readonly contract: string;
|
|
13
13
|
readonly before: string;
|
|
14
14
|
readonly candidate: string;
|
|
15
|
+
readonly scientific?: string;
|
|
15
16
|
}
|
|
16
17
|
export interface FoundryRepairPreparationRead {
|
|
17
18
|
readonly entry: ArtifactEntry;
|
|
@@ -33,4 +34,8 @@ export declare function readFoundryRepairPreparation(context: FoundryRuntimeCont
|
|
|
33
34
|
* already-registered report without issuing another remote call.
|
|
34
35
|
*/
|
|
35
36
|
export declare function prepareFoundryRepair(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, _entries: readonly ArtifactEntry[], authentication: FoundryAuthentication): Promise<JsonRecord>;
|
|
37
|
+
/** Fresh observation belongs before the first consumed attempt. Recovery keeps the original write. */
|
|
38
|
+
export declare function verifyScientificRepairBeforeDispatch(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication, requestSha256: string): Promise<void>;
|
|
39
|
+
/** Observe the written overlay and all peers again. This cannot close the interval between reads. */
|
|
40
|
+
export declare function verifyScientificRepairAfterReadback(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication, directory: string): Promise<JsonRecord | null>;
|
|
36
41
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { prepareEdgeProcessRepair, readEdgeRepairValidation, } from "./foundry-edge-repair-preparation.js";
|
|
1
2
|
import { proveFoundryRepairRemoteIntegrity } from "./foundry-repair-reference-binding.js";
|
|
2
3
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
3
4
|
import childProcess from "node:child_process";
|
|
@@ -11,11 +12,14 @@ import { createFoundryAuthenticationEnvironment, } from "./foundry-authenticatio
|
|
|
11
12
|
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
12
13
|
import { runFoundryTaskOperation, withFoundryTaskMetadata } from "./foundry-task-store.js";
|
|
13
14
|
import { createWorkflowDirectory, createWorkflowStageDirectory } from "./foundry-workflow-io.js";
|
|
14
|
-
import { readWorkflowArtifact } from "./foundry-workflow-state.js";
|
|
15
|
+
import { readWorkflowArtifact, workflowObject } from "./foundry-workflow-state.js";
|
|
15
16
|
import { readFoundryRepairScope } from "./foundry-repair-scope.js";
|
|
16
17
|
import { FOUNDRY_REPAIR_PREPARATION_SCHEMA, parseFoundryRepairDryRunReport, parseFoundryRepairValidateReport, } from "./foundry-repair-preflight.js";
|
|
18
|
+
import { applyScientificRepairProposals, assertScientificRepairDiagnosticReport, runScientificRepairDiagnostic, } from "./foundry-scientific-repair.js";
|
|
19
|
+
import { verifyFoundryRepairCensus } from "./foundry-repair-census.js";
|
|
17
20
|
import { readTaskJson, relative as taskRelative } from "./foundry-task-io.js";
|
|
18
21
|
import { sha256Json } from "./identity-preflight-proof.js";
|
|
22
|
+
import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
19
23
|
/** The task-store command this owner registers under; the facade owns invoking it. */
|
|
20
24
|
export const FOUNDRY_REPAIR_PREFLIGHT_COMMAND = "dataset-workflow-repair-preflight";
|
|
21
25
|
export const FOUNDRY_REPAIR_REPORT_NAME = "foundry-repair-preflight.json";
|
|
@@ -85,6 +89,7 @@ export function foundryRepairSelection(context) {
|
|
|
85
89
|
contract: repair.contract,
|
|
86
90
|
before: repair.before,
|
|
87
91
|
candidate: repair.candidate,
|
|
92
|
+
...(typeof repair.scientific === "string" ? { scientific: repair.scientific } : {}),
|
|
88
93
|
});
|
|
89
94
|
}
|
|
90
95
|
/**
|
|
@@ -110,7 +115,26 @@ function resolveRepairScope(context) {
|
|
|
110
115
|
verifiedProjectRef: account.projectRef,
|
|
111
116
|
stateCode: "0",
|
|
112
117
|
relativePath: (file) => path.relative(context.workspaceRoot, file),
|
|
118
|
+
...(selection.scientific
|
|
119
|
+
? {
|
|
120
|
+
scientific: {
|
|
121
|
+
descriptorFile: resolveFoundryInputPath(context, selection.scientific),
|
|
122
|
+
actorId: context.actorId,
|
|
123
|
+
selectedFiles: context.inputs.map((input) => input.path),
|
|
124
|
+
excludedRuntimeRoots: [
|
|
125
|
+
context.workspaceRoot,
|
|
126
|
+
context.cacheRoot,
|
|
127
|
+
...context.inputs.map((input) => input.path),
|
|
128
|
+
],
|
|
129
|
+
read: (file) => readFoundryInput(context, file, MAX_REPORT_BYTES),
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
: {}),
|
|
113
133
|
});
|
|
134
|
+
if (scope.scientific &&
|
|
135
|
+
sha256Json(readTaskJson(context, "repair-scope.json").scientific) !==
|
|
136
|
+
sha256Json(scope.scientific))
|
|
137
|
+
fail("repair_scientific_runtime_changed", "Scientific repair must retain its originally registered source evidence and trusted provider-impact runtime.");
|
|
114
138
|
return { scope, contractFile, beforeFile, candidateFile };
|
|
115
139
|
}
|
|
116
140
|
function expectationOf(context, scope, contractFile) {
|
|
@@ -270,6 +294,94 @@ export function readFoundryRepairPreparation(context, entries) {
|
|
|
270
294
|
content: role,
|
|
271
295
|
});
|
|
272
296
|
};
|
|
297
|
+
if (value.status !== "blocked" && verified.has("edge-repair:out/owner-report.json")) {
|
|
298
|
+
const report = ownerReport("edge-repair", currentScope.candidateFile);
|
|
299
|
+
const artifact = (role) => {
|
|
300
|
+
const entry = verified.get(`edge-repair:out/${role}`);
|
|
301
|
+
if (!entry)
|
|
302
|
+
fail("repair_report_invalid", "Guarded Edge repair requires complete indexed evidence.");
|
|
303
|
+
return JSON.parse(fs.readFileSync(resolveFoundryOutput(context, entry.path), "utf8"));
|
|
304
|
+
};
|
|
305
|
+
const typed = artifact("validation/outputs/validation-report.json");
|
|
306
|
+
const reference = artifact("references/edge-support-precommit.json");
|
|
307
|
+
const before = artifact("edge-before.json");
|
|
308
|
+
const rules = readEdgeRepairValidation(typed, expected);
|
|
309
|
+
if (currentScope.scope.scientific) {
|
|
310
|
+
const native = verified.get("science:provider-impact-report.json");
|
|
311
|
+
const census = verified.get("science:census/proof.json");
|
|
312
|
+
if (!native ||
|
|
313
|
+
!census ||
|
|
314
|
+
native.sha256 !== currentScope.scope.scientific.worker_report.sha256 ||
|
|
315
|
+
Object.values(rules).some((value) => !value))
|
|
316
|
+
fail("repair_report_invalid", "Scientific repair requires indexed exact native provider-impact, complete census and fully passed validation evidence.");
|
|
317
|
+
const proof = readWorkflowArtifact(context, census).value;
|
|
318
|
+
assertScientificRepairDiagnosticReport(readWorkflowArtifact(context, native).value, currentScope.scope.scientific);
|
|
319
|
+
const gates = workflowObject(report.scientific_gates);
|
|
320
|
+
const workerInput = JSON.parse(readFoundryInput(context, currentScope.scope.scientific.worker_input.path, MAX_REPORT_BYTES).toString("utf8"));
|
|
321
|
+
if (proof.schema !== "tiangong-foundry.repair-census.v1" ||
|
|
322
|
+
proof.status !== "verified" ||
|
|
323
|
+
proof.actor_user_id !== context.accountIntent.userId ||
|
|
324
|
+
proof.project_ref !== context.accountIntent.projectRef ||
|
|
325
|
+
proof.input_object_sha256 !== sha256Json(workerInput) ||
|
|
326
|
+
proof.observation_phase !== "before" ||
|
|
327
|
+
proof.double_scan !== true ||
|
|
328
|
+
proof.transaction_snapshot !== false)
|
|
329
|
+
fail("repair_report_invalid", "Scientific repair census must bind the exact registered Worker input, account and complete observed scope.");
|
|
330
|
+
for (const [kind, role] of [
|
|
331
|
+
["schema", "schema/outputs/validation-report.json"],
|
|
332
|
+
["cleanup", "cleanup/dataset-curation-cleanup-report.json"],
|
|
333
|
+
["curation", "curation/dataset-curation-gate-report.json"],
|
|
334
|
+
]) {
|
|
335
|
+
const entry = verified.get(`edge-repair:out/${role}`);
|
|
336
|
+
const fact = workflowObject(gates[kind]);
|
|
337
|
+
if (!entry || fact.sha256 !== entry.sha256 || fact.bytes !== entry.bytes)
|
|
338
|
+
fail("repair_report_invalid", "Scientific repair requires complete indexed native schema, cleanup and curation producer evidence.");
|
|
339
|
+
const checked = readWorkflowArtifact(context, entry).value;
|
|
340
|
+
if ((kind === "cleanup" && checked.status !== "completed") ||
|
|
341
|
+
(kind === "curation" && checked.status !== "ready"))
|
|
342
|
+
fail("repair_report_invalid", "Scientific repair cannot adopt failed cleanup or curation evidence.");
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (currentScope.scope.scientific) {
|
|
346
|
+
const gates = workflowObject(report.scientific_gates);
|
|
347
|
+
const projection = verified.get("edge-repair:out/schema-validation-rows.jsonl");
|
|
348
|
+
const projectionFact = workflowObject(gates.schema_projection);
|
|
349
|
+
if (!projection ||
|
|
350
|
+
projection.sha256 !== projectionFact.sha256 ||
|
|
351
|
+
projection.bytes !== projectionFact.bytes)
|
|
352
|
+
fail("repair_report_invalid", "Scientific native validation requires its indexed exact-payload Flow-context projection.");
|
|
353
|
+
const candidateRows = readRows(currentScope.candidateFile);
|
|
354
|
+
const projectedRows = readRows(resolveFoundryOutput(context, projection.path));
|
|
355
|
+
if (candidateRows.length !== projectedRows.length ||
|
|
356
|
+
candidateRows.some((row, index) => sha256Json(datasetIdentity(row, index, "process").payload) !==
|
|
357
|
+
sha256Json(datasetIdentity(projectedRows[index], index, "process").payload)))
|
|
358
|
+
fail("repair_report_invalid", "Scientific native validation projection changed a reviewed write payload.");
|
|
359
|
+
}
|
|
360
|
+
const beforeValidation = Object.values(rules).includes(false)
|
|
361
|
+
? artifact("before-validation/outputs/validation-report.json")
|
|
362
|
+
: null;
|
|
363
|
+
const detail = Array.isArray(evidence.detail)
|
|
364
|
+
? evidence.detail.map(workflowObject).find((item) => item.role === "edge_preflight")
|
|
365
|
+
: null;
|
|
366
|
+
const referenceEntry = verified.get("edge-repair:out/references/edge-support-precommit.json");
|
|
367
|
+
const referenceFact = record(report.reference_evidence, "repair_report_invalid", "Dependency report fact");
|
|
368
|
+
if (report.schema !== "tiangong-foundry.edge-repair-preflight.v1" ||
|
|
369
|
+
report.contract_sha256 !== expected.contract_sha256 ||
|
|
370
|
+
!sameFact(report.before, inputs.before, "repair_report_invalid", "Edge before rows") ||
|
|
371
|
+
report.validation_sha256 !== sha256Json(typed) ||
|
|
372
|
+
report.before_validation_sha256 !==
|
|
373
|
+
(beforeValidation ? sha256Json(beforeValidation) : null) ||
|
|
374
|
+
sha256Json(report.rule_verification) !== sha256Json(rules) ||
|
|
375
|
+
!detail ||
|
|
376
|
+
sha256Json(detail.report) !== sha256Json(report) ||
|
|
377
|
+
report.remote_before_sha256 !== sha256Json(before) ||
|
|
378
|
+
referenceFact.sha256 !== referenceEntry.sha256 ||
|
|
379
|
+
referenceFact.bytes !== referenceEntry.bytes ||
|
|
380
|
+
reference.status !== "passed_remote_verification" ||
|
|
381
|
+
(value.status === "prepared") !== (currentScope.scope.status === "dispatchable"))
|
|
382
|
+
fail("repair_report_invalid", "Guarded Edge repair proof differs from the registered scope.");
|
|
383
|
+
return Object.freeze({ entry, file: resolveFoundryOutput(context, entry.path), value });
|
|
384
|
+
}
|
|
273
385
|
if (value.status === "prepared") {
|
|
274
386
|
if (currentScope.scope.status !== "dispatchable")
|
|
275
387
|
fail("repair_report_invalid", "A no-op is not a write preparation.");
|
|
@@ -317,7 +429,38 @@ export async function prepareFoundryRepair(context, qualified, _entries, authent
|
|
|
317
429
|
verifyCommands: [FOUNDRY_REPAIR_PREFLIGHT_COMMAND],
|
|
318
430
|
});
|
|
319
431
|
try {
|
|
320
|
-
if (scope.
|
|
432
|
+
if (scope.scientific) {
|
|
433
|
+
if (qualified.cli.expectation.package_version !== "0.4.0")
|
|
434
|
+
fail("repair_scientific_runtime_unsupported", "Scientific repair requires the qualified typed Process runtime.");
|
|
435
|
+
const directory = path.join(temporary, "science");
|
|
436
|
+
fs.mkdirSync(directory, { mode: 0o700 });
|
|
437
|
+
stagedTrees.push({ name: "science", directory });
|
|
438
|
+
const workerInput = JSON.parse(readFoundryInput(context, scope.scientific.worker_input.path, MAX_REPORT_BYTES).toString("utf8"));
|
|
439
|
+
const census = await verifyFoundryRepairCensus(context, qualified, authentication, workerInput, path.join(directory, "census"));
|
|
440
|
+
const diagnostic = runScientificRepairDiagnostic(scope.scientific, directory);
|
|
441
|
+
applyScientificRepairProposals(context, qualified, temporary, scope.scientific, beforeFile, candidateFile, path.join(directory, "patch"));
|
|
442
|
+
evidenceDetails.push({
|
|
443
|
+
role: "scientific_preflight",
|
|
444
|
+
census: census.proof,
|
|
445
|
+
diagnostic_sha256: scope.scientific.worker_report.sha256,
|
|
446
|
+
affected_processes: diagnostic.affected_processes,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (qualified.cli.expectation.package_version === "0.4.0") {
|
|
450
|
+
const root = path.join(temporary, "edge-repair");
|
|
451
|
+
fs.mkdirSync(root, { mode: 0o700 });
|
|
452
|
+
stagedTrees.push({ name: "edge-repair", directory: root });
|
|
453
|
+
const report = await prepareEdgeProcessRepair(context, qualified, authentication, expectation, {
|
|
454
|
+
before: beforeFile,
|
|
455
|
+
candidate: candidateFile,
|
|
456
|
+
temporary,
|
|
457
|
+
directory: path.join(root, "out"),
|
|
458
|
+
scientific: scope.scientific,
|
|
459
|
+
});
|
|
460
|
+
evidenceDetails.push({ role: "edge_preflight", report });
|
|
461
|
+
status = scope.status === "dispatchable" ? "prepared" : "no_change_verified";
|
|
462
|
+
}
|
|
463
|
+
else if (scope.status === "dispatchable") {
|
|
321
464
|
const outDir = path.join(temporary, "dry-run", "out");
|
|
322
465
|
fs.mkdirSync(outDir, { recursive: true, mode: 0o700 });
|
|
323
466
|
stagedTrees.push({ name: "dry-run", directory: path.join(temporary, "dry-run") });
|
|
@@ -541,6 +684,7 @@ export async function prepareFoundryRepair(context, qualified, _entries, authent
|
|
|
541
684
|
rows_sha256: scope.rows_sha256,
|
|
542
685
|
changed_paths: [...scope.changed_paths],
|
|
543
686
|
actions: scope.actions.map((action) => ({ ...action })),
|
|
687
|
+
...(scope.scientific ? { scientific: scope.scientific } : {}),
|
|
544
688
|
},
|
|
545
689
|
contract: {
|
|
546
690
|
role: "execution_contract",
|
|
@@ -578,3 +722,61 @@ export async function prepareFoundryRepair(context, qualified, _entries, authent
|
|
|
578
722
|
fs.rmSync(temporary, { recursive: true, force: true });
|
|
579
723
|
}
|
|
580
724
|
}
|
|
725
|
+
/** Fresh observation belongs before the first consumed attempt. Recovery keeps the original write. */
|
|
726
|
+
export async function verifyScientificRepairBeforeDispatch(context, qualified, authentication, requestSha256) {
|
|
727
|
+
const { scope } = resolveRepairScope(context);
|
|
728
|
+
if (!scope.scientific)
|
|
729
|
+
return;
|
|
730
|
+
const evidence = scope.scientific;
|
|
731
|
+
const temporary = createWorkflowDirectory(context, "tmp/scientific-repair-precommit-");
|
|
732
|
+
try {
|
|
733
|
+
const input = JSON.parse(readFoundryInput(context, evidence.worker_input.path, MAX_REPORT_BYTES).toString("utf8"));
|
|
734
|
+
const census = await verifyFoundryRepairCensus(context, qualified, authentication, input, path.join(temporary, "census"));
|
|
735
|
+
await runFoundryTaskOperation(context, {
|
|
736
|
+
command: FOUNDRY_REPAIR_PREFLIGHT_COMMAND,
|
|
737
|
+
options: {
|
|
738
|
+
task: context.taskId,
|
|
739
|
+
stage: "scientific_precommit",
|
|
740
|
+
request_sha256: requestSha256,
|
|
741
|
+
nonce: randomUUID(),
|
|
742
|
+
},
|
|
743
|
+
validateCurrent: () => {
|
|
744
|
+
resolveRepairScope(context);
|
|
745
|
+
},
|
|
746
|
+
}, (operation) => {
|
|
747
|
+
const stage = createWorkflowStageDirectory(context, operation, "scientific-precommit");
|
|
748
|
+
for (const file of census.files) {
|
|
749
|
+
const relative = path.relative(temporary, file);
|
|
750
|
+
if (relative.startsWith("..") || path.isAbsolute(relative))
|
|
751
|
+
fail("repair_census_unproven", "Scientific precommit evidence must remain inside its producer directory.");
|
|
752
|
+
operation.writeText(path.join(stage, relative), fs.readFileSync(file));
|
|
753
|
+
}
|
|
754
|
+
const report = {
|
|
755
|
+
schema: "tiangong-foundry.scientific-repair-precommit.v1",
|
|
756
|
+
request_sha256: requestSha256,
|
|
757
|
+
worker_input: evidence.worker_input,
|
|
758
|
+
observed_census: census.proof,
|
|
759
|
+
remote_writes: 0,
|
|
760
|
+
};
|
|
761
|
+
operation.writeJson(path.join(stage, "scientific-precommit.json"), report);
|
|
762
|
+
return report;
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
finally {
|
|
766
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
/** Observe the written overlay and all peers again. This cannot close the interval between reads. */
|
|
770
|
+
export async function verifyScientificRepairAfterReadback(context, qualified, authentication, directory) {
|
|
771
|
+
const { scope } = resolveRepairScope(context);
|
|
772
|
+
if (!scope.scientific)
|
|
773
|
+
return null;
|
|
774
|
+
const input = JSON.parse(readFoundryInput(context, scope.scientific.worker_input.path, MAX_REPORT_BYTES).toString("utf8"));
|
|
775
|
+
const census = await verifyFoundryRepairCensus(context, qualified, authentication, input, directory, "after");
|
|
776
|
+
return {
|
|
777
|
+
original_worker_input: scope.scientific.worker_input,
|
|
778
|
+
observed_census: census.proof,
|
|
779
|
+
concurrent_interval_atomicity: "unproven",
|
|
780
|
+
publication_ready: false,
|
|
781
|
+
};
|
|
782
|
+
}
|
|
@@ -8,6 +8,7 @@ import { assertSelectedSemanticInput, readSelectedSemanticBytes, } from "./found
|
|
|
8
8
|
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
9
9
|
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
10
10
|
import { createWorkflowStageDirectory, createWorkflowDirectory, registerWorkflowStageFiles, runWorkflowLocalCliResult, } from "./foundry-workflow-io.js";
|
|
11
|
+
import { applyFoundryTypedAuthoringPatch } from "./foundry-typed-authoring-patch.js";
|
|
11
12
|
import { runDatasetAuthoringPatchCollect } from "./import-curation/patch-collect.js";
|
|
12
13
|
import { readJsonOrJsonl, ensureArray, readRows } from "./import-curation/internal/runtime-io.js";
|
|
13
14
|
import { createFoundryDecisionOwners } from "./foundry-decision-owners.js";
|
|
@@ -345,33 +346,51 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
345
346
|
if (packageDirectories.size !== 1)
|
|
346
347
|
fail("semantic_work_invalid", "Selected work must share its registered package snapshot directory.");
|
|
347
348
|
const repaired = path.join(output, type, "repaired.rows.jsonl");
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
349
|
+
const patch = path.join(output, type, "collected-patches.json");
|
|
350
|
+
const directory = path.join(output, type, "apply");
|
|
351
|
+
const typed = qualified.cli.expectation.package_version === "0.4.0";
|
|
352
|
+
const typedResult = typed
|
|
353
|
+
? applyFoundryTypedAuthoringPatch(context, qualified, temporary, {
|
|
354
|
+
type,
|
|
355
|
+
input: originalRows,
|
|
356
|
+
patch,
|
|
357
|
+
directory,
|
|
358
|
+
output: repaired,
|
|
359
|
+
packageDirectory: [...packageDirectories][0],
|
|
360
|
+
writeJson: (file, value) => operation.writeJson(file, value),
|
|
361
|
+
writeText: (file, value) => operation.writeText(file, value),
|
|
362
|
+
})
|
|
363
|
+
: null;
|
|
364
|
+
const legacyResult = typed
|
|
365
|
+
? null
|
|
366
|
+
: runWorkflowLocalCliResult(context, qualified, temporary, [
|
|
367
|
+
"dataset",
|
|
368
|
+
"patch",
|
|
369
|
+
"apply",
|
|
370
|
+
"--input",
|
|
371
|
+
originalRows,
|
|
372
|
+
"--patch",
|
|
373
|
+
patch,
|
|
374
|
+
"--out",
|
|
375
|
+
repaired,
|
|
376
|
+
"--out-dir",
|
|
377
|
+
directory,
|
|
378
|
+
"--authoring-package-dir",
|
|
379
|
+
[...packageDirectories][0],
|
|
380
|
+
"--require-authoring-package",
|
|
381
|
+
"--require-action-item-closure",
|
|
382
|
+
"--json",
|
|
383
|
+
]);
|
|
384
|
+
const applied = typedResult ?? legacyResult;
|
|
366
385
|
const original = rows.value.sets.find((set) => set.type === type && set.file === originalRows);
|
|
367
|
-
const
|
|
386
|
+
const check = () => {
|
|
368
387
|
if (!["completed", "blocked"].includes(String(applied.report.status)) ||
|
|
369
388
|
!Array.isArray(applied.report.blockers))
|
|
370
389
|
fail("semantic_apply_invalid", "Patch application returned no completed or blocked owner report.");
|
|
371
390
|
const reportFile = workflowObject(applied.report.files).report;
|
|
372
391
|
if (typeof reportFile !== "string")
|
|
373
392
|
fail("semantic_apply_invalid", "Patch application returned no report locator.");
|
|
374
|
-
|
|
393
|
+
legacyResult?.verifyReportFile(reportFile);
|
|
375
394
|
if (applied.exit !== 0 ||
|
|
376
395
|
applied.report.status !== "completed" ||
|
|
377
396
|
applied.report.blockers.length)
|
|
@@ -380,7 +399,8 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
380
399
|
fail("semantic_row_scope_changed", "Patch application changed the assessed row scope.");
|
|
381
400
|
captureFoundryInput(repaired);
|
|
382
401
|
return original;
|
|
383
|
-
}
|
|
402
|
+
};
|
|
403
|
+
const completed = legacyResult ? legacyResult.validate(check) : check();
|
|
384
404
|
if (!completed) {
|
|
385
405
|
blockers.push({ code: "semantic_apply_blocked", type, report: applied.report });
|
|
386
406
|
continue;
|
|
@@ -101,6 +101,7 @@ export declare function validateIdentityPreflightExecution(input: {
|
|
|
101
101
|
stderrText?: string;
|
|
102
102
|
signal?: string | null;
|
|
103
103
|
}): ValidationFailure | ValidationSuccess;
|
|
104
|
+
export declare function createIdentityPreflightExecutionManifest(binding: IdentityPreflightBinding, reportText: string, completedAtUtc: string): ExecutionManifest;
|
|
104
105
|
export declare function validateBoundExecutionManifest(value: unknown, binding: IdentityPreflightBinding, reportText: string | null): {
|
|
105
106
|
ok: boolean;
|
|
106
107
|
code?: string;
|