console fill apple-app-privacy: fit the Data Collection dialog to the real console

A real run (sanitized debug dump) showed why the walk stopped after Next:
the data types step is the same "Data Collection" dialog (URL unchanged),
and each checkbox's accessible name is its label run together with its
help text ("NameIncluding first or last name"). Some labels also differ
from Apple's help page ("Purchases", "Other Data").

- labelNames: the exact name, then the label as a prefix that ends where
  the help text starts (no lowercase letter follows), so "Name" never
  matches "Phone Number...", "Head" never "Health...", "Contact" never
  "Contacts...". Used for the data types and the purposes.
  TYPE_ALIASES maps Purchase History / Other Data Types to the console's
  labels.
- Dialog per step: a section's dialog is also found as the one visible
  dialog with a heading of that name.
- Every click and check is bounded (ACTION_MS, 10 s; the scan test now
  also rejects clicks without a timeout).
- The flow fixture mirrors the real dialog's structure (dialog/h2 title,
  group h3s, input name = Apple's enum, <label> with label + help <p>s,
  Save disabled until a type is ticked); no data from the dump. A test
  checks every Apple type matches exactly one real-style checkbox.
- Pitfall 15.

Publish is still never clicked; unknown steps still get the watchdog dump.
This commit is contained in:
CRTkafa 2026-10-12 07:17:15 +08:00
parent 8b669f5c86
commit 59150c1186
7 changed files with 135 additions and 41 deletions

View file

@ -40,6 +40,8 @@ export type Page = any;
export type Locator = any;
const TAG = 'console';
/** The longest any single click or check may take (Playwright waits for the control to be enabled and stable). */
export const ACTION_MS = 10_000;
const CHECK = 'storebound: check this';
/** Locators with only the visible matches (hidden earlier pages stay in many consoles' DOM). */
@ -111,8 +113,8 @@ export async function accName(loc: Locator): Promise<string> {
*/
export async function safeClick(loc: Locator, name: string, action: 'click' | 'check' | 'uncheck' = 'click'): Promise<boolean> {
if (forbiddenControl(name)) { warn(TAG, `not clicking "${name}": storebound never presses save, submit, publish, next or similar`); return false; }
if (action === 'click') await loc.click();
else await loc.setChecked(action === 'check');
if (action === 'click') await loc.click({ timeout: ACTION_MS });
else await loc.setChecked(action === 'check', { timeout: ACTION_MS });
return true;
}
@ -194,7 +196,13 @@ export async function fillPage(page: Page, def: FormDef, answers: Answer[], done
if (done.has(i)) continue;
let root: Locator = page;
if (sec.dialog) {
const d = await find(page, 'dialog', sec.dialog);
let d = await find(page, 'dialog', sec.dialog);
// a dialog titled otherwise (one dialog per step, the title elsewhere): the one visible dialog with such a heading
if (d.state === 'none') for (const n of sec.dialog) {
const l = vis(page.getByRole('dialog').filter({ has: page.getByRole('heading', nameOpts(n)) }));
const c = await l.count();
if (c) { d = c === 1 ? { state: 'ok', loc: l } : { state: 'ambiguous' }; break; }
}
if (d.state === 'none') continue;
if (d.state !== 'ok') return { section: i, title: sec.title, filled: [], highlighted: [], missing: [`dialog ${sec.title}`], fallback: true };
root = d.loc;
@ -276,7 +284,7 @@ export async function realRole(loc: Locator): Promise<string> {
export async function navClick(loc: Locator, createApp = false): Promise<{ clicked: boolean; name: string }> {
const name = await accName(loc), role = await realRole(loc);
if (createApp ? !await createAppHere(loc, name, role) : !navAllowed(name, role)) { warn(TAG, `not clicking "${name}" while opening the form: storebound never presses save, submit, publish, next or similar`); return { clicked: false, name }; }
await loc.click();
await loc.click({ timeout: ACTION_MS });
return { clicked: true, name };
}
@ -324,7 +332,7 @@ export async function flowClick(loc: Locator, form: FormId, dataTypes: string[],
const name = await accName(loc), role = await realRole(loc);
const where = await flowWhere(loc, dataTypes);
if (!flowAllowed(form, name, role, where)) { warn(TAG, `not clicking "${name}": only the owner presses it`); return false; }
await loc.click();
await loc.click({ timeout: ACTION_MS });
say(`clicked "${name}" (${flowClass(form, name, role, where)})`);
onClick?.(name);
return true;