@tiangong-lca/foundry 0.1.9 → 0.1.11
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 +13 -11
- package/docs/architecture.md +12 -10
- package/docs/foundry-task-contracts.md +16 -4
- package/docs/import-profiles/bafu/constraints.md +1 -1
- package/docs/import-profiles/bafu/profile.md +1 -1
- package/docs/import-profiles/worldsteel/constraints.md +3 -3
- package/docs/import-profiles/worldsteel/import-coverage.md +3 -3
- package/docs/import-profiles/worldsteel/import-plan.md +4 -4
- package/docs/import-profiles/worldsteel/profile.md +3 -3
- package/docs/package-distribution-contract.md +11 -9
- package/docs/public-runtime-contract.md +31 -9
- package/docs/runtime-context-contract.md +7 -5
- package/docs/task-authorization-contract.md +5 -3
- package/package-dist/assets/foundry-package-descriptor.json +300 -154
- package/package-dist/scripts/foundry-facade.d.ts +1 -0
- package/package-dist/scripts/foundry-facade.js +233 -28
- package/package-dist/scripts/foundry-runtime.d.ts +14 -3
- package/package-dist/scripts/foundry-runtime.js +2 -2
- package/package-dist/scripts/lib/finalize-owners/commit-handoff.js +3 -3
- package/package-dist/scripts/lib/finalize-owners/{native-insert-closeout.d.ts → native-draft-closeout.d.ts} +1 -1
- package/package-dist/scripts/lib/finalize-owners/{native-insert-closeout.js → native-draft-closeout.js} +10 -6
- package/package-dist/scripts/lib/finalize-owners/{native-insert-handoff.d.ts → native-draft-handoff.d.ts} +7 -5
- package/package-dist/scripts/lib/finalize-owners/{native-insert-handoff.js → native-draft-handoff.js} +30 -11
- package/package-dist/scripts/lib/finalize-owners/post-write-closeout.js +2 -2
- package/package-dist/scripts/lib/foundry-authorization-input.d.ts +10 -1
- package/package-dist/scripts/lib/foundry-authorization-input.js +27 -3
- package/package-dist/scripts/lib/foundry-command-metadata.js +25 -2
- package/package-dist/scripts/lib/foundry-command-registry.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-command-registry.js +3 -0
- package/package-dist/scripts/lib/foundry-execution-admission.js +3 -3
- package/package-dist/scripts/lib/foundry-facade-store.js +56 -6
- package/package-dist/scripts/lib/foundry-interaction-input.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-interaction-input.js +327 -0
- package/package-dist/scripts/lib/foundry-interaction-projection.d.ts +22 -0
- package/package-dist/scripts/lib/foundry-interaction-projection.js +81 -0
- package/package-dist/scripts/lib/foundry-interaction-types.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-interaction-types.js +4 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +33 -16
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +66 -5
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +101 -27
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-package-contract.js +4 -2
- package/package-dist/scripts/lib/foundry-repair-execution.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-repair-execution.js +70 -0
- package/package-dist/scripts/lib/foundry-repair-handoff.d.ts +16 -0
- package/package-dist/scripts/lib/foundry-repair-handoff.js +108 -0
- package/package-dist/scripts/lib/foundry-repair-preflight.d.ts +96 -0
- package/package-dist/scripts/lib/foundry-repair-preflight.js +313 -0
- package/package-dist/scripts/lib/foundry-repair-reference-binding.d.ts +26 -0
- package/package-dist/scripts/lib/foundry-repair-reference-binding.js +120 -0
- package/package-dist/scripts/lib/foundry-repair-reference-proof.d.ts +63 -0
- package/package-dist/scripts/lib/foundry-repair-reference-proof.js +329 -0
- package/package-dist/scripts/lib/foundry-repair-scope.d.ts +76 -0
- package/package-dist/scripts/lib/foundry-repair-scope.js +304 -0
- package/package-dist/scripts/lib/foundry-runtime-command-policy.js +1 -0
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
- package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.js +6 -1
- package/package-dist/scripts/lib/foundry-semantic-input.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-semantic-input.js +29 -2
- package/package-dist/scripts/lib/foundry-semantic-interaction.d.ts +12 -0
- package/package-dist/scripts/lib/foundry-semantic-interaction.js +38 -0
- package/package-dist/scripts/lib/foundry-successor-predecessor.d.ts +36 -0
- package/package-dist/scripts/lib/foundry-successor-predecessor.js +399 -0
- package/package-dist/scripts/lib/foundry-task-registration.js +64 -3
- package/package-dist/scripts/lib/foundry-task-start-spec.d.ts +14 -0
- package/package-dist/scripts/lib/foundry-task-start-spec.js +60 -1
- package/package-dist/scripts/lib/foundry-task-store.d.ts +13 -1
- package/package-dist/scripts/lib/foundry-task-store.js +23 -12
- package/package-dist/scripts/lib/foundry-task-types.d.ts +22 -1
- package/package-dist/scripts/lib/foundry-tidas-source.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-tidas-source.js +90 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +7 -1
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +127 -6
- package/package-dist/scripts/lib/foundry-workflow-authorization.d.ts +2 -1
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +194 -26
- package/package-dist/scripts/lib/foundry-workflow-context.js +4 -0
- package/package-dist/scripts/lib/foundry-workflow-execution.js +6 -1
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +7 -4
- package/package-dist/scripts/lib/foundry-workflow-interaction.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-workflow-interaction.js +63 -0
- package/package-dist/scripts/lib/foundry-workflow-repair.d.ts +36 -0
- package/package-dist/scripts/lib/foundry-workflow-repair.js +580 -0
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +21 -1
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +9 -1
- package/package-dist/scripts/lib/foundry-workflow-state.js +239 -39
- package/package-dist/scripts/lib/import-curation/curation-cleanup.js +39 -8
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.d.ts +13 -2
- package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.js +100 -29
- package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.js +1 -2
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.js +2 -3
- package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.js +8 -8
- package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.js +12 -2
- package/package-dist/scripts/public-api.d.ts +2 -0
- package/package-dist/scripts/public-api.js +1 -0
- package/package-dist/scripts/runtime-entry.js +9 -1
- package/package.json +3 -2
- package/specs/import-profiles.json +1 -1
- package/specs/schemas/foundry-authorization-input.schema.json +45 -2
- package/specs/schemas/foundry-interaction-input.schema.json +173 -0
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-package-descriptor.schema.json +3 -2
- package/specs/schemas/foundry-semantic-input.schema.json +12 -1
- package/specs/schemas/foundry-task-start.schema.json +275 -19
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { FoundryContextError, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
4
|
+
import { captureFoundryInput, FoundryContextError, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
5
|
import { readTaskBytes } from "./foundry-task-io.js";
|
|
6
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
7
|
+
import { applicableFoundryInteractionDigest } from "./foundry-interaction-projection.js";
|
|
8
|
+
/**
|
|
9
|
+
* The repair producer's registration of the preparation report. These two values are repeated here
|
|
10
|
+
* rather than imported so this projection module stays a graph leaf; the public repair suite fails
|
|
11
|
+
* if the producer ever stops registering under them.
|
|
12
|
+
*/
|
|
13
|
+
const FOUNDRY_REPAIR_PREFLIGHT_COMMAND = "dataset-workflow-repair-preflight";
|
|
14
|
+
const FOUNDRY_REPAIR_REPORT_NAME = "foundry-repair-preflight.json";
|
|
15
|
+
const FOUNDRY_REPAIR_PREPARATION_SCHEMA = "tiangong-foundry.repair-preparation.v1";
|
|
16
|
+
const queueTypes = new Set(["process", "flow", "contact", "source", "unitgroup", "flowproperty"]);
|
|
17
|
+
export function workflowAssessmentQueueScopeSha256(sets) {
|
|
18
|
+
if (!sets.some((set) => set.type === "process"))
|
|
19
|
+
return null;
|
|
20
|
+
return sha256Json(sets
|
|
21
|
+
.filter((set) => queueTypes.has(set.type))
|
|
22
|
+
.map((set) => {
|
|
23
|
+
const fact = captureFoundryInput(set.file);
|
|
24
|
+
return { type: set.type, path: set.file, bytes: fact.bytes, sha256: fact.sha256 };
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
function registeredAssessmentFile(context, entries, file) {
|
|
28
|
+
if (typeof file !== "string")
|
|
29
|
+
return false;
|
|
30
|
+
const entry = entries.find((candidate) => resolveFoundryOutput(context, candidate.path) === file);
|
|
31
|
+
if (!entry)
|
|
32
|
+
return false;
|
|
33
|
+
const fact = captureFoundryInput(file);
|
|
34
|
+
if (fact.bytes !== entry.bytes || fact.sha256 !== entry.sha256)
|
|
35
|
+
throw new FoundryContextError("workflow_assessment_changed", "A registered assessment input or report changed.");
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
6
38
|
export function workflowObject(value) {
|
|
7
39
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
8
40
|
throw new FoundryContextError("workflow_report_invalid", "Workflow metadata must be an object.");
|
|
@@ -77,6 +109,29 @@ export function currentWorkflowState(context, entries) {
|
|
|
77
109
|
}
|
|
78
110
|
}
|
|
79
111
|
}
|
|
112
|
+
const interactionEntry = entries.findLast((entry) => entry.command === "dataset-workflow-interaction" &&
|
|
113
|
+
path.basename(entry.path) === "interaction-state.json");
|
|
114
|
+
const interactionSha256 = interactionEntry?.sha256 ?? null;
|
|
115
|
+
const interactionValue = interactionEntry
|
|
116
|
+
? readWorkflowArtifact(context, interactionEntry).value
|
|
117
|
+
: null;
|
|
118
|
+
if (interactionValue &&
|
|
119
|
+
(interactionValue.schema !== "tiangong-foundry.interaction-state.v1" ||
|
|
120
|
+
interactionValue.task_id !== context.taskId ||
|
|
121
|
+
interactionValue.actor_id !== context.actorId ||
|
|
122
|
+
!Array.isArray(interactionValue.events)))
|
|
123
|
+
throw new FoundryContextError("workflow_interaction_invalid", "Registered task decisions are invalid.");
|
|
124
|
+
const interaction = interactionValue;
|
|
125
|
+
const contextShaByType = new Map();
|
|
126
|
+
for (const entry of entries) {
|
|
127
|
+
if (entry.command !== "dataset-context-pack" ||
|
|
128
|
+
path.basename(entry.path) !== "contract-report.json")
|
|
129
|
+
continue;
|
|
130
|
+
const report = readWorkflowArtifact(context, entry).value;
|
|
131
|
+
if (report.status === "completed" && typeof report.type === "string")
|
|
132
|
+
contextShaByType.set(report.type, entry.sha256);
|
|
133
|
+
}
|
|
134
|
+
const queueScopeSha256 = rows ? workflowAssessmentQueueScopeSha256(rows.value.sets) : null;
|
|
80
135
|
let assessment = null;
|
|
81
136
|
if (rows) {
|
|
82
137
|
for (const entry of [...entries].reverse()) {
|
|
@@ -85,31 +140,133 @@ export function currentWorkflowState(context, entries) {
|
|
|
85
140
|
continue;
|
|
86
141
|
const found = readWorkflowArtifact(context, entry), value = found.value;
|
|
87
142
|
if (value.schema !== "tiangong-foundry.assessment-stage.v1" ||
|
|
88
|
-
|
|
143
|
+
value.owner_base !== context.assetRoot ||
|
|
144
|
+
!["in_progress", "completed"].includes(String(value.status)) ||
|
|
89
145
|
!Array.isArray(value.sets))
|
|
90
146
|
throw new FoundryContextError("workflow_assessment_invalid", "Registered assessment metadata is invalid.");
|
|
91
147
|
const sets = value.sets.map(workflowObject);
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
148
|
+
const reportRowsEntry = entries.find((candidate) => ["dataset-workflow-rows", "dataset-semantic-apply"].includes(candidate.command) &&
|
|
149
|
+
path.basename(candidate.path) === "foundry-rows.json" &&
|
|
150
|
+
resolveFoundryOutput(context, candidate.path) === value.rows_report);
|
|
151
|
+
const reportRows = reportRowsEntry
|
|
152
|
+
? readWorkflowArtifact(context, reportRowsEntry).value
|
|
153
|
+
: value.rows_report === undefined
|
|
154
|
+
? rows.value
|
|
155
|
+
: null;
|
|
156
|
+
if (!reportRows || !Array.isArray(reportRows.sets))
|
|
157
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment row ancestry is not registered.");
|
|
158
|
+
// An empty reference-only row revision needs its own assessment receipt. There are
|
|
159
|
+
// no per-type set facts to reuse from a predecessor with different rows.
|
|
160
|
+
if (!rows.value.sets.length && value.rows_report !== rows.file)
|
|
161
|
+
continue;
|
|
162
|
+
const originalRows = reportRows.sets.map(workflowObject);
|
|
163
|
+
let lastOriginal = -1;
|
|
164
|
+
for (const set of sets) {
|
|
165
|
+
const next = originalRows.findIndex((row, index) => index > lastOriginal && row.type === set.type && row.file === set.rows);
|
|
166
|
+
if (next < 0)
|
|
167
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment contains an unbound or duplicate row set.");
|
|
168
|
+
lastOriginal = next;
|
|
110
169
|
}
|
|
170
|
+
if ((value.status === "completed") !== (sets.length === originalRows.length))
|
|
171
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment completion must match its registered row-set coverage.");
|
|
172
|
+
if (value.previous_assessment !== undefined) {
|
|
173
|
+
const previousPath = value.previous_assessment;
|
|
174
|
+
const previousSha = value.previous_assessment_sha256;
|
|
175
|
+
const previousEntry = typeof previousPath === "string"
|
|
176
|
+
? entries.find((candidate) => candidate.command === "dataset-workflow-assessment" &&
|
|
177
|
+
candidate.sequence < entry.sequence &&
|
|
178
|
+
resolveFoundryOutput(context, candidate.path) === previousPath &&
|
|
179
|
+
candidate.sha256 === previousSha)
|
|
180
|
+
: undefined;
|
|
181
|
+
if ((previousPath === null && previousSha !== null) ||
|
|
182
|
+
(typeof previousPath === "string" && !previousEntry) ||
|
|
183
|
+
(previousPath !== null && typeof previousPath !== "string") ||
|
|
184
|
+
(previousPath === null && (sets.length !== 1 || value.assessed_type !== sets[0]?.type)))
|
|
185
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment progress has no matching registered predecessor.");
|
|
186
|
+
if (previousEntry) {
|
|
187
|
+
const prior = readWorkflowArtifact(context, previousEntry).value;
|
|
188
|
+
const priorSets = Array.isArray(prior.sets) ? prior.sets.map(workflowObject) : null;
|
|
189
|
+
if (prior.schema !== "tiangong-foundry.assessment-stage.v1" ||
|
|
190
|
+
!priorSets ||
|
|
191
|
+
typeof value.assessed_type !== "string" ||
|
|
192
|
+
!sets.some((set) => set.type === value.assessed_type) ||
|
|
193
|
+
sets.some((set) => set.type !== value.assessed_type &&
|
|
194
|
+
!priorSets.some((old) => sha256Json(old) === sha256Json(set))))
|
|
195
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment retained a set outside its registered predecessor.");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (value.status === "in_progress") {
|
|
199
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Partial assessment must identify its predecessor boundary.");
|
|
200
|
+
}
|
|
201
|
+
const identityMatches = (value.identity_report ?? null) ===
|
|
202
|
+
(identity?.value.status === "completed" ? identity.file : null);
|
|
203
|
+
const currentSets = identityMatches
|
|
204
|
+
? sets.filter((set) => {
|
|
205
|
+
const row = rows.value.sets.find((candidate) => candidate.type === set.type);
|
|
206
|
+
if (!row || row.file !== set.rows)
|
|
207
|
+
return false;
|
|
208
|
+
if ((set.interaction_digest ?? null) !==
|
|
209
|
+
applicableFoundryInteractionDigest(interaction, row.type))
|
|
210
|
+
return false;
|
|
211
|
+
const expectedContext = contextShaByType.get(row.type);
|
|
212
|
+
if ((set.context_report_sha256 !== undefined &&
|
|
213
|
+
set.context_report_sha256 !== expectedContext) ||
|
|
214
|
+
(set.context_report_sha256 === undefined && value.rows_report !== rows.file))
|
|
215
|
+
return false;
|
|
216
|
+
if (["flow", "process"].includes(row.type)) {
|
|
217
|
+
if ((set.queue_scope_sha256 !== undefined &&
|
|
218
|
+
set.queue_scope_sha256 !== queueScopeSha256) ||
|
|
219
|
+
(set.queue_scope_sha256 === undefined &&
|
|
220
|
+
queueScopeSha256 !== null &&
|
|
221
|
+
value.rows_report !== rows.file))
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
const files = [
|
|
225
|
+
set.rows,
|
|
226
|
+
set.schema_report,
|
|
227
|
+
set.qa_report,
|
|
228
|
+
set.curation_report,
|
|
229
|
+
set.authoring_manifest,
|
|
230
|
+
];
|
|
231
|
+
if (set.interaction_context !== undefined)
|
|
232
|
+
files.push(set.interaction_context);
|
|
233
|
+
if (files.some((file) => !registeredAssessmentFile(context, entries, file)))
|
|
234
|
+
throw new FoundryContextError("workflow_assessment_invalid", "A reusable assessment file is not registered.");
|
|
235
|
+
return true;
|
|
236
|
+
})
|
|
237
|
+
: [];
|
|
238
|
+
const covered = new Set(currentSets.map((set) => set.type));
|
|
239
|
+
assessment = {
|
|
240
|
+
...found,
|
|
241
|
+
value: {
|
|
242
|
+
schema: "tiangong-foundry.assessment-stage.v1",
|
|
243
|
+
status: covered.size === rows.value.sets.length ? "completed" : "in_progress",
|
|
244
|
+
owner_base: value.owner_base,
|
|
245
|
+
rows_report: rows.file,
|
|
246
|
+
identity_report: identity?.value.status === "completed" ? identity.file : null,
|
|
247
|
+
...(value.previous_assessment !== undefined
|
|
248
|
+
? {
|
|
249
|
+
previous_assessment: value.previous_assessment,
|
|
250
|
+
previous_assessment_sha256: value.previous_assessment_sha256,
|
|
251
|
+
}
|
|
252
|
+
: {}),
|
|
253
|
+
...(typeof value.interaction_sha256 === "string"
|
|
254
|
+
? { interaction_sha256: value.interaction_sha256 }
|
|
255
|
+
: {}),
|
|
256
|
+
...(typeof value.assessed_type === "string"
|
|
257
|
+
? { assessed_type: value.assessed_type }
|
|
258
|
+
: {}),
|
|
259
|
+
sets: currentSets,
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
break;
|
|
111
263
|
}
|
|
112
264
|
}
|
|
265
|
+
const assessmentComplete = assessment?.value.status === "completed";
|
|
266
|
+
const coveredTypes = new Set(assessment?.value.sets.map((set) => set.type) ?? []);
|
|
267
|
+
const assessmentRemainingTypes = rows
|
|
268
|
+
? rows.value.sets.filter((set) => !coveredTypes.has(set.type)).map((set) => set.type)
|
|
269
|
+
: [];
|
|
113
270
|
const referenceInputs = new Map();
|
|
114
271
|
for (const entry of entries) {
|
|
115
272
|
if (entry.command !== "dataset-workflow-reference-input" ||
|
|
@@ -130,7 +287,7 @@ export function currentWorkflowState(context, entries) {
|
|
|
130
287
|
.digest("hex")
|
|
131
288
|
: null;
|
|
132
289
|
let finalization = null;
|
|
133
|
-
if (rows && assessment) {
|
|
290
|
+
if (rows && assessmentComplete && assessment) {
|
|
134
291
|
for (const entry of [...entries].reverse()) {
|
|
135
292
|
if (entry.command !== "dataset-workflow-finalize" ||
|
|
136
293
|
path.basename(entry.path) !== "foundry-finalize.json")
|
|
@@ -150,33 +307,76 @@ export function currentWorkflowState(context, entries) {
|
|
|
150
307
|
}
|
|
151
308
|
let authorization = null;
|
|
152
309
|
let preparedApproval = null;
|
|
153
|
-
if (
|
|
310
|
+
if (context.taskRoot && fs.existsSync(path.join(context.taskRoot, "authorization.json"))) {
|
|
154
311
|
const pointer = createHash("sha256")
|
|
155
312
|
.update(readTaskBytes(context, "authorization.json"))
|
|
156
313
|
.digest("hex");
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
found.value.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
314
|
+
if (finalization) {
|
|
315
|
+
for (const entry of [...entries].reverse()) {
|
|
316
|
+
if (entry.command !== "dataset-workflow-authorization" ||
|
|
317
|
+
path.basename(entry.path) !== "foundry-authorization.json")
|
|
318
|
+
continue;
|
|
319
|
+
const found = readWorkflowArtifact(context, entry);
|
|
320
|
+
if (found.value.schema !== "tiangong-foundry.authorization-stage.v1")
|
|
321
|
+
throw new FoundryContextError("workflow_authorization_invalid", "Registered approval metadata is invalid.");
|
|
322
|
+
const prepared = finalization.value.approval_source_sha256 === entry.sha256 &&
|
|
323
|
+
found.value.input_kind === "current_rows";
|
|
324
|
+
if (prepared)
|
|
325
|
+
preparedApproval = found;
|
|
326
|
+
if ((found.value.finalization_sha256 === finalization.entry.sha256 || prepared) &&
|
|
327
|
+
found.value.pointer_sha256 === pointer &&
|
|
328
|
+
typeof found.value.expires_at_utc === "string" &&
|
|
329
|
+
Date.parse(found.value.expires_at_utc) > Date.now()) {
|
|
330
|
+
authorization = found;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!authorization) {
|
|
336
|
+
// A repair scope has no finalization: its registered authority is the latest preparation report
|
|
337
|
+
// of this task, and only while that report is a prepared dispatchable write scope. An approval
|
|
338
|
+
// bound to a superseded report, or to evidence that has since become no-change or blocked,
|
|
339
|
+
// carries no current authority.
|
|
340
|
+
const latest = entries
|
|
341
|
+
.filter((entry) => entry.command === FOUNDRY_REPAIR_PREFLIGHT_COMMAND &&
|
|
342
|
+
path.basename(entry.path) === FOUNDRY_REPAIR_REPORT_NAME)
|
|
343
|
+
.sort((left, right) => left.sequence - right.sequence)
|
|
344
|
+
.at(-1);
|
|
345
|
+
if (latest) {
|
|
346
|
+
const report = readWorkflowArtifact(context, latest).value;
|
|
347
|
+
const reportScope = report.scope;
|
|
348
|
+
const dispatchable = report.schema === FOUNDRY_REPAIR_PREPARATION_SCHEMA &&
|
|
349
|
+
report.status === "prepared" &&
|
|
350
|
+
Boolean(reportScope) &&
|
|
351
|
+
typeof reportScope === "object" &&
|
|
352
|
+
!Array.isArray(reportScope) &&
|
|
353
|
+
reportScope.status === "dispatchable";
|
|
354
|
+
if (dispatchable)
|
|
355
|
+
for (const entry of [...entries].reverse()) {
|
|
356
|
+
if (entry.command !== "dataset-workflow-authorization" ||
|
|
357
|
+
path.basename(entry.path) !== "foundry-authorization.json")
|
|
358
|
+
continue;
|
|
359
|
+
const found = readWorkflowArtifact(context, entry);
|
|
360
|
+
if (found.value.schema !== "tiangong-foundry.authorization-stage.v1")
|
|
361
|
+
throw new FoundryContextError("workflow_authorization_invalid", "Registered approval metadata is invalid.");
|
|
362
|
+
if (found.value.input_kind === "repair_rows" &&
|
|
363
|
+
found.value.finalization_sha256 === latest.sha256 &&
|
|
364
|
+
found.value.pointer_sha256 === pointer &&
|
|
365
|
+
typeof found.value.expires_at_utc === "string" &&
|
|
366
|
+
Date.parse(found.value.expires_at_utc) > Date.now()) {
|
|
367
|
+
authorization = found;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
174
371
|
}
|
|
175
372
|
}
|
|
176
373
|
}
|
|
177
374
|
return {
|
|
178
375
|
rows,
|
|
179
376
|
assessment,
|
|
377
|
+
assessmentComplete,
|
|
378
|
+
assessmentRemainingTypes,
|
|
379
|
+
interactionSha256,
|
|
180
380
|
identity,
|
|
181
381
|
finalization,
|
|
182
382
|
authorization,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { datasetTypeFromOptions, datasetTypePlural } from "./internal/dataset-types.js";
|
|
3
3
|
import { datasetIdentity } from "./internal/dataset-payload.js";
|
|
4
|
-
import {
|
|
4
|
+
import { sha256Json } from "./internal/hash-utils.js";
|
|
5
|
+
import { annualSupplyFieldPath, applyDeterministicSourceExchangeCompletenessProofs, buildSourceRowsByIdentity, ensureFoundryTraceNamespaces, externalizeImportTraceMetadata, normalizeAnnualSupplyEvidence, normalizeDateTimeMetadata, sanitizeFoundryTraceEvidenceLocators, } from "./internal/prewrite-cleanup.js";
|
|
5
6
|
import { fileExists, jsonLines, nowIso, readRows, repoRelativePath, resolveRepoPath, writeJson, writeText, } from "./internal/runtime-io.js";
|
|
6
7
|
function dateTimeBlockersFromError(error) {
|
|
7
8
|
if (!error || typeof error !== "object" || Array.isArray(error))
|
|
@@ -27,7 +28,7 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
27
28
|
usage: [
|
|
28
29
|
"node scripts/foundry.ts dataset-curation-cleanup --type <process|flow|lifecyclemodel|support|contact|source> --rows-file <rows.jsonl> [--source-rows-file <source-rows.jsonl>] --out-dir <cleanup-dir>",
|
|
29
30
|
],
|
|
30
|
-
purpose: "Run deterministic prewrite cleanup transforms: annual-supply
|
|
31
|
+
purpose: "Run deterministic prewrite cleanup transforms: annual-supply evidence preservation, import trace externalization, Foundry trace namespace repair, local locator redaction, and timestamp normalization.",
|
|
31
32
|
remote_write_mode: "read-only",
|
|
32
33
|
blockers: [],
|
|
33
34
|
};
|
|
@@ -110,11 +111,13 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
110
111
|
redacted_foundry_trace_evidence_locators: 0,
|
|
111
112
|
added_foundry_trace_namespaces: 0,
|
|
112
113
|
normalized_datetime_values: 0,
|
|
113
|
-
|
|
114
|
+
annual_supply_unknown_normalized: 0,
|
|
115
|
+
annual_supply_evidence_gaps: 0,
|
|
114
116
|
source_exchange_completeness_proofs: 0,
|
|
115
117
|
},
|
|
116
118
|
source_rows_file: sourceRowsFile && hasFile(sourceRowsFile) ? repoRelativePath(root, sourceRowsFile) : null,
|
|
117
119
|
source_exchange_completeness_proofs: [],
|
|
120
|
+
annual_supply_evidence_gaps: [],
|
|
118
121
|
blockers,
|
|
119
122
|
policy: {
|
|
120
123
|
purpose: "Reject invalid TIDAS/ILCD datetime metadata before any cleanup transform or cleaned-row output.",
|
|
@@ -133,12 +136,21 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
133
136
|
let externalizedSourceTraceSummaries = 0;
|
|
134
137
|
let addedFoundryTraceNamespaces = 0;
|
|
135
138
|
let redactedFoundryTraceEvidenceLocators = 0;
|
|
136
|
-
let
|
|
139
|
+
let annualSupplyUnknownNormalized = 0;
|
|
137
140
|
let sourceExchangeCompletenessProofs = 0;
|
|
138
141
|
const sourceExchangeProofRows = [];
|
|
142
|
+
const inputPayloadSha256 = rows.map((row, rowIndex) => sha256Json(datasetIdentity(row, rowIndex, datasetType).payload));
|
|
143
|
+
const pendingAnnualSupplyGaps = [];
|
|
139
144
|
cleanedRows.forEach((cleaned, rowIndex) => {
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
const annualSupply = normalizeAnnualSupplyEvidence(cleaned, datasetType);
|
|
146
|
+
if (annualSupply.changed)
|
|
147
|
+
annualSupplyUnknownNormalized += 1;
|
|
148
|
+
if (annualSupply.gap) {
|
|
149
|
+
pendingAnnualSupplyGaps.push({
|
|
150
|
+
index: rowIndex,
|
|
151
|
+
reason: annualSupply.gap.reason,
|
|
152
|
+
reviewRequired: annualSupply.gap.review_required,
|
|
153
|
+
});
|
|
142
154
|
}
|
|
143
155
|
if (applyDeterministicSourceExchangeCompletenessProofs(cleaned, datasetType, {
|
|
144
156
|
rowIndex,
|
|
@@ -155,6 +167,23 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
155
167
|
redactedFoundryTraceEvidenceLocators += sanitizeFoundryTraceEvidenceLocators(cleaned);
|
|
156
168
|
addedFoundryTraceNamespaces += ensureFoundryTraceNamespaces(cleaned);
|
|
157
169
|
});
|
|
170
|
+
// Bound only after every other cleanup transform has run, so the output hash describes the
|
|
171
|
+
// exact unwrapped payload the caller will write, with no row metadata mixed in.
|
|
172
|
+
const annualSupplyEvidenceGaps = pendingAnnualSupplyGaps.map((pending) => {
|
|
173
|
+
const identity = datasetIdentity(rows[pending.index], pending.index, datasetType);
|
|
174
|
+
const outputIdentity = datasetIdentity(cleanedRows[pending.index], pending.index, datasetType);
|
|
175
|
+
return {
|
|
176
|
+
row_index: pending.index,
|
|
177
|
+
dataset_type: datasetType,
|
|
178
|
+
dataset_id: identity.id,
|
|
179
|
+
version: identity.version,
|
|
180
|
+
field: annualSupplyFieldPath,
|
|
181
|
+
reason: pending.reason,
|
|
182
|
+
review_required: pending.reviewRequired,
|
|
183
|
+
input_payload_sha256: inputPayloadSha256[pending.index] ?? null,
|
|
184
|
+
output_payload_sha256: sha256Json(outputIdentity.payload),
|
|
185
|
+
};
|
|
186
|
+
});
|
|
158
187
|
writeRows(outFile, jsonLines(cleanedRows));
|
|
159
188
|
const report = {
|
|
160
189
|
schema_version: 2,
|
|
@@ -173,11 +202,13 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
173
202
|
redacted_foundry_trace_evidence_locators: redactedFoundryTraceEvidenceLocators,
|
|
174
203
|
added_foundry_trace_namespaces: addedFoundryTraceNamespaces,
|
|
175
204
|
normalized_datetime_values: normalizedDateTimeValues,
|
|
176
|
-
|
|
205
|
+
annual_supply_unknown_normalized: annualSupplyUnknownNormalized,
|
|
206
|
+
annual_supply_evidence_gaps: annualSupplyEvidenceGaps.length,
|
|
177
207
|
source_exchange_completeness_proofs: sourceExchangeCompletenessProofs,
|
|
178
208
|
},
|
|
179
209
|
source_rows_file: sourceRowsFile && hasFile(sourceRowsFile) ? repoRelativePath(root, sourceRowsFile) : null,
|
|
180
210
|
source_exchange_completeness_proofs: sourceExchangeProofRows,
|
|
211
|
+
annual_supply_evidence_gaps: annualSupplyEvidenceGaps,
|
|
181
212
|
blockers: [],
|
|
182
213
|
policy: {
|
|
183
214
|
purpose: "Normalize write-time metadata and externalize import-only tidasimport:sourceTrace after curation context has been captured and before remote write.",
|
|
@@ -186,7 +217,7 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
|
|
|
186
217
|
foundry_trace_namespace_policy: "Any common:other tiangongfoundry:* trace kept in write payload gets @xmlns:tiangongfoundry before Rust tidas validation.",
|
|
187
218
|
foundry_trace_locator_policy: "Local machine paths from tiangongfoundry:* trace evidence are redacted from write payloads; authoring packages and patch evidence retain the full local context.",
|
|
188
219
|
datetime_policy: "TIDAS/ILCD dateTime values with timezone offsets are normalized to UTC Z form when the UTC projection remains inside the accepted four-digit year grammar; valid year-boundary offsets retain their exact source bytes.",
|
|
189
|
-
|
|
220
|
+
annual_supply_evidence_policy: "annualSupplyOrProductionVolume is schema-required. Foundry preserves real evidence — a single object or a language array — byte-semantically and in its original element order, and never rewrites a real quantity that merely collides numerically with a historical marker. A missing, empty, or explicitly-marked-absent volume is normalized to the supported empty array and reported as a row-level evidence gap in annual_supply_evidence_gaps; Foundry never fills in a synthesized quantity. Unsupported shapes are left untouched for the SDK/CLI gate to reject. Cleanup completion means the local transform finished, not that the row is authoring, write, or publication ready; downstream schema, authoring, curation, and write gates remain the blocking owners.",
|
|
190
221
|
source_exchange_completeness_policy: "For process rows, if an explicit source rows file is supplied and the source process row is Output-only with the same non-flow-reference exchange signature as the final row, Foundry may write deterministic tiangongfoundry:sourceExchangeCompleteness proof. Otherwise source-only-output acceptance still requires AI source_trace_verified evidence or exchange repair.",
|
|
191
222
|
},
|
|
192
223
|
};
|
|
@@ -6,7 +6,7 @@ import { asText, directoryExists, ensureArray, fileExists, readJson, readText, r
|
|
|
6
6
|
function asJsonRecord(value) {
|
|
7
7
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8
8
|
}
|
|
9
|
-
export const tidasSchemaSearchRoots = ["@tiangong-lca/cli@0.1.
|
|
9
|
+
export const tidasSchemaSearchRoots = ["@tiangong-lca/cli@0.1.19/assets/tidas-schemas"];
|
|
10
10
|
export function tidasSchemaPath(repoRoot, schemaFile) {
|
|
11
11
|
void repoRoot;
|
|
12
12
|
const candidate = path.join(resolveInstalledTiangongLcaCliPackage().schemaDir, schemaFile);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { datasetIdentity } from "./dataset-payload.ts";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const legacyAnnualSupplyMissingDataSentinelText = "9999 missing-data-sentinel/year";
|
|
3
|
+
export declare const annualSupplyFieldPath = "processDataSet.modellingAndValidation.dataSourcesTreatmentAndRepresentativeness.annualSupplyOrProductionVolume";
|
|
3
4
|
export declare const foundryTraceNamespace = "https://tiangong-lca.dev/foundry/import-curation/1";
|
|
4
5
|
interface JsonRecord {
|
|
5
6
|
[key: string]: unknown;
|
|
@@ -19,7 +20,17 @@ interface SourceExchangeProofOptions {
|
|
|
19
20
|
}
|
|
20
21
|
export declare function normalizeUtcDateTimeString(value: unknown): string | null;
|
|
21
22
|
export declare function normalizeDateTimeMetadata(value: unknown): number;
|
|
22
|
-
export
|
|
23
|
+
export type AnnualSupplyGapReason = "missing" | "empty" | "legacy_marker" | "explicit_missing_text" | "already_unknown" | "mixed_entries";
|
|
24
|
+
export interface AnnualSupplyGap {
|
|
25
|
+
field: string;
|
|
26
|
+
reason: AnnualSupplyGapReason;
|
|
27
|
+
review_required: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface AnnualSupplyResult {
|
|
30
|
+
changed: boolean;
|
|
31
|
+
gap: AnnualSupplyGap | null;
|
|
32
|
+
}
|
|
33
|
+
export declare function normalizeAnnualSupplyEvidence(row: unknown, datasetType: string): AnnualSupplyResult;
|
|
23
34
|
export declare function applyDeterministicSourceExchangeCompletenessProofs(row: unknown, datasetType: string, { rowIndex, sourceRowsByKey, sourceRowsFile, rowsFile, proofRows, }?: SourceExchangeProofOptions): boolean;
|
|
24
35
|
export declare function buildSourceRowsByIdentity(sourceRows: unknown[]): SourceRowsByIdentity;
|
|
25
36
|
export declare function externalizeImportTraceMetadata(value: unknown): {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { datasetIdentity, datasetRoot, unwrapDatasetPayload } from "./dataset-payload.js";
|
|
2
2
|
import { sha256Json, sha256Text } from "./hash-utils.js";
|
|
3
3
|
import { asText, ensureArray } from "./runtime-io.js";
|
|
4
|
-
|
|
4
|
+
// Historical recognition marker only. Foundry no longer writes this value; it is retained so
|
|
5
|
+
// service rows written by earlier rounds can still be recognized and normalized.
|
|
6
|
+
export const legacyAnnualSupplyMissingDataSentinelText = "9999 missing-data-sentinel/year";
|
|
7
|
+
export const annualSupplyFieldPath = "processDataSet.modellingAndValidation.dataSourcesTreatmentAndRepresentativeness.annualSupplyOrProductionVolume";
|
|
5
8
|
export const foundryTraceNamespace = "https://tiangong-lca.dev/foundry/import-curation/1";
|
|
6
9
|
const datetimeFieldsToNormalize = new Set(["common:timeStamp", "common:dateOfLastRevision"]);
|
|
7
10
|
const foundryTraceKeys = [
|
|
@@ -118,46 +121,114 @@ export function normalizeDateTimeMetadata(value) {
|
|
|
118
121
|
update.parent[update.key] = update.normalized;
|
|
119
122
|
return updates.length;
|
|
120
123
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
// Narrow, complete-string recognition only. Scientific prose that merely mentions an unknown or
|
|
125
|
+
// unavailable volume stays untouched; the downstream SDK/CLI/authoring gates own rejecting it.
|
|
126
|
+
const missingAnnualSupplyTexts = new Set([
|
|
127
|
+
"not specified",
|
|
128
|
+
"not declared in source package",
|
|
129
|
+
"source production volume unavailable",
|
|
130
|
+
"production volume unavailable",
|
|
131
|
+
"source evidence unavailable",
|
|
132
|
+
]);
|
|
133
|
+
function normalizeAnnualSupplyText(value) {
|
|
134
|
+
return value.trim().toLowerCase().replace(/\s+/gu, " ").replace(/\.$/u, "");
|
|
135
|
+
}
|
|
136
|
+
function classifyAnnualSupplyText(text) {
|
|
137
|
+
const normalized = normalizeAnnualSupplyText(text);
|
|
138
|
+
if (normalized === normalizeAnnualSupplyText(legacyAnnualSupplyMissingDataSentinelText)) {
|
|
139
|
+
return { kind: "unknown", reason: "legacy_marker" };
|
|
140
|
+
}
|
|
141
|
+
if (normalized === "")
|
|
142
|
+
return { kind: "unknown", reason: "empty" };
|
|
143
|
+
if (missingAnnualSupplyTexts.has(normalized)) {
|
|
144
|
+
return { kind: "unknown", reason: "explicit_missing_text" };
|
|
126
145
|
}
|
|
127
|
-
return "";
|
|
146
|
+
return { kind: "real", text };
|
|
128
147
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
function classifyAnnualSupplyEntry(value) {
|
|
149
|
+
if (typeof value === "string")
|
|
150
|
+
return classifyAnnualSupplyText(value);
|
|
151
|
+
if (!isRecord(value))
|
|
152
|
+
return null;
|
|
153
|
+
const raw = value["#text"] ?? value.value;
|
|
154
|
+
if (typeof raw !== "string")
|
|
155
|
+
return null;
|
|
156
|
+
return classifyAnnualSupplyText(raw);
|
|
157
|
+
}
|
|
158
|
+
// A language-array entry must be an object carrying both a non-empty string `@xml:lang` and a
|
|
159
|
+
// string `#text`. Any other element — including plain strings such as `["Not specified"]` — is an
|
|
160
|
+
// unsupported shape and is preserved untouched so the SDK/CLI gate owns rejecting it.
|
|
161
|
+
function classifyAnnualSupplyLanguageEntry(value) {
|
|
162
|
+
if (!isRecord(value))
|
|
163
|
+
return null;
|
|
164
|
+
const language = value["@xml:lang"];
|
|
165
|
+
if (typeof language !== "string" || language.trim() === "")
|
|
166
|
+
return null;
|
|
167
|
+
const text = value["#text"];
|
|
168
|
+
if (typeof text !== "string")
|
|
169
|
+
return null;
|
|
170
|
+
return classifyAnnualSupplyText(text);
|
|
139
171
|
}
|
|
140
|
-
function
|
|
172
|
+
function unchangedAnnualSupplyResult(reason, reviewRequired = false) {
|
|
141
173
|
return {
|
|
142
|
-
|
|
143
|
-
|
|
174
|
+
changed: false,
|
|
175
|
+
gap: reason === null
|
|
176
|
+
? null
|
|
177
|
+
: { field: annualSupplyFieldPath, reason, review_required: reviewRequired },
|
|
144
178
|
};
|
|
145
179
|
}
|
|
146
|
-
|
|
147
|
-
if (datasetType !== "process")
|
|
148
|
-
return false;
|
|
180
|
+
function annualSupplyContainer(row, datasetType) {
|
|
149
181
|
const payload = unwrapDatasetPayload(row, datasetType);
|
|
150
182
|
const root = datasetRoot(payload, datasetType);
|
|
151
183
|
const modelling = isRecord(root.modellingAndValidation) ? root.modellingAndValidation : {};
|
|
152
184
|
const dataSources = modelling.dataSourcesTreatmentAndRepresentativeness;
|
|
153
|
-
|
|
154
|
-
|
|
185
|
+
return isRecord(dataSources) ? dataSources : null;
|
|
186
|
+
}
|
|
187
|
+
// Unknown volume is written as the supported empty language array; it is never filled with a
|
|
188
|
+
// synthesized quantity, and the runner reports it as a row-level evidence gap.
|
|
189
|
+
function unknownAnnualSupplyResult(dataSources, reason) {
|
|
190
|
+
dataSources.annualSupplyOrProductionVolume = [];
|
|
191
|
+
return {
|
|
192
|
+
changed: true,
|
|
193
|
+
gap: { field: annualSupplyFieldPath, reason, review_required: false },
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
// Real evidence — single object or language array — is preserved byte-semantically, including its
|
|
197
|
+
// original element order. Unsupported shapes are preserved for the SDK/CLI gate to reject.
|
|
198
|
+
export function normalizeAnnualSupplyEvidence(row, datasetType) {
|
|
199
|
+
if (datasetType !== "process")
|
|
200
|
+
return unchangedAnnualSupplyResult(null);
|
|
201
|
+
const dataSources = annualSupplyContainer(row, datasetType);
|
|
202
|
+
if (!dataSources)
|
|
203
|
+
return unchangedAnnualSupplyResult(null);
|
|
155
204
|
const current = dataSources.annualSupplyOrProductionVolume;
|
|
156
|
-
if (current
|
|
157
|
-
return
|
|
205
|
+
if (current === undefined || current === null) {
|
|
206
|
+
return unknownAnnualSupplyResult(dataSources, "missing");
|
|
158
207
|
}
|
|
159
|
-
|
|
160
|
-
|
|
208
|
+
if (Array.isArray(current)) {
|
|
209
|
+
if (current.length === 0)
|
|
210
|
+
return unchangedAnnualSupplyResult("already_unknown");
|
|
211
|
+
const entries = [];
|
|
212
|
+
for (const element of current) {
|
|
213
|
+
const classified = classifyAnnualSupplyLanguageEntry(element);
|
|
214
|
+
if (classified === null)
|
|
215
|
+
return unchangedAnnualSupplyResult(null);
|
|
216
|
+
entries.push(classified);
|
|
217
|
+
}
|
|
218
|
+
const realCount = entries.filter((entry) => entry.kind === "real").length;
|
|
219
|
+
if (realCount === entries.length)
|
|
220
|
+
return unchangedAnnualSupplyResult(null);
|
|
221
|
+
if (realCount === 0) {
|
|
222
|
+
const legacyOnly = entries.every((entry) => entry.kind === "unknown" && entry.reason === "legacy_marker");
|
|
223
|
+
return unknownAnnualSupplyResult(dataSources, legacyOnly ? "legacy_marker" : "explicit_missing_text");
|
|
224
|
+
}
|
|
225
|
+
// Mixed real and unknown entries: keep every real element and flag the row for review.
|
|
226
|
+
return unchangedAnnualSupplyResult("mixed_entries", true);
|
|
227
|
+
}
|
|
228
|
+
const single = classifyAnnualSupplyEntry(current);
|
|
229
|
+
if (single === null || single.kind === "real")
|
|
230
|
+
return unchangedAnnualSupplyResult(null);
|
|
231
|
+
return unknownAnnualSupplyResult(dataSources, single.reason);
|
|
161
232
|
}
|
|
162
233
|
function processDataSetInformation(row) {
|
|
163
234
|
const payload = unwrapDatasetPayload(row, "process");
|