@sun-asterisk/sungen 3.2.4 → 3.2.5

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 (41) hide show
  1. package/dist/cli/commands/dashboard.js +2 -2
  2. package/dist/cli/commands/dashboard.js.map +1 -1
  3. package/dist/cli/commands/delivery.d.ts.map +1 -1
  4. package/dist/cli/commands/delivery.js +22 -5
  5. package/dist/cli/commands/delivery.js.map +1 -1
  6. package/dist/dashboard/snapshot-builder.d.ts +3 -0
  7. package/dist/dashboard/snapshot-builder.d.ts.map +1 -1
  8. package/dist/dashboard/snapshot-builder.js +47 -19
  9. package/dist/dashboard/snapshot-builder.js.map +1 -1
  10. package/dist/dashboard/templates/index.html +2 -2
  11. package/dist/dashboard/types.d.ts +4 -0
  12. package/dist/dashboard/types.d.ts.map +1 -1
  13. package/dist/exporters/api-testcase-formatter.d.ts +55 -0
  14. package/dist/exporters/api-testcase-formatter.d.ts.map +1 -0
  15. package/dist/exporters/api-testcase-formatter.js +304 -0
  16. package/dist/exporters/api-testcase-formatter.js.map +1 -0
  17. package/dist/exporters/csv-exporter.d.ts +13 -1
  18. package/dist/exporters/csv-exporter.d.ts.map +1 -1
  19. package/dist/exporters/csv-exporter.js +24 -2
  20. package/dist/exporters/csv-exporter.js.map +1 -1
  21. package/dist/exporters/types.d.ts +7 -0
  22. package/dist/exporters/types.d.ts.map +1 -1
  23. package/dist/generators/test-generator/patterns/index.d.ts +12 -0
  24. package/dist/generators/test-generator/patterns/index.d.ts.map +1 -1
  25. package/dist/generators/test-generator/patterns/index.js +21 -1
  26. package/dist/generators/test-generator/patterns/index.js.map +1 -1
  27. package/dist/orchestrator/project-initializer.d.ts +14 -0
  28. package/dist/orchestrator/project-initializer.d.ts.map +1 -1
  29. package/dist/orchestrator/project-initializer.js +58 -0
  30. package/dist/orchestrator/project-initializer.js.map +1 -1
  31. package/package.json +4 -3
  32. package/src/cli/commands/dashboard.ts +2 -2
  33. package/src/cli/commands/delivery.ts +24 -6
  34. package/src/dashboard/snapshot-builder.ts +46 -19
  35. package/src/dashboard/templates/index.html +2 -2
  36. package/src/dashboard/types.ts +5 -1
  37. package/src/exporters/api-testcase-formatter.ts +325 -0
  38. package/src/exporters/csv-exporter.ts +36 -3
  39. package/src/exporters/types.ts +7 -0
  40. package/src/generators/test-generator/patterns/index.ts +21 -1
  41. package/src/orchestrator/project-initializer.ts +59 -0
@@ -39,8 +39,12 @@ export interface AggregateSummary {
39
39
  }
40
40
 
41
41
  export interface ScreenSnapshot {
42
- name: string; // "kudos" or "flow/checkout" — the screen DIRECTORY name
42
+ name: string; // "kudos", "flow/checkout", or "api/login" — the unit label
43
43
  isFlow: boolean;
44
+ /** Unit kind — screen | flow | api. Drives the dashboard's suite badge so API
45
+ * suites read as API rather than being mislabelled "web". Optional so history
46
+ * snapshots written before this field still parse (they render as screen). */
47
+ kind?: 'screen' | 'flow' | 'api';
44
48
  platform?: 'web' | 'android' | 'ios' | 'mobile'; // 'mobile' = @platform:mobile screen (per-OS features below)
45
49
  featureName: string; // name of the primary (first) feature; kept for backwards compat
46
50
  featurePath?: string; // entry-point path of the primary feature
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Render an API test case's Steps / Expected-results cells for the delivery report.
3
+ *
4
+ * API scenarios carry no Given/When steps and assert against runtime response
5
+ * refs (`expect {{endpoint.status}} is 201`), so the generic row builder leaves
6
+ * the Steps cell empty and the Expected cell showing raw `{{…}}`. This module
7
+ * turns the scenario's `@api:<name>(args)` tag + the apis.yaml catalog into a
8
+ * human-readable request block (Method / API / Header / Body) and rewrites the
9
+ * assertions into "Status / Response" language.
10
+ *
11
+ * Deterministic — no AI, no network. Everything is sourced from the catalog +
12
+ * scenario tags + test-data, mirroring exactly what the generated request sends
13
+ * (see orchestrator/templates/specs-api.ts: catalog headers + a Content-Type
14
+ * implied by the body wire format; `:param` falls back to the same-named
15
+ * test-data key when the tag omits it).
16
+ */
17
+
18
+ import { ApiCatalogEntry } from './types';
19
+
20
+ /** A single `@api:<name>(k=v,…)` invocation parsed from a scenario's tags. */
21
+ export interface ApiCall {
22
+ name: string;
23
+ /** param → value expression, kept raw: `{{new_email}}`, `"literal"`, `3`. */
24
+ args: Record<string, string>;
25
+ }
26
+
27
+ /** True when the scenario invokes at least one `@api:` endpoint. */
28
+ export function hasApiCalls(tags: string[]): boolean {
29
+ return tags.some((t) => t.startsWith('@api:'));
30
+ }
31
+
32
+ /**
33
+ * Parse the ordered `@api:<name>(arg=expr,…)` invocations from a scenario's tags.
34
+ * Mirrors the driver's override grammar: split the top-level comma list, then the
35
+ * first `=` per pair. Values stay as raw expressions so the caller resolves them
36
+ * the same way the runtime does.
37
+ */
38
+ /**
39
+ * Same shape the runtime accepts (`driver-api/src/index.ts`): `@api:<name>` with an
40
+ * optional balanced `(...)` arg list. A malformed tag (e.g. unclosed paren) is rejected
41
+ * here too, so the report never documents a call the runtime silently dropped.
42
+ */
43
+ const API_TAG = /^@api:([A-Za-z_][A-Za-z0-9_]*)(?:\((.*)\))?$/;
44
+
45
+ export function parseApiCalls(tags: string[]): ApiCall[] {
46
+ const calls: ApiCall[] = [];
47
+ for (const t of tags) {
48
+ const m = API_TAG.exec(t);
49
+ if (!m) continue;
50
+ const args: Record<string, string> = {};
51
+ for (const pair of splitTopLevel(m[2] ?? '')) {
52
+ const eq = pair.indexOf('=');
53
+ if (eq < 0) continue;
54
+ args[pair.slice(0, eq).trim()] = pair.slice(eq + 1).trim();
55
+ }
56
+ calls.push({ name: m[1], args });
57
+ }
58
+ return calls;
59
+ }
60
+
61
+ /**
62
+ * Build the "Steps" cell for an API test case: one block per invoked endpoint,
63
+ * showing Method / API (resolved path) / Header / Body. Endpoints absent from the
64
+ * catalog are skipped. Returns '' when nothing resolves (caller keeps generic Steps).
65
+ *
66
+ * `localize` resolves `{{var}}` test-data placeholders (and selector keys) to
67
+ * concrete values — the same resolver the row builder uses for UI steps.
68
+ */
69
+ export function formatApiRequest(
70
+ tags: string[],
71
+ catalog: Record<string, ApiCatalogEntry>,
72
+ localize: (text: string) => string,
73
+ ): string {
74
+ const calls = parseApiCalls(tags).filter((c) => catalog[c.name]);
75
+ if (calls.length === 0) return '';
76
+
77
+ const blocks = calls.map((call) => {
78
+ const entry = catalog[call.name];
79
+ const resolve = (raw: string): string => localize(bindParams(raw, call.args));
80
+ // Coerce method/path — loadApiCatalog is a raw passthrough, so a malformed entry
81
+ // (numeric method/path) must degrade gracefully, not crash the unit's export.
82
+ const method = String(entry.method ?? '').toUpperCase() || '—';
83
+ const api = entry.path ? resolve(String(entry.path)) : '—';
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');
87
+ });
88
+
89
+ if (blocks.length === 1) return blocks[0];
90
+ // Multiple endpoints (flow) — number them so the call order is explicit.
91
+ return blocks
92
+ .map((b, i) => b.split('\n').map((l, j) => (j === 0 ? `${i + 1}. ${l}` : ` ${l}`)).join('\n'))
93
+ .join('\n');
94
+ }
95
+
96
+ /**
97
+ * Rewrite an API scenario's `Then` assertions into readable Status / Response lines.
98
+ * Raw assertions reference the runtime response object
99
+ * (`expect {{endpoint.status}} is 201`, `expect {{endpoint.body.email}} is {{x}}`);
100
+ * we strip the endpoint prefix (a runtime var, meaningless to a reader), keep the
101
+ * field path, label status vs body, and resolve `{{var}}` on the right-hand side.
102
+ */
103
+ export function formatApiExpected(
104
+ expectedSteps: Array<{ text: string }>,
105
+ tags: string[],
106
+ localize: (text: string) => string,
107
+ ): string {
108
+ const endpointNames = parseApiCalls(tags).map((c) => c.name);
109
+ const oracleNames = parseQueryOracles(tags);
110
+ const lines = expectedSteps
111
+ .map((s) => humanizeAssertion(s.text, endpointNames, oracleNames, localize))
112
+ .filter((l) => l.length > 0);
113
+ if (lines.length === 0) return '';
114
+ if (lines.length === 1) return lines[0];
115
+ return lines.map((l, i) => `${i + 1}. ${l}`).join('\n');
116
+ }
117
+
118
+ // ---------------------------------------------------------------------------
119
+ // Internals
120
+ // ---------------------------------------------------------------------------
121
+
122
+ /** Split a comma list, ignoring commas nested inside {}/[]/() so `{a,b}` stays whole. */
123
+ function splitTopLevel(s: string): string[] {
124
+ const out: string[] = [];
125
+ let depth = 0;
126
+ let cur = '';
127
+ for (const ch of s) {
128
+ if (ch === '{' || ch === '[' || ch === '(') depth++;
129
+ else if (ch === '}' || ch === ']' || ch === ')') depth = Math.max(0, depth - 1);
130
+ if (ch === ',' && depth === 0) {
131
+ out.push(cur);
132
+ cur = '';
133
+ } else {
134
+ cur += ch;
135
+ }
136
+ }
137
+ if (cur.trim().length > 0) out.push(cur);
138
+ return out;
139
+ }
140
+
141
+ /**
142
+ * Substitute `:param` tokens (path / body / header templates) with the invocation's
143
+ * arg expression, falling back to `{{param}}` when the tag omits it — matching the
144
+ * runtime, where an unbound param resolves from the same-named test-data key.
145
+ */
146
+ function bindParams(raw: string, args: Record<string, string>): string {
147
+ return raw.replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, (_m, p: string) => {
148
+ const expr = p in args ? args[p] : `{{${p}}}`;
149
+ return unquoteExpr(expr);
150
+ });
151
+ }
152
+
153
+ /** Strip a matching pair of surrounding quotes from a tag-arg literal (`"x"` → `x`). */
154
+ function unquoteExpr(e: string): string {
155
+ const m = e.match(/^"(.*)"$/) || e.match(/^'(.*)'$/);
156
+ return m ? m[1] : e;
157
+ }
158
+
159
+ /**
160
+ * Compose the Header cell from catalog `headers:` (with `:param` bound + `{{var}}`
161
+ * resolved) plus the Content-Type implied by the body wire format — Playwright sets
162
+ * that Content-Type from the encoding option at runtime (specs-api.ts), shown only
163
+ * when a body is sent and the catalog didn't already declare one. Returns '—' when
164
+ * the request has none.
165
+ *
166
+ * Scope: this reflects the per-endpoint catalog headers only. Datasource-level headers
167
+ * (`conf.headers` from the datasources config, merged at runtime) are NOT read here —
168
+ * the exporter doesn't load `.env.qa`/datasources — so the cell is a catalog view, not
169
+ * a byte-for-byte copy of the wire request.
170
+ */
171
+ function formatHeaders(
172
+ entry: ApiCatalogEntry,
173
+ args: Record<string, string>,
174
+ localize: (text: string) => string,
175
+ ): string {
176
+ const explicit = entry.headers && typeof entry.headers === 'object' ? entry.headers : {};
177
+ const hasContentType = Object.keys(explicit).some((k) => k.toLowerCase() === 'content-type');
178
+ // Auth headers (authorization/cookie/api-key…) carry credentials — show the scheme
179
+ // but mask the value. A value-based redaction pass (redactSecrets) backstops this.
180
+ const parts = Object.entries(explicit).map(([k, v]) =>
181
+ isSensitiveHeader(k) ? `${k}: ${maskHeaderValue(String(v))}` : `${k}: ${localize(bindParams(String(v), args))}`,
182
+ );
183
+ if (!hasContentType && entry.body !== undefined && entry.body !== null) {
184
+ parts.push(`Content-Type: ${contentTypeFor(entry.encoding)}`);
185
+ }
186
+ return parts.length > 0 ? parts.join('\n') : '—';
187
+ }
188
+
189
+ function contentTypeFor(encoding?: string): string {
190
+ if (encoding === 'form') return 'application/x-www-form-urlencoded';
191
+ if (encoding === 'multipart') return 'multipart/form-data';
192
+ return 'application/json';
193
+ }
194
+
195
+ /**
196
+ * Compose the Body cell, masking credential fields. When the body is a flat object
197
+ * with a sensitive key (password/token/secret/…), each value is rendered per-key so
198
+ * that field can be replaced with `***`; otherwise the body resolves wholesale
199
+ * (preserving numbers/nesting exactly as before).
200
+ */
201
+ function formatBody(body: unknown, args: Record<string, string>, localize: (text: string) => string): string {
202
+ if (body === undefined || body === null) return '—';
203
+ if (isPlainObject(body)) {
204
+ const obj = body as Record<string, unknown>;
205
+ if (Object.keys(obj).some(isSensitiveField)) {
206
+ const out: Record<string, string> = {};
207
+ for (const [k, v] of Object.entries(obj)) {
208
+ out[k] = isSensitiveField(k) ? '***' : localize(bindParams(typeof v === 'string' ? v : JSON.stringify(v), args));
209
+ }
210
+ return JSON.stringify(out);
211
+ }
212
+ }
213
+ return localize(bindParams(typeof body === 'string' ? body : JSON.stringify(body), args));
214
+ }
215
+
216
+ function isPlainObject(v: unknown): boolean {
217
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
218
+ }
219
+
220
+ /**
221
+ * Credential name matcher (substring, not anchored) for both body-field keys and
222
+ * test-data keys — catches variants like confirmPassword / new_password /
223
+ * password_confirmation / access_token / client_secret / otp / passcode.
224
+ */
225
+ const SENSITIVE_NAME = /pass(word|code)?|passwd|pwd|secret|token|otp|api[-_]?key|apikey|credential|authorization/i;
226
+ function isSensitiveField(key: string): boolean {
227
+ return SENSITIVE_NAME.test(key);
228
+ }
229
+
230
+ /**
231
+ * Resolved values of sensitive test-data keys — used for a value-based redaction pass
232
+ * over the finished Steps/Expected cells, closing the paths key-based masking misses
233
+ * (nested request bodies, query-string credentials, and the Expected assertion cell).
234
+ * Values shorter than 3 chars are skipped to avoid masking trivial/coincidental text.
235
+ */
236
+ export function collectSecretValues(testData: Record<string, string>): string[] {
237
+ const secrets: string[] = [];
238
+ for (const [k, v] of Object.entries(testData)) {
239
+ if (typeof v === 'string' && v.length >= 3 && SENSITIVE_NAME.test(k)) secrets.push(v);
240
+ }
241
+ // Longest-first so a longer secret is redacted before any shorter substring of it.
242
+ return [...new Set(secrets)].sort((a, b) => b.length - a.length);
243
+ }
244
+
245
+ /** Replace every occurrence of each secret value with `***` (literal, not regex). */
246
+ export function redactSecrets(text: string, secrets: string[]): string {
247
+ if (secrets.length === 0 || !text) return text;
248
+ let out = text;
249
+ for (const s of secrets) out = out.split(s).join('***');
250
+ return out;
251
+ }
252
+
253
+ /** Header names that carry credentials — value masked, scheme kept. */
254
+ const SENSITIVE_HEADER = /^(authorization|proxy-authorization|cookie|set-cookie|x-api-key|api-key|x-auth-token|x-access-token|x-session-token)$/i;
255
+ function isSensitiveHeader(name: string): boolean {
256
+ return SENSITIVE_HEADER.test(name);
257
+ }
258
+
259
+ /** Keep an auth scheme prefix (Bearer/Basic/…) but hide the credential. */
260
+ function maskHeaderValue(value: string): string {
261
+ const m = value.match(/^(Bearer|Basic|Digest|Token)\b/i);
262
+ return m ? `${m[1]} ***` : '***';
263
+ }
264
+
265
+ /** Ordered `@query:<oracle>` DB-oracle names (a @concurrent idempotency cross-check). */
266
+ function parseQueryOracles(tags: string[]): string[] {
267
+ return tags
268
+ .filter((t) => t.startsWith('@query:'))
269
+ .map((t) => {
270
+ const body = t.slice('@query:'.length);
271
+ const parenIdx = body.indexOf('(');
272
+ return parenIdx >= 0 ? body.slice(0, parenIdx) : body;
273
+ });
274
+ }
275
+
276
+ /**
277
+ * Turn one raw assertion line into a readable Status/Response statement.
278
+ * `{{<endpoint>.<field>}}` → a labelled response reference; `{{<oracle>.<field>}}`
279
+ * (a @query DB oracle) → the plain dotted path; remaining `{{var}}` (genuine
280
+ * test-data on the right-hand side) is resolved by `localize`.
281
+ */
282
+ function humanizeAssertion(
283
+ raw: string,
284
+ endpointNames: string[],
285
+ oracleNames: string[],
286
+ localize: (text: string) => string,
287
+ ): string {
288
+ let s = raw.trim().replace(/^expect\s+/i, '');
289
+ // Field path allows array-index segments so @concurrent refs like
290
+ // `{{login.responses[0].body.token}}` are matched, not left as raw `{{…}}`.
291
+ const FIELD = '(?:[\\w.]|\\[\\d+\\])+';
292
+ if (endpointNames.length > 0) {
293
+ const alt = endpointNames.map(escapeRe).join('|');
294
+ s = s.replace(new RegExp(`\\{\\{\\s*(?:${alt})\\.(${FIELD})\\s*\\}\\}`, 'g'), (_m, field: string) =>
295
+ responseFieldLabel(field),
296
+ );
297
+ }
298
+ if (oracleNames.length > 0) {
299
+ // @query oracle refs read as a DB check — strip the `{{ }}` noise, keep `oracle.field`.
300
+ const alt = oracleNames.map(escapeRe).join('|');
301
+ s = s.replace(new RegExp(`\\{\\{\\s*((?:${alt})\\.${FIELD})\\s*\\}\\}`, 'g'), (_m, ref: string) => ref);
302
+ }
303
+ s = localize(s);
304
+ if (s.length === 0) return s;
305
+ // Don't recase a line that leads with a @query oracle identifier (a code name) —
306
+ // `user_count.count is 1` must not become `User_count.count is 1`.
307
+ const leadsWithOracle = oracleNames.some((o) => s === o || s.startsWith(`${o}.`));
308
+ return leadsWithOracle ? s : s.charAt(0).toUpperCase() + s.slice(1);
309
+ }
310
+
311
+ /** Map a response field path (after the `<endpoint>.` prefix) to reader-friendly text. */
312
+ function responseFieldLabel(field: string): string {
313
+ if (field === 'status') return 'Status';
314
+ if (field === 'ok') return 'Response ok';
315
+ if (field === 'ok_count') return 'Success count';
316
+ if (field === 'body') return 'Response body';
317
+ if (field.startsWith('body.')) return `Response body.${field.slice('body.'.length)}`;
318
+ if (field.startsWith('status_counts.')) return `Count of ${field.slice('status_counts.'.length)} responses`;
319
+ if (field.startsWith('headers.')) return `Response header "${field.slice('headers.'.length)}"`;
320
+ return `Response ${field}`;
321
+ }
322
+
323
+ function escapeRe(s: string): string {
324
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
325
+ }
@@ -22,7 +22,8 @@ import {
22
22
  formatNote,
23
23
  statusToTestResult,
24
24
  } from './playwright-report-parser';
25
- import { EnvironmentInfo, PlaywrightResult, ScreenSummary, TestCaseRow } from './types';
25
+ import { ApiCatalogEntry, EnvironmentInfo, PlaywrightResult, ScreenSummary, TestCaseRow } from './types';
26
+ import { collectSecretValues, formatApiExpected, formatApiRequest, hasApiCalls, redactSecrets } from './api-testcase-formatter';
26
27
  import { SelectorKeyMap, substituteSelectorKeysInStep } from './selector-key-resolver';
27
28
 
28
29
  export interface BuildCsvInput {
@@ -43,6 +44,18 @@ export interface BuildCsvInput {
43
44
  * instead of the VI selector key "Click [VỀ KUDOS] link".
44
45
  */
45
46
  selectorKeyMap?: SelectorKeyMap;
47
+ /**
48
+ * Unit kind. When `'api'`, the row builder renders the request contract
49
+ * (Method/API/Header/Body) into the Steps cell and the response contract
50
+ * (Status + Response) into the Expected cell — API scenarios otherwise leave
51
+ * Steps empty and Expected showing raw `{{endpoint.field}}` refs.
52
+ */
53
+ kind?: 'screen' | 'flow' | 'api';
54
+ /**
55
+ * apis.yaml catalog (keyed by endpoint name) for api-kind units. Supplies the
56
+ * Method/path/headers/body/encoding the readable request block is built from.
57
+ */
58
+ apiCatalog?: Record<string, ApiCatalogEntry>;
46
59
  }
47
60
 
48
61
  /**
@@ -97,15 +110,35 @@ export function buildTestCaseRows(input: BuildCsvInput): TestCaseRow[] {
97
110
  localize(s.bucket === 'given' ? keepActor(s.text) : stripActor(s.text));
98
111
  const stepLines = m.resolvedSteps.map(formatStep).filter(Boolean);
99
112
  const expectedLines = m.resolvedExpected.map(formatStep).filter(Boolean);
100
- const steps =
113
+ let steps =
101
114
  stepLines.length === 0 ? '' :
102
115
  stepLines.length === 1 ? stepLines[0] :
103
116
  stepLines.map((l, i) => `${i + 1}. ${l}`).join('\n');
104
- const expectedResults =
117
+ let expectedResults =
105
118
  expectedLines.length === 0 ? '' :
106
119
  expectedLines.length === 1 ? expectedLines[0] :
107
120
  expectedLines.map((l, i) => `${i + 1}. ${l}`).join('\n');
108
121
 
122
+ // API test cases: the scenario has no Given/When (Steps empty) and asserts
123
+ // against runtime response refs (`{{endpoint.status}}` — left literal since
124
+ // they aren't test-data keys). Render the request contract into Steps and the
125
+ // response contract into Expected from the @api tag + apis.yaml catalog, so
126
+ // QA reads Method/API/Header/Body and Status/Response instead of raw refs.
127
+ if (input.kind === 'api' && input.apiCatalog && hasApiCalls(m.feature.tags)) {
128
+ const apiRequest = formatApiRequest(m.feature.tags, input.apiCatalog, localize);
129
+ if (apiRequest) steps = steps ? `${steps}\n\n${apiRequest}` : apiRequest;
130
+ const apiExpected = formatApiExpected(m.resolvedExpected, m.feature.tags, localize);
131
+ if (apiExpected) expectedResults = apiExpected;
132
+ // Value-based redaction backstop: mask resolved credential values (from
133
+ // sensitively-named test-data keys) anywhere in the API cells — closes the
134
+ // nested-body, query-string and Expected-cell paths key-based masking misses.
135
+ const secrets = collectSecretValues(input.testData);
136
+ if (secrets.length > 0) {
137
+ steps = redactSecrets(steps, secrets);
138
+ expectedResults = redactSecrets(expectedResults, secrets);
139
+ }
140
+ }
141
+
109
142
  // Multi-line bullet format keeps delivery CSV/XLSX in sync with the
110
143
  // dashboard's Test data section. Multi-line CSV cells are valid (quoted
111
144
  // automatically) and render natively as multi-line in XLSX.
@@ -170,5 +170,12 @@ export interface ApiCatalogEntry {
170
170
  description?: string;
171
171
  body?: unknown;
172
172
  params?: unknown;
173
+ /** Per-endpoint header templates (e.g. authorization: "Bearer :token"); `:param` tokens
174
+ * bind at runtime from the same args as the body/path. */
175
+ headers?: Record<string, string>;
176
+ /** Request-body wire format — decides the Content-Type the request sends.
177
+ * Absent/`json` → application/json, `form` → application/x-www-form-urlencoded,
178
+ * `multipart` → multipart/form-data. */
179
+ encoding?: 'json' | 'form' | 'multipart';
173
180
  expect?: { status?: number | string };
174
181
  }
@@ -4,6 +4,23 @@ import { StepPattern, PatternContext } from './types';
4
4
  import { capabilityRegistry } from '../../../capabilities/registry';
5
5
  import { discoverAndRegisterCapabilities } from '../../../capabilities/discover';
6
6
 
7
+ /**
8
+ * Mask the CONTENT of selector refs `[...]` and data placeholders `{{...}}` before verb matching,
9
+ * keeping the delimiters. A step's verb/keywords come from the SENTENCE — never from a selector or
10
+ * variable NAME — but matchers scan `step.text` with substring checks (e.g. `includes('click')`),
11
+ * so a data ref like `{{double_click_guard_account.email}}` would spuriously satisfy the click
12
+ * matcher and pre-empt fill. The content is replaced with an inert placeholder (`~` — carries no
13
+ * verb/keyword/digit substring) rather than emptied, so structural matchers that require a NON-EMPTY
14
+ * ref survive too — e.g. `expect {{a}} is {{b}}` matches `\{\{[^}]+\}\}`, and `in [X] table` /
15
+ * `/\bto\s+\[/` keep their delimiters. The resolver/generator always receives the ORIGINAL step, so
16
+ * value extraction and codegen are unaffected.
17
+ */
18
+ export function maskRefsForMatching(text: string): string {
19
+ return text
20
+ .replace(/\{\{[^}]*\}\}/g, '{{~}}')
21
+ .replace(/\[[^\]]*\]/g, '[~]');
22
+ }
23
+
7
24
  /**
8
25
  * Pattern Registry - manages all step patterns
9
26
  */
@@ -40,8 +57,11 @@ export class PatternRegistry {
40
57
  * Find matching pattern for a step
41
58
  */
42
59
  findPattern(step: ParsedStep): StepPattern | null {
60
+ // Match against text with ref CONTENTS masked, so a verb substring inside a selector/data name
61
+ // (e.g. "click" in `{{double_click_guard_account.email}}`) can't hijack the verb classification.
62
+ const matchStep: ParsedStep = { ...step, text: maskRefsForMatching(step.text) };
43
63
  for (const pattern of this.patterns) {
44
- if (this.matchesPattern(step, pattern.matcher)) {
64
+ if (this.matchesPattern(matchStep, pattern.matcher)) {
45
65
  return pattern;
46
66
  }
47
67
  }
@@ -23,6 +23,37 @@ function sungenVersion(): string {
23
23
  catch { return '0.0.0'; }
24
24
  }
25
25
 
26
+ /**
27
+ * Header written atop a NEW `.codex/config.toml`. Codex loads a PROJECT-scoped config.toml only
28
+ * for TRUSTED projects — without trust the MCP server silently never loads — so the note tells the
29
+ * user how to enable it. (Claude reads `.mcp.json` and Copilot `.vscode/mcp.json` with no such gate.)
30
+ */
31
+ const CODEX_MCP_HEADER = [
32
+ '# Sungen — Codex MCP config (project-scoped, gives run-test the same live browser as Claude/Copilot).',
33
+ '# NOTE: Codex loads a project .codex/config.toml ONLY for TRUSTED projects. If the browser tools',
34
+ '# never appear, trust this project (open it with `codex` and approve, or set trust_level = "trusted"',
35
+ '# for this path in ~/.codex/config.toml). To add Figma too, see https://mcp.figma.com/mcp.',
36
+ '',
37
+ '',
38
+ ].join('\n');
39
+
40
+ /**
41
+ * Append-if-absent merge for Codex's TOML MCP config. Mirrors `mergeMCPConfig`'s "user edits win"
42
+ * contract: preserves the existing file and any user-defined `[mcp_servers.*]`, and only appends the
43
+ * sungen server table when it is missing. Returns `null` when the target server is already present
44
+ * (nothing to write). TOML by hand (no toml dep) — the block is a fixed, simple table.
45
+ */
46
+ export function mergeCodexMcpToml(existing: string, mobileOnly: boolean): string | null {
47
+ const serverKey = mobileOnly ? 'appium-mcp' : 'playwright';
48
+ // Already configured (by the user or a previous run) → preserve, do nothing.
49
+ if (new RegExp(String.raw`^\s*\[mcp_servers\.(?:"?${serverKey}"?)\]`, 'm').test(existing)) return null;
50
+ const block = mobileOnly
51
+ ? '[mcp_servers.appium-mcp]\ncommand = "npx"\nargs = ["-y", "appium-mcp"]\n'
52
+ : '[mcp_servers.playwright]\ncommand = "npx"\nargs = ["@playwright/mcp@latest"]\n';
53
+ if (existing.trim() === '') return CODEX_MCP_HEADER + block;
54
+ return existing + (existing.endsWith('\n') ? '\n' : '\n\n') + block;
55
+ }
56
+
26
57
  export class ProjectInitializer {
27
58
  private baseCwd: string;
28
59
  private cwd: string;
@@ -116,6 +147,12 @@ export class ProjectInitializer {
116
147
  // Create root .mcp.json for Claude Code
117
148
  this.createClaudeMCPConfig();
118
149
 
150
+ // Create .codex/config.toml for Codex CLI — only when Codex is a selected assistant
151
+ // (`sungen init --assistant codex`), since it is Codex-specific config.
152
+ if (this.agents.includes('codex')) {
153
+ this.createCodexMCPConfig();
154
+ }
155
+
119
156
  // Display summary
120
157
  this.displaySummary(normalizedProjectName);
121
158
  }
@@ -309,6 +346,28 @@ export class ProjectInitializer {
309
346
  );
310
347
  }
311
348
 
349
+ /**
350
+ * Create `.codex/config.toml` for Codex CLI — the Codex analog of `.mcp.json` (Claude) and
351
+ * `.vscode/mcp.json` (Copilot), so `sungen run-test` under Codex drives the same live Playwright
352
+ * MCP browser instead of Codex's own (headless) fallback. Mobile-only → appium-mcp. Append-only:
353
+ * preserves an existing file + any user server table (via `mergeCodexMcpToml`).
354
+ */
355
+ private createCodexMCPConfig(): void {
356
+ const filePath = path.join(this.cwd, '.codex', 'config.toml');
357
+ const dir = path.dirname(filePath);
358
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
359
+
360
+ const existed = fs.existsSync(filePath);
361
+ const existing = existed ? fs.readFileSync(filePath, 'utf-8') : '';
362
+ const merged = mergeCodexMcpToml(existing, this.mobileOnly);
363
+ if (merged === null) {
364
+ this.skippedItems.push('.codex/config.toml');
365
+ return;
366
+ }
367
+ fs.writeFileSync(filePath, merged, 'utf-8');
368
+ this.createdItems.push(existed ? '.codex/config.toml (updated)' : '.codex/config.toml');
369
+ }
370
+
312
371
  /**
313
372
  * Add MCP server entries without overwriting user config.
314
373
  * Preserves existing entries with the same key — user edits always win.