Skip to content

Conversation

@frankbria
Copy link
Owner

@frankbria frankbria commented Jan 30, 2026

Summary

  • Add 98 new integration tests for credentials and environment modules
  • Tests exercise real system operations without mocking (encrypted storage, tool detection, version parsing)
  • Add integration test fixtures to tests/core/conftest.py
  • Increase test count for these modules from 78 to 176 tests

Changes

New Test Files

File Tests Coverage
test_credentials_integration.py 43 Real encryption, keyring, file permissions
test_environment_integration.py 55 Real tool detection, project type detection

Integration Fixtures Added

  • integration_storage_dir - Isolated temp directory for credential tests
  • integration_credential_store - CredentialStore with test storage
  • available_system_tools - Session-scoped tool availability detection
  • real_python_project, real_js_project, real_rust_project - Realistic project structures

Test Classes

Credentials:

  • TestCredentialStoreIntegration - Real encrypted file storage/retrieval
  • TestEncryptionIntegration - Fernet encryption, corruption handling
  • TestCredentialManagerIntegration - High-level API with real storage
  • TestCredentialValidationIntegration - Format validation
  • TestCredentialEdgeCases - Unicode, special chars, multiple instances
  • TestKeyringIntegration - Keyring backend detection

Environment:

  • TestRealToolDetection - Real git, python, pytest, ruff detection
  • TestRealVersionExtraction - Actual subprocess version parsing
  • TestRealProjectTypeDetection - Detection with realistic structures
  • TestRealEnvironmentValidation - Full validation workflow
  • TestVersionParsingReal - Real tool version formats

Test plan

  • All 98 new integration tests pass locally
  • All 78 original unit tests still pass
  • Ruff linting passes
  • CI passes

Related

Closes #309

Summary by CodeRabbit

  • Tests
    • Added extensive integration tests for credential management: real and encrypted storage, key rotation, permission checks, format validation, corruption handling, and keyring/non-keyring scenarios.
    • Expanded environment integration tests for real tool detection, version parsing/comparison, project-type detection (Python/JS/Rust/Go), health scoring, recommendations, and edge-case workflows.
    • Added reusable integration fixtures/helpers for isolated storage, credential handling, system-tool availability, realistic project generation, and temporary environment key removal.

✏️ Tip: You can customize this high-level summary in your review settings.

…ules

Add 98 new integration tests that exercise real system operations:

Credentials integration tests (43 tests):
- Real encrypted file storage/retrieval with Fernet
- File permission verification (0600)
- Salt file management and key derivation
- Credential manager operations with real storage
- Edge cases: unicode metadata, special characters, naive datetimes
- Keyring availability detection

Environment integration tests (55 tests):
- Real tool detection using shutil.which()
- Actual subprocess calls for version extraction
- Project type detection with realistic file structures
- Full validation workflow with real installed tools
- Version parsing with real tool output formats
- Ecosystem detector coverage

Also adds integration test fixtures to conftest.py:
- integration_storage_dir, integration_credential_store
- available_system_tools (session-scoped)
- real_python_project, real_js_project, real_rust_project

Closes #309
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2026

Walkthrough

Adds comprehensive integration test fixtures and two large integration test modules covering credential storage/management and environment/tool detection using real system tools and generated sample projects.

Changes

Cohort / File(s) Summary
Test Fixtures & Infrastructure
tests/core/conftest.py
Adds ~10 fixtures and helpers: TEST_KEYRING_SERVICE, per-test isolated storage and credential store, keyring cleanup, system-tool availability detection, skip-if-no-tool fixtures, real project generators (Python/JS/Rust), and env_without_anthropic_key.
Credential Integration Tests
tests/core/test_credentials_integration.py
New comprehensive credential integration tests: keyring and encrypted-file flows, Fernet encryption/salt/key-derivation, permission checks, corruption handling, CRUD/rotation/list semantics, env overrides, cross-instance scenarios, and conditional keyring coverage.
Environment Integration Tests
tests/core/test_environment_integration.py
New end-to-end environment/tool detection tests: real tool detection and version extraction (git, python, pytest, ruff, uv), project-type detection (Python/JS/Rust/Go), health scoring, recommendations, optional vs required tools, version parsing/comparison, timeouts and stderr edge cases, and full workflow scenarios.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐇 I hop through tmp dirs neat and spry,

Fixtures, projects, tests nearby.
Keys and tools I check with care,
Integration gardens bloom out there.
A rabbit cheers the passing CI.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the primary change: adding integration tests for the credentials and environment modules.
Linked Issues check ✅ Passed The pull request fully implements all objectives from issue #309: credential manager keyring/environment tests, environment validator tool detection tests, edge case coverage, and exceeds the test count target (98 new tests).
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #309 objectives: new integration test files, test fixtures, and supporting test infrastructure with no modifications to production code.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/integration-tests-credentials-env

Comment @coderabbitai help to get the list of available commands and usage tips.

@macroscopeapp
Copy link
Contributor

macroscopeapp bot commented Jan 30, 2026

Add integration tests for core credentials and environment modules in test_credentials_integration.py and test_environment_integration.py with shared fixtures in conftest.py

Introduce integration suites covering credential storage, encryption, validation, and environment/tool detection, backed by session-scoped tool availability and real project fixtures in conftest.py.

📍Where to Start

Start with the fixtures in conftest.py, then review credential tests in test_credentials_integration.py followed by environment tests in test_environment_integration.py.


Macroscope summarized 407f50e.

@claude
Copy link

claude bot commented Jan 30, 2026

Code Review - Integration Tests for Credentials and Environment Modules

This PR adds comprehensive integration test coverage for the credentials and environment modules, doubling the test count from 78 to 176. The tests exercise real system operations without mocking, which is exactly what integration tests should do.

✅ Strengths

1. Well-Structured Test Organization

  • Clear separation into test classes by functionality (e.g., TestCredentialStoreIntegration, TestRealToolDetection)
  • Logical grouping with section headers using comment blocks
  • Excellent docstrings explaining what each test validates

2. Proper Integration Test Fixtures

  • integration_storage_dir - Isolated temp directory preventing pollution of user's actual credential storage
  • available_system_tools - Session-scoped fixture for efficient tool detection
  • real_python_project, real_js_project, real_rust_project - Realistic project structures
  • Smart use of tmp_path for cleanup

3. Security-Focused Testing

  • File permission verification (0600 for credentials and salt files) - critical for credential security
  • Unicode and special character handling in credentials
  • Encryption/decryption round-trip tests with corruption handling

4. Comprehensive Edge Cases

# Examples from test_credentials_integration.py:
- Corrupt encrypted files (graceful degradation)
- Invalid salt files (proper error handling)
- Expired credentials (returns None)
- Large credential values (~5KB)
- Multiple store instances sharing same directory
- Naive datetime handling

5. Smart Test Skipping

  • Tests skip gracefully when tools aren't available: pytest.skip("git not available on system")
  • Conditional keyring tests: @pytest.mark.skipif(not KEYRING_AVAILABLE, ...)
  • This ensures tests run successfully in CI and on developer machines with varying toolsets

6. Realistic Version Parsing Tests

@pytest.mark.parametrize("version_str,expected", [
    ("git version 2.39.0", (2, 39, 0)),
    ("Python 3.11.4", (3, 11, 4)),
    ("cargo 1.75.0 (1d8b05cdd 2023-11-20)", (1, 75, 0)),
    # ... 20+ real-world version formats
])

This comprehensive parameterization tests actual tool output formats.

🔍 Observations & Minor Suggestions

1. Environment Variable Handling Pattern
In test_environment_variable_override (lines 566-571), there's a manual env var cleanup:

env = os.environ.copy()
env.pop("ANTHROPIC_API_KEY", None)
with patch.dict(os.environ, env, clear=True):
    value = manager.get_credential(CredentialProvider.LLM_ANTHROPIC)

Suggestion: Consider using the existing env_without_anthropic_key fixture from conftest.py for consistency. However, the current approach is explicit and correct.

2. Test Marker Consistency
Both test files use:

pytestmark = [pytest.mark.integration, pytest.mark.v2]

This is excellent - properly marks all tests and follows the v2 convention from CLAUDE.md.

3. Fixture Documentation
The conftest.py fixtures have excellent docstrings. Consider adding a note about the integration marker in conftest.py for discoverability:

# All integration tests should be marked with @pytest.mark.integration
# Run with: pytest -m integration

4. Test Coverage Verification
The PR description mentions "98 new integration tests" but I count:

  • test_credentials_integration.py: 648 lines, ~43 tests
  • test_environment_integration.py: 616 lines, ~55 tests
  • Total: ~98 tests ✅

This matches the claim. Well done!

🏗️ Alignment with CLAUDE.md

✅ Follows v2 Architecture:

  • Tests core modules (codeframe.core.credentials, codeframe.core.environment)
  • No server/UI dependencies
  • Marked with pytest.mark.v2

✅ Integration Testing Best Practices:

  • Real system operations (no mocking except for forcing fallbacks)
  • Tests actual tool detection, file I/O, encryption, subprocess calls
  • Isolated from user environment via fixtures

✅ Phase 1 CLI Completion:
This directly supports issue #309 from the V2 Strategic Roadmap.

🧪 Test Coverage Analysis

Credentials Module:

  • ✅ Encrypted file storage/retrieval
  • ✅ Keyring integration (when available)
  • ✅ File permissions (security critical)
  • ✅ CredentialManager high-level API
  • ✅ Environment variable precedence
  • ✅ Credential rotation
  • ✅ Format validation (Anthropic, GitHub, OpenAI)
  • ✅ Edge cases (unicode, special chars, corruption, expiry)

Environment Module:

  • ✅ Real tool detection (git, python, pytest, ruff, etc.)
  • ✅ Version extraction from subprocess output
  • ✅ Project type detection (Python, JS, Rust, Go)
  • ✅ Environment validation workflow
  • ✅ Health score calculation
  • ✅ Required vs optional tool handling
  • ✅ Version comparison with real formats

🐛 Potential Issues

None identified. The code is well-written, defensive, and follows best practices.

🔐 Security Considerations

✅ Excellent security testing:

  1. File permissions verified to be 0600 (owner-only)
  2. Encryption keys derived securely with salt
  3. Keyring fallback to encrypted file storage
  4. Test isolation prevents credential leakage
  5. Use of test-specific keyring service name

📊 Performance Considerations

Session-scoped available_system_tools fixture is smart - it caches tool availability checks to avoid repeated subprocess calls across all tests. This will significantly improve test suite performance.

✅ Recommendations

  1. Merge this PR - It's production-ready and adds critical integration test coverage
  2. CI should pass - The smart test skipping ensures compatibility with CI environments
  3. Consider adding a pytest.ini marker for integration:
    [tool.pytest.ini_options]
    markers = [
        "integration: Integration tests that interact with real system resources",
        "v2: Tests for v2 CLI-first, headless functionality",
    ]

📝 Summary

This is excellent work. The tests are:

  • Comprehensive and well-organized
  • Properly isolated with fixtures
  • Security-conscious
  • Performance-aware (session-scoped fixtures, smart skipping)
  • Well-documented
  • Aligned with v2 architecture principles

The 98 new tests significantly improve confidence in the credentials and environment modules, especially for real-world scenarios (actual encryption, tool detection, project structures).

Recommendation: APPROVE AND MERGE ✅

Great job closing issue #309! 🎉

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/core/conftest.py (1)

6-19: ⚠️ Potential issue | 🟡 Minor

Make the v2 auto-mark OS-agnostic.

"/tests/core/" in str(item.fspath) is path-separator sensitive and can fail on Windows, leaving core tests unmarked. Convert to a POSIX path (or check parts) before matching.

🔧 Suggested fix
 def pytest_collection_modifyitems(items):
     """Automatically mark all tests in this directory as v2."""
     for item in items:
         # Check if the test is in the core directory
-        if "/tests/core/" in str(item.fspath):
+        path = Path(str(item.fspath)).as_posix()
+        if "/tests/core/" in path:
             item.add_marker(pytest.mark.v2)
🤖 Fix all issues with AI agents
In `@tests/core/test_credentials_integration.py`:
- Around line 41-191: The POSIX permission assertions in tests
test_encrypted_file_permissions_are_secure and
test_salt_file_permissions_are_secure can fail on Windows/non-POSIX filesystems;
update those tests to skip or guard the 0o600 assertions when os.name != "posix"
(or os.name == "nt"), e.g., check os.name before calling stat.S_IMODE and
asserting, or use pytest.skip for non-posix platforms; modify the tests
referencing derive_encryption_key and CredentialStore/credentials.encrypted to
only assert file_mode == 0o600 on POSIX systems.

In `@tests/core/test_environment_integration.py`:
- Around line 506-540: The two edge-case tests are not asserting ToolDetector
behavior; update them to exercise ToolDetector.get_version (and keep
check_version_compatibility) by mocking subprocess.run: for
test_tool_with_slow_version_command, mock subprocess.run to raise
subprocess.TimeoutExpired and assert ToolDetector.get_version returns None or
handles timeout as expected; for test_version_extraction_from_stderr, mock
subprocess.run to return an object with stdout="" and stderr="some-tool version
1.2.3" and assert ToolDetector.get_version extracts "1.2.3" (or the detector's
expected parsed value). Ensure you reference ToolDetector.get_version and
ToolDetector.check_version_compatibility in the assertions and remove the unused
MockResult/inspect-based checks if you implement the mocks.
🧹 Nitpick comments (2)
tests/core/test_environment_integration.py (1)

1-35: Remove redundant pytest.mark.v2 in tests/core/.

Tests in tests/core/ automatically receive pytest.mark.v2 from the conftest.py hook. Keep only the integration marker:

Suggested change
-pytestmark = [pytest.mark.integration, pytest.mark.v2]
+pytestmark = [pytest.mark.integration]
tests/core/test_credentials_integration.py (1)

1-34: Remove redundant v2 marker from pytestmark.

Tests in tests/core/ automatically receive pytest.mark.v2 via the conftest.py hook, so explicitly declaring it creates duplication. Keep only the integration marker.

♻️ Suggested simplification
-pytestmark = [pytest.mark.integration, pytest.mark.v2]
+pytestmark = [pytest.mark.integration]

1. Add POSIX platform guards for file permission tests
   - Skip 0o600 permission assertions on Windows/non-POSIX platforms
   - Affects test_encrypted_file_permissions_are_secure
   - Affects test_salt_file_permissions_are_secure

2. Improve edge case tests with proper assertions
   - test_tool_with_slow_version_command_timeout: Mock TimeoutExpired
   - test_version_extraction_from_stderr: Mock stderr version output
   - test_version_extraction_subprocess_error: Test SubprocessError handling
   - test_detect_tool_version_incompatible: Add equality case
@claude
Copy link

claude bot commented Jan 30, 2026

Code Review - Integration Tests for Credentials and Environment Modules

I've reviewed the changes in this PR, including the follow-up commit that addressed CodeRabbit's feedback. This is excellent work that significantly strengthens the test coverage for critical v2 modules.


✅ Summary

What Changed:

  • Added 98 new integration tests (43 for credentials, 55 for environment)
  • Added integration test fixtures to conftest.py
  • Tests exercise real system operations (encryption, tool detection, file I/O)
  • Increased test coverage from 78 to 176 tests for these modules

Status:APPROVE - Ready to merge


🎯 Strengths

1. Proper Integration Testing Philosophy

The tests correctly exercise real system operations without excessive mocking:

  • Real Fernet encryption/decryption
  • Actual subprocess calls for version detection
  • Real file I/O with permission checks
  • Genuine tool detection via shutil.which()

This is exactly what integration tests should do - validate that components work correctly with real dependencies.

2. Excellent Test Isolation

The fixtures ensure tests don't pollute the user's environment:

integration_storage_dir  # Isolated temp directory for credentials
TEST_KEYRING_SERVICE     # Separate keyring service name
available_system_tools   # Session-scoped for efficiency

3. Security-Focused Testing

Critical security assertions are properly validated:

  • File permissions (0o600 for credentials and salt files) ✅
  • Encryption key derivation consistency ✅
  • Unicode and special character handling ✅
  • Corruption/error handling ✅

The addition of POSIX platform guards (os.name != "posix") in commit 25675e6 properly handles cross-platform testing.

4. Comprehensive Coverage

Credentials module:

  • Encrypted file storage/retrieval
  • Keyring integration (when available)
  • File permissions (security critical)
  • CredentialManager high-level API
  • Environment variable precedence
  • Credential rotation
  • Format validation (Anthropic, GitHub, OpenAI)
  • Edge cases (unicode, special chars, corruption, expiry)

Environment module:

  • Real tool detection (git, python, pytest, ruff, uv)
  • Version extraction from subprocess output
  • Project type detection (Python, JS, Rust, Go)
  • Environment validation workflow
  • Health score calculation
  • Version comparison with 20+ real formats

5. Smart Test Skipping

Tests gracefully handle missing tools:

if not available_system_tools.get("git"):
    pytest.skip("git not available on system")

This ensures tests pass in CI and on various developer machines.

6. Well-Organized Structure

  • Clear test class organization by functionality
  • Descriptive docstrings for every test
  • Section headers with comment blocks
  • Logical grouping of related tests

🔍 Minor Observations

1. Redundant pytest.mark.v2 Marker

Both test files include:

pytestmark = [pytest.mark.integration, pytest.mark.v2]

However, conftest.py automatically adds pytest.mark.v2 to all tests in tests/core/:

def pytest_collection_modifyitems(items):
    for item in items:
        if "/tests/core/" in str(item.fspath):
            item.add_marker(pytest.mark.v2)

Impact: Low - This creates duplicate markers but doesn't break anything. Could simplify to just pytestmark = pytest.mark.integration for cleaner code.

2. Session-Scoped Performance Optimization

The available_system_tools fixture is session-scoped, which is excellent:

@pytest.fixture(scope="session")
def available_system_tools() -> dict[str, bool]:

This prevents redundant tool detection across 98 tests - smart performance optimization.

3. Platform Guard Implementation

The fix in commit 25675e6 properly addresses Windows compatibility:

@pytest.mark.skipif(os.name != "posix", reason="POSIX permissions not supported on Windows")
def test_encrypted_file_permissions_are_secure(self, integration_storage_dir: Path):

This is the correct approach. ✅


🏗️ Alignment with CLAUDE.md

✅ V2 Architecture Compliance:

  • Tests core modules (codeframe.core.credentials, codeframe.core.environment)
  • No server/UI dependencies
  • CLI-first, headless functionality
  • Properly marked with pytest.mark.v2

✅ Phase 1 CLI Completion:

✅ Testing Best Practices:

  • Follows repository testing conventions
  • Uses existing test infrastructure
  • Maintains runnable state throughout

🔐 Security Analysis

✅ Excellent security testing:

  1. File permissions: 0o600 verified for credential and salt files
  2. Encryption: Fernet encryption round-trip tested
  3. Key derivation: Salt-based key generation tested for consistency
  4. Isolation: Test keyring service prevents pollution
  5. Edge cases: Corruption, invalid data, expired credentials handled

No security concerns identified.


🐛 Issues Found

None. The code is well-written, defensive, and follows best practices.


📊 Performance Considerations

Session-scoped tool detection (available_system_tools) is a smart optimization that will significantly improve test suite performance by avoiding 98+ redundant subprocess calls.


✅ Final Recommendation

APPROVE AND MERGE

This PR:

The test count increase from 78 to 176 represents a significant improvement in confidence for the credentials and environment modules, especially for real-world scenarios.

Great work! 🎉

The CI environment has ANTHROPIC_API_KEY set, which causes
get_credential() to return the env value instead of stored credentials.

Fixed tests:
- test_set_and_get_credential
- test_rotate_credential_preserves_metadata
- test_expired_credential_returns_none

Now properly clear the env var with patch.dict before testing stored
credential retrieval.
@claude
Copy link

claude bot commented Jan 30, 2026

Final Code Review - Integration Tests for Credentials and Environment Modules

I've reviewed the complete PR including the follow-up commit (25675e6) that addressed CodeRabbit's feedback. This is excellent work that significantly strengthens test coverage for critical v2 modules.


✅ Status: APPROVED - Ready to Merge

What This PR Delivers:


🎯 Key Strengths

1. Proper Integration Testing Philosophy

Tests exercise real system operations without excessive mocking:

  • Real Fernet encryption/decryption ✅
  • Actual subprocess calls for version detection ✅
  • Real file I/O with permission checks ✅
  • Genuine tool detection via shutil.which()

2. Security-Focused Testing

Critical security assertions are properly validated:

  • File permissions (0o600 for credentials/salt files) with proper POSIX guards ✅
  • Encryption key derivation consistency ✅
  • Unicode and special character handling ✅
  • Corruption/error handling ✅

The addition of @pytest.mark.skipif(os.name != "posix", ...) in commit 25675e6 properly handles cross-platform testing.

3. Excellent Test Isolation

Fixtures prevent environmental pollution:

integration_storage_dir  # Isolated temp directory
TEST_KEYRING_SERVICE     # Separate keyring service name
available_system_tools   # Session-scoped for efficiency

4. Smart Performance Optimization

The available_system_tools fixture is session-scoped, preventing 98+ redundant subprocess calls across the test suite. This is a smart optimization.

5. Comprehensive Coverage

Credentials module tests:

  • Encrypted file storage/retrieval
  • Keyring integration (when available)
  • File permissions (security critical)
  • CredentialManager high-level API
  • Environment variable precedence
  • Credential rotation
  • Format validation (Anthropic, GitHub, OpenAI)
  • Edge cases (unicode, special chars, corruption, expiry)

Environment module tests:

  • Real tool detection (git, python, pytest, ruff, uv)
  • Version extraction from subprocess output
  • Project type detection (Python, JS, Rust, Go)
  • Environment validation workflow
  • Health score calculation
  • Version comparison with 20+ real-world formats

🔍 Addressed Issues from Previous Review

✅ Fixed: POSIX Permission Tests (Commit 25675e6)

CodeRabbit correctly identified that permission tests would fail on Windows. The fix properly guards these tests:

@pytest.mark.skipif(os.name != "posix", reason="POSIX permissions not supported on Windows")
def test_encrypted_file_permissions_are_secure(self, integration_storage_dir: Path):

This is the correct approach. ✅

✅ Fixed: Edge Case Test Assertions (Commit 25675e6)

The edge case tests now properly mock and assert against ToolDetector behavior instead of using inspect-based checks. Well done.


💡 Minor Observations (Non-blocking)

1. Redundant pytest.mark.v2 Marker

Both test files include:

pytestmark = [pytest.mark.integration, pytest.mark.v2]

However, conftest.py automatically adds pytest.mark.v2 to all tests in tests/core/:

def pytest_collection_modifyitems(items):
    for item in items:
        if "/tests/core/" in str(item.fspath):
            item.add_marker(pytest.mark.v2)

Impact: This creates duplicate markers but doesn't break anything. Could simplify to just pytestmark = pytest.mark.integration in future PRs for cleaner code.


🏗️ Alignment with CLAUDE.md

✅ V2 Architecture Compliance:

  • Tests core modules (codeframe.core.credentials, codeframe.core.environment)
  • No server/UI dependencies
  • CLI-first, headless functionality
  • Properly marked with pytest.mark.v2

✅ Phase 1 CLI Completion:

✅ Testing Best Practices:

  • Follows repository testing conventions
  • Uses existing test infrastructure
  • Maintains runnable state throughout

🔐 Security Analysis

No security concerns identified. The tests properly validate:

  1. File permissions (0o600 for sensitive files)
  2. Encryption round-trips
  3. Salt-based key derivation
  4. Test isolation (no credential leakage)
  5. Edge cases (corruption, invalid data, expiry)

🐛 Issues Found

None. The code is well-written, defensive, and follows best practices.


✅ Final Recommendation

APPROVE AND MERGE

This PR:

The test count increase from 78 to 176 represents a significant improvement in confidence for the credentials and environment modules, especially for real-world scenarios.

Excellent work! 🎉

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@tests/core/test_credentials_integration.py`:
- Around line 374-401: The test test_rotate_credential_preserves_metadata stores
initial metadata via manager.set_credential then rotates the key but never
asserts the metadata; after calling manager.rotate_credential (for provider
CredentialProvider.LLM_ANTHROPIC) fetch the stored metadata (via the manager
method that returns credential metadata — e.g., manager.get_credential_metadata
or equivalent) and assert it still contains the original fields {"scopes":
["read", "write"], "rotated_count": 0} (or the expected preserved structure) to
verify metadata was not lost by rotate_credential.

In `@tests/core/test_environment_integration.py`:
- Around line 155-180: The test_python_version_format currently only reads
result.stdout; change it to use stderr when stdout is empty (e.g., version_str =
(result.stdout or result.stderr).strip() or combine both) so parse_version gets
the version whether Python prints to stdout or stderr; update the comment
accordingly and keep references to the test test_python_version_format and the
parse_version call.

1. test_rotate_credential_preserves_metadata: Now actually verifies
   metadata is preserved after rotation by checking stored_credential.metadata
   and stored_credential.name match original values

2. test_python_version_format: Handle Python versions that output to
   stderr by using (result.stdout or result.stderr).strip()
@claude
Copy link

claude bot commented Jan 30, 2026

✅ Final Review - LGTM (Approved)

I've reviewed all commits in this PR, including the latest fixes in commit 407f50e. This PR is ready to merge.


Summary

This PR successfully adds 98 comprehensive integration tests for the credentials and environment modules, increasing test coverage from 78 to 176 tests. The tests properly exercise real system operations (encryption, tool detection, file I/O) without excessive mocking - exactly what integration tests should do.

Closes: #309 from the V2 Strategic Roadmap ✅


What's Been Fixed

The PR author has diligently addressed all feedback from CodeRabbit and previous reviews:

✅ Commit 25675e6 - Cross-platform compatibility

  • Added POSIX guards for file permission tests
  • Tests now skip permission checks on Windows/non-POSIX platforms
  • Improved edge case test assertions

✅ Commit dcfd5b8 - Environment variable handling

  • Fixed credential manager tests that were failing in CI
  • Properly clears ANTHROPIC_API_KEY env var before testing stored credentials
  • Prevents CI environment from interfering with test isolation

✅ Commit 407f50e - Final refinements

  1. test_rotate_credential_preserves_metadata - Now properly verifies metadata preservation:

    stored_credential = manager._store.retrieve(CredentialProvider.LLM_ANTHROPIC)
    assert stored_credential.metadata == original_metadata
    assert stored_credential.name == "production-key"
  2. test_python_version_format - Handles Python versions that output to stderr:

    version_str = (result.stdout or result.stderr).strip()

Key Strengths

1. Proper Integration Testing Philosophy

  • Real Fernet encryption/decryption ✅
  • Actual subprocess calls for version detection ✅
  • Real file I/O with permission checks (POSIX-guarded) ✅
  • Genuine tool detection via shutil.which()

2. Security-Focused Testing

  • File permissions (0o600) with proper platform guards ✅
  • Encryption key derivation consistency ✅
  • Unicode and special character handling ✅
  • Corruption/error handling ✅

3. Excellent Test Isolation

integration_storage_dir  # Isolated temp directory
TEST_KEYRING_SERVICE     # Separate keyring service name
available_system_tools   # Session-scoped for efficiency

4. Smart CI/Developer Machine Compatibility

  • Session-scoped available_system_tools fixture prevents redundant subprocess calls
  • Tests skip gracefully when tools aren't available
  • Proper environment variable cleanup
  • Cross-platform guards for OS-specific features

5. Comprehensive Coverage

Credentials module (43 tests):

  • Encrypted file storage/retrieval
  • Keyring integration (when available)
  • File permissions (security critical)
  • CredentialManager high-level API
  • Environment variable precedence
  • Credential rotation with metadata preservation
  • Format validation (Anthropic, GitHub, OpenAI)
  • Edge cases (unicode, special chars, corruption, expiry)

Environment module (55 tests):

  • Real tool detection (git, python, pytest, ruff, uv)
  • Version extraction from subprocess output (stdout/stderr)
  • Project type detection (Python, JS, Rust, Go)
  • Environment validation workflow
  • Health score calculation
  • Version comparison with 20+ real-world formats

Alignment with CLAUDE.md

✅ V2 Architecture Compliance:

  • Tests core modules (codeframe.core.credentials, codeframe.core.environment)
  • No server/UI dependencies
  • CLI-first, headless functionality
  • Properly marked with pytest.mark.v2 and pytest.mark.integration

✅ Phase 1 CLI Completion:

✅ Testing Best Practices:

  • Follows repository testing conventions
  • Uses existing test infrastructure
  • Maintains runnable state throughout

Minor Note (Non-blocking)

The pytestmark = [pytest.mark.integration, pytest.mark.v2] in both test files is slightly redundant since conftest.py auto-adds pytest.mark.v2 to all tests/core/ tests. However, this is not a blocker and could be simplified in a future cleanup PR if desired.


Security Analysis

No security concerns identified. The tests properly validate:

  1. File permissions (0o600 for sensitive files, POSIX-guarded)
  2. Encryption round-trips with Fernet
  3. Salt-based key derivation
  4. Test isolation (no credential leakage)
  5. Edge cases (corruption, invalid data, expiry)

Final Recommendation

✅ APPROVE AND MERGE

This PR:

The test count increase from 78 to 176 represents a significant improvement in confidence for the credentials and environment modules, especially for real-world scenarios.

Excellent work! 🎉 This is production-ready.

@frankbria frankbria merged commit 3203109 into main Jan 30, 2026
11 checks passed
@frankbria frankbria deleted the feature/integration-tests-credentials-env branch January 30, 2026 19:59
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.

[Phase 1] Integration tests for credential and environment modules

2 participants