diff --git a/.claude/skills/web-test/scripts/browser.mjs b/.claude/skills/web-test/scripts/browser.mjs index 1056bba6..94723e71 100644 --- a/.claude/skills/web-test/scripts/browser.mjs +++ b/.claude/skills/web-test/scripts/browser.mjs @@ -143,7 +143,7 @@ import { _detectPlatformDialogs, _closePlatformDialogs, } from './core/errors.mjs'; import { - safeClick, findFieldInputId, readEdd, + safeClick, findFieldInputId, readEdd, returnFormState, detectNewForm as helperDetectNewForm, } from './core/helpers.mjs'; // Re-export only what was publicly exported before the refactor. @@ -215,10 +215,7 @@ export async function openCommand(name) { if (result?.error) throw new Error(`openCommand: "${name}" not found. Available: ${result.available?.join(', ') || 'none'}`); await waitForStable(formBefore); - const state = await getFormState(); - const err = await checkForErrors(); - if (err) state.errors = err; - return state; + return await returnFormState(); } /** Switch to an open tab by name (fuzzy match). Returns updated form state. */ @@ -390,10 +387,7 @@ export async function navigateLink(url) { } await waitForStable(formBefore); - const state = await getFormState(); - const err = await checkForErrors(); - if (err) state.errors = err; - return state; + return await returnFormState(); } /** Read current form state. Single evaluate call via combined script. */ diff --git a/.claude/skills/web-test/scripts/core/helpers.mjs b/.claude/skills/web-test/scripts/core/helpers.mjs index 4b8615e1..810cf2a9 100644 --- a/.claude/skills/web-test/scripts/core/helpers.mjs +++ b/.claude/skills/web-test/scripts/core/helpers.mjs @@ -3,7 +3,8 @@ // Source: https://github.com/Nikolay-Shirokov/cc-1c-skills import { page } from './state.mjs'; -import { dismissPendingErrors } from './errors.mjs'; +import { dismissPendingErrors, checkForErrors } from './errors.mjs'; +import { getFormState } from '../browser.mjs'; /** * page.click with the standard "intercepts pointer events" retry ladder: @@ -105,3 +106,23 @@ export async function readEdd() { }; })()`); } + +/** + * Standard "tail" of action functions: fetch current form state, attach + * caller-specified extras (e.g. `{ clicked: {...} }`) and the result of + * `checkForErrors()` if any. Returns the flat state object. + * + * Unifies ~15 hand-written copies in clickElement, selectValue, closeForm, + * navigation functions, etc. Also closes R1/R2/R3 from the refactor plan — + * any caller using this helper gets `state.errors` for free. + * + * @param {object} [extras] — merged into the state object via Object.assign. + * @returns {Promise} form state (flat) with optional `errors`. + */ +export async function returnFormState(extras = {}) { + const state = await getFormState(); + Object.assign(state, extras); + const err = await checkForErrors(); + if (err) state.errors = err; + return state; +}