@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
|
@@ -11,19 +11,29 @@ import { runFoundryTaskOperation, withFoundryTaskMetadata } from "./foundry-task
|
|
|
11
11
|
import { registerWorkflowStageFiles } from "./foundry-workflow-io.js";
|
|
12
12
|
import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
13
13
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
14
|
+
import { recoverFoundryWorkflowIdentity } from "./foundry-workflow-identity-recovery.js";
|
|
15
|
+
import { assertNoPendingFoundryIdentityStage } from "./foundry-identity-stage-state.js";
|
|
16
|
+
import { runFoundryEdgeIdentityPreflight } from "./foundry-edge-identity-preflight.js";
|
|
14
17
|
/** Run the existing read-only owner first; the local transaction only records its captured evidence. */
|
|
15
18
|
export async function runFoundryWorkflowIdentity(context, qualified, entries, authentication = { mode: "oauth" }) {
|
|
16
19
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
20
|
+
assertNoPendingFoundryIdentityStage(context, entries);
|
|
17
21
|
const state = currentWorkflowState(context, entries), rows = state.rows;
|
|
18
|
-
if (!rows || !state.assessment)
|
|
22
|
+
if (!rows || (!state.assessment && !state.retainedAssessment))
|
|
19
23
|
throw new FoundryContextError("workflow_rows_required", "Assess the current rows before identity preflight.");
|
|
20
24
|
if (!context.accountIntent)
|
|
21
25
|
throw new FoundryContextError("needs_auth", "Identity preflight requires a task spec with the intended project and user account.");
|
|
22
26
|
await withFoundryTaskMetadata(context, (_, index) => {
|
|
27
|
+
assertNoPendingFoundryIdentityStage(context, index);
|
|
23
28
|
if (currentWorkflowState(context, index).rows?.entry.sha256 !== rows.entry.sha256)
|
|
24
29
|
throw new FoundryContextError("workflow_identity_rows_changed", "Current rows changed before identity preflight.");
|
|
25
30
|
});
|
|
26
31
|
const identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
32
|
+
const recovered = await recoverFoundryWorkflowIdentity(context, qualified, entries, identity.receipt);
|
|
33
|
+
if (recovered)
|
|
34
|
+
return recovered;
|
|
35
|
+
if (!state.assessment)
|
|
36
|
+
throw new FoundryContextError("workflow_rows_required", "Current runtime assessment is required before a new identity query.");
|
|
27
37
|
const nonce = randomUUID();
|
|
28
38
|
const output = resolveFoundryOutput(context, `outputs/identity/${nonce}`);
|
|
29
39
|
const temporary = resolveFoundryOutput(context, `tmp/identity-${nonce}`);
|
|
@@ -81,21 +91,26 @@ export async function runFoundryWorkflowIdentity(context, qualified, entries, au
|
|
|
81
91
|
});
|
|
82
92
|
continue;
|
|
83
93
|
}
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
const runDir = path.join(outDir, "run");
|
|
95
|
+
const edgeResult = qualified.cli.expectation.package_version === "0.4.0"
|
|
96
|
+
? await runFoundryEdgeIdentityPreflight(context, qualified, authentication, set.type, index, runDir)
|
|
97
|
+
: null;
|
|
98
|
+
const result = edgeResult ??
|
|
99
|
+
workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightRun({
|
|
100
|
+
index,
|
|
101
|
+
outDir: runDir,
|
|
102
|
+
authReceipt: receipt,
|
|
103
|
+
expectedProjectRef: context.accountIntent.projectRef,
|
|
104
|
+
expectedUserId: context.accountIntent.userId,
|
|
105
|
+
maxAttempts: 1,
|
|
106
|
+
timeoutMs: 60_000,
|
|
107
|
+
})));
|
|
93
108
|
if (!["completed", "completed_with_identity_findings"].includes(String(result.status)))
|
|
94
109
|
blockers.push({ code: "identity_preflight_failed", type: set.type, report: result });
|
|
95
110
|
sets.push({
|
|
96
111
|
type: set.type,
|
|
97
112
|
rows: set.file,
|
|
98
|
-
index,
|
|
113
|
+
index: edgeResult?.index ?? index,
|
|
99
114
|
status: result.status,
|
|
100
115
|
report: workflowObject(result.files).report,
|
|
101
116
|
});
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
2
|
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { WorkflowChildFailure } from "./foundry-workflow-child-failure.ts";
|
|
3
4
|
import type { FoundryTaskOperation } from "./foundry-task-types.ts";
|
|
4
5
|
export declare function createWorkflowDirectory(context: FoundryRuntimeContext, prefix: string): string;
|
|
5
6
|
export declare function createWorkflowStageDirectory(context: FoundryRuntimeContext, operation: FoundryTaskOperation, stage: string): string;
|
|
6
|
-
export declare function registerWorkflowStageFiles(context: FoundryRuntimeContext, operation: FoundryTaskOperation, directory: string): string[];
|
|
7
|
+
export declare function registerWorkflowStageFiles(context: FoundryRuntimeContext, operation: FoundryTaskOperation, directory: string | readonly string[]): string[];
|
|
8
|
+
/** Existing owner-selected report paths must belong to this actual call's output generation. */
|
|
9
|
+
export declare function assertWorkflowReportArtifact(context: FoundryRuntimeContext, file: string, selectedDir: string): string;
|
|
7
10
|
export declare function runWorkflowLocalCli(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, argv: readonly string[]): Record<string, unknown>;
|
|
8
11
|
export declare function runWorkflowLocalCliResult(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, argv: readonly string[]): {
|
|
9
12
|
exit: number;
|
|
10
13
|
report: Record<string, unknown>;
|
|
14
|
+
failure: (rejection?: unknown) => WorkflowChildFailure;
|
|
15
|
+
validate: <T>(check: () => T) => T;
|
|
16
|
+
verifyReportFile: (file: string) => void;
|
|
11
17
|
};
|
|
@@ -5,7 +5,8 @@ import { randomUUID } from "node:crypto";
|
|
|
5
5
|
import { FoundryContextError, assertFoundryWorkspaceWrite, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
6
6
|
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
7
7
|
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
8
|
-
import {
|
|
8
|
+
import { withFoundryIsolatedLocalCliEnvironment } from "./foundry-runtime-environment.js";
|
|
9
|
+
import { bindWorkflowChildExecution, workflowChildFailure, WorkflowChildFailure, } from "./foundry-workflow-child-failure.js";
|
|
9
10
|
export function createWorkflowDirectory(context, prefix) {
|
|
10
11
|
assertFoundryWorkspaceWrite(context);
|
|
11
12
|
const directory = resolveFoundryOutput(context, `${prefix}${randomUUID()}`);
|
|
@@ -31,22 +32,50 @@ export function registerWorkflowStageFiles(context, operation, directory) {
|
|
|
31
32
|
else {
|
|
32
33
|
if (files.length >= 9_998)
|
|
33
34
|
throw new FoundryContextError("workflow_output_limit", "Stage exceeds the task artifact limit.");
|
|
34
|
-
operation.writeText(file, fs.readFileSync(file));
|
|
35
35
|
files.push(file);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
|
|
39
|
+
// Snapshot only the selected roots; one result retains one complete capture roster.
|
|
40
|
+
for (const root of typeof directory === "string" ? [directory] : [...directory])
|
|
41
|
+
visit(root);
|
|
42
|
+
operation.registerExistingFiles(files);
|
|
40
43
|
return files;
|
|
41
44
|
}
|
|
45
|
+
/** Existing owner-selected report paths must belong to this actual call's output generation. */
|
|
46
|
+
export function assertWorkflowReportArtifact(context, file, selectedDir) {
|
|
47
|
+
const output = resolveFoundryOutput(context, selectedDir);
|
|
48
|
+
const current = resolveFoundryOutput(context, file);
|
|
49
|
+
const relative = path.relative(output, current);
|
|
50
|
+
if (!relative ||
|
|
51
|
+
relative.startsWith(`..${path.sep}`) ||
|
|
52
|
+
relative === ".." ||
|
|
53
|
+
path.isAbsolute(relative))
|
|
54
|
+
throw new FoundryContextError("workflow_report_invalid", "The child report locator is outside this call's output directory.");
|
|
55
|
+
const stat = fs.lstatSync(current);
|
|
56
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 8 * 1024 * 1024)
|
|
57
|
+
throw new FoundryContextError("workflow_report_invalid", "The child report must be a bounded regular output artifact.");
|
|
58
|
+
return current;
|
|
59
|
+
}
|
|
42
60
|
export function runWorkflowLocalCli(context, qualified, temporary, argv) {
|
|
43
61
|
const result = runWorkflowLocalCliResult(context, qualified, temporary, argv);
|
|
44
62
|
if (![0, 2].includes(result.exit) || "error" in result.report)
|
|
45
|
-
throw
|
|
63
|
+
throw result.failure();
|
|
46
64
|
return result.report;
|
|
47
65
|
}
|
|
48
66
|
export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
49
|
-
const
|
|
67
|
+
const typedDatasetValidation = qualified.cli.expectation.package_version === "0.4.0" &&
|
|
68
|
+
argv[0] === "dataset" &&
|
|
69
|
+
["flow", "process", "model"].includes(argv[1]) &&
|
|
70
|
+
argv[argv.indexOf("--checks") + 1] === "schema,business" &&
|
|
71
|
+
argv[2] === "validate";
|
|
72
|
+
const typedPatch = qualified.cli.expectation.package_version === "0.4.0" &&
|
|
73
|
+
argv[0] === "dataset" &&
|
|
74
|
+
["flow", "process", "model", "contact", "source", "unitgroup", "flowproperty"].includes(argv[1]) &&
|
|
75
|
+
argv[2] === "patch";
|
|
76
|
+
const local = typedDatasetValidation ||
|
|
77
|
+
typedPatch ||
|
|
78
|
+
(argv[0] === "dataset" && argv[1] === "validate") ||
|
|
50
79
|
(argv[0] === "qa" && ["flow", "process", "lifecyclemodel"].includes(argv[1])) ||
|
|
51
80
|
(argv[0] === "dataset" && argv[1] === "curation-queue" && argv[2] === "build") ||
|
|
52
81
|
(argv[0] === "dataset" &&
|
|
@@ -57,22 +86,79 @@ export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
|
57
86
|
throw new FoundryContextError("workflow_command_invalid", "This stage admits local validation, QA, queue preparation and patch application only.");
|
|
58
87
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
59
88
|
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
60
|
-
const
|
|
89
|
+
const execution = bindWorkflowChildExecution(context, qualified, cli.binPath, argv);
|
|
90
|
+
const child = withFoundryIsolatedLocalCliEnvironment(temporary, (env) => spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
61
91
|
cwd: context.workspaceRoot,
|
|
62
|
-
env
|
|
92
|
+
env,
|
|
63
93
|
encoding: "utf8",
|
|
64
94
|
shell: false,
|
|
65
95
|
timeout: 120_000,
|
|
66
96
|
maxBuffer: 8 * 1024 * 1024,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
97
|
+
}));
|
|
98
|
+
const kind = child.error
|
|
99
|
+
? "spawn_error"
|
|
100
|
+
: child.signal
|
|
101
|
+
? "signal"
|
|
102
|
+
: ![0, 1, 2].includes(child.status ?? -1)
|
|
103
|
+
? "exit_code"
|
|
104
|
+
: !child.stdout.trim()
|
|
105
|
+
? "empty_stdout"
|
|
106
|
+
: null;
|
|
107
|
+
if (kind)
|
|
108
|
+
throw workflowChildFailure(execution, child, kind);
|
|
109
|
+
let report;
|
|
110
|
+
try {
|
|
111
|
+
report = JSON.parse(child.stdout);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
throw workflowChildFailure(execution, child, "malformed_json");
|
|
115
|
+
}
|
|
74
116
|
if (!report || typeof report !== "object" || Array.isArray(report))
|
|
75
|
-
throw
|
|
117
|
+
throw workflowChildFailure(execution, child, "invalid_report");
|
|
118
|
+
const envelope = report;
|
|
119
|
+
const patchError = typedPatch &&
|
|
120
|
+
envelope.status === "failed" &&
|
|
121
|
+
envelope.outcome === "invalid_input" &&
|
|
122
|
+
typeof envelope.error === "object" &&
|
|
123
|
+
envelope.error !== null &&
|
|
124
|
+
Object.hasOwn(envelope.error, "code") &&
|
|
125
|
+
Object.hasOwn(envelope.error, "message");
|
|
126
|
+
if (("error" in report &&
|
|
127
|
+
!((typedDatasetValidation || typedPatch) && report.error === null) &&
|
|
128
|
+
!patchError) ||
|
|
129
|
+
!("status" in report) ||
|
|
130
|
+
typeof report.status !== "string" ||
|
|
131
|
+
!report.status.trim())
|
|
132
|
+
throw workflowChildFailure(execution, child, "stage_rejected", new FoundryContextError("workflow_report_invalid", "Local CLI returned an error or no stage status."));
|
|
76
133
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
77
|
-
|
|
134
|
+
const failure = (rejection) => workflowChildFailure(execution, child, "stage_rejected", rejection);
|
|
135
|
+
return {
|
|
136
|
+
exit: child.status,
|
|
137
|
+
report,
|
|
138
|
+
failure,
|
|
139
|
+
verifyReportFile(file) {
|
|
140
|
+
try {
|
|
141
|
+
const selectedDir = argv[argv.indexOf("--out-dir") + 1];
|
|
142
|
+
if (!argv.includes("--out-dir") || typeof selectedDir !== "string")
|
|
143
|
+
throw new FoundryContextError("workflow_report_invalid", "The child report has no bound output directory.");
|
|
144
|
+
const current = assertWorkflowReportArtifact(context, file, selectedDir);
|
|
145
|
+
const recorded = JSON.parse(fs.readFileSync(current, "utf8"));
|
|
146
|
+
if (JSON.stringify(recorded) !== JSON.stringify(report))
|
|
147
|
+
throw new FoundryContextError("workflow_report_invalid", "The child report file differs from its original returned report.");
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw failure(error);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
validate(check) {
|
|
154
|
+
try {
|
|
155
|
+
return check();
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error instanceof WorkflowChildFailure)
|
|
159
|
+
throw error;
|
|
160
|
+
throw failure(error);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
};
|
|
78
164
|
}
|
|
@@ -15,6 +15,7 @@ import { sha256Json } from "./identity-preflight-proof.js";
|
|
|
15
15
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
16
16
|
import { datasetIdentity, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
|
|
17
17
|
import { bundleRowTypes } from "./bundle-row-types.js";
|
|
18
|
+
import { createFoundryEdgeActor } from "./foundry-edge-session.js";
|
|
18
19
|
function invalid(message) {
|
|
19
20
|
throw new FoundryContextError("reference_evidence_invalid", message);
|
|
20
21
|
}
|
|
@@ -133,7 +134,10 @@ export async function verifyFoundryReferences(context, qualified, entries, authe
|
|
|
133
134
|
const scope = current.scope;
|
|
134
135
|
if (!scope)
|
|
135
136
|
invalid("No current canonical reference partition exists.");
|
|
136
|
-
|
|
137
|
+
const typed = qualified.cli.expectation.package_version === "0.4.0";
|
|
138
|
+
const actor = typed ? await createFoundryEdgeActor(context, qualified, authentication) : null;
|
|
139
|
+
if (!actor)
|
|
140
|
+
verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
137
141
|
for (const fact of scope.sources)
|
|
138
142
|
readFoundryInput(context, fact.path);
|
|
139
143
|
const output = resolveFoundryOutput(context, `outputs/reference-verification/${randomUUID()}`);
|
|
@@ -142,7 +146,102 @@ export async function verifyFoundryReferences(context, qualified, entries, authe
|
|
|
142
146
|
fs.writeFileSync(input, scope.targets
|
|
143
147
|
.map((item) => JSON.stringify({ "@type": item.table, "@refObjectId": item.id, "@version": item.version }))
|
|
144
148
|
.join("\n") + "\n", { mode: 0o600 });
|
|
145
|
-
const inputFact = captureFoundryInput(input)
|
|
149
|
+
const inputFact = captureFoundryInput(input);
|
|
150
|
+
const publish = (command, blockers, reportFact, checksFact) => {
|
|
151
|
+
if (captureFoundryInput(input).sha256 !== inputFact.sha256)
|
|
152
|
+
invalid("Reference query changed during verification.");
|
|
153
|
+
for (const fact of scope.sources)
|
|
154
|
+
readFoundryInput(context, fact.path);
|
|
155
|
+
return runFoundryTaskOperation(context, {
|
|
156
|
+
command: "dataset-workflow-reference-verify",
|
|
157
|
+
options: { scope: scope.sha256, nonce: path.basename(output) },
|
|
158
|
+
validateCurrent(index) {
|
|
159
|
+
if (foundryReferenceScope(context, index)?.sha256 !== scope.sha256)
|
|
160
|
+
invalid("Reference scope changed during verification.");
|
|
161
|
+
},
|
|
162
|
+
}, (operation) => {
|
|
163
|
+
registerWorkflowStageFiles(context, operation, output);
|
|
164
|
+
const result = {
|
|
165
|
+
schema: "tiangong-foundry.reference-verification.v1",
|
|
166
|
+
status: blockers.length ? "unresolved" : "verified",
|
|
167
|
+
scope_sha256: scope.sha256,
|
|
168
|
+
targets: scope.targets,
|
|
169
|
+
input: inputFact,
|
|
170
|
+
report: reportFact,
|
|
171
|
+
checks: checksFact,
|
|
172
|
+
command,
|
|
173
|
+
blockers,
|
|
174
|
+
};
|
|
175
|
+
operation.writeJson(path.join(output, "foundry-reference-verification.json"), result);
|
|
176
|
+
return result;
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
if (actor) {
|
|
180
|
+
const endpoint = "app_dataset_verify_remote";
|
|
181
|
+
const requests = [];
|
|
182
|
+
const checks = [];
|
|
183
|
+
const blockers = [];
|
|
184
|
+
for (let offset = 0; offset < scope.targets.length; offset += 200) {
|
|
185
|
+
const targets = scope.targets.slice(offset, offset + 200);
|
|
186
|
+
const request = {
|
|
187
|
+
rootPolicy: "existing",
|
|
188
|
+
references: targets.map((target) => ({
|
|
189
|
+
...target,
|
|
190
|
+
role: "reference",
|
|
191
|
+
requirePayload: true,
|
|
192
|
+
})),
|
|
193
|
+
};
|
|
194
|
+
try {
|
|
195
|
+
const response = workflowObject(await actor.post(endpoint, request));
|
|
196
|
+
requests.push({ request, response });
|
|
197
|
+
const report = workflowObject(response.data);
|
|
198
|
+
const counts = workflowObject(report.counts);
|
|
199
|
+
const rows = Array.isArray(report.checks) ? report.checks.map(workflowObject) : [];
|
|
200
|
+
if (response.command !== "dataset_verify_remote" ||
|
|
201
|
+
response.ok !== true ||
|
|
202
|
+
report.status !== "passed_remote_verification" ||
|
|
203
|
+
report.root_policy !== request.rootPolicy ||
|
|
204
|
+
!Array.isArray(report.blockers) ||
|
|
205
|
+
report.blockers.length ||
|
|
206
|
+
counts.blockers !== 0 ||
|
|
207
|
+
counts.references !== targets.length ||
|
|
208
|
+
rows.length !== targets.length)
|
|
209
|
+
blockers.push({ code: "reference_verification_incomplete", offset });
|
|
210
|
+
targets.forEach((target, index) => {
|
|
211
|
+
const check = rows[index];
|
|
212
|
+
if (!check ||
|
|
213
|
+
check.index !== index ||
|
|
214
|
+
check.role !== "reference" ||
|
|
215
|
+
check.id !== target.id ||
|
|
216
|
+
check.table !== target.table ||
|
|
217
|
+
check.version !== target.version ||
|
|
218
|
+
check.status !== "ok" ||
|
|
219
|
+
check.exact_version !== target.version ||
|
|
220
|
+
check.latest_version !== target.version ||
|
|
221
|
+
check.payload_present !== true)
|
|
222
|
+
blockers.push({ code: "canonical_reference_not_verified", target });
|
|
223
|
+
});
|
|
224
|
+
checks.push(...rows);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
blockers.push({
|
|
228
|
+
code: error instanceof FoundryContextError ? error.code : "reference_edge_failed",
|
|
229
|
+
offset,
|
|
230
|
+
});
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const report = path.join(output, "edge-reference-verification.json");
|
|
235
|
+
const checksFile = path.join(output, "checks.jsonl");
|
|
236
|
+
fs.writeFileSync(report, JSON.stringify({ identity: actor.receipt, requests }) + "\n", {
|
|
237
|
+
mode: 0o600,
|
|
238
|
+
});
|
|
239
|
+
fs.writeFileSync(checksFile, checks.map((check) => JSON.stringify(check) + "\n").join(""), {
|
|
240
|
+
mode: 0o600,
|
|
241
|
+
});
|
|
242
|
+
return publish({ transport: "edge", endpoint }, blockers, captureFoundryInput(report), captureFoundryInput(checksFile));
|
|
243
|
+
}
|
|
244
|
+
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
146
245
|
const command = createFoundryCommandSpec({
|
|
147
246
|
executable: process.execPath,
|
|
148
247
|
argv: [
|
|
@@ -232,33 +331,7 @@ export async function verifyFoundryReferences(context, qualified, entries, authe
|
|
|
232
331
|
}
|
|
233
332
|
if (run.error || run.signal || run.status !== 0)
|
|
234
333
|
blockers.push({ code: "reference_cli_failed", exit_code: run.status });
|
|
235
|
-
|
|
236
|
-
invalid("Reference query changed during verification.");
|
|
237
|
-
for (const fact of scope.sources)
|
|
238
|
-
readFoundryInput(context, fact.path);
|
|
239
|
-
return runFoundryTaskOperation(context, {
|
|
240
|
-
command: "dataset-workflow-reference-verify",
|
|
241
|
-
options: { scope: scope.sha256, nonce: path.basename(output) },
|
|
242
|
-
validateCurrent(index) {
|
|
243
|
-
if (foundryReferenceScope(context, index)?.sha256 !== scope.sha256)
|
|
244
|
-
invalid("Reference scope changed during verification.");
|
|
245
|
-
},
|
|
246
|
-
}, (operation) => {
|
|
247
|
-
registerWorkflowStageFiles(context, operation, output);
|
|
248
|
-
const result = {
|
|
249
|
-
schema: "tiangong-foundry.reference-verification.v1",
|
|
250
|
-
status: blockers.length ? "unresolved" : "verified",
|
|
251
|
-
scope_sha256: scope.sha256,
|
|
252
|
-
targets: scope.targets,
|
|
253
|
-
input: inputFact,
|
|
254
|
-
report: reportFact,
|
|
255
|
-
checks: checksFact,
|
|
256
|
-
command,
|
|
257
|
-
blockers,
|
|
258
|
-
};
|
|
259
|
-
operation.writeJson(path.join(output, "foundry-reference-verification.json"), result);
|
|
260
|
-
return result;
|
|
261
|
-
});
|
|
334
|
+
return publish(command, blockers, reportFact, checksFact);
|
|
262
335
|
}
|
|
263
336
|
finally {
|
|
264
337
|
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { prepareEdgeProcessRepair, readEdgeRepairValidation, } from "./foundry-edge-repair-preparation.js";
|
|
1
2
|
import { proveFoundryRepairRemoteIntegrity } from "./foundry-repair-reference-binding.js";
|
|
2
3
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
3
4
|
import childProcess from "node:child_process";
|
|
@@ -11,7 +12,7 @@ import { createFoundryAuthenticationEnvironment, } from "./foundry-authenticatio
|
|
|
11
12
|
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
12
13
|
import { runFoundryTaskOperation, withFoundryTaskMetadata } from "./foundry-task-store.js";
|
|
13
14
|
import { createWorkflowDirectory, createWorkflowStageDirectory } from "./foundry-workflow-io.js";
|
|
14
|
-
import { readWorkflowArtifact } from "./foundry-workflow-state.js";
|
|
15
|
+
import { readWorkflowArtifact, workflowObject } from "./foundry-workflow-state.js";
|
|
15
16
|
import { readFoundryRepairScope } from "./foundry-repair-scope.js";
|
|
16
17
|
import { FOUNDRY_REPAIR_PREPARATION_SCHEMA, parseFoundryRepairDryRunReport, parseFoundryRepairValidateReport, } from "./foundry-repair-preflight.js";
|
|
17
18
|
import { readTaskJson, relative as taskRelative } from "./foundry-task-io.js";
|
|
@@ -270,6 +271,43 @@ export function readFoundryRepairPreparation(context, entries) {
|
|
|
270
271
|
content: role,
|
|
271
272
|
});
|
|
272
273
|
};
|
|
274
|
+
if (value.status !== "blocked" && verified.has("edge-repair:out/owner-report.json")) {
|
|
275
|
+
const report = ownerReport("edge-repair", currentScope.candidateFile);
|
|
276
|
+
const artifact = (role) => {
|
|
277
|
+
const entry = verified.get(`edge-repair:out/${role}`);
|
|
278
|
+
if (!entry)
|
|
279
|
+
fail("repair_report_invalid", "Guarded Edge repair requires complete indexed evidence.");
|
|
280
|
+
return JSON.parse(fs.readFileSync(resolveFoundryOutput(context, entry.path), "utf8"));
|
|
281
|
+
};
|
|
282
|
+
const typed = artifact("validation/outputs/validation-report.json");
|
|
283
|
+
const reference = artifact("references/edge-support-precommit.json");
|
|
284
|
+
const before = artifact("edge-before.json");
|
|
285
|
+
const rules = readEdgeRepairValidation(typed, expected);
|
|
286
|
+
const beforeValidation = Object.values(rules).includes(false)
|
|
287
|
+
? artifact("before-validation/outputs/validation-report.json")
|
|
288
|
+
: null;
|
|
289
|
+
const detail = Array.isArray(evidence.detail)
|
|
290
|
+
? evidence.detail.map(workflowObject).find((item) => item.role === "edge_preflight")
|
|
291
|
+
: null;
|
|
292
|
+
const referenceEntry = verified.get("edge-repair:out/references/edge-support-precommit.json");
|
|
293
|
+
const referenceFact = record(report.reference_evidence, "repair_report_invalid", "Dependency report fact");
|
|
294
|
+
if (report.schema !== "tiangong-foundry.edge-repair-preflight.v1" ||
|
|
295
|
+
report.contract_sha256 !== expected.contract_sha256 ||
|
|
296
|
+
!sameFact(report.before, inputs.before, "repair_report_invalid", "Edge before rows") ||
|
|
297
|
+
report.validation_sha256 !== sha256Json(typed) ||
|
|
298
|
+
report.before_validation_sha256 !==
|
|
299
|
+
(beforeValidation ? sha256Json(beforeValidation) : null) ||
|
|
300
|
+
sha256Json(report.rule_verification) !== sha256Json(rules) ||
|
|
301
|
+
!detail ||
|
|
302
|
+
sha256Json(detail.report) !== sha256Json(report) ||
|
|
303
|
+
report.remote_before_sha256 !== sha256Json(before) ||
|
|
304
|
+
referenceFact.sha256 !== referenceEntry.sha256 ||
|
|
305
|
+
referenceFact.bytes !== referenceEntry.bytes ||
|
|
306
|
+
reference.status !== "passed_remote_verification" ||
|
|
307
|
+
(value.status === "prepared") !== (currentScope.scope.status === "dispatchable"))
|
|
308
|
+
fail("repair_report_invalid", "Guarded Edge repair proof differs from the registered scope.");
|
|
309
|
+
return Object.freeze({ entry, file: resolveFoundryOutput(context, entry.path), value });
|
|
310
|
+
}
|
|
273
311
|
if (value.status === "prepared") {
|
|
274
312
|
if (currentScope.scope.status !== "dispatchable")
|
|
275
313
|
fail("repair_report_invalid", "A no-op is not a write preparation.");
|
|
@@ -317,7 +355,20 @@ export async function prepareFoundryRepair(context, qualified, _entries, authent
|
|
|
317
355
|
verifyCommands: [FOUNDRY_REPAIR_PREFLIGHT_COMMAND],
|
|
318
356
|
});
|
|
319
357
|
try {
|
|
320
|
-
if (
|
|
358
|
+
if (qualified.cli.expectation.package_version === "0.4.0") {
|
|
359
|
+
const root = path.join(temporary, "edge-repair");
|
|
360
|
+
fs.mkdirSync(root, { mode: 0o700 });
|
|
361
|
+
stagedTrees.push({ name: "edge-repair", directory: root });
|
|
362
|
+
const report = await prepareEdgeProcessRepair(context, qualified, authentication, expectation, {
|
|
363
|
+
before: beforeFile,
|
|
364
|
+
candidate: candidateFile,
|
|
365
|
+
temporary,
|
|
366
|
+
directory: path.join(root, "out"),
|
|
367
|
+
});
|
|
368
|
+
evidenceDetails.push({ role: "edge_preflight", report });
|
|
369
|
+
status = scope.status === "dispatchable" ? "prepared" : "no_change_verified";
|
|
370
|
+
}
|
|
371
|
+
else if (scope.status === "dispatchable") {
|
|
321
372
|
const outDir = path.join(temporary, "dry-run", "out");
|
|
322
373
|
fs.mkdirSync(outDir, { recursive: true, mode: 0o700 });
|
|
323
374
|
stagedTrees.push({ name: "dry-run", directory: path.join(temporary, "dry-run") });
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { registeredAssessmentSetProducerBase } from "./foundry-assessment-producer.js";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { FoundryContextError, captureFoundryInput, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
6
|
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
6
7
|
import { assertSelectedSemanticInput, readSelectedSemanticBytes, } from "./foundry-semantic-input.js";
|
|
7
8
|
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
8
9
|
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
9
10
|
import { createWorkflowStageDirectory, createWorkflowDirectory, registerWorkflowStageFiles, runWorkflowLocalCliResult, } from "./foundry-workflow-io.js";
|
|
11
|
+
import { applyFoundryTypedAuthoringPatch } from "./foundry-typed-authoring-patch.js";
|
|
10
12
|
import { runDatasetAuthoringPatchCollect } from "./import-curation/patch-collect.js";
|
|
11
13
|
import { readJsonOrJsonl, ensureArray, readRows } from "./import-curation/internal/runtime-io.js";
|
|
12
14
|
import { createFoundryDecisionOwners } from "./foundry-decision-owners.js";
|
|
@@ -142,6 +144,7 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
142
144
|
const decisionWork = [];
|
|
143
145
|
const work = [];
|
|
144
146
|
for (const set of assessment.value.sets) {
|
|
147
|
+
const ownerBase = registeredAssessmentSetProducerBase(context, entries, set);
|
|
145
148
|
const manifestFile = text(set.authoring_manifest, "Authoring manifest");
|
|
146
149
|
const manifest = workflowObject(JSON.parse(readFoundryInput(context, manifestFile).toString("utf8")));
|
|
147
150
|
if (!Array.isArray(manifest.tasks))
|
|
@@ -149,7 +152,7 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
149
152
|
const tasks = [];
|
|
150
153
|
for (const raw of manifest.tasks) {
|
|
151
154
|
const task = workflowObject(raw), files = workflowObject(task.files);
|
|
152
|
-
const taskFile = path.resolve(
|
|
155
|
+
const taskFile = path.resolve(ownerBase, text(files.task_json, "Authoring task"));
|
|
153
156
|
const entry = entries.find((candidate) => resolveFoundryOutput(context, candidate.path) === taskFile);
|
|
154
157
|
if (!entry)
|
|
155
158
|
fail("semantic_work_unregistered", "Authoring work is not registered in this task.");
|
|
@@ -165,7 +168,7 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
165
168
|
tasks.push({ task, sha: entry.sha256, fact: chosen.fact });
|
|
166
169
|
}
|
|
167
170
|
if (tasks.length)
|
|
168
|
-
work.push({ set, manifest, manifestFile, tasks });
|
|
171
|
+
work.push({ set, manifest, manifestFile, ownerBase, tasks });
|
|
169
172
|
for (const raw of Array.isArray(set.decisions) ? set.decisions : []) {
|
|
170
173
|
const decision = workflowObject(raw);
|
|
171
174
|
if (decision.kind !== "classification" &&
|
|
@@ -325,7 +328,7 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
325
328
|
if (blockers.length !== previousBlockers)
|
|
326
329
|
continue;
|
|
327
330
|
const collection = runDatasetAuthoringPatchCollect({
|
|
328
|
-
repoRoot:
|
|
331
|
+
repoRoot: group.ownerBase,
|
|
329
332
|
options: {
|
|
330
333
|
taskManifest: projectedFile,
|
|
331
334
|
outDir: path.join(output, type, "collect"),
|
|
@@ -339,39 +342,70 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
339
342
|
continue;
|
|
340
343
|
}
|
|
341
344
|
const originalRows = text(group.set.rows, "Assessed rows");
|
|
342
|
-
const packageDirectories = new Set(group.tasks.map(({ task }) => path.dirname(path.resolve(
|
|
345
|
+
const packageDirectories = new Set(group.tasks.map(({ task }) => path.dirname(path.resolve(group.ownerBase, text(workflowObject(task.files).authoring_package, "Authoring package")))));
|
|
343
346
|
if (packageDirectories.size !== 1)
|
|
344
347
|
fail("semantic_work_invalid", "Selected work must share its registered package snapshot directory.");
|
|
345
348
|
const repaired = path.join(output, type, "repaired.rows.jsonl");
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
349
|
+
const patch = path.join(output, type, "collected-patches.json");
|
|
350
|
+
const directory = path.join(output, type, "apply");
|
|
351
|
+
const typed = qualified.cli.expectation.package_version === "0.4.0";
|
|
352
|
+
const typedResult = typed
|
|
353
|
+
? applyFoundryTypedAuthoringPatch(context, qualified, temporary, {
|
|
354
|
+
type,
|
|
355
|
+
input: originalRows,
|
|
356
|
+
patch,
|
|
357
|
+
directory,
|
|
358
|
+
output: repaired,
|
|
359
|
+
packageDirectory: [...packageDirectories][0],
|
|
360
|
+
writeJson: (file, value) => operation.writeJson(file, value),
|
|
361
|
+
writeText: (file, value) => operation.writeText(file, value),
|
|
362
|
+
})
|
|
363
|
+
: null;
|
|
364
|
+
const legacyResult = typed
|
|
365
|
+
? null
|
|
366
|
+
: runWorkflowLocalCliResult(context, qualified, temporary, [
|
|
367
|
+
"dataset",
|
|
368
|
+
"patch",
|
|
369
|
+
"apply",
|
|
370
|
+
"--input",
|
|
371
|
+
originalRows,
|
|
372
|
+
"--patch",
|
|
373
|
+
patch,
|
|
374
|
+
"--out",
|
|
375
|
+
repaired,
|
|
376
|
+
"--out-dir",
|
|
377
|
+
directory,
|
|
378
|
+
"--authoring-package-dir",
|
|
379
|
+
[...packageDirectories][0],
|
|
380
|
+
"--require-authoring-package",
|
|
381
|
+
"--require-action-item-closure",
|
|
382
|
+
"--json",
|
|
383
|
+
]);
|
|
384
|
+
const applied = typedResult ?? legacyResult;
|
|
385
|
+
const original = rows.value.sets.find((set) => set.type === type && set.file === originalRows);
|
|
386
|
+
const check = () => {
|
|
387
|
+
if (!["completed", "blocked"].includes(String(applied.report.status)) ||
|
|
388
|
+
!Array.isArray(applied.report.blockers))
|
|
389
|
+
fail("semantic_apply_invalid", "Patch application returned no completed or blocked owner report.");
|
|
390
|
+
const reportFile = workflowObject(applied.report.files).report;
|
|
391
|
+
if (typeof reportFile !== "string")
|
|
392
|
+
fail("semantic_apply_invalid", "Patch application returned no report locator.");
|
|
393
|
+
legacyResult?.verifyReportFile(reportFile);
|
|
394
|
+
if (applied.exit !== 0 ||
|
|
395
|
+
applied.report.status !== "completed" ||
|
|
396
|
+
applied.report.blockers.length)
|
|
397
|
+
return null;
|
|
398
|
+
if (!original || Number(applied.report.row_count) !== original.count)
|
|
399
|
+
fail("semantic_row_scope_changed", "Patch application changed the assessed row scope.");
|
|
400
|
+
captureFoundryInput(repaired);
|
|
401
|
+
return original;
|
|
402
|
+
};
|
|
403
|
+
const completed = legacyResult ? legacyResult.validate(check) : check();
|
|
404
|
+
if (!completed) {
|
|
368
405
|
blockers.push({ code: "semantic_apply_blocked", type, report: applied.report });
|
|
369
406
|
continue;
|
|
370
407
|
}
|
|
371
|
-
|
|
372
|
-
if (!original || Number(applied.report.row_count) !== original.count)
|
|
373
|
-
fail("semantic_row_scope_changed", "Patch application changed the assessed row scope.");
|
|
374
|
-
updated.set(type, { ...original, file: repaired });
|
|
408
|
+
updated.set(type, { ...completed, file: repaired });
|
|
375
409
|
results.push({
|
|
376
410
|
type,
|
|
377
411
|
original_rows: originalRows,
|