Harden split background promotion preflight
This commit is contained in:
@@ -1,11 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def _bash_path(path: Path) -> str:
|
||||
raw_path = str(path)
|
||||
if os.name != "nt":
|
||||
return raw_path
|
||||
|
||||
result = subprocess.run(
|
||||
["bash", "-lc", f"wslpath -a {shlex.quote(raw_path)}"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
check=False,
|
||||
)
|
||||
if result.returncode == 0 and result.stdout.strip():
|
||||
return result.stdout.strip()
|
||||
return raw_path
|
||||
|
||||
|
||||
def test_split_background_promotion_workflow_runs_split_then_split_aware_report() -> None:
|
||||
script_path = ROOT / "scripts" / "run_split_background_promotion_workflow.sh"
|
||||
assert script_path.exists()
|
||||
@@ -35,6 +56,54 @@ def test_split_background_promotion_workflow_has_safe_preflight_mode() -> None:
|
||||
assert "Split-background promotion preflight passed" in source
|
||||
|
||||
|
||||
def test_split_background_preflight_derives_missing_background_categories(tmp_path: Path) -> None:
|
||||
positive_portfolio = tmp_path / "positive.json"
|
||||
positive_portfolio.write_text('{"items":[]}', encoding="utf-8")
|
||||
manifest = tmp_path / "operator_samples_manifest.json"
|
||||
manifest.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"samples": [
|
||||
{
|
||||
"sample_slug": "postel_bos",
|
||||
"sample_role": "background_candidate",
|
||||
"reference_feature_count": 0,
|
||||
},
|
||||
{
|
||||
"sample_slug": "kasterlee_bos",
|
||||
"sample_role": "background_candidate",
|
||||
"reference_feature_count": 7,
|
||||
},
|
||||
]
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
api_root = tmp_path / "api-root"
|
||||
projects_endpoint = api_root / "api" / "v1" / "projects"
|
||||
projects_endpoint.parent.mkdir(parents=True)
|
||||
projects_endpoint.write_text('{"data":{"items":[]}}', encoding="utf-8")
|
||||
|
||||
command = (
|
||||
f"PROMOTION_POSITIVE_PORTFOLIO_PATH={shlex.quote(_bash_path(positive_portfolio))} "
|
||||
f"OPERATOR_SAMPLE_MANIFEST_PATH={shlex.quote(_bash_path(manifest))} "
|
||||
f"bash scripts/run_split_background_promotion_workflow.sh --preflight-only "
|
||||
f"{shlex.quote(f'file://{_bash_path(api_root)}')}"
|
||||
)
|
||||
result = subprocess.run(
|
||||
["bash", "-lc", command],
|
||||
cwd=ROOT,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
check=False,
|
||||
)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "Split-background promotion preflight passed" in result.stdout
|
||||
|
||||
|
||||
def test_readiness_checks_split_background_promotion_workflow_syntax() -> None:
|
||||
readiness = (ROOT / "scripts" / "run_readiness_check.sh").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user