Skip to content
21 changes: 18 additions & 3 deletions scripts/verify/e2e/cases/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,23 @@ const consoleState = `(() => ({
*/
const markerPersisted = async (ctx: E2EContext): Promise<boolean> => {
const panel = await ctx.requireSurface({ surfaceId: "panel-1" });
const deadline = Date.now() + 20_000;
// The retention write is a single debounced (100ms) evalScript with a
// 500ms host-side timeout and no retry — under ExtendScript-engine
// congestion that one write can be dropped, and nothing rewrites the
// store until the NEXT console.* call. Each poll therefore also emits
// a nudge message so a fresh broadcast re-arms the write (the store
// write always serializes the full message list, marker included).
// Without the nudge the check depended on unrelated app logging to
// retrigger persistence and timed out at 20s on loaded hosts.
const deadline = Date.now() + 60_000;
let nudges = 0;
while (Date.now() < deadline) {
if (nudges > 0) {
await ctx
.evalJs(panel, `console.log("e2e-g02-persist-nudge")`)
.catch(() => undefined);
}
nudges += 1;
const raw = await ctx.evalScript(
panel,
`(function(){
Expand All @@ -175,7 +190,7 @@ const markerPersisted = async (ctx: E2EContext): Promise<boolean> => {
15_000,
);
if (raw.includes(MARKER)) return true;
await sleep(500);
await sleep(2_000);
}
return false;
};
Expand All @@ -197,7 +212,7 @@ export const debugCases: E2ECase[] = [
check(
"marker persisted to shared log store",
persisted,
persisted ? "in ty_plus_debug_logs_v1" : "not found within 20s",
persisted ? "in ty_plus_debug_logs_v1" : "not found within 60s",
),
);

Expand Down
69 changes: 42 additions & 27 deletions scripts/verify/e2e/cases/online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,42 @@ const closeDialogBySurfaceId = async (
);
};

/**
* Click a settings sidebar item until its section mounts. The dialog body
* mounts one frame after the surface goes live and React attaches handlers
* asynchronously — a single click can land before hydration and silently
* no-op (observed as UC-F04/E07 "section missing" flakes right after open).
*/
const openSettingsSection = async (
ctx: E2EContext,
dialog: LiveSurface,
sectionId: string,
timeoutMs = 20_000,
): Promise<boolean> => {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
await ctx.evalJs(
dialog,
`(() => {
const sec = document.querySelector('[data-settings-sidebar-section="${sectionId}"]');
if (sec) return "mounted";
const tab = document.querySelector('[data-settings-sidebar-item="${sectionId}"]');
if (tab) tab.click();
return tab ? "clicked" : "no-tab";
})()`,
);
const mounted = await waitForDom(
ctx,
dialog,
`Boolean(document.querySelector('[data-settings-sidebar-section="${sectionId}"]'))`,
2_000,
);
if (mounted) return true;
await sleep(500);
}
return false;
};

const readNotificationStore = async (
ctx: E2EContext,
): Promise<{
Expand Down Expand Up @@ -564,27 +600,14 @@ export const onlineCases: E2ECase[] = [
),
);

// Navigate to the Updates section.
await ctx.evalJs(
dialog,
`(() => {
const tab = document.querySelector(
'[data-settings-sidebar-item="update"]');
if (tab) tab.click();
return Boolean(tab);
})()`,
);
const sectionMounted = await waitForDom(
ctx,
dialog,
`Boolean(document.querySelector('[data-settings-sidebar-section="update"]'))`,
15_000,
);
// Navigate to the Updates section (retry the tab click until
// the section mounts — see openSettingsSection).
const sectionMounted = await openSettingsSection(ctx, dialog, "update");
checks.push(
check(
"Updates section mounted",
Boolean(sectionMounted),
String(sectionMounted).slice(0, 80),
sectionMounted,
String(sectionMounted),
),
);
if (!sectionMounted)
Expand Down Expand Up @@ -909,15 +932,7 @@ export const onlineCases: E2ECase[] = [
);
if (!dialog) return;

await ctx.evalJs(
dialog,
`(() => {
const tab = document.querySelector(
'[data-settings-sidebar-item="update"]');
if (tab) tab.click();
return Boolean(tab);
})()`,
);
await openSettingsSection(ctx, dialog, "update");
const sectionMounted = await waitForDom(
ctx,
dialog,
Expand Down
39 changes: 25 additions & 14 deletions scripts/verify/e2e/cases/preset-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,31 @@ const clickWsAction = async (
if (existing) {
return clickFirst(ctx, panel, `[data-ws-action="${action}"]`);
}
return ctx.evalJs(
panel,
`(() => {
const anchor = document.querySelector("[data-ws-action]");
if (!anchor) return "missing-anchor";
const btn = document.createElement("button");
btn.setAttribute("data-ws-action", ${JSON.stringify(action)});
btn.style.display = "none";
(anchor.parentElement || anchor).appendChild(btn);
btn.click();
btn.remove();
return "clicked-injected";
})()`,
);
// The injection anchor is any `[data-ws-action]` element; right after a
// snapshot-restore panel reload the workspace chrome has not hydrated
// yet, so a single probe can see zero anchors ("missing-anchor" flakes).
// Wait — bounded — for the chrome before giving up.
const deadline = Date.now() + 20_000;
let result: unknown = "missing-anchor";
while (result === "missing-anchor" && Date.now() < deadline) {
result = await ctx.evalJs(
panel,
`(() => {
const anchor = document.querySelector("[data-ws-action]");
if (!anchor) return "missing-anchor";
const btn = document.createElement("button");
btn.setAttribute("data-ws-action", ${JSON.stringify(action)});
btn.style.display = "none";
(anchor.parentElement || anchor).appendChild(btn);
btn.click();
btn.remove();
return "clicked-injected";
})()`,
);
if (result !== "missing-anchor") break;
await sleep(700);
}
return result;
};

/**
Expand Down
73 changes: 60 additions & 13 deletions scripts/verify/e2e/cases/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,59 @@ const expectedTablistAriaLabel = (locale: string): string =>

/**
* app.json is rewritten (re-serialized) by the panel on boot, so restore
* verification compares parsed content rather than raw bytes. Key order is
* not significant — the boot rewrite may re-serialize identical content in a
* different order, which `JSON.stringify` would report as a diff.
* verification cannot require byte/deep equality with the pre-case
* snapshot: the sandbox copy is not boot-normalized, and the panel's
* post-restore persist legitimately re-adds normalized keys the snapshot
* never had. Comparing `before` as a subset of the live file still catches
* a failed restore — a mutated value or a dropped key — while ignoring
* panel-added defaults. Key order is not significant either way.
*/
const appJsonMatches = (a: AppJson | null, b: AppJson | null): boolean =>
isDeepStrictEqual(a ?? null, b ?? null);
const appJsonCoversSnapshot = (before: unknown, actual: unknown): boolean => {
if (before === null || typeof before !== "object" || Array.isArray(before)) {
return isDeepStrictEqual(before ?? null, actual ?? null);
}
if (actual === null || typeof actual !== "object" || Array.isArray(actual)) {
return false;
}
const actualRecord = actual as Record<string, unknown>;
return Object.entries(before as Record<string, unknown>).every(
([key, value]) =>
key in actualRecord && appJsonCoversSnapshot(value, actualRecord[key]),
);
};

/**
* Diagnostic companion to `appJsonCoversSnapshot`: returns the first
* key path where `actual` fails to cover `before` (or null when it
* does). Restore-check details embed this so a FAIL names the diverging
* key instead of only the last-polled language/accent value — the
* transient mid-persist states observed on loaded hosts otherwise give
* no hint which section had not converged yet.
*/
const firstAppJsonMismatch = (
before: unknown,
actual: unknown,
path = "",
): string | null => {
if (before === null || typeof before !== "object" || Array.isArray(before)) {
return isDeepStrictEqual(before ?? null, actual ?? null)
? null
: path || "(root)";
}
if (actual === null || typeof actual !== "object" || Array.isArray(actual)) {
return path || "(root)";
}
const actualRecord = actual as Record<string, unknown>;
for (const [key, value] of Object.entries(
before as Record<string, unknown>,
)) {
const childPath = path ? `${path}.${key}` : key;
if (!(key in actualRecord)) return childPath;
const nested = firstAppJsonMismatch(value, actualRecord[key], childPath);
if (nested) return nested;
}
return null;
};

export const openSettingsDialog = async (
ctx: E2EContext,
Expand Down Expand Up @@ -239,11 +286,11 @@ const waitForAppJson = async (
const waitForRestoredAppJson = async (
ctx: E2EContext,
before: AppJson | null,
timeoutMs = 25_000,
timeoutMs = 60_000,
): Promise<AppJson | null> => {
const deadline = Date.now() + timeoutMs;
let last = await readAppJson(ctx);
while (!appJsonMatches(last, before) && Date.now() < deadline) {
while (!appJsonCoversSnapshot(before, last) && Date.now() < deadline) {
await sleep(700);
last = await readAppJson(ctx);
}
Expand Down Expand Up @@ -384,8 +431,8 @@ export const settingsCases: E2ECase[] = [
checks.push(
check(
"settings/app.json restored after case",
appJsonMatches(restored, before),
`${appJsonPath} language=${restored?.ui?.language}`,
appJsonCoversSnapshot(before, restored),
`${appJsonPath} language=${restored?.ui?.language} mismatch=${firstAppJsonMismatch(before, restored)}`,
),
);
return {
Expand Down Expand Up @@ -577,8 +624,8 @@ export const settingsCases: E2ECase[] = [
checks.push(
check(
"settings/app.json restored after case",
appJsonMatches(restored, before),
`language=${restored?.ui?.language}`,
appJsonCoversSnapshot(before, restored),
`language=${restored?.ui?.language} mismatch=${firstAppJsonMismatch(before, restored)}`,
),
);
return {
Expand Down Expand Up @@ -773,8 +820,8 @@ export const settingsCases: E2ECase[] = [
checks.push(
check(
"settings/app.json restored after case",
appJsonMatches(restored, before),
`accent=${restored?.ui?.accentColor}`,
appJsonCoversSnapshot(before, restored),
`accent=${restored?.ui?.accentColor} mismatch=${firstAppJsonMismatch(before, restored)}`,
),
);
return {
Expand Down
7 changes: 6 additions & 1 deletion scripts/verify/e2e/cases/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* navigation, which is the only honest way to exercise "app reads the
* file at startup" behaviour.
*/
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";

Expand Down Expand Up @@ -166,6 +166,11 @@ export const withManagedRootSnapshot = async <T>(
return await fn();
} finally {
await ctx.restoreManagedRoot(snapshotDir);
// Snapshots are full managed-root copies kept under %TEMP%; leaving
// them accumulates GBs across cases and runs — the devnode's system
// drive hit ENOSPC mid-suite. The restore has consumed the snapshot,
// so drop it best-effort (a failed rm must not mask case results).
await rm(snapshotDir, { recursive: true, force: true }).catch(() => {});
// The live panel still holds the mutated in-memory layout and will
// re-persist it over the restored files. Reload so it resyncs from
// disk; best-effort — suites without a live panel skip this.
Expand Down
7 changes: 5 additions & 2 deletions scripts/verify/e2e/cases/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,14 @@ export const workspaceCases: E2ECase[] = [
}
const allAlerts = [...seenAlerts];

// No blocking modal may appear over the panel.
// No blocking modal may appear over the panel. The widget
// tutorial bubble is a non-modal `<dialog open>` (its scrim is
// pointer-events:none), so `dialog[open]` alone false-positives
// on every fresh profile — exclude it via data-tutorial-bubble.
const modal = await ctx.evalJs(
panel,
`Boolean(document.querySelector(
'dialog[open], [role="alertdialog"], .modal-open'))`,
'dialog[open]:not([data-tutorial-bubble]), [role="alertdialog"], .modal-open'))`,
);
checks.push(
check(
Expand Down
22 changes: 21 additions & 1 deletion scripts/verify/e2e/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ export class E2EContext {
return this.liveCache;
}

/**
* Drop the cached live-surface list and re-enumerate CDP targets.
* Surfaces whose CEPHtmlEngine respawned mid-run hold a stale
* `webSocketDebuggerUrl` in the cache; sandbox activation reloads
* every surface and must probe the post-reload targets, not the
* pre-reload ones.
*/
async refreshLiveSurfaces(): Promise<LiveSurface[]> {
this.liveCache = await listLiveSurfaces(await this.surfaces());
return this.liveCache;
}

async requireSurface(match: {
surfaceId?: string;
extensionId?: string;
Expand Down Expand Up @@ -256,7 +268,15 @@ export class E2EContext {
async restoreManagedRoot(snapshotDir: string): Promise<void> {
await this.assertManagedRootSafe();
const root = this.managedRoot();
const transient = new Set(["EPERM", "EACCES", "EBUSY", "ENOTEMPTY"]);
// EEXIST: a live panel watcher can recreate the managed root between
// `rm` and `cp`, so the copy's own mkdir collides with the fresh dir.
const transient = new Set([
"EPERM",
"EACCES",
"EBUSY",
"ENOTEMPTY",
"EEXIST",
]);
const maxAttempts = 10;
let lastError: unknown;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
Expand Down
Loading
Loading