@plune-ai/cairn 0.4.2 → 0.6.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.
Files changed (262) hide show
  1. package/README.md +55 -261
  2. package/dist/agent/graph.d.ts +41 -0
  3. package/dist/agent/graph.d.ts.map +1 -1
  4. package/dist/agent/graph.js +110 -8
  5. package/dist/agent/graph.js.map +1 -1
  6. package/dist/agent/index.d.ts +34 -0
  7. package/dist/agent/index.d.ts.map +1 -1
  8. package/dist/agent/index.js +238 -54
  9. package/dist/agent/index.js.map +1 -1
  10. package/dist/agent/summary.d.ts +11 -0
  11. package/dist/agent/summary.d.ts.map +1 -1
  12. package/dist/agent/summary.js +10 -0
  13. package/dist/agent/summary.js.map +1 -1
  14. package/dist/analyze/index.d.ts +2 -0
  15. package/dist/analyze/index.d.ts.map +1 -1
  16. package/dist/analyze/index.js +1 -0
  17. package/dist/analyze/index.js.map +1 -1
  18. package/dist/api/adversarial.d.ts +38 -0
  19. package/dist/api/adversarial.d.ts.map +1 -0
  20. package/dist/api/adversarial.js +175 -0
  21. package/dist/api/adversarial.js.map +1 -0
  22. package/dist/api/cases.d.ts +105 -0
  23. package/dist/api/cases.d.ts.map +1 -0
  24. package/dist/api/cases.js +256 -0
  25. package/dist/api/cases.js.map +1 -0
  26. package/dist/api/coverage.d.ts +51 -0
  27. package/dist/api/coverage.d.ts.map +1 -0
  28. package/dist/api/coverage.js +80 -0
  29. package/dist/api/coverage.js.map +1 -0
  30. package/dist/api/openapi.d.ts +84 -0
  31. package/dist/api/openapi.d.ts.map +1 -0
  32. package/dist/api/openapi.js +119 -0
  33. package/dist/api/openapi.js.map +1 -0
  34. package/dist/api/runner.d.ts +58 -0
  35. package/dist/api/runner.d.ts.map +1 -0
  36. package/dist/api/runner.js +285 -0
  37. package/dist/api/runner.js.map +1 -0
  38. package/dist/api/scenario-runner.d.ts +22 -0
  39. package/dist/api/scenario-runner.d.ts.map +1 -0
  40. package/dist/api/scenario-runner.js +132 -0
  41. package/dist/api/scenario-runner.js.map +1 -0
  42. package/dist/api/scenarios.d.ts +31 -0
  43. package/dist/api/scenarios.d.ts.map +1 -0
  44. package/dist/api/scenarios.js +71 -0
  45. package/dist/api/scenarios.js.map +1 -0
  46. package/dist/api/testcase-docs.d.ts +12 -0
  47. package/dist/api/testcase-docs.d.ts.map +1 -0
  48. package/dist/api/testcase-docs.js +22 -0
  49. package/dist/api/testcase-docs.js.map +1 -0
  50. package/dist/artifacts/index.d.ts +23 -0
  51. package/dist/artifacts/index.d.ts.map +1 -1
  52. package/dist/artifacts/index.js +61 -1
  53. package/dist/artifacts/index.js.map +1 -1
  54. package/dist/artifacts/report.d.ts +29 -0
  55. package/dist/artifacts/report.d.ts.map +1 -1
  56. package/dist/artifacts/report.js +96 -0
  57. package/dist/artifacts/report.js.map +1 -1
  58. package/dist/artifacts/testcase-md.d.ts +27 -0
  59. package/dist/artifacts/testcase-md.d.ts.map +1 -1
  60. package/dist/artifacts/testcase-md.js +61 -0
  61. package/dist/artifacts/testcase-md.js.map +1 -1
  62. package/dist/browser/backends/playwright-lib.d.ts +12 -0
  63. package/dist/browser/backends/playwright-lib.d.ts.map +1 -1
  64. package/dist/browser/backends/playwright-lib.js +48 -3
  65. package/dist/browser/backends/playwright-lib.js.map +1 -1
  66. package/dist/browser/recovery.d.ts +42 -0
  67. package/dist/browser/recovery.d.ts.map +1 -0
  68. package/dist/browser/recovery.js +62 -0
  69. package/dist/browser/recovery.js.map +1 -0
  70. package/dist/browser/types.d.ts +7 -0
  71. package/dist/browser/types.d.ts.map +1 -1
  72. package/dist/checklist/index.d.ts +7 -0
  73. package/dist/checklist/index.d.ts.map +1 -1
  74. package/dist/checklist/index.js +14 -0
  75. package/dist/checklist/index.js.map +1 -1
  76. package/dist/ci/github.d.ts +83 -0
  77. package/dist/ci/github.d.ts.map +1 -0
  78. package/dist/ci/github.js +104 -0
  79. package/dist/ci/github.js.map +1 -0
  80. package/dist/ci/index.d.ts +14 -0
  81. package/dist/ci/index.d.ts.map +1 -0
  82. package/dist/ci/index.js +35 -0
  83. package/dist/ci/index.js.map +1 -0
  84. package/dist/ci/inputs.d.ts +93 -0
  85. package/dist/ci/inputs.d.ts.map +1 -0
  86. package/dist/ci/inputs.js +100 -0
  87. package/dist/ci/inputs.js.map +1 -0
  88. package/dist/ci/run.d.ts +51 -0
  89. package/dist/ci/run.d.ts.map +1 -0
  90. package/dist/ci/run.js +207 -0
  91. package/dist/ci/run.js.map +1 -0
  92. package/dist/ci/summary.d.ts +42 -0
  93. package/dist/ci/summary.d.ts.map +1 -0
  94. package/dist/ci/summary.js +45 -0
  95. package/dist/ci/summary.js.map +1 -0
  96. package/dist/cli/index.d.ts.map +1 -1
  97. package/dist/cli/index.js +65 -4
  98. package/dist/cli/index.js.map +1 -1
  99. package/dist/codegen/index.d.ts +13 -1
  100. package/dist/codegen/index.d.ts.map +1 -1
  101. package/dist/codegen/index.js +75 -0
  102. package/dist/codegen/index.js.map +1 -1
  103. package/dist/codegen/journey-setup.d.ts +14 -0
  104. package/dist/codegen/journey-setup.d.ts.map +1 -0
  105. package/dist/codegen/journey-setup.js +69 -0
  106. package/dist/codegen/journey-setup.js.map +1 -0
  107. package/dist/config/index.d.ts.map +1 -1
  108. package/dist/config/index.js +9 -0
  109. package/dist/config/index.js.map +1 -1
  110. package/dist/config/profiles.d.ts +6 -0
  111. package/dist/config/profiles.d.ts.map +1 -1
  112. package/dist/config/profiles.js +13 -0
  113. package/dist/config/profiles.js.map +1 -1
  114. package/dist/config/schema.d.ts +6 -0
  115. package/dist/config/schema.d.ts.map +1 -1
  116. package/dist/core/modalities/api.d.ts +27 -0
  117. package/dist/core/modalities/api.d.ts.map +1 -0
  118. package/dist/core/modalities/api.js +321 -0
  119. package/dist/core/modalities/api.js.map +1 -0
  120. package/dist/core/modalities/explore.d.ts.map +1 -1
  121. package/dist/core/modalities/explore.js +19 -1
  122. package/dist/core/modalities/explore.js.map +1 -1
  123. package/dist/core/registry.d.ts.map +1 -1
  124. package/dist/core/registry.js +4 -1
  125. package/dist/core/registry.js.map +1 -1
  126. package/dist/design/critique.d.ts +86 -0
  127. package/dist/design/critique.d.ts.map +1 -0
  128. package/dist/design/critique.js +62 -0
  129. package/dist/design/critique.js.map +1 -0
  130. package/dist/design/index.d.ts +2 -0
  131. package/dist/design/index.d.ts.map +1 -1
  132. package/dist/design/index.js +1 -0
  133. package/dist/design/index.js.map +1 -1
  134. package/dist/design/schema.d.ts +74 -0
  135. package/dist/design/schema.d.ts.map +1 -1
  136. package/dist/design/schema.js +22 -0
  137. package/dist/design/schema.js.map +1 -1
  138. package/dist/design/style.d.ts +18 -0
  139. package/dist/design/style.d.ts.map +1 -0
  140. package/dist/design/style.js +34 -0
  141. package/dist/design/style.js.map +1 -0
  142. package/dist/documentarian/index.d.ts +53 -0
  143. package/dist/documentarian/index.d.ts.map +1 -0
  144. package/dist/documentarian/index.js +135 -0
  145. package/dist/documentarian/index.js.map +1 -0
  146. package/dist/eval/coverage.d.ts +49 -0
  147. package/dist/eval/coverage.d.ts.map +1 -0
  148. package/dist/eval/coverage.js +60 -0
  149. package/dist/eval/coverage.js.map +1 -0
  150. package/dist/eval/gap-cases.d.ts +21 -0
  151. package/dist/eval/gap-cases.d.ts.map +1 -0
  152. package/dist/eval/gap-cases.js +27 -0
  153. package/dist/eval/gap-cases.js.map +1 -0
  154. package/dist/eval/legend.d.ts +3 -3
  155. package/dist/eval/legend.js +3 -3
  156. package/dist/eval/pilot.d.ts +4 -1
  157. package/dist/eval/pilot.d.ts.map +1 -1
  158. package/dist/eval/pilot.js +9 -2
  159. package/dist/eval/pilot.js.map +1 -1
  160. package/dist/flow/crawl.d.ts +66 -0
  161. package/dist/flow/crawl.d.ts.map +1 -0
  162. package/dist/flow/crawl.js +0 -0
  163. package/dist/flow/crawl.js.map +1 -0
  164. package/dist/flow/journey.d.ts +25 -0
  165. package/dist/flow/journey.d.ts.map +1 -0
  166. package/dist/flow/journey.js +51 -0
  167. package/dist/flow/journey.js.map +1 -0
  168. package/dist/flow/setup.d.ts +85 -0
  169. package/dist/flow/setup.d.ts.map +1 -0
  170. package/dist/flow/setup.js +65 -0
  171. package/dist/flow/setup.js.map +1 -0
  172. package/dist/index.d.ts +2 -1
  173. package/dist/index.d.ts.map +1 -1
  174. package/dist/knowledge/index.d.ts +30 -4
  175. package/dist/knowledge/index.d.ts.map +1 -1
  176. package/dist/knowledge/index.js +80 -22
  177. package/dist/knowledge/index.js.map +1 -1
  178. package/dist/llm/index.d.ts +2 -2
  179. package/dist/llm/index.d.ts.map +1 -1
  180. package/dist/llm/index.js +1 -1
  181. package/dist/llm/index.js.map +1 -1
  182. package/dist/llm/routing.d.ts.map +1 -1
  183. package/dist/llm/routing.js +8 -2
  184. package/dist/llm/routing.js.map +1 -1
  185. package/dist/llm/schema-lint.d.ts +9 -0
  186. package/dist/llm/schema-lint.d.ts.map +1 -0
  187. package/dist/llm/schema-lint.js +42 -0
  188. package/dist/llm/schema-lint.js.map +1 -0
  189. package/dist/llm/structured.d.ts +22 -0
  190. package/dist/llm/structured.d.ts.map +1 -1
  191. package/dist/llm/structured.js +42 -0
  192. package/dist/llm/structured.js.map +1 -1
  193. package/dist/mcp/server.d.ts +9 -0
  194. package/dist/mcp/server.d.ts.map +1 -0
  195. package/dist/mcp/server.js +49 -0
  196. package/dist/mcp/server.js.map +1 -0
  197. package/dist/mcp/tools.d.ts +149 -0
  198. package/dist/mcp/tools.d.ts.map +1 -0
  199. package/dist/mcp/tools.js +138 -0
  200. package/dist/mcp/tools.js.map +1 -0
  201. package/dist/observe/parse-aria.d.ts.map +1 -1
  202. package/dist/observe/parse-aria.js +11 -2
  203. package/dist/observe/parse-aria.js.map +1 -1
  204. package/dist/project/index.d.ts +70 -0
  205. package/dist/project/index.d.ts.map +1 -0
  206. package/dist/project/index.js +173 -0
  207. package/dist/project/index.js.map +1 -0
  208. package/dist/prompts/local/identify-elements.d.ts +1 -1
  209. package/dist/prompts/local/identify-elements.d.ts.map +1 -1
  210. package/dist/prompts/local/identify-elements.js +5 -2
  211. package/dist/prompts/local/identify-elements.js.map +1 -1
  212. package/dist/prompts/local/index.d.ts.map +1 -1
  213. package/dist/prompts/local/index.js +8 -0
  214. package/dist/prompts/local/index.js.map +1 -1
  215. package/dist/prompts/local/pilot-review.d.ts +1 -1
  216. package/dist/prompts/local/pilot-review.d.ts.map +1 -1
  217. package/dist/prompts/local/pilot-review.js +2 -1
  218. package/dist/prompts/local/pilot-review.js.map +1 -1
  219. package/dist/prompts/local/qa-case-critique.d.ts +8 -0
  220. package/dist/prompts/local/qa-case-critique.d.ts.map +1 -0
  221. package/dist/prompts/local/qa-case-critique.js +34 -0
  222. package/dist/prompts/local/qa-case-critique.js.map +1 -0
  223. package/dist/prompts/local/qa-gap-cases.d.ts +7 -0
  224. package/dist/prompts/local/qa-gap-cases.d.ts.map +1 -0
  225. package/dist/prompts/local/qa-gap-cases.js +22 -0
  226. package/dist/prompts/local/qa-gap-cases.js.map +1 -0
  227. package/dist/prompts/local/qa-journey-from-flow.d.ts +7 -0
  228. package/dist/prompts/local/qa-journey-from-flow.d.ts.map +1 -0
  229. package/dist/prompts/local/qa-journey-from-flow.js +29 -0
  230. package/dist/prompts/local/qa-journey-from-flow.js.map +1 -0
  231. package/dist/prompts/local/qa-setup-planner.d.ts +6 -0
  232. package/dist/prompts/local/qa-setup-planner.d.ts.map +1 -0
  233. package/dist/prompts/local/qa-setup-planner.js +28 -0
  234. package/dist/prompts/local/qa-setup-planner.js.map +1 -0
  235. package/dist/prompts/local/qa-testcase-from-ui.d.ts +1 -1
  236. package/dist/prompts/local/qa-testcase-from-ui.d.ts.map +1 -1
  237. package/dist/prompts/local/qa-testcase-from-ui.js +2 -0
  238. package/dist/prompts/local/qa-testcase-from-ui.js.map +1 -1
  239. package/dist/safety/guardrails.d.ts +36 -0
  240. package/dist/safety/guardrails.d.ts.map +1 -0
  241. package/dist/safety/guardrails.js +60 -0
  242. package/dist/safety/guardrails.js.map +1 -0
  243. package/dist/tui/hooks/use-runs.d.ts.map +1 -1
  244. package/dist/tui/hooks/use-runs.js +4 -1
  245. package/dist/tui/hooks/use-runs.js.map +1 -1
  246. package/dist/tui/screens/runs-list-screen.d.ts.map +1 -1
  247. package/dist/tui/screens/runs-list-screen.js +3 -1
  248. package/dist/tui/screens/runs-list-screen.js.map +1 -1
  249. package/dist/tui/screens/summary-screen.d.ts.map +1 -1
  250. package/dist/tui/screens/summary-screen.js +1 -1
  251. package/dist/tui/screens/summary-screen.js.map +1 -1
  252. package/dist/tui/types.d.ts +7 -1
  253. package/dist/tui/types.d.ts.map +1 -1
  254. package/dist/validate/index.d.ts +7 -3
  255. package/dist/validate/index.d.ts.map +1 -1
  256. package/dist/validate/index.js +22 -3
  257. package/dist/validate/index.js.map +1 -1
  258. package/dist/validate/runner.d.ts +61 -1
  259. package/dist/validate/runner.d.ts.map +1 -1
  260. package/dist/validate/runner.js +67 -4
  261. package/dist/validate/runner.js.map +1 -1
  262. package/package.json +5 -1
@@ -0,0 +1,256 @@
1
+ /**
2
+ * The stable key an operation is identified by across the model/cases/results/coverage — same rule
3
+ * everywhere (API-6, #136): `operationId` if declared, else `METHOD path`.
4
+ */
5
+ export function apiEndpointKey(e) {
6
+ return e.operationId ?? `${e.method} ${e.path}`;
7
+ }
8
+ /** Generate one baseline happy-path case per operation, in the model's (deterministic) order. */
9
+ export function generateApiCases(model) {
10
+ return model.endpoints.map(toCase);
11
+ }
12
+ /**
13
+ * C1-04 / API-8 (#145) — one negative-schema case per operation that has a request contract worth
14
+ * violating: corrupt a request-body property to the wrong JSON type, or (bodyless operations) omit a
15
+ * required non-path parameter. An operation with neither (e.g. `GET /health`) has nothing to violate
16
+ * and is skipped — a forced violation would just be noise, not a contract check.
17
+ */
18
+ export function generateNegativeCases(model) {
19
+ return model.endpoints.map(toNegativeCase).filter((c) => c !== undefined);
20
+ }
21
+ /** Required params (as sent for the nominal happy path), optionally dropping one to violate it. */
22
+ function synthRequiredParams(e, omit) {
23
+ const params = { path: {}, query: {}, header: {}, cookie: {} };
24
+ for (const p of e.parameters) {
25
+ if (!p.required)
26
+ continue;
27
+ if (omit && p.in === omit.in && p.name === omit.name)
28
+ continue;
29
+ params[p.in][p.name] = synth(p.schema);
30
+ }
31
+ return params;
32
+ }
33
+ /** ALL params (required AND optional) with schema-synthesised values — the "curious" adversarial
34
+ * style's full-coverage variant of `synthRequiredParams` (BORROW-07, #95): optional params get
35
+ * exercised too, instead of the happy path's omit-if-optional convention. */
36
+ export function synthAllParams(e) {
37
+ const params = { path: {}, query: {}, header: {}, cookie: {} };
38
+ for (const p of e.parameters)
39
+ params[p.in][p.name] = synth(p.schema);
40
+ return params;
41
+ }
42
+ /** Body-schema properties that declare an `enum` with more than one value — the "curious" style's
43
+ * one-case-per-additional-value expansion needs the full list (the happy path's `synth()` only ever
44
+ * sends the first). */
45
+ export function enumProps(schema) {
46
+ if (!schema || typeof schema !== "object")
47
+ return [];
48
+ const out = [];
49
+ for (const [name, sub] of Object.entries(schema.properties ?? {})) {
50
+ if (sub.enum && sub.enum.length > 1)
51
+ out.push([name, sub.enum]);
52
+ }
53
+ return out;
54
+ }
55
+ /** Build the happy-path case for one operation (API-9, #146: also reused by `scenarios.ts` per step —
56
+ * a scenario step is a normal case whose path params get overwritten with captured values at run time). */
57
+ export function toCase(e) {
58
+ const success = pickSuccess(e);
59
+ const expectedStatus = success?.status ?? "200";
60
+ return {
61
+ name: apiEndpointKey(e),
62
+ method: e.method,
63
+ path: e.path,
64
+ operationId: e.operationId,
65
+ params: synthRequiredParams(e),
66
+ body: e.requestBody?.schema !== undefined ? synth(e.requestBody.schema) : undefined,
67
+ expectedStatus,
68
+ expectedSchema: success?.schema,
69
+ ...(success?.links ? { responseLinks: success.links } : {}),
70
+ ...(e.requestBody?.mediaTypes[0] !== undefined ? { bodyMediaType: e.requestBody.mediaTypes[0] } : {}),
71
+ type: "Positive",
72
+ // Nominal happy-path = the valid equivalence class for this operation's inputs (ISO 29119-4).
73
+ technique: "equivalence-partitioning",
74
+ rationale: `Happy-path case in the valid equivalence class for ${e.method} ${e.path}: exercises the ` +
75
+ `required parameters/body with schema-valid values and asserts the declared success response ` +
76
+ `(${expectedStatus}).`,
77
+ };
78
+ }
79
+ /** Body-schema properties whose declared (primitive) type we can flip to something invalid — reused
80
+ * by the "psycho"/"hacker" adversarial styles (BORROW-07, #95) to target a string/numeric property. */
81
+ export function corruptibleProps(schema) {
82
+ if (!schema || typeof schema !== "object")
83
+ return [];
84
+ const out = [];
85
+ for (const [name, sub] of Object.entries(schema.properties ?? {})) {
86
+ const type = Array.isArray(sub.type) ? sub.type.find((t) => t !== "null") : sub.type;
87
+ if (typeof type === "string")
88
+ out.push([name, type]);
89
+ }
90
+ return out;
91
+ }
92
+ /** A JSON value of a different type than `type` — always a contract violation for that property. */
93
+ function wrongTypeValue(type) {
94
+ switch (type) {
95
+ case "string":
96
+ return 42;
97
+ case "integer":
98
+ case "number":
99
+ return "not-a-number";
100
+ case "boolean":
101
+ return "not-a-boolean";
102
+ default:
103
+ return "not-a-valid-value"; // array/object/other
104
+ }
105
+ }
106
+ /** The lowest declared 4xx status, else the generic "4XX" range (matched by the runner's `statusMatches`).
107
+ * Reused by the "psycho"/"hacker" adversarial styles (BORROW-07, #95) — same "expect rejection"
108
+ * convention as a negative case. */
109
+ export function pickErrorStatus(e) {
110
+ const fourXX = e.responses.filter((r) => /^4\d\d$/.test(r.status)).sort((a, b) => a.status.localeCompare(b.status));
111
+ return fourXX[0]?.status ?? "4XX";
112
+ }
113
+ /** The declared response schema for an EXACT status match, if the case picked one (not the "4XX" fallback). */
114
+ export function pickErrorSchema(e, expectedStatus) {
115
+ return e.responses.find((r) => r.status === expectedStatus)?.schema;
116
+ }
117
+ function buildNegativeCase(e, input, violation) {
118
+ const expectedStatus = pickErrorStatus(e);
119
+ return {
120
+ name: `${apiEndpointKey(e)} (negative)`,
121
+ method: e.method,
122
+ path: e.path,
123
+ operationId: e.operationId,
124
+ params: input.params,
125
+ body: input.body,
126
+ expectedStatus,
127
+ expectedSchema: pickErrorSchema(e, expectedStatus),
128
+ type: "Negative",
129
+ // Deliberately-invalid input, chosen from experience of common contract violations (ISO 29119-4).
130
+ technique: "error-guessing",
131
+ rationale: `Negative-schema case for ${e.method} ${e.path}: ${violation}, expecting the API to reject the ` +
132
+ `request (${expectedStatus}) rather than accept it.`,
133
+ };
134
+ }
135
+ function toNegativeCase(e) {
136
+ const bodySchema = e.requestBody?.schema;
137
+ if (bodySchema) {
138
+ const [prop] = corruptibleProps(bodySchema);
139
+ if (prop) {
140
+ const [name, type] = prop;
141
+ const body = synth(bodySchema);
142
+ body[name] = wrongTypeValue(type);
143
+ return buildNegativeCase(e, { body, params: synthRequiredParams(e) }, `sends "${name}" as the wrong type in the request body (expected ${type})`);
144
+ }
145
+ }
146
+ const nonPathRequired = e.parameters.find((p) => p.required && p.in !== "path");
147
+ if (nonPathRequired) {
148
+ return buildNegativeCase(e, { params: synthRequiredParams(e, nonPathRequired) }, `omits the required ${nonPathRequired.in} param "${nonPathRequired.name}"`);
149
+ }
150
+ return undefined; // nothing in this operation's contract is worth violating
151
+ }
152
+ /** The declared success response: the lowest 2xx, else `default`, else the first declared. */
153
+ function pickSuccess(e) {
154
+ const twoXX = e.responses.filter((r) => /^2\d\d$/.test(r.status)).sort((a, b) => a.status.localeCompare(b.status));
155
+ return twoXX[0] ?? e.responses.find((r) => r.status === "default") ?? e.responses[0];
156
+ }
157
+ /**
158
+ * Synthesise one valid value for a (dereferenced) JSON schema, respecting `example`/`default`/`enum`,
159
+ * types, `required` and `format`. `seen` guards the object cycles swagger-parser leaves behind for
160
+ * circular `$ref`s (e.g. `Pet.friends: Pet[]`) so recursion terminates.
161
+ */
162
+ function synth(schema, seen = new Set()) {
163
+ if (!schema || typeof schema !== "object")
164
+ return undefined;
165
+ const s = schema;
166
+ // Explicit values win, in spec-precedence order.
167
+ if (s.example !== undefined)
168
+ return s.example;
169
+ if (s.default !== undefined)
170
+ return s.default;
171
+ if (s.enum && s.enum.length)
172
+ return s.enum[0];
173
+ // Composition: allOf = merge all subschemas; one/anyOf = take the first branch.
174
+ if (s.allOf?.length)
175
+ return synth(mergeAllOf(s.allOf), seen);
176
+ if (s.oneOf?.length)
177
+ return synth(s.oneOf[0], seen);
178
+ if (s.anyOf?.length)
179
+ return synth(s.anyOf[0], seen);
180
+ const type = Array.isArray(s.type) ? s.type.find((t) => t !== "null") : s.type;
181
+ // Objects/arrays recurse — stop if we re-enter the same schema node (circular ref).
182
+ if (type === "object" || s.properties) {
183
+ if (seen.has(s))
184
+ return undefined;
185
+ return synthObject(s, new Set(seen).add(s));
186
+ }
187
+ if (type === "array") {
188
+ if (seen.has(s))
189
+ return [];
190
+ return s.items ? [synth(s.items, new Set(seen).add(s))].filter((v) => v !== undefined) : [];
191
+ }
192
+ switch (type) {
193
+ case "string":
194
+ // `format: binary` (e.g. a multipart file field) needs real bytes, not the literal word "string".
195
+ return s.format === "binary" ? synthBinary() : synthString(s.format);
196
+ case "integer":
197
+ case "number":
198
+ return s.minimum ?? 0;
199
+ case "boolean":
200
+ return true;
201
+ default:
202
+ return undefined; // untyped/unknown schema → omit
203
+ }
204
+ }
205
+ function synthObject(s, seen) {
206
+ const required = new Set(s.required ?? []);
207
+ const out = {};
208
+ for (const [key, sub] of Object.entries(s.properties ?? {})) {
209
+ const v = synth(sub, seen);
210
+ if (v !== undefined)
211
+ out[key] = v;
212
+ // A required field whose schema we couldn't synthesise (e.g. circular) still has to be present.
213
+ else if (required.has(key))
214
+ out[key] = null;
215
+ }
216
+ return out;
217
+ }
218
+ /** Shallow-merge `allOf` members into one object schema (enough for happy-path bodies). */
219
+ function mergeAllOf(parts) {
220
+ const merged = { type: "object", properties: {}, required: [] };
221
+ for (const p of parts) {
222
+ Object.assign(merged.properties, p.properties ?? {});
223
+ if (p.required)
224
+ merged.required.push(...p.required);
225
+ }
226
+ return merged;
227
+ }
228
+ /** A small in-memory placeholder for a `format: binary` property (API-10, #150) — real bytes so a
229
+ * multipart file field has actual "file" content to send; the runner (`runner.ts`) recognises a
230
+ * `Buffer` value and encodes it as a file part instead of a stringified form field. */
231
+ function synthBinary() {
232
+ return Buffer.from("cairn placeholder file content");
233
+ }
234
+ /** A format-appropriate sample string (valid for the common OpenAPI string formats). */
235
+ function synthString(format) {
236
+ switch (format) {
237
+ case "email":
238
+ return "user@example.com";
239
+ case "uuid":
240
+ return "00000000-0000-0000-0000-000000000000";
241
+ case "date":
242
+ return "2024-01-01";
243
+ case "date-time":
244
+ return "2024-01-01T00:00:00Z";
245
+ case "uri":
246
+ case "url":
247
+ return "https://example.com";
248
+ case "hostname":
249
+ return "example.com";
250
+ case "ipv4":
251
+ return "127.0.0.1";
252
+ default:
253
+ return "string";
254
+ }
255
+ }
256
+ //# sourceMappingURL=cases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cases.js","sourceRoot":"","sources":["../../src/api/cases.ts"],"names":[],"mappings":"AA0BA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,CAAyD;IACtF,OAAO,CAAC,CAAC,WAAW,IAAI,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AAClD,CAAC;AA+CD,iGAAiG;AACjG,MAAM,UAAU,gBAAgB,CAAC,KAAe;IAC9C,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAe;IACnD,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;AAC1F,CAAC;AAED,mGAAmG;AACnG,SAAS,mBAAmB,CAAC,CAAc,EAAE,IAAe;IAC1D,MAAM,MAAM,GAAkB,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE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b,OAAO,aAAa,CAAC;QACvB,KAAK,MAAM;YACT,OAAO,WAAW,CAAC;QACrB;YACE,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * C1-04 / API-6 (#136) — spec-vs-tested coverage report (`playswag`-style, borrowed from
3
+ * AZANIR/qa-skills): given the ingested {@link ApiModel} (API-1) and the generated/executed cases
4
+ * (API-2/API-3), report which spec operations are untested, and which are only partially exercised.
5
+ *
6
+ * "Partial" falls naturally out of the data already on hand: an operation can declare several
7
+ * responses (200, 404, 500…), but every case generated so far (API-2) targets exactly one status —
8
+ * the happy path. So an operation is `covered` only when every response IT declares has a matching
9
+ * case, `partial` when some (but not all) are exercised, and `uncovered` when none are. Grouping by
10
+ * declared-vs-tested statuses (not raw case count) means this keeps working once later slices (API-8
11
+ * contract/negative cases, API-9 scenarios) generate more than one case per operation — no rework
12
+ * needed here. An operation declaring zero responses (malformed but parseable) has nothing to miss —
13
+ * vacuously `covered`, the same "nothing observed → nothing left uncovered" convention
14
+ * `eval/coverage.ts` already uses for its ratio.
15
+ *
16
+ * Pure set arithmetic (no LLM, no I/O) — the API sibling of `eval/coverage.ts` (web gap-analysis).
17
+ */
18
+ import { type ApiCase } from "./cases.js";
19
+ import type { ApiModel } from "./openapi.js";
20
+ import type { ApiCaseResult } from "./runner.js";
21
+ export type ApiCoverageStatus = "covered" | "partial" | "uncovered";
22
+ export interface ApiEndpointCoverage {
23
+ method: string;
24
+ path: string;
25
+ operationId?: string;
26
+ deprecated: boolean;
27
+ status: ApiCoverageStatus;
28
+ /** Every status the spec declares for this operation ("200","404",…). */
29
+ declaredStatuses: string[];
30
+ /** The subset of `declaredStatuses` some generated case actually targets. */
31
+ testedStatuses: string[];
32
+ /** Whether the run (if one happened) passed — undefined when no `--base-url` execution occurred. */
33
+ passed?: boolean;
34
+ }
35
+ export interface ApiCoverageReport {
36
+ endpointCount: number;
37
+ coveredCount: number;
38
+ partialCount: number;
39
+ uncoveredCount: number;
40
+ /** coveredCount / endpointCount (1 when the spec has no operations, never NaN). */
41
+ ratio: number;
42
+ /** Every operation, in the model's order — filter by `status` for a gaps-only view. */
43
+ endpoints: ApiEndpointCoverage[];
44
+ }
45
+ /**
46
+ * Coverage = for each spec operation, which of its declared response statuses a generated case
47
+ * exercises. `results` is optional — a cases-only invocation (no `--base-url`) still gets a
48
+ * meaningful report, just without the per-endpoint pass/fail overlay.
49
+ */
50
+ export declare function computeApiCoverage(model: ApiModel, cases: ApiCase[], results?: ApiCaseResult[]): ApiCoverageReport;
51
+ //# sourceMappingURL=coverage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/api/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAEpE,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,yEAAyE;IACzE,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,6EAA6E;IAC7E,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,oGAAoG;IACpG,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;IACd,uFAAuF;IACvF,SAAS,EAAE,mBAAmB,EAAE,CAAC;CAClC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,QAAQ,EACf,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,CAAC,EAAE,aAAa,EAAE,GACxB,iBAAiB,CA4CnB"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * C1-04 / API-6 (#136) — spec-vs-tested coverage report (`playswag`-style, borrowed from
3
+ * AZANIR/qa-skills): given the ingested {@link ApiModel} (API-1) and the generated/executed cases
4
+ * (API-2/API-3), report which spec operations are untested, and which are only partially exercised.
5
+ *
6
+ * "Partial" falls naturally out of the data already on hand: an operation can declare several
7
+ * responses (200, 404, 500…), but every case generated so far (API-2) targets exactly one status —
8
+ * the happy path. So an operation is `covered` only when every response IT declares has a matching
9
+ * case, `partial` when some (but not all) are exercised, and `uncovered` when none are. Grouping by
10
+ * declared-vs-tested statuses (not raw case count) means this keeps working once later slices (API-8
11
+ * contract/negative cases, API-9 scenarios) generate more than one case per operation — no rework
12
+ * needed here. An operation declaring zero responses (malformed but parseable) has nothing to miss —
13
+ * vacuously `covered`, the same "nothing observed → nothing left uncovered" convention
14
+ * `eval/coverage.ts` already uses for its ratio.
15
+ *
16
+ * Pure set arithmetic (no LLM, no I/O) — the API sibling of `eval/coverage.ts` (web gap-analysis).
17
+ */
18
+ import { apiEndpointKey } from "./cases.js";
19
+ /**
20
+ * Coverage = for each spec operation, which of its declared response statuses a generated case
21
+ * exercises. `results` is optional — a cases-only invocation (no `--base-url`) still gets a
22
+ * meaningful report, just without the per-endpoint pass/fail overlay.
23
+ */
24
+ export function computeApiCoverage(model, cases, results) {
25
+ const casesByKey = new Map();
26
+ for (const c of cases) {
27
+ const key = apiEndpointKey({ method: c.method, path: c.path, operationId: c.operationId });
28
+ const bucket = casesByKey.get(key);
29
+ if (bucket)
30
+ bucket.push(c);
31
+ else
32
+ casesByKey.set(key, [c]);
33
+ }
34
+ const resultByName = new Map((results ?? []).map((r) => [r.name, r]));
35
+ let coveredCount = 0;
36
+ let partialCount = 0;
37
+ let uncoveredCount = 0;
38
+ const endpoints = model.endpoints.map((e) => {
39
+ const key = apiEndpointKey(e);
40
+ const targeting = casesByKey.get(key) ?? [];
41
+ const declaredStatuses = [...new Set(e.responses.map((r) => r.status))];
42
+ const testedStatuses = declaredStatuses.filter((s) => targeting.some((c) => c.expectedStatus === s));
43
+ // A malformed-but-parseable operation with no declared responses has nothing to miss — vacuously
44
+ // "covered" (same convention `eval/coverage.ts` uses: ratio is 1 when nothing was observed).
45
+ const status = declaredStatuses.length === 0 || testedStatuses.length === declaredStatuses.length
46
+ ? "covered"
47
+ : testedStatuses.length === 0
48
+ ? "uncovered"
49
+ : "partial";
50
+ if (status === "covered")
51
+ coveredCount += 1;
52
+ else if (status === "partial")
53
+ partialCount += 1;
54
+ else
55
+ uncoveredCount += 1;
56
+ const passed = targeting.length > 0 ? targeting.every((c) => resultByName.get(c.name)?.passed) : undefined;
57
+ return endpointCoverage(e, status, declaredStatuses, testedStatuses, results ? passed : undefined);
58
+ });
59
+ return {
60
+ endpointCount: model.endpoints.length,
61
+ coveredCount,
62
+ partialCount,
63
+ uncoveredCount,
64
+ ratio: model.endpoints.length === 0 ? 1 : coveredCount / model.endpoints.length,
65
+ endpoints,
66
+ };
67
+ }
68
+ function endpointCoverage(e, status, declaredStatuses, testedStatuses, passed) {
69
+ return {
70
+ method: e.method,
71
+ path: e.path,
72
+ operationId: e.operationId,
73
+ deprecated: e.deprecated,
74
+ status,
75
+ declaredStatuses,
76
+ testedStatuses,
77
+ ...(passed !== undefined ? { passed } : {}),
78
+ };
79
+ }
80
+ //# sourceMappingURL=coverage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.js","sourceRoot":"","sources":["../../src/api/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,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C,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM;QAC/E,SAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CACvB,CAAc,EACd,MAAyB,EACzB,gBAA0B,EAC1B,cAAwB,EACxB,MAA2B;IAE3B,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,MAAM;QACN,gBAAgB;QAChB,cAAc;QACd,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * C1-04 / API-1 (#22) — OpenAPI ingest into Cairn's internal endpoint model.
3
+ *
4
+ * This is the FIRST vertical slice of the `api` modality: it only *reads* an OpenAPI v3 spec
5
+ * (JSON or YAML, from a file path or a URL) and flattens it into a small, generation-ready model
6
+ * (one entry per method × path). Case generation, the runner, the report and the Plune-record write
7
+ * are later slices (API-2 #137 / API-3 #138) — nothing here generates or executes anything.
8
+ *
9
+ * Parsing, YAML support, `$ref` resolution (incl. circular refs) and 3.0/3.1 handling are delegated
10
+ * to the maintained `@apidevtools/swagger-parser` (lazy-loaded so it stays off every non-api path).
11
+ */
12
+ /** One parameter of an endpoint (query/path/header/cookie). */
13
+ export interface ApiParam {
14
+ name: string;
15
+ in: "query" | "path" | "header" | "cookie";
16
+ required: boolean;
17
+ /** Dereferenced JSON schema for the parameter value (may be absent). */
18
+ schema?: unknown;
19
+ }
20
+ /**
21
+ * An OpenAPI `links` entry (API-9, #146): declares which other operation a response can seed, and
22
+ * how — `parameters` maps a *target*-operation parameter name to a runtime expression (e.g.
23
+ * `"$response.body#/id"`) evaluated against this response. The spec-native alternative to guessing
24
+ * "which field feeds the next request" by name.
25
+ */
26
+ export interface ApiLink {
27
+ operationId?: string;
28
+ parameters: Record<string, string>;
29
+ }
30
+ /** One response of an endpoint, keyed by status code (or "default"). */
31
+ export interface ApiResponse {
32
+ status: string;
33
+ description?: string;
34
+ /** Schema of the first response media type, if the response carries a body. */
35
+ schema?: unknown;
36
+ /** Declared `links` (API-9, #146) — empty when the spec doesn't declare any. */
37
+ links?: Record<string, ApiLink>;
38
+ }
39
+ /** The request body of an endpoint (absent for GET/DELETE-style ops without a body). */
40
+ export interface ApiRequestBody {
41
+ required: boolean;
42
+ mediaTypes: string[];
43
+ /** Schema of the first request media type, if any. */
44
+ schema?: unknown;
45
+ }
46
+ /** One operation: a single HTTP method on a single path. */
47
+ export interface ApiEndpoint {
48
+ /** Upper-case HTTP method, e.g. "GET", "POST". */
49
+ method: string;
50
+ /** Templated path, e.g. "/users/{id}". */
51
+ path: string;
52
+ operationId?: string;
53
+ summary?: string;
54
+ tags: string[];
55
+ parameters: ApiParam[];
56
+ requestBody?: ApiRequestBody;
57
+ responses: ApiResponse[];
58
+ /** Names of the security schemes this op requires (operation-level, else the spec default). */
59
+ security: string[];
60
+ /** The spec's own `deprecated:` flag (API-6, #136) — surfaced, not filtered: still worth a coverage row. */
61
+ deprecated: boolean;
62
+ }
63
+ /** The flattened spec: everything a later slice (API-2) needs to design + run cases. */
64
+ export interface ApiModel {
65
+ title?: string;
66
+ /** info.version of the described API (not the OpenAPI version). */
67
+ version?: string;
68
+ /** The `openapi:` field, e.g. "3.0.3" / "3.1.0". */
69
+ openapiVersion: string;
70
+ endpoints: ApiEndpoint[];
71
+ /** Distinct tags across all endpoints, sorted. */
72
+ tags: string[];
73
+ /** Names declared under components.securitySchemes. */
74
+ securitySchemes: string[];
75
+ }
76
+ /**
77
+ * Read an OpenAPI 3.x spec (JSON or YAML; file path or URL) and flatten it into an {@link ApiModel}.
78
+ *
79
+ * Throws a single, message-clear `Error` on anything we can't use — unreadable/invalid spec,
80
+ * unresolvable `$ref`, or an unsupported version (Swagger 2.0 / non-3.x) — so the command can report
81
+ * it instead of crashing.
82
+ */
83
+ export declare function ingestOpenApi(spec: string): Promise<ApiModel>;
84
+ //# sourceMappingURL=openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/api/openapi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,+DAA+D;AAC/D,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,wEAAwE;IACxE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,wEAAwE;AACxE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,sDAAsD;IACtD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,4DAA4D;AAC5D,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,cAAc,CAAC;IAC7B,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,+FAA+F;IAC/F,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,4GAA4G;IAC5G,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,wFAAwF;AACxF,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,kDAAkD;IAClD,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,uDAAuD;IACvD,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AA0CD;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwDnE"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * C1-04 / API-1 (#22) — OpenAPI ingest into Cairn's internal endpoint model.
3
+ *
4
+ * This is the FIRST vertical slice of the `api` modality: it only *reads* an OpenAPI v3 spec
5
+ * (JSON or YAML, from a file path or a URL) and flattens it into a small, generation-ready model
6
+ * (one entry per method × path). Case generation, the runner, the report and the Plune-record write
7
+ * are later slices (API-2 #137 / API-3 #138) — nothing here generates or executes anything.
8
+ *
9
+ * Parsing, YAML support, `$ref` resolution (incl. circular refs) and 3.0/3.1 handling are delegated
10
+ * to the maintained `@apidevtools/swagger-parser` (lazy-loaded so it stays off every non-api path).
11
+ */
12
+ const HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
13
+ /**
14
+ * Read an OpenAPI 3.x spec (JSON or YAML; file path or URL) and flatten it into an {@link ApiModel}.
15
+ *
16
+ * Throws a single, message-clear `Error` on anything we can't use — unreadable/invalid spec,
17
+ * unresolvable `$ref`, or an unsupported version (Swagger 2.0 / non-3.x) — so the command can report
18
+ * it instead of crashing.
19
+ */
20
+ export async function ingestOpenApi(spec) {
21
+ // Lazy: keep swagger-parser (and its YAML/ref-resolver deps) off every non-`api` code path.
22
+ const { default: SwaggerParser } = await import("@apidevtools/swagger-parser");
23
+ let doc;
24
+ try {
25
+ // dereference = parse (JSON/YAML, file/URL) + resolve every $ref (circular refs become object
26
+ // cycles rather than throwing), so the walk below sees concrete params/schemas.
27
+ doc = (await SwaggerParser.dereference(spec));
28
+ }
29
+ catch (e) {
30
+ throw new Error(`Could not read OpenAPI spec "${spec}": ${e.message}`);
31
+ }
32
+ const version = doc.openapi;
33
+ if (!version || !/^3\./.test(version)) {
34
+ throw new Error(doc.swagger
35
+ ? `Unsupported spec: Swagger/OpenAPI 2.0 ("swagger: ${doc.swagger}") — provide an OpenAPI 3.x spec.`
36
+ : `Unsupported spec: expected an "openapi: 3.x" document (got ${version ? `"${version}"` : "no openapi/swagger field"}).`);
37
+ }
38
+ const endpoints = [];
39
+ for (const [path, item] of Object.entries(doc.paths ?? {})) {
40
+ if (!item)
41
+ continue;
42
+ const pathParams = item.parameters ?? [];
43
+ for (const method of HTTP_METHODS) {
44
+ const op = item[method];
45
+ if (!op || typeof op !== "object")
46
+ continue;
47
+ endpoints.push({
48
+ method: method.toUpperCase(),
49
+ path,
50
+ operationId: op.operationId,
51
+ summary: op.summary,
52
+ tags: op.tags ?? [],
53
+ parameters: mergeParams(pathParams, op.parameters ?? []).map(toApiParam),
54
+ requestBody: toRequestBody(op.requestBody),
55
+ responses: toResponses(op.responses),
56
+ // Operation security overrides the spec default; [] means "explicitly public".
57
+ security: securityNames(op.security ?? doc.security ?? []),
58
+ deprecated: op.deprecated ?? false,
59
+ });
60
+ }
61
+ }
62
+ const tags = [...new Set(endpoints.flatMap((e) => e.tags))].sort();
63
+ const securitySchemes = Object.keys(doc.components?.securitySchemes ?? {});
64
+ return {
65
+ title: doc.info?.title,
66
+ version: doc.info?.version,
67
+ openapiVersion: version,
68
+ endpoints,
69
+ tags,
70
+ securitySchemes,
71
+ };
72
+ }
73
+ /** Merge path-level params with operation params; an op param overrides a path param of same (name,in). */
74
+ function mergeParams(pathParams, opParams) {
75
+ const byKey = new Map();
76
+ for (const p of pathParams)
77
+ byKey.set(`${p.in}:${p.name}`, p);
78
+ for (const p of opParams)
79
+ byKey.set(`${p.in}:${p.name}`, p);
80
+ return [...byKey.values()];
81
+ }
82
+ function toApiParam(p) {
83
+ const where = p.in === "query" || p.in === "path" || p.in === "header" || p.in === "cookie" ? p.in : "query";
84
+ return { name: p.name, in: where, required: p.required ?? where === "path", schema: p.schema };
85
+ }
86
+ function toRequestBody(rb) {
87
+ if (!rb)
88
+ return undefined;
89
+ const content = rb.content ?? {};
90
+ const mediaTypes = Object.keys(content);
91
+ const first = mediaTypes[0];
92
+ return { required: rb.required ?? false, mediaTypes, schema: first ? content[first]?.schema : undefined };
93
+ }
94
+ function toResponses(responses) {
95
+ return Object.entries(responses ?? {}).map(([status, r]) => {
96
+ const first = Object.keys(r.content ?? {})[0];
97
+ const links = toLinks(r.links);
98
+ return {
99
+ status,
100
+ description: r.description,
101
+ schema: first ? r.content?.[first]?.schema : undefined,
102
+ ...(links ? { links } : {}),
103
+ };
104
+ });
105
+ }
106
+ /** API-9 (#146): declared `links`, if any — `undefined` (not `{}`) when the spec declares none. */
107
+ function toLinks(raw) {
108
+ if (!raw || Object.keys(raw).length === 0)
109
+ return undefined;
110
+ const out = {};
111
+ for (const [name, l] of Object.entries(raw))
112
+ out[name] = { operationId: l.operationId, parameters: l.parameters ?? {} };
113
+ return out;
114
+ }
115
+ /** Flatten security requirement objects to the distinct set of scheme names they reference. */
116
+ function securityNames(reqs) {
117
+ return [...new Set(reqs.flatMap((r) => Object.keys(r)))];
118
+ }
119
+ //# sourceMappingURL=openapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../src/api/openapi.ts"],"names":[],"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