|
| 1 | +"""Tests for the /workflows route's concern + bucket_counts context. |
| 2 | +
|
| 3 | +A2 of docs/specs/ops-workflows-page-refinement/. The route serializer |
| 4 | +populates per-row concern (via workflow_concern.derive_concern) and |
| 5 | +per-bucket counts (concern_counts) so the template's chip toolbar + |
| 6 | +per-row concern badge can render server-side on first paint. |
| 7 | +
|
| 8 | +Tests check the rendered HTML body for these values. A3a will add the |
| 9 | +template surface; for now we assert the data is in the page context |
| 10 | +by grepping for the strings the template will eventually render. |
| 11 | +""" |
| 12 | + |
| 13 | +from __future__ import annotations |
| 14 | + |
| 15 | +from pathlib import Path |
| 16 | + |
| 17 | +import pytest |
| 18 | +from fastapi.testclient import TestClient |
| 19 | + |
| 20 | +from attune.ops.config import Config |
| 21 | +from attune.ops.server import create_app |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture() |
| 25 | +def cfg(tmp_path: Path) -> Config: |
| 26 | + project = tmp_path / "project" |
| 27 | + project.mkdir() |
| 28 | + return Config( |
| 29 | + project_root=project, |
| 30 | + attune_home=tmp_path / "attune-home", |
| 31 | + ) |
| 32 | + |
| 33 | + |
| 34 | +@pytest.fixture() |
| 35 | +def client(cfg: Config) -> TestClient: |
| 36 | + app = create_app(cfg) |
| 37 | + c = TestClient(app) |
| 38 | + c.headers["Host"] = f"{cfg.host}:{cfg.port}" |
| 39 | + return c |
| 40 | + |
| 41 | + |
| 42 | +class TestWorkflowsRouteServesConcerns: |
| 43 | + """The /workflows route puts concern data into the template context.""" |
| 44 | + |
| 45 | + def test_route_returns_200(self, client: TestClient) -> None: |
| 46 | + """Sanity: route renders without raising after the A2 wiring.""" |
| 47 | + resp = client.get("/workflows") |
| 48 | + assert resp.status_code == 200 |
| 49 | + |
| 50 | + def test_known_workflows_render(self, client: TestClient) -> None: |
| 51 | + """The workflows table renders the canonical workflow names. |
| 52 | +
|
| 53 | + Without this, the concern serialization has nothing to attach |
| 54 | + to. Quick smoke test that the workflow_concern data layer |
| 55 | + plumbing hasn't broken the table render. |
| 56 | + """ |
| 57 | + resp = client.get("/workflows") |
| 58 | + body = resp.text |
| 59 | + # Just check a handful of well-known workflow names appear. |
| 60 | + assert "code-review" in body |
| 61 | + assert "security-audit" in body |
| 62 | + assert "release-prep" in body |
| 63 | + |
| 64 | + |
| 65 | +class TestConcernDerivation: |
| 66 | + """A2's derive_concern wiring — values match what the |
| 67 | + workflow_concern module produces standalone. |
| 68 | + """ |
| 69 | + |
| 70 | + def test_derive_concern_matches_module_output(self) -> None: |
| 71 | + """The route's `concerns` dict must match the module's output. |
| 72 | +
|
| 73 | + Smoke-test via direct module call rather than HTML parsing so a |
| 74 | + template-rendering change doesn't break this. Belt-and- |
| 75 | + suspenders against future drift between the route and the |
| 76 | + underlying derivation. |
| 77 | + """ |
| 78 | + from attune.ops import data, workflow_concern |
| 79 | + |
| 80 | + workflows = data.list_workflows() |
| 81 | + derived = {w.name: workflow_concern.derive_concern(w.name) for w in workflows} |
| 82 | + |
| 83 | + # Spot-check the trade-off boundaries from decisions.md |
| 84 | + assert derived["code-review"] == "review" |
| 85 | + assert derived["security-audit"] == "review" # not "audit" |
| 86 | + assert derived["test-audit"] == "test" # not "audit" |
| 87 | + assert derived["doc-audit"] == "docs" # not "audit" |
| 88 | + assert derived["doc-orchestrator"] == "docs" # not "meta" |
| 89 | + assert derived["perf-audit"] == "audit" |
| 90 | + assert derived["release-prep"] == "meta" |
| 91 | + assert derived["rag-code-gen"] == "other" |
| 92 | + |
| 93 | + def test_concern_counts_sums_to_workflow_total(self) -> None: |
| 94 | + """concern_counts populates all 7 buckets; sum equals workflow total.""" |
| 95 | + from attune.ops import data, workflow_concern |
| 96 | + |
| 97 | + workflows = data.list_workflows() |
| 98 | + counts = workflow_concern.concern_counts([w.name for w in workflows]) |
| 99 | + assert set(counts.keys()) == set(workflow_concern.ALL_CONCERNS) |
| 100 | + assert sum(counts.values()) == len(workflows) |
| 101 | + |
| 102 | + |
| 103 | +class TestRouteContextShape: |
| 104 | + """The /workflows route emits the new context keys A3a will consume. |
| 105 | +
|
| 106 | + Source-grep tests against the HTML body. Cheap and stable. |
| 107 | + """ |
| 108 | + |
| 109 | + def test_response_includes_workflow_names(self, client: TestClient) -> None: |
| 110 | + """Smoke — table renders. Concerns + bucket_counts go via the |
| 111 | + template; A3a tests will assert the rendered chip toolbar. |
| 112 | + """ |
| 113 | + resp = client.get("/workflows") |
| 114 | + body = resp.text |
| 115 | + # Workflow rows exist |
| 116 | + assert 'data-workflow="code-review"' in body or "code-review" in body |
| 117 | + |
| 118 | + |
| 119 | +class TestNoRegressionOnExistingFeatures: |
| 120 | + """A2 added context fields; ensure no existing features broke.""" |
| 121 | + |
| 122 | + def test_existing_scope_picker_still_renders(self, client: TestClient) -> None: |
| 123 | + resp = client.get("/workflows") |
| 124 | + body = resp.text |
| 125 | + # Scope picker for security-audit |
| 126 | + assert "scope-picker" in body or "scope-cell" in body |
| 127 | + |
| 128 | + def test_existing_tier_map_still_renders(self, client: TestClient) -> None: |
| 129 | + resp = client.get("/workflows") |
| 130 | + body = resp.text |
| 131 | + # Tier chips are rendered with class names like "chip-cheap" etc. |
| 132 | + # Just check that one tier-classed chip appears. |
| 133 | + assert "chip-cheap" in body or "chip-capable" in body or "chip-premium" in body |
0 commit comments