STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_config_write_precondition.py
Go to the documentation of this file.
1"""A write computed for one design is refused when another is live (PUT /api/config?expect_sha256=).
2
3Layer X's fitted K0 and reconciled holes are fitted to the design a burn ran on. The UI's guard
4read a preflight that is stale for seconds after a design load; the server is the guard now.
5"""
6import os
7import sys
8
9sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
11from fastapi import FastAPI # noqa: E402
12from fastapi.testclient import TestClient # noqa: E402
13
14from backend.checkout import require_design_checkout # noqa: E402
15from backend.session import UserSession, get_session # noqa: E402
16
17
18def _client(session):
19 from backend.routers import config as config_router
20
21 app = FastAPI()
22 app.include_router(config_router.router)
23 app.dependency_overrides[get_session] = lambda: session
24 app.dependency_overrides[require_design_checkout] = lambda: None
25 return TestClient(app)
26
27
29 from engine.layerx.fingerprint import config_fingerprint
30
31 session = UserSession("precondition")
32 client = _client(session)
33 client.get("/api/config")
34 live = config_fingerprint(session.app_state.config)
35 stale = "0" * 64
36 refused = client.put(f"/api/config?expect_sha256={stale}", json={"thrust": {"burn_time": 3.0}})
37 assert refused.status_code == 409
38 assert config_fingerprint(session.app_state.config) == live # nothing was written
39 landed = client.put(f"/api/config?expect_sha256={live}", json={"rocket": {"fin_thickness_m": 0.004}})
40 assert landed.status_code == 200
41 assert client.put("/api/config", json={"rocket": {"fin_thickness_m": 0.005}}).status_code == 200 # no precondition: as before