@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,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>;
|
|
@@ -10,11 +10,17 @@ import { assertVerifiedFoundryIdentity, } from "./foundry-runtime-identity.js";
|
|
|
10
10
|
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
11
11
|
import { foundryRuntimeCommandPolicy } from "./foundry-runtime-command-policy.js";
|
|
12
12
|
import { loadFoundryTaskAuthorization } from "./foundry-task-authorization.js";
|
|
13
|
-
import { assertFoundryTaskInputLineage } from "./foundry-task-store.js";
|
|
13
|
+
import { assertFoundryTaskInputLineage, readVerifiedTaskSnapshot } from "./foundry-task-store.js";
|
|
14
|
+
import { assertFoundryQualityReviewForExecution } from "./foundry-quality-review.js";
|
|
14
15
|
import { taskAuthorizationAllows, taskAuthorizationWaivesQa, } from "./task-authorization.js";
|
|
15
16
|
import { bytes, digest } from "./foundry-task-io.js";
|
|
16
17
|
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
17
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
|
+
}
|
|
18
24
|
const admissions = new WeakSet();
|
|
19
25
|
function fail(code, message) {
|
|
20
26
|
throw new FoundryContextError(code, message);
|
|
@@ -188,6 +194,7 @@ async function verifyAdmission(context, qualification, identity, capsule, specVa
|
|
|
188
194
|
fail("execution_command_unadmitted", "Selected command is not a qualified task stage.");
|
|
189
195
|
const approved = selected(context, capsule.approved_input.path);
|
|
190
196
|
const finalRows = selected(context, capsule.final_rows.path);
|
|
197
|
+
assertFoundryQualityReviewForExecution(context, qualification, readVerifiedTaskSnapshot(context).index, finalRows.path);
|
|
191
198
|
assertFoundryMigrationNoReplay(context, finalRows.path);
|
|
192
199
|
if (!sameFact(approved, capsule.approved_input) || !sameFact(finalRows, capsule.final_rows))
|
|
193
200
|
fail("execution_input_changed", "Capsule input facts differ from current host selection.");
|
|
@@ -201,7 +208,24 @@ async function verifyAdmission(context, qualification, identity, capsule, specVa
|
|
|
201
208
|
if (!taskAuthorizationWaivesQa(authorization, "process", code))
|
|
202
209
|
fail("execution_qa_waiver_required", "Current final rows require a QA waiver not present in current authorization.");
|
|
203
210
|
}
|
|
204
|
-
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
|
+
}
|
|
205
229
|
if (spec.sha256 !== capsule.command_spec_sha256)
|
|
206
230
|
fail("execution_command_changed", "CommandSpec differs from the reviewed execution capsule.");
|
|
207
231
|
assertQualifiedFoundryRuntime(context, qualification);
|
|
@@ -219,9 +243,10 @@ export async function createFoundryExecutionCapsule(context, qualification, iden
|
|
|
219
243
|
assertVerifiedFoundryIdentity(context, identity, qualification);
|
|
220
244
|
const approved = selected(context, options.approvedInputFile);
|
|
221
245
|
const finalRows = selected(context, options.finalRowsFile);
|
|
246
|
+
assertFoundryQualityReviewForExecution(context, qualification, readVerifiedTaskSnapshot(context).index, finalRows.path);
|
|
222
247
|
assertFoundryMigrationNoReplay(context, finalRows.path);
|
|
223
248
|
const authorization = await loadFoundryTaskAuthorization(context, identity, finalRows.path, qualification);
|
|
224
|
-
const spec =
|
|
249
|
+
const spec = parseOwnerDispatchSpec(options.commandSpec);
|
|
225
250
|
const capsule = parseCapsule({
|
|
226
251
|
schema: FOUNDRY_EXECUTION_CAPSULE_SCHEMA,
|
|
227
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
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { runFoundryTypedDatasetQa } from "./foundry-typed-flow-qa.js";
|
|
5
|
+
import { isFoundryEdgeDraftType } from "./foundry-edge-support-plan.js";
|
|
6
|
+
import { planFoundryEdgeSupportStage } from "./foundry-edge-support-planning.js";
|
|
7
|
+
import { buildFoundryCurationQueue } from "./foundry-curation-queue.js";
|
|
8
|
+
import { bindWorkflowChildExecution, workflowChildFailure, } from "./foundry-workflow-child-failure.js";
|
|
2
9
|
import { parseScalar } from "./foundry-args.js";
|
|
3
10
|
import { createFoundryRuntimeUtils, resolveTiangongLcaCliRuntimeCommand, } from "./foundry-runtime-utils.js";
|
|
4
11
|
import { createTidasRowUtils } from "./tidas-row-utils.js";
|
|
@@ -26,9 +33,9 @@ import { runTidasRowsValidation } from "./tidas-adapter.js";
|
|
|
26
33
|
import { ensureArray } from "./import-curation/internal/runtime-io.js";
|
|
27
34
|
import { datasetIdentity, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
|
|
28
35
|
import { workflowObject } from "./foundry-workflow-state.js";
|
|
29
|
-
import { runWorkflowLocalCliResult } from "./foundry-workflow-io.js";
|
|
36
|
+
import { assertWorkflowReportArtifact, runWorkflowLocalCliResult } from "./foundry-workflow-io.js";
|
|
30
37
|
import { createFoundryIsolatedChildEnvironment } from "./foundry-runtime-environment.js";
|
|
31
|
-
import { FoundryContextError } from "./foundry-runtime-context.js";
|
|
38
|
+
import { FoundryContextError, readFoundryInput, resolveFoundryOutput, writeFoundryArtifact, } from "./foundry-runtime-context.js";
|
|
32
39
|
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
33
40
|
function bind(factory, dependencies) {
|
|
34
41
|
return factory(dependencies);
|
|
@@ -39,6 +46,18 @@ export function createFoundryFinalizeOwners(context, qualified, temporary, execu
|
|
|
39
46
|
const runtime = createFoundryRuntimeUtils({ parseScalar, repoRoot: context.assetRoot });
|
|
40
47
|
const rows = createTidasRowUtils({ ...runtime, bundleRowTypes });
|
|
41
48
|
const localEnvironment = createFoundryIsolatedChildEnvironment({ tempRoot: temporary });
|
|
49
|
+
const readStageRows = (file) => {
|
|
50
|
+
const selected = runtime.resolveRepoPath(file);
|
|
51
|
+
if (execution.outputRoot) {
|
|
52
|
+
const relative = path.relative(execution.outputRoot, selected);
|
|
53
|
+
if (relative &&
|
|
54
|
+
relative !== ".." &&
|
|
55
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
56
|
+
!path.isAbsolute(relative))
|
|
57
|
+
return fs.readFileSync(assertWorkflowReportArtifact(context, selected, execution.outputRoot));
|
|
58
|
+
}
|
|
59
|
+
return readFoundryInput(context, selected);
|
|
60
|
+
};
|
|
42
61
|
const cli = resolveTiangongLcaCliRuntimeCommand({});
|
|
43
62
|
const base = {
|
|
44
63
|
...runtime,
|
|
@@ -87,7 +106,27 @@ export function createFoundryFinalizeOwners(context, qualified, temporary, execu
|
|
|
87
106
|
const finalizeUtils = bind(createPostAuthoringFinalizeUtils, {
|
|
88
107
|
...base,
|
|
89
108
|
...references,
|
|
90
|
-
cliWrapperCommands:
|
|
109
|
+
cliWrapperCommands: qualified.cli.expectation.package_version === "0.4.0"
|
|
110
|
+
? {
|
|
111
|
+
...cliWrappers,
|
|
112
|
+
runDatasetCurationQueueBuild: (options) => {
|
|
113
|
+
const file = (value) => resolveFoundryOutput(context, String(value));
|
|
114
|
+
const processes = file(options.processes);
|
|
115
|
+
return buildFoundryCurationQueue({
|
|
116
|
+
processes,
|
|
117
|
+
flows: options.flows ? runtime.resolveRepoPath(options.flows) : null,
|
|
118
|
+
support: runtime
|
|
119
|
+
.normalizedList(options.support)
|
|
120
|
+
.map((name) => runtime.resolveRepoPath(name)),
|
|
121
|
+
external: runtime
|
|
122
|
+
.normalizedList(options.externalFlowRef)
|
|
123
|
+
.map((name) => runtime.resolveRepoPath(name)),
|
|
124
|
+
outDir: file(options.outDir),
|
|
125
|
+
readInput: readStageRows,
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
: cliWrappers,
|
|
91
130
|
identityPreflightCommands: identityCommands,
|
|
92
131
|
executionEnvironment: execution.environment,
|
|
93
132
|
readRowsFile: (file) => runtime.readRowsFile(file).map((row) => unwrapDatasetPayload(row, "")),
|
|
@@ -107,6 +146,7 @@ export function createFoundryFinalizeOwners(context, qualified, temporary, execu
|
|
|
107
146
|
writeCloseoutImportLedger: undefined,
|
|
108
147
|
readRowsFile: (file) => runtime.readRowsFile(file).map((row) => unwrapDatasetPayload(row, "")),
|
|
109
148
|
});
|
|
149
|
+
const readOnlyReports = new WeakMap();
|
|
110
150
|
const runTiangongJsonStage = (stage, argv) => {
|
|
111
151
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
112
152
|
const name = argv.slice(0, 2).join(" ");
|
|
@@ -119,20 +159,56 @@ export function createFoundryFinalizeOwners(context, qualified, temporary, execu
|
|
|
119
159
|
const remoteRead = name === "dataset verify-remote";
|
|
120
160
|
if (argv.some((arg) => /^--(?:commit|execute)(?:=|$)/u.test(arg)))
|
|
121
161
|
throw new FoundryContextError("finalize_write_forbidden", "Finalization cannot dispatch a remote mutation.");
|
|
122
|
-
|
|
123
|
-
|
|
162
|
+
const supportType = execution.datasetType;
|
|
163
|
+
if (qualified.cli.expectation.package_version === "0.4.0" &&
|
|
164
|
+
isFoundryEdgeDraftType(supportType) &&
|
|
165
|
+
(dryRun || remoteRead)) {
|
|
166
|
+
return planFoundryEdgeSupportStage(context, qualified, execution.environment, supportType, stage, argv, remoteRead, execution.receiptFile);
|
|
167
|
+
}
|
|
168
|
+
const qaType = argv[0] === "qa" ? argv[1] : null;
|
|
169
|
+
if (qualified.cli.expectation.package_version === "0.4.0" &&
|
|
170
|
+
(qaType === "flow" || qaType === "process" || qaType === "lifecyclemodel")) {
|
|
171
|
+
const rowsFile = argv[argv.indexOf("--rows-file") + 1];
|
|
172
|
+
const directory = argv[argv.indexOf("--out-dir") + 1];
|
|
173
|
+
const result = runFoundryTypedDatasetQa(context, qualified, temporary, (file, value) => writeFoundryArtifact(context, file, JSON.stringify(value, null, 2) + "\n"), qaType, rowsFile, directory, {
|
|
174
|
+
readRowsFile: (file) => readStageRows(file).toString("utf8"),
|
|
175
|
+
referenceFiles: argv.flatMap((value, index) => value === "--reference-rows-file" ? [argv[index + 1]] : []),
|
|
176
|
+
});
|
|
124
177
|
return {
|
|
125
178
|
stage,
|
|
126
|
-
exit_code: result.exit,
|
|
179
|
+
exit_code: result.exit || (qaType !== "process" && result.report.findings.length) ? 2 : 0,
|
|
127
180
|
report: result.report,
|
|
181
|
+
...(qaType === "process"
|
|
182
|
+
? { cli_validation: { report: result.validationReportFile, exit: result.exit } }
|
|
183
|
+
: {}),
|
|
128
184
|
status: result.report.status,
|
|
129
185
|
command: cli.command,
|
|
130
|
-
args: [...cli.args,
|
|
186
|
+
args: [...cli.args, "dataset", qaType === "lifecyclemodel" ? "model" : qaType, "validate"],
|
|
131
187
|
stderr: "",
|
|
132
188
|
};
|
|
133
189
|
}
|
|
190
|
+
if (!dryRun && !remoteRead) {
|
|
191
|
+
const result = runWorkflowLocalCliResult(context, qualified, temporary, argv);
|
|
192
|
+
return result.validate(() => {
|
|
193
|
+
const ownerStage = {
|
|
194
|
+
stage,
|
|
195
|
+
exit_code: result.exit,
|
|
196
|
+
report: result.report,
|
|
197
|
+
status: String(result.report.status),
|
|
198
|
+
command: cli.command,
|
|
199
|
+
args: [...cli.args, ...argv],
|
|
200
|
+
stderr: "",
|
|
201
|
+
};
|
|
202
|
+
const reportFile = runtime.reportFileFromCliStage(ownerStage, ["files.report"], null);
|
|
203
|
+
if (!reportFile)
|
|
204
|
+
throw new FoundryContextError("workflow_report_invalid", "The local finalization owner returned no existing report artifact.");
|
|
205
|
+
result.verifyReportFile(reportFile);
|
|
206
|
+
return ownerStage;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
134
209
|
if (!context.accountIntent)
|
|
135
210
|
throw new FoundryContextError("needs_auth", "Remote finalization checks require explicit task account intent.");
|
|
211
|
+
const childExecution = bindWorkflowChildExecution(context, qualified, cli.bin_path, argv, temporary, cli.command);
|
|
136
212
|
const result = spawnSync(cli.command, [...cli.args, ...argv], {
|
|
137
213
|
cwd: temporary,
|
|
138
214
|
env: execution.environment,
|
|
@@ -142,16 +218,31 @@ export function createFoundryFinalizeOwners(context, qualified, temporary, execu
|
|
|
142
218
|
timeout: 120_000,
|
|
143
219
|
maxBuffer: 16 * 1024 * 1024,
|
|
144
220
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
221
|
+
const kind = result.error
|
|
222
|
+
? "spawn_error"
|
|
223
|
+
: result.signal
|
|
224
|
+
? "signal"
|
|
225
|
+
: ![0, 1, 2].includes(result.status ?? -1)
|
|
226
|
+
? "exit_code"
|
|
227
|
+
: !result.stdout.trim()
|
|
228
|
+
? "empty_stdout"
|
|
229
|
+
: null;
|
|
230
|
+
if (kind)
|
|
231
|
+
throw workflowChildFailure(childExecution, result, kind);
|
|
232
|
+
let parsed;
|
|
148
233
|
try {
|
|
149
|
-
|
|
234
|
+
parsed = JSON.parse(result.stdout);
|
|
150
235
|
}
|
|
151
236
|
catch {
|
|
152
|
-
throw
|
|
237
|
+
throw workflowChildFailure(childExecution, result, "malformed_json");
|
|
153
238
|
}
|
|
154
|
-
|
|
239
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
240
|
+
throw workflowChildFailure(childExecution, result, "invalid_report");
|
|
241
|
+
const report = workflowObject(parsed);
|
|
242
|
+
// Domain blocked/readback findings remain with the existing read-only owner contract.
|
|
243
|
+
if ("error" in report || typeof report.status !== "string" || !report.status.trim())
|
|
244
|
+
throw workflowChildFailure(childExecution, result, "stage_rejected", new FoundryContextError("finalize_cli_failed", "The qualified read-only owner returned an error or no stage status."));
|
|
245
|
+
const ownerStage = {
|
|
155
246
|
stage,
|
|
156
247
|
exit_code: result.status ?? 1,
|
|
157
248
|
report,
|
|
@@ -160,6 +251,11 @@ export function createFoundryFinalizeOwners(context, qualified, temporary, execu
|
|
|
160
251
|
args: [...cli.args, ...argv],
|
|
161
252
|
stderr: result.stderr,
|
|
162
253
|
};
|
|
254
|
+
readOnlyReports.set(ownerStage, {
|
|
255
|
+
outputDirectory: argv[argv.indexOf("--out-dir") + 1],
|
|
256
|
+
failure: (rejection) => workflowChildFailure(childExecution, result, "stage_rejected", rejection),
|
|
257
|
+
});
|
|
258
|
+
return ownerStage;
|
|
163
259
|
};
|
|
164
260
|
const finalize = bind(createPostAuthoringFinalizeCommands, {
|
|
165
261
|
...base,
|
|
@@ -171,6 +267,7 @@ export function createFoundryFinalizeOwners(context, qualified, temporary, execu
|
|
|
171
267
|
...finalizeUtils,
|
|
172
268
|
...handoff,
|
|
173
269
|
profileFor,
|
|
270
|
+
readReferenceBytes: (file) => readFoundryInput(context, file),
|
|
174
271
|
runDatasetCurationCleanup,
|
|
175
272
|
runDatasetMutationManifest,
|
|
176
273
|
runDatasetCurationGate: (request) => runDatasetCurationGate({
|
|
@@ -183,6 +280,22 @@ export function createFoundryFinalizeOwners(context, qualified, temporary, execu
|
|
|
183
280
|
environment: localEnvironment,
|
|
184
281
|
}),
|
|
185
282
|
runTiangongJsonStage,
|
|
283
|
+
reportFileFromCliStage(stage, selectors, fallbackPath) {
|
|
284
|
+
const proof = readOnlyReports.get(stage);
|
|
285
|
+
if (!proof)
|
|
286
|
+
return runtime.reportFileFromCliStage(stage, selectors, fallbackPath);
|
|
287
|
+
try {
|
|
288
|
+
// Preserve the owner selectors and fallback rules. Some read-only commands return
|
|
289
|
+
// a summary rather than the same full report, so do not invent stdout/file equality.
|
|
290
|
+
const file = runtime.reportFileFromCliStage(stage, selectors, fallbackPath);
|
|
291
|
+
if (!file)
|
|
292
|
+
throw new FoundryContextError("finalize_report_invalid", "The read-only owner returned no existing selected or fallback report artifact.");
|
|
293
|
+
return assertWorkflowReportArtifact(context, file, proof.outputDirectory);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
throw proof.failure(error);
|
|
297
|
+
}
|
|
298
|
+
},
|
|
186
299
|
writeFinalizeImportLedger: undefined,
|
|
187
300
|
});
|
|
188
301
|
return {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
export declare const FOUNDRY_IDENTITY_STAGE_INPUT_SCHEMA: "tiangong-foundry.identity-stage-input.v1";
|
|
3
|
+
export interface FoundryIdentityStageTarget {
|
|
4
|
+
readonly dataset_type: "flow" | "process";
|
|
5
|
+
readonly dataset_id: string;
|
|
6
|
+
readonly dataset_version: string;
|
|
7
|
+
readonly source_row_sha256: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FoundryIdentityStageInput {
|
|
10
|
+
readonly schema: typeof FOUNDRY_IDENTITY_STAGE_INPUT_SCHEMA;
|
|
11
|
+
readonly intent_id: string;
|
|
12
|
+
readonly task_id: string;
|
|
13
|
+
readonly actor_id: string;
|
|
14
|
+
readonly rows_report_sha256: string;
|
|
15
|
+
readonly predecessor_identity_sha256: string;
|
|
16
|
+
readonly targets: readonly FoundryIdentityStageTarget[];
|
|
17
|
+
}
|
|
18
|
+
export interface SelectedFoundryIdentityStageInput {
|
|
19
|
+
readonly descriptor: FoundryInputFact;
|
|
20
|
+
readonly value: FoundryIdentityStageInput;
|
|
21
|
+
}
|
|
22
|
+
export declare function parseFoundryIdentityStageInput(value: unknown): FoundryIdentityStageInput;
|
|
23
|
+
export declare function selectFoundryIdentityStageInput(context: FoundryRuntimeContext, file: string): SelectedFoundryIdentityStageInput;
|
|
24
|
+
export declare function assertSelectedFoundryIdentityStageInput(context: FoundryRuntimeContext, selected: SelectedFoundryIdentityStageInput): void;
|