Normalize fieldset legend text same as getLabel (dedup, strip Required)

Legend text was saved to answers.json with duplicated text and "Required"
suffix, causing pattern mismatches on future runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 13:27:40 -08:00
parent 4048d8e5c4
commit 615899e9a9

View File

@@ -411,7 +411,16 @@ Answer:`;
// Fieldsets (radios and checkbox groups)
for (const fs of await container.$$('fieldset')) {
const leg = await fs.$eval('legend', el => el.textContent.trim()).catch(() => '');
const leg = await fs.$eval('legend', el => {
let raw = (el.textContent || '').replace(/\s+/g, ' ').replace(/\s*\*\s*$/, '').replace(/\s*Required\s*$/i, '').trim();
if (raw.length > 8) {
for (let len = Math.ceil(raw.length / 2); len >= 4; len--) {
const candidate = raw.slice(0, len);
if (raw.startsWith(candidate + candidate)) { raw = candidate.trim(); break; }
}
}
return raw;
}).catch(() => '');
if (!leg) continue;
const anyChecked = await fs.$('input:checked');
if (anyChecked) continue;