Files
PraisonAIUI/tests/test_feature_config_runtime.py
a433c483c1 fix: document bootstrap entrypoints in examples (fixes #71) (#96)
* feat: standardize bootstrap entrypoint to 'aiui run app.py' across examples

Standardizes platform bootstrap patterns across examples per issue #71:

- Update examples README table to use 'aiui run app.py' consistently
- Update docstrings in examples 10, 12, 19-21 to show 'aiui run' instead of 'python app.py'
- Remove fragmented bootstrap approaches (uvicorn.run, asyncio patterns)
- Enforce single bootstrap SSOT as designed in CLI

Co-authored-by: Mervin Praison <[email protected]>

* feat: consolidate bootstrap entrypoints - auto-detect gateway apps (fixes #71)

- Add bootstrap detection in CLI run command
- Auto-detect gateway pattern (async main + AIUIGateway imports)
- Auto-switch to praisonai backend for gateway apps
- Delegate to user-defined main() when present
- Remove sys.path hacks from example 14
- Update examples README to show unified aiui run entrypoint
- Add BOOTSTRAP.md documentation for migration patterns

Co-authored-by: Mervin Praison <[email protected]>

* fix: resolve critical bootstrap entrypoint issues

- Fix AST parsing bug in gateway auto-detection (cli.py:1419)
- Revert background bots (email-bot, agentmail-bot) to python app.py
- Revert custom UI apps (agent-dashboard) to python app.py
- Update README.md to reflect correct run commands
- Fix import formatting and remove unused imports

These changes ensure that:
1. Gateway auto-detection works correctly by properly checking ast.alias.name
2. Background bots execute their __main__ blocks and don't start unnecessary web servers
3. Custom UI apps register their custom routes in __main__ blocks
4. Documentation matches actual working run commands

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Mervin Praison <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mervin Praison <[email protected]>
Co-authored-by: Mervin Praison <[email protected]>
Co-authored-by: Cursor <[email protected]>
2026-06-15 16:36:35 +01:00

123 lines
3.9 KiB
Python

"""Per-feature test: Config Runtime — API + CLI parity."""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from starlette.testclient import TestClient
from praisonaiui.server import create_app
client = TestClient(create_app())
passed = failed = 0
errors = []
def check(name, r, status=200, keys=None):
global passed, failed
try:
assert r.status_code == status, f"Expected {status}, got {r.status_code}: {r.text[:200]}"
if keys:
data = r.json()
for k in keys:
assert k in data, f"Missing '{k}' in {list(data.keys())}"
passed += 1
print(f" ✓ {name}")
except AssertionError as e:
failed += 1; errors.append(f" ✗ {name}: {e}"); print(f" ✗ {name}: {e}")
print("\n── Config Runtime: API Tests ──")
# Empty
r = client.get("/api/config/runtime")
check("GET runtime (empty)", r, 200, ["config"])
assert r.json()["config"] == {}
# History empty
r = client.get("/api/config/runtime/history")
check("GET history (empty)", r, 200, ["history", "count"])
assert r.json()["count"] == 0
# PATCH — set multiple keys
r = client.request("PATCH", "/api/config/runtime", json={"model": "gpt-4o", "temperature": "0.7", "max_tokens": "4096"})
check("PATCH set 3 keys", r, 200, ["config", "applied"])
assert r.json()["applied"] == 3
assert r.json()["config"]["model"] == "gpt-4o"
# GET single key
r = client.get("/api/config/runtime/model")
check("GET /model", r, 200, ["key", "value"])
assert r.json()["value"] == "gpt-4o"
r = client.get("/api/config/runtime/temperature")
check("GET /temperature", r, 200)
assert r.json()["value"] == "0.7"
# GET nonexistent
check("GET nonexistent → 404", client.get("/api/config/runtime/nonexistent"), 404)
# PUT single key
r = client.put("/api/config/runtime/temperature", json={"value": "0.9"})
check("PUT /temperature", r, 200, ["key", "value"])
assert r.json()["value"] == "0.9"
# Verify update
r = client.get("/api/config/runtime/temperature")
assert r.json()["value"] == "0.9"
# PATCH — update existing + add new
r = client.request("PATCH", "/api/config/runtime", json={"model": "gpt-4o-mini", "top_p": "0.95"})
check("PATCH update + add", r, 200)
assert r.json()["config"]["model"] == "gpt-4o-mini"
assert r.json()["config"]["top_p"] == "0.95"
# History should have entries
r = client.get("/api/config/runtime/history")
check("GET history (has entries)", r, 200)
assert r.json()["count"] >= 4
# History with limit
r = client.get("/api/config/runtime/history?limit=2")
check("GET history (limit=2)", r, 200)
assert len(r.json()["history"]) == 2
# DELETE key
check("DELETE /model", client.delete("/api/config/runtime/model"), 200, ["deleted"])
check("GET deleted → 404", client.get("/api/config/runtime/model"), 404)
# DELETE nonexistent
check("DELETE nonexistent → 404", client.delete("/api/config/runtime/nonexistent"), 404)
# PUT replace all
r = client.put("/api/config/runtime", json={"single_key": "test_value"})
check("PUT replace all", r, 200, ["config"])
assert r.json()["config"] == {"single_key": "test_value"}
# Verify only one key
r = client.get("/api/config/runtime")
assert len(r.json()["config"]) == 1
# Full GET
r = client.get("/api/config/runtime")
check("GET all config", r, 200, ["config"])
print("\n── Config Runtime: CLI Parity ──")
from typer.testing import CliRunner
from praisonaiui.cli import app as cli_app
runner = CliRunner()
result = runner.invoke(cli_app, ["config", "--help"])
check("CLI config --help", type("R", (), {"status_code": 200 if result.exit_code == 0 else 500, "json": lambda: {}, "text": result.output})(), 200)
assert "get" in result.output
assert "set" in result.output
assert "list" in result.output
assert "history" in result.output
print(f"\n{'='*50}")
print(f" Config Runtime: {passed} passed, {failed} failed")
print(f"{'='*50}")
if errors:
for e in errors: print(e)
sys.exit(1)