@tiangong-lca/foundry 0.1.18 → 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/docs/package-distribution-contract.md +5 -5
- package/docs/public-runtime-contract.md +12 -0
- package/docs/runtime-context-contract.md +2 -0
- package/package-dist/assets/foundry-package-descriptor.json +268 -98
- package/package-dist/scripts/foundry-facade.js +3 -0
- package/package-dist/scripts/foundry-runtime.d.ts +1 -1
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +3 -1
- 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 +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 +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 +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-managed-authentication.js +1 -1
- 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 +2 -2
- package/package-dist/scripts/lib/foundry-package-contract.js +2 -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-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 +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-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 +54 -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.js +53 -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.json +2 -2
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-package-descriptor.schema.json +2 -2
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
type RowIdentity = {
|
|
4
|
+
id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
payload: unknown;
|
|
7
|
+
};
|
|
8
|
+
type ValidationType = "flow" | "process" | "lifecyclemodel";
|
|
9
|
+
export declare function projectFlowValidation(row: RowIdentity, output: string, exit: number, receipt: unknown, bytes: Buffer): {
|
|
10
|
+
entity_id: string;
|
|
11
|
+
version: string;
|
|
12
|
+
severity: string;
|
|
13
|
+
code: string;
|
|
14
|
+
path: string;
|
|
15
|
+
message: string;
|
|
16
|
+
}[];
|
|
17
|
+
type ValidationOptions = {
|
|
18
|
+
referenceFiles?: readonly string[];
|
|
19
|
+
validationInput?: string;
|
|
20
|
+
readRowsFile?: (file: string) => string;
|
|
21
|
+
};
|
|
22
|
+
type ValidationIo = {
|
|
23
|
+
writeJson: (file: string, value: unknown) => void;
|
|
24
|
+
readRowsFile: (file: string) => string;
|
|
25
|
+
readResult: (file: string) => Buffer;
|
|
26
|
+
run: (argv: string[]) => {
|
|
27
|
+
exit: number;
|
|
28
|
+
report: Record<string, unknown>;
|
|
29
|
+
validate: <T>(check: () => T) => T;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export declare function runFoundryTypedDatasetQa(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, writeJson: ValidationIo["writeJson"], type: ValidationType, rowsFile: string, output: string, options?: ValidationOptions): {
|
|
33
|
+
reportFile: string;
|
|
34
|
+
report: {
|
|
35
|
+
schema: string;
|
|
36
|
+
status: string;
|
|
37
|
+
rows_file: string;
|
|
38
|
+
validation_input: string;
|
|
39
|
+
validation_operation: string;
|
|
40
|
+
validations: {
|
|
41
|
+
id: string;
|
|
42
|
+
version: string;
|
|
43
|
+
result: string;
|
|
44
|
+
reference_documents: string | null;
|
|
45
|
+
complete_sha256: string;
|
|
46
|
+
}[];
|
|
47
|
+
rows: {
|
|
48
|
+
findings: {
|
|
49
|
+
entity_id: string;
|
|
50
|
+
version: string;
|
|
51
|
+
severity: string;
|
|
52
|
+
code: string;
|
|
53
|
+
path: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}[];
|
|
56
|
+
}[];
|
|
57
|
+
findings: {
|
|
58
|
+
entity_id: string;
|
|
59
|
+
version: string;
|
|
60
|
+
severity: string;
|
|
61
|
+
code: string;
|
|
62
|
+
path: string;
|
|
63
|
+
message: string;
|
|
64
|
+
}[];
|
|
65
|
+
files: {
|
|
66
|
+
report: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exit: number;
|
|
70
|
+
validationReportFile: string;
|
|
71
|
+
} | {
|
|
72
|
+
reportFile: string;
|
|
73
|
+
report: {
|
|
74
|
+
status: string;
|
|
75
|
+
policy_decision_owner: string;
|
|
76
|
+
qa_mode: string;
|
|
77
|
+
mass_balance: import("./foundry-process-mass-balance.ts").ProcessMassBalance[];
|
|
78
|
+
findings: {
|
|
79
|
+
process_file: string;
|
|
80
|
+
severity: "info" | "warning" | "blocker";
|
|
81
|
+
code: string;
|
|
82
|
+
methodology_rule_id: string | null;
|
|
83
|
+
message: string;
|
|
84
|
+
source: "rule";
|
|
85
|
+
evidence?: {
|
|
86
|
+
[x: string]: unknown;
|
|
87
|
+
};
|
|
88
|
+
}[];
|
|
89
|
+
schema: string;
|
|
90
|
+
rows_file: string;
|
|
91
|
+
reference_evidence: import("./foundry-runtime-context-types.ts").FoundryInputFact[];
|
|
92
|
+
files: {
|
|
93
|
+
report: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
exit: number;
|
|
97
|
+
validationReportFile: string;
|
|
98
|
+
};
|
|
99
|
+
export declare function runTypedDatasetQa(type: ValidationType, rowsFile: string, directory: string, options: ValidationOptions, { writeJson, readRowsFile, readResult, run }: ValidationIo): {
|
|
100
|
+
reportFile: string;
|
|
101
|
+
report: {
|
|
102
|
+
schema: string;
|
|
103
|
+
status: string;
|
|
104
|
+
rows_file: string;
|
|
105
|
+
validation_input: string;
|
|
106
|
+
validation_operation: string;
|
|
107
|
+
validations: {
|
|
108
|
+
id: string;
|
|
109
|
+
version: string;
|
|
110
|
+
result: string;
|
|
111
|
+
reference_documents: string | null;
|
|
112
|
+
complete_sha256: string;
|
|
113
|
+
}[];
|
|
114
|
+
rows: {
|
|
115
|
+
findings: {
|
|
116
|
+
entity_id: string;
|
|
117
|
+
version: string;
|
|
118
|
+
severity: string;
|
|
119
|
+
code: string;
|
|
120
|
+
path: string;
|
|
121
|
+
message: string;
|
|
122
|
+
}[];
|
|
123
|
+
}[];
|
|
124
|
+
findings: {
|
|
125
|
+
entity_id: string;
|
|
126
|
+
version: string;
|
|
127
|
+
severity: string;
|
|
128
|
+
code: string;
|
|
129
|
+
path: string;
|
|
130
|
+
message: string;
|
|
131
|
+
}[];
|
|
132
|
+
files: {
|
|
133
|
+
report: string;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
exit: number;
|
|
137
|
+
validationReportFile: string;
|
|
138
|
+
} | {
|
|
139
|
+
reportFile: string;
|
|
140
|
+
report: {
|
|
141
|
+
status: string;
|
|
142
|
+
policy_decision_owner: string;
|
|
143
|
+
qa_mode: string;
|
|
144
|
+
mass_balance: import("./foundry-process-mass-balance.ts").ProcessMassBalance[];
|
|
145
|
+
findings: {
|
|
146
|
+
process_file: string;
|
|
147
|
+
severity: "info" | "warning" | "blocker";
|
|
148
|
+
code: string;
|
|
149
|
+
methodology_rule_id: string | null;
|
|
150
|
+
message: string;
|
|
151
|
+
source: "rule";
|
|
152
|
+
evidence?: {
|
|
153
|
+
[x: string]: unknown;
|
|
154
|
+
};
|
|
155
|
+
}[];
|
|
156
|
+
schema: string;
|
|
157
|
+
rows_file: string;
|
|
158
|
+
reference_evidence: import("./foundry-runtime-context-types.ts").FoundryInputFact[];
|
|
159
|
+
files: {
|
|
160
|
+
report: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
exit: number;
|
|
164
|
+
validationReportFile: string;
|
|
165
|
+
};
|
|
166
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { FoundryContextError, captureFoundryInput, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
4
|
+
import { canonicalPayloadSha256 } from "./post-write-root-proof.js";
|
|
5
|
+
import { datasetIdentity, detectDatasetType } from "./import-curation/internal/dataset-payload.js";
|
|
6
|
+
import { foundryProcessQa } from "./foundry-process-qa.js";
|
|
7
|
+
import { sha256Text } from "./identity-preflight-proof.js";
|
|
8
|
+
import { projectFoundryValidationReferences } from "./foundry-validation-reference-context.js";
|
|
9
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
10
|
+
import { assertWorkflowReportArtifact, runWorkflowLocalCliResult } from "./foundry-workflow-io.js";
|
|
11
|
+
function invalid() {
|
|
12
|
+
throw new FoundryContextError("workflow_qa_failed", "The complete typed dataset validation does not match the selected row and receipt.");
|
|
13
|
+
}
|
|
14
|
+
function object(value) {
|
|
15
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
16
|
+
return invalid();
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
const operationFor = (type) => `dataset ${type === "lifecyclemodel" ? "model" : type} validate`;
|
|
20
|
+
function projectValidation(type, row, output, exit, receipt, bytes) {
|
|
21
|
+
const report = object(receipt);
|
|
22
|
+
const artifact = Array.isArray(report.artifacts) ? object(report.artifacts[0]) : invalid();
|
|
23
|
+
if (report.schemaVersion !== 1 ||
|
|
24
|
+
report.operation !== operationFor(type) ||
|
|
25
|
+
report.status !== "completed" ||
|
|
26
|
+
report.error !== null ||
|
|
27
|
+
artifact.path !== output ||
|
|
28
|
+
artifact.purpose !== "complete_result" ||
|
|
29
|
+
artifact.bytes !== bytes.length)
|
|
30
|
+
return invalid();
|
|
31
|
+
const complete = object(JSON.parse(bytes.toString("utf8")));
|
|
32
|
+
const preview = object(object(report.data).validation);
|
|
33
|
+
const issues = complete.issues;
|
|
34
|
+
const previewIssues = preview.issues;
|
|
35
|
+
const receiptKeys = [
|
|
36
|
+
"id",
|
|
37
|
+
"type",
|
|
38
|
+
"version",
|
|
39
|
+
"status",
|
|
40
|
+
"validator",
|
|
41
|
+
"issue_count",
|
|
42
|
+
"payload_sha256",
|
|
43
|
+
];
|
|
44
|
+
const status = complete.status;
|
|
45
|
+
const admittedStatuses = type === "process" ? ["passed", "failed", "incomplete"] : ["passed", "failed"];
|
|
46
|
+
if (!admittedStatuses.includes(String(status)) ||
|
|
47
|
+
exit !== (status === "passed" ? 0 : 1) ||
|
|
48
|
+
report.outcome !== `validation_${status}` ||
|
|
49
|
+
complete.type !== type ||
|
|
50
|
+
complete.index !== 0 ||
|
|
51
|
+
complete.id !== row.id ||
|
|
52
|
+
complete.version !== row.version ||
|
|
53
|
+
complete.payload_sha256 !== canonicalPayloadSha256(row.payload) ||
|
|
54
|
+
JSON.stringify(complete.checks) !== '["schema","business"]' ||
|
|
55
|
+
!Array.isArray(issues) ||
|
|
56
|
+
!Array.isArray(previewIssues) ||
|
|
57
|
+
complete.issue_count !== issues.length ||
|
|
58
|
+
(status === "passed" && issues.length !== 0) ||
|
|
59
|
+
(status === "failed" && issues.length === 0) ||
|
|
60
|
+
receiptKeys.some((key) => complete[key] !== preview[key]) ||
|
|
61
|
+
canonicalPayloadSha256(previewIssues) !==
|
|
62
|
+
canonicalPayloadSha256(issues.slice(0, previewIssues.length)))
|
|
63
|
+
return invalid();
|
|
64
|
+
const ownerIssues = [...issues];
|
|
65
|
+
if (type === "process" && status === "incomplete") {
|
|
66
|
+
const names = object(complete.flow_reference_names);
|
|
67
|
+
if (names.status === "unresolved" && Array.isArray(names.issues))
|
|
68
|
+
ownerIssues.push(...names.issues);
|
|
69
|
+
}
|
|
70
|
+
const findings = ownerIssues.map((raw) => {
|
|
71
|
+
const { code, path: issuePath, message } = object(raw);
|
|
72
|
+
if (typeof code !== "string" ||
|
|
73
|
+
!code ||
|
|
74
|
+
typeof issuePath !== "string" ||
|
|
75
|
+
typeof message !== "string" ||
|
|
76
|
+
!message)
|
|
77
|
+
return invalid();
|
|
78
|
+
return {
|
|
79
|
+
entity_id: row.id,
|
|
80
|
+
version: row.version,
|
|
81
|
+
severity: "error",
|
|
82
|
+
code,
|
|
83
|
+
path: issuePath,
|
|
84
|
+
message,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
if (status === "incomplete" && findings.length === 0)
|
|
88
|
+
findings.push({
|
|
89
|
+
entity_id: row.id,
|
|
90
|
+
version: row.version,
|
|
91
|
+
severity: "error",
|
|
92
|
+
code: "process_business_validation_incomplete",
|
|
93
|
+
path: "$",
|
|
94
|
+
message: "Resolve exact Process reference evidence and repeat CLI business validation.",
|
|
95
|
+
});
|
|
96
|
+
return { complete, findings };
|
|
97
|
+
}
|
|
98
|
+
export function projectFlowValidation(row, output, exit, receipt, bytes) {
|
|
99
|
+
return projectValidation("flow", row, output, exit, receipt, bytes).findings;
|
|
100
|
+
}
|
|
101
|
+
export function runFoundryTypedDatasetQa(context, qualified, temporary, writeJson, type, rowsFile, output, options = {}) {
|
|
102
|
+
const directory = resolveFoundryOutput(context, output);
|
|
103
|
+
return runTypedDatasetQa(type, rowsFile, directory, options, {
|
|
104
|
+
writeJson,
|
|
105
|
+
readRowsFile: options.readRowsFile ?? ((file) => readFoundryInput(context, file).toString("utf8")),
|
|
106
|
+
readResult: (file) => fs.readFileSync(assertWorkflowReportArtifact(context, file, directory)),
|
|
107
|
+
run: (argv) => runWorkflowLocalCliResult(context, qualified, temporary, argv),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
export function runTypedDatasetQa(type, rowsFile, directory, options, { writeJson, readRowsFile, readResult, run }) {
|
|
111
|
+
const rows = readRows(rowsFile, readRowsFile);
|
|
112
|
+
fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
113
|
+
const referenceEvidence = [...new Set(options.referenceFiles ?? [])].map((file) => {
|
|
114
|
+
const fact = captureFoundryInput(file);
|
|
115
|
+
const contents = readRowsFile(file);
|
|
116
|
+
if (sha256Text(contents) !== fact.sha256)
|
|
117
|
+
return invalid();
|
|
118
|
+
return { fact, rows: readRows(file, () => contents) };
|
|
119
|
+
});
|
|
120
|
+
const references = referenceEvidence.flatMap(({ rows }) => rows);
|
|
121
|
+
const projected = type === "process" ? projectFoundryValidationReferences(rows, references) : rows;
|
|
122
|
+
const massReferences = { rows: new Map() };
|
|
123
|
+
const support = [];
|
|
124
|
+
for (const source of references) {
|
|
125
|
+
const kind = detectDatasetType(source);
|
|
126
|
+
if (kind !== "flow" && kind !== "unitgroup" && kind !== "flowproperty")
|
|
127
|
+
return invalid();
|
|
128
|
+
const supplied = datasetIdentity(source, 0, kind);
|
|
129
|
+
const { id, version, payload } = datasetIdentity(supplied.payload, 0, kind);
|
|
130
|
+
const key = `${kind}/${id}/${version}`;
|
|
131
|
+
if (!id || !version || id === "row-1" || id !== supplied.id || version !== supplied.version)
|
|
132
|
+
return invalid();
|
|
133
|
+
const sha256 = canonicalPayloadSha256(payload);
|
|
134
|
+
const prior = massReferences.rows.get(key);
|
|
135
|
+
if (prior && prior.sha256 !== sha256)
|
|
136
|
+
return invalid();
|
|
137
|
+
if (!prior) {
|
|
138
|
+
massReferences.rows.set(key, { payload: object(payload), sha256 });
|
|
139
|
+
if (kind !== "flow")
|
|
140
|
+
support.push(payload);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const operation = operationFor(type);
|
|
144
|
+
const validations = rows.map((source, index) => {
|
|
145
|
+
const row = datasetIdentity(source, index, type);
|
|
146
|
+
const input = path.join(directory, `${type}-${index + 1}.json`);
|
|
147
|
+
const resultFile = path.join(directory, `validation-${index + 1}.json`);
|
|
148
|
+
// 0.4 checks the typed root before its validation reader unwraps json and reads
|
|
149
|
+
// semantic_context. The complete result must still hash to the original payload.
|
|
150
|
+
const processInput = type === "process" ? object(projected[index]) : null;
|
|
151
|
+
writeJson(input, processInput
|
|
152
|
+
? {
|
|
153
|
+
...object(row.payload),
|
|
154
|
+
json: row.payload,
|
|
155
|
+
semantic_context: processInput.semantic_context,
|
|
156
|
+
...(processInput.allocation_transformation === undefined
|
|
157
|
+
? {}
|
|
158
|
+
: { allocation_transformation: processInput.allocation_transformation }),
|
|
159
|
+
}
|
|
160
|
+
: row.payload);
|
|
161
|
+
const argv = [
|
|
162
|
+
...operation.split(" "),
|
|
163
|
+
"--input",
|
|
164
|
+
input,
|
|
165
|
+
"--checks",
|
|
166
|
+
"schema,business",
|
|
167
|
+
"--output",
|
|
168
|
+
resultFile,
|
|
169
|
+
"--json",
|
|
170
|
+
];
|
|
171
|
+
let referenceDocuments;
|
|
172
|
+
if (type === "process") {
|
|
173
|
+
const flowDocs = object(processInput?.semantic_context).flow_documents;
|
|
174
|
+
if (!Array.isArray(flowDocs))
|
|
175
|
+
return invalid();
|
|
176
|
+
const documents = [
|
|
177
|
+
...new Map([...flowDocs, ...support].map((document) => [canonicalPayloadSha256(document), document])).values(),
|
|
178
|
+
];
|
|
179
|
+
if (documents.length) {
|
|
180
|
+
referenceDocuments = path.join(directory, `references-${index + 1}.json`);
|
|
181
|
+
writeJson(referenceDocuments, { documents });
|
|
182
|
+
argv.push("--reference-documents", referenceDocuments);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const validation = run(argv);
|
|
186
|
+
const result = validation.validate(() => projectValidation(type, row, resultFile, validation.exit, validation.report, readResult(resultFile)));
|
|
187
|
+
return {
|
|
188
|
+
id: row.id,
|
|
189
|
+
version: row.version,
|
|
190
|
+
result: resultFile,
|
|
191
|
+
reference_documents: referenceDocuments ?? null,
|
|
192
|
+
...result,
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
const reportFile = type === "process"
|
|
196
|
+
? path.join(directory, "outputs", "validation-report.json")
|
|
197
|
+
: path.join(directory, `${type}-qa-report.json`);
|
|
198
|
+
const report = {
|
|
199
|
+
schema: `tiangong-foundry.typed-${type}-qa.v1`,
|
|
200
|
+
status: `completed_typed_${type}_validation`,
|
|
201
|
+
rows_file: rowsFile,
|
|
202
|
+
validation_input: options.validationInput ?? rowsFile,
|
|
203
|
+
validation_operation: operation,
|
|
204
|
+
validations: validations.map(({ complete, findings: _findings, ...validation }) => ({
|
|
205
|
+
...validation,
|
|
206
|
+
complete_sha256: canonicalPayloadSha256(complete),
|
|
207
|
+
})),
|
|
208
|
+
rows: validations.map(({ complete, findings }) => ({ ...complete, findings })),
|
|
209
|
+
findings: validations.flatMap(({ findings }) => findings),
|
|
210
|
+
files: { report: reportFile },
|
|
211
|
+
};
|
|
212
|
+
writeJson(reportFile, report);
|
|
213
|
+
const exit = validations.some(({ complete }) => complete.status !== "passed") ? 1 : 0;
|
|
214
|
+
if (type !== "process")
|
|
215
|
+
return { reportFile, report, exit, validationReportFile: reportFile };
|
|
216
|
+
const qaFile = path.join(directory, "process-qa-report.json");
|
|
217
|
+
const qa = {
|
|
218
|
+
...foundryProcessQa(rows, massReferences),
|
|
219
|
+
schema: "tiangong-foundry.process-qa.v1",
|
|
220
|
+
rows_file: rowsFile,
|
|
221
|
+
reference_evidence: referenceEvidence.map(({ fact }) => fact),
|
|
222
|
+
files: { report: qaFile },
|
|
223
|
+
};
|
|
224
|
+
writeJson(qaFile, qa);
|
|
225
|
+
return { reportFile: qaFile, report: qa, exit, validationReportFile: reportFile };
|
|
226
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FoundryAuthentication } from "./foundry-authentication-environment.ts";
|
|
2
|
+
import type { createFoundryEdgeActor } from "./foundry-edge-session.ts";
|
|
3
|
+
import type { EdgeSupportRoot } from "./foundry-edge-support-plan.ts";
|
|
4
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
5
|
+
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
6
|
+
export declare function createFoundryTypedModelDraft(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication, receipt: Awaited<ReturnType<typeof createFoundryEdgeActor>>["receipt"], originalRequest: string, root: EdgeSupportRoot, content: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { createFoundryAuthenticationEnvironment, } from "./foundry-authentication-environment.js";
|
|
3
|
+
import { FoundryContextError } from "./foundry-runtime-context.js";
|
|
4
|
+
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
5
|
+
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
6
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
7
|
+
import { sha256Json, sha256Text } from "./identity-preflight-proof.js";
|
|
8
|
+
export function createFoundryTypedModelDraft(context, qualified, authentication, receipt, originalRequest, root, content) {
|
|
9
|
+
assertQualifiedFoundryRuntime(context, qualified);
|
|
10
|
+
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
11
|
+
const expectedActor = receipt.identity.user_id;
|
|
12
|
+
const expectedEnvironment = new URL(receipt.project.project_base_url).origin;
|
|
13
|
+
const request = {
|
|
14
|
+
id: root.id,
|
|
15
|
+
version: root.version,
|
|
16
|
+
content,
|
|
17
|
+
requestId: sha256Json({ originalRequest, id: root.id, version: root.version }),
|
|
18
|
+
expectedActor,
|
|
19
|
+
expectedEnvironment,
|
|
20
|
+
};
|
|
21
|
+
const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent?.sessionReference, process.env);
|
|
22
|
+
let child;
|
|
23
|
+
try {
|
|
24
|
+
child = spawnSync(process.execPath, [cli.binPath, "dataset", "model", "create", "--input", "-", "--json"], {
|
|
25
|
+
cwd: context.workspaceRoot,
|
|
26
|
+
env: environment,
|
|
27
|
+
input: JSON.stringify(request),
|
|
28
|
+
encoding: "utf8",
|
|
29
|
+
shell: false,
|
|
30
|
+
timeout: 60_000,
|
|
31
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
36
|
+
}
|
|
37
|
+
const unproven = () => new FoundryContextError("model_draft_result_unproven", "The original Model write requires independent exact readback.");
|
|
38
|
+
if (child.status !== 0 || child.signal || child.error || child.stderr)
|
|
39
|
+
throw unproven();
|
|
40
|
+
const envelope = workflowObject(JSON.parse(child.stdout));
|
|
41
|
+
const data = workflowObject(envelope.data);
|
|
42
|
+
const subject = workflowObject(data.subject);
|
|
43
|
+
const provenance = workflowObject(envelope.context);
|
|
44
|
+
if (envelope.schemaVersion !== 1 ||
|
|
45
|
+
envelope.operation !== "dataset model create" ||
|
|
46
|
+
envelope.status !== "completed" ||
|
|
47
|
+
envelope.outcome !== "dataset_written" ||
|
|
48
|
+
envelope.error !== null ||
|
|
49
|
+
subject.type !== "model" ||
|
|
50
|
+
subject.id !== root.id ||
|
|
51
|
+
subject.version !== root.version ||
|
|
52
|
+
data.contentDigest !== sha256Text(JSON.stringify(content)) ||
|
|
53
|
+
provenance.environment !== expectedEnvironment ||
|
|
54
|
+
workflowObject(provenance.actor).id !== expectedActor ||
|
|
55
|
+
provenance.requestId !== request.requestId ||
|
|
56
|
+
workflowObject(data.readback).contentMatchesIntent !== true)
|
|
57
|
+
throw unproven();
|
|
58
|
+
return envelope;
|
|
59
|
+
}
|
|
@@ -12,6 +12,8 @@ import { runDatasetCurationGate } from "./import-curation/curation-gate.js";
|
|
|
12
12
|
import { loadFoundryQualityReview } from "./foundry-quality-review.js";
|
|
13
13
|
import { runDatasetAuthoringTaskBuild } from "./import-curation/authoring-packages.js";
|
|
14
14
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
15
|
+
import { runFoundryTypedDatasetQa } from "./foundry-typed-flow-qa.js";
|
|
16
|
+
import { buildFoundryCurationQueue } from "./foundry-curation-queue.js";
|
|
15
17
|
import { projectFoundryValidationReferences, selectedFoundryExternalFlowReferences, } from "./foundry-validation-reference-context.js";
|
|
16
18
|
import { parseFoundryPreparationCliReport } from "./foundry-preparation-cli-validation.js";
|
|
17
19
|
import { routeFoundryDecisionAction } from "./foundry-decision-routing.js";
|
|
@@ -407,8 +409,23 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
407
409
|
args.push("--external-flow-ref", external.file);
|
|
408
410
|
}
|
|
409
411
|
const currentQueueDir = queueDir;
|
|
410
|
-
|
|
411
|
-
|
|
412
|
+
if (qualified.cli.expectation.package_version === "0.4.0") {
|
|
413
|
+
const report = buildFoundryCurationQueue({
|
|
414
|
+
processes: processes.file,
|
|
415
|
+
flows: selectedSets.find((set) => set.type === "flow")?.file,
|
|
416
|
+
support: selectedSets
|
|
417
|
+
.filter((set) => ["contact", "source", "unitgroup", "flowproperty"].includes(String(set.type)))
|
|
418
|
+
.map((set) => String(set.file)),
|
|
419
|
+
external: external ? [external.file] : [],
|
|
420
|
+
outDir: currentQueueDir,
|
|
421
|
+
readInput: (file) => file === external?.file ? fs.readFileSync(file) : readFoundryInput(context, file),
|
|
422
|
+
});
|
|
423
|
+
assertCurrentQueueBuild(context, currentQueueDir, { report, exit: report.status === "ready" ? 0 : 1 }, selectedSets, external);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
const queue = runWorkflowLocalCliResult(context, qualified, temporary, args);
|
|
427
|
+
queue.validate(() => assertCurrentQueueBuild(context, currentQueueDir, queue, selectedSets, external));
|
|
428
|
+
}
|
|
412
429
|
}
|
|
413
430
|
const assessed = previousSets.map(record);
|
|
414
431
|
const toAssess = options.scopeType
|
|
@@ -467,18 +484,55 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
467
484
|
registerWorkflowStageFiles(context, operation, output);
|
|
468
485
|
return result;
|
|
469
486
|
}
|
|
470
|
-
|
|
487
|
+
let cliValidation;
|
|
488
|
+
let validationProjection;
|
|
489
|
+
const typed = qualified.cli.expectation.package_version === "0.4.0";
|
|
490
|
+
const datasetType = set.type;
|
|
491
|
+
const qaDir = path.join(output, datasetType, "qa");
|
|
492
|
+
const processReferenceFiles = datasetType === "process"
|
|
493
|
+
? [
|
|
494
|
+
...selectedSets
|
|
495
|
+
.filter((ref) => ["flow", "flowproperty", "unitgroup"].includes(String(ref.type)))
|
|
496
|
+
.map((ref) => String(ref.file)),
|
|
497
|
+
...qaReferenceFiles,
|
|
498
|
+
]
|
|
499
|
+
: [];
|
|
500
|
+
const validationDir = typed ? qaDir : path.join(output, datasetType, "cli-validation");
|
|
501
|
+
let validationInput = set.file;
|
|
502
|
+
let validationRows = [];
|
|
503
|
+
if (datasetType === "process") {
|
|
504
|
+
validationRows = readRows(set.file, (name) => readFoundryInput(context, name).toString("utf8"));
|
|
505
|
+
if (qaReferenceFiles.length) {
|
|
506
|
+
validationRows = projectFoundryValidationReferences(validationRows, qaReferenceFiles.flatMap((file) => readRows(file, (name) => readFoundryInput(context, name).toString("utf8"))));
|
|
507
|
+
validationInput = path.join(validationDir, "validation-only.process.rows.json");
|
|
508
|
+
operation.writeJson(validationInput, validationRows);
|
|
509
|
+
validationProjection = {
|
|
510
|
+
cli_validation_input: captureFoundryInput(validationInput),
|
|
511
|
+
cli_validation_source_rows: captureFoundryInput(set.file),
|
|
512
|
+
cli_validation_reference_input_sha256: referenceInputSha256,
|
|
513
|
+
cli_validation_reference_files: reference.value.qa_files,
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}
|
|
471
517
|
let qaReport;
|
|
472
|
-
if (
|
|
518
|
+
if (typed &&
|
|
519
|
+
(datasetType === "flow" ||
|
|
520
|
+
datasetType === "process" ||
|
|
521
|
+
datasetType === "lifecyclemodel")) {
|
|
522
|
+
const result = runFoundryTypedDatasetQa(context, qualified, temporary, (file, value) => operation.writeJson(file, value), datasetType, set.file, qaDir, { referenceFiles: processReferenceFiles, validationInput });
|
|
523
|
+
qaReport = result.reportFile;
|
|
524
|
+
if (datasetType === "process")
|
|
525
|
+
cliValidation = {
|
|
526
|
+
report: result.validationReportFile,
|
|
527
|
+
exit: result.exit,
|
|
528
|
+
...(validationProjection ? { input: captureFoundryInput(validationInput) } : {}),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
else if (["flow", "process", "lifecyclemodel"].includes(set.type)) {
|
|
473
532
|
const qaArgv = ["qa", set.type, "--rows-file", set.file, "--out-dir", qaDir, "--json"];
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
readFoundryInput(context, String(referenceSet.file));
|
|
478
|
-
qaArgv.push("--reference-rows-file", String(referenceSet.file));
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
qaArgv.push(...qaReferenceFiles.flatMap((file) => ["--reference-rows-file", file]));
|
|
533
|
+
for (const file of processReferenceFiles) {
|
|
534
|
+
readFoundryInput(context, file);
|
|
535
|
+
qaArgv.push("--reference-rows-file", file);
|
|
482
536
|
}
|
|
483
537
|
const qa = runWorkflowLocalCliResult(context, qualified, temporary, qaArgv);
|
|
484
538
|
qaReport = qa.validate(() => {
|
|
@@ -500,23 +554,7 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
500
554
|
});
|
|
501
555
|
}
|
|
502
556
|
const gateDir = path.join(output, set.type, "curation");
|
|
503
|
-
|
|
504
|
-
let validationProjection;
|
|
505
|
-
if (set.type === "process") {
|
|
506
|
-
const validationDir = path.join(output, set.type, "cli-validation");
|
|
507
|
-
let validationInput = String(set.file);
|
|
508
|
-
let validationRows = readRows(validationInput);
|
|
509
|
-
if (qaReferenceFiles.length) {
|
|
510
|
-
validationRows = projectFoundryValidationReferences(validationRows, qaReferenceFiles.flatMap((file) => readRows(file, (name) => readFoundryInput(context, name).toString("utf8"))));
|
|
511
|
-
validationInput = path.join(validationDir, "validation-only.process.rows.json");
|
|
512
|
-
operation.writeJson(validationInput, validationRows);
|
|
513
|
-
validationProjection = {
|
|
514
|
-
cli_validation_input: captureFoundryInput(validationInput),
|
|
515
|
-
cli_validation_source_rows: captureFoundryInput(String(set.file)),
|
|
516
|
-
cli_validation_reference_input_sha256: referenceInputSha256,
|
|
517
|
-
cli_validation_reference_files: reference.value.qa_files,
|
|
518
|
-
};
|
|
519
|
-
}
|
|
557
|
+
if (set.type === "process" && !typed) {
|
|
520
558
|
const validation = runWorkflowLocalCliResult(context, qualified, temporary, [
|
|
521
559
|
"dataset",
|
|
522
560
|
"validate",
|