Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #282 +/- ##
==========================================
+ Coverage 94.49% 94.62% +0.12%
==========================================
Files 49 49
Lines 4163 4203 +40
==========================================
+ Hits 3934 3977 +43
+ Misses 229 226 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
A moderate formatting issue can still raise IndexError, and the CCSDS fallback paths lack regression coverage.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes unrecognized-packet handling for XTCE definitions without PKT_APID, preserving partial_data and improving diagnostics.
Changes:
- Removes the hard dependency on
PKT_APID. - Adds APID/header diagnostics where available.
- Adds regression tests and a changelog entry.
File summaries
| File | Summary |
|---|---|
tests/unit/test_xtce/test_definitions.py |
Adds regression coverage. Nit (1 vote): missing coverage for the CCSDSPacketBytes fallback header path. |
space_packet_parser/xtce/definitions.py |
Updates exception construction. Moderate (3 votes): short CCSDSPacketBytes may raise IndexError while formatting. Nit (2 votes): the CCSDS fallback lacks regression coverage. |
CHANGELOG.md |
Documents the fix. |
Review details
Suppressed comments (1)
tests/unit/test_xtce/test_definitions.py:710
- The new
elifpath that appends a CCSDS header whenPKT_APIDis absent is not covered: the no-APID regression passes plainbytes, while this test uses a parsedPKT_APIDand exercises the preceding branch. Please add a case using aCCSDSPacketBytesinput with a non-CCSDS definition and assert the header text is included, so this advertised diagnostic behavior is protected.
def test_parse_bytes_unrecognized_packet_reports_apid(test_data_dir):
"""Test that an unrecognized CCSDS packet still reports its APID in the UnrecognizedPacketTypeError message"""
xdef = definitions.XtcePacketDefinition.from_xtce(test_data_dir / "test_xtce.xml")
# APID 2047 is not defined in test_xtce.xml
unknown_apid_packet = space_packet_parser.generators.ccsds.create_ccsds_packet(
data=bytes(65), apid=2047, sequence_flags=space_packet_parser.generators.ccsds.SequenceFlags.UNSEGMENTED
)
with pytest.raises(UnrecognizedPacketTypeError, match="APID=2047") as exc_info:
xdef.parse_bytes(unknown_apid_packet)
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
medley56
left a comment
There was a problem hiding this comment.
Fix is correct and minimal. The KeyError path from #276 is gone, partial_data is populated on every raise, and the CCSDS message now names the abstract container as well as the APID. Both new tests pass and CI is green on all 20 checks. Two things stand before merge: CHANGELOG.md conflicts with #290 which landed on main after this branch was cut, and the two open Copilot threads are both valid (I reproduced the IndexError on a short CCSDSPacketBytes; the fallback branch is Codecov's one uncovered line).
Severity tally: 0 critical, 1 warning, 1 suggestion, 1 nitpick.
🤖 AI-assisted comment, reviewed and approved by @medley56 before posting.
The abstract-container-with-no-valid-inheritors error path built its message by subscripting packet['PKT_APID']. XTCE has no notion of the CCSDS standard, so definitions without that parameter got a KeyError from inside exception construction instead of the documented UnrecognizedPacketTypeError, and partial_data was lost with it. Name the abstract container in the message, report the APID only when the packet actually has one (falling back to the CCSDS header printout when the bytes are CCSDSPacketBytes), and add regression tests for both the non-CCSDS and CCSDS cases. Closes #276 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
str(CCSDSPacketBytes) indexed all six primary header bytes, so a shorter input raised IndexError. That made the CCSDS header printout unsafe to use in diagnostic messages, including the new UnrecognizedPacketTypeError fallback and the existing trailing-bits warning. Render the available bytes instead when the input is short. Add a regression test for the CCSDSPacketBytes fallback branch in parse_bytes with a definition that has no PKT_APID parameter, and share the no-CCSDS test definition between the tests that use it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
25a1942 to
53af2bd
Compare
The docstring said the error is raised when the packet type cannot be determined "based on the header". The error is raised when no or multiple inheritors match by restriction criteria, which does not depend on a header being present. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Closes #276
Problem
When an abstract container had no valid inheritors,
parse_bytesbuilt theUnrecognizedPacketTypeErrormessage by subscriptingpacket['PKT_APID']. XTCE has no notion of the CCSDS standard, so any definition without a parameter literally namedPKT_APIDraisedKeyErrorwhile constructing the exception. The documentedexcept UnrecognizedPacketTypeErrorpattern silently stopped working andpartial_datawas lost.Fix
PKT_APIDvalue. If it does not, but the bytes areCCSDSPacketBytes, the CCSDS header printout is appended instead (same approach as the existing trailing-bits warning). Otherwise the message simply omits APID information.partial_datais populated in every case.CCSDSPacketBytes.__str__no longer raisesIndexErrorfor inputs shorter than the six-byte primary header. It renders the bytes it has (CCSDSPacket Header: (incomplete, 1 of 6 bytes: 07)), so the header printout is safe to use in diagnostic messages, including the pre-existing trailing-bits warning. Construction is unchanged.I scanned the package for sibling CCSDS-naming assumptions on error paths. This was the only
PKT_APIDsubscript; the only other CCSDS field names outside thegenerators.ccsdsmodule are the CLI display headers, which read fromCCSDSPacketBytesrather than parsed parameters.Tests
test_parse_bytes_unrecognized_packet_without_pkt_apid: the reproduction from the issue. Asserts the intended exception type, that the message does not claim an APID, and thatpartial_datacarries the parsedCOUNTER.test_parse_bytes_unrecognized_packet_reports_apid: a CCSDS packet with an undefined APID still getsAPID=...in the message and inpartial_data.test_parse_bytes_unrecognized_packet_ccsds_bytes_without_pkt_apid: theCCSDSPacketBytesfallback branch, with a full header and with a single byte.test_ccsds_packet_bytes_str_short_input:str(CCSDSPacketBytes)on fewer than six bytes.Full suite: 485 passed.
ruff checkandruff format --checkclean. Changelog entry added under Unreleased.🤖 Generated with Claude Code