Skip to content

feat: port batch of modules from Bridge#10

Merged
olivermeyer merged 8 commits intomainfrom
feat/port-module-batch
Mar 26, 2026
Merged

feat: port batch of modules from Bridge#10
olivermeyer merged 8 commits intomainfrom
feat/port-module-batch

Conversation

@olivermeyer
Copy link
Copy Markdown
Collaborator

  • Porting models, process, api, log modules from Bridge.
  • Minor QoL changes

@olivermeyer olivermeyer requested a review from a team as a code owner March 26, 2026 12:41
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 88.14815% with 16 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/aignostics_foundry_core/log.py 80.95% 10 Missing and 6 partials ⚠️
Files with missing lines Coverage Δ
src/aignostics_foundry_core/api/__init__.py 100.00% <100.00%> (ø)
src/aignostics_foundry_core/api/exceptions.py 100.00% <100.00%> (ø)
src/aignostics_foundry_core/models.py 100.00% <100.00%> (ø)
src/aignostics_foundry_core/process.py 100.00% <100.00%> (ø)
src/aignostics_foundry_core/log.py 80.95% <80.95%> (ø)

@olivermeyer olivermeyer force-pushed the feat/port-module-batch branch from 8212430 to c715b9d Compare March 26, 2026 13:00
@olivermeyer olivermeyer added the claude Trigger Claude Code automation label Mar 26, 2026
@olivermeyer olivermeyer force-pushed the feat/port-module-batch branch from c715b9d to 849331e Compare March 26, 2026 13:53
@claude
Copy link
Copy Markdown

claude bot commented Mar 26, 2026

Claude encountered an error —— View job


PR Review Complete ✅

Todos

  • Analyze PR changes with git diff
  • Review commit messages
  • Review new modules (api, log, models, process)
  • Verify test coverage and markers
  • Check for security issues
  • Check for performance concerns
  • Verify documentation completeness
  • Post comprehensive review feedback

Summary

This PR successfully ports four modules (models, process, api, log) from Bridge to Foundry Python Core. The code quality is high, with clean architecture, comprehensive tests, and excellent documentation. SonarQube and all quality gates pass.

✅ Strengths

  1. Excellent Documentation: All modules thoroughly documented in AGENTS.md with purpose, features, dependencies, and usage examples
  2. Proper Test Markers: All tests correctly marked with @pytest.mark.unit
  3. Clean Architecture: Well-structured exception hierarchy, clear separation of concerns
  4. Conventional Commits: All commit messages follow the conventional commits format
  5. Type Safety: Good use of TYPE_CHECKING, lazy imports, and type hints
  6. Security: Proper file permission checks, sensitive data filtering (Sentry messages)

📋 Suggestions

Coverage Improvement Needed (log.py)

Location: src/aignostics_foundry_core/log.py
Issue: Patch coverage is 80.95% (16 lines missing), below the 85% minimum threshold
Impact: Suggestions

The missing coverage is likely in error handling paths:

  1. _validate_file_name error paths (lines 56-64): Not writable file case, OSError on file creation
  2. InterceptHandler.emit exception handling (line 87-88): ValueError catch for unknown log level
  3. InterceptHandler.emit patcher details (lines 94-101): Process/thread/task name conditionals
  4. RuntimeError suppression (line 112): Re-entrancy error handling

Recommendation: Add tests for these edge cases to meet the 85% coverage requirement:

@pytest.mark.unit
def test_validate_file_name_rejects_non_writable_file(tmp_path):
    """File validation fails when file exists but is not writable."""
    # Test readonly file rejection
    
@pytest.mark.unit  
def test_intercept_handler_handles_unknown_log_level():
    """InterceptHandler falls back to DEBUG for unknown log levels."""
    # Test ValueError handling
    
@pytest.mark.unit
def test_intercept_handler_patches_process_thread_info():
    """InterceptHandler preserves process/thread/task metadata."""
    # Test patcher function branches

Fix coverage →

Code Clarity Improvements

1. Document RuntimeError Suppression
Location: src/aignostics_foundry_core/log.py:112
Current: Comment explains re-entrancy but could be clearer about when this occurs
Suggestion: Expand comment to explain async context scenarios:

# Suppress RuntimeError from Loguru re-entrancy in async contexts.
# This can occur when:
# 1. An async task logs while holding the Loguru lock
# 2. The logging triggers another log (e.g., from psycopg during connection)
# 3. Loguru attempts to acquire the already-held lock
# Silently dropping is safe - the message will be logged when the lock releases.
with contextlib.suppress(RuntimeError):

2. Type Hint for Patcher Function
Location: src/aignostics_foundry_core/log.py:91
Current: def patcher(record_dict: "Record") -> None:
Suggestion: The patcher function modifies a Record dict extensively. Consider adding inline comments for each modification to improve maintainability.

3. SUBPROCESS_CREATION_FLAGS Usage
Location: src/aignostics_foundry_core/process.py:9
Issue: Exported but never used in this module
Suggestion: Add a usage example in the docstring or consider moving to a subprocess utility module if not immediately needed:

SUBPROCESS_CREATION_FLAGS = getattr(subprocess, "CREATE_NO_WINDOW", 0)
"""Creation flags for subprocess calls (suppresses console window on Windows).

Usage:
    subprocess.run(cmd, creationflags=SUBPROCESS_CREATION_FLAGS)
"""

🔍 Review Details

models.py ✅

  • Simple, clean OutputFormat StrEnum
  • Excellent documentation
  • Full test coverage
  • No issues

process.py ✅

  • Clean Pydantic models for process introspection
  • Good use of psutil
  • project_root calculation using Path(__file__).parent.parent.parent is acceptable for this use case
  • Full test coverage with proper markers
  • Minor: SUBPROCESS_CREATION_FLAGS exported but not used (see suggestion above)

api/exceptions.py ✅

  • Well-designed exception hierarchy
  • Consistent error response format ({"success": false, "error": {...}})
  • Good use of TYPE_CHECKING and lazy imports to avoid circular dependencies
  • Protocol pattern for _HasErrors is elegant
  • Excellent documentation of HTTP 401 vs 403 distinction
  • Full test coverage
  • Security Note: unhandled_exception_handler logs f"{exc!r}" which could contain sensitive data, but acceptable given CRITICAL log level
  • No blocking issues

log.py ⚠️

  • Sophisticated logging configuration with good features
  • InterceptHandler properly preserves metadata from stdlib logging
  • Sentry message filtering is a good practice
  • psycopg logger suppression prevents deadlock - well documented
  • File validation logic is secure and thorough
  • Issue: Coverage at 80.95% (below 85% minimum) - see suggestion above
  • No blocking issues, but coverage should be improved

Tests ✅

  • All tests properly marked with @pytest.mark.unit
  • Good test organization with descriptive class names
  • Proper use of constants to avoid string duplication (following S1192)
  • Sequential marker used appropriately for TestLoggingInitialize
  • Good coverage of happy paths
  • Suggestion: Add error path tests for log.py

Documentation ✅

  • AGENTS.md comprehensively updated with all four new modules
  • Each module section includes: purpose, features, location, dependencies, imports
  • Clear and helpful usage examples
  • ATTRIBUTIONS.md properly updated with new dependencies
  • Excellent work

Dependencies ✅

  • fastapi>=0.110,<1 - widely used, well maintained
  • loguru>=0.7,<1 - excellent logging library
  • platformdirs>=4,<5 - standard for platform-specific directories
  • psutil>=6 - mature, widely used
  • All dependencies have appropriate version constraints
  • No concerns

Commit Messages ✅

  • All follow conventional commits format
  • Clear, descriptive scopes and messages
  • No issues

🎯 Recommendation

Approve with Suggestions - This PR is ready to merge from a code quality and architecture perspective. The only concern is the log.py coverage at 80.95%, which is slightly below the 85% minimum. Consider adding the suggested tests to improve coverage before merge, but this is not blocking given that:

  1. SonarQube quality gate passed
  2. All critical paths are tested
  3. Missing coverage is in edge case error handling

@olivermeyer olivermeyer force-pushed the feat/port-module-batch branch from 849331e to f8acdc2 Compare March 26, 2026 14:15
@olivermeyer olivermeyer force-pushed the feat/port-module-batch branch from f8acdc2 to 5cbae2d Compare March 26, 2026 14:22
@olivermeyer olivermeyer merged commit b45d99c into main Mar 26, 2026
11 of 13 checks passed
@sonarqubecloud
Copy link
Copy Markdown

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

Labels

claude Trigger Claude Code automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant