File size: 2,966 Bytes
2559788
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from __future__ import annotations

import json
import os
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def _run(script: str, *args: str) -> subprocess.CompletedProcess[str]:
    environment = os.environ | {"PYTHONPATH": str(ROOT / "src")}
    return subprocess.run(
        [sys.executable, str(ROOT / "scripts" / script), *args],
        cwd=ROOT,
        env=environment,
        capture_output=True,
        text=True,
        check=False,
    )


def test_calibration_dry_run_has_no_realized_measurement(tmp_path: Path) -> None:
    """Catches a calibration scaffold that pretends an intended delta was measured."""
    result = _run(
        "calibrate_correction_action.py",
        "--dry-run",
        "--action-family",
        "bust_circumference_delta_cm",
        "--intended-delta-cm",
        "3",
        "--output",
        str(tmp_path / "calibration.json"),
    )
    assert result.returncode == 0, result.stderr
    payload = json.loads((tmp_path / "calibration.json").read_text(encoding="utf-8"))
    assert payload["intended_delta_cm"] == 3.0
    assert payload["realized_delta_cm"] is None
    assert payload["status"] == "NOT_RUN"


def test_smoke_runner_dry_run_never_claims_simulation(tmp_path: Path) -> None:
    """Catches a dry-run that accidentally reports fabricated simulation output."""
    result = _run(
        "run_fit_correction_smoke.py",
        "--dry-run",
        "--case",
        "CHEST_CASE",
        "--output-dir",
        str(tmp_path),
    )
    assert result.returncode == 0, result.stderr
    payload = json.loads(result.stdout)
    assert payload["simulation_status"] == "NOT_RUN"
    assert payload["backend_status"] == "NOT_VERIFIED"
    assert payload["planned_action_count"] == 5
    assert payload["render_status"] == "NOT_RUN"
    assert payload["reproducibility"] == {"status": "NOT_RUN"}
    assert len(payload["hashes"]["smoke_plan_sha256"]) == 64


def test_smoke_runner_preserves_and_resumes_backend_failure(tmp_path: Path) -> None:
    """Catches overwrite or disappearance of a non-dry-run backend failure."""
    first = _run(
        "run_fit_correction_smoke.py",
        "--case",
        "SLEEVE_CASE",
        "--action",
        "sleeve_length_delta_cm:-1",
        "--output-dir",
        str(tmp_path),
    )
    assert first.returncode == 2
    failure = json.loads(first.stdout)
    assert failure["error_code"] == "SIMULATION_BACKEND_NOT_CONFIGURED"
    artifact = Path(failure["failure_artifact"])
    original = artifact.read_text(encoding="utf-8")

    resumed = _run(
        "run_fit_correction_smoke.py",
        "--resume",
        "--case",
        "SLEEVE_CASE",
        "--action",
        "sleeve_length_delta_cm:-1",
        "--output-dir",
        str(tmp_path),
    )
    assert resumed.returncode == 2
    assert json.loads(resumed.stdout)["resumed"] is True
    assert artifact.read_text(encoding="utf-8") == original