Skip to content

chore(examples): stop tracking the four rendered capture reports (#685) - #697

Open
JarryShaw wants to merge 1 commit into
mainfrom
chore/untrack-rendered-capture-reports-685
Open

JarryShaw wants to merge 1 commit into
mainfrom
chore/untrack-rendered-capture-reports-685

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Please follow the guide below

What is the purpose of your pull request?

  • fix — corrects a defect
  • feat — adds a feature
  • perf — changes performance, not behaviour
  • refactor — changes neither behaviour nor performance
  • test — tests only
  • docs — documentation only
  • ci — workflows or build tooling
  • chore — anything else

(No chore label exists in this repository, so this is labelled test — the closest available, and honest, since the PR adds a test module. Worth creating a chore label if that category should be distinguishable in the generated release notes.)


Description

Fixes #685.

examples/captures/pcapng.txt recorded packet -> NIL for four blocks that had
been carrying their captured octets since #683. The staleness was found by
someone reading the file, not by anything failing — which is the whole problem.

The fix is not to regenerate the file. Four of the six files that were
tracked under examples/captures/ are build output, not fixtures, and a tracked
build output with no reader goes stale silently every time the renderer changes:

File Written by Read by
out.json, out.plist, out.txt examples/legacy_smoke/test_extractor.py, test_basic.py nothing
pcapng.txt examples/legacy_smoke/test_pcapng.py nothing
in.pcap nothing — genuine input ~50 modules
dhcp.pcapng nothing — genuine input ~9 modules

So the four reports are untracked (git rm --cached, files left on disk), their
!examples/captures/… exceptions dropped from .gitignore so the existing
examples/captures/* line covers them, and in.pcap / dhcp.pcapng stay
tracked. A fresh clone now has exactly those two.

Verification

Nothing reads the four files. Every reference is a bare string literal or a
tmpdir path, checked individually:
tests/cli/test_main.py:83,86 (an argparse assertion on the string 'out.json'),
tests/foundation/test_extraction.py:275,293,547 (all temp / 'out.json'),
tests/protocols/internet/test_esp_unit.py:976 (os.path.dirname(make_pcap(...)),
a tmpdir), tests/test_tier_guard.py:146 and tests/_tiers.py:146 (an
assertNotIn and its explanatory comment). No sample_path() call anywhere
names one — now enforced, see below.

The docs only quote them as prose. docs/source/demo.rst:17,19,80,93,101,107,115
sit inside code-block directives and console transcripts. There is no
literalinclude, no include::, no csv-table :file:, no raw :file: and no
doctest extension anywhere in docs/conf.py's extensions list has no
sphinx.ext.doctest, and deploy-pages.yml runs the plain HTML builder. The
docs build reads none of these files from disk.

The tier guard needs no change. tests/_tiers.committed_captures() runs
git ls-files -z -- examples/captures rather than holding a list of names, so it
reports the new state on its own; it now answers ['dhcp.pcapng', 'in.pcap'].
tests/test_tier_guard.py is 25 passed / 15 subtests passed against the change.

No packaging change, measured rather than reasoned. MANIFEST.in:10 already
prunes examples/captures wholesale, the backend is plain setuptools.build_meta
with no setuptools_scm or any other git-aware file finder (so tracked-ness
never reached the file list), and [tool.setuptools.packages.find] only takes
pcapkit*. An sdist built from this tree has 871 entries and zero under
examples/captures — not even in.pcap or dhcp.pcapng, which stay tracked.
The wheel never contained examples/ at all. So MANIFEST.in needs no matching
change, and the published artifacts are identical either way.

Regeneration was already documented, and was already slightly wrong.
examples/legacy_smoke/ has a make fixtures target for exactly these four
files. Note it is make fixtures, not make samples
examples/generators/make_samples.py never produced them, so CI's
fixture-generation step would not have either. The README section and the
Makefile comments called them "committed"; they now say what a fresh clone has to
run, and why the reports are not worth tracking. One pleasant side effect:
README.rst:23-24 already claimed "Only in.pcap and dhcp.pcapng are
committed"
, which was false while six files were tracked and is now true.

Test

tests/project/test_capture_tracking.py is new — 5 tests, 8 subtests — pinning
the invariant this change establishes, since the regression is one git add -f
away and looks like nothing in a diff review:

  • every tracked name under examples/captures/ ends in a capture suffix (stated
    by suffix, so a new input fixture needs no edit here while a committed report
    fails at once);
  • none of the four reports is tracked, by name, in case the suffix list widens;
  • both inputs are tracked, which keeps the first assertion from passing
    vacuously on a checkout that tracks nothing there;
  • no module under tests/, in either tier, reads a report through
    sample_path(). This is not covered by the tier guard's own audit, which only
    flags unit-tier reads of untracked captures — these four are worse than
    untracked, because fixture generation does not rebuild them either.

Shown to fail without the fix. With the four restored to the index via
git add -f, two of the five tests fail across four subtests:

FAILED    tests/project/test_capture_tracking.py::TrackedCaptureTests::test_every_tracked_file_is_an_input_capture
SUBFAILED tests/project/test_capture_tracking.py::TrackedCaptureTests::test_no_rendered_report_is_tracked (report='out.json')
SUBFAILED ... (report='out.plist')   SUBFAILED ... (report='out.txt')   SUBFAILED ... (report='pcapng.txt')
5 failed, 4 passed, 8 subtests passed

It also degrades where git cannot answer, so an unpacked source distribution
still runs: 4 skipped with the reason quoted, 1 passed, verified against a
git checkout-index export outside any repository.

Targeted runs, all green: tests/project/ + tests/test_tier_guard.py
149 passed, 494 subtests passed; tests/test_docstring_contract.py → 7 passed.

On coverage: this change touches no pcapkit/ module, so library coverage
cannot move and does not — stated plainly rather than implied. tests/_tiers.py
also holds at 87%, because the new tests exercise paths its own suite already
covered. What the new module adds is a regression guard over repository state,
which coverage cannot measure; it is demonstrated by the failure run above
instead.

Follow-ups, not touched here

Three comments elsewhere now understate the count, none of which affects a test.
Left alone because they are outside this change's files:

  • tests/_tiers.py:36-37"there are six today, not the two the rule started with" → two again.
  • tests/integration/_helpers.py:58-59"four of them are committed" → two.
  • tests/test_tier_guard.py:15"the moment a seventh capture is committed" → a third.

* `examples/captures/pcapng.txt` recorded `packet -> NIL` for four blocks that
  had been carrying their octets since #683, and nothing had noticed, because
  nothing reads a rendered report back: no test asserts on one, and
  `docs/source/demo.rst` only quotes them as hand-written transcripts.
* Regenerating them on every parser change is work with no reader, so the four
  reports -- `out.json`, `out.plist`, `out.txt` and `pcapng.txt` -- are no longer
  tracked. `.gitignore` loses their un-ignore exceptions and the existing
  `examples/captures/*` line covers them; they stay on disk for anyone who has
  them already.
* `in.pcap` and `dhcp.pcapng` stay tracked. They are inputs nothing in the
  repository regenerates, and the unit tier reads both on a fresh clone.
* `examples/legacy_smoke/` is the only thing that rebuilds the reports --
  `make fixtures`, not `make samples`, since
  `examples/generators/make_samples.py` never produced them. That README section
  and the Makefile comments called them "committed"; they now say what a fresh
  clone has to run, and why the reports are not worth tracking.
* No packaging change. `MANIFEST.in` already prunes `examples/captures`
  wholesale, and the build is plain setuptools with no git-aware file finder, so
  the sdist and wheel listings are identical either way -- measured, and neither
  artifact ever carried a single file from that directory.
* The tier guard needs no change either: `tests._tiers.committed_captures()`
  asks `git ls-files` rather than holding a list of names, so it reports two
  tracked captures instead of six on its own.

tests/project/test_capture_tracking.py is new -- 5 tests and 8 subtests -- and
pins that git tracks no rendered report, that both inputs stay tracked, and that
no module under tests/ reads a report through `sample_path()`. Two of its tests
fail across four subtests with the reports restored to the index, which is the
regression it exists for. It skips where git cannot answer, so an unpacked source
tarball still runs. No pcapkit module changes, so library coverage is unmoved by
construction.

Fixes #685
@JarryShaw JarryShaw added the test Pull requests that add or correct tests (test: subject prefix) label Sep 23, 2026
@JarryShaw JarryShaw added the chore Maintenance work: tooling, repo hygiene, no library behaviour change label Sep 23, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO MERGE

Independent cross-review, different model from the PR's author (Claude Sonnet 5 here). Reviewed head 6fca065e2 against base f0999858e. All read-only git plus one scratch-dir git clone of the real repo (/local/home/jarryx/tmp/xreview-697/repo-clone, checked out to 6fca065e2 there — the real checkout at /local/home/jarryx/GitHub/PyPCAPKit was never mutated) so the tier-guard/new-test claims could be exercised for real rather than reasoned about.

Per-claim verdicts, each derived independently:

1. Nothing reads the four reports' contents — CONFIRMED. Re-ran git grep for out.json|out.plist|out.txt|pcapng.txt across tests/ pcapkit/ examples/ util/ docs/ .github/ at 6fca065e2 from scratch and inspected every hit's surrounding code. Found the same set the author and a prior reviewer already covered, nothing new:

  • examples/legacy_smoke/{test_extractor,test_pcapng,test_basic,test_ip_reasm}.py write the reports via pcapkit.extract(fout=...), and aren't pytest-collected at all (pyproject.toml sets testpaths = ["tests"], which excludes examples/).
  • tests/protocols/internet/test_esp_unit.py:976 and tests/foundation/test_extraction.py:275/293/547 build out.txt/out.json under a tempfile.mkdtemp()-created tmpdir (confirmed by reading make_pcap() at test_esp_unit.py:113) — same filename, unrelated file.
  • tests/cli/test_main.py:83/86 uses 'out.json' as an arbitrary CLI-arg-parser fixture string, unrelated to the real file.
  • tests/_tiers.py:146 and tests/test_tier_guard.py:146 are a comment and a suffix-filter assertion respectively — confirmed tests/test_tier_guard.py is byte-identical between base and head (git diff f0999858e...6fca065e2 -- tests/test_tier_guard.py is empty), so this line predates the PR and isn't about tracked/untracked status at all.
  • Everything under examples/legacy_smoke/README.rst, Makefile, and the new test's own docstring/RENDERED_REPORTS tuple is prose/definition, not a read.

2. Sphinx docs never read them off disk — CONFIRMED. docs/source/conf.py's extensions list has no sphinx.ext.doctest. git grep for literalinclude, include::, csv-table, and raw:: under docs/ at 6fca065e2 turns up only three unrelated .. raw:: html blocks. Enumerated every :file: occurrence in docs/ (~40 hits across index.rst, pep.rst, testing.rst, 3rdparty.rst, engines/index.rst, changelog.rst) — every single one is the inline role used as filename prose, never a csv-table :file: or other file-reading directive option. None of the four filenames appear anywhere under docs/. .github/workflows/deploy-pages.yml runs make -C docs html, and docs/Makefile's html target is sphinx-build -M html ... — the plain HTML builder, confirmed by reading the Makefile directly.

3. MANIFEST.in makes this packaging-neutral — CONFIRMED, with one number to correct. MANIFEST.in:10 is exactly prune examples/captures, unchanged between base and head (git diff f0999858e...6fca065e2 -- MANIFEST.in is empty). build-backend = "setuptools.build_meta", no setuptools_scm in requires. I built real sdists for both trees with the repo's own venv (setuptools 84.0.0, build 1.6.1, nothing installed): base (f0999858e) → 871 entries, 0 under examples/captures/; head (6fca065e2) → 872 entries, 0 under examples/captures/. Diffing the two listings shows exactly one added line, tests/project/test_capture_tracking.py — the PR's own new test file. So "zero entries under examples/captures" holds for both trees (packaging already excluded the whole directory before this PR, even the six-file base state — the change is genuinely orthogonal to what ships), but the specific count "871" describes the base sdist, not the head sdist the PR actually produces, which is 872. Doesn't affect the substance of the claim, just the exact number quoted for the after-state.

4. The tier guard adapts without change — CONFIRMED. Read tests/_tiers.py:288-311: committed_captures() resolves live via _git('ls-files', '-z', '--', relative_root), no hardcoded list. In the scratch clone at 6fca065e2, before trusting anything: pcapkit.__file__ = /local/home/jarryx/tmp/xreview-697/repo-clone/pcapkit/__init__.py, tests._tiers.ROOT = the same clone path, and committed_captures() == frozenset({'dhcp.pcapng', 'in.pcap'}) — correctly answers the new 2-file state with zero code changes. pytest tests/test_tier_guard.py -v25 passed, 15 subtests passed in 0.33s, exact match to the author's figure. Grepped tests/ pcapkit/ util/ examples/ for any other hardcoded capture list/count in code (not comments): found none.

5. The new test genuinely fails without the change — CONFIRMED, reproduced all three scenarios in the scratch clone (never mutating the real checkout):

  • Restored the four via git show f0999858e:examples/captures/<f> + git add -f in the clone onlypytest tests/project/test_capture_tracking.py -v: 5 failed, 4 passed, 8 subtests passed. Decomposed: 1 plain-assertion failure (test_every_tracked_file_is_an_input_capture) + 4 subtest failures, one per report name (test_no_rendered_report_is_tracked) — i.e. exactly 2 originating test methods produce failures, spanning 4 subtests, matching "2 tests fail across 4 subtests" precisely.
  • git reset --hard 6fca065e2 && git clean -fd examples/captures/ in the clone (clean branch state) → 5 passed, 8 subtests passed, exact match.
  • Ran the same file against a plain git archive 6fca065e2 extraction with no .git anywhere on the path (confirmed via git rev-parse --show-toplevel failing there) → 1 passed, 4 skipped, exact match.

6. The .gitignore edit is exactly right — CONFIRMED, with direct behavioral testing, not just a diff read. git diff f0999858e...6fca065e2 -- .gitignore shows the four !examples/captures/{out.json,out.plist,out.txt} lines and the separate !examples/captures/pcapng.txt line removed, the two !examples/captures/{in.pcap,dhcp.pcapng} exceptions untouched, and the pre-existing "Guard the pre-rename path too... examples/sample/" comment survives unchanged. Built an isolated scratch git repo containing only the head .gitignore plus dummy files and ran git check-ignore -v/-q on all six: out.json, out.plist, out.txt, pcapng.txt all matched examples/captures/* (line 8, ignored, exit 0); in.pcap and dhcp.pcapng matched their own !... negation lines (lines 23/24, not ignored, exit 1).

7. The prose changes are true — CONFIRMED, and the correction about make_samples.py is also confirmed independently. Base examples/legacy_smoke/Makefile already had the fixtures: target and README already had a "Regenerating the committed fixtures" section (confirmed by reading both base and head and diffing); the diff is wording only (heading retitled, "Git tracks none of them (#685)" added, a new explanatory paragraph about the staleness story, plus the new-issue read-consequence paragraph in .gitignore/README). The fixtures: recipe itself is byte-identical: test_extractor.py (writes out.plist/out.json/out.txt from in.pcap) + test_pcapng.py (writes pcapng.txt from dhcp.pcapng) — confirmed by reading both scripts, so make fixtures really does build all four. git grep -rn "fixtures\|legacy_smoke" 6fca065e2 -- .github/workflows/ is empty — no CI job runs it, so nothing is newly missing files it never had. Separately, the prior briefing that examples/generators/make_samples.py regenerates the four reports is confirmed wrong: its own docstring lists it as delegating only to pcap.py/endian.py/pcapng.py/options.py, all producing .pcap/.pcapng/.cap samples; docs/source/testing.rst (pre-existing, untouched by this PR) independently corroborates "make samples # write examples/captures/*.pcap and *.pcapng" as a distinct thing from the legacy_smoke fixtures. Only examples/legacy_smoke/Makefile's fixtures target builds the four reports, and no CI job runs it — confirmed on both counts.

8. Docs-only/test-only scope — CONFIRMED. git diff --name-only f0999858e...6fca065e2 -- pcapkit/ is empty. Full changed-file list is exactly the eight files in the PR description (.gitignore, the four deletions, Makefile, README.rst, the new test); no CHANGELOG.md/.rst or docs/source/changelog* file appears anywhere in the diff.

Could not verify / not attempted: I did not run the whole test suite (out of scope per the brief), did not verify wheel-building (only sdist, as the brief asked), and did not try to reproduce the CI runner environment for unit-tests.yml end to end — I only confirmed by reading that it doesn't invoke fixtures/legacy_smoke. I also didn't audit every one of docs/'s ~40 :file: hits against a live Sphinx build (no network/build attempted there), only against the extension list and directive syntax; a build-level check of docs/ isn't in the brief's write authority and I didn't attempt one.

Nothing else disputed. The one correction (sdist count 872, not 871, for the head tree — the base-tree count is 871) is cosmetic and doesn't require a code change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance work: tooling, repo hygiene, no library behaviour change test Pull requests that add or correct tests (test: subject prefix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

examples/captures/pcapng.txt records packet -> NIL for four blocks that now carry octets

1 participant