mirror of
https://github.com/expo/explore.git
synced 2026-11-15 17:32:23 -10:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7360502e86 | ||
|
|
6539b5c002 | ||
|
|
422cf8caf4 | ||
|
|
b281c734f4 | ||
|
|
c99c26f9bb | ||
|
|
9150a24cd9 | ||
|
|
2c5f8f85a3 | ||
|
|
23227ca55c | ||
|
|
ed1bf34434 | ||
|
|
bdf9e597d3 |
No files matched your search
@@ -61,7 +61,13 @@ jobs:
|
||||
env:
|
||||
# npm cannot generate provenance for a private repository.
|
||||
NPM_CONFIG_PROVENANCE: "false"
|
||||
run: npm publish --access public
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
shell: bash
|
||||
# A prerelease (0.20.0-next.0) goes to the next tag, so latest keeps the last release.
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [[ "$VERSION" == *-* ]]; then tag=next; else tag=latest; fi
|
||||
npm publish --access public --tag "$tag"
|
||||
- name: Tag the release
|
||||
if: steps.version.outputs.publish == 'true'
|
||||
env:
|
||||
|
||||
@@ -580,7 +580,7 @@ npm test
|
||||
|
||||
- `npm test` rebuilds the CLI and the Viewer first, because the node tests run the compiled `dist/`. After one `npm run build`, `npm run test:node` skips the rebuild.
|
||||
- The agent runtimes and `eas-cli` are optional dependencies that only capture needs. Do not install with `--omit=optional`, which also drops esbuild's platform package.
|
||||
- To release, bump `version` in `package.json` and merge to main. The [publish workflow](.github/workflows/publish.yml) publishes any version npm does not have yet.
|
||||
- To release, bump `version` in `package.json` and merge to main. The [publish workflow](.github/workflows/publish.yml) publishes any version npm does not have yet. A prerelease version such as `0.20.0-next.0` goes to the `next` tag, so `latest` stays on the last release.
|
||||
|
||||
```sh
|
||||
npx playwright install chromium
|
||||
|
||||
+7
-3
@@ -157,6 +157,10 @@ runs:
|
||||
EXPO_TOKEN: ${{ inputs.expo_token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [[ ! -e "$OUTPUT/head-session" && ! -L "$OUTPUT/head-session" && ! -e "$OUTPUT/base-session" && ! -L "$OUTPUT/base-session" ]]; then exit 0; fi
|
||||
node "$TOOLS/scripts/cleanup-ci-sessions.mjs" --eas "$TOOLS/node_modules/.bin/eas" \
|
||||
--session-file "$OUTPUT/head-session" --session-file "$OUTPUT/base-session"
|
||||
# A side that captures an appearance in a session of its own records it as <side>-session-<scheme>.
|
||||
files=()
|
||||
for name in head-session base-session head-session-light head-session-dark base-session-light base-session-dark; do
|
||||
if [[ -e "$OUTPUT/$name" || -L "$OUTPUT/$name" ]]; then files+=(--session-file "$OUTPUT/$name"); fi
|
||||
done
|
||||
if (( ${#files[@]} == 0 )); then exit 0; fi
|
||||
node "$TOOLS/scripts/cleanup-ci-sessions.mjs" --eas "$TOOLS/node_modules/.bin/eas" "${files[@]}"
|
||||
@@ -103,6 +103,8 @@ exploration:
|
||||
capture:
|
||||
maxMinutes: 30
|
||||
maxActions: 500
|
||||
# maxSessions: 5 # the most EAS Simulator sessions one review runs at once, across all its targets and sides (default: 5, a typical plan's concurrent simulator limit). Each target's job gets floor(maxSessions / targets) sessions, at least one, and sessions left over go to foldable targets (pose): one target gets 5 (head and base at once, light and dark in their own sessions when that pays), two get 2 each, five get 1 each (head, then base). Below the number of targets, only that many target jobs run at once (the workflow's max-parallel, and a local review's targets), one session each. A side spreads its light and dark passes over separate sessions only when that saves it at least a minute, so the ceiling is a limit, not a target: a 3-route target stays on two sessions. euxy's four targets: 8 is two per target, 16 captures each appearance in its own session (measured: an iPhone side 6:12 → 4:26, one repack shared by its sessions, ~3.5 session-minutes more per side).
|
||||
# On a starter plan (one simulator per platform), set maxSessions to the plan's limit, e.g. 2 for an iOS and an Android target.
|
||||
repack: eas # eas (hosted workflow job; the default on EAS Simulator) | local (repack-app on the runner; the default with simulator: local)
|
||||
appearance: auto # auto (follow the app's userInterfaceStyle: automatic captures light and dark) | dark | light | [dark, light]
|
||||
launch: screenshot # screenshot (relaunch the app per appearance and keep its splash and first settled frame, default) | video (also keep a launch recording in the report) | off
|
||||
|
||||
@@ -109,6 +109,8 @@ capture:
|
||||
# simulator: eas # eas (EAS Simulator, default) | local (a simulator or emulator Explore starts on this machine with Xcode or the Android SDK; --simulator overrides it for one run)
|
||||
maxMinutes: 30
|
||||
maxActions: 500
|
||||
# maxSessions: 5 # the most EAS Simulator sessions one review runs at once, across all its targets and sides (default: 5, a typical plan's concurrent simulator limit). Each target's job gets floor(maxSessions / targets) sessions, at least one, and sessions left over go to foldable targets (pose): one target gets 5 (head and base at once, light and dark in their own sessions when that pays), two get 2 each, five get 1 each (head, then base). Below the number of targets, only that many target jobs run at once (the workflow's max-parallel, and a local review's targets), one session each. A side spreads its light and dark passes over separate sessions only when that saves it at least a minute, so the ceiling is a limit, not a target: a 3-route target stays on two sessions. euxy's four targets: 8 is two per target, 16 captures each appearance in its own session (measured: an iPhone side 6:12 → 4:26, one repack shared by its sessions, ~3.5 session-minutes more per side).
|
||||
# On a starter plan (one simulator per platform), set maxSessions to the plan's limit, e.g. 2 for an iOS and an Android target.
|
||||
repack: eas # eas (hosted EAS workflow job, the default on EAS Simulator) | local (repack-app on the runner, the default with simulator: local; --repack overrides it for one run)
|
||||
appearance: auto # auto (follow the app's userInterfaceStyle: automatic captures light and dark) | dark | light | [dark, light]
|
||||
launch: screenshot # screenshot (relaunch the app per appearance and keep its splash and first settled frame, default) | video (also keep a launch recording in the report) | off
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@expo/explore",
|
||||
"version": "0.19.8",
|
||||
"version": "0.20.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@expo/explore",
|
||||
"version": "0.19.8",
|
||||
"version": "0.20.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@expo/repack-app": "0.10.1",
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/explore",
|
||||
"version": "0.19.8",
|
||||
"version": "0.20.0",
|
||||
"description": "Source-driven mobile app maps, deterministic CI capture, and visual reviews",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
@@ -50,7 +50,7 @@
|
||||
"test:node": "node --test test/node/*.test.mjs",
|
||||
"test:hosting": "npm --prefix viewer-host run typecheck && npm --prefix viewer-host test",
|
||||
"test:viewer:artifacts": "node --test test/browser/artifact-report.browser.mjs test/browser/artifact-cache.browser.mjs",
|
||||
"test:viewer:browser": "node --test test/browser/screenshot-image.browser.mjs test/browser/swipe-outlines.browser.mjs test/browser/inspector-notes.browser.mjs test/browser/inspector-variants.browser.mjs test/browser/inspector-source-navigation.browser.mjs test/browser/map-edge-presentation.browser.mjs test/browser/local-ci-view.browser.mjs test/browser/report-viewer.browser.mjs",
|
||||
"test:viewer:browser": "node --test test/browser/screenshot-image.browser.mjs test/browser/swipe-outlines.browser.mjs test/browser/split-outlines.browser.mjs test/browser/inspector-notes.browser.mjs test/browser/inspector-variants.browser.mjs test/browser/inspector-source-navigation.browser.mjs test/browser/map-edge-presentation.browser.mjs test/browser/local-ci-view.browser.mjs test/browser/report-viewer.browser.mjs",
|
||||
"test:viewer:e2e": "npm run test:viewer:browser && playwright test",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p viewer/tsconfig.json --noEmit",
|
||||
"lint": "eslint .",
|
||||
|
||||
@@ -10,7 +10,8 @@ const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
|
||||
|
||||
/** Stop only exact sessions whose ownership the capture coordinator already verified. */
|
||||
export async function cleanupCiSessions({ sessionFiles, easCommand, environment = process.env, runCommand = spawnSync }) {
|
||||
if (!Array.isArray(sessionFiles) || sessionFiles.length > 3) throw new Error('Provide at most three explicit session handoff files.');
|
||||
// head, base and baseline, each with a session per appearance pass (light, dark) beside its own.
|
||||
if (!Array.isArray(sessionFiles) || sessionFiles.length > 9) throw new Error('Provide at most nine explicit session handoff files.');
|
||||
const temporary = await realpath(environment.RUNNER_TEMP || tmpdir());
|
||||
const result = { stopped: [], failures: [] };
|
||||
let project;
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Runs the Argent bridge's commands on a worker thread of this process, through a synchronous runner, so the
|
||||
* capture's command-at-a-time control flow keeps one bridge and one tool-server connection for the whole run
|
||||
* instead of starting a process per command. Commands for any other executable go to the fallback runner.
|
||||
*/
|
||||
import { Worker } from "node:worker_threads";
|
||||
import { commandOutcome } from "./controller.js";
|
||||
import type { CommandRequest, CommandResult, CommandRunner } from "./run.js";
|
||||
import { BRIDGE_HEADER_BYTES, BRIDGE_KIND_UNAVAILABLE, BRIDGE_SLOT_KIND, BRIDGE_SLOT_LENGTH, BRIDGE_SLOT_READY, type BridgeRequest, type BridgeWorkerData } from "./argent-bridge-worker.js";
|
||||
|
||||
/** Room for one answer: an accessibility tree of a large screen is a few megabytes. */
|
||||
const BRIDGE_BUFFER_BYTES = 64 * 1024 * 1024;
|
||||
/** How long a command gets when its request names no timeout. */
|
||||
const DEFAULT_COMMAND_TIMEOUT_MS = 10 * 60_000;
|
||||
/** After a timeout, how long the thread gets to confirm it dropped the command. */
|
||||
const ABORT_GRACE_MS = 15_000;
|
||||
|
||||
export type ArgentBridgeRunner = {
|
||||
runner: CommandRunner;
|
||||
/** Whether commands still go to the thread (false after it proved unavailable or stopped answering). */
|
||||
readonly active: boolean;
|
||||
close(): void;
|
||||
};
|
||||
|
||||
export function startArgentBridgeRunner(options: {
|
||||
/** The bridge executable the callers name; its commands run on the thread. */
|
||||
command: string;
|
||||
/** The bridge's environment, as argentControllerInvocation builds it. */
|
||||
environment: NodeJS.ProcessEnv;
|
||||
fallback: CommandRunner;
|
||||
/** Tests: a module exporting `createArgentClient` in place of the pinned Argent release's client. */
|
||||
clientModule?: string;
|
||||
progress?: (message: string) => void;
|
||||
}): ArgentBridgeRunner {
|
||||
const shared = new SharedArrayBuffer(BRIDGE_HEADER_BYTES + BRIDGE_BUFFER_BYTES);
|
||||
const header = new Int32Array(shared, 0, BRIDGE_HEADER_BYTES / 4);
|
||||
const bytes = new Uint8Array(shared, BRIDGE_HEADER_BYTES);
|
||||
const workerData: BridgeWorkerData = { shared, ...(options.clientModule ? { clientModule: options.clientModule } : {}) };
|
||||
let worker: Worker | undefined;
|
||||
// The environment the thread runs with: a copy, so a caller that changes the session's (a restarted local
|
||||
// tool-server's URL and token) is seen by the next command, which starts a thread with the new one.
|
||||
let environment: NodeJS.ProcessEnv = {};
|
||||
const start = (from: NodeJS.ProcessEnv) => {
|
||||
environment = { ...from };
|
||||
try {
|
||||
const started = new Worker(new URL("./argent-bridge-worker.js", import.meta.url), { workerData, env: environment });
|
||||
// A thread that crashes stops serving; the commands after it run per command.
|
||||
started.on("error", error => { if (worker === started) stop(`the Argent bridge thread failed (${error.message}); running the bridge per command`); });
|
||||
worker = started;
|
||||
} catch (error) { options.progress?.(`the Argent bridge thread could not start (${(error as Error).message}); running the bridge per command`); }
|
||||
};
|
||||
let sequence = 0;
|
||||
const stop = (reason: string) => {
|
||||
if (!worker) return;
|
||||
options.progress?.(reason);
|
||||
void worker.terminate();
|
||||
worker = undefined;
|
||||
};
|
||||
const changed = (next: NodeJS.ProcessEnv) => {
|
||||
const keys = new Set([...Object.keys(environment), ...Object.keys(next)]);
|
||||
return [...keys].some(key => environment[key] !== next[key]);
|
||||
};
|
||||
const waitFor = (id: number, timeoutMs: number): boolean => {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
for (;;) {
|
||||
// The value waited on is the one just compared: an answer stored after the comparison wakes the wait at once.
|
||||
const ready = Atomics.load(header, BRIDGE_SLOT_READY);
|
||||
if (ready === id) return true;
|
||||
const remaining = deadline - Date.now();
|
||||
if (remaining <= 0) return false;
|
||||
Atomics.wait(header, BRIDGE_SLOT_READY, ready, remaining);
|
||||
}
|
||||
};
|
||||
start(options.environment);
|
||||
const runner: CommandRunner = (request: CommandRequest): CommandResult => {
|
||||
// A recording runs per command, in the session's own directory: Argent's client saves one under the project its
|
||||
// working directory is in, and this thread's is the caller's checkout. The state file carries it between hosts.
|
||||
if (!worker || request.command !== options.command || request.args[0] === "record") return options.fallback(request);
|
||||
if (changed(request.environment)) { void worker.terminate(); worker = undefined; start(request.environment); }
|
||||
if (!worker) return options.fallback(request);
|
||||
const id = ++sequence;
|
||||
Atomics.store(header, BRIDGE_SLOT_READY, 0);
|
||||
worker.postMessage({ id, argv: request.args, ...(request.timeoutMs !== undefined ? { timeoutMs: request.timeoutMs } : {}) } satisfies BridgeRequest);
|
||||
const timeoutMs = request.timeoutMs ?? DEFAULT_COMMAND_TIMEOUT_MS;
|
||||
if (!waitFor(id, timeoutMs)) {
|
||||
worker.postMessage({ abort: id } satisfies BridgeRequest);
|
||||
if (!waitFor(id, ABORT_GRACE_MS)) stop("the Argent bridge thread stopped answering; running the bridge per command");
|
||||
throw Object.assign(new Error(`${request.command} ${request.args[0] ?? ""} timed out after ${timeoutMs} ms`), { code: "ETIMEDOUT" });
|
||||
}
|
||||
const text = Buffer.from(bytes.subarray(0, Atomics.load(header, BRIDGE_SLOT_LENGTH))).toString("utf8");
|
||||
if (Atomics.load(header, BRIDGE_SLOT_KIND) === BRIDGE_KIND_UNAVAILABLE) {
|
||||
stop(`the Argent bridge thread is unavailable (${text}); running the bridge per command`);
|
||||
return options.fallback(request);
|
||||
}
|
||||
const result = JSON.parse(text) as { exitCode: number; stdout: string };
|
||||
return commandOutcome(request, { status: result.exitCode, stdout: result.stdout, stderr: "" });
|
||||
};
|
||||
return { runner, get active() { return worker !== undefined; }, close: () => { if (worker) { void worker.terminate(); worker = undefined; } } };
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* The Argent bridge on a worker thread: one bridge and one tool-server connection for a whole capture, instead of a
|
||||
* process (and a TLS handshake) per command. The capture thread posts a command and blocks on the shared buffer;
|
||||
* this thread runs it through Argent's own client library (the code `argent run` uses) and writes the answer back.
|
||||
*/
|
||||
import { isMainThread, parentPort, workerData } from "node:worker_threads";
|
||||
import { copyFile, mkdir, open, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { ArgentCallError, type ArgentCall } from "./argent-driver.js";
|
||||
import { argentBridgeSettings, createArgentBridge, type ArgentBridge } from "./argent-bridge.js";
|
||||
import { ensureController } from "../shared/controller-cache.js";
|
||||
|
||||
/** The shared buffer: four Int32 header slots, then the UTF-8 answer. */
|
||||
export const BRIDGE_HEADER_BYTES = 16;
|
||||
export const BRIDGE_SLOT_READY = 0;
|
||||
export const BRIDGE_SLOT_LENGTH = 1;
|
||||
export const BRIDGE_SLOT_KIND = 2;
|
||||
export const BRIDGE_KIND_RESULT = 0;
|
||||
/** The bridge cannot run on this thread (Argent's client did not load); the host falls back to the process bridge. */
|
||||
export const BRIDGE_KIND_UNAVAILABLE = 1;
|
||||
|
||||
export type BridgeWorkerData = { shared: SharedArrayBuffer; clientModule?: string };
|
||||
export type BridgeRequest = { id: number; argv: readonly string[]; timeoutMs?: number } | { abort: number };
|
||||
|
||||
const ARGENT_CALL_TIMEOUT_MS = 180_000;
|
||||
|
||||
/** Argent's programmatic client, as `dist/client.js` of the pinned release exports it. */
|
||||
type ArgentClient = { callTool(name: string, args: Record<string, unknown>, options?: { signal?: AbortSignal }): Promise<{ data: unknown; note?: string }> };
|
||||
|
||||
/** Whether some bytes begin as a PNG or a JPEG does: `--out` is a screenshot, and nothing else is taken for one. */
|
||||
function isImage(head: Uint8Array): boolean {
|
||||
const png = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], jpeg = [0xff, 0xd8, 0xff];
|
||||
return [png, jpeg].some(signature => signature.every((byte, index) => head[index] === byte));
|
||||
}
|
||||
|
||||
/** Whether a path names a file that is an image by its content. */
|
||||
async function imageFile(path: string): Promise<boolean> {
|
||||
const file = await open(path, "r").catch(() => undefined);
|
||||
if (!file) return false;
|
||||
try {
|
||||
if (!(await file.stat()).isFile()) return false;
|
||||
const head = new Uint8Array(8);
|
||||
const { bytesRead } = await file.read(head, 0, head.length, 0);
|
||||
return isImage(head.subarray(0, bytesRead));
|
||||
} finally { await file.close(); }
|
||||
}
|
||||
|
||||
/** The first string in a tool's answer that names an image file: the materialized screenshot (`path` first). */
|
||||
async function materializedFile(data: unknown): Promise<string | undefined> {
|
||||
const candidates: string[] = [];
|
||||
const walk = (value: unknown, key?: string) => {
|
||||
if (typeof value === "string") { if (key === "path") candidates.unshift(value); else candidates.push(value); }
|
||||
else if (Array.isArray(value)) value.forEach(item => walk(item));
|
||||
else if (value && typeof value === "object") Object.entries(value).forEach(([k, v]) => walk(v, k));
|
||||
};
|
||||
walk(data);
|
||||
for (const candidate of candidates) {
|
||||
if (candidate.startsWith("/") && await imageFile(candidate)) return candidate;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function loadClient(environment: NodeJS.ProcessEnv, clientModule?: string): Promise<ArgentClient> {
|
||||
const module = clientModule ?? join(dirname(await ensureController("argent", { environment })), "client.js");
|
||||
const loaded = await import(pathToFileURL(module).href) as { createArgentClient?: () => ArgentClient };
|
||||
if (typeof loaded.createArgentClient !== "function") throw new Error(`${module} does not export createArgentClient`);
|
||||
return loaded.createArgentClient();
|
||||
}
|
||||
|
||||
/** The in-thread Argent call: the client's `callTool`, with `--out` served from the artifact it materialized. */
|
||||
export function argentClientCall(client: ArgentClient, signal: () => AbortSignal): ArgentCall {
|
||||
return async (tool, args, options) => {
|
||||
const active = signal();
|
||||
if (active.aborted) throw new ArgentCallError(`argent run ${tool} was not sent: the command was given up.`, false);
|
||||
let answer: { data: unknown };
|
||||
try { answer = await client.callTool(tool, args, { signal: AbortSignal.any([active, AbortSignal.timeout(ARGENT_CALL_TIMEOUT_MS)]) }); }
|
||||
catch (error) { throw new ArgentCallError(`argent run ${tool} failed: ${(error instanceof Error ? error.message : String(error)).slice(0, 800)}`, true); }
|
||||
if (!options?.out) return answer.data;
|
||||
const file = await materializedFile(answer.data);
|
||||
if (!file) {
|
||||
const url = (answer.data as { url?: unknown } | null)?.url;
|
||||
if (typeof url !== "string") throw new ArgentCallError(`argent run ${tool} did not write ${options.out}`, true);
|
||||
const response = await fetch(url, { signal: signal() });
|
||||
if (!response.ok) throw new ArgentCallError(`argent run ${tool} did not write ${options.out}: ${response.status}`, true);
|
||||
const body = Buffer.from(await response.arrayBuffer());
|
||||
if (!isImage(body)) throw new ArgentCallError(`argent run ${tool} did not write ${options.out}: the answer is not an image`, true);
|
||||
await mkdir(dirname(options.out), { recursive: true });
|
||||
await writeFile(options.out, body);
|
||||
return { path: options.out };
|
||||
}
|
||||
await mkdir(dirname(options.out), { recursive: true });
|
||||
if (file !== options.out) await copyFile(file, options.out);
|
||||
return { path: options.out };
|
||||
};
|
||||
}
|
||||
|
||||
if (!isMainThread && parentPort && (workerData as Partial<BridgeWorkerData> | null)?.shared instanceof SharedArrayBuffer) {
|
||||
const port = parentPort;
|
||||
const { shared, clientModule } = workerData as BridgeWorkerData;
|
||||
const header = new Int32Array(shared, 0, BRIDGE_HEADER_BYTES / 4);
|
||||
const bytes = new Uint8Array(shared, BRIDGE_HEADER_BYTES);
|
||||
const answer = (id: number, kind: number, text: string) => {
|
||||
let encoded = Buffer.from(text, "utf8");
|
||||
if (encoded.length > bytes.length) {
|
||||
encoded = Buffer.from(JSON.stringify({ exitCode: 1, stdout: JSON.stringify({ success: false,
|
||||
error: { code: "COMMAND_FAILED", message: `The controller's answer (${encoded.length} bytes) exceeds the bridge buffer.` } }) }));
|
||||
}
|
||||
bytes.set(encoded);
|
||||
Atomics.store(header, BRIDGE_SLOT_LENGTH, encoded.length);
|
||||
Atomics.store(header, BRIDGE_SLOT_KIND, kind);
|
||||
Atomics.store(header, BRIDGE_SLOT_READY, id);
|
||||
Atomics.notify(header, BRIDGE_SLOT_READY);
|
||||
};
|
||||
const controllers = new Map<number, AbortController>();
|
||||
let current: AbortController | undefined;
|
||||
const settings = argentBridgeSettings(process.env);
|
||||
const bridge: Promise<ArgentBridge> = settings && settings.toolsUrl
|
||||
? loadClient(process.env, clientModule).then(client => createArgentBridge(settings, argentClientCall(client, () => current?.signal ?? new AbortController().signal), "thread"))
|
||||
: Promise.reject(new Error("The Argent bridge needs EXPLORE_ARGENT_STATE, EXPLORE_ARGENT_PLATFORM and ARGENT_TOOLS_URL."));
|
||||
bridge.catch(() => undefined);
|
||||
let queue: Promise<unknown> = Promise.resolve();
|
||||
port.on("message", (request: BridgeRequest) => {
|
||||
if ("abort" in request) { controllers.get(request.abort)?.abort(new Error("The capture gave up waiting for this command.")); return; }
|
||||
const controller = new AbortController();
|
||||
controllers.set(request.id, controller);
|
||||
queue = queue.then(async () => {
|
||||
current = controller;
|
||||
try {
|
||||
const ready = await bridge.catch(error => { throw Object.assign(error as Error, { unavailable: true }); });
|
||||
if (controller.signal.aborted) throw controller.signal.reason;
|
||||
const result = await ready.run(request.argv);
|
||||
answer(request.id, BRIDGE_KIND_RESULT, JSON.stringify(result));
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
if ((error as { unavailable?: boolean }).unavailable) answer(request.id, BRIDGE_KIND_UNAVAILABLE, message);
|
||||
else answer(request.id, BRIDGE_KIND_RESULT, JSON.stringify({ exitCode: 1, stdout: JSON.stringify({ success: false, error: { code: "COMMAND_FAILED", message } }) }));
|
||||
} finally {
|
||||
controllers.delete(request.id);
|
||||
current = undefined;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* The Argent bridge behind both of its hosts: the command-line worker Explore spawns per command, and the
|
||||
* in-process worker thread that keeps one bridge (and one tool-server connection) for a whole capture. Each command
|
||||
* reads the shared state file, runs through `runBridgeCommand`, and writes the state back, so the two hosts can
|
||||
* take turns on one session.
|
||||
*/
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { appendFile, copyFile, mkdir, readFile, realpath, rename, rm, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import type { DecodedFrame } from "../shared/png-evidence.js";
|
||||
import { runBridgeCommand, type ArgentBridgeState, type ArgentCall, type ArgentPlatform, type ArgentTree, type BridgeResult } from "./argent-driver.js";
|
||||
import { ARGENT_VERSION } from "../shared/argent-version.js";
|
||||
|
||||
export type ArgentBridgeSettings = {
|
||||
environment: NodeJS.ProcessEnv;
|
||||
statePath: string;
|
||||
platform: ArgentPlatform;
|
||||
toolsUrl: string | undefined;
|
||||
};
|
||||
|
||||
/** Reads the settings the bridge takes from its environment; absent when they are incomplete. */
|
||||
export function argentBridgeSettings(environment: NodeJS.ProcessEnv): ArgentBridgeSettings | undefined {
|
||||
const statePath = environment.EXPLORE_ARGENT_STATE;
|
||||
const platform = environment.EXPLORE_ARGENT_PLATFORM;
|
||||
if (!statePath || (platform !== "ios" && platform !== "android")) return undefined;
|
||||
return { environment, statePath, platform, toolsUrl: environment.ARGENT_TOOLS_URL };
|
||||
}
|
||||
|
||||
async function readState(path: string): Promise<ArgentBridgeState> {
|
||||
try { return JSON.parse(await readFile(path, "utf8")) as ArgentBridgeState; }
|
||||
catch { return { generation: 0 }; }
|
||||
}
|
||||
|
||||
/** Written whole and renamed into place, so a command stopped mid-write never leaves a torn state. */
|
||||
async function writeState(path: string, state: ArgentBridgeState): Promise<void> {
|
||||
const temporary = `${path}.${process.pid}.tmp`;
|
||||
await writeFile(temporary, JSON.stringify(state), { mode: 0o600 });
|
||||
await rename(temporary, path);
|
||||
}
|
||||
|
||||
/** A call's arguments for the debug log: text that could be typed into a field is logged by length only. */
|
||||
function loggedArgs(args: Record<string, unknown>): Record<string, unknown> {
|
||||
return Object.fromEntries(Object.entries(args).map(([key, value]) => key === "text" && typeof value === "string" ? [key, `<${value.length} characters>`]
|
||||
: key === "steps" && Array.isArray(value) ? [key, `<${value.length} steps>`] : [key, value]));
|
||||
}
|
||||
|
||||
/** What a call answered, for the debug log: a tree's shape, not its contents. */
|
||||
function summarize(tool: string, value: unknown): unknown {
|
||||
if (!value || typeof value !== "object") return value;
|
||||
if (tool !== "ui-tree") return Object.keys(value);
|
||||
const tree = value as ArgentTree;
|
||||
let nodes = 0;
|
||||
const walk = (node: { children?: unknown[] }) => { nodes++; (node.children ?? []).forEach(child => walk(child as { children?: unknown[] })); };
|
||||
(tree.roots ?? []).forEach(walk);
|
||||
return { foregroundApp: tree.foregroundApp, alertVisible: tree.alertVisible, keyboardVisible: tree.keyboardVisible, truncated: tree.truncated,
|
||||
screen: tree.screen, nodes, roots: (tree.roots ?? []).map(root => [root.type ?? null, root.bundleId ?? null, (root.children ?? []).length]) };
|
||||
}
|
||||
|
||||
export type ArgentBridge = {
|
||||
/** Runs one agent-device-shaped command against the session. */
|
||||
run(argv: readonly string[]): Promise<BridgeResult>;
|
||||
};
|
||||
|
||||
/**
|
||||
* One bridge over the given Argent call. `host` names the process running it in the debug log.
|
||||
*/
|
||||
export function createArgentBridge(settings: ArgentBridgeSettings, call: ArgentCall, host: "process" | "thread"): ArgentBridge {
|
||||
const { environment, statePath, platform, toolsUrl } = settings;
|
||||
const logPath = environment.EXPLORE_ARGENT_LOG_DIR
|
||||
? join(environment.EXPLORE_ARGENT_LOG_DIR, `argent-${platform}-${environment.EXPLORE_ARGENT_LOG_NAME ?? "bridge"}.jsonl`) : undefined;
|
||||
return {
|
||||
async run(argv) {
|
||||
// EXPLORE_ARGENT_LOG_DIR (opt-in): every Argent call this bridge makes, how long it took, and the shape of what it read.
|
||||
const log = async (entry: Record<string, unknown>) => {
|
||||
if (!logPath) return;
|
||||
await appendFile(logPath, `${JSON.stringify({ at: new Date().toISOString(), host, command: argv[0], ...entry })}\n`, { mode: 0o600 }).catch(() => undefined);
|
||||
};
|
||||
const state = await readState(statePath);
|
||||
const result = await runBridgeCommand(argv, {
|
||||
state, platform, version: ARGENT_VERSION,
|
||||
...(environment.EXPLORE_ARGENT_BUNDLE_ID ? { bundleId: environment.EXPLORE_ARGENT_BUNDLE_ID } : {}),
|
||||
...(environment.EXPLORE_ARGENT_DEVICE ? { device: environment.EXPLORE_ARGENT_DEVICE } : {}),
|
||||
// An opened foldable's inner panel shows its UI in landscape (Argent's fold: "Unfolded, the UI is landscape").
|
||||
...(platform === "ios" && ["open", "half-open"].includes(environment.EXPLORE_ARGENT_POSE ?? "") ? { landscape: true } : {}),
|
||||
call: async (tool, args, options) => {
|
||||
const started = Date.now();
|
||||
try {
|
||||
const value = await call(tool, args, options);
|
||||
await log({ tool, args: loggedArgs(args), ms: Date.now() - started, summary: summarize(tool, value) });
|
||||
return value;
|
||||
} catch (error) {
|
||||
await log({ tool, args: loggedArgs(args), ms: Date.now() - started, error: (error instanceof Error ? error.message : String(error)).slice(0, 400) });
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
reachable: async () => {
|
||||
let ok = false;
|
||||
try {
|
||||
const token = environment.ARGENT_AUTH_TOKEN;
|
||||
// The same URL Argent's own client checks: ARGENT_TOOLS_URL may carry a path, which /tools is appended to.
|
||||
const response = await fetch(`${(toolsUrl ?? "").replace(/\/+$/, "")}/tools`, { headers: token ? { authorization: `Bearer ${token}` } : {}, signal: AbortSignal.timeout(5_000) });
|
||||
await response.body?.cancel();
|
||||
ok = response.status < 500;
|
||||
} catch { ok = false; }
|
||||
if (!ok) await log({ tool: "reachable", ok });
|
||||
return ok;
|
||||
},
|
||||
sleep: milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)),
|
||||
orientVideo: async path => {
|
||||
const probed = spawnSync("ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height", "-of", "csv=p=0:s=x", path], { encoding: "utf8", timeout: 30_000 });
|
||||
const [width, height] = (probed.stdout ?? "").trim().split("x").map(Number);
|
||||
if (probed.status !== 0 || !width || !height || width >= height) return;
|
||||
const turned = `${path}.upright.mp4`;
|
||||
const ffmpeg = spawnSync("ffmpeg", ["-nostdin", "-y", "-loglevel", "error", "-i", path, "-vf", "transpose=clock", "-an", turned], { encoding: "utf8", timeout: 120_000 });
|
||||
if (ffmpeg.status === 0) await rename(turned, path);
|
||||
else await rm(turned, { force: true });
|
||||
},
|
||||
scratchImage: { path: join(dirname(statePath), "argent-scratch.png"), read: async path => {
|
||||
const { PNG } = createRequire(import.meta.url)("pngjs") as { PNG: { sync: { read(bytes: Buffer, options: { checkCRC: boolean }): DecodedFrame } } };
|
||||
return PNG.sync.read(await readFile(path), { checkCRC: false });
|
||||
} },
|
||||
moveFile: async (from, to) => {
|
||||
const source = await realpath(from);
|
||||
const roots = await Promise.all([environment.HOME, process.cwd()].filter((root): root is string => !!root).map(root => realpath(root).catch(() => root)));
|
||||
if (!roots.some(root => source.startsWith(`${root}/`))) throw new Error(`Argent returned a recording outside its own directories: ${from}`);
|
||||
await mkdir(dirname(to), { recursive: true });
|
||||
try { await rename(from, to); }
|
||||
catch { await copyFile(from, to); await rm(from, { force: true }); }
|
||||
},
|
||||
});
|
||||
await writeState(statePath, state);
|
||||
await log({ result: result.exitCode === 0 ? "ok" : result.stdout.slice(0, 300) });
|
||||
return result;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -2,71 +2,30 @@
|
||||
* The Argent controller's command line: Explore runs it where it would run agent-device, with the same
|
||||
* arguments. Each command becomes `argent run <tool> --args <json>` calls, as EAS Simulator recommends
|
||||
* driving an `argent` session, with the session's ARGENT_TOOLS_URL and ARGENT_AUTH_TOKEN in the environment.
|
||||
* A capture keeps the same bridge on a worker thread instead (argent-bridge-host); this entry serves the callers
|
||||
* that run one command at a time.
|
||||
*/
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { appendFile, copyFile, mkdir, readFile, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import type { DecodedFrame } from "../shared/png-evidence.js";
|
||||
import { ArgentCallError, runBridgeCommand, type ArgentBridgeState, type ArgentPlatform, type ArgentTree } from "./argent-driver.js";
|
||||
import { ARGENT_VERSION } from "../shared/argent-version.js";
|
||||
import { stat } from "node:fs/promises";
|
||||
import { ArgentCallError } from "./argent-driver.js";
|
||||
import { argentBridgeSettings, createArgentBridge } from "./argent-bridge.js";
|
||||
import { ensureController } from "../shared/controller-cache.js";
|
||||
|
||||
const ARGENT_CALL_TIMEOUT_MS = 180_000;
|
||||
|
||||
async function readState(path: string): Promise<ArgentBridgeState> {
|
||||
try { return JSON.parse(await readFile(path, "utf8")) as ArgentBridgeState; }
|
||||
catch { return { generation: 0 }; }
|
||||
}
|
||||
|
||||
/** Written whole and renamed into place, so a command stopped mid-write never leaves a torn state. */
|
||||
async function writeState(path: string, state: ArgentBridgeState): Promise<void> {
|
||||
const temporary = `${path}.${process.pid}.tmp`;
|
||||
await writeFile(temporary, JSON.stringify(state), { mode: 0o600 });
|
||||
await rename(temporary, path);
|
||||
}
|
||||
|
||||
/** A call's arguments for the debug log: text that could be typed into a field is logged by length only. */
|
||||
function loggedArgs(args: Record<string, unknown>): Record<string, unknown> {
|
||||
return Object.fromEntries(Object.entries(args).map(([key, value]) => key === "text" && typeof value === "string" ? [key, `<${value.length} characters>`]
|
||||
: key === "steps" && Array.isArray(value) ? [key, `<${value.length} steps>`] : [key, value]));
|
||||
}
|
||||
|
||||
/** What a call answered, for the debug log: a tree's shape, not its contents. */
|
||||
function summarize(tool: string, value: unknown): unknown {
|
||||
if (!value || typeof value !== "object") return value;
|
||||
if (tool !== "ui-tree") return Object.keys(value);
|
||||
const tree = value as ArgentTree;
|
||||
let nodes = 0;
|
||||
const walk = (node: { children?: unknown[] }) => { nodes++; (node.children ?? []).forEach(child => walk(child as { children?: unknown[] })); };
|
||||
(tree.roots ?? []).forEach(walk);
|
||||
return { foregroundApp: tree.foregroundApp, alertVisible: tree.alertVisible, keyboardVisible: tree.keyboardVisible, truncated: tree.truncated,
|
||||
screen: tree.screen, nodes, roots: (tree.roots ?? []).map(root => [root.type ?? null, root.bundleId ?? null, (root.children ?? []).length]) };
|
||||
}
|
||||
|
||||
async function main(): Promise<number> {
|
||||
const environment = process.env;
|
||||
const statePath = environment.EXPLORE_ARGENT_STATE;
|
||||
const platform = environment.EXPLORE_ARGENT_PLATFORM as ArgentPlatform | undefined;
|
||||
const toolsUrl = environment.ARGENT_TOOLS_URL;
|
||||
if (!statePath || (platform !== "ios" && platform !== "android")) {
|
||||
const settings = argentBridgeSettings(environment);
|
||||
if (!settings) {
|
||||
process.stdout.write(JSON.stringify({ success: false, error: { code: "INVALID_ARGS", message: "The Argent controller needs EXPLORE_ARGENT_STATE and EXPLORE_ARGENT_PLATFORM." } }));
|
||||
return 1;
|
||||
}
|
||||
const argv = process.argv.slice(2);
|
||||
if (argv[0] !== "--version" && !toolsUrl) {
|
||||
if (argv[0] !== "--version" && !settings.toolsUrl) {
|
||||
// Without a URL the Argent client would start a local tool-server; Explore only drives the session's own.
|
||||
process.stdout.write(JSON.stringify({ success: false, error: { code: "INVALID_ARGS", message: "ARGENT_TOOLS_URL is not set for the Argent controller." } }));
|
||||
return 1;
|
||||
}
|
||||
// EXPLORE_ARGENT_LOG_DIR (opt-in): every Argent call this bridge makes, how long it took, and the shape of what it read.
|
||||
const logPath = environment.EXPLORE_ARGENT_LOG_DIR
|
||||
? join(environment.EXPLORE_ARGENT_LOG_DIR, `argent-${platform}-${environment.EXPLORE_ARGENT_LOG_NAME ?? "bridge"}.jsonl`) : undefined;
|
||||
const log = async (entry: Record<string, unknown>) => {
|
||||
if (!logPath) return;
|
||||
await appendFile(logPath, `${JSON.stringify({ at: new Date().toISOString(), command: argv[0], ...entry })}\n`, { mode: 0o600 }).catch(() => undefined);
|
||||
};
|
||||
const state = await readState(statePath);
|
||||
let cli: string;
|
||||
try { cli = argv[0] === "--version" ? "" : await ensureController("argent", { environment, progress: message => process.stderr.write(`[explore] ${message}\n`) }); }
|
||||
catch (error) {
|
||||
@@ -93,65 +52,9 @@ async function main(): Promise<number> {
|
||||
catch { throw new ArgentCallError(`argent run ${tool} did not answer with JSON`, true); }
|
||||
};
|
||||
|
||||
const result = await runBridgeCommand(argv, {
|
||||
state, platform, version: ARGENT_VERSION,
|
||||
...(environment.EXPLORE_ARGENT_BUNDLE_ID ? { bundleId: environment.EXPLORE_ARGENT_BUNDLE_ID } : {}),
|
||||
...(environment.EXPLORE_ARGENT_DEVICE ? { device: environment.EXPLORE_ARGENT_DEVICE } : {}),
|
||||
// An opened foldable's inner panel shows its UI in landscape (Argent's fold: "Unfolded, the UI is landscape").
|
||||
...(platform === "ios" && ["open", "half-open"].includes(environment.EXPLORE_ARGENT_POSE ?? "") ? { landscape: true } : {}),
|
||||
call: async (tool, args, options) => {
|
||||
const started = Date.now();
|
||||
try {
|
||||
const value = await callArgent(tool, args, options);
|
||||
await log({ tool, args: loggedArgs(args), ms: Date.now() - started, summary: summarize(tool, value) });
|
||||
return value;
|
||||
} catch (error) {
|
||||
await log({ tool, args: loggedArgs(args), ms: Date.now() - started, error: (error instanceof Error ? error.message : String(error)).slice(0, 400) });
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
reachable: async () => {
|
||||
let ok = false;
|
||||
try {
|
||||
const token = environment.ARGENT_AUTH_TOKEN;
|
||||
// The same URL Argent's own client checks: ARGENT_TOOLS_URL may carry a path, which /tools is appended to.
|
||||
const response = await fetch(`${(toolsUrl ?? "").replace(/\/+$/, "")}/tools`, { headers: token ? { authorization: `Bearer ${token}` } : {}, signal: AbortSignal.timeout(5_000) });
|
||||
await response.body?.cancel();
|
||||
ok = response.status < 500;
|
||||
} catch { ok = false; }
|
||||
if (!ok) await log({ tool: "reachable", ok });
|
||||
return ok;
|
||||
},
|
||||
sleep: milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)),
|
||||
orientVideo: async path => {
|
||||
// Turned with ffmpeg, which observing a launch needs anyway; without it the recording is left as it is.
|
||||
const probed = spawnSync("ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height", "-of", "csv=p=0:s=x", path], { encoding: "utf8", timeout: 30_000 });
|
||||
const [width, height] = (probed.stdout ?? "").trim().split("x").map(Number);
|
||||
if (probed.status !== 0 || !width || !height || width >= height) return;
|
||||
const turned = `${path}.upright.mp4`;
|
||||
const ffmpeg = spawnSync("ffmpeg", ["-nostdin", "-y", "-loglevel", "error", "-i", path, "-vf", "transpose=clock", "-an", turned], { encoding: "utf8", timeout: 120_000 });
|
||||
if (ffmpeg.status === 0) await rename(turned, path);
|
||||
else await rm(turned, { force: true });
|
||||
},
|
||||
scratchImage: { path: join(dirname(statePath), "argent-scratch.png"), read: async path => {
|
||||
const { PNG } = createRequire(import.meta.url)("pngjs") as { PNG: { sync: { read(bytes: Buffer, options: { checkCRC: boolean }): DecodedFrame } } };
|
||||
return PNG.sync.read(await readFile(path), { checkCRC: false });
|
||||
} },
|
||||
moveFile: async (from, to) => {
|
||||
// Argent's client downloads a recording under its HOME or the working directory; nothing else is moved.
|
||||
const source = await realpath(from);
|
||||
const roots = await Promise.all([environment.HOME, process.cwd()].filter((root): root is string => !!root).map(root => realpath(root).catch(() => root)));
|
||||
if (!roots.some(root => source.startsWith(`${root}/`))) throw new Error(`Argent returned a recording outside its own directories: ${from}`);
|
||||
await mkdir(dirname(to), { recursive: true });
|
||||
try { await rename(from, to); }
|
||||
catch { await copyFile(from, to); await rm(from, { force: true }); }
|
||||
},
|
||||
});
|
||||
await writeState(statePath, state);
|
||||
await log({ result: result.exitCode === 0 ? "ok" : result.stdout.slice(0, 300) });
|
||||
const result = await createArgentBridge(settings, callArgent, "process").run(argv);
|
||||
process.stdout.write(result.stdout);
|
||||
return result.exitCode;
|
||||
}
|
||||
|
||||
process.exitCode = await main();
|
||||
|
||||
@@ -14,20 +14,25 @@ export function defaultRunner(request: CommandRequest): CommandResult {
|
||||
...(request.timeoutMs ? { timeout: request.timeoutMs } : {}),
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
return commandOutcome(request, { status: result.status, stdout: result.stdout ?? "", stderr: result.stderr ?? "" });
|
||||
}
|
||||
|
||||
/** A finished command's output, or the error its exit status and output describe. */
|
||||
export function commandOutcome(request: CommandRequest, result: { status: number | null; stdout: string; stderr: string }): CommandResult {
|
||||
if (result.status !== 0 && !request.allowFailure) {
|
||||
const sessionIndex = request.args.indexOf("--session");
|
||||
// Our own session or a caller's session attached by explore:session: both answer --json failures with a structured error.
|
||||
const structuredFailure = (sessionIndex >= 0 && request.args[sessionIndex + 1] === CONTROLLER_SESSION) || request.args.includes("--json")
|
||||
? controllerCommandFailure(result.stdout ?? "", request.args[0] ?? "command") : undefined;
|
||||
? controllerCommandFailure(result.stdout, request.args[0] ?? "command") : undefined;
|
||||
if (structuredFailure) throw structuredFailure;
|
||||
const subcommand = typeof request.args[0] === "string" ? ` ${request.args[0]}` : "";
|
||||
const detail = failureDetail(`${result.stderr ?? ""}\n${result.stdout ?? ""}`);
|
||||
const detail = failureDetail(`${result.stderr}\n${result.stdout}`);
|
||||
throw new Error(
|
||||
`${request.command}${subcommand} exited with status ${result.status ?? "unknown"}`
|
||||
+ (detail ? `: ${detail}` : ""),
|
||||
);
|
||||
}
|
||||
return { stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
|
||||
return { stdout: result.stdout, stderr: result.stderr };
|
||||
}
|
||||
|
||||
/** Keep the CLI tool host responsive while a remote controller request is in flight. */
|
||||
|
||||
+47
-13
@@ -1,4 +1,4 @@
|
||||
import { appearanceArgs, argentColorSchemes, bundleColorSchemes, mergeSchemeOutcomes, resolveColorSchemes, routeIdOfScreen, type AppearanceSetting, type ColorScheme } from "./appearance.js";
|
||||
import { appearanceArgs, argentColorSchemes, bundleColorSchemes, mergeSchemeOutcomes, resolveColorSchemes, routeIdOfScreen, schemeScreenId, type AppearanceSetting, type ColorScheme } from "./appearance.js";
|
||||
import { assertNoCaptureHealthIssues, captureHealthIssues, partitionCaptureHealthIssues } from "./health.js";
|
||||
import { type RouteResetSetting } from "./route-reset.js";
|
||||
import { defaultReadinessSeconds } from "./readiness.js";
|
||||
@@ -24,6 +24,7 @@ import { silentProgress, type Progress } from "../shared/progress.js";
|
||||
import { assertCaptureEasProfile, assertSimulatorAvailable, fingerprintFrom, hasEasEnvironmentFetchFailure, nativeBuildFrom, existingBuild, repackProfileFrom, prepareExactSourceBuild, type RepackMode } from "./eas-build.js";
|
||||
import { SIMULATOR_DOTENV_FILE_NAME, SIMULATOR_DOTENV_HEADER, endedOwnSimulatorSession, liveSimulatorSessionsNamed, simulatorSessionName, simulatorStartFailure, readSimulatorDotenvHandoff, assertSimulatorSessionIdentity, assertSimulatorStopped, collectRuntime, controllerVersion, simulatorOsVersion, type ActiveSimulatorRuntime, type SimulatorConnection } from "./simulator.js";
|
||||
import { argentControllerInvocation } from "./controller-invocation.js";
|
||||
import { startArgentBridgeRunner, type ArgentBridgeRunner } from "./argent-bridge-host.js";
|
||||
import { sharedBuild } from "./shared-build.js";
|
||||
import { LOCAL_EMULATOR_STATE_PREFIX, LOCAL_SIMULATOR_STATE_PREFIX, agentDeviceClaims, assertLocalEmulatorCompatible, createLocalSimulator, startLocalEmulator, waitForLocalEmulator, waitForLocalSimulator, deleteLocalEmulator,
|
||||
deleteLocalSimulator, hostEmulatorAbi, installOnLocalEmulator, installOnLocalSimulator, approveLinkScheme, localPoseShown,
|
||||
@@ -72,6 +73,12 @@ export type CiMapOptions = {
|
||||
buildShare?: string;
|
||||
/** Which appearances to capture; `auto` (default) follows the app's `userInterfaceStyle`. */
|
||||
appearance?: AppearanceSetting;
|
||||
/**
|
||||
* One session's share of the appearance passes when a side splits them across sessions: `capture` names the passes
|
||||
* this run makes, out of the `all` it would make alone, so frames keep the ids of a single run (`<id>@dark`) and the
|
||||
* exports merge. Absent: every resolved appearance.
|
||||
*/
|
||||
appearancePass?: { all: readonly ColorScheme[]; capture: readonly ColorScheme[] };
|
||||
/** Whether to observe the app launch (splash screen) per appearance; `video` also keeps the recording. Defaults to `off`. */
|
||||
launch?: LaunchSetting;
|
||||
/** Decodes launch recordings; defaults to ffmpeg when installed. */
|
||||
@@ -218,7 +225,7 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
});
|
||||
const routes = inventory.filter(route => selected.has(route.id));
|
||||
const setup = revisionSetup(options.setup ?? [], plan, side);
|
||||
const runner = options.runner ?? defaultRunner;
|
||||
let runner = options.runner ?? defaultRunner;
|
||||
const sourceEnvironment = options.environment ?? process.env;
|
||||
const controller = options.controller ?? "agent-device";
|
||||
const local = options.simulator === "local";
|
||||
@@ -353,7 +360,11 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
let captureFailure: unknown;
|
||||
const finish = async (): Promise<CiMapResult> => {
|
||||
if (!(await store.exists())) await store.initialize(map, false);
|
||||
const incomplete = captureFailure !== undefined || selectedIds.some(id => outcomes[id]?.status !== "captured" || outcomes[id]?.landing !== "verified")
|
||||
// A session making only secondary passes owns the `<id>@<scheme>` frames of those passes, not the primary ones.
|
||||
const ownFrameIds = options.appearancePass && !options.appearancePass.capture.includes(colorSchemes[0]!)
|
||||
? selectedIds.flatMap(id => colorSchemes.filter(scheme => options.appearancePass!.capture.includes(scheme)).map(scheme => schemeScreenId(id, scheme)))
|
||||
: selectedIds;
|
||||
const incomplete = captureFailure !== undefined || ownFrameIds.some(id => outcomes[id]?.status !== "captured" || outcomes[id]?.landing !== "verified")
|
||||
|| map.gaps.some(gap => gap.status === "open");
|
||||
map.run.status = incomplete || map.screens.length === 0 ? "partial" : "complete";
|
||||
if (routes.length === 0) map.run.stopReason = "No source targets require capture.";
|
||||
@@ -422,7 +433,9 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
if (options.agent) assertAgentAcceptance(bundle, map, { required: true });
|
||||
// The side that produces the evidence checks it the way the review will: an integrity defect fails here, naming
|
||||
// its codes, instead of on the consuming side after both captures. Unavailable screens are not defects.
|
||||
assertNoCaptureHealthIssues(partitionCaptureHealthIssues(captureHealthIssues(bundle, selectedIds)).integrity);
|
||||
// A session capturing only a secondary appearance has no primary frames by design; the merged export is checked instead.
|
||||
const partialPass = options.appearancePass !== undefined && !options.appearancePass.capture.includes(colorSchemes[0]!);
|
||||
if (!partialPass) assertNoCaptureHealthIssues(partitionCaptureHealthIssues(captureHealthIssues(bundle, selectedIds)).integrity);
|
||||
await writeFile(join(outputDirectory, "bundle.json"), `${JSON.stringify(bundle, null, 2)}\n`, { flag: "wx" });
|
||||
if (metadata) await writeFile(join(outputDirectory, "execution.json"), `${JSON.stringify(metadata, null, 2)}\n`, { flag: "wx" });
|
||||
assertCheckout();
|
||||
@@ -481,6 +494,7 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
let localOsVersion: string | undefined;
|
||||
// Argent's tool-server on this machine, when Argent drives a local device.
|
||||
let localArgent: LocalArgentServer | undefined;
|
||||
let argentBridge: ArgentBridgeRunner | undefined;
|
||||
const localDevice = () => localSimulator ?? localEmulator;
|
||||
// A local device starts booting now and finishes while the app is built and repacked; the session waits for it.
|
||||
let localEmulatorStart: Awaited<ReturnType<typeof startLocalEmulator>> | undefined;
|
||||
@@ -563,7 +577,8 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
const appDirectory = !options.buildShare ? await realpath(await mkdtemp(join(tmpdir(), "expo-explore-app-"))) : undefined;
|
||||
let localApp: string | undefined;
|
||||
type BuiltApp = { fingerprint: string; nativeEasBuildId: string | null; easBuildId: string | null; app?: string; reused: boolean; version?: string; buildNumber?: string };
|
||||
const buildApp = async (keepApp: string): Promise<BuiltApp> => {
|
||||
// `repacking` tells the captures sharing this build that their sessions can start too (sharedBuild).
|
||||
const buildApp = async (keepApp: string, repacking?: () => Promise<void>): Promise<BuiltApp> => {
|
||||
options.signal?.throwIfAborted();
|
||||
say("computing the native fingerprint");
|
||||
const fingerprintResult = eas(["fingerprint:generate", "--platform", options.platform, "--build-profile", options.easProfile, "--json", "--non-interactive"]);
|
||||
@@ -573,7 +588,7 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
"--fingerprint-hash", sourceFingerprint, ...(options.platform === "ios" ? ["--simulator"] : []), "--limit", "1", "--json", "--non-interactive"]).stdout);
|
||||
if (reusable) {
|
||||
say(`reusing EAS build ${reusable.id} (fingerprint ${sourceFingerprint.slice(0, 12)}); repacking it with this commit's JavaScript and the route observer`);
|
||||
startSession();
|
||||
startSession(); await repacking?.();
|
||||
const repacked = await prepareExactSourceBuild({ platform: options.platform, runner, easCommand: options.easCommand, repackCommand: options.repackCommand,
|
||||
project, nativeBuildId: reusable.id, fingerprint: sourceFingerprint, repackProfile: profile, easEnvironment, repackEnvironment: restrictedEnvironment, routes: inventory, repack: options.repack, easProfile: options.easProfile, keepApp });
|
||||
if (!repacked) throw new CiError({ code: "CAPTURE_OBSERVER_BUILD_UNSUPPORTED", stage: "instrumentation",
|
||||
@@ -587,7 +602,7 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
: `no finished simulator build has fingerprint ${sourceFingerprint.slice(0, 12)}; building on EAS and waiting for it to finish`);
|
||||
const built = nativeBuildFrom(eas(["build", "--platform", options.platform, "--profile", options.easProfile, "--wait", "--json", "--non-interactive"], 45 * 60_000).stdout);
|
||||
say(`EAS build ${built.id} finished; repacking it with the route observer`);
|
||||
startSession();
|
||||
startSession(); await repacking?.();
|
||||
const repacked = await prepareExactSourceBuild({ platform: options.platform, runner, easCommand: options.easCommand, repackCommand: options.repackCommand,
|
||||
project, nativeBuildId: built.id, fingerprint: built.fingerprint, repackProfile: profile, easEnvironment, repackEnvironment: restrictedEnvironment, routes: inventory, repack: options.repack, easProfile: options.easProfile, keepApp });
|
||||
if (!repacked) throw new CiError({ code: "CAPTURE_OBSERVER_BUILD_UNSUPPORTED", stage: "instrumentation",
|
||||
@@ -603,9 +618,11 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
? await sharedBuild({ directory: options.buildShare, appName, ...(options.signal ? { signal: options.signal } : {}), build: buildApp, owner: options.outputDirectory,
|
||||
key: { platform: options.platform, easProfile: options.easProfile, bundleId: options.bundleId, gitCommit: options.gitCommit, repack: options.repack ?? "eas", local,
|
||||
routes: inventory.map(route => route.id) },
|
||||
waiting: () => say("using the build another target of this review is preparing for this commit") })
|
||||
waiting: () => say("using the build another target of this review is preparing for this commit"),
|
||||
// The session is named before its app exists, so a waiter's session boots while the other capture repacks.
|
||||
repacking: () => startSession() })
|
||||
: await buildApp(join(appDirectory!, appName));
|
||||
// A capture that used another target's build starts its session now.
|
||||
// A capture that used another capture's build has its session started above; this starts the rest.
|
||||
startSession();
|
||||
fingerprint = built.fingerprint; nativeEasBuildId = built.nativeEasBuildId; easBuildId = built.easBuildId; localApp = built.app; reusedEasBuild = built.reused;
|
||||
if (!app.version && built.version) app.version = built.version;
|
||||
@@ -756,6 +773,11 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
AGENT_DEVICE_SESSION: CONTROLLER_SESSION, AGENT_DEVICE_SESSION_LOCK: "reject", AGENT_DEVICE_PLATFORM: options.platform };
|
||||
// Every controller call below goes to the session's controller; for Argent that is the bridge.
|
||||
const controllerCommand = argent?.command ?? options.agentDeviceCommand;
|
||||
// The capture's commands keep one bridge on a worker thread (EXPLORE_ARGENT_BRIDGE=process: one process per command, as before).
|
||||
if (argent && !options.runner && sourceEnvironment.EXPLORE_ARGENT_BRIDGE !== "process") {
|
||||
argentBridge = startArgentBridgeRunner({ command: argent.command, environment: argent.environment, fallback: defaultRunner, progress: say });
|
||||
runner = argentBridge.runner;
|
||||
}
|
||||
if (!local && localApp) {
|
||||
// The session started empty while the app was repacked; the controller installs it now.
|
||||
say(`installing the app on session ${sessionId}`);
|
||||
@@ -914,7 +936,10 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
// Every pass sets the appearance explicitly, so a capture does not inherit whatever the simulator last used.
|
||||
const passes: CaptureBundle["outcomes"][] = [];
|
||||
const recordingTools = launchSetting === "off" ? undefined : options.recordingTools === undefined ? ffmpegRecordingTools() : options.recordingTools ?? undefined;
|
||||
const capturedSchemes = options.appearancePass ? colorSchemes.filter(scheme => options.appearancePass!.capture.includes(scheme)) : colorSchemes;
|
||||
for (const [index, colorScheme] of colorSchemes.entries()) {
|
||||
// A pass another session makes leaves its slot empty, so the passes stay aligned with the appearances they merge by.
|
||||
if (!capturedSchemes.includes(colorScheme)) { passes.push({}); continue; }
|
||||
// Argent cannot switch the appearance yet (software-mansion/argent#1509): the host does, simctl or adb on this
|
||||
// machine and serve-sim on an EAS iOS session; elsewhere its single pass runs as the device starts.
|
||||
if (controller !== "argent") runner({ command: controllerCommand, args: [...appearanceArgs(colorScheme), "--session", CONTROLLER_SESSION, ...deviceArgs(runtime), "--platform", options.platform],
|
||||
@@ -944,16 +969,22 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
...deviceArgs(runtime), "--platform", options.platform, "--level", "full", "--json"], cwd: simulatorProject, environment: controllerEnvironment, timeoutMs: 60_000 });
|
||||
runtime.colorScheme = colorScheme;
|
||||
if (colorSchemes.length > 1) say(`appearance ${colorScheme} (${index + 1}/${colorSchemes.length})`);
|
||||
passes.push(await capturePlannedRoutes({ capture: { ...options, agentDeviceCommand: controllerCommand, setup, progress: say }, routes: missingRoutes, inventory, scheme, appName: app.name, runtime,
|
||||
passes.push(await capturePlannedRoutes({ capture: { ...options, ...(argentBridge && !options.agent ? { runner: argentBridge.runner } : {}), agentDeviceCommand: controllerCommand, setup, progress: say }, routes: missingRoutes, inventory, scheme, appName: app.name, runtime,
|
||||
connection, environment: controllerEnvironment, store, map, acceptedFrames, outcomes: index === 0 ? outcomes : {},
|
||||
...(colorSchemes.length > 1 ? { appearance: { scheme: colorScheme, primary: index === 0 } } : {}) }));
|
||||
}
|
||||
runtime.colorScheme = colorSchemes[0]!;
|
||||
Object.assign(outcomes, mergeSchemeOutcomes(passes, colorSchemes));
|
||||
// A session without the primary pass keeps each outcome as its pass recorded it, under `<id>@<scheme>`: the export
|
||||
// merge recombines them with the primary pass's (mergeSchemeOutcomes), which only then can tell an unattributed
|
||||
// frame beside a primary one from a lost route.
|
||||
if (options.appearancePass && !capturedSchemes.includes(colorSchemes[0]!)) {
|
||||
for (const [index, pass] of passes.entries()) for (const [id, outcome] of Object.entries(pass)) outcomes[schemeScreenId(id, colorSchemes[index])] = outcome;
|
||||
} else Object.assign(outcomes, mergeSchemeOutcomes(passes, colorSchemes));
|
||||
} catch (error) { primaryError = toCiError(error, { code: `CAPTURE_${runtimeStage.toUpperCase()}_FAILED`, stage: runtimeStage,
|
||||
nextAction: "Inspect the capture diagnostic, correct the failing prerequisite, and rerun Explore." }); }
|
||||
finally {
|
||||
if (appDirectory) await rm(appDirectory, { recursive: true, force: true });
|
||||
argentBridge?.close();
|
||||
if (localArgent) stopLocalArgentServer(localArgent);
|
||||
if (localEmulator) {
|
||||
try {
|
||||
@@ -1017,7 +1048,10 @@ async function executeCiMap(options: CiMapOptions, setStage: (stage: string) =>
|
||||
throw primaryError;
|
||||
}
|
||||
setStage("export");
|
||||
const captured = selectedIds.filter(id => outcomes[id]?.status === "captured").length;
|
||||
say(`${captured} of ${selectedIds.length} ${selectedIds.length === 1 ? "route" : "routes"} captured`);
|
||||
const ownSchemes = options.appearancePass && !options.appearancePass.capture.includes(colorSchemes[0]!)
|
||||
? colorSchemes.filter(scheme => options.appearancePass!.capture.includes(scheme)) : undefined;
|
||||
const captured = selectedIds.filter(id => ownSchemes
|
||||
? ownSchemes.every(scheme => outcomes[schemeScreenId(id, scheme)]?.status === "captured") : outcomes[id]?.status === "captured").length;
|
||||
say(`${captured} of ${selectedIds.length} ${selectedIds.length === 1 ? "route" : "routes"} captured${ownSchemes ? ` in ${ownSchemes.join(", ")}` : ""}`);
|
||||
return finish();
|
||||
}
|
||||
@@ -19,21 +19,23 @@ const POLL_MS = 2_000;
|
||||
|
||||
/**
|
||||
* Runs `build` once per key across every capture sharing `directory`; the app it leaves goes in the build's folder
|
||||
* (`keepApp`), which outlives each capture. A waiter is told so it can say whose build it uses.
|
||||
* (`keepApp`), which outlives each capture. A waiter is told so it can say whose build it uses, and told again
|
||||
* (`repacking`) once the builder calls its `repacking` (the native build is known and is being repacked), or the
|
||||
* build is done: a waiter starts its session then, not while a native build may run for most of an hour.
|
||||
*/
|
||||
export async function sharedBuild<T extends object>(options: { directory: string; key: SharedBuildKey; appName: string; signal?: AbortSignal;
|
||||
build: (keepApp: string) => Promise<T>; waiting?: () => void;
|
||||
build: (keepApp: string, repacking: () => Promise<void>) => Promise<T>; waiting?: () => void; repacking?: () => void;
|
||||
/** Who builds it (the capture's output directory), so a review can fail its waiters if that capture dies (abandonSharedBuilds). */
|
||||
owner?: string }): Promise<T> {
|
||||
const folder = join(options.directory, sharedBuildId(options.key));
|
||||
const result = join(folder, "result.json"), failure = join(folder, "failure.json");
|
||||
const result = join(folder, "result.json"), failure = join(folder, "failure.json"), repack = join(folder, "repacking");
|
||||
await mkdir(options.directory, { recursive: true });
|
||||
let owner = true;
|
||||
try { await mkdir(folder); } catch (error) { if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error; owner = false; }
|
||||
if (owner) {
|
||||
if (options.owner) await writeFile(join(folder, "owner"), options.owner);
|
||||
try {
|
||||
const built = await options.build(join(folder, options.appName));
|
||||
const built = await options.build(join(folder, options.appName), () => writeFile(repack, "").catch(() => undefined));
|
||||
await writeFile(`${result}.tmp`, JSON.stringify(built));
|
||||
await rename(`${result}.tmp`, result);
|
||||
return built;
|
||||
@@ -44,9 +46,11 @@ export async function sharedBuild<T extends object>(options: { directory: string
|
||||
}
|
||||
}
|
||||
options.waiting?.();
|
||||
let repackSeen = false;
|
||||
for (;;) {
|
||||
options.signal?.throwIfAborted();
|
||||
const done = await readFile(result, "utf8").catch(() => undefined);
|
||||
if (!repackSeen && (done !== undefined || existsSync(repack))) { repackSeen = true; options.repacking?.(); }
|
||||
if (done !== undefined) return JSON.parse(done) as T;
|
||||
const failed = await readFile(failure, "utf8").catch(() => undefined);
|
||||
if (failed !== undefined) {
|
||||
|
||||
@@ -28,6 +28,9 @@ const recipeKey = ({ inventory, profile, config, toolsCommit }: Recipe) => {
|
||||
|
||||
/** Only settings that can change captured runtime evidence belong in the recipe. */
|
||||
export function captureRecipeConfig(config: ExploreConfig, instructionsSha256?: string): string {
|
||||
// How many sessions capture the evidence (capture.maxSessions) does not change it.
|
||||
const { maxSessions: _maxSessions, ...capture } = config.capture;
|
||||
void _maxSessions;
|
||||
return canonicalJson({
|
||||
observer: CAPTURE_OBSERVER_HASH,
|
||||
mode: config.mode,
|
||||
@@ -36,7 +39,7 @@ export function captureRecipeConfig(config: ExploreConfig, instructionsSha256?:
|
||||
...(config.app.scheme === undefined ? {} : { scheme: config.app.scheme }) },
|
||||
device: config.device, parameters: config.parameters, setup: config.setup ?? [],
|
||||
// The repack as it resolves, so a config that leaves it to the default keeps the recipe it had when the default was written out.
|
||||
capture: { ...config.capture, repack: captureRepack(config) },
|
||||
capture: { ...capture, repack: captureRepack(config) },
|
||||
// agent-device recipes stay as they were; an Argent capture is keyed to the Argent release that drove it.
|
||||
...(config.capture.controller === "argent" ? { controllerVersion: ARGENT_VERSION } : {}),
|
||||
});
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { copyFile, mkdir, readdir, readFile, writeFile, appendFile, lstat } from "node:fs/promises";
|
||||
import { dirname, join, relative } from "node:path";
|
||||
|
||||
import { bundleColorSchemes, mergeSchemeOutcomes, routeIdOfScreen, type ColorScheme } from "../capture/appearance.js";
|
||||
import type { CaptureOutcome } from "../contracts/capture.js";
|
||||
import type { CaptureBundle } from "../contracts/capture.js";
|
||||
import type { ExploreMap } from "../types.js";
|
||||
|
||||
const LIST_FIELDS = ["artifacts", "screens", "variants", "observations", "elements", "actionAttempts", "transitions", "journeys", "frontier", "gaps"] as const;
|
||||
|
||||
async function readJson<T>(path: string): Promise<T> { return JSON.parse(await readFile(path, "utf8")) as T; }
|
||||
|
||||
async function copyTree(source: string, destination: string, skip: (relativePath: string) => boolean, root = source): Promise<void> {
|
||||
for (const entry of await readdir(source, { withFileTypes: true })) {
|
||||
const from = join(source, entry.name), to = join(destination, entry.name), rel = relative(root, from);
|
||||
if (skip(rel)) continue;
|
||||
if (entry.isDirectory()) { await mkdir(to, { recursive: true }); await copyTree(from, to, skip, root); continue; }
|
||||
if (!entry.isFile()) continue;
|
||||
if ((await lstat(to).catch(() => undefined))) continue;
|
||||
await mkdir(dirname(to), { recursive: true });
|
||||
await copyFile(from, to);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fold the exports of a side's secondary appearance sessions into its primary export, in place: the frames, outcomes,
|
||||
* launch evidence and map records of each `<id>@<scheme>` screen, and their files. Each session captured its passes as
|
||||
* one run would (`appearancePass`), so records only append; a secondary export never replaces a primary record.
|
||||
*/
|
||||
export async function mergeCaptureExports(primary: string, secondaries: readonly { directory: string; scheme: ColorScheme }[]): Promise<void> {
|
||||
if (secondaries.length === 0) return;
|
||||
const bundle = await readJson<CaptureBundle>(join(primary, "bundle.json"));
|
||||
const map = await readJson<ExploreMap>(join(primary, "screen-map.json"));
|
||||
const known = { screens: new Set(map.screens.map(screen => screen.id)), artifacts: new Set(map.artifacts.map(artifact => artifact.id)) };
|
||||
// The outcomes recombine as one run's passes do (mergeSchemeOutcomes): a secondary pass records a verified frame under
|
||||
// `<id>@<scheme>` and a lost route under `<id>`, which the merge folds into the primary record the same way.
|
||||
const schemes = bundleColorSchemes(bundle);
|
||||
const passes: Record<string, CaptureOutcome>[] = schemes.map(() => ({}));
|
||||
for (const [id, outcome] of Object.entries(bundle.outcomes)) if (!routeIdOfScreen(id).scheme) passes[0]![id] = outcome;
|
||||
for (const { directory: secondary, scheme } of secondaries) {
|
||||
const other = await readJson<CaptureBundle>(join(secondary, "bundle.json"));
|
||||
const pass = passes[schemes.indexOf(scheme)];
|
||||
// A session that could not show its appearance (Argent without appearance.set captures one) has nothing to add, as
|
||||
// one run would have no pass for it.
|
||||
if (!pass && !bundleColorSchemes(other).includes(scheme)) continue;
|
||||
if (!pass) throw new Error(`The ${scheme} session's export is not an appearance of the primary export (${schemes.join(", ")})`);
|
||||
for (const [id, outcome] of Object.entries(other.outcomes)) pass[routeIdOfScreen(id).routeId] = outcome;
|
||||
const otherMap = await readJson<ExploreMap>(join(secondary, "screen-map.json"));
|
||||
for (const [id, image] of Object.entries(other.images)) if (routeIdOfScreen(id).scheme && !bundle.images[id]) bundle.images[id] = image;
|
||||
for (const [scheme, record] of Object.entries(other.launch ?? {})) { bundle.launch ??= {}; bundle.launch[scheme] ??= record; }
|
||||
for (const [id, context] of Object.entries(other.captureContexts ?? {})) { bundle.captureContexts ??= {}; bundle.captureContexts[id] ??= context; }
|
||||
for (const field of LIST_FIELDS) {
|
||||
const records = (otherMap[field] ?? []) as Array<Record<string, unknown>>;
|
||||
const target = ((map as unknown as Record<string, unknown[]>)[field] ??= []);
|
||||
for (const record of records) {
|
||||
if (field === "screens" && known.screens.has(record.id as string)) continue;
|
||||
if (field === "artifacts" && known.artifacts.has(record.id as string)) continue;
|
||||
if (field === "screens") known.screens.add(record.id as string);
|
||||
if (field === "artifacts") known.artifacts.add(record.id as string);
|
||||
target.push(record);
|
||||
}
|
||||
}
|
||||
// Files: artifacts and launch evidence are new paths; diagnostics append to the primary's lines.
|
||||
await copyTree(secondary, primary, rel => rel === "bundle.json" || rel === "screen-map.json" || rel === "screen-map.schema.json" || rel === "manifest.json"
|
||||
|| rel === "execution.json" || rel.startsWith("capture-diagnostics"));
|
||||
const diagnostics = join(secondary, "capture-diagnostics");
|
||||
for (const entry of await readdir(diagnostics, { withFileTypes: true }).catch(() => [])) {
|
||||
if (!entry.isFile()) continue;
|
||||
const to = join(primary, "capture-diagnostics", entry.name);
|
||||
await mkdir(dirname(to), { recursive: true });
|
||||
if (entry.name.endsWith(".jsonl")) await appendFile(to, await readFile(join(diagnostics, entry.name)));
|
||||
else if (!(await lstat(to).catch(() => undefined))) await copyFile(join(diagnostics, entry.name), to);
|
||||
}
|
||||
}
|
||||
// An open gap a secondary pass left makes the run partial, as it does one run's (a complete run has none).
|
||||
if (map.gaps.some(gap => gap.status === "open")) map.run.status = "partial";
|
||||
const manifest = await readJson<{ files: unknown[] }>(join(primary, "manifest.json"));
|
||||
manifest.files = map.artifacts.map(artifact => ({ path: artifact.path, sha256: artifact.sha256, bytes: artifact.bytes, mimeType: artifact.mimeType }));
|
||||
await writeFile(join(primary, "screen-map.json"), JSON.stringify(map));
|
||||
bundle.outcomes = mergeSchemeOutcomes(passes, schemes);
|
||||
await writeFile(join(primary, "bundle.json"), JSON.stringify(bundle));
|
||||
await writeFile(join(primary, "manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`);
|
||||
}
|
||||
+16
-7
@@ -1,14 +1,14 @@
|
||||
import type { RunTarget } from "../types.js";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { readFileSync, readdirSync } from "node:fs";
|
||||
import { copyFile, cp, lstat, mkdir, mkdtemp, readdir, readFile, realpath, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, relative, resolve } from "node:path";
|
||||
import { runCiReview } from "./pipeline.js";
|
||||
import { resolveCommit } from "./workflow-steps.js";
|
||||
import { ciLayout, installCommand, type PackageManager } from "./workflow-install.js";
|
||||
import { configPlatforms, readExploreConfig, resolveTargetConfig, configTargets, withRunOverrides, DEFAULT_EXPLORE_CONFIG_PATH, type ExploreConfig, type ExplorePlatform } from "../config/explore-config.js";
|
||||
import { configPlatforms, readExploreConfig, resolveTargetConfig, configTargets, posedTargets, withRunOverrides, DEFAULT_EXPLORE_CONFIG_PATH, type ExploreConfig, type ExplorePlatform } from "../config/explore-config.js";
|
||||
import { AGENT_PROVIDERS, defaultExploreConfig } from "../config/setup.js";
|
||||
import type { PrepareCiExplorationOptions } from "../capture/agent/exploration.js";
|
||||
import { createCiAgentSession } from "../capture/agent/session.js";
|
||||
@@ -26,6 +26,7 @@ import { abandonSharedBuilds } from "../capture/shared-build.js";
|
||||
import { exploreCacheRoot } from "../shared/cache-root.js";
|
||||
import { packageBin } from "../shared/package-paths.js";
|
||||
import { silentProgress, type Progress } from "../shared/progress.js";
|
||||
import { maxParallelTargets } from "./session-plan.js";
|
||||
|
||||
/**
|
||||
* `capture:review --base REF [--head REF]` on a laptop: the same review CI runs (`runCiReview`), on two commits of the
|
||||
@@ -44,7 +45,7 @@ export type LocalReviewOptions = {
|
||||
platform?: ExplorePlatform | undefined;
|
||||
/** `--target`: capture this config.yaml target alone; with `platform`, the targets of that platform. */
|
||||
target?: string | undefined;
|
||||
/** `--parallel`: how many targets capture at once (each runs a simulator or emulator per side); all of them by default. */
|
||||
/** `--parallel`: how many targets capture at once (each runs a simulator or emulator per side); by default all of them, up to capture.maxSessions. */
|
||||
parallel?: number | undefined;
|
||||
scope?: string | undefined;
|
||||
expiresIn?: string | undefined;
|
||||
@@ -285,8 +286,15 @@ export async function keepCapture(exported: string, target: string): Promise<boo
|
||||
}
|
||||
}
|
||||
|
||||
/** The session state files a review writes: `<side>-session`, and `<side>-session-<scheme>` for appearance passes in their own sessions. */
|
||||
function sessionStateFiles(output: string): string[] {
|
||||
const rank = (name: string) => ["head", "base", "baseline"].indexOf(name.split("-")[0]!);
|
||||
try { return readdirSync(output).filter(name => /^(head|base|baseline)-session(-[a-z]+)?$/.test(name)).sort((a, b) => rank(a) - rank(b) || a.localeCompare(b)); }
|
||||
catch { return []; }
|
||||
}
|
||||
|
||||
function recordedSessionIds(outputs: string[]): string[] {
|
||||
return outputs.flatMap(output => ["head-session", "base-session"].flatMap(name => {
|
||||
return outputs.flatMap(output => sessionStateFiles(output).flatMap(name => {
|
||||
try { const id = readFileSync(join(output, name), "utf8").trim(); return /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/.test(id) ? [id] : []; } catch { return []; }
|
||||
}));
|
||||
}
|
||||
@@ -307,7 +315,7 @@ export async function stopRecordedSessions(outputs: string[], environment: NodeJ
|
||||
simctl: (args: string[]) => { status: number | null } = args => spawnSync("xcrun", ["simctl", ...args], { env: environment, encoding: "utf8", timeout: 120_000 }),
|
||||
adb: (args: string[]) => { status: number | null } = args => spawnSync(androidTools(environment).adb, args, { env: environment, encoding: "utf8", timeout: 60_000 })): Promise<string[]> {
|
||||
const stopped: string[] = [];
|
||||
for (const output of outputs) for (const name of ["head-session", "base-session"]) {
|
||||
for (const output of outputs) for (const name of sessionStateFiles(output)) {
|
||||
const file = join(output, name);
|
||||
const id = (await readFile(file, "utf8").catch(() => "")).trim();
|
||||
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/.test(id)) continue;
|
||||
@@ -479,7 +487,7 @@ export async function runLocalReview(options: LocalReviewOptions): Promise<Local
|
||||
target, ...(targets.length > 1 ? { targets } : {}) };
|
||||
progress(`${target.id}: reviewing${target.id === platform ? "" : ` (${target.label})`}`);
|
||||
const result = await runCiReview({ projects, output, config, presentation, runId, runAttempt: "1", state, environment: platformEnvironment,
|
||||
...(platforms.length > 1 ? { platforms } : {}), ...(targets.length > 1 ? { targets } : {}),
|
||||
...(platforms.length > 1 ? { platforms } : {}), ...(targets.length > 1 ? { targets } : {}), posedTargets: posedTargets(rawConfig),
|
||||
// Targets of one platform capture the same commits from the same build; it is built and repacked once.
|
||||
...(targets.length > 1 ? { buildShare: join(work, ".builds") } : {}),
|
||||
subscription, useLocalEasSession, progress: message => progress(`${target.id}: ${message}`),
|
||||
@@ -537,7 +545,8 @@ export async function runLocalReview(options: LocalReviewOptions): Promise<Local
|
||||
await abandonSharedBuilds(join(work, ".builds"), owner => owner === join(work, target.id, `${side}-export`), failure.code);
|
||||
}
|
||||
};
|
||||
const settled = await settleLimited(targets, options.parallel ?? targets.length,
|
||||
// Each target needs a simulator session: no more run at once than capture.maxSessions, unless --parallel says.
|
||||
const settled = await settleLimited(targets, options.parallel ?? maxParallelTargets(rawConfig.capture.maxSessions, targets.length),
|
||||
target => captureTarget(target).catch(async (error: unknown) => { await releaseBuilds(target, error).catch(() => undefined); throw error; }));
|
||||
// One target that fails costs that target's report, not the others': they are kept, and the failure is named.
|
||||
// Only an interrupted review, or one where every target failed, fails as a whole.
|
||||
|
||||
+125
-10
@@ -1,13 +1,18 @@
|
||||
import { systemRegions } from "../contracts/capture.js";
|
||||
import type { RunTarget } from "../types.js";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdir, open, readFile, realpath, writeFile } from "node:fs/promises";
|
||||
import { execFile, spawnSync } from "node:child_process";
|
||||
import { mkdir, mkdtemp, open, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
||||
import { join, relative, resolve, isAbsolute } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { promisify } from "node:util";
|
||||
import { buildVerifiedPlan } from "./verified-plan.js";
|
||||
import { runCiMap, type CommandRunner } from "../capture/run.js";
|
||||
import { routeIdOfScreen } from "../capture/appearance.js";
|
||||
import { runCiMap, type CiMapOptions, type CommandRunner } from "../capture/run.js";
|
||||
import { resolveColorSchemes, routeIdOfScreen, type ColorScheme } from "../capture/appearance.js";
|
||||
import { baseEnvironment } from "../capture/common.js";
|
||||
import { DEFAULT_MAX_SESSIONS, planSideSessions, sessionShare } from "./session-plan.js";
|
||||
import { mergeCaptureExports } from "./export-merge.js";
|
||||
import { abandonSharedBuilds } from "../capture/shared-build.js";
|
||||
import { prepareCaptureReview, readCaptureBundle } from "../review/capture-review.js";
|
||||
import { quarantineReviewContract } from "../contracts/review-validation.js";
|
||||
import { agentCaptureConstraints } from "../capture/agent/source-context.js";
|
||||
@@ -64,6 +69,8 @@ async function recipe(config: ExploreConfig, plan: SourceCapturePlan, side: "bas
|
||||
/** The capture's clock and host-side pause; tests pair them with an injected runner so readiness budgets are not real time. */
|
||||
type CaptureClock = { now?: (() => number) | undefined; sleep?: ((milliseconds: number) => void) | undefined };
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
function captureOptions(config: ExploreConfig, environment: NodeJS.ProcessEnv, runner?: CommandRunner, clock: CaptureClock = {}) {
|
||||
return { ...(runner && clock.now ? { now: clock.now } : {}), ...(runner && clock.sleep ? { sleep: clock.sleep } : {}), platform: config.app.platform, bundleId: config.app.bundleId,
|
||||
...(config.app.scheme ? { scheme: config.app.scheme } : {}), device: config.device.name, ...(config.device.pose ? { devicePose: config.device.pose } : {}),
|
||||
@@ -85,6 +92,87 @@ async function prefetchControllers(config: ExploreConfig, environment: NodeJS.Pr
|
||||
if (config.capture.controller === "argent" && config.capture.simulator === "local") await ensureArgentToolServer({ environment, progress });
|
||||
}
|
||||
|
||||
/**
|
||||
* The appearances a capture of this side renders, read before any session starts so the sessions can divide them. The
|
||||
* app config comes from `eas config` in a child process, as the capture reads it, with the capture's restricted
|
||||
* environment: never evaluated in this process, which holds the review's secrets. Unknown: undefined.
|
||||
*/
|
||||
async function expectedColorSchemes(config: ExploreConfig, project: string, environment: NodeJS.ProcessEnv, easCommand: string): Promise<ColorScheme[] | undefined> {
|
||||
// Argent switches the appearance only through serve-sim on an EAS iOS session; elsewhere it captures one.
|
||||
if (config.capture.controller === "argent" && config.capture.simulator !== "local" && config.app.platform !== "ios") return undefined;
|
||||
if (config.capture.appearance !== "auto") return resolveColorSchemes(config.capture.appearance, undefined, config.app.platform);
|
||||
const easEnvironment = { ...baseEnvironment(environment), ...(environment.EXPO_TOKEN ? { EXPO_TOKEN: environment.EXPO_TOKEN } : {}) };
|
||||
try {
|
||||
const { stdout } = await execFileAsync(easCommand, ["config", "--platform", config.app.platform, "--profile", config.app.easProfile, "--json", "--non-interactive"],
|
||||
{ cwd: project, env: easEnvironment, timeout: 5 * 60_000, maxBuffer: 16 * 1024 * 1024 });
|
||||
const app = (JSON.parse(stdout) as { appConfig?: Record<string, unknown> }).appConfig;
|
||||
return app && typeof app === "object" ? resolveColorSchemes("auto", app, config.app.platform) : undefined;
|
||||
} catch {
|
||||
// The capture reads the same config and reports why it cannot; until then the side keeps one session.
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run one side's capture: in one session, or when `passes` splits its appearances, one worker session per pass. The
|
||||
* primary pass exports to `mapOptions.outputDirectory`; the others beside it, named by their appearances, then merge.
|
||||
*/
|
||||
async function captureSideInSessions(mapOptions: CiMapOptions, passes: readonly (readonly ColorScheme[])[] | undefined,
|
||||
progress: Progress, signal: AbortSignal | undefined, worker: boolean): Promise<Awaited<ReturnType<typeof runCiMap>>> {
|
||||
const runOnWorker = (passOptions: CiMapOptions) =>
|
||||
runCiMapOnWorker((({ progress: _progress, runner: _runner, agent: _agent, signal: _signal, ...rest }) => rest)(passOptions), progress, signal);
|
||||
if (!passes || passes.length <= 1) return worker ? runOnWorker(mapOptions) : runCiMap(mapOptions);
|
||||
const schemes = passes.flat();
|
||||
progress(`${mapOptions.side}: capturing ${passes.map(pass => pass.join("+")).join(" and ")} in separate sessions`);
|
||||
// The passes install the same app: they share one build and repack, as the targets of a local review do.
|
||||
const ownBuildShare = mapOptions.buildShare ? undefined : await mkdtemp(join(tmpdir(), "expo-explore-builds-"));
|
||||
const buildShare = mapOptions.buildShare ?? ownBuildShare!;
|
||||
const settled = await Promise.allSettled(passes.map(async (pass, index) => {
|
||||
const suffix = index === 0 ? "" : `-${pass.join("-")}`;
|
||||
const outputDirectory = `${mapOptions.outputDirectory}${suffix}`;
|
||||
try {
|
||||
return await runOnWorker({ ...mapOptions, mapDirectory: `${mapOptions.mapDirectory}${suffix}`, outputDirectory, buildShare,
|
||||
...(mapOptions.sessionStatePath ? { sessionStatePath: `${mapOptions.sessionStatePath}${suffix}` } : {}), appearancePass: { all: schemes, capture: pass } });
|
||||
} catch (error) {
|
||||
// A pass that dies mid-build must not leave the others polling for its result.
|
||||
await abandonSharedBuilds(buildShare, owner => owner === outputDirectory, toCiError(error).code).catch(() => undefined);
|
||||
throw error;
|
||||
}
|
||||
}));
|
||||
// The build folder holds the repacked app, which the sessions have installed.
|
||||
if (ownBuildShare) await rm(ownBuildShare, { recursive: true, force: true });
|
||||
for (const outcome of settled) if (outcome.status === "rejected") throw outcome.reason;
|
||||
await mergeCaptureExports(mapOptions.outputDirectory, passes.slice(1).map(pass => ({ directory: `${mapOptions.outputDirectory}-${pass.join("-")}`, scheme: pass[0]! })));
|
||||
return (settled[0] as PromiseFulfilledResult<Awaited<ReturnType<typeof runCiMap>>>).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This target's share of `capture.maxSessions`: the targets are this review's (`targets`), or the config's one, and
|
||||
* `posedTargets` (foldables) take the sessions that do not divide evenly.
|
||||
*/
|
||||
function targetSessionShare(config: ExploreConfig, targets: readonly RunTarget[] | undefined, posedTargets: readonly string[] | undefined): number {
|
||||
const targetIds: string[] = (targets ?? []).map(target => target.id);
|
||||
if (targetIds.length === 0) targetIds.push(...(config.targets ? Object.keys(config.targets) : [config.target?.id ?? "default"]));
|
||||
return sessionShare({ maxSessions: config.capture.maxSessions, targets: targetIds, target: config.target?.id ?? targetIds[0]!,
|
||||
prefer: id => posedTargets?.includes(id) ? 1 : 0 });
|
||||
}
|
||||
|
||||
/**
|
||||
* The appearance passes one side spreads over sessions of its own, out of its target's share of `capture.maxSessions`;
|
||||
* undefined keeps the side in one session. The side's app config is read only when its share and routes could pay for
|
||||
* a split.
|
||||
*/
|
||||
export async function sideAppearancePasses(config: ExploreConfig, environment: NodeJS.ProcessEnv,
|
||||
input: { share: number; sides: 1 | 2; routes: number; project: string; easCommand?: string }): Promise<ColorScheme[][] | undefined> {
|
||||
// A pass observes its launch only when capture.launch asks for it.
|
||||
const plan = (schemes: readonly ColorScheme[]) => planSideSessions({ share: input.share, sides: input.sides, routes: input.routes, schemes,
|
||||
...(config.capture.launch === "off" ? { launchSeconds: 0 } : {}) }).passes;
|
||||
if (plan(["light", "dark"]).length < 2) return undefined;
|
||||
const schemes = await expectedColorSchemes(config, input.project, environment, input.easCommand ?? packageBin("eas-cli", "eas"));
|
||||
const passes = schemes ? plan(schemes) : [];
|
||||
return passes.length > 1 ? passes.map(pass => [...pass]) : undefined;
|
||||
}
|
||||
|
||||
export function captureSidesConcurrently(input: { plan: SourceCapturePlan; agent: boolean; injectedRunner: boolean; baselineMayExist: boolean }): boolean {
|
||||
return !input.agent && !input.injectedRunner && !input.baselineMayExist
|
||||
&& input.plan.headCaptureSurfaceIds.length > 0 && input.plan.baseCaptureSurfaceIds.length > 0;
|
||||
@@ -112,6 +200,8 @@ export type PublicCiOptions = {
|
||||
platforms?: ExplorePlatform[];
|
||||
/** Every target config.yaml captures, in config order; recorded in the report so the Viewer links the sibling targets' reports. */
|
||||
targets?: RunTarget[];
|
||||
/** The targets with a device pose (foldables), which take the sessions `capture.maxSessions` does not divide evenly. */
|
||||
posedTargets?: readonly string[];
|
||||
baseProject: string; headProject: string; pullRequestPath: string; output: string;
|
||||
config: ExploreConfig; configPath?: string; environment?: NodeJS.ProcessEnv; transport?: typeof fetch;
|
||||
now?: () => number; sleep?: (milliseconds: number) => void; onComment?: (state: PublicCommentState, body: string) => void;
|
||||
@@ -254,6 +344,8 @@ export async function runCiReview(options: {
|
||||
platforms?: ExplorePlatform[];
|
||||
/** Every target config.yaml captures; `config.target` is the one this review captures. */
|
||||
targets?: RunTarget[];
|
||||
/** The targets with a device pose (foldables), which take the sessions `capture.maxSessions` does not divide evenly. */
|
||||
posedTargets?: readonly string[];
|
||||
/** A folder shared with the other targets' reviews, so the targets of one platform build each commit once. */
|
||||
buildShare?: string;
|
||||
measure?: Parameters<typeof assessPublicEvidence>[0]["measure"];
|
||||
@@ -309,7 +401,20 @@ export async function runCiReview(options: {
|
||||
// A baseline that may be restored needs the head runtime profile first; otherwise both sides capture at once.
|
||||
const baselineMayExist = plan.baseCaptureSurfaceIds.length > 0 && await captureArtifactCacheMayMatch({ ...cacheRecipes.base,
|
||||
...(environment.EXPLORE_CAPTURE_CACHE ? { sourceDirectory: environment.EXPLORE_CAPTURE_CACHE } : {}), commit: pr.base.sha });
|
||||
const concurrent = captureSidesConcurrently({ plan, agent: !!exploration.agent, injectedRunner: !!options.runner, baselineMayExist });
|
||||
const share = targetSessionShare(config, options.targets, options.posedTargets);
|
||||
// A share of one session captures the sides in turn.
|
||||
const concurrent = captureSidesConcurrently({ plan, agent: !!exploration.agent, injectedRunner: !!options.runner, baselineMayExist }) && share >= 2;
|
||||
// Each side's appearances split by its own app config: a pull request can change userInterfaceStyle. Sides taken in
|
||||
// turn (a baseline may be restored) each have the whole share. Passes run on worker threads, which cannot take an
|
||||
// injected runner or an agent session.
|
||||
const sidePasses = { head: undefined as ColorScheme[][] | undefined, base: undefined as ColorScheme[][] | undefined };
|
||||
if (!exploration.agent && !options.runner) await Promise.all((["head", "base"] as const).map(async side => {
|
||||
sidePasses[side] = await sideAppearancePasses(config, environment, { share, sides: concurrent ? 2 : 1, routes: plan[`${side}CaptureSurfaceIds`].length, project: projects[side] });
|
||||
}));
|
||||
const split = (["head", "base"] as const).filter(side => sidePasses[side]);
|
||||
progress(`sessions: ${share} of ${config.capture.maxSessions ?? DEFAULT_MAX_SESSIONS} for this target; `
|
||||
+ (split.length ? `${split.join(" and ")} ${split.length === 1 ? "captures its" : "capture their"} appearances in separate sessions`
|
||||
: concurrent ? "one session per side" : "the sides in turn"));
|
||||
const captureSide = async (side: "head" | "base") => {
|
||||
const directory = join(output, `${side}-export`);
|
||||
const selectedIds = plan[`${side}CaptureSurfaceIds`];
|
||||
@@ -329,9 +434,8 @@ export async function runCiReview(options: {
|
||||
name: config.app.name ?? pr.repository, buildId: pr.origin === "local" ? `local-${pr.runId}-${side}` : pr.origin === "compare" ? `compare-${options.runId}-${side}` : `pr-${pr.number}-${side}`, buildVersion: pr[side].sha.slice(0, 8), gitCommit: pr[side].sha,
|
||||
planPath: join(output, "execution-plan.json"), side, sessionStatePath: join(output, `${side}-session`), ...(options.buildShare ? { buildShare: options.buildShare } : {}),
|
||||
...(reuseDirectory ? { reuseDirectory } : {}), ...(options.signal ? { signal: options.signal } : {}) };
|
||||
const captured = concurrent
|
||||
? await runCiMapOnWorker((({ progress: _progress, runner: _runner, agent: _agent, signal: _signal, ...rest }) => rest)(mapOptions), progress, options.signal)
|
||||
: await runCiMap(mapOptions);
|
||||
// A restored baseline already holds every appearance pass, so it never splits.
|
||||
const captured = await captureSideInSessions(mapOptions, reuseDirectory ? undefined : sidePasses[side], progress, options.signal, concurrent);
|
||||
const bundle = await readCaptureBundle(directory);
|
||||
bundle.profile = cacheRecipe.profile;
|
||||
await writeFile(join(directory, "bundle.json"), JSON.stringify(bundle));
|
||||
@@ -464,6 +568,10 @@ export async function runCiReview(options: {
|
||||
}
|
||||
|
||||
export async function runBaselineCi(options: { platform?: ExplorePlatform; project: string; sha: string; output: string; config: ExploreConfig; environment?: NodeJS.ProcessEnv; runner?: CommandRunner;
|
||||
/** Every target config.yaml captures, so this baseline takes its target's share of `capture.maxSessions`. */
|
||||
targets?: RunTarget[];
|
||||
/** The targets with a device pose (foldables), which take the sessions `capture.maxSessions` does not divide evenly. */
|
||||
posedTargets?: readonly string[];
|
||||
now?: () => number; sleep?: (milliseconds: number) => void;
|
||||
agentSessionFactory?: PrepareCiExplorationOptions["createSession"]; progress?: Progress;
|
||||
/** Use the local `eas login` session instead of EXPO_TOKEN (expo-explore doctor --capture). */
|
||||
@@ -489,12 +597,19 @@ export async function runBaselineCi(options: { platform?: ExplorePlatform; proje
|
||||
onUsage: recordAgentUsage(output, () => usagePhase), ...(options.subscription ? { subscription: true } : {}) });
|
||||
const directory = join(output, "baseline-export");
|
||||
usagePhase = "capture-baseline";
|
||||
const result = await runCiMap({ ...captureOptions(options.config, environment, options.runner, { now: options.now, sleep: options.sleep }), progress,
|
||||
const baselineOptions: CiMapOptions = { ...captureOptions(options.config, environment, options.runner, { now: options.now, sleep: options.sleep }), progress,
|
||||
...(options.useLocalEasSession ? { useLocalEasSession: true } : {}),
|
||||
...(exploration.agent ? { agent: exploration.agent } : {}), project: options.project,
|
||||
mapDirectory: join(output, "baseline-map"), outputDirectory: directory, name: options.config.app.name ?? options.config.app.bundleId,
|
||||
buildId: `baseline-${options.sha.slice(0, 12)}`, buildVersion: options.sha.slice(0, 8), gitCommit: options.sha,
|
||||
side: "head", planPath: join(output, "execution-plan.json"), sessionStatePath: join(output, "baseline-session") });
|
||||
side: "head", planPath: join(output, "execution-plan.json"), sessionStatePath: join(output, "baseline-session") };
|
||||
const share = targetSessionShare(options.config, options.targets, options.posedTargets);
|
||||
// Passes on worker threads cannot take an injected runner or an agent session.
|
||||
const passes = !options.runner && !exploration.agent
|
||||
? await sideAppearancePasses(options.config, environment, { share, sides: 1, routes: plan.headCaptureSurfaceIds.length, project: options.project }) : undefined;
|
||||
progress(`sessions: ${share} of ${options.config.capture.maxSessions ?? DEFAULT_MAX_SESSIONS} for this target; `
|
||||
+ (passes ? `capturing ${passes.map(pass => pass.join("+")).join(" and ")} in separate sessions` : "one session"));
|
||||
const result = await captureSideInSessions(baselineOptions, passes, progress, undefined, passes !== undefined);
|
||||
const cacheRecipe = await recipe(options.config, plan, "head", environment, exploration.instructionsSha256);
|
||||
if (options.subscription) cacheRecipe.toolsCommit += ":local-subscription";
|
||||
const bundle = await readCaptureBundle(directory); bundle.profile = cacheRecipe.profile;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import type { ColorScheme } from "../capture/appearance.js";
|
||||
|
||||
/** One route capture on a remote session, with the bridge thread (observed ~5 s; 9.4 s before it). */
|
||||
export const ROUTE_SECONDS = 5;
|
||||
/** Observing the app launch once per appearance. */
|
||||
export const LAUNCH_SECONDS = 28;
|
||||
/** A pass moves to its own session only when that shortens the side by at least this much. */
|
||||
export const SPLIT_MIN_SAVING_SECONDS = 60;
|
||||
/**
|
||||
* `capture.maxSessions` when the config sets none: the simulators a typical EAS plan runs at once. A starter plan runs
|
||||
* one per platform, so its config sets the ceiling lower (2 for an iOS and an Android target).
|
||||
*/
|
||||
export const DEFAULT_MAX_SESSIONS = 5;
|
||||
|
||||
export type SessionShareInput = {
|
||||
/** `capture.maxSessions`: the review-wide ceiling; absent means DEFAULT_MAX_SESSIONS. */
|
||||
maxSessions: number | undefined;
|
||||
/** The review's target ids in config order, and the one this job captures. */
|
||||
targets: readonly string[];
|
||||
target: string;
|
||||
/** Targets a split pays off most for take the sessions that do not divide evenly: foldables and large screens first. */
|
||||
prefer?: (target: string) => number;
|
||||
};
|
||||
|
||||
/**
|
||||
* This job's share of the review's session ceiling: the ceiling divided over the targets, the remainder going to the
|
||||
* preferred targets (foldables) in config order, and unused when there are none. Never below 1 (a side then captures after the other): under a ceiling below the
|
||||
* number of targets, at most that many target jobs run at once (maxParallelTargets).
|
||||
*/
|
||||
export function sessionShare(input: SessionShareInput): number {
|
||||
const count = Math.max(1, input.targets.length);
|
||||
const ceiling = input.maxSessions ?? DEFAULT_MAX_SESSIONS;
|
||||
const base = Math.floor(ceiling / count);
|
||||
let remainder = ceiling - base * count;
|
||||
// A session left over goes to a preferred target only; without one it stays unused (two targets of five: two each).
|
||||
const ranked = input.targets.filter(id => (input.prefer?.(id) ?? 0) > 0)
|
||||
.sort((a, b) => input.prefer!(b) - input.prefer!(a) || input.targets.indexOf(a) - input.targets.indexOf(b));
|
||||
const extra = new Set<string>();
|
||||
for (const id of ranked) { if (remainder <= 0) break; extra.add(id); remainder -= 1; }
|
||||
return Math.max(1, base + (extra.has(input.target) ? 1 : 0));
|
||||
}
|
||||
|
||||
/** How many target jobs one review runs at once: each needs a session, so never more than the ceiling. */
|
||||
export function maxParallelTargets(maxSessions: number | undefined, targets: number): number {
|
||||
return Math.max(1, Math.min(targets, maxSessions ?? DEFAULT_MAX_SESSIONS));
|
||||
}
|
||||
|
||||
export type SidePlan = {
|
||||
/** Whether head and base capture at the same time. */
|
||||
concurrentSides: boolean;
|
||||
/** The appearance passes of one side, each on its own session; one entry means the side keeps a single session. */
|
||||
passes: readonly (readonly ColorScheme[])[];
|
||||
};
|
||||
|
||||
/**
|
||||
* How one target's job spends its share of sessions: both sides at once when it has two, and a side's appearance passes
|
||||
* in separate sessions only when the pass moved out shortens the side by at least a minute (a session costs its fixed
|
||||
* boot and install time, so a few routes are not worth one). Sessions the work cannot fill stay unused: the ceiling is
|
||||
* a limit, not a target.
|
||||
*/
|
||||
export function planSideSessions(input: { share: number; sides: 1 | 2; routes: number; schemes: readonly ColorScheme[];
|
||||
minSavingSeconds?: number; routeSeconds?: number; launchSeconds?: number }): SidePlan {
|
||||
const minSaving = input.minSavingSeconds ?? SPLIT_MIN_SAVING_SECONDS, perRoute = input.routeSeconds ?? ROUTE_SECONDS, launch = input.launchSeconds ?? LAUNCH_SECONDS;
|
||||
const concurrentSides = input.sides === 1 || input.share >= 2;
|
||||
const perSide = Math.floor(input.share / (concurrentSides ? input.sides : 1));
|
||||
const schemes = [...input.schemes];
|
||||
const passSeconds = input.routes * perRoute + launch;
|
||||
const splitAppearances = schemes.length > 1 && perSide >= schemes.length && passSeconds >= minSaving;
|
||||
return { concurrentSides, passes: splitAppearances ? schemes.map(scheme => [scheme]) : [schemes] };
|
||||
}
|
||||
@@ -196,7 +196,8 @@ export async function cleanupAfterCapture(options: { output: string; checkouts:
|
||||
const environment = options.environment ?? process.env;
|
||||
const result: { stopped: string[]; failures: Array<{ code: string; message: string; nextAction: string }> } = { stopped: [], failures: [] };
|
||||
const sessionFiles: string[] = [];
|
||||
for (const name of ["head-session", "base-session", "baseline-session"]) {
|
||||
// A side that captures an appearance in a session of its own (capture.maxSessions) records it as `<side>-session-<scheme>`.
|
||||
for (const name of ["head", "base", "baseline"].flatMap(side => ["", "-light", "-dark"].map(scheme => `${side}-session${scheme}`))) {
|
||||
const path = resolve(options.output, name);
|
||||
try { await lstat(path); sessionFiles.push(path); } catch { /* That side never started a session. */ }
|
||||
}
|
||||
|
||||
+12
-6
@@ -15,12 +15,13 @@ import { installCiFiles } from "../ci/workflow-install.js";
|
||||
import { readRouteEntry } from "../ci/route-entry.js";
|
||||
import { buildVerifiedPlan } from "../ci/verified-plan.js";
|
||||
import { formatCaptureCheck, formatDoctorReport, referencedSecretNames, runCaptureCheck, runDoctor } from "../ci/doctor.js";
|
||||
import { readExploreConfig, readExploreInstructions, resolveTargetConfig, configTargets, isTargetId, withRunOverrides, warnIgnoredExpiry, configPlatforms as listPlatforms, EXPLORE_PLATFORMS, DEFAULT_EXPLORE_CONFIG_PATH, type ExplorePlatform } from "../config/explore-config.js";
|
||||
import { readExploreConfig, readExploreInstructions, resolveTargetConfig, configTargets, posedTargets, isTargetId, withRunOverrides, warnIgnoredExpiry, configPlatforms as listPlatforms, EXPLORE_PLATFORMS, DEFAULT_EXPLORE_CONFIG_PATH, type ExplorePlatform } from "../config/explore-config.js";
|
||||
import { argumentError, output, required, has, flag, flags, nonNegativeInteger, oneOf, positiveInteger } from "./args.js";
|
||||
import { help } from "./help.js";
|
||||
import { CiError } from "../shared/ci-errors.js";
|
||||
import { cleanupAfterCapture, findOptionalBaseline, resolveCompareRefs, resolvePullRequest, writeCaptureOutputs, writeStepOutputs } from "../ci/workflow-steps.js";
|
||||
import { stderrProgress } from "../shared/progress.js";
|
||||
import { maxParallelTargets } from "../ci/session-plan.js";
|
||||
|
||||
export async function doctor(): Promise<void> {
|
||||
if (has("help")) return help();
|
||||
@@ -159,10 +160,14 @@ export async function configPlatforms(): Promise<void> {
|
||||
output({ ok: true, platforms: configTargets(config).map(target => target.id) });
|
||||
}
|
||||
|
||||
/** The targets config.yaml captures, in order, with their platforms and labels: the review workflow's matrix. */
|
||||
/**
|
||||
* The targets config.yaml captures, in order, with their platforms and labels: the review workflow's matrix, and how
|
||||
* many of its jobs run at once (`maxParallel`), since each needs a session of capture.maxSessions.
|
||||
*/
|
||||
export async function configTargetList(): Promise<void> {
|
||||
const config = await readExploreConfig(flag("project") ?? process.cwd(), flag("config") ?? DEFAULT_EXPLORE_CONFIG_PATH);
|
||||
output({ ok: true, targets: configTargets(config) });
|
||||
const targets = configTargets(config);
|
||||
output({ ok: true, targets, maxParallel: maxParallelTargets(config.capture.maxSessions, targets.length) });
|
||||
}
|
||||
|
||||
async function exists(path: string): Promise<boolean> {
|
||||
@@ -229,7 +234,7 @@ export async function captureReview(): Promise<void> {
|
||||
// A matrix job names its target; its artifacts, report and comment section carry the target's id.
|
||||
const named = selection.target !== undefined || selection.platform !== undefined;
|
||||
const common = { ...(named ? { target: config.target!.id } : {}), ...(selection.platform ? { platform: selection.platform } : {}),
|
||||
platforms: listPlatforms(rawConfig), targets: configTargets(rawConfig), baseProject: required("base-project"), headProject,
|
||||
platforms: listPlatforms(rawConfig), targets: configTargets(rawConfig), posedTargets: posedTargets(rawConfig), baseProject: required("base-project"), headProject,
|
||||
output: required("output"), config, configPath, progress: stderrProgress() };
|
||||
const result = has("compare") ? await runCompareCi({ ...common, comparePath: required("compare") })
|
||||
: await runPublicCi({ ...common, pullRequestPath: required("pull-request") });
|
||||
@@ -240,8 +245,9 @@ export async function captureReview(): Promise<void> {
|
||||
|
||||
export async function captureBaseline(): Promise<void> {
|
||||
const project = required("project");
|
||||
const config = withRunOverrides(resolveTargetConfig(await readExploreConfig(project, flag("config") ?? DEFAULT_EXPLORE_CONFIG_PATH), targetSelection()), { controller: flag("controller"), simulator: flag("simulator"), repack: flag("repack") });
|
||||
output({ ok: true, ...await runBaselineCi({ platform: config.app.platform, project, sha: required("sha"), output: required("output"), config, progress: stderrProgress() }) });
|
||||
const rawConfig = await readExploreConfig(project, flag("config") ?? DEFAULT_EXPLORE_CONFIG_PATH);
|
||||
const config = withRunOverrides(resolveTargetConfig(rawConfig, targetSelection()), { controller: flag("controller"), simulator: flag("simulator"), repack: flag("repack") });
|
||||
output({ ok: true, ...await runBaselineCi({ platform: config.app.platform, project, sha: required("sha"), output: required("output"), config, targets: configTargets(rawConfig), posedTargets: posedTargets(rawConfig), progress: stderrProgress() }) });
|
||||
}
|
||||
|
||||
/** `capture` (or `capture:review`) `[--base REF] [--head REF | --committed]`: a local review, opened in the Viewer or hosted with --upload. */
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ const GET_STARTED = `Get started (run these in the Expo app's directory):
|
||||
machine, instead of EAS Simulator, and removes it afterwards (or set capture.simulator in config.yaml); builds
|
||||
still run on EAS, and the host switches appearance for either controller; the app is repacked with the route
|
||||
observer on this machine too (--repack eas, or capture.repack, keeps the hosted EAS job);
|
||||
with targets in config.yaml it reviews them at once (--parallel N at most N at a time; the targets of a platform
|
||||
with targets in config.yaml it reviews them at once, up to capture.maxSessions (--parallel N at most N at a time; the targets of a platform
|
||||
share each commit's build), --target ID one of them, --platform those of a platform)
|
||||
view [--catalog FILE] [--port N] [--no-open]
|
||||
(opens a report in the Viewer)
|
||||
|
||||
@@ -94,6 +94,11 @@ export type ExploreConfig = {
|
||||
/** `exclude` names routes, as `requiresRoute` does, that stay in the map but are never captured. */
|
||||
exploration: { scope: "changes" | "all"; exclude?: string[] };
|
||||
capture: { maxMinutes: number; maxActions: number;
|
||||
/**
|
||||
* The most EAS Simulator sessions one review may run at once, across its targets and sides; absent:
|
||||
* DEFAULT_MAX_SESSIONS (5). Below the number of targets, that many target jobs run at once, one session each.
|
||||
*/
|
||||
maxSessions?: number;
|
||||
/** Where the route observer is bundled into the app, when the config chooses; captureRepack gives the default. */
|
||||
repack?: "eas" | "local"; appearance: AppearanceSetting; launch: LaunchSetting; reset: RouteResetSetting; unattributed: UnattributedSetting; readinessSeconds?: number;
|
||||
/** The device controller; absent means agent-device, so configs that never chose one keep their cache recipes. */
|
||||
@@ -295,7 +300,7 @@ export function validateExploreConfig(value: unknown): ExploreConfig {
|
||||
const exploration = optionalRecord(root.exploration, "exploration");
|
||||
exactKeys(exploration, ["scope", "exclude"], "exploration");
|
||||
const capture = optionalRecord(root.capture, "capture");
|
||||
exactKeys(capture, ["maxMinutes", "maxActions", "repack", "appearance", "launch", "reset", "unattributed", "readinessSeconds", "controller", "simulator"], "capture");
|
||||
exactKeys(capture, ["maxMinutes", "maxActions", "maxSessions", "repack", "appearance", "launch", "reset", "unattributed", "readinessSeconds", "controller", "simulator"], "capture");
|
||||
const controller = literal(capture.controller, ["agent-device", "argent"] as const, "capture.controller", "agent-device");
|
||||
const simulator = literal(capture.simulator, ["eas", "local"] as const, "capture.simulator", "eas");
|
||||
const mode = literal(root.mode, ["deterministic", "agent"] as const, "mode", "deterministic");
|
||||
@@ -342,6 +347,7 @@ export function validateExploreConfig(value: unknown): ExploreConfig {
|
||||
capture: {
|
||||
maxMinutes: positiveInteger(capture.maxMinutes, "capture.maxMinutes", 30),
|
||||
maxActions: positiveInteger(capture.maxActions, "capture.maxActions", 500),
|
||||
...(capture.maxSessions === undefined ? {} : { maxSessions: positiveInteger(capture.maxSessions, "capture.maxSessions", 2) }),
|
||||
...(capture.repack === undefined ? {} : { repack: literal(capture.repack, ["eas", "local"] as const, "capture.repack") }),
|
||||
appearance: parseAppearance(capture.appearance, "capture.appearance"),
|
||||
launch: parseLaunchSetting(capture.launch, "capture.launch"),
|
||||
@@ -440,6 +446,11 @@ export function configTargets(config: ExploreConfig): RunTarget[] {
|
||||
label: target.label ?? `${target.device ?? (target.platform === config.app.platform ? config.device.name : DEFAULT_ANDROID_DEVICE)}${target.pose ? ` (${target.pose})` : ""}` }));
|
||||
}
|
||||
|
||||
/** The targets with a device pose (foldables): they take the sessions `capture.maxSessions` does not divide evenly. */
|
||||
export function posedTargets(config: ExploreConfig): string[] {
|
||||
return Object.entries(config.targets ?? {}).filter(([, target]) => target.pose).map(([id]) => id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The flat configuration capture consumes for one target, with `target` naming it. `--target` names one; `--platform`
|
||||
* names the target of that platform, when only one has it; with neither, the config must have a single target.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { unattributedIssue } from "../capture/health.js";
|
||||
import { appearancePairs, bundleColorSchemes } from "../capture/appearance.js";
|
||||
import { appearancePairs, bundleColorSchemes, type ColorScheme } from "../capture/appearance.js";
|
||||
import { launchSurfaceId, systemRegions as defaultSystemRegions, type SystemRegion } from "../contracts/capture.js";
|
||||
import { readFileSync, statSync } from "node:fs";
|
||||
import { stat } from "node:fs/promises";
|
||||
@@ -27,7 +27,9 @@ import {
|
||||
} from "./visual-evidence.js";
|
||||
import { AGENT_DEVICE_VERSION } from "../shared/agent-device-version.js";
|
||||
import { STATUS_BAR_BAND_PERCENT, decodePng, differentPixelsInRect, maxColorDistance, type DecodedFrame } from "../shared/png-evidence.js";
|
||||
import { measureRegionMoves, type RegionMove, type RegionShift } from "./region-shift.js";
|
||||
import type { RegionMove, RegionShift } from "./region-shift.js";
|
||||
import { measureRegionMovesInWorker } from "./region-shift-worker.js";
|
||||
import { availableParallelism } from "node:os";
|
||||
|
||||
export const DEFAULT_VISUAL_THRESHOLD = 0.1;
|
||||
export const DEFAULT_EVIDENCE_TIME_BUDGET_MS = 10 * 60_000;
|
||||
@@ -194,7 +196,7 @@ export function publishMeasuredRegions(all: readonly VisualDiffRegion[], shifts:
|
||||
async function withRegionShifts(basePath: string, headPath: string, all: readonly VisualDiffRegion[], published: NonNullable<PublicVisualVerdict["regions"]>):
|
||||
Promise<Pick<PublicVisualVerdict, "regions" | "allRegionsMoved">> {
|
||||
try {
|
||||
const { shifts, moves, width, height } = await measureRegionMoves(basePath, headPath,
|
||||
const { shifts, moves, width, height } = await measureRegionMovesInWorker(basePath, headPath,
|
||||
all.map(region => ({ ...region.rect, dominantChange: region.dominantChange })));
|
||||
if (moves.length) return publishMeasuredRegions(all, shifts, moves, width, height);
|
||||
const shiftOf = new Map(all.map((region, index) => [region.rect, shifts[index]] as const));
|
||||
@@ -406,6 +408,40 @@ function impactFor(surface: PlanSurface, presence: ComparatorSurfaceImpact["pres
|
||||
};
|
||||
}
|
||||
|
||||
/** The screenshot pairs `assessPublicEvidence` compares: both sides captured and landed, in the loop's order. */
|
||||
function comparablePairs(options: { plan: SourceCapturePlan; base: PublicEvidenceSide; head: PublicEvidenceSide }, colorSchemes: readonly ColorScheme[],
|
||||
baseColorSchemes: readonly ColorScheme[]): Array<{ id: string; basePath: string; headPath: string }> {
|
||||
const pairs: Array<{ id: string; basePath: string; headPath: string }> = [];
|
||||
for (const surface of options.plan.surfaces) {
|
||||
if (surface.baseSurface?.kind !== "screen" || surface.headSurface?.kind !== "screen" || (!surface.baseCapture && !surface.headCapture)) continue;
|
||||
for (const { id, baseId } of appearancePairs(surface.id, colorSchemes, baseColorSchemes)) {
|
||||
if (baseId === null) continue;
|
||||
const basePath = localImagePath(options.base, baseId);
|
||||
const headPath = localImagePath(options.head, id);
|
||||
if (!basePath || !headPath || captureDiagnostic(surface, "base", options.base, baseId) || captureDiagnostic(surface, "head", options.head, id)) continue;
|
||||
pairs.push({ id, basePath, headPath });
|
||||
}
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
/** Runs tasks at most `size` at a time, each started in the order it was queued. */
|
||||
function concurrencyLimit(size: number): <T>(task: () => Promise<T>) => Promise<T> {
|
||||
let active = 0;
|
||||
const queue: Array<() => void> = [];
|
||||
const next = () => { if (active < size) queue.shift()?.(); };
|
||||
return task => new Promise((resolve, reject) => {
|
||||
queue.push(() => {
|
||||
active += 1;
|
||||
task().then(resolve, reject).finally(() => { active -= 1; next(); });
|
||||
});
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
/** The limit the reviews in this process share when none is given: a local review compares its targets at once. */
|
||||
let processLimit: ReturnType<typeof concurrencyLimit> | undefined;
|
||||
|
||||
function localImagePath(side: PublicEvidenceSide, id: string): string | undefined {
|
||||
const frame = side.bundle.images[id];
|
||||
return frame ? localEvidencePath(side, frame.path) : undefined;
|
||||
@@ -499,6 +535,8 @@ export async function assessPublicEvidence(options: {
|
||||
timeBudgetMs?: number;
|
||||
now?: () => number;
|
||||
measure?: (baselinePath: string, currentPath: string) => Promise<ScreenshotDiffMeasurement>;
|
||||
/** How many screenshot pairs compare at once. Absent: one per available CPU, shared by every review in this process. */
|
||||
concurrency?: number;
|
||||
}): Promise<PublicEvidenceResult> {
|
||||
const threshold = options.threshold ?? DEFAULT_VISUAL_THRESHOLD;
|
||||
const system = options.systemRegions ?? defaultSystemRegions({ platform: options.platform });
|
||||
@@ -517,6 +555,34 @@ export async function assessPublicEvidence(options: {
|
||||
const measure = options.measure ?? (async (baselinePath: string, currentPath: string) => (
|
||||
await diffScreenshots({ baselinePath, currentPath, command: options.agentDeviceCommand, threshold })
|
||||
));
|
||||
type ComparedPair = { visual: PublicVisualVerdict; assessment: VisualEvidenceAssessment };
|
||||
/** One pair's measurement, verdict and region moves: the work that runs ahead of the surface loop. */
|
||||
const comparePair = async (basePath: string, headPath: string): Promise<ComparedPair> => {
|
||||
const raw = await measure(basePath, headPath);
|
||||
const { measurement, ignoredStatusBar: ignoredTop, ignoredHomeIndicator: ignoredBottom } = ignoreSystemRegions(raw, system, systemBandFrameLoader(raw, threshold));
|
||||
const assessment = assessVisualMeasurements({
|
||||
baselineSamples: 1,
|
||||
currentSamples: 1,
|
||||
requiredSamples: 1,
|
||||
baselineWithin: [],
|
||||
currentWithin: [],
|
||||
crossBuild: [measurement],
|
||||
representative: measurement,
|
||||
});
|
||||
const visual = visualVerdict(assessment, threshold);
|
||||
// Measuring moves is extra: once the comparison budget is spent, regions go out unmeasured.
|
||||
if (visual.verdict === "modified" && visual.regions?.length && now() <= deadline) {
|
||||
Object.assign(visual, await withRegionShifts(basePath, headPath, measurement.regions, visual.regions));
|
||||
}
|
||||
if (ignoredTop > 0) visual.ignoredStatusBarRegions = ignoredTop;
|
||||
if (ignoredBottom > 0) visual.ignoredHomeIndicatorRegions = ignoredBottom;
|
||||
if (ignoredTop > 0 || ignoredBottom > 0) visual.systemRegions = system.map((area) => ({ ...area }));
|
||||
return { visual, assessment };
|
||||
};
|
||||
/** A pair compared if the budget has not expired when its turn to start comes; undefined when it has. */
|
||||
const compareInBudget = async (basePath: string, headPath: string): Promise<ComparedPair | undefined> => (
|
||||
now() > deadline ? undefined : await comparePair(basePath, headPath)
|
||||
);
|
||||
const visualCounts = { compared: 0, modified: 0, unchanged: 0, needsReview: 0, failed: 0, errors: [] as string[] };
|
||||
const accessibilityCounts = { compared: 0, described: 0, failed: 0, skipped: 0, errors: [] as string[] };
|
||||
const reviewCounts = { modified: 0, needsReview: 0, variants: 0, unchanged: 0 };
|
||||
@@ -533,6 +599,20 @@ export async function assessPublicEvidence(options: {
|
||||
|
||||
const colorSchemes = bundleColorSchemes(options.head.bundle);
|
||||
const baseColorSchemes = bundleColorSchemes(options.base.bundle);
|
||||
// The pairs the loop below compares start now, a few at a time: each is a comparator process and a pixel search
|
||||
// that take seconds on a large screenshot, so they overlap instead of queueing behind one another. The loop reads
|
||||
// them in its own order, so the result does not depend on which finishes first. A pair whose turn comes after the
|
||||
// budget expired is not started; one started in time is waited for and used.
|
||||
const ahead = new Map<string, Promise<ComparedPair | undefined>>();
|
||||
if (visualAvailable) {
|
||||
const limit = options.concurrency !== undefined ? concurrencyLimit(Math.max(1, Math.floor(options.concurrency)))
|
||||
: processLimit ??= concurrencyLimit(availableParallelism());
|
||||
for (const { id, basePath, headPath } of comparablePairs(options, colorSchemes, baseColorSchemes)) {
|
||||
const started = limit(() => compareInBudget(basePath, headPath));
|
||||
started.catch(() => undefined);
|
||||
ahead.set(id, started);
|
||||
}
|
||||
}
|
||||
for (const surface of options.plan.surfaces) {
|
||||
for (const side of ["base", "head"] as const) {
|
||||
if (!surface[`${side}Capture`] || surface[`${side}Surface`]?.kind !== "screen") continue;
|
||||
@@ -598,48 +678,29 @@ export async function assessPublicEvidence(options: {
|
||||
continue;
|
||||
}
|
||||
|
||||
let visual: PublicVisualVerdict;
|
||||
let assessment: VisualEvidenceAssessment | undefined;
|
||||
if (now() > deadline) {
|
||||
let compared: ComparedPair | undefined;
|
||||
try {
|
||||
compared = await (ahead.get(id) ?? compareInBudget(basePath, headPath));
|
||||
} catch (error) {
|
||||
visualCounts.failed += 1;
|
||||
const diagnostic = comparisonError(id, error, { code: "VISUAL_COMPARISON_FAILED", stage: "compare",
|
||||
message: "Screenshot comparison failed.", nextAction: "Check the screenshot files and the agent-device comparison diagnostics, then rerun comparison.", retryable: true });
|
||||
recordError(visualCounts.errors, id, diagnostic.message);
|
||||
continue;
|
||||
}
|
||||
if (!compared) {
|
||||
visualCounts.failed += 1;
|
||||
const diagnostic = comparisonError(id, undefined, { code: "VISUAL_COMPARISON_BUDGET_EXHAUSTED", stage: "compare",
|
||||
message: "The time budget expired before screenshot comparison.",
|
||||
nextAction: "Increase the evidence comparison time budget or reduce the number of selected routes, then rerun comparison.", retryable: true });
|
||||
recordError(visualCounts.errors, id, diagnostic.message);
|
||||
continue;
|
||||
} else {
|
||||
try {
|
||||
const raw = await measure(basePath, headPath);
|
||||
const { measurement, ignoredStatusBar: ignoredTop, ignoredHomeIndicator: ignoredBottom } = ignoreSystemRegions(raw, system, systemBandFrameLoader(raw, threshold));
|
||||
assessment = assessVisualMeasurements({
|
||||
baselineSamples: 1,
|
||||
currentSamples: 1,
|
||||
requiredSamples: 1,
|
||||
baselineWithin: [],
|
||||
currentWithin: [],
|
||||
crossBuild: [measurement],
|
||||
representative: measurement,
|
||||
});
|
||||
visual = visualVerdict(assessment, threshold);
|
||||
// Measuring moves is extra: once the comparison budget is spent, regions go out unmeasured.
|
||||
if (visual.verdict === "modified" && visual.regions?.length && now() <= deadline) {
|
||||
Object.assign(visual, await withRegionShifts(basePath, headPath, measurement.regions, visual.regions));
|
||||
}
|
||||
if (ignoredTop > 0) visual.ignoredStatusBarRegions = ignoredTop;
|
||||
if (ignoredBottom > 0) visual.ignoredHomeIndicatorRegions = ignoredBottom;
|
||||
if (ignoredTop > 0 || ignoredBottom > 0) visual.systemRegions = system.map((area) => ({ ...area }));
|
||||
visualCounts.compared += 1;
|
||||
if (visual.verdict === "modified") visualCounts.modified += 1;
|
||||
else if (visual.verdict === "unchanged") visualCounts.unchanged += 1;
|
||||
else visualCounts.needsReview += 1;
|
||||
} catch (error) {
|
||||
visualCounts.failed += 1;
|
||||
const diagnostic = comparisonError(id, error, { code: "VISUAL_COMPARISON_FAILED", stage: "compare",
|
||||
message: "Screenshot comparison failed.", nextAction: "Check the screenshot files and the agent-device comparison diagnostics, then rerun comparison.", retryable: true });
|
||||
recordError(visualCounts.errors, id, diagnostic.message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const { visual, assessment } = compared;
|
||||
visualCounts.compared += 1;
|
||||
if (visual.verdict === "modified") visualCounts.modified += 1;
|
||||
else if (visual.verdict === "unchanged") visualCounts.unchanged += 1;
|
||||
else visualCounts.needsReview += 1;
|
||||
|
||||
const scope = surfaceSourceScope(surface) ?? "none";
|
||||
let review: PublicSurfaceReview | undefined;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Worker, isMainThread, parentPort, workerData } from "node:worker_threads";
|
||||
import { measureRegionMoves, type Rect } from "./region-shift.js";
|
||||
|
||||
type MeasuredRegions = Awaited<ReturnType<typeof measureRegionMoves>>;
|
||||
type RegionMoveWork = { regionMoveWork: true; basePath: string; headPath: string; regions: ReadonlyArray<Rect & { dominantChange?: string }> };
|
||||
type RegionMoveReply = { measured: MeasuredRegions } | { error: string };
|
||||
|
||||
/**
|
||||
* Measures region shifts and large moves on a worker thread, so several screenshot pairs search at once while the
|
||||
* main thread stays free: the search is CPU-bound and takes seconds on a tablet-sized screenshot. Falls back to the
|
||||
* calling thread when no worker can start.
|
||||
*/
|
||||
export async function measureRegionMovesInWorker(basePath: string, headPath: string, regions: RegionMoveWork["regions"]): Promise<MeasuredRegions> {
|
||||
const work: RegionMoveWork = { regionMoveWork: true, basePath, headPath, regions };
|
||||
let worker: Worker;
|
||||
try { worker = new Worker(new URL("./region-shift-worker.js", import.meta.url), { workerData: work }); }
|
||||
catch { return measureRegionMoves(basePath, headPath, regions); }
|
||||
return new Promise((resolve, reject) => {
|
||||
let settled = false;
|
||||
const finish = (outcome: () => void) => { if (!settled) { settled = true; outcome(); } };
|
||||
worker.once("message", (reply: RegionMoveReply) => finish(() => "error" in reply ? reject(new Error(reply.error)) : resolve(reply.measured)));
|
||||
// A worker that fails to load or dies before answering is a worker that did not start: the calling thread measures.
|
||||
worker.once("error", () => finish(() => resolve(measureRegionMoves(basePath, headPath, regions))));
|
||||
worker.once("exit", () => finish(() => resolve(measureRegionMoves(basePath, headPath, regions))));
|
||||
});
|
||||
}
|
||||
|
||||
if (!isMainThread && parentPort && (workerData as Partial<RegionMoveWork> | null)?.regionMoveWork === true) {
|
||||
const port = parentPort;
|
||||
const work = workerData as RegionMoveWork;
|
||||
measureRegionMoves(work.basePath, work.headPath, work.regions)
|
||||
.then(measured => port.postMessage({ measured } satisfies RegionMoveReply), (error: unknown) => port.postMessage({ error: (error as Error).message } satisfies RegionMoveReply));
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import type { DecodedFrame } from "../shared/png-evidence.js";
|
||||
|
||||
/** How far a region's content moved from Before to After, in screenshot pixels (right and down are positive). */
|
||||
export type RegionShift = { x: number; y: number };
|
||||
type Rect = { x: number; y: number; width: number; height: number };
|
||||
export type Rect = { x: number; y: number; width: number; height: number };
|
||||
|
||||
/**
|
||||
* The farthest a region is searched for, in screenshot pixels: layout drift, not a different screen. Drift adds up
|
||||
@@ -63,16 +63,38 @@ function at(source: Image, x: number, y: number, channel?: number): number {
|
||||
return value(x0, y0) * (1 - fx) * (1 - fy) + value(x1, y0) * fx * (1 - fy) + value(x0, y1) * (1 - fx) * fy + value(x1, y1) * fx * fy;
|
||||
}
|
||||
|
||||
/** How badly After's region matches Before shifted by (sx, sy). A whole-pixel shift reads Before's pixels directly. */
|
||||
function mismatch(base: Image, head: Image, rect: Rect, sx: number, sy: number): number {
|
||||
/**
|
||||
* How badly After's region matches Before shifted by (sx, sy): the summed luminance difference, row by row. A sum
|
||||
* that passes `limit` stops early and returns a value above it: such a fit is neither the best, nor a tie, nor an
|
||||
* ambiguity, so its exact error is never read. Whole-pixel shifts read the pixel directly (the bilinear weights are
|
||||
* exactly 1 and 0 there); fractional ones interpolate like `at`.
|
||||
*/
|
||||
function mismatch(base: Image, head: Image, rect: Rect, sx: number, sy: number, limit = Infinity): number {
|
||||
const { width, height, luminance } = base;
|
||||
const maxX = width - 1, maxY = height - 1;
|
||||
const headLuminance = head.luminance, headWidth = head.width;
|
||||
const whole = Number.isInteger(sx) && Number.isInteger(sy);
|
||||
let error = 0;
|
||||
for (let y = rect.y; y < rect.y + rect.height; y += 1) {
|
||||
const by = Math.min(base.height - 1, Math.max(0, y - sy));
|
||||
for (let x = rect.x; x < rect.x + rect.width; x += 1) {
|
||||
const before = whole ? base.luminance[by * base.width + Math.min(base.width - 1, Math.max(0, x - sx))]! : at(base, x - sx, y - sy);
|
||||
error += Math.abs(before - head.luminance[y * head.width + x]!);
|
||||
const headRow = y * headWidth;
|
||||
if (whole) {
|
||||
const row = Math.min(maxY, Math.max(0, y - sy)) * width;
|
||||
for (let x = rect.x; x < rect.x + rect.width; x += 1) {
|
||||
error += Math.abs(luminance[row + Math.min(maxX, Math.max(0, x - sx))]! - headLuminance[headRow + x]!);
|
||||
}
|
||||
} else {
|
||||
const cy = Math.min(maxY, Math.max(0, y - sy));
|
||||
const y0 = Math.floor(cy), y1 = Math.min(maxY, y0 + 1), fy = cy - y0;
|
||||
const row0 = y0 * width, row1 = y1 * width;
|
||||
for (let x = rect.x; x < rect.x + rect.width; x += 1) {
|
||||
const cx = Math.min(maxX, Math.max(0, x - sx));
|
||||
const x0 = Math.floor(cx), x1 = Math.min(maxX, x0 + 1), fx = cx - x0;
|
||||
const sample = luminance[row0 + x0]! * (1 - fx) * (1 - fy) + luminance[row0 + x1]! * fx * (1 - fy)
|
||||
+ luminance[row1 + x0]! * (1 - fx) * fy + luminance[row1 + x1]! * fx * fy;
|
||||
error += Math.abs(sample - headLuminance[headRow + x]!);
|
||||
}
|
||||
}
|
||||
if (error > limit) return error;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
@@ -113,18 +135,29 @@ function regionShift(base: Image, head: Image, region: Rect): RegionShift | unde
|
||||
const unshifted = mismatch(base, head, rect, 0, 0);
|
||||
if (unshifted === 0) return undefined;
|
||||
// Whole pixels first, every pixel counting: sampling every other row aliases on thin shapes (text, hairlines).
|
||||
// A fit worse than the best so far by more than the ambiguity margin cannot become the best, tie with it, or make
|
||||
// it ambiguous; its measurement stops as soon as that is known. The margin is taken from the worst fit the tie
|
||||
// could choose, since a tie goes to the smallest move, not the least error.
|
||||
const whole: Fit[] = [];
|
||||
let least = unshifted;
|
||||
for (let sy = -MAX_SHIFT_Y; sy <= MAX_SHIFT_Y; sy += 1) {
|
||||
for (let sx = -MAX_SHIFT_X; sx <= MAX_SHIFT_X; sx += 1) whole.push({ sx, sy, error: mismatch(base, head, rect, sx, sy) });
|
||||
for (let sx = -MAX_SHIFT_X; sx <= MAX_SHIFT_X; sx += 1) {
|
||||
const error = sx === 0 && sy === 0 ? unshifted : mismatch(base, head, rect, sx, sy, (least * TIE + 1e-6) * AMBIGUOUS + 1e-6);
|
||||
least = Math.min(least, error);
|
||||
whole.push({ sx, sy, error });
|
||||
}
|
||||
}
|
||||
const coarse = bestOf(whole);
|
||||
if (whole.some(fit => Math.abs(fit.sy - coarse.sy) >= 2 && fit.error <= coarse.error * AMBIGUOUS + 1e-6)) return undefined;
|
||||
// Then sixths of a pixel around it, from whole-number steps so a move up and a move down round alike.
|
||||
const fine: Fit[] = [];
|
||||
least = coarse.error;
|
||||
for (let iy = -STEPS_PER_PIXEL; iy <= STEPS_PER_PIXEL; iy += 1) {
|
||||
for (let ix = -STEPS_PER_PIXEL; ix <= STEPS_PER_PIXEL; ix += 1) {
|
||||
const sx = coarse.sx + ix / STEPS_PER_PIXEL, sy = coarse.sy + iy / STEPS_PER_PIXEL;
|
||||
fine.push({ sx, sy, error: ix === 0 && iy === 0 ? coarse.error : mismatch(base, head, rect, sx, sy) });
|
||||
const error = ix === 0 && iy === 0 ? coarse.error : mismatch(base, head, rect, sx, sy, least * TIE + 1e-6);
|
||||
least = Math.min(least, error);
|
||||
fine.push({ sx, sy, error });
|
||||
}
|
||||
}
|
||||
const best = bestOf(fine);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { execFile } from "node:child_process";
|
||||
import { lstat, readFile, realpath } from "node:fs/promises";
|
||||
import { isAbsolute } from "node:path";
|
||||
|
||||
@@ -133,30 +133,34 @@ export async function diffScreenshots(options: {
|
||||
|| !isAbsolute(options.command)
|
||||
|| /[\u0000-\u001f\u007f]/.test(options.command)
|
||||
) throw new Error("agent-device command must be an absolute path");
|
||||
const result = spawnSync(
|
||||
options.command,
|
||||
[
|
||||
"--json",
|
||||
"diff",
|
||||
"screenshot",
|
||||
"--baseline",
|
||||
baselinePath,
|
||||
currentPath,
|
||||
"--threshold",
|
||||
String(threshold),
|
||||
],
|
||||
{
|
||||
encoding: "utf8",
|
||||
shell: false,
|
||||
timeout: options.timeoutMs ?? 60_000,
|
||||
env: {
|
||||
PATH: process.env.PATH,
|
||||
const result = await new Promise<{ error: (Error & { code?: unknown }) | null; stdout: string; stderr: string }>(resolve => {
|
||||
execFile(
|
||||
options.command,
|
||||
[
|
||||
"--json",
|
||||
"diff",
|
||||
"screenshot",
|
||||
"--baseline",
|
||||
baselinePath,
|
||||
currentPath,
|
||||
"--threshold",
|
||||
String(threshold),
|
||||
],
|
||||
{
|
||||
encoding: "utf8",
|
||||
shell: false,
|
||||
timeout: options.timeoutMs ?? 60_000,
|
||||
env: {
|
||||
PATH: process.env.PATH,
|
||||
},
|
||||
maxBuffer: 4 * 1024 * 1024,
|
||||
},
|
||||
maxBuffer: 4 * 1024 * 1024,
|
||||
},
|
||||
);
|
||||
if (result.error) throw new Error(`Could not run screenshot diff: ${result.error.message}`);
|
||||
if (result.status !== 0) {
|
||||
(error, stdout, stderr) => resolve({ error, stdout, stderr }),
|
||||
);
|
||||
});
|
||||
// execFile reports a non-zero exit as an error carrying the exit status; a spawn failure or timeout carries none.
|
||||
if (result.error && typeof result.error.code !== "number") throw new Error(`Could not run screenshot diff: ${result.error.message}`);
|
||||
if (result.error) {
|
||||
const detail = (result.stderr || result.stdout || "unknown error").trim().slice(0, 500);
|
||||
throw new Error(`Screenshot diff failed: ${detail}`);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,57 @@
|
||||
import { posix } from "node:path";
|
||||
import ts from "typescript";
|
||||
|
||||
/** The `@/*` import alias a tsconfig maps to one project directory, such as `src/` or the root. */
|
||||
/** The import aliases a tsconfig maps to project directories, such as `@/*` to `src/` and `@/assets/*` to `assets/`. */
|
||||
export type TsconfigAlias = {
|
||||
/** Directory prefix that replaces `@/`, with a trailing slash or empty for the project root. */
|
||||
target: string;
|
||||
/** Each alias prefix (`@/`, `@/assets/`) and the directory prefix that replaces it, longest prefix first. */
|
||||
prefixes: readonly { prefix: string; target: string }[];
|
||||
/** `baseUrl` is the project root: a bare specifier no alias matches is looked up there before it is taken for a package. */
|
||||
baseUrl?: true;
|
||||
/** Set when the tsconfig asks for module resolution the static analysis cannot follow. */
|
||||
unsupported?: string;
|
||||
};
|
||||
|
||||
const SINGLE_DIRECTORY_TARGET = /^(?:\.\/)?((?:[\w.-]+\/)*)\*$/;
|
||||
// A relative-looking key (`./*`, `/*`) is never applied: TypeScript and Metro resolve relative specifiers directly.
|
||||
const PREFIX_KEY = /^([^*./][^*]*\/)\*$/;
|
||||
const DEFAULT: TsconfigAlias = { prefixes: [{ prefix: "@/", target: "src/" }] };
|
||||
|
||||
/**
|
||||
* Static analysis follows one alias, `@/*`, pointing at a single directory (`./*`, `src/*`, `./src/*`),
|
||||
* which is what create-expo-app and the Expo docs set up. Anything else is reported, not guessed.
|
||||
* Static analysis follows `paths` entries of the form `prefix/*` that each point at a single directory (`./*`, `src/*`,
|
||||
* `./assets/*`), which covers create-expo-app's `@/*` and the extra entries apps add beside it. Anything else is
|
||||
* reported, not guessed.
|
||||
*/
|
||||
export function readTsconfigAlias(configText: string | undefined): TsconfigAlias {
|
||||
if (configText === undefined) return { target: "src/" };
|
||||
if (configText === undefined) return DEFAULT;
|
||||
const parsed = ts.parseConfigFileTextToJson("tsconfig.json", configText);
|
||||
const options = parsed.config?.compilerOptions ?? {};
|
||||
const unsupported = { target: "src/", unsupported: "custom module resolution is not statically supported" };
|
||||
const unsupported = { ...DEFAULT, unsupported: "custom module resolution is not statically supported" };
|
||||
if (parsed.error) return unsupported;
|
||||
if (options.baseUrl && ![".", "./"].includes(options.baseUrl)) return unsupported;
|
||||
if (parsed.config?.extends && parsed.config.extends !== "expo/tsconfig.base") return unsupported;
|
||||
const baseUrl = options.baseUrl ? { baseUrl: true as const } : {};
|
||||
const entries = Object.entries(options.paths ?? {}) as [string, unknown][];
|
||||
if (entries.length === 0) return { target: "src/" };
|
||||
if (entries.length > 1 || entries[0]![0] !== "@/*") return unsupported;
|
||||
const targets = entries[0]![1];
|
||||
if (!Array.isArray(targets) || targets.length !== 1 || typeof targets[0] !== "string") return unsupported;
|
||||
const match = SINGLE_DIRECTORY_TARGET.exec(targets[0]);
|
||||
if (!match || match[1]!.split("/").includes("..")) return unsupported;
|
||||
return { target: match[1]! };
|
||||
if (entries.length === 0) return { ...DEFAULT, ...baseUrl };
|
||||
const prefixes: { prefix: string; target: string }[] = [];
|
||||
for (const [key, targets] of entries) {
|
||||
const prefix = PREFIX_KEY.exec(key)?.[1];
|
||||
if (!prefix || !Array.isArray(targets) || targets.length !== 1 || typeof targets[0] !== "string") return unsupported;
|
||||
const match = SINGLE_DIRECTORY_TARGET.exec(targets[0]);
|
||||
if (!match || match[1]!.split("/").some(segment => segment === "." || segment === "..")) return unsupported;
|
||||
prefixes.push({ prefix, target: match[1]! });
|
||||
}
|
||||
// TypeScript picks the pattern with the longest prefix, so `@/assets/x` goes to `assets/`, not `src/assets/`.
|
||||
return { prefixes: prefixes.sort((a, b) => b.prefix.length - a.prefix.length), ...baseUrl };
|
||||
}
|
||||
|
||||
/** The project path an aliased specifier names, before extensions, or undefined when no alias matches it. */
|
||||
export function resolveTsconfigAlias(alias: TsconfigAlias, specifier: string): string | undefined {
|
||||
const entry = alias.prefixes.find(({ prefix }) => specifier.startsWith(prefix));
|
||||
// Normalized as Metro joins it: `@app/a/../b` is `src/b`, and a trailing slash still finds `index`.
|
||||
return entry ? posix.normalize(`${entry.target}${specifier.slice(entry.prefix.length)}`).replace(/\/$/, "") : undefined;
|
||||
}
|
||||
|
||||
/** The project path a bare specifier names under a root `baseUrl`, or undefined; a miss there is a package, not a gap. */
|
||||
export function resolveTsconfigBaseUrl(alias: TsconfigAlias, specifier: string): string | undefined {
|
||||
return alias.baseUrl && !/^[./]/.test(specifier) ? specifier : undefined;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { spawnSync } from "node:child_process";
|
||||
import ts from "typescript";
|
||||
import type { SourceChange } from "./git-diff.js";
|
||||
import { validateSourceRoutes, type SourceRoute } from "../contracts/source-route.js";
|
||||
import { readTsconfigAlias } from "../shared/tsconfig-alias.js";
|
||||
import { readTsconfigAlias, resolveTsconfigAlias, resolveTsconfigBaseUrl } from "../shared/tsconfig-alias.js";
|
||||
|
||||
/** Repository path → file text at one exact commit. Non-source files carry an empty string. */
|
||||
export type SourceSnapshot = ReadonlyMap<string, string>;
|
||||
@@ -50,11 +50,12 @@ export function surfaceDependencies(routes: readonly SourceRoute[], files: Sourc
|
||||
if (alias.unsupported) unresolved.add("Custom TypeScript module resolution requires conservative capture");
|
||||
const cache = new Map<string, string[]>();
|
||||
const resolveModule = (importer: string, specifier: string): string | undefined => {
|
||||
const base = specifier.startsWith("@/") ? `${alias.target}${specifier.slice(2)}`
|
||||
: specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer), specifier))
|
||||
: undefined;
|
||||
const base = resolveTsconfigAlias(alias, specifier)
|
||||
?? (specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer), specifier))
|
||||
: resolveTsconfigBaseUrl(alias, specifier));
|
||||
if (!base) return undefined;
|
||||
const extensions = ["tsx", "ts", "jsx", "js"].flatMap(ext => [`.${platform}.${ext}`, ...(platform === "web" ? [] : [`.native.${ext}`]), `.${ext}`]).concat([".mjs", ".cjs", ".json"]);
|
||||
// Metro tries a platform suffix with every extension before the next suffix, so `Foo.ios.ts` beats `Foo.tsx`.
|
||||
const extensions = [`.${platform}`, ...(platform === "web" ? [] : [".native"]), ""].flatMap(suffix => ["tsx", "ts", "jsx", "js"].map(ext => `${suffix}.${ext}`)).concat([".mjs", ".cjs", ".json"]);
|
||||
return [...extensions.map((ext) => base + ext), base,
|
||||
...extensions.map((ext) => `${base}/index${ext}`)].find((candidate) => !/(?:^|\/)surfaces?\.json$/.test(candidate) && files.has(candidate));
|
||||
};
|
||||
@@ -78,7 +79,8 @@ export function surfaceDependencies(routes: readonly SourceRoute[], files: Sourc
|
||||
const specifier = node.text;
|
||||
const resolved = resolveModule(path, specifier);
|
||||
if (resolved) dependencies.push(resolved);
|
||||
else if (specifier.startsWith(".") || specifier.startsWith("@/") || specifier.startsWith("~")) {
|
||||
// An alias that matches but finds no file (an .svg, a scale variant) is local code this analysis cannot follow, not a package.
|
||||
else if (specifier.startsWith(".") || resolveTsconfigAlias(alias, specifier) !== undefined || specifier.startsWith("@/") || specifier.startsWith("~")) {
|
||||
unresolved.add(`Unresolved runtime import: ${path} -> ${specifier}`);
|
||||
}
|
||||
// Bare npm packages are covered by lockfile/package changes.
|
||||
@@ -103,7 +105,7 @@ export function surfaceDependencies(routes: readonly SourceRoute[], files: Sourc
|
||||
const pending = [surface.routeFile, ...surface.sourceFiles];
|
||||
let directory = posix.dirname(surface.routeFile);
|
||||
while (directory !== "." && directory !== "/") {
|
||||
const suffixes = ["tsx", "ts", "jsx", "js"].flatMap(extension => [`.${platform}.${extension}`, ...(platform === "web" ? [] : [`.native.${extension}`]), `.${extension}`]);
|
||||
const suffixes = [`.${platform}`, ...(platform === "web" ? [] : [".native"]), ""].flatMap(suffix => ["tsx", "ts", "jsx", "js"].map(ext => `${suffix}.${ext}`));
|
||||
const layout = suffixes.map(suffix => `${directory}/_layout${suffix}`).find(path => files.has(path));
|
||||
if (layout) pending.push(layout);
|
||||
directory = posix.dirname(directory);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { posix } from "node:path";
|
||||
import ts from "typescript";
|
||||
import type { SourceSnapshot } from "./dependency-graph.js";
|
||||
import { readTsconfigAlias } from "../shared/tsconfig-alias.js";
|
||||
import { readTsconfigAlias, resolveTsconfigAlias, resolveTsconfigBaseUrl } from "../shared/tsconfig-alias.js";
|
||||
import { detectAppDir, routeGroupOf } from "./route-providers/expo-router.js";
|
||||
import { validateSourceRoutes, type SourceRoute } from "../contracts/source-route.js";
|
||||
import { validateNavigationGraph, type NavigationEdge, type NavigationGraph } from "../contracts/navigation-graph.js";
|
||||
@@ -54,7 +54,7 @@ export function extractSourceNavigation(routes: readonly SourceRoute[], files: S
|
||||
if (routes.length > 5_000 || files.size > 50_000) throw new Error("Source navigation inventory exceeds its analysis limit");
|
||||
const appDir = detectAppDir(files, analysis.entry);
|
||||
const platform = analysis.platform ?? "ios";
|
||||
const extensions = ["tsx", "ts", "jsx", "js"].flatMap(extension => [`.${platform}.${extension}`, ...(platform === "web" ? [] : [`.native.${extension}`]), `.${extension}`]).concat([".mjs", ".cjs"]);
|
||||
const extensions = [`.${platform}`, ...(platform === "web" ? [] : [".native"]), ""].flatMap(suffix => ["tsx", "ts", "jsx", "js"].map(ext => `${suffix}.${ext}`)).concat([".mjs", ".cjs"]);
|
||||
const unresolved = new Set<string>();
|
||||
const edges = new Map<string, NavigationEdge>();
|
||||
const modalSurfaceIds = new Set<string>();
|
||||
@@ -65,8 +65,8 @@ export function extractSourceNavigation(routes: readonly SourceRoute[], files: S
|
||||
const alias = readTsconfigAlias(files.get("tsconfig.json"));
|
||||
if (alias.unsupported) unresolved.add(`Unresolved navigation: tsconfig.json: ${alias.unsupported}`);
|
||||
const resolveModule = (specifier: string, importer: string): string | undefined => {
|
||||
const base = specifier.startsWith("@/") ? `${alias.target}${specifier.slice(2)}`
|
||||
: specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer.replace(/^\//, "")), specifier)) : undefined;
|
||||
const base = resolveTsconfigAlias(alias, specifier)
|
||||
?? (specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer.replace(/^\//, "")), specifier)) : resolveTsconfigBaseUrl(alias, specifier));
|
||||
if (!base || base.startsWith("../")) return undefined;
|
||||
const withoutJs = /\.[cm]?jsx?$/.test(base) ? base.replace(/\.[cm]?jsx?$/, "") : base;
|
||||
return [...extensions.map((ext) => base + ext), base,
|
||||
@@ -542,7 +542,7 @@ export function extractSourceNavigation(routes: readonly SourceRoute[], files: S
|
||||
let parent: ts.Node = declaration;
|
||||
while (!ts.isImportDeclaration(parent) && !ts.isSourceFile(parent)) parent = parent.parent;
|
||||
if (ts.isImportDeclaration(parent) && ts.isStringLiteral(parent.moduleSpecifier)
|
||||
&& /^(?:\.|@\/|~)/.test(parent.moduleSpecifier.text)
|
||||
&& (/^(?:\.|@\/|~)/.test(parent.moduleSpecifier.text) || resolveTsconfigAlias(alias, parent.moduleSpecifier.text) !== undefined)
|
||||
&& !assetFile.test(parent.moduleSpecifier.text)
|
||||
&& !resolveModule(parent.moduleSpecifier.text, parent.getSourceFile().fileName)) issue(parent, "local imported code could not be resolved");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { posix } from "node:path";
|
||||
import ts from "typescript";
|
||||
import { readTsconfigAlias } from "../../shared/tsconfig-alias.js";
|
||||
import { readTsconfigAlias, resolveTsconfigAlias, resolveTsconfigBaseUrl } from "../../shared/tsconfig-alias.js";
|
||||
|
||||
const UNKNOWN = "\u0000";
|
||||
const MAX_VALUES = 64;
|
||||
@@ -15,7 +15,7 @@ function unwrap(node: ts.Node): ts.Node {
|
||||
|
||||
/** Prove that every render path forwards elsewhere; unknown behavior remains capturable. */
|
||||
export function expoRedirectTargets(files: ReadonlyMap<string, string>, routeFiles: readonly string[], platform = "ios"): Map<string, string[]> {
|
||||
const extensions = ["tsx", "ts", "jsx", "js"].flatMap(ext => [`.${platform}.${ext}`, ...(platform === "web" ? [] : [`.native.${ext}`]), `.${ext}`]).concat([".mjs", ".cjs"]);
|
||||
const extensions = [`.${platform}`, ...(platform === "web" ? [] : [".native"]), ""].flatMap(suffix => ["tsx", "ts", "jsx", "js"].map(ext => `${suffix}.${ext}`)).concat([".mjs", ".cjs"]);
|
||||
const sources = new Map<string, ts.SourceFile | undefined>();
|
||||
let sourceBytes = 0;
|
||||
const sourceFile = (name: string): ts.SourceFile | undefined => {
|
||||
@@ -34,8 +34,8 @@ export function expoRedirectTargets(files: ReadonlyMap<string, string>, routeFil
|
||||
};
|
||||
const alias = readTsconfigAlias(files.get("tsconfig.json"));
|
||||
const resolveModule = (specifier: string, importer: string): string | undefined => {
|
||||
const base = specifier.startsWith("@/") && !alias.unsupported ? `${alias.target}${specifier.slice(2)}`
|
||||
: specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer.replace(/^\//, "")), specifier)) : undefined;
|
||||
const base = (alias.unsupported ? undefined : resolveTsconfigAlias(alias, specifier))
|
||||
?? (specifier.startsWith(".") ? posix.normalize(posix.join(posix.dirname(importer.replace(/^\//, "")), specifier)) : alias.unsupported ? undefined : resolveTsconfigBaseUrl(alias, specifier));
|
||||
if (!base || base.startsWith("../")) return undefined;
|
||||
const withoutJs = base.replace(/\.[cm]?jsx?$/, "");
|
||||
return [...extensions.map(ext => base + ext), base, ...extensions.map(ext => `${base}/index${ext}`),
|
||||
|
||||
@@ -45,6 +45,8 @@ export function discoverReactNavigation(files: Record<string, string>, options:
|
||||
}
|
||||
}
|
||||
}
|
||||
// TypeScript uses the pattern with the longest prefix and no other, so `@/assets/x` never falls back to `@/*`.
|
||||
aliases.sort((a, b) => b.pattern.split("*")[0]!.length - a.pattern.split("*")[0]!.length);
|
||||
const resolveModule = (file: string, specifier: string): string | undefined => {
|
||||
const bases: string[] = [];
|
||||
if (specifier.startsWith(".")) bases.push(posix.normalize(posix.join(posix.dirname(file), specifier)));
|
||||
@@ -54,6 +56,7 @@ export function discoverReactNavigation(files: Record<string, string>, options:
|
||||
if (suffix === undefined ? specifier === prefix : specifier.startsWith(prefix!) && specifier.endsWith(suffix)) {
|
||||
const replacement = suffix === undefined ? "" : specifier.slice(prefix!.length, specifier.length - suffix.length);
|
||||
bases.push(...alias.targets.map((target) => posix.normalize(posix.join(alias.base, target.replace("*", replacement)))));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ jobs:
|
||||
contents: read
|
||||
outputs:
|
||||
targets: ${{ steps.targets.outputs.targets }}
|
||||
max_parallel: ${{ steps.targets.outputs.max_parallel }}
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with: { ref: '${{ github.sha }}', path: app, persist-credentials: false }
|
||||
@@ -51,12 +52,15 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
targets="$(node "$TOOLS/dist/cli.js" config:targets --project "$GITHUB_WORKSPACE/app/$APP_PROJECT_DIR" --config .expo-explore/config.yaml | jq -c '[.targets[].id]')"
|
||||
echo "targets=$targets" >> "$GITHUB_OUTPUT"
|
||||
listed="$(node "$TOOLS/dist/cli.js" config:targets --project "$GITHUB_WORKSPACE/app/$APP_PROJECT_DIR" --config .expo-explore/config.yaml)"
|
||||
echo "targets=$(jq -c '[.targets[].id]' <<< "$listed")" >> "$GITHUB_OUTPUT"
|
||||
# Each target job needs a simulator session: at most capture.maxSessions of them run at once.
|
||||
echo "max_parallel=$(jq '.maxParallel // (.targets | length)' <<< "$listed")" >> "$GITHUB_OUTPUT"
|
||||
baseline:
|
||||
needs: targets
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: ${{ fromJSON(needs.targets.outputs.max_parallel) }}
|
||||
matrix:
|
||||
target: ${{ fromJSON(needs.targets.outputs.targets) }}
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
@@ -48,6 +48,7 @@ jobs:
|
||||
contents: read
|
||||
outputs:
|
||||
targets: ${{ steps.targets.outputs.targets }}
|
||||
max_parallel: ${{ steps.targets.outputs.max_parallel }}
|
||||
base: ${{ steps.refs.outputs.base }}
|
||||
head: ${{ steps.refs.outputs.head }}
|
||||
compare: ${{ steps.refs.outputs.compare }}
|
||||
@@ -89,12 +90,15 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
targets="$(node "$TOOLS/dist/cli.js" config:targets --project "$GITHUB_WORKSPACE/app-head/$APP_PROJECT_DIR" --config .expo-explore/config.yaml | jq -c '[.targets[].id]')"
|
||||
echo "targets=$targets" >> "$GITHUB_OUTPUT"
|
||||
listed="$(node "$TOOLS/dist/cli.js" config:targets --project "$GITHUB_WORKSPACE/app-head/$APP_PROJECT_DIR" --config .expo-explore/config.yaml)"
|
||||
echo "targets=$(jq -c '[.targets[].id]' <<< "$listed")" >> "$GITHUB_OUTPUT"
|
||||
# Each target job needs a simulator session: at most capture.maxSessions of them run at once.
|
||||
echo "max_parallel=$(jq '.maxParallel // (.targets | length)' <<< "$listed")" >> "$GITHUB_OUTPUT"
|
||||
capture:
|
||||
needs: targets
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: ${{ fromJSON(needs.targets.outputs.max_parallel) }}
|
||||
matrix:
|
||||
target: ${{ fromJSON(needs.targets.outputs.targets) }}
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
@@ -33,6 +33,7 @@ jobs:
|
||||
pull-requests: read
|
||||
outputs:
|
||||
targets: ${{ steps.targets.outputs.targets }}
|
||||
max_parallel: ${{ steps.targets.outputs.max_parallel }}
|
||||
# The failure job comments with these when a capture job fails before it resolves the PR itself.
|
||||
pr_number: ${{ steps.pr.outputs.pr_number }}
|
||||
base: ${{ steps.pr.outputs.base }}
|
||||
@@ -69,12 +70,15 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
targets="$(node "$TOOLS/dist/cli.js" config:targets --project "$GITHUB_WORKSPACE/app-head/$APP_PROJECT_DIR" --config .expo-explore/config.yaml | jq -c '[.targets[].id]')"
|
||||
echo "targets=$targets" >> "$GITHUB_OUTPUT"
|
||||
listed="$(node "$TOOLS/dist/cli.js" config:targets --project "$GITHUB_WORKSPACE/app-head/$APP_PROJECT_DIR" --config .expo-explore/config.yaml)"
|
||||
echo "targets=$(jq -c '[.targets[].id]' <<< "$listed")" >> "$GITHUB_OUTPUT"
|
||||
# Each target job needs a simulator session: at most capture.maxSessions of them run at once.
|
||||
echo "max_parallel=$(jq '.maxParallel // (.targets | length)' <<< "$listed")" >> "$GITHUB_OUTPUT"
|
||||
capture:
|
||||
needs: targets
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: ${{ fromJSON(needs.targets.outputs.max_parallel) }}
|
||||
matrix:
|
||||
target: ${{ fromJSON(needs.targets.outputs.targets) }}
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
@@ -188,12 +188,11 @@ test("Map keeps selected elevated arrows behind screenshots without rendering na
|
||||
await expect(sourceHitArea.locator("title")).toHaveText("Source navigation\npush · app/home.tsx");
|
||||
await page.mouse.move(1320, 30);
|
||||
const dimmedComparisons = [];
|
||||
for (const presentation of ["muted", "selection"]) {
|
||||
// Only the Changes filter dims a screen; a selection fades nothing.
|
||||
for (const presentation of ["muted"]) {
|
||||
await page.evaluate(mode => {
|
||||
const profile = document.querySelector('.react-flow__node[data-id="profile"]');
|
||||
const canvas = document.querySelector(".map-canvas");
|
||||
profile.classList.toggle("graph-node-muted", mode === "muted");
|
||||
canvas.classList.toggle("screen-selection-active", mode === "selection");
|
||||
}, presentation);
|
||||
const dimmedWithArrows = await profileImage.screenshot({ animations: "disabled" });
|
||||
await page.locator(".map-surface .react-flow__edges").evaluate(node => { node.style.visibility = "hidden"; });
|
||||
@@ -216,7 +215,6 @@ test("Map keeps selected elevated arrows behind screenshots without rendering na
|
||||
}
|
||||
await page.evaluate(() => {
|
||||
document.querySelector('.react-flow__node[data-id="profile"]').classList.remove("graph-node-muted");
|
||||
document.querySelector(".map-canvas").classList.remove("screen-selection-active");
|
||||
});
|
||||
await page.getByRole("button", { name: "Open Profile", exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.selectedScreen), "profile");
|
||||
|
||||
@@ -155,7 +155,7 @@ test("Compare steps through changed screens and their changed areas", { timeout:
|
||||
|
||||
// A changed screen opens the same review in the Inspector on every canvas: Compare at sidebar
|
||||
// size. CI compares the images pixel for pixel, so /games's four CI regions read as changed
|
||||
// areas, outlined at the same place on both sides.
|
||||
// areas, outlined on After; Before keeps the same outlines unseen until one is hovered on After.
|
||||
await openChangedScreen(page, /, Modified, \/games$/);
|
||||
const inspector = page.locator(".right-panel");
|
||||
const review = inspector.getByRole("region", { name: "Changes in /games" });
|
||||
@@ -166,6 +166,8 @@ test("Compare steps through changed screens and their changed areas", { timeout:
|
||||
await expect.poll(() => outlineCount("after")).toBeGreaterThan(0);
|
||||
const areas = await outlineCount("after");
|
||||
assert.equal(await outlineCount("before"), areas);
|
||||
await expect(review.locator('[data-side="after"] .visual-change-outlines')).toHaveClass(/linked/);
|
||||
await expect(review.locator('[data-side="before"] .visual-change-outlines')).toHaveClass(/ghost/);
|
||||
// Esc closes the Inspector; the selection stays, a second Esc clears it.
|
||||
const selected = page.locator(".map-canvas .react-flow__node-screen.selected");
|
||||
await page.keyboard.press("Escape");
|
||||
@@ -225,6 +227,12 @@ test("Compare steps through changed screens and their changed areas", { timeout:
|
||||
await expect.poll(() => compare.locator(`[data-side="${side}"] img`).first()
|
||||
.evaluate(image => image.naturalWidth)).toBe(402);
|
||||
}
|
||||
// Hovering an outline on After lights the same area on Before, and only that one.
|
||||
await compare.locator('[data-side="after"] .visual-change-outline').nth(1).hover();
|
||||
await expect(compare.locator('[data-side="before"] .visual-change-outline.hovered')).toHaveCount(1);
|
||||
await expect(compare.locator('[data-side="before"] .visual-change-outline').nth(1)).toHaveClass(/hovered/);
|
||||
await page.mouse.move(0, 0);
|
||||
await expect(compare.locator(".visual-change-outline.hovered")).toHaveCount(0);
|
||||
|
||||
// J and K step through the changed areas; Esc clears the highlight.
|
||||
const outlines = compare.locator('[data-side="after"] .visual-change-outline');
|
||||
@@ -234,6 +242,14 @@ test("Compare steps through changed screens and their changed areas", { timeout:
|
||||
await expect(outlines.nth(1)).toHaveClass(/active/);
|
||||
await page.keyboard.press("k");
|
||||
await expect(outlines.nth(0)).toHaveClass(/active/);
|
||||
// Esc in the bottom bar's More menu closes the menu and only the menu.
|
||||
const more = page.getByRole("button", { name: "More", exact: true });
|
||||
await more.click();
|
||||
await expect(page.getByRole("menu", { name: "More" })).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(page.getByRole("menu", { name: "More" })).toHaveCount(0);
|
||||
await expect(more).toBeFocused();
|
||||
await expect(outlines.nth(0)).toHaveClass(/active/);
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(compare.locator(".visual-change-outline.active")).toHaveCount(0);
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { chromium, expect } from "@playwright/test";
|
||||
import { PNG } from "pngjs";
|
||||
import { createBrowserVite } from "../helpers/browser-vite.mjs";
|
||||
|
||||
function png(width, height, color) {
|
||||
const image = new PNG({ width, height });
|
||||
for (let index = 0; index < image.data.length; index += 4) image.data.set([...color, 255], index);
|
||||
return `data:image/png;base64,${PNG.sync.write(image).toString("base64")}`;
|
||||
}
|
||||
|
||||
// Split over one screen with two changed areas and a card that moved 40% of the width right (at 60% in After, so
|
||||
// at 20% in Before), and a second screen with one changed area elsewhere. The status bar CI left out is a foldable's
|
||||
// rail pill, not a band across the top. Keys stand in for the controller's, so the pointer can stay where it is:
|
||||
// 1 and 2 pick Split and Swipe, o toggles the outlines, n steps to the other screen, j selects the first area.
|
||||
const entry = `
|
||||
import { useState, useEffect } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { CompareStage } from "/src/components/compare/compare-section.tsx";
|
||||
import "/src/styles.css";
|
||||
const screens = [
|
||||
[
|
||||
{ x: 10, y: 20, width: 30, height: 20, share: 40, regionCount: 1 },
|
||||
{ x: 60, y: 60, width: 30, height: 20, share: 30, regionCount: 1, move: { x: 40, y: 0, amount: { x: 400, y: 0 }, unit: "px" } },
|
||||
{ x: 55, y: 20, width: 35, height: 20, share: 30, regionCount: 1 },
|
||||
],
|
||||
[{ x: 10, y: 85, width: 20, height: 10, share: 100, regionCount: 1 }],
|
||||
];
|
||||
const systemRegions = [{ kind: "status-bar", x: 40, y: 0, width: 20, height: 4 }];
|
||||
function Harness() {
|
||||
const [mode, setMode] = useState("split");
|
||||
const [outlines, setOutlines] = useState(true);
|
||||
const [screen, setScreen] = useState(0);
|
||||
const [active, setActive] = useState();
|
||||
useEffect(() => {
|
||||
const onKey = (event) => {
|
||||
if (event.key === "1") setMode("split");
|
||||
if (event.key === "2") setMode("swipe");
|
||||
if (event.key === "o") setOutlines((shown) => !shown);
|
||||
if (event.key === "n") setScreen((index) => 1 - index);
|
||||
if (event.key === "j") setActive(0);
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, []);
|
||||
const diff = { id: "s" + screen, status: "modified", beforeScreenshot: window.before, afterScreenshot: window.after };
|
||||
return (
|
||||
<div className={"compare-stage mode-" + mode} style={{ width: 800, height: 500, display: "flex" }}>
|
||||
<CompareStage key="stage" mode={mode} diff={diff} title="Share" areas={screens[screen]} activeArea={active}
|
||||
showOutlines={outlines} systemRegions={systemRegions} overlay={null} flipSide="after" onFlip={() => {}}
|
||||
swipePosition={50} onSwipePosition={() => {}} aspect={1} onAspect={() => {}} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
createRoot(document.getElementById("root")).render(<Harness />);
|
||||
`;
|
||||
|
||||
async function openSplit(t, contextOptions = {}) {
|
||||
const vite = await createBrowserVite(t, {
|
||||
configFile: false, root: fileURLToPath(new URL("../../viewer", import.meta.url)),
|
||||
logLevel: "error", esbuild: { jsx: "automatic" },
|
||||
plugins: [{
|
||||
name: "split-outlines-fixture",
|
||||
resolveId: id => id === "/__split-outlines.tsx" ? id : undefined,
|
||||
load: id => id === "/__split-outlines.tsx" ? entry : undefined,
|
||||
configureServer(server) {
|
||||
server.middlewares.use((request, response, next) => {
|
||||
if (new URL(request.url, "http://localhost").pathname !== "/") return next();
|
||||
response.setHeader("Content-Type", "text/html");
|
||||
response.end('<!doctype html><html><body style="margin:0"><div id="root"></div><script type="module" src="/__split-outlines.tsx"></script></body></html>');
|
||||
});
|
||||
},
|
||||
}],
|
||||
server: { host: "127.0.0.1", port: 0 },
|
||||
});
|
||||
await vite.listen();
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
t.after(() => browser.close());
|
||||
const page = await browser.newPage({ viewport: { width: 900, height: 600 }, ...contextOptions });
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
t.after(() => assert.deepEqual(errors, []));
|
||||
await page.addInitScript(images => Object.assign(window, images), { before: png(100, 100, [240, 240, 240]), after: png(100, 100, [230, 230, 230]) });
|
||||
await page.goto(`http://127.0.0.1:${vite.httpServer.address().port}/`);
|
||||
const outline = (side, index) => page.locator(`[data-side="${side}"] .visual-change-outline`).nth(index);
|
||||
await expect(outline("after", 0)).toBeVisible();
|
||||
return { page, outline };
|
||||
}
|
||||
|
||||
const opacity = locator => locator.evaluate(element => Number(getComputedStyle(element).opacity));
|
||||
|
||||
test("Split keeps the ignored system regions the report names on both sides", { timeout: 30_000 }, async t => {
|
||||
const { page } = await openSplit(t);
|
||||
for (const side of ["before", "after"]) {
|
||||
const band = page.locator(`[data-side="${side}"] .visual-system-region-status-bar`);
|
||||
await expect(band).toHaveCount(1);
|
||||
const [frame, box] = await Promise.all([page.locator(`[data-side="${side}"] .compare-frame`).boundingBox(), band.boundingBox()]);
|
||||
assert.ok(Math.abs((box.x - frame.x) - 0.4 * frame.width) < 1, `${side}'s band sits where the report puts the rail pill`);
|
||||
assert.ok(Math.abs(box.width - 0.2 * frame.width) < 1);
|
||||
}
|
||||
});
|
||||
|
||||
test("Split hides Before's changed outlines but keeps a moved area where its content was", { timeout: 30_000 }, async t => {
|
||||
const { page, outline } = await openSplit(t);
|
||||
await expect.poll(() => opacity(outline("before", 0))).toBe(0);
|
||||
await expect.poll(() => opacity(outline("before", 1))).toBe(1);
|
||||
await expect(outline("before", 1).locator(".visual-change-measure")).toHaveCount(1);
|
||||
const frame = side => page.locator(`[data-side="${side}"] .compare-frame`).boundingBox();
|
||||
const [before, after, beforeFrame, afterFrame] = await Promise.all([outline("before", 1).boundingBox(), outline("after", 1).boundingBox(),
|
||||
frame("before"), frame("after")]);
|
||||
assert.ok(Math.abs(((after.x - afterFrame.x) - (before.x - beforeFrame.x)) - 0.4 * afterFrame.width) < 1, "Before's moved outline is back by the move");
|
||||
});
|
||||
|
||||
test("A hover is dropped when the screen, the mode or the outlines change under the pointer", { timeout: 30_000 }, async t => {
|
||||
const { page, outline } = await openSplit(t);
|
||||
const hovered = page.locator(".visual-change-outline.hovered");
|
||||
for (const [away, back] of [["2", "1"], ["o", "o"], ["n", "n"]]) {
|
||||
await outline("after", 0).hover();
|
||||
await expect(outline("before", 0)).toHaveClass(/hovered/);
|
||||
// The outline goes from under the pointer, which then moves off the frame before it comes back.
|
||||
await page.keyboard.press(away);
|
||||
await page.mouse.move(0, 0);
|
||||
await page.keyboard.press(back);
|
||||
await expect(outline("after", 0)).toBeVisible();
|
||||
await expect(hovered).toHaveCount(0);
|
||||
}
|
||||
});
|
||||
|
||||
test("The hovered outline on After stays lit while another area is selected", { timeout: 30_000 }, async t => {
|
||||
const { page, outline } = await openSplit(t);
|
||||
await page.keyboard.press("j");
|
||||
await outline("after", 2).hover();
|
||||
await expect.poll(() => opacity(outline("after", 2))).toBe(1);
|
||||
await expect.poll(() => opacity(outline("before", 2))).toBe(1);
|
||||
await expect.poll(() => opacity(outline("after", 1))).toBe(0.35);
|
||||
});
|
||||
|
||||
test("A screen without hover keeps Before's outlines, as it cannot reveal one", { timeout: 30_000 }, async t => {
|
||||
const { page, outline } = await openSplit(t, { hasTouch: true, isMobile: true });
|
||||
assert.equal(await page.evaluate(() => matchMedia("(hover: none)").matches), true);
|
||||
await expect.poll(() => opacity(outline("before", 0))).toBe(1);
|
||||
await expect.poll(() => opacity(outline("before", 2))).toBe(1);
|
||||
});
|
||||
@@ -0,0 +1,266 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
const STORAGE_KEY = "expo-explore:inspector-width";
|
||||
const panel = (page: Page) => page.getByRole("complementary", { name: "Inspector panel" });
|
||||
const handle = (page: Page) => page.getByRole("separator", { name: "Resize inspector" });
|
||||
const panelWidth = async (page: Page) => (await panel(page).boundingBox())!.width;
|
||||
const storedWidth = (page: Page) => page.evaluate((key) => localStorage.getItem(key), STORAGE_KEY);
|
||||
|
||||
/** Drags the panel's edge `dx` pixels (negative is left, which widens the panel). */
|
||||
async function dragEdge(page: Page, dx: number) {
|
||||
const box = (await handle(page).boundingBox())!;
|
||||
const x = box.x + box.width / 2;
|
||||
const y = box.y + box.height / 2;
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x + dx / 2, y);
|
||||
await page.mouse.move(x + dx, y);
|
||||
await page.mouse.up();
|
||||
}
|
||||
|
||||
test.describe("Inspector resize", () => {
|
||||
test("dragging the edge resizes the Inspector, and the width is kept for the next visit", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
// The 1280px test window takes the wide default.
|
||||
expect(await panelWidth(page)).toBe(400);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "400");
|
||||
|
||||
await dragEdge(page, -150);
|
||||
await expect.poll(() => panelWidth(page)).toBe(550);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "550");
|
||||
expect(await storedWidth(page)).toBe("550");
|
||||
|
||||
await page.reload();
|
||||
await expect(panel(page)).toBeVisible();
|
||||
await expect.poll(() => panelWidth(page)).toBe(550);
|
||||
|
||||
// Dragging back right narrows it, never below the minimum.
|
||||
await dragEdge(page, 400);
|
||||
await expect.poll(() => panelWidth(page)).toBe(320);
|
||||
expect(await storedWidth(page)).toBe("320");
|
||||
});
|
||||
|
||||
test("the width stops at half the window, and a double-click restores the default", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
await dragEdge(page, -600);
|
||||
await expect.poll(() => panelWidth(page)).toBe(640);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuemax", "640");
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "640");
|
||||
|
||||
// The canvas toolbar moves left, out from under the wide panel, instead of being covered.
|
||||
const toolbar = page.getByRole("toolbar", { name: "Canvas tools" });
|
||||
await expect(toolbar).toBeVisible();
|
||||
await expect.poll(async () => {
|
||||
const toolbarBox = (await toolbar.boundingBox())!;
|
||||
const panelBox = (await panel(page).boundingBox())!;
|
||||
return panelBox.x - (toolbarBox.x + toolbarBox.width);
|
||||
}).toBeGreaterThanOrEqual(8);
|
||||
|
||||
await handle(page).dblclick();
|
||||
await expect.poll(() => panelWidth(page)).toBe(400);
|
||||
expect(await storedWidth(page)).toBeNull();
|
||||
});
|
||||
|
||||
test("arrow keys move the edge a step; Home and End take it to its limits", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
await handle(page).focus();
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await expect.poll(() => panelWidth(page)).toBe(416);
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await expect.poll(() => panelWidth(page)).toBe(432);
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect.poll(() => panelWidth(page)).toBe(416);
|
||||
await page.keyboard.press("End");
|
||||
await expect.poll(() => panelWidth(page)).toBe(640);
|
||||
await page.keyboard.press("Home");
|
||||
await expect.poll(() => panelWidth(page)).toBe(320);
|
||||
// The arrows resized the panel; they did not step the selected screen.
|
||||
expect(new URL(page.url()).searchParams.get("screen")).toBe("area-0-screen-1");
|
||||
});
|
||||
|
||||
test("a saved width wider than half of a smaller window is held to half of it", async ({ page }) => {
|
||||
await page.addInitScript((key) => localStorage.setItem(key, "760"), STORAGE_KEY);
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
expect(await panelWidth(page)).toBe(640);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "640");
|
||||
});
|
||||
|
||||
test("a drag that ends where it started leaves the default width in place", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
const box = (await handle(page).boundingBox())!;
|
||||
const x = box.x + box.width / 2;
|
||||
const y = box.y + box.height / 2;
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x - 100, y);
|
||||
await expect.poll(() => panelWidth(page)).toBe(500);
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.up();
|
||||
await expect.poll(() => panelWidth(page)).toBe(400);
|
||||
expect(await storedWidth(page)).toBeNull();
|
||||
// Still the default: a narrower window takes the narrow default, not the 400 the drag passed through.
|
||||
await page.setViewportSize({ width: 1100, height: 820 });
|
||||
await expect.poll(() => panelWidth(page)).toBe(320);
|
||||
});
|
||||
|
||||
test("a saved width below the minimum is held to it", async ({ page }) => {
|
||||
await page.addInitScript((key) => localStorage.setItem(key, "40"), STORAGE_KEY);
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
expect(await panelWidth(page)).toBe(320);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "320");
|
||||
});
|
||||
|
||||
test.describe("in a window wider than two maximum panels", () => {
|
||||
test.use({ viewport: { width: 1700, height: 900 } });
|
||||
|
||||
test("a saved width above the maximum is held to it", async ({ page }) => {
|
||||
await page.addInitScript((key) => localStorage.setItem(key, "5000"), STORAGE_KEY);
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
// Half of this window is 850.
|
||||
expect(await panelWidth(page)).toBe(800);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "800");
|
||||
});
|
||||
});
|
||||
|
||||
test("a key that cannot move the edge keeps the saved width", async ({ page }) => {
|
||||
await page.addInitScript((key) => localStorage.setItem(key, "760"), STORAGE_KEY);
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
expect(await panelWidth(page)).toBe(640);
|
||||
await handle(page).focus();
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
expect(await storedWidth(page)).toBe("760");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect.poll(() => panelWidth(page)).toBe(624);
|
||||
expect(await storedWidth(page)).toBe("624");
|
||||
});
|
||||
|
||||
test("the separator's values follow the window", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
await handle(page).focus();
|
||||
await page.keyboard.press("End");
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "640");
|
||||
await page.setViewportSize({ width: 1000, height: 820 });
|
||||
await expect.poll(() => panelWidth(page)).toBe(500);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuemax", "500");
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "500");
|
||||
// Back in the wide window the saved width returns.
|
||||
await page.setViewportSize({ width: 1280, height: 820 });
|
||||
await expect.poll(() => panelWidth(page)).toBe(640);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "640");
|
||||
});
|
||||
|
||||
test("closing the Inspector mid-drag ends the drag", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
const box = (await handle(page).boundingBox())!;
|
||||
const x = box.x + box.width / 2;
|
||||
const y = box.y + box.height / 2;
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x - 100, y);
|
||||
await expect(page.locator("html")).toHaveClass(/inspector-resizing/);
|
||||
await page.keyboard.press("i");
|
||||
await expect(panel(page)).toHaveCount(0);
|
||||
await page.mouse.up();
|
||||
await expect(page.locator("html")).not.toHaveClass(/inspector-resizing/);
|
||||
// The width the drag reached is kept.
|
||||
await page.keyboard.press("i");
|
||||
await expect.poll(() => panelWidth(page)).toBe(500);
|
||||
});
|
||||
|
||||
test.describe("in a window too narrow for the toolbar beside a half-window Inspector", () => {
|
||||
test.use({ viewport: { width: 820, height: 800 } });
|
||||
|
||||
/** The widest the panel may be here: the window less the bottom bar and a 12px gap either side. */
|
||||
async function widestBesideToolbar(page: Page) {
|
||||
const toolbarBox = (await page.getByRole("toolbar", { name: "Canvas tools" }).boundingBox())!;
|
||||
return Math.floor(820 - (toolbarBox.width + 2 * 12));
|
||||
}
|
||||
|
||||
async function expectToolbarBesidePanel(page: Page) {
|
||||
const toolbar = page.getByRole("toolbar", { name: "Canvas tools" });
|
||||
await expect(toolbar).toBeVisible();
|
||||
await expect(toolbar.getByRole("button", { name: "More", exact: true })).toBeVisible();
|
||||
const toolbarBox = (await toolbar.boundingBox())!;
|
||||
const panelBox = (await panel(page).boundingBox())!;
|
||||
expect(toolbarBox.x).toBeGreaterThanOrEqual(12 - 1);
|
||||
expect(toolbarBox.x + toolbarBox.width + 12).toBeLessThanOrEqual(panelBox.x + 1);
|
||||
}
|
||||
|
||||
test("End stops the Inspector where the toolbar still fits beside it, with More in reach", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
const widest = await widestBesideToolbar(page);
|
||||
// Half the window would be 410; the toolbar needs more of the canvas than that leaves.
|
||||
expect(widest).toBeLessThan(410);
|
||||
expect(widest).toBeGreaterThan(320);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuemax", String(widest));
|
||||
await handle(page).focus();
|
||||
await page.keyboard.press("End");
|
||||
await expect.poll(() => panelWidth(page)).toBe(widest);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", String(widest));
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await expect.poll(() => panelWidth(page)).toBe(widest);
|
||||
await expectToolbarBesidePanel(page);
|
||||
// Narrowed again, the toolbar keeps its gap to the panel.
|
||||
await page.keyboard.press("Home");
|
||||
await expect.poll(() => panelWidth(page)).toBe(320);
|
||||
await expectToolbarBesidePanel(page);
|
||||
});
|
||||
|
||||
test("a drag or a saved width stops there too", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
const widest = await widestBesideToolbar(page);
|
||||
await dragEdge(page, -300);
|
||||
await expect.poll(() => panelWidth(page)).toBe(widest);
|
||||
expect(await storedWidth(page)).toBe(String(widest));
|
||||
await expectToolbarBesidePanel(page);
|
||||
|
||||
await page.evaluate((key) => localStorage.setItem(key, "800"), STORAGE_KEY);
|
||||
await page.reload();
|
||||
await expect(panel(page)).toBeVisible();
|
||||
await expect.poll(() => panelWidth(page)).toBe(widest);
|
||||
await expectToolbarBesidePanel(page);
|
||||
// A wider window gives the saved width more room again.
|
||||
await page.setViewportSize({ width: 1280, height: 800 });
|
||||
await expect.poll(() => panelWidth(page)).toBe(640);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("in a narrow window", () => {
|
||||
test.use({ viewport: { width: 1180, height: 820 } });
|
||||
|
||||
test("the Inspector starts at its narrow default, and a saved width is held to half the window", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
expect(await panelWidth(page)).toBe(320);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "320");
|
||||
await page.evaluate((key) => localStorage.setItem(key, "760"), STORAGE_KEY);
|
||||
await page.reload();
|
||||
await expect(panel(page)).toBeVisible();
|
||||
expect(await panelWidth(page)).toBe(590);
|
||||
await expect(handle(page)).toHaveAttribute("aria-valuenow", "590");
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("on a phone", () => {
|
||||
test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true });
|
||||
|
||||
test("the Inspector sheet has no resize edge", async ({ page }) => {
|
||||
await page.goto("/map?screen=area-0-screen-1");
|
||||
await expect(panel(page)).toBeVisible();
|
||||
await expect(handle(page)).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
+605
-283
File diff suppressed because it is too large.
Load diff
@@ -54,7 +54,7 @@ export async function readUsage(output) {
|
||||
|
||||
export async function fixture(t, provider, { docsOnly = false, unresolvedParameters = false, observerFailurePath, agentMode = false,
|
||||
instructions = 'Explore selected routes in a stable, comparable state.', recoverableOpenFailure = false,
|
||||
userInterfaceStyle, headUserInterfaceStyle, platform: initialPlatform = 'ios', targets } = {}) {
|
||||
userInterfaceStyle, headUserInterfaceStyle, platform: initialPlatform = 'ios', targets, maxSessions } = {}) {
|
||||
let platform = initialPlatform;
|
||||
const root = await realpath(await mkdtemp(join(tmpdir(), 'explore-ci-integration-')));
|
||||
t.after(() => rm(root, { recursive: true, force: true }));
|
||||
@@ -67,7 +67,7 @@ export async function fixture(t, provider, { docsOnly = false, unresolvedParamet
|
||||
const commit = message => { git(headProject, 'add', '.'); git(headProject, 'commit', '-m', message); return git(headProject, 'rev-parse', 'HEAD'); };
|
||||
const config = { mode: 'deterministic', app: { name: 'Example', platform, bundleId: 'com.example.app', easProfile: 'capture', scheme: 'sample' },
|
||||
device: { name: 'iPhone 17 Pro' }, navigation: { provider, ...(provider === 'react-navigation' ? { entry: 'src/App.tsx' } : {}) },
|
||||
exploration: { scope: 'changes' }, capture: { maxMinutes: 30, maxActions: 500, repack: 'eas' },
|
||||
exploration: { scope: 'changes' }, capture: { maxMinutes: 30, maxActions: 500, repack: 'eas', ...(maxSessions ? { maxSessions } : {}) },
|
||||
parameters: provider === 'expo-router' && !unresolvedParameters ? { '/item/[id]': { id: 'example-item' } } : {} };
|
||||
if (targets) config.targets = targets;
|
||||
if (agentMode) { config.mode = 'agent'; config.agent = { provider: 'anthropic', model: 'fixture-model', instructions: '.expo-explore/instructions.md' }; }
|
||||
|
||||
@@ -138,9 +138,10 @@ test("baseline captures a complete single default-branch commit without a PR", (
|
||||
const job = baseline.jobs.baseline;
|
||||
assert.match(baseline.jobs.targets.if, /github\.event\.repository\.default_branch/);
|
||||
assert.deepEqual(job.needs, "targets");
|
||||
assert.deepEqual(job.strategy, { "fail-fast": false, matrix: { target: "${{ fromJSON(needs.targets.outputs.targets) }}" } });
|
||||
assert.deepEqual(job.strategy, { "fail-fast": false, "max-parallel": "${{ fromJSON(needs.targets.outputs.max_parallel) }}",
|
||||
matrix: { target: "${{ fromJSON(needs.targets.outputs.targets) }}" } });
|
||||
assert.equal(job.env.TARGET, "${{ matrix.target }}");
|
||||
assert.match(baseline.jobs.targets.steps.at(-1).run, /config:targets .* \| jq -c '\[\.targets\[\]\.id\]'/);
|
||||
assert.match(baseline.jobs.targets.steps.at(-1).run, /config:targets --project "\$GITHUB_WORKSPACE\/app\/\$APP_PROJECT_DIR"/);
|
||||
const verify = job.steps.find(step => step.name === "Verify deterministic source planning");
|
||||
assert.match(verify.run, /--base-sha "\$GITHUB_SHA" --head-sha "\$GITHUB_SHA" --scope all/);
|
||||
const capture = job.steps.find(step => step.name === "Capture complete single-commit baseline");
|
||||
@@ -325,16 +326,21 @@ test("review captures and reports each configured target in its own matrix job,
|
||||
assert.deepEqual(targets.permissions, { contents: "read", "pull-requests": "read" });
|
||||
assert.equal(targets.outputs.targets, "${{ steps.targets.outputs.targets }}");
|
||||
// config:targets lists ids in config order; a config without targets: lists ["ios"] / ["ios","android"], as config:platforms did.
|
||||
assert.match(targets.steps.at(-1).run, /config:targets --project "\$GITHUB_WORKSPACE\/app-head\/\$APP_PROJECT_DIR" --config \.expo-explore\/config\.yaml \| jq -c '\[\.targets\[\]\.id\]'/);
|
||||
assert.match(targets.steps.at(-1).run, /config:targets --project "\$GITHUB_WORKSPACE\/app-head\/\$APP_PROJECT_DIR" --config \.expo-explore\/config\.yaml/);
|
||||
assert.equal(targets.outputs.max_parallel, "${{ steps.targets.outputs.max_parallel }}");
|
||||
assert.doesNotMatch(JSON.stringify(targets), /EXPO_TOKEN|OPENAI_API_KEY|ANTHROPIC_API_KEY|APP_REVIEW/);
|
||||
for (const workflow of [review, compare, baseline]) {
|
||||
assert.doesNotMatch(JSON.stringify(workflow), /matrix\.platform|config:platforms|\$PLATFORM|needs\.platforms/, "every job is keyed by target, never by platform");
|
||||
assert.match(JSON.stringify(workflow), /matrix\.target/, "doctor looks for matrix.target in an installed workflow");
|
||||
}
|
||||
for (const job of [review.jobs.capture, review.jobs.report]) {
|
||||
assert.deepEqual(job.strategy, { "fail-fast": false, matrix: { target: "${{ fromJSON(needs.targets.outputs.targets) }}" } });
|
||||
// Each capture job needs a simulator session, so at most capture.maxSessions of them run at once; a report needs none.
|
||||
for (const job of [review.jobs.capture, compare.jobs.capture]) {
|
||||
assert.deepEqual(job.strategy, { "fail-fast": false, "max-parallel": "${{ fromJSON(needs.targets.outputs.max_parallel) }}",
|
||||
matrix: { target: "${{ fromJSON(needs.targets.outputs.targets) }}" } });
|
||||
assert.equal(job.env.TARGET, "${{ matrix.target }}");
|
||||
}
|
||||
assert.deepEqual(review.jobs.report.strategy, { "fail-fast": false, matrix: { target: "${{ fromJSON(needs.targets.outputs.targets) }}" } });
|
||||
assert.equal(review.jobs.report.env.TARGET, "${{ matrix.target }}");
|
||||
assert.equal(review.jobs.capture.needs, "targets");
|
||||
assert.deepEqual(review.jobs.report.needs, ["targets", "capture"]);
|
||||
const runs = [review.jobs.capture, review.jobs.report, baseline.jobs.baseline].flatMap(job => job.steps.filter(step => step.run).map(step => step.run));
|
||||
@@ -378,3 +384,27 @@ test("compare reviews any two refs from a manual run or another workflow, with n
|
||||
assert.match(compare.jobs.capture.steps.find(step => step.id === "capture").run, /printf '%s' "\$COMPARE" > "\$RUNNER_TEMP\/explore-compare\.json"/);
|
||||
assert.match(compare.jobs.deploy.steps.at(-1).run, /ci:deploy --inputs/);
|
||||
});
|
||||
|
||||
test("the targets job lists the target ids and how many capture jobs run at once: no more than capture.maxSessions", async t => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-targets-step-"));
|
||||
t.after(() => rm(root, { recursive: true, force: true }));
|
||||
const tools = new URL("../..", import.meta.url).pathname;
|
||||
const run = async (workflow, checkout, config) => {
|
||||
const project = join(root, checkout); await mkdir(join(project, ".expo-explore"), { recursive: true });
|
||||
await writeFile(join(project, ".expo-explore", "config.yaml"), config);
|
||||
const output = join(root, "output"); await writeFile(output, "");
|
||||
const step = workflow.jobs.targets.steps.find(entry => entry.id === "targets");
|
||||
const result = spawnSync("bash", ["-c", step.run], { encoding: "utf8",
|
||||
env: { PATH: process.env.PATH, HOME: root, TOOLS: tools, GITHUB_WORKSPACE: root, APP_PROJECT_DIR: ".", GITHUB_OUTPUT: output } });
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
const outputs = Object.fromEntries((await readFile(output, "utf8")).trim().split("\n").map(line => line.split(/=(.*)/s).slice(0, 2)));
|
||||
return { targets: JSON.parse(outputs.targets), maxParallel: JSON.parse(outputs.max_parallel) };
|
||||
};
|
||||
const app = "app:\n bundleId: com.example.app\n easProfile: explore\ndevice:\n name: iPhone 17\n";
|
||||
const five = "targets:\n" + ["iphone", "ipad", "duo-closed", "duo-open"].map(id => ` ${id}: { platform: ios }\n`).join("") + " pixel: { platform: android, bundleId: com.example.app, easProfile: explore }\n";
|
||||
for (const [workflow, checkout] of [[review, "app-head"], [compare, "app-head"], [baseline, "app"]]) {
|
||||
assert.deepEqual(await run(workflow, checkout, app + five), { targets: ["iphone", "ipad", "duo-closed", "duo-open", "pixel"], maxParallel: 5 }, "unset: five");
|
||||
assert.deepEqual((await run(workflow, checkout, app + "capture:\n maxSessions: 2\n" + five)).maxParallel, 2, "a starter plan's two");
|
||||
assert.deepEqual(await run(workflow, checkout, app), { targets: ["ios"], maxParallel: 1 });
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,135 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import { startArgentBridgeRunner } from "../../dist/capture/argent-bridge-host.js";
|
||||
import { ARGENT_VERSION } from "../../dist/shared/argent-version.js";
|
||||
|
||||
const PNG = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=", "base64");
|
||||
|
||||
async function fakeClient(root, body) {
|
||||
const module = join(root, "client.mjs");
|
||||
await writeFile(module, `const calls = [];\nexport function createArgentClient() { return { calls, async callTool(name, args, options) { calls.push({ name, args }); ${body} } }; }\n`);
|
||||
return module;
|
||||
}
|
||||
|
||||
test("the bridge thread answers the capture's commands through Argent's client and falls back for other executables", async (t) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-argent-bridge-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
await writeFile(join(root, "shot.png"), PNG);
|
||||
const clientModule = await fakeClient(root, `
|
||||
if (name === "list-devices") return { data: { devices: [{ udid: "UDID-1", name: "iPhone 17", state: "Booted", platform: "ios", runtime: "iOS 26.0" }] } };
|
||||
if (name === "screenshot") return { data: { path: ${JSON.stringify(join(root, "shot.png"))} } };
|
||||
if (name === "await-screen-idle") { if (options?.signal?.aborted) throw options.signal.reason; await new Promise((resolve, reject) => { const timer = setTimeout(resolve, 5_000); options?.signal?.addEventListener("abort", () => { clearTimeout(timer); reject(options.signal.reason); }); }); return { data: { idle: true } }; }
|
||||
throw new Error("unexpected tool " + name);`);
|
||||
const fallbackCalls = [];
|
||||
const environment = { EXPLORE_ARGENT_STATE: join(root, "state.json"), EXPLORE_ARGENT_PLATFORM: "ios", ARGENT_TOOLS_URL: "http://127.0.0.1:9/tools", HOME: root, PATH: process.env.PATH };
|
||||
const bridge = startArgentBridgeRunner({ command: "/opt/argent-controller", environment, clientModule, fallback: request => { fallbackCalls.push(request.args[0]); return { stdout: "{}", stderr: "" }; } });
|
||||
t.after(() => bridge.close());
|
||||
const request = args => ({ command: "/opt/argent-controller", args, cwd: root, environment, timeoutMs: 20_000 });
|
||||
|
||||
const version = bridge.runner(request(["--version"]));
|
||||
assert.equal(version.stdout.trim(), ARGENT_VERSION);
|
||||
const shot = JSON.parse(bridge.runner(request(["screenshot", join(root, "out", "screen.png"), "--session", "explore", "--platform", "ios", "--json"])).stdout);
|
||||
assert.equal(shot.success, true);
|
||||
assert.deepEqual(await readFile(join(root, "out", "screen.png")), PNG, "the materialized artifact is copied where the command asked");
|
||||
assert.ok(bridge.active);
|
||||
|
||||
bridge.runner({ command: "/usr/bin/other", args: ["noop"], cwd: root, environment });
|
||||
assert.deepEqual(fallbackCalls, ["noop"], "other executables go to the fallback runner");
|
||||
|
||||
const started = Date.now();
|
||||
assert.throws(() => bridge.runner({ ...request(["wait", "stable", "500", "8000", "--session", "explore", "--platform", "ios", "--json"]), timeoutMs: 300 }), /timed out after 300 ms/);
|
||||
assert.ok(Date.now() - started < 5_000, "a timed-out command is aborted, not waited out");
|
||||
assert.ok(bridge.active, "the thread answered the abort, so it keeps serving");
|
||||
assert.equal(bridge.runner(request(["--version"])).stdout.trim(), ARGENT_VERSION);
|
||||
});
|
||||
|
||||
test("a thread whose Argent client cannot load hands every command to the fallback runner", async (t) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-argent-bridge-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
const fallbackCalls = [];
|
||||
const environment = { EXPLORE_ARGENT_STATE: join(root, "state.json"), EXPLORE_ARGENT_PLATFORM: "ios", ARGENT_TOOLS_URL: "http://127.0.0.1:9/tools", HOME: root, PATH: process.env.PATH };
|
||||
const bridge = startArgentBridgeRunner({ command: "/opt/argent-controller", environment, clientModule: join(root, "missing.mjs"), fallback: request => { fallbackCalls.push(request.args[0]); return { stdout: "{}", stderr: "" }; } });
|
||||
t.after(() => bridge.close());
|
||||
bridge.runner({ command: "/opt/argent-controller", args: ["snapshot", "--json"], cwd: root, environment, timeoutMs: 20_000 });
|
||||
bridge.runner({ command: "/opt/argent-controller", args: ["screenshot", "x.png", "--json"], cwd: root, environment, timeoutMs: 20_000 });
|
||||
assert.deepEqual(fallbackCalls, ["snapshot", "screenshot"]);
|
||||
assert.equal(bridge.active, false);
|
||||
});
|
||||
|
||||
test("a session whose tool-server was replaced is driven at the new one: the thread starts again with the changed environment", async (t) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-argent-bridge-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
await writeFile(join(root, "shot.png"), PNG);
|
||||
// The fake client notes which tool-server it was given, as Argent's reads ARGENT_TOOLS_URL from its environment.
|
||||
const clientModule = await fakeClient(root, `
|
||||
if (name === "list-devices") return { data: { devices: [{ udid: "UDID-1", name: "iPhone 17", state: "Booted", platform: "ios", runtime: "iOS 26.0" }] } };
|
||||
if (name === "screenshot") { (await import("node:fs")).appendFileSync(${JSON.stringify(join(root, "servers.txt"))}, process.env.ARGENT_TOOLS_URL + "\\n"); return { data: { path: ${JSON.stringify(join(root, "shot.png"))} } }; }
|
||||
throw new Error("unexpected tool " + name);`);
|
||||
const environment = { EXPLORE_ARGENT_STATE: join(root, "state.json"), EXPLORE_ARGENT_PLATFORM: "ios", ARGENT_TOOLS_URL: "http://127.0.0.1:9/old", HOME: root, PATH: process.env.PATH };
|
||||
const bridge = startArgentBridgeRunner({ command: "/opt/argent-controller", environment, clientModule, fallback: () => assert.fail("the thread serves every command") });
|
||||
t.after(() => bridge.close());
|
||||
const screenshot = () => JSON.parse(bridge.runner({ command: "/opt/argent-controller", args: ["screenshot", join(root, "out", "screen.png"), "--session", "explore", "--platform", "ios", "--json"],
|
||||
cwd: root, environment, timeoutMs: 20_000 }).stdout);
|
||||
assert.equal(screenshot().success, true);
|
||||
// As the capture's local recovery does: the same environment object, pointed at the restarted tool-server.
|
||||
Object.assign(environment, { ARGENT_TOOLS_URL: "http://127.0.0.1:9/new", ARGENT_AUTH_TOKEN: "new-token" });
|
||||
assert.equal(screenshot().success, true);
|
||||
assert.deepEqual((await readFile(join(root, "servers.txt"), "utf8")).trim().split("\n"), ["http://127.0.0.1:9/old", "http://127.0.0.1:9/new"]);
|
||||
assert.ok(bridge.active);
|
||||
});
|
||||
|
||||
test("a thread that crashes stops serving, and the commands after it run per command", async (t) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-argent-bridge-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
await writeFile(join(root, "shot.png"), PNG);
|
||||
// An exception nothing catches, thrown on the thread well after its answer.
|
||||
const clientModule = await fakeClient(root, `
|
||||
if (name === "list-devices") return { data: { devices: [{ udid: "UDID-1", name: "iPhone 17", state: "Booted", platform: "ios", runtime: "iOS 26.0" }] } };
|
||||
if (name === "screenshot") { setTimeout(() => { throw new Error("the client crashed"); }, 300); return { data: { path: ${JSON.stringify(join(root, "shot.png"))} } }; }
|
||||
throw new Error("unexpected tool " + name);`);
|
||||
const fallbackCalls = [], messages = [];
|
||||
const environment = { EXPLORE_ARGENT_STATE: join(root, "state.json"), EXPLORE_ARGENT_PLATFORM: "ios", ARGENT_TOOLS_URL: "http://127.0.0.1:9/tools", HOME: root, PATH: process.env.PATH };
|
||||
const bridge = startArgentBridgeRunner({ command: "/opt/argent-controller", environment, clientModule, progress: message => messages.push(message),
|
||||
fallback: request => { fallbackCalls.push(request.args[0]); return { stdout: "{}", stderr: "" }; } });
|
||||
t.after(() => bridge.close());
|
||||
const request = args => ({ command: "/opt/argent-controller", args, cwd: root, environment, timeoutMs: 20_000 });
|
||||
assert.equal(JSON.parse(bridge.runner(request(["screenshot", join(root, "out", "screen.png"), "--session", "explore", "--platform", "ios", "--json"])).stdout).success, true);
|
||||
await new Promise(resolve => setTimeout(resolve, 1_500));
|
||||
assert.equal(bridge.active, false);
|
||||
assert.match(messages.join("\n"), /the Argent bridge thread failed \(the client crashed\)/);
|
||||
bridge.runner(request(["snapshot", "--json"]));
|
||||
assert.deepEqual(fallbackCalls, ["snapshot"]);
|
||||
});
|
||||
|
||||
test("a recording runs per command, and a screenshot is taken only from a file that is an image", async (t) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-argent-bridge-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
await writeFile(join(root, "shot.png"), PNG);
|
||||
await writeFile(join(root, "notes.txt"), "not a screenshot\n");
|
||||
const answer = join(root, "answer.json");
|
||||
const clientModule = await fakeClient(root, `
|
||||
if (name === "list-devices") return { data: { devices: [{ udid: "UDID-1", name: "iPhone 17", state: "Booted", platform: "ios", runtime: "iOS 26.0" }] } };
|
||||
if (name === "screenshot") return { data: JSON.parse((await import("node:fs")).readFileSync(${JSON.stringify(answer)}, "utf8")) };
|
||||
throw new Error("unexpected tool " + name);`);
|
||||
const fallbackCalls = [];
|
||||
const environment = { EXPLORE_ARGENT_STATE: join(root, "state.json"), EXPLORE_ARGENT_PLATFORM: "ios", ARGENT_TOOLS_URL: "http://127.0.0.1:9/tools", HOME: root, PATH: process.env.PATH };
|
||||
const bridge = startArgentBridgeRunner({ command: "/opt/argent-controller", environment, clientModule,
|
||||
fallback: request => { fallbackCalls.push(request.args.slice(0, 2).join(" ")); return { stdout: "{}", stderr: "" }; } });
|
||||
t.after(() => bridge.close());
|
||||
const request = args => ({ command: "/opt/argent-controller", args, cwd: root, environment, timeoutMs: 20_000 });
|
||||
|
||||
bridge.runner(request(["record", "start", join(root, "launch.mp4"), "--scope", "app", "--json"]));
|
||||
bridge.runner(request(["record", "stop", "--json"]));
|
||||
assert.deepEqual(fallbackCalls, ["record start", "record stop"], "recordings go to the per-command bridge");
|
||||
assert.ok(bridge.active);
|
||||
|
||||
const screenshot = out => JSON.parse(bridge.runner({ ...request(["screenshot", out, "--session", "explore", "--platform", "ios", "--json"]), allowFailure: true }).stdout);
|
||||
// A path to a file that is not an image is not a screenshot, whatever its key; the image beside it is.
|
||||
await writeFile(answer, JSON.stringify({ path: join(root, "notes.txt"), image: join(root, "shot.png") }));
|
||||
assert.equal(screenshot(join(root, "out", "one.png")).success, true);
|
||||
assert.deepEqual(await readFile(join(root, "out", "one.png")), PNG);
|
||||
await writeFile(answer, JSON.stringify({ path: join(root, "notes.txt") }));
|
||||
const failed = screenshot(join(root, "out", "two.png"));
|
||||
assert.equal(failed.success, false);
|
||||
assert.match(failed.error.message, /did not write/);
|
||||
await assert.rejects(readFile(join(root, "out", "two.png")), { code: "ENOENT" });
|
||||
});
|
||||
@@ -135,6 +135,9 @@ test("capture recipes exclude display settings but bind agent instructions and c
|
||||
assert.equal(JSON.parse(key).observer, CAPTURE_OBSERVER_HASH);
|
||||
assert.match(JSON.parse(key).observer, /^[a-f0-9]{64}$/);
|
||||
assert.equal(key,captureRecipeConfig({...config,app:{...config.app,name:"Renamed display"}}));
|
||||
// How many sessions capture it does not change the evidence: a baseline captured under any ceiling serves the review.
|
||||
assert.equal(key,captureRecipeConfig({...config,capture:{...config.capture,maxSessions:16}}));
|
||||
assert.equal(captureRecipeConfig({...config,capture:{...config.capture,maxSessions:4}}),captureRecipeConfig({...config,capture:{...config.capture,maxSessions:16}}));
|
||||
// An unset repack is keyed as it resolves, so configs that never chose one keep the recipe of the old written-out default.
|
||||
assert.equal(key,captureRecipeConfig({...config,capture:{...config.capture,repack:"eas"}}));
|
||||
assert.equal(JSON.parse(key).capture.repack, "eas");
|
||||
|
||||
@@ -14,7 +14,10 @@ import { AGENT_DEVICE_VERSION, captureDeepLink, controllerCommandFailure, revisi
|
||||
import { CiError, serializeCiError } from '../../dist/shared/ci-errors.js';
|
||||
import { createSourceCapturePlan } from '../../dist/source/capture-plan.js';
|
||||
import { CAPTURE_OBSERVER_IDENTIFIER } from '../../dist/capture/observer.js';
|
||||
import { parseRuntimeExecutionContext } from '../../dist/review/runtime-adapter.js';
|
||||
import { parseRuntimeExecutionContext, runtimeEvidenceInputFromMap } from '../../dist/review/runtime-adapter.js';
|
||||
import { readExportedMap } from '../../dist/review/evidence-assessment.js';
|
||||
import { projectRuntimeEvidence } from '../../dist/review/runtime-evidence.js';
|
||||
import { mergeCaptureExports } from '../../dist/ci/export-merge.js';
|
||||
import { assertCompleteCaptures, hasVerifiedCapture } from '../../dist/capture/health.js';
|
||||
import { readCaptureBundle } from '../../dist/review/capture-review.js';
|
||||
import { writeCaptureObserverPackages } from '../helpers/capture-observer-fixture.mjs';
|
||||
@@ -3557,3 +3560,57 @@ test('a verified label is located on the image\'s axes when the screenshot is th
|
||||
// A 669 x 951 portrait panel captured upright as a 951 x 669 image: the button near its bottom-left is near the image's top-left.
|
||||
assert.deepEqual(verifiedCaptureLabels(nodes, ['Done'], { height: 951 })[0].rect, { x: 11, y: 10, width: 40, height: 100 });
|
||||
});
|
||||
|
||||
test('a session given only the dark pass (appearancePass) captures @dark screens shaped as in a single run', async t => {
|
||||
const f = await fixture(t, { userInterfaceStyle: 'automatic' });
|
||||
const result = await runCiMap({ ...f.options, appearancePass: { all: ['light', 'dark'], capture: ['dark'] } });
|
||||
assert.equal(result.runStatus, 'complete');
|
||||
assert.deepEqual(f.requests.filter(request => request.args[0] === 'settings').map(request => request.args.slice(1, 3)), [['appearance', 'dark']]);
|
||||
assert.equal(f.requests.filter(request => request.args[0] === 'screenshot').length, 2);
|
||||
const map = JSON.parse(await readFile(join(f.options.outputDirectory, 'screen-map.json'), 'utf8'));
|
||||
assert.deepEqual(map.run.environment.colorSchemes, ['light', 'dark']);
|
||||
assert.deepEqual(map.screens.map(screen => [screen.id, screen.colorScheme]), [[`${f.ids.home}@dark`, 'dark'], [`${f.ids.settings}@dark`, 'dark']]);
|
||||
const bundle = JSON.parse(await readFile(join(f.options.outputDirectory, 'bundle.json'), 'utf8'));
|
||||
assert.deepEqual(Object.keys(bundle.images).sort(), [`${f.ids.home}@dark`, `${f.ids.settings}@dark`]);
|
||||
assert.deepEqual(Object.keys(bundle.outcomes).sort(), [`${f.ids.home}@dark`, `${f.ids.settings}@dark`]);
|
||||
assert.equal(bundle.runtimeProfile.colorSchemes, 'light,dark');
|
||||
});
|
||||
|
||||
test('a session given only the dark pass keeps a wrong landing as the unattributed frame its pass recorded, for the export merge', async t => {
|
||||
const f = await fixture(t, { userInterfaceStyle: 'automatic', markerMismatchAt: { path: '/settings', scheme: 'dark' } });
|
||||
const result = await runCiMap({ ...f.options, appearancePass: { all: ['light', 'dark'], capture: ['dark'] } });
|
||||
const dark = `${f.ids.settings}@dark`;
|
||||
// Without the light pass beside it, the frame is not demoted to a lost route: the merge decides, as one run's passes do.
|
||||
assert.equal(result.outcomes[dark].status, 'captured');
|
||||
assert.equal(result.outcomes[dark].landing, 'unverified');
|
||||
assert.equal(result.outcomes[f.ids.settings], undefined);
|
||||
assert.equal(result.runStatus, 'partial');
|
||||
const bundle = JSON.parse(await readFile(join(f.options.outputDirectory, 'bundle.json'), 'utf8'));
|
||||
assert.equal(bundle.images[dark].sha256, result.outcomes[dark].screenshotSha256);
|
||||
assert.deepEqual(Object.keys(bundle.outcomes).sort(), [`${f.ids.home}@dark`, dark].sort());
|
||||
});
|
||||
|
||||
test('a split side merges into the export one run makes: each appearance a verified sibling, its runtime evidence resolvable', async t => {
|
||||
const f = await fixture(t, { userInterfaceStyle: 'automatic' });
|
||||
const at = name => ({ mapDirectory: join(f.root, `map${name}`), outputDirectory: join(f.root, `export${name}`) });
|
||||
await runCiMap({ ...f.options, ...at('-single') });
|
||||
await runCiMap({ ...f.options, ...at(''), appearancePass: { all: ['light', 'dark'], capture: ['light'] } });
|
||||
await runCiMap({ ...f.options, ...at('-dark'), appearancePass: { all: ['light', 'dark'], capture: ['dark'] } });
|
||||
await mergeCaptureExports(join(f.root, 'export'), [{ directory: join(f.root, 'export-dark'), scheme: 'dark' }]);
|
||||
const [single, merged] = await Promise.all(['export-single', 'export'].map(name => readCaptureBundle(join(f.root, name))));
|
||||
assert.deepEqual(Object.keys(merged.images).sort(), Object.keys(single.images).sort());
|
||||
assert.deepEqual(merged.outcomes, single.outcomes);
|
||||
// What a review needs of a sibling appearance (#28): its own verified frame and a map that resolves it as one run's would.
|
||||
const map = await readExportedMap(join(f.root, 'export'));
|
||||
const execution = parseRuntimeExecutionContext(JSON.parse(await readFile(join(f.root, 'export', 'execution.json'), 'utf8')));
|
||||
for (const [route, id] of Object.values(f.ids).flatMap(id => [[id, id], [id, `${id}@dark`]])) {
|
||||
// A verified secondary frame has no outcome of its own: it is verified under its route's, as the review reads it.
|
||||
const outcome = merged.outcomes[id] ?? merged.outcomes[route];
|
||||
assert.equal(outcome.status, 'captured', id); assert.equal(outcome.landing, 'verified', id);
|
||||
assert.ok(existsSync(join(f.root, 'export', merged.images[id].path)), id);
|
||||
const screen = map.screens.find(entry => entry.id === id);
|
||||
assert.equal(screen.observationIds.length, 1, id);
|
||||
projectRuntimeEvidence(runtimeEvidenceInputFromMap({ side: 'head', map, screenId: id, representativeObservationId: screen.observationIds[0],
|
||||
sampleObservationIds: screen.observationIds, expectedSampleCount: 1, profile: 'capture:com.example.app', execution }));
|
||||
}
|
||||
});
|
||||
@@ -346,6 +346,15 @@ test("target ids and entries are validated", () => {
|
||||
assert.throws(() => validateExploreConfig({ ...base(), targets }), error => error.code === "CONFIG_INVALID", JSON.stringify(targets));
|
||||
}
|
||||
assert.throws(() => validateExploreConfig({ ...base(), platforms: { ios: {} }, targets: { iphone: { platform: "ios" } } }), /targets or platforms, not both/);
|
||||
const twoTargets = { iphone: { platform: "ios" }, ipad: { platform: "ios" } };
|
||||
assert.equal(validateExploreConfig({ ...base(), targets: twoTargets, capture: { maxSessions: 2 } }).capture.maxSessions, 2);
|
||||
assert.equal("maxSessions" in validateExploreConfig({ ...base(), targets: twoTargets }).capture, false);
|
||||
// A ceiling below the number of targets runs that many target jobs at once (a starter plan's one simulator per platform).
|
||||
assert.equal(validateExploreConfig({ ...base(), targets: twoTargets, capture: { maxSessions: 1 } }).capture.maxSessions, 1);
|
||||
assert.throws(() => validateExploreConfig({ ...base(), capture: { maxSessions: 0 } }), /capture.maxSessions must be a positive integer/);
|
||||
assert.throws(() => validateExploreConfig({ ...base(), capture: { maxSessions: 1.5 } }), /capture.maxSessions must be a positive integer/);
|
||||
const platforms = { ios: {}, android: { bundleId: "com.example.app", easProfile: "explore" } };
|
||||
assert.equal(validateExploreConfig({ ...base(), platforms, capture: { maxSessions: 1 } }).capture.maxSessions, 1);
|
||||
});
|
||||
|
||||
test("a target can choose its own controller and simulator over capture's", () => {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import { mergeSchemeOutcomes } from "../../dist/capture/appearance.js";
|
||||
import { mergeCaptureExports } from "../../dist/ci/export-merge.js";
|
||||
|
||||
async function writeExport(root, { screens, images, outcomes, launch, diagnostics }) {
|
||||
await mkdir(join(root, "artifacts"), { recursive: true });
|
||||
await mkdir(join(root, "capture-diagnostics"), { recursive: true });
|
||||
const artifacts = [];
|
||||
for (const screen of screens) {
|
||||
const path = `artifacts/${screen}.png`;
|
||||
await writeFile(join(root, path), screen);
|
||||
artifacts.push({ id: `artifact-${screen}`, path, sha256: screen, bytes: screen.length, mimeType: "image/png" });
|
||||
}
|
||||
const map = { contract: "explore.map", revision: 1, run: { id: "run", environment: { colorSchemes: ["light", "dark"] } }, artifacts,
|
||||
screens: screens.map(id => ({ id, colorScheme: id.endsWith("@dark") ? "dark" : "light" })), variants: [], observations: screens.map(id => ({ screenId: id })),
|
||||
elements: [], actionAttempts: [], transitions: [], journeys: [], frontier: [], gaps: [] };
|
||||
await writeFile(join(root, "screen-map.json"), JSON.stringify(map));
|
||||
await writeFile(join(root, "bundle.json"), JSON.stringify({ contract: "explore.bundle", side: "head", runtimeProfile: { colorSchemes: "light,dark" }, images, outcomes, ...(launch ? { launch } : {}) }));
|
||||
await writeFile(join(root, "manifest.json"), JSON.stringify({ contract: "explore.map", runId: "run", revision: 1, files: artifacts.map(({ id: _id, ...file }) => file) }));
|
||||
await writeFile(join(root, "capture-diagnostics", "controller-timing.jsonl"), diagnostics);
|
||||
return root;
|
||||
}
|
||||
|
||||
test("a dark session's export folds into the light session's: @dark frames, outcomes, launch, map records, files and diagnostics", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-merge-"));
|
||||
const primary = await writeExport(join(root, "head-export"), { screens: ["home", "settings"],
|
||||
images: { home: { path: "artifacts/home.png" }, settings: { path: "artifacts/settings.png" } },
|
||||
outcomes: { home: { status: "captured", landing: "verified", attempts: 1 }, settings: { status: "captured", landing: "verified", attempts: 1 } },
|
||||
launch: { light: { splash: "l" } }, diagnostics: "{\"pass\":\"light\"}\n" });
|
||||
const dark = await writeExport(join(root, "head-export-dark"), { screens: ["home@dark", "settings@dark"],
|
||||
images: { "home@dark": { path: "artifacts/[email protected]" }, "settings@dark": { path: "artifacts/[email protected]" } },
|
||||
// A secondary-only run reports a route it lost under the route id, as a run's dark pass does before the passes merge.
|
||||
outcomes: { "home@dark": { status: "captured", landing: "verified", attempts: 2 }, settings: { status: "failed", landing: "unverified", attempts: 3 } },
|
||||
launch: { dark: { splash: "d" } }, diagnostics: "{\"pass\":\"dark\"}\n" });
|
||||
await mergeCaptureExports(primary, [{ directory: dark, scheme: "dark" }]);
|
||||
const bundle = JSON.parse(await readFile(join(primary, "bundle.json"), "utf8"));
|
||||
assert.deepEqual(Object.keys(bundle.images).sort(), ["home", "home@dark", "settings", "settings@dark"]);
|
||||
// As in one run: a dark frame verified beside its light one needs no record of its own; a lost one is the scheme's own outcome.
|
||||
assert.deepEqual(bundle.outcomes, { home: { status: "captured", landing: "verified", attempts: 2 }, settings: { status: "captured", landing: "verified", attempts: 3 },
|
||||
"settings@dark": { status: "failed", landing: "unverified", attempts: 3 } });
|
||||
assert.deepEqual(bundle.launch, { light: { splash: "l" }, dark: { splash: "d" } });
|
||||
const map = JSON.parse(await readFile(join(primary, "screen-map.json"), "utf8"));
|
||||
assert.deepEqual(map.screens.map(screen => screen.id), ["home", "settings", "home@dark", "settings@dark"]);
|
||||
assert.equal(map.observations.length, 4);
|
||||
assert.equal(map.artifacts.length, 4);
|
||||
const manifest = JSON.parse(await readFile(join(primary, "manifest.json"), "utf8"));
|
||||
assert.deepEqual(manifest.files.map(file => file.path).sort(), ["artifacts/home.png", "artifacts/[email protected]", "artifacts/settings.png", "artifacts/[email protected]"]);
|
||||
assert.equal(await readFile(join(primary, "artifacts/[email protected]"), "utf8"), "home@dark");
|
||||
assert.equal(await readFile(join(primary, "capture-diagnostics/controller-timing.jsonl"), "utf8"), "{\"pass\":\"light\"}\n{\"pass\":\"dark\"}\n");
|
||||
// Merging is idempotent for records already present.
|
||||
await mergeCaptureExports(primary, [{ directory: dark, scheme: "dark" }]);
|
||||
assert.equal(JSON.parse(await readFile(join(primary, "screen-map.json"), "utf8")).screens.length, 4);
|
||||
});
|
||||
|
||||
test("merged passes recombine as one run's: an unattributed dark frame beside a verified light one is kept", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-merge-"));
|
||||
const light = { status: "captured", landing: "verified", attempts: 1 };
|
||||
const wrong = { status: "captured", landing: "unverified", attempts: 2, screenshotSha256: "x", observed: { reason: "landing-mismatch", route: "/login", attempts: 2 } };
|
||||
const primary = await writeExport(join(root, "head-export"), { screens: ["settings"], images: { settings: { path: "artifacts/settings.png" } },
|
||||
outcomes: { settings: light }, diagnostics: "" });
|
||||
const dark = await writeExport(join(root, "head-export-dark"), { screens: ["settings@dark"], images: { "settings@dark": { path: "artifacts/[email protected]" } },
|
||||
outcomes: { "settings@dark": wrong }, diagnostics: "" });
|
||||
await mergeCaptureExports(primary, [{ directory: dark, scheme: "dark" }]);
|
||||
const bundle = JSON.parse(await readFile(join(primary, "bundle.json"), "utf8"));
|
||||
assert.deepEqual(bundle.outcomes, mergeSchemeOutcomes([{ settings: light }, { settings: wrong }], ["light", "dark"]));
|
||||
assert.deepEqual(bundle.outcomes["settings@dark"], wrong);
|
||||
});
|
||||
|
||||
test("a dark session that could not show dark (Argent without appearance.set) adds nothing, and an open gap leaves the run partial", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-merge-"));
|
||||
const primary = await writeExport(join(root, "head-export"), { screens: ["home"], images: { home: { path: "artifacts/home.png" } },
|
||||
outcomes: { home: { status: "captured", landing: "verified", attempts: 1 } }, diagnostics: "" });
|
||||
const bundlePath = join(primary, "bundle.json"), mapPath = join(primary, "screen-map.json");
|
||||
// The primary session could not switch either: it captured light only.
|
||||
await writeFile(bundlePath, JSON.stringify({ ...JSON.parse(await readFile(bundlePath, "utf8")), runtimeProfile: { colorScheme: "light" } }));
|
||||
await writeFile(mapPath, JSON.stringify({ ...JSON.parse(await readFile(mapPath, "utf8")), run: { id: "run", status: "complete", environment: {} } }));
|
||||
const narrowed = await writeExport(join(root, "head-export-dark"), { screens: [], images: {}, outcomes: {}, diagnostics: "" });
|
||||
const narrowedBundle = join(narrowed, "bundle.json");
|
||||
await writeFile(narrowedBundle, JSON.stringify({ ...JSON.parse(await readFile(narrowedBundle, "utf8")), runtimeProfile: { colorScheme: "light" } }));
|
||||
await mergeCaptureExports(primary, [{ directory: narrowed, scheme: "dark" }]);
|
||||
assert.deepEqual(Object.keys(JSON.parse(await readFile(bundlePath, "utf8")).outcomes), ["home"]);
|
||||
assert.equal(JSON.parse(await readFile(mapPath, "utf8")).run.status, "complete");
|
||||
|
||||
const gapped = await writeExport(join(root, "other-export-dark"), { screens: ["home@dark"], images: { "home@dark": { path: "artifacts/[email protected]" } },
|
||||
outcomes: { "home@dark": { status: "captured", landing: "verified", attempts: 1 } }, diagnostics: "" });
|
||||
const gappedMap = join(gapped, "screen-map.json");
|
||||
await writeFile(gappedMap, JSON.stringify({ ...JSON.parse(await readFile(gappedMap, "utf8")), gaps: [{ id: "gap-1", status: "open" }] }));
|
||||
await writeFile(bundlePath, JSON.stringify({ ...JSON.parse(await readFile(bundlePath, "utf8")), runtimeProfile: { colorSchemes: "light,dark" } }));
|
||||
await mergeCaptureExports(primary, [{ directory: gapped, scheme: "dark" }]);
|
||||
assert.equal(JSON.parse(await readFile(mapPath, "utf8")).run.status, "partial", "a complete run has no open gaps");
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
const { tsImport } = await import("tsx/esm/api");
|
||||
const { clampInspectorWidth, inspectorWidthBounds, INSPECTOR_WIDTH_MAX, INSPECTOR_WIDTH_MIN } =
|
||||
await tsImport("../../viewer/src/utils/inspector-width.ts", import.meta.url);
|
||||
|
||||
test("the Inspector may take at most half the window, within its fixed range", () => {
|
||||
assert.deepEqual(inspectorWidthBounds(1440), { min: INSPECTOR_WIDTH_MIN, max: 720 });
|
||||
assert.deepEqual(inspectorWidthBounds(2560), { min: INSPECTOR_WIDTH_MIN, max: INSPECTOR_WIDTH_MAX });
|
||||
// A window narrower than two minimum panels still allows the minimum.
|
||||
assert.deepEqual(inspectorWidthBounds(500), { min: INSPECTOR_WIDTH_MIN, max: INSPECTOR_WIDTH_MIN });
|
||||
});
|
||||
|
||||
test("the bounds are in the panel's own pixels when the chrome is zoomed", () => {
|
||||
assert.deepEqual(inspectorWidthBounds(1600, 1.25), { min: INSPECTOR_WIDTH_MIN, max: 640 });
|
||||
assert.deepEqual(inspectorWidthBounds(1600, 0), inspectorWidthBounds(1600, 1));
|
||||
});
|
||||
|
||||
test("the Inspector stops where the canvas keeps the bottom bar's room, never below the minimum", () => {
|
||||
// 820 - 424 leaves 396, less than half of 820.
|
||||
assert.deepEqual(inspectorWidthBounds(820, 1, 424), { min: INSPECTOR_WIDTH_MIN, max: 396 });
|
||||
// In a wide window half of it is the tighter cap.
|
||||
assert.deepEqual(inspectorWidthBounds(1440, 1, 424), { min: INSPECTOR_WIDTH_MIN, max: 720 });
|
||||
// The room is in window pixels, the width in the panel's own: (1000 - 530) / 1.25 = 376.
|
||||
assert.deepEqual(inspectorWidthBounds(1000, 1.25, 530), { min: INSPECTOR_WIDTH_MIN, max: 376 });
|
||||
assert.deepEqual(inspectorWidthBounds(700, 1, 424), { min: INSPECTOR_WIDTH_MIN, max: INSPECTOR_WIDTH_MIN });
|
||||
});
|
||||
|
||||
test("a width is clamped to the bounds and rounded to whole pixels", () => {
|
||||
const bounds = { min: 320, max: 720 };
|
||||
assert.equal(clampInspectorWidth(100, bounds), 320);
|
||||
assert.equal(clampInspectorWidth(1000, bounds), 720);
|
||||
assert.equal(clampInspectorWidth(455.6, bounds), 456);
|
||||
});
|
||||
@@ -437,6 +437,30 @@ test('a review runs at most --parallel targets at once, and every target settles
|
||||
assert.deepEqual(results.map(result => result.status === 'fulfilled' ? result.value : result.reason.message), [10, 20, 'three', 40, 50]);
|
||||
});
|
||||
|
||||
test('a local review runs no more targets at once than capture.maxSessions', async t => {
|
||||
const targets = { phone: { platform: 'ios' }, tablet: { platform: 'ios', device: 'iPad Air' } };
|
||||
// Whether one target's review began before the other's ended, from the order of their progress lines.
|
||||
const overlapped = async (maxSessions, parallel) => {
|
||||
const f = await fixture(t, 'expo-router', { targets, maxSessions });
|
||||
t.mock.method(globalThis, 'fetch', async input => assert.fail(`Unmocked network request: ${input}`));
|
||||
const environment = { ...f.environment, EXPLORE_CACHE_DIR: await scratch(t, 'explore-local-cache-'), GITHUB_RUN_ID: '', GITHUB_RUN_ATTEMPT: '', GITHUB_TOKEN: '' };
|
||||
const lines = [];
|
||||
const result = await runLocalReview({ project: f.headProject, base: f.baseSha, head: f.headSha, environment, cache: false, ...(parallel ? { parallel } : {}),
|
||||
install: async checkout => { await writeCaptureObserverPackages(checkout, { provider: 'expo-router' }); }, runner: f.runner, now: f.now, sleep: f.sleep,
|
||||
progress: message => lines.push(message) });
|
||||
t.after(() => rm(result.work, { recursive: true, force: true }));
|
||||
assert.deepEqual(result.reports.map(report => report.target.id).sort(), ['phone', 'tablet']);
|
||||
const span = id => [lines.findIndex(line => line.startsWith(`${id}: `)), lines.findLastIndex(line => line.startsWith(`${id}: `))];
|
||||
const [phone, tablet] = [span('phone'), span('tablet')];
|
||||
return phone[0] < tablet[1] && tablet[0] < phone[1];
|
||||
};
|
||||
// One simulator at a time: the targets take turns.
|
||||
assert.equal(await overlapped(1), false);
|
||||
// The default ceiling (five) runs both at once, and --parallel still chooses for itself.
|
||||
assert.equal(await overlapped(undefined), true);
|
||||
assert.equal(await overlapped(1, 2), true);
|
||||
});
|
||||
|
||||
test('a target that fails outright costs only its own report', async t => {
|
||||
const targets = { phone: { platform: 'ios' }, tablet: { platform: 'ios', device: 'iPad Air' } };
|
||||
const f = await fixture(t, 'expo-router', { targets });
|
||||
|
||||
@@ -340,8 +340,10 @@ test("expired comparison budgets produce diagnostics rather than review verdicts
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-public-evidence-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
const base = await side(root, "base", manifests.base);
|
||||
const head = await side(root, "head", manifests.head);
|
||||
let clock = 0;
|
||||
const result = await assessPublicEvidence({ plan: plan(), base, head, profile: "explore:bundle", agentDeviceCommand: "/nonexistent/agent-device", timeBudgetMs: 0, now: () => clock++, measure: async () => { assert.fail('expired comparisons do not run'); } });
|
||||
let clock = 0, measured = 0;
|
||||
const result = await assessPublicEvidence({ plan: plan(), base, head, profile: "explore:bundle", agentDeviceCommand: "/nonexistent/agent-device", timeBudgetMs: 0, now: () => clock++,
|
||||
measure: async (...args) => { measured += 1; return measurer({})(...args); } });
|
||||
assert.equal(measured, 0, "expired comparisons do not run");
|
||||
assert.equal(result.summary.visual.compared, 0);
|
||||
assert.equal(result.summary.visual.failed, 3);
|
||||
assert.equal(result.summary.visual.needsReview, 0);
|
||||
@@ -526,6 +528,47 @@ test("a presence verdict for a long route (an encoded share link) stays within t
|
||||
assert.equal(presenceDescription("Added ", "/home", " screen."), "Added /home screen.");
|
||||
});
|
||||
|
||||
test("screenshot pairs compare a few at a time, in the loop's order, with the same verdicts as one at a time", async (t) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-public-evidence-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
const base = await side(root, "base", manifests.base);
|
||||
const head = await side(root, "head", manifests.head);
|
||||
const run = async (concurrency) => {
|
||||
let active = 0, peak = 0;
|
||||
const started = [];
|
||||
const measure = async (baselinePath, currentPath) => {
|
||||
started.push(baselinePath);
|
||||
active += 1; peak = Math.max(peak, active);
|
||||
await new Promise(resolve => setTimeout(resolve, 20));
|
||||
active -= 1;
|
||||
return measurer({ changed: 3.2, stable: 0.4 })(baselinePath, currentPath);
|
||||
};
|
||||
const result = await assessPublicEvidence({ plan: plan(), base, head, profile: "explore:bundle", agentDeviceCommand: "/nonexistent/agent-device", measure, concurrency });
|
||||
return { peak, started, surfaces: result.surfaces, summary: result.summary };
|
||||
};
|
||||
const sequential = await run(1);
|
||||
const parallel = await run(4);
|
||||
assert.equal(sequential.peak, 1);
|
||||
assert.ok(parallel.peak > 1, `comparisons overlap (peak ${parallel.peak})`);
|
||||
assert.deepEqual(parallel.started, sequential.started, "pairs start in the loop's order");
|
||||
assert.deepEqual(parallel.surfaces, sequential.surfaces);
|
||||
assert.deepEqual(parallel.summary, sequential.summary);
|
||||
});
|
||||
|
||||
test("a pair whose turn comes after the budget expired is not started, and one started in time is used", async (t) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-public-evidence-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
const base = await side(root, "base", manifests.base);
|
||||
const head = await side(root, "head", manifests.head);
|
||||
// The first comparison takes past the budget: it was started in time, the two queued behind it were not.
|
||||
let time = 0, measured = 0;
|
||||
const measure = async (...args) => { measured += 1; time += 1_000; return measurer({})(...args); };
|
||||
const result = await assessPublicEvidence({ plan: plan(), base, head, profile: "explore:bundle", agentDeviceCommand: "/nonexistent/agent-device",
|
||||
timeBudgetMs: 100, now: () => time, measure, concurrency: 1 });
|
||||
assert.equal(measured, 1);
|
||||
assert.equal(result.summary.visual.compared, 1);
|
||||
assert.equal(result.summary.visual.failed, 2);
|
||||
assert.ok(result.summary.diagnostics.every(item => item.code === 'VISUAL_COMPARISON_BUDGET_EXHAUSTED'));
|
||||
});
|
||||
|
||||
test("unstable text never makes a screen Modified, and names a variant's runtime state", () => {
|
||||
const unstable = { category: "visible-text", templateId: "visible-text.unstable-within-build", bullet: 'Text varies between captures of the same build: "2m" / "4m" / "3m".' };
|
||||
const summary = (facts) => ({ facts, needsReview: false, reviewIssues: [] });
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { Buffer } from "node:buffer";
|
||||
import { regionMoves, regionShifts } from "../../dist/review/region-shift.js";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { PNG } from "pngjs";
|
||||
import { measureRegionMoves, regionMoves, regionShifts } from "../../dist/review/region-shift.js";
|
||||
import { measureRegionMovesInWorker } from "../../dist/review/region-shift-worker.js";
|
||||
|
||||
/** A 120×160 frame of a light background with dark text-like bars, drawn `offsetY` pixels lower (fractions blend rows). */
|
||||
function frame(offsetY, { barColor = 40, extraBar = false } = {}) {
|
||||
@@ -102,6 +107,18 @@ test("a half-pixel move up and down is judged alike", () => {
|
||||
assert.deepEqual([up?.y, down?.y], [-0.5, 0.5]);
|
||||
});
|
||||
|
||||
test("a move whose best fit ties with a smaller one is still a move: the search stops no fit that could make it ambiguous", () => {
|
||||
// Two and a half pixels lower, with a sparse speckle of noise. The tie goes to a fit a little worse than the least error,
|
||||
// and an ambiguity is judged against that one, so a fit stopped short against the least error must not pass for one.
|
||||
const moved = frame(2.5), speckled = { ...moved, data: Buffer.from(moved.data) };
|
||||
for (let y = 0; y < moved.height; y += 1) for (let x = 0; x < moved.width; x += 1) {
|
||||
if ((x * 3 + y * 5) % 11 !== 0) continue;
|
||||
const offset = (y * moved.width + x) * 4, value = Math.max(0, Math.min(255, moved.data[offset] + ((x + y) % 2 ? 10 : -10)));
|
||||
speckled.data.fill(value, offset, offset + 3);
|
||||
}
|
||||
assert.deepEqual(regionShifts(frame(0), speckled, [region]), [{ x: 0, y: 2.5 }]);
|
||||
});
|
||||
|
||||
/**
|
||||
* A light frame with a dark card of irregular blocks at (x, y): the blocks make every offset look different, as a
|
||||
* real card's text and icons do. `tile` repeats one such block pattern every `tile` pixels across the whole row
|
||||
@@ -138,6 +155,22 @@ test("a card that moved far along a row is one move, from the regions where it l
|
||||
[{ rect: { x: 330, y: 80, width: 150, height: 120 }, shift: { x: 270, y: 0 }, members: [1, 0] }], "the region it arrived in first");
|
||||
});
|
||||
|
||||
test("a large move is measured on a worker thread the same as on the calling thread", async (t) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-region-shift-")); t.after(() => rm(root, { recursive: true, force: true }));
|
||||
const write = async (name, frame) => {
|
||||
const png = new PNG({ width: frame.width, height: frame.height }); frame.data.copy(png.data);
|
||||
await writeFile(join(root, name), PNG.sync.write(png)); return join(root, name);
|
||||
};
|
||||
const basePath = await write("base.png", cardFrame()), headPath = await write("head.png", cardFrame({ x: 330 }));
|
||||
const regions = [
|
||||
{ x: 60, y: 80, width: 150, height: 120, dominantChange: "brighter" },
|
||||
{ x: 330, y: 80, width: 150, height: 120, dominantChange: "darker" },
|
||||
];
|
||||
const measured = await measureRegionMovesInWorker(basePath, headPath, regions);
|
||||
assert.deepEqual(measured, await measureRegionMoves(basePath, headPath, regions));
|
||||
assert.deepEqual(measured.moves, [{ rect: { x: 330, y: 80, width: 150, height: 120 }, shift: { x: 270, y: 0 }, members: [1, 0] }]);
|
||||
});
|
||||
|
||||
test("a move whose old and new places overlap takes in the fragments of it the comparison found in between", () => {
|
||||
// A 300-wide card moved 120 right: the comparison sees where it only was, where it only is, and a fragment of the
|
||||
// overlap whose pixels differ because the card's own content moved over itself.
|
||||
|
||||
@@ -113,6 +113,10 @@ test("the palette's commands follow the canvas: Compare steps changes with the a
|
||||
assert.ok(!ids(compare).includes("go:compare"));
|
||||
assert.ok(ids(compare).includes("go:map"));
|
||||
|
||||
// Full screen, where the browser has it, prints F; without it there is no command.
|
||||
assert.equal(commandItems({ ...base, canvas: "map", fullscreen: false }, actions).find((item) => item.id === "command:view:fullscreen").shortcut, "F");
|
||||
assert.ok(!ids(map).includes("view:fullscreen"));
|
||||
|
||||
// A phone has no keyboard shortcuts to list.
|
||||
assert.ok(ids(map).includes("go:shortcuts"));
|
||||
assert.ok(!ids(commandItems({ ...base, canvas: "map", phone: true }, actions)).includes("go:shortcuts"));
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { chmod, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import { sideAppearancePasses } from "../../dist/ci/pipeline.js";
|
||||
import { DEFAULT_MAX_SESSIONS, maxParallelTargets, planSideSessions, sessionShare } from "../../dist/ci/session-plan.js";
|
||||
import { validateExploreConfig } from "../../dist/config/explore-config.js";
|
||||
|
||||
test("the review-wide session ceiling is divided over the targets, the remainder going to the preferred ones", () => {
|
||||
const targets = ["iphone", "duo-closed", "duo-open", "android"];
|
||||
const prefer = target => target.startsWith("duo") ? 1 : 0;
|
||||
assert.equal(sessionShare({ maxSessions: 8, targets, target: "android" }), 2);
|
||||
assert.equal(sessionShare({ maxSessions: 16, targets, target: "iphone" }), 4);
|
||||
assert.equal(sessionShare({ maxSessions: 10, targets, target: "duo-closed", prefer }), 3, "remainder goes to the foldable first");
|
||||
assert.equal(sessionShare({ maxSessions: 10, targets, target: "duo-open", prefer }), 3);
|
||||
assert.equal(sessionShare({ maxSessions: 10, targets, target: "iphone", prefer }), 2);
|
||||
assert.equal(sessionShare({ maxSessions: 2, targets, target: "iphone" }), 1, "never below one");
|
||||
});
|
||||
|
||||
test("unset, the ceiling is a typical plan's five simulators; below the number of targets, that many target jobs run at once", () => {
|
||||
assert.equal(DEFAULT_MAX_SESSIONS, 5);
|
||||
// One target: head and base at once, with sessions left to split light and dark.
|
||||
assert.equal(sessionShare({ maxSessions: undefined, targets: ["iphone"], target: "iphone" }), 5);
|
||||
assert.deepEqual(planSideSessions({ share: 5, sides: 2, routes: 16, schemes: ["light", "dark"] }), { concurrentSides: true, passes: [["light"], ["dark"]] });
|
||||
// Two targets: two each, head and base at once, as before the option.
|
||||
for (const target of ["iphone", "android"]) assert.equal(sessionShare({ maxSessions: undefined, targets: ["iphone", "android"], target }), 2);
|
||||
// Five targets: one each, head then base.
|
||||
const five = ["iphone", "ipad", "duo-closed", "duo-open", "android"];
|
||||
for (const target of five) assert.equal(sessionShare({ maxSessions: undefined, targets: five, target }), 1);
|
||||
assert.equal(planSideSessions({ share: 1, sides: 2, routes: 16, schemes: ["light", "dark"] }).concurrentSides, false);
|
||||
assert.deepEqual([maxParallelTargets(undefined, 1), maxParallelTargets(undefined, 2), maxParallelTargets(undefined, 5), maxParallelTargets(undefined, 7)], [1, 2, 5, 5]);
|
||||
// A starter plan, one simulator per platform: an iOS and an Android target, one session each, both jobs at once.
|
||||
for (const target of ["iphone", "android"]) assert.equal(sessionShare({ maxSessions: 2, targets: ["iphone", "android"], target }), 1);
|
||||
assert.equal(maxParallelTargets(2, 2), 2);
|
||||
// A ceiling below the targets: one session each, and only that many target jobs at a time.
|
||||
for (const target of five) assert.equal(sessionShare({ maxSessions: 2, targets: five, target }), 1);
|
||||
assert.equal(maxParallelTargets(2, 5), 2);
|
||||
assert.equal(maxParallelTargets(16, 4), 4);
|
||||
});
|
||||
|
||||
test("a side splits its appearance passes only when the pass moved out saves at least a minute", () => {
|
||||
const euxy = { sides: 2, routes: 16, schemes: ["light", "dark"] };
|
||||
assert.deepEqual(planSideSessions({ share: 2, ...euxy }), { concurrentSides: true, passes: [["light", "dark"]] });
|
||||
assert.deepEqual(planSideSessions({ share: 4, ...euxy }), { concurrentSides: true, passes: [["light"], ["dark"]] });
|
||||
assert.deepEqual(planSideSessions({ share: 3, ...euxy }), { concurrentSides: true, passes: [["light", "dark"]] }, "one spare session cannot host a pass for both sides");
|
||||
assert.deepEqual(planSideSessions({ share: 8, ...euxy, routes: 3 }), { concurrentSides: true, passes: [["light", "dark"]] }, "three routes would save under a minute");
|
||||
assert.deepEqual(planSideSessions({ share: 8, ...euxy, schemes: ["light"] }), { concurrentSides: true, passes: [["light"]] }, "one appearance never splits");
|
||||
assert.deepEqual(planSideSessions({ share: 1, ...euxy }), { concurrentSides: false, passes: [["light", "dark"]] }, "one session: the sides take turns");
|
||||
assert.deepEqual(planSideSessions({ share: 2, sides: 1, routes: 16, schemes: ["light", "dark"] }), { concurrentSides: true, passes: [["light"], ["dark"]] }, "a baseline has one side");
|
||||
});
|
||||
|
||||
test("a side's appearances come from eas config in a child with the capture's environment, read only when a split could pay", async t => {
|
||||
const root = await mkdtemp(join(tmpdir(), "explore-session-plan-"));
|
||||
t.after(() => rm(root, { recursive: true, force: true }));
|
||||
// The app config would leak this process's environment if it were evaluated here.
|
||||
await writeFile(join(root, "app.config.js"), `module.exports = () => { require("fs").writeFileSync(${JSON.stringify(join(root, "evaluated"))}, "yes"); return {}; };\n`);
|
||||
const eas = join(root, "eas");
|
||||
await writeFile(eas, `#!/usr/bin/env node
|
||||
require("fs").appendFileSync(${JSON.stringify(join(root, "calls"))}, JSON.stringify({ args: process.argv.slice(2), cwd: process.cwd(), env: process.env }) + "\\n");
|
||||
process.stdout.write(JSON.stringify({ appConfig: { userInterfaceStyle: require("fs").existsSync("light-only") ? "light" : "automatic" }, buildProfile: {} }));
|
||||
`);
|
||||
await chmod(eas, 0o755);
|
||||
const calls = async () => (await readFile(join(root, "calls"), "utf8").catch(() => "")).split("\n").filter(Boolean).map(line => JSON.parse(line));
|
||||
const config = maxSessions => validateExploreConfig({ app: { bundleId: "com.example.app", easProfile: "explore" }, device: { name: "iPhone 17" },
|
||||
...(maxSessions === undefined ? {} : { capture: { maxSessions } }) });
|
||||
const environment = { PATH: process.env.PATH, HOME: process.env.HOME, EXPO_TOKEN: "expo-token", GITHUB_TOKEN: "github-token", ANTHROPIC_API_KEY: "agent-key" };
|
||||
const side = { share: 2, sides: 1, routes: 16, project: root, easCommand: eas };
|
||||
assert.equal(await sideAppearancePasses(config(8), environment, { ...side, routes: 3 }), undefined, "three routes would save under a minute");
|
||||
assert.equal(await sideAppearancePasses(config(1), environment, { ...side, share: 1 }), undefined);
|
||||
assert.deepEqual(await calls(), [], "no app config is read when no split could pay");
|
||||
assert.deepEqual(await sideAppearancePasses(config(2), environment, side), [["light"], ["dark"]]);
|
||||
const [call] = await calls();
|
||||
assert.deepEqual(call.args, ["config", "--platform", "ios", "--profile", "explore", "--json", "--non-interactive"]);
|
||||
assert.equal(await realpath(call.cwd), await realpath(root));
|
||||
assert.equal(call.env.EXPO_TOKEN, "expo-token");
|
||||
assert.equal(call.env.GITHUB_TOKEN, undefined);
|
||||
assert.equal(call.env.ANTHROPIC_API_KEY, undefined);
|
||||
await assert.rejects(readFile(join(root, "evaluated")), "the app config is never evaluated in the review's process");
|
||||
assert.deepEqual(await sideAppearancePasses(config(undefined), environment, side), [["light"], ["dark"]], "unset, the default ceiling's share splits too");
|
||||
// Each side reads its own app config: one that declares a single appearance keeps one session.
|
||||
const lightOnly = join(root, "base"); await mkdir(lightOnly); await writeFile(join(lightOnly, "light-only"), "");
|
||||
assert.equal(await sideAppearancePasses(config(2), environment, { ...side, project: lightOnly }), undefined);
|
||||
assert.equal(await sideAppearancePasses(config(2), environment, { ...side, easCommand: join(root, "missing-eas") }), undefined, "an unreadable config keeps one session");
|
||||
});
|
||||
@@ -59,3 +59,33 @@ test("a capture that ends without finishing its shared build releases the target
|
||||
assert.equal(error.code, "CAPTURE_BUILD_FAILED");
|
||||
assert.match(error.message, /the capture building it stopped \(CAPTURE_WORKER_EXITED\)/);
|
||||
});
|
||||
|
||||
test("a waiter is told the build is repacking only when its builder says so, not while a native build may run", async t => {
|
||||
const directory = await scratch(t);
|
||||
let started, repack, finish;
|
||||
const building = new Promise(resolve => { started = resolve; });
|
||||
const owner = sharedBuild({ directory, key, appName: "App.app", build: (_keepApp, repacking) => new Promise(resolve => {
|
||||
started(); repack = repacking; finish = () => resolve({ buildId: "native" }); }) });
|
||||
await building;
|
||||
const told = [];
|
||||
const waiter = sharedBuild({ directory, key, appName: "App.app", build: async () => assert.fail("only the owner builds"),
|
||||
waiting: () => told.push("waiting"), repacking: () => told.push("repacking") });
|
||||
// The owner is still in its native build: two polls go by without the waiter's session starting.
|
||||
await new Promise(resolve => setTimeout(resolve, 4_500));
|
||||
assert.deepEqual(told, ["waiting"]);
|
||||
await repack();
|
||||
await new Promise(resolve => setTimeout(resolve, 2_500));
|
||||
assert.deepEqual(told, ["waiting", "repacking"]);
|
||||
finish();
|
||||
await owner; await waiter;
|
||||
assert.deepEqual(told, ["waiting", "repacking"]);
|
||||
});
|
||||
|
||||
test("a waiter whose build finished before it looked is told it is repacking once, with the result", async t => {
|
||||
const directory = await scratch(t);
|
||||
await sharedBuild({ directory, key, appName: "App.app", build: async () => ({ buildId: "native" }) });
|
||||
const told = [];
|
||||
assert.deepEqual(await sharedBuild({ directory, key, appName: "App.app", build: async () => assert.fail("only the owner builds"),
|
||||
waiting: () => told.push("waiting"), repacking: () => told.push("repacking") }), { buildId: "native" });
|
||||
assert.deepEqual(told, ["waiting", "repacking"]);
|
||||
});
|
||||
@@ -70,3 +70,11 @@ test("⌥1–⌥8 open a target by its place, with ⌥ alone; D and ` are plain
|
||||
assert.ok(matchesShortcut(key("KeyD"), SHORTCUTS.target.menu));
|
||||
assert.ok(matchesShortcut(key("Backquote"), SHORTCUTS.target.last));
|
||||
});
|
||||
|
||||
test("F is full screen, a plain key: ⌘F stays the browser's find", () => {
|
||||
assert.equal(formatShortcut(SHORTCUTS.view.fullscreen, true), "F");
|
||||
assert.ok(matchesShortcut(key("KeyF"), SHORTCUTS.view.fullscreen));
|
||||
assert.ok(!matchesShortcut(key("KeyF", { metaKey: true }), SHORTCUTS.view.fullscreen));
|
||||
assert.ok(!matchesShortcut(key("KeyF", { ctrlKey: true }), SHORTCUTS.view.fullscreen));
|
||||
assert.ok(!matchesShortcut(key("KeyF", { shiftKey: true }), SHORTCUTS.view.fullscreen));
|
||||
});
|
||||
@@ -21,6 +21,60 @@ test("import closure attributes component and platform-source changes to depende
|
||||
assert.deepEqual(selectedPaths(plan({base:files,platform:"android",changes:[{status:"modified",path:"src/theme.ios.ts"}]})), []);
|
||||
});
|
||||
|
||||
test("tsconfig paths with several single-directory aliases resolve by their longest prefix, as TypeScript does", () => {
|
||||
const tsconfig = JSON.stringify({ extends: "expo/tsconfig.base", compilerOptions: { paths: { "@/*": ["./src/*"], "@/assets/*": ["./assets/*"] } } });
|
||||
const files = [["tsconfig.json", tsconfig], ["src/app/one.tsx", 'import { tint } from "@/theme"; import icon from "@/assets/icon"; export default () => [tint, icon];'],
|
||||
["src/app/two.tsx", page], ["src/theme.ts", "export const tint = 'blue';"], ["assets/icon.ts", "export default 'icon';"], ["src/assets/icon.ts", "export default 'other';"]];
|
||||
const result = plan({ base: files, changes: [{ status: "modified", path: "assets/icon.ts" }] });
|
||||
assert.deepEqual(selectedPaths(result), ["/one"]);
|
||||
assert.equal(result.surfaces.flatMap(row => row.reasons ?? []).some(reason => /module resolution/.test(reason)), false);
|
||||
// `@/assets/icon` is `assets/icon.ts`, not `src/assets/icon.ts`, so an edit to the latter changes nothing.
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, changes: [{ status: "modified", path: "src/assets/icon.ts" }] })), []);
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, changes: [{ status: "modified", path: "src/theme.ts" }] })), ["/one"]);
|
||||
});
|
||||
|
||||
test("an alias import that finds no file is local code the plan cannot follow, not a package", () => {
|
||||
const tsconfig = JSON.stringify({ compilerOptions: { paths: { "@/*": ["./src/*"], "@icons/*": ["./src/icons/*"] } } });
|
||||
const files = [["tsconfig.json", tsconfig], ["src/app/one.tsx", 'import Logo from "@icons/logo"; export default () => Logo;'], ["src/app/two.tsx", page], ["src/icons/logo.svg", "<svg/>"]];
|
||||
const result = plan({ base: files, changes: [{ status: "modified", path: "src/icons/logo.svg" }] });
|
||||
assert.ok(result.unresolved.some(message => message.includes("@icons/logo")), JSON.stringify(result.unresolved));
|
||||
assert.ok(selectedPaths(result).includes("/one"));
|
||||
});
|
||||
|
||||
test("tsconfig aliases: single-directory prefix keys are followed; anything TypeScript would read differently is not", async () => {
|
||||
const { readTsconfigAlias, resolveTsconfigAlias } = await tsImport("../../src/shared/tsconfig-alias.ts", import.meta.url);
|
||||
const read = paths => readTsconfigAlias(JSON.stringify({ compilerOptions: { paths } }));
|
||||
for (const paths of [{ "*": ["src/*"] }, { "@*": ["src/*"] }, { "@/x": ["src/x"] }, { "@/*/x": ["src/*"] }, { "./*": ["src/*"] }, { "/*": ["src/*"] },
|
||||
{ "@/*": ["src/*", "lib/*"] }, { "@/*": ["../src/*"] }, { "@/*": ["./src/./lib/*"] }, { "@/*": ["src/*.ts"] }]) {
|
||||
assert.ok(read(paths).unsupported, JSON.stringify(paths));
|
||||
}
|
||||
const alias = read({ "@/*": ["./src/*"], "@/assets/*": ["./assets/*"], "~/*": ["./*"] });
|
||||
assert.equal(alias.unsupported, undefined);
|
||||
assert.equal(resolveTsconfigAlias(alias, "@/assets/icon"), "assets/icon");
|
||||
assert.equal(resolveTsconfigAlias(alias, "@/assets"), "src/assets");
|
||||
assert.equal(resolveTsconfigAlias(alias, "~/theme"), "theme");
|
||||
assert.equal(resolveTsconfigAlias(alias, "react"), undefined);
|
||||
assert.equal(resolveTsconfigAlias(alias, "@/a/../b"), "src/b");
|
||||
assert.equal(resolveTsconfigAlias(alias, "@/components/"), "src/components");
|
||||
});
|
||||
|
||||
test("a platform file wins over a plain file of another extension, as Metro resolves it", () => {
|
||||
const files = [["app/one.tsx", 'import Card from "../src/card"; export default () => Card;'], ["app/two.tsx", page],
|
||||
["src/card.tsx", "export default 1;"], ["src/card.ios.ts", "export default 2;"]];
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, changes: [{ status: "modified", path: "src/card.ios.ts" }] })), ["/one"]);
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, changes: [{ status: "modified", path: "src/card.tsx" }] })), []);
|
||||
assert.deepEqual(selectedPaths(plan({ base: files, platform: "android", changes: [{ status: "modified", path: "src/card.tsx" }] })), ["/one"]);
|
||||
});
|
||||
|
||||
test("with a root baseUrl, a bare specifier that names a project file is a dependency; one that does not is a package", () => {
|
||||
const tsconfig = JSON.stringify({ compilerOptions: { baseUrl: ".", paths: { "components/*": ["./src/components/*"] } } });
|
||||
const files = [["tsconfig.json", tsconfig], ["app/one.tsx", 'import theme from "theme"; import { View } from "react-native"; export default () => [theme, View];'],
|
||||
["app/two.tsx", page], ["theme.ts", "export default 1;"]];
|
||||
const result = plan({ base: files, changes: [{ status: "modified", path: "theme.ts" }] });
|
||||
assert.deepEqual(selectedPaths(result), ["/one"]);
|
||||
assert.deepEqual(result.unresolved, []);
|
||||
});
|
||||
|
||||
test("route additions and removals are independently inventoried at each commit", () => {
|
||||
const result = plan({base:[["app/removed.tsx",page]],head:[["app/added.tsx",page]]});
|
||||
assert.deepEqual(selectedPaths(result,"base"), ["/removed"]);
|
||||
|
||||
@@ -168,7 +168,7 @@ test("follows the create-expo-app alias @/* -> ./* without a diagnostic", () =>
|
||||
|
||||
test("unresolved object hrefs and unsupported custom aliases remain explicit diagnostics", () => {
|
||||
const result = graph([surface("one"),surface("two")], {
|
||||
"tsconfig.json": JSON.stringify({compilerOptions:{paths:{"~/*":["src/*"]}}}),
|
||||
"tsconfig.json": JSON.stringify({compilerOptions:{paths:{"~/*":["src/*","lib/*"]}}}),
|
||||
"src/app/one.tsx": "import {router} from 'expo-router';import {Screen} from '~/screen';export default function One(){router.push({pathname:getPath()});return <Screen/>;}",
|
||||
});
|
||||
assert.deepEqual(result.edges, []);
|
||||
|
||||
@@ -93,3 +93,13 @@ test("doctor names a workflow that sets the app directory in one job but not ano
|
||||
assert.deepEqual(issues.map(issue => issue.code), ["WORKFLOW_APP_DIR_MISMATCH"]);
|
||||
assert.match(issues[0].message, /APP_PROJECT_DIR is \. in one of its jobs/);
|
||||
});
|
||||
|
||||
test("ci:after-capture stops the sessions a side's appearance passes recorded, not only the side's own", async t => {
|
||||
const output = await mkdtemp(join(tmpdir(), "explore-steps-sessions-"));
|
||||
t.after(() => rm(output, { recursive: true, force: true }));
|
||||
// Unreadable ids make the cleanup report each file it was handed without calling EAS.
|
||||
for (const name of ["head-session-dark", "base-session-dark", "baseline-session-light"]) await writeFile(join(output, name), "not a session id\n");
|
||||
await writeFile(join(output, "head-session-sepia"), "not a session id\n");
|
||||
const result = await cleanupAfterCapture({ output, checkouts: [], environment: { RUNNER_TEMP: output, EXPO_TOKEN: "token" } });
|
||||
assert.deepEqual(result.failures.map(failure => failure.message), Array(3).fill("Refusing an invalid session ID."));
|
||||
});
|
||||
+20
-13
@@ -7,12 +7,13 @@ import { isEmbeddedArtifactUrl, leaseEmbeddedArtifactUrl, optionalStorage, viewe
|
||||
import { REPORT_SOURCE } from "./utils/report-source";
|
||||
import { CanvasToolbar } from "./components/canvas/toolbar";
|
||||
import { CanvasCameraControls } from "./components/canvas/camera-controls";
|
||||
import { MoreMenu } from "./components/canvas/more-menu";
|
||||
import { CanvasVisibleFrameProvider } from "./components/canvas/visible-frame-provider";
|
||||
import { AppLoading } from "./components/shared/app-loading";
|
||||
import { ReportLoadingShell } from "./components/shared/report-loading-shell";
|
||||
import { screenLabel } from "./utils/screen-path";
|
||||
import { AppPill, PLATFORM_NAMES, runTargets, siblingReportUrl, targetSwitch } from "./components/panels/app-pill";
|
||||
import { useFullscreen } from "./components/panels/shell-actions";
|
||||
import { fullscreenSupported, useFullscreen } from "./components/panels/shell-actions";
|
||||
import { getCanvasZoomState, runCanvasZoomCommand } from "./utils/canvas-zoom";
|
||||
import { commandItems, suggestedCommands } from "./utils/commands";
|
||||
import { changedScreens, focusCounts as countFocusStatuses, isCapturedChange, type ChangedScreen } from "./utils/changed-screens";
|
||||
@@ -383,11 +384,8 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
|
||||
const revisionRef = useRef<{ runId: string; revision: number } | undefined>(undefined);
|
||||
const pollingRef = useRef(false);
|
||||
const theme = themePreference === "system" ? preferredSystemTheme : themePreference;
|
||||
// Auto → Dark → Light → Auto, as the button's tooltip spells out.
|
||||
const toggleTheme = useCallback(() => {
|
||||
setThemePreference(current => current === "system" ? "dark" : current === "dark" ? "light" : "system");
|
||||
}, []);
|
||||
// The T key flips what is on screen, dark to light and back; only the button returns to Auto.
|
||||
// The T key flips what is on screen, dark to light and back; only the More menu's theme switch
|
||||
// (or the palette) returns to Auto.
|
||||
const flipTheme = useCallback(() => {
|
||||
setThemePreference(current => (current === "system" ? preferredSystemTheme : current) === "dark" ? "light" : "dark");
|
||||
}, [preferredSystemTheme]);
|
||||
@@ -1043,6 +1041,10 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
|
||||
setHandoffOpen(true);
|
||||
} else if (matchesShortcut(event, SHORTCUTS.appearance.theme)) {
|
||||
flipTheme();
|
||||
} else if (matchesShortcut(event, SHORTCUTS.view.fullscreen)) {
|
||||
// The More menu and the palette offer full screen only where the browser has it.
|
||||
if (phoneRef.current || !fullscreenSupported()) return;
|
||||
toggleFullscreen();
|
||||
} else if (matchesShortcut(event, SHORTCUTS.appearance.app)) {
|
||||
// Only a report captured in both schemes has another appearance to show.
|
||||
const { options, current } = appearanceRef.current;
|
||||
@@ -1064,7 +1066,7 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
};
|
||||
}, [chooseAppearance, clearSelectedScreen, flipTheme, navigate, searchOpen, selectCanvas, toggleRightPanel]);
|
||||
}, [chooseAppearance, clearSelectedScreen, flipTheme, navigate, searchOpen, selectCanvas, toggleFullscreen, toggleRightPanel]);
|
||||
|
||||
// A side-panel row or a deep link is a "go to": the camera fits that screen and the step is
|
||||
// kept. Screens inventory clicks only select in place; Map clicks also focus the chosen screen. Repeating a selected target refits it without adding history.
|
||||
@@ -1574,7 +1576,7 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
|
||||
theme: themePreference,
|
||||
appearances: appearances.length > 1 ? appearances.map((option) => ({ id: option, label: appearanceLabel(option), current: option === appearance })) : [],
|
||||
inspector: phone || comparingScreens ? undefined : { open: !rightCollapsed },
|
||||
fullscreen: !phone && typeof document.documentElement.requestFullscreen === "function" ? fullscreen : undefined,
|
||||
fullscreen: !phone && fullscreenSupported() ? fullscreen : undefined,
|
||||
targets: (() => {
|
||||
const run = runTargets(map.run);
|
||||
const noun = run.targets.every((target) => target.id === target.platform) ? "platform" as const : "device" as const;
|
||||
@@ -1692,10 +1694,8 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{phone ? null : (
|
||||
<CanvasCameraControls inspectorCollapsed={comparing ? false : rightCollapsed} theme={theme} themePreference={themePreference} onToggleTheme={toggleTheme}
|
||||
camera={route.canvas === "map"} />
|
||||
)}
|
||||
{/* Top right holds the camera only, so only the Map has anything there. */}
|
||||
{phone || route.canvas !== "map" ? null : <CanvasCameraControls />}
|
||||
{phone ? (
|
||||
<PhoneTabBar
|
||||
canvas={route.canvas}
|
||||
@@ -1706,7 +1706,13 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
|
||||
canvas={route.canvas}
|
||||
searchOpen={searchOpen}
|
||||
{...(handoffAction ? { actions: handoffAction } : {})}
|
||||
onOpenShortcuts={() => setShortcutsOpen(true)}
|
||||
more={<MoreMenu
|
||||
themePreference={themePreference}
|
||||
onChangeTheme={setThemePreference}
|
||||
{...(fullscreenSupported() ? { fullscreen: { active: fullscreen, onToggle: toggleFullscreen } } : {})}
|
||||
{...(comparingScreens ? {} : { inspector: { open: !rightCollapsed, onToggle: toggleRightPanel } })}
|
||||
onOpenShortcuts={() => setShortcutsOpen(true)}
|
||||
/>}
|
||||
onSelectCanvas={selectCanvas}
|
||||
onOpenSearch={() => setSearchOpen(true)}
|
||||
/>}
|
||||
@@ -1714,6 +1720,7 @@ const ViewerApp = memo(function ViewerApp({ reportKey }: { reportKey: number })
|
||||
{shortcutsOpen ? (
|
||||
<ShortcutsDialog
|
||||
context={{ canvas: route.canvas, review: reviewingInSidebar, hasChanges: compareOrder.length > 0, handoff: Boolean(handoffInput), appearances: appearances.length > 1,
|
||||
fullscreen: !phone && fullscreenSupported(),
|
||||
...(switchTargets ? { targets: switchTargets } : {}) }}
|
||||
onClose={() => setShortcutsOpen(false)}
|
||||
/>
|
||||
|
||||
@@ -6,20 +6,9 @@ import { formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
|
||||
import { KeyHint } from "../shared/key-hint";
|
||||
import { Menu, type MenuItem } from "../shared/menu";
|
||||
import { Tooltip } from "../shared/tooltip";
|
||||
import { FullscreenToggleButton, ThemeToggleButton, type ShellActionsProps, type ShellTheme } from "../panels/shell-actions";
|
||||
import { useCanvasVisibleFrame } from "./visible-frame-provider";
|
||||
import { setFollowSelection, useFollowSelection } from "../../utils/follow-selection";
|
||||
|
||||
type CanvasCameraControlsProps = {
|
||||
/** Makes room for the collapsed inspector controls at the window edge. */
|
||||
inspectorCollapsed: boolean;
|
||||
theme: ShellTheme;
|
||||
themePreference: ShellActionsProps["themePreference"];
|
||||
onToggleTheme: () => void;
|
||||
/** Fit, center and zoom act on a canvas; a page (Screens) or Compare shows only the page actions. */
|
||||
camera?: boolean;
|
||||
};
|
||||
|
||||
const CAMERA_CONTROLS_MINIMUM_FRAME_WIDTH = 240;
|
||||
|
||||
function ZoomControl() {
|
||||
@@ -114,11 +103,11 @@ function RecenterControl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Camera actions belong to the canvas, not to either inspector panel. The page-level theme and
|
||||
* full screen actions share the toolbar, so it stays in one place whether the inspector is open
|
||||
* or not.
|
||||
* Camera actions belong to the canvas, not to either inspector panel: fit, center and the zoom
|
||||
* level, top right on the Map. Screens and Compare have no camera, so nothing renders there; the
|
||||
* page-wide theme and full screen live in the bottom bar's "More" menu.
|
||||
*/
|
||||
export function CanvasCameraControls({ inspectorCollapsed, theme, themePreference, onToggleTheme, camera = true }: CanvasCameraControlsProps) {
|
||||
export function CanvasCameraControls() {
|
||||
const { visibleFrame } = useCanvasVisibleFrame();
|
||||
if (visibleFrame && visibleFrame.width < CAMERA_CONTROLS_MINIMUM_FRAME_WIDTH) return null;
|
||||
const style = visibleFrame ? ({
|
||||
@@ -126,24 +115,12 @@ export function CanvasCameraControls({ inspectorCollapsed, theme, themePreferenc
|
||||
} as CSSProperties) : undefined;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`canvas-camera-controls${inspectorCollapsed ? " inspector-collapsed" : ""}`}
|
||||
style={style}
|
||||
role="group"
|
||||
aria-label="Canvas camera controls">
|
||||
<div className="canvas-camera-controls" style={style} role="group" aria-label="Canvas camera controls">
|
||||
<div className="canvas-camera-controls-inner">
|
||||
{camera ? (
|
||||
<>
|
||||
<FitControl />
|
||||
<span className="camera-control-divider" aria-hidden="true" />
|
||||
<RecenterControl />
|
||||
<span className="camera-control-divider" aria-hidden="true" />
|
||||
<ZoomControl />
|
||||
<span className="camera-control-divider" aria-hidden="true" />
|
||||
</>
|
||||
) : null}
|
||||
<ThemeToggleButton theme={theme} themePreference={themePreference} onToggleTheme={onToggleTheme} className="camera-action-button" />
|
||||
<FullscreenToggleButton className="camera-action-button" />
|
||||
<FitControl />
|
||||
<RecenterControl />
|
||||
<span className="camera-control-divider" aria-hidden="true" />
|
||||
<ZoomControl />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
import { useCallback, useId, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
|
||||
import { Check, Ellipsis, Keyboard, Maximize, Minimize, Monitor, Moon, PanelRight, Sun } from "lucide-react";
|
||||
import { Menu } from "../shared/menu";
|
||||
import { Tooltip } from "../shared/tooltip";
|
||||
import { formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
|
||||
import type { ThemePreference } from "../../utils/navigation";
|
||||
|
||||
const THEME_OPTIONS: { id: ThemePreference; label: string; title: string; icon: ReactNode }[] = [
|
||||
{ id: "system", label: "Auto", title: "Auto (system)", icon: <Monitor /> },
|
||||
{ id: "light", label: "Light", title: "Light", icon: <Sun /> },
|
||||
{ id: "dark", label: "Dark", title: "Dark", icon: <Moon /> },
|
||||
];
|
||||
|
||||
export type MoreMenuProps = {
|
||||
themePreference: ThemePreference;
|
||||
onChangeTheme: (theme: ThemePreference) => void;
|
||||
/** Full screen's state and toggle; left out where the browser has no full screen. */
|
||||
fullscreen?: { active: boolean; onToggle: () => void } | undefined;
|
||||
/** The Inspector's state and toggle; left out where there is no Inspector (Compare). */
|
||||
inspector?: { open: boolean; onToggle: () => void } | undefined;
|
||||
onOpenShortcuts: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* The bottom bar's last button: the page-wide settings that have no place on a canvas. Every row
|
||||
* reads the same way, icon, label, control and key: the Viewer's theme (Auto, Light, Dark; T
|
||||
* flips light and dark), full screen (F), the Inspector (I) and the keyboard shortcuts (?).
|
||||
*/
|
||||
export function MoreMenu(props: MoreMenuProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const listRef = useRef<HTMLDivElement>(null);
|
||||
// The menu opens on the current theme, as a choice menu opens on its current choice.
|
||||
const currentThemeRef = useRef<HTMLButtonElement>(null);
|
||||
const themeLabelId = useId();
|
||||
const close = useCallback(() => setOpen(false), []);
|
||||
|
||||
// ↑ and ↓ move between rows (the theme row's stop is its current choice), ← and → between the
|
||||
// three themes. Tab leaves the menu, as it does a native one. The menu's keys are its own: Esc
|
||||
// and the arrows are marked used, so a canvas behind it (Compare's screens and areas) leaves them.
|
||||
// ? opens the shortcuts as the row does, so the dialog hands focus back to More.
|
||||
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
||||
const list = listRef.current;
|
||||
if (!list) return;
|
||||
if (event.key === "Tab") {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (event.key === "?" && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
||||
event.preventDefault();
|
||||
close();
|
||||
props.onOpenShortcuts();
|
||||
return;
|
||||
}
|
||||
const active = document.activeElement as HTMLElement | null;
|
||||
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
||||
event.preventDefault();
|
||||
const radios = [...list.querySelectorAll<HTMLElement>('[role="menuitemradio"]')];
|
||||
const at = active ? radios.indexOf(active) : -1;
|
||||
if (at < 0) return;
|
||||
radios[(at + (event.key === "ArrowRight" ? 1 : -1) + radios.length) % radios.length]?.focus();
|
||||
return;
|
||||
}
|
||||
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
|
||||
event.preventDefault();
|
||||
const rows = [...list.querySelectorAll<HTMLElement>("[data-more-row]")];
|
||||
if (rows.length === 0) return;
|
||||
const at = rows.findIndex((row) => active && row.contains(active));
|
||||
const next = event.key === "Home" ? 0
|
||||
: event.key === "End" ? rows.length - 1
|
||||
: (Math.max(at, event.key === "ArrowDown" ? -1 : 0) + (event.key === "ArrowDown" ? 1 : -1) + rows.length) % rows.length;
|
||||
const row = rows[next];
|
||||
const stop = row?.matches('[role="menuitem"], [role="menuitemcheckbox"]') ? row
|
||||
: row?.querySelector<HTMLElement>('[aria-checked="true"]') ?? row?.querySelector<HTMLElement>('[role="menuitemradio"]');
|
||||
stop?.focus();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Tooltip label="More" placement="top" disabled={open}>
|
||||
<button
|
||||
ref={buttonRef}
|
||||
type="button"
|
||||
className={`toolbar-button${open ? " active" : ""}`}
|
||||
aria-label="More"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={open}
|
||||
onClick={() => setOpen((current) => !current)}>
|
||||
<Ellipsis />
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Menu open={open} anchorRef={buttonRef} initialFocusRef={currentThemeRef} align="end" className="more-menu" onDismiss={close}>
|
||||
<div ref={listRef} className="more-menu-list" role="menu" aria-label="More" onKeyDown={onKeyDown}>
|
||||
<div className="more-menu-row" role="group" aria-labelledby={themeLabelId} data-more-row>
|
||||
<span className="more-menu-icon" aria-hidden="true"><Moon /></span>
|
||||
<span className="more-menu-label" id={themeLabelId}>Theme</span>
|
||||
<span className="more-theme-switch">
|
||||
{THEME_OPTIONS.map((option) => {
|
||||
const checked = props.themePreference === option.id;
|
||||
return (
|
||||
<button
|
||||
key={option.id}
|
||||
ref={checked ? currentThemeRef : undefined}
|
||||
type="button"
|
||||
className="more-theme-option"
|
||||
role="menuitemradio"
|
||||
aria-checked={checked}
|
||||
aria-label={option.label}
|
||||
title={option.title}
|
||||
tabIndex={-1}
|
||||
onClick={() => props.onChangeTheme(option.id)}>
|
||||
{option.icon}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
<kbd className="more-menu-key" aria-hidden="true">{formatShortcut(SHORTCUTS.appearance.theme)}</kbd>
|
||||
</div>
|
||||
{props.fullscreen ? (
|
||||
<button
|
||||
type="button"
|
||||
className="more-menu-row more-menu-item"
|
||||
role="menuitem"
|
||||
tabIndex={-1}
|
||||
aria-keyshortcuts={SHORTCUTS.view.fullscreen.key}
|
||||
data-more-row
|
||||
onClick={() => {
|
||||
props.fullscreen?.onToggle();
|
||||
close();
|
||||
}}>
|
||||
<span className="more-menu-icon" aria-hidden="true">{props.fullscreen.active ? <Minimize /> : <Maximize />}</span>
|
||||
<span className="more-menu-label">{props.fullscreen.active ? "Exit full screen" : "Full screen"}</span>
|
||||
<kbd className="more-menu-key" aria-hidden="true">{formatShortcut(SHORTCUTS.view.fullscreen)}</kbd>
|
||||
</button>
|
||||
) : null}
|
||||
{props.inspector ? (
|
||||
<button
|
||||
type="button"
|
||||
className="more-menu-row more-menu-item"
|
||||
role="menuitemcheckbox"
|
||||
aria-checked={props.inspector.open}
|
||||
tabIndex={-1}
|
||||
aria-keyshortcuts={SHORTCUTS.panel.right.key}
|
||||
data-more-row
|
||||
onClick={() => {
|
||||
props.inspector?.onToggle();
|
||||
close();
|
||||
}}>
|
||||
<span className="more-menu-icon" aria-hidden="true"><PanelRight /></span>
|
||||
<span className="more-menu-label">Inspector</span>
|
||||
{props.inspector.open ? <span className="more-menu-check" aria-hidden="true"><Check /></span> : null}
|
||||
<kbd className="more-menu-key" aria-hidden="true">{formatShortcut(SHORTCUTS.panel.right)}</kbd>
|
||||
</button>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
className="more-menu-row more-menu-item"
|
||||
role="menuitem"
|
||||
tabIndex={-1}
|
||||
aria-haspopup="dialog"
|
||||
aria-keyshortcuts="?"
|
||||
data-more-row
|
||||
onClick={() => {
|
||||
close();
|
||||
props.onOpenShortcuts();
|
||||
}}>
|
||||
<span className="more-menu-icon" aria-hidden="true"><Keyboard /></span>
|
||||
<span className="more-menu-label">Keyboard shortcuts</span>
|
||||
<kbd className="more-menu-key" aria-hidden="true">?</kbd>
|
||||
</button>
|
||||
</div>
|
||||
</Menu>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -31,8 +31,8 @@ export type ScreenScreenshotCardProps = {
|
||||
loading?: "eager" | "lazy";
|
||||
leading?: ReactNode;
|
||||
trailing?: ReactNode;
|
||||
/** Where the "Open in Inspector" tooltip sits: away from the route heading, which is above the screenshot on the Map. */
|
||||
tooltipPlacement?: "top" | "bottom";
|
||||
/** Say "Open in Inspector" in a tooltip over the screenshot (Screens). The Map's cards go without. */
|
||||
inspectorTooltip?: boolean;
|
||||
/** Short lines about the screen, inside the card after its screenshot (Screens: how it was reached, where else it changed). */
|
||||
note?: ReactNode;
|
||||
onClick: MouseEventHandler<HTMLButtonElement>;
|
||||
@@ -92,10 +92,10 @@ export function ScreenScreenshotCard(props: ScreenScreenshotCardProps) {
|
||||
free of block children. */}
|
||||
<span className="screen-screenshot-slot">
|
||||
{props.leading}
|
||||
{/* With a pointer, what a click does is said once, zoom-independent, in the shared tooltip
|
||||
after its usual delay; the selected screen is already in the Inspector. The button has
|
||||
no title of its own, so no native tooltip joins it; the heading names the screen. */}
|
||||
<Tooltip label="Open in Inspector" placement={props.tooltipPlacement ?? "top"} disabled={Boolean(props.selected)}>
|
||||
{/* On Screens, with a pointer, what a click does is said once in the shared tooltip after
|
||||
its usual delay; the selected screen is already in the Inspector. The button has no
|
||||
title of its own, so no native tooltip joins it; the heading names the screen. */}
|
||||
<Tooltip label="Open in Inspector" placement="top" disabled={props.inspectorTooltip === false || Boolean(props.selected)}>
|
||||
<button
|
||||
type="button"
|
||||
className="screen-screenshot-target"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { GitCompareArrows, Keyboard, LayoutGrid, Map, Search } from "lucide-react";
|
||||
import { type CSSProperties } from "react";
|
||||
import { GitCompareArrows, LayoutGrid, Map, Search } from "lucide-react";
|
||||
import { type CSSProperties, useLayoutEffect, useState } from "react";
|
||||
import { Tooltip } from "../shared/tooltip";
|
||||
import { useCanvasVisibleFrame } from "./visible-frame-provider";
|
||||
import { setToolbarRoom } from "../../utils/inspector-width";
|
||||
import { CANVAS_NUMBER_KEYS, formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
|
||||
import { KeyHint } from "../shared/key-hint";
|
||||
import {
|
||||
@@ -26,23 +27,59 @@ type CanvasToolbarProps = {
|
||||
actions?: React.ReactNode;
|
||||
onSelectCanvas: (canvas: CanvasView) => void;
|
||||
onOpenSearch: () => void;
|
||||
onOpenShortcuts: () => void;
|
||||
/** The bar's last button: the "More" menu with theme, full screen and keyboard shortcuts. */
|
||||
more: React.ReactNode;
|
||||
};
|
||||
|
||||
/** Room kept between the toolbar and an Inspector wide enough to reach it. */
|
||||
const TOOLBAR_PANEL_GAP = 12;
|
||||
|
||||
export function CanvasToolbar(props: CanvasToolbarProps) {
|
||||
const { visibleFrame } = useCanvasVisibleFrame();
|
||||
// The bar as mounted now: it unmounts while hidden, and its last width is kept for deciding when
|
||||
// it fits again.
|
||||
const [element, setElement] = useState<HTMLDivElement | null>(null);
|
||||
const [ownWidth, setOwnWidth] = useState(0);
|
||||
useLayoutEffect(() => {
|
||||
if (!element) return;
|
||||
const measure = () => setOwnWidth(element.getBoundingClientRect().width);
|
||||
measure();
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(element);
|
||||
return () => observer.disconnect();
|
||||
}, [element]);
|
||||
// The Inspector stops short of covering the bar: it may widen only as far as leaves the canvas
|
||||
// room for the bar and a gap either side.
|
||||
useLayoutEffect(() => {
|
||||
if (ownWidth > 0) setToolbarRoom(ownWidth + 2 * TOOLBAR_PANEL_GAP);
|
||||
}, [ownWidth]);
|
||||
// When responsive panels leave less room than the toolbar itself, hiding it is the only
|
||||
// collision-free layout. It returns as soon as either panel is collapsed.
|
||||
// collision-free layout. It returns as soon as either panel is collapsed. The Inspector's width is
|
||||
// capped to leave the bar its room, so this is a last resort: a desktop window (820px and up)
|
||||
// always fits the bar beside the narrowest Inspector.
|
||||
if (visibleFrame && visibleFrame.width < TOOLBAR_MINIMUM_FRAME_WIDTH) return null;
|
||||
// The toolbar is the canvas' persistent mode switcher. Panel geometry may raise it to avoid
|
||||
// bottom chrome, but must not pull it away from the window's stable horizontal centre.
|
||||
// bottom chrome, but must not pull it away from the window's stable horizontal centre. Only an
|
||||
// Inspector that would cover it (widened by the reader, or a narrow window's overlay) pushes it
|
||||
// left, and by just that much, never past the canvas' left edge: with no room left between the
|
||||
// two, it hides as it does above, which the Inspector's cap keeps from happening.
|
||||
let shift = 0;
|
||||
if (visibleFrame && typeof window !== "undefined") {
|
||||
const centredLeft = window.innerWidth / 2 - ownWidth / 2;
|
||||
const needed = centredLeft + ownWidth + TOOLBAR_PANEL_GAP - (visibleFrame.x + visibleFrame.width);
|
||||
const room = centredLeft - (visibleFrame.x + TOOLBAR_PANEL_GAP);
|
||||
if (needed > 0 && needed > room) return null;
|
||||
shift = Math.max(0, needed);
|
||||
}
|
||||
const style = visibleFrame ? ({
|
||||
"--canvas-visible-bottom-inset": `calc(100% - ${visibleFrame.y + visibleFrame.height}px)`,
|
||||
"--canvas-toolbar-shift": `${shift}px`,
|
||||
} as CSSProperties) : undefined;
|
||||
const views = CANVAS_VIEW_ORDER;
|
||||
|
||||
return (
|
||||
<div className="canvas-toolbar" role="toolbar" aria-label="Canvas tools" style={style}>
|
||||
<div ref={setElement} className="canvas-toolbar" role="toolbar" aria-label="Canvas tools" style={style}>
|
||||
{/* The contents grow with --ui-scale; the bar itself keeps its exact place. */}
|
||||
<div className="canvas-toolbar-inner">
|
||||
<div className="toolbar-group" role="group" aria-label="Canvas actions">
|
||||
@@ -96,12 +133,7 @@ export function CanvasToolbar(props: CanvasToolbarProps) {
|
||||
|
||||
|
||||
<span className="toolbar-divider" aria-hidden="true" />
|
||||
<Tooltip label="Keyboard shortcuts" shortcut="?" placement="top">
|
||||
<button type="button" className="toolbar-button" aria-label="Keyboard shortcuts"
|
||||
aria-haspopup="dialog" onClick={props.onOpenShortcuts}>
|
||||
<Keyboard />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{props.more}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -12,7 +12,8 @@ export type TransitionEdgeData = {
|
||||
transitionCount: number;
|
||||
active: boolean;
|
||||
primary: boolean;
|
||||
dimmed: boolean;
|
||||
/** Another screen is selected: the edge steps back to a hairline, so the selection's own stand out. */
|
||||
quiet: boolean;
|
||||
sourceOnly?: boolean;
|
||||
previousSource?: boolean;
|
||||
tooltip?: string;
|
||||
@@ -39,9 +40,10 @@ export function TransitionEdge(props: EdgeProps<TransitionGraphEdge>) {
|
||||
curvature: 0.24,
|
||||
});
|
||||
const emphasized = Boolean(props.data?.active || props.selected || hovered);
|
||||
const dimmed = Boolean(props.data?.dimmed && !emphasized);
|
||||
const quiet = Boolean(props.data?.quiet && !emphasized);
|
||||
const stroke = emphasized
|
||||
? "var(--accent)"
|
||||
: quiet ? "var(--border-subtle)"
|
||||
: props.data?.previousSource ? "var(--danger)" : props.data?.primary ? "var(--graph-line)" : "var(--graph-line-soft)";
|
||||
|
||||
return (
|
||||
@@ -66,9 +68,8 @@ export function TransitionEdge(props: EdgeProps<TransitionGraphEdge>) {
|
||||
style={{
|
||||
...props.style,
|
||||
stroke,
|
||||
strokeWidth: emphasized ? 2.2 : props.data?.primary ? 1.15 : 0.9,
|
||||
strokeWidth: emphasized ? 2.5 : quiet ? 1 : props.data?.primary ? 1.15 : 0.9,
|
||||
strokeDasharray: props.data?.sourceOnly ? "6 5" : emphasized || props.data?.primary ? undefined : "4 7",
|
||||
opacity: dimmed ? 0.12 : 1,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -107,6 +107,13 @@ export function ZoomBridge(props: {
|
||||
publishZoom(Math.round(zoom * 100) / 100);
|
||||
}, [props.cameraReady, zoom]);
|
||||
|
||||
// What a stroke that must stay legible at any zoom divides by (the Map's selection ring). It
|
||||
// moves in quarter-octave steps, so a pinch restyles the canvas a few times, not every frame.
|
||||
const strokeZoom = 2 ** (Math.round(Math.log2(zoom) * 4) / 4);
|
||||
useEffect(() => {
|
||||
canvas?.style.setProperty("--canvas-zoom", String(strokeZoom));
|
||||
}, [canvas, strokeZoom]);
|
||||
|
||||
useEffect(() => {
|
||||
// Re-registering after selection changes publishes the new capability to the zoom menu.
|
||||
// Reading through getNodes keeps the commands themselves on the latest canvas snapshot.
|
||||
|
||||
@@ -490,9 +490,9 @@
|
||||
the size a changed screen's is. */
|
||||
.sidebar-review-off .variant-preview.has-image-ratio { width: min(100%, calc(70dvh * var(--preview-aspect))); }
|
||||
.sidebar-review-stage {
|
||||
/* Two frames and a 12px gap share the panel's width. One frame takes the whole width, up to
|
||||
most of the window's height. */
|
||||
--compare-frame-height: calc((100cqw - 12px) / 2 / var(--compare-aspect));
|
||||
/* Two frames and a 12px gap share the panel's width, up to most of the window's height (a wide
|
||||
panel would otherwise push What changed below the fold). One frame takes the whole width. */
|
||||
--compare-frame-height: min(calc((100cqw - 12px) / 2 / var(--compare-aspect)), 70dvh);
|
||||
gap: 12px;
|
||||
}
|
||||
.sidebar-review-stage.mode-swipe,
|
||||
|
||||
@@ -468,6 +468,10 @@ export function CompareStage(props: StageProps) {
|
||||
const { diff } = props;
|
||||
const before = diff.beforeScreenshot;
|
||||
const after = diff.afterScreenshot;
|
||||
const [hoverIndex, setHoverIndex] = useState<number>();
|
||||
// An outline taken out from under the pointer reports no leave, so another screen, mode or outline
|
||||
// toggle drops the hover rather than lighting an area the pointer is not on.
|
||||
useLayoutEffect(() => setHoverIndex(undefined), [props.areas, props.mode, props.showOutlines]);
|
||||
if (!before && !after) {
|
||||
const reason = diff.captureNotes?.after ?? diff.captureNotes?.before;
|
||||
return (
|
||||
@@ -556,6 +560,21 @@ export function CompareStage(props: StageProps) {
|
||||
const sides = (["before", "after"] as const).filter((side) => (
|
||||
side === "before" ? diff.status !== "added" : diff.status !== "removed"
|
||||
));
|
||||
// Split outlines the changed areas on After, where the eye lands; Before keeps the same outlines
|
||||
// unseen, and shows one while its twin on After is hovered or the area is selected (J, K). A moved area keeps
|
||||
// its outline on Before, where its content was.
|
||||
// One frame, or no outlines, takes the caller's overlay as the other modes do.
|
||||
const paired = Boolean(before && after) && props.showOutlines && props.areas.length > 0;
|
||||
const sideOverlay = (side: "before" | "after"): ReactNode => {
|
||||
if (!paired) return props.overlay;
|
||||
return (
|
||||
<>
|
||||
<ChangeOutlines changes={props.areas} activeIndex={props.activeArea} hoverIndex={hoverIndex}
|
||||
reveal={side === "after" ? "linked" : "ghost"} onHover={side === "after" ? setHoverIndex : undefined} />
|
||||
<SystemRegionBands regions={props.systemRegions} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
{sides.map((side) => {
|
||||
@@ -574,7 +593,7 @@ export function CompareStage(props: StageProps) {
|
||||
) : (
|
||||
<ScreenshotPlaceholder label={placeholderFor(side, diff.status, diff.captureNotes)} />
|
||||
)}
|
||||
{src ? props.overlay : null}
|
||||
{src ? sideOverlay(side) : null}
|
||||
</div>
|
||||
{props.labels === "inside" ? (
|
||||
<span className={`compare-side-label compare-side-tag ${side}`}>{label}{note}</span>
|
||||
|
||||
@@ -19,6 +19,8 @@ export type ShortcutContext = {
|
||||
handoff?: boolean;
|
||||
/** The report was captured in both light and dark, so the app's appearance can be switched. */
|
||||
appearances?: boolean;
|
||||
/** The browser can put the Viewer in full screen. */
|
||||
fullscreen?: boolean;
|
||||
/** The run's other targets are one switch away; the pill calls them devices, or platforms in reports from before targets. */
|
||||
targets?: { noun: "device" | "platform"; count: number };
|
||||
};
|
||||
@@ -94,6 +96,7 @@ export function shortcutGroups(context: ShortcutContext): Group[][] {
|
||||
...(context.canvas === "compare" ? [] : [{ label: "Show or hide the inspector", keys: [SHORTCUTS.panel.right] }]),
|
||||
{ label: "Viewer theme: dark or light", keys: [SHORTCUTS.appearance.theme] },
|
||||
...(context.appearances ? [{ label: "The app's appearance: light or dark", keys: [SHORTCUTS.appearance.app] }] : []),
|
||||
...(context.fullscreen ? [{ label: "Enter or exit full screen", keys: [SHORTCUTS.view.fullscreen] }] : []),
|
||||
{ label: "Show this list", keys: ["?"] },
|
||||
],
|
||||
};
|
||||
@@ -119,7 +122,7 @@ export function shortcutGroups(context: ShortcutContext): Group[][] {
|
||||
return [here, [goTo, view]];
|
||||
}
|
||||
|
||||
/** The keyboard reference, opened with "?" or the button at the end of the bottom bar. */
|
||||
/** The keyboard reference, opened with "?" or from the More menu at the end of the bottom bar. */
|
||||
export function ShortcutsDialog(props: { context: ShortcutContext; onClose: () => void }) {
|
||||
const dialogRef = useModalDialog(true, props.onClose);
|
||||
useEffect(() => {
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
import {
|
||||
useCallback, useRef, useSyncExternalStore, type CSSProperties, type KeyboardEvent, type PointerEvent, type RefObject,
|
||||
} from "react";
|
||||
import {
|
||||
clampInspectorWidth, getToolbarRoom, inspectorWidthBounds, INSPECTOR_WIDTH_MAX, INSPECTOR_WIDTH_MIN, INSPECTOR_WIDTH_STEP,
|
||||
setInspectorWidth, subscribeToToolbarRoom, useInspectorWidth,
|
||||
type InspectorWidthBounds,
|
||||
} from "../../utils/inspector-width";
|
||||
|
||||
/** On the root while the edge is dragged, so the whole page keeps the resize cursor and selects nothing. */
|
||||
const RESIZING_CLASS = "inspector-resizing";
|
||||
|
||||
/** The chrome's zoom (`--ui-scale`): pointer distances are in window pixels, the panel's width in its own. */
|
||||
function uiScale(): number {
|
||||
const raw = parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--ui-scale"));
|
||||
return Number.isFinite(raw) && raw > 0 ? raw : 1;
|
||||
}
|
||||
|
||||
/** The panel's width in its own pixels: the reader's, else the stylesheet's default for this window. */
|
||||
function panelWidth(panel: HTMLElement): number {
|
||||
return parseFloat(getComputedStyle(panel).width) || 0;
|
||||
}
|
||||
|
||||
function defaultWidth(): number {
|
||||
return window.matchMedia("(max-width: 1180px)").matches ? 320 : 400;
|
||||
}
|
||||
|
||||
/** The panel's widest and default widths follow the window (and `--ui-scale`, which follows it too). */
|
||||
function subscribeToWindow(onChange: () => void): () => void {
|
||||
window.addEventListener("resize", onChange);
|
||||
return () => window.removeEventListener("resize", onChange);
|
||||
}
|
||||
|
||||
/** The widest the panel can be now: it follows the window, `--ui-scale` and the bottom bar's width. */
|
||||
function currentBounds(): InspectorWidthBounds {
|
||||
return inspectorWidthBounds(window.innerWidth, uiScale(), getToolbarRoom());
|
||||
}
|
||||
|
||||
function subscribeToBounds(onChange: () => void): () => void {
|
||||
const unsubscribeToolbar = subscribeToToolbarRoom(onChange);
|
||||
const unsubscribeWindow = subscribeToWindow(onChange);
|
||||
return () => {
|
||||
unsubscribeToolbar();
|
||||
unsubscribeWindow();
|
||||
};
|
||||
}
|
||||
|
||||
function widestWidth(): number {
|
||||
return currentBounds().max;
|
||||
}
|
||||
|
||||
type Drag = {
|
||||
pointerId: number;
|
||||
startX: number;
|
||||
startWidth: number;
|
||||
scale: number;
|
||||
bounds: InspectorWidthBounds;
|
||||
last: number;
|
||||
/** The panel's own `--inspector-width` before the drag, put back when the drag changes nothing. */
|
||||
inline: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes the Inspector's left edge a splitter. A drag moves the edge live (the width is written to
|
||||
* the panel's `--inspector-width` directly, so nothing re-renders per pointer move) and is kept
|
||||
* when the pointer lifts; arrow keys move it a step; Home and End take it to its narrowest and
|
||||
* widest; a double-click returns it to the default.
|
||||
*/
|
||||
export function useInspectorResize(panelRef: RefObject<HTMLElement | null>) {
|
||||
const width = useInspectorWidth();
|
||||
const widest = useSyncExternalStore(subscribeToBounds, widestWidth, () => INSPECTOR_WIDTH_MAX);
|
||||
const fallback = useSyncExternalStore(subscribeToWindow, defaultWidth, () => 400);
|
||||
const drag = useRef<Drag | null>(null);
|
||||
|
||||
// Every way a drag can stop ends here, once: the pointer lifting, the browser taking the pointer
|
||||
// back, the window losing focus, or the edge itself going away (the Inspector closed mid-drag).
|
||||
const endDrag = useCallback(() => {
|
||||
const state = drag.current;
|
||||
if (!state) return;
|
||||
drag.current = null;
|
||||
document.documentElement.classList.remove(RESIZING_CLASS);
|
||||
if (state.last !== state.startWidth) {
|
||||
setInspectorWidth(state.last);
|
||||
return;
|
||||
}
|
||||
// Nothing changed, so nothing re-renders to replace the width the drag wrote.
|
||||
const panel = panelRef.current;
|
||||
if (!panel) return;
|
||||
if (state.inline) panel.style.setProperty("--inspector-width", state.inline);
|
||||
else panel.style.removeProperty("--inspector-width");
|
||||
}, [panelRef]);
|
||||
|
||||
const handleRef = useCallback((element: HTMLElement | null) => {
|
||||
if (!element) return;
|
||||
window.addEventListener("blur", endDrag);
|
||||
return () => {
|
||||
window.removeEventListener("blur", endDrag);
|
||||
endDrag();
|
||||
};
|
||||
}, [endDrag]);
|
||||
|
||||
const onPointerDown = (event: PointerEvent<HTMLElement>) => {
|
||||
const panel = panelRef.current;
|
||||
if (event.button !== 0 || !panel) return;
|
||||
const scale = uiScale();
|
||||
const startWidth = panelWidth(panel);
|
||||
drag.current = {
|
||||
pointerId: event.pointerId, startX: event.clientX, startWidth, scale,
|
||||
bounds: currentBounds(), last: startWidth,
|
||||
inline: panel.style.getPropertyValue("--inspector-width"),
|
||||
};
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
document.documentElement.classList.add(RESIZING_CLASS);
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
const onPointerMove = (event: PointerEvent<HTMLElement>) => {
|
||||
const state = drag.current;
|
||||
const panel = panelRef.current;
|
||||
if (!state || state.pointerId !== event.pointerId || !panel) return;
|
||||
// A release the handle never heard about.
|
||||
if (event.buttons === 0) {
|
||||
endDrag();
|
||||
return;
|
||||
}
|
||||
// The edge is on the left: moving the pointer left widens the panel.
|
||||
const next = clampInspectorWidth(state.startWidth + (state.startX - event.clientX) / state.scale, state.bounds);
|
||||
if (next === state.last) return;
|
||||
state.last = next;
|
||||
panel.style.setProperty("--inspector-width", `${next}px`);
|
||||
};
|
||||
|
||||
const onPointerEnd = (event: PointerEvent<HTMLElement>) => {
|
||||
const state = drag.current;
|
||||
if (!state || state.pointerId !== event.pointerId) return;
|
||||
if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
|
||||
endDrag();
|
||||
};
|
||||
|
||||
const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {
|
||||
const panel = panelRef.current;
|
||||
if (!panel) return;
|
||||
const bounds = currentBounds();
|
||||
const current = panelWidth(panel);
|
||||
let next: number;
|
||||
switch (event.key) {
|
||||
case "ArrowLeft": next = current + INSPECTOR_WIDTH_STEP; break;
|
||||
case "ArrowRight": next = current - INSPECTOR_WIDTH_STEP; break;
|
||||
case "Home": next = bounds.min; break;
|
||||
case "End": next = bounds.max; break;
|
||||
default: return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
// A key that cannot move the edge (End at a smaller window's cap) keeps the saved width.
|
||||
next = clampInspectorWidth(next, bounds);
|
||||
if (next !== Math.round(current)) setInspectorWidth(next);
|
||||
};
|
||||
|
||||
// The saved width is the reader's preference; the panel takes as much of it as this window allows.
|
||||
const bounds = { min: INSPECTOR_WIDTH_MIN, max: widest };
|
||||
const shown = width === undefined ? undefined : clampInspectorWidth(width, bounds);
|
||||
const style = (shown === undefined ? undefined : { "--inspector-width": `${shown}px` }) as CSSProperties | undefined;
|
||||
const handleProps = {
|
||||
role: "separator",
|
||||
"aria-orientation": "vertical",
|
||||
"aria-label": "Resize inspector",
|
||||
"aria-valuemin": bounds.min,
|
||||
"aria-valuemax": bounds.max,
|
||||
"aria-valuenow": shown ?? fallback,
|
||||
title: "Drag to resize. Double-click to reset.",
|
||||
tabIndex: 0,
|
||||
ref: handleRef,
|
||||
onPointerDown,
|
||||
onPointerMove,
|
||||
onPointerUp: onPointerEnd,
|
||||
onPointerCancel: onPointerEnd,
|
||||
onLostPointerCapture: endDrag,
|
||||
onKeyDown,
|
||||
onDoubleClick: () => setInspectorWidth(undefined),
|
||||
} as const;
|
||||
return { style, handleProps };
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { GitCompareArrows, PanelRight, ScanSearch, X } from "lucide-react";
|
||||
import { GitCompareArrows, ScanSearch, X } from "lucide-react";
|
||||
import { Tooltip } from "../shared/tooltip";
|
||||
import { formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
|
||||
import { InspectorPanel } from "./inspector";
|
||||
@@ -14,6 +14,7 @@ import { setOutlinesShown, useOutlinesShown } from "../compare/compare-section";
|
||||
import { AutoHideScrollArea } from "../shared/auto-hide-scroll-area";
|
||||
import { usePhoneLayout } from "../../utils/phone-layout";
|
||||
import { useDragToDismiss } from "../phone/phone-chrome";
|
||||
import { useInspectorResize } from "./inspector-resize";
|
||||
|
||||
type RightPanelProps = {
|
||||
index: MapIndex;
|
||||
@@ -36,6 +37,9 @@ export function RightPanel(props: RightPanelProps) {
|
||||
// On a phone the panel is a bottom sheet; dragging its header down closes it.
|
||||
const phone = usePhoneLayout();
|
||||
const drag = useDragToDismiss(props.onToggleCollapsed);
|
||||
// On a desktop its left edge is a splitter; the sheet keeps the window's width.
|
||||
const panelRef = useRef<HTMLElement>(null);
|
||||
const resize = useInspectorResize(panelRef);
|
||||
const selectedPath = props.screen ? displayPathForScreen(props.screen) : undefined;
|
||||
const screenDiff = props.screen ? props.diff?.screens.get(props.screen.id) : undefined;
|
||||
// Compare opens only a screen it reviews: a changed screen in the review order, not a state
|
||||
@@ -55,36 +59,28 @@ export function RightPanel(props: RightPanelProps) {
|
||||
if (scrollRef.current) scrollRef.current.scrollTop = 0;
|
||||
}, [screenId]);
|
||||
|
||||
// Collapsed, the panel icon brings the Inspector back; open, an X closes it.
|
||||
// Closed, the Inspector leaves no button behind: a selection, Return or I opens it. Open, an X
|
||||
// closes it.
|
||||
if (props.collapsed) return null;
|
||||
const panelButton = (
|
||||
<Tooltip
|
||||
label={props.collapsed ? "Expand inspector" : "Close inspector"}
|
||||
shortcut={formatShortcut(SHORTCUTS.panel.right)}
|
||||
placement="bottom-end">
|
||||
<Tooltip label="Close inspector" shortcut={formatShortcut(SHORTCUTS.panel.right)} placement="bottom-end">
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button"
|
||||
aria-label={props.collapsed ? "Expand inspector" : "Close inspector"}
|
||||
aria-expanded={!props.collapsed}
|
||||
aria-label="Close inspector"
|
||||
aria-expanded
|
||||
onClick={props.onToggleCollapsed}>
|
||||
{props.collapsed ? <PanelRight aria-hidden="true" /> : <X aria-hidden="true" />}
|
||||
<X aria-hidden="true" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
if (props.collapsed) {
|
||||
return (
|
||||
<div className="right-float" role="toolbar" aria-label="Canvas actions">
|
||||
{panelButton}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// One header row: the screen's status and path, then the close button. On a phone the close
|
||||
// button leads the row instead, away from the screen stepper's arrows. Theme and full screen
|
||||
// live in the canvas camera controls.
|
||||
// live in the bottom bar's "More" menu.
|
||||
return (
|
||||
<aside className="right-panel" data-drag-sheet aria-label="Inspector panel">
|
||||
<aside ref={panelRef} className="right-panel" data-drag-sheet aria-label="Inspector panel" style={phone ? undefined : resize.style}>
|
||||
{phone ? null : <div className="right-panel-resize" {...resize.handleProps} />}
|
||||
<header className="right-head" {...(phone ? drag : {})}>
|
||||
{phone ? <span className="right-sheet-grabber" aria-hidden="true" /> : null}
|
||||
{phone ? panelButton : null}
|
||||
|
||||
@@ -1,25 +1,18 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Maximize, Minimize, Moon, Sun, SunMoon } from "lucide-react";
|
||||
import { Tooltip } from "../shared/tooltip";
|
||||
import { formatShortcut, SHORTCUTS } from "../../utils/shortcuts";
|
||||
import type { ThemePreference } from "../../utils/navigation";
|
||||
|
||||
export type ShellTheme = "light" | "dark";
|
||||
|
||||
export type ShellActionsProps = {
|
||||
/** The theme on screen: the preference, or the system's when that is Auto. */
|
||||
theme: ShellTheme;
|
||||
themePreference: ThemePreference;
|
||||
/** Steps Auto → Dark → Light → Auto. */
|
||||
onToggleTheme: () => void;
|
||||
/** The host toolbar's button class, so the actions match their neighbours. */
|
||||
className?: string;
|
||||
};
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
function fullscreenActive(): boolean {
|
||||
return typeof document !== "undefined" && document.fullscreenElement !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this browser can put the page in full screen at all: iPhone Safari has no element full
|
||||
* screen, and a frame that was not allowed it (an embedded Viewer) refuses every request.
|
||||
*/
|
||||
export function fullscreenSupported(): boolean {
|
||||
return typeof document !== "undefined" && typeof document.documentElement.requestFullscreen === "function"
|
||||
&& document.fullscreenEnabled !== false;
|
||||
}
|
||||
|
||||
/** Tracks the page-level fullscreen state, including exits triggered by the browser itself. */
|
||||
export function useFullscreen(): [boolean, () => void] {
|
||||
const [active, setActive] = useState(fullscreenActive);
|
||||
@@ -30,54 +23,14 @@ export function useFullscreen(): [boolean, () => void] {
|
||||
return () => document.removeEventListener("fullscreenchange", sync);
|
||||
}, []);
|
||||
|
||||
const toggle = () => {
|
||||
const toggle = useCallback(() => {
|
||||
if (document.fullscreenElement) {
|
||||
void document.exitFullscreen().catch(() => {});
|
||||
return;
|
||||
}
|
||||
if (typeof document.documentElement.requestFullscreen !== "function") return;
|
||||
if (!fullscreenSupported()) return;
|
||||
void document.documentElement.requestFullscreen().catch(() => {});
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [active, toggle];
|
||||
}
|
||||
|
||||
const THEME_LABELS: Record<ThemePreference, string> = {
|
||||
system: "Theme: Auto (system)",
|
||||
dark: "Theme: Dark",
|
||||
light: "Theme: Light",
|
||||
};
|
||||
|
||||
/** The theme button shows the current preference; a press steps Auto → Dark → Light. */
|
||||
export function ThemeToggleButton(props: ShellActionsProps) {
|
||||
const Icon = props.themePreference === "system" ? SunMoon : props.themePreference === "dark" ? Moon : Sun;
|
||||
return (
|
||||
<Tooltip label={THEME_LABELS[props.themePreference]} shortcut={formatShortcut(SHORTCUTS.appearance.theme)} placement="bottom">
|
||||
<button
|
||||
type="button"
|
||||
className={props.className ?? "icon-button"}
|
||||
aria-label="Toggle theme"
|
||||
data-theme-preference={props.themePreference}
|
||||
onClick={props.onToggleTheme}>
|
||||
<Icon aria-hidden="true" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
export function FullscreenToggleButton(props: Pick<ShellActionsProps, "className">) {
|
||||
const [active, toggle] = useFullscreen();
|
||||
const label = active ? "Exit full screen" : "Enter full screen";
|
||||
return (
|
||||
<Tooltip label={label} placement="bottom">
|
||||
<button
|
||||
type="button"
|
||||
className={props.className ?? "icon-button"}
|
||||
aria-label={label}
|
||||
aria-pressed={active}
|
||||
onClick={toggle}>
|
||||
{active ? <Minimize aria-hidden="true" /> : <Maximize aria-hidden="true" />}
|
||||
</button>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
@@ -18,7 +18,20 @@
|
||||
background: color-mix(in srgb, var(--modified) 22%, transparent);
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--modified) 35%, transparent);
|
||||
}
|
||||
.visual-change-outlines.has-active .visual-change-outline:not(.active) { opacity: 0.35; }
|
||||
.visual-change-outlines.has-active .visual-change-outline:not(.active):not(.hovered) { opacity: 0.35; }
|
||||
/* Split's pair: linked outlines (After) take the pointer, and the hovered one reads as the selected one
|
||||
does; ghost outlines (Before) show nothing until their twin is hovered or the area is selected. An area
|
||||
that only moved keeps its outline on Before, where its content was, and a screen without hover (touch)
|
||||
keeps them all, as it has no way to reveal one. */
|
||||
.visual-change-outlines.linked .visual-change-outline { pointer-events: auto; cursor: default; }
|
||||
.visual-change-outline.hovered { background: color-mix(in srgb, var(--modified) 22%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--modified) 35%, transparent); }
|
||||
.visual-change-outline.moved.hovered { background: color-mix(in srgb, var(--moved) 14%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--moved) 30%, transparent); }
|
||||
@media (hover: hover) {
|
||||
.visual-change-outlines.ghost .visual-change-outline:not(.moved) { opacity: 0; transition: opacity 120ms ease, box-shadow 120ms ease, background-color 120ms ease; }
|
||||
.visual-change-outlines.ghost .visual-change-outline.hovered,
|
||||
.visual-change-outlines.ghost .visual-change-outline.active { opacity: 1; }
|
||||
.visual-change-outlines.ghost.has-active .visual-change-outline:not(.active):not(.hovered):not(.moved) { opacity: 0; }
|
||||
}
|
||||
/* An area that only moved: dashed and quiet, in the slate of a measurement rather than the orange of a change. */
|
||||
.visual-change-outline.moved {
|
||||
border: 1.5px dashed var(--moved);
|
||||
|
||||
@@ -15,11 +15,23 @@ import "./visual-diff.css";
|
||||
export function ChangeOutlines(props: {
|
||||
changes: readonly VisualChange[];
|
||||
activeIndex?: number | undefined;
|
||||
/** The outline under the pointer, on this frame or its twin; drawn as the selected one is. */
|
||||
hoverIndex?: number | undefined;
|
||||
/** Reports the outline under the pointer; with it the outlines take the pointer (see `reveal`). */
|
||||
onHover?: ((index: number | undefined) => void) | undefined;
|
||||
/**
|
||||
* How Split pairs its two frames: `linked` outlines (on After) take the pointer and report hovers;
|
||||
* `ghost` ones (on Before) sit at the same places unseen until one is hovered on After or selected; a moved
|
||||
* area's stays, where its content was, and a screen without hover shows them all. Without it every outline
|
||||
* shows, as on a single frame.
|
||||
*/
|
||||
reveal?: "all" | "ghost" | "linked";
|
||||
}) {
|
||||
const measurements = useMeasurementsShown();
|
||||
const reveal = props.reveal ?? "all";
|
||||
return (
|
||||
<span
|
||||
className={`visual-change-outlines${props.activeIndex !== undefined ? " has-active" : ""}`}
|
||||
className={`visual-change-outlines${props.activeIndex !== undefined ? " has-active" : ""}${reveal !== "all" ? ` ${reveal}` : ""}`}
|
||||
aria-hidden="true">
|
||||
{props.changes.map((change, index) => {
|
||||
const rect = outlineRect(change);
|
||||
@@ -29,7 +41,9 @@ export function ChangeOutlines(props: {
|
||||
return (
|
||||
<span
|
||||
key={index}
|
||||
className={`visual-change-outline${change.move ? " moved" : ""}${props.activeIndex === index ? " active" : ""}`}
|
||||
className={`visual-change-outline${change.move ? " moved" : ""}${props.activeIndex === index ? " active" : ""}${props.hoverIndex === index ? " hovered" : ""}`}
|
||||
onPointerEnter={props.onHover ? () => props.onHover!(index) : undefined}
|
||||
onPointerLeave={props.onHover ? () => props.onHover!(undefined) : undefined}
|
||||
style={{
|
||||
left: back(rect.x, change.move?.x),
|
||||
top: back(rect.y, change.move?.y),
|
||||
|
||||
@@ -531,10 +531,10 @@
|
||||
.changes-menu .panel-search-clear { width: 44px; height: 44px; }
|
||||
/* The minimap repeats what a phone already shows whole, and covers a sixth of it. */
|
||||
.phone-layout .canvas-minimap-shell { display: none; }
|
||||
/* With nothing selected there is no Inspector to reopen. */
|
||||
.phone-layout .right-float { display: none; }
|
||||
/* The Inspector slides up over the whole screen; a drag down on its header puts it away. */
|
||||
.phone-layout .right-panel {
|
||||
/* The sheet is the window's width; the desktop's half-window limit is not for it. */
|
||||
max-width: none;
|
||||
position: fixed;
|
||||
z-index: 120;
|
||||
inset: 0;
|
||||
|
||||
@@ -237,12 +237,29 @@ export function Menu({ items = [], children, initialFocusRef, open, ariaLabel, c
|
||||
if (initialFocusRef && event.target instanceof Node
|
||||
&& !popoverRef.current?.contains(event.target) && !anchorRef?.current?.contains(event.target)) dismissRef.current();
|
||||
};
|
||||
// A trigger can also move with no scroll or resize, as the bottom bar does when the Inspector
|
||||
// opens beside it; an anchored menu checks where its trigger is once a frame while it is open.
|
||||
let frame = 0;
|
||||
let anchorAt = "";
|
||||
const follow = () => {
|
||||
const rect = anchorRef?.current?.getBoundingClientRect();
|
||||
const at = rect ? `${rect.left},${rect.top}` : "";
|
||||
if (at !== anchorAt) {
|
||||
if (anchorAt) place();
|
||||
anchorAt = at;
|
||||
}
|
||||
frame = requestAnimationFrame(follow);
|
||||
};
|
||||
window.addEventListener("pointerdown", onPointerDown);
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
window.addEventListener("resize", place);
|
||||
if (anchorRef) window.addEventListener("scroll", onScroll, true);
|
||||
if (anchorRef) {
|
||||
window.addEventListener("scroll", onScroll, true);
|
||||
follow();
|
||||
}
|
||||
window.addEventListener("focusin", onFocusIn);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
window.removeEventListener("pointerdown", onPointerDown);
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
window.removeEventListener("resize", place);
|
||||
|
||||
@@ -31,6 +31,7 @@ import { arrowsOwnedBy, mapKeyDirection, mapKeyEntry, mapKeyTarget, type MapKeyD
|
||||
import { createKeyHold } from "../../utils/key-hold";
|
||||
|
||||
const HOVER_CLEAR_DELAY = 180;
|
||||
const PRESSABLE = 'button, a, summary, [role="button"]';
|
||||
const MAP_LAYOUT_REVISION = "flat-v1";
|
||||
const MAP_FIT_VIEW_OPTIONS = {
|
||||
padding: 0.04,
|
||||
@@ -115,8 +116,8 @@ function ScreenNodeCard({ data, selected }: NodeProps<ScreenGraphNode>) {
|
||||
imageHeight={data.screenshotSize?.imageHeight ?? data.frame.screen.height}
|
||||
placeholderSize={data.frame.screen}
|
||||
loading="lazy"
|
||||
// The route heads the card, so the tooltip goes below it.
|
||||
tooltipPlacement="bottom"
|
||||
// The ring says which screen is which; a click opening it in the Inspector needs no tooltip.
|
||||
inspectorTooltip={false}
|
||||
leading={<Handle type="target" position={horizontal ? Position.Left : Position.Top} className="graph-handle" />}
|
||||
trailing={<Handle type="source" position={horizontal ? Position.Right : Position.Bottom} className="graph-handle" />}
|
||||
onMouseEnter={() => data.onHover(data.screen.id)}
|
||||
@@ -342,8 +343,9 @@ function projectionElements(
|
||||
const edges: TransitionGraphEdge[] = structure.groups.map((group) => {
|
||||
const hierarchyEdge = structure.primaryEdgeKeys.has(group.key);
|
||||
const connected = group.from === selectedScreenId || group.to === selectedScreenId;
|
||||
const dimmed = false;
|
||||
const active = connected;
|
||||
// While a screen is selected, every other transition quiets to a hairline; cards never fade.
|
||||
const quiet = Boolean(selectedScreenId) && !connected;
|
||||
const sourceOnly = group.transitionIds.length === 0 && Boolean(group.sourceEdges?.length);
|
||||
const previousSource = group.sourceRevision === "baseline";
|
||||
const removed = previousSource || (!group.synthetic && diff?.screens.get(group.to)?.status === "removed");
|
||||
@@ -356,25 +358,26 @@ function projectionElements(
|
||||
const primary = hierarchyEdge;
|
||||
const stroke = active
|
||||
? "var(--accent)"
|
||||
: quiet ? "var(--border-subtle)"
|
||||
: removed ? "var(--danger)" : primary ? "var(--graph-line)" : "var(--graph-line-soft)";
|
||||
return {
|
||||
id: edgeElementId(group.key),
|
||||
source: group.from,
|
||||
target: group.to,
|
||||
type: "transition",
|
||||
className: `${hierarchyEdge ? "graph-edge-primary" : "graph-edge-secondary"}${sourceOnly ? " graph-edge-source" : ""}${previousSource ? " graph-edge-source-baseline" : ""}${active ? " graph-edge-active" : ""}${dimmed ? " graph-edge-dimmed" : ""}`,
|
||||
className: `${hierarchyEdge ? "graph-edge-primary" : "graph-edge-secondary"}${sourceOnly ? " graph-edge-source" : ""}${previousSource ? " graph-edge-source-baseline" : ""}${active ? " graph-edge-active" : ""}${quiet ? " graph-edge-quiet" : ""}`,
|
||||
markerEnd: {
|
||||
type: MarkerType.ArrowClosed,
|
||||
width: active || hierarchyEdge ? 14 : 11,
|
||||
height: active || hierarchyEdge ? 14 : 11,
|
||||
width: active || (hierarchyEdge && !quiet) ? 14 : 11,
|
||||
height: active || (hierarchyEdge && !quiet) ? 14 : 11,
|
||||
color: stroke,
|
||||
},
|
||||
style: {
|
||||
stroke,
|
||||
strokeWidth: active ? 2.2 : hierarchyEdge ? 1.15 : 0.9,
|
||||
strokeWidth: active ? 2.5 : quiet ? 1 : hierarchyEdge ? 1.15 : 0.9,
|
||||
strokeDasharray: !hierarchyEdge && !active && !removed ? "4 7" : undefined,
|
||||
},
|
||||
data: { label, transitionCount: group.transitionIds.length, active, primary, dimmed, sourceOnly, previousSource, ...(tooltip ? { tooltip } : {}) },
|
||||
data: { label, transitionCount: group.transitionIds.length, active, primary, quiet, sourceOnly, previousSource, ...(tooltip ? { tooltip } : {}) },
|
||||
// React Flow renders a positive edge z-index above root nodes. Keep every connection in
|
||||
// the base edge layer so selected/highlighted paths still pass behind screen imagery.
|
||||
zIndex: 0,
|
||||
@@ -433,7 +436,7 @@ function sameTransitionEdge(a: TransitionGraphEdge, b: TransitionGraphEdge) {
|
||||
&& a.data?.transitionCount === b.data?.transitionCount
|
||||
&& a.data?.active === b.data?.active
|
||||
&& a.data?.primary === b.data?.primary
|
||||
&& a.data?.dimmed === b.data?.dimmed;
|
||||
&& a.data?.quiet === b.data?.quiet;
|
||||
}
|
||||
|
||||
function reuseUnchangedElements(
|
||||
@@ -557,7 +560,8 @@ function ConnectionCanvas(props: MapViewProps) {
|
||||
}, [applyHover]);
|
||||
// The arrow keys (or h j k l) walk the map from the selected screen: along an edge in the
|
||||
// layout's flow, across to the neighbour on the same rank otherwise. With nothing selected they
|
||||
// enter the map at its edge, as on the Screens page. A held key keeps walking.
|
||||
// enter the map at its edge, as on the Screens page. A held key keeps walking. Return opens the
|
||||
// selection in the Inspector.
|
||||
const { selectedScreenId } = props;
|
||||
const selectedRef = useRef(selectedScreenId);
|
||||
selectedRef.current = selectedScreenId;
|
||||
@@ -568,22 +572,39 @@ function ConnectionCanvas(props: MapViewProps) {
|
||||
if (!structure) return undefined;
|
||||
return from ? mapKeyTarget(structure, from, direction) : mapKeyEntry(structure, direction);
|
||||
};
|
||||
// A click leaves the keyboard focus on the clicked screen's button, where Return would press it
|
||||
// and open that screen again. A walk lets go of it, so Return reaches the screen walked to.
|
||||
const walkTo = (id: string) => {
|
||||
const focused = document.activeElement;
|
||||
if (focused instanceof HTMLElement && surfaceRef.current?.contains(focused)) focused.blur();
|
||||
selectScreen(id);
|
||||
};
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
hold.interrupt(event);
|
||||
if (event.repeat && hold.holding(event.code)) { event.preventDefault(); return; }
|
||||
if (event.defaultPrevented || !shortcutsLive(event) || arrowsOwnedBy(event.target)) return;
|
||||
if (event.key === "Enter") {
|
||||
// A focused button or link keeps its own Return; elsewhere on the page it opens the selection.
|
||||
const target = event.target instanceof Element ? event.target : null;
|
||||
const selected = selectedRef.current;
|
||||
if (!selected || event.isComposing || event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
|
||||
if (target && target !== document.body && (target.closest(PRESSABLE) || !surfaceRef.current?.contains(target))) return;
|
||||
event.preventDefault();
|
||||
selectScreen(selected);
|
||||
return;
|
||||
}
|
||||
const direction = mapKeyDirection(event);
|
||||
if (!direction) return;
|
||||
if (!structureRef.current) return;
|
||||
event.preventDefault();
|
||||
let at = move(direction, selectedRef.current);
|
||||
if (!at) return;
|
||||
selectScreen(at);
|
||||
walkTo(at);
|
||||
hold.begin(event.code, () => {
|
||||
const target = move(direction, at);
|
||||
if (!target) return false;
|
||||
at = target;
|
||||
selectScreen(target);
|
||||
walkTo(target);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
@@ -636,9 +657,6 @@ function ConnectionCanvas(props: MapViewProps) {
|
||||
.sort((left, right) => left.depth - right.depth || left.y - right.y || left.x - right.x || left.index - right.index)
|
||||
.map(({ id }) => id), [layout.nodes]);
|
||||
const phone = usePhoneLayout();
|
||||
const selectedScreenVisible = Boolean(
|
||||
props.selectedScreenId && layout.nodes.some((node) => node.id === props.selectedScreenId),
|
||||
);
|
||||
if (props.map.screens.length === 0) {
|
||||
const blockers = props.map.gaps.filter((gap) => gap.status === "open" && !gap.screenId).map((gap) => gap.message);
|
||||
return (
|
||||
@@ -656,10 +674,7 @@ function ConnectionCanvas(props: MapViewProps) {
|
||||
<div ref={surfaceRef} className="connection-canvas-surface map-surface">
|
||||
<CanvasStage
|
||||
ariaLabel="Screen map"
|
||||
className={[
|
||||
"map-canvas",
|
||||
selectedScreenVisible ? "screen-selection-active" : "",
|
||||
].filter(Boolean).join(" ")}
|
||||
className="map-canvas"
|
||||
nodes={layout.nodes}
|
||||
edges={layout.edges}
|
||||
nodeTypes={NODE_TYPES}
|
||||
|
||||
+152
-108
@@ -110,7 +110,6 @@
|
||||
/* How far an item the Changes filter does not cover falls back. Low enough to read as
|
||||
background at a glance, high enough that the canvas keeps its shape. */
|
||||
--dim-out: 0.35;
|
||||
--hover-neighbour-frame: color-mix(in srgb, var(--accent) 55%, var(--border-subtle));
|
||||
--shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.025), 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
--shadow-md: 0 10px 20px rgba(0, 0, 0, 0.1), 0 3px 6px rgba(0, 0, 0, 0.05);
|
||||
|
||||
@@ -134,13 +133,10 @@
|
||||
--icon-hit-min: 32px;
|
||||
/* Chevrons, carets and status glyphs that sit inline next to text. */
|
||||
--icon-glyph-inline: 14px;
|
||||
/* Floating canvas chrome shares a y=30px center line. The collapsed inspector joins the
|
||||
camera controls into one compact toolbar. Reserve space for the visible actions only. */
|
||||
/* Floating canvas chrome shares a y=30px center line. Reserve space for the visible actions only. */
|
||||
--floating-chrome-top: 14px;
|
||||
--floating-chrome-height: 42px;
|
||||
--canvas-chrome-inline-inset: 12px;
|
||||
--right-float-edge: 12px;
|
||||
--right-float-width: calc(var(--icon-btn-md) + 6px);
|
||||
--left-collapsed-pill-width: 420px;
|
||||
--left-collapsed-pill-height: var(--floating-chrome-height);
|
||||
--left-collapsed-pill-top: var(--floating-chrome-top);
|
||||
@@ -305,16 +301,14 @@ code {
|
||||
}
|
||||
:root[data-canvas-transition-direction]::view-transition-group(app-pill),
|
||||
:root[data-canvas-transition-direction]::view-transition-group(canvas-camera-controls),
|
||||
:root[data-canvas-transition-direction]::view-transition-group(canvas-toolbar),
|
||||
:root[data-canvas-transition-direction]::view-transition-group(right-floating-controls) {
|
||||
:root[data-canvas-transition-direction]::view-transition-group(canvas-toolbar) {
|
||||
z-index: 101;
|
||||
animation: none;
|
||||
}
|
||||
:root[data-canvas-transition-direction]::view-transition-image-pair(canvas-minimap),
|
||||
:root[data-canvas-transition-direction]::view-transition-image-pair(app-pill),
|
||||
:root[data-canvas-transition-direction]::view-transition-image-pair(canvas-camera-controls),
|
||||
:root[data-canvas-transition-direction]::view-transition-image-pair(canvas-toolbar),
|
||||
:root[data-canvas-transition-direction]::view-transition-image-pair(right-floating-controls) {
|
||||
:root[data-canvas-transition-direction]::view-transition-image-pair(canvas-toolbar) {
|
||||
isolation: isolate;
|
||||
}
|
||||
:root[data-canvas-transition-direction]::view-transition-old(canvas-view-content),
|
||||
@@ -326,9 +320,7 @@ code {
|
||||
:root[data-canvas-transition-direction]::view-transition-old(canvas-toolbar),
|
||||
:root[data-canvas-transition-direction]::view-transition-old(phone-top-actions),
|
||||
:root[data-canvas-transition-direction]::view-transition-new(canvas-toolbar),
|
||||
:root[data-canvas-transition-direction]::view-transition-new(phone-top-actions),
|
||||
:root[data-canvas-transition-direction]::view-transition-old(right-floating-controls),
|
||||
:root[data-canvas-transition-direction]::view-transition-new(right-floating-controls) {
|
||||
:root[data-canvas-transition-direction]::view-transition-new(phone-top-actions) {
|
||||
mix-blend-mode: normal;
|
||||
}
|
||||
:root[data-canvas-transition-direction="forward"]::view-transition-old(canvas-view-content) {
|
||||
@@ -351,15 +343,13 @@ code {
|
||||
}
|
||||
:root[data-canvas-transition-direction]::view-transition-old(app-pill),
|
||||
:root[data-canvas-transition-direction]::view-transition-old(canvas-camera-controls),
|
||||
:root[data-canvas-transition-direction]::view-transition-old(canvas-toolbar),
|
||||
:root[data-canvas-transition-direction]::view-transition-old(right-floating-controls) {
|
||||
:root[data-canvas-transition-direction]::view-transition-old(canvas-toolbar) {
|
||||
animation: none;
|
||||
opacity: 0;
|
||||
}
|
||||
:root[data-canvas-transition-direction]::view-transition-new(app-pill),
|
||||
:root[data-canvas-transition-direction]::view-transition-new(canvas-camera-controls),
|
||||
:root[data-canvas-transition-direction]::view-transition-new(canvas-toolbar),
|
||||
:root[data-canvas-transition-direction]::view-transition-new(right-floating-controls) {
|
||||
:root[data-canvas-transition-direction]::view-transition-new(canvas-toolbar) {
|
||||
animation: none;
|
||||
opacity: 1;
|
||||
}
|
||||
@@ -461,6 +451,8 @@ code {
|
||||
--graph-line-soft: #c5c7ce;
|
||||
/* One flat fill for a group — no border, no second tone inside it. */
|
||||
--canvas-group: #f5f5f6;
|
||||
/* The ring a hovered Map card takes: a step past the border scale, short of the connectors. */
|
||||
--hover-ring: #b9bbc6;
|
||||
color: var(--text);
|
||||
background: var(--screen);
|
||||
}
|
||||
@@ -480,6 +472,7 @@ code {
|
||||
--graph-line: #696e77;
|
||||
--graph-line-soft: #3f4349;
|
||||
--canvas-group: #18191b;
|
||||
--hover-ring: #5a6169;
|
||||
}
|
||||
/* The canvas is a fixed map: dragging anywhere pans, while clicking an object selects it. */
|
||||
.graph-canvas .canvas-tool-pan,
|
||||
@@ -499,27 +492,14 @@ code {
|
||||
.graph-canvas .transition-edge-hitarea { cursor: pointer; pointer-events: stroke; }
|
||||
.graph-canvas .transition-edge-path { transition: stroke 100ms ease, stroke-width 100ms ease, opacity 140ms ease; }
|
||||
.graph-canvas .graph-edge-secondary { opacity: 0.72; }
|
||||
.graph-canvas .graph-edge-dimmed { opacity: 0.14; }
|
||||
.graph-canvas .graph-edge-active { opacity: 1; }
|
||||
.graph-canvas .react-flow__node { transition: opacity 180ms ease, filter 180ms ease; }
|
||||
.graph-canvas .canvas-focus-animating .react-flow__node { transition: none; }
|
||||
/* Focus: what the chosen state does not cover only steps back, so the map is still readable. */
|
||||
.graph-canvas .react-flow__node.graph-node-muted { opacity: var(--dim-out); --map-card-opacity: var(--dim-out); }
|
||||
/* A route-selected screenshot stays visually anchored while the surrounding screenshots recede.
|
||||
They fade as focus dims them, by opacity alone: a filter would grey the card's opaque backing.
|
||||
Summary cards retain their normal contrast so the selected screen's semantic context is legible. */
|
||||
.map-canvas.screen-selection-active .react-flow__node-screen:not(.selected) {
|
||||
opacity: var(--dim-out);
|
||||
--map-card-opacity: var(--dim-out);
|
||||
}
|
||||
.map-canvas.screen-selection-active .react-flow__node-screen:not(.selected):hover,
|
||||
.map-canvas.screen-selection-active .react-flow__node-screen:not(.selected):focus-within {
|
||||
opacity: 1;
|
||||
--map-card-opacity: 1;
|
||||
}
|
||||
/* Hover never recedes anything, but where focus or a selection has already dimmed the map, the
|
||||
hovered screen and the screens it connects to come back up, with the transitions between them,
|
||||
so the neighbourhood reads. These come after both dimming rules so the pointer's context wins. */
|
||||
/* Hover never recedes anything, but where the Changes filter has dimmed the map, the hovered
|
||||
screen and the screens it connects to come back up, with the transitions between them, so the
|
||||
neighbourhood reads. These come after the dimming rule so the pointer's context wins. */
|
||||
.connection-canvas-surface.canvas-hovering .react-flow__node-screen.graph-node-hover-related {
|
||||
opacity: 1;
|
||||
--map-card-opacity: 1;
|
||||
@@ -687,7 +667,7 @@ code {
|
||||
/* Hover and selection draw a 3px ring in the accent colour: the 1px border recoloured plus a 2px
|
||||
shadow outside it, so the image keeps its size (a thicker border would shrink the picture inside
|
||||
its box). Changed screens keep their own colour at the same weight: the diff rules below win on
|
||||
specificity. */
|
||||
specificity. The Map leaves the border to the status and rings the card from outside instead. */
|
||||
.screen-node-image:hover img,
|
||||
.screen-screenshot-card.selected .screen-node-image img { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
|
||||
.screen-node-image:hover > .image-placeholder,
|
||||
@@ -707,8 +687,8 @@ code {
|
||||
border-radius: 17px;
|
||||
pointer-events: none;
|
||||
}
|
||||
/* Selection needs no ring: the canvas dims every other screen. The highlight ring stays for the
|
||||
transient pointer-over state that panels project onto the canvas. */
|
||||
/* Selection needs no overlay: the Map rings the screenshot and Screens frames the card. The
|
||||
highlight ring stays for the transient pointer-over state that panels project onto the canvas. */
|
||||
.canvas-active-frame.is-highlighted::after {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 24%, transparent);
|
||||
@@ -723,10 +703,9 @@ code {
|
||||
pointer-events: none;
|
||||
}
|
||||
/* A screen's handles are ports on its frame: they take the frame colour, whether that is the
|
||||
status colour of a changed screen or the accent of a hovered or selected one, and a ring in
|
||||
the canvas colour keeps them legible as connection points on the border. */
|
||||
status colour of a changed screen or the accent of a selected one, and a ring in the canvas
|
||||
colour keeps them legible as connection points on the border. */
|
||||
.screen-screenshot-card { --screen-frame: var(--graph-line); }
|
||||
.screen-screenshot-card:has(.screen-node-image:hover),
|
||||
.screen-screenshot-card.selected,
|
||||
.screen-screenshot-card.highlighted { --screen-frame: var(--accent); }
|
||||
.screen-screenshot-card:is(.diff-added, .diff-modified, .diff-removed) { --screen-frame: var(--diff); }
|
||||
@@ -738,23 +717,48 @@ code {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Hover is transient canvas state. Nothing recedes: the pointer's screen gets its ring, the
|
||||
transitions into and out of it turn accent, and the screens at their other ends take a tinted
|
||||
frame, so the neighbourhood reads without the rest of the map changing. Only the symmetric
|
||||
difference of related nodes/edges receives a class, avoiding a React commit across the graph. */
|
||||
.connection-canvas-surface.canvas-hovering .graph-edge-hover-related .transition-edge-path {
|
||||
stroke: var(--accent) !important;
|
||||
stroke-width: 2.2 !important;
|
||||
/* A Map card's border is its status alone. Selection rings it from outside instead: an accent
|
||||
ring past a gap in the canvas colour, outside the status border, with a soft lift; hover draws
|
||||
the same ring in grey. The ring scales with the canvas, so below a readable zoom its unit grows
|
||||
to keep it about a screen pixel and a half wide (--canvas-zoom, set by the zoom bridge). */
|
||||
.map-surface .screen-screenshot-card {
|
||||
--ring-unit: clamp(1px, 0.6px / var(--canvas-zoom, 1), 6px);
|
||||
--ring-status: 0px;
|
||||
}
|
||||
.map-surface .screen-screenshot-card:is(.diff-added, .diff-modified, .diff-removed) { --ring-status: 2px; }
|
||||
.map-surface .screen-screenshot-card .screen-node-image :is(img, .image-placeholder) {
|
||||
border-color: var(--border-subtle);
|
||||
box-shadow: none;
|
||||
}
|
||||
.map-surface .react-flow__node-screen:is(.selected, .graph-node-hover-subject) .screen-screenshot-card .screen-node-image :is(img, .image-placeholder) {
|
||||
box-shadow:
|
||||
0 0 0 var(--ring-status) var(--diff, transparent),
|
||||
0 0 0 calc(var(--ring-status) + 4 * var(--ring-unit)) var(--screen),
|
||||
0 0 0 calc(var(--ring-status) + 6.5 * var(--ring-unit)) var(--ring-color),
|
||||
var(--ring-lift, 0 0 transparent);
|
||||
}
|
||||
.map-surface .react-flow__node-screen.graph-node-hover-subject { --ring-color: var(--hover-ring); }
|
||||
.map-surface .react-flow__node-screen.selected {
|
||||
--ring-color: var(--accent);
|
||||
--ring-lift: 0 calc(10 * var(--ring-unit)) calc(28 * var(--ring-unit)) color-mix(in srgb, var(--accent) 18%, transparent);
|
||||
}
|
||||
.map-surface .react-flow__node-screen.selected .screen-node-title { color: var(--accent-strong); }
|
||||
/* Keyboard focus is dashed, past where a ring would sit, so it never reads as either. */
|
||||
.map-surface .screen-screenshot-target:focus-visible {
|
||||
outline: 2px dashed var(--accent-strong) !important;
|
||||
outline-offset: calc(var(--ring-status) + 9 * var(--ring-unit)) !important;
|
||||
filter: none !important;
|
||||
}
|
||||
|
||||
/* Hover is transient canvas state. Nothing recedes: the pointer's screen takes its grey ring and
|
||||
the transitions into and out of it darken. Only the symmetric difference of related
|
||||
nodes/edges receives a class, avoiding a React commit across the graph. A selected screen's
|
||||
transitions stay accent. */
|
||||
.connection-canvas-surface.canvas-hovering .graph-edge-hover-related:not(.graph-edge-active) .transition-edge-path {
|
||||
stroke: var(--tertiary) !important;
|
||||
stroke-width: 2 !important;
|
||||
stroke-dasharray: none !important;
|
||||
}
|
||||
.connection-canvas-surface.canvas-hovering .react-flow__node-screen.graph-node-hover-related:not(.graph-node-hover-subject)
|
||||
.screen-screenshot-card:not(.selected, .diff-added, .diff-modified, .diff-removed) {
|
||||
--screen-frame: var(--hover-neighbour-frame);
|
||||
}
|
||||
.connection-canvas-surface.canvas-hovering .react-flow__node-screen.graph-node-hover-related:not(.graph-node-hover-subject)
|
||||
.screen-screenshot-card:not(.selected, .diff-added, .diff-modified, .diff-removed) .screen-node-image :is(img, .image-placeholder) {
|
||||
border-color: var(--hover-neighbour-frame);
|
||||
}
|
||||
|
||||
/* Semantic Map: an area is a meaningful destination, never an anonymous "X states" step. */
|
||||
.semantic-summary-node {
|
||||
@@ -928,7 +932,7 @@ code {
|
||||
|
||||
/* The phone map's open hint. The first tap there only selects, so the pill sits in the middle of
|
||||
the selected screenshot (always on the image whatever the slot's shape) and says what the next
|
||||
tap does. In a wider window the card's tooltip carries the message and nothing covers the image. */
|
||||
tap does. In a wider window a click opens the Inspector at once and nothing covers the image. */
|
||||
.screen-screenshot-target { cursor: pointer; }
|
||||
.screen-open-hint {
|
||||
position: absolute;
|
||||
@@ -954,7 +958,7 @@ code {
|
||||
.screen-open-hint > svg { width: 14px; height: 14px; flex: none; }
|
||||
/* Only the phone layout's map shows the pill, on the selected screen, where a second tap or click
|
||||
opens the Inspector. That layout is a width, not a device, and has no tooltips, so a narrow
|
||||
desktop window shows it too. Elsewhere the screenshot button's tooltip says it instead. */
|
||||
desktop window shows it too. */
|
||||
.phone-layout .map-canvas .screen-screenshot-card.selected .screen-open-hint {
|
||||
display: inline-flex;
|
||||
animation: screen-open-hint-in 140ms ease-out;
|
||||
@@ -998,7 +1002,7 @@ code {
|
||||
border-radius: calc(14px * var(--ui-scale));
|
||||
background: var(--surface);
|
||||
box-shadow: var(--floating-chrome-shadow);
|
||||
transform: translateX(-50%);
|
||||
transform: translateX(calc(-50% - var(--canvas-toolbar-shift, 0px)));
|
||||
view-transition-name: canvas-toolbar;
|
||||
}
|
||||
.canvas-toolbar-inner { display: flex; align-items: center; gap: 2px; zoom: var(--ui-scale); }
|
||||
@@ -1105,7 +1109,10 @@ code {
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
flex: none;
|
||||
width: 400px;
|
||||
/* The reader's own width when they have dragged the edge (utils/inspector-width.ts), else the
|
||||
default; never more than half the window, so the canvas keeps the other half. */
|
||||
width: var(--inspector-width, 400px);
|
||||
max-width: 50%;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
flex-direction: column;
|
||||
@@ -1117,33 +1124,35 @@ code {
|
||||
/* Two Diff previews, their 8px gap, and the 14px side insets must fit this same width. */
|
||||
--inspector-shared-preview-max-width: calc((100cqw - 36px) / 2);
|
||||
}
|
||||
/* When minimised, the inspector actions join the camera controls as one floating toolbar. */
|
||||
.right-float {
|
||||
position: fixed;
|
||||
z-index: 100;
|
||||
top: var(--chrome-top);
|
||||
right: var(--right-float-edge);
|
||||
width: calc(var(--right-float-width) * var(--ui-scale));
|
||||
height: var(--chrome-height);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: calc(3px * var(--ui-scale));
|
||||
border: 0;
|
||||
border-radius: 0 calc(8px * var(--ui-scale)) calc(8px * var(--ui-scale)) 0;
|
||||
background: var(--side-panel-surface);
|
||||
box-shadow: none;
|
||||
/* No backdrop blur: the surface is opaque, and a blurred backdrop leaves this toolbar's view
|
||||
transition snapshot stale, so a button that moves into its place paints late. */
|
||||
view-transition-name: right-floating-controls;
|
||||
/* The panel's left edge is a splitter: a 10px strip over the border, quiet until it is hovered,
|
||||
dragged or focused, when the border thickens into the accent line. */
|
||||
.right-panel-resize {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: -5px;
|
||||
width: 10px;
|
||||
cursor: col-resize;
|
||||
touch-action: none;
|
||||
outline: none;
|
||||
}
|
||||
.right-float > * { zoom: var(--ui-scale); }
|
||||
.right-float .icon-button.active { color: var(--text); background: var(--element); }
|
||||
.right-float .icon-button[disabled] { color: var(--border); cursor: default; background: transparent; }
|
||||
.right-float .icon-button:hover {
|
||||
border-color: transparent;
|
||||
background: var(--panel-hover);
|
||||
.right-panel-resize::before {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 4px;
|
||||
width: 2px;
|
||||
background: var(--accent);
|
||||
content: "";
|
||||
opacity: 0;
|
||||
transition: opacity var(--toolbar-motion) var(--toolbar-easing) 120ms;
|
||||
}
|
||||
.right-panel-resize:hover::before,
|
||||
.right-panel-resize:focus-visible::before,
|
||||
.inspector-resizing .right-panel-resize::before { opacity: 1; transition-delay: 0ms; }
|
||||
/* While the edge is dragged nothing else may select or change the cursor. */
|
||||
.inspector-resizing, .inspector-resizing * { cursor: col-resize !important; user-select: none !important; }
|
||||
.right-head {
|
||||
display: flex;
|
||||
flex: none;
|
||||
@@ -1202,7 +1211,8 @@ code {
|
||||
position: absolute;
|
||||
z-index: 20;
|
||||
top: var(--chrome-top);
|
||||
right: calc(var(--canvas-visible-right-inset, 0px) + 8px);
|
||||
/* Mirrors the pill: the same inset from the canvas' right edge as the pill's from its left. */
|
||||
right: calc(var(--canvas-visible-right-inset, 0px) + var(--canvas-chrome-inline-inset));
|
||||
display: inline-flex;
|
||||
height: var(--chrome-height);
|
||||
align-items: center;
|
||||
@@ -1213,30 +1223,9 @@ code {
|
||||
color: var(--text);
|
||||
background: var(--side-panel-surface);
|
||||
box-shadow: var(--floating-chrome-shadow);
|
||||
/* No backdrop blur, as on .right-float: with it, entering Compare painted full screen late. */
|
||||
/* No backdrop blur: with it, the view transition's snapshot of these controls painted late. */
|
||||
view-transition-name: canvas-camera-controls;
|
||||
}
|
||||
.canvas-camera-controls.inspector-collapsed {
|
||||
right: calc(
|
||||
var(--canvas-visible-right-inset, 0px) +
|
||||
var(--right-float-edge) + var(--right-float-width) * var(--ui-scale) - 1px
|
||||
);
|
||||
border: 0;
|
||||
border-radius: calc(8px * var(--ui-scale)) 0 0 calc(8px * var(--ui-scale));
|
||||
box-shadow: none;
|
||||
}
|
||||
.canvas-camera-controls.inspector-collapsed::before {
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
top: 0;
|
||||
right: calc((var(--right-float-width) * var(--ui-scale) - 1px) * -1);
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
border-radius: calc(8px * var(--ui-scale));
|
||||
box-shadow: var(--floating-chrome-shadow);
|
||||
content: "";
|
||||
pointer-events: none;
|
||||
}
|
||||
.canvas-camera-controls .camera-action-button,
|
||||
.canvas-camera-controls .zoom-button {
|
||||
border: 0;
|
||||
@@ -1260,7 +1249,6 @@ code {
|
||||
flex: none;
|
||||
background: var(--border-subtle);
|
||||
}
|
||||
.canvas-camera-controls.inspector-collapsed .camera-control-divider { display: none; }
|
||||
.canvas-camera-controls .zoom-button:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 1px;
|
||||
@@ -2056,6 +2044,61 @@ code {
|
||||
.menu-row-shortcut { flex: none; margin-left: 16px; color: var(--tertiary); font-size: 11px; }
|
||||
.menu-separator { height: 1px; margin: 4px 6px; background: var(--popover-line); }
|
||||
|
||||
/* ── More menu (the bottom bar's "…") ───────────────────────────────────── */
|
||||
|
||||
/* The menu is anchored to its button, but clears the bar the button sits in. The popover itself
|
||||
is the surface, as the Changes menu's is: an anchored popover scrolls, and would clip a shadow
|
||||
drawn by the list inside it. Only a window too short for the menu scrolls it. */
|
||||
.menu-popover.more-menu {
|
||||
overflow-x: hidden !important;
|
||||
border: 1px solid var(--popover-line);
|
||||
border-radius: calc(9px * var(--ui-scale));
|
||||
background: var(--popover);
|
||||
box-shadow: var(--popover-shadow);
|
||||
translate: 0 calc(-12px * var(--ui-scale));
|
||||
}
|
||||
/* Rows read icon, label, control, key, in the menu's own type and colours. */
|
||||
.more-menu-list { display: flex; width: 248px; flex-direction: column; padding: 4px; }
|
||||
.more-menu-row {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
min-height: 34px;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 4px 6px 4px 8px;
|
||||
border-radius: 5px;
|
||||
color: var(--text);
|
||||
background: transparent;
|
||||
font-size: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
.more-menu-item:hover,
|
||||
.more-menu-item:focus-visible { background: var(--popover-hover); outline: none; }
|
||||
.more-menu-icon { display: flex; width: 16px; flex: none; align-items: center; justify-content: center; color: var(--secondary); }
|
||||
.more-menu-icon > svg { width: 15px; height: 15px; }
|
||||
.more-menu-label { min-width: 0; flex: 1; white-space: nowrap; }
|
||||
.more-menu-check { display: flex; flex: none; color: var(--secondary); }
|
||||
.more-menu-check > svg { width: 14px; height: 14px; }
|
||||
/* The key column lines up down the menu, whatever the row holds before it. */
|
||||
.more-menu-key { min-width: 22px; flex: none; text-align: center; }
|
||||
/* A compact three-way switch: Auto, Light, Dark, on the segmented control's track and thumb. */
|
||||
.more-theme-switch { display: flex; flex: none; gap: 2px; padding: 2px; border-radius: 7px; background: var(--segment-track); }
|
||||
.more-theme-option {
|
||||
display: flex;
|
||||
width: 26px;
|
||||
height: 22px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 5px;
|
||||
color: var(--tertiary);
|
||||
background: transparent;
|
||||
transition: color 120ms ease, background 120ms ease;
|
||||
}
|
||||
.more-theme-option > svg { width: 14px; height: 14px; }
|
||||
.more-theme-option:hover { color: var(--text); }
|
||||
.more-theme-option[aria-checked="true"] { color: var(--text); background: var(--segment-thumb); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
|
||||
.more-theme-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
|
||||
|
||||
/* ── Feedback dialog ────────────────────────────────────────────────────── */
|
||||
|
||||
.dialog-backdrop {
|
||||
@@ -2202,7 +2245,8 @@ code {
|
||||
.search-command-result-copy code { color: inherit; font-size: inherit; }
|
||||
.search-command-section + .search-command-section { margin-top: 4px; }
|
||||
.search-command-section > .search-command-section-label { padding: 8px 8px 4px; }
|
||||
.search-command-result-key {
|
||||
.search-command-result-key,
|
||||
.more-menu-key {
|
||||
padding: 2px 6px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 5px;
|
||||
@@ -2330,7 +2374,7 @@ html [data-sonner-toaster][data-sonner-theme] {
|
||||
@keyframes tooltip-in { from { opacity: 0; } }
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.right-panel { width: 320px; }
|
||||
.right-panel { width: var(--inspector-width, 320px); }
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
|
||||
@@ -102,7 +102,8 @@ export function commandItems(context: CommandContext, actions: CommandActions):
|
||||
{ keywords: ["app", "appearance", "scheme", "captured"], shortcut: !appearance.current && context.appearances.length === 2 ? key(SHORTCUTS.appearance.app) : undefined });
|
||||
}
|
||||
if (context.fullscreen !== undefined) {
|
||||
add("view:fullscreen", "View", context.fullscreen ? "Exit full screen" : "Enter full screen", actions.toggleFullscreen, { keywords: ["fullscreen", "window", "focus"] });
|
||||
add("view:fullscreen", "View", context.fullscreen ? "Exit full screen" : "Enter full screen", actions.toggleFullscreen,
|
||||
{ keywords: ["fullscreen", "window", "focus"], shortcut: key(SHORTCUTS.view.fullscreen) });
|
||||
}
|
||||
|
||||
for (const target of context.targets) {
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { optionalStorage } from "./embedded-report";
|
||||
|
||||
const INSPECTOR_WIDTH_STORAGE_KEY = "expo-explore:inspector-width";
|
||||
/** Below this the Before/After pair no longer reads; above the maximum the canvas is the one squeezed. */
|
||||
export const INSPECTOR_WIDTH_MIN = 320;
|
||||
export const INSPECTOR_WIDTH_MAX = 800;
|
||||
/** How far one arrow key press moves the panel's edge. */
|
||||
export const INSPECTOR_WIDTH_STEP = 16;
|
||||
|
||||
const listeners = new Set<() => void>();
|
||||
/** The choice made this visit: storage can be denied (a private window), and the drag must still hold. `null` is a reset. */
|
||||
let chosen: number | null | undefined;
|
||||
|
||||
function parseWidth(value: string | null): number | undefined {
|
||||
if (value === null) return undefined;
|
||||
const width = Number(value);
|
||||
return Number.isFinite(width) && width > 0 ? width : undefined;
|
||||
}
|
||||
|
||||
function stored(): number | undefined {
|
||||
if (chosen !== undefined) return chosen ?? undefined;
|
||||
return parseWidth(optionalStorage.getItem(INSPECTOR_WIDTH_STORAGE_KEY));
|
||||
}
|
||||
|
||||
/** Sets the Inspector's width in unscaled CSS pixels, or `undefined` to return to the default, and remembers it where it can. */
|
||||
export function setInspectorWidth(width: number | undefined) {
|
||||
chosen = width ?? null;
|
||||
if (width === undefined) optionalStorage.removeItem(INSPECTOR_WIDTH_STORAGE_KEY);
|
||||
else optionalStorage.setItem(INSPECTOR_WIDTH_STORAGE_KEY, String(width));
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
|
||||
/** The reader's Inspector width, or `undefined` while the panel keeps its default width. */
|
||||
export function useInspectorWidth(): number | undefined {
|
||||
return useSyncExternalStore(
|
||||
(onChange) => {
|
||||
listeners.add(onChange);
|
||||
return () => listeners.delete(onChange);
|
||||
},
|
||||
stored,
|
||||
() => undefined,
|
||||
);
|
||||
}
|
||||
|
||||
/** The room the bottom bar needs beside the Inspector, in window pixels: its measured width and a gap either side. */
|
||||
let toolbarRoom = 0;
|
||||
const toolbarListeners = new Set<() => void>();
|
||||
|
||||
/** The bottom bar reports the room it needs whenever its measured width changes (with `--ui-scale` too). */
|
||||
export function setToolbarRoom(room: number) {
|
||||
if (room === toolbarRoom) return;
|
||||
toolbarRoom = room;
|
||||
for (const listener of toolbarListeners) listener();
|
||||
}
|
||||
|
||||
export function getToolbarRoom(): number {
|
||||
return toolbarRoom;
|
||||
}
|
||||
|
||||
export function subscribeToToolbarRoom(onChange: () => void): () => void {
|
||||
toolbarListeners.add(onChange);
|
||||
return () => toolbarListeners.delete(onChange);
|
||||
}
|
||||
|
||||
export type InspectorWidthBounds = { min: number; max: number };
|
||||
|
||||
/**
|
||||
* The widths the panel may take in a window `windowWidth` wide: at most half of it, so the canvas
|
||||
* keeps the other half, and never so wide that the canvas beside it loses the `toolbarRoom` the
|
||||
* bottom bar needs (window pixels), in the panel's own (unscaled) pixels when the chrome is zoomed
|
||||
* by `scale`. Neither cap goes below the minimum.
|
||||
*/
|
||||
export function inspectorWidthBounds(windowWidth: number, scale = 1, room = 0): InspectorWidthBounds {
|
||||
const zoom = scale > 0 ? scale : 1;
|
||||
const half = Math.floor(windowWidth / 2 / zoom);
|
||||
const besideBar = Math.floor((windowWidth - room) / zoom);
|
||||
return { min: INSPECTOR_WIDTH_MIN, max: Math.max(INSPECTOR_WIDTH_MIN, Math.min(INSPECTOR_WIDTH_MAX, half, besideBar)) };
|
||||
}
|
||||
|
||||
export function clampInspectorWidth(width: number, bounds: InspectorWidthBounds): number {
|
||||
return Math.round(Math.min(bounds.max, Math.max(bounds.min, width)));
|
||||
}
|
||||
@@ -77,6 +77,10 @@ export const SHORTCUTS = {
|
||||
theme: plain("KeyT", "T"),
|
||||
app: shift("KeyT", "T"),
|
||||
},
|
||||
/** F puts the whole Viewer in or out of full screen, where the browser allows it. */
|
||||
view: {
|
||||
fullscreen: plain("KeyF", "F"),
|
||||
},
|
||||
/** Canvas edits follow the platform-standard history keys. */
|
||||
edit: {
|
||||
undo: mod("KeyZ", "Z"),
|
||||
|
||||
Reference in new issue
Block a user