Skip to content

Add cratis affected: build and test only what a change can reach - #658

Open
einari wants to merge 3 commits into
mainfrom
feature/268-affected-tests
Open

einari wants to merge 3 commits into
mainfrom
feature/268-affected-tests

Conversation

@einari

@einari einari commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Build and test only what a pull request can reach, using one command in the Cratis CLI.

Added

  • Add cratis affected select, which decides which test projects and which tests a change can reach from the project graph and per-project coverage maps, and writes a JSON and Markdown selection report that explains each decision (part of Affected-tests CLI and reusable workflow: build and test only what a pull request can reach Workflows#268).
  • Add cratis affected run, which runs the selection; with --mode merge it runs every test unit in isolation under dotnet-coverage or coverlet and writes deterministic coverage maps to .cratis/affected/maps.
  • Add cratis affected replay, which replays merged changes against the maps committed before them and reports the median fraction of tests selected and every failure the selection would have missed.
  • Add the Affected tests documentation, covering the selection rules, the .cratis/affected.json configuration and how a selection reaches the xUnit v3 runner.

Synchronize the installed guidance with the latest corpus. No profiles are added.
Selects the test projects and tests a change can reach: a project graph read
from git at the base and head revisions, deterministic per-test-project
coverage maps, selection with namespace roll-up, xUnit v3 filter generation
with batching, selection verification against the runner, merge-time
attribution, and an offline replay of merged changes.

Part of Cratis/Workflows#268.
Expose the affected-tests library as select, run and replay commands, with a
selection report written as JSON and Markdown and appended to the GitHub step
summary. Document the command, the coverage maps and the repository
configuration.

Part of Cratis/Workflows#268.
@einari einari added the minor New features, non-breaking additions label Nov 25, 2026
@einari

einari commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Reviewer notes for the affected-tests work (Cratis/Workflows#268).

Decisions

  • The project graph is read from the project XML at the base and head revisions rather than through DotnetAffected.Core. The library needs an in-process MSBuild ProjectGraph plus LibGit2Sharp's native library and does its own diffing; the issue needs the base graph for removed and moved projects and conservative handling of files outside project directories. Anything the XML reading cannot resolve (an unresolved property in a path, a file outside every project) forces more work, never less.
  • Coverage maps live in .cratis/affected/maps/, as agreed. The corpus rule cratis-folder-is-configuration says generated data does not belong in .cratis/; the maps are tool-owned state that the tool itself reads, not a shipped deliverable, so they are kept there deliberately.

Spike results (phase 1, one sample project)

  • Sample: Environments.Specs copied into a scratch repository, 28 test classes, xUnit v3 executable, coverlet collector.
  • Two merge runs on the same commit produced byte-identical maps. Map size 8 KB; merge run 16-23 s.
  • xUnit v3 -filter accepts repeated arguments (ORed) and matches class names exactly. 5,000 filters (about 284 KB) ran in one command line on macOS. The Linux runners were not measured; batching by maxFilterLength is the fallback.
  • The spike found and fixed two defects: dotnet build -getProperty evaluates without building, and Cobertura lists classes with zero hits, which made every unit appear to cover every file.
  • dotnet-coverage could not be exercised: its profiler does not initialize on this macOS arm64 machine ("Profiler was not initialized"). Its command line is implemented and coverlet is the verified path. This needs one run on a Linux runner before the pilot.

Not done here

  • The phase 2 replay over 100 merged pull requests needs maps committed in a repository's history, so it can only run after the merge-time job has been running. cratis affected replay is the tool for it.

Checks

  • Cratis.Affected.Specs: 139 passing, Release build with no warnings. dotnet pack bundles Cratis.Affected.dll in the tool and adds no package dependency.
  • Three for_CliApp root-help specs fail in this environment because AI_AGENT=pi suppresses the community pointer and colour handling in Program.cs; they do not touch this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features, non-breaking additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant