@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
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { parseAuthIdentityReceipt } from "@tiangong-lca/cli/auth-identity-receipt";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { bundleRowTypes } from "./bundle-row-types.js";
|
|
6
|
+
import { buildEdgeSupportPlan, isNextFlowVersion, } from "./foundry-edge-support-plan.js";
|
|
7
|
+
import { FoundryContextError, captureFoundryInput, readFoundryInput, resolveFoundryOutput, writeFoundryArtifact, } from "./foundry-runtime-context.js";
|
|
8
|
+
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
9
|
+
import { bindWorkflowChildExecution, workflowChildFailure, } from "./foundry-workflow-child-failure.js";
|
|
10
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
11
|
+
import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
12
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
13
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
14
|
+
import { edgeReferenceKey, readEdgeReferenceIntent } from "./foundry-edge-reference-intent.js";
|
|
15
|
+
export function planFoundryEdgeSupportStage(context, qualified, environment, type, stage, source, verifyDependencies, receiptFile, selectedInput) {
|
|
16
|
+
const inputOption = source.indexOf(source.includes("--input-file") ? "--input-file" : "--input");
|
|
17
|
+
const input = selectedInput?.path ?? resolveFoundryOutput(context, source[inputOption + 1]);
|
|
18
|
+
const output = resolveFoundryOutput(context, source[source.indexOf("--out-dir") + 1]);
|
|
19
|
+
const account = context.accountIntent;
|
|
20
|
+
if (!account)
|
|
21
|
+
throw new FoundryContextError("needs_auth", "Edge support planning requires task account intent.");
|
|
22
|
+
const rows = selectedInput
|
|
23
|
+
? readRows(input, (file) => readFoundryInput(context, file).toString("utf8"))
|
|
24
|
+
: readRows(input);
|
|
25
|
+
const target = { project_ref: account.projectRef, user_id: account.userId };
|
|
26
|
+
const plan = buildEdgeSupportPlan(type, captureFoundryInput(input), target, rows);
|
|
27
|
+
const intentOption = source.indexOf("--reference-intent-file");
|
|
28
|
+
const intent = intentOption < 0
|
|
29
|
+
? null
|
|
30
|
+
: readEdgeReferenceIntent(context, source[intentOption + 1], type, target, rows);
|
|
31
|
+
const save = (name, value) => {
|
|
32
|
+
const file = path.join(output, name);
|
|
33
|
+
writeFoundryArtifact(context, file, JSON.stringify(value, null, 2) + "\n");
|
|
34
|
+
return file;
|
|
35
|
+
};
|
|
36
|
+
if (!verifyDependencies) {
|
|
37
|
+
const reportFile = path.join(output, "edge-support-dry-run.json");
|
|
38
|
+
const progress = path.join(output, "edge-support-progress.jsonl");
|
|
39
|
+
const builds = plan.roots.map(({ id, version }) => ({
|
|
40
|
+
id,
|
|
41
|
+
version,
|
|
42
|
+
status: "prepared",
|
|
43
|
+
operation: "would_insert",
|
|
44
|
+
}));
|
|
45
|
+
writeFoundryArtifact(context, progress, builds.map((row) => JSON.stringify(row)).join("\n") + "\n");
|
|
46
|
+
const successFile = type === "flow" ? save("edge-flow-dry-run-rows.json", builds) : null;
|
|
47
|
+
const report = {
|
|
48
|
+
schema: "tiangong-foundry.edge-support-dry-run.v1",
|
|
49
|
+
status: "completed_dataset_save_draft",
|
|
50
|
+
mode: "dry_run",
|
|
51
|
+
dry_run: true,
|
|
52
|
+
commit: false,
|
|
53
|
+
input_path: input,
|
|
54
|
+
counts: { selected: plan.roots.length, executed: 0, failed: 0 },
|
|
55
|
+
files: {
|
|
56
|
+
summary_json: reportFile,
|
|
57
|
+
progress_jsonl: progress,
|
|
58
|
+
...(successFile ? { report: reportFile, success_list: successFile } : {}),
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
save("edge-support-dry-run.json", report);
|
|
62
|
+
return {
|
|
63
|
+
stage,
|
|
64
|
+
status: report.status,
|
|
65
|
+
report,
|
|
66
|
+
exit_code: 0,
|
|
67
|
+
command: "foundry-edge-support-plan",
|
|
68
|
+
args: [],
|
|
69
|
+
stderr: "",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
73
|
+
const references = new Map(plan.roots.flatMap((root) => root.references).map((ref) => [edgeReferenceKey(ref), ref]));
|
|
74
|
+
const assessedFlowHashes = new Map();
|
|
75
|
+
if (type === "process") {
|
|
76
|
+
for (const row of rows) {
|
|
77
|
+
const documents = workflowObject(workflowObject(row).semantic_context ?? {}).flow_documents;
|
|
78
|
+
if (!Array.isArray(documents))
|
|
79
|
+
continue;
|
|
80
|
+
for (const document of documents) {
|
|
81
|
+
const flow = datasetIdentity(document, 0, "flow");
|
|
82
|
+
const key = `flows:${flow.id}@${flow.version}`;
|
|
83
|
+
const hash = sha256Json(flow.payload);
|
|
84
|
+
if (assessedFlowHashes.has(key) && assessedFlowHashes.get(key) !== hash)
|
|
85
|
+
throw new FoundryContextError("edge_draft_flow_conflict", "Final rows carry competing exact Flow reference evidence.");
|
|
86
|
+
assessedFlowHashes.set(key, hash);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const types = Object.keys(bundleRowTypes);
|
|
91
|
+
if (!receiptFile)
|
|
92
|
+
throw new FoundryContextError("needs_auth", "Exact support dependency lookup requires the verified project receipt.");
|
|
93
|
+
const receipt = parseAuthIdentityReceipt(JSON.parse(fs.readFileSync(receiptFile, "utf8")));
|
|
94
|
+
if (receipt.project.project_ref !== account.projectRef ||
|
|
95
|
+
receipt.identity.user_id !== account.userId)
|
|
96
|
+
throw new FoundryContextError("edge_support_account_mismatch", "The selected dependency receipt belongs to a different account.");
|
|
97
|
+
const expectedOrigin = new URL(receipt.project.project_base_url).origin;
|
|
98
|
+
const referenceDocuments = [];
|
|
99
|
+
const observe = (reference, requestedVersion, observeHead = false) => {
|
|
100
|
+
const key = edgeReferenceKey(reference);
|
|
101
|
+
const dataset = types.find((kind) => bundleRowTypes[kind].plural === reference.table);
|
|
102
|
+
const cliType = dataset === "lifecyclemodel"
|
|
103
|
+
? "model"
|
|
104
|
+
: (dataset ?? (reference.table === "lciamethods" ? "lciamethod" : null));
|
|
105
|
+
if (!cliType)
|
|
106
|
+
throw new FoundryContextError("edge_support_reference_invalid", "Unsupported exact support reference type.");
|
|
107
|
+
const argv = [
|
|
108
|
+
"dataset",
|
|
109
|
+
cliType,
|
|
110
|
+
"get",
|
|
111
|
+
"--id",
|
|
112
|
+
reference.id,
|
|
113
|
+
"--version",
|
|
114
|
+
requestedVersion,
|
|
115
|
+
"--json",
|
|
116
|
+
];
|
|
117
|
+
const execution = bindWorkflowChildExecution(context, qualified, cli.binPath, argv);
|
|
118
|
+
const child = spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
119
|
+
cwd: path.dirname(input),
|
|
120
|
+
env: environment,
|
|
121
|
+
encoding: "utf8",
|
|
122
|
+
shell: false,
|
|
123
|
+
timeout: 30_000,
|
|
124
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
125
|
+
});
|
|
126
|
+
const reject = (error) => {
|
|
127
|
+
throw workflowChildFailure(execution, child, "stage_rejected", error);
|
|
128
|
+
};
|
|
129
|
+
if (child.error || child.signal || child.stderr || ![0, 1].includes(child.status ?? -1))
|
|
130
|
+
reject();
|
|
131
|
+
try {
|
|
132
|
+
const envelope = workflowObject(JSON.parse(child.stdout));
|
|
133
|
+
const observed = workflowObject(envelope.context);
|
|
134
|
+
const selected = workflowObject(observed.effectiveInput);
|
|
135
|
+
if (envelope.schemaVersion !== 1 ||
|
|
136
|
+
envelope.operation !== `dataset ${cliType} get` ||
|
|
137
|
+
typeof observed.environment !== "string" ||
|
|
138
|
+
new URL(observed.environment).origin !== expectedOrigin ||
|
|
139
|
+
selected.id !== reference.id ||
|
|
140
|
+
selected.version !== requestedVersion)
|
|
141
|
+
throw new Error("Typed reference result has a different project, UUID or version.");
|
|
142
|
+
save(`reference-${sha256Json([key, requestedVersion])}.json`, envelope);
|
|
143
|
+
if (envelope.status === "failed" &&
|
|
144
|
+
envelope.outcome === "not_found_or_not_visible" &&
|
|
145
|
+
workflowObject(envelope.error).code === "DATASET_NOT_FOUND") {
|
|
146
|
+
return { ...reference, role: "reference", status: "missing_dataset" };
|
|
147
|
+
}
|
|
148
|
+
const data = workflowObject(envelope.data);
|
|
149
|
+
const subject = workflowObject(data.subject);
|
|
150
|
+
const states = [100, 200];
|
|
151
|
+
const visible = typeof subject.stateCode === "number" &&
|
|
152
|
+
(states.includes(subject.stateCode) ||
|
|
153
|
+
(subject.stateCode === 0 && subject.owner === account.userId));
|
|
154
|
+
if (child.status !== 0 ||
|
|
155
|
+
envelope.status !== "completed" ||
|
|
156
|
+
envelope.error !== null ||
|
|
157
|
+
envelope.outcome !== "dataset_read" ||
|
|
158
|
+
subject.type !== cliType ||
|
|
159
|
+
subject.id !== reference.id ||
|
|
160
|
+
typeof subject.version !== "string")
|
|
161
|
+
throw new Error("Typed reference result does not prove the exact visible version.");
|
|
162
|
+
const content = workflowObject(data.content);
|
|
163
|
+
const observedHash = sha256Json(content);
|
|
164
|
+
if (requestedVersion !== "latest" &&
|
|
165
|
+
(dataset === "flow" || dataset === "flowproperty" || dataset === "unitgroup"))
|
|
166
|
+
referenceDocuments.push(content);
|
|
167
|
+
const expectedHash = requestedVersion === "latest" ? undefined : assessedFlowHashes.get(key);
|
|
168
|
+
return {
|
|
169
|
+
...reference,
|
|
170
|
+
role: "reference",
|
|
171
|
+
status: expectedHash && expectedHash !== observedHash
|
|
172
|
+
? "payload_mismatch"
|
|
173
|
+
: visible && (observeHead || subject.version === reference.version)
|
|
174
|
+
? "ok"
|
|
175
|
+
: "state_code_mismatch",
|
|
176
|
+
remote_user_id: subject.owner,
|
|
177
|
+
remote_state_code: subject.stateCode,
|
|
178
|
+
remote_payload_sha256: observedHash,
|
|
179
|
+
observed_version: subject.version,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return reject(error);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const matchesReview = (observed, expected) => observed.status === "ok" &&
|
|
187
|
+
"remote_payload_sha256" in observed &&
|
|
188
|
+
observed.remote_payload_sha256 === expected.payload_sha256 &&
|
|
189
|
+
observed.remote_user_id === expected.user_id &&
|
|
190
|
+
observed.remote_state_code === expected.state_code;
|
|
191
|
+
const checks = [...references].map(([key, reference]) => {
|
|
192
|
+
const observed = observe(reference, reference.version);
|
|
193
|
+
const review = intent?.reviewed.get(key);
|
|
194
|
+
if (!review)
|
|
195
|
+
return observed;
|
|
196
|
+
const latest = observe(review.latest, "latest");
|
|
197
|
+
return {
|
|
198
|
+
...observed,
|
|
199
|
+
status: matchesReview(observed, review.selected) && matchesReview(latest, review.latest)
|
|
200
|
+
? "ok"
|
|
201
|
+
: "reference_intent_drift",
|
|
202
|
+
reviewed_latest: review.latest,
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
const blockers = checks
|
|
206
|
+
.filter((check) => check.status !== "ok")
|
|
207
|
+
.map((check) => ({ ...check, code: check.status }));
|
|
208
|
+
const flowHeads = type === "flow"
|
|
209
|
+
? plan.roots.map((root) => {
|
|
210
|
+
const observed = observe(root, "latest", true);
|
|
211
|
+
if (observed.status === "missing_dataset")
|
|
212
|
+
return { id: root.id, head: null };
|
|
213
|
+
if (observed.status === "ok" &&
|
|
214
|
+
"observed_version" in observed &&
|
|
215
|
+
isNextFlowVersion(observed.observed_version, root.version) &&
|
|
216
|
+
typeof observed.remote_user_id === "string" &&
|
|
217
|
+
(observed.remote_state_code === 100 ||
|
|
218
|
+
(observed.remote_state_code === 0 && observed.remote_user_id === account.userId))) {
|
|
219
|
+
return {
|
|
220
|
+
id: root.id,
|
|
221
|
+
head: {
|
|
222
|
+
table: root.table,
|
|
223
|
+
id: root.id,
|
|
224
|
+
version: observed.observed_version,
|
|
225
|
+
user_id: observed.remote_user_id,
|
|
226
|
+
state_code: observed.remote_state_code,
|
|
227
|
+
payload_sha256: observed.remote_payload_sha256,
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
blockers.push({ ...observed, code: "flow_target_not_next_version" });
|
|
232
|
+
return { id: root.id, head: null };
|
|
233
|
+
})
|
|
234
|
+
: null;
|
|
235
|
+
const reportFile = path.join(output, "edge-support-precommit.json");
|
|
236
|
+
const report = {
|
|
237
|
+
schema: "tiangong-foundry.edge-support-precommit.v1",
|
|
238
|
+
status: blockers.length ? "blocked_remote_verification" : "passed_remote_verification",
|
|
239
|
+
input_path: input,
|
|
240
|
+
edge_plan_sha256: plan.sha256,
|
|
241
|
+
checks,
|
|
242
|
+
blockers,
|
|
243
|
+
counts: { rows: rows.length, blockers: blockers.length },
|
|
244
|
+
...(intent ? { reference_intent: intent.binding } : {}),
|
|
245
|
+
...(flowHeads ? { flow_heads: flowHeads } : {}),
|
|
246
|
+
files: { report: reportFile },
|
|
247
|
+
};
|
|
248
|
+
save("edge-support-precommit.json", report);
|
|
249
|
+
return {
|
|
250
|
+
stage,
|
|
251
|
+
status: report.status,
|
|
252
|
+
report,
|
|
253
|
+
exit_code: blockers.length ? 1 : 0,
|
|
254
|
+
referenceDocuments,
|
|
255
|
+
command: "foundry-edge-support-dependency-read",
|
|
256
|
+
args: [],
|
|
257
|
+
stderr: "",
|
|
258
|
+
};
|
|
259
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { createFoundryEdgeActor } from "./foundry-edge-session.ts";
|
|
2
|
+
import type { EdgeSupportPlan, EdgeSupportRoot } from "./foundry-edge-support-plan.ts";
|
|
3
|
+
type Actor = Pick<Awaited<ReturnType<typeof createFoundryEdgeActor>>, "receipt" | "post">;
|
|
4
|
+
type RootContent = {
|
|
5
|
+
root: EdgeSupportRoot;
|
|
6
|
+
content: Record<string, unknown>;
|
|
7
|
+
beforeContent?: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
export declare function verifyFoundryEdgeSupport(actor: Actor, plan: EdgeSupportPlan, phase: "before" | "after", retainRepairReferences?: boolean): Promise<{
|
|
10
|
+
responses: unknown[];
|
|
11
|
+
blockers: {
|
|
12
|
+
table: string;
|
|
13
|
+
id: string;
|
|
14
|
+
version: string;
|
|
15
|
+
role: string;
|
|
16
|
+
}[];
|
|
17
|
+
}>;
|
|
18
|
+
export declare function dispatchFoundryEdgeSupport(actor: Actor, plan: EdgeSupportPlan, rows: RootContent[], createModel?: (root: EdgeSupportRoot, content: Record<string, unknown>) => unknown): Promise<unknown[]>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { FoundryContextError } from "./foundry-runtime-context.js";
|
|
2
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
3
|
+
function object(value) {
|
|
4
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
5
|
+
return {};
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
function assertActor(actor, plan) {
|
|
9
|
+
if (actor.receipt.project.project_ref !== plan.project_ref ||
|
|
10
|
+
actor.receipt.identity.user_id !== plan.user_id)
|
|
11
|
+
throw new FoundryContextError("edge_support_account_mismatch", "The Edge actor differs from the sealed draft owner.");
|
|
12
|
+
}
|
|
13
|
+
// Verify the original exact content and dependencies even when an HTTP mutation response was lost.
|
|
14
|
+
export async function verifyFoundryEdgeSupport(actor, plan, phase, retainRepairReferences = Boolean(plan.update)) {
|
|
15
|
+
assertActor(actor, plan);
|
|
16
|
+
const responses = [];
|
|
17
|
+
const blockers = [];
|
|
18
|
+
const candidate = phase === "before" && !plan.update;
|
|
19
|
+
const rootPolicy = candidate ? "candidate" : "existing";
|
|
20
|
+
for (const root of plan.roots) {
|
|
21
|
+
const expectedRootSha256 = phase === "before" && plan.update ? root.before_sha256 : root.payload_sha256;
|
|
22
|
+
const dependencies = root.references.flatMap((reference) => {
|
|
23
|
+
const selected = {
|
|
24
|
+
table: reference.table,
|
|
25
|
+
id: reference.id,
|
|
26
|
+
version: reference.version,
|
|
27
|
+
role: "reference",
|
|
28
|
+
requirePayload: true,
|
|
29
|
+
expectedJsonSha256: reference.payload_sha256,
|
|
30
|
+
expectedStateCodes: reference.expected_state_code === undefined ? [] : [reference.expected_state_code],
|
|
31
|
+
};
|
|
32
|
+
const latest = reference.reviewed_latest;
|
|
33
|
+
const expected = {
|
|
34
|
+
request: selected,
|
|
35
|
+
owner: reference.expected_owner,
|
|
36
|
+
latest: latest?.version,
|
|
37
|
+
};
|
|
38
|
+
return !latest || latest.version === reference.version
|
|
39
|
+
? [expected]
|
|
40
|
+
: [
|
|
41
|
+
expected,
|
|
42
|
+
{
|
|
43
|
+
request: {
|
|
44
|
+
...selected,
|
|
45
|
+
version: latest.version,
|
|
46
|
+
expectedJsonSha256: latest.payload_sha256,
|
|
47
|
+
expectedStateCodes: [latest.state_code],
|
|
48
|
+
},
|
|
49
|
+
owner: latest.user_id,
|
|
50
|
+
latest: latest.version,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
});
|
|
54
|
+
if (candidate && root.flow_head) {
|
|
55
|
+
const head = root.flow_head;
|
|
56
|
+
dependencies.push({
|
|
57
|
+
request: {
|
|
58
|
+
table: head.table,
|
|
59
|
+
id: head.id,
|
|
60
|
+
version: head.version,
|
|
61
|
+
role: "reference",
|
|
62
|
+
requirePayload: true,
|
|
63
|
+
expectedJsonSha256: head.payload_sha256,
|
|
64
|
+
expectedStateCodes: [head.state_code],
|
|
65
|
+
},
|
|
66
|
+
owner: head.user_id,
|
|
67
|
+
latest: head.version,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const references = [
|
|
71
|
+
{
|
|
72
|
+
table: root.table,
|
|
73
|
+
id: root.id,
|
|
74
|
+
version: root.version,
|
|
75
|
+
role: "root",
|
|
76
|
+
expectedStateCodes: [0],
|
|
77
|
+
expectedJsonSha256: expectedRootSha256,
|
|
78
|
+
requirePayload: true,
|
|
79
|
+
},
|
|
80
|
+
...dependencies.map(({ request }) => request),
|
|
81
|
+
];
|
|
82
|
+
const payload = await actor.post("app_dataset_verify_remote", {
|
|
83
|
+
rootPolicy,
|
|
84
|
+
references,
|
|
85
|
+
});
|
|
86
|
+
const envelope = object(payload);
|
|
87
|
+
const report = object(envelope.data);
|
|
88
|
+
const checks = report.checks;
|
|
89
|
+
if (envelope.command !== "dataset_verify_remote" ||
|
|
90
|
+
report.root_policy !== rootPolicy ||
|
|
91
|
+
!Array.isArray(checks) ||
|
|
92
|
+
checks.length !== references.length)
|
|
93
|
+
throw new FoundryContextError("edge_support_readback_invalid", "Exact Edge verification returned incomplete evidence.");
|
|
94
|
+
responses.push(payload);
|
|
95
|
+
references.forEach((reference, index) => {
|
|
96
|
+
const check = object(checks[index]);
|
|
97
|
+
const dependency = dependencies[index - 1];
|
|
98
|
+
const same = check.index === index &&
|
|
99
|
+
check.id === reference.id &&
|
|
100
|
+
check.table === reference.table &&
|
|
101
|
+
check.role === reference.role &&
|
|
102
|
+
check.version === reference.version;
|
|
103
|
+
const expectedStatus = dependency?.latest && dependency.latest > reference.version ? "version_outdated" : "ok";
|
|
104
|
+
const unchangedRepairReference = retainRepairReferences &&
|
|
105
|
+
reference.role === "reference" &&
|
|
106
|
+
dependency.latest === undefined &&
|
|
107
|
+
check.status === "version_outdated" &&
|
|
108
|
+
typeof check.latest_version === "string" &&
|
|
109
|
+
/^\d{2}\.\d{2}\.\d{3}$/u.test(check.latest_version) &&
|
|
110
|
+
check.latest_version > reference.version;
|
|
111
|
+
const exact = (check.status === expectedStatus || unchangedRepairReference) &&
|
|
112
|
+
check.exact_version === reference.version &&
|
|
113
|
+
check.payload_present === true;
|
|
114
|
+
const expected = reference.role === "root"
|
|
115
|
+
? candidate
|
|
116
|
+
? check.status === "candidate_root" &&
|
|
117
|
+
check.exact_version === null &&
|
|
118
|
+
check.latest_version === (root.flow_head?.version ?? null)
|
|
119
|
+
: exact &&
|
|
120
|
+
check.state_code === 0 &&
|
|
121
|
+
check.user_id === plan.user_id &&
|
|
122
|
+
check.actual_json_sha256 === expectedRootSha256
|
|
123
|
+
: exact &&
|
|
124
|
+
check.actual_json_sha256 === reference.expectedJsonSha256 &&
|
|
125
|
+
check.state_code === reference.expectedStateCodes[0] &&
|
|
126
|
+
check.user_id === dependency.owner &&
|
|
127
|
+
(dependency.latest === undefined || check.latest_version === dependency.latest);
|
|
128
|
+
if (!same || !expected)
|
|
129
|
+
blockers.push({
|
|
130
|
+
table: reference.table,
|
|
131
|
+
id: reference.id,
|
|
132
|
+
version: reference.version,
|
|
133
|
+
role: reference.role,
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return { responses, blockers };
|
|
138
|
+
}
|
|
139
|
+
export async function dispatchFoundryEdgeSupport(actor, plan, rows, createModel) {
|
|
140
|
+
assertActor(actor, plan);
|
|
141
|
+
if (rows.length !== plan.roots.length ||
|
|
142
|
+
rows.some(({ root, content, beforeContent }, index) => {
|
|
143
|
+
const sealed = plan.roots[index];
|
|
144
|
+
return (root.table !== sealed.table ||
|
|
145
|
+
root.id !== sealed.id ||
|
|
146
|
+
root.version !== sealed.version ||
|
|
147
|
+
sha256Json(content) !== sealed.payload_sha256 ||
|
|
148
|
+
(plan.update
|
|
149
|
+
? !beforeContent || sha256Json(beforeContent) !== sealed.before_sha256
|
|
150
|
+
: beforeContent !== undefined));
|
|
151
|
+
}))
|
|
152
|
+
throw new FoundryContextError("edge_support_input_changed", "The exact Edge request differs from the sealed final rows.");
|
|
153
|
+
const acknowledgements = [];
|
|
154
|
+
const operation = plan.update ? "dataset_save_draft" : "dataset_create";
|
|
155
|
+
for (const { root, content, beforeContent } of rows) {
|
|
156
|
+
if (beforeContent && sha256Json(beforeContent) === sha256Json(content))
|
|
157
|
+
continue;
|
|
158
|
+
if (plan.dataset_type === "lifecyclemodel") {
|
|
159
|
+
if (!createModel)
|
|
160
|
+
throw new FoundryContextError("model_draft_write_unavailable", "Model drafts require the installed typed Model transaction.");
|
|
161
|
+
acknowledgements.push(await createModel(root, content));
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const response = await actor.post(plan.update ? "app_dataset_save_draft" : "app_dataset_create", {
|
|
165
|
+
table: root.table,
|
|
166
|
+
id: root.id,
|
|
167
|
+
jsonOrdered: content,
|
|
168
|
+
...(plan.update
|
|
169
|
+
? {
|
|
170
|
+
version: root.version,
|
|
171
|
+
expectedJsonOrdered: beforeContent,
|
|
172
|
+
ruleVerification: plan.update.rule_verification[root.payload_sha256],
|
|
173
|
+
}
|
|
174
|
+
: {}),
|
|
175
|
+
});
|
|
176
|
+
const envelope = object(response);
|
|
177
|
+
const row = object(envelope.data);
|
|
178
|
+
if (envelope.command !== operation ||
|
|
179
|
+
envelope.ok !== true ||
|
|
180
|
+
row.id !== root.id ||
|
|
181
|
+
row.version !== root.version ||
|
|
182
|
+
row.state_code !== 0 ||
|
|
183
|
+
row.user_id !== plan.user_id)
|
|
184
|
+
throw new FoundryContextError("edge_support_result_unproven", "The Edge draft write needs exact readback.");
|
|
185
|
+
acknowledgements.push(envelope);
|
|
186
|
+
}
|
|
187
|
+
return acknowledgements;
|
|
188
|
+
}
|
|
@@ -5,10 +5,12 @@ import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
|
5
5
|
import { type VerifiedFoundryIdentity } from "./foundry-runtime-identity.ts";
|
|
6
6
|
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
7
7
|
import { type TaskAuthorizationAction, type ValidatedTaskAuthorization } from "./task-authorization.ts";
|
|
8
|
+
import { type EdgeSupportPlan } from "./foundry-edge-support-plan.ts";
|
|
9
|
+
type OwnerDispatchSpec = FoundryCommandSpec | EdgeSupportPlan;
|
|
8
10
|
export interface FoundryExecutionAdmission {
|
|
9
11
|
readonly capsule: Readonly<ExecutionCapsule>;
|
|
10
12
|
readonly capsule_file: string;
|
|
11
|
-
readonly command_spec: Readonly<
|
|
13
|
+
readonly command_spec: Readonly<OwnerDispatchSpec>;
|
|
12
14
|
readonly authorization: ValidatedTaskAuthorization;
|
|
13
15
|
}
|
|
14
16
|
export interface CreateFoundryExecutionCapsuleOptions {
|
|
@@ -30,4 +32,4 @@ export declare function createFoundryExecutionCapsule(context: FoundryRuntimeCon
|
|
|
30
32
|
}>>;
|
|
31
33
|
export declare function rehydrateFoundryExecutionAdmission(context: FoundryRuntimeContext, qualification: QualifiedFoundryRuntime, identity: VerifiedFoundryIdentity, options: RehydrateFoundryExecutionAdmissionOptions): Promise<FoundryExecutionAdmission>;
|
|
32
34
|
/** Re-run every external fact immediately before handing the spec to the existing no-replay owner. */
|
|
33
|
-
export declare function assertFoundryExecutionAdmission(context: FoundryRuntimeContext, qualification: QualifiedFoundryRuntime, identity: VerifiedFoundryIdentity, admission: FoundryExecutionAdmission): Promise<
|
|
35
|
+
export declare function assertFoundryExecutionAdmission(context: FoundryRuntimeContext, qualification: QualifiedFoundryRuntime, identity: VerifiedFoundryIdentity, admission: FoundryExecutionAdmission): Promise<OwnerDispatchSpec>;
|
|
@@ -16,6 +16,11 @@ import { taskAuthorizationAllows, taskAuthorizationWaivesQa, } from "./task-auth
|
|
|
16
16
|
import { bytes, digest } from "./foundry-task-io.js";
|
|
17
17
|
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
18
18
|
import { assertFoundryMigrationNoReplay } from "./foundry-migration-replay.js";
|
|
19
|
+
import { isEdgeSupportPlan } from "./foundry-edge-support-plan.js";
|
|
20
|
+
import { verifySelectedEdgeDraftPlan } from "./foundry-edge-draft-admission.js";
|
|
21
|
+
function parseOwnerDispatchSpec(value) {
|
|
22
|
+
return isEdgeSupportPlan(value) ? value : parseFoundryCommandSpec(value);
|
|
23
|
+
}
|
|
19
24
|
const admissions = new WeakSet();
|
|
20
25
|
function fail(code, message) {
|
|
21
26
|
throw new FoundryContextError(code, message);
|
|
@@ -203,7 +208,24 @@ async function verifyAdmission(context, qualification, identity, capsule, specVa
|
|
|
203
208
|
if (!taskAuthorizationWaivesQa(authorization, "process", code))
|
|
204
209
|
fail("execution_qa_waiver_required", "Current final rows require a QA waiver not present in current authorization.");
|
|
205
210
|
}
|
|
206
|
-
const
|
|
211
|
+
const parsed = parseOwnerDispatchSpec(specValue);
|
|
212
|
+
let spec;
|
|
213
|
+
if (isEdgeSupportPlan(parsed)) {
|
|
214
|
+
if (qualification.cli.expectation.package_version !== "0.4.0" ||
|
|
215
|
+
((parsed.dataset_type === "unitgroup" || parsed.dataset_type === "flowproperty") &&
|
|
216
|
+
(!capsule.required_actions.includes("canonical_support_local_mint") ||
|
|
217
|
+
!capsule.required_actions.includes(`${parsed.dataset_type}_write`))) ||
|
|
218
|
+
!context.accountIntent)
|
|
219
|
+
fail("execution_action_unauthorized", "Edge draft creation requires current task authorization for the exact scope.");
|
|
220
|
+
verifySelectedEdgeDraftPlan(context, parsed, finalRows, {
|
|
221
|
+
project_ref: context.accountIntent.projectRef,
|
|
222
|
+
user_id: context.accountIntent.userId,
|
|
223
|
+
});
|
|
224
|
+
spec = parsed;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
spec = commandSpec(context, specValue, finalRows, capsule.required_actions);
|
|
228
|
+
}
|
|
207
229
|
if (spec.sha256 !== capsule.command_spec_sha256)
|
|
208
230
|
fail("execution_command_changed", "CommandSpec differs from the reviewed execution capsule.");
|
|
209
231
|
assertQualifiedFoundryRuntime(context, qualification);
|
|
@@ -224,7 +246,7 @@ export async function createFoundryExecutionCapsule(context, qualification, iden
|
|
|
224
246
|
assertFoundryQualityReviewForExecution(context, qualification, readVerifiedTaskSnapshot(context).index, finalRows.path);
|
|
225
247
|
assertFoundryMigrationNoReplay(context, finalRows.path);
|
|
226
248
|
const authorization = await loadFoundryTaskAuthorization(context, identity, finalRows.path, qualification);
|
|
227
|
-
const spec =
|
|
249
|
+
const spec = parseOwnerDispatchSpec(options.commandSpec);
|
|
228
250
|
const capsule = parseCapsule({
|
|
229
251
|
schema: FOUNDRY_EXECUTION_CAPSULE_SCHEMA,
|
|
230
252
|
workspace_id: context.workspaceId,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { createFoundryIdentityOwners } from "./foundry-identity-owners.ts";
|
|
2
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
3
|
+
import type { FoundryAuthentication } from "./foundry-runtime-identity.ts";
|
|
4
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
5
|
+
export declare function refreshFoundryFinalizeIdentity(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication, owner: ReturnType<typeof createFoundryIdentityOwners>, scope: {
|
|
6
|
+
rowsFile: string;
|
|
7
|
+
outDir: string;
|
|
8
|
+
type: "flow" | "process";
|
|
9
|
+
index: string;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
stage: string;
|
|
12
|
+
status: string;
|
|
13
|
+
report: {
|
|
14
|
+
schema: string;
|
|
15
|
+
status: string;
|
|
16
|
+
counts: {
|
|
17
|
+
selected_rows: number;
|
|
18
|
+
completed: number;
|
|
19
|
+
skipped_existing_report: number;
|
|
20
|
+
failed: number;
|
|
21
|
+
};
|
|
22
|
+
index_file: string;
|
|
23
|
+
base_index_file: string;
|
|
24
|
+
edge_report: string | null;
|
|
25
|
+
};
|
|
26
|
+
report_file: string;
|
|
27
|
+
index_file: string;
|
|
28
|
+
base_index_file: string;
|
|
29
|
+
refresh_required: boolean;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
3
|
+
import { readIdentityPreflightIndexRow } from "./import-curation/internal/workflow-identity-preflight.js";
|
|
4
|
+
import { runFoundryEdgeIdentityPreflight } from "./foundry-edge-identity-preflight.js";
|
|
5
|
+
import { assertWorkflowReportArtifact } from "./foundry-workflow-io.js";
|
|
6
|
+
import { FoundryContextError, readFoundryInput, resolveFoundryOutput, writeFoundryArtifact, } from "./foundry-runtime-context.js";
|
|
7
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
8
|
+
export async function refreshFoundryFinalizeIdentity(context, qualified, authentication, owner, scope) {
|
|
9
|
+
const invalid = () => new FoundryContextError("finalize_identity_inputs_invalid", "Finalization requires an audited request for each exact cleaned row.");
|
|
10
|
+
const { rowsFile, type } = scope;
|
|
11
|
+
const outDir = resolveFoundryOutput(context, path.join(scope.outDir, "identity-preflight-run"));
|
|
12
|
+
const baseIndex = resolveFoundryOutput(context, scope.index);
|
|
13
|
+
const previous = readRows(baseIndex, (file) => readFoundryInput(context, file).toString("utf8")).map(workflowObject);
|
|
14
|
+
const prepared = workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightRequestsBuild({
|
|
15
|
+
type,
|
|
16
|
+
rowsFile,
|
|
17
|
+
sourceIndex: baseIndex,
|
|
18
|
+
outDir: path.join(outDir, "requests"),
|
|
19
|
+
})));
|
|
20
|
+
const candidate = workflowObject(prepared.files).identity_preflight_requests;
|
|
21
|
+
if (prepared.status !== "ready" || typeof candidate !== "string")
|
|
22
|
+
throw invalid();
|
|
23
|
+
const preparedIndex = assertWorkflowReportArtifact(context, path.resolve(context.assetRoot, candidate), outDir);
|
|
24
|
+
const current = readRows(preparedIndex).map(workflowObject);
|
|
25
|
+
const key = (row) => JSON.stringify([row.dataset_type, row.dataset_id, row.dataset_version, row.target_sha256]);
|
|
26
|
+
const original = new Map(previous.map((row) => [key(row), row]));
|
|
27
|
+
const retained = new Map();
|
|
28
|
+
const pending = current.filter((row) => {
|
|
29
|
+
const old = original.get(key(row));
|
|
30
|
+
if (!old ||
|
|
31
|
+
old.dataset_type !== type ||
|
|
32
|
+
old.command !== `POST ${type}_hybrid_search` ||
|
|
33
|
+
old.expected_project_ref !== context.accountIntent?.projectRef ||
|
|
34
|
+
old.expected_user_id !== context.accountIntent?.userId)
|
|
35
|
+
return true;
|
|
36
|
+
for (const locator of [
|
|
37
|
+
old.request_file,
|
|
38
|
+
old.expected_report_file,
|
|
39
|
+
old.execution_manifest_file,
|
|
40
|
+
]) {
|
|
41
|
+
if (typeof locator !== "string")
|
|
42
|
+
throw invalid();
|
|
43
|
+
readFoundryInput(context, path.resolve(context.assetRoot, locator));
|
|
44
|
+
}
|
|
45
|
+
if (readIdentityPreflightIndexRow(context.assetRoot, baseIndex, old)?.status !== "completed")
|
|
46
|
+
throw invalid();
|
|
47
|
+
retained.set(key(row), old);
|
|
48
|
+
return false;
|
|
49
|
+
});
|
|
50
|
+
if (!current.length ||
|
|
51
|
+
current.some((row) => row.dataset_type !== type) ||
|
|
52
|
+
new Set(current.map(key)).size !== current.length)
|
|
53
|
+
throw invalid();
|
|
54
|
+
const write = (file, rows) => writeFoundryArtifact(context, file, rows.map((row) => JSON.stringify(row) + "\n").join(""));
|
|
55
|
+
let edgeReport = null;
|
|
56
|
+
if (pending.length) {
|
|
57
|
+
const pendingIndex = path.join(outDir, "pending.jsonl");
|
|
58
|
+
write(pendingIndex, pending);
|
|
59
|
+
const audit = owner.invoke(() => owner.preflight.runDatasetIdentityPreflightQueryAudit({
|
|
60
|
+
index: pendingIndex,
|
|
61
|
+
outDir: path.join(outDir, "query-audit"),
|
|
62
|
+
}));
|
|
63
|
+
if (audit.status !== "passed")
|
|
64
|
+
throw invalid();
|
|
65
|
+
const edge = await runFoundryEdgeIdentityPreflight(context, qualified, authentication, type, pendingIndex, path.join(outDir, "edge"));
|
|
66
|
+
edgeReport = edge.files.report;
|
|
67
|
+
for (const row of readRows(edge.index).map(workflowObject))
|
|
68
|
+
retained.set(key(row), row);
|
|
69
|
+
}
|
|
70
|
+
const finalRows = current.map((row) => {
|
|
71
|
+
const matched = retained.get(key(row));
|
|
72
|
+
if (!matched)
|
|
73
|
+
throw invalid();
|
|
74
|
+
return matched;
|
|
75
|
+
});
|
|
76
|
+
const indexFile = path.join(outDir, "identity-preflight-requests.jsonl");
|
|
77
|
+
write(indexFile, [...previous.filter((row) => row.dataset_type !== type), ...finalRows]);
|
|
78
|
+
const reportFile = path.join(outDir, "finalize-identity-refresh.json");
|
|
79
|
+
const report = {
|
|
80
|
+
schema: "tiangong-foundry.finalize-edge-identity.v1",
|
|
81
|
+
status: "completed_with_identity_findings",
|
|
82
|
+
counts: {
|
|
83
|
+
selected_rows: current.length,
|
|
84
|
+
completed: current.length,
|
|
85
|
+
skipped_existing_report: current.length - pending.length,
|
|
86
|
+
failed: 0,
|
|
87
|
+
},
|
|
88
|
+
index_file: indexFile,
|
|
89
|
+
base_index_file: baseIndex,
|
|
90
|
+
edge_report: edgeReport,
|
|
91
|
+
};
|
|
92
|
+
writeFoundryArtifact(context, reportFile, JSON.stringify(report, null, 2) + "\n");
|
|
93
|
+
return {
|
|
94
|
+
stage: "identity_preflight_run",
|
|
95
|
+
status: report.status,
|
|
96
|
+
report,
|
|
97
|
+
report_file: reportFile,
|
|
98
|
+
index_file: indexFile,
|
|
99
|
+
base_index_file: baseIndex,
|
|
100
|
+
refresh_required: pending.length > 0,
|
|
101
|
+
};
|
|
102
|
+
}
|