Files
pipelines/app/tool/test_check_full.py
T

81 lines
3.4 KiB
Python

"""Exercise the landing gate's orchestration without launching Flutter tests."""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
class CheckFullTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory(prefix="check-full-")
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.app = self.root / "app"
self.tool = self.app / "tool"
(self.tool / "memwatch").mkdir(parents=True)
shutil.copyfile(Path(__file__).with_name("check_full.sh"),
self.tool / "check_full.sh")
self.wrapper("analyze.sh", "analyze", "ANALYZE")
self.wrapper("memwatch/full.sh", "memwatch", "TEST")
def wrapper(self, path, name, prefix):
script = self.tool / path
script.write_text(
"#!/bin/sh\n"
f'printf "%s\\n" "{name}:$*:$PWD" >> "$CALL_LOG"\n'
f'printf "%s\\n" "${{{prefix}_OUTPUT:-bounded summary}}"\n'
f'exit "${{{prefix}_STATUS:-0}}"\n')
script.chmod(0o755)
def run_gate(self, **overrides):
env = dict(os.environ, CALL_LOG=str(self.root / "calls"), **overrides)
result = subprocess.run(["sh", str(self.tool / "check_full.sh")],
cwd=self.root, env=env, capture_output=True,
text=True)
calls = self.root / "calls"
return result, calls.read_text().splitlines() if calls.exists() else []
def test_success_uses_both_wrappers_from_app_and_keeps_summaries(self):
result, calls = self.run_gate()
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(calls, [f"analyze::{self.app}",
f"memwatch:test:{self.app}"])
self.assertIn("CHECK PASSED", result.stdout)
for name in ("analyze", "test"):
self.assertEqual((self.app / f"build/check/{name}.log").read_text(),
"bounded summary\n")
def test_analysis_failure_cannot_be_hidden_by_success_text(self):
result, calls = self.run_gate(ANALYZE_STATUS="14",
ANALYZE_OUTPUT="No issues found")
self.assertEqual(result.returncode, 14)
self.assertEqual(len(calls), 1)
self.assertNotIn("CHECK PASSED", result.stdout)
self.assertFalse((self.app / "build/check/test.log").exists())
def test_test_failure_cannot_be_hidden_by_success_text(self):
result, calls = self.run_gate(TEST_STATUS="7",
TEST_OUTPUT="All tests passed!")
self.assertEqual(result.returncode, 7)
self.assertEqual(len(calls), 2)
self.assertIn("CHECK FAILED: test exited 7", result.stdout)
self.assertNotIn("CHECK PASSED", result.stdout)
def test_watchdog_kill_status_is_preserved(self):
result, _ = self.run_gate(TEST_STATUS="137", TEST_OUTPUT="KILLED")
self.assertEqual(result.returncode, 137)
self.assertNotIn("CHECK PASSED", result.stdout)
def test_missing_wrapper_fails_instead_of_claiming_success(self):
(self.tool / "memwatch/full.sh").unlink()
result, calls = self.run_gate()
self.assertNotEqual(result.returncode, 0)
self.assertEqual(len(calls), 1)
self.assertNotIn("CHECK PASSED", result.stdout)
if __name__ == "__main__":
unittest.main()