mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
Of the 76 open code scanning alerts, 39 point at code that can change. svc-ai-mcp-adapter: - A path argument that is empty or made only of dots is refused. Percent-encoding keeps a separator inside its segment, but "." and ".." need none, so an upstream that resolves dot segments could answer from a path the contract does not name. - parse_duration splits on the units. The pattern it used before rescanned a long run of digits from every start position. Tests and the README generators: - Every Jinja environment built with autoescape=False and a "noqa: S701" uses select_autoescape now, as six test modules and utils/templating/jinja.py already did. It escapes templates named *.html, *.htm and *.xml, which none of these call sites loads. - Dead code goes: a doubled "rel" block in the email lint, an unread _SKIP_DIRS, and a module that _resolve returned to no caller. - Two "except ...: pass" blocks become contextlib.suppress and assertRaises. - Nine test modules import unittest.mock one way instead of two, and one lookup test imports its module once. Closes #807 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from jinja2 import Environment, select_autoescape
|
|
|
|
from utils.cache.yaml import load_yaml_any
|
|
|
|
from . import PROJECT_ROOT
|
|
|
|
TASKS = PROJECT_ROOT / "roles/test-e2e-playwright/tasks/02_run_one.yml"
|
|
TASK_NAME = "⏳ Wait until application is ready (any non-error response)"
|
|
|
|
|
|
def until_expression() -> str:
|
|
tasks = load_yaml_any(str(TASKS))
|
|
for task in tasks:
|
|
if task.get("name") == TASK_NAME:
|
|
return task["until"]
|
|
raise AssertionError(f"task {TASK_NAME!r} not found in {TASKS}")
|
|
|
|
|
|
def settles(result: dict) -> bool:
|
|
template = Environment(
|
|
autoescape=select_autoescape(default_for_string=False)
|
|
).from_string("{{ " + until_expression() + " }}")
|
|
return template.render(_wait_result=result) == "True"
|
|
|
|
|
|
class TestReadinessUntil(unittest.TestCase):
|
|
def test_a_connection_error_keeps_the_gate_waiting(self):
|
|
self.assertFalse(settles({"status": -1}))
|
|
|
|
def test_a_missing_status_keeps_the_gate_waiting(self):
|
|
self.assertFalse(settles({}))
|
|
|
|
def test_a_served_response_settles_the_gate(self):
|
|
self.assertTrue(settles({"status": 200}))
|
|
|
|
def test_a_redirect_settles_the_gate(self):
|
|
self.assertTrue(settles({"status": 302}))
|
|
|
|
def test_a_server_error_keeps_the_gate_waiting(self):
|
|
self.assertFalse(settles({"status": 502}))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|