diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8854d39a..7dc80f4a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -330,15 +330,15 @@ Claude plugin folder `release/claude-plugin/mobile-dev` with its ZIP, and a loca Claude's server (`apps/claude/server`), with the panel and agent-device's commands as `device_*` tools, the skill in `apps/claude/skills` and the shared agent-device skill. Packaging fails if a file exceeds the Claude plugin directory's 5 MiB limit, so the -packages leave out the panel's native parts (`PANEL_PARTS` in -`tooling/host-runtime.mjs`: Baguette, serve-emu, the iOS mirror addon and its -service), as `"panelRuntime": "download"` in `apps/claude/plugin-host.json` asks. +packages use `"panelRuntime": "download"` in `apps/claude/plugin-host.json`. The archive +includes the native panel parts and the Testing Studio runner +(`DOWNLOADED_RUNTIME_PARTS` in `tooling/host-runtime.mjs`). Packaging packs those parts from `dist/` into `release/mobile-dev--panel-runtime-darwin-arm64.tar.gz` and pins it in `dist/panel-runtime.json` with its size and SHA-256. A local build pins the archive by its `file:` URL; `--release` pins it on the GitHub release `v`, which the release workflow creates with every `release/mobile-dev--*` file, this archive -included. On the first panel open, the server downloads the archive, checks its size +included. On first use of a component in the archive, the server downloads it, checks its size and checksum, refuses entries outside the parts and links, and extracts it into `${CLAUDE_PLUGIN_DATA}/panel-runtime/-` (or `~/Library/Caches/mobile-dev/panel-runtime` without it). The folder appears only once diff --git a/PRIVACY.md b/PRIVACY.md index 38733b3f..fac232c1 100644 --- a/PRIVACY.md +++ b/PRIVACY.md @@ -96,7 +96,7 @@ not a reason to put secrets into your test data. ### Product analytics -Starting with version 0.1.190, release builds send basic product analytics to Anal +Starting with version 0.1.191, release builds send basic product analytics to Anal at `anal.margelo.com` so we can see how many installations use Mobile Dev and which tools they use most. Events record that a host session started or that a tool was called, with the tool's name, whether it succeeded, the host (Codex, Claude, diff --git a/apps/claude/README.md b/apps/claude/README.md index 1f737b80..f2bfca57 100644 --- a/apps/claude/README.md +++ b/apps/claude/README.md @@ -56,15 +56,15 @@ The plugin bundles most of its runtimes and native helpers, so no `npm install`, account, or hosted service is needed. Your project's own tools build the app. Besides its Node.js server, it runs: -- **The device panel's runtime, downloaded once.** The first time you open the panel, +- **The device and Testing Studio runtime, downloaded once.** On first use, Mobile Dev downloads one archive from this project's GitHub release for the installed version (`mobile-dev--panel-runtime-darwin-arm64.tar.gz`, from `github.com/callstackincubator/codex-mobile-dev-plugin/releases`). The plugin pins the archive's size and SHA-256 checksum and refuses any other file. It holds [Baguette](https://github.com/tddworks/baguette), which streams and controls iOS simulators, serve-emu with scrcpy for Android streaming, and the physical iPhone - mirroring addon and its service, built from the source and versions this - repository pins. It is unpacked into Claude Code's data folder for the plugin + mirroring addon and its service, plus the Testing Studio runner. The repository + pins their versions. The archive is unpacked into Claude Code's plugin data folder (`~/.claude/plugins/data/`), or `~/Library/Caches/mobile-dev` elsewhere, and kept across sessions; an update downloads its own version and removes older ones. Nothing is downloaded until you open the panel, and the other tools work without it. diff --git a/apps/claude/server/server.ts b/apps/claude/server/server.ts index 67a5801b..5051df56 100644 --- a/apps/claude/server/server.ts +++ b/apps/claude/server/server.ts @@ -9,9 +9,8 @@ import { downloadedPanelRuntime, panelRuntimeReleaseSchema, usePanelRuntime } fr // which Claude Code shows in a browser beside the chat. The panel never renders inline, // even in the desktop app's Code tab, which renders MCP Apps: every host gets the // browser link, so the device stays beside the chat. The plugin directory's file limit -// leaves the panel's native parts out of the package; it pins their release archive in -// panel-runtime.json, which the server downloads on first use. Without that file, as in -// host tests, the parts sit beside the server. +// applies to the panel's native parts and the Testing Studio runner. The package pins +// their release archive in panel-runtime.json, which the server downloads on first use. const pinned = await readFile(new URL("./panel-runtime.json", import.meta.url), "utf8").catch(() => undefined); if (pinned !== undefined) usePanelRuntime(downloadedPanelRuntime(panelRuntimeReleaseSchema.parse(JSON.parse(pinned)))); await runStdioServer({ panel: createPanel({ inline: false }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: true })] }); diff --git a/docs/architecture.md b/docs/architecture.md index 1624f2c4..aad7b08a 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -34,7 +34,7 @@ A host adds to the shared pieces without changing them: - **Runtime:** a host's `plugin-host.json` can leave out the panel's parts of `dist/` (`"panel": false`, see `PANEL_PARTS` in `tooling/host-runtime.mjs`), download them instead (`"panelRuntime": "download"`), and name a server build of its own. Claude - downloads Baguette, serve-emu and the iOS mirror from a release archive its package + downloads the native helpers and Testing Studio runner from a release archive its package pins (`packages/core/src/panel-runtime.ts`), and its server loads after telemetry as a separate module, so esbuild splits it into chunks beside `server.mjs`, keeping every file under the Claude plugin directory's 5 MiB limit. diff --git a/docs/telemetry.md b/docs/telemetry.md index e1a68df4..c401af76 100644 --- a/docs/telemetry.md +++ b/docs/telemetry.md @@ -35,13 +35,14 @@ Behavior never depends on this value; it only attributes measurements and errors model context updates by `outcome` (`stored`, `invalid` or `too_large`), and `browser_panel.context_bytes` records the size of stored updates in bytes; the context's text and images are never sent. -- Packages that download the panel's native parts, such as Claude's, measure that +- Packages that download the device and Testing Studio runtime, such as Claude's, measure that step. `panel_runtime.ready` records, in milliseconds, how long the runtime took to be - ready on a panel's first backend start in a server, by `outcome`: `cached` when a + ready on its first use in a server, by `outcome`: `cached` when a complete folder was already there, `downloaded` for a download, checksum check and extraction, or `failed` with a bounded `reason` (`network`, `http`, `checksum`, `archive` or `filesystem`). `panel_runtime.download_bytes` records the archive size - of each download. A failure surfaces as the expected `download_failed` outcome; + of each download, including the Testing Studio runtime since 0.1.191. A failure + surfaces as the expected `download_failed` outcome; checksum, archive and filesystem failures are also captured as `panel_runtime.prepare` errors with a `panel_runtime_failure` tag, while offline machines and unreachable releases are not. URLs, paths and versions are never @@ -60,7 +61,7 @@ shell has no native Sentry SDK. ## Product analytics -Starting with 0.1.190, release MCP servers send basic product analytics to the +Starting with 0.1.191, release MCP servers send basic product analytics to the Mobile Dev project in Anal to count installations and feature use. Earlier releases from 0.1.177 send to Mixpanel's EU endpoint. `instrumentProductAnalytics` (`packages/core/src/analytics.ts`) wraps the `tools/call` handler and reports diff --git a/package-lock.json b/package-lock.json index 11f9d87f..7b9bb74b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mobile-dev", - "version": "0.1.190", + "version": "0.1.191", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mobile-dev", - "version": "0.1.190", + "version": "0.1.191", "workspaces": [ "packages/shared", "packages/core", diff --git a/package.json b/package.json index 33461316..a5f6f497 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mobile-dev", - "version": "0.1.190", + "version": "0.1.191", "private": true, "workspaces": [ "packages/shared", diff --git a/packages/core/src/e2e-runtime.ts b/packages/core/src/e2e-runtime.ts index d8daf11c..8f2c6b3b 100644 --- a/packages/core/src/e2e-runtime.ts +++ b/packages/core/src/e2e-runtime.ts @@ -4,6 +4,7 @@ import { readFile } from "node:fs/promises"; import { dirname, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { ExpectedOperationError } from "@mobile-dev/shared/error-reporting.ts"; +import { panelRuntimePath } from "./panel-runtime.ts"; export type TestingRuntimeMode = "project" | "bundled"; @@ -15,18 +16,20 @@ export interface TestingRuntimeDescriptor { reason?: string; } -const sourceRuntime = resolve("packages/runtimes/e2e"); +const modulePath = fileURLToPath(import.meta.url); +const moduleDirectory = dirname(modulePath); /** The runner a project run executes (`runnerBin`); its presence is what makes a project's own setup usable. */ export const PROJECT_CLI = "node_modules/.bin/e2e"; -/** The shipped runtime beside server.mjs, with the source tree fallback used by unit tests. */ -export function bundledE2eRoot(): string { +/** Resolves the E2E runtime from the source tree or the packaged host's runtime. */ +export async function bundledE2eRoot(): Promise { const configured = process.env.MOBILE_DEV_E2E_RUNTIME?.trim(); - const besideServer = join(dirname(fileURLToPath(import.meta.url)), "e2e"); - for (const candidate of [configured, besideServer, sourceRuntime]) { - if (candidate && existsSync(join(candidate, "node_modules/e2e/package.json"))) return candidate; - } + const root = configured || (modulePath.endsWith(".ts") + ? resolve(moduleDirectory, "../../runtimes/e2e") + : await panelRuntimePath("e2e")); + const manifest = join(root, "node_modules/e2e/package.json"); + if (existsSync(manifest)) return root; throw new ExpectedOperationError("app_unavailable", "The bundled e2e runtime is missing. Reinstall Mobile Dev."); } @@ -36,7 +39,7 @@ async function version(root: string, name: string): Promise { } export async function bundledRuntimeDescriptor(reason?: string): Promise { - const root = bundledE2eRoot(); + const root = await bundledE2eRoot(); return { mode: "bundled", root, @@ -65,7 +68,7 @@ export async function projectRuntimeDescriptor(projectPath: string): Promise { - const root = bundledE2eRoot(); + const root = await bundledE2eRoot(); const lock = await readFile(join(root, "package-lock.json"), "utf8"); const release = JSON.parse(await readFile(join(root, "release.json"), "utf8")); const actual = createHash("sha256").update(lock).digest("hex"); diff --git a/packages/core/src/panel-runtime.ts b/packages/core/src/panel-runtime.ts index 3dcc188c..7490f7fd 100644 --- a/packages/core/src/panel-runtime.ts +++ b/packages/core/src/panel-runtime.ts @@ -12,9 +12,10 @@ import { z } from "zod"; import { ExpectedOperationError } from "@mobile-dev/shared/error-reporting.ts"; import { captureServerError, recordPanelRuntime } from "./telemetry.ts"; -/** The panel's native parts, as the runtime archive and dist/ lay them out (tooling's PANEL_PARTS). */ -export const PANEL_RUNTIME_PARTS = ["baguette", "serve-emu", "ios-mirror", "ios-mirror-service.mjs", "resource-saving"] as const; -export type PanelRuntimeFile = "baguette/Baguette" | "serve-emu/src/cli.mjs" | "ios-mirror-service.mjs" | "resource-saving/simslim" | "resource-saving/avdslim"; +/** The parts in the downloadable runtime, as laid out in dist/. */ +export const PANEL_RUNTIME_PARTS = ["baguette", "serve-emu", "ios-mirror", "ios-mirror-service.mjs", "resource-saving", "e2e"] as const; +export type PanelRuntimeFile = "baguette/Baguette" | "serve-emu/src/cli.mjs" | "ios-mirror-service.mjs" | "resource-saving/simslim" | "resource-saving/avdslim" | "e2e"; +const E2E_CLI = "e2e/node_modules/e2e/dist/cli/bin.js"; // Bundled, this module is server.mjs or a chunk in dist/, beside the parts. let locate: () => Promise = async () => fileURLToPath(new URL("./", import.meta.url)); @@ -40,7 +41,7 @@ export type PanelRuntimeRelease = z.infer; export class PanelRuntimeUnavailableError extends ExpectedOperationError { constructor(detail: string) { - super("download_failed", `Mobile Dev could not download its device runtime: ${detail} Check the internet connection, then open Mobile Dev again.`); + super("download_failed", `Mobile Dev could not download its device and testing runtime: ${detail} Check the internet connection, then try again.`); } } @@ -123,6 +124,8 @@ async function complete(target: string, release: PanelRuntimeRelease) { const marker: unknown = JSON.parse(await readFile(join(target, "panel-runtime.json"), "utf8")); if (typeof marker !== "object" || marker === null || ("sha256" in marker && marker.sha256 === release.sha256) === false) return false; await access(join(target, "baguette/Baguette"), constants.X_OK); + const e2eCli = join(target, E2E_CLI); + await access(e2eCli); for (const name of ["simslim", "avdslim"]) { const executable = join(target, "resource-saving", name); await access(executable, constants.X_OK); @@ -182,6 +185,10 @@ async function extract(archive: string, staging: string) { await access(join(staging, "baguette/Baguette"), constants.X_OK).catch(() => { throw new RuntimeFailure("archive", "the simulator backend in the archive is not executable."); }); + const e2eCli = join(staging, E2E_CLI); + await access(e2eCli).catch(() => { + throw new RuntimeFailure("archive", "the archive is missing the Testing Studio runner."); + }); for (const name of ["simslim", "avdslim"]) { const executable = join(staging, "resource-saving", name); await access(executable, constants.X_OK).catch(() => { throw new RuntimeFailure("archive", "a resource optimizer in the archive is not executable."); }); diff --git a/packages/core/src/testing-device.ts b/packages/core/src/testing-device.ts index 771c0259..2cc3b0c2 100644 --- a/packages/core/src/testing-device.ts +++ b/packages/core/src/testing-device.ts @@ -145,7 +145,7 @@ async function loadProjectionWithFallback(runtimeRoot: string): Promise { throw error; }); } diff --git a/packages/core/src/testing-setup.ts b/packages/core/src/testing-setup.ts index 2aec51c8..7c6ae2c2 100644 --- a/packages/core/src/testing-setup.ts +++ b/packages/core/src/testing-setup.ts @@ -74,7 +74,10 @@ const SUBSCRIPTION_IDS = ["openai", "github-copilot", "opencode-console", "space export async function readTestingLoginStatus(): Promise { const status = Object.fromEntries(SUBSCRIPTION_IDS.map(id => [id, false])) as TestingLoginStatus; try { - const module = await import(pathToFileURL(join(bundledE2eRoot(), "node_modules/e2e/dist/oauth/store.js")).href) as { + const root = await bundledE2eRoot(); + const store = join(root, "node_modules/e2e/dist/oauth/store.js"); + const url = pathToFileURL(store); + const module = await import(url.href) as { defaultCredentialStore(): { list(): Promise }; }; const stored = new Set(await module.defaultCredentialStore().list()); @@ -200,7 +203,8 @@ function packageManager(root: string, manifest: Record): SetupP } async function skillFiles(): Promise<{ relative: string; content: string }[]> { - const root = join(bundledE2eRoot(), "node_modules/e2e/skills/e2e"); + const runtime = await bundledE2eRoot(); + const root = join(runtime, "node_modules/e2e/skills/e2e"); const files: { relative: string; content: string }[] = []; const walk = async (directory: string) => { for (const entry of await readdir(directory, { withFileTypes: true })) { @@ -372,7 +376,10 @@ type OAuthProvider = "openai" | "github-copilot" | "opencode-console" | "spacexa type LoginCallbacks = { signal: AbortSignal; onAuth(auth: { url: string; instructions: string; userCode?: string }): void; onProgress(message: string): void; onPrompt(prompt: { message: string; placeholder?: string }): Promise }; type LoginRunner = (provider: OAuthProvider, callbacks: LoginCallbacks) => Promise; async function e2eLogin(providerId: OAuthProvider, callbacks: LoginCallbacks) { - const module = await import(pathToFileURL(join(bundledE2eRoot(), "node_modules/e2e/dist/oauth/login.js")).href) as { login(provider: string, input: Record): Promise }; + const root = await bundledE2eRoot(); + const login = join(root, "node_modules/e2e/dist/oauth/login.js"); + const url = pathToFileURL(login); + const module = await import(url.href) as { login(provider: string, input: Record): Promise }; return module.login(providerId, { callbacks }); } export function startTestingLogin(id: OAuthProvider, runLogin: LoginRunner = e2eLogin): SetupOperation { diff --git a/packages/core/test/panel-runtime.test.ts b/packages/core/test/panel-runtime.test.ts index 3dca5762..8bbd5c7b 100644 --- a/packages/core/test/panel-runtime.test.ts +++ b/packages/core/test/panel-runtime.test.ts @@ -10,7 +10,7 @@ import { join } from "node:path"; import { pathToFileURL } from "node:url"; import { ExpectedOperationError } from "@mobile-dev/shared/error-reporting.ts"; import { downloadedPanelRuntime, PANEL_RUNTIME_PARTS, panelRuntimeDirectory, panelRuntimeReleaseSchema, panelRuntimePath, PanelRuntimeUnavailableError, usePanelRuntime, type PanelRuntimeRelease } from "../src/panel-runtime.ts"; -import { PANEL_PARTS } from "../../../tooling/host-runtime.mjs"; +import { DOWNLOADED_RUNTIME_PARTS } from "../../../tooling/host-runtime.mjs"; /** A runtime archive laid out like dist/, with extra entries a tampered archive might hold. */ async function archive(t: test.TestContext, extra?: (root: string) => Promise) { @@ -32,6 +32,9 @@ async function archive(t: test.TestContext, extra?: (root: string) => Promise { status: number; body? } test("the runtime parts match the parts packaging leaves out", () => { - assert.deepEqual([...PANEL_RUNTIME_PARTS], PANEL_PARTS); + assert.deepEqual([...PANEL_RUNTIME_PARTS], DOWNLOADED_RUNTIME_PARTS); }); test("the runtime downloads once, verifies, and is shared by later servers", async t => { @@ -76,6 +79,8 @@ test("the runtime downloads once, verifies, and is shared by later servers", asy assert.deepEqual(await readdir(data), [`1.2.3-${release.sha256.slice(0, 12)}`]); usePanelRuntime(first); assert.equal(await panelRuntimePath("serve-emu/src/cli.mjs"), join(root, "serve-emu/src/cli.mjs")); + const e2e = await panelRuntimePath("e2e"); + assert.equal(e2e, join(root, "e2e")); }); test("an archive that does not match its pin is refused and leaves nothing behind", async t => { diff --git a/packages/core/test/testing-run.test.ts b/packages/core/test/testing-run.test.ts index 36ccee89..02dae2fe 100644 --- a/packages/core/test/testing-run.test.ts +++ b/packages/core/test/testing-run.test.ts @@ -380,7 +380,7 @@ test("bundled mode runs and cleans an isolated Testing Studio workspace", async const seen: { command?: string; args?: readonly string[]; cwd?: string } = {}; const result = await runRecordedTest({ projectPath: root, relativePath: FILE, untilSource: 'test("x", async () => {});\n', - runtime: { mode: "bundled", root: bundledE2eRoot() }, + runtime: { mode: "bundled", root: await bundledE2eRoot() }, bundledTarget: { platform: "ios", bundleId: "com.example.app" }, }, { spawner: spawner(JSON.stringify(report([{ line: 1, status: "passed" }])), 0, seen), runnerCwd }); assert.equal(result.status, "passed"); @@ -402,7 +402,7 @@ test("a bundled run spawns from the app's stable runner folder by default", asyn const seen: { command?: string; args?: readonly string[]; cwd?: string } = {}; await runRecordedTest({ projectPath: await project(), relativePath: FILE, untilSource: 'test("x", async () => {});\n', - runtime: { mode: "bundled", root: bundledE2eRoot() }, bundledTarget: { platform: "ios", bundleId: "com.example.app" }, + runtime: { mode: "bundled", root: await bundledE2eRoot() }, bundledTarget: { platform: "ios", bundleId: "com.example.app" }, }, { spawner: spawner(JSON.stringify(report([{ line: 1, status: "passed" }])), 0, seen) }); assert.equal(seen.cwd, RUNNER_CWD); assert.ok(!seen.cwd.startsWith(tmpdir())); @@ -413,7 +413,7 @@ test("bundled deterministic tests need no model and agent tests request one", as assert.doesNotMatch(bundledConfigSource({ platform: "android", bundleId: "com.example.app" }), /agents:/); await assert.rejects(runRecordedTest({ projectPath: "/unused", relativePath: FILE, untilSource: 'test("x", async ({ agent }) => { await agent.extract("title"); });\n', - runtime: { mode: "bundled", root: bundledE2eRoot() }, bundledTarget: { platform: "android", bundleId: "com.example.app" }, + runtime: { mode: "bundled", root: await bundledE2eRoot() }, bundledTarget: { platform: "android", bundleId: "com.example.app" }, }), /Choose a provider and model/); }); @@ -435,7 +435,7 @@ test("a pinned bundled run passes its own target and output directory, removed a const seen: { command?: string; args?: readonly string[]; cwd?: string } = {}; await runRecordedTest({ projectPath: root, relativePath: FILE, untilSource: 'test("x", async () => {});\n', - runtime: { mode: "bundled", root: bundledE2eRoot() }, + runtime: { mode: "bundled", root: await bundledE2eRoot() }, bundledTarget: { platform: "android", bundleId: "com.example.app", device: "emulator-5554" }, }, { spawner: spawner(JSON.stringify(report([{ line: 1, status: "passed" }])), 0, seen) }); const args = seen.args ?? []; @@ -459,7 +459,7 @@ test("aborting a run kills its process and reports it as cancelled", async () => }) as never; const run = runRecordedTest({ projectPath: root, relativePath: FILE, untilSource: 'test("x", async () => {});\n', - runtime: { mode: "bundled", root: bundledE2eRoot() }, bundledTarget: { platform: "ios", bundleId: "a.b" }, + runtime: { mode: "bundled", root: await bundledE2eRoot() }, bundledTarget: { platform: "ios", bundleId: "a.b" }, }, { spawner: hanging, signal: controller.signal }); setTimeout(() => controller.abort(), 20); await assert.rejects(run, /cancelled/); diff --git a/packages/shared/src/version.ts b/packages/shared/src/version.ts index 0708860b..384a3656 100644 --- a/packages/shared/src/version.ts +++ b/packages/shared/src/version.ts @@ -1 +1 @@ -export const PLUGIN_VERSION = "0.1.190"; +export const PLUGIN_VERSION = "0.1.191"; diff --git a/tooling/host-runtime.mjs b/tooling/host-runtime.mjs index 509a3b84..48f36282 100644 --- a/tooling/host-runtime.mjs +++ b/tooling/host-runtime.mjs @@ -10,6 +10,7 @@ export const RELEASE_DOCUMENTS = ["README.md", "LICENSE", "THIRD_PARTY_NOTICES.m * server has no panel leave them out. */ export const PANEL_PARTS = ["baguette", "serve-emu", "ios-mirror", "ios-mirror-service.mjs", "resource-saving"]; +export const DOWNLOADED_RUNTIME_PARTS = [...PANEL_PARTS, "e2e"]; const APPLE_RUNTIME_FILES = [ "baguette/Baguette", "baguette/Baguette_Baguette.bundle", @@ -28,10 +29,14 @@ const RUNTIME_FILES = [ "e2e/package-lock.json", "e2e/release.json", "e2e/THIRD_PARTY_NOTICES.txt", ]; -export async function stageRuntime(directory, { panel = true } = {}) { +export async function stageRuntime(directory, { exclude = [] } = {}) { await cp("dist", directory, { recursive: true, verbatimSymlinks: true, - filter: source => panel || PANEL_PARTS.includes(relative("dist", source).split(sep)[0]) === false, + filter(source) { + const path = relative("dist", source); + const [part] = path.split(sep); + return exclude.includes(part) === false; + }, }); } diff --git a/tooling/package-plugin.mjs b/tooling/package-plugin.mjs index 630f6070..0380b462 100644 --- a/tooling/package-plugin.mjs +++ b/tooling/package-plugin.mjs @@ -2,7 +2,7 @@ import { execFileSync } from "node:child_process"; import { cp, copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises"; import { basename, dirname, join, relative, resolve } from "node:path"; import { telemetryBuildEnvironment } from "./telemetry-build.mjs"; -import { assertRuntime, oversizedFiles, RELEASE_DOCUMENTS as documents, releaseVersion, stageRuntime } from "./host-runtime.mjs"; +import { assertRuntime, DOWNLOADED_RUNTIME_PARTS, oversizedFiles, PANEL_PARTS, RELEASE_DOCUMENTS as documents, releaseVersion, stageRuntime } from "./host-runtime.mjs"; import { pluginHost } from "./plugin-hosts.mjs"; import { pluginMarketplace } from "./plugin-marketplace.mjs"; import { packPanelRuntime } from "./panel-runtime.mjs"; @@ -21,9 +21,10 @@ const version = await releaseVersion(); // the same Sentry debug IDs. const runtime = resolve(`release/${name}-runtime`); await rm(runtime, { recursive: true, force: true }); -await stageRuntime(runtime, { panel: host.bundlesPanel }); -// A host that downloads the panel's parts pins their archive, which releases attach. -if (host.panel && host.bundlesPanel === false) { +const downloadsRuntime = host.panel && host.panelRuntime === "download"; +const excludedParts = host.bundlesPanel ? [] : PANEL_PARTS; +await stageRuntime(runtime, { exclude: downloadsRuntime ? DOWNLOADED_RUNTIME_PARTS : excludedParts }); +if (downloadsRuntime) { const { archive, pin } = await packPanelRuntime(version, { release: environment === "release" }); await writeFile(`${runtime}/panel-runtime.json`, JSON.stringify(pin, null, 2) + "\n"); console.log(`Panel runtime archive: ${archive}`); diff --git a/tooling/panel-runtime.mjs b/tooling/panel-runtime.mjs index 5c5685a6..31d18912 100644 --- a/tooling/panel-runtime.mjs +++ b/tooling/panel-runtime.mjs @@ -3,13 +3,13 @@ import { createHash } from "node:crypto"; import { readFile, rm, stat } from "node:fs/promises"; import { resolve } from "node:path"; import { pathToFileURL } from "node:url"; -import { PANEL_PARTS } from "./host-runtime.mjs"; +import { DOWNLOADED_RUNTIME_PARTS } from "./host-runtime.mjs"; /** The panel runtime archive each release attaches beside its packages. */ export const panelRuntimeArchive = version => `mobile-dev-${version}-panel-runtime-darwin-arm64.tar.gz`; /** - * Packs the panel's parts from dist/ into the release archive and returns the pin a + * Packs the downloadable runtime from dist/ into the release archive and returns the pin a * package ships as panel-runtime.json. A release pins the archive on its GitHub * release, under the tag `v`; a local build pins the file it just wrote, so * development packages work before anything is published. @@ -17,8 +17,11 @@ export const panelRuntimeArchive = version => `mobile-dev-${version}-panel-runti export async function packPanelRuntime(version, { release = false, repository = defaultRepository() } = {}) { const archive = resolve("release", panelRuntimeArchive(version)); await rm(archive, { force: true }); - // No AppleDouble files or extended attributes: the server accepts only the parts. - execFileSync("tar", ["-czf", archive, "--no-mac-metadata", "--exclude", ".DS_Store", "-C", "dist", ...PANEL_PARTS], { + // The runtime accepts plain files. Testing Studio invokes the runner directly. + execFileSync("tar", [ + "-czf", archive, "--no-mac-metadata", "--exclude", ".DS_Store", + "--exclude", "e2e/node_modules/.bin", "-C", "dist", ...DOWNLOADED_RUNTIME_PARTS, + ], { env: { ...process.env, COPYFILE_DISABLE: "1" }, }); const bytes = await readFile(archive); diff --git a/tooling/smoke-plugin.mjs b/tooling/smoke-plugin.mjs index d1efc64f..04978387 100644 --- a/tooling/smoke-plugin.mjs +++ b/tooling/smoke-plugin.mjs @@ -8,7 +8,7 @@ import { pathToFileURL } from "node:url"; import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"; -import { PANEL_PARTS, releaseVersion } from "./host-runtime.mjs"; +import { DOWNLOADED_RUNTIME_PARTS, PANEL_PARTS, releaseVersion } from "./host-runtime.mjs"; import { panelRuntimeArchive } from "./panel-runtime.mjs"; import { codexOnlyPaths, pluginHost, pluginHosts } from "./plugin-hosts.mjs"; @@ -27,6 +27,8 @@ const panelTools = ["mobile_open_workspace", "mobile_open_simulator", "mobile_li // Every host's agent controls apps with agent-device's commands. const expectedTools = [...panels ? panelTools : ["mobile_render_performance_recording", "mobile_logs_session"], "device_open", "device_snapshot"]; const panelFiles = PANEL_PARTS.map(part => `dist/${part}`); +const omittedParts = panels ? DOWNLOADED_RUNTIME_PARTS : PANEL_PARTS; +const omittedFiles = omittedParts.map(part => `dist/${part}`); // Packages that leave the panel's parts out pin their archive instead. const bundled = host.bundlesPanel; const packagedFiles = panels ? bundled ? panelFiles : ["dist/panel-runtime.json", "dist/browser-panel.html"] : []; @@ -90,11 +92,25 @@ async function smokePanelRuntime(plugin, launch) { // The published release may not exist yet, so the copy pins this archive by its file. await writeFile(join(plugin, "dist/panel-runtime.json"), JSON.stringify({ ...pin, url: pathToFileURL(archive).href })); const data = join(temporary, "plugin data"); + const testingProject = join(temporary, "empty testing project"); + await mkdir(testingProject); await launch({ CLAUDE_PLUGIN_DATA: data }, async client => { + const config = await client.callTool({ name: "mobile_testing_project_config", arguments: { projectPath: testingProject } }); + const configContent = JSON.stringify(config.content); + assert.notEqual(config.isError, true, configContent); + const cache = join(data, "panel-runtime"); + const installed = await readdir(cache); + const hashPrefix = pin.sha256.slice(0, 12); + const folder = `${version}-${hashPrefix}`; + assert.deepEqual(installed, [folder]); + const runtime = join(cache, folder, "e2e"); + assert.equal(config.structuredContent.runtime.root, runtime); + const cli = join(runtime, "node_modules/e2e/dist/cli/bin.js"); + const cliVersion = execFileSync(process.execPath, [cli, "--version"], { encoding: "utf8" }); + const reportedVersion = cliVersion.trim(); + assert.equal(reportedVersion, config.structuredContent.runtime.e2eVersion); const started = await client.callTool({ name: "mobile_start_baguette", arguments: {} }); assert.notEqual(started.isError, true, JSON.stringify(started.content)); - const installed = await readdir(join(data, "panel-runtime")); - assert.deepEqual(installed, [`${version}-${pin.sha256.slice(0, 12)}`]); await smokeBrowserPanel(client); }); } @@ -132,7 +148,7 @@ async function smokeDesktopBundle() { for (const path of [manifest.server.entry_point, "dist/app.html", "dist/agent-device/tools.json", ...packagedFiles]) { await access(join(directory, path)); } - if (bundled === false) for (const path of panelFiles) await assert.rejects(access(join(directory, path)), path); + if (bundled === false) for (const path of omittedFiles) await assert.rejects(access(join(directory, path)), path); // No Codex installation, no PATH Node lookup, and no dependency on package cwd. const args = manifest.server.mcp_config.args.map(arg => arg.replaceAll("${__dirname}", directory)); for (const [environment, forms] of [["development", false], ["release", false], ["development", true]]) { @@ -166,7 +182,7 @@ try { for (const path of ["LICENSE", "README.md", "PRIVACY.md", "dist/app.html", ...host.skills.map(skill => `skills/${basename(skill)}/SKILL.md`), "skills/agent-device/references/workflow.md", ...packagedFiles]) { await access(join(plugin, path)); } - if (bundled === false) for (const path of panelFiles) await assert.rejects(access(join(plugin, path)), path); + if (bundled === false) for (const path of omittedFiles) await assert.rejects(access(join(plugin, path)), path); if (host.readme) assert.equal(await readFile(join(plugin, "README.md"), "utf8"), await readFile(host.readme, "utf8")); // Plugin directories reject symlinks, and agents/openai.yaml is Codex's skill metadata. for (const entry of await readdir(plugin, { recursive: true, withFileTypes: true })) { diff --git a/tooling/test/e2e-runtime-package.test.ts b/tooling/test/e2e-runtime-package.test.ts index c01b569f..3bcfd460 100644 --- a/tooling/test/e2e-runtime-package.test.ts +++ b/tooling/test/e2e-runtime-package.test.ts @@ -2,7 +2,7 @@ import assert from "node:assert/strict"; import { createHash } from "node:crypto"; import { readFile } from "node:fs/promises"; import test from "node:test"; -import { PANEL_PARTS } from "../host-runtime.mjs"; +import { DOWNLOADED_RUNTIME_PARTS, PANEL_PARTS } from "../host-runtime.mjs"; test("the release metadata pins every bundled e2e runtime dependency", async () => { const root = "packages/runtimes/e2e"; @@ -19,10 +19,11 @@ test("the release metadata pins every bundled e2e runtime dependency", async () } }); -test("the bundled e2e runtime ships notices and is not panel-only", async () => { +test("e2e ships notices and is included in the downloadable runtime", async () => { const notices = await readFile("packages/runtimes/e2e/THIRD_PARTY_NOTICES.txt", "utf8"); assert.ok(notices.length > 10_000); assert.match(notices, /e2e 0\.23\.1/); assert.match(notices, /@ai-sdk\/gateway\/node_modules\/@ai-sdk\/provider 4\.0\.36/); assert.equal(PANEL_PARTS.includes("e2e"), false); + assert.ok(DOWNLOADED_RUNTIME_PARTS.includes("e2e")); }); diff --git a/website/src/content/docs/docs/privacy.md b/website/src/content/docs/docs/privacy.md index 16bc9c4d..ae254de0 100644 --- a/website/src/content/docs/docs/privacy.md +++ b/website/src/content/docs/docs/privacy.md @@ -106,7 +106,7 @@ not a reason to put secrets into your test data. ### Product analytics -Starting with version 0.1.190, release builds send basic product analytics to Anal +Starting with version 0.1.191, release builds send basic product analytics to Anal at `anal.margelo.com` so we can see how many installations use Mobile Dev and which tools they use most. Events record that a host session started or that a tool was called, with the tool's name, whether it succeeded, the host (Codex, Claude,