core/tests/test_workbench_demos.py
Shay 4cba6f488c feat(workbench): Wave M Phase C legibility — pipeline record, contemplation, identity continuity
Lands the Phase C "make cognition legible" slice plus Phase A residue, all
backend-reader-first over real engine data (no theater, read-only doctrine
intact, zero serving-path imports).

C1-a — Cognitive pipeline record (persistence-first, per #729 worthiness edit):
  - workbench/pipeline_record.py: curated CognitivePipelineRecord over the real
    CognitiveTurnResult (input → intent → proposition_graph → articulation_target
    → realizer → walk_telemetry → trace_hash). Raw field multivectors are
    DELIBERATELY excluded; _assert_no_raw_field_payload recursively rejects raw
    field keys, and validate_pipeline_record fails closed on missing/duplicate
    stages, non-recorded status, or dangling edges — the UI can never receive a
    partial record that claims to be complete.
  - test_workbench_pipeline_record.py: non-vacuous guards — missing stage,
    monkeypatched new required stage, and injected raw {"F": [...]} each raise.

C2-a — Contemplation as a process: /contemplation route over real persisted
  contemplation/runs/*.json (glob reader; honest-empty when absent).

C4-a — Identity continuity (L10/L11): RunDetail.identity_continuity + Runs
  Identity tab, sourced from the real core.engine_identity (engine_identity /
  parent_engine_identity lineage relation, re-derived to verify).

Demo Theater: renders backend-owned proof-promotion + entailment DAGs.

Phase A residue: density preference wired end-to-end (settings → shell → tokens);
  cross-route consistency touch-ups.

Infra: local API CORS now echoes only validated 127.0.0.1/localhost origins
  (hostname-checked, not arbitrary reflection) so Vite fallback ports work.
  Route chunk-split keeps the build warning-free.

Cleanup: corrected the stale ADR-0175 practice-lane assertions (build_report is
  6 correct / 0 wrong / 44 refused after the current serving lane; wrong=0 held)
  and the two registry-derived count tests (LeftNav + CommandPalette 12 → 13 for
  the new Contemplation route).

Docs: runtime_contracts.md (pipeline-record contract), UI-UX-GUIDE,
  api-contract-v1, data-shapes-v1, wave-M-worthiness, phase-a-residue-ledger.

Validation: 106 workbench/practice Python tests green (incl. wrong=0 lane +
  pipeline-record fail-closed guards); 459/459 frontend; pnpm build clean;
  git diff --check clean. No generate.derivation / reliability_gate / stream /
  field.propagate / vault.store imports.
2026-06-13 15:44:31 -07:00

104 lines
3.5 KiB
Python

from __future__ import annotations
from pathlib import Path
from workbench.api import WorkbenchApi
from workbench import readers
def _demo_out_dirs() -> dict[str, bool]:
root = Path("demos")
return {
path.as_posix(): path.exists()
for path in sorted(root.glob("*/out"))
}
def test_list_demos_projects_closed_registry() -> None:
demos = readers.list_demos()
ids = {demo.demo_id for demo in demos}
assert "proof_carrying_promotion" in ids
assert "deductive_entailment_authority" in ids
assert all(demo.read_only is True for demo in demos)
assert all(demo.scenario_count == len(demo.scenarios) for demo in demos)
assert all(s.what_this_proves for demo in demos for s in demo.scenarios)
def test_run_demo_compares_against_committed_expected_artifacts() -> None:
result = readers.run_demo("deductive_entailment_authority")
assert result.demo_id == "deductive_entailment_authority"
assert result.all_passed is True
assert result.what_this_proves
assert any(s.proposer_wrong for s in result.scenarios)
assert all(s.response for s in result.scenarios)
def test_proof_carrying_promotion_projects_all_scenarios_as_dags() -> None:
result = readers.run_demo("proof_carrying_promotion")
assert len(result.scenarios) == 8
assert all(s.evidence_dag is not None for s in result.scenarios)
for scenario in result.scenarios:
assert scenario.evidence_dag is not None
assert scenario.evidence_dag.graph_kind == "proof_carrying_promotion"
assert scenario.evidence_dag.source_digest
node_ids = {node.node_id for node in scenario.evidence_dag.nodes}
assert {"request", "validate", "claim", "certify", "apply", "outcome"}.issubset(
node_ids
)
assert all(
edge.from_node in node_ids and edge.to_node in node_ids
for edge in scenario.evidence_dag.edges
)
def test_deductive_entailment_projects_trace_as_dag_when_engine_ran() -> None:
result = readers.run_demo("deductive_entailment_authority")
traced = [
s
for s in result.scenarios
if isinstance(s.response, dict) and s.response.get("entailment_trace")
]
assert traced
assert all(s.evidence_dag is not None for s in traced)
for scenario in traced:
assert scenario.evidence_dag is not None
assert scenario.evidence_dag.graph_kind == "deductive_entailment"
node_ids = {node.node_id for node in scenario.evidence_dag.nodes}
assert {
"conjunction",
"query",
"engine_check",
"oracle_check",
"decision",
}.issubset(node_ids)
assert all(
edge.from_node in node_ids and edge.to_node in node_ids
for edge in scenario.evidence_dag.edges
)
def test_demo_api_refuses_unknown_or_unsafe_ids() -> None:
api = WorkbenchApi()
unknown = api.handle("POST", "/demos/not_registered/run", b"")
unsafe = api.handle("POST", "/demos/../proof_carrying_promotion/run", b"")
assert unknown.status == 404
assert unknown.payload["error"]["code"] == "not_found"
assert unsafe.status == 400
assert unsafe.payload["error"]["code"] == "bad_request"
def test_demo_run_endpoint_does_not_write_demo_out_dirs() -> None:
before = _demo_out_dirs()
api = WorkbenchApi()
response = api.handle("POST", "/demos/proof_carrying_promotion/run", b"")
assert response.status == 200
assert response.payload["data"]["all_passed"] is True
assert _demo_out_dirs() == before