diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecfcc460..fb22c177 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,7 @@ jobs: cache: npm - run: npm install -g npm@11 --no-fund --no-audit - run: npm ci --no-fund - - run: npm run lint - - run: npm run check:styles && npm run check:themes && npm run check:structure - - run: npm run check:i18n && npm run check:rawtext + - run: npm run check:static - run: npm test # Both platforms the app ships on. Windows is here because the release build @@ -65,12 +63,36 @@ jobs: - name: Guard against unexpected install warnings shell: bash run: node scripts/check-install-warnings.mjs npm-ci.log - - run: npm run check # ESLint + Vitest - - run: npm run build # ensure it bundles + - name: The whole gate + if: runner.os != 'Windows' + run: npm run check + # Every test and guard, without coverage instrumentation: coverage is a + # measurement, not a test, and its floors are enforced on ubuntu above. + - name: Guards and lint + if: runner.os == 'Windows' + run: npm run check:static + - name: Unit tests, without coverage + if: runner.os == 'Windows' + run: npm test + - name: Build + if: runner.os == 'Windows' + run: npm run build + + # Packages the real exe and launches it, in parallel with check rather than after it. + packaged: + runs-on: windows-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 22 + cache: npm + - run: npm install -g npm@11 --no-fund --no-audit + - run: npm ci --no-fund + - run: npm run build # Claude Desktop launches `Diff Bro.exe mcp` with piped stdio; whether a # GUI-subsystem exe keeps those pipes can only be proven on Windows. - name: Claude connection answers over stdio (packaged exe) - if: runner.os == 'Windows' shell: bash env: CSC_IDENTITY_AUTO_DISCOVERY: 'false' @@ -80,7 +102,6 @@ jobs: # The GUI launch of the same package: e2e runs build/ from the repo, so a file # the package leaves out or a Windows-only startup step is invisible to it. - name: Packaged app starts clean - if: runner.os == 'Windows' run: node scripts/packaged-smoke.mjs dist # One bundle for every shard: building in each shard was most of its fixed cost. @@ -153,7 +174,7 @@ jobs: # which starts a single display and owns DISPLAY itself. - name: Start a virtual display per worker run: bash scripts/e2e-displays.sh - - uses: actions/download-artifact@v6 + - uses: actions/download-artifact@v8 with: name: e2e-build path: build/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b9beb1ff..bdeb93cd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -173,7 +173,7 @@ jobs: # and nsis) on every single run. Keyed on the lockfile, so an Electron bump # misses and refetches rather than packaging a stale runtime. - name: Cache the Electron + electron-builder downloads - uses: actions/cache@v4 + uses: actions/cache@v6 with: path: ${{ github.workspace }}/.cache key: ${{ runner.os }}-ebuilder-${{ hashFiles('package-lock.json') }} @@ -264,7 +264,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Mint a token for the version-sync App - uses: actions/create-github-app-token@v2 + uses: actions/create-github-app-token@v3 id: app-token with: app-id: '4412629' diff --git a/docs/standards.md b/docs/standards.md index 1d0f9ed5..1cb42992 100644 --- a/docs/standards.md +++ b/docs/standards.md @@ -696,7 +696,10 @@ system-ui, sans-serif`, at `--font-md` 13px, `--font-sm` 12px and works everywhere over one guarded by `process.platform`: spawn `process.execPath` against a package's own `bin`, compare generated text line-ending agnostically. E2E stays Linux-only (it needs Xvfb), so a Windows INTERACTION bug still has to - be found by hand. + be found by hand. Windows runs every guard and test (`check:static`, `npm test`, + the build) without coverage instrumentation: coverage is a measurement, not a + test, and its floors are enforced on ubuntu. A separate `packaged` job builds + the real exe and runs both smokes in parallel. - **macOS-only E2E runs on the Mac, not in Docker.** Some window-lifecycle bugs cannot exist on Linux — closing the last window quits the app there diff --git a/package.json b/package.json index ea48819a..118fa28f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "check:styles": "node scripts/check-style-tokens.mjs", "check:themes": "node scripts/check-theme-depth.mjs", "format": "prettier --write \"src/**/*.{js,vue,css}\" \"tests/**/*.js\" \"*.mjs\"", - "check": "npm run lint && npm run check:styles && npm run check:themes && npm run check:structure && npm run check:i18n && npm run check:rawtext && npm run test:coverage && npm run build", + "check": "npm run check:static && npm run test:coverage && npm run build", + "check:static": "npm run lint && npm run check:styles && npm run check:themes && npm run check:structure && npm run check:i18n && npm run check:rawtext", "postinstall": "electron-builder install-app-deps", "build:win": "npm run build && electron-builder --win --publish never", "build:mac": "npm run build && electron-builder --mac --publish never", diff --git a/scripts/lib/releaseVerified.mjs b/scripts/lib/releaseVerified.mjs index 20fff5d3..6f622688 100644 --- a/scripts/lib/releaseVerified.mjs +++ b/scripts/lib/releaseVerified.mjs @@ -1,5 +1,5 @@ -const OURS = /^(quick|check|e2e)\b/ -const REQUIRED = ['check (ubuntu', 'check (windows', 'e2e ('] +const OURS = /^(quick|check|packaged|e2e)\b/ +const REQUIRED = ['check (ubuntu', 'check (windows', 'packaged', 'e2e ('] // Judges CI on the tagged commit itself, so nothing is assumed about how it was merged. export function releaseVerdict(checkRuns) { diff --git a/src/main/window.js b/src/main/window.js index 97db4f5c..704273b4 100644 --- a/src/main/window.js +++ b/src/main/window.js @@ -4,6 +4,7 @@ import { readFileSync } from 'fs' import { join } from 'path' import { DEV_URL } from './env' import appIcon from '../../resources/icon.png?asset' +import { createStateSaver } from './windowStateSaver' // --- Window state persistence (size/position across launches) --- @@ -27,20 +28,14 @@ function loadWindowState() { } function trackWindowState(win) { - let timer = null - const save = () => { - const bounds = win.getNormalBounds() - writeFile(windowStatePath(), JSON.stringify({ ...bounds, maximized: win.isMaximized() })).catch( - () => {} - ) - } - const debounced = () => { - clearTimeout(timer) - timer = setTimeout(save, 500) - } - win.on('resize', debounced) - win.on('move', debounced) - win.on('close', save) + const saver = createStateSaver({ + snapshot: () => ({ ...win.getNormalBounds(), maximized: win.isMaximized() }), + write: (state) => writeFile(windowStatePath(), JSON.stringify(state)).catch(() => {}), + isGone: () => win.isDestroyed() + }) + win.on('resize', saver.soon) + win.on('move', saver.soon) + win.on('close', saver.now) } // The TOOLBAR sets the width floor, not the panes — below it the whole document diff --git a/src/main/windowStateSaver.js b/src/main/windowStateSaver.js new file mode 100644 index 00000000..013fd810 --- /dev/null +++ b/src/main/windowStateSaver.js @@ -0,0 +1,18 @@ +// Closing cancels a save still pending from the last move, which would otherwise fire on a destroyed window. +export function createStateSaver({ snapshot, write, isGone, delayMs = 500 }) { + let timer = null + const save = () => { + if (!isGone()) write(snapshot()) + } + return { + soon() { + clearTimeout(timer) + timer = setTimeout(save, delayMs) + }, + now() { + clearTimeout(timer) + timer = null + save() + } + } +} diff --git a/tests/main/windowStateSaver.test.js b/tests/main/windowStateSaver.test.js new file mode 100644 index 00000000..08a863cb --- /dev/null +++ b/tests/main/windowStateSaver.test.js @@ -0,0 +1,35 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { createStateSaver } from '../../src/main/windowStateSaver' + +beforeEach(() => vi.useFakeTimers()) +afterEach(() => vi.useRealTimers()) + +function setUp() { + const win = { gone: false } + const snapshot = vi.fn(() => { + if (win.gone) throw new Error('Object has been destroyed') + return { width: 800 } + }) + const write = vi.fn() + const saver = createStateSaver({ snapshot, write, isGone: () => win.gone }) + return { win, snapshot, write, saver } +} + +describe('saving window bounds', () => { + it('saves once, after the last of a burst of moves', () => { + const { saver, write } = setUp() + saver.soon() + saver.soon() + vi.advanceTimersByTime(500) + expect(write).toHaveBeenCalledTimes(1) + }) + + it('never reaches a window closed while a save was pending', () => { + const { win, saver, write } = setUp() + saver.soon() + saver.now() + win.gone = true + expect(() => vi.advanceTimersByTime(500)).not.toThrow() + expect(write).toHaveBeenCalledTimes(1) + }) +}) diff --git a/tests/scripts/releaseVerified.test.js b/tests/scripts/releaseVerified.test.js index d832e4de..228d0506 100644 --- a/tests/scripts/releaseVerified.test.js +++ b/tests/scripts/releaseVerified.test.js @@ -6,6 +6,7 @@ const FULL = green( 'quick', 'check (ubuntu-latest)', 'check (windows-latest)', + 'packaged', 'e2e-build', 'e2e (1)', 'e2e (2)' @@ -30,6 +31,10 @@ describe('releaseVerdict', () => { ) }) + it('retests when the packaged-app job is missing, so a broken package is never reused', () => { + expect(releaseVerdict(FULL.filter((r) => r.name !== 'packaged')).verified).toBe(false) + }) + it('ignores check runs from other workflows', () => { expect(releaseVerdict([...FULL, { name: 'CodeQL', conclusion: 'neutral' }]).verified).toBe(true) }) diff --git a/vitest.config.mjs b/vitest.config.mjs index 7af50a4b..7bc8abcf 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -72,6 +72,7 @@ export default defineConfig({ 'src/main/sealingTtl.js', 'src/main/launchGuard.js', 'src/main/startSteps.js', + 'src/main/windowStateSaver.js', 'src/main/lan/acks.js', 'src/main/lan/itemReceiver.js', 'src/main/lan/peerName.js',