Skip to content

test(html): cover graph_to_html - #254

Merged
evandowning merged 2 commits into
trailofbits:masterfrom
sushant-me:test/html-coverage
Oct 26, 2026
Merged

evandowning merged 2 commits into
trailofbits:masterfrom
sushant-me:test/html-coverage

Conversation

@sushant-me

Copy link
Copy Markdown
Contributor

Refs #96. This is a first step toward the coverage target, not the whole of it.

What this covers

src/it_depends/html.py goes from 14% to 92% (36 statements, 3 still missed), and the suite from 110 to 123 passing tests. Overall coverage moves 57% -> 59%.

The 13 cases in test/test_html.py cover:

  • every template placeholder is substituted — a leftover $NODES/$EDGES/$TITLE/$LAYOUT would mean one of the branches never ran;
  • the default title and an explicit title=;
  • the input path that takes a PackageCache rather than a DependencyGraph, asserted to produce the same output as passing cache.to_graph() directly;
  • collapse_versions in both directions;
  • the root styling (shape/color/borderWidth) applied to a source package, and a plain dependency not getting it;
  • the edge-label branch being skipped when the dependency name matches the package name, and taken when collapse_versions=False;
  • the empty-cache case still rendering a document.

What it does not cover

Three lines remain in html.py:

106:  roots: set[Package] = graph.source_packages
130:  nodes[-1].update({"color": "red"})                      # vulnerabilities
132:  nodes[-1]["level"] = max(graph.shortest_path_from_root(package), 0)

106 and 132 need a source-repository-backed graph, and 130 needs a package carrying a vulnerability. I left them rather than build a fixture I could not verify quickly; they are a reasonable next step.

Verification

$ uv sync --frozen --extra test
$ uv run --frozen --extra test coverage run -m pytest -q
123 passed, 15 skipped
$ uv run --frozen --extra test coverage report --include="*html.py"
src/it_depends/html.py      36      3    92%
test/test_html.py           60      0   100%
$ uv run --frozen --extra test coverage report --format=total
59

On the target

59% is not 90%, and I would rather say that plainly than let this read as closing #96. The remaining gaps are concentrated and large:

resolution.py   211 stmts   189 missed   10%
docker.py       243         187          23%
cmake.py        212         177          17%
go.py           273         158          42%
ubuntu/apt.py   152         117          23%
resolver.py     200         106          47%

If you would rather take coverage one module per PR like this one, that is the shape I would keep following; if you want a specific module first, say which and I will do that instead.

Refs trailofbits#96 — a first step toward the requested coverage, not the whole of it.

src/it_depends/html.py goes from 14% to 92% (36 statements, 3 still missed),
and the suite from 110 to 123 passing tests. Overall coverage moves 57% -> 59%.

The 13 cases cover the substitution of every template placeholder (a leftover
$NODES/$EDGES/$TITLE/$LAYOUT would mean a branch never ran), the default and
explicit titles, the cache-vs-graph input path, collapse_versions both ways, the
root styling applied to a source package, and the edge-label branch that is
skipped when a dependency name matches its package name.

Not covered: the graph.source_packages path and the per-node level assignment
(lines 106 and 132), which need a source-repository-backed graph, and the
vulnerability tint at line 130.

Overall coverage is 59%, so trailofbits#96's 90% target needs substantially more than this;
the remaining gaps are concentrated in resolution.py (189 missed), docker.py
(187), cmake.py (177) and go.py (158).
@evandowning
evandowning merged commit 0e3d9e8 into trailofbits:master Oct 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants