@sun-asterisk/sungen 3.1.2-beta.123 → 3.1.2-beta.125
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.
- package/dist/capabilities/sensor.d.ts +1 -0
- package/dist/capabilities/sensor.d.ts.map +1 -1
- package/dist/orchestrator/templates/ai-instructions/claude-cmd-run-test.md +1 -0
- package/dist/orchestrator/templates/ai-instructions/claude-skill-api-design.md +1 -0
- package/dist/orchestrator/templates/ai-instructions/copilot-cmd-run-test.md +1 -1
- package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-api-design.md +1 -0
- package/dist/orchestrator/templates/specs-api.d.ts +2 -0
- package/dist/orchestrator/templates/specs-api.d.ts.map +1 -1
- package/dist/orchestrator/templates/specs-api.js +16 -3
- package/dist/orchestrator/templates/specs-api.js.map +1 -1
- package/dist/orchestrator/templates/specs-api.ts +15 -5
- package/package.json +2 -2
- package/src/capabilities/sensor.ts +1 -1
- package/src/orchestrator/templates/ai-instructions/claude-cmd-run-test.md +1 -0
- package/src/orchestrator/templates/ai-instructions/claude-skill-api-design.md +1 -0
- package/src/orchestrator/templates/ai-instructions/copilot-cmd-run-test.md +1 -1
- package/src/orchestrator/templates/ai-instructions/github-skill-sungen-api-design.md +1 -0
- package/src/orchestrator/templates/specs-api.ts +15 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sensor.d.ts","sourceRoot":"","sources":["../../src/capabilities/sensor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACtC;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,OAAO;IACjC,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;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC1I,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B"}
|
|
@@ -44,6 +44,7 @@ If the unit is **api-first**, skip every selector/capture phase (an API test has
|
|
|
44
44
|
- **datasource/base_url unresolved** → set the `${X_URL}` key in `.env.qa`.
|
|
45
45
|
- **missing/empty bound param** → trace `{{var}}` to test-data or a prior `@api` response; fill it.
|
|
46
46
|
- **`expect.status` mismatch** → reconcile against `apis.yaml`/spec (the catalog is the oracle); **never hand-edit the generated spec** (re-`generate --area` instead).
|
|
47
|
+
- **400 "parameter missing" / body ignored** → the endpoint wants a form body, not JSON → set `encoding: form` (or `multipart`) on the catalog entry, re-`generate --area`. Don't mark the scenario `@manual`.
|
|
47
48
|
- **flaky** → enforce self-cleaning flows, per-row isolation (`@cases`), `@concurrent` caps.
|
|
48
49
|
5. **Integrity + trace** — `sungen script-check --area <name>` (verify the spec is a 1:1 of the Gherkin; on DRIFT re-`generate --area`, never hand-edit) and `sungen trace --area <name>` (process map + HUMAN-LOOP FOCUS). Then report + offer next steps.
|
|
49
50
|
|
|
@@ -36,6 +36,7 @@ Run `sungen audit --area <name>`; read `gateStatus` + `findings`. Then the **sem
|
|
|
36
36
|
| `VIEWPOINT-API-CONTRACT` | the endpoint is invoked but its response is never asserted → add `expect {{name.status}}` + a `{{name.body.…}}` check |
|
|
37
37
|
| `VIEWPOINT-API-ERROR` | a mutating endpoint has no failure scenario → add a `@cases` error matrix (or an explicit 4xx) |
|
|
38
38
|
| `VIEWPOINT-API-IDEMPOTENCY` | a mutating endpoint has no race check → add `@concurrent:N` + a `@query` DB cross-check |
|
|
39
|
+
| `VIEWPOINT-API-MANUAL-AUTOMATABLE` | a `@manual` scenario whose endpoint resolves is automatable → drop `@manual`, use `@api` (+ `@cases`); reserve `@manual` for genuine judgment cases |
|
|
39
40
|
| **`DEPTH-FAIL`** (businessDepth < 0.7) | a **mutating success** scenario asserts only `status` → make it **prove the effect**: assert a response **body** field, a **`@query`** side-effect, or a **`@concurrent` `ok_count`** invariant. (An error/`@cases` scenario proving the status is correct — it is *not* depth-required.) |
|
|
40
41
|
|
|
41
42
|
Stop when the gate PASSes + businessDepth ≥ 0.7, or the budget is exhausted → report residual gaps honestly (mark genuinely-unautomatable cases `@manual` with an oracle). Never fake a pass.
|
|
@@ -38,7 +38,7 @@ If the unit is **api-first**, skip every selector/capture phase (an API test has
|
|
|
38
38
|
1. **Resolve the datasource** — `base_url` + auth wired in `qa/datasources.yaml` + `.env.qa` (`${X_URL}` from `sungen api init`); a `production` datasource is refused unless `SUNGEN_ALLOW_PROD=1`.
|
|
39
39
|
2. **Compile**: `npx sungen generate --area <name>` → `specs/generated/api/<name>/`.
|
|
40
40
|
3. **Run**: `npx playwright test specs/generated/api/<name>/<name>.spec.ts`.
|
|
41
|
-
4. **Auto-fix** (use `sungen-error-mapping`): 401/403 → `@hybrid`+`@auth` or `Bearer :token` header (`sungen makeauth`); base_url unresolved → set `${X_URL}`; missing param → trace `{{var}}` to test-data/a prior `@api` response; `expect.status` mismatch → reconcile against `apis.yaml` (re-`generate --area`, never hand-edit the spec); flaky → self-clean + `@concurrent` caps.
|
|
41
|
+
4. **Auto-fix** (use `sungen-error-mapping`): 401/403 → `@hybrid`+`@auth` or `Bearer :token` header (`sungen makeauth`); base_url unresolved → set `${X_URL}`; missing param → trace `{{var}}` to test-data/a prior `@api` response; `expect.status` mismatch → reconcile against `apis.yaml` (re-`generate --area`, never hand-edit the spec); **400 "parameter missing" / body ignored → set `encoding: form` (or `multipart`) on the catalog entry, don't mark @manual**; flaky → self-clean + `@concurrent` caps.
|
|
42
42
|
5. **Integrity + trace** — `sungen script-check --area <name>` (1:1; on DRIFT re-`generate --area`, never hand-edit the spec) + `sungen trace --area <name>` (process map + HUMAN-LOOP FOCUS). Report + offer next steps.
|
|
43
43
|
|
|
44
44
|
## Pre-run (phased — per `sungen-selector-fix` skill)
|
|
@@ -36,6 +36,7 @@ Run `sungen audit --area <name>`; read `gateStatus` + `findings`. Then the **sem
|
|
|
36
36
|
| `VIEWPOINT-API-CONTRACT` | the endpoint is invoked but its response is never asserted → add `expect {{name.status}}` + a `{{name.body.…}}` check |
|
|
37
37
|
| `VIEWPOINT-API-ERROR` | a mutating endpoint has no failure scenario → add a `@cases` error matrix (or an explicit 4xx) |
|
|
38
38
|
| `VIEWPOINT-API-IDEMPOTENCY` | a mutating endpoint has no race check → add `@concurrent:N` + a `@query` DB cross-check |
|
|
39
|
+
| `VIEWPOINT-API-MANUAL-AUTOMATABLE` | a `@manual` scenario whose endpoint resolves is automatable → drop `@manual`, use `@api` (+ `@cases`); reserve `@manual` for genuine judgment cases |
|
|
39
40
|
| **`DEPTH-FAIL`** (businessDepth < 0.7) | a **mutating success** scenario asserts only `status` → make it **prove the effect**: assert a response **body** field, a **`@query`** side-effect, or a **`@concurrent` `ok_count`** invariant. (An error/`@cases` scenario proving the status is correct — it is *not* depth-required.) |
|
|
40
41
|
|
|
41
42
|
Stop when the gate PASSes + businessDepth ≥ 0.7, or the budget is exhausted → report residual gaps honestly (mark genuinely-unautomatable cases `@manual` with an oracle). Never fake a pass.
|
|
@@ -11,6 +11,7 @@ declare class ApiClient {
|
|
|
11
11
|
method: string;
|
|
12
12
|
path: string;
|
|
13
13
|
body?: unknown;
|
|
14
|
+
encoding?: 'json' | 'form' | 'multipart';
|
|
14
15
|
headers?: Record<string, string>;
|
|
15
16
|
datasource?: string;
|
|
16
17
|
}, params?: Record<string, any>, opts?: {
|
|
@@ -32,6 +33,7 @@ declare class ApiClient {
|
|
|
32
33
|
method: string;
|
|
33
34
|
path: string;
|
|
34
35
|
body?: unknown;
|
|
36
|
+
encoding?: 'json' | 'form' | 'multipart';
|
|
35
37
|
headers?: Record<string, string>;
|
|
36
38
|
datasource?: string;
|
|
37
39
|
}, params?: Record<string, any>, n?: number, opts?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specs-api.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/templates/specs-api.ts"],"names":[],"mappings":"AAmDA,cAAM,SAAS;IACb,OAAO,CAAC,OAAO,CAA8C;IAE7D,OAAO,CAAC,GAAG;IAWX;;;;;OAKG;IACG,IAAI,CACR,KAAK,EAAE,MAAM,EACb,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,
|
|
1
|
+
{"version":3,"file":"specs-api.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/templates/specs-api.ts"],"names":[],"mappings":"AAmDA,cAAM,SAAS;IACb,OAAO,CAAC,OAAO,CAA8C;IAE7D,OAAO,CAAC,GAAG;IAWX;;;;;OAKG;IACG,IAAI,CACR,KAAK,EAAE,MAAM,EACb,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,CAAC;QAAC,OAAO,CA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,MAAM,GAAG,WAAkB,CAAC"}
|
|
@@ -106,9 +106,22 @@ class ApiClient {
|
|
|
106
106
|
// catalog headers; :param tokens bind at runtime — raw (no URL-encoding, unlike the path)
|
|
107
107
|
for (const [k, v] of Object.entries(req.headers || {}))
|
|
108
108
|
headers[k] = String(v).replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, (_m, p) => String(params[p] ?? ''));
|
|
109
|
-
|
|
109
|
+
// Body: substitute `:param` into the body template (object values), then encode per `encoding`.
|
|
110
|
+
let body;
|
|
110
111
|
if (req.body !== undefined && req.body !== null) {
|
|
111
|
-
|
|
112
|
+
body = JSON.parse(JSON.stringify(req.body).replace(/":([A-Za-z_][A-Za-z0-9_]*)"/g, (_m, p) => JSON.stringify(params[p] ?? null)));
|
|
113
|
+
}
|
|
114
|
+
// Map the wire format to the right Playwright option (#345): json → data (application/json,
|
|
115
|
+
// default), form → form (application/x-www-form-urlencoded), multipart → multipart (form-data).
|
|
116
|
+
const bodyOpt = {};
|
|
117
|
+
if (body !== undefined) {
|
|
118
|
+
const enc = req.encoding ?? 'json';
|
|
119
|
+
if (enc === 'form')
|
|
120
|
+
bodyOpt.form = body;
|
|
121
|
+
else if (enc === 'multipart')
|
|
122
|
+
bodyOpt.multipart = body;
|
|
123
|
+
else
|
|
124
|
+
bodyOpt.data = body;
|
|
112
125
|
}
|
|
113
126
|
// Playwright APIRequestContext: same runner/report/retries as UI tests. @hybrid passes
|
|
114
127
|
// `storageState` (the @auth role's saved session) so the request shares the browser's
|
|
@@ -120,7 +133,7 @@ class ApiClient {
|
|
|
120
133
|
...(opts.storageState ? { storageState: opts.storageState } : {}),
|
|
121
134
|
});
|
|
122
135
|
try {
|
|
123
|
-
const res = await ctx.fetch(urlPath, { method: req.method, ...
|
|
136
|
+
const res = await ctx.fetch(urlPath, { method: req.method, ...bodyOpt });
|
|
124
137
|
const text = await res.text();
|
|
125
138
|
let parsed = text;
|
|
126
139
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
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C,MAAM;YAC9C,aAAa;YACb,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;SACzC,CAAC;IACJ,CAAC;CACF;AAEY,QAAA,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC"}
|
|
@@ -71,7 +71,7 @@ class ApiClient {
|
|
|
71
71
|
*/
|
|
72
72
|
async call(
|
|
73
73
|
label: string,
|
|
74
|
-
req: { method: string; path: string; body?: unknown; headers?: Record<string, string>; datasource?: string },
|
|
74
|
+
req: { method: string; path: string; body?: unknown; encoding?: 'json' | 'form' | 'multipart'; headers?: Record<string, string>; datasource?: string },
|
|
75
75
|
params: Record<string, any> = {},
|
|
76
76
|
opts: { storageState?: string } = {},
|
|
77
77
|
): Promise<{ status: number; ok: boolean; body: any; headers: Record<string, string> }> {
|
|
@@ -84,9 +84,19 @@ class ApiClient {
|
|
|
84
84
|
// catalog headers; :param tokens bind at runtime — raw (no URL-encoding, unlike the path)
|
|
85
85
|
for (const [k, v] of Object.entries(req.headers || {}))
|
|
86
86
|
headers[k] = String(v).replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, (_m, p) => String(params[p] ?? ''));
|
|
87
|
-
|
|
87
|
+
// Body: substitute `:param` into the body template (object values), then encode per `encoding`.
|
|
88
|
+
let body: any;
|
|
88
89
|
if (req.body !== undefined && req.body !== null) {
|
|
89
|
-
|
|
90
|
+
body = JSON.parse(JSON.stringify(req.body).replace(/":([A-Za-z_][A-Za-z0-9_]*)"/g, (_m, p) => JSON.stringify(params[p] ?? null)));
|
|
91
|
+
}
|
|
92
|
+
// Map the wire format to the right Playwright option (#345): json → data (application/json,
|
|
93
|
+
// default), form → form (application/x-www-form-urlencoded), multipart → multipart (form-data).
|
|
94
|
+
const bodyOpt: Record<string, unknown> = {};
|
|
95
|
+
if (body !== undefined) {
|
|
96
|
+
const enc = req.encoding ?? 'json';
|
|
97
|
+
if (enc === 'form') bodyOpt.form = body;
|
|
98
|
+
else if (enc === 'multipart') bodyOpt.multipart = body;
|
|
99
|
+
else bodyOpt.data = body;
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
// Playwright APIRequestContext: same runner/report/retries as UI tests. @hybrid passes
|
|
@@ -99,7 +109,7 @@ class ApiClient {
|
|
|
99
109
|
...(opts.storageState ? { storageState: opts.storageState } : {}),
|
|
100
110
|
});
|
|
101
111
|
try {
|
|
102
|
-
const res = await ctx.fetch(urlPath, { method: req.method, ...
|
|
112
|
+
const res = await ctx.fetch(urlPath, { method: req.method, ...bodyOpt });
|
|
103
113
|
const text = await res.text();
|
|
104
114
|
let parsed: any = text;
|
|
105
115
|
try { parsed = text ? JSON.parse(text) : null; } catch { /* non-JSON → keep text */ }
|
|
@@ -118,7 +128,7 @@ class ApiClient {
|
|
|
118
128
|
*/
|
|
119
129
|
async callN(
|
|
120
130
|
label: string,
|
|
121
|
-
req: { method: string; path: string; body?: unknown; headers?: Record<string, string>; datasource?: string },
|
|
131
|
+
req: { method: string; path: string; body?: unknown; encoding?: 'json' | 'form' | 'multipart'; headers?: Record<string, string>; datasource?: string },
|
|
122
132
|
params: Record<string, any> = {},
|
|
123
133
|
n = 1,
|
|
124
134
|
opts: { storageState?: string } = {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sun-asterisk/sungen",
|
|
3
|
-
"version": "3.1.2-beta.
|
|
3
|
+
"version": "3.1.2-beta.125",
|
|
4
4
|
"description": "Deterministic E2E Test Compiler - Gherkin + Selectors → Playwright tests",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=18.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@sungen/driver-ui": "3.1.2-beta.
|
|
36
|
+
"@sungen/driver-ui": "3.1.2-beta.125",
|
|
37
37
|
"@anthropic-ai/sdk": "^0.71.0",
|
|
38
38
|
"@babel/parser": "^7.28.5",
|
|
39
39
|
"@babel/traverse": "^7.28.5",
|
|
@@ -41,7 +41,7 @@ export interface GateInput {
|
|
|
41
41
|
screenName: string;
|
|
42
42
|
cwd: string;
|
|
43
43
|
featureText: string;
|
|
44
|
-
scenarios: Array<{ name: string; queryRefs?: string[]; apiRefs?: string[]; casesDataset?: string; stepsText?: string }>;
|
|
44
|
+
scenarios: Array<{ name: string; queryRefs?: string[]; apiRefs?: string[]; casesDataset?: string; stepsText?: string; manual?: boolean }>;
|
|
45
45
|
/** UI: universal-viewpoint theme gaps the coverage gate found (generic string list). */
|
|
46
46
|
universalGaps?: string[];
|
|
47
47
|
}
|
|
@@ -44,6 +44,7 @@ If the unit is **api-first**, skip every selector/capture phase (an API test has
|
|
|
44
44
|
- **datasource/base_url unresolved** → set the `${X_URL}` key in `.env.qa`.
|
|
45
45
|
- **missing/empty bound param** → trace `{{var}}` to test-data or a prior `@api` response; fill it.
|
|
46
46
|
- **`expect.status` mismatch** → reconcile against `apis.yaml`/spec (the catalog is the oracle); **never hand-edit the generated spec** (re-`generate --area` instead).
|
|
47
|
+
- **400 "parameter missing" / body ignored** → the endpoint wants a form body, not JSON → set `encoding: form` (or `multipart`) on the catalog entry, re-`generate --area`. Don't mark the scenario `@manual`.
|
|
47
48
|
- **flaky** → enforce self-cleaning flows, per-row isolation (`@cases`), `@concurrent` caps.
|
|
48
49
|
5. **Integrity + trace** — `sungen script-check --area <name>` (verify the spec is a 1:1 of the Gherkin; on DRIFT re-`generate --area`, never hand-edit) and `sungen trace --area <name>` (process map + HUMAN-LOOP FOCUS). Then report + offer next steps.
|
|
49
50
|
|
|
@@ -36,6 +36,7 @@ Run `sungen audit --area <name>`; read `gateStatus` + `findings`. Then the **sem
|
|
|
36
36
|
| `VIEWPOINT-API-CONTRACT` | the endpoint is invoked but its response is never asserted → add `expect {{name.status}}` + a `{{name.body.…}}` check |
|
|
37
37
|
| `VIEWPOINT-API-ERROR` | a mutating endpoint has no failure scenario → add a `@cases` error matrix (or an explicit 4xx) |
|
|
38
38
|
| `VIEWPOINT-API-IDEMPOTENCY` | a mutating endpoint has no race check → add `@concurrent:N` + a `@query` DB cross-check |
|
|
39
|
+
| `VIEWPOINT-API-MANUAL-AUTOMATABLE` | a `@manual` scenario whose endpoint resolves is automatable → drop `@manual`, use `@api` (+ `@cases`); reserve `@manual` for genuine judgment cases |
|
|
39
40
|
| **`DEPTH-FAIL`** (businessDepth < 0.7) | a **mutating success** scenario asserts only `status` → make it **prove the effect**: assert a response **body** field, a **`@query`** side-effect, or a **`@concurrent` `ok_count`** invariant. (An error/`@cases` scenario proving the status is correct — it is *not* depth-required.) |
|
|
40
41
|
|
|
41
42
|
Stop when the gate PASSes + businessDepth ≥ 0.7, or the budget is exhausted → report residual gaps honestly (mark genuinely-unautomatable cases `@manual` with an oracle). Never fake a pass.
|
|
@@ -38,7 +38,7 @@ If the unit is **api-first**, skip every selector/capture phase (an API test has
|
|
|
38
38
|
1. **Resolve the datasource** — `base_url` + auth wired in `qa/datasources.yaml` + `.env.qa` (`${X_URL}` from `sungen api init`); a `production` datasource is refused unless `SUNGEN_ALLOW_PROD=1`.
|
|
39
39
|
2. **Compile**: `npx sungen generate --area <name>` → `specs/generated/api/<name>/`.
|
|
40
40
|
3. **Run**: `npx playwright test specs/generated/api/<name>/<name>.spec.ts`.
|
|
41
|
-
4. **Auto-fix** (use `sungen-error-mapping`): 401/403 → `@hybrid`+`@auth` or `Bearer :token` header (`sungen makeauth`); base_url unresolved → set `${X_URL}`; missing param → trace `{{var}}` to test-data/a prior `@api` response; `expect.status` mismatch → reconcile against `apis.yaml` (re-`generate --area`, never hand-edit the spec); flaky → self-clean + `@concurrent` caps.
|
|
41
|
+
4. **Auto-fix** (use `sungen-error-mapping`): 401/403 → `@hybrid`+`@auth` or `Bearer :token` header (`sungen makeauth`); base_url unresolved → set `${X_URL}`; missing param → trace `{{var}}` to test-data/a prior `@api` response; `expect.status` mismatch → reconcile against `apis.yaml` (re-`generate --area`, never hand-edit the spec); **400 "parameter missing" / body ignored → set `encoding: form` (or `multipart`) on the catalog entry, don't mark @manual**; flaky → self-clean + `@concurrent` caps.
|
|
42
42
|
5. **Integrity + trace** — `sungen script-check --area <name>` (1:1; on DRIFT re-`generate --area`, never hand-edit the spec) + `sungen trace --area <name>` (process map + HUMAN-LOOP FOCUS). Report + offer next steps.
|
|
43
43
|
|
|
44
44
|
## Pre-run (phased — per `sungen-selector-fix` skill)
|
|
@@ -36,6 +36,7 @@ Run `sungen audit --area <name>`; read `gateStatus` + `findings`. Then the **sem
|
|
|
36
36
|
| `VIEWPOINT-API-CONTRACT` | the endpoint is invoked but its response is never asserted → add `expect {{name.status}}` + a `{{name.body.…}}` check |
|
|
37
37
|
| `VIEWPOINT-API-ERROR` | a mutating endpoint has no failure scenario → add a `@cases` error matrix (or an explicit 4xx) |
|
|
38
38
|
| `VIEWPOINT-API-IDEMPOTENCY` | a mutating endpoint has no race check → add `@concurrent:N` + a `@query` DB cross-check |
|
|
39
|
+
| `VIEWPOINT-API-MANUAL-AUTOMATABLE` | a `@manual` scenario whose endpoint resolves is automatable → drop `@manual`, use `@api` (+ `@cases`); reserve `@manual` for genuine judgment cases |
|
|
39
40
|
| **`DEPTH-FAIL`** (businessDepth < 0.7) | a **mutating success** scenario asserts only `status` → make it **prove the effect**: assert a response **body** field, a **`@query`** side-effect, or a **`@concurrent` `ok_count`** invariant. (An error/`@cases` scenario proving the status is correct — it is *not* depth-required.) |
|
|
40
41
|
|
|
41
42
|
Stop when the gate PASSes + businessDepth ≥ 0.7, or the budget is exhausted → report residual gaps honestly (mark genuinely-unautomatable cases `@manual` with an oracle). Never fake a pass.
|
|
@@ -71,7 +71,7 @@ class ApiClient {
|
|
|
71
71
|
*/
|
|
72
72
|
async call(
|
|
73
73
|
label: string,
|
|
74
|
-
req: { method: string; path: string; body?: unknown; headers?: Record<string, string>; datasource?: string },
|
|
74
|
+
req: { method: string; path: string; body?: unknown; encoding?: 'json' | 'form' | 'multipart'; headers?: Record<string, string>; datasource?: string },
|
|
75
75
|
params: Record<string, any> = {},
|
|
76
76
|
opts: { storageState?: string } = {},
|
|
77
77
|
): Promise<{ status: number; ok: boolean; body: any; headers: Record<string, string> }> {
|
|
@@ -84,9 +84,19 @@ class ApiClient {
|
|
|
84
84
|
// catalog headers; :param tokens bind at runtime — raw (no URL-encoding, unlike the path)
|
|
85
85
|
for (const [k, v] of Object.entries(req.headers || {}))
|
|
86
86
|
headers[k] = String(v).replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, (_m, p) => String(params[p] ?? ''));
|
|
87
|
-
|
|
87
|
+
// Body: substitute `:param` into the body template (object values), then encode per `encoding`.
|
|
88
|
+
let body: any;
|
|
88
89
|
if (req.body !== undefined && req.body !== null) {
|
|
89
|
-
|
|
90
|
+
body = JSON.parse(JSON.stringify(req.body).replace(/":([A-Za-z_][A-Za-z0-9_]*)"/g, (_m, p) => JSON.stringify(params[p] ?? null)));
|
|
91
|
+
}
|
|
92
|
+
// Map the wire format to the right Playwright option (#345): json → data (application/json,
|
|
93
|
+
// default), form → form (application/x-www-form-urlencoded), multipart → multipart (form-data).
|
|
94
|
+
const bodyOpt: Record<string, unknown> = {};
|
|
95
|
+
if (body !== undefined) {
|
|
96
|
+
const enc = req.encoding ?? 'json';
|
|
97
|
+
if (enc === 'form') bodyOpt.form = body;
|
|
98
|
+
else if (enc === 'multipart') bodyOpt.multipart = body;
|
|
99
|
+
else bodyOpt.data = body;
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
// Playwright APIRequestContext: same runner/report/retries as UI tests. @hybrid passes
|
|
@@ -99,7 +109,7 @@ class ApiClient {
|
|
|
99
109
|
...(opts.storageState ? { storageState: opts.storageState } : {}),
|
|
100
110
|
});
|
|
101
111
|
try {
|
|
102
|
-
const res = await ctx.fetch(urlPath, { method: req.method, ...
|
|
112
|
+
const res = await ctx.fetch(urlPath, { method: req.method, ...bodyOpt });
|
|
103
113
|
const text = await res.text();
|
|
104
114
|
let parsed: any = text;
|
|
105
115
|
try { parsed = text ? JSON.parse(text) : null; } catch { /* non-JSON → keep text */ }
|
|
@@ -118,7 +128,7 @@ class ApiClient {
|
|
|
118
128
|
*/
|
|
119
129
|
async callN(
|
|
120
130
|
label: string,
|
|
121
|
-
req: { method: string; path: string; body?: unknown; headers?: Record<string, string>; datasource?: string },
|
|
131
|
+
req: { method: string; path: string; body?: unknown; encoding?: 'json' | 'form' | 'multipart'; headers?: Record<string, string>; datasource?: string },
|
|
122
132
|
params: Record<string, any> = {},
|
|
123
133
|
n = 1,
|
|
124
134
|
opts: { storageState?: string } = {},
|