Skip to content

[SDTEST-2713] Fix monorepo subdirectory path handling when ITR is enabled#34

Merged
anmarchenko merged 4 commits intomainfrom
anmarchenko/fix_monorepo_subdirectory_tests
Feb 17, 2026
Merged

[SDTEST-2713] Fix monorepo subdirectory path handling when ITR is enabled#34
anmarchenko merged 4 commits intomainfrom
anmarchenko/fix_monorepo_subdirectory_tests

Conversation

@anmarchenko
Copy link
Member

@anmarchenko anmarchenko commented Feb 12, 2026

Summary

Fixes #33

  • When running ddtest from a monorepo subdirectory (cd core && ddtest run), full test discovery (ITR enabled) returns repo-root-relative paths like core/spec/models/order_spec.rb. Workers run from the subdirectory CWD, so they resolve core/core/spec/... which does not exist.
  • Added conservative path normalization in PrepareTestOptimization that detects the CWD's position relative to the git root and strips the matching prefix from repo-root-relative paths. Fail-safe: no-op if git root is unavailable, prefix doesn't match, or CWD is already repo root.
  • Fast discovery path is unchanged (it already returns CWD-relative paths from glob).

E2E verification

  • Run spree tests with ddtest both from repo root and from the core subfolder
  • Make sure that backend skips at least one test suite completely
  • Assert that tests are running successfully, that the test suite is skipped completely in both cases

Made with Cursor

When running ddtest from a monorepo subdirectory (e.g., `cd core && ddtest run`),
full test discovery returns repo-root-relative paths like `core/spec/models/order_spec.rb`.
These paths were passed unchanged to workers running from the `core/` CWD, causing them
to resolve `core/core/spec/...` which does not exist.

Add conservative path normalization that detects the CWD's position relative to the git
root and strips the matching prefix from repo-root-relative paths before storing them.
The normalization is fail-safe: paths are returned unchanged if git root is unavailable,
the prefix doesn't match, or CWD is already the repo root.

Co-authored-by: Cursor <cursoragent@cursor.com>
@anmarchenko anmarchenko marked this pull request as ready for review February 12, 2026 18:19
@anmarchenko anmarchenko requested a review from a team as a code owner February 12, 2026 18:19
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49256468eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@anmarchenko
Copy link
Member Author

E2E Test Report: SUCCESS ✅

Tested by: Shepherd Agent (autonomous QA for Datadog Test Optimization)

Test Environment

  • Method: Local testing with spree monorepo playground (core sub-project, ~5919 RSpec examples)
  • Revision: 980cffe
  • Backend: mockdog (local mock Datadog backend) with ITR skip scenarios
  • ddtest branch: anmarchenko/fix_monorepo_subdirectory_tests

Results

Test Command Description Status
From repo root ddtest-core-root Run ddtest from repo root with --tests-location "core/spec/**/*_spec.rb" ✅ PASSED
From subdirectory ddtest-core Run ddtest with cd core && ../bin/ddtest run ✅ PASSED

Details

Both runs used a mockdog scenario that marks 2 tests in role_spec.rb as skippable (ITR enabled). In both cases:

  • ddtest correctly removed role_spec.rb from the worker split entirely — the file never appeared in any worker
  • All 8 mockdog assertions passed: tests=5901, suites=421, sessions=4, modules=4, coverages=5865, telemetry valid
  • Coverage collection was active and produced expected counts

Key difference between runs:

  • From repo root, the skippable test suite name uses repo-root-relative path: Spree::Role at ./core/spec/models/spree/role_spec.rb
  • From subdirectory, the skippable test suite name uses CWD-relative path: Spree::Role at ./spec/models/spree/role_spec.rb

The path normalization fix correctly handles both cases for test discovery and split distribution.

Test Methodology

  1. Built ddtest from PR branch anmarchenko/fix_monorepo_subdirectory_tests
  2. Used two mockdog scenarios with ITR enabled and role_spec.rb tests marked as skippable:
    • itr-spree-root-skip-role-spec — skippable test suite paths relative to repo root
    • itr-spree-core-skip-role-spec — skippable test suite paths relative to core/ subdirectory
  3. Ran spree core tests with --debug flag in two configurations:
    • ddtest-core-root: from repo root with --tests-location "core/spec/**/*_spec.rb"
    • ddtest-core: with cd core && ../bin/ddtest run --framework rspec
  4. Verified assertions against expected test/suite/coverage counts via mockdog report endpoint

This E2E test was performed by Shepherd — autonomous QA agent for Datadog Test Optimization

@anmarchenko anmarchenko changed the title Fix monorepo subdirectory path handling when ITR is enabled [SDTEST-2713] Fix monorepo subdirectory path handling when ITR is enabled Feb 16, 2026
@anmarchenko anmarchenko merged commit b53c276 into main Feb 17, 2026
3 checks passed
@anmarchenko anmarchenko deleted the anmarchenko/fix_monorepo_subdirectory_tests branch February 17, 2026 14:32
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.

Monorepo: workers fail with LoadError when ITR is enabled and CWD is a subdirectory

2 participants