import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync, } from 'node:fs'; import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import test from 'node:test'; import { fileURLToPath } from 'node:url'; import { classifyGitDiff, classifyWebHostOnly, WEB_HOST_ONLY_ALLOWLIST, ZERO_SHA, } from './classify-web-host-only.mjs'; const REPO_ROOT = fileURLToPath(new URL('../..', import.meta.url)); const CLI_PATH = join(REPO_ROOT, 'scripts/ci/classify-web-host-only.mjs'); const SAMPLE_BASE = '65460a7f136d32b15d0d4398f0f4976273c51c9d'; await test('Native Playground CI applies desktop gates under the correct conditions', () => { const workflow = readFileSync( join(REPO_ROOT, '.github/workflows/native-playground.yml'), 'utf8' ); const jobs = new Map(); const jobBlocks = workflow.split('\njobs:\n')[1].split(/(?=^ {2}[\w-]+:\n)/m); for (const block of jobBlocks) { const [heading, ...lines] = block.split('\n'); jobs.set(heading.trim().slice(0, -1), lines.join('\n')); } const step = (job, name) => { const body = jobs .get(job) .split(/^ {6}- name: /m) .find(block => block.startsWith(`${name}\n`)); assert.ok(body, `Missing step: ${name}`); return body .trimEnd() .split('\n') .map(line => line.trim()); }; const lintJob = 'lint-and-wasm'; const clippy = step(lintJob, 'Clippy check'); assert.deepEqual(clippy.slice(3, -1), [ 'cargo clippy --locked --workspace --all-targets --features harness -- -D warnings', ]); const tokenDrift = step( lintJob, 'Verify generated tokens, icons, and fonts.lock have zero drift' ); assert.equal(tokenDrift[1], 'run: |'); assert.ok( tokenDrift.includes( 'node ../ui/tokens/extract-tokens.mjs --check --node-modules /tmp/np-token-deps/node_modules' ) ); const wasmCheck = step(lintJob, 'Check WebAssembly target'); assert.equal( wasmCheck[1], "if: needs.changes.outputs.desktop-rs-only != 'true'" ); assert.deepEqual(wasmCheck.slice(4, -1), [ 'cargo check --locked -p ui-tokens -p ui -p ui-kit -p blocksuite-editor -p playground --target wasm32-unknown-unknown', 'cargo check --locked -p blocksuite-playground-doc --no-default-features --target wasm32-unknown-unknown', 'cargo check --locked -p affine-store --no-default-features --target wasm32-unknown-unknown', 'cargo check --locked -p blocksuite-preview --no-default-features --features mermaid,wasm-worker --target wasm32-unknown-unknown', 'cargo check --locked -p blocksuite-preview --no-default-features --features math,wasm-worker --target wasm32-unknown-unknown', 'cargo check --locked -p blocksuite-preview --no-default-features --features typst,wasm-worker --target wasm32-unknown-unknown', 'cargo check --locked -p blocksuite-preview --no-default-features --features pdf,wasm-worker --target wasm32-unknown-unknown', ]); const allTargetsCheck = 'cargo check --locked -p affine-desktop --all-targets --features harness'; const desktopCheck = step( lintJob, 'Check Desktop on Linux (default and harness)' ); assert.equal( desktopCheck[1], "if: needs.changes.outputs.desktop-rs-only == 'true'" ); assert.deepEqual(desktopCheck.slice(4, -1), [ 'cargo check --locked -p affine-desktop --lib', allTargetsCheck, ]); const desktopTest = step( 'headless-linux-and-perf', 'Test Desktop on Linux (default and harness)' ); assert.equal( desktopTest[1], "if: needs.changes.outputs.desktop-leaf-only == 'true'" ); assert.deepEqual(desktopTest.slice(4, -1), [ 'cargo test --locked -p affine-desktop', 'cargo test --locked -p affine-desktop --features harness --bin desktop-harness', 'if [ "${{ needs.changes.outputs.desktop-rs-only }}" != "true" ]; then', allTargetsCheck, 'fi', ]); assert.deepEqual( [...jobs].flatMap(([job, body]) => [...body.matchAll(/^ +timeout-minutes: (.+)$/gm)].map(([, value]) => [ job, value, ]) ), [ ['web-wasm-smoke', '20'], ['headless-linux-and-perf', '25'], ['perf-guardrail', '5'], ] ); }); await test('allowlist remains frozen to the seven pure web-host paths', () => { assert.deepEqual( [...WEB_HOST_ONLY_ALLOWLIST], [ 'packages/frontend/hosts/web/src/idb-storage.js', 'packages/frontend/hosts/web/desktop/boot.js', 'packages/frontend/hosts/web/desktop/start.js', 'packages/frontend/hosts/web/desktop/index.html', 'packages/frontend/hosts/web/tests/idb-storage.test.mjs', 'packages/frontend/hosts/web/tests/desktop.test.mjs', 'packages/frontend/hosts/web/tests/dual-shell-save.browser.mjs', ] ); }); await test('classifyWebHostOnly handles allowlist, rename, and guards', () => { const cases = [ { name: 'single allowlisted file modification', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-web-fix', nameStatusLines: ['M\tpackages/frontend/hosts/web/src/idb-storage.js'], }, expected: true, }, { name: 'multi-file allowlist modification matching e7236462b016', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-wave-h2-idb-quota', nameStatusLines: [ 'M\tpackages/frontend/hosts/web/desktop/start.js', 'M\tpackages/frontend/hosts/web/src/idb-storage.js', 'M\tpackages/frontend/hosts/web/tests/desktop.test.mjs', 'M\tpackages/frontend/hosts/web/tests/idb-storage.test.mjs', ], }, expected: true, }, { name: 'allowlist files mixed with Rust source or Cargo.toml', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-mixed', nameStatusLines: [ 'M\tpackages/frontend/hosts/web/src/idb-storage.js', 'M\tpackages/frontend/Cargo.toml', ], }, expected: false, }, { name: 'allowlist files mixed with .rs file', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-mixed-rs', nameStatusLines: [ 'M\tpackages/frontend/hosts/web/desktop/start.js', 'M\tpackages/frontend/mobile/src/lib.rs', ], }, expected: false, }, { name: 'preview-workers.js included by Rust tests must be false', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-preview-worker', nameStatusLines: [ 'M\tblocksuite/crates/playground/web/preview-workers.js', ], }, expected: false, }, { name: 'R100 rename inside allowlist is true', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-rename-in', nameStatusLines: [ [ 'R100', 'packages/frontend/hosts/web/desktop/start.js', 'packages/frontend/hosts/web/src/idb-storage.js', ].join('\t'), ], }, expected: true, }, { name: 'R100 rename from outside allowlist into allowlist is false', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-rename-into', nameStatusLines: [ [ 'R100', 'packages/frontend/hosts/web/src/other.js', 'packages/frontend/hosts/web/src/idb-storage.js', ].join('\t'), ], }, expected: false, }, { name: 'R100 rename from allowlist to outside allowlist is false', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-rename-out', nameStatusLines: [ [ 'R100', 'packages/frontend/hosts/web/desktop/start.js', 'packages/frontend/hosts/web/desktop/start-v2.js', ].join('\t'), ], }, expected: false, }, { name: 'C100 copy from outside allowlist into allowlist is false', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-copy-into', nameStatusLines: [ [ 'C100', 'packages/frontend/hosts/web/src/other.js', 'packages/frontend/hosts/web/src/idb-storage.js', ].join('\t'), ], }, expected: false, }, { name: 'web host helper script verify-idb-real-browser.mjs must be false', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-script', nameStatusLines: [ 'M\tpackages/frontend/hosts/web/scripts/verify-idb-real-browser.mjs', ], }, expected: false, }, { name: 'empty diff must be false', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-empty', nameStatusLines: [], }, expected: false, }, { name: 'forceAll=true overrides allowlist diff to false', input: { baseSha: SAMPLE_BASE, forceAll: true, ref: 'refs/heads/darksky/np/mobile-force', nameStatusLines: ['M\tpackages/frontend/hosts/web/src/idb-storage.js'], }, expected: false, }, { name: 'trunk push to refs/heads/darksky/np/mobile must be false', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile', nameStatusLines: ['M\tpackages/frontend/hosts/web/src/idb-storage.js'], }, expected: false, }, { name: 'trunk push to refs/heads/canary must be false', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/canary', nameStatusLines: ['M\tpackages/frontend/hosts/web/src/idb-storage.js'], }, expected: false, }, { name: 'zero SHA base must be false', input: { baseSha: ZERO_SHA, ref: 'refs/heads/darksky/np/mobile-zero', nameStatusLines: ['M\tpackages/frontend/hosts/web/src/idb-storage.js'], }, expected: false, }, { name: 'missing base SHA must be false', input: { baseSha: '', ref: 'refs/heads/darksky/np/mobile-missing-base', nameStatusLines: ['M\tpackages/frontend/hosts/web/src/idb-storage.js'], }, expected: false, }, { name: 'NUL-delimited -z output works for allowlist and rejects invalid status', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-z', nameStatus: 'M\0packages/frontend/hosts/web/desktop/index.html\0' + 'M\0packages/frontend/hosts/web/tests/dual-shell-save.browser.mjs\0', }, expected: true, }, { name: 'unknown git status code fails closed', input: { baseSha: SAMPLE_BASE, ref: 'refs/heads/darksky/np/mobile-unknown', nameStatus: 'U\0packages/frontend/hosts/web/src/idb-storage.js\0', }, expected: false, }, ]; for (const tc of cases) { const result = classifyWebHostOnly(tc.input); assert.equal(result.webHostOnly, tc.expected, tc.name); } }); await test('Desktop lanes distinguish Rust changes from mixed web host changes', () => { const desktop = 'packages/frontend/desktop'; const source = `M\t${desktop}/src/window/mod.rs`; const webHost = 'M\tpackages/frontend/hosts/web/src/idb-storage.js'; const cases = [ ['Desktop source', [source], [false, true, true]], ['Desktop test', [`A\t${desktop}/tests/smoke.rs`], [false, true, true]], ['Desktop and web host', [source, webHost], [false, true, false]], ['web host only', [webHost], [true, false, false]], ['empty diff', [], [false, false, false]], [ 'Desktop manifest', [source, `M\t${desktop}/Cargo.toml`], [false, false, false], ], [ 'workspace lockfile', [source, 'M\tpackages/frontend/Cargo.lock'], [false, false, false], ], ['Desktop asset', [`M\t${desktop}/src/icon.png`], [false, false, false]], ['Desktop build script', [`M\t${desktop}/build.rs`], [false, false, false]], [ 'client source', [source, 'M\tpackages/frontend/client/src/lib.rs'], [false, false, false], ], [ 'BlockSuite source', [source, 'M\tblocksuite/crates/editor/src/lib.rs'], [false, false, false], ], [ 'rename from client', [`R100\tpackages/frontend/client/src/lib.rs\t${desktop}/src/moved.rs`], [false, false, false], ], [ 'rename within Desktop', [`R100\t${desktop}/src/old.rs\t${desktop}/src/new.rs`], [false, true, true], ], ['invalid status', [`U\t${desktop}/src/file.rs`], [false, false, false]], ]; for (const [label, nameStatusLines, expected] of cases) { const { webHostOnly, desktopLeafOnly, desktopRsOnly } = classifyWebHostOnly( { nameStatusLines, baseSha: SAMPLE_BASE, } ); assert.deepEqual( [webHostOnly, desktopLeafOnly, desktopRsOnly], expected, label ); } for (const guard of [ { forceAll: true }, { ref: 'refs/heads/darksky/np/mobile' }, { baseSha: ZERO_SHA }, ]) { const result = classifyWebHostOnly({ nameStatusLines: [source], ...guard }); assert.equal(result.webHostOnly, false, result.reason); assert.equal(result.desktopLeafOnly, false, result.reason); assert.equal(result.desktopRsOnly, false, result.reason); } }); function createGitRunner(cwd) { return (...args) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], }).trim(); } await test('classifyGitDiff handles Git commits, lane guards, and CLI outputs', () => { const tmpRepo = mkdtempSync(join(tmpdir(), 'classify-web-host-')); const outputFile = join(tmpRepo, 'github-output.txt'); try { const git = createGitRunner(tmpRepo); git('init', '-b', 'main'); git('config', 'user.name', 'Test User'); git('config', 'user.email', 'test@example.com'); const allowFile = join( tmpRepo, 'packages/frontend/hosts/web/src/idb-storage.js' ); const desktopHtmlFile = join( tmpRepo, 'packages/frontend/hosts/web/desktop/index.html' ); const desktopStartFile = join( tmpRepo, 'packages/frontend/hosts/web/desktop/start.js' ); const otherFile = join( tmpRepo, 'packages/frontend/hosts/web/scripts/verify-idb-real-browser.mjs' ); const otherContent = [ 'export function runVerify(target) {', ' const steps = ["boot", "sync", "persist", "reload"];', ' return steps.map((step, index) => `${index}:${target}:${step}`);', '}', '', ].join('\n'); mkdirSync(join(tmpRepo, 'packages/frontend/hosts/web/src'), { recursive: true, }); mkdirSync(join(tmpRepo, 'packages/frontend/hosts/web/desktop'), { recursive: true, }); mkdirSync(join(tmpRepo, 'packages/frontend/hosts/web/scripts'), { recursive: true, }); const backend = 'packages/backend/server-domain/src'; const web = 'packages/frontend/hosts/web'; const sharedSource = 'packages/common/store/shared.js'; const sharedContent = 'export const shared = "common store";\n'; mkdirSync(join(tmpRepo, backend), { recursive: true }); mkdirSync(join(tmpRepo, 'packages/common/store'), { recursive: true }); writeFileSync(join(tmpRepo, sharedSource), sharedContent); writeFileSync(join(tmpRepo, backend, 'lib.rs'), 'pub fn first() {}\n'); writeFileSync(join(tmpRepo, web, 'index.html'), 'Base\n'); writeFileSync(allowFile, 'export const v = 1;\n'); writeFileSync(otherFile, otherContent); git('add', '.'); git('commit', '-m', 'base'); const baseSha = git('rev-parse', 'HEAD'); // Empty diff against self -> false. assert.equal( classifyGitDiff({ baseSha, ref: 'refs/heads/darksky/np/mobile-test', cwd: tmpRepo, }).webHostOnly, false ); // Pure allowlist commit -> true. writeFileSync(allowFile, 'export const v = 2;\n'); git('add', '.'); git('commit', '-m', 'web host only'); const cliOut = execFileSync( process.execPath, [ CLI_PATH, '--base', baseSha, '--ref', 'refs/heads/darksky/np/mobile-test', '--github-output', outputFile, ], { cwd: tmpRepo, encoding: 'utf8' } ); assert.match(cliOut, /^web_host_only=true /); assert.equal( readFileSync(outputFile, 'utf8'), 'web_host_only=true\ndesktop_leaf_only=false\ndesktop_rs_only=false\n' + 'backend_only=false\nweb_wrapper_only=true\napple_specific=false\n' ); assert.match(cliOut, /^apple_specific=false$/m); const webHostSha = git('rev-parse', 'HEAD'); const desktopDir = join(tmpRepo, 'packages/frontend/desktop/src'); const desktopFile = join(desktopDir, 'new.rs'); mkdirSync(desktopDir, { recursive: true }); writeFileSync(desktopFile, 'pub fn unique() {}\n'); git('add', desktopFile); git('commit', '-m', 'add Desktop source'); const desktop = classifyGitDiff({ baseSha: webHostSha, cwd: tmpRepo }); assert.equal(desktop.desktopLeafOnly, true); assert.equal(desktop.desktopRsOnly, true); const mixed = classifyGitDiff({ baseSha, cwd: tmpRepo }); assert.equal(mixed.desktopLeafOnly, true); assert.equal(mixed.desktopRsOnly, false); assert.equal(mixed.webHostOnly, false); writeFileSync(desktopFile, otherContent); git('add', desktopFile); git('commit', '-m', 'copy into Desktop source'); const desktopCopy = classifyGitDiff({ baseSha: webHostSha, cwd: tmpRepo }); assert.equal(desktopCopy.desktopLeafOnly, false); assert.equal(desktopCopy.desktopRsOnly, false); git('reset', '--hard', 'HEAD~2'); // Unreachable / non-existent base -> false. assert.equal( classifyGitDiff({ baseSha: 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef', ref: 'refs/heads/darksky/np/mobile-test', cwd: tmpRepo, }).webHostOnly, false ); // Brand-new unique allowlisted file -> still true after copy re-check. writeFileSync( desktopHtmlFile, 'AFFiNE Workbench\n' ); git('add', desktopHtmlFile); git('commit', '-m', 'add unique allowlisted html'); assert.equal( classifyGitDiff({ baseSha, ref: 'refs/heads/darksky/np/mobile-test', cwd: tmpRepo, }).webHostOnly, true ); // Copying an unmodified non-allowlisted file into a newly added // allowlisted file -> false (caught by --find-copies-harder). writeFileSync(desktopStartFile, otherContent); git('add', desktopStartFile); git('commit', '-m', 'copy non-allowlisted file into allowlisted path'); const copyResult = classifyGitDiff({ baseSha, ref: 'refs/heads/darksky/np/mobile-test', cwd: tmpRepo, }); assert.equal(copyResult.webHostOnly, false); assert.equal(copyResult.reason, 'non_allowlist_path'); // Adding a non-allowlisted file -> false. writeFileSync(otherFile, 'export const s = 2;\n'); git('add', otherFile); git('commit', '-m', 'touch helper script'); assert.equal( classifyGitDiff({ baseSha, ref: 'refs/heads/darksky/np/mobile-test', cwd: tmpRepo, }).webHostOnly, false ); const cases = [ { name: 'backend edits and additions', files: [ [`${backend}/lib.rs`, 'pub fn second() {}\n'], [`${backend}/new.rs`, 'pub fn new_file() {}\n'], ], backendOnly: true, }, { name: 'Web wrapper HTML and script edits', files: [ [`${web}/index.html`, 'Updated\n'], [ `${web}/scripts/verify-idb-real-browser.mjs`, 'export const v = 3;\n', ], ], webWrapperOnly: true, }, { name: 'copy from the common store into an allowlisted Web wrapper path', files: [[`${web}/desktop/start.js`, sharedContent]], copyTo: `${web}/desktop/start.js`, }, { name: 'copy from the common store into the backend', files: [[`${backend}/copy.js`, sharedContent]], copyTo: `${backend}/copy.js`, }, { name: 'mixed backend and Web wrapper edits', files: [ [`${backend}/lib.rs`, 'pub fn second() {}\n'], [`${web}/index.html`, 'Updated\n'], ], }, ]; for (const { name, files, copyTo, backendOnly = false, webWrapperOnly = false, } of cases) { git('reset', '--hard', baseSha); for (const [path, content] of files) { const file = join(tmpRepo, path); mkdirSync(dirname(file), { recursive: true }); writeFileSync(file, content); } git('add', '--', ...files.map(([path]) => path)); git('commit', '-m', name); if (copyTo) { assert.equal( git( 'diff', '--name-status', '-C', '--find-copies-harder', baseSha, 'HEAD' ), `C100\t${sharedSource}\t${copyTo}` ); } const result = classifyGitDiff({ baseSha, cwd: tmpRepo }); assert.equal(result.backendOnly, backendOnly, name); assert.equal(result.webWrapperOnly, webWrapperOnly, name); assert.equal(result.webHostOnly, false, name); assert.equal(result.desktopLeafOnly, false, name); assert.equal(result.desktopRsOnly, false, name); if (backendOnly || webWrapperOnly) { for (const guard of [ { forceAll: 'true' }, { ref: 'refs/heads/darksky/np/mobile' }, { baseSha: ZERO_SHA }, { baseSha: 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' }, { baseSha: git('rev-parse', 'HEAD') }, ]) { const guarded = classifyGitDiff({ baseSha, cwd: tmpRepo, ...guard }); assert.equal(guarded.backendOnly, false, guarded.reason); assert.equal(guarded.webWrapperOnly, false, guarded.reason); } } } } finally { rmSync(tmpRepo, { recursive: true, force: true }); } }); await test('classifyWebHostOnly flags Apple jobs for full runs and Apple paths', () => { const slice = 'refs/heads/darksky/np/mobile-r29-foo'; const crossPlatform = [ 'M\tpackages/frontend/desktop/src/sidebar/mod.rs', 'M\tblocksuite/crates/editor/src/directory.rs', 'M\tpackages/frontend/mobile/src/state/derived.rs', ]; const cases = [ ['trunk darksky/np/mobile', { ref: 'refs/heads/darksky/np/mobile' }, true], ['trunk canary', { ref: 'refs/heads/canary' }, true], ['trunk main', { ref: 'refs/heads/main' }, true], ['pull request ref', { ref: 'refs/pull/123/merge' }, true], ['pull request event', { ref: slice, event: 'pull_request' }, true], ['manual dispatch', { ref: slice, event: 'workflow_dispatch' }, true], ['force all', { ref: slice, forceAll: true }, true], ['invalid base', { ref: slice, baseSha: ZERO_SHA }, true], ['empty diff', { ref: slice, nameStatusLines: [] }, true], ['missing diff', { ref: slice, nameStatusLines: null }, true], ['cross-platform slice', { ref: slice }, false], ['push event slice', { ref: slice, event: 'push' }, false], ['content hit', { ref: slice, contentTouchesApple: true }, true], [ 'content hit on a changed path', { ref: slice, contentTouchesApple: new Set([ 'blocksuite/crates/editor/src/directory.rs', ]), }, true, ], [ 'content hit on an unchanged path', { ref: slice, contentTouchesApple: new Set(['other.rs']) }, false, ], ]; for (const path of [ 'packages/ui/ui/src/platform/apple/metal_renderer.rs', 'packages/ui/ui/src/platform/macos/window.rs', 'packages/ui/ui/src/platform/ios/window.rs', 'packages/frontend/hosts/ios/Sources/AppDelegate.swift', 'packages/frontend/apps/ios/App/App/AppDelegate.swift', '.cargo/config.toml', 'packages/ui/ui/tests/metal_atlas_fence.rs', 'packages/ui/ui/build.rs', 'packages/frontend/Cargo.toml', 'packages/frontend/Cargo.lock', 'packages/frontend/desktop/Cargo.toml', 'packages/frontend/native/media_capture/build.rs', 'packages/frontend/native/media_capture/src/macos/audio_buffer.rs', 'packages/frontend/rust-toolchain.toml', 'packages/ui/ui/src/platform/apple/shaders.metal', 'Cargo.lock', 'rust-toolchain.toml', '.github/workflows/native-playground.yml', '.github/workflows/np-mobile.yml', 'scripts/ci/classify-web-host-only.mjs', ]) { cases.push([path, { ref: slice, nameStatusLines: [`M\t${path}`] }, true]); } cases.push([ 'rename out of an Apple path', { ref: slice, nameStatusLines: [ 'R100\tpackages/ui/ui/src/platform/macos/a.rs\tpackages/ui/ui/src/b.rs', ], }, true, ]); for (const [label, input, expected] of cases) { const result = classifyWebHostOnly({ baseSha: SAMPLE_BASE, nameStatusLines: crossPlatform, ...input, }); assert.equal(result.appleSpecific, expected, `${label} (${result.reason})`); } }); await test('classifyWebHostOnly skips non-Apple desktop topic branches and runs trunk', () => { const desktopLeaf = 'packages/frontend/desktop/src/views_extra/scroll.rs'; const rows = [ [ 'non-Apple desktop topic branch', { ref: 'refs/heads/darksky/np/mobile-test', event: 'push', nameStatusLines: [`M\t${desktopLeaf}`], contentTouchesApple: false, }, { appleSpecific: false, desktopLeafOnly: true }, ], [ 'same desktop change on trunk', { ref: 'refs/heads/darksky/np/mobile', event: 'push', nameStatusLines: [`M\t${desktopLeaf}`], contentTouchesApple: false, }, { appleSpecific: true, desktopLeafOnly: false }, ], [ 'Apple-cfg desktop topic branch', { ref: 'refs/heads/darksky/np/mobile-test', event: 'push', nameStatusLines: [`M\t${desktopLeaf}`], contentTouchesApple: true, }, { appleSpecific: true, desktopLeafOnly: true }, ], [ 'workflow push on darksky/native-playground', { ref: 'refs/heads/darksky/native-playground', event: 'push', nameStatusLines: ['M\t.github/workflows/native-playground.yml'], contentTouchesApple: false, }, { appleSpecific: true, desktopLeafOnly: false }, ], ]; for (const [label, input, expected] of rows) { const result = classifyWebHostOnly({ baseSha: SAMPLE_BASE, ...input }); assert.equal( result.appleSpecific, expected.appleSpecific, `${label} appleSpecific` ); assert.equal( result.desktopLeafOnly, expected.desktopLeafOnly, `${label} desktopLeafOnly` ); } }); await test('classifyGitDiff flags Apple jobs from Apple target cfg text', () => { const tmpRepo = mkdtempSync(join(tmpdir(), 'classify-apple-cfg-')); try { const git = createGitRunner(tmpRepo); const write = (path, content) => { const file = join(tmpRepo, path); mkdirSync(dirname(file), { recursive: true }); writeFileSync(file, content); }; git('init', '-b', 'main'); git('config', 'user.name', 'Test User'); git('config', 'user.email', 'test@example.com'); const moreMenu = 'blocksuite/crates/editor/src/more_menu.rs'; const vendorFile = 'blocksuite/crates/editor/src/vendor.rs'; const plain = 'blocksuite/crates/editor/src/directory.rs'; write( moreMenu, '#[cfg(target_os = "macos")]\nconst COPY: &str = "C";\nfn a() {}\n' ); write(vendorFile, '#[cfg(target_vendor = "apple")]\nfn v() {}\n'); write(plain, 'pub fn directory() {}\n'); git('add', '.'); git('commit', '-m', 'base'); const baseSha = git('rev-parse', 'HEAD'); const cases = [ [ 'edit outside the cfg in a file with a macOS cfg', () => write( moreMenu, '#[cfg(target_os = "macos")]\nconst COPY: &str = "C";\nfn b() {}\n' ), true, ], [ 'add a file with an iOS cfg', () => write( 'blocksuite/crates/editor/src/ios.rs', '#[cfg(target_os = "ios")]\nfn i() {}\n' ), true, ], [ 'delete a file with an Apple vendor cfg', () => rmSync(join(tmpRepo, vendorFile)), true, ], [ 'remove the macOS cfg from a file', () => write(moreMenu, 'const COPY: &str = "C";\n'), true, ], [ 'rename a file with a macOS cfg', () => git('mv', moreMenu, 'blocksuite/crates/editor/src/menu.rs'), true, ], [ 'edit a file with no Apple cfg', () => write(plain, 'pub fn directory() -> u8 { 1 }\n'), false, ], ]; for (const [label, change, expected] of cases) { git('reset', '--hard', baseSha); change(); git('add', '-A'); git('commit', '-m', label); const result = classifyGitDiff({ baseSha, ref: 'refs/heads/darksky/np/mobile-r29-foo', cwd: tmpRepo, }); assert.equal(result.appleSpecific, expected, label); } } finally { rmSync(tmpRepo, { recursive: true, force: true }); } });