import {execFileSync,spawnSync} from 'node:child_process'; import {appendFileSync} from 'node:fs'; export const groups=['rust','windows','windows_native','static','xtask','node','eval','execution','debug','web','scripts','macos_scripts','dependencies','sharing']; const everything=Object.fromEntries(groups.map(group=>[group,true])); const documentation=/^docs\/|^[^/]+\.md$/; const cargoManifest=/(?:^|\/)Cargo\.toml$/; // The Windows-only boundary flows no other platform compiles (#2065): the // product files behind crates/dim-agent-capabilities/tests/file_storage_flow.rs, // tests/host_platform_windows_flow.rs and crates/dim-app-server/tests/named_pipe_flow.rs, // the worktree removal refusal in crates/dim-app-server/src/worktrees.rs and its // flow in crates/dim-app-server/tests/worktree_removal_flow.rs, the test targets // that include them, and the runner that selects them. A file // missing here still reaches the Windows step on the daily sweep, so add it when // a Windows branch of those flows moves or gains another file. // The same tests are named in scripts/test-windows-native.mjs's `flows`, which // decides what the step runs; this list decides whether it runs at all. Change both // together. Without a path here, a change to that file reaches the step only on the // daily sweep or through another matching file; without a `flows` entry, the test // never runs, the daily sweep included. const windowsNative=[ /^crates\/dim-agent-capabilities\/src\/(?:file_storage\.rs|file_storage\/|host_platform\.rs|host_platform\/)/, /^crates\/dim-agent-capabilities\/tests\/(?:capabilities_flow|file_storage_flow|host_platform_windows_flow)\.rs$/, /^crates\/dim-app-server\/src\/(?:lib|transport|pipe_client|cli|worktrees)\.rs$/, /^crates\/dim-app-server\/tests\/(?:app_server_flow|named_pipe_flow|worktree_removal_flow)\.rs$/, /^scripts\/test-windows-native\.mjs$/, ]; const rules=[ [/^benchmarks\/baselines\/[^/]+\.json$/,[]], [/^\.agents\/|^skills\/|^\.github\/(?:ISSUE_TEMPLATE\/|pull_request_template\.md$|PULL_REQUEST_TEMPLATE\.md$)/,[]], [/^docs\/architecture\/rust-agent\/plugins\//,['xtask']], [/^docs\/design\/appserver\/native-storage-format\.md$/,['rust']], // scripts/tui-tmux.test.mjs reads this page and checks every scenario is documented. [/^docs\/architecture\/tui-e2e\.md$/,['scripts']], // crates/dim-event-hub tests compare their strings to its appendix blocks. [/^docs\/design\/plugins\/EventHub\.md$/,['rust']], // runtime/plugin-sdk.test.mjs compiles its fenced TypeScript blocks. [/^docs\/typescript-plugin-authoring\.md$/,['rust','node']], // The ADR check runs in the changes job; docs alone need no build group. [documentation,[]], [/^deny\.toml$|^LICENSE$/,['dependencies']], [/^web\/src\/features\/chat\/quote-cases\.json$/,['web','rust','windows']], [/^web\/src\/.*\.(ts|vue|mjs|js)$/,['web','static']], [/^web\//,['web']], [/^runtime\/native-sharing\/|^crates\/dim-terminal-transport\//,['rust','sharing']], [/^crates\/dim-cli\/src\/(?:sharing|ui\/remote_access)\.rs$/,['rust','windows','sharing']], [/^scripts\/(?:build-sharing|native-sharing-flow)\.mjs$/,['rust','scripts','sharing']], [/^scripts\/run-rust-test\.mjs$/,groups], [/^scripts\/test-macos-native(?:\.test)?\.mjs$/,['rust','scripts']], [/^scripts\/stage-web\.mjs$/,['scripts','web']], [/^scripts\/ci-test-concurrency\.mjs$/,['rust','scripts']], [/^scripts\/ci-web-check\.ps1$/,['scripts','web']], [/^scripts\/ci-windows-target\.ps1$/,['scripts','windows']], [/^scripts\/ci-windows-native-tools\.ps1$/,['scripts','windows','windows_native']], [/^scripts\/(code-layout\/|code-layout-darwin\.test\.mjs$)/,['scripts','macos_scripts']], [/^scripts\/(stage-release|pack-release|native-binary|store-formats|release\.test)\.mjs$/,['scripts','macos_scripts']], [/^scripts\//,['scripts']], [/^docker\//,['scripts']], // The startup, replacement and update paths these acceptances protect. [/^crates\/dim-cli\/src\/(?:client\.rs|update(?:\.rs|\/))/,['rust','windows','debug']], [/^crates\/dim-cli\/src\/(?:lib\.rs|plugins\.rs|session_host(?:\.rs|\/)|ui\/)/,['rust','windows','debug']], [/^crates\/dim-cli\//,['rust','windows']], [/^crates\/dim-client\//,['rust','windows','node']], [/^crates\/dim-agent-types\//,['rust','windows','node']], // Debug-build acceptances (#2218) leave ordinary workspace tests. The owning // test files and the production paths they protect select the dedicated step. [/^crates\/dimcode\/tests\/(?:cli_flow|cli_daemon_flow)\.rs$/,['rust','debug']], [/^crates\/dimcode\/tests\/cli_flow\/(?:daemon_startup_progress|daemon_replace|staged_update)\.rs$/,['rust','debug']], [/^crates\/dimcode\/tests\/support\/(?:cli_harness|daemon)\.rs$/,['rust','node','debug']], [/^crates\/dimcode\/(?:Cargo\.toml|src\/main\.rs)$/,['rust','debug']], [/^crates\/dimcode\//,['rust']], [/^crates\/dim-agent-capabilities\/src\/build\.rs$/,['rust','node','debug']], [/^crates\/dim-app-server\/src\/transport\.rs$/,['rust','node','debug']], [/^crates\/dim-app-server\/src\/protocol\.rs$/,['rust','node','web','scripts']], [/^crates\/dim-app-server\/src\/storage\/sqlite\.rs$/,['rust','node','scripts','macos_scripts','debug']], [/^crates\/dim-app-server\/src\/cli\.rs$/,['rust','node','debug']], [/^crates\/dim-app-server\/resources\//,['rust','node','scripts']], [/^crates\/dim-agent-capabilities\/src\/(workspace_tools\/(background|exec)|host_platform)/,['rust','node','execution']], [/^tests\/integration\/tests\/(local_execution|local_support|minimal_execution)/,['rust','node','execution']], [/^vendor\/grok-build\//,['rust','windows','node']], [/^xtask\/check\//,['static','xtask']], [/^xtask\//,['rust','node','eval']], [/^(crates|tests|vendor|runtime|npm)\//,['rust','node']], ]; // The platforms full verification runs on for an event: pull requests verify // Linux, a `main` push verifies macOS, and a sweep or manual run covers both. export function platforms(event) { if (event === 'pull_request') return ['linux']; if (event === 'push') return ['macos']; return ['linux', 'macos']; } export function classify(files) { const needed=new Set(); for (const file of files) { const rule=rules.find(([pattern])=>pattern.test(file)); for (const group of rule?rule[1]:groups) needed.add(group); if (cargoManifest.test(file)) needed.add('dependencies'); if (windowsNative.some(pattern=>pattern.test(file))) needed.add('windows_native'); } return Object.fromEntries(groups.map(group=>[group,needed.has(group)])); } function changedFiles(base) { return execFileSync('git',['diff','--name-only','--no-renames','-z',base,'HEAD','--'],{encoding:'utf8'}).split('\0').filter(Boolean); } if (import.meta.main) { let result=everything; if (process.env.GITHUB_EVENT_NAME==='pull_request') { const files=changedFiles('HEAD^1'); console.log(JSON.stringify(files)); result=classify(files); } else if (process.env.GITHUB_EVENT_NAME==='push') { const base=process.env.DIM_CI_PUSH_BEFORE; if (/^[a-f0-9]{40}$/.test(base) && base!=='0'.repeat(40)) { try { if (spawnSync('git',['cat-file','-e',`${base}^{commit}`]).status!==0) { execFileSync('git',['fetch','--no-tags','--depth=1','origin',base],{stdio:'pipe',timeout:30_000}); } const files=changedFiles(base); if (files.length) { console.log(JSON.stringify(files)); const selected=classify(files); // Stage ADR 026 D5 rollout: skip main pushes that select no check // group, and keep code pushes full until the daily sweep is verified. if (!Object.values(selected).includes(true)) result=selected; } } catch { console.log('Could not compare the push base; running all check groups.'); } } } const lines=Object.entries(result).map(([group,value])=>`${group}=${value}`); console.log(lines.join('\n')); if(process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT,`${lines.join('\n')}\nplatforms=${JSON.stringify(platforms(process.env.GITHUB_EVENT_NAME))}\n`); }