Repository navigation
Description
What happens
expandMatrix (src/ci-inference/matrix.ts) does not follow GitHub's documented include rules, so CI inference builds matrix cells that GitHub never runs and misses cells it does run.
GitHub's rules (Expanding or adding matrix configurations):
- An
includeentry is added to every original combination whose original values it does not overwrite. - Values added by an earlier
includecan be overwritten. - An entry that fits no original combination becomes a new combination. Later
includeentries do not extend that appended combination.
matches() treats a value added by an earlier include as fixed, which breaks rule 2. It also checks appended cells as if they were original, which breaks rule 3. And a matrix with no axes starts from one empty cell, so the first include entry extends it instead of becoming its own cell.
Repro: GitHub's own example
import { expandMatrix } from "./src/ci-inference/matrix.js";
expandMatrix({
fruit: ["apple", "pear"], animal: ["cat", "dog"],
include: [
{ color: "green" }, { color: "pink", animal: "cat" },
{ fruit: "apple", shape: "circle" }, { fruit: "banana" }, { fruit: "banana", animal: "cat" },
],
}).instances;GitHub documents this result:
{fruit: apple, animal: cat, color: pink, shape: circle}
{fruit: apple, animal: dog, color: green, shape: circle}
{fruit: pear, animal: cat, color: pink}
{fruit: pear, animal: dog, color: green}
{fruit: banana}
{fruit: banana, animal: cat}
On main (40aa308) the result is:
{ fruit: 'apple', animal: 'cat', color: 'green', shape: 'circle' }
{ fruit: 'apple', animal: 'dog', color: 'green', shape: 'circle' }
{ fruit: 'pear', animal: 'cat', color: 'green' }
{ fruit: 'pear', animal: 'dog', color: 'green' }
{ color: 'pink', animal: 'cat', fruit: 'apple', shape: 'circle' } <- not a GitHub cell
{ fruit: 'banana', animal: 'cat' } <- `{fruit: banana}` was extended instead of kept
A matrix of only includes, { include: [{ os: "ubuntu-latest" }, { node: "20" }] }, gives one merged cell, { os, node }. GitHub runs two.
Impact
Each instance's assignment drives ${{ matrix.* }} rendering and step if: evaluation in inferPipeline. With the wrong cells, the pipeline reproduces commands and step conditions GitHub never runs. A common pattern, include: [{ experimental: false }, { node: 20, experimental: true }], adds a phantom {node: 20, experimental: true} cell, and node: 20 keeps experimental: false. Steps gated on matrix.experimental then evaluate the wrong way.
Failing test
tests/ci-inference/matrix.test.ts in the linked PR. Output on main:
test at tests/ci-inference/matrix.test.ts:10:1
✖ matrix include follows GitHub's documented expansion example (4.67525ms)
AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected
... Skipped lines
[
{
animal: 'cat',
+ color: 'green',
- color: 'pink',
fruit: 'apple',
shape: 'circle'
},
{
animal: 'dog',
...
animal: 'cat',
+ color: 'green',
- color: 'pink',
fruit: 'pear'
},
{
animal: 'dog',
color: 'green',
...
{
+ animal: 'cat',
+ color: 'pink',
+ fruit: 'apple',
+ shape: 'circle'
- fruit: 'banana'
},
Activity
fix(ci-inference): expand matrix include the way GitHub does (DiffCI#165