Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
CI planner: shard broad scoped plans instead of forcing full CI
Claude7e5ee09e542f
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.mdindex 4a83e77211..c7bdd0278d 100644--- a/docs/GITHUB_ACTIONS.md+++ b/docs/GITHUB_ACTIONS.md@@ -527,9 +527,19 @@ extra shards. `scripts/run-ci-tests.js` turns `CI_SHARD=<index>/<count>` intoVitest's `--shard`, which slices the file list by path hash — every shard is afixed, disjoint subset, and their union is the complete selected suite. Windowsrelated plans retain the same source graph and explicit contracts on every-shard; only execution is partitioned. Exact-file plans stay on one runner-(their handful of files can trip Vitest's shard-count guard), and scoped Linux-plans also retain one runner. Once-only steps — smoke boot, the client build, the+shard; only execution is partitioned. Scoped Linux plans fan out the same way+(`fansOut()` in the planner): a server `related` plan always does, because its+import-graph reach is unbounded by the explicit selector count (scoped server+runs took 6.1 min median, 9.4 p90, on one runner), and either runner does when+its explicit selection exceeds `MAX_TARGETED_TEST_FILES` (125). That cap used to+force a full plan for the whole repository; it now keeps the scoped selection+and only partitions it, so a server-only overflow no longer starts three client+shards, the DB/browser suites, and a Windows run (#11871). Exact-file plans+under the cap and client `related` plans stay on one runner. Vitest refuses a+shard count above the number of files it resolved, so a runner fans out only+when at least that many explicit selectors are files the Linux job actually+runs (DB and browser suites have their own jobs); each shard repeats Vitest's+related-graph pass, the trade the Windows job already makes. Once-only steps — smoke boot, the client build, theScalar-removal bundle pin — pin themselves to shard 1; lint is not among them,because it has its own job (see above). `CI Gate` sees a matrix job as one`needs` result, so nothing downstream changes; public-repo runner minutes are@@ -570,7 +580,7 @@ reason `windows-server` cannot observe:| Full-plan reason | Runs | Windows-relevant? || --- | --- | --- |-| targeted test set exceeded safety cap | 17 | no — capacity, not risk |+| targeted test set exceeded safety cap (no longer full; see "Full-suite sharding") | 17 | no — capacity, not risk || wide change (>30 executable files) | 6 | no — capacity, not risk || client composition root / build config / lint config / test setup | 1 | no — client-only || dependency manifest, server contract, CI pipeline script, workflow, … | 40 | yes |@@ -844,9 +854,16 @@ successor run".case fails closed to the complete suite.- Database adapters, DB scripts, and relevant migrations add the completeserial DB suite.+- A changed source's basename lookup (`git grep` of test files, #6363) keeps+ every hit for a unique basename. For a basename several tracked sources+ share (`index.js`, `providers.js`), it keeps only tests inside the source's+ directory subtree or whose text also names its parent directory, so a+ `server/cos-runner/index.js` edit no longer selects every test naming any+ `index.js` (#11870). Import-graph selection still reaches real importers.- Unmapped executable files use related-test mode. Unclassified artifacts,- shared roots/config, more than 30 executable changes, or more than 125- selected tests fail safe to full CI.+ shared roots/config, or more than 30 executable changes fail safe to full+ CI. More than 125 selected tests on one runner keeps the scoped selection+ and shards that runner instead.## Release Workflow (`release.yml`)diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.jsindex 90bd9772ba..0d48411f14 100644--- a/scripts/ci-test-plan.js+++ b/scripts/ci-test-plan.js@@ -4,6 +4,7 @@ import { execFileSync } from 'child_process';import { existsSync, readFileSync } from 'fs';import { join, posix } from 'path';import { staticImportSpecifiersFromSource } from '../server/lib/staticImportGraph.js';+import { escapeRegExp } from '../server/lib/textUtils.js';import { isDirectlyInvoked } from './lib/directInvocation.js';import { writeStepOutput } from './lib/githubOutput.js';import { resolveDbTestFiles } from './lib/dbTestFiles.js';@@ -25,9 +26,12 @@ const SERVER_LINT_RE = /^server\/(?!node_modules\/).*\.(?:m?js)$|^server\/biome\const isLintSurface = (path) => CLIENT_LINT_RE.test(path) || SERVER_LINT_RE.test(path);const EXECUTABLE_RE = /\.(?:cjs|css|html|js|jsx|json|mjs|sql|ts|tsx|ya?ml)$/i;const MAX_CHANGED_CODE_FILES = 30;-// 125, not 120: the always-run guards grew to the old edge, and the real-repo-// editorial-leaf planner test sat exactly on it (#10312).-const MAX_TARGETED_TEST_FILES = 125;+// Explicit selectors one runner carries before its scoped plan fans out across+// the full-suite shard matrix. It used to escalate the whole repository to a+// full plan; over-selection is a capacity limit, not a risk signal, so the+// selection now stays exactly as computed and only execution is partitioned+// (#11871). 125 is that former full-plan threshold (#10312).+export const MAX_TARGETED_TEST_FILES = 125;// Preserve the planner's public registry export for existing callers.export { BROWSER_SUITES } from './lib/browserSuites.js';@@ -62,6 +66,31 @@ export const shardIndexes = (mode, count) => (mode === 'full' ? Array.from({ length: count }, (_, index) => index + 1) : [1]);+/**+ * Whether a scoped Linux runner fans out across its full-suite shard count.+ *+ * - Over MAX_TARGETED_TEST_FILES explicit selectors: either runner, either mode.+ * - Server `related` mode: always. Its import-graph fan-out is unbounded by the+ * explicit count (#9999: 57 selectors became ~941 files), and scoped server+ * runs took 6.1 min median / 9.4 p90 on one runner. Each shard repeats+ * Vitest's related-graph pass, which is the Windows job's existing trade.+ * Client related plans stay on one runner unless over the cap.+ * - Exact-file plans under the cap stay on one runner: they run in seconds.+ *+ * Vitest throws when the shard count exceeds the files it resolved+ * (`--shard <count> must be a smaller than count of test files`). Every+ * explicit selector is in the resolved set — `vitest related` selects a test+ * file passed as input — so the floor counts explicit files the Linux runner+ * does not exclude (DB suites run in their own job, browser suites in theirs).+ * Below the floor the runner stays on one shard.+ */+const fansOut = (runner, { mode, files }, excludedFiles) => {+ if (mode === 'skip' || mode === 'full') return false;+ const runnable = files.filter((path) => !excludedFiles.has(path));+ if (runnable.length < FULL_SUITE_SHARDS[runner]) return false;+ return files.length > MAX_TARGETED_TEST_FILES || (runner === 'server' && mode === 'related');+};+// `windowsEscalates` decides whether a trigger widens the WINDOWS job too, not// only the Linux ones. Three windows-server shards are 3 of a full run's 12// jobs and 41% of its runner-minutes (58% at GitHub's 2x windows-latest@@ -386,12 +415,14 @@ const SLASHDO_CONTRACT_SOURCE_FILES = [* changing would not set this, even though Vitest's real `related` selection* can still transitively pull the contract tests in — in which case they run* without the submodule and take the documented skip. In practice a- * sufficiently shared dependency changing also tends to select enough tests- * to exceed MAX_TARGETED_TEST_FILES and force a full plan, which does trigger- * this; a narrowly-shared one is the remaining gap.+ * sufficiently shared dependency changing also tends to select more than+ * MAX_TARGETED_TEST_FILES explicit server tests, which does trigger this (as+ * the full plan that cap used to force did); a narrowly-shared one is the+ * remaining gap.*/export const needsSlashdoSubmodule = (plan) => Boolean(plan.full+ || plan.server.files.length > MAX_TARGETED_TEST_FILES|| plan.changedFiles.includes(SLASHDO_GITLINK_PATH)|| plan.server.files.some((path) => SLASHDO_CONTRACT_TEST_FILES.includes(path))|| plan.server.sources.some((path) => SLASHDO_CONTRACT_SOURCE_FILES.includes(path))@@ -634,19 +665,29 @@ export const isRouteOnlyAppDiff = (diff) => {return changedLines.length > 0 && changedLines.every((line) => /^[-+]\s*<\/?Route\b.*>(?:\s*)$/.test(line));};+// A scoped runner spread over several shards says why, so the summary never+// reads as a full run.+const fanOutNote = (plan, runner) => {+ const count = plan.shards[runner].length;+ if (plan.full || count === 1) return '';+ return plan[runner].files.length > MAX_TARGETED_TEST_FILES+ ? `; ${plan[runner].files.length} selected test files exceed the ${MAX_TARGETED_TEST_FILES}-file cap, sharded ${count} ways`+ : `; related import graph sharded ${count} ways`;+};+const suiteReasonsFor = (plan, { appRouteOnly = false } = {}) => ({server: plan.server.mode === 'skip'? 'skipped: no server-impacting source changed': plan.full? `full matrix: ${plan.reason}`- : 'always-run cross-install and repository guards',+ : `always-run cross-install and repository guards${fanOutNote(plan, 'server')}`,client: plan.client.mode === 'skip'? 'skipped: no client-impacting source changed': appRouteOnly- ? 'route-only client App.jsx change: related client contracts'+ ? `route-only client App.jsx change: related client contracts${fanOutNote(plan, 'client')}`: plan.full? `full matrix: ${plan.reason}`- : 'client-impacting source changed',+ : `client-impacting source changed${fanOutNote(plan, 'client')}`,browser: plan.browserFiles.length > 0? (plan.full ? `full matrix: ${plan.reason}` : `${plan.browserFiles.length} cross-workspace browser suite(s) selected`): 'skipped: no cross-workspace browser suite selected',@@ -853,10 +894,6 @@ export function buildCiTestPlan(changedFiles, {const serverFiles = uniqueSorted(selectedTests.filter((path) => runnerForTest(path) === 'server'));const clientFiles = uniqueSorted(selectedTests.filter((path) => runnerForTest(path) === 'client'));- if (serverFiles.length > MAX_TARGETED_TEST_FILES || clientFiles.length > MAX_TARGETED_TEST_FILES) {- return fullPlan(changed, 'targeted test set exceeded safety cap', { appRouteOnly, trackedSet, windowsEscalates: false });- }-const hasServerSource = jsSources.some(isServerRunnerFile);const hasClientSource = jsSources.some(isClientSource);@@ -931,25 +968,38 @@ export function buildCiTestPlan(changedFiles, {...directTests.filter(path => isServerRunnerFile(path) && hasWindowsRiskFile([path])),]) : [],windowsSources: windowsMode === 'related' ? serverSources : [],- }, { appRouteOnly });+ }, { appRouteOnly, linuxRunnerExcludes: new Set([...dbTests, ...BROWSER_SUITES]) });}-/** The derived fields every plan carries: per-suite reasons and shard matrices. */-const finishPlan = (plan, options) => ({- ...plan,- slashdo: needsSlashdoSubmodule(plan),- suiteReasons: suiteReasonsFor(plan, options),- shards: {- server: shardIndexes(plan.server.mode, FULL_SUITE_SHARDS.server),- client: shardIndexes(plan.client.mode, FULL_SUITE_SHARDS.client),+/**+ * The derived fields every plan carries: per-suite reasons and shard matrices.+ *+ * `linuxRunnerExcludes` names selected files the Linux test jobs never run+ * (DB and browser suites have their own jobs); fansOut() keeps them out of the+ * shard-count floor.+ */+const finishPlan = (plan, { linuxRunnerExcludes = new Set(), ...options } = {}) => {+ const linuxShards = (runner) => shardIndexes(+ fansOut(runner, plan[runner], linuxRunnerExcludes) ? 'full' : plan[runner].mode,+ FULL_SUITE_SHARDS[runner],+ );+ const shards = {+ server: linuxShards('server'),+ client: linuxShards('client'),// Related mode can reach most of the server graph through one shared// source. The explicit selector count does not bound that work: one Windows// runner exceeded the unchanged 15-minute step budget on a TUI handshake// edit. Split execution across the existing matrix without widening or// reducing related-test selection; exact-file plans stay on one runner.windows: shardIndexes(plan.windowsMode === 'related' ? 'full' : plan.windowsMode, FULL_SUITE_SHARDS.windows),- },-});+ };+ return {+ ...plan,+ slashdo: needsSlashdoSubmodule(plan),+ suiteReasons: suiteReasonsFor({ ...plan, shards }, options),+ shards,+ };+};/*** A full plan for every Linux suite — with the Windows job at the depth the@@ -957,7 +1007,7 @@ const finishPlan = (plan, options) => ({** `windowsEscalates` (default true, so an unlisted caller fails closed) is* false only for a trigger windows-server cannot observe: a client-only- * surface, or a CAPACITY escalation (the targeted-test cap, a wide diff) that+ * surface, or a CAPACITY escalation (a wide diff) that* says the planner ran out of scoping headroom, not that anything risky* changed. A touched WINDOWS_RISK_RULES path overrides it back to full.*@@ -1011,6 +1061,41 @@ const gitGrepFiles = (pattern, pathspecs, cwd) => {}};+const basenameOf = (path) => path.slice(path.lastIndexOf('/') + 1);++/** Basenames carried by more than one present, executable, non-test source. */+const sharedSourceBasenames = (files) => {+ const seen = new Set();+ const shared = new Set();+ for (const path of files) {+ if (!isExecutable(path) || isTestFile(path)) continue;+ const name = basenameOf(path);+ (seen.has(name) ? shared : seen).add(name);+ }+ return shared;+};++/**+ * Keep the basename hits that plausibly mean THIS copy of a shared basename:+ * a test inside the source's directory subtree (it reaches the file as+ * `./name` or `../name`), or one whose text also names the source's parent+ * directory as a token (`cos-runner`, `aiToolkit`, `join(…, 'imageGen', …)`).+ * A test naming only another directory's `index.js` is dropped; Vitest's+ * import graph still selects every real importer. A repo-root source has no+ * parent to tell copies apart, so it keeps every hit (#11870).+ */+const narrowSharedBasenameHits = (source, hits, cwd) => {+ const dir = posix.dirname(source);+ if (dir === '.' || hits.length === 0) return hits;+ const parent = basenameOf(dir);+ const naming = new Set(gitGrepFiles(+ `(^|[^A-Za-z0-9_])${escapeRegExp(parent)}([^A-Za-z0-9_]|$)`,+ hits.map((path) => `:(literal)${path}`),+ cwd,+ ));+ return hits.filter((path) => path.startsWith(`${dir}/`) || naming.has(path));+};+export function emitGitHubPlan(plan) {const outputs = {full: plan.full,@@ -1184,11 +1269,17 @@ export function collectPlanInputs({ baseSha, forceFull = false, changedFiles, cw// the text-reading contract tests (mirror parity, navManifest.js's 20+ client// reads) that no import edge or feature-directory match can reach. Basename// matching is deliberate: a mirror test names the client copy only as e.g.- // 'canonPrompt.js', never by its full path. Over-selection here costs- // seconds; under-selection is the bug this closes (issue #6363).- const pathContractTests = Object.fromEntries(collectedChangedFiles- .filter((path) => isExecutable(path) && !isTestFile(path))- .map((path) => [path, gitGrepFiles(sourceReferencePattern(path), TEST_FILE_GLOBS, cwd)]));+ // 'canonPrompt.js', never by its full path. Under-selection is the bug this+ // closes (issue #6363), but over-selection is not free: every hit is an+ // explicit selector, and a broad selection fans the runner out across shards.+ // A basename several tracked sources share (42 `index.js`) is narrowed by+ // narrowSharedBasenameHits (#11870).+ const changedSources = collectedChangedFiles.filter((path) => isExecutable(path) && !isTestFile(path));+ const sharedBasenames = changedSources.length > 0 ? sharedSourceBasenames(presentFiles) : new Set();+ const pathContractTests = Object.fromEntries(changedSources.map((path) => {+ const hits = gitGrepFiles(sourceReferencePattern(path), TEST_FILE_GLOBS, cwd);+ return [path, sharedBasenames.has(basenameOf(path)) ? narrowSharedBasenameHits(path, hits, cwd) : hits];+ }));const clientDependencies = collectedChangedFiles.some((path) => path.startsWith('server/lib/')&& isExecutable(path) && !isTestFile(path))diff --git a/scripts/ci-test-plan.test.js b/scripts/ci-test-plan.test.jsindex d41249ca67..21276b3133 100644--- a/scripts/ci-test-plan.test.js+++ b/scripts/ci-test-plan.test.js@@ -15,6 +15,7 @@ import {forceFullReasonFor,FULL_SUITE_SHARDS,isRouteOnlyAppDiff,+ MAX_TARGETED_TEST_FILES,needsSlashdoSubmodule,shardIndexes,SLASHDO_GITLINK_PATH,@@ -175,6 +176,38 @@ it('preserves Git-quoted source and contract paths through the planner CLI', ()}});+it('narrows a shared basename to tests that can mean the changed copy, and keeps a unique one by name (#11870)', () => {+ const root = mkdtempSync(join(tmpdir(), 'portos-ci-basenames-'));+ const git = (...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim();+ const write = (path, body) => {+ mkdirSync(dirname(join(root, path)), { recursive: true });+ writeFileSync(join(root, path), body);+ };+ const alpha = 'server/alpha/index.js';+ const mirror = 'client/src/lib/mirrorOnly.js';+ const tests = {+ inDirectory: ['server/alpha/local.test.js', "readFileSync(new URL('./index.js', import.meta.url));\n"],+ inSubtree: ['server/alpha/nested/deep.test.js', "readFileSync(new URL('../index.js', import.meta.url));\n"],+ namesAlpha: ['server/other/namesAlpha.test.js', "readFileSync(join(root, 'alpha', 'index.js'));\n"],+ namesBeta: ['server/other/namesBeta.test.js', "readFileSync(join(root, 'beta', 'index.js'));\n"],+ mirror: ['server/other/mirror.test.js', "readFileSync(join(clientLib, 'mirrorOnly.js'));\n"],+ };+ try {+ git('init', '-q');+ for (const source of [alpha, 'server/beta/index.js', mirror]) write(source, 'export const value = 1;\n');+ for (const [path, body] of Object.values(tests)) write(path, body);+ git('add', '--all');++ const { pathContractTests } = collectPlanInputs({ baseSha: 'HEAD', changedFiles: [alpha, mirror], cwd: root });+ expect(pathContractTests[alpha].sort()).toEqual(+ [tests.inDirectory[0], tests.inSubtree[0], tests.namesAlpha[0]].sort());+ // A unique basename keeps the #6363 lookup: the mirror test names no directory.+ expect(pathContractTests[mirror]).toEqual([tests.mirror[0]]);+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+});+it('builds the same plan from an explicit working-tree override as from the equivalent commit', () => {const root = mkdtempSync(join(tmpdir(), 'portos-ci-override-'));const git = (...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim();@@ -990,7 +1023,7 @@ describe('CI test impact planner', () => {expect(re.test("'generate_ltx2xpy'")).toBe(false);});- it('shards full plans and Windows related graphs while keeping exact-file plans on one runner', () => {+ it('shards full plans and related graphs while keeping small exact-file plans on one runner', () => {expect(shardIndexes('full', 3)).toEqual([1, 2, 3]);expect(shardIndexes('related', 3)).toEqual([1]);expect(shardIndexes('files', 3)).toEqual([1]);@@ -1010,7 +1043,7 @@ describe('CI test impact planner', () => {const relatedWindows = buildCiTestPlan(['server/lib/bufferedSpawn.js'], { trackedFiles: TRACKED });expect(relatedWindows).toMatchObject({ full: false, windowsMode: 'related',windowsSources: ['server/lib/bufferedSpawn.js'],- shards: { server: [1], client: [1], windows: [1, 2, 3] } });+ shards: { server: [1, 2], client: [1], windows: [1, 2, 3] } });expect(relatedWindows.windowsFiles).toEqual(WINDOWS_CONTRACT_TESTS.filter(path => TRACKED.includes(path)).sort());const exactWindows = buildCiTestPlan(['server/lib/bufferedSpawn.test.js'], { trackedFiles: TRACKED });expect(exactWindows).toMatchObject({ windowsMode: 'files', shards: { windows: [1] } });@@ -1018,6 +1051,80 @@ describe('CI test impact planner', () => {expect(docsOnly.shards).toEqual({ server: [1], client: [1], windows: [1] });});+ describe('scoped fan-out instead of a full plan (#11871)', () => {+ const SERVER_FANOUT = shardIndexes('full', FULL_SUITE_SHARDS.server);+ const CLIENT_FANOUT = shardIndexes('full', FULL_SUITE_SHARDS.client);+ const featureTests = (prefix, count, ext = 'js') => Array.from({ length: count },+ (_, i) => `${prefix}/case${String(i).padStart(3, '0')}.test.${ext}`);++ it('keeps an over-cap server selection scoped, runs every selected test, and fans only the server out', () => {+ const source = 'server/services/bigfeature/core.js';+ const tests = featureTests('server/services/bigfeature', MAX_TARGETED_TEST_FILES + 5);+ const plan = buildCiTestPlan([source], { trackedFiles: [...TRACKED, ...WINDOWS_CONTRACT_TESTS, source, ...tests] });++ expect(plan).toMatchObject({ full: false, reason: 'targeted features: bigfeature',+ server: { mode: 'related', sources: [source] }, client: { mode: 'skip' },+ lint: { mode: 'files', files: [source] }, build: false, smoke: true, windows: false });+ // Sharding partitions the selection; it never drops a selector.+ expect(plan.server.files).toEqual(expect.arrayContaining(tests));+ expect(plan.shards).toEqual({ server: SERVER_FANOUT, client: [1], windows: [1] });+ expect(plan.suiteReasons.server).toMatch(/exceed the 125-file cap, sharded 2 ways/);+ // A broad shared dependency can still reach the slashdo contracts.+ expect(plan.slashdo).toBe(true);+ });++ it('fans the client out only when its own selection is over the cap', () => {+ const source = 'client/src/components/bigfeature/Panel.jsx';+ const tests = featureTests('client/src/components/bigfeature', MAX_TARGETED_TEST_FILES + 5, 'jsx');+ const plan = buildCiTestPlan([source], { trackedFiles: [...TRACKED, source, ...tests] });++ expect(plan).toMatchObject({ full: false, client: { mode: 'related', sources: [source] }, build: true });+ expect(plan.client.files).toEqual(expect.arrayContaining(tests));+ expect(plan.shards.client).toEqual(CLIENT_FANOUT);+ expect(plan.shards.server).toEqual([1]);++ const underCap = buildCiTestPlan([source], { trackedFiles: [...TRACKED, source, ...tests.slice(0, 20)] });+ expect(underCap.shards.client).toEqual([1]);+ });++ it('shards a server related graph, but not an exact-file plan under the cap', () => {+ const source = 'server/services/flat.js';+ const tests = featureTests('server/services/flatfeature', 3);+ const trackedFiles = [...TRACKED, source, ...tests];+ const related = buildCiTestPlan([source, ...tests.slice(0, 2)], { trackedFiles });+ expect(related.server.mode).toBe('related');+ expect(related.shards.server).toEqual(SERVER_FANOUT);+ expect(related.suiteReasons.server).toMatch(/related import graph sharded 2 ways/);++ const exact = buildCiTestPlan(tests, { trackedFiles });+ expect(exact.server.mode).toBe('files');+ expect(exact.shards.server).toEqual([1]);++ // A barrel-only edit keeps exact-file selection; over the cap it fans out.+ const barrel = 'server/lib/index.js';+ const named = featureTests('server/consumers', MAX_TARGETED_TEST_FILES + 1);+ const barrelPlan = buildCiTestPlan([barrel], { trackedFiles: [...TRACKED, ...named],+ pathContractTests: { [barrel]: named } });+ expect(barrelPlan.server.mode).toBe('files');+ expect(barrelPlan.server.files).toEqual(expect.arrayContaining(named));+ expect(barrelPlan.shards.server).toEqual(SERVER_FANOUT);+ });++ it("stays on one runner when Vitest's shard guard could see fewer files than shards", () => {+ // Vitest throws when the shard count exceeds the files it resolves. The+ // Linux job never runs DB or browser suites, so they cannot meet the floor.+ const source = 'server/services/flat.js';+ const unit = 'server/services/flat.test.js';+ const floor = (extra) => buildCiTestPlan([source, unit, ...extra],+ { trackedFiles: [source, unit, ...extra] }).shards.server;++ expect(floor([])).toEqual([1]);+ expect(floor(['server/services/appQuality.db.test.js'])).toEqual([1]);+ expect(floor(['server/lib/filmLook.browser.test.js'])).toEqual([1]);+ expect(floor(['server/services/flat.contract.test.js'])).toEqual(SERVER_FANOUT);+ });+ });+it('falls back to full CI for unknown artifacts and wide changes', () => {const unknown = buildCiTestPlan(['data.reference/bootstrap.bin'], {trackedFiles: TRACKED,diff --git a/scripts/run-ci-tests.js b/scripts/run-ci-tests.jsindex 3042da88ba..67637e14e6 100644--- a/scripts/run-ci-tests.js+++ b/scripts/run-ci-tests.js@@ -430,7 +430,9 @@ async function main() {process.exitCode = 0;return;}- process.exitCode = await spawnNpm(scope, 'test:ci', selectedFiles, 'selected tests');+ // The planner fans an exact-file plan out only when it selects more files+ // than the shard count (ci-test-plan.js fansOut), so the slice is never empty.+ process.exitCode = await spawnNpm(scope, 'test:ci', [...selectedFiles, ...shardArgs(process.env.CI_SHARD)], 'selected tests');return;}diff --git a/scripts/run-ci-tests.test.js b/scripts/run-ci-tests.test.jsindex d93928f483..643742854d 100644--- a/scripts/run-ci-tests.test.js+++ b/scripts/run-ci-tests.test.js@@ -55,7 +55,7 @@ describe('shardArgs', () => {});});-it('forwards the related matrix slice and all selectors through the real launcher', () => {+it('forwards the scoped matrix slice and all selectors through the real launcher', () => {const fixture = mkdtempSync(join(tmpdir(), 'portos-related-shard-'));try {const npmScript = join(fixture, 'npm.js');@@ -63,19 +63,26 @@ it('forwards the related matrix slice and all selectors through the real launchewriteFileSync(join(fixture, 'npm'), `#!${process.execPath}\n`+ 'process.stdout.write(JSON.stringify(process.argv.slice(2)) + "\\n");', { mode: 0o755 });writeFileSync(join(fixture, 'npm.cmd'), `@"${process.execPath}" "${npmScript}" %*\r\n`);- const result = spawnSync(process.execPath, [join(import.meta.dirname, 'run-ci-tests.js'), 'server'], {- encoding: 'utf8', timeout: 30000,- env: { ...process.env, PATH: `${fixture}${delimiter}${process.env.PATH}`,- CI_TEST_MODE: 'related', CI_SHARD: '2/3',- CI_TEST_SOURCES: JSON.stringify(['server/lib/example.js']),- CI_TEST_FILES: JSON.stringify(['server/lib/example.test.js', 'scripts/example.test.js']),- GITHUB_ENV: '', GITHUB_STEP_SUMMARY: '' },- });- expect(result.error).toBeUndefined();- expect(result.status, result.stderr).toBe(0);- const args = JSON.parse(result.stdout.split('\n').find(line => line.startsWith('["run"')));- expect(args.slice(0, 9)).toEqual(['run', 'test:ci:related', '--prefix', 'server', '--',- './lib/example.js', './lib/example.test.js', '../scripts/example.test.js', '--shard=2/3']);+ // The planner fans both scoped modes out (ci-test-plan.js fansOut), so+ // each must hand Vitest its slice rather than run the whole selection twice.+ for (const [mode, script, sources, expected] of [+ ['related', 'test:ci:related', ['server/lib/example.js'], ['./lib/example.js']],+ ['files', 'test:ci', [], []],+ ]) {+ const result = spawnSync(process.execPath, [join(import.meta.dirname, 'run-ci-tests.js'), 'server'], {+ encoding: 'utf8', timeout: 30000,+ env: { ...process.env, PATH: `${fixture}${delimiter}${process.env.PATH}`,+ CI_TEST_MODE: mode, CI_SHARD: '2/3',+ CI_TEST_SOURCES: JSON.stringify(sources),+ CI_TEST_FILES: JSON.stringify(['server/lib/example.test.js', 'scripts/example.test.js']),+ GITHUB_ENV: '', GITHUB_STEP_SUMMARY: '' },+ });+ expect(result.error).toBeUndefined();+ expect(result.status, result.stderr).toBe(0);+ const args = JSON.parse(result.stdout.split('\n').find(line => line.startsWith('["run"')));+ const selectors = [...expected, './lib/example.test.js', '../scripts/example.test.js', '--shard=2/3'];+ expect(args.slice(0, 5 + selectors.length), mode).toEqual(['run', script, '--prefix', 'server', '--', ...selectors]);+ }} finally {rmSync(fixture, { recursive: true, force: true });}