Skip to content

Comments

Improve constant mapping with ancestor expansion (default on)#7

Open
ngan wants to merge 2 commits intomainfrom
np-ancestor-references-default-and-docs
Open

Improve constant mapping with ancestor expansion (default on)#7
ngan wants to merge 2 commits intomainfrom
np-ancestor-references-default-and-docs

Conversation

@ngan
Copy link
Collaborator

@ngan ngan commented Feb 18, 2026

Summary

This PR improves constant-reference mapping for shared concerns/mixins and enables the behavior by default.

Changes:

  • Add ancestor expansion for constant references in the native extension.
  • Add a dedicated cache bucket for ancestor file resolution (:const_ancestor_files).
  • Add fixtures/spec coverage for dynamic include scenarios.
  • Add benchmark scenarios for ancestor expansion (cold/warm cache).
  • Change ancestor_references default from false to true.
  • Update README docs for the new option/default and behavior.

Problem

We observed mapping gaps where a changed module/concern did not map to all consuming controller specs in CI. In eagerload/boot-heavy environments, a file can be loaded once and then reused, so line execution and simple file-load signals are insufficient to connect all impacted tests.

Solution

When constant_references is enabled, FastCov already resolves referenced constants to defining files. This PR adds optional ancestor expansion: if a resolved constant is a class/module, FastCov also resolves its ancestors (includes/extends/superclasses) and adds those source files to impacted output.

With this change, updates to shared mixins/concerns are much more likely to map to tests that reference consumers, even when the concern file itself is not re-executed during that worker's run.

Default Behavior

ancestor_references now defaults to true.

You can disable it explicitly:

config.use FastCov::CoverageTracker, ancestor_references: false

Benchmark (vs existing baseline)

From bin/benchmark:

  • Constant resolution (cold cache): 0.398 ms (+1.7%)
  • Constant resolution (warm cache): 0.006 ms (+20.5%)
  • Constant resolution + ancestors (cold cache): 0.130 ms
  • Constant resolution + ancestors (warm cache): 0.003 ms

Validation

  • bundle exec rspec --fail-fast
  • bin/benchmark --baseline (run before implementation)
  • bin/benchmark (post-change compare)

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.

1 participant