-
Notifications
You must be signed in to change notification settings - Fork 432
ci: select desktop e2e specs through source reachability #4583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/usr/bin/env node | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { readdirSync } from 'node:fs'; | ||
| import { dirname, relative, resolve, sep } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| import { changedFilesBetween, planTests } from './ci-test-plan.mjs'; | ||
| import { collectWorkspaceSourceClosure } from './workspace-source-closure.mjs'; | ||
|
|
||
| const scriptPath = fileURLToPath(import.meta.url); | ||
| const defaultRepoRoot = dirname(dirname(scriptPath)); | ||
| const desktopE2eRoot = 'apps/desktop/e2e'; | ||
|
|
||
| const SELECTION_AUTHORITY_FILES = new Set([ | ||
| 'apps/desktop/e2e/playwright.config.ts', | ||
| 'scripts/desktop-e2e-test-selection.mjs', | ||
| 'scripts/workspace-source-closure.mjs', | ||
| ]); | ||
|
|
||
| function normalizePath(path) { | ||
| return path.split(sep).join('/').replace(/^\.\//u, ''); | ||
| } | ||
|
|
||
| export function listDesktopE2eSpecs(repoRoot = defaultRepoRoot) { | ||
| const root = resolve(repoRoot, desktopE2eRoot); | ||
| return readdirSync(root, { recursive: true }) | ||
| .filter((path) => path.endsWith('.spec.ts')) | ||
| .map((path) => normalizePath(relative(repoRoot, resolve(root, path)))) | ||
| .sort(); | ||
| } | ||
|
|
||
| export async function collectDesktopE2eSpecClosures(specs, repoRoot = defaultRepoRoot) { | ||
| const closures = new Map(); | ||
| for (const spec of specs) { | ||
| closures.set(spec, new Set(await collectWorkspaceSourceClosure([spec], repoRoot))); | ||
| } | ||
| return closures; | ||
| } | ||
|
|
||
| export async function selectDesktopE2eSpecs(changedFiles, options = {}) { | ||
| const repoRoot = options.repoRoot ?? defaultRepoRoot; | ||
| const files = [...new Set(changedFiles.map(normalizePath).filter(Boolean))]; | ||
| const specs = options.specs ?? listDesktopE2eSpecs(repoRoot); | ||
| const plan = planTests(files, { repoRoot, forceFull: options.forceFull }); | ||
| if (!plan.e2e) return []; | ||
| if (plan.full || files.some((path) => SELECTION_AUTHORITY_FILES.has(path))) return specs; | ||
|
|
||
| const closures = options.closures ?? (await collectDesktopE2eSpecClosures(specs, repoRoot)); | ||
| return specs.filter((spec) => files.some((path) => closures.get(spec)?.has(path))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This is the whole selection, and the relation it uses is wrong for e2e. A spec imports |
||
| } | ||
|
|
||
| function parseArgs(args) { | ||
| const parsed = { base: undefined, forceFull: false, head: undefined }; | ||
| for (let index = 0; index < args.length; index += 1) { | ||
| const arg = args[index]; | ||
| if (arg === '--full') parsed.forceFull = true; | ||
| else if (arg === '--base') parsed.base = args[++index]; | ||
| else if (arg === '--head') parsed.head = args[++index]; | ||
| else throw new Error(`Unknown argument: ${arg}`); | ||
| } | ||
| if (!parsed.forceFull && (!parsed.base || !parsed.head)) { | ||
| throw new Error('Expected --full or both --base <sha> and --head <sha>'); | ||
| } | ||
| return parsed; | ||
| } | ||
|
|
||
| async function main(args) { | ||
| const parsed = parseArgs(args); | ||
| const changedFiles = parsed.forceFull ? [] : changedFilesBetween(parsed.base, parsed.head); | ||
| const specs = await selectDesktopE2eSpecs(changedFiles, { forceFull: parsed.forceFull }); | ||
| const workspaceSpecs = specs.map((path) => path.slice('apps/desktop/'.length)); | ||
| process.stdout.write(workspaceSpecs.length > 0 ? `${workspaceSpecs.join('\n')}\n` : ''); | ||
| process.stderr.write(`Desktop e2e selection: ${specs.length} spec files\n`); | ||
| } | ||
|
|
||
| if (process.argv[1] && resolve(process.argv[1]) === scriptPath) { | ||
| try { | ||
| await main(process.argv.slice(2)); | ||
| } catch (error) { | ||
| process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`); | ||
| process.exitCode = 2; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import assert from 'node:assert/strict'; | ||
| import test from 'node:test'; | ||
|
|
||
| import { | ||
| collectDesktopE2eSpecClosures, | ||
| listDesktopE2eSpecs, | ||
| selectDesktopE2eSpecs, | ||
| } from './desktop-e2e-test-selection.mjs'; | ||
|
|
||
| const specs = ['apps/desktop/e2e/alpha.spec.ts', 'apps/desktop/e2e/beta.spec.ts']; | ||
| const closures = new Map([ | ||
| [specs[0], new Set([specs[0], 'apps/desktop/e2e/fixtures.ts', 'apps/desktop/src/main/a.ts'])], | ||
| [specs[1], new Set([specs[1], 'apps/desktop/e2e/fixtures.ts', 'apps/desktop/src/main/b.ts'])], | ||
| ]); | ||
|
|
||
| test('selection follows the exact source closure of each spec', async () => { | ||
| assert.deepEqual( | ||
| await selectDesktopE2eSpecs(['apps/desktop/src/main/a.ts'], { specs, closures }), | ||
| [specs[0]], | ||
| ); | ||
| assert.deepEqual( | ||
| await selectDesktopE2eSpecs(['apps/desktop/e2e/fixtures.ts'], { specs, closures }), | ||
| specs, | ||
| ); | ||
| assert.deepEqual( | ||
| await selectDesktopE2eSpecs(['apps/desktop/src/main/unreached.ts'], { specs, closures }), | ||
| [], | ||
| ); | ||
| }); | ||
|
|
||
| test('full plans and selection authorities run every spec', async () => { | ||
| for (const path of [ | ||
| 'package-lock.json', | ||
| 'apps/desktop/e2e/playwright.config.ts', | ||
| 'scripts/desktop-e2e-test-selection.mjs', | ||
| 'scripts/workspace-source-closure.mjs', | ||
| ]) { | ||
| assert.deepEqual(await selectDesktopE2eSpecs([path], { specs, closures }), specs, path); | ||
| } | ||
| }); | ||
|
|
||
| test('non-Electron changes select no Desktop spec', async () => { | ||
| assert.deepEqual( | ||
| await selectDesktopE2eSpecs(['packages/runtime/src/runtime.ts'], { specs, closures }), | ||
| [], | ||
| ); | ||
| }); | ||
|
|
||
| test('current spec closures select every repository script they import', async () => { | ||
| const currentSpecs = listDesktopE2eSpecs(); | ||
| const currentClosures = await collectDesktopE2eSpecClosures(currentSpecs); | ||
|
|
||
| assert.ok(currentSpecs.length > 0); | ||
| for (const spec of currentSpecs) { | ||
| assert.ok(currentClosures.get(spec)?.has(spec), spec); | ||
| assert.ok(currentClosures.get(spec)?.has('apps/desktop/e2e/fixtures.ts'), spec); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The suite does not test the scenario the PR is for. Three of the four tests use the hand-written |
||
| } | ||
|
|
||
| const scriptInputs = [ | ||
| ...new Set( | ||
| [...currentClosures.values()].flatMap((closure) => | ||
| [...closure].filter((path) => path.startsWith('scripts/')), | ||
| ), | ||
| ), | ||
| ].sort(); | ||
| assert.ok(scriptInputs.length > 0); | ||
| for (const path of scriptInputs) { | ||
| const reachableSpecs = currentSpecs.filter((spec) => currentClosures.get(spec)?.has(path)); | ||
| assert.deepEqual( | ||
| await selectDesktopE2eSpecs([path], { | ||
| specs: currentSpecs, | ||
| closures: currentClosures, | ||
| }), | ||
| reachableSpecs, | ||
| path, | ||
| ); | ||
| } | ||
| assert.deepEqual( | ||
| await selectDesktopE2eSpecs(['scripts/ax-tree-audit.mjs'], { | ||
| specs: currentSpecs, | ||
| closures: currentClosures, | ||
| }), | ||
| ['apps/desktop/e2e/accessibility-coverage.spec.ts'], | ||
| ); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Redundant with the caller. The
Desktop e2estep is already gated onsteps.plan.outputs.e2eand already branches onsteps.plan.outputs.full, soplan.e2e,plan.fulland the secondchangedFilesBetweenhere recompute a decision the same job made one step earlier. Let the selector take changed files and nothing else.