diff --git a/packages/desktop/README.md b/packages/desktop/README.md index 29f28e86d63..b39db89ea25 100644 --- a/packages/desktop/README.md +++ b/packages/desktop/README.md @@ -69,14 +69,14 @@ Expect zero events for `/usr/bin/codesign`, `/Applications/Harness.app`, and `Ha `Harness.app` carries the Tracker: the compiled Harness CLI at `Contents/Helpers/harness` (the same executable `harness tracker serve` runs, signed with the app's Developer ID and hardened runtime, with the entitlements in `scripts/mac-tracker-entitlements.plist` that Bun's JIT needs) and the `tracker` shim at `Contents/Resources/tracker-shim.sh`. `bun run package:mac --verify` refuses an app without them, with the wrong signature, or whose executable does not report a version. -Installing or replacing the app is the only step. Each packaged launch starts `startBundledTracker` in the background, which: +Installing or replacing the app is the only step. Each packaged launch starts `startBundledTracker` in the background. A launch verifies the installed Tracker revision against the Git history sealed into the signed app, then: 1. Copies the executable and shim to an immutable release at `~/.local/state/tracker/harness-releases//` (content-named, `SHA256SUMS`, `BUILD_COMMIT`), so the running service survives the app being replaced, and keeps the last three releases it staged. 2. Points `~/.local/libexec/harness/harness` and `~/.local/bin/tracker` at that release with atomic link swaps. A regular file at either path is never replaced; the install stops and reports it. 3. Repoints only the executable (`ProgramArguments[0]`) of the existing `local.harness.tracker` LaunchAgent, then reloads it. The `--config` path, role, environment, logs, SQLite journal, secrets and fence files are not touched. If there is no agent but `~/.config/harness/tracker.json` exists, it writes one for that file's role; with no configuration it installs the command line only. 4. Waits for `harness tracker ensure` to report ready. If the new release does not become ready in 30 seconds, it restores the previous executable, links and agent and reports `rolled-back`. -A launch with its own `--user-data-dir` (tests, or a candidate run beside the installed app) skips all of this. A second launch with the same app changes and restarts nothing. Another app instance or an installer already running holds a lock, so two installs never interleave. A LaunchAgent whose command is not `tracker serve` is refused. Rollback of a bad app is the previous release directory plus `launchctl bootout`/`bootstrap` of the previous agent file; the previous app bundle remains the rollback source for the executable. +A launch with its own `--user-data-dir` (tests, or a candidate run beside the installed app) skips all of this. A second launch with the same app changes and restarts nothing. Packaged startup and the [native release installer](#native-release-activation) share the Mac activation lock. A LaunchAgent whose command is not `tracker serve` is refused. Rollback of a bad app is the previous release directory plus `launchctl bootout`/`bootstrap` of the previous agent file; the previous app bundle remains the rollback source for the executable. ## Projects and shared collaboration @@ -211,3 +211,71 @@ The first plugin supports Cloudflare Workers with explicit named environments an ``` Add stage, preprod and prod entries for configured targets. Worker mappings must match an explicit `env..name` in Wrangler and use distinct Worker identities. Pages mappings instead name a `branch` and the Pages project `name`; output comes from `pages_build_output_dir`. The adapter checks the live Pages production branch before upload. Provider credentials are read only in the host, passed only to the adapter subprocess and removed from agent/check subprocess environments. Set the dedicated variables in the desktop host's managed launch environment; do not put tokens in this JSON. A repository needs its normal `check` and `build` scripts and locally installed Wrangler. Receipts live in the Git common directory's `harness-deployments/receipts.json` and are shared across worktrees. Remote phones and hosted read-only projects cannot execute deployment operations. + +## Native release activation + +Build, sign, verify, and stage artifacts before acquiring an activation lock. Run the +approved activation plan through `bun scripts/native-install.ts` from the repository +root on the computer named for each target. Start from the same plan on both Macs. +A plan pins one Git revision, an owner, and the release approval reference. Each +target has a stable ID, an absolute canonical artifact path, the expected code +signature CDHash, and instructions or an artifact location for rollback. + +```text +bun scripts/native-install.ts activate /path/to/release.json primary +bun scripts/native-install.ts activate /path/to/release.json mb2 /path/to/primary.json +bun scripts/native-install.ts activate /path/to/release.json iphone +bun scripts/native-install.ts status /path/to/release.json +``` + +The plan has `id`, `revision`, `owner`, `approval`, `targets`, and optionally +`primaryFirst` set to the primary Mac target ID. Each target has `id`, `kind`, +`computer` (the local Tracker node), `artifact`, `signature`, and `rollback`. +Use a separate ID for each release and each target. Set `primaryFirst` when the +release order requires it. The other targets require that release's exact +primary receipt. On MB2 pass the primary receipt from the completed primary +activation, using the approved host-work path for remote operations. + +- **`mac`** uses a signed `Harness.app` and an `activate` argument array beginning + with the absolute path to the approved bundle replacement script. The script + keeps the previous app, quits Harness normally, swaps the bundle, and returns. + Launch Harness after the command reports installed. App startup takes the same + Mac lock and handles the bundled Tracker separately. Mac readback checks the + installed app's actual code signature and revision and verifies that the + Tracker stayed at the pre-install revision during the bundle swap. +- **`tracker`** uses the staged release directory and an `activate` argument + array for the approved standalone activation script. Preserve the + restart-before-repoint sequence and its health and rollback checks inside the + script. Set `checksums` to the SHA-256 of `SHA256SUMS`; that file must cover + `harness`, `tracker-shim.sh`, and `SOURCE_COMMIT`. For a separately approved + deliberate Tracker rollback, create its own plan and set the target's + `rollbackFrom` to the exact live revision that the approval names. +- **`iphone`** runs on `daniel-primary-mbp` with the paired physical device's + CoreDevice UUID in `device`. Use the signed `.app`, a unique fourteen-digit + build number in `build`. Build the renderer from the clean pinned checkout, then + run `bun scripts/native-install.ts stamp-ios packages/desktop/build` before + running `cap sync ios` from the desktop package. Sync copies the revision stamp + into the web assets that Xcode seals inside the signed app. The installed + build number is read directly from the requested physical iPhone via + `devicectl`. + +Both Mac activation paths share the same lock on that Mac. The primary Mac +holds the distinct lock for the paired iPhone. The release command waits up to +five minutes for an ongoing activation. The kernel releases a lock when +its last holder exits. The lease expiry in the receipt is for diagnosis. A retry +takes the same lock, reads the target again, and reconciles any interrupted +attempt against that observation. Keep the old release artifacts until the +release is verified and its rollback window has closed. + +Receipts are under `~/.local/state/tracker/native-install//.json`. +They record the owner, approval, artifact, expected and previous revisions, +Tracker compatibility floor, lease, rollback, and actual readback. To combine +status across the Macs, copy the receipts into one private directory with the +same release/target layout and pass its root to `status`. A target with no receipt +is pending. A failed or interrupted readback is unconfirmed. An installed receipt +reports what the target returned at its recorded observation time. + +The Mac bundle installer rejects a candidate whose Git history excludes the +active Tracker revision. For rollback of the desktop app, keep a verified +compatible app artifact and follow the approved rollback instructions. Legacy +Mac bundles built before this guard can replace Tracker on launch. diff --git a/packages/desktop/scripts/package-mac-app.ts b/packages/desktop/scripts/package-mac-app.ts index 21f45803e84..d4a36266985 100644 --- a/packages/desktop/scripts/package-mac-app.ts +++ b/packages/desktop/scripts/package-mac-app.ts @@ -31,6 +31,7 @@ async function copyProject(output: string, sources: MacAppSources): Promise { @@ -100,7 +102,16 @@ async function packageRelease(): Promise { try { const bundles = join(staging, 'bundles'); await buildDesktopMain(define, bundles); - await assembleMacApp(candidate, { bundles, renderer: resolve('build'), revision }); + const ancestry = execFileSync('git', ['rev-list', revision], { + encoding: 'utf8', + maxBuffer: 16 * 1024 * 1024 + }); + await assembleMacApp(candidate, { + bundles, + renderer: resolve('build'), + revision, + trackerAncestors: ancestry.trim().split('\n').slice(1) + }); const { sign } = await import('@electron/osx-sign'); await sign({ app: candidate, diff --git a/packages/desktop/src/services/development-tooling/tracker-bundle/TrackerBundleService.types.ts b/packages/desktop/src/services/development-tooling/tracker-bundle/TrackerBundleService.types.ts index dcc1371804d..3c4fc92ff2c 100644 --- a/packages/desktop/src/services/development-tooling/tracker-bundle/TrackerBundleService.types.ts +++ b/packages/desktop/src/services/development-tooling/tracker-bundle/TrackerBundleService.types.ts @@ -5,6 +5,8 @@ export interface TrackerBundleHost { run(file: string, args: string[], env?: Record): Promise; /** The user id whose launchd domain owns the service. */ uid: number; + /** For a packaged launch, identify the executable launchd is actually using. */ + activeExecutable?(): Promise; sleep(milliseconds: number): Promise; } @@ -18,6 +20,8 @@ export interface TrackerBundleInput { app: string; /** The full git commit the app was built from. */ revision: string; + /** Git ancestors sealed into the signed app manifest. */ + ancestors?: readonly string[]; home: string; host: TrackerBundleHost; /** How many one-second readiness checks to allow after a restart. */ diff --git a/packages/desktop/src/services/development-tooling/tracker-bundle/installBundledTracker.ts b/packages/desktop/src/services/development-tooling/tracker-bundle/installBundledTracker.ts index 05568e54b5d..cdd9a8e94fe 100644 --- a/packages/desktop/src/services/development-tooling/tracker-bundle/installBundledTracker.ts +++ b/packages/desktop/src/services/development-tooling/tracker-bundle/installBundledTracker.ts @@ -8,7 +8,9 @@ import type { TrackerBundleLayout } from './trackerBundleLayout.types'; import type { ReleaseLink } from './trackerSessionLinks.types'; import { stageTrackerRelease } from './stageTrackerRelease'; import { inspectLink, replaceSymlink } from './replaceSymlink'; -import { recordRelease, withLock } from './trackerBundleRecord'; +import { recordRelease } from './trackerBundleRecord'; +import { withNativeActivationLock } from './nativeActivationLock'; +import { trackerFloorRefusal } from './trackerRevisionFloor'; import { activateService, serviceConfig } from './activateTrackerService'; import { trackerSessionLinks } from './trackerSessionLinks'; import { isTrackerServe, readAgentProgram } from './trackerLaunchAgent'; @@ -39,8 +41,12 @@ export async function installBundledTracker( if (!(await present(files.executable)) || !(await present(files.shim))) return { status: 'not-bundled' }; const layout = trackerBundleLayout(input.home); - const outcome = await withLock(layout.lock, () => apply(input, layout, files)); - return outcome ?? { status: 'refused', reason: 'Another Tracker install is running.' }; + const outcome = await withNativeActivationLock( + layout.lock, + () => apply(input, layout, files), + 10 + ); + return outcome ?? { status: 'refused', reason: 'Another native install is running on this Mac.' }; } /** Points each link into the release and returns what it held, for a rollback. */ @@ -52,16 +58,32 @@ async function repointLinks(links: ReleaseLink[], release: string) { return before; } +async function bundleRefusal( + input: TrackerBundleInput, + layout: TrackerBundleLayout, + program: string[] | null +): Promise { + if (program !== null && !isTrackerServe(program)) + return 'The Tracker LaunchAgent is not a Tracker service.'; + const foreign = await foreignEntry(layout); + if (foreign) return `${foreign} is not a link this app owns.`; + const active = await input.host.activeExecutable?.(); + if (active && !(await present(active))) return 'The loaded Tracker executable is missing.'; + return trackerFloorRefusal( + [...(program ? [program[0]] : []), ...(active ? [active] : []), layout.launcher], + input.revision, + input.ancestors + ); +} + async function apply( input: TrackerBundleInput, layout: TrackerBundleLayout, files: ReturnType ): Promise { const program = await readAgentProgram(layout.agent, input.host); - if (program !== null && !isTrackerServe(program)) - return { status: 'refused', reason: 'The Tracker LaunchAgent is not a Tracker service.' }; - const foreign = await foreignEntry(layout); - if (foreign) return { status: 'refused', reason: `${foreign} is not a link this app owns.` }; + const refusal = await bundleRefusal(input, layout, program); + if (refusal) return { status: 'refused', reason: refusal }; const staged = await stageTrackerRelease(files, layout.releases, input.revision); const executable = join(staged.directory, 'harness'); // Every link moves before the service restarts, so it never starts beside an older one. diff --git a/packages/desktop/src/services/development-tooling/tracker-bundle/nativeActivationLock.ts b/packages/desktop/src/services/development-tooling/tracker-bundle/nativeActivationLock.ts new file mode 100644 index 00000000000..05fd917083f --- /dev/null +++ b/packages/desktop/src/services/development-tooling/tracker-bundle/nativeActivationLock.ts @@ -0,0 +1,33 @@ +// @harness-uid u_tqudg6lphc +import { spawn } from 'node:child_process'; +import { mkdir, open } from 'node:fs/promises'; +import { dirname } from 'node:path'; +import { TrackerBundleError } from './TrackerBundleError'; + +function claim(fd: number, wait: number): Promise { + return new Promise((resolve, reject) => { + const process = spawn('/usr/bin/lockf', ['-s', '-t', String(wait), '3'], { + stdio: ['ignore', 'ignore', 'ignore', fd] + }); + process.once('error', reject); + process.once('exit', resolve); + }); +} + +/** The descriptor owns the lock. Keep its inode even when the installer exits or crashes. */ +export async function withNativeActivationLock( + file: string, + work: (descriptor: number) => Promise, + wait = 0 +): Promise { + await mkdir(dirname(file), { recursive: true, mode: 0o700 }); + const handle = await open(file, 'a', 0o600); + try { + const status = await claim(handle.fd, wait); + if (status === 75) return null; + if (status !== 0) throw new TrackerBundleError('Could not lock native device activation.'); + return await work(handle.fd); + } finally { + await handle.close(); + } +} diff --git a/packages/desktop/src/services/development-tooling/tracker-bundle/stageTrackerRelease.ts b/packages/desktop/src/services/development-tooling/tracker-bundle/stageTrackerRelease.ts index 53fa812728c..6426cd3accd 100644 --- a/packages/desktop/src/services/development-tooling/tracker-bundle/stageTrackerRelease.ts +++ b/packages/desktop/src/services/development-tooling/tracker-bundle/stageTrackerRelease.ts @@ -20,6 +20,17 @@ async function readIfPresent(file: string): Promise { } } +async function existingRelease( + directory: string, + revision: string, + sums: string +): Promise { + return ( + (await readIfPresent(join(directory, 'SHA256SUMS'))) === sums && + (await readIfPresent(join(directory, 'SOURCE_COMMIT')))?.trim() === revision + ); +} + /** * Copies the bundled executable and shim to an immutable, content-named release directory * outside the app, so a running service survives the app being replaced. An existing release @@ -31,10 +42,16 @@ export async function stageTrackerRelease( revision: string ): Promise { const [executable, shim] = await Promise.all([sha256(files.executable), sha256(files.shim)]); - const id = createHash('sha256').update(`${executable}:${shim}`).digest('hex').slice(0, 10); - const directory = join(releases, id); const sums = `${executable} harness\n${shim} tracker-shim.sh\n`; - if ((await readIfPresent(join(directory, 'SHA256SUMS'))) === sums) return { id, directory }; + const legacy = createHash('sha256').update(`${executable}:${shim}`).digest('hex').slice(0, 10); + if (await existingRelease(join(releases, legacy), revision, sums)) + return { id: legacy, directory: join(releases, legacy) }; + const id = createHash('sha256') + .update(`${revision}:${executable}:${shim}`) + .digest('hex') + .slice(0, 10); + const directory = join(releases, id); + if (await existingRelease(directory, revision, sums)) return { id, directory }; await mkdir(releases, { recursive: true, mode: 0o700 }); const staging = await mkdtemp(join(releases, `.stage-${id}-`)); try { @@ -47,7 +64,6 @@ export async function stageTrackerRelease( await writeFile(join(staging, 'SHA256SUMS'), sums, { mode: 0o600 }); if ((await sha256(join(staging, 'harness'))) !== executable) throw new TrackerBundleError('The staged Tracker executable does not match the bundle.'); - await rm(directory, { recursive: true, force: true }); await rename(staging, directory); } finally { await rm(staging, { recursive: true, force: true }); diff --git a/packages/desktop/src/services/development-tooling/tracker-bundle/startBundledTracker.ts b/packages/desktop/src/services/development-tooling/tracker-bundle/startBundledTracker.ts index 9664dba85ff..c05dd38a0f2 100644 --- a/packages/desktop/src/services/development-tooling/tracker-bundle/startBundledTracker.ts +++ b/packages/desktop/src/services/development-tooling/tracker-bundle/startBundledTracker.ts @@ -4,10 +4,13 @@ import { readFile } from 'node:fs/promises'; import { join, resolve } from 'node:path'; import type { TrackerBundleHost, TrackerBundleOutcome } from './TrackerBundleService.types'; import { installBundledTracker } from './installBundledTracker'; +import { isTrackerRevision } from './trackerRevisionFloor'; +import { trackerLabel } from './trackerBundleLayout'; +import { TrackerBundleError } from './TrackerBundleError'; /** Runs programs for real, never through a shell, and reports their exit status. */ export function systemTrackerHost(): TrackerBundleHost { - return { + const host: TrackerBundleHost = { uid: process.getuid?.() ?? 0, sleep: (milliseconds) => new Promise((done) => setTimeout(done, milliseconds)), run: (file, args, env) => @@ -23,6 +26,15 @@ export function systemTrackerHost(): TrackerBundleHost { ); }) }; + host.activeExecutable = async () => { + const result = await host.run('/bin/launchctl', ['print', `gui/${host.uid}/${trackerLabel}`]); + if (result.status === 113) return null; + const executable = /^\s*program = (.+)$/m.exec(result.stdout)?.[1]?.trim(); + if (result.status !== 0 || !executable) + throw new TrackerBundleError('Could not read the loaded Tracker launch program.'); + return executable; + }; + return host; } /** @@ -37,7 +49,13 @@ export async function startBundledTracker( ): Promise { const manifest = JSON.parse(await readFile(join(appPath, 'package.json'), 'utf8')); const revision: unknown = manifest.revision; - if (typeof revision !== 'string' || !/^[0-9a-f]{40}$/.test(revision)) - return { status: 'not-bundled' }; - return installBundledTracker({ app: resolve(appPath, '../../..'), revision, home, host }); + if (!isTrackerRevision(revision)) return { status: 'not-bundled' }; + const ancestors: unknown = manifest.trackerAncestors; + return installBundledTracker({ + app: resolve(appPath, '../../..'), + revision, + ancestors: Array.isArray(ancestors) ? ancestors.filter(isTrackerRevision) : [], + home, + host + }); } diff --git a/packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleLayout.ts b/packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleLayout.ts index d75c797b3e1..b232bb19958 100644 --- a/packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleLayout.ts +++ b/packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleLayout.ts @@ -9,7 +9,7 @@ export function trackerBundleLayout(home: string) { return { releases: join(state, 'harness-releases'), record: join(state, 'tracker-bundle.json'), - lock: join(state, 'tracker-bundle.lock'), + lock: join(state, 'native-install', 'mac.lock'), launcher: join(home, '.local/libexec/harness/harness'), entry: join(home, '.local/bin/tracker'), agent: join(home, 'Library/LaunchAgents', `${trackerLabel}.plist`), diff --git a/packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleRecord.ts b/packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleRecord.ts index f67bb9f739d..cab4d91febc 100644 --- a/packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleRecord.ts +++ b/packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleRecord.ts @@ -1,9 +1,8 @@ // @harness-uid u_tb5vh2cjta -import { mkdir, open, readFile, rename, rm, stat, writeFile } from 'node:fs/promises'; +import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'; import { dirname, join } from 'node:path'; import type { TrackerBundleRecord } from './TrackerBundleService.types'; -const staleLock = 10 * 60 * 1000; const keptReleases = 3; export async function readRecord(file: string): Promise { @@ -44,22 +43,3 @@ export async function recordRelease( await writeRecord(input.file, next); return next; } - -/** One installer at a time; a lock older than ten minutes belongs to a dead process. */ -export async function withLock(file: string, work: () => Promise): Promise { - await mkdir(dirname(file), { recursive: true, mode: 0o700 }); - const acquire = async () => (await open(file, 'wx', 0o600)).close(); - try { - await acquire(); - } catch { - const age = Date.now() - (await stat(file).catch(() => ({ mtimeMs: 0 }))).mtimeMs; - if (age < staleLock) return null; - await rm(file, { force: true }); - await acquire().catch(() => null); - } - try { - return await work(); - } finally { - await rm(file, { force: true }); - } -} diff --git a/packages/desktop/src/services/development-tooling/tracker-bundle/trackerRevisionFloor.ts b/packages/desktop/src/services/development-tooling/tracker-bundle/trackerRevisionFloor.ts new file mode 100644 index 00000000000..f0ee87cf7e2 --- /dev/null +++ b/packages/desktop/src/services/development-tooling/tracker-bundle/trackerRevisionFloor.ts @@ -0,0 +1,44 @@ +// @harness-uid u_o7wjd42x5c +import { readFile, realpath } from 'node:fs/promises'; +import { dirname, join } from 'node:path'; + +export function isTrackerRevision(value: unknown): value is string { + return typeof value === 'string' && /^[0-9a-f]{40}$/.test(value); +} + +/** Missing executables do not set a floor. Existing executables need a recorded source commit. */ +export async function trackerSourceRevision( + executable: string +): Promise { + let resolved: string; + try { + resolved = await realpath(executable); + } catch (error) { + if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined; + throw error; + } + let revision: string; + try { + revision = (await readFile(join(dirname(resolved), 'SOURCE_COMMIT'), 'utf8')).trim(); + } catch (error) { + if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null; + throw error; + } + return isTrackerRevision(revision) ? revision : null; +} + +/** A release can replace Tracker only if it contains every installed source revision. */ +export async function trackerFloorRefusal( + executables: readonly string[], + revision: string, + ancestors: readonly string[] = [] +): Promise { + const compatible = new Set([revision, ...ancestors]); + for (const executable of new Set(executables)) { + const installed = await trackerSourceRevision(executable); + if (installed === null) return 'The installed Tracker source revision could not be verified.'; + if (installed !== undefined && !compatible.has(installed)) + return `The candidate does not contain installed Tracker revision ${installed}.`; + } + return null; +} diff --git a/packages/desktop/test/tracker-bundle.test.ts b/packages/desktop/test/tracker-bundle.test.ts index b39293e1777..05218fd7e74 100644 --- a/packages/desktop/test/tracker-bundle.test.ts +++ b/packages/desktop/test/tracker-bundle.test.ts @@ -7,6 +7,7 @@ import { readFileSync, readlinkSync, rmSync, + symlinkSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; @@ -92,8 +93,8 @@ darwin( } ); -darwin('running the same app again changes nothing and does not restart the service', async () => { - const { app, home } = fixture(); +darwin('app startup leaves the current or newer standalone Tracker running', async () => { + const { app, home, layout } = fixture(); writeTrackerConfig(home, 'hub'); const launchd = fakeLaunchd(); await installBundledTracker({ app, revision, home, host: launchd.host }); @@ -101,6 +102,21 @@ darwin('running the same app again changes nothing and does not restart the serv const again = await installBundledTracker({ app, revision, home, host: launchd.host }); expect(again.status).toBe('current'); expect(launchd.calls).toEqual(['print']); + + const standalone = join(layout.releases, 'standalone', 'harness'); + mkdirSync(join(standalone, '..')); + writeFileSync(standalone, '#!/bin/sh\n'); + writeFileSync(join(standalone, '..', 'SOURCE_COMMIT'), `${'b'.repeat(40)}\n`); + existingAgent(home, standalone); + rmSync(layout.launcher); + symlinkSync(standalone, layout.launcher); + launchd.calls.length = 0; + + const stale = await installBundledTracker({ app, revision, home, host: launchd.host }); + expect((agentJson(layout.agent).ProgramArguments as string[])[0]).toBe(standalone); + expect(readlinkSync(layout.launcher)).toBe(standalone); + expect(stale.status).toBe('refused'); + expect(launchd.calls).toEqual([]); }); darwin('a release that never becomes ready is replaced by the one that was running', async () => { diff --git a/scripts/native-install.ts b/scripts/native-install.ts new file mode 100644 index 00000000000..fac883d7c74 --- /dev/null +++ b/scripts/native-install.ts @@ -0,0 +1,52 @@ +// @harness-uid u_wu7fdvimla +import { NativeInstallError } from './native-install/NativeInstallError'; +import { readFile } from 'node:fs/promises'; +import { homedir } from 'node:os'; +import { activateNativeTarget } from './native-install/activateNativeTarget'; +import { stampIphoneRenderer } from './native-install/nativeInstallArtifacts'; +import { + nativeInstallEffects, + nativeInstallRoot, + requireLocalComputer +} from './native-install/nativeInstallEffects'; +import { nativeInstallPlan } from './native-install/nativeInstallPlan'; +import { + nativeInstallStatus, + requirePrimaryInstalled +} from './native-install/nativeInstallReceipt'; +import { runNativeInstallCommand } from './native-install/runNativeInstallCommand'; + +async function main() { + const [action, file, targetId, proof, ...extra] = process.argv.slice(2); + if (action === 'stamp-ios' && file && !targetId) { + await stampIphoneRenderer(file); + return; + } + if (!file || extra.length || (action !== 'status' && (action !== 'activate' || !targetId))) + throw new NativeInstallError( + 'Usage: bun scripts/native-install.ts status PLAN [RECEIPT_ROOT] | activate PLAN TARGET [PRIMARY_RECEIPT] | stamp-ios BUILD_DIRECTORY' + ); + const plan = nativeInstallPlan.parse(JSON.parse(await readFile(file, 'utf8'))); + const home = homedir(); + const root = nativeInstallRoot(home); + if (action === 'status') { + if (proof) throw new NativeInstallError('Status accepts one optional receipt root.'); + const status = await Promise.all( + plan.targets.map((target) => nativeInstallStatus(targetId ?? root, plan, target)) + ); + console.log(JSON.stringify(status, null, 2)); + return; + } + const target = plan.targets.find(({ id }) => id === targetId); + if (!target) throw new NativeInstallError('This release does not have the requested target.'); + await requireLocalComputer(target, home, runNativeInstallCommand); + if (targetId !== plan.primaryFirst) await requirePrimaryInstalled(plan, root, proof); + const effects = nativeInstallEffects(plan, target, home, runNativeInstallCommand); + const receipt = await activateNativeTarget(root, plan, target, effects); + console.log(JSON.stringify(receipt, null, 2)); +} + +void main().catch((error: unknown) => { + console.error(error instanceof Error ? error.message : 'Native install failed.'); + process.exitCode = 1; +}); diff --git a/scripts/native-install/NativeInstallError.ts b/scripts/native-install/NativeInstallError.ts new file mode 100644 index 00000000000..e89cddcc456 --- /dev/null +++ b/scripts/native-install/NativeInstallError.ts @@ -0,0 +1,5 @@ +// @harness-uid u_nyxchio63x +/** Native activation could not proceed or its installed state could not be confirmed. */ +export class NativeInstallError extends Error { + override name = 'NativeInstallError'; +} diff --git a/scripts/native-install/activateNativeTarget.ts b/scripts/native-install/activateNativeTarget.ts new file mode 100644 index 00000000000..54bb7e17b51 --- /dev/null +++ b/scripts/native-install/activateNativeTarget.ts @@ -0,0 +1,142 @@ +// @harness-uid u_4vh4l462o2 +import { NativeInstallError } from './NativeInstallError'; +import { join } from 'node:path'; +import { withNativeActivationLock } from '../../packages/desktop/src/services/development-tooling/tracker-bundle/nativeActivationLock'; +import { + iphoneBuildReceipt, + matchesReadback, + readNativeReceipt, + receiptMatchesTarget, + receiptPath, + saveNativeReceipt +} from './nativeInstallReceipt'; +import type { + NativeInstallEffects, + NativeInstallPlan, + NativeInstallReceipt, + NativeInstallTarget, + NativeReadback +} from './nativeInstallPlan.types'; + +function activationRecord( + plan: NativeInstallPlan, + target: NativeInstallTarget, + previous: NativeReadback, + old: NativeInstallReceipt | null +): NativeInstallReceipt { + const startedAt = new Date(); + return { + release: plan.id, + target: target.id, + computer: target.computer, + kind: target.kind, + device: target.kind === 'iphone' ? target.device : undefined, + owner: plan.owner, + approval: plan.approval, + artifact: target.artifact, + signature: target.signature, + revision: plan.revision, + rollback: target.rollback, + previous: old?.previous ?? previous, + trackerFloor: target.kind === 'tracker' ? previous.revision : (previous.tracker ?? null), + startedAt: startedAt.toISOString(), + leaseExpiresAt: new Date(+startedAt + 10 * 60_000).toISOString(), + status: 'activating', + interrupted: + old?.status === 'activating' ? { status: old.status, observed: previous } : old?.interrupted + }; +} + +async function observeActivation( + file: string, + receipt: NativeInstallReceipt, + operation: () => Promise, + matches: (value: NativeReadback) => boolean +) { + try { + const actual = await operation(); + const status = matches(actual) ? 'installed' : 'unconfirmed'; + const observed = { ...receipt, actual, status, observedAt: new Date().toISOString() } as const; + await saveNativeReceipt(file, observed); + if (status === 'unconfirmed') + throw new NativeInstallError('The target did not report the expected signed revision.'); + return observed; + } catch (error) { + const current = await readNativeReceipt(file); + if (current?.status === 'activating') + await saveNativeReceipt(file, { ...receipt, status: 'unconfirmed' }); + throw error; + } +} + +async function resolveIphoneBuild( + root: string, + target: NativeInstallTarget, + plan: NativeInstallPlan, + before: NativeReadback +) { + if (target.kind !== 'iphone') return { previous: before, index: null, known: false }; + const index = iphoneBuildReceipt(root, target.device, target.build); + const pinned = await readNativeReceipt(index); + if (pinned && !matchesReadback(plan, target, pinned.actual ?? { revision: null })) + throw new NativeInstallError( + 'This iPhone build number already belongs to a different source revision.' + ); + if (pinned && pinned.signature !== target.signature) + throw new NativeInstallError( + 'This iPhone build number already belongs to a different signed artifact.' + ); + const priorBuild = before.build + ? await readNativeReceipt(iphoneBuildReceipt(root, target.device, before.build)) + : null; + const previous = { ...before, revision: priorBuild?.actual?.revision ?? null }; + return { previous, index, known: pinned !== null }; +} + +export async function activateNativeTarget( + root: string, + plan: NativeInstallPlan, + target: NativeInstallTarget, + effects: NativeInstallEffects +) { + const key = target.kind === 'iphone' ? `iphone-${target.device}` : 'mac'; + const file = receiptPath(root, plan, target); + const result = await withNativeActivationLock( + join(root, `${key}.lock`), + async (descriptor) => { + const old = await readNativeReceipt(file); + if (old && !receiptMatchesTarget(plan, target, old)) + throw new NativeInstallError('This release target already records a different artifact.'); + const before = await effects.read(); + const { previous, index, known } = await resolveIphoneBuild(root, target, plan, before); + const receipt = activationRecord(plan, target, previous, old); + const matches = (observed: NativeReadback) => + matchesReadback(plan, target, observed) && + (target.kind !== 'mac' || observed.tracker === receipt.trackerFloor); + await effects.verify(before); + await saveNativeReceipt(file, receipt); + const confirmed = await observeActivation( + file, + receipt, + async () => { + const canReuseIphone = + known || + old?.status === 'installed' || + (old?.status === 'activating' && old.previous.build !== before.build); + if (matches(before) && (!index || canReuseIphone)) return before; + await effects.activate(descriptor); + return effects.read(); + }, + matches + ); + if (index) await saveNativeReceipt(index, confirmed); + return confirmed; + }, + effects.waitSeconds + ); + if (!result) + throw new NativeInstallError( + 'Another activation is in progress on this device. Try again after it finishes.' + ); + return result; +} diff --git a/scripts/native-install/nativeInstallArtifacts.ts b/scripts/native-install/nativeInstallArtifacts.ts new file mode 100644 index 00000000000..22ad3fcbf29 --- /dev/null +++ b/scripts/native-install/nativeInstallArtifacts.ts @@ -0,0 +1,119 @@ +// @harness-uid u_hipgrr74v5 +import { NativeInstallError } from './NativeInstallError'; +import { createHash } from 'node:crypto'; +import { createReadStream } from 'node:fs'; +import { readFile, realpath, writeFile } from 'node:fs/promises'; +import { join } from 'node:path'; +import { releaseRevision } from '../../packages/desktop/scripts/release-revision'; +import { isTrackerRevision } from '../../packages/desktop/src/services/development-tooling/tracker-bundle/trackerRevisionFloor'; +import type { + NativeInstallCommand, + NativeInstallPlan, + NativeInstallTarget +} from './nativeInstallPlan.types'; + +export async function macManifest(app: string) { + const file = join(app, 'Contents/Resources/app/package.json'); + const manifest: { revision?: unknown; trackerAncestors?: unknown } = JSON.parse( + await readFile(file, 'utf8') + ); + if (!isTrackerRevision(manifest.revision)) + throw new NativeInstallError('Mac app revision is unavailable.'); + const ancestors = manifest.trackerAncestors; + return { + revision: manifest.revision, + ancestors: Array.isArray(ancestors) && ancestors.every(isTrackerRevision) ? ancestors : null + }; +} + +export async function signedIdentity(path: string, run: NativeInstallCommand, deep = false) { + await run('/usr/bin/codesign', ['--verify', '--strict', ...(deep ? ['--deep'] : []), path]); + const { stderr } = await run('/usr/bin/codesign', ['-d', '--verbose=4', path]); + const signature = /^CDHash=([0-9a-f]{40})$/m.exec(stderr)?.[1]; + if (!signature) throw new NativeInstallError('The artifact has no readable code signature.'); + return signature; +} + +async function verifyIphoneArtifact( + target: Extract, + revision: string, + run: NativeInstallCommand +) { + const { stdout } = await run('/usr/bin/plutil', [ + '-convert', + 'json', + '-o', + '-', + join(target.artifact, 'Info.plist') + ]); + const plist = JSON.parse(stdout); + const stamp = JSON.parse( + await readFile(join(target.artifact, 'public/native-release.json'), 'utf8') + ); + if ( + plist.CFBundleIdentifier !== 'com.dafuga.harness' || + plist.CFBundleVersion !== target.build || + stamp.revision !== revision + ) + throw new NativeInstallError( + 'The signed iPhone app does not match the requested bundle, revision and build.' + ); +} + +async function hash(path: string): Promise { + const digest = createHash('sha256'); + for await (const chunk of createReadStream(path)) digest.update(chunk); + return digest.digest('hex'); +} + +async function verifyTrackerChecksums( + target: Extract +): Promise { + const file = join(target.artifact, 'SHA256SUMS'); + const sums = await readFile(file); + if (createHash('sha256').update(sums).digest('hex') !== target.checksums) + throw new NativeInstallError('The staged Tracker checksum manifest changed.'); + const lines = sums.toString('utf8').trimEnd().split('\n'); + for (const name of ['harness', 'tracker-shim.sh', 'SOURCE_COMMIT']) { + const digest = await hash(join(target.artifact, name)); + if (!lines.includes(`${digest} ${name}`) && !lines.includes(`${digest} *${name}`)) + throw new NativeInstallError(`Tracker checksum mismatch for ${name}.`); + } +} + +export async function verifyNativeArtifact( + plan: NativeInstallPlan, + target: NativeInstallTarget, + run: NativeInstallCommand +): Promise { + if ((await realpath(target.artifact)) !== target.artifact) + throw new NativeInstallError('Use the canonical path to the staged artifact.'); + if (target.kind === 'tracker') { + const executable = join(target.artifact, 'harness'); + if ((await signedIdentity(executable, run)) !== target.signature) + throw new NativeInstallError('Tracker signature changed.'); + await verifyTrackerChecksums(target); + if ((await readFile(join(target.artifact, 'SOURCE_COMMIT'), 'utf8')).trim() !== plan.revision) + throw new NativeInstallError('Tracker source pin does not match the requested revision.'); + return []; + } + if ((await signedIdentity(target.artifact, run, true)) !== target.signature) + throw new NativeInstallError('Native app signature changed.'); + if (target.kind === 'iphone') { + await verifyIphoneArtifact(target, plan.revision, run); + return []; + } + const manifest = await macManifest(target.artifact); + if (manifest.revision !== plan.revision || !manifest.ancestors) + throw new NativeInstallError( + 'Mac candidate is missing its signed Tracker ancestry or has the wrong revision.' + ); + return manifest.ancestors; +} + +/** Stamps the already-built Capacitor web assets before they are copied into the signed app. */ +export async function stampIphoneRenderer(renderer: string): Promise { + await realpath(join(renderer, 'index.html')); + const revision = releaseRevision(); + await writeFile(join(renderer, 'native-release.json'), `${JSON.stringify({ revision })}\n`); +} diff --git a/scripts/native-install/nativeInstallEffects.ts b/scripts/native-install/nativeInstallEffects.ts new file mode 100644 index 00000000000..ceb9d767061 --- /dev/null +++ b/scripts/native-install/nativeInstallEffects.ts @@ -0,0 +1,109 @@ +// @harness-uid u_m3j5pldz4r +import { NativeInstallError } from './NativeInstallError'; +import { dirname } from 'node:path'; +import { trackerBundleLayout } from '../../packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleLayout'; +import { verifyNativeArtifact } from './nativeInstallArtifacts'; +import { readNativeTarget } from './nativeInstallReadback'; +import type { + NativeInstallCommand, + NativeInstallEffects, + NativeInstallPlan, + NativeInstallTarget, + NativeReadback +} from './nativeInstallPlan.types'; + +async function protectTracker( + plan: NativeInstallPlan, + target: NativeInstallTarget, + prior: NativeReadback, + context: { ancestors: readonly string[]; run: NativeInstallCommand } +): Promise { + if ( + target.kind === 'mac' && + prior.tracker && + prior.tracker !== plan.revision && + !context.ancestors.includes(prior.tracker) + ) + throw new NativeInstallError( + `The Mac candidate does not contain installed Tracker revision ${prior.tracker}.` + ); + if (target.kind !== 'tracker' || prior.revision === plan.revision) return; + if (target.rollbackFrom) { + if (prior.revision !== target.rollbackFrom) + throw new NativeInstallError('The approved rollback baseline changed.'); + await context.run('/usr/bin/git', [ + 'merge-base', + '--is-ancestor', + plan.revision, + prior.revision + ]); + } else if (prior.revision) { + await context.run('/usr/bin/git', [ + 'merge-base', + '--is-ancestor', + prior.revision, + plan.revision + ]); + } +} + +export function nativeInstallEffects( + plan: NativeInstallPlan, + target: NativeInstallTarget, + home: string, + run: NativeInstallCommand +): NativeInstallEffects { + return { + waitSeconds: 5 * 60, + read: () => readNativeTarget(plan, target, home, run), + verify: async (previous) => { + const ancestors = await verifyNativeArtifact(plan, target, run); + if ( + target.kind === 'iphone' && + previous.build && + BigInt(previous.build) > BigInt(target.build) + ) + throw new NativeInstallError('The physical iPhone already carries a newer build.'); + await protectTracker(plan, target, previous, { ancestors, run }); + }, + activate: async (descriptor) => { + if (target.kind === 'iphone') { + await run( + '/usr/bin/xcrun', + [ + 'devicectl', + 'device', + 'install', + 'app', + '--device', + target.device, + '--timeout', + '180', + target.artifact + ], + descriptor + ); + return; + } + const [program, ...args] = target.activate; + await run(program, args, descriptor); + } + }; +} + +export async function requireLocalComputer( + target: NativeInstallTarget, + home: string, + run: NativeInstallCommand +): Promise { + const { stdout } = await run(trackerBundleLayout(home).entry, ['status']); + const node: unknown = JSON.parse(stdout).node; + if (node !== target.computer || (target.kind === 'iphone' && node !== 'daniel-primary-mbp')) + throw new NativeInstallError( + 'Run this on the declared release computer. Physical iPhone activation uses the primary Mac.' + ); +} + +export function nativeInstallRoot(home: string) { + return dirname(trackerBundleLayout(home).lock); +} diff --git a/scripts/native-install/nativeInstallPlan.ts b/scripts/native-install/nativeInstallPlan.ts new file mode 100644 index 00000000000..af480b3e22a --- /dev/null +++ b/scripts/native-install/nativeInstallPlan.ts @@ -0,0 +1,57 @@ +// @harness-uid u_yo34lp5jui +import { z } from 'zod'; + +const name = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,95}$/); +const sha = z.string().regex(/^[0-9a-f]{40}$/); +const fields = { + id: name, + computer: name, + artifact: z.string().startsWith('/'), + signature: sha, + rollback: z.string().min(1) +}; +const command = z.tuple([z.string().startsWith('/')]).rest(z.string()); +const target = z.discriminatedUnion('kind', [ + z.object({ ...fields, kind: z.literal('mac'), activate: command }), + z.object({ + ...fields, + kind: z.literal('tracker'), + activate: command, + checksums: z.string().regex(/^[0-9a-f]{64}$/), + rollbackFrom: sha.optional() + }), + z.object({ + ...fields, + kind: z.literal('iphone'), + computer: z.literal('daniel-primary-mbp'), + device: z + .string() + .uuid() + .transform((value) => value.toLowerCase()), + build: z.string().regex(/^\d{14}$/) + }) +]); + +export const nativeInstallPlan = z + .object({ + id: name, + revision: sha, + owner: z.string().trim().min(1), + approval: z.string().trim().min(1), + primaryFirst: name.optional(), + targets: z.array(target).min(1) + }) + .refine((plan) => new Set(plan.targets.map(({ id }) => id)).size === plan.targets.length, { + message: 'Target IDs must be unique.' + }) + .refine( + (plan) => + !plan.primaryFirst || + plan.targets.some( + (target) => + target.id === plan.primaryFirst && + target.computer === 'daniel-primary-mbp' && + target.kind !== 'iphone' + ), + { message: 'The first target must be a primary Mac activation.' } + ); diff --git a/scripts/native-install/nativeInstallPlan.types.ts b/scripts/native-install/nativeInstallPlan.types.ts new file mode 100644 index 00000000000..46ad87783ca --- /dev/null +++ b/scripts/native-install/nativeInstallPlan.types.ts @@ -0,0 +1,54 @@ +// @harness-uid u_yo34lp5jui +import type { z } from 'zod'; +import type { nativeInstallPlan } from './nativeInstallPlan'; + +export type NativeInstallPlan = z.infer; +export type NativeInstallTarget = NativeInstallPlan['targets'][number]; + +export interface NativeReadback { + revision: string | null; + signature?: string; + tracker?: string | null; + build?: string; +} + +export interface NativeInstallReceipt { + release: string; + target: string; + computer: string; + kind: NativeInstallTarget['kind']; + device?: string; + owner: string; + approval: string; + artifact: string; + signature: string; + revision: string; + rollback: string; + previous: NativeReadback; + trackerFloor: string | null; + startedAt: string; + leaseExpiresAt: string; + status: 'activating' | 'installed' | 'unconfirmed'; + observedAt?: string; + actual?: NativeReadback; + interrupted?: { status: NativeInstallReceipt['status']; observed: NativeReadback }; +} + +export type NativeInstallCommand = ( + executable: string, + args: string[], + descriptor?: number +) => Promise; + +export interface NativeInstallCommandResult { + stdout: string; + stderr: string; +} + +export interface NativeInstallEffects { + /** Seconds an operator can wait for another activation before retrying. */ + waitSeconds?: number; + read(): Promise; + verify(previous: NativeReadback): Promise; + activate(descriptor: number): Promise; +} diff --git a/scripts/native-install/nativeInstallReadback.ts b/scripts/native-install/nativeInstallReadback.ts new file mode 100644 index 00000000000..d1bb740acf9 --- /dev/null +++ b/scripts/native-install/nativeInstallReadback.ts @@ -0,0 +1,120 @@ +// @harness-uid u_hpvdiqfxlv +import { NativeInstallError } from './NativeInstallError'; +import { lstat, mkdtemp, readFile, realpath, rm } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { + trackerBundleLayout, + trackerLabel +} from '../../packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleLayout'; +import { trackerSourceRevision } from '../../packages/desktop/src/services/development-tooling/tracker-bundle/trackerRevisionFloor'; +import { macManifest, signedIdentity } from './nativeInstallArtifacts'; +import type { + NativeInstallCommand, + NativeInstallPlan, + NativeInstallTarget, + NativeReadback +} from './nativeInstallPlan.types'; + +export const installedMacApp = '/Applications/Harness.app'; +const iphoneBundle = 'com.dafuga.harness'; + +async function exists(path: string): Promise { + try { + await lstat(path); + return true; + } catch (error) { + if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false; + throw error; + } +} + +/** A configured agent needs a running process and matching executable, config and CLI link. */ +async function trackerReadback(home: string, run: NativeInstallCommand): Promise { + const layout = trackerBundleLayout(home); + if (!(await exists(layout.agent))) { + if (await exists(layout.launcher)) + throw new NativeInstallError('Tracker CLI exists without a service readback.'); + return { revision: null }; + } + const { stdout: configured } = await run('/usr/bin/plutil', [ + '-extract', + 'ProgramArguments.0', + 'raw', + '-o', + '-', + layout.agent + ]); + const { stdout: live } = await run('/bin/launchctl', [ + 'print', + `gui/${process.getuid?.()}/${trackerLabel}` + ]); + const executable = /^\s*program = (.+)$/m.exec(live)?.[1]?.trim(); + const pid = /^\s*pid = ([1-9][0-9]*)$/m.exec(live)?.[1]; + if ( + !executable || + !pid || + executable !== configured.trim() || + (await realpath(layout.launcher)) !== (await realpath(executable)) + ) + throw new NativeInstallError('The running Tracker, LaunchAgent and launcher do not agree.'); + const revision = await trackerSourceRevision(executable); + if (!revision) + throw new NativeInstallError('Could not read the running Tracker source revision.'); + return { revision, signature: await signedIdentity(executable, run) }; +} + +async function iphoneReadback( + target: Extract, + revision: string, + run: NativeInstallCommand +): Promise { + const temp = await mkdtemp(join(tmpdir(), 'harness-iphone-readback-')); + const file = join(temp, 'apps.json'); + try { + await run('/usr/bin/xcrun', [ + 'devicectl', + 'device', + 'info', + 'apps', + '--device', + target.device, + '--bundle-id', + iphoneBundle, + '--timeout', + '30', + '--json-output', + file + ]); + const { result } = JSON.parse(await readFile(file, 'utf8')); + if (result?.deviceIdentifier?.toLowerCase() !== target.device || !Array.isArray(result.apps)) + throw new NativeInstallError('Readback did not identify the requested physical iPhone.'); + const apps = result.apps.filter( + (app: { bundleIdentifier?: string }) => app.bundleIdentifier === iphoneBundle + ); + if (apps.length === 0) return { revision: null }; + const build: unknown = apps[0].bundleVersion; + if (apps.length !== 1 || typeof build !== 'string' || !/^\d+$/.test(build)) + throw new NativeInstallError('The iPhone did not report one installed Harness build number.'); + return { build, revision: build === target.build ? revision : null }; + } finally { + await rm(temp, { recursive: true, force: true }); + } +} + +export async function readNativeTarget( + plan: NativeInstallPlan, + target: NativeInstallTarget, + home: string, + run: NativeInstallCommand +): Promise { + if (target.kind === 'iphone') return iphoneReadback(target, plan.revision, run); + const tracker = await trackerReadback(home, run); + if (target.kind === 'tracker') return tracker; + if (!(await exists(installedMacApp))) return { revision: null, tracker: tracker.revision }; + return { + revision: (await macManifest(installedMacApp)).revision, + signature: await signedIdentity(installedMacApp, run, true), + tracker: tracker.revision + }; +} diff --git a/scripts/native-install/nativeInstallReceipt.ts b/scripts/native-install/nativeInstallReceipt.ts new file mode 100644 index 00000000000..d7665ced8f5 --- /dev/null +++ b/scripts/native-install/nativeInstallReceipt.ts @@ -0,0 +1,114 @@ +// @harness-uid u_fwa75ljyvf +import { NativeInstallError } from './NativeInstallError'; +import { randomUUID } from 'node:crypto'; +import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'; +import { dirname, join } from 'node:path'; +import type { + NativeInstallPlan, + NativeInstallReceipt, + NativeInstallTarget, + NativeReadback +} from './nativeInstallPlan.types'; + +export function receiptPath(root: string, plan: NativeInstallPlan, target: NativeInstallTarget) { + return join(root, plan.id, `${target.id}.json`); +} + +export async function readNativeReceipt(file: string): Promise { + try { + return JSON.parse(await readFile(file, 'utf8')); + } catch (error) { + if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null; + throw error; + } +} + +export async function saveNativeReceipt( + file: string, + receipt: NativeInstallReceipt +): Promise { + await mkdir(dirname(file), { recursive: true, mode: 0o700 }); + const temporary = `${file}.${randomUUID()}.tmp`; + await writeFile(temporary, `${JSON.stringify(receipt, null, 2)}\n`, { mode: 0o600, flag: 'wx' }); + await rename(temporary, file); +} + +export function matchesReadback( + plan: NativeInstallPlan, + target: NativeInstallTarget, + observed: NativeReadback +): boolean { + if (observed.revision !== plan.revision) return false; + return target.kind === 'iphone' + ? observed.build === target.build + : observed.signature === target.signature; +} + +export function receiptMatchesTarget( + plan: NativeInstallPlan, + target: NativeInstallTarget, + receipt: NativeInstallReceipt +): boolean { + const { id, computer, signature, kind } = target; + return ( + receipt.release === plan.id && + receipt.target === id && + receipt.computer === computer && + receipt.revision === plan.revision && + receipt.signature === signature && + receipt.kind === kind && + receipt.device === (target.kind === 'iphone' ? target.device : undefined) + ); +} + +export async function nativeInstallStatus( + root: string, + plan: NativeInstallPlan, + target: NativeInstallTarget +) { + const receipt = await readNativeReceipt(receiptPath(root, plan, target)); + const valid = receipt && receiptMatchesTarget(plan, target, receipt); + const installed = + valid && + receipt.status === 'installed' && + receipt.actual && + receipt.observedAt && + matchesReadback(plan, target, receipt.actual); + if (installed) return receipt; + return { + release: plan.id, + target: target.id, + computer: target.computer, + kind: target.kind, + revision: plan.revision, + status: valid ? 'unconfirmed' : 'pending', + receipt: valid ? receipt : null + }; +} + +export async function requirePrimaryInstalled( + plan: NativeInstallPlan, + root: string, + imported?: string +): Promise { + const primary = plan.targets.find(({ id }) => id === plan.primaryFirst); + if (!primary) return; + const receipt = await readNativeReceipt(imported ?? receiptPath(root, plan, primary)); + if ( + !receipt || + receipt.status !== 'installed' || + !receipt.observedAt || + !receipt.actual || + !receiptMatchesTarget(plan, primary, receipt) || + !matchesReadback(plan, primary, receipt.actual) + ) + throw new NativeInstallError( + 'The primary Mac needs its own installed readback for this release first.' + ); +} + +export function iphoneBuildReceipt(root: string, device: string, build: string): string { + if (!/^\d{1,32}$/.test(build)) + throw new NativeInstallError('Invalid installed iPhone build number.'); + return join(root, 'iphone-builds', device, `${build}.json`); +} diff --git a/scripts/native-install/runNativeInstallCommand.ts b/scripts/native-install/runNativeInstallCommand.ts new file mode 100644 index 00000000000..15777258df3 --- /dev/null +++ b/scripts/native-install/runNativeInstallCommand.ts @@ -0,0 +1,33 @@ +// @harness-uid u_whrkrbrb75 +import { NativeInstallError } from './NativeInstallError'; +import { spawn } from 'node:child_process'; +import type { NativeInstallCommandResult } from './nativeInstallPlan.types'; + +/** Pass the acquired lock to activation processes so they retain it if their coordinator exits. */ +export function runNativeInstallCommand( + executable: string, + args: string[], + descriptor?: number +): Promise { + return new Promise((resolve, reject) => { + const child = spawn(executable, args, { + stdio: + descriptor === undefined + ? ['ignore', 'pipe', 'pipe'] + : ['ignore', 'pipe', 'pipe', descriptor] + }); + let stdout = ''; + let stderr = ''; + child.stdout?.setEncoding('utf8').on('data', (chunk: string) => { + stdout += chunk; + }); + child.stderr?.setEncoding('utf8').on('data', (chunk: string) => { + stderr += chunk; + }); + child.once('error', reject); + child.once('close', (status, signal) => { + if (status === 0) resolve({ stdout, stderr }); + else reject(new NativeInstallError(`${executable} failed (${signal ?? status}).`)); + }); + }); +} diff --git a/specification/loops/t2m0n5-native-install/loop.json b/specification/loops/t2m0n5-native-install/loop.json new file mode 100644 index 00000000000..72feb2fbe6f --- /dev/null +++ b/specification/loops/t2m0n5-native-install/loop.json @@ -0,0 +1,74 @@ +{ + "name": "t2m0n5-native-install", + "goal": "Replay standalone Tracker and native app activation on independent devices, preserve the newer Tracker, recover an abandoned lease and require target-specific readback.", + "createdAt": "2026-11-29T18:50:18.703Z", + "updatedAt": "2026-11-29T19:10:08.221Z", + "template": "regression-prevention", + "templateLineage": ["regression-prevention"], + "enforceOrder": true, + "regressionCommits": 1, + "steps": [ + { + "id": "spec", + "title": "Identify the regression, prior working behavior, root cause, and evidence.", + "status": "complete", + "completedAt": "2026-11-29T18:51:22.243Z", + "evidence": "fyaces notes p2 and retro 7zhthn p1: standalone Tracker and app installers rely on timing and manually inspected pins; bundled startup has only a private mtime lock and no ancestry check." + }, + { + "id": "coverage", + "title": "Explain why existing standardized tests missed the regression; name the coverage gap and reusable test or shared guard change.", + "status": "complete", + "completedAt": "2026-11-29T18:51:25.526Z", + "evidence": "The desktop Tracker bundle matrix tests serialized updates and readiness rollback with fake launchd; it does not exercise an installed standalone pin newer than the app. Physical installs were only verified by local release scripts." + }, + { + "id": "red", + "title": "Strengthen the existing standardized test; commit it before repair, run it failing with loop record --phase red, and preserve the assertion.", + "status": "complete", + "completedAt": "2026-11-29T18:55:02.824Z", + "evidence": "Recorded f35c7610d4: changed ProgramArguments[0] from standalone/harness to the older bundled release; 6 other cases passed." + }, + { + "id": "propose", + "title": "Propose a root-cause repair and an automated guard for the identified failure.", + "status": "complete", + "completedAt": "2026-11-29T18:55:04.632Z", + "evidence": "Use one macOS kernel lock per device, signed Git ancestry for bundle startup, and receipts reconciled against target-specific readback. Fake launchd/device adapters are zero-cost. Live install takes roughly 30–45 minutes across three devices and needs release approval." + }, + { + "id": "implement", + "title": "Implement the repair and wire the prevention test or guard into normal project verification.", + "status": "complete", + "completedAt": "2026-11-29T19:04:56.386Z", + "evidence": "e1cb1956d7 adds the shared macOS kernel lock and the Mac bundle startup floor check. The original bundle startup regression remains in the standard Tracker bundle suite." + }, + { + "id": "green", + "title": "Rerun the same unchanged regression test at a separate fix commit with loop record --phase green; preserve passing proof.", + "status": "complete", + "completedAt": "2026-11-29T19:10:02.939Z", + "evidence": "All seven cases passed in the exact e1cb1956d7 snapshot with the same command and environment as the red checkpoint." + }, + { + "id": "guard", + "title": "In an isolated fixture or temporary workspace, prove reintroducing the original failure makes the guard fail; restore and prove it passes.", + "status": "complete", + "completedAt": "2026-11-29T19:10:08.221Z", + "evidence": "The guard fails on the original isolated f35c7610d4 fixture and passes on the repaired e1cb1956d7 source with identical tests." + }, + { + "id": "verify", + "title": "Repeat until the guard and relevant project checks pass; verify affected UI flows with fresh inspected screenshots and no unexpected browser errors; preserve diagnostics and keep pending while proof fails.", + "status": "pending" + } + ], + "evaluators": [ + { + "id": "check", + "title": "Run the project check script.", + "command": "bun run check", + "step": "verify" + } + ] +} diff --git a/specification/loops/t2m0n5-native-install/trace.ndjson b/specification/loops/t2m0n5-native-install/trace.ndjson new file mode 100644 index 00000000000..8e04d83b3ea --- /dev/null +++ b/specification/loops/t2m0n5-native-install/trace.ndjson @@ -0,0 +1,8 @@ +{"event":"loop.created","timestamp":"2026-11-29T18:50:18.703Z","name":"t2m0n5-native-install","goal":"Replay standalone Tracker and native app activation on independent devices, preserve the newer Tracker, recover an abandoned lease and require target-specific readback.","template":"regression-prevention","templateLineage":["regression-prevention"]} +{"event":"step.completed","timestamp":"2026-11-29T18:51:22.243Z","loop":"t2m0n5-native-install","step":"spec","evidence":"fyaces notes p2 and retro 7zhthn p1: standalone Tracker and app installers rely on timing and manually inspected pins; bundled startup has only a private mtime lock and no ancestry check."} +{"event":"step.completed","timestamp":"2026-11-29T18:51:25.526Z","loop":"t2m0n5-native-install","step":"coverage","evidence":"The desktop Tracker bundle matrix tests serialized updates and readiness rollback with fake launchd; it does not exercise an installed standalone pin newer than the app. Physical installs were only verified by local release scripts."} +{"event":"step.completed","timestamp":"2026-11-29T18:55:02.824Z","loop":"t2m0n5-native-install","step":"red","evidence":"Recorded f35c7610d4: changed ProgramArguments[0] from standalone/harness to the older bundled release; 6 other cases passed."} +{"event":"step.completed","timestamp":"2026-11-29T18:55:04.632Z","loop":"t2m0n5-native-install","step":"propose","evidence":"Use one macOS kernel lock per device, signed Git ancestry for bundle startup, and receipts reconciled against target-specific readback. Fake launchd/device adapters are zero-cost. Live install takes roughly 30–45 minutes across three devices and needs release approval."} +{"event":"step.completed","timestamp":"2026-11-29T19:04:56.386Z","loop":"t2m0n5-native-install","step":"implement","evidence":"e1cb1956d7 adds the shared macOS kernel lock and the Mac bundle startup floor check. The original bundle startup regression remains in the standard Tracker bundle suite."} +{"event":"step.completed","timestamp":"2026-11-29T19:10:02.939Z","loop":"t2m0n5-native-install","step":"green","evidence":"All seven cases passed in the exact e1cb1956d7 snapshot with the same command and environment as the red checkpoint."} +{"event":"step.completed","timestamp":"2026-11-29T19:10:08.221Z","loop":"t2m0n5-native-install","step":"guard","evidence":"The guard fails on the original isolated f35c7610d4 fixture and passes on the repaired e1cb1956d7 source with identical tests."} diff --git a/specification/units/desktop.service.development-tooling-tracker-bundle-install-bundled-tracker.json b/specification/units/desktop.service.development-tooling-tracker-bundle-install-bundled-tracker.json index a92236d533c..7f87adba334 100644 --- a/specification/units/desktop.service.development-tooling-tracker-bundle-install-bundled-tracker.json +++ b/specification/units/desktop.service.development-tooling-tracker-bundle-install-bundled-tracker.json @@ -4,8 +4,8 @@ "uid": "u_wsau7njqqr", "kind": "service", "title": "installBundledTracker", - "responsibility": "Owns the installBundledTracker service workflow.", - "responsibilityOrigin": "derived", + "responsibility": "Stages and activates the app’s Tracker under the Mac release lock after checking the installed revision floor.", + "responsibilityOrigin": "declared", "status": "active", "owns": { "source": [ @@ -16,32 +16,37 @@ "symbols": ["installBundledTracker", "trackerSessionLinks", "ReleaseLink"] }, "contract": { - "origin": "derived", + "origin": "declared", "inputs": [ { "name": "installBundledTracker.input", "type": "TrackerBundleInput", - "required": true + "required": true, + "description": "Bundle installer paths, host adapter and candidate revision, or a record update request." }, { "name": "trackerSessionLinks.config", "type": "string", - "required": true + "required": true, + "description": "Active Tracker configuration path containing the managed session tool location." }, { "name": "trackerSessionLinks.layout", "type": "TrackerBundleLayout", - "required": true + "required": true, + "description": "Resolved paths the Mac bundle may manage under the current home." } ], "outputs": [ { "name": "installBundledTracker", - "type": "Promise" + "type": "Promise", + "description": "Installed, current, CLI-only, refused or rolled-back bundle outcome." }, { "name": "trackerSessionLinks", - "type": "Promise" + "type": "Promise", + "description": "Existing, managed Tracker tool links eligible to move to the release." } ], "errors": [], @@ -53,13 +58,15 @@ { "name": "installBundledTracker.input", "type": "TrackerBundleInput", - "required": true + "required": true, + "description": "Bundle installer paths, host adapter and candidate revision, or a record update request." } ], "outputs": [ { "name": "installBundledTracker", - "type": "Promise" + "type": "Promise", + "description": "Installed, current, CLI-only, refused or rolled-back bundle outcome." } ], "errors": [], @@ -71,18 +78,21 @@ { "name": "trackerSessionLinks.config", "type": "string", - "required": true + "required": true, + "description": "Active Tracker configuration path containing the managed session tool location." }, { "name": "trackerSessionLinks.layout", "type": "TrackerBundleLayout", - "required": true + "required": true, + "description": "Resolved paths the Mac bundle may manage under the current home." } ], "outputs": [ { "name": "trackerSessionLinks", - "type": "Promise" + "type": "Promise", + "description": "Existing, managed Tracker tool links eligible to move to the release." } ], "errors": [], @@ -97,6 +107,11 @@ "via": "import", "origin": "derived" }, + { + "unit": "desktop.service.development-tooling-tracker-bundle-native-activation-lock", + "via": "import", + "origin": "derived" + }, { "unit": "desktop.service.development-tooling-tracker-bundle-replace-symlink", "via": "import", @@ -126,6 +141,11 @@ "unit": "desktop.service.development-tooling-tracker-bundle-tracker-launch-agent", "via": "import", "origin": "derived" + }, + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-revision-floor", + "via": "import", + "origin": "derived" } ], "runtime": { diff --git a/specification/units/desktop.service.development-tooling-tracker-bundle-native-activation-lock.json b/specification/units/desktop.service.development-tooling-tracker-bundle-native-activation-lock.json new file mode 100644 index 00000000000..348e9c41b2f --- /dev/null +++ b/specification/units/desktop.service.development-tooling-tracker-bundle-native-activation-lock.json @@ -0,0 +1,120 @@ +{ + "schemaVersion": 1, + "id": "desktop.service.development-tooling-tracker-bundle-native-activation-lock", + "uid": "u_tqudg6lphc", + "kind": "service", + "title": "nativeActivationLock", + "responsibility": "Holds a stable macOS kernel lock while one installer activates a device.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": [ + "packages/desktop/src/services/development-tooling/tracker-bundle/nativeActivationLock.ts" + ], + "symbols": ["withNativeActivationLock"] + }, + "contract": { + "origin": "declared", + "inputs": [ + { + "name": "withNativeActivationLock.file", + "type": "string", + "required": true, + "description": "Absolute file path for the lock or receipt used by this operation." + }, + { + "name": "withNativeActivationLock.work", + "type": "(descriptor: number) => Promise", + "required": true, + "description": "Activation callback invoked with the acquired lock descriptor." + }, + { + "name": "withNativeActivationLock.wait", + "type": "number", + "required": false, + "default": 0, + "description": "Maximum seconds to wait for an occupied device lock." + } + ], + "outputs": [ + { + "name": "withNativeActivationLock", + "type": "Promise", + "description": "Callback result, or null when another process owns the lock." + } + ], + "errors": [ + { + "name": "TrackerBundleError", + "type": "thrown", + "description": "The operation refuses conflicting, unreadable or invalid activation state, or propagates a failed system operation." + } + ], + "errorStatus": "declared", + "operations": [ + { + "name": "withNativeActivationLock", + "inputs": [ + { + "name": "withNativeActivationLock.file", + "type": "string", + "required": true, + "description": "Absolute file path for the lock or receipt used by this operation." + }, + { + "name": "withNativeActivationLock.work", + "type": "(descriptor: number) => Promise", + "required": true, + "description": "Activation callback invoked with the acquired lock descriptor." + }, + { + "name": "withNativeActivationLock.wait", + "type": "number", + "required": false, + "default": 0, + "description": "Maximum seconds to wait for an occupied device lock." + } + ], + "outputs": [ + { + "name": "withNativeActivationLock", + "type": "Promise", + "description": "Callback result, or null when another process owns the lock." + } + ], + "errors": [ + { + "name": "TrackerBundleError", + "type": "thrown", + "description": "The operation refuses conflicting, unreadable or invalid activation state, or propagates a failed system operation." + } + ], + "errorStatus": "declared" + } + ], + "initialization": [] + }, + "dependencies": [ + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-bundle-error", + "via": "import", + "origin": "derived" + } + ], + "runtime": { + "kind": "module", + "entry": "packages/desktop/src/services/development-tooling/tracker-bundle/nativeActivationLock.ts", + "targets": [ + { + "kind": "module", + "entry": "packages/desktop/src/services/development-tooling/tracker-bundle/nativeActivationLock.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/desktop.service.development-tooling-tracker-bundle-start-bundled-tracker.json b/specification/units/desktop.service.development-tooling-tracker-bundle-start-bundled-tracker.json index 8f717a3afad..2c1faca6f7f 100644 --- a/specification/units/desktop.service.development-tooling-tracker-bundle-start-bundled-tracker.json +++ b/specification/units/desktop.service.development-tooling-tracker-bundle-start-bundled-tracker.json @@ -4,8 +4,8 @@ "uid": "u_tba2m5pvzc", "kind": "service", "title": "startBundledTracker", - "responsibility": "Owns the startBundledTracker service workflow.", - "responsibilityOrigin": "derived", + "responsibility": "Reads the packaged revision and ancestry, then starts the guarded bundle install with the local macOS host.", + "responsibilityOrigin": "declared", "status": "active", "owns": { "source": [ @@ -14,36 +14,47 @@ "symbols": ["systemTrackerHost", "startBundledTracker"] }, "contract": { - "origin": "derived", + "origin": "declared", "inputs": [ { "name": "startBundledTracker.appPath", "type": "string", - "required": true + "required": true, + "description": "Electron application directory containing the package manifest." }, { "name": "startBundledTracker.home", "type": "string", - "required": true + "required": true, + "description": "Home directory where the local Tracker state and device locks live." }, { "name": "startBundledTracker.host", "type": "TrackerBundleHost", - "required": false + "required": false, + "description": "Injected macOS process adapter for launchd and Tracker readiness." } ], "outputs": [ { "name": "systemTrackerHost", - "type": "TrackerBundleHost" + "type": "TrackerBundleHost", + "description": "Local adapter for launchd, filesystem tooling and readiness commands." }, { "name": "startBundledTracker", - "type": "Promise" + "type": "Promise", + "description": "Packaged startup outcome, including a no-op when no bundled revision is present." } ], - "errors": [], - "errorStatus": "unknown", + "errors": [ + { + "name": "TrackerBundleError", + "type": "thrown", + "description": "The operation refuses conflicting, unreadable or invalid activation state, or propagates a failed system operation." + } + ], + "errorStatus": "declared", "operations": [ { "name": "systemTrackerHost", @@ -51,7 +62,8 @@ "outputs": [ { "name": "systemTrackerHost", - "type": "TrackerBundleHost" + "type": "TrackerBundleHost", + "description": "Local adapter for launchd, filesystem tooling and readiness commands." } ], "errors": [], @@ -63,23 +75,27 @@ { "name": "startBundledTracker.appPath", "type": "string", - "required": true + "required": true, + "description": "Electron application directory containing the package manifest." }, { "name": "startBundledTracker.home", "type": "string", - "required": true + "required": true, + "description": "Home directory where the local Tracker state and device locks live." }, { "name": "startBundledTracker.host", "type": "TrackerBundleHost", - "required": false + "required": false, + "description": "Injected macOS process adapter for launchd and Tracker readiness." } ], "outputs": [ { "name": "startBundledTracker", - "type": "Promise" + "type": "Promise", + "description": "Packaged startup outcome, including a no-op when no bundled revision is present." } ], "errors": [], @@ -94,10 +110,25 @@ "via": "import", "origin": "derived" }, + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-bundle-error", + "via": "import", + "origin": "derived" + }, + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-bundle-layout", + "via": "import", + "origin": "derived" + }, { "unit": "desktop.service.development-tooling-tracker-bundle-tracker-bundle-service-types", "via": "import", "origin": "derived" + }, + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-revision-floor", + "via": "import", + "origin": "derived" } ], "runtime": { diff --git a/specification/units/desktop.service.development-tooling-tracker-bundle-tracker-bundle-record.json b/specification/units/desktop.service.development-tooling-tracker-bundle-tracker-bundle-record.json index 14946a266ab..9c101d9bb91 100644 --- a/specification/units/desktop.service.development-tooling-tracker-bundle-tracker-bundle-record.json +++ b/specification/units/desktop.service.development-tooling-tracker-bundle-tracker-bundle-record.json @@ -4,75 +4,70 @@ "uid": "u_tb5vh2cjta", "kind": "service", "title": "trackerBundleRecord", - "responsibility": "Owns the trackerBundleRecord service workflow.", - "responsibilityOrigin": "derived", + "responsibility": "Persists the active bundled Tracker release and retains earlier installer-owned releases for rollback.", + "responsibilityOrigin": "declared", "status": "active", "owns": { "source": [ "packages/desktop/src/services/development-tooling/tracker-bundle/trackerBundleRecord.ts" ], - "symbols": ["readRecord", "writeRecord", "recordRelease", "withLock"] + "symbols": ["readRecord", "writeRecord", "recordRelease"] }, "contract": { - "origin": "derived", + "origin": "declared", "inputs": [ { "name": "readRecord.file", "type": "string", - "required": true + "required": true, + "description": "Absolute file path for the lock or receipt used by this operation." }, { "name": "writeRecord.file", "type": "string", - "required": true + "required": true, + "description": "Absolute file path for the lock or receipt used by this operation." }, { "name": "writeRecord.record", "type": "TrackerBundleRecord", - "required": true + "required": true, + "description": "Latest bundle release record to store." }, { "name": "recordRelease.input", "type": "{ file: string; releases: string; revision: string }", - "required": true + "required": true, + "description": "Bundle installer paths, host adapter and candidate revision, or a record update request." }, { "name": "recordRelease.release", "type": "string", - "required": true + "required": true, + "description": "Immutable staged release identifier." }, { "name": "recordRelease.keep", "type": "string[]", - "required": true - }, - { - "name": "withLock.file", - "type": "string", - "required": true - }, - { - "name": "withLock.work", - "type": "() => Promise", - "required": true + "required": true, + "description": "Earlier release identifiers that must survive pruning." } ], "outputs": [ { "name": "readRecord", - "type": "Promise" + "type": "Promise", + "description": "Existing bundle release record, or an empty default." }, { "name": "writeRecord", - "type": "Promise" + "type": "Promise", + "description": "Completion after atomically replacing the bundle release record." }, { "name": "recordRelease", - "type": "Promise" - }, - { - "name": "withLock", - "type": "Promise" + "type": "Promise", + "description": "Updated bundled release history with protected rollback releases retained." } ], "errors": [], @@ -84,13 +79,15 @@ { "name": "readRecord.file", "type": "string", - "required": true + "required": true, + "description": "Absolute file path for the lock or receipt used by this operation." } ], "outputs": [ { "name": "readRecord", - "type": "Promise" + "type": "Promise", + "description": "Existing bundle release record, or an empty default." } ], "errors": [], @@ -102,18 +99,21 @@ { "name": "writeRecord.file", "type": "string", - "required": true + "required": true, + "description": "Absolute file path for the lock or receipt used by this operation." }, { "name": "writeRecord.record", "type": "TrackerBundleRecord", - "required": true + "required": true, + "description": "Latest bundle release record to store." } ], "outputs": [ { "name": "writeRecord", - "type": "Promise" + "type": "Promise", + "description": "Completion after atomically replacing the bundle release record." } ], "errors": [], @@ -125,46 +125,27 @@ { "name": "recordRelease.input", "type": "{ file: string; releases: string; revision: string }", - "required": true + "required": true, + "description": "Bundle installer paths, host adapter and candidate revision, or a record update request." }, { "name": "recordRelease.release", "type": "string", - "required": true + "required": true, + "description": "Immutable staged release identifier." }, { "name": "recordRelease.keep", "type": "string[]", - "required": true + "required": true, + "description": "Earlier release identifiers that must survive pruning." } ], "outputs": [ { "name": "recordRelease", - "type": "Promise" - } - ], - "errors": [], - "errorStatus": "unknown" - }, - { - "name": "withLock", - "inputs": [ - { - "name": "withLock.file", - "type": "string", - "required": true - }, - { - "name": "withLock.work", - "type": "() => Promise", - "required": true - } - ], - "outputs": [ - { - "name": "withLock", - "type": "Promise" + "type": "Promise", + "description": "Updated bundled release history with protected rollback releases retained." } ], "errors": [], diff --git a/specification/units/desktop.service.development-tooling-tracker-bundle-tracker-revision-floor.json b/specification/units/desktop.service.development-tooling-tracker-bundle-tracker-revision-floor.json new file mode 100644 index 00000000000..4107e2e1f44 --- /dev/null +++ b/specification/units/desktop.service.development-tooling-tracker-bundle-tracker-revision-floor.json @@ -0,0 +1,164 @@ +{ + "schemaVersion": 1, + "id": "desktop.service.development-tooling-tracker-bundle-tracker-revision-floor", + "uid": "u_o7wjd42x5c", + "kind": "service", + "title": "trackerRevisionFloor", + "responsibility": "Reads the installed Tracker source revision and rejects a candidate without proven compatible ancestry.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": [ + "packages/desktop/src/services/development-tooling/tracker-bundle/trackerRevisionFloor.ts" + ], + "symbols": ["isTrackerRevision", "trackerSourceRevision", "trackerFloorRefusal"] + }, + "contract": { + "origin": "declared", + "inputs": [ + { + "name": "isTrackerRevision.value", + "type": "JavaScript value", + "required": true, + "description": "Value to check for a full lowercase Git revision." + }, + { + "name": "trackerSourceRevision.executable", + "type": "string", + "required": true, + "description": "Executable path to inspect or start." + }, + { + "name": "trackerFloorRefusal.executables", + "type": "readonly string[]", + "required": true, + "description": "Paths of the configured, running or linked Tracker executables." + }, + { + "name": "trackerFloorRefusal.revision", + "type": "string", + "required": true, + "description": "Full candidate Git revision." + }, + { + "name": "trackerFloorRefusal.ancestors", + "type": "readonly string[]", + "required": false, + "default": [], + "description": "Signed candidate Git ancestor revisions accepted as the installed floor." + } + ], + "outputs": [ + { + "name": "isTrackerRevision", + "type": "value is string", + "description": "Whether the value has the format of a complete lowercase Git commit." + }, + { + "name": "trackerSourceRevision", + "type": "Promise", + "description": "Verified source revision, null for unknown provenance, or undefined for a missing executable." + }, + { + "name": "trackerFloorRefusal", + "type": "Promise", + "description": "A refusal reason for an unknown or incompatible installed revision, or null if compatible." + } + ], + "errors": [], + "errorStatus": "unknown", + "operations": [ + { + "name": "isTrackerRevision", + "inputs": [ + { + "name": "isTrackerRevision.value", + "type": "JavaScript value", + "required": true, + "description": "Value to check for a full lowercase Git revision." + } + ], + "outputs": [ + { + "name": "isTrackerRevision", + "type": "value is string", + "description": "Whether the value has the format of a complete lowercase Git commit." + } + ], + "errors": [], + "errorStatus": "unknown" + }, + { + "name": "trackerSourceRevision", + "inputs": [ + { + "name": "trackerSourceRevision.executable", + "type": "string", + "required": true, + "description": "Executable path to inspect or start." + } + ], + "outputs": [ + { + "name": "trackerSourceRevision", + "type": "Promise", + "description": "Verified source revision, null for unknown provenance, or undefined for a missing executable." + } + ], + "errors": [], + "errorStatus": "unknown" + }, + { + "name": "trackerFloorRefusal", + "inputs": [ + { + "name": "trackerFloorRefusal.executables", + "type": "readonly string[]", + "required": true, + "description": "Paths of the configured, running or linked Tracker executables." + }, + { + "name": "trackerFloorRefusal.revision", + "type": "string", + "required": true, + "description": "Full candidate Git revision." + }, + { + "name": "trackerFloorRefusal.ancestors", + "type": "readonly string[]", + "required": false, + "default": [], + "description": "Signed candidate Git ancestor revisions accepted as the installed floor." + } + ], + "outputs": [ + { + "name": "trackerFloorRefusal", + "type": "Promise", + "description": "A refusal reason for an unknown or incompatible installed revision, or null if compatible." + } + ], + "errors": [], + "errorStatus": "unknown" + } + ], + "initialization": [] + }, + "dependencies": [], + "runtime": { + "kind": "module", + "entry": "packages/desktop/src/services/development-tooling/tracker-bundle/trackerRevisionFloor.ts", + "targets": [ + { + "kind": "module", + "entry": "packages/desktop/src/services/development-tooling/tracker-bundle/trackerRevisionFloor.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install-activate-native-target.json b/specification/units/script.native-install-activate-native-target.json new file mode 100644 index 00000000000..33a8d1eddfd --- /dev/null +++ b/specification/units/script.native-install-activate-native-target.json @@ -0,0 +1,143 @@ +{ + "schemaVersion": 1, + "id": "script.native-install-activate-native-target", + "uid": "u_4vh4l462o2", + "kind": "script", + "title": "activateNativeTarget", + "responsibility": "Runs one target activation under its device lock and completes its receipt only from an exact readback.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": ["scripts/native-install/activateNativeTarget.ts"], + "symbols": ["activateNativeTarget"] + }, + "contract": { + "origin": "declared", + "inputs": [ + { + "name": "activateNativeTarget.root", + "type": "string", + "required": true, + "description": "Private receipt directory or portable copy using the same release and target layout." + }, + { + "name": "activateNativeTarget.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan with the exact source revision, owner and target pins." + }, + { + "name": "activateNativeTarget.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Activation target from the release plan." + }, + { + "name": "activateNativeTarget.effects", + "type": "NativeInstallEffects", + "required": true, + "description": "Target adapter for preflight, activation and live readback." + } + ], + "outputs": [ + { + "name": "activateNativeTarget", + "type": "Promise", + "description": "Target receipt after successful signed revision readback." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared", + "operations": [ + { + "name": "activateNativeTarget", + "inputs": [ + { + "name": "activateNativeTarget.root", + "type": "string", + "required": true, + "description": "Private receipt directory or portable copy using the same release and target layout." + }, + { + "name": "activateNativeTarget.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan with the exact source revision, owner and target pins." + }, + { + "name": "activateNativeTarget.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Activation target from the release plan." + }, + { + "name": "activateNativeTarget.effects", + "type": "NativeInstallEffects", + "required": true, + "description": "Target adapter for preflight, activation and live readback." + } + ], + "outputs": [ + { + "name": "activateNativeTarget", + "type": "Promise", + "description": "Target receipt after successful signed revision readback." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared" + } + ], + "initialization": [] + }, + "dependencies": [ + { + "unit": "desktop.service.development-tooling-tracker-bundle-native-activation-lock", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-error", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-plan", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-receipt", + "via": "import", + "origin": "derived" + } + ], + "runtime": { + "kind": "module", + "entry": "scripts/native-install/activateNativeTarget.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install/activateNativeTarget.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install-native-install-artifacts.json b/specification/units/script.native-install-native-install-artifacts.json new file mode 100644 index 00000000000..38d03349e1a --- /dev/null +++ b/specification/units/script.native-install-native-install-artifacts.json @@ -0,0 +1,257 @@ +{ + "schemaVersion": 1, + "id": "script.native-install-native-install-artifacts", + "uid": "u_hipgrr74v5", + "kind": "script", + "title": "nativeInstallArtifacts", + "responsibility": "Verifies staged Macs, standalone Tracker releases and iPhone apps against their pinned identities.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": ["scripts/native-install/nativeInstallArtifacts.ts"], + "symbols": ["macManifest", "signedIdentity", "verifyNativeArtifact", "stampIphoneRenderer"] + }, + "contract": { + "origin": "declared", + "inputs": [ + { + "name": "macManifest.app", + "type": "string", + "required": true, + "description": "Absolute path of a staged or installed Harness app bundle." + }, + { + "name": "signedIdentity.path", + "type": "string", + "required": true, + "description": "Path of the artifact whose code signature is verified." + }, + { + "name": "signedIdentity.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Native process runner used for operating system verification and activation." + }, + { + "name": "signedIdentity.deep", + "type": "boolean", + "required": false, + "default": false, + "description": "Whether to verify the signatures of nested executables." + }, + { + "name": "verifyNativeArtifact.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan with the exact source revision, owner and target pins." + }, + { + "name": "verifyNativeArtifact.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Activation target from the release plan." + }, + { + "name": "verifyNativeArtifact.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Native process runner used for operating system verification and activation." + }, + { + "name": "stampIphoneRenderer.renderer", + "type": "string", + "required": true, + "description": "Directory containing the built Capacitor renderer from the pinned revision." + } + ], + "outputs": [ + { + "name": "macManifest", + "type": "unknown", + "description": "Exact packaged Git revision and optional signed Tracker ancestry." + }, + { + "name": "signedIdentity", + "type": "unknown", + "description": "Verified code signature CDHash of the staged or installed artifact." + }, + { + "name": "verifyNativeArtifact", + "type": "Promise", + "description": "Verified Mac candidate ancestry, or an empty list for other verified artifacts." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared", + "operations": [ + { + "name": "macManifest", + "inputs": [ + { + "name": "macManifest.app", + "type": "string", + "required": true, + "description": "Absolute path of a staged or installed Harness app bundle." + } + ], + "outputs": [ + { + "name": "macManifest", + "type": "unknown", + "description": "Exact packaged Git revision and optional signed Tracker ancestry." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared" + }, + { + "name": "signedIdentity", + "inputs": [ + { + "name": "signedIdentity.path", + "type": "string", + "required": true, + "description": "Path of the artifact whose code signature is verified." + }, + { + "name": "signedIdentity.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Native process runner used for operating system verification and activation." + }, + { + "name": "signedIdentity.deep", + "type": "boolean", + "required": false, + "default": false, + "description": "Whether to verify the signatures of nested executables." + } + ], + "outputs": [ + { + "name": "signedIdentity", + "type": "unknown", + "description": "Verified code signature CDHash of the staged or installed artifact." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared" + }, + { + "name": "verifyNativeArtifact", + "inputs": [ + { + "name": "verifyNativeArtifact.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan with the exact source revision, owner and target pins." + }, + { + "name": "verifyNativeArtifact.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Activation target from the release plan." + }, + { + "name": "verifyNativeArtifact.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Native process runner used for operating system verification and activation." + } + ], + "outputs": [ + { + "name": "verifyNativeArtifact", + "type": "Promise", + "description": "Verified Mac candidate ancestry, or an empty list for other verified artifacts." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared" + }, + { + "name": "stampIphoneRenderer", + "inputs": [ + { + "name": "stampIphoneRenderer.renderer", + "type": "string", + "required": true, + "description": "Directory containing the built Capacitor renderer from the pinned revision." + } + ], + "outputs": [ + { + "name": "stampIphoneRenderer", + "type": "Promise", + "description": "Completion after writing the source revision resource to be signed." + } + ], + "errors": [], + "errorStatus": "unknown" + } + ], + "initialization": [] + }, + "dependencies": [ + { + "unit": "desktop.script.release-revision", + "via": "import", + "origin": "derived" + }, + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-revision-floor", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-error", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-plan", + "via": "import", + "origin": "derived" + } + ], + "runtime": { + "kind": "module", + "entry": "scripts/native-install/nativeInstallArtifacts.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install/nativeInstallArtifacts.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install-native-install-effects.json b/specification/units/script.native-install-native-install-effects.json new file mode 100644 index 00000000000..46d0abcc6af --- /dev/null +++ b/specification/units/script.native-install-native-install-effects.json @@ -0,0 +1,234 @@ +{ + "schemaVersion": 1, + "id": "script.native-install-native-install-effects", + "uid": "u_m3j5pldz4r", + "kind": "script", + "title": "nativeInstallEffects", + "responsibility": "Creates the macOS and CoreDevice operations for an install target and applies the compatibility floor.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": ["scripts/native-install/nativeInstallEffects.ts"], + "symbols": ["nativeInstallEffects", "requireLocalComputer", "nativeInstallRoot"] + }, + "contract": { + "origin": "declared", + "inputs": [ + { + "name": "nativeInstallEffects.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan with the exact source revision, owner and target pins." + }, + { + "name": "nativeInstallEffects.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Activation target from the release plan." + }, + { + "name": "nativeInstallEffects.home", + "type": "string", + "required": true, + "description": "Home directory where the local Tracker state and device locks live." + }, + { + "name": "nativeInstallEffects.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Native process runner used for operating system verification and activation." + }, + { + "name": "requireLocalComputer.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Activation target from the release plan." + }, + { + "name": "requireLocalComputer.home", + "type": "string", + "required": true, + "description": "Home directory where the local Tracker state and device locks live." + }, + { + "name": "requireLocalComputer.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Native process runner used for operating system verification and activation." + }, + { + "name": "nativeInstallRoot.home", + "type": "string", + "required": true, + "description": "Home directory where the local Tracker state and device locks live." + } + ], + "outputs": [ + { + "name": "nativeInstallEffects", + "type": "NativeInstallEffects", + "description": "Target-specific verify, activate and readback operations." + }, + { + "name": "requireLocalComputer", + "type": "Promise", + "description": "Completion if the current Tracker node is the declared controller." + }, + { + "name": "nativeInstallRoot", + "type": "unknown", + "description": "Canonical local directory for native install locks and receipts." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared", + "operations": [ + { + "name": "nativeInstallEffects", + "inputs": [ + { + "name": "nativeInstallEffects.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan with the exact source revision, owner and target pins." + }, + { + "name": "nativeInstallEffects.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Activation target from the release plan." + }, + { + "name": "nativeInstallEffects.home", + "type": "string", + "required": true, + "description": "Home directory where the local Tracker state and device locks live." + }, + { + "name": "nativeInstallEffects.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Native process runner used for operating system verification and activation." + } + ], + "outputs": [ + { + "name": "nativeInstallEffects", + "type": "NativeInstallEffects", + "description": "Target-specific verify, activate and readback operations." + } + ], + "errors": [], + "errorStatus": "none-found" + }, + { + "name": "requireLocalComputer", + "inputs": [ + { + "name": "requireLocalComputer.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Activation target from the release plan." + }, + { + "name": "requireLocalComputer.home", + "type": "string", + "required": true, + "description": "Home directory where the local Tracker state and device locks live." + }, + { + "name": "requireLocalComputer.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Native process runner used for operating system verification and activation." + } + ], + "outputs": [ + { + "name": "requireLocalComputer", + "type": "Promise", + "description": "Completion if the current Tracker node is the declared controller." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared" + }, + { + "name": "nativeInstallRoot", + "inputs": [ + { + "name": "nativeInstallRoot.home", + "type": "string", + "required": true, + "description": "Home directory where the local Tracker state and device locks live." + } + ], + "outputs": [ + { + "name": "nativeInstallRoot", + "type": "unknown", + "description": "Canonical local directory for native install locks and receipts." + } + ], + "errors": [], + "errorStatus": "unknown" + } + ], + "initialization": [] + }, + "dependencies": [ + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-bundle-layout", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-artifacts", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-error", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-plan", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-readback", + "via": "import", + "origin": "derived" + } + ], + "runtime": { + "kind": "module", + "entry": "scripts/native-install/nativeInstallEffects.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install/nativeInstallEffects.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install-native-install-error.json b/specification/units/script.native-install-native-install-error.json new file mode 100644 index 00000000000..3a16c20aabf --- /dev/null +++ b/specification/units/script.native-install-native-install-error.json @@ -0,0 +1,40 @@ +{ + "schemaVersion": 1, + "id": "script.native-install-native-install-error", + "uid": "u_nyxchio63x", + "kind": "script", + "title": "NativeInstallError", + "responsibility": "Reports a native activation that failed or whose installed state could not be confirmed.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": ["scripts/native-install/NativeInstallError.ts"], + "symbols": ["NativeInstallError"] + }, + "contract": { + "origin": "derived", + "inputs": [], + "outputs": [], + "errors": [], + "errorStatus": "none-found", + "operations": [], + "initialization": [] + }, + "dependencies": [], + "runtime": { + "kind": "module", + "entry": "scripts/native-install/NativeInstallError.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install/NativeInstallError.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install-native-install-plan.json b/specification/units/script.native-install-native-install-plan.json new file mode 100644 index 00000000000..4a49ba1ef7a --- /dev/null +++ b/specification/units/script.native-install-native-install-plan.json @@ -0,0 +1,58 @@ +{ + "schemaVersion": 1, + "id": "script.native-install-native-install-plan", + "uid": "u_yo34lp5jui", + "kind": "script", + "title": "nativeInstallPlan", + "responsibility": "Validates the release owner, approval, pinned artifact identity, target IDs and install order.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": [ + "scripts/native-install/nativeInstallPlan.ts", + "scripts/native-install/nativeInstallPlan.types.ts" + ], + "symbols": [ + "nativeInstallPlan", + "NativeInstallPlan", + "NativeInstallTarget", + "NativeReadback", + "NativeInstallReceipt", + "NativeInstallCommand", + "NativeInstallCommandResult", + "NativeInstallEffects" + ] + }, + "contract": { + "origin": "declared", + "inputs": [], + "outputs": [ + { + "name": "nativeInstallPlan", + "type": "unknown", + "description": "Schema that validates a local activation plan and normalizes device UUIDs." + } + ], + "errors": [], + "errorStatus": "none-found", + "operations": [], + "initialization": [] + }, + "dependencies": [], + "runtime": { + "kind": "module", + "entry": "scripts/native-install/nativeInstallPlan.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install/nativeInstallPlan.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install-native-install-readback.json b/specification/units/script.native-install-native-install-readback.json new file mode 100644 index 00000000000..d4d75654ef4 --- /dev/null +++ b/specification/units/script.native-install-native-install-readback.json @@ -0,0 +1,147 @@ +{ + "schemaVersion": 1, + "id": "script.native-install-native-install-readback", + "uid": "u_hpvdiqfxlv", + "kind": "script", + "title": "nativeInstallReadback", + "responsibility": "Reads the signed installed Mac app, running Tracker and requested physical iPhone build.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": ["scripts/native-install/nativeInstallReadback.ts"], + "symbols": ["installedMacApp", "readNativeTarget"] + }, + "contract": { + "origin": "declared", + "inputs": [ + { + "name": "readNativeTarget.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "readNativeTarget.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + }, + { + "name": "readNativeTarget.home", + "type": "string", + "required": true, + "description": "Home directory of the local Tracker service." + }, + { + "name": "readNativeTarget.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Runner for the target-specific native programs." + } + ], + "outputs": [ + { + "name": "installedMacApp", + "type": "unknown", + "description": "Canonical path inspected for the installed desktop app." + }, + { + "name": "readNativeTarget", + "type": "Promise", + "description": "Actual reported source, signature or bundle build for the target." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared", + "operations": [ + { + "name": "readNativeTarget", + "inputs": [ + { + "name": "readNativeTarget.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "readNativeTarget.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + }, + { + "name": "readNativeTarget.home", + "type": "string", + "required": true, + "description": "Home directory of the local Tracker service." + }, + { + "name": "readNativeTarget.run", + "type": "NativeInstallCommand", + "required": true, + "description": "Runner for the target-specific native programs." + } + ], + "outputs": [ + { + "name": "readNativeTarget", + "type": "Promise", + "description": "Actual reported source, signature or bundle build for the target." + } + ], + "errors": [], + "errorStatus": "unknown" + } + ], + "initialization": [] + }, + "dependencies": [ + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-bundle-layout", + "via": "import", + "origin": "derived" + }, + { + "unit": "desktop.service.development-tooling-tracker-bundle-tracker-revision-floor", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-artifacts", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-error", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-plan", + "via": "import", + "origin": "derived" + } + ], + "runtime": { + "kind": "module", + "entry": "scripts/native-install/nativeInstallReadback.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install/nativeInstallReadback.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install-native-install-receipt.json b/specification/units/script.native-install-native-install-receipt.json new file mode 100644 index 00000000000..7bc6db65931 --- /dev/null +++ b/specification/units/script.native-install-native-install-receipt.json @@ -0,0 +1,485 @@ +{ + "schemaVersion": 1, + "id": "script.native-install-native-install-receipt", + "uid": "u_fwa75ljyvf", + "kind": "script", + "title": "nativeInstallReceipt", + "responsibility": "Stores target receipts and determines order and status from exact per-target readback.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": ["scripts/native-install/nativeInstallReceipt.ts"], + "symbols": [ + "receiptPath", + "readNativeReceipt", + "saveNativeReceipt", + "matchesReadback", + "receiptMatchesTarget", + "nativeInstallStatus", + "requirePrimaryInstalled", + "iphoneBuildReceipt" + ] + }, + "contract": { + "origin": "declared", + "inputs": [ + { + "name": "receiptPath.root", + "type": "string", + "required": true, + "description": "Private receipt directory." + }, + { + "name": "receiptPath.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "receiptPath.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + }, + { + "name": "readNativeReceipt.file", + "type": "string", + "required": true, + "description": "Absolute receipt path." + }, + { + "name": "saveNativeReceipt.file", + "type": "string", + "required": true, + "description": "Absolute receipt path." + }, + { + "name": "saveNativeReceipt.receipt", + "type": "NativeInstallReceipt", + "required": true, + "description": "Stored release target receipt." + }, + { + "name": "matchesReadback.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "matchesReadback.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + }, + { + "name": "matchesReadback.observed", + "type": "NativeReadback", + "required": true, + "description": "Fresh readback received directly from the target." + }, + { + "name": "receiptMatchesTarget.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "receiptMatchesTarget.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + }, + { + "name": "receiptMatchesTarget.receipt", + "type": "NativeInstallReceipt", + "required": true, + "description": "Stored release target receipt." + }, + { + "name": "nativeInstallStatus.root", + "type": "string", + "required": true, + "description": "Private receipt directory." + }, + { + "name": "nativeInstallStatus.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "nativeInstallStatus.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + }, + { + "name": "requirePrimaryInstalled.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "requirePrimaryInstalled.root", + "type": "string", + "required": true, + "description": "Private receipt directory." + }, + { + "name": "requirePrimaryInstalled.imported", + "type": "string", + "required": false, + "description": "Optional receipt copied from the primary Mac." + }, + { + "name": "iphoneBuildReceipt.root", + "type": "string", + "required": true, + "description": "Private receipt directory." + }, + { + "name": "iphoneBuildReceipt.device", + "type": "string", + "required": true, + "description": "Paired physical iPhone CoreDevice UUID." + }, + { + "name": "iphoneBuildReceipt.build", + "type": "string", + "required": true, + "description": "Reported iPhone bundle build number." + } + ], + "outputs": [ + { + "name": "receiptPath", + "type": "unknown", + "description": "Absolute receipt path for a release target." + }, + { + "name": "readNativeReceipt", + "type": "Promise", + "description": "Stored receipt or null when it is missing." + }, + { + "name": "saveNativeReceipt", + "type": "Promise", + "description": "Completion after replacing the receipt atomically." + }, + { + "name": "matchesReadback", + "type": "boolean", + "description": "Whether the observed revision and artifact or build match the target." + }, + { + "name": "receiptMatchesTarget", + "type": "boolean", + "description": "Whether the receipt belongs to the same release, device and artifact." + }, + { + "name": "nativeInstallStatus", + "type": "unknown", + "description": "Installed, pending or unconfirmed status for one target." + }, + { + "name": "requirePrimaryInstalled", + "type": "Promise", + "description": "Completion when the exact release has a confirmed primary Mac receipt." + }, + { + "name": "iphoneBuildReceipt", + "type": "string", + "description": "Path indexing a physical device build to its signed source revision." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared", + "operations": [ + { + "name": "receiptPath", + "inputs": [ + { + "name": "receiptPath.root", + "type": "string", + "required": true, + "description": "Private receipt directory." + }, + { + "name": "receiptPath.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "receiptPath.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + } + ], + "outputs": [ + { + "name": "receiptPath", + "type": "unknown", + "description": "Absolute receipt path for a release target." + } + ], + "errors": [], + "errorStatus": "unknown" + }, + { + "name": "readNativeReceipt", + "inputs": [ + { + "name": "readNativeReceipt.file", + "type": "string", + "required": true, + "description": "Absolute receipt path." + } + ], + "outputs": [ + { + "name": "readNativeReceipt", + "type": "Promise", + "description": "Stored receipt or null when it is missing." + } + ], + "errors": [], + "errorStatus": "unknown" + }, + { + "name": "saveNativeReceipt", + "inputs": [ + { + "name": "saveNativeReceipt.file", + "type": "string", + "required": true, + "description": "Absolute receipt path." + }, + { + "name": "saveNativeReceipt.receipt", + "type": "NativeInstallReceipt", + "required": true, + "description": "Stored release target receipt." + } + ], + "outputs": [ + { + "name": "saveNativeReceipt", + "type": "Promise", + "description": "Completion after replacing the receipt atomically." + } + ], + "errors": [], + "errorStatus": "unknown" + }, + { + "name": "matchesReadback", + "inputs": [ + { + "name": "matchesReadback.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "matchesReadback.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + }, + { + "name": "matchesReadback.observed", + "type": "NativeReadback", + "required": true, + "description": "Fresh readback received directly from the target." + } + ], + "outputs": [ + { + "name": "matchesReadback", + "type": "boolean", + "description": "Whether the observed revision and artifact or build match the target." + } + ], + "errors": [], + "errorStatus": "none-found" + }, + { + "name": "receiptMatchesTarget", + "inputs": [ + { + "name": "receiptMatchesTarget.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "receiptMatchesTarget.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + }, + { + "name": "receiptMatchesTarget.receipt", + "type": "NativeInstallReceipt", + "required": true, + "description": "Stored release target receipt." + } + ], + "outputs": [ + { + "name": "receiptMatchesTarget", + "type": "boolean", + "description": "Whether the receipt belongs to the same release, device and artifact." + } + ], + "errors": [], + "errorStatus": "none-found" + }, + { + "name": "nativeInstallStatus", + "inputs": [ + { + "name": "nativeInstallStatus.root", + "type": "string", + "required": true, + "description": "Private receipt directory." + }, + { + "name": "nativeInstallStatus.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "nativeInstallStatus.target", + "type": "NativeInstallTarget", + "required": true, + "description": "Device target from the release plan." + } + ], + "outputs": [ + { + "name": "nativeInstallStatus", + "type": "unknown", + "description": "Installed, pending or unconfirmed status for one target." + } + ], + "errors": [], + "errorStatus": "unknown" + }, + { + "name": "requirePrimaryInstalled", + "inputs": [ + { + "name": "requirePrimaryInstalled.plan", + "type": "NativeInstallPlan", + "required": true, + "description": "Validated release plan." + }, + { + "name": "requirePrimaryInstalled.root", + "type": "string", + "required": true, + "description": "Private receipt directory." + }, + { + "name": "requirePrimaryInstalled.imported", + "type": "string", + "required": false, + "description": "Optional receipt copied from the primary Mac." + } + ], + "outputs": [ + { + "name": "requirePrimaryInstalled", + "type": "Promise", + "description": "Completion when the exact release has a confirmed primary Mac receipt." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared" + }, + { + "name": "iphoneBuildReceipt", + "inputs": [ + { + "name": "iphoneBuildReceipt.root", + "type": "string", + "required": true, + "description": "Private receipt directory." + }, + { + "name": "iphoneBuildReceipt.device", + "type": "string", + "required": true, + "description": "Paired physical iPhone CoreDevice UUID." + }, + { + "name": "iphoneBuildReceipt.build", + "type": "string", + "required": true, + "description": "Reported iPhone bundle build number." + } + ], + "outputs": [ + { + "name": "iphoneBuildReceipt", + "type": "string", + "description": "Path indexing a physical device build to its signed source revision." + } + ], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared" + } + ], + "initialization": [] + }, + "dependencies": [ + { + "unit": "script.native-install-native-install-error", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-plan", + "via": "import", + "origin": "derived" + } + ], + "runtime": { + "kind": "module", + "entry": "scripts/native-install/nativeInstallReceipt.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install/nativeInstallReceipt.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install-run-native-install-command.json b/specification/units/script.native-install-run-native-install-command.json new file mode 100644 index 00000000000..eb4d53fde56 --- /dev/null +++ b/specification/units/script.native-install-run-native-install-command.json @@ -0,0 +1,109 @@ +{ + "schemaVersion": 1, + "id": "script.native-install-run-native-install-command", + "uid": "u_whrkrbrb75", + "kind": "script", + "title": "runNativeInstallCommand", + "responsibility": "Runs native release commands and passes the acquired activation lock to the child.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": ["scripts/native-install/runNativeInstallCommand.ts"], + "symbols": ["runNativeInstallCommand"] + }, + "contract": { + "origin": "declared", + "inputs": [ + { + "name": "runNativeInstallCommand.executable", + "type": "string", + "required": true, + "description": "Absolute executable path." + }, + { + "name": "runNativeInstallCommand.args", + "type": "string[]", + "required": true, + "description": "Arguments passed directly to the process." + }, + { + "name": "runNativeInstallCommand.descriptor", + "type": "number", + "required": false, + "description": "Optional activation lock descriptor inherited by the process." + } + ], + "outputs": [ + { + "name": "runNativeInstallCommand", + "type": "Promise", + "description": "Captured stdout and stderr when the command exits successfully." + } + ], + "errors": [], + "errorStatus": "none-found", + "operations": [ + { + "name": "runNativeInstallCommand", + "inputs": [ + { + "name": "runNativeInstallCommand.executable", + "type": "string", + "required": true, + "description": "Absolute executable path." + }, + { + "name": "runNativeInstallCommand.args", + "type": "string[]", + "required": true, + "description": "Arguments passed directly to the process." + }, + { + "name": "runNativeInstallCommand.descriptor", + "type": "number", + "required": false, + "description": "Optional activation lock descriptor inherited by the process." + } + ], + "outputs": [ + { + "name": "runNativeInstallCommand", + "type": "Promise", + "description": "Captured stdout and stderr when the command exits successfully." + } + ], + "errors": [], + "errorStatus": "none-found" + } + ], + "initialization": [] + }, + "dependencies": [ + { + "unit": "script.native-install-native-install-error", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-plan", + "via": "import", + "origin": "derived" + } + ], + "runtime": { + "kind": "module", + "entry": "scripts/native-install/runNativeInstallCommand.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install/runNativeInstallCommand.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/specification/units/script.native-install.json b/specification/units/script.native-install.json new file mode 100644 index 00000000000..e3a2920dfdc --- /dev/null +++ b/specification/units/script.native-install.json @@ -0,0 +1,82 @@ +{ + "schemaVersion": 1, + "id": "script.native-install", + "uid": "u_wu7fdvimla", + "kind": "script", + "title": "native-install", + "responsibility": "Runs an approved native activation plan for one target or renders stored status for all targets.", + "responsibilityOrigin": "declared", + "status": "active", + "owns": { + "source": ["scripts/native-install.ts"], + "symbols": [] + }, + "contract": { + "origin": "declared", + "inputs": [], + "outputs": [], + "errors": [ + { + "name": "NativeInstallError", + "type": "thrown", + "description": "Activation was refused, or an artifact, target readback or native command did not match expectations." + } + ], + "errorStatus": "declared", + "operations": [], + "initialization": [] + }, + "dependencies": [ + { + "unit": "script.native-install-activate-native-target", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-artifacts", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-effects", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-error", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-plan", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-native-install-receipt", + "via": "import", + "origin": "derived" + }, + { + "unit": "script.native-install-run-native-install-command", + "via": "import", + "origin": "derived" + } + ], + "runtime": { + "kind": "module", + "entry": "scripts/native-install.ts", + "targets": [ + { + "kind": "module", + "entry": "scripts/native-install.ts" + } + ] + }, + "scenarios": [], + "budgets": { + "size": "frozen", + "complexity": "frozen", + "performance": [] + } +} diff --git a/test/native-install.test.ts b/test/native-install.test.ts new file mode 100644 index 00000000000..0ef5cc036f3 --- /dev/null +++ b/test/native-install.test.ts @@ -0,0 +1,201 @@ +import { once } from 'node:events'; +import { spawn } from 'node:child_process'; +import { mkdtemp, readFile, rm } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { afterEach, expect, test } from 'vitest'; +import { activateNativeTarget } from '../scripts/native-install/activateNativeTarget'; +import { nativeInstallPlan } from '../scripts/native-install/nativeInstallPlan'; +import { + nativeInstallStatus, + receiptPath, + requirePrimaryInstalled, + saveNativeReceipt +} from '../scripts/native-install/nativeInstallReceipt'; +import type { + NativeInstallReceipt, + NativeInstallTarget, + NativeReadback +} from '../scripts/native-install/nativeInstallPlan.types'; + +const revision = 'a'.repeat(40); +const signature = 'c'.repeat(40); +const old = { revision: 'b'.repeat(40), signature: 'd'.repeat(40) }; +const current = { revision, signature }; +const artifact = { + signature, + artifact: '/private/tmp/signed.app', + rollback: 'approved prior artifact' +}; +const plan = nativeInstallPlan.parse({ + id: 'release', + owner: 'MOCK owner', + revision, + approval: 'MOCK approval', + primaryFirst: 'primary', + targets: [ + { + ...artifact, + kind: 'mac', + id: 'primary', + computer: 'daniel-primary-mbp', + activate: ['/mock'] + }, + { ...artifact, kind: 'mac', id: 'mb2', computer: 'harbor-mbp-2', activate: ['/mock'] }, + { + ...artifact, + kind: 'tracker', + id: 'tracker', + computer: 'daniel-primary-mbp', + activate: ['/mock'], + checksums: 'f'.repeat(64) + }, + { + ...artifact, + kind: 'iphone', + id: 'phone', + computer: 'daniel-primary-mbp', + build: '20261129190000', + device: '20f7e51d-d1ea-456d-a653-00f9a3698363' + } + ] +}); +const roots: string[] = []; +afterEach(async () => { + await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true }))); +}); +async function stateRoot() { + const root = await mkdtemp(join(tmpdir(), 'harness-native-install-MOCK-')); + roots.push(root); + return root; +} +const darwin = test.runIf(process.platform === 'darwin'); + +darwin( + 'records each device independently and refuses to finish without exact readback', + async () => { + const root = await stateRoot(); + const [primary, mb2, , phone] = plan.targets; + let actual: NativeReadback = { ...old, tracker: old.revision }; + const effects = { + read: async () => actual, + verify: async () => {}, + activate: async () => { + actual = { ...current, tracker: old.revision }; + } + }; + await expect(requirePrimaryInstalled(plan, root)).rejects.toThrow('primary Mac needs its own'); + await activateNativeTarget(root, plan, primary, effects); + await expect(requirePrimaryInstalled(plan, root)).resolves.toBeUndefined(); + await expect( + requirePrimaryInstalled({ ...plan, revision: old.revision }, root) + ).rejects.toThrow('primary Mac needs its own'); + const status = () => + Promise.all([primary, mb2, phone].map((target) => nativeInstallStatus(root, plan, target))); + expect((await status()).map(({ status }) => status)).toEqual([ + 'installed', + 'pending', + 'pending' + ]); + expect(await nativeInstallStatus(root, plan, primary)).toMatchObject({ + trackerFloor: old.revision, + previous: { revision: old.revision }, + actual: current + }); + + await expect( + activateNativeTarget(root, plan, phone, { + ...effects, + read: async () => ({ revision: null, build: '20261129180000' }), + activate: async () => {} + }) + ).rejects.toThrow('did not report the expected signed revision'); + expect((await status()).map(({ status }) => status)).toEqual([ + 'installed', + 'pending', + 'unconfirmed' + ]); + } +); + +async function saveInterruptedAttempt(root: string, tracker: NativeInstallTarget) { + const file = receiptPath(root, plan, tracker); + const stale: NativeInstallReceipt = { + release: plan.id, + target: tracker.id, + computer: tracker.computer, + kind: tracker.kind, + revision, + signature, + owner: plan.owner, + approval: plan.approval, + artifact: tracker.artifact, + previous: old, + trackerFloor: old.revision, + startedAt: '2026-01-01T00:00:00Z', + leaseExpiresAt: '2026-01-01T00:10:00Z', + status: 'activating', + rollback: tracker.rollback + }; + await saveNativeReceipt(file, stale); + return file; +} + +darwin( + 'shares the Mac lock with standalone Tracker and reconciles a killed activation', + async () => { + const root = await stateRoot(); + const [primary, , tracker, phone] = plan.targets; + const file = await saveInterruptedAttempt(root, tracker); + // The kernel lock survives for as long as any activation subprocess owns the descriptor. + const holder = spawn( + '/usr/bin/lockf', + ['-k', join(root, 'mac.lock'), '/bin/sh', '-c', 'printf "%s" "$$"; exec /bin/cat >/dev/null'], + { stdio: ['pipe', 'pipe', 'ignore'] } + ); + let worker: number | undefined; + try { + const [event] = await once(holder.stdout, 'data'); + worker = Number(String(event)); + expect(worker).toBeGreaterThan(1); + const effects = { + read: async () => { + throw new Error('Must not read or write on a busy Mac'); + }, + verify: async () => {}, + activate: async () => {} + }; + for (const target of [primary, tracker]) + await expect(activateNativeTarget(root, plan, target, effects)).rejects.toThrow( + 'in progress' + ); + + await expect( + activateNativeTarget(root, plan, phone, { + ...effects, + read: async () => ({ revision, build: '20261129190000' }) + }) + ).resolves.toMatchObject({ status: 'installed' }); + } finally { + // Kill the worker while the stale receipt and lock inode are still present. + const exited = once(holder, 'exit'); + if (worker && worker > 1) process.kill(worker, 'SIGKILL'); + holder.stdin.end(); + await exited; + } + + await activateNativeTarget(root, plan, tracker, { + read: async () => current, + verify: async () => {}, + activate: async () => { + throw new Error('Do not reinstall when readback matches'); + } + }); + expect(JSON.parse(await readFile(file, 'utf8'))).toMatchObject({ + status: 'installed', + previous: old, + actual: current, + interrupted: { status: 'activating', observed: current } + }); + } +);