@sungen/driver-api 3.1.2-beta.121 → 3.1.2-beta.122
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/package.json +2 -2
- package/src/api-repair.ts +37 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sungen/driver-api",
|
|
3
|
-
"version": "3.1.2-beta.
|
|
3
|
+
"version": "3.1.2-beta.122",
|
|
4
4
|
"description": "Sungen API capability — the @api annotation, API catalog, OpenAPI import + `sungen api import`, and the specs/api.ts runtime template. Plugs into @sun-asterisk/sungen via the capability SPI.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "eqe team (engineer & quality) — Sun Asterisk",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@sun-asterisk/sungen": "3.1.2-beta.
|
|
16
|
+
"@sun-asterisk/sungen": "3.1.2-beta.122",
|
|
17
17
|
"commander": "^14.0.2",
|
|
18
18
|
"yaml": "^2.8.2"
|
|
19
19
|
},
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API repair catalog (#343) — the `api` capability's deterministic fix rules.
|
|
3
|
+
*
|
|
4
|
+
* `sungen repair --api <area>` matches each audit finding + runtime failure against these rules and
|
|
5
|
+
* proposes the concrete fix. Same catalog the `/sungen:run-test` API mode + `sungen-api-design`
|
|
6
|
+
* repair loop apply by hand — here it is capability-owned DATA, so it composes audit + runtime
|
|
7
|
+
* signals into one plan and a project/driver can extend it. Type-only on core.
|
|
8
|
+
*/
|
|
9
|
+
import type { RepairProvider } from '@sun-asterisk/sungen';
|
|
10
|
+
|
|
11
|
+
export const apiRepair: RepairProvider = {
|
|
12
|
+
rules: [
|
|
13
|
+
// ── Coverage / depth (from `sungen audit --api`) ──────────────────────────────────────────
|
|
14
|
+
{ id: 'api-contract', match: /VIEWPOINT-API-CONTRACT/i,
|
|
15
|
+
fix: 'The endpoint is invoked but its response is never asserted — add `expect {{name.status}} is …` plus a body check `{{name.body.<field>}}`.' },
|
|
16
|
+
{ id: 'api-error', match: /VIEWPOINT-API-ERROR/i,
|
|
17
|
+
fix: 'A mutating endpoint has no failure scenario — add a `@cases` error matrix (input → expected status) or an explicit 4xx assertion (the ~70% band).' },
|
|
18
|
+
{ id: 'api-idempotency', match: /VIEWPOINT-API-IDEMPOTENCY/i,
|
|
19
|
+
fix: 'A mutating endpoint has no race check — add `@concurrent:N` + assert `{{name.ok_count}} is 1`, cross-checked with a `@query` DB count (the ~10% band).' },
|
|
20
|
+
{ id: 'api-depth', match: /DEPTH-?FAIL|businessDepth|SHALLOW/i,
|
|
21
|
+
fix: 'A mutating success scenario only asserts the status — make it PROVE THE EFFECT: assert a response body field, a `@query` DB side-effect, or a `@concurrent` `ok_count` invariant.' },
|
|
22
|
+
{ id: 'api-verification', match: /VERIFICATION-FAIL|does not resolve|not found in/i,
|
|
23
|
+
fix: 'An `@api:<name>` does not resolve in the catalog — fix the name, or add/import the endpoint into `api/apis.yaml` (`sungen api import`).' },
|
|
24
|
+
|
|
25
|
+
// ── Runtime failures (from the Playwright test-result) ────────────────────────────────────
|
|
26
|
+
{ id: 'api-auth', match: /\b40[13]\b|unauthor|forbidden/i,
|
|
27
|
+
fix: 'Auth failure (401/403) — tag the scenario `@hybrid` + `@auth:<role>` to reuse the UI session, or wire a catalog `authorization: "Bearer :token"` header; capture a session with `sungen makeauth <role>`.' },
|
|
28
|
+
{ id: 'api-datasource', match: /base_url|ECONNREFUSED|ENOTFOUND|ENETUNREACH|getaddrinfo/i,
|
|
29
|
+
fix: 'The API was unreachable — set the datasource `${X_URL}` key in `.env.qa` (from `sungen api init`) and confirm the service is up / non-prod.' },
|
|
30
|
+
{ id: 'api-status-mismatch', match: /expected.*status|status.*expected|toBe.*\b[45]\d\d\b|received.*\b[45]\d\d\b/i,
|
|
31
|
+
fix: 'Asserted status ≠ actual — reconcile the expectation against `apis.yaml`/spec (the catalog is the oracle). Never hand-edit the generated spec; fix the feature/test-data and re-`generate --api`.' },
|
|
32
|
+
{ id: 'api-timeout', match: /timeout|timed out|exceeded/i,
|
|
33
|
+
fix: 'Request timed out — raise the datasource `timeout_ms`, or check the endpoint/path; for flows ensure prior steps bound the values the call needs.' },
|
|
34
|
+
{ id: 'api-flaky', match: /flak|intermitt|conflict|already exists|duplicate key/i,
|
|
35
|
+
fix: 'Likely state bleed — make the flow self-cleaning (delete what it created / `@cleanup`), isolate `@cases` rows, and cap `@concurrent`.' },
|
|
36
|
+
],
|
|
37
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { resolveApi, apiParamNames, lintApiCatalog } from './api-catalog';
|
|
|
21
21
|
import { registerApiCommand } from './cli-import';
|
|
22
22
|
import { apiViewpoints, apiGateProvider } from './api-harness';
|
|
23
23
|
import { apiDiscovery, apiContextMapper } from './api-context';
|
|
24
|
+
import { apiRepair } from './api-repair';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Parse `name(a={{x}},b="lit",c=3)` annotation overrides → JS expressions. Inlined from core
|
|
@@ -190,6 +191,7 @@ export function register(registry: CapabilityRegistry): void {
|
|
|
190
191
|
gateProvider: apiGateProvider as (i: unknown) => unknown, // AO-2: API coverage + businessDepth
|
|
191
192
|
discovery: apiDiscovery, // AO-3: catalog/spec → Context slice
|
|
192
193
|
contextMapper: apiContextMapper, // AO-3: endpoints → matrix/async/flow generation units
|
|
194
|
+
repair: apiRepair, // #343: finding/failure → concrete fix catalog
|
|
193
195
|
cliCommands: [registerApiCommand as (program: unknown) => void], // `sungen api import <openapi>`
|
|
194
196
|
});
|
|
195
197
|
}
|