Skip to content

test: verify Code.tag() returns correct tags for all codecs - #50

Open
sumanjeet0012 wants to merge 1 commit into
multiformats:masterfrom
sumanjeet0012:feature-issue-5-tag-tests
Open

test: verify Code.tag() returns correct tags for all codecs#50
sumanjeet0012 wants to merge 1 commit into
multiformats:masterfrom
sumanjeet0012:feature-issue-5-tag-tests

Conversation

@sumanjeet0012

@sumanjeet0012 sumanjeet0012 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Closes #42.

What was changed:

  • Added a parametrized test test_code_tag_all_categories to tests/test_code.py that verifies the tags of 22 codecs covering all known tags.
  • Added test_no_unknown_tags() to verify that no codec in CODECS returns "<unknown>" as its tag.
  • Fixed multiple unmapped tags in multicodec/code.py (like provenance-log, aes-128, etc.) which caused test_no_unknown_tags to fail, ensuring all 603 codecs have correct recognized tags.

Why the change was needed:

  • The existing tests only checked 4 tags out of 23. This PR increases tag coverage to all categories.
  • Ensures all registered codecs have correct tag metadata.

How it was verified:

  • Verified by running make pr which invokes pytest. All tests pass successfully, confirming that Code.tag() properly maps all codecs in multicodec/constants.py.

@sumanjeet0012
sumanjeet0012 force-pushed the feature-issue-5-tag-tests branch 3 times, most recently from 5abe732 to 54c7c0d Compare July 5, 2026 16:16
Also adds test_no_unknown_tags and fixes unmapped tags.

@acul71 acul71 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI PR Review: #50 — test: verify Code.tag() returns correct tags for all codecs

Reviewer: acul71 (maintainer)
PR: #50
Author: sumanjeet0012
Date: 2026-09-07


1. Summary of Changes

This PR addresses Closes #42: tag tests previously covered only 4 codecs / 4 tags. It adds broader category coverage and ensures no registered codec returns "<unknown>".

Changes:

  • Expands _get_tag() mappings in multicodec/code.py (same six tags as #49, plus many additional name matches across key/libp2p/multiaddr/multiformat/multihash/namespace/serialization/transport)
  • Adds inline assertions for the six previously missing tags in test_code_tag
  • Adds parametrized test_code_tag_all_categories (22 cases covering known tag categories)
  • Adds test_no_unknown_tags() iterating CODECS

Modules/files: multicodec/code.py, tests/test_code.py
Breaking changes / deprecations: None (behavior change: fewer "<unknown>" tags — desirable)


2. Branch Sync Status and Merge Conflicts

Branch Sync Status

  • Status: Ahead of origin/master
  • Details: 0 1 → 0 behind, 1 ahead

Merge Conflict Analysis

No merge conflicts detected. The PR branch can be merged cleanly into origin/master.

Overlap with PR #49

Both PRs modify the same files. PR #50 fully subsumes PR #49’s six-tag additions (multikey, multisig, nonce, shelter, softhash, vlad) and goes further with additional mappings required for test_no_unknown_tags to pass.

Recommendation: Prefer merging #50 (after newsfragment) and closing or superseding #49, rather than merging both sequentially. If both must land, merge #49 first then rebase #50 (expect conflicts in code.py / test_code.py).


3. Strengths

  • Implements the issue’s proposed parametrized coverage + no-unknown invariant
  • Fixes the root cause of "<unknown>" tags beyond the six categories from #37/#49
  • Correct multisig ordering before multihash
  • Local validation: lint, typecheck, 712 tests passed, docs build OK; GitHub CI green

4. Issues Found

Critical

  • File: newsfragments/ (missing)
  • Issue: Missing mandatory newsfragment for issue #42
  • Suggestion: Add newsfragments/42.misc.rst or 42.bugfix.rst describing that Code.tag() coverage/tests ensure all registered codecs map to recognized tags

Major

  • File: tests/test_code.py

  • Line(s): TAG_TEST_CASES / test_code_tag

  • Issue: Duplication: the six new tags are tested both inline in test_code_tag and again via parametrize (plus #49 overlap)

  • Suggestion: Keep parametrized + test_no_unknown_tags as the source of truth; drop redundant inline asserts to reduce maintenance cost

  • File: multicodec/code.py

  • Line(s): Multiformat list includes "multisig" / "multikey" while later branches also return those tags for other names

  • Issue: Easy to misread; the multiformat entries are for codecs literally named multisig/multikey, while chacha20-poly1305 / *-msig use dedicated branches — this matches Go-style dual use but deserves a short comment

  • Suggestion: Add a one-line comment clarifying codec-name vs category-tag matching

Minor

  • File: tests/test_code.py
  • Issue: Parametrized list still samples one codec per category rather than “all 603 codecs” as the issue title suggests; test_no_unknown_tags closes that gap for unknown detection but does not assert the expected tag string per codec against an external oracle
  • Suggestion: Acceptable for #42’s proposed solution; fuller oracle checks belong with #51’s table.csv work if tags are present upstream

5. Security Review

No security concerns. Classification-only changes over static codec tables.


6. Documentation and Examples

No API docs required beyond newsfragment for user-visible tag corrections.


7. Newsfragment Requirement

⚠️ BLOCKER

  • Severity: CRITICAL / BLOCKER
  • Issue: No newsfragments/42.*.rst; PR correctly references Closes #42
  • Suggestion: Add newsfragments/42.bugfix.rst (or .misc.rst) with user-facing note that Code.tag() now returns recognized tags for all registered codecs / expanded categories
  • Action Required: Newsfragment before approval

8. Tests and Validation

Linting (make lint)

  • Exit 0 — all hooks passed

Type Checking (make typecheck)

  • Exit 0 — mypy passed

Test Execution (make test)

  • Exit 0 — 712 passed (up from 689 on master/#49), 0 failed

Documentation Build (make docs-ci)

  • Exit 0 — Sphinx -W succeeded

GitHub CI

  • All tox/windows checks SUCCESS

9. Recommendations for Improvement

  1. Add newsfragment 42.*.rst (blocker)
  2. Coordinate with #49: recommend supersede #49 with this PR (or close #49 after #50 merges)
  3. Deduplicate inline vs parametrized tag assertions
  4. Optional comment on multiformat vs category multikey/multisig names

10. Questions for the Author

  1. Should #49 be closed as superseded by this PR?
  2. Preferred newsfragment type: bugfix vs misc?
  3. Were the additional name mappings (aes-*, provenance-log, silverpine, etc.) cross-checked against go-multicodec Tag()?

11. Overall Assessment

  • Quality Rating: Good
  • Security Impact: None
  • Merge Readiness: Needs fixes (newsfragment; clarify relationship to #49)
  • Confidence: High

Verdict: REQUEST_CHANGES — strong improvement that subsumes #49 and addresses #42, blocked only on newsfragment (and process clarity vs #49).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No test verifying Code.tag() returns correct tags for all 603 codecs

2 participants