Merge origin/main into shots-glyphs

This commit is contained in:
CRTkafa 2026-10-12 03:13:05 +08:00
commit 296aa6a6ae
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) { if (f.names?.length) {
let g = await find(root, 'radiogroup', f.names); let g = await find(root, 'radiogroup', f.names);
if (g.state === 'none') g = await find(root, 'group', 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' }; if (g.state === 'ambiguous') return { field: f, ok: false, seen: true };
scope = g.loc; 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> = {}; const options: Record<string, Locator> = {};
let ok = true; let ok = true;
@ -87,7 +89,8 @@ async function resolve(root: Locator, f: FieldDef): Promise<Resolved> {
const r = await find(scope, 'radio', names); 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; } 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). */ /** 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 * 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). * 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])); const byId = new Map(answers.map(a => [a.id, a]));
for (const [i, sec] of def.sections.entries()) { for (const [i, sec] of def.sections.entries()) {
if (done.has(i)) continue; 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)); for (const f of sec.fields) rs.push(await resolve(root, f));
if (!sec.dialog && !rs.some(r => r.seen)) continue; if (!sec.dialog && !rs.some(r => r.seen)) continue;
const missing = rs.filter(r => !r.ok).map(r => r.field.id); 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 }; // only when no field of the section can be found is it a UI change; otherwise fill what was found and leave the
const filled: string[] = [], highlighted: string[] = []; // 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) { for (const r of rs) {
if (!r.ok) continue;
const a = byId.get(r.field.id); const a = byId.get(r.field.id);
if (!a) continue; if (!a) continue;
const set = a.certain && a.value !== null ? await setField(r, a.value) : false; 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); } if (set) filled.push(a.id); else { await mark(r); highlighted.push(a.id); }
} }
done.add(i); 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 }; 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 // 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; } if (s.fallback && (++misses < 3 || Date.now() - firstMiss < 1500)) { if (misses === 1) firstMiss = Date.now(); await Bun.sleep(tick); continue; }
misses = 0; 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) { if (s.fallback) {
fallback = true; 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:`); warn(TAG, `the page does not match what storebound expects (${s.missing.join(', ')}): the console UI changed. Nothing more is filled; follow these steps:`);

View file

@ -225,6 +225,29 @@ describe.skipIf(!browser)('engine (headless, modeled pages)', () => {
await page.close(); await page.close();
}); });
test('User Access under a plain heading (real App Store Connect): the radios are found in the dialog', async () => {
const page = await open('apple-app-record-heading.html');
const s = await fillPage(page, formDef('apple-app-record', pageAnswers('apple-app-record')), pageAnswers('apple-app-record'));
expect(s.fallback).toBe(false);
expect(s.missing).toEqual([]);
expect(s.filled).toContain('name');
expect(await clicks(page)).toEqual([]);
await page.close();
});
test('a lasting partial miss fills every field that was found and leaves only the missing one', async () => {
const page = await open('apple-app-record-renamed.html');
const def = formDef('apple-app-record', pageAnswers('apple-app-record'));
const s = await fillPage(page, def, pageAnswers('apple-app-record'), new Set(), true);
expect(s.fallback).toBe(false);
expect(s.missing).toEqual(['name']);
expect(s.highlighted).toContain('name');
expect(s.filled).toContain('bundleId');
expect(await checked(page, 'iOS')).toBe(true);
expect(await clicks(page)).toEqual([]);
await page.close();
});
test('a renamed label stops filling and falls back to guidance', async () => { test('a renamed label stops filling and falls back to guidance', async () => {
const page = await open('apple-app-record-renamed.html'); const page = await open('apple-app-record-renamed.html');
const s = await fillPage(page, formDef('apple-app-record', pageAnswers('apple-app-record')), pageAnswers('apple-app-record')); const s = await fillPage(page, formDef('apple-app-record', pageAnswers('apple-app-record')), pageAnswers('apple-app-record'));

View file

@ -0,0 +1,23 @@
<!doctype html>
<!-- MODELED from a real report (2026-10-12): User Access is a plain heading, not a fieldset/group. Not recorded: a sanitized stand-in for App Store Connect > Apps > + > New App, written from Apple's public
help page "Add a new app" (platforms, Name, Primary Language, Bundle ID, SKU, User Access, Create).
Placeholder data only. -->
<html lang="en"><head><meta charset="utf-8"><title>Apps - App Store Connect</title><script src="_common.js"></script></head>
<body>
<h1>Apps</h1>
<div role="dialog" aria-labelledby="t" data-step>
<h2 id="t">New App</h2>
<fieldset><legend>Platforms</legend>
<label><input type="checkbox"> iOS</label> <label><input type="checkbox"> macOS</label>
<label><input type="checkbox"> tvOS</label> <label><input type="checkbox"> visionOS</label>
</fieldset>
<p><label>Name <input type="text" maxlength="30"></label></p>
<p><label>Primary Language <select><option value="">Choose</option><option>English (U.K.)</option><option>English (U.S.)</option><option>Turkish</option></select></label></p>
<p><label>Bundle ID <select><option value="">Choose</option><option>Other App - com.example.other</option><option>Example Game - com.example.game</option></select></label></p>
<p><label>SKU <input type="text"></label></p>
<div class="h">User Access</div><div>
<label><input type="radio" name="access"> Limited Access</label> <label><input type="radio" name="access"> Full Access</label>
</div>
<button type="button">Help</button> <button type="button">Cancel</button> <button type="button">Create</button>
</div>
</body></html>