mirror of
https://github.com/zvx-echo6/meshai.git
synced 2026-08-26 17:31:34 +00:00
refactor: move source tree into work/, multi-stage Docker build, fix satpass
- Move all application source (meshai/, dashboard-frontend/, tests/, config/, docs/, Dockerfile, etc.) into work/ directory - Add Node.js multi-stage build to Dockerfile for frontend compilation; remove compiled static assets from git tracking - Fix satpass missing time windows: consolidation was splitting wire on newline and only putting line 1 in event.title, dropping the time window line that the composer uses for precomposed broadcasts - Fix satpass burst flooding: stagger consolidation timers (+60s per pending pass) so Central batch publishes don't blast the mesh - Update CI workflow build context to work/ - Anchor lib/ and data/ gitignore patterns to repo root to prevent false matches on nested directories - Add dashboard-frontend/node_modules/ to .dockerignore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7128b432ee
commit
2e1fb325f7
283 changed files with 109402 additions and 483 deletions
148
work/tests/test_bool_roundtrip.py
Normal file
148
work/tests/test_bool_roundtrip.py
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
"""Boolean round-trip tests for adapter_config enabled toggle.
|
||||
|
||||
Proves:
|
||||
1. PUT satpass.enabled=true -> value_json='true' in DB -> accessor reads Python True
|
||||
2. PUT satpass.enabled=false -> value_json='false' in DB -> accessor reads Python False
|
||||
3. Same round-trip on a second adapter (wfigs.broadcast_on_acres) -> not satpass-special
|
||||
4. PUT rejects non-bool values (string 'true', int 1)
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from meshai.adapter_config import adapter_config, invalidate_cache
|
||||
from meshai.dashboard.api.adapter_config_routes import router
|
||||
from meshai.persistence import get_db
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
app = FastAPI()
|
||||
app.include_router(router, prefix="/api")
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
# -- satpass.enabled boolean round-trip --
|
||||
|
||||
def test_satpass_enabled_true_roundtrip(client):
|
||||
"""PUT enabled=true -> DB value_json='true' -> accessor returns Python True."""
|
||||
# Default is false
|
||||
assert adapter_config.satpass.enabled is False
|
||||
|
||||
# PUT true
|
||||
r = client.put(
|
||||
"/api/adapter-config/satpass/enabled",
|
||||
json={"value": True},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json()["value"] is True
|
||||
|
||||
# DB has value_json='true' (the JSON literal, not Python repr)
|
||||
conn = get_db()
|
||||
row = conn.execute(
|
||||
"SELECT value_json FROM adapter_config WHERE adapter='satpass' AND key='enabled'"
|
||||
).fetchone()
|
||||
assert row is not None
|
||||
assert row["value_json"] == "true", (
|
||||
f"expected value_json='true', got {row['value_json']!r}"
|
||||
)
|
||||
|
||||
# Accessor reads Python True (not string, not int)
|
||||
val = adapter_config.satpass.enabled
|
||||
assert val is True
|
||||
assert type(val) is bool
|
||||
|
||||
|
||||
def test_satpass_enabled_false_roundtrip(client):
|
||||
"""PUT enabled=false after enabling -> DB value_json='false' -> accessor False."""
|
||||
# Enable first
|
||||
client.put("/api/adapter-config/satpass/enabled", json={"value": True})
|
||||
assert adapter_config.satpass.enabled is True
|
||||
|
||||
# Disable
|
||||
r = client.put(
|
||||
"/api/adapter-config/satpass/enabled",
|
||||
json={"value": False},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json()["value"] is False
|
||||
|
||||
# DB
|
||||
conn = get_db()
|
||||
row = conn.execute(
|
||||
"SELECT value_json FROM adapter_config WHERE adapter='satpass' AND key='enabled'"
|
||||
).fetchone()
|
||||
assert row["value_json"] == "false"
|
||||
|
||||
# Accessor
|
||||
assert adapter_config.satpass.enabled is False
|
||||
|
||||
|
||||
def test_satpass_enabled_rejects_string_true(client):
|
||||
"""String 'true' must be rejected -- only Python bool accepted."""
|
||||
r = client.put(
|
||||
"/api/adapter-config/satpass/enabled",
|
||||
json={"value": "true"},
|
||||
)
|
||||
assert r.status_code == 400
|
||||
|
||||
|
||||
def test_satpass_enabled_rejects_int_one(client):
|
||||
"""Integer 1 must be rejected -- only Python bool accepted."""
|
||||
r = client.put(
|
||||
"/api/adapter-config/satpass/enabled",
|
||||
json={"value": 1},
|
||||
)
|
||||
assert r.status_code == 400
|
||||
|
||||
|
||||
# -- Second adapter boolean round-trip (not satpass-special) --
|
||||
|
||||
def test_wfigs_broadcast_on_acres_bool_roundtrip(client):
|
||||
"""Same round-trip on wfigs.broadcast_on_acres proves bool handling is generic."""
|
||||
# Read default
|
||||
default_val = adapter_config.wfigs.broadcast_on_acres
|
||||
|
||||
# Flip it
|
||||
new_val = not default_val
|
||||
r = client.put(
|
||||
"/api/adapter-config/wfigs/broadcast_on_acres",
|
||||
json={"value": new_val},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json()["value"] is new_val
|
||||
|
||||
# DB has correct JSON literal
|
||||
conn = get_db()
|
||||
row = conn.execute(
|
||||
"SELECT value_json FROM adapter_config WHERE adapter='wfigs' AND key='broadcast_on_acres'"
|
||||
).fetchone()
|
||||
assert row["value_json"] == json.dumps(new_val)
|
||||
|
||||
# Accessor
|
||||
val = adapter_config.wfigs.broadcast_on_acres
|
||||
assert val is new_val
|
||||
assert type(val) is bool
|
||||
|
||||
|
||||
def test_fires_digest_enabled_bool_roundtrip(client):
|
||||
"""Third adapter (fires.digest_enabled) -- additional proof of generic handling."""
|
||||
# Read default
|
||||
default_val = adapter_config.fires.digest_enabled
|
||||
|
||||
# Flip
|
||||
new_val = not default_val
|
||||
r = client.put(
|
||||
"/api/adapter-config/fires/digest_enabled",
|
||||
json={"value": new_val},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json()["value"] is new_val
|
||||
|
||||
# Accessor returns the correct bool
|
||||
assert adapter_config.fires.digest_enabled is new_val
|
||||
assert type(adapter_config.fires.digest_enabled) is bool
|
||||
Loading…
Add table
Add a link
Reference in a new issue