@plune-ai/cairn 0.5.0 → 0.7.0
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/README.md +10 -4
- package/dist/agent/finalize.d.ts +4 -0
- package/dist/agent/finalize.d.ts.map +1 -1
- package/dist/agent/finalize.js +8 -1
- package/dist/agent/finalize.js.map +1 -1
- package/dist/agent/graph.d.ts +17 -0
- package/dist/agent/graph.d.ts.map +1 -1
- package/dist/agent/graph.js +36 -6
- package/dist/agent/graph.js.map +1 -1
- package/dist/agent/index.d.ts +22 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +143 -51
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/summary.d.ts +14 -0
- package/dist/agent/summary.d.ts.map +1 -1
- package/dist/agent/summary.js +15 -0
- package/dist/agent/summary.js.map +1 -1
- package/dist/analyze/index.d.ts +2 -0
- package/dist/analyze/index.d.ts.map +1 -1
- package/dist/analyze/index.js +1 -0
- package/dist/analyze/index.js.map +1 -1
- package/dist/api/adversarial.d.ts +38 -0
- package/dist/api/adversarial.d.ts.map +1 -0
- package/dist/api/adversarial.js +175 -0
- package/dist/api/adversarial.js.map +1 -0
- package/dist/api/cases.d.ts +109 -0
- package/dist/api/cases.d.ts.map +1 -0
- package/dist/api/cases.js +256 -0
- package/dist/api/cases.js.map +1 -0
- package/dist/api/coverage.d.ts +51 -0
- package/dist/api/coverage.d.ts.map +1 -0
- package/dist/api/coverage.js +80 -0
- package/dist/api/coverage.js.map +1 -0
- package/dist/api/openapi.d.ts +84 -0
- package/dist/api/openapi.d.ts.map +1 -0
- package/dist/api/openapi.js +119 -0
- package/dist/api/openapi.js.map +1 -0
- package/dist/api/runner.d.ts +58 -0
- package/dist/api/runner.d.ts.map +1 -0
- package/dist/api/runner.js +285 -0
- package/dist/api/runner.js.map +1 -0
- package/dist/api/scenario-runner.d.ts +22 -0
- package/dist/api/scenario-runner.d.ts.map +1 -0
- package/dist/api/scenario-runner.js +132 -0
- package/dist/api/scenario-runner.js.map +1 -0
- package/dist/api/scenarios.d.ts +31 -0
- package/dist/api/scenarios.d.ts.map +1 -0
- package/dist/api/scenarios.js +71 -0
- package/dist/api/scenarios.js.map +1 -0
- package/dist/api/testcase-docs.d.ts +12 -0
- package/dist/api/testcase-docs.d.ts.map +1 -0
- package/dist/api/testcase-docs.js +22 -0
- package/dist/api/testcase-docs.js.map +1 -0
- package/dist/artifacts/contract.d.ts +62 -0
- package/dist/artifacts/contract.d.ts.map +1 -0
- package/dist/artifacts/contract.js +58 -0
- package/dist/artifacts/contract.js.map +1 -0
- package/dist/artifacts/index.d.ts +2 -0
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +3 -0
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/report.d.ts +21 -0
- package/dist/artifacts/report.d.ts.map +1 -1
- package/dist/artifacts/report.js +49 -0
- package/dist/artifacts/report.js.map +1 -1
- package/dist/artifacts/testcase-md.d.ts +29 -0
- package/dist/artifacts/testcase-md.d.ts.map +1 -1
- package/dist/artifacts/testcase-md.js +69 -1
- package/dist/artifacts/testcase-md.js.map +1 -1
- package/dist/checklist/index.d.ts +7 -0
- package/dist/checklist/index.d.ts.map +1 -1
- package/dist/checklist/index.js +14 -0
- package/dist/checklist/index.js.map +1 -1
- package/dist/ci/github.d.ts +83 -0
- package/dist/ci/github.d.ts.map +1 -0
- package/dist/ci/github.js +104 -0
- package/dist/ci/github.js.map +1 -0
- package/dist/ci/index.d.ts +14 -0
- package/dist/ci/index.d.ts.map +1 -0
- package/dist/ci/index.js +35 -0
- package/dist/ci/index.js.map +1 -0
- package/dist/ci/inputs.d.ts +93 -0
- package/dist/ci/inputs.d.ts.map +1 -0
- package/dist/ci/inputs.js +100 -0
- package/dist/ci/inputs.js.map +1 -0
- package/dist/ci/run.d.ts +51 -0
- package/dist/ci/run.d.ts.map +1 -0
- package/dist/ci/run.js +207 -0
- package/dist/ci/run.js.map +1 -0
- package/dist/ci/summary.d.ts +42 -0
- package/dist/ci/summary.d.ts.map +1 -0
- package/dist/ci/summary.js +45 -0
- package/dist/ci/summary.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +45 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/codegen/index.d.ts +13 -1
- package/dist/codegen/index.d.ts.map +1 -1
- package/dist/codegen/index.js +75 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +9 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/profiles.d.ts +6 -0
- package/dist/config/profiles.d.ts.map +1 -1
- package/dist/config/profiles.js +13 -0
- package/dist/config/profiles.js.map +1 -1
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/core/modalities/api.d.ts +27 -0
- package/dist/core/modalities/api.d.ts.map +1 -0
- package/dist/core/modalities/api.js +330 -0
- package/dist/core/modalities/api.js.map +1 -0
- package/dist/core/modalities/explore.d.ts.map +1 -1
- package/dist/core/modalities/explore.js +9 -1
- package/dist/core/modalities/explore.js.map +1 -1
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/core/registry.js +4 -1
- package/dist/core/registry.js.map +1 -1
- package/dist/design/critique.d.ts.map +1 -1
- package/dist/design/critique.js +3 -0
- package/dist/design/critique.js.map +1 -1
- package/dist/design/index.d.ts +2 -0
- package/dist/design/index.d.ts.map +1 -1
- package/dist/design/index.js +5 -0
- package/dist/design/index.js.map +1 -1
- package/dist/design/schema.d.ts +3 -0
- package/dist/design/schema.d.ts.map +1 -1
- package/dist/design/schema.js.map +1 -1
- package/dist/documentarian/index.d.ts +53 -0
- package/dist/documentarian/index.d.ts.map +1 -0
- package/dist/documentarian/index.js +135 -0
- package/dist/documentarian/index.js.map +1 -0
- package/dist/eval/gap-cases.d.ts.map +1 -1
- package/dist/eval/gap-cases.js +2 -0
- package/dist/eval/gap-cases.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/knowledge/index.d.ts +30 -4
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +80 -22
- package/dist/knowledge/index.js.map +1 -1
- package/dist/llm/index.d.ts +2 -2
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/routing.d.ts.map +1 -1
- package/dist/llm/routing.js +8 -2
- package/dist/llm/routing.js.map +1 -1
- package/dist/llm/structured.d.ts +22 -0
- package/dist/llm/structured.d.ts.map +1 -1
- package/dist/llm/structured.js +42 -0
- package/dist/llm/structured.js.map +1 -1
- package/dist/mcp/server.d.ts +9 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +49 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +149 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +138 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/project/index.d.ts +70 -0
- package/dist/project/index.d.ts.map +1 -0
- package/dist/project/index.js +173 -0
- package/dist/project/index.js.map +1 -0
- package/dist/prompts/local/identify-elements.d.ts +1 -1
- package/dist/prompts/local/identify-elements.d.ts.map +1 -1
- package/dist/prompts/local/identify-elements.js +5 -2
- package/dist/prompts/local/identify-elements.js.map +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.d.ts +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.d.ts.map +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.js +2 -0
- package/dist/prompts/local/qa-testcase-from-ui.js.map +1 -1
- package/dist/tui/hooks/use-runs.d.ts.map +1 -1
- package/dist/tui/hooks/use-runs.js +4 -1
- package/dist/tui/hooks/use-runs.js.map +1 -1
- package/dist/tui/screens/runs-list-screen.d.ts.map +1 -1
- package/dist/tui/screens/runs-list-screen.js +3 -1
- package/dist/tui/screens/runs-list-screen.js.map +1 -1
- package/dist/tui/screens/summary-screen.d.ts.map +1 -1
- package/dist/tui/screens/summary-screen.js +1 -1
- package/dist/tui/screens/summary-screen.js.map +1 -1
- package/dist/tui/types.d.ts +7 -1
- package/dist/tui/types.d.ts.map +1 -1
- package/dist/validate/index.d.ts +7 -3
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +22 -3
- package/dist/validate/index.js.map +1 -1
- package/dist/validate/runner.d.ts +61 -1
- package/dist/validate/runner.d.ts.map +1 -1
- package/dist/validate/runner.js +67 -4
- package/dist/validate/runner.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C1-04 / API-3 (#133) — execute the generated happy-path cases (API-2) against a configurable
|
|
3
|
+
* base URL and assert each response.
|
|
4
|
+
*
|
|
5
|
+
* Per case we: build the request (path/query/header/cookie params + auth headers from config and
|
|
6
|
+
* api-scope knowledge, #92), send it, assert the HTTP status matches the case's declared success
|
|
7
|
+
* code, and assert the response body conforms to the declared success schema. Request/response
|
|
8
|
+
* evidence is captured per case (with sensitive headers redacted) for the report slice (API-4).
|
|
9
|
+
*
|
|
10
|
+
* Transient transport faults (connection reset / timeout) and transient responses (429 / 5xx) reuse
|
|
11
|
+
* the tiered-recovery pattern from BORROW-02 (#90) / `retryInvoke`: a positively-recognised transient
|
|
12
|
+
* fault earns a cheap backoff + retry of the SAME request; everything else fails fast (we never mask a
|
|
13
|
+
* real 4xx / assertion failure behind a retry). `fetch` is injected so tests never touch the network.
|
|
14
|
+
*/
|
|
15
|
+
import { Ajv } from "ajv";
|
|
16
|
+
import addFormats from "ajv-formats";
|
|
17
|
+
/** Header names whose values are secrets — masked in captured evidence so tokens never hit disk/logs. */
|
|
18
|
+
const SENSITIVE = /authorization|cookie|api[-_]?key|token|secret|password/i;
|
|
19
|
+
function redactHeaders(headers) {
|
|
20
|
+
const out = {};
|
|
21
|
+
for (const [k, v] of Object.entries(headers))
|
|
22
|
+
out[k] = SENSITIVE.test(k) ? "***" : v;
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Transient transport faults worth a backoff + retry. Mirrors #90's stance: only positively-recognised
|
|
27
|
+
* transient errors retry; unknown faults and DNS/refused (a real misconfig) fail fast.
|
|
28
|
+
*/
|
|
29
|
+
const TRANSIENT_THROW = /ECONNRESET|ETIMEDOUT|EAI_AGAIN|socket hang up|network.?changed|the operation was aborted|aborted|timed? ?out/i;
|
|
30
|
+
/** A response status is transient (worth a retry) when it's a 429 or any 5xx. */
|
|
31
|
+
function isTransientStatus(status) {
|
|
32
|
+
return status === 429 || (status >= 500 && status <= 599);
|
|
33
|
+
}
|
|
34
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
35
|
+
/** Execute every case against `baseUrl`, asserting status + schema; returns per-case evidence. */
|
|
36
|
+
export async function runApiCases(cases, opts) {
|
|
37
|
+
const results = [];
|
|
38
|
+
for (const c of cases)
|
|
39
|
+
results.push(await runOne(c, opts));
|
|
40
|
+
return results;
|
|
41
|
+
}
|
|
42
|
+
async function runOne(c, opts) {
|
|
43
|
+
const doFetch = opts.fetch ?? globalThis.fetch;
|
|
44
|
+
const retries = opts.retries ?? 2;
|
|
45
|
+
const baseDelayMs = opts.baseDelayMs ?? 300;
|
|
46
|
+
const timeoutMs = opts.timeoutMs ?? 30_000;
|
|
47
|
+
const url = buildUrl(opts.baseUrl, c);
|
|
48
|
+
const headers = buildHeaders(c, opts.auth);
|
|
49
|
+
const hasBody = c.body !== undefined;
|
|
50
|
+
const isMultipart = c.bodyMediaType === "multipart/form-data";
|
|
51
|
+
const init = {
|
|
52
|
+
method: c.method,
|
|
53
|
+
headers,
|
|
54
|
+
...(hasBody ? { body: isMultipart ? toFormData(c.body) : JSON.stringify(c.body) } : {}),
|
|
55
|
+
};
|
|
56
|
+
const evidence = {
|
|
57
|
+
name: c.name,
|
|
58
|
+
method: c.method,
|
|
59
|
+
url,
|
|
60
|
+
request: { headers: redactHeaders(headers), ...(hasBody ? { body: c.body } : {}) },
|
|
61
|
+
attempts: 0,
|
|
62
|
+
expectedStatus: c.expectedStatus,
|
|
63
|
+
statusOk: false,
|
|
64
|
+
schemaOk: false,
|
|
65
|
+
schemaErrors: [],
|
|
66
|
+
passed: false,
|
|
67
|
+
};
|
|
68
|
+
// Tiered recovery ladder (#90): send → transient (throw or 429/5xx) with retries left → backoff + resend
|
|
69
|
+
// the SAME request → else stop. A non-transient response (4xx, or a status mismatch) is a real result.
|
|
70
|
+
let res;
|
|
71
|
+
let lastErr;
|
|
72
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
73
|
+
evidence.attempts = attempt + 1;
|
|
74
|
+
try {
|
|
75
|
+
res = await withTimeout(doFetch, url, init, timeoutMs);
|
|
76
|
+
if (isTransientStatus(res.status) && attempt < retries) {
|
|
77
|
+
await sleep(baseDelayMs * 2 ** attempt);
|
|
78
|
+
continue; // transient response — retry the same request
|
|
79
|
+
}
|
|
80
|
+
break; // a result we can assert on
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
lastErr = e;
|
|
84
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
85
|
+
if (attempt === retries || !TRANSIENT_THROW.test(msg))
|
|
86
|
+
break; // exhausted or fatal → give up
|
|
87
|
+
await sleep(baseDelayMs * 2 ** attempt);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!res) {
|
|
91
|
+
evidence.error = lastErr instanceof Error ? lastErr.message : String(lastErr);
|
|
92
|
+
return evidence; // no response → not passed
|
|
93
|
+
}
|
|
94
|
+
const bodyText = await res.text();
|
|
95
|
+
const json = parseJson(bodyText);
|
|
96
|
+
evidence.response = { status: res.status, bodyText, ...(json.ok ? { json: json.value } : {}) };
|
|
97
|
+
evidence.statusOk = statusMatches(c.expectedStatus, res.status);
|
|
98
|
+
if (c.expectedSchema === undefined) {
|
|
99
|
+
evidence.schemaOk = true; // nothing declared to conform to
|
|
100
|
+
}
|
|
101
|
+
else if (!json.ok) {
|
|
102
|
+
evidence.schemaOk = false;
|
|
103
|
+
evidence.schemaErrors = [`response body is not valid JSON (${json.error})`];
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
evidence.schemaErrors = validateAgainstSchema(json.value, c.expectedSchema);
|
|
107
|
+
evidence.schemaOk = evidence.schemaErrors.length === 0;
|
|
108
|
+
}
|
|
109
|
+
evidence.passed = evidence.statusOk && evidence.schemaOk;
|
|
110
|
+
return evidence;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A status matches when it equals the declared code. Two OpenAPI forms beyond an exact code:
|
|
114
|
+
* `default` accepts any non-error (<400) status, and a range like `2XX` matches its whole class.
|
|
115
|
+
*/
|
|
116
|
+
function statusMatches(expected, actual) {
|
|
117
|
+
if (expected === "default")
|
|
118
|
+
return actual < 400;
|
|
119
|
+
if (/^\dXX$/i.test(expected))
|
|
120
|
+
return String(actual)[0] === expected[0];
|
|
121
|
+
return String(actual) === expected;
|
|
122
|
+
}
|
|
123
|
+
async function withTimeout(doFetch, url, init, timeoutMs) {
|
|
124
|
+
if (timeoutMs <= 0)
|
|
125
|
+
return doFetch(url, init);
|
|
126
|
+
const ctrl = new AbortController();
|
|
127
|
+
const t = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
128
|
+
try {
|
|
129
|
+
return await doFetch(url, { ...init, signal: ctrl.signal });
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
clearTimeout(t);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function parseJson(text) {
|
|
136
|
+
if (text.trim() === "")
|
|
137
|
+
return { ok: true, value: undefined }; // empty body (e.g. 204) is valid
|
|
138
|
+
try {
|
|
139
|
+
return { ok: true, value: JSON.parse(text) };
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
return { ok: false, error: e.message };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Build the request URL: substitute `{path}` params, append `query` params, join onto the base URL. */
|
|
146
|
+
function buildUrl(baseUrl, c) {
|
|
147
|
+
let path = c.path;
|
|
148
|
+
for (const [k, v] of Object.entries(c.params.path)) {
|
|
149
|
+
path = path.replace(`{${k}}`, encodeURIComponent(String(v)));
|
|
150
|
+
}
|
|
151
|
+
const qs = new URLSearchParams();
|
|
152
|
+
for (const [k, v] of Object.entries(c.params.query))
|
|
153
|
+
qs.append(k, String(v));
|
|
154
|
+
const query = qs.toString();
|
|
155
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
156
|
+
const sep = path.startsWith("/") ? "" : "/";
|
|
157
|
+
return `${base}${sep}${path}${query ? `?${query}` : ""}`;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Merge auth headers, case header-params and a Cookie header from cookie-params; add a JSON
|
|
161
|
+
* content-type for a body case — UNLESS the operation declares `multipart/form-data` (API-10,
|
|
162
|
+
* #150), where `fetch`/undici must generate its own `Content-Type: multipart/form-data; boundary=…`
|
|
163
|
+
* from the `FormData` body; a manually-set header here would just fight (and lose to) that.
|
|
164
|
+
* `stripAuth` (BORROW-07, #95 `hacker` style) skips the configured auth headers entirely — the case
|
|
165
|
+
* is deliberately testing whether the operation actually rejects an unauthenticated request.
|
|
166
|
+
*/
|
|
167
|
+
function buildHeaders(c, auth) {
|
|
168
|
+
const headers = c.stripAuth ? {} : { ...(auth?.headers ?? {}) };
|
|
169
|
+
for (const [k, v] of Object.entries(c.params.header))
|
|
170
|
+
headers[k] = String(v);
|
|
171
|
+
const cookies = Object.entries(c.params.cookie);
|
|
172
|
+
if (cookies.length)
|
|
173
|
+
headers["Cookie"] = cookies.map(([k, v]) => `${k}=${v}`).join("; ");
|
|
174
|
+
const hasContentType = Object.keys(headers).some((h) => h.toLowerCase() === "content-type");
|
|
175
|
+
if (c.body !== undefined && !hasContentType && c.bodyMediaType !== "multipart/form-data") {
|
|
176
|
+
headers["Content-Type"] = "application/json";
|
|
177
|
+
}
|
|
178
|
+
return headers;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* C1-04 / API-10 (#150) — encode a synthesised body object as `multipart/form-data`. A `Buffer`
|
|
182
|
+
* value (from `synth()`'s `format: binary` handling, `cases.ts`) becomes a file part; every other
|
|
183
|
+
* value is a stringified form field. Relies on Node's native `FormData`/`File` (undici, global since
|
|
184
|
+
* Node 18+) so `fetch` itself generates the boundary and per-part `Content-Disposition` — no
|
|
185
|
+
* hand-rolled multipart encoder.
|
|
186
|
+
*/
|
|
187
|
+
function toFormData(body) {
|
|
188
|
+
const fd = new FormData();
|
|
189
|
+
if (!body || typeof body !== "object")
|
|
190
|
+
return fd;
|
|
191
|
+
for (const [k, v] of Object.entries(body)) {
|
|
192
|
+
if (v === undefined)
|
|
193
|
+
continue;
|
|
194
|
+
fd.append(k, Buffer.isBuffer(v) ? new File([v], `${k}.bin`, { type: "application/octet-stream" }) : String(v));
|
|
195
|
+
}
|
|
196
|
+
return fd;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* C1-04 / API-8 (#145) — strict JSON-Schema response conformance via `ajv` (draft 2020-12 + formats):
|
|
200
|
+
* type/required/properties/items/enum/allOf/oneOf/anyOf, plus format/pattern/min/max/additionalProperties
|
|
201
|
+
* that a hand-rolled checker would have to reimplement one keyword at a time. Returns path-qualified
|
|
202
|
+
* error strings (same shape callers already expect).
|
|
203
|
+
*/
|
|
204
|
+
const ajv = new Ajv({ allErrors: true, strict: false, verbose: true });
|
|
205
|
+
// ponytail: ajv-formats' .d.ts models CJS/ESM interop differently than its actual dist/index.js emit
|
|
206
|
+
// (`module.exports = formatsPlugin` directly) — the mismatch is type-only, so this cast matches runtime.
|
|
207
|
+
addFormats(ajv);
|
|
208
|
+
/** One compiled validator per (already-dereferenced) schema object — a run checks the same declared
|
|
209
|
+
* schema across many responses; recompiling per call would be wasted work. */
|
|
210
|
+
const compiledCache = new WeakMap();
|
|
211
|
+
function compile(schema) {
|
|
212
|
+
const cached = compiledCache.get(schema);
|
|
213
|
+
if (cached)
|
|
214
|
+
return cached;
|
|
215
|
+
const validate = ajv.compile(deCycle(schema, new Set()));
|
|
216
|
+
compiledCache.set(schema, validate);
|
|
217
|
+
return validate;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Swagger-parser's `dereference()` (API-1) resolves circular `$ref`s into literal object-identity
|
|
221
|
+
* cycles (e.g. `Pet.friends -> Pet`) rather than JSON-Schema `$ref` pointers — ajv can't compile a
|
|
222
|
+
* schema containing a real object cycle (infinite recursion). Breaking the cycle at the point of
|
|
223
|
+
* re-entry — tracked as the current DFS ancestor path, not a global "seen" set, since a schema
|
|
224
|
+
* legitimately reused as two *sibling* branches is not a cycle — relaxes only the recursive tail to
|
|
225
|
+
* "anything" and keeps the rest of the schema strict. Also folds OpenAPI 3.0's `nullable: true` into
|
|
226
|
+
* a `type` array, since ajv only understands the keyword `type` (no 3.0 extensions).
|
|
227
|
+
*/
|
|
228
|
+
function deCycle(node, ancestors) {
|
|
229
|
+
if (!node || typeof node !== "object")
|
|
230
|
+
return node;
|
|
231
|
+
if (ancestors.has(node))
|
|
232
|
+
return true; // re-entering an ancestor — stop recursing, accept anything
|
|
233
|
+
ancestors.add(node);
|
|
234
|
+
try {
|
|
235
|
+
if (Array.isArray(node))
|
|
236
|
+
return node.map((v) => deCycle(v, ancestors));
|
|
237
|
+
const out = {};
|
|
238
|
+
for (const [k, v] of Object.entries(node))
|
|
239
|
+
out[k] = deCycle(v, ancestors);
|
|
240
|
+
if (out.nullable === true) {
|
|
241
|
+
const t = out.type;
|
|
242
|
+
out.type = Array.isArray(t) ? [...t, "null"] : t !== undefined ? [t, "null"] : "null";
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
ancestors.delete(node);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
export function validateAgainstSchema(value, schema, path = "$") {
|
|
251
|
+
if (!schema || typeof schema !== "object")
|
|
252
|
+
return [];
|
|
253
|
+
const validate = compile(schema);
|
|
254
|
+
if (validate(value))
|
|
255
|
+
return [];
|
|
256
|
+
return (validate.errors ?? []).map((e) => formatAjvError(e, path));
|
|
257
|
+
}
|
|
258
|
+
function formatAjvError(e, root) {
|
|
259
|
+
const dotPath = e.instancePath ? e.instancePath.replace(/\//g, ".") : "";
|
|
260
|
+
if (e.keyword === "required") {
|
|
261
|
+
const prop = e.params.missingProperty;
|
|
262
|
+
return `${root}${dotPath}.${prop}: required property missing`;
|
|
263
|
+
}
|
|
264
|
+
if (e.keyword === "type") {
|
|
265
|
+
return `${root}${dotPath}: expected ${e.params.type}, got ${jsonType(e.data)}`;
|
|
266
|
+
}
|
|
267
|
+
if (e.keyword === "enum") {
|
|
268
|
+
return `${root}${dotPath}: ${JSON.stringify(e.data)} not in enum`;
|
|
269
|
+
}
|
|
270
|
+
if (e.keyword === "additionalProperties") {
|
|
271
|
+
const extra = e.params.additionalProperty;
|
|
272
|
+
return `${root}${dotPath}: unexpected additional property "${extra}"`;
|
|
273
|
+
}
|
|
274
|
+
return `${root}${dotPath}: ${e.message ?? "invalid"}`;
|
|
275
|
+
}
|
|
276
|
+
function jsonType(v) {
|
|
277
|
+
if (v === null)
|
|
278
|
+
return "null";
|
|
279
|
+
if (Array.isArray(v))
|
|
280
|
+
return "array";
|
|
281
|
+
if (typeof v === "number")
|
|
282
|
+
return "number";
|
|
283
|
+
return typeof v; // string | boolean | object | undefined
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/api/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,GAAG,EAA2C,MAAM,KAAK,CAAC;AACnE,OAAO,UAAU,MAAM,aAAa,CAAC;AAmDrC,yGAAyG;AACzG,MAAM,SAAS,GAAG,yDAAyD,CAAC;AAE5E,SAAS,aAAa,CAAC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AAC;IACD,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,GAAG,IAAI,GAAG,OAAO,cAAe,CAAC,CAAC,MAA2B,CAAC,IAAI,SAAS,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;IACvG,CAAC;IACD,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,GAAG,IAAI,GAAG,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;IACpE,CAAC;IACD,IAAI,CAAC,CAAC,OAAO,KAAK,sBAAsB,EAAE,CAAC;QACzC,MAAM,KAAK,GAAI,CAAC,CAAC,MAAyC,CAAC,kBAAkB,CAAC;QAC9E,OAAO,GAAG,IAAI,GAAG,OAAO,qCAAqC,KAAK,GAAG,CAAC;IACxE,CAAC;IACD,OAAO,GAAG,IAAI,GAAG,OAAO,KAAK,CAAC,CAAC,OAAO,IAAI,SAAS,EAAE,CAAC;AACxD,CAAC;AAED,SAAS,QAAQ,CAAC,CAAU;IAC1B,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,OAAO,CAAC;IACrC,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC3C,OAAO,OAAO,CAAC,CAAC,CAAC,wCAAwC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C1-04 / API-9 (#146) — execute a generated {@link ApiScenario} step by step, threading captured
|
|
3
|
+
* response values into downstream requests.
|
|
4
|
+
*
|
|
5
|
+
* Each step reuses `runApiCases` (API-3) verbatim — a resolved step IS a normal `ApiCase`, so all of
|
|
6
|
+
* the runner's auth/retry/redaction/schema-assertion behaviour applies unchanged. The only new
|
|
7
|
+
* behaviour here: (a) before sending a step, overwrite any of its params whose name matches a value
|
|
8
|
+
* captured earlier; (b) after a step succeeds, capture values for steps still to come — preferring a
|
|
9
|
+
* declared `links` expression (`ApiCase.responseLinks`) over the fallback heuristic (a response-body
|
|
10
|
+
* field with the same name as the needed param); (c) a failed step aborts the rest of the scenario —
|
|
11
|
+
* continuing with an unresolved captured value (e.g. a missing id after a failed create) would just
|
|
12
|
+
* cascade one real failure into several meaningless ones.
|
|
13
|
+
*/
|
|
14
|
+
import { type ApiCaseResult, type RunnerOptions } from "./runner.js";
|
|
15
|
+
import type { ApiScenario } from "./scenarios.js";
|
|
16
|
+
export interface ApiScenarioResult {
|
|
17
|
+
name: string;
|
|
18
|
+
steps: ApiCaseResult[];
|
|
19
|
+
passed: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function runApiScenarios(scenarios: ApiScenario[], opts: RunnerOptions): Promise<ApiScenarioResult[]>;
|
|
22
|
+
//# sourceMappingURL=scenario-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenario-runner.d.ts","sourceRoot":"","sources":["../../src/api/scenario-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAIjH"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C1-04 / API-9 (#146) — execute a generated {@link ApiScenario} step by step, threading captured
|
|
3
|
+
* response values into downstream requests.
|
|
4
|
+
*
|
|
5
|
+
* Each step reuses `runApiCases` (API-3) verbatim — a resolved step IS a normal `ApiCase`, so all of
|
|
6
|
+
* the runner's auth/retry/redaction/schema-assertion behaviour applies unchanged. The only new
|
|
7
|
+
* behaviour here: (a) before sending a step, overwrite any of its params whose name matches a value
|
|
8
|
+
* captured earlier; (b) after a step succeeds, capture values for steps still to come — preferring a
|
|
9
|
+
* declared `links` expression (`ApiCase.responseLinks`) over the fallback heuristic (a response-body
|
|
10
|
+
* field with the same name as the needed param); (c) a failed step aborts the rest of the scenario —
|
|
11
|
+
* continuing with an unresolved captured value (e.g. a missing id after a failed create) would just
|
|
12
|
+
* cascade one real failure into several meaningless ones.
|
|
13
|
+
*/
|
|
14
|
+
import { runApiCases } from "./runner.js";
|
|
15
|
+
export async function runApiScenarios(scenarios, opts) {
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const scenario of scenarios)
|
|
18
|
+
results.push(await runOneScenario(scenario, opts));
|
|
19
|
+
return results;
|
|
20
|
+
}
|
|
21
|
+
async function runOneScenario(scenario, opts) {
|
|
22
|
+
const captured = {};
|
|
23
|
+
const steps = [];
|
|
24
|
+
let aborted = false;
|
|
25
|
+
for (let i = 0; i < scenario.steps.length; i++) {
|
|
26
|
+
const step = scenario.steps[i];
|
|
27
|
+
if (aborted) {
|
|
28
|
+
steps.push(skippedResult(step));
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const [result] = await runApiCases([resolveParams(step, captured)], opts);
|
|
32
|
+
steps.push(result);
|
|
33
|
+
if (!result.passed) {
|
|
34
|
+
aborted = true; // an earlier step in the chain failed — later steps have nothing valid to run on
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
captureValues(step, result, scenario.steps.slice(i + 1), captured);
|
|
38
|
+
}
|
|
39
|
+
return { name: scenario.name, steps, passed: steps.every((s) => s.passed) };
|
|
40
|
+
}
|
|
41
|
+
function skippedResult(step) {
|
|
42
|
+
return {
|
|
43
|
+
name: step.name,
|
|
44
|
+
method: step.method,
|
|
45
|
+
url: "",
|
|
46
|
+
request: { headers: {} },
|
|
47
|
+
attempts: 0,
|
|
48
|
+
expectedStatus: step.expectedStatus,
|
|
49
|
+
statusOk: false,
|
|
50
|
+
schemaOk: false,
|
|
51
|
+
schemaErrors: [],
|
|
52
|
+
passed: false,
|
|
53
|
+
error: "skipped — an earlier step in this scenario failed",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Overwrite any param whose name matches a value captured from an earlier step. */
|
|
57
|
+
function resolveParams(step, captured) {
|
|
58
|
+
if (Object.keys(captured).length === 0)
|
|
59
|
+
return step;
|
|
60
|
+
const apply = (bucket) => {
|
|
61
|
+
const out = { ...bucket };
|
|
62
|
+
for (const k of Object.keys(out))
|
|
63
|
+
if (k in captured)
|
|
64
|
+
out[k] = captured[k];
|
|
65
|
+
return out;
|
|
66
|
+
};
|
|
67
|
+
const params = {
|
|
68
|
+
path: apply(step.params.path),
|
|
69
|
+
query: apply(step.params.query),
|
|
70
|
+
header: apply(step.params.header),
|
|
71
|
+
cookie: apply(step.params.cookie),
|
|
72
|
+
};
|
|
73
|
+
return { ...step, params };
|
|
74
|
+
}
|
|
75
|
+
/** After a step succeeds, capture whatever later steps' params need — links first, name-match second. */
|
|
76
|
+
function captureValues(step, result, laterSteps, captured) {
|
|
77
|
+
const neededNames = new Set(laterSteps.flatMap((s) => [
|
|
78
|
+
...Object.keys(s.params.path),
|
|
79
|
+
...Object.keys(s.params.query),
|
|
80
|
+
...Object.keys(s.params.header),
|
|
81
|
+
...Object.keys(s.params.cookie),
|
|
82
|
+
]));
|
|
83
|
+
if (neededNames.size === 0)
|
|
84
|
+
return;
|
|
85
|
+
const body = result.response?.json;
|
|
86
|
+
const bodyObj = body && typeof body === "object" && !Array.isArray(body) ? body : undefined;
|
|
87
|
+
for (const name of neededNames) {
|
|
88
|
+
const viaLink = evalLinkFor(step, name, laterSteps, body);
|
|
89
|
+
if (viaLink !== undefined) {
|
|
90
|
+
captured[name] = viaLink;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (bodyObj && name in bodyObj)
|
|
94
|
+
captured[name] = String(bodyObj[name]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** A declared `links` expression targeting one of the later steps, for the given param name. */
|
|
98
|
+
function evalLinkFor(step, paramName, laterSteps, body) {
|
|
99
|
+
if (!step.responseLinks)
|
|
100
|
+
return undefined;
|
|
101
|
+
const laterOpIds = new Set(laterSteps.map((s) => s.operationId).filter((id) => !!id));
|
|
102
|
+
for (const link of Object.values(step.responseLinks)) {
|
|
103
|
+
if (!link.operationId || !laterOpIds.has(link.operationId))
|
|
104
|
+
continue;
|
|
105
|
+
const expr = link.parameters[paramName];
|
|
106
|
+
if (!expr)
|
|
107
|
+
continue;
|
|
108
|
+
const val = evalResponseBodyPointer(body, expr);
|
|
109
|
+
if (val !== undefined)
|
|
110
|
+
return String(val);
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* ponytail: supports only the `$response.body#/<json-pointer>` runtime-expression form (OpenAPI's
|
|
116
|
+
* `links` grammar also allows `$request.*`/`$url`/etc.) — the one shape that actually matters for
|
|
117
|
+
* threading a created resource's id into the next request; add more forms if a real spec needs them.
|
|
118
|
+
*/
|
|
119
|
+
function evalResponseBodyPointer(body, expr) {
|
|
120
|
+
const m = /^\$response\.body#(\/.*)$/.exec(expr);
|
|
121
|
+
if (!m)
|
|
122
|
+
return undefined;
|
|
123
|
+
let cur = body;
|
|
124
|
+
for (const raw of m[1].split("/").slice(1)) {
|
|
125
|
+
const key = raw.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
126
|
+
if (cur === null || typeof cur !== "object")
|
|
127
|
+
return undefined;
|
|
128
|
+
cur = cur[key];
|
|
129
|
+
}
|
|
130
|
+
return cur;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=scenario-runner.js.map
|
|
@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AS,CAAC;IACzB,IAAI,GAAG,GAAY,IAAI,CAAC;IACxB,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACxD,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QAC9D,GAAG,GAAI,GAA+B,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C1-04 / API-9 (#146) — multi-endpoint scenario chains ("journeys" for the API modality): given the
|
|
3
|
+
* {@link ApiModel}, generate ordered chains of related operations on the same resource (create → read
|
|
4
|
+
* → update → delete, using whichever of those the spec actually declares), so a scenario can prove a
|
|
5
|
+
* resource's identifier really flows from one response into the next request — something no
|
|
6
|
+
* single-operation case (API-2/API-8) can express.
|
|
7
|
+
*
|
|
8
|
+
* "Related" = same resource, detected the same way REST APIs are conventionally shaped: a *collection*
|
|
9
|
+
* path (`/pets`) and an *item* path templated one level deeper (`/pets/{id}`). No LLM, no new schema
|
|
10
|
+
* keywords — pure structural grouping over the already-ingested model (API-1).
|
|
11
|
+
*
|
|
12
|
+
* A scenario step IS a normal {@link ApiCase} (from `toCase()`, API-2's exact synthesis) — nothing new
|
|
13
|
+
* to learn for rendering/reporting. The only scenario-specific behaviour lives in the runner
|
|
14
|
+
* (`scenario-runner.ts`): before sending a downstream step, it overwrites any of that step's params
|
|
15
|
+
* whose name matches a value captured from an earlier step's response (declared `links` first, a
|
|
16
|
+
* same-name field second — see `ApiCase.responseLinks`).
|
|
17
|
+
*/
|
|
18
|
+
import { type ApiCase } from "./cases.js";
|
|
19
|
+
import type { ApiModel } from "./openapi.js";
|
|
20
|
+
export interface ApiScenario {
|
|
21
|
+
/** e.g. "pets lifecycle" — derived from the resource's collection path. */
|
|
22
|
+
name: string;
|
|
23
|
+
/** In CRUD order (whichever of create/read/update/delete the spec actually declares). */
|
|
24
|
+
steps: ApiCase[];
|
|
25
|
+
technique: "state-transition";
|
|
26
|
+
rationale: string;
|
|
27
|
+
}
|
|
28
|
+
/** Generate one lifecycle scenario per resource that has both a create op and something to chain it
|
|
29
|
+
* to — a resource with only a create (nothing to read/update/delete) has no chain worth generating. */
|
|
30
|
+
export declare function generateApiScenarios(model: ApiModel): ApiScenario[];
|
|
31
|
+
//# sourceMappingURL=scenarios.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenarios.d.ts","sourceRoot":"","sources":["../../src/api/scenarios.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE1D,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,yFAAyF;IACzF,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;AAyBD;uGACuG;AACvG,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,QAAQ,GAAG,WAAW,EAAE,CA0BnE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C1-04 / API-9 (#146) — multi-endpoint scenario chains ("journeys" for the API modality): given the
|
|
3
|
+
* {@link ApiModel}, generate ordered chains of related operations on the same resource (create → read
|
|
4
|
+
* → update → delete, using whichever of those the spec actually declares), so a scenario can prove a
|
|
5
|
+
* resource's identifier really flows from one response into the next request — something no
|
|
6
|
+
* single-operation case (API-2/API-8) can express.
|
|
7
|
+
*
|
|
8
|
+
* "Related" = same resource, detected the same way REST APIs are conventionally shaped: a *collection*
|
|
9
|
+
* path (`/pets`) and an *item* path templated one level deeper (`/pets/{id}`). No LLM, no new schema
|
|
10
|
+
* keywords — pure structural grouping over the already-ingested model (API-1).
|
|
11
|
+
*
|
|
12
|
+
* A scenario step IS a normal {@link ApiCase} (from `toCase()`, API-2's exact synthesis) — nothing new
|
|
13
|
+
* to learn for rendering/reporting. The only scenario-specific behaviour lives in the runner
|
|
14
|
+
* (`scenario-runner.ts`): before sending a downstream step, it overwrites any of that step's params
|
|
15
|
+
* whose name matches a value captured from an earlier step's response (declared `links` first, a
|
|
16
|
+
* same-name field second — see `ApiCase.responseLinks`).
|
|
17
|
+
*/
|
|
18
|
+
import { apiEndpointKey, toCase } from "./cases.js";
|
|
19
|
+
/**
|
|
20
|
+
* A path's *collection* form: the path with a trailing `{param}` segment stripped, e.g.
|
|
21
|
+
* `/pets/{id}` → `/pets`. A path with no trailing template segment is already a collection path.
|
|
22
|
+
*/
|
|
23
|
+
function collectionPathOf(path) {
|
|
24
|
+
const segments = path.split("/");
|
|
25
|
+
const last = segments[segments.length - 1];
|
|
26
|
+
if (last && /^\{.+\}$/.test(last))
|
|
27
|
+
return segments.slice(0, -1).join("/") || "/";
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
/** Group endpoints by their collection path — the candidate "same resource" grouping. */
|
|
31
|
+
function groupByResource(model) {
|
|
32
|
+
const groups = new Map();
|
|
33
|
+
for (const e of model.endpoints) {
|
|
34
|
+
const key = collectionPathOf(e.path);
|
|
35
|
+
const bucket = groups.get(key);
|
|
36
|
+
if (bucket)
|
|
37
|
+
bucket.push(e);
|
|
38
|
+
else
|
|
39
|
+
groups.set(key, [e]);
|
|
40
|
+
}
|
|
41
|
+
return groups;
|
|
42
|
+
}
|
|
43
|
+
/** Generate one lifecycle scenario per resource that has both a create op and something to chain it
|
|
44
|
+
* to — a resource with only a create (nothing to read/update/delete) has no chain worth generating. */
|
|
45
|
+
export function generateApiScenarios(model) {
|
|
46
|
+
const scenarios = [];
|
|
47
|
+
for (const [collectionPath, endpoints] of groupByResource(model)) {
|
|
48
|
+
const itemOps = endpoints.filter((e) => e.path !== collectionPath);
|
|
49
|
+
const create = endpoints.find((e) => e.path === collectionPath && e.method === "POST" && e.requestBody);
|
|
50
|
+
if (!create)
|
|
51
|
+
continue;
|
|
52
|
+
const read = itemOps.find((e) => e.method === "GET");
|
|
53
|
+
const update = itemOps.find((e) => e.method === "PUT" || e.method === "PATCH");
|
|
54
|
+
const del = itemOps.find((e) => e.method === "DELETE");
|
|
55
|
+
const downstream = [read, update, del].filter((e) => e !== undefined);
|
|
56
|
+
if (downstream.length === 0)
|
|
57
|
+
continue;
|
|
58
|
+
const resourceName = collectionPath.replace(/^\//, "") || collectionPath;
|
|
59
|
+
const chain = [create, ...downstream];
|
|
60
|
+
scenarios.push({
|
|
61
|
+
name: `${resourceName} lifecycle`,
|
|
62
|
+
steps: chain.map(toCase),
|
|
63
|
+
technique: "state-transition",
|
|
64
|
+
rationale: `Chains ${chain.length} related operations on ${collectionPath} (${chain.map((e) => apiEndpointKey(e)).join(" → ")}), ` +
|
|
65
|
+
`threading the resource identifier captured from ${apiEndpointKey(create)}'s response into each ` +
|
|
66
|
+
`downstream request (state-transition, ISO/IEC/IEEE 29119-4) — the API analogue of a multi-page journey.`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return scenarios;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=scenarios.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenarios.js","sourceRoot":"","sources":["../../src/api/scenarios.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,EAAgB,MAAM,YAAY,CAAC;AAYlE;;;GAGG;AACH,SAAS,gBAA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AmD,cAAc,CAAC,MAAM,CAAC,wBAAwB;gBACjG,yGAAyG;SAC5G,CAAC,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ApiCase } from "./cases.js";
|
|
2
|
+
import type { ApiCaseResult } from "./runner.js";
|
|
3
|
+
export interface ApiTestCaseDocsResult {
|
|
4
|
+
/** id + rendered ATC markdown, in input order. */
|
|
5
|
+
docs: {
|
|
6
|
+
id: string;
|
|
7
|
+
md: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
/** Pure — no I/O. `results` is absent for a cases-only (no `--base-url`) invocation. */
|
|
11
|
+
export declare function buildApiTestCaseDocs(cases: ApiCase[], results: ApiCaseResult[] | undefined, suite: string): ApiTestCaseDocsResult;
|
|
12
|
+
//# sourceMappingURL=testcase-docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testcase-docs.d.ts","sourceRoot":"","sources":["../../src/api/testcase-docs.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,qBAAqB;IACpC,kDAAkD;IAClD,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACpC;AAED,wFAAwF;AACxF,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,EAAE,aAAa,EAAE,GAAG,SAAS,EACpC,KAAK,EAAE,MAAM,GACZ,qBAAqB,CASvB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C1-04 / API-5 (#135) — build ATC case docs (.md) for the generated/run API cases: the API sibling
|
|
3
|
+
* of `agent/testcase-docs.ts` (web), writing into the same `testcases/<id>.md` boundary Plune reads
|
|
4
|
+
* for web runs. Every API-2 case is happy-path/auto, so these are always ATC — an MTC branch would
|
|
5
|
+
* need a case that names a manual step, which no API slice produces yet.
|
|
6
|
+
*
|
|
7
|
+
* Provenance (aligns with BORROW-04, #91): a case's status can only read "Passed" when a same-named
|
|
8
|
+
* result is present AND asserts `passed` — never inferred from the mere absence of a failure.
|
|
9
|
+
*/
|
|
10
|
+
import { renderApiTestCaseMd } from "../artifacts/testcase-md.js";
|
|
11
|
+
/** Pure — no I/O. `results` is absent for a cases-only (no `--base-url`) invocation. */
|
|
12
|
+
export function buildApiTestCaseDocs(cases, results, suite) {
|
|
13
|
+
const resultByName = new Map((results ?? []).map((r) => [r.name, r]));
|
|
14
|
+
const docs = cases.map((c, i) => {
|
|
15
|
+
const id = `ATC-${suite}-${String(i + 1).padStart(3, "0")}`;
|
|
16
|
+
const result = resultByName.get(c.name);
|
|
17
|
+
const status = !result ? "❌ Not run" : result.passed ? "✅ Passed" : "❌ Failed";
|
|
18
|
+
return { id, md: renderApiTestCaseMd(c, { id, suite, status }) };
|
|
19
|
+
});
|
|
20
|
+
return { docs };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=testcase-docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testcase-docs.js","sourceRoot":"","sources":["../../src/api/testcase-docs.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AASlE,wFAAwF;AACxF,MAAM,UAAU,oBAAoB,CAClC,KAAgB,EAChB,OAAoC,EACpC,KAAa;IAEb,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACtE,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC9B,MAAM,EAAE,GAAG,OAAO,KAAK,IAAI,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;QAC/E,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACnE,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC"}
|