@cutleryapp/agent 1.0.42 → 1.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -448,10 +448,23 @@ class TestExecutor {
448
448
  }
449
449
  }
450
450
  catch (err) {
451
- // Log the errordo NOT call AI here, it's too slow and usually can't recover either
452
- console.log(` ⚠️ Step failed: ${err.message.split('\n')[0]}`);
453
- stepError = err.message;
454
- result.success = false;
451
+ // AI last-resort recoveryonly when Playwright strategies all failed
452
+ if (process.env.OPENAI_API_KEY) {
453
+ console.log(` 🤖 Playwright failed, trying AI: ${err.message.split('\n')[0]}`);
454
+ try {
455
+ await aiSingleShot(page, raw);
456
+ }
457
+ catch (aiErr) {
458
+ console.log(` ⚠️ AI recovery also failed: ${aiErr.message.split('\n')[0]}`);
459
+ stepError = err.message;
460
+ result.success = false;
461
+ }
462
+ }
463
+ else {
464
+ console.log(` ⚠️ Step failed: ${err.message.split('\n')[0]}`);
465
+ stepError = err.message;
466
+ result.success = false;
467
+ }
455
468
  }
456
469
  // Screenshot on failure, on the last step, or every 5 steps — not every step
457
470
  let screenshotB64 = "";
@@ -1249,39 +1262,27 @@ async function tryFill(page, label, value) {
1249
1262
  const labelRe = new RegExp(escapeRegex(label), "i");
1250
1263
  const variants = labelVariants(label);
1251
1264
  const attrContains = (attr) => variants.map(v => `input[${attr}*="${cssEscape(v)}" i], textarea[${attr}*="${cssEscape(v)}" i], [contenteditable="true"][${attr}*="${cssEscape(v)}" i]`).join(", ");
1252
- function withTimeout(fn, ms) {
1253
- return Promise.race([fn(), new Promise((_, r) => setTimeout(() => r(new Error('timeout')), ms))]);
1254
- }
1255
- // Phase 1: race the 3 highest-coverage strategies simultaneously (500ms cap)
1256
- // These cover labelled inputs, placeholder inputs, and role-textbox — 95%+ of forms
1257
- const phase1 = [
1258
- () => page.getByLabel(labelRe).first().fill(value),
1259
- () => page.getByPlaceholder(labelRe).first().fill(value),
1260
- () => page.getByRole("textbox", { name: labelRe }).first().fill(value),
1261
- ];
1262
- try {
1263
- await Promise.any(phase1.map(fn => withTimeout(fn, 500)));
1264
- return;
1265
- }
1266
- catch { /* all 3 failed, try phase 2 */ }
1267
- // Phase 2: attribute-based selectors covering name/id/data-test variants (300ms each)
1268
- const exactAttrs = variants.flatMap(v => [
1269
- `input[name="${cssEscape(v)}" i]`, `input[id="${cssEscape(v)}" i]`,
1270
- `textarea[name="${cssEscape(v)}" i]`, `textarea[id="${cssEscape(v)}" i]`,
1271
- ]).join(", ");
1272
- const phase2 = [
1273
- () => page.locator(exactAttrs).first().fill(value),
1274
- () => page.locator(`${attrContains("name")}, ${attrContains("id")}`).first().fill(value),
1275
- () => page.locator(attrContains("data-test")).first().fill(value),
1276
- () => page.locator(attrContains("aria-label")).first().fill(value),
1277
- () => page.locator(attrContains("placeholder")).first().fill(value),
1265
+ // Sequential strategies — do NOT run concurrently (concurrent fills can cross-contaminate fields)
1266
+ // Each uses a short timeout since if the element exists, Playwright resolves near-instantly.
1267
+ const strategies = [
1268
+ ['getByLabel', () => page.getByLabel(labelRe).first().fill(value)],
1269
+ ['getByPlaceholder', () => page.getByPlaceholder(labelRe).first().fill(value)],
1270
+ ['getByRole', () => page.getByRole("textbox", { name: labelRe }).first().fill(value)],
1271
+ ['id/name exact', () => page.locator(variants.flatMap(v => [
1272
+ `input[name="${cssEscape(v)}" i]`, `input[id="${cssEscape(v)}" i]`,
1273
+ `textarea[name="${cssEscape(v)}" i]`, `textarea[id="${cssEscape(v)}" i]`,
1274
+ ]).join(", ")).first().fill(value)],
1275
+ ['id/name contains', () => page.locator(`${attrContains("name")}, ${attrContains("id")}`).first().fill(value)],
1276
+ ['data-test', () => page.locator(attrContains("data-test")).first().fill(value)],
1277
+ ['aria-label', () => page.locator(attrContains("aria-label")).first().fill(value)],
1278
+ ['placeholder attr', () => page.locator(attrContains("placeholder")).first().fill(value)],
1278
1279
  ];
1279
- for (const fn of phase2) {
1280
+ for (const [, fn] of strategies) {
1280
1281
  try {
1281
- await withTimeout(fn, 300);
1282
+ await Promise.race([fn(), new Promise((_, r) => setTimeout(() => r(new Error('t')), 400))]);
1282
1283
  return;
1283
1284
  }
1284
- catch { /* next */ }
1285
+ catch { /* next strategy */ }
1285
1286
  }
1286
1287
  throw new Error(`Could not find input field: "${label}"`);
1287
1288
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutleryapp/agent",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "description": "Local agent that connects your machine to the Cutlery QA platform and runs UI tests via Playwright",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {