diff --git a/.github/workflows/continuum-rust-tests.yml b/.github/workflows/continuum-rust-tests.yml index a74ea84521..e7eb802735 100644 --- a/.github/workflows/continuum-rust-tests.yml +++ b/.github/workflows/continuum-rust-tests.yml @@ -26,6 +26,7 @@ jobs: lib_tests: ${{ steps.select.outputs.lib_tests }} cli: ${{ steps.select.outputs.cli }} bins: ${{ steps.select.outputs.bins }} + examples: ${{ steps.select.outputs.examples }} steps: - uses: actions/checkout@v4 - run: node --test tools/scripts/tests/ci-change-scope.test.cjs tools/scripts/tests/ci-cargo-freshness.test.cjs @@ -56,7 +57,7 @@ jobs: } catch (error) { core.warning(`Cannot classify changes; running all checks: ${error.message}`); } - core.info(`Selected crates: ${selection.crates.join(', ') || '(none)'}; CLI handoff: ${selection.cli}; binaries: ${JSON.stringify(selection.bins)}`); + core.info(`Selected crates: ${selection.crates.join(', ') || '(none)'}; CLI handoff: ${selection.cli}; binaries: ${JSON.stringify(selection.bins)}; examples: ${JSON.stringify(selection.examples)}`); core.setOutput('rust', String(selection.rust)); core.setOutput('installer', String(selection.installer)); core.setOutput('crates', JSON.stringify(selection.crates)); @@ -64,6 +65,7 @@ jobs: core.setOutput('lib_tests', JSON.stringify(LIB_TESTS)); core.setOutput('cli', String(selection.cli)); core.setOutput('bins', JSON.stringify(selection.bins)); + core.setOutput('examples', JSON.stringify(selection.examples)); # One job per affected crate, in parallel (card 44a3c460). The selector derives the set: # every crate a changed path lies in plus all of its dependents, from the Cargo.toml graph. @@ -162,6 +164,19 @@ jobs: for bin in $BINS; do args+=(--bin "$bin"); done cargo check --locked -p "$CRATE" --profile dev-fast --features "$FEATURES" "${args[@]}" + # ---- the examples this change touches (#5511, #5611): built, and those declaring `test = true` + # run their own tests; the lib build compiles neither ---- + - name: cargo check and test the examples this change touches + if: ${{ fromJSON(needs.changes.outputs.examples || '{}')[matrix.crate] != null }} + env: + EXAMPLES: ${{ join(fromJSON(needs.changes.outputs.examples || '{}')[matrix.crate].all, ' ') }} + TESTED: ${{ join(fromJSON(needs.changes.outputs.examples || '{}')[matrix.crate].tested, ' ') }} + run: | + args=(); for example in $EXAMPLES; do args+=(--example "$example"); done + cargo check --locked -p "$CRATE" --profile dev-fast --features "$FEATURES" "${args[@]}" + tested=(); for example in $TESTED; do tested+=(--example "$example"); done + if [ ${#tested[@]} -gt 0 ]; then cargo test --locked -p "$CRATE" --profile dev-fast --features "$FEATURES" "${tested[@]}"; fi + # ---- continuum-kernel: lib tests ---- - name: cargo test -p continuum-kernel --lib if: matrix.crate == 'continuum-kernel' diff --git a/Cargo.toml b/Cargo.toml index 5f8c41ef31..34940c3f8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -493,7 +493,7 @@ by_nature = ["continuum-cli-lifecycle", "jtag-mcp", "livekit-bridge", "llama", " # pending: tests exist but no job selects them yet (card 996e3537). Debt that only shrinks: an # entry leaves by being deleted, and crate_wiring fails if this list grows past its ceiling. pending = [ - "airc-test-fixtures", "continuum-airc-protocol", "continuum-bridge-protocol", "continuum-context", + "airc-test-fixtures", "continuum-airc-protocol", "continuum-bridge-protocol", "continuum-orm-derive", "continuum-positron", "continuum-text-analysis", "continuum-tool-protocol", "expert-pager-policy", "inference-grpc", "serving-replay", "tool-working-set", ] diff --git a/tools/scripts/ci-change-scope.cjs b/tools/scripts/ci-change-scope.cjs index dfdb8b76d5..589b2da558 100644 --- a/tools/scripts/ci-change-scope.cjs +++ b/tools/scripts/ci-change-scope.cjs @@ -50,21 +50,34 @@ function readWorkspace(root = '.') { const members = strip(read('Cargo.toml')).match(/^\s*members\s*=\s*\[([^\]]*)\]/m); if (!members) throw new Error('Cannot read workspace members from Cargo.toml'); const crates = [...members[1].matchAll(/"([^"]+)"/g)].map(([, dir]) => { - let section = ''; let name = null; const deps = new Set(); const bins = []; const features = []; + let section = ''; let name = null; const deps = new Set(); const bins = []; const examples = []; const features = []; for (const line of strip(read(`${dir}/Cargo.toml`)).split('\n')) { const header = line.match(/^\s*\[+([^\]]+)\]+/); - if (header) { section = header[1].trim(); if (section === 'bin') bins.push({}); continue; } + if (header) { + section = header[1].trim(); + if (section === 'bin') bins.push({}); + if (section === 'example') examples.push({ requiredFeatures: [], test: false }); + continue; + } if (section === 'package' && !name) name = line.match(/^\s*name\s*=\s*"([^"]+)"/)?.[1] ?? null; if (section === 'features') { const f = line.match(/^\s*([A-Za-z0-9_-]+)\s*=/); if (f) features.push(f[1]); } const field = section === 'bin' && line.match(/^\s*(name|path)\s*=\s*"([^"]+)"/); if (field) bins[bins.length - 1][field[1]] = field[2]; + if (section === 'example') { + const example = examples[examples.length - 1]; + const named = line.match(/^\s*name\s*=\s*"([^"]+)"/); + if (named) example.name = named[1]; + const required = line.match(/^\s*required-features\s*=\s*\[([^\]]*)\]/); + if (required) example.requiredFeatures = [...required[1].matchAll(/"([^"]+)"/g)].map(([, f]) => f); + if (/^\s*test\s*=\s*true\b/.test(line)) example.test = true; + } const dependency = /(^|\.)(dev-|build-)?dependencies(\.|$)/.test(section); for (const [, dep] of dependency ? line.matchAll(/\bpath\s*=\s*"([^"]+)"/g) : []) { deps.add(path.posix.normalize(path.posix.join(dir, dep))); } } if (!name) throw new Error(`Cannot read the package name of ${dir}`); - return { name, dir, deps: [...deps], features, bins: bins.filter(b => b.name && b.path) }; + return { name, dir, deps: [...deps], features, bins: bins.filter(b => b.name && b.path), examples: examples.filter(e => e.name) }; }); return { crates }; } @@ -153,25 +166,38 @@ function selectCrates(paths, workspace) { return { crates: TESTED_CRATES.filter(name => names.has(name)), cli: paths.some(cliPath) || names.has('continuum-cli-lifecycle') }; } -// The declared binaries (`[[bin]]`) of tested crates whose own source a change touches: the bin's -// file, and for `src/bin/.rs` its module directory `src/bin//`; a change to the crate's -// Cargo.toml, where the declarations live, selects all of them. Implicit (undeclared) bins are not -// read. Lib and lib-test builds never -// compile a bin, so without this a PR editing `src/main.rs` reached canary uncompiled (card -// 67bf5d81). The CLI binary is left to the handoff job, which already compiles it. A change to the -// lib a bin uses is not covered here; the hourly core-binaries publication compiles every bin. -function selectBins(paths, workspace, crates) { - const bins = {}; +// The non-lib targets of tested crates whose own source a change touches. Lib and lib-test builds +// compile neither, so without this a PR editing `src/main.rs` (card 67bf5d81) or an example +// (#5511, #5611) reached canary uncompiled. A change to the lib a target uses is not covered here; +// the hourly core-binaries publication compiles every bin. +// +// `bins`: the declared binaries (`[[bin]]`) whose file is touched, and for `src/bin/.rs` its +// module directory `src/bin//`; a change to the crate's Cargo.toml, where the declarations live, +// selects all of them. Implicit (undeclared) bins are not read. The CLI binary is left to the +// handoff job, which already compiles it. +// +// `examples`: `examples/.rs` or anything under `examples//` names the example ``, +// declared or implicit. One whose `required-features` the crate's test build does not enable is +// not selected (cargo refuses to build it). `tested` lists those declaring `test = true`, whose own +// tests run as well. +function selectTargets(paths, workspace, crates) { + const bins = {}; const examples = {}; for (const c of workspace?.crates ?? []) { if (!crates.includes(c.name)) continue; - const touched = (c.bins ?? []).filter(b => { + const touchedBins = (c.bins ?? []).filter(b => { const file = path.posix.join(c.dir, b.path); const moduleDir = file.endsWith('.rs') && path.posix.basename(path.posix.dirname(file)) === 'bin' ? `${file.slice(0, -3)}/` : null; return paths.some(p => p === file || p === `${c.dir}/Cargo.toml` || (moduleDir && p.startsWith(moduleDir))); }).map(b => b.name).filter(name => !(c.name === 'continuum-core' && name === 'continuum')); - if (touched.length) bins[c.name] = touched; + if (touchedBins.length) bins[c.name] = touchedBins; + const enabled = (TEST_FEATURES[c.name] ?? '').split(/[\s,]+/).filter(Boolean); + const names = new Set(paths.filter(p => p.startsWith(`${c.dir}/examples/`)) + .map(p => p.slice(`${c.dir}/examples/`.length).split('/')[0].replace(/\.rs$/, ''))); + const declared = name => (c.examples ?? []).find(e => e.name === name); + const buildable = [...names].sort().filter(name => (declared(name)?.requiredFeatures ?? []).every(f => enabled.includes(f))); + if (buildable.length) examples[c.name] = { all: buildable, tested: buildable.filter(name => declared(name)?.test) }; } - return bins; + return { bins, examples }; } // Only explicitly covered non-Rust surfaces may skip Rust compilation. @@ -179,7 +205,7 @@ function selectBins(paths, workspace, crates) { // `evidence.workspace` (readWorkspace) narrows Rust to the affected crates on pull requests; // without it, and on pushes to canary/main (the post-merge net), every crate runs. function selectChecks(files, evidence = {}) { - const full = { rust: true, installer: true, publication: true, crates: [...TESTED_CRATES], cli: true, bins: {} }; + const full = { rust: true, installer: true, publication: true, crates: [...TESTED_CRATES], cli: true, bins: {}, examples: {} }; if (!Array.isArray(files) || !files.length) return full; if (files.some(f => !f || typeof f.filename !== 'string' || !f.filename || (f.previous_filename !== undefined && (typeof f.previous_filename !== 'string' || !f.previous_filename)))) return full; @@ -189,8 +215,8 @@ function selectChecks(files, evidence = {}) { const rust = rustPaths.length > 0; const workspace = evidence.eventName === 'push' ? null : evidence.workspace; const scope = !rust ? { crates: [], cli: false } : selectCrates(rustPaths, workspace); - const bins = selectBins(rustPaths, workspace, scope.crates); - return { rust, installer: rust || paths.some(windows), publication: selectPublication(paths, evidence), ...scope, bins }; + const targets = selectTargets(rustPaths, workspace, scope.crates); + return { rust, installer: rust || paths.some(windows), publication: selectPublication(paths, evidence), ...scope, ...targets }; } module.exports = { selectChecks, readWorkspace, readPolicy, deriveCrates, TESTED_CRATES, TEST_FEATURES, LIB_TESTS }; diff --git a/tools/scripts/tests/ci-change-scope.test.cjs b/tools/scripts/tests/ci-change-scope.test.cjs index 3e68820bbf..ddd4c5bfb8 100644 --- a/tools/scripts/tests/ci-change-scope.test.cjs +++ b/tools/scripts/tests/ci-change-scope.test.cjs @@ -13,7 +13,9 @@ const select = (...paths) => { // with no workspace dependency at all (continuum-service). A kernel or lifecycle change cannot // reach them. Kept explicit, so a crate moving in the graph fails here instead of silently // changing what CI runs. -const BELOW_KERNEL = ['continuum-base', 'continuum-host', 'continuum-git', 'continuum-service']; +// Tested crates a kernel change does not reach: the floor (base, host, git, service) and the leaf +// codec continuum-context, which depends on nothing in the workspace. +const BELOW_KERNEL = ['continuum-base', 'continuum-host', 'continuum-git', 'continuum-service', 'continuum-context']; test('installer repairs run installer checks without unrelated Rust builds', () => { for (const file of ['install.ps1', 'tools/scripts/lib/install-common.ps1', 'tools/scripts/lib/win-modules.ps1', 'tools/scripts/lib/win-engine.ps1', 'tools/scripts/lib/windows-engine-receipt.ps1', 'tools/scripts/lib/windows-service.ps1', 'tools/scripts/lib/windows-media-reconciliation.ps1', 'tools/scripts/lib/windows-elevation.ps1', 'tools/scripts/tests/windows-process.test.ps1', 'tools/scripts/tests/windows-airc-download.test.ps1', 'tools/scripts/tests/windows-xz.test.ps1', 'tools/scripts/sync-windows-bootstrap.ps1']) @@ -24,10 +26,10 @@ test('unknown, Rust, dependency, workflow and genome inputs retain full gates', assert.deepEqual(select(file), { rust: true, installer: true, publication: true }); }); test('rename sources cannot hide a Rust deletion in docs', () => { - assert.deepEqual(selectChecks([{ filename: 'docs/old.md', previous_filename: 'core/old.rs' }]), { rust: true, installer: true, publication: true, ...ALL, bins: {} }); + assert.deepEqual(selectChecks([{ filename: 'docs/old.md', previous_filename: 'core/old.rs' }]), { rust: true, installer: true, publication: true, ...ALL, bins: {}, examples: {} }); }); test('missing or malformed change evidence runs full gates', () => { - for (const files of [null, undefined, [], [{}]]) assert.deepEqual(selectChecks(files), { rust: true, installer: true, publication: true, ...ALL, bins: {} }); + for (const files of [null, undefined, [], [{}]]) assert.deepEqual(selectChecks(files), { rust: true, installer: true, publication: true, ...ALL, bins: {}, examples: {} }); }); test('mixed changes retain all affected checks', () => { assert.deepEqual(select('docs/setup.md', 'install.ps1'), { rust: false, installer: true, publication: true }); @@ -116,7 +118,7 @@ test('a crate-local change runs that crate and every crate that depends on it', const aboveFloor = TESTED_CRATES.filter(n => !BELOW_KERNEL.includes(n)); assert.deepEqual(scope(['core/continuum-kernel/src/lib.rs']), { crates: aboveFloor, cli: false }); // A floor change runs the floor crate and every crate built on it. - assert.deepEqual(scope(['core/continuum-host/src/durable/mod.rs']), { crates: TESTED_CRATES.filter(n => n !== 'continuum-base' && n !== 'continuum-service'), cli: true }); + assert.deepEqual(scope(['core/continuum-host/src/durable/mod.rs']), { crates: TESTED_CRATES.filter(n => !['continuum-base', 'continuum-service', 'continuum-context'].includes(n)), cli: true }); // continuum-git is used by hands (a citizen's git) and core (the deploy tree): both run, and every crate above hands. assert.deepEqual(scope(['core/continuum-git/src/index_lock.rs']), crates('continuum-git', 'continuum-hands', 'continuum-cognition', 'continuum-academy', 'continuum-mind', 'continuum-dreaming', 'continuum-grid', 'continuum-serving', 'continuum-core')); // Untested crates reach the tested ones through the graph: llama -> engine -> ... @@ -154,6 +156,27 @@ test('CLI handoff regressions run for the CLI and lifecycle paths, or with every assert.equal(scope(['core/continuum-mind/src/a.rs']).cli, false); }); +test('a PR that touches an example builds it, and runs the tests of one declaring them', () => { + // what this catches: a PR breaking examples/replay reaching canary uncompiled, because every + // crate job builds only the lib (#5511, Cormac on #5611: E0425 in examples/replay/sediment.rs). + const examples = (paths, eventName = 'pull_request') => + selectChecks(paths.map(filename => ({ filename })), { eventName, workspace }).examples; + const context = workspace.crates.find(c => c.name === 'continuum-context'); + assert.ok(context.examples.some(e => e.name === 'replay' && e.test), 'replay declares test = true'); + // A module file under examples// names the example; the implicit summarize is built, not tested. + assert.deepEqual(examples(['core/continuum-context/examples/replay/sediment.rs', 'core/continuum-context/examples/summarize.rs']), + { 'continuum-context': { all: ['replay', 'summarize'], tested: ['replay'] } }); + // An example whose required features the crate's test build does not enable is not selected. + const core = workspace.crates.find(c => c.name === 'continuum-core'); + assert.ok(core.examples.some(e => e.name === 'avatar_breathe' && e.requiredFeatures.includes('avatar-3d'))); + assert.deepEqual(examples(['core/continuum-core/examples/avatar_breathe.rs'])['continuum-core'], + TEST_FEATURES['continuum-core'].includes('avatar-3d') ? { all: ['avatar_breathe'], tested: [] } : undefined); + // A lib change, docs and pushes build no example. + assert.deepEqual(examples(['core/continuum-context/src/source.rs']), {}); + assert.deepEqual(examples(['docs/a.md']), {}); + assert.deepEqual(examples(['core/continuum-context/examples/replay.rs'], 'push'), {}); +}); + test('a PR that touches a declared binary\'s own source compiles that binary', () => { // what this catches: a PR editing core/continuum-core/src/main.rs reaching canary with no // compile of continuum-core-server, because every crate job builds only the lib (card 67bf5d81).