Files
ThothII/harness/tests/test_cli_phase_meta.py
marcopanandClaude Fable 5 e24b41b156 feat(opt): three efficiency levers for NL→SQL workflow
Lever 1: Join-graph via FK logics in annotations + suggest-fks command
  - TableAnnotation.foreign_keys field stores curated logical FKs (DWH has no FK constraints)
  - tht schema suggest-fks: mine from approved SQL, heuristics (time_key → dim_time),
    same-name discovery + explicit --assume flag for multi-owner PKs
  - mschema renders 【Foreign keys】 section populated; validation in merge.py
  - SKILL.md F4 now reads FKs from mschema-text, no custom data_time_key logic

Lever 2: Context-pack consolidation at kickoff (tht search pack)
  - Single embedding of question, reused for schema + evidence + solved searches
  - One command: tht search pack <question> --session <id> → retrieval_pack.md
  - Graceful degradation when Ollama/vector store unreachable (exit 0, empty sections)
  - SKILL.md F1 prescribes as first call; reduces model thinking turns via pre-retrieval

Lever 3: Phase-summary recap v2 auto-construction from session ledger
  - tht session show --json includes full decisions ledger
  - tht phase meta --json exports 'emits' (substantive decision types per phase)
  - Gate appends deterministic 【Decisioni registrate in questa fase】 section (appendLedgerSection)
  - Model authors only summary + checks; recap table comes from persisted state (exact by construction)
  - SKILL.md Disciplina 6: brief model output, gate fills the rest

Tests: 358 Python (including 10 FK + 3 pack + 1 session-ledger tests) + 111 JS gate tests, all pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 17:43:08 +02:00

41 lines
1.4 KiB
Python

"""L1: tht phase meta --json -- the gate reads workflow facts from here (F2).
Kills the JS/Python drift (no mirrored constants): workflow.yaml is the single source.
"""
import json
from typer.testing import CliRunner
from tht.cli import app
runner = CliRunner()
def test_phase_meta_json_returns_workflow_data():
result = runner.invoke(app, ["phase", "meta", "--json"])
assert result.exit_code == 0
data = json.loads(result.stdout)
assert data["max_phase"] == 8
assert len(data["phases"]) == 8
# F8 must be present — this is the exact JS-drift bug (PHASE_NAMES truncated to 7).
assert data["phases"][7]["name"] == "datamart"
assert data["phases"][7]["num"] == 8
assert "advance" in data["phases"][0]
assert "artifacts_out" in data["phases"][0]
def test_phase_meta_each_phase_carries_id_and_name():
result = runner.invoke(app, ["phase", "meta", "--json"])
data = json.loads(result.stdout)
for i, p in enumerate(data["phases"], start=1):
assert p["num"] == i
assert p["id"], f"phase {i} missing id"
assert p["name"], f"phase {i} missing name"
def test_phase_meta_exposes_emits():
# Il gate filtra il ledger per fase con `emits` (recap deterministico v2).
result = runner.invoke(app, ["phase", "meta", "--json"])
data = json.loads(result.stdout)
f1 = data["phases"][0]
assert f1["emits"] == ["concept_clarified", "ambiguity_open"]