Files
leleka/scripts/dev/test-outcomes.py
T
Pavlo Ratushnyi 35bf3a03d3 STRA-338 S16: gateway ports (EngineClient, ResponseStore, Clock, ToolHub, VisionEncoder) with adapters and fakes
AppState now holds ports instead of concrete types: `engine: Option<SharedEngine>` replaces the
mpsc::Sender<GenerationCommand>, `responses: SharedResponseStore` replaces Arc<RwLock<ResponseHistory>>,
`clock: SharedClock` serves queue deadlines, uptime and response timestamps, `mcp` is a ToolHub and `vision` a
VisionEncoder. The channel (adapters::ChannelEngine), the history with its disk snapshot
(responses::HistoryResponseStore), the system clock, mcp::Hub and vision::Vision are the adapters; main.rs serve()
composes them. No behaviour change: the HTTP handlers make the same calls in the same order, the queue claim race is
unchanged, only the deadline now reads the injected clock.

Ports are called per request, never per token or stream event (docs/architecture/gateway-ports.md).
ports/fakes has an in-memory adapter per port; control-plane/tests/ports_fakes.rs (12 tests), queue.rs and
adapters/channel_engine.rs add tests that drive the real handlers through them.

Architecture gate: dyn-trait:strata-control fell 35 -> 21 (a BoxError alias replaces 20 `Box<dyn Error>` spellings,
which pays for the 6 new port aliases); main.rs 1156 -> 1155 lines. Also adds scripts/dev/test-outcomes.py (per-test
outcome comparison of two cargo test logs) and scripts/dev/wsl-cargo.sh.
2026-11-05 20:06:28 +01:00

77 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""Per-test outcomes from a `cargo test` log, and a comparison of two logs (STRA-338 gateway track).
test-outcomes.py extract LOG print "<binary> :: <test> :: <outcome>" lines, sorted
test-outcomes.py compare BEFORE AFTER list tests whose outcome changed, tests only in one log, and the totals
A "binary" is the `Running ...` / `Doc-tests ...` header the test came from. Pure stdlib.
"""
import re
import sys
def extract(path):
outcomes = {}
binary = "?"
unresolved = []
with open(path, encoding="utf-8", errors="replace") as log:
for line in log:
line = line.rstrip("\n")
running = re.match(r"\s*Running (?:unittests )?(.+?)(?: \((.*)\))?$", line)
if running:
source = running.group(1).replace(chr(92), "/")
artifact = (running.group(2) or "").replace(chr(92), "/").split("/")[-1]
artifact = re.sub(r"(-[0-9a-f]{16})?(\.exe)?$", "", artifact)
binary = f"{artifact} [{source}]"
continue
doc = re.match(r"\s*Doc-tests (.+)", line)
if doc:
binary = "doc:" + doc.group(1)
continue
result = re.match(r"test (.+?) \.\.\. (ok|FAILED|ignored)", line)
if result:
outcomes[(binary, result.group(1))] = result.group(2)
continue
# A test that prints (an engine's stderr, a log line) puts its verdict somewhere else in the stream.
# The name is kept as unresolved and settled by the binary's `test result:` summary line.
started = re.match(r"test (\S+) \.\.\. ", line)
if started:
unresolved.append(started.group(1))
continue
summary = re.match(r"test result: (ok|FAILED)\. (\d+) passed; (\d+) failed", line)
if summary:
for name in unresolved:
verdict = "ok" if summary.group(3) == "0" else "UNRESOLVED"
outcomes[(binary, name)] = verdict
unresolved = []
return outcomes
def main(argv):
if len(argv) == 2 and argv[0] == "extract":
for (binary, name), outcome in sorted(extract(argv[1]).items()):
print(f"{binary} :: {name} :: {outcome}")
return 0
if len(argv) == 3 and argv[0] == "compare":
before, after = extract(argv[1]), extract(argv[2])
changed = [(k, before[k], after[k]) for k in before if k in after and before[k] != after[k]]
only_before = sorted(set(before) - set(after))
only_after = sorted(set(after) - set(before))
for key, was, now in changed:
print(f"CHANGED {key[0]} :: {key[1]}: {was} -> {now}")
for key in only_before:
print(f"MISSING {key[0]} :: {key[1]} (was {before[key]})")
for key in only_after:
print(f"NEW {key[0]} :: {key[1]} ({after[key]})")
count = lambda d, o: sum(1 for v in d.values() if v == o)
print(f"before: {count(before, 'ok')} ok, {count(before, 'FAILED')} failed, {count(before, 'ignored')} ignored")
print(f"after: {count(after, 'ok')} ok, {count(after, 'FAILED')} failed, {count(after, 'ignored')} ignored")
print(f"changed={len(changed)} missing={len(only_before)} new={len(only_after)}")
return 1 if changed or only_before or any(after[k] == "FAILED" for k in only_after) else 0
print(__doc__)
return 2
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))