TypeScript
ci(release): desktop builds that cannot open no longer publish (#25928)
Theo Brownef41518f3bc26
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.ymlindex 516a0a7785a..bff1b125be4 100644--- a/.github/workflows/release-desktop.yml+++ b/.github/workflows/release-desktop.yml@@ -64,6 +64,12 @@ on:required: falsedefault: falsetype: boolean+ # Whether the job opens the packaged app against a seeded database and+ # opens a thread before uploading it. Linux AppImage or macOS DMG.+ launch_check:+ required: false+ default: false+ type: boolean# A runner of the target's own platform and architecture, for a `runner`# that cannot execute the target. The build job skips everything that# runs the packaged binaries, and a second job runs it there.@@ -517,6 +523,38 @@ jobs:vp run dist:desktop:artifact "${args[@]}"+ # A build can package fine and still not open (a missing module in the+ # backend or the bundle). This launches the app from the shipped+ # AppImage or DMG.+ - name: Launch check+ if: inputs.launch_check+ shell: bash+ run: |+ set -euo pipefail+ check=(node scripts/smoke-desktop-app.ts --artifacts-dir "$RUNNER_TEMP/desktop-launch-check")+ if [[ "${{ inputs.platform }}" == "mac" ]]; then+ mount="$RUNNER_TEMP/desktop-launch-dmg"+ hdiutil attach -nobrowse -readonly -mountpoint "$mount" "$(ls "$GITHUB_WORKSPACE"/release/*.dmg)"+ trap 'hdiutil detach "$mount" -force >/dev/null || true' EXIT+ app=$(ls -d "$mount"/*.app)+ executable=$(/usr/libexec/PlistBuddy -c "Print :CFBundleExecutable" "$app/Contents/Info.plist")+ "${check[@]}" --executable "$app/Contents/MacOS/$executable"+ else+ sudo apt-get install -y xvfb+ appimage=$(ls "$GITHUB_WORKSPACE"/release/*.AppImage)+ chmod +x "$appimage"+ (cd "$RUNNER_TEMP" && "$appimage" --appimage-extract >/dev/null)+ xvfb-run -a "${check[@]}" --executable "$RUNNER_TEMP/squashfs-root/t3code"+ fi++ - name: Upload launch check output+ if: failure() && inputs.launch_check+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7+ with:+ name: desktop-launch-check-${{ inputs.platform }}-${{ inputs.arch }}+ path: ${{ runner.temp }}/desktop-launch-check+ if-no-files-found: ignore+# The verify job runs what this host could not: the packaged natives and# the CLI. Its scripts are bundled so that job needs no install.- name: Stage verification inputsdiff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 422dee70624..33076d208f3 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -619,6 +619,7 @@ jobs:rust_target: aarch64-apple-darwinresource_key: darwin-arm64cli_archive: true+ launch_check: truedesktop_mac_x64:name: Desktop macOS x64@@ -668,6 +669,7 @@ jobs:rust_target: x86_64-unknown-linux-gnuresource_key: linux-x64cli_archive: true+ launch_check: true# node-pty has no Linux prebuild and compiles from source, so the arm64 app# and archive are built on arm64 hardware rather than cross-built.diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex ad70e206af6..728ab36f7fc 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -7,8 +7,7 @@"scripts": {"ensure:electron": "node scripts/ensure-electron-runtime.mjs","start": "node scripts/start-electron.mjs",- "test": "vp test run --passWithNoTests",- "smoke-test": "node scripts/smoke-test.mjs"+ "test": "vp test run --passWithNoTests"},"dependencies": {"@clerk/electron": "catalog:",diff --git a/apps/desktop/scripts/smoke-test.mjs b/apps/desktop/scripts/smoke-test.mjsdeleted file mode 100644index 05195bb8d8c..00000000000--- a/apps/desktop/scripts/smoke-test.mjs+++ /dev/null@@ -1,58 +0,0 @@-import * as NodeChildProcess from "node:child_process";-import * as NodePath from "node:path";-import * as NodeURL from "node:url";-import { resolveElectronLaunchCommand } from "./electron-launcher.mjs";--const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));-const desktopDir = NodePath.resolve(__dirname, "..");-const mainJs = NodePath.resolve(desktopDir, "dist-electron/boot.cjs");--console.log("\nLaunching Electron smoke test...");--const electronCommand = resolveElectronLaunchCommand([mainJs]);-const child = NodeChildProcess.spawn(electronCommand.electronPath, electronCommand.args, {- stdio: ["pipe", "pipe", "pipe"],- env: {- ...process.env,- VITE_DEV_SERVER_URL: "",- ELECTRON_ENABLE_LOGGING: "1",- },-});--let output = "";-child.stdout.on("data", (chunk) => {- output += chunk.toString();-});-child.stderr.on("data", (chunk) => {- output += chunk.toString();-});--const timeout = setTimeout(() => {- child.kill();-}, 8_000);--child.on("exit", () => {- clearTimeout(timeout);-- const fatalPatterns = [- "Cannot find module",- "MODULE_NOT_FOUND",- "Refused to execute",- "Uncaught Error",- "Uncaught TypeError",- "Uncaught ReferenceError",- ];- const failures = fatalPatterns.filter((pattern) => output.includes(pattern));-- if (failures.length > 0) {- console.error("\nDesktop smoke test failed:");- for (const failure of failures) {- console.error(` - ${failure}`);- }- console.error("\nFull output:\n" + output);- process.exit(1);- }-- console.log("Desktop smoke test passed.");- process.exit(0);-});diff --git a/docs/operations/release.md b/docs/operations/release.mdindex b7dbe7e9d7b..4438d844536 100644--- a/docs/operations/release.md+++ b/docs/operations/release.md@@ -36,6 +36,7 @@ the version.- macOS `x64` DMG- Linux `x64` and `arm64` AppImage and `.deb`, from one electron-builder run. The `.deb` updates in the app through electron-updater, which installs it with `dpkg`.- Windows `x64` and `arm64` NSIS installer+- Opens the packaged Linux x64 AppImage (under Xvfb) and macOS arm64 DMG against a seeded database and opens a thread (`scripts/smoke-desktop-app.ts`). A build whose backend or bundle cannot start fails here, so nothing is published. The database in `scripts/fixtures/desktop-launch` is an old snapshot on purpose: the packaged server must migrate it forward, as it does for upgrading users. Do not regenerate it on schema changes.- Publishes one GitHub Release with all produced files.- Stable tags with a suffix after `X.Y.Z` (for example `1.2.3-alpha.1`) are published as GitHub prereleases.- Only plain stable `X.Y.Z` releases are marked as the repository's latest release.diff --git a/knip.jsonc b/knip.jsoncindex ab2c0b96c8e..4ff0f92ecfd 100644--- a/knip.jsonc+++ b/knip.jsonc@@ -21,7 +21,8 @@// worktree setup (from t3.json) run directly. release-desktop.yml bundles the// Windows verify script with esbuild through a path knip does not trace,// electron-builder loads the macOS signer by path, and mobile-e2e.ts runs- // agent-device's CLI by path.+ // agent-device's CLI by path. release-desktop.yml runs the desktop launch+ // check through xvfb-run, which knip does not trace."entry": [// These fixture scripts are injected into a browser page by path."fixtures/*/*.js",@@ -29,6 +30,7 @@"mobile-native-client.ts","setup-worktree.ts","sign-macos.ts",+ "smoke-desktop-app.ts","verify-windows-desktop-artifact.ts",],"ignoreDependencies": ["agent-device", "esbuild"],diff --git a/package.json b/package.jsonindex efbe53b4806..d0808c9d60a 100644--- a/package.json+++ b/package.json@@ -39,7 +39,6 @@"test:cached": "node scripts/test-cached.ts","test:perf:v2-wire": "vp test run apps/server/src/orchestration-v2/WireProjection.test.ts apps/server/src/orchestration-v2/threadHistoryPaging.test.ts apps/server/src/orchestration-v2/ThreadStream.test.ts apps/server/src/orchestration-v2/ThreadTransportPerformance.test.ts apps/server/src/orchestration-v2/ShellStream.test.ts apps/server/src/orchestration-v2/CommandPolicy.test.ts apps/server/src/orchestration-v2/runtimeLayer.test.ts apps/server/src/ws.test.ts packages/contracts/src/orchestrationV2.test.ts packages/client-runtime/src/operations/commands.test.ts packages/client-runtime/src/operations/commands.performance.test.ts packages/client-runtime/src/state/boundedThreadSnapshotHttp.test.ts packages/client-runtime/src/state/threadHistoryController.test.ts packages/client-runtime/src/state/threadHistoryMerge.test.ts packages/client-runtime/src/state/threads-sync.test.ts packages/client-runtime/src/state/shellReducer.test.ts","test:resource-monitor": "cargo test --locked --manifest-path native/resource-monitor/Cargo.toml",- "test:desktop-smoke": "vp run --filter @t3tools/desktop smoke-test","fmt": "vp fmt","fmt:check": "vp fmt --check","dist:desktop:artifact": "node scripts/build-desktop-artifact.ts",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 16a4e6269fc..c854ee33647 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2258,6 +2258,9 @@ importers:effect:specifier: 4.0.5version: 4.0.5+ playwright-core:+ specifier: 1.60.0+ version: 1.60.0plist:specifier: 'catalog:'version: 3.1.1diff --git a/scripts/fixtures/desktop-launch/statev2.sqlite b/scripts/fixtures/desktop-launch/statev2.sqlitenew file mode 100644index 00000000000..d63d6eec468Binary files /dev/null and b/scripts/fixtures/desktop-launch/statev2.sqlite differdiff --git a/scripts/package.json b/scripts/package.jsonindex bd5b39ce347..3733b5e4a81 100644--- a/scripts/package.json+++ b/scripts/package.json@@ -14,6 +14,7 @@"@t3tools/tailscale": "workspace:*","agent-device": "0.21.32","effect": "catalog:",+ "playwright-core": "1.60.0","plist": "catalog:","pngjs": "7.0.0","sharp": "0.35.4"diff --git a/scripts/smoke-desktop-app.ts b/scripts/smoke-desktop-app.tsnew file mode 100644index 00000000000..169d7faf4f9--- /dev/null+++ b/scripts/smoke-desktop-app.ts@@ -0,0 +1,97 @@+// @effect-diagnostics nodeBuiltinImport:off globalConsole:off+// Launches a packaged desktop app against a seeded T3 home, opens a thread, and checks its+// messages render. Release jobs run it so a build whose backend or bundle cannot start fails+// before it is published.+import * as NodeFS from "node:fs";+import * as NodeOS from "node:os";+import * as NodePath from "node:path";+import * as NodeTimersPromises from "node:timers/promises";+import * as NodeUtil from "node:util";+import { _electron, type ElectronApplication } from "playwright-core";++// A snapshot from an older build on purpose: the packaged server must migrate it forward, as it+// does for every upgrading user. It holds one project and two threads, nothing else.+const FIXTURE_DB = NodePath.join(import.meta.dirname, "fixtures/desktop-launch/statev2.sqlite");+const THREAD_TITLE = "Release launch check";+const THREAD_MESSAGE = "The release opens and shows this thread.";+const STEP_TIMEOUT_MS = 60_000;++const { values } = NodeUtil.parseArgs({+ options: {+ executable: { type: "string" },+ "artifacts-dir": { type: "string" },+ },+});+const executable = values.executable;+if (!executable)+ throw new Error("Usage: smoke-desktop-app.ts --executable <app> [--artifacts-dir <dir>]");+const artifactsDir = NodePath.resolve(values["artifacts-dir"] ?? "desktop-launch-check");++const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-desktop-launch-"));+const t3Home = NodePath.join(home, "t3");+NodeFS.mkdirSync(NodePath.join(t3Home, "userdata"), { recursive: true });+NodeFS.copyFileSync(FIXTURE_DB, NodePath.join(t3Home, "userdata/statev2.sqlite"));++let step = "launching the app";+let app: ElectronApplication | undefined;+try {+ app = await _electron.launch({+ executablePath: executable,+ // Linux CI runners do not allow the Chromium sandbox's user namespaces.+ args: ["--no-sandbox"],+ // HOME stays real: on macOS a fake HOME has no login keychain, and safeStorage blocks the+ // main process on a keychain dialog. macOS keeps its Electron profile in the runner's HOME.+ env: {+ ...process.env,+ XDG_CONFIG_HOME: NodePath.join(home, ".config"),+ XDG_DATA_HOME: NodePath.join(home, ".local/share"),+ T3CODE_HOME: t3Home,+ T3CODE_TELEMETRY_ENABLED: "false",+ T3CODE_DISABLE_AUTO_UPDATE: "true",+ },+ timeout: STEP_TIMEOUT_MS,+ });+ // A backend that never starts leaves no window, or only the "could not start" window, so the+ // thread wait below fails either way and its screenshot shows the startup error.+ step = "waiting for the first window";+ const page = await app.firstWindow({ timeout: STEP_TIMEOUT_MS });+ try {+ step = `finding "${THREAD_TITLE}" in the sidebar`;+ const thread = page.locator("li[data-thread-item]", { hasText: THREAD_TITLE });+ await thread.waitFor({ timeout: STEP_TIMEOUT_MS });+ step = "opening the thread";+ await thread.click();+ await page.getByText(THREAD_MESSAGE).waitFor({ timeout: STEP_TIMEOUT_MS });+ } catch (error) {+ NodeFS.mkdirSync(artifactsDir, { recursive: true });+ await page+ .screenshot({ path: NodePath.join(artifactsDir, "window.png"), timeout: 10_000 })+ .catch(() => {});+ throw error;+ }+ console.log("Desktop launch check passed: the app opened and showed the seeded thread.");+} catch (error) {+ console.error(`Desktop launch check failed while ${step}.`);+ NodeFS.mkdirSync(artifactsDir, { recursive: true });+ console.error(error instanceof Error ? error.message : error);+ const logs = NodePath.join(t3Home, "userdata/logs");+ if (NodeFS.existsSync(logs)) {+ NodeFS.cpSync(logs, NodePath.join(artifactsDir, "logs"), { recursive: true });+ const serverLog = NodePath.join(logs, "server-child.log");+ if (NodeFS.existsSync(serverLog)) {+ console.error("\nLast backend output (server-child.log):");+ console.error(NodeFS.readFileSync(serverLog, "utf8").split("\n").slice(-20).join("\n"));+ }+ }+ process.exitCode = 1;+} finally {+ if (app) {+ // A hung app never finishes closing; kill it so the job does not wait for its timeout.+ // Playwright drops the process handle once the app closes, so read it first.+ const child = app.process();+ const closed = app.close().catch(() => {});+ await Promise.race([closed, NodeTimersPromises.setTimeout(10_000, undefined, { ref: false })]);+ child.kill("SIGKILL");+ }+ NodeFS.rmSync(home, { recursive: true, force: true, maxRetries: 5 });+}