Skip to content

SWE Pipeline: Automated code improvements for ipfs_dict_chain - #3

Merged
WouterGlorieux merged 17 commits into
mainfrom
swe-pipeline/integration
Jun 14, 2026
Merged

SWE Pipeline: Automated code improvements for ipfs_dict_chain#3
WouterGlorieux merged 17 commits into
mainfrom
swe-pipeline/integration

Conversation

@WouterGlorieux

Copy link
Copy Markdown
Contributor

SWE Pipeline — Automated Code Improvements

This pull request was automatically generated by the SWE Pipeline.

Summary

  • 6 issues fixed: 5 bugs, 1 refactors, 0 enhancements
  • Phase A hygiene applied (lint fixes, type annotations, docstrings)
  • Coverage: 100%
  • Tests: all passing

What changed

See the commit history on the swe-pipeline/integration branch for the full list of changes.

Review

The pipeline performed multiple code reviews and all issues found were addressed. The codebase is at 100% test coverage with a green test suite.


Automatically generated at commit a59b1f6c.

Valyrian SWE Pipeline added 17 commits June 14, 2026 20:44
…-are-incorrect-for-cidv1 into swe-pipeline/integration
…ethods-when-keys-match-method-names into swe-pipeline/integration
…-inconsistent-key-filtering-for-underscore-prefixed-keys into swe-pipeline/integration
…-for-underscore-prefixed-keys-from-previous-state into swe-pipeline/integration
…ict-contains-an-empty-string-key into swe-pipeline/integration
…regex-in-cid-class into swe-pipeline/integration
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ipfs_dict_chain/CID.py 100.00% <100.00%> (ø)
ipfs_dict_chain/IPFS.py 100.00% <100.00%> (ø)
ipfs_dict_chain/IPFSDict.py 100.00% <100.00%> (ø)
ipfs_dict_chain/IPFSDictChain.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@WouterGlorieux WouterGlorieux left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Summary

This PR addresses several concrete bugs and inconsistencies across the ipfs_dict_chain codebase. The changes are well-scoped, each commit targets a single issue, and the fixes are logically coherent. The CID validation regex is corrected to properly handle both CIDv0 and CIDv1 formats, the IPFSDict.__getattribute__ no longer shadows dict methods, key filtering for underscore-prefixed keys is made consistent across items() and changes(), and __setitem__ now explicitly rejects reserved underscore keys. The test suite is also expanded to cover these edge cases. Overall, this is a solid, well-structured PR that meaningfully improves correctness and consistency.

Changes Overview

CID.py — CID validation fix

  • Removed the separate CIDV0_REGEX, CIDV1_REGEX, and MIN_CID_LENGTH class variables that were unused after the fix.
  • Replaced the overly-permissive single regex with a combined regex that enforces CIDv0 (exactly 46 Base58 characters) or CIDv1 (starts with a valid multibase prefix followed by one or more Base58 characters).
  • Removed the redundant minimum-length check in __init__ since the regex now encodes the length requirement directly.

IPFS.py — Documentation and type annotations

  • Added docstrings to _get_loop() and _close_loop().
  • Added return type annotations (-> asyncio.AbstractEventLoop, -> None).

IPFSDict.py — Method shadowing, key filtering, and underscore key protection

  • Added _DICT_METHODS frozenset to IPFSDict listing all standard dict method names.
  • Modified __getattribute__ to bypass the dict-storage lookup for standard dict methods, preventing silent shadowing (e.g., d['items'] = 'x' no longer breaks d.items()).
  • Changed items() key filtering from key[0] != '_' to not key.startswith('_') for correctness with empty-string keys.
  • Added explicit KeyError raise in __setitem__ when a key starts with _, preventing silent corruption of internal state.

IPFSDictChain.py — Consistent underscore key filtering in changes()

  • Extended the skip condition in changes() from key == 'previous_cid' to also skip keys starting with _, matching the filtering in IPFSDict.items().
  • Removed unused add_json import.

tests/test_IPFSDict.py — New test for reserved key rejection

  • Added test_setitem_reserved_key to verify that setting a key starting with _ raises KeyError.

Issues & Concerns

I reviewed each change carefully and found no blocking issues. The fixes are correct, the test coverage is appropriate, and the code quality is good. A few observations for consideration:

  1. CID regex readability — The combined regex on line 14 of CID.py is quite dense. While it works correctly, consider adding a short inline comment explaining the two alternatives (CIDv0: 46-char Base58; CIDv1: multibase prefix + one or more Base58 chars). This would help future maintainers.

  2. Empty string key edge case — The test file includes a test for ipfs_dict[''] = 'empty_value' which works because ''.startswith('_') is False. This is correct behavior, but it's worth noting that an empty string key would be filtered out by items() (since ''.startswith('_') is False but the old code key[0] != '_' would have raised an IndexError). The fix to use startswith elegantly resolves this. Good catch.

  3. Test coverage for CID.py changes — The CID tests (test_CID.py) already cover many edge cases, but I notice there's no explicit test for a valid CIDv1 string (e.g., bafy...). The existing tests use CIDv0-style CIDs. Adding a test_init_valid_cidv1 would be a nice improvement to validate the new regex branch.

  4. IPFS.py docstrings — The docstring additions in IPFS.py are welcome. However, the _close_loop function body is wrapped in # pragma: no cover comments, which means these lines are excluded from coverage. This is reasonable for an atexit handler, but it's worth confirming that the coverage target (100%) is still met — the test suite should be verifying this.

None of these are blocking concerns; they are suggestions for further polish.

Recommendation

Ready to merge — post as COMMENT.

The changes are correct, well-tested, and improve the codebase's correctness and consistency. The commit history is clean and each change is logically isolated. I recommend merging this PR.

@WouterGlorieux
WouterGlorieux merged commit 2dd5fba into main Jun 14, 2026
4 checks passed
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.

1 participant