Skip to content

fix(foundation): keep format='pcap' when an unavailable engine falls back to the default one (#1264) - #1430

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1264-pcap-format-not-downgraded
Oct 8, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1264-pcap-format-not-downgraded

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

Closes #1264

Extractor.__init__ swapped format='pcap' for 'json' from the requested engine name; run() only later found the engine unavailable and ran the default PCAP engine. The availability check now lives in _select_engine(), which __init__ calls before the format and trace-format guards, so both follow the engine that runs. Each fallback still warns once.

Probe (examples/captures/test.pcap, format='pcap'/'cap', Python 3.14): pypcap, pcap_ct (not installed), pyshark, pypcapfile (unsupported) wrote out.json before and now write out.pcap, byte-identical to the input. dpkt/scapy, which do run, still get out.json plus the FormatWarning.

tests/foundation/test_extraction.py::_traced now patches _select_engine out alongside run; it pinned the guard firing for engines that can't run on this host. The FormatWarning text now names the lowercased engine (engine=dpkt, not engine=DPKT), as the trace one already did.

New test_extraction_engine_fallback_format_unit.py: 4 passed / 28 subtests with the fix; 29 failed, 3 passed without it.

…back to the default one (#1264)

Extractor replaced format='pcap' with 'json' from the requested engine
name, before run() found that engine missing and ran the default PCAP
engine, so out.json was written where out.pcap was asked for. The trace
format guard had the same flaw.

- Factor the availability check out of run() into _select_engine(), and
  call it in __init__ before the format decisions, so both follow the
  engine that actually runs. A second call is silent, so each fallback
  still warns once.
- The FormatWarning now names the normalised engine, as the trace one does.
- test_extraction._traced patches _select_engine out with run, so its
  dict-frame cases keep testing the guard on hosts missing those engines.

Tests: new test_extraction_engine_fallback_format_unit.py (fails without
the fix: 29 failed, 3 passed); foundation/interface modules and the
foundation unittest leg pass.
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 8, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Verdict: GOOD TO GO at 5d86ceca6 (Sonnet cross-review; the author ran on Opus).

  • Re-derived by me using test.pcap with format='pcap' and an engine that is not installed:
    • On main, pypcap and pcap_ct write out.pcap.json and raise FormatWarning + EngineWarning.
    • On this head they write out.pcap, byte-identical to the input, with only EngineWarning.
  • Reviewer, unsupported engines: on 3.14, pyshark and pypcapfile behave the same way. dpkt and scapy are installed and still give json with a FormatWarning, unchanged. An unknown engine is unchanged.
  • One warning per fallback: calling _select_engine() again adds nothing, and extract() gives exactly one EngineWarning.
  • Side effects, none of them breaking:
    • trace_format now follows the engine that runs, and the new test_trace_format_is_kept covers it.
    • The warning text is now engine=dpkt. The only pin, test_extraction_pcap_output_unit.py:103, does not include the engine name.
    • Engine warnings now fire before FileNotFound.
  • Edited _traced helper: the change is legitimate. Its six subtests assert only the format guard, and the real path is still covered end to end.
  • Tests:
    • With only extraction.py reverted, 29 fail.
    • 66 foundation/interface/project modules plus 13 cli/integration modules pass.
    • The foundation leg runs 526 tests with 0 failures.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Coverage: 89.45% (unit tier, Python 3.14, 5d86ceca6, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18791 968 2352 869 90.90%
pcapkit/corekit 2038 89 634 25 94.76%
pcapkit/dumpkit 234 2 84 2 98.74%
pcapkit/foundation 2643 98 930 48 94.79%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 16615 221 4474 185 98.04%
pcapkit/toolkit 539 74 168 3 84.58%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2342 1006 157 43.25%

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

@JarryShaw
JarryShaw merged commit 6aca029 into main Oct 8, 2026
63 of 65 checks passed
@JarryShaw
JarryShaw deleted the fix/1264-pcap-format-not-downgraded branch October 8, 2026 22:26
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 8, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(foundation): format='pcap' is downgraded to json when a requested engine is unavailable and the default engine runs

1 participant