Repository navigation
Tell the state detector which reader doctor is on - #16
Merged
Merged
Conversation
doctor built its card session without the resolved reader name, so is_contactless_interface saw only the ATR. Readers synthesise the PC/SC composed contactless ATR for ISO 14443 cards, but a card answering with its own wired-style ATR leaves the reader name as the only evidence - and without it the DESFire probe recommends a contactless reader to an operator already on one, the exact misdirection state/detector.py:248-252 describes. The detector tests could not catch this: they build CardSession themselves and pass reader_name, and the contactless case uses the composed ATR, which satisfies the ATR signal alone. The new tests drive the command, patch PC/SC at the module boundary, and use a wired-style ATR so the name is the only signal under test. A contact-reader control asserts the other direction is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tell the state detector which reader
doctoris ondoctorbuilt its card session without the resolved reader name, so the DESFire diagnosisran on the ATR alone and could recommend a contactless reader to someone already using one.
Changes
doctorpassesreader_name=tomake_session.tests/unit/test_doctor_reader_name.py: three tests driving the real command.Constraints
Both signals are needed.
is_contactless_interfaceaccepts either the reader name or aPC/SC composed contactless ATR (
3B 8x 80 01 ...). Readers synthesise that ATR for ISO 14443cards, but a card answering with its own wired-style ATR leaves the reader name as the only
evidence. With the name dropped, such a session looks like contact and
DesfireState.NEEDS_CONTACTLESS_READERwins, which is the inverted advice. The comment atstate/detector.py:248-252already describes this failure mode; the session simply was notcarrying what it needed.
The existing detector tests cannot catch this.
test_state_detector.pyconstructsCardSessiondirectly and passesreader_nameitself, so it never exercises howdoctorbuilds one. Its contactless case also uses the composed
3B 80 80 01 ...ATR, whichsatisfies the ATR signal alone and would pass with or without the name. The new tests use a
wired-style ATR so the reader name is the only thing under test, and patch
reader_states,pick_readerandconnectin thedoctormodule namespace rather than anything insidedoctoritself.A control test guards the other direction. On a genuine contact interface the
contactless advice is correct, and a test asserts it still appears. It passes both before and
after this change, so the pair discriminates rather than merely failing.
Verification
ruff check,ruff format --check,mypy,sphinx-build -W --keep-goingpass. The suitegoes 347 to 350 tests. Before the fix, two of the three new tests fail and the control passes.
Coverage of
cli/commands/doctor.pyrises from 11% to 55%.Note for whoever merges second
Touches
CHANGELOG.mdunder Unreleased, as do #13 and #14. The entries are independent andany conflict is textual.
🤖 Generated with Claude Code