Skip to content

Commit c6ff860

Browse files
committed
fix(ci): count both sides of a rename in the desktop live gate, keep canary reports
1 parent 8760ca7 commit c6ff860

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

‎.github/scripts/desktop-live-changes.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ run() {
1515
}
1616
[ -n "$base" ] || run 'no base commit'
1717
git fetch --quiet --depth=1 origin "$base" || run "could not fetch $base"
18-
names=$(git diff --name-only "$base" HEAD) || run "could not diff against $base"
18+
names=$(git diff --no-renames --name-only "$base" HEAD) || run "could not diff against $base"
1919
[ -n "$names" ] || run 'no changed files listed'
2020
if printf '%s\n' "$names" | grep -qvE "$unrelated"; then
2121
run 'a change may affect it'

‎.github/workflows/desktop-e2e.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ jobs:
136136
- name: Run Playwright _electron smoke suite
137137
working-directory: apps/desktop
138138
run: bunx playwright test
139+
env:
140+
BACKGROUND_EXECUTOR_REPORT_PATH: test-results/background-executor-report.json
141+
TERMINAL_CANCEL_REPORT_PATH: test-results/terminal-cancel-report.json
139142

140143
- name: Upload test results
141144
if: failure()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { spawnSync } from 'node:child_process'
2+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
3+
import { tmpdir } from 'node:os'
4+
import { dirname, join } from 'node:path'
5+
import { fileURLToPath } from 'node:url'
6+
import { afterEach, describe, expect, it } from 'vitest'
7+
8+
const script = fileURLToPath(new URL('../.github/scripts/desktop-live-changes.sh', import.meta.url))
9+
const fixtures: string[] = []
10+
11+
function git(cwd: string, ...args: string[]) {
12+
const result = spawnSync('git', args, { cwd, encoding: 'utf8' })
13+
if (result.status !== 0) throw new Error(`git ${args.join(' ')}: ${result.stderr}`)
14+
return result.stdout.trim()
15+
}
16+
17+
function write(repo: string, file: string, content: string) {
18+
mkdirSync(dirname(join(repo, file)), { recursive: true })
19+
writeFileSync(join(repo, file), content)
20+
}
21+
22+
/** Builds a clone whose base commit holds `apps/sim/x.ts` and whose origin is a local bare repo. */
23+
function fixture() {
24+
const root = mkdtempSync(join(tmpdir(), 'desktop-live-changes-'))
25+
fixtures.push(root)
26+
const origin = join(root, 'origin.git')
27+
const repo = join(root, 'repo')
28+
git(root, 'init', '--quiet', '--bare', origin)
29+
git(root, 'init', '--quiet', repo)
30+
git(repo, 'config', 'user.email', 'test@example.com')
31+
git(repo, 'config', 'user.name', 'Test')
32+
git(repo, 'config', 'commit.gpgsign', 'false')
33+
git(repo, 'remote', 'add', 'origin', origin)
34+
write(repo, 'apps/sim/x.ts', 'export const x = 1\n'.repeat(20))
35+
git(repo, 'add', '-A')
36+
git(repo, 'commit', '--quiet', '-m', 'base')
37+
const base = git(repo, 'rev-parse', 'HEAD')
38+
git(repo, 'push', '--quiet', 'origin', 'HEAD:refs/heads/base')
39+
return { repo, base }
40+
}
41+
42+
function detect(repo: string, base: string) {
43+
return spawnSync('bash', [script, base], { cwd: repo, encoding: 'utf8' })
44+
}
45+
46+
afterEach(() => {
47+
for (const root of fixtures.splice(0)) rmSync(root, { recursive: true, force: true })
48+
})
49+
50+
describe('desktop live change gate', () => {
51+
it('runs the suite when a live file moves into a skipped path', () => {
52+
const { repo, base } = fixture()
53+
mkdirSync(join(repo, 'apps/docs'), { recursive: true })
54+
git(repo, 'mv', 'apps/sim/x.ts', 'apps/docs/x.ts')
55+
git(repo, 'commit', '--quiet', '-m', 'move')
56+
57+
const result = detect(repo, base)
58+
expect(result.status, result.stderr).toBe(0)
59+
expect(result.stdout.trim()).toBe('changed=true')
60+
})
61+
62+
it('skips the suite when every change is in a skipped path', () => {
63+
const { repo, base } = fixture()
64+
write(repo, 'apps/docs/guide.mdx', '# Guide\n')
65+
git(repo, 'add', '-A')
66+
git(repo, 'commit', '--quiet', '-m', 'docs')
67+
68+
const result = detect(repo, base)
69+
expect(result.status, result.stderr).toBe(0)
70+
expect(result.stdout.trim()).toBe('changed=false')
71+
})
72+
73+
it('runs the suite when the base commit cannot be fetched', () => {
74+
const { repo } = fixture()
75+
const result = detect(repo, '0'.repeat(40))
76+
expect(result.stdout.trim()).toBe('changed=true')
77+
})
78+
})

0 commit comments

Comments
 (0)