← Richard Murillo

BLOG

Green should say how many things it checked

Your CI run is green. Every gate passed. One of them checked zero items.

I found two gates like that in one repo this year. VSTest behaves the same way. Each gate judged the inputs it received. Each skipped two questions: how many inputs arrived and whether they were the right ones.

The short answer

A gate that runs over a set must check the set before it checks the items. Is the set empty? Is it the set you meant? An empty set fails. A set with the wrong members fails too, even when the count matches.

When I set one gate to fail on mismatched inputs, it failed on its first run. That failure was correct. It showed that the perf gate in moq.analyzers had compared zero benchmarks since the suite gained a parameter.

Passing gates that checked zero items

The perf gate. The moq.analyzers repo uses PerfDiff to compare benchmark runs. PerfDiff's exit code determines whether the required merge gate passes. PerfDiff compared the overlap: benchmarks present in both the baseline run and the PR run. Issue #1266 traced what happened when that overlap held zero benchmarks. The regression checks looped over zero items. The tool logged "No regressions detected" and exited 0. A PR that broke the benchmark harness would pass the perf gate.

The coverage gate. The repo's AGENTS.md requires 100% block coverage of modified code. The coverage filter named two assemblies and left out PerfDiff.dll. On PR #1330, a PerfDiff-only change, the qlty coverage diff said: "Not applicable. There was no coverage data for the files in this diff." The gate passed. Issue #1332 records the gap. The fix, PR #1365, reports the before and after. Before, all 145 PerfDiff tests passed while the coverage report held zero PerfDiff classes. After, it held 24.

The test runner. This case comes from runner documentation, outside the repo. pytest exits with code 5 when it collects zero tests. Microsoft's migration guide says VSTest "tolerates that and exits with success" when an assembly runs zero tests. Microsoft.Testing.Platform reports an empty test module with exit code 8. A filter that matches zero tests turns red or green, depending on the runner.

A pass can hide an empty comparison, a gap in coverage, or a run with zero tests.

Empty and mismatched are failures

A gate without an input check answers one question. Did anything fail? An empty set answers no. So the gate says pass.

The gate must ask two questions first. Did I check anything? Did I check the right things? The answers give four outcomes:

  1. Pass: the set is the one you meant, it holds at least one item, and every item passed.
  2. Fail: at least one item broke a rule.
  3. Empty: the gate checked zero items.
  4. Mismatch: the gate checked items other than the ones you meant.

Empty and mismatch are separate failures. Counting inputs catches an empty set. Equal counts can mask a mismatch. Two sets can hold equal counts of names with zero names in common. The perf gate hit that problem. The baseline and PR runs listed the same benchmarks under different names.

Both gates I found reported an empty or mismatched set as a pass. That is the bug. Confusing "all good" with "saw nothing" disarms a gate, and the gate stays green.

My last post made the same point about an agent. It reported PASSED after it wrote 16 of 49 files. The validator checked format and skipped the count. A CI gate is the same machine with a different input.

The fix in moq.analyzers is short. PR #1309 added a check that runs before any comparison. It finds the benchmarks missing from each side and fails if either list has entries:

string[] missingFromResults = benchmarkIdToBaseResults.Keys
    .Except(benchmarkIdToDiffResults.Keys, StringComparer.Ordinal).ToArray();
string[] missingFromBaseline = benchmarkIdToDiffResults.Keys
    .Except(benchmarkIdToBaseResults.Keys, StringComparer.Ordinal).ToArray();
if (missingFromResults.Length == 0 && missingFromBaseline.Length == 0)
{
    return true;
}

logger.LogError("Benchmark result sets do not match. ...");
return false;

A separate check fails when either result set is empty. The same PR fails the run on duplicate names. The gate compares values after those checks pass.

The first failure revealed the mismatch

The new check failed on PR #1309's own perf run. It logged:

Benchmark result sets do not match.
Missing from results: ...Moq1400ExplicitBehaviorBenchmarks.Moq1400Baseline, ...
Missing from baseline: ...Moq1400ExplicitBehaviorBenchmarks.Moq1400Baseline(FileCount: 1), ...

Every pair referred to the same benchmark and differed by the (FileCount: 1) suffix. Issue #1310 identifies the cause.

The perf job regenerates its baseline on every run. It checks out a pinned baseline commit, builds the benchmarks there, and runs them. The pin pointed at release 0.1.1, from June 9, 2025. After that release, the benchmarks gained a FileCount parameter. Every benchmark name changed.

So the baseline names and the PR names diverged. The old code took the overlap, found it empty, and exited 0. The issue puts it in one line: the gate "provided no protection for an extended period." During that period, the gate was blind to performance regressions.

PR #1309 fixed the baseline too. It moved the pin to a commit that has the parameter. With the new pin, the two name sets matched and the gate resumed comparing real numbers. PR #1309 shipped the check and the new baseline in one merge on July 6, 2026.

A routine change to the benchmark suite disarmed the gate. A pinned baseline can drift out of step with the code the gate guards, and the drift stays silent.

The honest gate failed first. Expect that when you add an input check to an old gate. Treat that first failure as a finding and investigate it.

What you can do in your setup

Start with a list. Write down every gate that loops over a set. Tests, coverage, perf, lint on changed files, security scans and schema checks all qualify.

  1. Print the count. A gate log should report the test count: "checked 412 tests". A number in the log is the cheapest alarm you can buy.
  2. Fail on zero. pytest does this with exit code 5. Let that exit code fail the job, and keep || true off the command. On Microsoft.Testing.Platform, exit code 8 means zero tests. Limit any exemption to the one project that needs it.
  3. Fail on mismatch. When a gate compares two sets, such as a baseline and a PR, check that the names match before you compare values. Matching counts can hide mismatched names.
  4. Scope coverage to what ships or runs in CI. Every assembly that ships or runs in CI belongs in the coverage filter. A file outside the filter reads as "not applicable", and not applicable reads as green.

Why CI passes when zero tests run

The answer depends on the runner. dotnet test runs VSTest unless you opt in to Microsoft.Testing.Platform.

VSTest passes an empty run. When it finds zero matching tests, it prints a warning and returns 0. Set TreatNoTestsAsError to true in a .runsettings file. With that setting, a run that discovers or selects zero tests returns 1.

<RunSettings>
  <RunConfiguration>
    <TreatNoTestsAsError>true</TreatNoTestsAsError>
  </RunConfiguration>
</RunSettings>

Pass the file with dotnet test --settings test.runsettings.

Microsoft.Testing.Platform fails an empty test module with exit code 8. With the .NET 11 SDK, an empty module alone does not fail the run if another module runs tests. The run fails when every module runs zero tests.

The --minimum-expected-tests flag sets a floor. You give it a number. If fewer tests run, the run exits with code 9. That catches a run that finds some tests but fewer than you expect.

dotnet test --minimum-expected-tests 10

The flag requires Microsoft.Testing.Platform mode. That mode needs the .NET 10 SDK, version 10.0.100 or later. It needs test projects on Microsoft.Testing.Platform 1.7 or later. Set the runner to Microsoft.Testing.Platform in global.json. The VSTest page omits the flag.

The number must be positive. Skipped tests count toward the whole-run minimum. Put the flag after -- to set a per-module minimum.

How this could be wrong

The evidence is narrow: two gates in one repo, plus documented runner behavior. It shows that the failure exists and that the fix exposed a real case. It leaves the rate of empty passes unknown. I want that number for my own repos.

A check has to be able to fail. This post shows where to look: the inputs your gate left uncounted and unmatched.

Which of your green checks would stay green on zero inputs?

Written by Richard Murillo. Find me on GitHub rjmurillo, LinkedIn richardmurillo, X @OODARichard.