feat: use FoundryContext in all modules#18
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a Usage section covering set_context()/boot() at startup, get_context() for module-level access, and the explicit context pattern for tests. Remove the scaffolding NOTE block. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9246eae to
05ab569
Compare
|
Claude finished @olivermeyer's task in 2m 39s —— View job Code Review Complete ✅Reviewing PR #18: feat: use FoundryContext in all modules SummaryThis PR successfully refactors all modules to use Overall Assessment: Strong work! The code quality is high, tests follow best practices, and documentation is thorough. A few minor suggestions below for further improvement. Issues FoundCoverage Gap (Non-Blocking)Location: Issue: The detached HEAD SHA validation branch in if len(content) == 40 and all(c in string.hexdigits for c in content): # noqa: PLR2004
return content[:7]Codecov reports 88.23% patch coverage for Suggestion: Add a test case for detached HEAD state: @pytest.mark.unit
def test_get_vcs_ref_from_git_returns_short_sha_when_detached_head(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""Returns first 7 chars of SHA when in detached HEAD state."""
git_dir = tmp_path / ".git"
git_dir.mkdir()
full_sha = "a" * 40
(git_dir / "HEAD").write_text(full_sha)
from aignostics_foundry_core.foundry import _get_vcs_ref_from_git
result = _get_vcs_ref_from_git(tmp_path)
assert result == "aaaaaaa"Suggestions (Non-Blocking)1. Magic Number DocumentationLocation: Current: if len(content) == 40 and all(c in string.hexdigits for c in content): # noqa: PLR2004Suggestion: While the _GIT_SHA_FULL_LENGTH = 40
_GIT_SHA_SHORT_LENGTH = 7
if len(content) == _GIT_SHA_FULL_LENGTH and all(c in string.hexdigits for c in content):
return content[:_GIT_SHA_SHORT_LENGTH]Why: Improves readability and makes the intent explicit. Magic numbers should be avoided even with noqa comments. 2. Complex Fallback ChainLocation: Current: vcs_ref = os.environ.get("VCS_REF") or (project_path and _get_vcs_ref_from_git(project_path)) or "unknown"Suggestion: Consider breaking this into multiple lines for readability: vcs_ref = (
os.environ.get("VCS_REF")
or (project_path and _get_vcs_ref_from_git(project_path))
or "unknown"
)Why: The current one-liner is correct but dense. Breaking it up makes the fallback logic clearer. 3. Error Context in Git OperationsLocation: Current: try:
content = (project_path / ".git" / "HEAD").read_text().strip()
except OSError:
return "unknown"Suggestion: Consider logging the exception for debugging: try:
content = (project_path / ".git" / "HEAD").read_text().strip()
except OSError as exc:
logger.trace(f"Could not read .git/HEAD: {exc}")
return "unknown"Why: While returning "unknown" is safe, logging would help diagnose git-related issues in production. Positive Observations ✨
Breaking Changes (Acknowledged)This PR introduces breaking changes (as noted in the PR description for squash merge):
These are intentional refactoring changes for internal consistency. Final Recommendations
The code is production-ready as-is. The suggestions above are quality-of-life improvements, not blockers. Status: ✅ Approved with suggestions — Ready to merge after optional improvements Tasks
|
|



This PR updates all modules to use the
FoundryContext.The commits are a bit messy as I fixed some issues along the way; I will squash merge this one.