test_wiki_web.py¶
tests/test_wiki_web.py
The repository web: one zoomable, walkable view of every function (round 4, R3).
test_a_flow_is_played_by_its_functions_in_call_order
None test_wiki_web.test_a_flow_is_played_by_its_functions_in_call_order(Path db)
Flow steps on the web.
Checks
assert steps == ["handle", "save", "clean"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_a_flow_is_played_by_its_functions_in_call_order → _data → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_a_flow_is_played_by_its_functions_in_call_order → _data → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_a_flow_is_played_by_its_functions_in_call_order → _data → build_graph |
| REQ-DDB-WIKI-022 | measured | test_a_flow_is_played_by_its_functions_in_call_order → _data → web_data → _index_requirements |
Source · 27 lines
def test_a_flow_is_played_by_its_functions_in_call_order(db: Path) -> None:
"""OWNER 2026-11-15: "an animated core flow traced across the map". A flow's steps are its
functions in call order (caller, then callee, each once in a row); a step whose function is
not drawn is skipped, never invented.
@brief Flow steps on the web.
"""
from types import SimpleNamespace
from clew.wiki.web import _flow
data = _data(db)
slot = {(n["name"], n["file"]): i for i, n in enumerate(data["nodes"])}
page = SimpleNamespace(
name="flow-handle",
title="Handle",
calls=(("handle", "save"), ("save", "clean"), ("clean", "nowhere")),
hops=(
("pkg/api/handlers.py", "pkg/core/store.py"),
("pkg/core/store.py", "pkg/util.py"),
("pkg/util.py", "elsewhere.py"),
),
)
steps = [data["nodes"][i]["name"] for i in _flow(page, slot)["steps"]]
assert steps == ["handle", "save", "clean"]
Activity · 7 steps
test_calls_between_files_are_counted
None test_wiki_web.test_calls_between_files_are_counted(Path db)
`file_links` = [from file slice, to file slice, calls], across files only.
Checks
assert a != b and calls >= 1assert total == cross and total > 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_calls_between_files_are_counted → _data → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_calls_between_files_are_counted → _data → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_calls_between_files_are_counted → _data → build_graph |
| REQ-DDB-WIKI-022 | measured | test_calls_between_files_are_counted → _data → web_data → _index_requirements |
Source · 19 lines
def test_calls_between_files_are_counted(db: Path) -> None:
"""@brief `file_links` = [from file slice, to file slice, calls], across files only."""
data = _data(db)
files = data["files"]
total = 0
for a, b, calls in data["file_links"]:
assert a != b and calls >= 1
total += calls
nodes = data["nodes"]
index = {(f["block"], f["file"]): i for i, f in enumerate(files)}
cross = sum(
1
for x, y in data["edges"]
if index[(nodes[x]["block"], nodes[x]["file"])]
!= index[(nodes[y]["block"], nodes[y]["file"])]
)
assert total == cross and total > 0
Activity · 10 steps
test_each_file_is_one_slice_of_its_block
None test_wiki_web.test_each_file_is_one_slice_of_its_block(Path db)
Files as slices.
Checks
assert [f["file"] for f in mine] == sorted(f["file"] for f in mine)assert abs(mine[0]["a0"] - block["a0"]) < 1e-6 and abs(mine[-1]["a1"] - block["a1"]) < 1e-6assert all(mine[i]["a1"] <= mine[i + 1]["a0"] + 1e-9 for i in range(len(mine) - 1))assert s["a0"] - 1e-6 <= angle <= s["a1"] + 1e-6, (n["name"], n["file"])
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_each_file_is_one_slice_of_its_block → _data → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_each_file_is_one_slice_of_its_block → _data → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_each_file_is_one_slice_of_its_block → _data → build_graph |
| REQ-DDB-WIKI-022 | measured | test_each_file_is_one_slice_of_its_block → _data → web_data → _index_requirements |
| REQ-DDB-WIKI-054 | inferred | test_each_file_is_one_slice_of_its_block → all |
Source · 21 lines
def test_each_file_is_one_slice_of_its_block(db: Path) -> None:
"""OWNER (2026-11-22): "the by file divides and interconnects on zoom in the map". A file is one
contiguous slice of its block's wedge (ordered by file, sized by its functions, disjoint), the
same slice on every ring, and each of its functions sits inside it.
@brief Files as slices.
"""
data = _data(db)
files = data["files"]
for bi, block in enumerate(data["blocks"]):
mine = [f for f in files if f["block"] == bi]
assert [f["file"] for f in mine] == sorted(f["file"] for f in mine)
assert abs(mine[0]["a0"] - block["a0"]) < 1e-6 and abs(mine[-1]["a1"] - block["a1"]) < 1e-6
assert all(mine[i]["a1"] <= mine[i + 1]["a0"] + 1e-9 for i in range(len(mine) - 1))
slices = {(f["block"], f["file"]): f for f in files}
for n in data["nodes"]:
s = slices[(n["block"], n["file"])]
angle = math.atan2(n["y"], n["x"]) % (2 * math.pi)
assert s["a0"] - 1e-6 <= angle <= s["a1"] + 1e-6, (n["name"], n["file"])
Activity · 12 steps
test_each_function_carries_the_requirements_it_implements
None test_wiki_web.test_each_function_carries_the_requirements_it_implements(Path db)
P5.4: per-function requirement ids, compact, and the `#req=` hash.
Checks
assert data["req_ids"] == ["R-1", "R-2"]assert by_name["save"] == [0, 1] and by_name["clean"] == [0] and by_name["handle"] is Noneassert "req=" in WEB_JS, "the map reads the overlay's hash"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_each_function_carries_the_requirements_it_implements → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_each_function_carries_the_requirements_it_implements → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_each_function_carries_the_requirements_it_implements → build_graph |
| REQ-DDB-WIKI-022 | measured | test_each_function_carries_the_requirements_it_implements → web_data → _index_requirements |
Source · 27 lines
def test_each_function_carries_the_requirements_it_implements(db: Path) -> None:
"""OWNER (round 5, P5.4): the requirement overlay. A requirement page's "Show on the map"
opens `map.html#req=<id>`, which lights that requirement's implementing functions. The map
data carries ONE table of ids and, per function, indices into it: a site of thousands of
functions does not repeat each id string on every node it implements.
@brief P5.4: per-function requirement ids, compact, and the `#req=` hash.
"""
from types import SimpleNamespace
rows = [
SimpleNamespace(
req_id="R-2", tier="PASS", implementer_sites=(("save", "pkg/core/store.py", 4),)
),
SimpleNamespace(
req_id="R-1",
tier="UNTESTED",
implementer_sites=(("save", "pkg/core/store.py", 4), ("clean", "pkg/util.py", 1)),
),
]
data = web_data(db, build_graph(db, rows, None, _DECLARED, exclude_tests=True))
assert data["req_ids"] == ["R-1", "R-2"]
by_name = {n["name"]: n.get("r") for n in data["nodes"]}
assert by_name["save"] == [0, 1] and by_name["clean"] == [0] and by_name["handle"] is None
assert "req=" in WEB_JS, "the map reads the overlay's hash"
Activity · 7 steps
test_edges_and_block_links_are_carried_for_walking_and_the_overview
None test_wiki_web.test_edges_and_block_links_are_carried_for_walking_and_the_overview(Path db)
Function edges by node index (walking source); block links weighted (overview).
Checks
assert ("handle", "save") in edges and ("save", "clean") in edgesassert {"from": "API", "to": "Core", "calls": 1} in data["links"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_edges_and_block_links_are_carried_for_walking_and_the_overview → _data → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_edges_and_block_links_are_carried_for_walking_and_the_overview → _data → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_edges_and_block_links_are_carried_for_walking_and_the_overview → _data → build_graph |
| REQ-DDB-WIKI-022 | measured | test_edges_and_block_links_are_carried_for_walking_and_the_overview → _data → web_data → _index_requirements |
Source · 9 lines
def test_edges_and_block_links_are_carried_for_walking_and_the_overview(db: Path) -> None:
"""@brief Function edges by node index (walking source); block links weighted (overview)."""
data = _data(db)
names = [n["name"] for n in data["nodes"]]
edges = {(names[a], names[b]) for a, b in data["edges"]}
assert ("handle", "save") in edges and ("save", "clean") in edges
assert {"from": "API", "to": "Core", "calls": 1} in data["links"]
Activity · 5 steps
test_every_block_is_a_wedge_and_wedges_do_not_overlap
None test_wiki_web.test_every_block_is_a_wedge_and_wedges_do_not_overlap(Path db)
Spokes: one angular range per block, in declared order, disjoint, inside one turn.
Checks
assert [b["id"] for b in blocks] == ["API", "Core"]assert all(0 <= a0 < a1 <= 2 * math.pi + 1e-9 for a0, a1 in spans)assert all(spans[i][1] <= spans[i + 1][0] for i in range(len(spans) - 1))
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_every_block_is_a_wedge_and_wedges_do_not_overlap → _data → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_every_block_is_a_wedge_and_wedges_do_not_overlap → _data → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_every_block_is_a_wedge_and_wedges_do_not_overlap → _data → build_graph |
| REQ-DDB-WIKI-022 | measured | test_every_block_is_a_wedge_and_wedges_do_not_overlap → _data → web_data → _index_requirements |
| REQ-DDB-WIKI-054 | inferred | test_every_block_is_a_wedge_and_wedges_do_not_overlap → all |
Source · 9 lines
def test_every_block_is_a_wedge_and_wedges_do_not_overlap(db: Path) -> None:
"""@brief Spokes: one angular range per block, in declared order, disjoint, inside one turn."""
blocks = _data(db)["blocks"]
assert [b["id"] for b in blocks] == ["API", "Core"]
spans = [(b["a0"], b["a1"]) for b in blocks]
assert all(0 <= a0 < a1 <= 2 * math.pi + 1e-9 for a0, a1 in spans)
assert all(spans[i][1] <= spans[i + 1][0] for i in range(len(spans) - 1))
Activity · 5 steps
test_functions_sit_in_their_block_on_rings_by_call_depth
None test_wiki_web.test_functions_sit_in_their_block_on_rings_by_call_depth(Path db)
Rings by depth; every point inside its wedge.
Checks
assert "test_save" not in nodesassert (nodes["handle"]["ring"], nodes["save"]["ring"], nodes["clean"]["ring"]) == (0, 1, 2)assert block["a0"] - 1e-6 <= angle <= block["a1"] + 1e-6, n["name"]assert nodes["clean"]["block"] == [b["id"] for b in data["blocks"]].index("Core")assert blocks["Core"]["inferred_files"] == ["pkg/util.py"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_functions_sit_in_their_block_on_rings_by_call_depth → _data → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_functions_sit_in_their_block_on_rings_by_call_depth → _data → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_functions_sit_in_their_block_on_rings_by_call_depth → _data → build_graph |
| REQ-DDB-WIKI-022 | measured | test_functions_sit_in_their_block_on_rings_by_call_depth → _data → web_data → _index_requirements |
Source · 19 lines
def test_functions_sit_in_their_block_on_rings_by_call_depth(db: Path) -> None:
"""THE WEB'S THREADS: an entry point (no non-test caller) is ring 0 at the centre; each call
takes its callee one ring out. Test code is not drawn — it is a lens, not a block.
@brief Rings by depth; every point inside its wedge.
"""
data = _data(db)
nodes = {n["name"]: n for n in data["nodes"]}
assert "test_save" not in nodes
assert (nodes["handle"]["ring"], nodes["save"]["ring"], nodes["clean"]["ring"]) == (0, 1, 2)
blocks = {b["id"]: b for b in data["blocks"]}
for n in data["nodes"]:
block = data["blocks"][n["block"]]
angle = math.atan2(n["y"], n["x"]) % (2 * math.pi)
assert block["a0"] - 1e-6 <= angle <= block["a1"] + 1e-6, n["name"]
assert nodes["clean"]["block"] == [b["id"] for b in data["blocks"]].index("Core")
assert blocks["Core"]["inferred_files"] == ["pkg/util.py"]
Activity · 11 steps
test_the_change_lens_exists_only_with_an_impact_report
None test_wiki_web.test_the_change_lens_exists_only_with_an_impact_report(Path db)
Lens options follow their sources.
Checks
assert "Change</option>" not in web_html(web_data(db, plain))assert "Change</option>" in web_html(data)assert {n["name"]: n.get("changed") for n in data["nodes"]}["save"] is True
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_the_change_lens_exists_only_with_an_impact_report → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_the_change_lens_exists_only_with_an_impact_report → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_the_change_lens_exists_only_with_an_impact_report → build_graph |
| REQ-DDB-WIKI-021 | measured | test_the_change_lens_exists_only_with_an_impact_report → web_html |
| REQ-DDB-WIKI-022 | measured | test_the_change_lens_exists_only_with_an_impact_report → web_data → _index_requirements |
Source · 15 lines
def test_the_change_lens_exists_only_with_an_impact_report(db: Path) -> None:
"""NO IMPACT REPORT, NO CHANGE LENS (ported from the box map, which the web replaced): with a
report the lens exists and a changed function carries `changed`.
@brief Lens options follow their sources.
"""
plain = build_graph(db, [], None, _DECLARED, exclude_tests=True)
assert "Change</option>" not in web_html(web_data(db, plain))
impact = [{"req_id": "R-1", "functions": [{"name": "save", "file": "pkg/core/store.py"}]}]
measured = build_graph(db, [], impact, _DECLARED, exclude_tests=True)
data = web_data(db, measured)
assert "Change</option>" in web_html(data)
assert {n["name"]: n.get("changed") for n in data["nodes"]}["save"] is True
Activity · 7 steps
test_the_file_layer_is_its_own_budgeted_script
None test_wiki_web.test_the_file_layer_is_its_own_budgeted_script()
web-files.js.
Checks
assert "function webFiles(" in js and len(js.encode()) <= 8192 assert "window.webFiles" in WEB_JS page = web_html({"nodes": [], "blocks": [], "links": []}) assert page.index("web-files.js") < page.index("_static/web.js")
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-021 | measured | test_the_file_layer_is_its_own_budgeted_script → web_html |
Source · 15 lines
def test_the_file_layer_is_its_own_budgeted_script() -> None:
"""web.js is at its 16 KB budget, so the file layer is a second script with its own budget (the
clew-views.js precedent), loaded BEFORE web.js; web.js calls it when zoomed in.
@brief web-files.js.
"""
import clew.wiki
js = (Path(clew.wiki.__file__).parent / "themes/clew/static/web-files.js").read_text()
assert "function webFiles(" in js and len(js.encode()) <= 8192
assert "window.webFiles" in WEB_JS
page = web_html({"nodes": [], "blocks": [], "links": []})
assert page.index("web-files.js") < page.index("_static/web.js")
Activity · 6 steps
test_the_map_controls_are_grouped_and_sized_to_content
None test_wiki_web.test_the_map_controls_are_grouped_and_sized_to_content()
C-14: zoom as one group; labels never wrap a word per line; selects size to content.
Checks
assert '<span class="seg">' in htmlassert (".web-bar label{white-space:nowrap}" in css and ".web-bar select{width:auto;max-width:18rem}" in css )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-021 | measured | test_the_map_controls_are_grouped_and_sized_to_content → web_html |
Source · 11 lines
def test_the_map_controls_are_grouped_and_sized_to_content() -> None:
"""@brief C-14: zoom as one group; labels never wrap a word per line; selects size to content."""
html = web_html({"nodes": [], "blocks": [], "links": []})
assert '<span class="seg">' in html
import clew.wiki
css = (Path(clew.wiki.__file__).parent / "themes/clew/static/clew.css").read_text()
assert (
".web-bar label{white-space:nowrap}" in css
and ".web-bar select{width:auto;max-width:18rem}" in css
)1 more lines, not shown
Activity · 5 steps
test_the_page_embeds_the_data_a_canvas_and_a_table_view
None test_wiki_web.test_the_page_embeds_the_data_a_canvas_and_a_table_view(Path db)
Canvas + inline JSON + the same blocks as a table; web.js local and budgeted.
Checks
assert "<canvas" in html and 'class="web"' in htmlassert payload and json.loads(payload.group(1))["blocks"]assert "<table" in html and "Core" in html.split("<table", 1)[1]assert "http://" not in WEB_JS and "https://" not in WEB_JSassert len(WEB_JS.encode()) <= 16384assert "prefers-reduced-motion" in WEB_JS
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_the_page_embeds_the_data_a_canvas_and_a_table_view → _data → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_the_page_embeds_the_data_a_canvas_and_a_table_view → _data → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_the_page_embeds_the_data_a_canvas_and_a_table_view → _data → build_graph |
| REQ-DDB-WIKI-021 | measured | test_the_page_embeds_the_data_a_canvas_and_a_table_view → web_html |
| REQ-DDB-WIKI-022 | measured | test_the_page_embeds_the_data_a_canvas_and_a_table_view → _data → web_data → _index_requirements |
Source · 12 lines
def test_the_page_embeds_the_data_a_canvas_and_a_table_view(db: Path) -> None:
"""@brief Canvas + inline JSON + the same blocks as a table; web.js local and budgeted."""
html = web_html(_data(db))
assert "<canvas" in html and 'class="web"' in html
payload = re.search(r'<script type="application/json" id="web-data">(.*?)</script>', html, re.S)
assert payload and json.loads(payload.group(1))["blocks"]
assert "<table" in html and "Core" in html.split("<table", 1)[1]
assert "http://" not in WEB_JS and "https://" not in WEB_JS
assert len(WEB_JS.encode()) <= 16384
assert "prefers-reduced-motion" in WEB_JS
Activity · 8 steps
test_zoomed_out_blocks_and_a_legend_show_the_lens
None test_wiki_web.test_zoomed_out_blocks_and_a_legend_show_the_lens()
Wedge pies and the lens legend.
Checks
assert ("function cat(n)" in WEB_JS and "function pies()" in WEB_JS and "function legend()" in WEB_JS )assert "data-web-legend" in web_html({"nodes": [], "blocks": [], "links": []})
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-021 | measured | test_zoomed_out_blocks_and_a_legend_show_the_lens → web_html |
Source · 16 lines
def test_zoomed_out_blocks_and_a_legend_show_the_lens() -> None:
"""OWNER MAP NOTES (2026-11-22): change impact → map showed the changed dots but nothing zoomed
out, and there was no colour legend. Owner Q/A: a folded block is drawn as the active lens's
status pie (sub-arcs in proportion), and a legend names each colour with its count. One
category function (`cat`) serves the dots, the pies and the legend, so they cannot disagree.
@brief Wedge pies and the lens legend.
"""
assert (
"function cat(n)" in WEB_JS
and "function pies()" in WEB_JS
and "function legend()" in WEB_JS
)
assert "data-web-legend" in web_html({"nodes": [], "blocks": [], "links": []})