@sun-asterisk/sungen 3.2.7 → 3.2.8

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.
Files changed (46) hide show
  1. package/dist/cli/commands/delivery.d.ts +25 -0
  2. package/dist/cli/commands/delivery.d.ts.map +1 -1
  3. package/dist/cli/commands/delivery.js +23 -1
  4. package/dist/cli/commands/delivery.js.map +1 -1
  5. package/dist/exporters/api-testcase-formatter.d.ts.map +1 -1
  6. package/dist/exporters/api-testcase-formatter.js +80 -4
  7. package/dist/exporters/api-testcase-formatter.js.map +1 -1
  8. package/dist/exporters/csv-exporter.d.ts.map +1 -1
  9. package/dist/exporters/csv-exporter.js +6 -1
  10. package/dist/exporters/csv-exporter.js.map +1 -1
  11. package/dist/exporters/types.d.ts +5 -0
  12. package/dist/exporters/types.d.ts.map +1 -1
  13. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/column-cell-assertion.hbs +3 -3
  14. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-empty.hbs +1 -1
  15. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-match-data.hbs +2 -2
  16. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-count.hbs +1 -1
  17. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-exists.hbs +2 -2
  18. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-not-exists.hbs +2 -2
  19. package/dist/generators/test-generator/step-mapper.d.ts +6 -2
  20. package/dist/generators/test-generator/step-mapper.d.ts.map +1 -1
  21. package/dist/generators/test-generator/step-mapper.js +10 -6
  22. package/dist/generators/test-generator/step-mapper.js.map +1 -1
  23. package/dist/orchestrator/templates/ai-src/skills/sungen-api-design/SKILL.md +8 -0
  24. package/dist/orchestrator/templates/ai-src/skills/sungen-error-mapping/SKILL.md +12 -1
  25. package/dist/orchestrator/templates/ai-src/skills/sungen-selector-fix/SKILL.md +3 -0
  26. package/dist/orchestrator/templates/specs-api.d.ts +14 -2
  27. package/dist/orchestrator/templates/specs-api.d.ts.map +1 -1
  28. package/dist/orchestrator/templates/specs-api.js +38 -14
  29. package/dist/orchestrator/templates/specs-api.js.map +1 -1
  30. package/dist/orchestrator/templates/specs-api.ts +43 -14
  31. package/package.json +3 -3
  32. package/src/cli/commands/delivery.ts +24 -4
  33. package/src/exporters/api-testcase-formatter.ts +77 -4
  34. package/src/exporters/csv-exporter.ts +6 -1
  35. package/src/exporters/types.ts +5 -0
  36. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/column-cell-assertion.hbs +3 -3
  37. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-empty.hbs +1 -1
  38. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-match-data.hbs +2 -2
  39. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-count.hbs +1 -1
  40. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-exists.hbs +2 -2
  41. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-not-exists.hbs +2 -2
  42. package/src/generators/test-generator/step-mapper.ts +10 -6
  43. package/src/orchestrator/templates/ai-src/skills/sungen-api-design/SKILL.md +8 -0
  44. package/src/orchestrator/templates/ai-src/skills/sungen-error-mapping/SKILL.md +12 -1
  45. package/src/orchestrator/templates/ai-src/skills/sungen-selector-fix/SKILL.md +3 -0
  46. package/src/orchestrator/templates/specs-api.ts +43 -14
@@ -82,8 +82,17 @@ export function formatApiRequest(
82
82
  const method = String(entry.method ?? '').toUpperCase() || '—';
83
83
  const api = entry.path ? resolve(String(entry.path)) : '—';
84
84
  const header = formatHeaders(entry, call.args, localize);
85
- const bodyStr = formatBody(entry.body, call.args, localize);
86
- return [`Method: ${method}`, `API: ${api}`, `Header: ${header}`, `Body: ${bodyStr}`].join('\n');
85
+ const lines = [`Method: ${method}`, `API: ${api}`, `Header: ${header}`];
86
+ // A file upload carries its parts in `files:` / `bodyFile:`, NOT `body:` — render them so the
87
+ // delivery Steps reflect the actual request (without this, fields like `gift_image` vanished from
88
+ // the export even though the compiled .spec.ts sent them).
89
+ const filesStr = formatFiles(entry.files, call.args, localize);
90
+ const bodyFileStr = formatBodyFile(entry.bodyFile, call.args, localize);
91
+ // Body is scalar fields; a pure file upload may have none → still show `Body: —` for a stable shape.
92
+ lines.push(`Body: ${formatBody(entry.body, call.args, localize)}`);
93
+ if (filesStr) lines.push(`Files: ${filesStr}`);
94
+ if (bodyFileStr) lines.push(`Body file: ${bodyFileStr}`);
95
+ return lines.join('\n');
87
96
  });
88
97
 
89
98
  if (blocks.length === 1) return blocks[0];
@@ -180,8 +189,14 @@ function formatHeaders(
180
189
  const parts = Object.entries(explicit).map(([k, v]) =>
181
190
  isSensitiveHeader(k) ? `${k}: ${maskHeaderValue(String(v))}` : `${k}: ${localize(bindParams(String(v), args))}`,
182
191
  );
183
- if (!hasContentType && entry.body !== undefined && entry.body !== null) {
184
- parts.push(`Content-Type: ${contentTypeFor(entry.encoding)}`);
192
+ // Content-Type the request actually sends (Playwright sets it at runtime): a `files:` block is always
193
+ // multipart/form-data (even with `encoding` omitted); a `bodyFile:` sends the file's own media type;
194
+ // otherwise it follows the body encoding. Only shown when the request carries a body/file and the
195
+ // catalog didn't already declare a Content-Type.
196
+ if (!hasContentType) {
197
+ const ct = uploadContentType(entry);
198
+ if (ct) parts.push(`Content-Type: ${ct}`);
199
+ else if (entry.body !== undefined && entry.body !== null) parts.push(`Content-Type: ${contentTypeFor(entry.encoding)}`);
185
200
  }
186
201
  return parts.length > 0 ? parts.join('\n') : '—';
187
202
  }
@@ -192,6 +207,14 @@ function contentTypeFor(encoding?: string): string {
192
207
  return 'application/json';
193
208
  }
194
209
 
210
+ /** Content-Type implied by a file upload, or '' when the entry sends no file. */
211
+ function uploadContentType(entry: ApiCatalogEntry): string {
212
+ if (entry.files && typeof entry.files === 'object' && Object.keys(entry.files).length) return 'multipart/form-data';
213
+ const bf = normalizeFileSpec(entry.bodyFile);
214
+ if (bf) return bf.mimeType || 'application/octet-stream';
215
+ return '';
216
+ }
217
+
195
218
  /**
196
219
  * Compose the Body cell, masking credential fields. When the body is a flat object
197
220
  * with a sensitive key (password/token/secret/…), each value is rendered per-key so
@@ -217,6 +240,56 @@ function isPlainObject(v: unknown): boolean {
217
240
  return typeof v === 'object' && v !== null && !Array.isArray(v);
218
241
  }
219
242
 
243
+ interface NormalizedFileSpec { path: string; mimeType?: string; filename?: string; name?: string }
244
+
245
+ /** Normalize a raw file spec (string shorthand or object) → a typed spec, or undefined if invalid. */
246
+ function normalizeFileSpec(raw: unknown): NormalizedFileSpec | undefined {
247
+ if (typeof raw === 'string') return { path: raw };
248
+ if (isPlainObject(raw)) {
249
+ const o = raw as Record<string, unknown>;
250
+ if (typeof o.path === 'string') {
251
+ return {
252
+ path: o.path,
253
+ mimeType: typeof o.mimeType === 'string' ? o.mimeType : undefined,
254
+ filename: typeof o.filename === 'string' ? o.filename : undefined,
255
+ name: typeof o.name === 'string' ? o.name : undefined,
256
+ };
257
+ }
258
+ }
259
+ return undefined;
260
+ }
261
+
262
+ /** Render one file part: `field: <path> (<mimeType>)`, with `:param`/`{{var}}` resolved. */
263
+ function renderFilePart(field: string, spec: NormalizedFileSpec, args: Record<string, string>, localize: (t: string) => string): string {
264
+ const p = localize(bindParams(spec.path, args));
265
+ return `${spec.name ?? field}: ${p}${spec.mimeType ? ` (${spec.mimeType})` : ''}`;
266
+ }
267
+
268
+ /**
269
+ * Render the `files:` block for the Steps cell. A field value may be a single spec, its string
270
+ * shorthand, or an array (multiple files under one field name) — every part is rendered. Multiple
271
+ * parts are comma-joined. Returns '' when there is no file field.
272
+ */
273
+ function formatFiles(files: unknown, args: Record<string, string>, localize: (t: string) => string): string {
274
+ if (!isPlainObject(files)) return '';
275
+ const parts: string[] = [];
276
+ for (const [field, raw] of Object.entries(files as Record<string, unknown>)) {
277
+ for (const s of Array.isArray(raw) ? raw : [raw]) {
278
+ const spec = normalizeFileSpec(s);
279
+ if (spec) parts.push(renderFilePart(field, spec, args, localize));
280
+ }
281
+ }
282
+ return parts.join(', ');
283
+ }
284
+
285
+ /** Render the `bodyFile:` (raw-binary body) for the Steps cell, or '' when absent. */
286
+ function formatBodyFile(bodyFile: unknown, args: Record<string, string>, localize: (t: string) => string): string {
287
+ const spec = normalizeFileSpec(bodyFile);
288
+ if (!spec) return '';
289
+ const p = localize(bindParams(spec.path, args));
290
+ return `${p} (${spec.mimeType || 'application/octet-stream'})`;
291
+ }
292
+
220
293
  /**
221
294
  * Credential name matcher (substring, not anchored) for both body-field keys and
222
295
  * test-data keys — catches variants like confirmPassword / new_password /
@@ -183,7 +183,12 @@ export function buildTestCaseRows(input: BuildCsvInput): TestCaseRow[] {
183
183
  steps,
184
184
  expectedResults,
185
185
  priority,
186
- testcaseType: m.spec ? testcaseType : testcaseType === 'Manual' ? 'Manual' : 'Not compiled',
186
+ // An execution `result` proves the scenario compiled AND ran it MUST win over the
187
+ // `!m.spec` "not compiled" heuristic, exactly as the testResult branch above does. A @cases
188
+ // scenario compiles to per-row titles with a `— <label>` suffix, so findMatchingSpecTest
189
+ // (base-name match) often leaves m.spec null even though the row ran; without checking result
190
+ // here, those already-passed/failed rows were mislabelled "Not compiled".
191
+ testcaseType: (m.spec || result) ? testcaseType : testcaseType === 'Manual' ? 'Manual' : 'Not compiled',
187
192
  testResult,
188
193
  executedDate,
189
194
  testExecutor: executor,
@@ -177,5 +177,10 @@ export interface ApiCatalogEntry {
177
177
  * Absent/`json` → application/json, `form` → application/x-www-form-urlencoded,
178
178
  * `multipart` → multipart/form-data. */
179
179
  encoding?: 'json' | 'form' | 'multipart';
180
+ /** Multipart file parts (multipart/form-data). A field value may be a single file spec, its string
181
+ * shorthand, or an array of specs (multiple files under one field name). Typed loosely — guard before use. */
182
+ files?: Record<string, unknown>;
183
+ /** Raw-binary body: the request body IS the file's bytes. Typed loosely — guard before use. */
184
+ bodyFile?: unknown;
180
185
  expect?: { status?: number | string };
181
186
  }
@@ -1,3 +1,3 @@
1
- await expect({{> locator}}.getByRole('columnheader', { name: '{{columnName}}' })).toBeVisible();
2
- const {{columnIndexVar}} = (await page.getByRole('columnheader').allTextContents()).findIndex(h => h.includes('{{columnName}}'));
3
- await expect(page.getByRole('row').nth({{rowNth}}).getByRole('cell').nth({{columnIndexVar}})).toHaveText('{{dataValue}}');
1
+ await expect({{> locator}}.getByRole('columnheader', { name: '{{columnName}}', includeHidden: true })).toBeVisible();
2
+ const {{columnIndexVar}} = (await page.getByRole('columnheader', { includeHidden: true }).filter({ visible: true }).allTextContents()).findIndex(h => h.includes('{{columnName}}'));
3
+ await expect(page.getByRole('row', { includeHidden: true }).filter({ visible: true }).nth({{rowNth}}).getByRole('cell', { includeHidden: true }).filter({ visible: true }).nth({{columnIndexVar}})).toHaveText('{{dataValue}}');
@@ -1 +1 @@
1
- await expect({{> locator}}.locator('tbody').getByRole('row')).toHaveCount(0);
1
+ await expect({{> locator}}.locator('tbody').getByRole('row', { includeHidden: true }).filter({ visible: true })).toHaveCount(0);
@@ -1,13 +1,13 @@
1
1
  {{~#if isGiven~}}
2
2
  {
3
- const rows = {{> locator}}.locator('tbody').getByRole('row');
3
+ const rows = {{> locator}}.locator('tbody').getByRole('row', { includeHidden: true }).filter({ visible: true });
4
4
  {{#each assertions}}
5
5
  {{this}}
6
6
  {{/each~}}
7
7
  }
8
8
  {{~else~}}
9
9
  {
10
- const rows = {{> locator}}.locator('tbody').getByRole('row');
10
+ const rows = {{> locator}}.locator('tbody').getByRole('row', { includeHidden: true }).filter({ visible: true });
11
11
  {{#each assertions}}
12
12
  {{this}}
13
13
  {{/each~}}
@@ -1 +1 @@
1
- await expect({{> locator}}.locator('tbody').getByRole('row')).toHaveCount({{expectedCount}});
1
+ await expect({{> locator}}.locator('tbody').getByRole('row', { includeHidden: true }).filter({ visible: true })).toHaveCount({{expectedCount}});
@@ -1,7 +1,7 @@
1
1
  {{~#if isGiven}}
2
- const tableRow = {{> locator}}.getByRole('row').filter({ hasText: '{{escapeQuotes filterValue}}' });
2
+ const tableRow = {{> locator}}.getByRole('row', { includeHidden: true }).filter({ hasText: '{{escapeQuotes filterValue}}' }).filter({ visible: true });
3
3
  await tableRow.waitFor();
4
4
  {{~else}}
5
- const tableRow = {{> locator}}.getByRole('row').filter({ hasText: '{{escapeQuotes filterValue}}' });
5
+ const tableRow = {{> locator}}.getByRole('row', { includeHidden: true }).filter({ hasText: '{{escapeQuotes filterValue}}' }).filter({ visible: true });
6
6
  await expect(tableRow).toBeVisible();
7
7
  {{~/if}}
@@ -1,5 +1,5 @@
1
1
  {{~#if isGiven}}
2
- await {{> locator}}.getByRole('row').filter({ hasText: '{{escapeQuotes filterValue}}' }).waitFor({ state: 'hidden' });
2
+ await {{> locator}}.getByRole('row', { includeHidden: true }).filter({ hasText: '{{escapeQuotes filterValue}}' }).filter({ visible: true }).waitFor({ state: 'hidden' });
3
3
  {{~else}}
4
- await expect({{> locator}}.getByRole('row').filter({ hasText: '{{escapeQuotes filterValue}}' })).toHaveCount(0);
4
+ await expect({{> locator}}.getByRole('row', { includeHidden: true }).filter({ hasText: '{{escapeQuotes filterValue}}' }).filter({ visible: true })).toHaveCount(0);
5
5
  {{~/if}}
@@ -229,8 +229,12 @@ export class StepMapper {
229
229
  * Generate column assertion scoped to the current row.
230
230
  * Uses columns config for exact cell targeting (nth), or filter fallback.
231
231
  *
232
- * With columns: await expect(tableRow.getByRole('cell').nth(index)).toHaveText('value');
233
- * Without: await expect(tableRow.getByRole('cell').filter({ hasText: 'value' })).toBeVisible();
232
+ * With columns: await expect(tableRow.getByRole('cell', { includeHidden: true }).filter({ visible: true }).nth(index)).toHaveText('value');
233
+ * Without: await expect(tableRow.getByRole('cell', { includeHidden: true }).filter({ hasText: 'value' }).filter({ visible: true })).toBeVisible();
234
+ *
235
+ * includeHidden + visible filter: when a modal (e.g. Radix Dialog) is open the
236
+ * background gets aria-hidden="true", which empties plain getByRole() even though
237
+ * the cells are still rendered — measure what the user SEES, not the a11y tree.
234
238
  */
235
239
  private generateRowScopedColumnAssertion(step: ParsedStep): MappedStep {
236
240
  const columnRef = step.selectorRef || '';
@@ -259,16 +263,16 @@ export class StepMapper {
259
263
  if (columnIndex !== undefined) {
260
264
  // Exact cell: nth(index) + toHaveText
261
265
  if (isGiven) {
262
- code = `await expect(tableRow.getByRole('cell').nth(${columnIndex})).toHaveText('${escapedValue}');`;
266
+ code = `await expect(tableRow.getByRole('cell', { includeHidden: true }).filter({ visible: true }).nth(${columnIndex})).toHaveText('${escapedValue}');`;
263
267
  } else {
264
- code = `await expect(tableRow.getByRole('cell').nth(${columnIndex})).toHaveText('${escapedValue}');`;
268
+ code = `await expect(tableRow.getByRole('cell', { includeHidden: true }).filter({ visible: true }).nth(${columnIndex})).toHaveText('${escapedValue}');`;
265
269
  }
266
270
  } else {
267
271
  // Fallback: filter by text
268
272
  if (isGiven) {
269
- code = `await tableRow.getByRole('cell').filter({ hasText: '${escapedValue}' }).waitFor();`;
273
+ code = `await tableRow.getByRole('cell', { includeHidden: true }).filter({ hasText: '${escapedValue}' }).filter({ visible: true }).waitFor();`;
270
274
  } else {
271
- code = `await expect(tableRow.getByRole('cell').filter({ hasText: '${escapedValue}' })).toBeVisible();`;
275
+ code = `await expect(tableRow.getByRole('cell', { includeHidden: true }).filter({ hasText: '${escapedValue}' }).filter({ visible: true })).toBeVisible();`;
272
276
  }
273
277
  }
274
278
 
@@ -72,6 +72,14 @@ A flow (`create → login → delete`) is a **Functional integration** test, **n
72
72
  ## File upload (real files)
73
73
  `body:` carries only scalar fields — to send a **real file**, declare it in the catalog entry; the runtime reads the fixture from disk. Two forms, by how the server accepts the file:
74
74
  - **`files:`** → `multipart/form-data`, the file is a form part: `files: { file: { path: ":avatar", mimeType: image/png } }` (+ optional text `body:` fields alongside). Shorthand `files: { file: ":avatar" }`.
75
+ - **Multiple files under ONE field name** → make the field's value an **array** (each element a spec or shorthand string):
76
+ ```yaml
77
+ files:
78
+ gift_image:
79
+ - ":gift_image_1" # test-data: gift_image_1 → fixtures/a.png
80
+ - ":gift_image_2" # test-data: gift_image_2 → fixtures/b.png
81
+ ```
82
+ Each element binds its own `:param` from test-data. Use this for endpoints that accept a list of files under the same field — a single object value can only hold one file. **Automate multi-file uploads with `@api`; don't defer to `@manual`.** (File uploads use Playwright's `FormData` multipart, which requires **`@playwright/test` ≥ 1.44** — the version sungen installs by default; only projects pinned to an older Playwright need to upgrade.)
75
83
  - **`bodyFile:`** → raw binary body (the whole body IS the file's bytes, e.g. `application/octet-stream`): `bodyFile: { path: ":image", mimeType: application/octet-stream }`.
76
84
 
77
85
  Fixture path resolves cwd-relative/absolute first, else `qa/fixtures/<path>` (drop sample files there, reference by name from `test-data`). An empty resolved file param omits the part → use for missing-file `@cases` error rows. `files:`/`bodyFile:` are mutually exclusive. **Automate the upload success case with `@api`** — don't defer it to `@manual`.
@@ -91,7 +91,7 @@ needs any of these, it is a **finding for QA** — surface it in the run summary
91
91
  | toHaveValue mismatch | Expected value differs from actual | Fix value in test-data |
92
92
  | toContainText mismatch | Partial text not found | Fix expected partial text in test-data |
93
93
  | toBeVisible timeout | Element exists but hidden, or name wrong | Check: is element conditionally visible? Wrong name? Inside dialog? |
94
- | toHaveCount mismatch | Row count differs | Fix expected count in test-data. Verify: is table loaded? Filtered? |
94
+ | toHaveCount mismatch | Row count differs | Fix expected count in test-data. Verify: is table loaded? Filtered? If `Received: 0` while a dialog is open → aria-hidden trap, see **Table-Specific Errors** |
95
95
 
96
96
  ### Assertion type rule
97
97
 
@@ -111,6 +111,7 @@ If `toHaveText` fails on an input → the Gherkin step has the wrong target type
111
111
  | `tableRow is not defined` | Column assertion without preceding row scope step | The Gherkin is missing a row-scope step — this is a **QA authoring gap → report it, let it FAIL**. Do NOT add the step during run-test (the Gherkin is frozen). |
112
112
  | `toHaveText` on cell fails (with columns) | Wrong column index in `columns` config | Re-count columns in snapshot (0-indexed). Fix `index` in selectors.yaml |
113
113
  | `toBeVisible` on cell fails (no columns) | `filter({ hasText })` didn't match | Check exact cell text in snapshot. Fix value in test-data |
114
+ | Row/cell count reads 0 while a dialog is open, rows visibly present behind it | **aria-hidden trap**: the modal (Radix/MUI/HeadlessUI…) sets `aria-hidden="true"` on the background; plain `getByRole('row'/'cell')` reads the a11y tree, which is empty behind a modal. Twin symptom: count-0 assertions (`table is empty`, `row not exists`) false-PASS under the same condition | Re-run `sungen generate` — table locators from sungen ≥3.2.8 emit `getByRole(…, { includeHidden: true }).filter({ visible: true })` and are immune. Do NOT edit the expected count or weaken the assertion — the rows exist; the old locator measured the wrong tree |
114
115
  | Row filter matches 0 rows | Filter text doesn't match any row content | Re-snapshot → find actual row text. Fix filter value in test-data |
115
116
  | Row filter matches multiple rows | Filter text is too generic (matches multiple rows) | Use more specific filter text (unique identifier like email, ID) |
116
117
  | Table not found | Wrong table name or table not rendered | Re-snapshot → copy exact table accessible name |
@@ -153,6 +154,16 @@ If `toHaveText` fails on an input → the Gherkin step has the wrong target type
153
154
 
154
155
  ---
155
156
 
157
+ ## API Request Errors (`@api` / catalog)
158
+
159
+ | Error | Diagnosis | Fix |
160
+ |---|---|---|
161
+ | `400 "Unexpected field"` on a file upload | Endpoint accepts **multiple files under one field**, but the catalog declared a single file (one part sent) | In `apis.yaml`, make that `files:` field an **array** — one `:param` per file: `files: { gift_image: [":gift_image_1", ":gift_image_2"] }`. Add matching `test-data` paths. This is a real automatable case — do NOT defer to `@manual`. |
162
+ | `415 Unsupported Media Type` on upload | Sent multipart where the endpoint wants a raw binary body (or vice-versa) | Use `bodyFile:` (raw binary body) instead of `files:` (multipart part), or the reverse — they are mutually exclusive. |
163
+ | `fixture "…" not found` | The referenced file isn't on disk | Drop the sample file under `qa/fixtures/` and reference it by name from `test-data`. |
164
+
165
+ ---
166
+
156
167
  ## Performance & Infrastructure Errors → Fix in `specs/base.ts`
157
168
 
158
169
  All generated `.spec.ts` import from `specs/base.ts` — shared context caching, navigation, overlay cleanup. AI **can and should** tune `base.ts` to match the project.
@@ -282,9 +282,12 @@ Report results. Do NOT enter another fix loop here.
282
282
  | `toHaveText` / `toHaveValue` mismatch | Wrong expected data | `test-data.yaml` |
283
283
  | `page.goto` error | Wrong URL | page selector in `selectors.yaml` |
284
284
  | `frame` error | Element inside iframe | add `frame` field |
285
+ | `role` selector resolves to 0 elements **while a dialog is open**, element visibly rendered behind it | aria-hidden trap — the modal sets `aria-hidden="true"` on the background; role locators read the a11y tree | see aria-hidden note below — NOT a name mismatch, don't churn the selector name |
285
286
 
286
287
  **Group by root cause** — if 5 tests fail because `[Submit]` button has a different name, that's 1 fix, not 5.
287
288
 
289
+ > **aria-hidden trap** (element exists in the screenshot, locator says 0, a modal is open): compiled TABLE steps are immune from sungen ≥3.2.8 (`includeHidden` + `visible` filter) — if the failing generated code lacks that, re-run `sungen generate` first. For a **user-defined `role` selector** asserted while a dialog is open, the selector name is NOT the problem: prefer restructuring the scenario to assert after the dialog closes; if asserting behind the modal is genuinely intended, switch that selector to `testid` or an allowed `locator` CSS (both DOM-based, immune to aria-hidden). Never "fix" it by renaming the role.
290
+
288
291
  **Check `test-results/` first** — Playwright captures failure screenshots automatically. Use these to diagnose before any MCP exploration.
289
292
 
290
293
  ### Step 2: Targeted MCP Exploration
@@ -80,6 +80,46 @@ export function resolveFixture(p: string, label: string): string {
80
80
  throw new Error(`API Driver: ${label} — fixture "${p}" not found (looked in ${direct} and qa/fixtures/${p}).`);
81
81
  }
82
82
 
83
+ /**
84
+ * Build the multipart FormData body for a file-upload request. A field's value may be a single spec
85
+ * OR an array of specs — an array sends MULTIPLE files under the SAME field name, which a plain object
86
+ * cannot express (a repeated key would overwrite). FormData.append keeps every part, so the request
87
+ * carries all files. Text `body` values ride along as form fields. An empty resolved path omits that
88
+ * part (the missing-file / wrong-type error row). Exported for unit test (assert form.getAll entries).
89
+ *
90
+ * Blob (not File): the global File constructor only exists on Node ≥20 while this package supports
91
+ * Node ≥18; Blob is available on 18+. FormData wraps Blob + filename into a File part internally, so
92
+ * the wire result is identical.
93
+ */
94
+ export function buildMultipart(
95
+ files: Record<string, FileSpec | FileSpec[]>,
96
+ body: unknown,
97
+ params: Record<string, any>,
98
+ label: string,
99
+ ): FormData {
100
+ const form = new FormData();
101
+ // Append file parts first. A field's value may be a single spec or an array (multiple files under
102
+ // one name); FormData.append keeps every part where a plain object would overwrite on a repeated key.
103
+ for (const [field, raw] of Object.entries(files)) {
104
+ for (const s of Array.isArray(raw) ? raw : [raw]) {
105
+ const spec = typeof s === 'string' ? { path: s } : s;
106
+ const fpath = substituteRaw(String(spec.path), params);
107
+ if (!fpath) continue; // empty param → omit the part (a missing-file / wrong-type error row)
108
+ const resolved = resolveFixture(fpath, label);
109
+ const filename = spec.filename ?? path.basename(resolved);
110
+ const blob = new Blob([fs.readFileSync(resolved)], { type: spec.mimeType ?? inferMime(filename) });
111
+ form.append(spec.name ?? field, blob, filename);
112
+ }
113
+ }
114
+ // Text body fields ride along — but skip any name already added as a file part, so a catalog that
115
+ // declares the same key in both body: and files: sends ONE part (the file wins), matching the prior
116
+ // plain-object behaviour rather than emitting a duplicate field a strict server would reject.
117
+ if (body && typeof body === 'object')
118
+ for (const [k, v] of Object.entries(body as Record<string, unknown>))
119
+ if (!form.has(k)) form.append(k, typeof v === 'string' ? v : JSON.stringify(v));
120
+ return form;
121
+ }
122
+
83
123
  /**
84
124
  * Join a datasource base URL with a catalog path. Concatenate rather than rely on Playwright's
85
125
  * baseURL resolution: an absolute path (`/user/1`) resolves against the base ORIGIN and would drop
@@ -113,7 +153,7 @@ class ApiClient {
113
153
  */
114
154
  async call(
115
155
  label: string,
116
- req: { method: string; path: string; body?: unknown; encoding?: 'json' | 'form' | 'multipart'; files?: Record<string, FileSpec>; bodyFile?: FileSpec; headers?: Record<string, string>; timeout?: number; datasource?: string },
156
+ req: { method: string; path: string; body?: unknown; encoding?: 'json' | 'form' | 'multipart'; files?: Record<string, FileSpec | FileSpec[]>; bodyFile?: FileSpec; headers?: Record<string, string>; timeout?: number; datasource?: string },
117
157
  params: Record<string, any> = {},
118
158
  opts: { storageState?: string } = {},
119
159
  ): Promise<{ status: number; ok: boolean; body: any; headers: Record<string, string> }> {
@@ -150,21 +190,10 @@ class ApiClient {
150
190
  headers['content-type'] = spec.mimeType ?? 'application/octet-stream';
151
191
  }
152
192
  } else if (req.files && Object.keys(req.files).length) {
153
- const mp: Record<string, any> = {};
154
- if (body && typeof body === 'object')
155
- for (const [k, v] of Object.entries(body as Record<string, unknown>)) mp[k] = typeof v === 'string' ? v : JSON.stringify(v);
156
- for (const [field, raw] of Object.entries(req.files)) {
157
- const spec = typeof raw === 'string' ? { path: raw } : raw;
158
- const fpath = substituteRaw(String(spec.path), params);
159
- if (!fpath) continue; // empty param → omit the part (a missing-file / wrong-type error row)
160
- const resolved = resolveFixture(fpath, label);
161
- const filename = spec.filename ?? path.basename(resolved);
162
- mp[spec.name ?? field] = { name: filename, mimeType: spec.mimeType ?? inferMime(filename), buffer: fs.readFileSync(resolved) };
163
- }
164
193
  // Playwright generates the multipart/form-data Content-Type (with boundary); drop any datasource
165
194
  // default Content-Type so it doesn't conflict with / duplicate the generated one.
166
195
  deleteHeader(headers, 'content-type');
167
- bodyOpt.multipart = mp;
196
+ bodyOpt.multipart = buildMultipart(req.files, body, params, label);
168
197
  } else if (body !== undefined) {
169
198
  const enc = req.encoding ?? 'json';
170
199
  if (enc === 'form') bodyOpt.form = body;
@@ -201,7 +230,7 @@ class ApiClient {
201
230
  */
202
231
  async callN(
203
232
  label: string,
204
- req: { method: string; path: string; body?: unknown; encoding?: 'json' | 'form' | 'multipart'; files?: Record<string, FileSpec>; bodyFile?: FileSpec; headers?: Record<string, string>; timeout?: number; datasource?: string },
233
+ req: { method: string; path: string; body?: unknown; encoding?: 'json' | 'form' | 'multipart'; files?: Record<string, FileSpec | FileSpec[]>; bodyFile?: FileSpec; headers?: Record<string, string>; timeout?: number; datasource?: string },
205
234
  params: Record<string, any> = {},
206
235
  n = 1,
207
236
  opts: { storageState?: string } = {},