mirror of
https://github.com/Hmbown/DeepSeek-TUI.git
synced 2026-09-02 22:36:19 +08:00
Test bankruptcy is a scheduling problem, not a rotten suite. With one concurrency group per branch, GitHub cancelled pending main runs when the next merge queued — 31 of the last 40 main CI runs never finished. Key non-PR runs by SHA so each commit actually gets a result. PRs still cancel superseded heads. Add a 15-minute Safety gate job for command_safety / auto_review / authority / sandbox / execpolicy. The 71-minute macOS Test job stays until a summary job exists for protect-main; nothing was deleted. Also align the persistence-backlog argv contract with the --all-features flag that stopped that check from rebuilding the workspace.
120 lines
3.8 KiB
Python
120 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Hermetic tests for scripts/measure-persistence-backlog.py."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import io
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from contextlib import redirect_stdout
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SCRIPT = ROOT / "scripts" / "measure-persistence-backlog.py"
|
|
|
|
SPEC = importlib.util.spec_from_file_location("measure_persistence_backlog", SCRIPT)
|
|
assert SPEC and SPEC.loader
|
|
mod = importlib.util.module_from_spec(SPEC)
|
|
sys.modules[SPEC.name] = mod
|
|
SPEC.loader.exec_module(mod)
|
|
|
|
|
|
class PersistenceBacklogMeasurementTests(unittest.TestCase):
|
|
def test_runner_targets_exact_library_test(self) -> None:
|
|
completed = subprocess.CompletedProcess(
|
|
args=[],
|
|
returncode=0,
|
|
stdout=(
|
|
"running 1 test\n"
|
|
f"test {mod.TEST_NAME} ... ok\n\n"
|
|
"test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; "
|
|
"0 filtered out\n"
|
|
),
|
|
stderr="",
|
|
)
|
|
receipt = {"document_kind": "fixture"}
|
|
|
|
with tempfile.TemporaryDirectory() as root:
|
|
receipt_path = Path(root) / "receipt.json"
|
|
receipt_path.write_text(json.dumps(receipt), encoding="utf-8")
|
|
with mock.patch.object(
|
|
mod.subprocess, "run", return_value=completed
|
|
) as run:
|
|
measured = mod.run_measurement(receipt_path, {"FIXTURE": "1"})
|
|
|
|
self.assertEqual(measured, receipt)
|
|
self.assertEqual(
|
|
run.call_args.args[0],
|
|
[
|
|
"cargo",
|
|
"test",
|
|
"--locked",
|
|
"--all-features",
|
|
"-p",
|
|
"codewhale-tui",
|
|
"--lib",
|
|
mod.TEST_NAME,
|
|
"--",
|
|
"--exact",
|
|
"--ignored",
|
|
"--test-threads=1",
|
|
],
|
|
)
|
|
self.assertEqual(run.call_args.kwargs["cwd"], mod.ROOT)
|
|
|
|
def test_successful_zero_test_run_is_rejected(self) -> None:
|
|
completed = subprocess.CompletedProcess(
|
|
args=[],
|
|
returncode=0,
|
|
stdout=(
|
|
"running 0 tests\n\n"
|
|
"test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; "
|
|
"1 filtered out\n"
|
|
),
|
|
stderr="",
|
|
)
|
|
|
|
with tempfile.TemporaryDirectory() as root:
|
|
receipt_path = Path(root) / "receipt.json"
|
|
receipt_path.write_text("{}", encoding="utf-8")
|
|
with (
|
|
mock.patch.object(mod.subprocess, "run", return_value=completed),
|
|
redirect_stdout(io.StringIO()),
|
|
self.assertRaisesRegex(
|
|
mod.PersistenceBacklogMeasurementError, "ran zero tests"
|
|
),
|
|
):
|
|
mod.run_measurement(receipt_path, {})
|
|
|
|
def test_successful_test_without_receipt_is_rejected(self) -> None:
|
|
completed = subprocess.CompletedProcess(
|
|
args=[],
|
|
returncode=0,
|
|
stdout=(
|
|
"running 1 test\n"
|
|
f"test {mod.TEST_NAME} ... ok\n\n"
|
|
"test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; "
|
|
"0 filtered out\n"
|
|
),
|
|
stderr="",
|
|
)
|
|
|
|
with tempfile.TemporaryDirectory() as root:
|
|
with (
|
|
mock.patch.object(mod.subprocess, "run", return_value=completed),
|
|
self.assertRaisesRegex(
|
|
mod.PersistenceBacklogMeasurementError,
|
|
"emitted no valid receipt",
|
|
),
|
|
):
|
|
mod.run_measurement(Path(root) / "missing.json", {})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(unittest.main())
|