fix(tools): match explicit trace summaries to their capture

This commit is contained in:
ArjenS-LA 2026-10-12 15:10:22 -07:00
parent 43e3a70f81
commit 819c475266
2 changed files with 14 additions and 1 deletions

View File

@ -64,6 +64,19 @@ class TraceDigestTests(unittest.TestCase):
def test_summary_is_the_line_of_this_trace(self): def test_summary_is_the_line_of_this_trace(self):
self.assertEqual(self.result()["summary"]["trace"], "aps5-trace-abc-7.json.gz") self.assertEqual(self.result()["summary"]["trace"], "aps5-trace-abc-7.json.gz")
def test_explicit_summary_selects_the_matching_trace(self):
summary = Path(self.directory.name) / "relocated-summary.jsonl"
other = dict(SUMMARY, trace="other.json.gz", presents=99)
summary.write_text(json.dumps(SUMMARY) + "\n" + json.dumps(other) + "\n", encoding="utf-8")
selected = trace_digest.load_summary(summary, self.trace)
self.assertEqual(selected["trace"], self.trace.name)
self.assertEqual(selected["presents"], 3)
def test_explicit_summary_without_matching_trace_is_not_used(self):
summary = Path(self.directory.name) / "unrelated-summary.jsonl"
summary.write_text(json.dumps(dict(SUMMARY, trace="other.json.gz")) + "\n", encoding="utf-8")
self.assertIsNone(trace_digest.load_summary(summary, self.trace))
def test_frames_end_at_the_window(self): def test_frames_end_at_the_window(self):
result = self.result() result = self.result()
self.assertEqual(result["frames"], 3) self.assertEqual(result["frames"], 3)

View File

@ -67,7 +67,7 @@ def load_summary(path, trace_path):
return None return None
lines = [json.loads(line) for line in candidate.read_text(encoding="utf-8").splitlines() if line.strip()] lines = [json.loads(line) for line in candidate.read_text(encoding="utf-8").splitlines() if line.strip()]
for line in reversed(lines): for line in reversed(lines):
if path or line.get("trace") == Path(trace_path).name: if line.get("trace") == Path(trace_path).name:
return line return line
return None return None