1"""A recreated backend session is recognisable, so the design bar never autosaves its default.
32026-10-01: a backend restart left the session holding configs/default.yaml (methalox); the design
4bar's autosave read it as an edit and saved it over an ethalox design. The bar now compares the
5session epoch it loaded the design into with the one the backend reports, and restores the design
6when they differ. This guards the backend half: every session object has its own epoch, and the
7config routes the bar reads report it.
12sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
14from fastapi
import FastAPI
15from fastapi.testclient
import TestClient
22 assert a.epoch
and b.epoch
and a.epoch != b.epoch
30 app.include_router(config_router.router)
31 app.dependency_overrides[get_session] =
lambda: session
32 client = TestClient(app)
33 got = client.get(
"/api/config").
json()
34 assert got[
"session_epoch"] == session.epoch
35 loaded = client.post(
"/api/config/load", json=got[
"config"]).
json()
36 assert loaded[
"session_epoch"] == session.epoch
40 """The session is one per user and every tab shares it. Tab B opening design X POSTs X over
41 the design Y tab A holds; A's autosave then read X as an edit and saved it into Y. Every
42 wholesale load now gets a fresh token, and a fresh session has none (only the default is in
43 it), so A can refuse to autosave a config it did not load, and a read-only tab can tell a
44 default it may replace from another tab's design it must not."""
49 app.include_router(config_router.router)
50 app.dependency_overrides[get_session] =
lambda: session
51 client = TestClient(app)
52 got = client.get(
"/api/config").
json()
53 assert got[
"load_token"]
is None
54 first = client.post(
"/api/config/load", json=got[
"config"]).
json()[
"load_token"]
55 assert first
and client.get(
"/api/config").
json()[
"load_token"] == first
56 second = client.post(
"/api/config/load", json=got[
"config"]).
json()[
"load_token"]
57 assert second
and second != first
59 client.put(
"/api/config", json={})
60 assert client.get(
"/api/config").
json()[
"load_token"] == second
a class to store JSON values
test_the_config_routes_report_the_epoch()
test_a_wholesale_load_is_stamped_so_another_tab_can_tell_it_is_not_its_own()
test_every_session_has_its_own_epoch()