From b78bf7d8d424bd4c3676f03aca654b1092d046b4 Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Sun, 29 Nov 2026 18:24:52 +0800 Subject: [PATCH] List every node --test input in the CI guard The frontend test step ran three node --test inputs behind an ls guard that listed only .github/scripts/*.test.mjs. node --test exits 0 with zero tests when a pattern matches no file, so renaming tests/ or the compose planner file would have left the step green with missing coverage. List all three inputs before the run, in a block scalar, and make tests/ci_test_list.test.mjs require the guard and the run line to name exactly the same inputs: the guard must come first, and neither a missing guard entry nor an input dropped from the run line may pass. Related #3440 --- .github/workflows/tests.yml | 9 ++++++--- tests/ci_test_list.test.mjs | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 41d04e0e8..ccf1d5e52 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,9 +25,12 @@ jobs: with: node-version: '22' # The ls guard is not decoration: node --test treats a pattern that matches no file as zero - # tests and exits 0 (measured on Node 24.22), so without it this step would go green if the - # script tests ever disappeared. - - run: ls .github/scripts/*.test.mjs > /dev/null && node --test tests/*.test.mjs .github/scripts/*.test.mjs manager/compose-planner/compose-command-planner.test.js + # tests and exits 0 (measured on Node 24.22 and 22.23.5), so every input is listed before the + # run. A rename or a move of any of the three now fails this step instead of passing with no + # tests at all. + - run: | + ls tests/*.test.mjs .github/scripts/*.test.mjs manager/compose-planner/compose-command-planner.test.js > /dev/null + node --test tests/*.test.mjs .github/scripts/*.test.mjs manager/compose-planner/compose-command-planner.test.js management: name: Management API ยท Python ${{ matrix.python }} diff --git a/tests/ci_test_list.test.mjs b/tests/ci_test_list.test.mjs index dae4c5cee..c8a0a614a 100644 --- a/tests/ci_test_list.test.mjs +++ b/tests/ci_test_list.test.mjs @@ -4,10 +4,27 @@ import test from 'node:test'; const workflow = readFileSync(new URL('../.github/workflows/tests.yml', import.meta.url), 'utf8'); -test('CI runs all web tests, the script tests and the compose planner in one test invocation', () => { - assert.match( - workflow, - /^ {6}- run: ls \.github\/scripts\/\*\.test\.mjs > \/dev\/null && node --test tests\/\*\.test\.mjs \.github\/scripts\/\*\.test\.mjs manager\/compose-planner\/compose-command-planner\.test\.js$/m, +test('CI lists every node --test input before running it', () => { + // node --test exits 0 when a pattern matches no file, so a renamed or moved suite would + // otherwise turn this step green with zero tests. The two lines must list exactly the same + // inputs: an input missing from the guard is unguarded, and an input missing from the run line + // is coverage that silently stopped running. + const block = workflow.match(/^ {6}- run: \|\n((?: {10}.*\n)+)/m); + assert.ok(block, 'the frontend test step must be a block scalar'); + const lines = block[1].split('\n').filter(Boolean); + assert.ok(lines.length >= 2, 'the block must hold an ls guard and a node --test line'); + const guardIndex = lines.findIndex((line) => /^\s*ls\s/.test(line)); + const runIndex = lines.findIndex((line) => /\bnode --test\b/.test(line)); + assert.ok(guardIndex !== -1, 'the block must guard its inputs with ls'); + assert.ok(runIndex !== -1, 'the block must run node --test'); + assert.ok(guardIndex < runIndex, 'the ls guard must come before node --test'); + const guardArgs = lines[guardIndex].replace(/^\s*ls\s+/, '').replace(/\s*>\s*\/dev\/null$/, '').trim().split(/\s+/); + const runArgs = lines[runIndex].replace(/^\s*node --test\s+/, '').trim().split(/\s+/); + assert.ok(runArgs.length > 0); + assert.deepEqual( + [...guardArgs].sort(), + [...runArgs].sort(), + 'the ls guard must list exactly the inputs on the node --test line', ); });