Skip to content

test(imports): add concurrency and multi-file cycle tests for ImportsValidator (#456)#502

Merged
avifenesh merged 6 commits intomainfrom
feature/concurrency-tests-456
Feb 17, 2026
Merged

test(imports): add concurrency and multi-file cycle tests for ImportsValidator (#456)#502
avifenesh merged 6 commits intomainfrom
feature/concurrency-tests-456

Conversation

@avifenesh
Copy link
Copy Markdown
Collaborator

Summary

Tests Added

Multi-file circular chains

  • test_cycle_detection_three_file_chain - A→B→C→A (3-node cycle), verifies CC-MEM-002 fires and message contains the full cycle path
  • test_cycle_detection_four_file_chain - A→B→C→D→A (4-node cycle), verifies CC-MEM-002 and cycle detection short-circuits before depth check
  • test_cycle_detection_three_file_chain_with_non_claude_root - same 3-file cycle with SKILL.md root, verifies CC-MEM-002/003 are suppressed

Depth boundary conditions

  • test_depth_below_boundary_no_trigger - 5-file chain (depth 4), well below MAX_IMPORT_DEPTH=5
  • test_depth_at_boundary_no_trigger - 6-file chain (depth 5), exactly at MAX_IMPORT_DEPTH, verifies CC-MEM-003 does NOT fire

Concurrent cache access

  • test_concurrent_cycle_detection_no_deadlock - 8 threads sharing Arc<RwLock<HashMap>> on a 2-file cycle
  • test_concurrent_three_file_cycle_shared_cache - 10 threads on 3-file cycle, verifies cache populated for all 3 files
  • test_concurrent_cycle_near_depth_limit - 5 threads on 5-file cycle at depth 4, verifies CC-MEM-002 fires and CC-MEM-003 does not
  • test_concurrent_diamond_dependency_no_duplicate_diagnostics - diamond dependency (CLAUDE→{b,c}→shared→missing), asserts exactly 1 missing-import diagnostic per thread
  • test_concurrent_different_roots_shared_cache - interleaved CLAUDE.md and SKILL.md threads sharing one cache; CLAUDE threads get CC-MEM-002, SKILL threads do not

Mid-chain traversal

  • test_missing_transitive_import_stops_traversal - missing b.md in chain a.md→b.md stops recursion, c.md never referenced

Test Plan

  • cargo test --lib -p agnix-core -- rules::imports::tests --quiet → 65/65 pass
  • cargo test -p agnix-core → full suite passes (2916 tests)
  • cargo build -p agnix-core → zero warnings

Related Issues

Closes #456

…Validator

Add 10 new tests to the ImportsValidator test module covering:
- Three-file and four-file circular dependency chain detection
- Depth boundary verification (chain of 5 files stays under limit)
- Concurrent cycle detection with shared cache (8 and 10 threads)
- Concurrent cycle near MAX_IMPORT_DEPTH boundary
- Diamond dependency pattern with missing file at leaf
- Filesystem error mid-chain recovery (missing intermediate file)
- Concurrent validation with different root file types sharing cache
- Non-CLAUDE root file type exclusion from cycle/depth rules

All tests are purely additive - no production code changes.

Closes #456
Remove redundant comments that restate code context, and normalize
the assertion pattern in test_filesystem_error_mid_chain_recovery to
use .any() consistently with the rest of the test suite.
- Rename test_depth_at_boundary_no_trigger to test_depth_below_boundary_no_trigger
  (was testing depth 4, not the true MAX_IMPORT_DEPTH=5 boundary)
- Add test_depth_at_boundary_no_trigger for the actual boundary (6 files, depth 5)
- Fix test_cycle_detection_four_file_chain assertion message: CC-MEM-003 is absent
  because cycle detection short-circuits traversal, not due to depth being <=5
- Add message content assertion to test_cycle_detection_three_file_chain to verify
  format_cycle produces a path containing the cycle files
- Fix test_concurrent_diamond_dependency_no_duplicate_diagnostics to assert count=1
  (the name promised deduplication but only checked presence)
- Interleave CLAUDE.md and SKILL.md thread spawning in
  test_concurrent_different_roots_shared_cache so both groups race concurrently
- Rename test_filesystem_error_mid_chain_recovery to
  test_missing_transitive_import_stops_traversal (it tests a missing file, not an I/O error)
Copilot AI review requested due to automatic review settings February 17, 2026 23:18
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @avifenesh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the test suite for the ImportsValidator by introducing comprehensive tests for complex import scenarios. It focuses on validating the validator's behavior with multi-file cycles, import depth limits, and concurrent operations, ensuring robustness and correctness without altering any production code. The new tests cover critical edge cases and concurrency concerns, improving the overall reliability of the import validation logic.

Highlights

  • Expanded Test Coverage: Added 11 new tests to the ImportsValidator inline test module, addressing gaps identified in issue Add concurrency tests for ImportsValidator circular dependency detection #456.
  • Multi-file Cycle Detection: Introduced tests for 3-file and 4-file circular import chains, including scenarios with non-CLAUDE.md roots, to verify correct cycle detection and diagnostic messages.
  • Import Depth Boundary Conditions: Added tests to validate the ImportsValidator's behavior at and below the MAX_IMPORT_DEPTH limit, ensuring CC-MEM-003 is triggered appropriately.
  • Concurrent Validation and Cache Access: Implemented several concurrent tests to ensure thread-safety, prevent deadlocks, and verify correct shared cache population and diagnostic deduplication under parallel validation for various import graph structures, including diamond dependencies.
  • Transitive Import Traversal: Included a test to confirm that traversal stops correctly when a transitive import is missing, preventing unnecessary further processing.
Changelog
  • CHANGELOG.md
    • Added 11 new tests for ImportsValidator covering concurrency, multi-file import cycles, and depth boundary conditions.
  • crates/agnix-core/src/rules/imports.rs
    • Added 11 new test cases to the ImportsValidator module to cover various import scenarios including cycles, depth limits, and concurrent access.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces 11 new tests for the ImportsValidator, addressing gaps in multi-file circular dependency detection, depth boundary conditions, and concurrent validation safety. The tests are comprehensive, covering complex scenarios like diamond dependencies, interleaved root types (CLAUDE.md vs. SKILL.md), and shared cache contention. The implementation follows existing patterns and correctly verifies the validator's logic, including the suppression of specific rules for non-CLAUDE.md roots and the prevention of duplicate diagnostics. No issues were identified in the added test code.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds comprehensive inline test coverage for ImportsValidator to address gaps around multi-file cycle detection, depth boundary behavior, and concurrent access to the shared import cache (issue #456).

Changes:

  • Added 11 new inline unit tests in rules::imports covering 3-/4-node cycles, depth boundaries, missing-transitive-import traversal behavior, and several concurrency scenarios using a shared ImportCache.
  • Updated CHANGELOG.md to note the expanded ImportsValidator test coverage.

Reviewed changes

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

File Description
crates/agnix-core/src/rules/imports.rs Adds new cycle/depth/concurrency-focused tests for ImportsValidator, including shared-cache multi-thread scenarios.
CHANGELOG.md Documents the addition of the new ImportsValidator tests under “Added”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Fix misleading comment in test_depth_at_boundary_no_trigger that
  referenced a nonexistent file 'e'; rewrite to match actual chain
  (CLAUDE -> a -> b -> c -> d -> leaf) and describe depth check precisely
- Add channel-based recv_timeout to test_concurrent_cycle_detection_no_deadlock
  so a deadlock regression fails CI within 10s instead of hanging indefinitely
- Fix CHANGELOG wording: above-boundary depth condition is covered by an
  existing test, not newly added; update to say 'at and below' with a note
  about complementing existing coverage
@avifenesh avifenesh merged commit 386dcc2 into main Feb 17, 2026
29 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.

Add concurrency tests for ImportsValidator circular dependency detection

2 participants