@forkstage/verify 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # @forkstage/verify
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The probes a Forkstage verification runs against a fork, as plain functions with no driver
4
+ inside, so the CLI (`forkstage verify`, the MCP tool `verify_change`) and the control plane
5
+ (the GitHub App on pull requests) run the same plan and reach the same verdict.
6
+
7
+ Each probe first decides whether it applies to this stack, then runs, then reports one
8
+ outcome: `passed`, `failed`, `warn`, or `skipped` with the reason.
9
+
10
+ - `apiSmoke(baseUrl)`: finds an OpenAPI, Swagger or GraphQL description and calls every
11
+ parameterless read route once; fails on 5xx, timeouts and refused connections.
12
+ - `runCheck(check, context)`: a `checks:` entry from `forkstage.yaml`, a command that must
13
+ exit 0 or one request that must answer a status.
14
+ - `logScan(text)`: counts error-level lines and crash signatures in service logs; warns.
15
+ - `parseMailList(json, since)`, `mailOutcome(messages, hosts)`, `emailEvents(messages)`:
16
+ captured mail from the fork's mail service, as proof events.
17
+
18
+ The verdict rule itself lives in `@forkstage/proof`.
@@ -0,0 +1,89 @@
1
+ import type { Event } from "@forkstage/proof";
2
+ import type { Check } from "@forkstage/recipe";
3
+ export interface Outcome {
4
+ status: "passed" | "failed" | "warn" | "skipped";
5
+ /** One line: what was checked and the numbers. */
6
+ detail: string;
7
+ tail?: string;
8
+ ms: number;
9
+ }
10
+ export interface Exec {
11
+ exitCode: number;
12
+ output: string;
13
+ ms: number;
14
+ }
15
+ /** The last lines of a text, enough to read, never the whole thing. */
16
+ export declare function tailText(text: string, lines?: number, chars?: number): string;
17
+ export declare const API_DOCS: string[];
18
+ export type DiscoveredApi = {
19
+ kind: "openapi";
20
+ path: string;
21
+ routes: string[];
22
+ } | {
23
+ kind: "graphql";
24
+ path: string;
25
+ fields: number;
26
+ };
27
+ /** The app's own description of its API, when it publishes one. */
28
+ export declare function discoverApi(base: string): Promise<DiscoveredApi | null>;
29
+ /**
30
+ * API smoke: if the app publishes a description of itself, call every parameterless read
31
+ * route once and count the ones that crash (5xx, timeout, connection error). Not a test of
32
+ * correctness; a test that nothing explodes when touched.
33
+ */
34
+ export declare function apiSmoke(base: string | undefined, log?: (line: string) => void, fallback?: () => Promise<{
35
+ kind: "routes";
36
+ source: string;
37
+ routes: string[];
38
+ } | {
39
+ kind: "grpc";
40
+ services: string[];
41
+ } | null>): Promise<Outcome>;
42
+ export interface CheckContext {
43
+ /** The app's address, for `http` checks. */
44
+ base?: string | undefined;
45
+ /** The service `run` checks use when the check names none. */
46
+ appService?: string | undefined;
47
+ /** Run a command in a service and return its exit code and output. */
48
+ exec: (service: string, command: string) => Promise<Exec>;
49
+ }
50
+ /** One `checks:` entry: a command that must exit 0, or one request that must answer a status. */
51
+ export declare function runCheck(check: Check, ctx: CheckContext): Promise<Outcome>;
52
+ /** The outcome recorded when a recipe declares no checks: a skip, with the reason that matters. */
53
+ export declare const NO_CHECKS: Outcome;
54
+ /**
55
+ * Service logs: count error-level lines and crash signatures. Never fails a verdict on its
56
+ * own; it warns, and the lines are the evidence.
57
+ */
58
+ export declare function logScan(text: string, ms?: number): Outcome;
59
+ export interface MailMessage {
60
+ id: string;
61
+ at: string;
62
+ from: string;
63
+ to: string[];
64
+ cc: string[];
65
+ subject: string;
66
+ /** The first line or so, from the listing. */
67
+ snippet: string;
68
+ /** The text part, when the detail was fetched. */
69
+ text?: string | undefined;
70
+ html?: string | undefined;
71
+ }
72
+ /**
73
+ * The mail service's listing (Mailpit's `GET /api/v1/messages`) as messages captured at or
74
+ * after `since`, oldest first. Throws when the text is not that listing.
75
+ */
76
+ export declare function parseMailList(json: string, since: string): MailMessage[];
77
+ /** One message's detail (Mailpit's `GET /api/v1/message/{id}`) folded into the summary. */
78
+ export declare function withMailDetail(m: MailMessage, json: string): MailMessage;
79
+ export type EmailEvent = Extract<Event, {
80
+ kind: "email";
81
+ }>;
82
+ /** Captured messages as proof events, with a short preview of the text. */
83
+ export declare function emailEvents(messages: MailMessage[]): EmailEvent[];
84
+ /** The step's outcome for a set of captured messages. */
85
+ export declare function mailOutcome(messages: MailMessage[], hosts: string[], ms: number): Outcome;
86
+ export declare const NO_CAPTURE: Outcome;
87
+ export { detectScript, MIGRATION_TOOLS, type MigrationsContext, type MigrationsOutcome, type MigrationTool, migrationsProbe, parseDetected, } from "./migrations.js";
88
+ export { grpcScript, parseGrpc, parseRoutes, type RoutesByCommand, routesFallback, routesScript, } from "./routes.js";
89
+ export { type ChangeFiles, changeScope, type Scope, serviceFor } from "./scope.js";
package/dist/index.js ADDED
@@ -0,0 +1,261 @@
1
+ /** The last lines of a text, enough to read, never the whole thing. */
2
+ export function tailText(text, lines = 12, chars = 1200) {
3
+ const t = text.trim().split("\n").slice(-lines).join("\n");
4
+ return t.length > chars ? t.slice(-chars) : t;
5
+ }
6
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
7
+ // ------------------------------------------------------------------ API smoke
8
+ export const API_DOCS = [
9
+ "/openapi.json",
10
+ "/swagger.json",
11
+ "/v3/api-docs",
12
+ "/api-docs",
13
+ "/api/openapi.json",
14
+ ];
15
+ const MAX_ROUTES = 200;
16
+ async function getJson(url) {
17
+ try {
18
+ const res = await fetch(url, { signal: AbortSignal.timeout(10_000) });
19
+ if (!res.ok)
20
+ return null;
21
+ return await res.json();
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ }
27
+ /** The app's own description of its API, when it publishes one. */
28
+ export async function discoverApi(base) {
29
+ for (const path of API_DOCS) {
30
+ const doc = await getJson(`${base}${path}`);
31
+ if (!doc || typeof doc !== "object" || !("paths" in doc))
32
+ continue;
33
+ const paths = doc.paths;
34
+ const routes = Object.entries(paths)
35
+ .filter(([p, ops]) => !p.includes("{") && ops && typeof ops === "object" && "get" in ops)
36
+ .map(([p]) => p)
37
+ .slice(0, MAX_ROUTES);
38
+ return { kind: "openapi", path, routes };
39
+ }
40
+ const gql = await fetch(`${base}/graphql`, {
41
+ method: "POST",
42
+ headers: { "content-type": "application/json" },
43
+ body: JSON.stringify({ query: "{ __schema { queryType { fields { name } } } }" }),
44
+ signal: AbortSignal.timeout(10_000),
45
+ }).catch(() => null);
46
+ if (gql?.ok) {
47
+ const body = (await gql.json().catch(() => null));
48
+ const fields = body?.data?.__schema?.queryType?.fields;
49
+ if (Array.isArray(fields))
50
+ return { kind: "graphql", path: "/graphql", fields: fields.length };
51
+ }
52
+ return null;
53
+ }
54
+ /**
55
+ * API smoke: if the app publishes a description of itself, call every parameterless read
56
+ * route once and count the ones that crash (5xx, timeout, connection error). Not a test of
57
+ * correctness; a test that nothing explodes when touched.
58
+ */
59
+ export async function apiSmoke(base, log = () => { }, fallback) {
60
+ const started = Date.now();
61
+ if (!base)
62
+ return { status: "skipped", detail: "the app has no HTTP address", ms: 0 };
63
+ let found = await discoverApi(base);
64
+ if (!found && fallback) {
65
+ const fb = await fallback().catch(() => null);
66
+ if (fb?.kind === "grpc")
67
+ return {
68
+ status: "passed",
69
+ detail: `gRPC reflection lists ${plural(fb.services.length, "service")}: ${fb.services.slice(0, 6).join(", ")}${fb.services.length > 6 ? ", …" : ""}`,
70
+ ms: Date.now() - started,
71
+ };
72
+ if (fb?.kind === "routes")
73
+ found = { kind: "openapi", path: `the ${fb.source} route table`, routes: fb.routes };
74
+ }
75
+ if (!found)
76
+ return {
77
+ status: "skipped",
78
+ detail: `no API description found (tried ${API_DOCS.join(", ")}, GraphQL at /graphql, and the Laravel, Rails and Django route tables)`,
79
+ ms: Date.now() - started,
80
+ };
81
+ if (found.kind === "graphql")
82
+ return {
83
+ status: "passed",
84
+ detail: `GraphQL schema at ${found.path}: ${plural(found.fields, "query field")}, introspection answered`,
85
+ ms: Date.now() - started,
86
+ };
87
+ if (!found.routes.length)
88
+ return {
89
+ status: "skipped",
90
+ detail: `${found.path} lists no parameterless GET route to call`,
91
+ ms: Date.now() - started,
92
+ };
93
+ log(`API smoke: ${plural(found.routes.length, "read route")} from ${found.path}`);
94
+ const failures = [];
95
+ const queue = [...found.routes];
96
+ const worker = async () => {
97
+ for (let path = queue.shift(); path !== undefined; path = queue.shift()) {
98
+ try {
99
+ const res = await fetch(`${base}${path}`, {
100
+ redirect: "manual",
101
+ signal: AbortSignal.timeout(15_000),
102
+ headers: { accept: "application/json, text/html;q=0.5, */*;q=0.1" },
103
+ });
104
+ if (res.status >= 500)
105
+ failures.push(`GET ${path} → ${res.status}`);
106
+ }
107
+ catch (error) {
108
+ failures.push(`GET ${path} → ${error.name === "TimeoutError" ? "timeout" : "no answer"}`);
109
+ }
110
+ }
111
+ };
112
+ await Promise.all(Array.from({ length: Math.min(6, found.routes.length) }, worker));
113
+ return {
114
+ status: failures.length ? "failed" : "passed",
115
+ detail: `${plural(found.routes.length, "read route")} from ${found.path}, ${failures.length ? `${failures.length} crashed` : "none crashed"}`,
116
+ ...(failures.length ? { tail: tailText(failures.join("\n"), 12) } : {}),
117
+ ms: Date.now() - started,
118
+ };
119
+ }
120
+ /** One `checks:` entry: a command that must exit 0, or one request that must answer a status. */
121
+ export async function runCheck(check, ctx) {
122
+ const started = Date.now();
123
+ if (check.run) {
124
+ const service = check.in ?? ctx.appService;
125
+ if (!service)
126
+ return { status: "failed", detail: "no service to run in", ms: 0 };
127
+ const r = await ctx.exec(service, check.run);
128
+ return {
129
+ status: r.exitCode === 0 ? "passed" : "failed",
130
+ detail: `${check.run} exited ${r.exitCode} in ${service}`,
131
+ ...(r.output.trim() ? { tail: tailText(r.output) } : {}),
132
+ ms: Date.now() - started,
133
+ };
134
+ }
135
+ if (!check.http)
136
+ return { status: "failed", detail: "the check has neither run nor http", ms: 0 };
137
+ if (!ctx.base)
138
+ return { status: "failed", detail: "the app has no HTTP address", ms: 0 };
139
+ const [method, path] = check.http.split(" ");
140
+ const expect = check.expect ?? 200;
141
+ let status = 0;
142
+ let body = "";
143
+ try {
144
+ const res = await fetch(`${ctx.base}${path}`, {
145
+ method,
146
+ redirect: "manual",
147
+ signal: AbortSignal.timeout(30_000),
148
+ ...(check.body ? { headers: { "content-type": "application/json" }, body: check.body } : {}),
149
+ });
150
+ status = res.status;
151
+ body = await res.text().catch(() => "");
152
+ }
153
+ catch (error) {
154
+ body = error.message;
155
+ }
156
+ return {
157
+ status: status === expect ? "passed" : "failed",
158
+ detail: `${check.http} → ${status || "no answer"}, expected ${expect}`,
159
+ ...(status !== expect && body ? { tail: tailText(body, 6, 600) } : {}),
160
+ ms: Date.now() - started,
161
+ };
162
+ }
163
+ /** The outcome recorded when a recipe declares no checks: a skip, with the reason that matters. */
164
+ export const NO_CHECKS = {
165
+ status: "skipped",
166
+ detail: "no checks: in forkstage.yaml; a change that adds behaviour should bring one",
167
+ ms: 0,
168
+ };
169
+ // ------------------------------------------------------------------ service logs
170
+ const CRASH = /Traceback \(most recent call last\)|panic: |FATAL|Unhandled(?:Promise)?Rejection|\bsegfault\b|Exception in thread|java\.lang\.\w+(?:Exception|Error)|\bECONNREFUSED\b|^\s*Error: .+\n\s+at /m;
171
+ const ERROR_LINE = /\b(ERROR|CRITICAL|FATAL|panic)\b|Traceback|Exception/;
172
+ /**
173
+ * Service logs: count error-level lines and crash signatures. Never fails a verdict on its
174
+ * own; it warns, and the lines are the evidence.
175
+ */
176
+ export function logScan(text, ms = 0) {
177
+ const lines = text.split("\n").filter((l) => l.length);
178
+ const crashes = lines.filter((l) => CRASH.test(l));
179
+ const errors = lines.filter((l) => ERROR_LINE.test(l));
180
+ return {
181
+ status: errors.length ? "warn" : "passed",
182
+ detail: errors.length
183
+ ? `${plural(errors.length, "error-level line")} in ${lines.length}${crashes.length ? `, ${crashes.length} look like crashes` : ""}`
184
+ : `${lines.length} lines, no error-level lines`,
185
+ ...(errors.length ? { tail: tailText(errors.slice(-12).join("\n"), 12, 1600) } : {}),
186
+ ms,
187
+ };
188
+ }
189
+ const addr = (a) => (a ? a.Address : "");
190
+ const addrs = (list) => (list ?? []).map(addr);
191
+ /**
192
+ * The mail service's listing (Mailpit's `GET /api/v1/messages`) as messages captured at or
193
+ * after `since`, oldest first. Throws when the text is not that listing.
194
+ */
195
+ export function parseMailList(json, since) {
196
+ let parsed;
197
+ try {
198
+ parsed = JSON.parse(json);
199
+ }
200
+ catch {
201
+ throw new Error("the mail service answered with something that is not JSON");
202
+ }
203
+ if (!parsed || !Array.isArray(parsed.messages))
204
+ throw new Error("the mail service answered with something that is not a message list");
205
+ const floor = Date.parse(since) - 1000;
206
+ return parsed.messages
207
+ .filter((m) => Date.parse(m.Created) >= floor)
208
+ .sort((a, b) => Date.parse(a.Created) - Date.parse(b.Created))
209
+ .map((m) => ({
210
+ id: m.ID,
211
+ at: m.Created,
212
+ from: addr(m.From),
213
+ to: addrs(m.To),
214
+ cc: addrs(m.Cc),
215
+ subject: m.Subject ?? "",
216
+ snippet: m.Snippet ?? "",
217
+ }));
218
+ }
219
+ /** One message's detail (Mailpit's `GET /api/v1/message/{id}`) folded into the summary. */
220
+ export function withMailDetail(m, json) {
221
+ try {
222
+ const full = JSON.parse(json);
223
+ return { ...m, text: full.Text, html: full.HTML };
224
+ }
225
+ catch {
226
+ return m;
227
+ }
228
+ }
229
+ /** Captured messages as proof events, with a short preview of the text. */
230
+ export function emailEvents(messages) {
231
+ return messages.map((m) => {
232
+ const body = (m.text ?? m.snippet ?? "").trim();
233
+ return {
234
+ kind: "email",
235
+ at: m.at,
236
+ from: m.from,
237
+ to: m.to,
238
+ subject: m.subject,
239
+ ...(body ? { preview: tailText(body, 12, 1200) } : {}),
240
+ };
241
+ });
242
+ }
243
+ /** The step's outcome for a set of captured messages. */
244
+ export function mailOutcome(messages, hosts, ms) {
245
+ return {
246
+ status: "passed",
247
+ detail: messages.length
248
+ ? `${plural(messages.length, "message")} captured via ${hosts.join(", ")}, none delivered`
249
+ : `nothing sent via ${hosts.join(", ")}`,
250
+ ms,
251
+ };
252
+ }
253
+ export const NO_CAPTURE = {
254
+ status: "skipped",
255
+ detail: "no outside host in capture mode; mail the stack sends is not observed",
256
+ ms: 0,
257
+ };
258
+ export { detectScript, MIGRATION_TOOLS, migrationsProbe, parseDetected, } from "./migrations.js";
259
+ export { grpcScript, parseGrpc, parseRoutes, routesFallback, routesScript, } from "./routes.js";
260
+ export { changeScope, serviceFor } from "./scope.js";
261
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqBA,uEAAuE;AACvE,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAK,GAAG,EAAE,EAAE,KAAK,GAAG,IAAI;IAC7D,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3D,OAAO,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,GAAW,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAE5F,+EAA+E;AAE/E,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,eAAe;IACf,eAAe;IACf,cAAc;IACd,WAAW;IACX,mBAAmB;CACpB,CAAC;AACF,MAAM,UAAU,GAAG,GAAG,CAAC;AAMvB,KAAK,UAAU,OAAO,CAAC,GAAW;IAChC,IAAI,CAA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EACd,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAoB,WAAW,EAAc,UAAU,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { Exec, Outcome } from "./index.js";
2
+ export interface MigrationTool {
3
+ name: string;
4
+ /** A shell test that succeeds when the tool is in use, run in the app's working directory. */
5
+ detect: string;
6
+ /** The command that applies pending migrations; empty when they apply at application start. */
7
+ command: string;
8
+ }
9
+ export declare const MIGRATION_TOOLS: MigrationTool[];
10
+ /** One shell command that prints the name of every tool detected, one per line. */
11
+ export declare function detectScript(): string;
12
+ export declare function parseDetected(output: string): MigrationTool[];
13
+ export interface MigrationsContext {
14
+ /** The recipe's own `migrate:` command, when set; it wins. */
15
+ recipeMigrate?: string | undefined;
16
+ appService?: string | undefined;
17
+ exec: (service: string, command: string) => Promise<Exec>;
18
+ /** Whether the app answers its ready check; run after migrations when given. */
19
+ healthy?: (() => Promise<boolean>) | undefined;
20
+ }
21
+ export interface MigrationsOutcome extends Outcome {
22
+ tool?: string;
23
+ command?: string;
24
+ }
25
+ /** The migrations step. */
26
+ export declare function migrationsProbe(ctx: MigrationsContext): Promise<MigrationsOutcome>;
@@ -0,0 +1,119 @@
1
+ export const MIGRATION_TOOLS = [
2
+ { name: "alembic", detect: "test -f alembic.ini", command: "alembic upgrade head" },
3
+ {
4
+ name: "django",
5
+ detect: "test -f manage.py",
6
+ command: "python manage.py migrate --noinput 2>&1 || python3 manage.py migrate --noinput",
7
+ },
8
+ { name: "prisma", detect: "test -f prisma/schema.prisma", command: "npx prisma migrate deploy" },
9
+ {
10
+ name: "rails",
11
+ detect: "test -d db/migrate",
12
+ command: "bin/rails db:migrate 2>&1 || bundle exec rails db:migrate",
13
+ },
14
+ { name: "knex", detect: "ls knexfile.* >/dev/null 2>&1", command: "npx knex migrate:latest" },
15
+ { name: "sequelize", detect: "test -f .sequelizerc", command: "npx sequelize-cli db:migrate" },
16
+ {
17
+ name: "drizzle",
18
+ detect: "ls drizzle.config.* >/dev/null 2>&1",
19
+ command: "npx drizzle-kit migrate",
20
+ },
21
+ {
22
+ name: "typeorm",
23
+ detect: "ls ormconfig.* >/dev/null 2>&1",
24
+ command: "npx typeorm migration:run",
25
+ },
26
+ {
27
+ name: "golang-migrate",
28
+ detect: "ls migrations/*.sql >/dev/null 2>&1 && command -v migrate >/dev/null",
29
+ command: 'migrate -path migrations -database "$DATABASE_URL" up',
30
+ },
31
+ {
32
+ name: "goose",
33
+ detect: "command -v goose >/dev/null && test -d migrations",
34
+ command: "goose up",
35
+ },
36
+ {
37
+ name: "dbmate",
38
+ detect: "command -v dbmate >/dev/null && test -d db/migrations",
39
+ command: "dbmate up",
40
+ },
41
+ {
42
+ name: "ef-core",
43
+ detect: "ls *.csproj >/dev/null 2>&1 && test -d Migrations && command -v dotnet >/dev/null",
44
+ command: "dotnet ef database update",
45
+ },
46
+ { name: "flyway", detect: "test -d src/main/resources/db/migration", command: "" },
47
+ {
48
+ name: "liquibase",
49
+ detect: "test -d src/main/resources/db/changelog || test -f liquibase.properties",
50
+ command: "",
51
+ },
52
+ ];
53
+ /** One shell command that prints the name of every tool detected, one per line. */
54
+ export function detectScript() {
55
+ return `${MIGRATION_TOOLS.map((t) => `(${t.detect}) 2>/dev/null && echo ${t.name}`).join("; ")}; true`;
56
+ }
57
+ export function parseDetected(output) {
58
+ const names = new Set(output
59
+ .split("\n")
60
+ .map((l) => l.trim())
61
+ .filter(Boolean));
62
+ return MIGRATION_TOOLS.filter((t) => names.has(t.name));
63
+ }
64
+ const LOOKED_FOR = "alembic.ini, manage.py, prisma/schema.prisma, db/migrate, knexfile, drizzle.config, .sequelizerc, ormconfig, migrations/*.sql with migrate, goose or dbmate, EF Core Migrations, flyway and liquibase folders";
65
+ /** The migrations step. */
66
+ export async function migrationsProbe(ctx) {
67
+ const started = Date.now();
68
+ if (!ctx.appService)
69
+ return { status: "skipped", detail: "no app service to run migrations in", ms: 0 };
70
+ let tool = null;
71
+ if (ctx.recipeMigrate)
72
+ tool = { name: "recipe", detect: "", command: ctx.recipeMigrate };
73
+ else {
74
+ const found = await ctx.exec(ctx.appService, detectScript());
75
+ const tools = parseDetected(found.output);
76
+ tool = tools[0] ?? null;
77
+ }
78
+ if (!tool)
79
+ return {
80
+ status: "skipped",
81
+ detail: `no migration tool found (looked for ${LOOKED_FOR})`,
82
+ ms: Date.now() - started,
83
+ };
84
+ if (!tool.command) {
85
+ const ok = ctx.healthy ? await ctx.healthy() : true;
86
+ return {
87
+ status: ok ? "passed" : "warn",
88
+ tool: tool.name,
89
+ detail: ok
90
+ ? `${tool.name} migrations apply at application start; the app answered after boot`
91
+ : `${tool.name} migrations apply at application start, but the app is not answering`,
92
+ ms: Date.now() - started,
93
+ };
94
+ }
95
+ const r = await ctx.exec(ctx.appService, tool.command);
96
+ if (r.exitCode !== 0)
97
+ return {
98
+ status: "failed",
99
+ tool: tool.name,
100
+ command: tool.command,
101
+ detail: `${tool.name}: ${tool.command} exited ${r.exitCode}`,
102
+ tail: r.output.trim().split("\n").slice(-12).join("\n").slice(-1600),
103
+ ms: Date.now() - started,
104
+ };
105
+ const healthy = ctx.healthy ? await ctx.healthy() : true;
106
+ return {
107
+ status: healthy ? "passed" : "failed",
108
+ tool: tool.name,
109
+ command: tool.command,
110
+ detail: healthy
111
+ ? `${tool.name}: ${tool.command} exited 0 in ${(r.ms / 1000).toFixed(1)} s; the app answers`
112
+ : `${tool.name}: ${tool.command} exited 0, but the app stopped answering`,
113
+ ...(r.output.trim()
114
+ ? { tail: r.output.trim().split("\n").slice(-6).join("\n").slice(-600) }
115
+ : {}),
116
+ ms: Date.now() - started,
117
+ };
118
+ }
119
+ //# sourceMappingURL=migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,eAAe,GAAoB;IAC9C,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,qBAAqB,EAA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C,IAAI,CAAC;YACpE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;SACzB,CAAC;IACJ,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACzD,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;QACrC,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,EAAE,OAAO;YACb,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB;YAC5F,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,0CAA0C;QAC3E,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE;YACjB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE;YACxE,CAAC,CAAC,EAAE,CAAC;QACP,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;KACzB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Exec } from "./index.js";
2
+ export interface RoutesByCommand {
3
+ source: string;
4
+ /** GET paths without parameters, for the smoke. */
5
+ routes: string[];
6
+ }
7
+ /** Prints `== <source>` then the framework's own route listing, for the first framework found. */
8
+ export declare function routesScript(): string;
9
+ /** The GET paths without parameters from a framework's listing; null when nothing was printed. */
10
+ export declare function parseRoutes(output: string): RoutesByCommand | null;
11
+ /** Lists gRPC services through reflection when grpcurl is in the app container. */
12
+ export declare function grpcScript(port: number): string;
13
+ export declare function parseGrpc(output: string): string[];
14
+ /** The probes that need a command in the app, as one function for the API smoke to call. */
15
+ export declare function routesFallback(exec: (service: string, command: string) => Promise<Exec>, appService: string | undefined, port: number | undefined): Promise<{
16
+ kind: "routes";
17
+ source: string;
18
+ routes: string[];
19
+ } | {
20
+ kind: "grpc";
21
+ services: string[];
22
+ } | null>;
package/dist/routes.js ADDED
@@ -0,0 +1,85 @@
1
+ /** Prints `== <source>` then the framework's own route listing, for the first framework found. */
2
+ export function routesScript() {
3
+ return [
4
+ // Laravel: JSON, the cleanest.
5
+ 'if [ -f artisan ]; then echo "== laravel"; php artisan route:list --json 2>/dev/null; exit 0; fi',
6
+ // Rails: the text table.
7
+ 'if [ -f bin/rails ]; then echo "== rails"; bin/rails routes 2>/dev/null; exit 0; fi',
8
+ // Django with django-extensions: show_urls.
9
+ 'if [ -f manage.py ]; then echo "== django"; (python manage.py show_urls 2>/dev/null || python3 manage.py show_urls 2>/dev/null); exit 0; fi',
10
+ "true",
11
+ ].join("; ");
12
+ }
13
+ /** The GET paths without parameters from a framework's listing; null when nothing was printed. */
14
+ export function parseRoutes(output) {
15
+ const m = /^== (\w+)\n?([\s\S]*)$/.exec(output.trim());
16
+ if (!m)
17
+ return null;
18
+ const [, source, body] = m;
19
+ const routes = new Set();
20
+ if (source === "laravel") {
21
+ try {
22
+ const list = JSON.parse(body);
23
+ for (const r of list)
24
+ if (r.uri && /(^|\|)GET(\||$)/.test(r.method ?? "") && !r.uri.includes("{"))
25
+ routes.add(`/${r.uri.replace(/^\/+/, "")}`);
26
+ }
27
+ catch {
28
+ return { source, routes: [] };
29
+ }
30
+ }
31
+ else if (source === "rails") {
32
+ for (const line of body.split("\n")) {
33
+ const cols = line.trim().split(/\s+/);
34
+ // "prefix GET /path(.:format) controller#action" or "GET /path(.:format) controller#action"
35
+ const i = cols.indexOf("GET");
36
+ const uri = i >= 0 ? cols[i + 1]?.replace(/\(\.:format\)$/, "") : undefined;
37
+ if (uri?.startsWith("/") && !uri.includes(":") && !uri.includes("*"))
38
+ routes.add(uri || "/");
39
+ }
40
+ }
41
+ else if (source === "django") {
42
+ for (const line of body.split("\n")) {
43
+ const uri = line.trim().split(/\s+/)[0];
44
+ if (uri?.startsWith("/") && !uri.includes("<") && !uri.includes("^"))
45
+ routes.add(uri);
46
+ }
47
+ }
48
+ if (!body.trim())
49
+ return { source, routes: [] };
50
+ return {
51
+ source,
52
+ routes: [...routes].filter((r) => !/\.(js|css|png|ico)$/.test(r)).slice(0, 200),
53
+ };
54
+ }
55
+ /** Lists gRPC services through reflection when grpcurl is in the app container. */
56
+ export function grpcScript(port) {
57
+ return `command -v grpcurl >/dev/null 2>&1 && grpcurl -plaintext localhost:${port} list 2>&1`;
58
+ }
59
+ export function parseGrpc(output) {
60
+ return output
61
+ .split("\n")
62
+ .map((l) => l.trim())
63
+ .filter((l) => l && !l.startsWith("grpc.reflection") && !/^(Failed|Error)/i.test(l));
64
+ }
65
+ /** The probes that need a command in the app, as one function for the API smoke to call. */
66
+ export async function routesFallback(exec, appService, port) {
67
+ if (!appService)
68
+ return null;
69
+ const r = await exec(appService, routesScript()).catch(() => null);
70
+ if (r && r.exitCode === 0) {
71
+ const parsed = parseRoutes(r.output);
72
+ if (parsed)
73
+ return { kind: "routes", ...parsed };
74
+ }
75
+ if (port) {
76
+ const g = await exec(appService, grpcScript(port)).catch(() => null);
77
+ if (g && g.exitCode === 0) {
78
+ const services = parseGrpc(g.output);
79
+ if (services.length)
80
+ return { kind: "grpc", services };
81
+ }
82
+ }
83
+ return null;
84
+ }
85
+ //# sourceMappingURL=routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAYA,kGAAkG;AAClG,MAAM,UAAU,YAAY;IAC1B,OAAO;QACL,+BAA+B;QAC/B,kGAAkG;Q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Q,CAAC,MAAM;gBAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QACzD,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Recipe } from "@forkstage/recipe";
2
+ import type { Outcome } from "./index.js";
3
+ export interface ChangeFiles {
4
+ changed: string[];
5
+ deleted: string[];
6
+ }
7
+ export interface Scope extends Outcome {
8
+ services: string[];
9
+ source: number;
10
+ tests: number;
11
+ migrations: number;
12
+ recipe: boolean;
13
+ docs: number;
14
+ }
15
+ /** The service whose build context or source folder holds the path; the longest match wins. */
16
+ export declare function serviceFor(path: string, recipe: Recipe): string | null;
17
+ export declare function changeScope(files: ChangeFiles, recipe: Recipe): Scope;
package/dist/scope.js ADDED
@@ -0,0 +1,75 @@
1
+ const TEST_FILE = /(^|\/)(tests?|__tests__|spec|specs|e2e|cypress)\/|\.(test|spec)\.[cm]?[jt]sx?$|_test\.go$|(^|\/)test_[^/]*\.py$|_test\.py$|Tests?\.java$|Spec\.(scala|groovy|kt)$|_spec\.rb$|Test\.php$|_test\.rs$/;
2
+ const MIGRATION_FILE = /(^|\/)(migrations?|db\/migrate|alembic\/versions|prisma\/migrations|db\/changelog|db\/migration|supabase\/migrations)\//;
3
+ const DOC_FILE = /\.(md|mdx|rst|txt|adoc)$|(^|\/)(docs?|LICENSE|CHANGELOG)(\/|$)/i;
4
+ /** The service whose build context or source folder holds the path; the longest match wins. */
5
+ export function serviceFor(path, recipe) {
6
+ let best = null;
7
+ for (const [name, s] of Object.entries(recipe.services)) {
8
+ // Only services the repository builds or mounts own files; an image has no source here.
9
+ if (!s.build && !s.source)
10
+ continue;
11
+ const dir = (s.build ?? s.source ?? "").replace(/^\.\/?/, "").replace(/\/+$/, "");
12
+ const inside = dir === "" || path === dir || path.startsWith(`${dir}/`);
13
+ if (!inside)
14
+ continue;
15
+ if (!best || dir.length > best.len)
16
+ best = { name, len: dir.length };
17
+ }
18
+ return best?.name ?? null;
19
+ }
20
+ export function changeScope(files, recipe) {
21
+ const all = [...files.changed, ...files.deleted];
22
+ const services = new Set();
23
+ let source = 0;
24
+ let tests = 0;
25
+ let migrations = 0;
26
+ let docs = 0;
27
+ let recipeChanged = false;
28
+ for (const p of all) {
29
+ const svc = serviceFor(p, recipe);
30
+ if (svc)
31
+ services.add(svc);
32
+ if (p === "forkstage.yaml" || p.endsWith("/forkstage.yaml")) {
33
+ recipeChanged = true;
34
+ continue;
35
+ }
36
+ if (TEST_FILE.test(p))
37
+ tests += 1;
38
+ else if (MIGRATION_FILE.test(p))
39
+ migrations += 1;
40
+ else if (DOC_FILE.test(p))
41
+ docs += 1;
42
+ else
43
+ source += 1;
44
+ }
45
+ const parts = [];
46
+ if (source)
47
+ parts.push(`${source} source`);
48
+ if (tests)
49
+ parts.push(`${tests} test`);
50
+ if (migrations)
51
+ parts.push(`${migrations} migration`);
52
+ if (docs)
53
+ parts.push(`${docs} docs`);
54
+ if (recipeChanged)
55
+ parts.push("the recipe");
56
+ const where = services.size ? ` in ${[...services].join(", ")}` : "";
57
+ const base = {
58
+ services: [...services],
59
+ source,
60
+ tests,
61
+ migrations,
62
+ recipe: recipeChanged,
63
+ docs,
64
+ ms: 0,
65
+ };
66
+ if (!all.length)
67
+ return { ...base, status: "passed", detail: "no files differ from the snapshot's commit" };
68
+ const unproven = source > 0 && tests === 0 && !recipeChanged;
69
+ return {
70
+ ...base,
71
+ status: unproven ? "warn" : "passed",
72
+ detail: `${all.length} file${all.length === 1 ? "" : "s"}${where}: ${parts.join(", ")}${unproven ? "; no test or check came with the source change" : ""}`,
73
+ };
74
+ }
75
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAqBA,MAAM,SAAS,GACb,oMAAoM,CAAC;AACvM,MAAM,cAAc,GAClB,yHAAyH,CAAC;AAC5H,MAAM,QAAQ,G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,IAAI,GAAG;QACX,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC;QACvB,MAAM;QACN,KAAK;QACL,UAAU;QACV,MAAM,EAAE,aAAa;QACrB,IAAI;QACJ,EAAE,EAAE,CAAC;KACN,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,MAAM;QACb,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,4CAA4C,EAAE,CAAC;IAC7F,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC;IAC7D,OAAO;QACL,GAAG,IAAI;QACP,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ;QACpC,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,gDAAgD,CAAC,CAAC,CAAC,EAAE,EAAE;KAC3J,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@forkstage/verify",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "The verification probes Forkstage runs against a fork: API smoke, change checks, captured mail, log scan. Portable; the CLI and the control plane share them.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@forkstage/proof": "^0.4.0",
20
+ "@forkstage/recipe": "^0.7.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^26.6.4",
24
+ "typescript": "^7.0.2",
25
+ "vitest": "^5.0.3"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/Metricall-AI-Lab/forkstage.git",
30
+ "directory": "packages/verify"
31
+ },
32
+ "homepage": "https://forkstage.com",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "keywords": [
37
+ "forkstage",
38
+ "verification",
39
+ "testing",
40
+ "environments"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json",
44
+ "typecheck": "tsc -p tsconfig.json --noEmit",
45
+ "test": "vitest run"
46
+ }
6
47
  }