STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_switch_warnings.py
Go to the documentation of this file.
1"""POST /api/config/switch says "needs re-optimization" only when the chamber is a seed.
2
3The selector shows ``design_warning`` as "needs re-optimization" (ConfigurationSelector.tsx; the
4SwitchResponse contract: null after a clean injector swap, canonical configs being coherent).
53c04b16b folded the fluid-preset drift into design_staleness, so a clean swap to pintle -- whose
6canonical config carries the old LOX block -- read "needs re-optimization" for a chamber that is
7the right one. The drift now comes back on its own, as ``fluid_warning``.
8"""
9
10from __future__ import annotations
11
12import asyncio
13from pathlib import Path
14
15from starlette.requests import Request
16
17from backend.routers import config as config_router
18from backend.session import get_session
19from engine.pipeline.io import load_config
20
21REPO = Path(__file__).resolve().parents[1]
22
23
24def _switch(email: str, start: str, **body) -> dict:
25 request = Request({"type": "http", "method": "POST", "path": "/", "query_string": b"",
26 "headers": [(b"x-auth-email", email.encode())]})
27
28 async def main():
29 session = get_session(request)
30 session.app_state.set_config(load_config(str(REPO / "configs" / start)))
31 return await config_router.switch_config_endpoint(body, session=session)
32
33 return asyncio.run(main())
34
35
37 # ethalox_doublet_7000N carries the preset's LOX; canonical/pintle.yaml the old block
38 out = _switch("switch-warn-inj@berkeley.edu", "ethalox_doublet_7000N.yaml", injector_type="pintle")
39 assert out["config"]["injector"]["type"] == "pintle"
40 assert out["design_warning"] is None, out["design_warning"]
41 assert "ethalox preset" in (out["fluid_warning"] or ""), out["fluid_warning"]
42 assert "specific_heat 2300 (preset 1700)" in out["fluid_warning"]
43
44
46 out = _switch("switch-warn-prop@berkeley.edu", "default.yaml", propellant_preset="ethalox")
47 assert "methalox -> ethalox" in (out["design_warning"] or "")
48 assert "Fluid properties" not in out["design_warning"]
49 assert out["fluid_warning"] is None, out["fluid_warning"]
dict _switch(str email, str start, **body)
test_a_clean_injector_swap_is_not_a_seed_but_its_stale_fluids_are_said()
int main()