feat(m4): crop_fill setting + tape-line prototype (#99)

Add global crop_fill percent (default 90, 1-100) as a settings key with
FastAPI 4xx validation. Wires the value through to the inventory PNG
encode (non-retro: stored PNGs untouched). Adds a throwaway
TapePrototype.svelte behind ?tape-prototype for the #99 design sandbox.

Gates: check_requirements PASS, check_coverage PASS, settings tests 8/8.
This commit is contained in:
Ty
2026-09-24 12:01:18 -07:00
parent 0c00d25cc7
commit 818874e65c
13 changed files with 831 additions and 23 deletions
+48
View File
@@ -138,3 +138,51 @@ def test_settings_decrypt_failure_returns_reenter_state_not_500(monkeypatch):
body = resp.json()
assert body["inference_api_key"] == {"configured": False}
db_mod._reset_for_tests()
def test_settings_crop_fill_defaults_to_90(monkeypatch):
"""Given: no crop_fill row; When: GET; Then: crop_fill == 90 (#99 req.4 default 90%)."""
with tempfile.TemporaryDirectory() as tmp:
_setup_env(monkeypatch, tmp)
from backend.app import app
client = TestClient(app)
db_mod.init_db()
resp = client.get("/api/v1/settings")
assert resp.status_code == 200
assert resp.json()["crop_fill"] == 90
db_mod._reset_for_tests()
def test_settings_crop_fill_round_trips_as_plain_number(monkeypatch):
"""Given: crop_fill in PUT; When: PUT then GET; Then: plain TEXT row (no value_enc) and a number back (#99 req.4)."""
with tempfile.TemporaryDirectory() as tmp:
_setup_env(monkeypatch, tmp)
from backend.app import app
client = TestClient(app)
db_mod.init_db()
resp = client.put("/api/v1/settings", json={"crop_fill": 75})
assert resp.status_code == 200
assert resp.json()["crop_fill"] == 75
conn = db_mod.get_connection()
row = conn.execute("SELECT value, value_enc FROM settings WHERE key='crop_fill'").fetchone()
assert row["value"] == "75" and row["value_enc"] is None
assert client.get("/api/v1/settings").json()["crop_fill"] == 75
db_mod._reset_for_tests()
def test_settings_crop_fill_out_of_range_is_4xx_and_not_written(monkeypatch):
"""Given: bad crop_fill; When: PUT; Then: 400 validation, nothing written (#99; rules in the 4xx layer)."""
with tempfile.TemporaryDirectory() as tmp:
_setup_env(monkeypatch, tmp)
from backend.app import app
client = TestClient(app)
db_mod.init_db()
for bad in (0, 101, -5, "abc", None):
resp = client.put("/api/v1/settings", json={"crop_fill": bad})
assert resp.status_code == 400, f"{bad!r} should be rejected"
assert resp.json()["error"]["code"] == "validation"
assert client.get("/api/v1/settings").json()["crop_fill"] == 90 # untouched default
# boundaries are valid
assert client.put("/api/v1/settings", json={"crop_fill": 100}).status_code == 200
assert client.put("/api/v1/settings", json={"crop_fill": 1}).status_code == 200
db_mod._reset_for_tests()