Files
stack/tests/sem/test_runtime.py
kert 96b8ccf6df
Some checks failed
CI / skinny-install (aco) (push) Successful in 53s
CI / lint-test (push) Successful in 1m15s
CI / skinny-install (api) (push) Successful in 26s
CI / skinny-install (bcda) (push) Successful in 29s
CI / skinny-install (bib) (push) Successful in 31s
CI / skinny-install (bls) (push) Successful in 27s
CI / skinny-install (ccw) (push) Successful in 30s
CI / skinny-install (cli) (push) Successful in 30s
CI / skinny-install (cms) (push) Successful in 26s
CI / skinny-install (conf) (push) Successful in 26s
CI / skinny-install (opps) (push) Successful in 28s
CI / skinny-install (perf) (push) Successful in 29s
CI / skinny-install (pfs) (push) Successful in 27s
Infra CI / notebooks (push) Successful in 7s
Infra CI / zotero (push) Successful in 7s
CI / skinny-install (rex) (push) Successful in 27s
Infra CI / docs (push) Failing after 9s
Infra CI / api (push) Successful in 8s
Infra CI / mc (push) Successful in 6s
Package Supply Chain / pkg-supply-chain (push) Successful in 52s
CI / lint-test (pull_request) Successful in 1m18s
CI / skinny-install (aco) (pull_request) Successful in 44s
CI / skinny-install (api) (pull_request) Successful in 24s
CI / skinny-install (bcda) (pull_request) Successful in 32s
CI / skinny-install (bib) (pull_request) Successful in 30s
CI / skinny-install (bls) (pull_request) Successful in 25s
CI / skinny-install (ccw) (pull_request) Successful in 23s
CI / skinny-install (cli) (pull_request) Successful in 30s
CI / skinny-install (cms) (pull_request) Successful in 27s
CI / skinny-install (conf) (pull_request) Successful in 30s
CI / skinny-install (opps) (pull_request) Successful in 29s
CI / skinny-install (perf) (pull_request) Successful in 32s
CI / skinny-install (pfs) (pull_request) Successful in 33s
Infra CI / notebooks (pull_request) Successful in 7s
Infra CI / zotero (pull_request) Successful in 6s
Infra CI / docs (pull_request) Failing after 6s
CI / skinny-install (rex) (pull_request) Successful in 27s
Infra CI / api (pull_request) Successful in 6s
Infra CI / mc (pull_request) Successful in 6s
feat: sem — semantic coverage orchestration (AST + Ruff + ty + coverage)
4-layer architecture for tracking coverage as semantic AST nodes rather
than raw line numbers: parse → enrich → runtime → plan.  Stable node
identities, Ruff/ty diagnostic attachment, coverage mapping, priority
scoring heuristic, and drift-resistant rolling state persistence.

39 tests, ruff clean.
2026-03-26 14:37:54 -04:00

79 lines
2.2 KiB
Python

"""Tests for sem.runtime — coverage data attachment."""
from __future__ import annotations
import json
import tempfile
from pathlib import Path
from sem.nodes import NodeKind, SemanticNode, Span
from sem.runtime import attach_coverage
def _make_node(nid: str, start: int, end: int) -> SemanticNode:
return SemanticNode(
node_id=nid,
kind=NodeKind.BRANCH_IF,
span=Span(start_line=start, end_line=end),
module="pkg.mod",
)
def _write_coverage(data: dict) -> Path:
p = Path(tempfile.mktemp(suffix=".json"))
p.write_text(json.dumps(data))
return p
class TestAttachCoverage:
def test_marks_hit_nodes(self):
nodes = [_make_node("a", 1, 5), _make_node("b", 10, 15)]
cov = _write_coverage(
{
"files": {
"src/pkg/mod.py": {
"executed_lines": [1, 2, 3, 4, 5],
"missing_lines": [10, 11, 12, 13, 14, 15],
}
}
}
)
try:
attach_coverage(nodes, cov, "src/pkg/mod.py")
assert nodes[0].runtime.hit is True
assert nodes[0].runtime.hit_count == 5
assert nodes[1].runtime.hit is False
finally:
cov.unlink()
def test_missing_file_key_is_noop(self):
nodes = [_make_node("a", 1, 5)]
cov = _write_coverage({"files": {}})
try:
attach_coverage(nodes, cov, "nonexistent.py")
assert nodes[0].runtime.hit is False
finally:
cov.unlink()
def test_contexts_attached(self):
nodes = [_make_node("a", 1, 3)]
cov = _write_coverage(
{
"files": {
"mod.py": {
"executed_lines": [1, 2, 3],
"missing_lines": [],
"contexts": {
"2": ["test_foo", "test_bar"],
},
}
}
}
)
try:
attach_coverage(nodes, cov, "mod.py")
assert "test_foo" in nodes[0].runtime.tests_seen
assert "test_bar" in nodes[0].runtime.tests_seen
finally:
cov.unlink()