Skip to content

refactor(protocols): one home per duplicated RFC-fixed constant (#1739) - #1752

Merged
JarryShaw merged 1 commit into
mainfrom
refactor/1739-rfc-constants-one-home
Oct 15, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
refactor/1739-rfc-constants-one-home

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Please follow the guide below

What is the purpose of your pull request?

Tick the commit type your subject line carries.

  • 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
  • release — bumps the version or rolls up a distribution
  • chore — anything else

Description

Closes #1739, which carries ruling 7 from #1726. Every RFC- or format-fixed constant that was spelled out in more than one module now has one home. That home is the module that owns the protocol, or its schema module, and every other place reads the constant from there. None of them is configurable.

  • Homes:

    • IPv4, IPv6, AH and TCP: the header lengths and offsets, plus IP_MAX_LENGTH;
    • PCAP: the header and record lengths, the magic number and the resolution;
    • PCAP-NG: the byte-order magic, the block minimums and the default resolution.

    Each home carries versionadded:: 1.5.0 and an autodata entry.

  • No re-exports (refactor(corekit)!: move the byte-order field helpers into corekit (#1711) #1715, docs: #719-style prose sweep after the #1090–#1102 defect wave #1103): the old spellings are deleted. None of them shipped in 1.4.x, so they get no versionremoved.

  • Guard, tests/project/test_rfc_constants_one_home_1739_unit.py: sweeps protocols, foundation, toolkit and dumpkit for every integer literal with a homed value, wherever it appears. Only the homes' own definitions are skipped. Every hit that is not a copy is allowlisted with a reason: 490 hits, 0 offenders.

  • Edge test, tests/foundation/reassembly/test_ip_max_length_edge_1739_unit.py: pins IP_MAX_LENGTH as a strict bound.

Tests, narrow runs on Python 3.14:

  • the five *_1739_unit.py files plus test_unit_tests_queue.py: 69 passed, 675 subtests;
  • tests/foundation/reassembly: 134 passed.

Out of scope: the dpkt engine's loopback address-family keys repeat Loopback.__proto__. Those numbers are set by the operating systems, not by an RFC, so they are not covered by #1739.

Ruling 7 on #1726: an RFC- or format-fixed constant spelled out in more
than one module is defined once, in the module that owns the protocol
(or its schema or const module), and is never configurable.

- IP/IPv4/IPv6/AH/TCP: IPV6_HEADER_LEN and IPV6_NEXT_HEADER_OFFSET live
  in protocols.internet.ipv6; IPV4_HEADER_LEN, AH_HEADER_LEN,
  TCP_MIN_HEADER_LEN, TCP_DATA_OFFSET_OCTET and IP_MAX_LENGTH in their
  schema modules, which spelled them too and cannot import the protocol
  modules; the toolkit, reassembly and schema copies are gone.
- PCAP: GLOBAL_HEADER_LEN, MAGIC_NUMBER, RESOLUTION, RESOLUTION_PLACES
  in schema.misc.pcap.header and RECORD_HEADER_LEN in schema.misc.pcap
  .frame, read by the protocols and the pcap/pypcapfile/scapy engines.
- PCAP-NG: BYTE_ORDER_MAGIC, BLOCK_MINIMUM, GENERIC_BLOCK_MINIMUM and
  DEFAULT_RESOLUTION live in schema.misc.pcapng; the engine tables are
  removed, and every block length derives from the two minimum tables.
- No old home re-exports a name; none shipped in 1.4.x, so no
  versionremoved. Each new home has versionadded 1.5.0 and autodata.

The guard sweeps protocols, foundation, toolkit and dumpkit for every
integer literal of a homed value, wherever it sits -- operand, default,
tuple, table, conditional or assignment at any level -- skipping only
the homes' own definitions, and allowlists each non-copy with a reason.
A reassembly test pins IP_MAX_LENGTH as a strict bound at its edge: a
Total Length 0 datagram of exactly 65,535 octets does not grow the
buffer, so a declared final fragment past it still never completes.

Closes #1739
@JarryShaw JarryShaw added the refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix) label Oct 15, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 15, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Verdict: GOOD TO GO at 9155375a6. A Sonnet cross-review (author: Opus) ran over four rounds.

  • Round 4 blocker, now fixed: the guard's sweep depended on where a literal sat, so copies placed as a default argument, a tuple member, a conditional branch or a table entry went unflagged. It now flags every homed integer literal wherever it appears. The reviewer's own scan, written independently of the guard, matched the guard's 490 hits line for line.
  • Mutants, all 41 killed: M1–M12, R1–R12, N1–N12 and X13–X17, plus 16 placements the reviewer added (negative and hex literals, keyword and lambda defaults, comprehensions, annotations and others). M11 is killed by the new IP_MAX_LENGTH edge test, not written off as equivalent.
  • Allowlist: 12 reasons spot-checked against the code, and all of them match.
  • Non-blocking notes:
    • the commit body runs about 22 lines;
    • a copy placed outside the four swept trees would not be caught, and none exists today.
  • My own check: the five *_1739_unit.py files plus test_unit_tests_queue.py give 69 passed and 675 subtests, with pcapkit.__file__ printed inside the PR's worktree.

@JarryShaw JarryShaw added the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 89.59% (unit tier, Python 3.15, 9155375a6, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 3 20 3 95.16%
pcapkit/const 18860 954 2368 868 91.06%
pcapkit/corekit 2457 69 780 35 96.54%
pcapkit/dumpkit 276 3 100 3 98.40%
pcapkit/foundation 2915 164 1016 34 93.59%
pcapkit/interface 138 7 52 5 93.68%
pcapkit/protocols 17186 224 4574 189 98.08%
pcapkit/toolkit 872 177 298 8 77.18%
pcapkit/utilities 512 2 158 4 99.10%
pcapkit/vendor 4417 2342 1010 157 43.38%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit 3946bf5 into main Oct 15, 2026
55 of 56 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 15, 2026
@JarryShaw
JarryShaw deleted the refactor/1739-rfc-constants-one-home branch October 15, 2026 01:43
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

refactor(protocols): one home per duplicated RFC-fixed constant (#1726 ruling 7)

1 participant