Skip to content

fix/bug hunt critical fixes#292

Open
gbrennon wants to merge 13 commits into
mainfrom
fix/bug-hunt-critical-fixes
Open

fix/bug hunt critical fixes#292
gbrennon wants to merge 13 commits into
mainfrom
fix/bug-hunt-critical-fixes

Conversation

@gbrennon

Copy link
Copy Markdown
Contributor
  • chore(release): bump version to 1.0.0
  • Revert "chore(release): bump version to 1.0.0"
  • fix(foundation): prevent FieldErrors iterator exhaustion on has_errors check
  • fix(infrastructure): consolidate InMemoryRepository diamond init storage assignment
  • fix(foundation): add auto_freeze to foundation package exports and all
  • test(infrastructure): add missing assertion after message bus query dispatch

gbrennon added 9 commits July 22, 2026 04:31
…s check

The  method was calling  then checking
, which tested the now-exhausted iterator instead of
the materialized tuple. Replaced with  — the
already-materialized errors tuple — avoiding silent false negatives
when a field has errors.
…age assignment

The cooperative super() chain in the InMemoryRepository diamond hierarchy
(double-inheriting InMemoryReadRepository and InMemoryWriteRepository)
caused _storage to be set twice: once by super().__init__() and once
by the subclass. Consolidated to a single assignment after super().__init__,
removing the fragile dependency on statement ordering.
…all__

auto_freeze was importable from its submodule but not re-exported
from the foundation package, unlike auto_eq and auto_hash which were
already in __all__. This caused 4 doc examples using the canonical
import 'from forging_blocks.foundation import auto_freeze' to break.
Added both the import and __all__ entry.
…ispatch

The test_dispatches_and_returns_result test called bus.dispatch(query)
but never assigned or asserted the return value, making the test pass
regardless of dispatch behavior. Added result assignment and equality
assertion to verify correct dispatch output.

Copilot AI 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.

Pull request overview

This PR applies targeted fixes and small API/test improvements across the Forging Blocks toolkit’s foundation and infrastructure layers, focusing on correctness and reliability in common building blocks (errors, repositories, and the in-memory message bus).

Changes:

  • Improves FieldErrors construction by avoiding iterator exhaustion when validating provided errors.
  • Adjusts InMemoryRepository initialization to ensure a single, explicit storage assignment for the composed read/write repository.
  • Exposes auto_freeze via forging_blocks.foundation and strengthens message-bus query dispatch test assertions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/forging_blocks/infrastructure/message_bus/test_in_memory_message_bus.py Adds an assertion ensuring query dispatch returns the handler’s result.
src/forging_blocks/infrastructure/repositories/in_memory_repository.py Refactors storage initialization for the combined in-memory repository.
src/forging_blocks/foundation/errors/field_errors.py Prevents iterator exhaustion by validating against the materialized error sequence.
src/forging_blocks/foundation/init.py Re-exports auto_freeze at the foundation package boundary.

Comment on lines +30 to 33
if not self._errors or not field:
raise ValueError("FieldErrors must contain at least one error and field defined.")

message = ErrorMessage(f"{len(self._errors)} error(s) for field '{field}'.")

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment on lines +41 to +42
super().__init__()
self._storage: dict[TId, TEntity] = dict(storage) if storage is not None else {}
"""Write bytes to a file, creating parent directories."""
target = Path(path)
target.parent.mkdir(parents=True, exist_ok=True)
await asyncio.to_thread(lambda: target.parent.mkdir(parents=True, exist_ok=True))
Comment on lines 33 to 35
Raises:
urllib.error.HTTPError: On HTTP 4xx/5xx responses.
urllib.error.URLError: On network/connection failures.
OSError: On network or connection failures.
ConfigurationError: On misconfigured URLs (e.g., non-HTTP schemes).

@personal-reviewer personal-reviewer 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 Code Review

Verdict: Changes Requested

The PR makes several important improvements including adding auto_freeze, improving test coverage, and fixing potential iterator exhaustion issues. However, security risks in file system operations and potential test compatibility issues from exception type changes require attention. The code generally follows good practices in async handling and module exports.

Issues

  1. [security] [MINOR] src/forging_blocks/infrastructure/file_system/os_file_system.py

Path input validation is missing in read/write operations. User-provided paths could lead to security risks if not properly sanitized.

Current:

async def read(self, path: Path | str) -> bytes:
        async def write(self, path: Path | str, data: bytes) -> None:
            """Write bytes to a file, creating parent directories."""
            target = Path(path)
            await asyncio.to_thread(lambda: target.parent.mkdir(parents=True, exist_ok=True))
            await asyncio.to_thread(target.write_bytes, data)

Suggested:

async def read(self, path: Path | str) -> bytes:
        path = Path(path).resolve()
        if not path.is_absolute():
            raise ValueError("Path must be absolute")
        async def write(self, path: Path | str, data: bytes) -> None:
            """Write bytes to a file, creating parent directories."""
            target = Path(path).resolve()
            if not target.parent.exists():
                target.parent.mkdir(parents=True, exist_ok=True)
            await asyncio.to_thread(target.write_bytes, data)
  1. [testability] [MINOR] src/forging_blocks/infrastructure/http_client/urllib_client.py

Exception type change from specific urllib errors to generic OSError may break existing test assumptions and reduce testability.

Current:

Raises:
-        urllib.error.HTTPError: On HTTP 4xx/5xx responses.
-        urllib.error.URLError: On network/connection failures.
+        OSError: On network or connection failures.

Suggested:

Raises:
-        urllib.error.HTTPError: On HTTP 4xx/5xx responses.
-        urllib.error.URLError: On network/connection failures.
+        urllib.error.HTTPError: On HTTP 4xx/5xx responses.
+        urllib.error.URLError: On network/connection failures.
+        # Note: These exceptions are preserved for compatibility with existing test expectations.

Praise

  • src/forging_blocks/foundation/init.py: Properly added auto_freeze to all exports, maintaining consistent module interface and improving type safety.

  • tests/forging_blocks/infrastructure/message_bus/test_in_memory_message_bus.py: Improved test coverage by adding assertion for dispatch result, ensuring correct handler behavior is validated.

  • src/forging_blocks/infrastructure/file_system/os_file_system.py: Correctly uses asyncio.to_thread for blocking operations, maintaining async compatibility while handling file system operations.

Suggestions

No suggestions to apply.


Reviewed by code-review:latest

@personal-reviewer personal-reviewer 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 Code Review

Verdict: Approved

The changes adhere to SOLID principles, improve type safety, and address resource management concerns. All modifications are well-documented and include necessary test assertions. No critical issues were found.

Issues

No issues found.

Praise

  • src/forging_blocks/foundation/init.py: Properly updated all with auto_freeze and included the necessary import, maintaining module consistency.

  • src/forging_blocks/infrastructure/file_system/os_file_system.py: Correctly uses asyncio.to_thread for blocking filesystem operations, ensuring async compatibility.

  • tests/forging_blocks/infrastructure/message_bus/test_in_memory_message_bus.py: Added a meaningful assertion to validate message bus dispatch behavior, improving test coverage.

Suggestions

No suggestions to apply.


Reviewed by code-review:latest

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.

3 participants