@gate-forge/cli 0.7.1 → 0.8.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 (254) hide show
  1. package/README.md +499 -47
  2. package/dist/adapter-audit.d.ts +154 -0
  3. package/dist/adapter-audit.d.ts.map +1 -0
  4. package/dist/adapter-audit.js +531 -0
  5. package/dist/adapter-audit.js.map +1 -0
  6. package/dist/adapter-scaffold.d.ts +66 -0
  7. package/dist/adapter-scaffold.d.ts.map +1 -0
  8. package/dist/adapter-scaffold.js +353 -0
  9. package/dist/adapter-scaffold.js.map +1 -0
  10. package/dist/adopted-baseline.d.ts +10 -0
  11. package/dist/adopted-baseline.d.ts.map +1 -1
  12. package/dist/adopted-baseline.js +18 -1
  13. package/dist/adopted-baseline.js.map +1 -1
  14. package/dist/args.d.ts +15 -0
  15. package/dist/args.d.ts.map +1 -1
  16. package/dist/args.js +59 -2
  17. package/dist/args.js.map +1 -1
  18. package/dist/behavior-setup.d.ts +239 -0
  19. package/dist/behavior-setup.d.ts.map +1 -0
  20. package/dist/behavior-setup.js +738 -0
  21. package/dist/behavior-setup.js.map +1 -0
  22. package/dist/broker.d.ts.map +1 -1
  23. package/dist/broker.js +28 -2
  24. package/dist/broker.js.map +1 -1
  25. package/dist/cache-exclusions.d.ts +45 -0
  26. package/dist/cache-exclusions.d.ts.map +1 -0
  27. package/dist/cache-exclusions.js +205 -0
  28. package/dist/cache-exclusions.js.map +1 -0
  29. package/dist/candidate-tree.d.ts +86 -14
  30. package/dist/candidate-tree.d.ts.map +1 -1
  31. package/dist/candidate-tree.js +236 -62
  32. package/dist/candidate-tree.js.map +1 -1
  33. package/dist/ci-witnessed-template.d.ts +43 -0
  34. package/dist/ci-witnessed-template.d.ts.map +1 -0
  35. package/dist/ci-witnessed-template.js +283 -0
  36. package/dist/ci-witnessed-template.js.map +1 -0
  37. package/dist/cli.d.ts +1 -1
  38. package/dist/cli.d.ts.map +1 -1
  39. package/dist/cli.js +31 -4
  40. package/dist/cli.js.map +1 -1
  41. package/dist/commands/adapters.d.ts +15 -0
  42. package/dist/commands/adapters.d.ts.map +1 -0
  43. package/dist/commands/adapters.js +284 -0
  44. package/dist/commands/adapters.js.map +1 -0
  45. package/dist/commands/adopt.d.ts.map +1 -1
  46. package/dist/commands/adopt.js +9 -1
  47. package/dist/commands/adopt.js.map +1 -1
  48. package/dist/commands/baseline.d.ts.map +1 -1
  49. package/dist/commands/baseline.js +42 -1
  50. package/dist/commands/baseline.js.map +1 -1
  51. package/dist/commands/blocking.d.ts +81 -2
  52. package/dist/commands/blocking.d.ts.map +1 -1
  53. package/dist/commands/blocking.js +336 -53
  54. package/dist/commands/blocking.js.map +1 -1
  55. package/dist/commands/check.d.ts +36 -0
  56. package/dist/commands/check.d.ts.map +1 -1
  57. package/dist/commands/check.js +1008 -62
  58. package/dist/commands/check.js.map +1 -1
  59. package/dist/commands/classify.d.ts +2 -1
  60. package/dist/commands/classify.d.ts.map +1 -1
  61. package/dist/commands/classify.js +143 -5
  62. package/dist/commands/classify.js.map +1 -1
  63. package/dist/commands/enforce.d.ts +4 -4
  64. package/dist/commands/enforce.d.ts.map +1 -1
  65. package/dist/commands/enforce.js +41 -9
  66. package/dist/commands/enforce.js.map +1 -1
  67. package/dist/commands/enforcement.d.ts +13 -1
  68. package/dist/commands/enforcement.d.ts.map +1 -1
  69. package/dist/commands/enforcement.js +800 -30
  70. package/dist/commands/enforcement.js.map +1 -1
  71. package/dist/commands/history.d.ts +12 -0
  72. package/dist/commands/history.d.ts.map +1 -0
  73. package/dist/commands/history.js +45 -0
  74. package/dist/commands/history.js.map +1 -0
  75. package/dist/commands/init-presets.d.ts +148 -0
  76. package/dist/commands/init-presets.d.ts.map +1 -0
  77. package/dist/commands/init-presets.js +194 -0
  78. package/dist/commands/init-presets.js.map +1 -0
  79. package/dist/commands/init.d.ts +7 -12
  80. package/dist/commands/init.d.ts.map +1 -1
  81. package/dist/commands/init.js +610 -69
  82. package/dist/commands/init.js.map +1 -1
  83. package/dist/commands/keys.d.ts.map +1 -1
  84. package/dist/commands/keys.js +29 -13
  85. package/dist/commands/keys.js.map +1 -1
  86. package/dist/commands/next.d.ts.map +1 -1
  87. package/dist/commands/next.js +744 -15
  88. package/dist/commands/next.js.map +1 -1
  89. package/dist/commands/pre-commit.d.ts +25 -0
  90. package/dist/commands/pre-commit.d.ts.map +1 -1
  91. package/dist/commands/pre-commit.js +91 -6
  92. package/dist/commands/pre-commit.js.map +1 -1
  93. package/dist/commands/quarantine.d.ts +16 -0
  94. package/dist/commands/quarantine.d.ts.map +1 -0
  95. package/dist/commands/quarantine.js +213 -0
  96. package/dist/commands/quarantine.js.map +1 -0
  97. package/dist/commands/run.d.ts +39 -0
  98. package/dist/commands/run.d.ts.map +1 -0
  99. package/dist/commands/run.js +196 -0
  100. package/dist/commands/run.js.map +1 -0
  101. package/dist/commands/test-gates.d.ts +284 -2
  102. package/dist/commands/test-gates.d.ts.map +1 -1
  103. package/dist/commands/test-gates.js +3619 -186
  104. package/dist/commands/test-gates.js.map +1 -1
  105. package/dist/commands/tests.d.ts +1 -1
  106. package/dist/commands/tests.d.ts.map +1 -1
  107. package/dist/commands/tests.js +225 -22
  108. package/dist/commands/tests.js.map +1 -1
  109. package/dist/endpoint-compiler.d.ts.map +1 -1
  110. package/dist/endpoint-compiler.js +29 -8
  111. package/dist/endpoint-compiler.js.map +1 -1
  112. package/dist/engine-browser.d.ts +183 -0
  113. package/dist/engine-browser.d.ts.map +1 -0
  114. package/dist/engine-browser.js +381 -0
  115. package/dist/engine-browser.js.map +1 -0
  116. package/dist/engine-identity.d.ts +100 -0
  117. package/dist/engine-identity.d.ts.map +1 -0
  118. package/dist/engine-identity.js +182 -0
  119. package/dist/engine-identity.js.map +1 -0
  120. package/dist/evaluate.d.ts +89 -0
  121. package/dist/evaluate.d.ts.map +1 -1
  122. package/dist/evaluate.js +137 -16
  123. package/dist/evaluate.js.map +1 -1
  124. package/dist/execution.d.ts +253 -9
  125. package/dist/execution.d.ts.map +1 -1
  126. package/dist/execution.js +309 -12
  127. package/dist/execution.js.map +1 -1
  128. package/dist/git-hooks.d.ts +17 -0
  129. package/dist/git-hooks.d.ts.map +1 -1
  130. package/dist/git-hooks.js +119 -0
  131. package/dist/git-hooks.js.map +1 -1
  132. package/dist/git-objects.d.ts +60 -0
  133. package/dist/git-objects.d.ts.map +1 -0
  134. package/dist/git-objects.js +152 -0
  135. package/dist/git-objects.js.map +1 -0
  136. package/dist/history.d.ts +52 -0
  137. package/dist/history.d.ts.map +1 -0
  138. package/dist/history.js +116 -0
  139. package/dist/history.js.map +1 -0
  140. package/dist/host-load.d.ts +49 -0
  141. package/dist/host-load.d.ts.map +1 -0
  142. package/dist/host-load.js +78 -0
  143. package/dist/host-load.js.map +1 -0
  144. package/dist/input-snapshot.d.ts +63 -9
  145. package/dist/input-snapshot.d.ts.map +1 -1
  146. package/dist/input-snapshot.js +195 -17
  147. package/dist/input-snapshot.js.map +1 -1
  148. package/dist/io.d.ts +36 -0
  149. package/dist/io.d.ts.map +1 -1
  150. package/dist/io.js +21 -0
  151. package/dist/io.js.map +1 -1
  152. package/dist/mapping.d.ts +84 -1
  153. package/dist/mapping.d.ts.map +1 -1
  154. package/dist/mapping.js +276 -5
  155. package/dist/mapping.js.map +1 -1
  156. package/dist/native-freeze.d.ts +217 -0
  157. package/dist/native-freeze.d.ts.map +1 -0
  158. package/dist/native-freeze.js +332 -0
  159. package/dist/native-freeze.js.map +1 -0
  160. package/dist/pipeline.d.ts +52 -1
  161. package/dist/pipeline.d.ts.map +1 -1
  162. package/dist/pipeline.js +141 -3
  163. package/dist/pipeline.js.map +1 -1
  164. package/dist/playwright-browsers.d.ts +210 -0
  165. package/dist/playwright-browsers.d.ts.map +1 -0
  166. package/dist/playwright-browsers.js +364 -0
  167. package/dist/playwright-browsers.js.map +1 -0
  168. package/dist/plugins.d.ts +15 -5
  169. package/dist/plugins.d.ts.map +1 -1
  170. package/dist/plugins.js +59 -9
  171. package/dist/plugins.js.map +1 -1
  172. package/dist/progress.d.ts +148 -0
  173. package/dist/progress.d.ts.map +1 -0
  174. package/dist/progress.js +263 -0
  175. package/dist/progress.js.map +1 -0
  176. package/dist/providers.d.ts +26 -1
  177. package/dist/providers.d.ts.map +1 -1
  178. package/dist/providers.js +39 -0
  179. package/dist/providers.js.map +1 -1
  180. package/dist/receipts.d.ts +1 -0
  181. package/dist/receipts.d.ts.map +1 -1
  182. package/dist/receipts.js +35 -7
  183. package/dist/receipts.js.map +1 -1
  184. package/dist/repo-scan.d.ts +8 -1
  185. package/dist/repo-scan.d.ts.map +1 -1
  186. package/dist/repo-scan.js +221 -27
  187. package/dist/repo-scan.js.map +1 -1
  188. package/dist/reseal-chain.d.ts +184 -0
  189. package/dist/reseal-chain.d.ts.map +1 -0
  190. package/dist/reseal-chain.js +735 -0
  191. package/dist/reseal-chain.js.map +1 -0
  192. package/dist/reseal-evidence.d.ts +241 -0
  193. package/dist/reseal-evidence.d.ts.map +1 -0
  194. package/dist/reseal-evidence.js +319 -0
  195. package/dist/reseal-evidence.js.map +1 -0
  196. package/dist/reseal.d.ts +181 -0
  197. package/dist/reseal.d.ts.map +1 -0
  198. package/dist/reseal.js +1620 -0
  199. package/dist/reseal.js.map +1 -0
  200. package/dist/response-field-guidance.d.ts +82 -0
  201. package/dist/response-field-guidance.d.ts.map +1 -0
  202. package/dist/response-field-guidance.js +184 -0
  203. package/dist/response-field-guidance.js.map +1 -0
  204. package/dist/run-cache.d.ts +260 -0
  205. package/dist/run-cache.d.ts.map +1 -0
  206. package/dist/run-cache.js +771 -0
  207. package/dist/run-cache.js.map +1 -0
  208. package/dist/run-preflight.d.ts +77 -0
  209. package/dist/run-preflight.d.ts.map +1 -0
  210. package/dist/run-preflight.js +774 -0
  211. package/dist/run-preflight.js.map +1 -0
  212. package/dist/run-recipe.d.ts +107 -0
  213. package/dist/run-recipe.d.ts.map +1 -0
  214. package/dist/run-recipe.js +295 -0
  215. package/dist/run-recipe.js.map +1 -0
  216. package/dist/run-reliability.d.ts +126 -0
  217. package/dist/run-reliability.d.ts.map +1 -0
  218. package/dist/run-reliability.js +221 -0
  219. package/dist/run-reliability.js.map +1 -0
  220. package/dist/runtime.d.ts +15 -0
  221. package/dist/runtime.d.ts.map +1 -1
  222. package/dist/runtime.js +11 -1
  223. package/dist/runtime.js.map +1 -1
  224. package/dist/secret-guard.d.ts +36 -0
  225. package/dist/secret-guard.d.ts.map +1 -0
  226. package/dist/secret-guard.js +63 -0
  227. package/dist/secret-guard.js.map +1 -0
  228. package/dist/singleton-guidance.d.ts +73 -0
  229. package/dist/singleton-guidance.d.ts.map +1 -0
  230. package/dist/singleton-guidance.js +118 -0
  231. package/dist/singleton-guidance.js.map +1 -0
  232. package/dist/staged-candidate.d.ts +17 -0
  233. package/dist/staged-candidate.d.ts.map +1 -1
  234. package/dist/staged-candidate.js +50 -0
  235. package/dist/staged-candidate.js.map +1 -1
  236. package/dist/state-artifacts.d.ts +70 -0
  237. package/dist/state-artifacts.d.ts.map +1 -0
  238. package/dist/state-artifacts.js +215 -0
  239. package/dist/state-artifacts.js.map +1 -0
  240. package/dist/state.d.ts +170 -2
  241. package/dist/state.d.ts.map +1 -1
  242. package/dist/state.js +248 -8
  243. package/dist/state.js.map +1 -1
  244. package/dist/verifier-keys.d.ts +33 -2
  245. package/dist/verifier-keys.d.ts.map +1 -1
  246. package/dist/verifier-keys.js +95 -9
  247. package/dist/verifier-keys.js.map +1 -1
  248. package/guides/CONNECT-YOUR-PROJECT.md +367 -0
  249. package/guides/QUICKSTART.md +259 -24
  250. package/guides/RUNNER-NEUTRAL-EVIDENCE.md +199 -0
  251. package/guides/TEST-ENVIRONMENT.md +1041 -6
  252. package/guides/UPGRADE-0.6-to-0.7.md +3 -3
  253. package/guides/UPGRADE-0.7-to-0.8.md +114 -0
  254. package/package.json +10 -9
@@ -0,0 +1,154 @@
1
+ import type { GraphResource, HttpRouteCandidate } from '@gate-forge/core';
2
+ /** The header the target environment presents its marker in (GF-13). */
3
+ export declare const ENV_FINGERPRINT_HEADER = "x-gateforge-env-fingerprint";
4
+ /** One adapter file, loaded and validated. */
5
+ export interface AdapterFileReport {
6
+ /** Adapter name (the file's base name, without `.mjs`). */
7
+ name: string;
8
+ /** Absolute path of the adapter module. */
9
+ file: string;
10
+ /** True when the module satisfies the frozen contract. */
11
+ ok: boolean;
12
+ /** Why it is not (empty when ok). */
13
+ issues: string[];
14
+ /** The loaded module, when it loaded at all. */
15
+ module: Record<string, unknown> | null;
16
+ /** Declared capabilities (empty defaults for a broken module). */
17
+ declares: {
18
+ /** The adapter can list the collection (pre-observation). */
19
+ list: boolean;
20
+ /** Entity-scoped create absence via a natural key. */
21
+ naturalKey: boolean;
22
+ /** Server-computed fields the adapter declared (E18a). */
23
+ volatileFields: string[];
24
+ /** Removal semantics the adapter declares. */
25
+ deletion: string | null;
26
+ /** Environment marker the adapter declares. */
27
+ environmentFingerprint: string | null;
28
+ };
29
+ }
30
+ /** The outcome of one `--probe` GET. */
31
+ export type AdapterProbeOutcome = 'ok' | 'absent' | 'auth' | 'fingerprint-mismatch' | 'failed' | 'skipped';
32
+ /** One probe result. */
33
+ export interface AdapterProbeReport {
34
+ /** The adapter that was probed. */
35
+ name: string;
36
+ /** What happened. */
37
+ outcome: AdapterProbeOutcome;
38
+ /** The path the probe read. */
39
+ path: string;
40
+ /** Human detail (never a credential). */
41
+ detail: string;
42
+ }
43
+ /**
44
+ * Lists the adapter module files in one adapters directory.
45
+ *
46
+ * Args:
47
+ * adaptersDir: absolute path of the adapters directory.
48
+ *
49
+ * Returns:
50
+ * string[]: absolute paths of every `.mjs` adapter, sorted by name.
51
+ */
52
+ export declare function listAdapterFiles(adaptersDir: string): string[];
53
+ /**
54
+ * Loads one adapter module and validates it against the frozen contract.
55
+ *
56
+ * Args:
57
+ * file: absolute path of the `.mjs` adapter.
58
+ *
59
+ * Returns:
60
+ * AdapterFileReport: the verdict plus what the module declares. A
61
+ * module that cannot even be imported is reported, never thrown.
62
+ */
63
+ export declare function auditAdapterFile(file: string): Promise<AdapterFileReport>;
64
+ /**
65
+ * Loads and validates every adapter in a directory.
66
+ *
67
+ * Args:
68
+ * adaptersDir: absolute path of the adapters directory.
69
+ *
70
+ * Returns:
71
+ * AdapterFileReport[]: one report per `.mjs` file, sorted by name.
72
+ */
73
+ export declare function auditAdapters(adaptersDir: string): Promise<AdapterFileReport[]>;
74
+ /**
75
+ * Normalizes one compiled route path to the engine's `{...}` shape so
76
+ * `pathMatchesShape` can compare it with a concrete adapter path.
77
+ *
78
+ * Args:
79
+ * canonicalPath: the compiled route shape (`:id` style).
80
+ *
81
+ * Returns:
82
+ * string: the same shape with every positional segment as `{}`.
83
+ */
84
+ export declare function toShapePath(canonicalPath: string): string;
85
+ /**
86
+ * Whether a declared adapter path instantiates a compiled GET route.
87
+ *
88
+ * Args:
89
+ * adapterPath: the path an adapter declares (query stripped).
90
+ * routes: the compiled route inventory.
91
+ *
92
+ * Returns:
93
+ * boolean: true when some GET route has the same shape.
94
+ */
95
+ export declare function pathIsCompiledGet(adapterPath: string, routes: readonly HttpRouteCandidate[]): boolean;
96
+ /**
97
+ * The GET routes that could serve one business resource: those the
98
+ * engine LINKED to it, plus (clearly separated) those whose path NAMES
99
+ * it. Linkage is evidence; a name match is a candidate the scaffolder
100
+ * marks as a guess. Naming is matched per whole path segment, with `_`
101
+ * and `-` treated as the same separator, so a table `work_reports`
102
+ * still finds `/api/v1/work-reports` — but `tasks` never matches
103
+ * `/api/v1/tasks-archive` or `/api/v1/subtasks`.
104
+ *
105
+ * Args:
106
+ * resource: the business resource.
107
+ * routes: the compiled route inventory.
108
+ *
109
+ * Returns:
110
+ * {linked: HttpRouteCandidate[], candidates: HttpRouteCandidate[]}.
111
+ */
112
+ export declare function routesForResource(resource: GraphResource, routes: readonly HttpRouteCandidate[]): {
113
+ linked: HttpRouteCandidate[];
114
+ candidates: HttpRouteCandidate[];
115
+ };
116
+ /**
117
+ * Splits one compiled path into its literal prefix and its trailing
118
+ * positional segments (`:id` / `{}`).
119
+ *
120
+ * Args:
121
+ * canonicalPath: the compiled route shape.
122
+ *
123
+ * Returns:
124
+ * {prefix: string, idSegments: string[]}: the collection path and the
125
+ * positional tail (empty for a collection route).
126
+ */
127
+ export declare function splitRoutePath(canonicalPath: string): {
128
+ prefix: string;
129
+ idSegments: string[];
130
+ };
131
+ /**
132
+ * Probes one adapter with a single GET (read-only).
133
+ *
134
+ * The probe reads exactly what a witnessed run would read, so it can
135
+ * report the real status, the real `Location` of a redirect-only
136
+ * path, and the real environment marker (GF-13) instead of what the
137
+ * adapter chose to report about itself. A kit adapter issues the read
138
+ * through its own `probe` hook — its seat, its cookies, one re-login
139
+ * on 401; a kit that predates the hook declares the path it reads
140
+ * (`evidencePaths`) and the probe issues the GET itself. A
141
+ * hand-written adapter is probed through its own read with a
142
+ * recording context, so the GETs it issues are observed from the
143
+ * outside.
144
+ *
145
+ * Args:
146
+ * report: the loaded adapter.
147
+ * baseUrl: the running app's base URL.
148
+ * probeId: entity id to read when there is no collection read.
149
+ *
150
+ * Returns:
151
+ * Promise<AdapterProbeReport>: what the one GET showed.
152
+ */
153
+ export declare function probeAdapter(report: AdapterFileReport, baseUrl: string, probeId?: string): Promise<AdapterProbeReport>;
154
+ //# sourceMappingURL=adapter-audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-audit.d.ts","sourceRoot":"","sources":["../src/adapter-audit.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG1E,wEAAwE;AACxE,eAAO,MAAM,sBAAsB,gCAAgC,CAAC;AAEpE,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,EAAE,EAAE,OAAO,CAAC;IACZ,qCAAqC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACvC,kEAAkE;IAClE,QAAQ,EAAE;QACR,6DAA6D;QAC7D,IAAI,EAAE,OAAO,CAAC;QACd,sDAAsD;QACtD,UAAU,EAAE,OAAO,CAAC;QACpB,0DAA0D;QAC1D,cAAc,EAAE,MAAM,EAAE,CAAC;QACzB,8CAA8C;QAC9C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,+CAA+C;QAC/C,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAC;KACvC,CAAC;CACH;AAED,wCAAwC;AACxC,MAAM,MAAM,mBAAmB,GAC3B,IAAI,GACJ,QAAQ,GACR,MAAM,GACN,sBAAsB,GACtB,QAAQ,GACR,SAAS,CAAC;AAEd,wBAAwB;AACxB,MAAM,WAAW,kBAAkB;IACjC,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAM9D;AAED;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA2C/E;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAOrF;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,kBAAkB,EAAE,GAAG,OAAO,CAKrG;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,SAAS,kBAAkB,EAAE,GACpC;IAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAAC,UAAU,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAWpE;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAU9F;AAgCD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,kBAAkB,CAAC,CA8B7B"}
@@ -0,0 +1,531 @@
1
+ /**
2
+ * Adapter audit: what a project actually has in `.gateforge/adapters/`
3
+ * and what it is missing.
4
+ *
5
+ * The engine never trusts an adapter's name — it loads the module and
6
+ * validates it against the SAME contract the witness validates
7
+ * (`validateAdapter`, reached through `@gate-forge/pack-playwright`'s
8
+ * compatibility re-export), so `adapters check` and the witnessed run
9
+ * can never disagree about what an adapter is.
10
+ *
11
+ * Everything here is read-only: loading an adapter runs its own
12
+ * top-level code, and the optional probe issues exactly ONE GET per
13
+ * adapter. No adapter is ever trusted, rewritten, or deleted here.
14
+ */
15
+ import { existsSync, readdirSync } from 'node:fs';
16
+ import { basename, join } from 'node:path';
17
+ import { pathToFileURL } from 'node:url';
18
+ import { validateAdapter } from '@gate-forge/pack-playwright';
19
+ import { pathMatchesShape } from '@gate-forge/core';
20
+ /** The header the target environment presents its marker in (GF-13). */
21
+ export const ENV_FINGERPRINT_HEADER = 'x-gateforge-env-fingerprint';
22
+ /**
23
+ * Lists the adapter module files in one adapters directory.
24
+ *
25
+ * Args:
26
+ * adaptersDir: absolute path of the adapters directory.
27
+ *
28
+ * Returns:
29
+ * string[]: absolute paths of every `.mjs` adapter, sorted by name.
30
+ */
31
+ export function listAdapterFiles(adaptersDir) {
32
+ if (!existsSync(adaptersDir))
33
+ return [];
34
+ return readdirSync(adaptersDir)
35
+ .filter((entry) => entry.endsWith('.mjs'))
36
+ .sort()
37
+ .map((entry) => join(adaptersDir, entry));
38
+ }
39
+ /**
40
+ * Loads one adapter module and validates it against the frozen contract.
41
+ *
42
+ * Args:
43
+ * file: absolute path of the `.mjs` adapter.
44
+ *
45
+ * Returns:
46
+ * AdapterFileReport: the verdict plus what the module declares. A
47
+ * module that cannot even be imported is reported, never thrown.
48
+ */
49
+ export async function auditAdapterFile(file) {
50
+ const name = basename(file, '.mjs');
51
+ let module = null;
52
+ const issues = [];
53
+ try {
54
+ // Runtime-selected module: the adapter file is the project's own
55
+ // reviewed code, and its path is only known at run time.
56
+ const imported = (await import(pathToFileURL(file).href));
57
+ if (typeof imported.default !== 'object' || imported.default === null) {
58
+ issues.push('must default-export an object {read, normalize, deletion, environmentFingerprint}');
59
+ }
60
+ else {
61
+ module = imported.default;
62
+ }
63
+ }
64
+ catch (error) {
65
+ issues.push(`could not be imported: ${error.message.split('\n')[0] ?? 'unknown error'}`);
66
+ }
67
+ if (module !== null && issues.length === 0) {
68
+ try {
69
+ validateAdapter(module, name);
70
+ }
71
+ catch (error) {
72
+ issues.push(error.message.split('\n')[0] ?? 'invalid adapter');
73
+ }
74
+ }
75
+ const declared = module ?? {};
76
+ return {
77
+ name,
78
+ file,
79
+ ok: issues.length === 0,
80
+ issues,
81
+ module,
82
+ declares: {
83
+ list: typeof declared['list'] === 'function',
84
+ naturalKey: declared['identity'] === 'natural-key',
85
+ volatileFields: Array.isArray(declared['volatileFields'])
86
+ ? declared['volatileFields'].filter((key) => typeof key === 'string')
87
+ : [],
88
+ deletion: typeof declared['deletion'] === 'string' ? declared['deletion'] : null,
89
+ environmentFingerprint: typeof declared['environmentFingerprint'] === 'string'
90
+ ? declared['environmentFingerprint']
91
+ : null,
92
+ },
93
+ };
94
+ }
95
+ /**
96
+ * Loads and validates every adapter in a directory.
97
+ *
98
+ * Args:
99
+ * adaptersDir: absolute path of the adapters directory.
100
+ *
101
+ * Returns:
102
+ * AdapterFileReport[]: one report per `.mjs` file, sorted by name.
103
+ */
104
+ export async function auditAdapters(adaptersDir) {
105
+ const files = listAdapterFiles(adaptersDir);
106
+ const reports = [];
107
+ for (const file of files) {
108
+ reports.push(await auditAdapterFile(file));
109
+ }
110
+ return reports;
111
+ }
112
+ /**
113
+ * Normalizes one compiled route path to the engine's `{...}` shape so
114
+ * `pathMatchesShape` can compare it with a concrete adapter path.
115
+ *
116
+ * Args:
117
+ * canonicalPath: the compiled route shape (`:id` style).
118
+ *
119
+ * Returns:
120
+ * string: the same shape with every positional segment as `{}`.
121
+ */
122
+ export function toShapePath(canonicalPath) {
123
+ return canonicalPath
124
+ .split('/')
125
+ .map((segment) => (segment.startsWith(':') || segment === '{}' ? '{}' : segment))
126
+ .join('/');
127
+ }
128
+ /**
129
+ * Whether a declared adapter path instantiates a compiled GET route.
130
+ *
131
+ * Args:
132
+ * adapterPath: the path an adapter declares (query stripped).
133
+ * routes: the compiled route inventory.
134
+ *
135
+ * Returns:
136
+ * boolean: true when some GET route has the same shape.
137
+ */
138
+ export function pathIsCompiledGet(adapterPath, routes) {
139
+ const bare = adapterPath.split('?')[0] ?? adapterPath;
140
+ return routes.some((route) => route.method === 'GET' && pathMatchesShape(bare, toShapePath(route.canonicalPath)));
141
+ }
142
+ /**
143
+ * The GET routes that could serve one business resource: those the
144
+ * engine LINKED to it, plus (clearly separated) those whose path NAMES
145
+ * it. Linkage is evidence; a name match is a candidate the scaffolder
146
+ * marks as a guess. Naming is matched per whole path segment, with `_`
147
+ * and `-` treated as the same separator, so a table `work_reports`
148
+ * still finds `/api/v1/work-reports` — but `tasks` never matches
149
+ * `/api/v1/tasks-archive` or `/api/v1/subtasks`.
150
+ *
151
+ * Args:
152
+ * resource: the business resource.
153
+ * routes: the compiled route inventory.
154
+ *
155
+ * Returns:
156
+ * {linked: HttpRouteCandidate[], candidates: HttpRouteCandidate[]}.
157
+ */
158
+ export function routesForResource(resource, routes) {
159
+ const gets = routes.filter((route) => route.method === 'GET');
160
+ const linked = gets.filter((route) => route.linkedResourceName === resource.name);
161
+ const name = nameSegment(resource.name);
162
+ const candidates = gets.filter((route) => {
163
+ if (route.linkedResourceName === resource.name)
164
+ return false;
165
+ return route.canonicalPath
166
+ .split('/')
167
+ .some((segment) => nameSegment(segment) === name);
168
+ });
169
+ return { linked, candidates };
170
+ }
171
+ /**
172
+ * Normalizes one name or path segment for whole-segment name matching.
173
+ *
174
+ * Args:
175
+ * value: a resource name or one path segment.
176
+ *
177
+ * Returns:
178
+ * string: lowercase, with every run of `_`/`-` collapsed to `-`.
179
+ */
180
+ function nameSegment(value) {
181
+ return value.toLowerCase().replace(/[-_]+/g, '-');
182
+ }
183
+ /**
184
+ * Splits one compiled path into its literal prefix and its trailing
185
+ * positional segments (`:id` / `{}`).
186
+ *
187
+ * Args:
188
+ * canonicalPath: the compiled route shape.
189
+ *
190
+ * Returns:
191
+ * {prefix: string, idSegments: string[]}: the collection path and the
192
+ * positional tail (empty for a collection route).
193
+ */
194
+ export function splitRoutePath(canonicalPath) {
195
+ const segments = canonicalPath.split('/').filter((segment) => segment.length > 0);
196
+ const idSegments = [];
197
+ while (segments.length > 0) {
198
+ const last = segments[segments.length - 1];
199
+ if (!last.startsWith(':') && last !== '{}')
200
+ break;
201
+ idSegments.unshift(last);
202
+ segments.pop();
203
+ }
204
+ return { prefix: `/${segments.join('/')}`, idSegments };
205
+ }
206
+ /**
207
+ * Reads an adapter's kit introspection, when it has one.
208
+ *
209
+ * Args:
210
+ * module: the loaded adapter module.
211
+ *
212
+ * Returns:
213
+ * KitEvidencePaths | null: the declared paths, or null for a
214
+ * hand-written adapter that declares none.
215
+ */
216
+ function kitPathsOf(module) {
217
+ const declared = module['evidencePaths'];
218
+ if (typeof declared !== 'object' || declared === null)
219
+ return null;
220
+ const paths = declared;
221
+ if (typeof paths['read'] !== 'function' || typeof paths['list'] !== 'function')
222
+ return null;
223
+ return {
224
+ read: paths['read'].bind(declared),
225
+ list: paths['list'].bind(declared),
226
+ };
227
+ }
228
+ /**
229
+ * Probes one adapter with a single GET (read-only).
230
+ *
231
+ * The probe reads exactly what a witnessed run would read, so it can
232
+ * report the real status, the real `Location` of a redirect-only
233
+ * path, and the real environment marker (GF-13) instead of what the
234
+ * adapter chose to report about itself. A kit adapter issues the read
235
+ * through its own `probe` hook — its seat, its cookies, one re-login
236
+ * on 401; a kit that predates the hook declares the path it reads
237
+ * (`evidencePaths`) and the probe issues the GET itself. A
238
+ * hand-written adapter is probed through its own read with a
239
+ * recording context, so the GETs it issues are observed from the
240
+ * outside.
241
+ *
242
+ * Args:
243
+ * report: the loaded adapter.
244
+ * baseUrl: the running app's base URL.
245
+ * probeId: entity id to read when there is no collection read.
246
+ *
247
+ * Returns:
248
+ * Promise<AdapterProbeReport>: what the one GET showed.
249
+ */
250
+ export async function probeAdapter(report, baseUrl, probeId) {
251
+ const module = report.module;
252
+ if (module === null || typeof module['read'] !== 'function') {
253
+ return {
254
+ name: report.name,
255
+ outcome: 'skipped',
256
+ path: '',
257
+ detail: 'adapter does not load; nothing to probe',
258
+ };
259
+ }
260
+ const paths = kitPathsOf(module);
261
+ if (paths !== null) {
262
+ const target = paths.list() ?? paths.read(probeId ?? '0');
263
+ if (target === null) {
264
+ return {
265
+ name: report.name,
266
+ outcome: 'skipped',
267
+ path: '',
268
+ detail: 'adapter declares no probeable path (composed collection reads are probed by the run)',
269
+ };
270
+ }
271
+ // A kit adapter reads through its own seat, so the probe must
272
+ // too: an unauthenticated GET would report a 401 the adapter
273
+ // never sees and blame credentials that are perfectly correct.
274
+ const probe = module['probe'];
275
+ return typeof probe === 'function'
276
+ ? probeThroughKit(report, baseUrl, probe, probeId)
277
+ : probePath(report, baseUrl, target);
278
+ }
279
+ return probeThroughAdapter(report, baseUrl, probeId);
280
+ }
281
+ /**
282
+ * Probes a kit adapter through its own read, and reports what the
283
+ * seat had to say.
284
+ *
285
+ * Args:
286
+ * report: the loaded adapter (for the declared fingerprint).
287
+ * baseUrl: the running app's base URL.
288
+ * probe: the adapter's read-only probe hook.
289
+ * probeId: the entity id to read when there is no collection read.
290
+ *
291
+ * Returns:
292
+ * Promise<AdapterProbeReport>: classified outcome, or the seat's own
293
+ * plain failure (never a credential).
294
+ */
295
+ async function probeThroughKit(report, baseUrl, probe, probeId) {
296
+ let observed;
297
+ try {
298
+ observed = await probe({ baseUrl }, probeId);
299
+ }
300
+ catch (error) {
301
+ return kitReadFailure(report, error);
302
+ }
303
+ return classifyRead(report, observed.path, observed.status, observed.headers.get('location'), observed.headers.get(ENV_FINGERPRINT_HEADER));
304
+ }
305
+ /**
306
+ * Classifies what one read showed. Shared by the probe's own GET and
307
+ * the kit's read, so both report the same status the same way.
308
+ *
309
+ * Args:
310
+ * report: the loaded adapter (for the declared fingerprint).
311
+ * path: the path the read hit.
312
+ * status: the HTTP status the app answered.
313
+ * location: the redirect target, when the app answered with one.
314
+ * marker: the environment marker the app presented (GF-13).
315
+ *
316
+ * Returns:
317
+ * AdapterProbeReport: the classified outcome.
318
+ */
319
+ function classifyRead(report, path, status, location, marker) {
320
+ if (status >= 300 && status < 400) {
321
+ return {
322
+ name: report.name,
323
+ outcome: 'failed',
324
+ path,
325
+ detail: `GET ${path} answered ${String(status)}` +
326
+ `${location === null ? '' : ` -> ${location}`}; a read that only works through a ` +
327
+ 'redirect is not a stable evidence path',
328
+ };
329
+ }
330
+ if (status === 401 || status === 403) {
331
+ return {
332
+ name: report.name,
333
+ outcome: 'auth',
334
+ path,
335
+ detail: `GET ${path} answered ${String(status)}; check the adapter's login seat and ` +
336
+ 'the witness environment credentials it names',
337
+ };
338
+ }
339
+ if (status === 404) {
340
+ return {
341
+ name: report.name,
342
+ outcome: 'absent',
343
+ path,
344
+ detail: `GET ${path} answered 404; the resource is not served at this path`,
345
+ };
346
+ }
347
+ if (status < 200 || status >= 300) {
348
+ return {
349
+ name: report.name,
350
+ outcome: 'failed',
351
+ path,
352
+ detail: `GET ${path} answered ${String(status)}`,
353
+ };
354
+ }
355
+ const declared = report.declares.environmentFingerprint;
356
+ if (declared !== null && marker !== declared) {
357
+ return {
358
+ name: report.name,
359
+ outcome: 'fingerprint-mismatch',
360
+ path,
361
+ detail: `GET ${path} presents ${ENV_FINGERPRINT_HEADER}=${JSON.stringify(marker)} but the adapter ` +
362
+ `declares ${JSON.stringify(declared)} (GF-13: the adapter must read the environment under test)`,
363
+ };
364
+ }
365
+ return {
366
+ name: report.name,
367
+ outcome: 'ok',
368
+ path,
369
+ detail: marker === null
370
+ ? 'GET answered 2xx (no environment marker presented)'
371
+ : `GET answered 2xx and presents the declared fingerprint '${declared}'`,
372
+ };
373
+ }
374
+ /**
375
+ * Reports why the adapter's own read never got an answer: an absent
376
+ * credential is named by the env vars it needs, a rejected login by
377
+ * the login POST status, and never by a credential value.
378
+ *
379
+ * Args:
380
+ * report: the loaded adapter.
381
+ * error: what the kit's read threw.
382
+ *
383
+ * Returns:
384
+ * AdapterProbeReport: the failure, as the probe reports it.
385
+ */
386
+ function kitReadFailure(report, error) {
387
+ const thrown = error;
388
+ const message = thrown.message?.split('\n')[0] ?? 'the adapter read failed';
389
+ if (thrown.name !== 'KitAuthError') {
390
+ return { name: report.name, outcome: 'failed', path: '', detail: message };
391
+ }
392
+ const envVars = thrown.failure?.envVars ?? null;
393
+ return {
394
+ name: report.name,
395
+ outcome: 'auth',
396
+ path: '',
397
+ detail: envVars === null || envVars.length === 0
398
+ ? message
399
+ : `the seat '${thrown.failure?.seat ?? ''}' needs ${envVars.join(', ')} in the ` +
400
+ 'environment — not probed',
401
+ };
402
+ }
403
+ /**
404
+ * Issues the probe's single GET against a known path.
405
+ *
406
+ * Args:
407
+ * report: the loaded adapter (for the declared fingerprint).
408
+ * baseUrl: the running app's base URL.
409
+ * path: the path the adapter reads.
410
+ *
411
+ * Returns:
412
+ * Promise<AdapterProbeReport>: classified status.
413
+ */
414
+ async function probePath(report, baseUrl, path) {
415
+ const response = await fetch(`${baseUrl.replace(/\/$/, '')}${path}`, { redirect: 'manual' });
416
+ return classifyRead(report, path, response.status, response.headers.get('location'), response.headers.get(ENV_FINGERPRINT_HEADER));
417
+ }
418
+ /**
419
+ * Probes a hand-written adapter through its own read, observing the
420
+ * GETs it issues from the outside.
421
+ *
422
+ * Args:
423
+ * report: the loaded adapter.
424
+ * baseUrl: the running app's base URL.
425
+ * probeId: the entity id to read.
426
+ *
427
+ * Returns:
428
+ * Promise<AdapterProbeReport>: classified outcome.
429
+ */
430
+ async function probeThroughAdapter(report, baseUrl, probeId) {
431
+ if (probeId === undefined) {
432
+ return {
433
+ name: report.name,
434
+ outcome: 'skipped',
435
+ path: '',
436
+ detail: 'hand-written adapter: pass --probe-id to read one entity through it',
437
+ };
438
+ }
439
+ const seen = [];
440
+ const ctx = {
441
+ baseUrl,
442
+ resourceId: report.name,
443
+ get: async (path) => {
444
+ const response = await fetch(`${baseUrl.replace(/\/$/, '')}${path}`, { redirect: 'manual' });
445
+ seen.push({
446
+ path,
447
+ status: response.status,
448
+ marker: response.headers.get(ENV_FINGERPRINT_HEADER),
449
+ });
450
+ return {
451
+ status: response.status,
452
+ json: () => response.json(),
453
+ text: () => response.text(),
454
+ headers: response.headers,
455
+ };
456
+ },
457
+ };
458
+ const read = report.module?.['read'];
459
+ if (read === undefined) {
460
+ return {
461
+ name: report.name,
462
+ outcome: 'skipped',
463
+ path: '',
464
+ detail: 'adapter has no read function',
465
+ };
466
+ }
467
+ let body;
468
+ try {
469
+ body = await read(ctx, probeId);
470
+ }
471
+ catch (error) {
472
+ return {
473
+ name: report.name,
474
+ outcome: 'failed',
475
+ path: seen[0]?.path ?? '',
476
+ detail: error.message.split('\n')[0] ?? 'read failed',
477
+ };
478
+ }
479
+ const observed = seen[0];
480
+ if (observed === undefined) {
481
+ return {
482
+ name: report.name,
483
+ outcome: 'failed',
484
+ path: '',
485
+ detail: 'the adapter read issued no GET through the witness transport',
486
+ };
487
+ }
488
+ if (observed.status === 401 || observed.status === 403) {
489
+ return {
490
+ name: report.name,
491
+ outcome: 'auth',
492
+ path: observed.path,
493
+ detail: `GET ${observed.path} answered ${String(observed.status)}`,
494
+ };
495
+ }
496
+ if (observed.status >= 300 && observed.status < 400) {
497
+ return {
498
+ name: report.name,
499
+ outcome: 'failed',
500
+ path: observed.path,
501
+ detail: `GET ${observed.path} answered ${String(observed.status)} (redirect-only path)`,
502
+ };
503
+ }
504
+ if (body === null || body === undefined) {
505
+ return {
506
+ name: report.name,
507
+ outcome: 'absent',
508
+ path: observed.path,
509
+ detail: observed.status === 404
510
+ ? `GET ${observed.path} answered 404`
511
+ : `GET ${observed.path} answered ${String(observed.status)} and the adapter reported the entity absent`,
512
+ };
513
+ }
514
+ const declared = report.declares.environmentFingerprint;
515
+ if (declared !== null && observed.marker !== declared) {
516
+ return {
517
+ name: report.name,
518
+ outcome: 'fingerprint-mismatch',
519
+ path: observed.path,
520
+ detail: `GET ${observed.path} presents ${ENV_FINGERPRINT_HEADER}=${JSON.stringify(observed.marker)} ` +
521
+ `but the adapter declares ${JSON.stringify(declared)} (GF-13)`,
522
+ };
523
+ }
524
+ return {
525
+ name: report.name,
526
+ outcome: 'ok',
527
+ path: observed.path,
528
+ detail: `GET ${observed.path} answered ${String(observed.status)} and the entity was read`,
529
+ };
530
+ }
531
+ //# sourceMappingURL=adapter-audit.js.map