2 """Validation: workflow interpretation guardrails. 4 Builds the workflow-interpretation layer from: 5 - the emitted workflow-contract bundle, 6 - the emitted end-to-end trace bundle, 7 - the emitted matrix baseline bundle, 8 - the emitted unsupported-workflow bundle, 9 - and the committed optional evidence bundle. 11 This layer is intentionally thin: 12 - it computes the main workflow claim only from mandatory complete supported 14 - it keeps optional evidence explicitly supplemental, 15 - it keeps unsupported/deferred evidence explicitly negative, 16 - and it treats missing mandatory evidence as incomplete rather than partial 20 python benchmarks/density_matrix/workflow_evidence/workflow_interpretation_validation.py 23 from __future__
import annotations
28 from pathlib
import Path
30 REPO_ROOT = Path(__file__).resolve().parents[3]
31 if str(REPO_ROOT)
not in sys.path:
32 sys.path.insert(0, str(REPO_ROOT))
34 from benchmarks.density_matrix.workflow_evidence.workflow_contract_validation
import (
35 ARTIFACT_FILENAME
as WORKFLOW_CONTRACT_ARTIFACT_FILENAME,
37 DEFAULT_OUTPUT_DIR
as WORKFLOW_EVIDENCE_OUTPUT_DIR,
39 build_software_metadata,
41 run_validation
as run_workflow_contract_validation,
42 validate_artifact_bundle
as validate_workflow_contract_artifact,
44 from benchmarks.density_matrix.workflow_evidence.end_to_end_trace_validation
import (
45 ARTIFACT_FILENAME
as END_TO_END_TRACE_ARTIFACT_FILENAME,
46 run_validation
as run_end_to_end_trace_validation,
47 validate_artifact_bundle
as validate_end_to_end_trace_artifact,
49 from benchmarks.density_matrix.workflow_evidence.matrix_baseline_validation
import (
50 ARTIFACT_FILENAME
as MATRIX_BASELINE_ARTIFACT_FILENAME,
51 run_validation
as run_matrix_baseline_validation,
52 validate_artifact_bundle
as validate_matrix_baseline_artifact,
54 from benchmarks.density_matrix.workflow_evidence.unsupported_workflow_validation
import (
55 ARTIFACT_FILENAME
as UNSUPPORTED_WORKFLOW_ARTIFACT_FILENAME,
56 run_validation
as run_unsupported_workflow_validation,
57 validate_artifact_bundle
as validate_unsupported_workflow_artifact,
60 SUITE_NAME =
"workflow_interpretation_validation" 61 ARTIFACT_FILENAME =
"workflow_interpretation_bundle.json" 62 DEFAULT_OUTPUT_DIR = WORKFLOW_EVIDENCE_OUTPUT_DIR
63 WORKFLOW_CONTRACT_PATH = DEFAULT_OUTPUT_DIR / WORKFLOW_CONTRACT_ARTIFACT_FILENAME
64 END_TO_END_TRACE_BUNDLE_PATH = DEFAULT_OUTPUT_DIR / END_TO_END_TRACE_ARTIFACT_FILENAME
65 MATRIX_BASELINE_BUNDLE_PATH = DEFAULT_OUTPUT_DIR / MATRIX_BASELINE_ARTIFACT_FILENAME
66 UNSUPPORTED_WORKFLOW_BUNDLE_PATH = (
67 DEFAULT_OUTPUT_DIR / UNSUPPORTED_WORKFLOW_ARTIFACT_FILENAME
69 OPTIONAL_NOISE_BUNDLE_PATH = (
75 /
"optional_noise_classification_bundle.json" 77 ARTIFACT_CORE_FIELDS = (
94 return json.loads(path.read_text(encoding=
"utf-8"))
100 validate_workflow_contract_artifact(artifact)
102 _, artifact = run_workflow_contract_validation(verbose=
False)
109 validate_end_to_end_trace_artifact(artifact)
111 _, _, _, artifact = run_end_to_end_trace_validation(verbose=
False)
118 validate_matrix_baseline_artifact(artifact)
120 _, _, _, artifact = run_matrix_baseline_validation(verbose=
False)
127 validate_unsupported_workflow_artifact(artifact)
129 *_, artifact = run_unsupported_workflow_validation(verbose=
False)
135 "workflow_id": workflow_contract[
"workflow_id"],
136 "contract_version": workflow_contract[
"contract_version"],
138 "Only mandatory, complete, supported evidence may close the main " 141 "excluded_evidence_classes": [
147 "required_bundle_sources": [
148 "workflow_contract_validation",
149 "end_to_end_trace_validation",
150 "matrix_baseline_validation",
151 "unsupported_workflow_validation",
152 "optional_noise_classification",
159 end_to_end_trace_bundle,
160 matrix_baseline_bundle,
161 unsupported_workflow_bundle,
162 optional_noise_bundle,
164 incomplete_mandatory_artifacts = []
165 mandatory_artifacts = {
166 "workflow_contract": workflow_contract,
167 "end_to_end_trace_reference": end_to_end_trace_bundle,
168 "matrix_baseline_reference": matrix_baseline_bundle,
169 "unsupported_workflow_reference": unsupported_workflow_bundle,
171 for artifact_id, artifact
in mandatory_artifacts.items():
172 if artifact[
"status"] !=
"pass":
173 incomplete_mandatory_artifacts.append(artifact_id)
175 workflow_contract_complete =
bool(
176 workflow_contract[
"summary"].get(
"contract_sections_complete",
False)
178 end_to_end_gate_complete =
bool(
179 end_to_end_trace_bundle[
"summary"].get(
"end_to_end_gate_completed",
False)
181 matrix_baseline_gate_complete =
bool(
182 matrix_baseline_bundle[
"summary"].get(
"matrix_gate_completed",
False)
184 unsupported_workflow_gate_complete =
bool(
185 unsupported_workflow_bundle[
"summary"].get(
"unsupported_gate_completed",
False)
187 unsupported_case_field_alignment = (
188 unsupported_workflow_bundle[
"requirements"][
"required_case_fields"]
189 == workflow_contract[
"output_contract"][
"required_unsupported_case_fields"]
191 mandatory_artifacts_complete =
bool(
192 not incomplete_mandatory_artifacts
193 and workflow_contract_complete
194 and end_to_end_gate_complete
195 and matrix_baseline_gate_complete
196 and unsupported_workflow_gate_complete
198 optional_evidence_supplemental =
bool(
199 optional_noise_bundle[
"status"] ==
"pass" 200 and optional_noise_bundle[
"summary"][
201 "optional_cases_count_toward_mandatory_baseline" 205 unsupported_evidence_negative_only =
bool(
206 unsupported_workflow_bundle[
"status"] ==
"pass" 207 and unsupported_workflow_bundle[
"summary"][
"unsupported_status_cases"]
208 == unsupported_workflow_bundle[
"summary"][
"total_cases"]
209 and unsupported_workflow_bundle[
"summary"][
"mandatory_baseline_case_count"]
211 and unsupported_case_field_alignment
213 main_workflow_claim_completed =
bool(
214 mandatory_artifacts_complete
215 and optional_evidence_supplemental
216 and unsupported_evidence_negative_only
220 "suite_name": SUITE_NAME,
221 "status":
"pass" if main_workflow_claim_completed
else "fail",
222 "workflow_id": workflow_contract[
"workflow_id"],
223 "contract_version": workflow_contract[
"contract_version"],
224 "backend": workflow_contract[
"backend"],
225 "reference_backend": workflow_contract[
"reference_backend"],
228 "mandatory_completion_rule":
"all_mandatory_artifacts_pass",
229 "optional_cases_count_toward_mandatory_baseline": 0,
230 "mandatory_baseline_case_count_for_negative_evidence": 0,
234 "generation_command": (
235 "python benchmarks/density_matrix/" 236 "workflow_evidence/workflow_interpretation_validation.py" 238 "working_directory": str(REPO_ROOT),
240 "workflow_contract_path": str(WORKFLOW_CONTRACT_PATH),
241 "end_to_end_trace_bundle_path": str(END_TO_END_TRACE_BUNDLE_PATH),
242 "matrix_baseline_bundle_path": str(MATRIX_BASELINE_BUNDLE_PATH),
243 "unsupported_workflow_bundle_path": str(
244 UNSUPPORTED_WORKFLOW_BUNDLE_PATH
246 "optional_noise_bundle_path": str(OPTIONAL_NOISE_BUNDLE_PATH),
249 "mandatory_artifacts": list(mandatory_artifacts.keys()),
250 "incomplete_mandatory_artifacts": incomplete_mandatory_artifacts,
251 "workflow_contract_complete": workflow_contract_complete,
252 "end_to_end_gate_complete": end_to_end_gate_complete,
253 "matrix_baseline_gate_complete": matrix_baseline_gate_complete,
254 "unsupported_workflow_gate_complete": unsupported_workflow_gate_complete,
255 "unsupported_case_field_alignment": unsupported_case_field_alignment,
256 "mandatory_artifacts_complete": mandatory_artifacts_complete,
257 "optional_cases": optional_noise_bundle[
"summary"][
"optional_cases"],
258 "optional_passed_cases": optional_noise_bundle[
"summary"][
259 "optional_passed_cases" 261 "optional_cases_count_toward_mandatory_baseline": optional_noise_bundle[
263 ][
"optional_cases_count_toward_mandatory_baseline"],
264 "optional_evidence_supplemental": optional_evidence_supplemental,
265 "unsupported_status_cases": unsupported_workflow_bundle[
"summary"][
266 "unsupported_status_cases" 268 "unsupported_cases": unsupported_workflow_bundle[
"summary"][
271 "deferred_cases": unsupported_workflow_bundle[
"summary"][
"deferred_cases"],
272 "unsupported_evidence_negative_only": unsupported_evidence_negative_only,
273 "main_workflow_claim_completed": main_workflow_claim_completed,
275 "required_artifacts": {
276 "workflow_contract": {
277 "suite_name": workflow_contract[
"suite_name"],
278 "status": workflow_contract[
"status"],
279 "summary": workflow_contract[
"summary"],
281 "end_to_end_trace_reference": {
282 "suite_name": end_to_end_trace_bundle[
"suite_name"],
283 "status": end_to_end_trace_bundle[
"status"],
284 "summary": end_to_end_trace_bundle[
"summary"],
286 "matrix_baseline_reference": {
287 "suite_name": matrix_baseline_bundle[
"suite_name"],
288 "status": matrix_baseline_bundle[
"status"],
289 "summary": matrix_baseline_bundle[
"summary"],
291 "unsupported_workflow_reference": {
292 "suite_name": unsupported_workflow_bundle[
"suite_name"],
293 "status": unsupported_workflow_bundle[
"status"],
294 "summary": unsupported_workflow_bundle[
"summary"],
296 "optional_noise_reference": {
297 "suite_name": optional_noise_bundle[
"suite_name"],
298 "status": optional_noise_bundle[
"status"],
299 "summary": optional_noise_bundle[
"summary"],
308 missing_fields = [field
for field
in ARTIFACT_CORE_FIELDS
if field
not in bundle]
311 "Workflow-interpretation bundle is missing required fields: {}".format(
312 ", ".join(missing_fields)
316 if bundle[
"workflow_id"] != WORKFLOW_ID:
318 "Workflow-interpretation bundle has unexpected workflow_id '{}'".format(
319 bundle[
"workflow_id"]
322 if bundle[
"contract_version"] != CONTRACT_VERSION:
324 "Workflow-interpretation bundle has unexpected contract_version '{}'".format(
325 bundle[
"contract_version"]
328 if bundle[
"summary"][
"main_workflow_claim_completed"] != (bundle[
"status"] ==
"pass"):
330 "Workflow-interpretation bundle main_workflow_claim_completed summary is inconsistent" 336 output_path.parent.mkdir(parents=
True, exist_ok=
True)
337 output_path.write_text(
338 json.dumps(bundle, indent=2, sort_keys=
True) +
"\n", encoding=
"utf-8" 344 workflow_contract_path: Path = WORKFLOW_CONTRACT_PATH,
345 end_to_end_trace_bundle_path: Path = END_TO_END_TRACE_BUNDLE_PATH,
346 matrix_baseline_bundle_path: Path = MATRIX_BASELINE_BUNDLE_PATH,
347 unsupported_workflow_bundle_path: Path = UNSUPPORTED_WORKFLOW_BUNDLE_PATH,
348 optional_noise_bundle_path: Path = OPTIONAL_NOISE_BUNDLE_PATH,
353 end_to_end_trace_bundle_path
357 unsupported_workflow_bundle_path
359 optional_noise_bundle =
_load_json(optional_noise_bundle_path)
362 end_to_end_trace_bundle,
363 matrix_baseline_bundle,
364 unsupported_workflow_bundle,
365 optional_noise_bundle,
369 "{} [{}] mandatory_complete={} optional_supplemental={} unsupported_negative_only={}".format(
370 bundle[
"suite_name"],
372 bundle[
"summary"][
"mandatory_artifacts_complete"],
373 bundle[
"summary"][
"optional_evidence_supplemental"],
374 bundle[
"summary"][
"unsupported_evidence_negative_only"],
379 end_to_end_trace_bundle,
380 matrix_baseline_bundle,
381 unsupported_workflow_bundle,
382 optional_noise_bundle,
388 parser = argparse.ArgumentParser(description=__doc__)
392 default=DEFAULT_OUTPUT_DIR,
393 help=
"Directory for the workflow-interpretation JSON artifact bundle.",
396 "--workflow-contract-path",
398 default=WORKFLOW_CONTRACT_PATH,
399 help=
"Path to the canonical workflow-contract artifact.",
402 "--end-to-end-trace-bundle-path",
404 default=END_TO_END_TRACE_BUNDLE_PATH,
405 help=
"Path to the end-to-end trace bundle.",
408 "--matrix-baseline-bundle-path",
410 default=MATRIX_BASELINE_BUNDLE_PATH,
411 help=
"Path to the matrix-baseline bundle.",
414 "--unsupported-workflow-bundle-path",
416 default=UNSUPPORTED_WORKFLOW_BUNDLE_PATH,
417 help=
"Path to the unsupported-workflow bundle.",
420 "--optional-noise-bundle-path",
422 default=OPTIONAL_NOISE_BUNDLE_PATH,
423 help=
"Path to the committed optional evidence bundle.",
428 help=
"Suppress summary output.",
430 return parser.parse_args()
436 workflow_contract_path=args.workflow_contract_path,
437 end_to_end_trace_bundle_path=args.end_to_end_trace_bundle_path,
438 matrix_baseline_bundle_path=args.matrix_baseline_bundle_path,
439 unsupported_workflow_bundle_path=args.unsupported_workflow_bundle_path,
440 optional_noise_bundle_path=args.optional_noise_bundle_path,
441 verbose=
not args.quiet,
443 output_path = args.output_dir / ARTIFACT_FILENAME
446 "Wrote {} with status {} ({})".format(
449 bundle[
"summary"][
"main_workflow_claim_completed"],
452 if bundle[
"status"] !=
"pass":
456 if __name__ ==
"__main__":
def build_requirement_metadata(workflow_contract)
def validate_artifact_bundle(bundle)
def _load_workflow_contract
def write_artifact_bundle
def _load_unsupported_workflow_bundle
def build_software_metadata()
def _load_matrix_baseline_bundle
def build_artifact_bundle(workflow_contract, end_to_end_trace_bundle, matrix_baseline_bundle, unsupported_workflow_bundle, optional_noise_bundle)
def _load_end_to_end_trace_bundle