Merge origin/main into shots-glyphs

This commit is contained in:
CRTkafa 2026-10-11 19:13:05 +00:00
commit e331a316d7
3 changed files with 63 additions and 7 deletions

View file

@ -78,8 +78,10 @@ async function resolve(root: Locator, f: FieldDef): Promise<Resolved> {
if (f.names?.length) {
let g = await find(root, 'radiogroup', f.names);
if (g.state === 'none') g = await find(root, 'group', f.names);
if (g.state !== 'ok') return { field: f, ok: false, seen: g.state !== 'none' };
scope = g.loc; seen = true;
if (g.state === 'ambiguous') return { field: f, ok: false, seen: true };
// App Store Connect labels "User Access" with a plain heading, not an ARIA group: then the options are looked up
// in the whole dialog (their own names, e.g. "Full Access", are unique there)
if (g.state === 'ok') { scope = g.loc; seen = true; }
}
const options: Record<string, Locator> = {};
let ok = true;
@ -87,7 +89,8 @@ async function resolve(root: Locator, f: FieldDef): Promise<Resolved> {
const r = await find(scope, 'radio', names);
if (r.state === 'ok') { options[v] = r.loc; seen = true; } else { ok = false; if (r.state === 'ambiguous') seen = true; }
}
return { field: f, ok, seen, ...(f.names?.length ? { loc: scope } : {}), options };
// loc = the group when the page has one; without it (plain heading) each option is highlighted on its own
return { field: f, ok, seen, ...(scope !== root ? { loc: scope } : {}), options };
}
/** The accessible name of a control as the page labels it (what the click gate checks). */
@ -170,7 +173,7 @@ export interface FillStep {
* ambiguous field -> fallback (nothing of that section is touched). Certain answers are set, the rest is highlighted
* and left empty. Never clicks Next / Save. `answers` carry the values the page gets (fillValue).
*/
export async function fillPage(page: Page, def: FormDef, answers: Answer[], done: Set<number> = new Set()): Promise<FillStep> {
export async function fillPage(page: Page, def: FormDef, answers: Answer[], done: Set<number> = new Set(), partial = false): Promise<FillStep> {
const byId = new Map(answers.map(a => [a.id, a]));
for (const [i, sec] of def.sections.entries()) {
if (done.has(i)) continue;
@ -185,16 +188,20 @@ export async function fillPage(page: Page, def: FormDef, answers: Answer[], done
for (const f of sec.fields) rs.push(await resolve(root, f));
if (!sec.dialog && !rs.some(r => r.seen)) continue;
const missing = rs.filter(r => !r.ok).map(r => r.field.id);
if (missing.length) return { section: i, title: sec.title, filled: [], highlighted: [], missing, fallback: true };
const filled: string[] = [], highlighted: string[] = [];
// only when no field of the section can be found is it a UI change; otherwise fill what was found and leave the
// missing fields to the owner (reported as "check")
// (a page still loading can also miss a field for a moment: the caller retries before it passes partial = true)
if (missing.length && (!partial || missing.length === rs.length)) return { section: i, title: sec.title, filled: [], highlighted: [], missing, fallback: true };
const filled: string[] = [], highlighted: string[] = [...missing];
for (const r of rs) {
if (!r.ok) continue;
const a = byId.get(r.field.id);
if (!a) continue;
const set = a.certain && a.value !== null ? await setField(r, a.value) : false;
if (set) filled.push(a.id); else { await mark(r); highlighted.push(a.id); }
}
done.add(i);
return { section: i, title: sec.title, filled, highlighted, missing: [], fallback: false };
return { section: i, title: sec.title, filled, highlighted, missing, fallback: false };
}
return { section: null, filled: [], highlighted: [], missing: [], fallback: false };
}
@ -634,6 +641,9 @@ export async function fillSession(b: ConsoleBrowser, o: FillSessionOpts): Promis
// a page still loading can miss a field for a moment: only a miss that lasts (3 rounds, at least 1.5 s) is a UI change
if (s.fallback && (++misses < 3 || Date.now() - firstMiss < 1500)) { if (misses === 1) firstMiss = Date.now(); await Bun.sleep(tick); continue; }
misses = 0;
// the miss lasts: fill every field that was found, leave the missing ones to the owner (only all-missing is a UI change)
if (s.fallback) { try { s = await fillPage(p, def, pageAnswers, done, true); } catch { await Bun.sleep(tick); continue; } }
if (!s.fallback && s.missing.length) warn(TAG, `${s.title}: could not find ${s.missing.map(id => labels.get(id) ?? id).join(', ')} on the page (the console UI may have changed): fill ${s.missing.length === 1 ? 'it' : 'them'} yourself`);
if (s.fallback) {
fallback = true;
warn(TAG, `the page does not match what storebound expects (${s.missing.join(', ')}): the console UI changed. Nothing more is filled; follow these steps:`);