Repository navigation
chore: generate pyshark's encap-type and filter-name maps from a util script - #853
Conversation
|
Three legs failed, and the root cause is a genuine finding rather than a code defect: the tests are pinned The versions, from the job log and my host: The script behaved exactly as designed. It refused to rewrite the table when the sweep disagreed with the What is wrong is
(1) is honest about what is being pinned; (2) is weaker but survives an upgrade. Doing (1) as the fix, with A consequence worth stating even though it is not a defect: the committed tables describe 4.6.9's 226 |
|
NEEDS CHANGES on 1. Rebase onto current But this is textual, not behavioural — I checked, and the reviewer's framing overstates it. On current
2. The docstring's trap numbers do not reproduce — and they are my error, inherited from #851's body.
646 was unique tokens under a 3. 4. My own finding from CI: On the gate design, the reviewer disagrees with the approach and I think it is right. Two things confirmed clean and worth recording: idempotence survives perturbation — reversed order, |
|
Correcting my own root cause: there are two defects here, not one. I said earlier the three red legs were
Every failure is in Defect 2, new and unrelated to Wireshark:
Fix: use Worth noting how close this came to being missed. Both 3.10 failures sit in Both defects are now with the worker. |
…il script - Add util/pyshark_encap_map.py: sweeps every editcap -T encapsulation, writes it as pcap from examples/captures/in.pcap, reads the DLT from the file's own header and frame.encap_type back via tshark PDML, and rewrites ENCAP_TYPE_TO_LINKTYPE/FILTER_NAME_TO_LINKTYPE in pcapkit/toolkit/pyshark.py in place. Evicts any editable-install finder and pins sys.path to this checkout before importing LinkType, so the sweep cannot silently measure against a different tree's registry. - Extracts the PDML showname's trailing number with a regex anchored to the end of the string, and parses editcap -T's own help listing by the "<token> - <desc>" line shape, so neither of its two banner lines is miscounted as a token. - Excludes a DLT with no LinkType member and an ambiguous filter name, checking against the registry's genuinely-registered values up front so LinkType's own _missing_ cannot mint a placeholder member as a side effect of the check (#575). Rebased onto #848 (I2C_LINUX canonical for DLT 209): regenerating now correctly prefers it over the legacy IPMB_LINUX alias. - Asserts the sweep arithmetic (226 accepted, 157 writable, 69 refused) only against the Wireshark version it was measured on (MEASURED_WIRESHARK_VERSION = 4.6.9); skips cleanly when tshark/editcap are absent or on a different version, since CI's packaged Wireshark (Ubuntu noble, 4.2.2) accepts 224. - Add tests/project/test_pyshark_encap_map.py: version-independent invariants (no key/DLT ambiguity, agreement with the committed table) run on whatever Wireshark is on PATH; the exact-count sweep is gated on HAS_WIRESHARK, a NON_DISTRIBUTION_FLAGS entry in tests/_dependency_gates.py (a binary, not a pip distribution) plus the pinned version, so the gap is visible rather than silently dark. 3.10-safe (no TestCase.enterContext, 3.11+ only). - Verified: regenerating against the rebased tree reproduces pcapkit/toolkit/pyshark.py byte-identically on a second run (md5 c9ec0f6952da3be0c07f13e6a49e06d0 before and after --check); one legitimate line changes from origin/main (IPMB_LINUX -> I2C_LINUX, textual only, same aliased member); tests/test_tier_guard.py is green (102 passed, plain unittest cross-check OK); py_compile clean on Python 3.10.
4e5a31a to
7f42887
Compare
|
All four rounds of feedback cleared. Head
Two things the worker found that are worth keeping: It hit the editable-install trap inside its own generator.
One honest UNVERIFIED, which I am carrying rather than smoothing over: the 3.10 compatibility claim rests on |
|
GOOD TO GO on The description's four falsehoods, each re-measured by me before I touched it:
It also never mentioned What the review established beyond the previous round:
Three non-blocking observations recorded rather than acted on: |
Adds util/pyshark_encap_map.py, a generator that regenerates ENCAP_TYPE_TO_LINKTYPE (152 entries) and FILTER_NAME_TO_LINKTYPE (58) in place inside pcapkit/toolkit/pyshark.py, so the two tables #850 hand-built stop being hand-maintained. Guards against its own worst failure mode: a naive LinkType(dlt) lookup cannot detect an unmapped DLT, because _missing_ mints a placeholder rather than raising, so the generator snapshots every known value before any lookup. The real-tshark sweep is gated on a new HAS_WIRESHARK flag and is version-pinned -- editcap -T accepts 226 encapsulations on Wireshark 4.6.9, 224 on 4.2.2 (CI's Ubuntu noble) -- so the count assertions run only under the measured version. One line of pyshark.py itself changes as a result: the IPMB_LINUX table entry becomes I2C_LINUX, the canonical name #848 gave value 209. util/changelog_md.py regenerated CHANGELOG.md for all seven entries added across this and the six preceding commits (#838, #846, #847, #848, #849, #850, #853); `--check` exit 0.
#846 and #850 - #838's "the 21 whose vendor crawler leaves Vendor.process() unmodified" measures 22, not 21 -- pcapkit.const.hip.transport.Transport also has an unmodified process(), but its FLAG-bound range has no unassigned gap, so its _missing_ carries no bounded-range extend_enum branch to fix. The real discriminator is that branch, not the process() override; reworded, and the "other 84" split into the 83 that do override process() and the one that doesn't but has nothing to fix either. Re-derived independently against 5e25db2^..5e25db2 (not main, which would fold in #847's own edit to ipx/socket.py): 22 registries have no process() override, 21 of them have the bounded-range branch, matching tests/const/test_const_enum_no_mint.py's own REGISTRIES_WITH_UNASSIGNED_RANGES (21 entries) vs ALL_REGISTRIES (22, +hip.transport, with a NOTE explaining the exclusion). - #846's "Only tests/integration/test_engine_runtime.py and test_engine_parity.py change" is false -- 30bca99's own numstat also touches .github/workflows/unit-tests.yml (17+/2-). Qualified to "only these two test files change". - #850 gets the breaking marker: its own prose already says the fallback is gone and an unrecognised encapsulation or filter name now raises MissingKeyError instead of substituting a plausible DLT -- the same shape as the two existing markers at AppType.get (1.5.0.rst:2456) and the four .get()-backed enum fields (1.5.0.rst:2720). Restructured to lead with the marker and the subject, matching their wording and placement; the later restatement of the same fact is dropped. None of these are code or test changes -- prose only, matching the cross-review's own framing. #848 stays unmarked (its own "Not breaking" paragraph holds); #838, #849 and #853 stay unmarked per explicit instruction not to add markers beyond what was asked.
Adds util/pyshark_encap_map.py, a generator that regenerates ENCAP_TYPE_TO_LINKTYPE (152 entries) and FILTER_NAME_TO_LINKTYPE (58) in place inside pcapkit/toolkit/pyshark.py, so the two tables #850 hand-built stop being hand-maintained. Guards against its own worst failure mode: a naive LinkType(dlt) lookup cannot detect an unmapped DLT, because _missing_ mints a placeholder rather than raising, so the generator snapshots every known value before any lookup. The real-tshark sweep is gated on a new HAS_WIRESHARK flag and is version-pinned -- editcap -T accepts 226 encapsulations on Wireshark 4.6.9, 224 on 4.2.2 (CI's Ubuntu noble) -- so the count assertions run only under the measured version. One line of pyshark.py itself changes as a result: the IPMB_LINUX table entry becomes I2C_LINUX, the canonical name #848 gave value 209. util/changelog_md.py regenerated CHANGELOG.md for all seven entries added across this and the six preceding commits (#838, #846, #847, #848, #849, #850, #853); `--check` exit 0.
#846 and #850 - #838's "the 21 whose vendor crawler leaves Vendor.process() unmodified" measures 22, not 21 -- pcapkit.const.hip.transport.Transport also has an unmodified process(), but its FLAG-bound range has no unassigned gap, so its _missing_ carries no bounded-range extend_enum branch to fix. The real discriminator is that branch, not the process() override; reworded, and the "other 84" split into the 83 that do override process() and the one that doesn't but has nothing to fix either. Re-derived independently against 5e25db2^..5e25db2 (not main, which would fold in #847's own edit to ipx/socket.py): 22 registries have no process() override, 21 of them have the bounded-range branch, matching tests/const/test_const_enum_no_mint.py's own REGISTRIES_WITH_UNASSIGNED_RANGES (21 entries) vs ALL_REGISTRIES (22, +hip.transport, with a NOTE explaining the exclusion). - #846's "Only tests/integration/test_engine_runtime.py and test_engine_parity.py change" is false -- 30bca99's own numstat also touches .github/workflows/unit-tests.yml (17+/2-). Qualified to "only these two test files change". - #850 gets the breaking marker: its own prose already says the fallback is gone and an unrecognised encapsulation or filter name now raises MissingKeyError instead of substituting a plausible DLT -- the same shape as the two existing markers at AppType.get (1.5.0.rst:2456) and the four .get()-backed enum fields (1.5.0.rst:2720). Restructured to lead with the marker and the subject, matching their wording and placement; the later restatement of the same fact is dropped. None of these are code or test changes -- prose only, matching the cross-review's own framing. #848 stays unmarked (its own "Not breaking" paragraph holds); #838, #849 and #853 stay unmarked per explicit instruction not to add markers beyond what was asked.
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
chore— anything elseDescription of your pull request and other information
Closes #851. Adds
util/pyshark_encap_map.py, which regeneratesENCAP_TYPE_TO_LINKTYPE(152 entries) andFILTER_NAME_TO_LINKTYPE(58) in place inpcapkit/toolkit/pyshark.py, so they stop being hand-maintained.Per your ruling on #850 — "They may exist in toolkit still - if generated by scripts" — the tables stay
where they are; only their provenance changes.
util/rather thanpcapkit/vendor/becauseVendor._dest_path()is hardwired topcapkit/const/,Vendor.context()emits a whole enum class file, andVendor.request()is an HTTP fetch, whereas this generator's source of truth is the localtshark/editcapbinaries.
4 files, +1359/−1.
pcapkit/toolkit/pyshark.pyis modified by exactly one line — theIPMB_LINUX→I2C_LINUXrename that #848 made canonical for value 209. Textual only: they are the same member(
LinkType.IPMB_LINUX is LinkType.I2C_LINUX), soENCAP_TYPE_TO_LINKTYPE[112]is 209 before and after.The
HAS_WIRESHARKgate — the part an earlier draft of this PR got backwardsThe real-sweep tests need
tsharkandeditcap. Those were first guarded by unprefixedshutil.whichconstants, on the theory that avoiding the
HAS_*prefix avoided thetests/_dependency_gates.pyscan thatcost #848 ten CI legs. That was the defect, not the fix: it made the scan blind to two classes skipping on
every leg. This head declares
HAS_WIRESHARKproperly and registers it inNON_DISTRIBUTION_FLAGS(
tests/_dependency_gates.py:240), next toHAS_PROC_FD— the bucket for "asks about something pip cannotinstall at all".
dependency_gate_gaps()returns no gap for it; CI installstsharkat.github/workflows/unit-tests.yml:379and:469, which pullswireshark-commonforeditcap.The version gate, because the sweep arithmetic is version-pinned
editcap -Taccepts 226 encapsulations on Wireshark 4.6.9 (this host) and 224 on 4.2.2 (CI's Ubuntunoble). The count assertions therefore run only when
detect_tshark_version()reports exactlyMEASURED_WIRESHARK_VERSION = '4.6.9'; every mismatch and every parse failure lands on one named skip.VersionIndependentInvariantTestscarries the checks that hold at any version, so CI is not left assertingnothing.
Verification on head
7f42887f8Also confirmed on a real Python 3.10.21 interpreter (CI's floor leg), because an earlier head used
unittest.TestCase.enterContext, which is 3.11+: all 29 tests pass there, withhasattr(unittest.TestCase, 'enterContext') is Falseprinted from that same interpreter.The bug the generator had to work around, which is the most valuable part
A naive
try: LinkType(dlt) except ValueErrorcannot detect an unmapped DLT, becauseLinkType._missing_mints a placeholder
Unassigned_Nmember rather than raising. The first lookup of DLT 121 would haveminted
Unassigned_121and written it straight into the table. Fixed by snapshottingknown_values = frozenset(member.value for member in linktype)before any lookup, soLinkType(dlt)isonly ever called once that has already said yes. Pinned by
BuildTablesExclusionTests.test_an_unmapped_dlt_is_left_out_and_noted.Both traps from #851 are covered: a
shownamecontaining/(ParseParenthesisedNumberTests) and theeditcap -Tbanner tokens (ListEncapTypesTests, including a fabricated fake-binary round trip).Caveats
make pylintandmake mypycoverpcapkit/only, so no lint or type gate applies toutil/ortests/here.
isort --check-only -l100 -ppcapkitis clean on both new files.note:lines rather than dropped silently (user_dlt,bluetooth,usb,usbll,raw,arcnet,gfp,i2c,lapd,mtp2,netanalyzer,null,ppp,sll,wlan,wpan), matching the exclusionspyshark.py's own comments already document.VersionIndependentInvariantTestshas never executed on 4.2.2, the version it exists to compensate for.Its invariants are closed under taking subsets of measurements, so 224 ⊂ 226 should pass; the CI leg
settles it.