STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_cea_build_gate.py
Go to the documentation of this file.
1"""A missing/stale CEA cache must FAIL FAST where in-process builds are disabled.
2
3Root cause of a production crash: switching to a propellant whose cache was not
4committed (kerolox) made a request handler start a cold CEA build -- ~n_points^3
5rocketcea calls whose growing in-process cache took the host to >12 GB. Builds
6are an offline job (regenerate-cea-cache.yml); the deployed server disables them
7by setting ED_ALLOW_CEA_BUILD=0 (docker-compose.yml) and must instead raise
8immediately on a missing cache.
9
10The gate is environment-based (env var), not code-path based, because local dev
11runs the same backend over localhost and must keep building on demand. These
12tests pin both directions.
13"""
14
15import os
16import unittest
17from pathlib import Path
18
19from engine.pipeline.io import load_config
20from engine.pipeline.config_switch import switch_config
21from engine.pipeline.config_schemas import PintleEngineConfig
22from engine.pipeline import cea_cache
23from engine.pipeline.cea_cache import CEACache
24
25ROOT = Path(__file__).resolve().parents[1]
26BOGUS_CACHE = "/tmp/__ed_gate_test_should_never_be_written.npz"
27
28
29class TestCeaBuildGate(unittest.TestCase):
30 def setUp(self):
31 # A kerolox CEA identity pointed at a cache path that does not exist, so
32 # any construction would otherwise fall through to a cold build.
33 base = load_config(str(ROOT / "configs" / "default.yaml")).model_dump(mode="json")
34 kero = switch_config(base, propellant_preset="kerolox")
35 kero["combustion"]["cea"]["cache_file"] = BOGUS_CACHE
36 self.cea_cfg = PintleEngineConfig(**kero).combustion.cea
37 self._saved_env = os.environ.get("ED_ALLOW_CEA_BUILD")
38 Path(BOGUS_CACHE).unlink(missing_ok=True)
39
40 def tearDown(self):
41 if self._saved_env is None:
42 os.environ.pop("ED_ALLOW_CEA_BUILD", None)
43 else:
44 os.environ["ED_ALLOW_CEA_BUILD"] = self._saved_env
45 Path(BOGUS_CACHE).unlink(missing_ok=True)
46
48 # Default (unset) allows building; the server's "0" disallows it; an
49 # explicit "1" re-enables (the escape hatch).
50 os.environ.pop("ED_ALLOW_CEA_BUILD", None)
51 self.assertTrue(cea_cache._cea_build_allowed())
52 os.environ["ED_ALLOW_CEA_BUILD"] = "0"
53 self.assertFalse(cea_cache._cea_build_allowed())
54 os.environ["ED_ALLOW_CEA_BUILD"] = "1"
55 self.assertTrue(cea_cache._cea_build_allowed())
56
58 # Production posture: builds off. A missing cache must raise immediately
59 # (not spend hours building and blow up memory), and write nothing.
60 os.environ["ED_ALLOW_CEA_BUILD"] = "0"
61 with self.assertRaises(RuntimeError) as ctx:
62 CEACache(self.cea_cfg)
63 msg = str(ctx.exception)
64 self.assertIn("RP-1", msg)
65 self.assertIn("ED_ALLOW_CEA_BUILD", msg)
66 self.assertFalse(
67 Path(BOGUS_CACHE).exists(),
68 "a disabled build must not write a cache file",
69 )
70
71
72if __name__ == "__main__":
73 unittest.main()
void setUp(void)
Definition test_main.cpp:17
void tearDown(void)
Definition test_main.cpp:20