Skip to content

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

@anmarchenko

Description

@anmarchenko

Description

When running ddtest from a monorepo subdirectory (e.g., cd core && ../bin/ddtest run ...), all workers fail with LoadError if ITR/Test Impact Analysis is enabled. Without ITR (default settings), the same command works correctly.

Root Cause

ddtest normalizes test file paths to git-root-relative when ITR is enabled, but passes these normalized paths to rspec workers that run from the subdirectory CWD. This causes a double-prefix path issue.

Step by step:

  1. Command: cd core && ../bin/ddtest run --framework rspec --platform ruby ...
  2. ddtest discovers test files using glob spec/**/*_spec.rb from CWD (core/) — finds spec/models/spree/order_spec.rb
  3. ddtest normalizes these to git-root-relative paths — becomes core/spec/models/spree/order_spec.rb
  4. Normalized paths are written to .testoptimization/tests-split/runner-*
  5. Workers run rspec from the same CWD (core/) — rspec tries to load core/spec/models/spree/order_spec.rb relative to CWD
  6. This resolves to core/core/spec/models/spree/order_spec.rbfile does not exist

Reproduction

Repository: Any Ruby monorepo where tests are run from a subdirectory (e.g., Spree Commerce with core/ and api/ sub-projects).

Steps:

# Clone a monorepo with test suites in subdirectories
git clone <monorepo-with-subdirs>
cd monorepo

# This works (ITR disabled by default):
cd core && ddtest run --framework rspec --platform ruby --min-parallelism 1 --max-parallelism 4

# This fails (ITR enabled via backend settings):
# When the backend returns itr_enabled: true, tests_skipping: true
cd core && ddtest run --framework rspec --platform ruby --min-parallelism 1 --max-parallelism 4

Backend settings that trigger the bug:

{
  "itr_enabled": true,
  "tests_skipping": true,
  "code_coverage": true
}

Error Output

All workers produce:

Finished in 0.00004 seconds (files took 10.42 seconds to load)
0 examples, 0 failures, 104 errors occurred outside of examples

Each error is:

LoadError:
  cannot load such file -- /path/to/monorepo/core/core/spec/models/spree/payment_spec.rb

Note the doubled core/core/ in the path.

Evidence

Contents of .testoptimization/test-files.txt (git-root-relative, with core/ prefix):

core/spec/finders/spree/addresses/find_spec.rb
core/spec/finders/spree/option_values/find_available_spec.rb
core/spec/helpers/base_helper_spec.rb
...

Contents of .testoptimization/tests-split/runner-0 (same prefix, passed to rspec in core/ CWD):

core/spec/models/spree/order_spec.rb
core/spec/models/spree/return_item_spec.rb
...

Expected Behavior

When ddtest passes file paths to rspec workers, it should use paths relative to the worker's CWD (i.e., strip the subdirectory prefix). The tests-split/runner-* files should contain:

spec/models/spree/order_spec.rb
spec/models/spree/return_item_spec.rb
...

Environment

  • ddtest: latest main branch
  • Ruby: 4.0.1
  • datadog-ci gem: latest main branch
  • OS: macOS (Darwin 24.6.0, arm64)
  • Framework: RSpec

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions