Skip to content

test(discovery): read collector snapshots and derive the delta - #60

Closed
pengyuzhang wants to merge 1 commit into
pr/03-manifest-checksfrom
pr/04-snapshot
Closed

test(discovery): read collector snapshots and derive the delta#60
pengyuzhang wants to merge 1 commit into
pr/03-manifest-checksfrom
pr/04-snapshot

Conversation

@pengyuzhang

Copy link
Copy Markdown
Collaborator

Stacked on #59.

A reader's view of the JSON the collector emits, and the computation of what installation added.

Scoring works on the delta

Not on the raw second snapshot. Residual baseline noise then cancels out instead of being attributed to the manifest. The baseline is separately asserted to be near-empty, so anything it reported is a false positive with nothing to blame — which fails the run before installation begins.

A tool that changed channel between scans counts as added: same identity, different asset id. Dropping it would score a tool that is demonstrably present as a miss.

A snapshot that repeats an asset_id is refused rather than scored. It would silently halve the delta, and any number computed from that is wrong in the direction that flatters the collector.

Why this does not import the collector

The plan reaches for diff_snapshots from adr_discovery. This does not, for two reasons.

The practical one: the harness must run from Discovery/tests/ alone, so scoring a recorded run needs nothing installed beside it.

The load-bearing one: a test that imports the thing it measures stops being able to catch a whole class of defect. If the scorer computed "what arrived" with the collector's own diff, a diff that dropped assets would drop them from the measurement too — the run would score a clean sheet while quietly measuring less. Re-deriving means the two definitions can disagree, and a disagreement is exactly the finding worth having.

The cost is that snapshot.py encodes an expectation about the snapshot format. That is deliberate: the format is the collector's published contract, and a test that fails when it changes silently is the correct outcome.

Note on serialized()

The canary check searches the original document, not a re-serialization of the parsed model. A credential that leaked into a field the harness does not model is exactly the one that would otherwise be missed.

Verification

$ python3 -m unittest discover -s tests -t . -q
Ran 20 tests in 0.011s
OK

A reader's view of the JSON the collector emits, and the set of assets that
installation added.

Scoring works on the delta rather than on the raw second snapshot, so residual
baseline noise cancels out instead of being attributed to the manifest. A tool
that changed channel between the two scans counts as added: the identity is the
same but the asset id is not, and dropping it would score a tool that is
demonstrably present as a miss.

The harness derives the delta itself rather than importing the collector's own
diff, for two reasons. The harness has to run from this directory alone, so
scoring a recorded run needs nothing installed beside it. More importantly, a
test that imports the thing it measures stops being able to catch a whole class
of defect: a diff that dropped assets would drop them from the measurement too,
and the run would score a clean sheet while quietly measuring less.

The cost is that this file encodes an expectation about the snapshot format.
That is deliberate - the format is the collector's published contract, and a
test that fails when it changes silently is the correct outcome.
@pengyuzhang
pengyuzhang deleted the pr/04-snapshot branch August 23, 2026 16:08
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