@luckystack/test-runner 0.10.1 → 0.11.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/AGENTS.md +7 -0
- package/CHANGELOG.md +28 -1
- package/README.md +13 -66
- package/dist/authEnforcementCheck.d.ts +12 -0
- package/dist/contractCheck.d.ts +24 -0
- package/dist/csrfEnforcementCheck.d.ts +25 -0
- package/dist/customTests.d.ts +145 -0
- package/dist/extensionRegistry.d.ts +83 -0
- package/dist/fuzzCheck.d.ts +12 -0
- package/dist/index.d.ts +49 -557
- package/dist/index.js +560 -304
- package/dist/index.js.map +1 -1
- package/dist/probeRequest.d.ts +48 -0
- package/dist/rateLimitCheck.d.ts +14 -0
- package/dist/reporter.d.ts +3 -0
- package/dist/resetServerState.d.ts +13 -0
- package/dist/resolveTestBaseUrl.d.ts +7 -0
- package/dist/resolveTestEnvironment.d.ts +21 -0
- package/dist/runAllTests.d.ts +88 -0
- package/dist/runAuthEnforcementTests.d.ts +17 -0
- package/dist/runContractTests.d.ts +22 -0
- package/dist/runCsrfEnforcementTests.d.ts +29 -0
- package/dist/runFuzzTests.d.ts +16 -0
- package/dist/runRateLimitTests.d.ts +38 -0
- package/dist/runRegisteredLayers.d.ts +24 -0
- package/dist/sampleInputFor.d.ts +13 -0
- package/dist/schemaSampleInput.d.ts +12 -0
- package/dist/socketProbeTransport.d.ts +9 -0
- package/dist/streamWatcher.d.ts +37 -0
- package/dist/testDataMarker.d.ts +2 -0
- package/dist/testLayerHelpers.d.ts +55 -0
- package/dist/testSocket.d.ts +58 -0
- package/dist/types.d.ts +46 -0
- package/dist/walkEndpoints.d.ts +6 -0
- package/docs/auth-tests.md +4 -223
- package/docs/contract-tests.md +11 -293
- package/docs/extension-hooks.md +4 -460
- package/docs/fuzz-tests.md +4 -245
- package/docs/rate-limit-tests.md +9 -253
- package/package.json +5 -5
- package/CLAUDE.md +0 -104
package/dist/index.d.ts
CHANGED
|
@@ -1,557 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* Optional input factory. Defaults to `{}`. When an endpoint requires a
|
|
51
|
-
* specific shape to not crash, callers can override per-endpoint here.
|
|
52
|
-
*/
|
|
53
|
-
inputFor?: (endpoint: EndpointDescriptor) => unknown;
|
|
54
|
-
/**
|
|
55
|
-
* Optional headers (auth tokens, cookies). Applied to every request.
|
|
56
|
-
*/
|
|
57
|
-
headers?: Record<string, string>;
|
|
58
|
-
/**
|
|
59
|
-
* Per-call request timeout in ms. Defaults to 5000. Bump for slow endpoints
|
|
60
|
-
* (AI calls, large reports) where the framework default would false-fail
|
|
61
|
-
* the contract check.
|
|
62
|
-
*/
|
|
63
|
-
requestTimeoutMs?: number;
|
|
64
|
-
}
|
|
65
|
-
declare const runContractCheck: (input: ContractCheckInput) => Promise<ContractCheckResult>;
|
|
66
|
-
|
|
67
|
-
interface RunContractTestsInput {
|
|
68
|
-
apiMethodMap: ApiMethodMap$1;
|
|
69
|
-
baseUrl: string;
|
|
70
|
-
/**
|
|
71
|
-
* Endpoints to skip. Matched against `<page>/<name>` (version-agnostic) and
|
|
72
|
-
* `<page>/<name>/<version>` (version-specific). Useful for endpoints that
|
|
73
|
-
* are known to need real input (e.g. a file upload).
|
|
74
|
-
*/
|
|
75
|
-
skip?: string[];
|
|
76
|
-
inputFor?: (endpoint: EndpointDescriptor) => unknown;
|
|
77
|
-
headers?: Record<string, string>;
|
|
78
|
-
onResult?: (result: ContractCheckResult) => void;
|
|
79
|
-
}
|
|
80
|
-
declare const runContractTests: (input: RunContractTestsInput) => Promise<RunContractSummary>;
|
|
81
|
-
|
|
82
|
-
interface AuthEnforcementCheckInput {
|
|
83
|
-
endpoint: EndpointDescriptor;
|
|
84
|
-
baseUrl: string;
|
|
85
|
-
inputFor?: (endpoint: EndpointDescriptor) => unknown;
|
|
86
|
-
/** Per-call request timeout in ms. Defaults to 5000. */
|
|
87
|
-
requestTimeoutMs?: number;
|
|
88
|
-
}
|
|
89
|
-
declare const runAuthEnforcementCheck: (input: AuthEnforcementCheckInput) => Promise<ContractCheckResult>;
|
|
90
|
-
|
|
91
|
-
interface RunAuthEnforcementTestsInput {
|
|
92
|
-
apiMethodMap: ApiMethodMap$1;
|
|
93
|
-
apiMetaMap: ApiMetaMap;
|
|
94
|
-
baseUrl: string;
|
|
95
|
-
skip?: string[];
|
|
96
|
-
inputFor?: (endpoint: EndpointDescriptor) => unknown;
|
|
97
|
-
onResult?: (result: ContractCheckResult) => void;
|
|
98
|
-
}
|
|
99
|
-
declare const runAuthEnforcementTests: (input: RunAuthEnforcementTestsInput) => Promise<RunContractSummary>;
|
|
100
|
-
|
|
101
|
-
interface RateLimitCheckInput {
|
|
102
|
-
endpoint: EndpointDescriptor;
|
|
103
|
-
baseUrl: string;
|
|
104
|
-
rateLimit: number;
|
|
105
|
-
inputFor?: (endpoint: EndpointDescriptor) => unknown;
|
|
106
|
-
headers?: Record<string, string>;
|
|
107
|
-
/** Per-call request timeout in ms. Defaults to 10000. */
|
|
108
|
-
requestTimeoutMs?: number;
|
|
109
|
-
}
|
|
110
|
-
declare const runRateLimitCheck: (input: RateLimitCheckInput) => Promise<ContractCheckResult>;
|
|
111
|
-
|
|
112
|
-
interface RunRateLimitTestsInput {
|
|
113
|
-
apiMethodMap: ApiMethodMap$1;
|
|
114
|
-
apiMetaMap: ApiMetaMap;
|
|
115
|
-
baseUrl: string;
|
|
116
|
-
skip?: string[];
|
|
117
|
-
inputFor?: (endpoint: EndpointDescriptor) => unknown;
|
|
118
|
-
headers?: Record<string, string>;
|
|
119
|
-
/**
|
|
120
|
-
* Max rateLimit value to test. Endpoints with a higher limit are skipped
|
|
121
|
-
* to avoid firing thousands of requests in CI.
|
|
122
|
-
*/
|
|
123
|
-
maxRateLimitToTest?: number;
|
|
124
|
-
/**
|
|
125
|
-
* When true, hit `/_test/reset` before each endpoint so limiter state is
|
|
126
|
-
* clean. Requires the server to allow the endpoint: `NODE_ENV` in
|
|
127
|
-
* { 'development', 'test' } AND `TEST_RESET_TOKEN` set on the server with a
|
|
128
|
-
* matching `resetToken` here (an unset token is 403, never open). Without
|
|
129
|
-
* resetting, the shared IP bucket leaks state between endpoints.
|
|
130
|
-
*/
|
|
131
|
-
resetBetweenEndpoints?: boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Token forwarded as `X-Test-Reset-Token` when resetting. Only relevant in
|
|
134
|
-
* staging/preview deploys that enable the endpoint behind a token.
|
|
135
|
-
*/
|
|
136
|
-
resetToken?: string;
|
|
137
|
-
onResult?: (result: ContractCheckResult) => void;
|
|
138
|
-
}
|
|
139
|
-
declare const runRateLimitTests: (input: RunRateLimitTestsInput) => Promise<RunContractSummary>;
|
|
140
|
-
|
|
141
|
-
interface CsrfEnforcementCheckInput {
|
|
142
|
-
endpoint: EndpointDescriptor;
|
|
143
|
-
baseUrl: string;
|
|
144
|
-
/**
|
|
145
|
-
* A valid session Cookie header (`<name>=<token>`). The probe deliberately
|
|
146
|
-
* carries it so the request passes the auth guard and reaches the CSRF check.
|
|
147
|
-
*/
|
|
148
|
-
authCookie: string;
|
|
149
|
-
inputFor?: (endpoint: EndpointDescriptor) => unknown;
|
|
150
|
-
/** Per-call request timeout in ms. Defaults to 5000. */
|
|
151
|
-
requestTimeoutMs?: number;
|
|
152
|
-
/** Error code expected on CSRF rejection. Defaults to `auth.csrfMismatch`. */
|
|
153
|
-
expectedErrorCode?: string;
|
|
154
|
-
/** HTTP status expected on CSRF rejection. Defaults to 403; pass `false` to skip. */
|
|
155
|
-
expectedHttpStatus?: number | false;
|
|
156
|
-
}
|
|
157
|
-
declare const runCsrfEnforcementCheck: (input: CsrfEnforcementCheckInput) => Promise<ContractCheckResult>;
|
|
158
|
-
|
|
159
|
-
interface RunCsrfEnforcementTestsInput {
|
|
160
|
-
apiMethodMap: ApiMethodMap$1;
|
|
161
|
-
apiMetaMap: ApiMetaMap;
|
|
162
|
-
baseUrl: string;
|
|
163
|
-
/** Valid session Cookie header (`<name>=<token>`) the probes carry so they reach the CSRF check. */
|
|
164
|
-
authCookie: string;
|
|
165
|
-
skip?: string[];
|
|
166
|
-
inputFor?: (endpoint: EndpointDescriptor) => unknown;
|
|
167
|
-
/** Per-call request timeout in ms forwarded to each check. */
|
|
168
|
-
requestTimeoutMs?: number;
|
|
169
|
-
/** Error code expected on CSRF rejection. Defaults to `auth.csrfMismatch`. */
|
|
170
|
-
expectedErrorCode?: string;
|
|
171
|
-
/** HTTP status expected on CSRF rejection. Defaults to 403; pass `false` to skip. */
|
|
172
|
-
expectedHttpStatus?: number | false;
|
|
173
|
-
onResult?: (result: ContractCheckResult) => void;
|
|
174
|
-
}
|
|
175
|
-
declare const runCsrfEnforcementTests: (input: RunCsrfEnforcementTestsInput) => Promise<RunContractSummary>;
|
|
176
|
-
|
|
177
|
-
interface FuzzCheckInput {
|
|
178
|
-
endpoint: EndpointDescriptor;
|
|
179
|
-
baseUrl: string;
|
|
180
|
-
headers?: Record<string, string>;
|
|
181
|
-
/** Per-call request timeout in ms. Defaults to 5000. */
|
|
182
|
-
requestTimeoutMs?: number;
|
|
183
|
-
}
|
|
184
|
-
declare const runFuzzCheck: (input: FuzzCheckInput) => Promise<ContractCheckResult>;
|
|
185
|
-
|
|
186
|
-
interface RunFuzzTestsInput {
|
|
187
|
-
apiMethodMap: ApiMethodMap$1;
|
|
188
|
-
baseUrl: string;
|
|
189
|
-
skip?: string[];
|
|
190
|
-
headers?: Record<string, string>;
|
|
191
|
-
onResult?: (result: ContractCheckResult) => void;
|
|
192
|
-
}
|
|
193
|
-
declare const runFuzzTests: (input: RunFuzzTestsInput) => Promise<RunContractSummary>;
|
|
194
|
-
|
|
195
|
-
interface ResetServerStateInput {
|
|
196
|
-
baseUrl: string;
|
|
197
|
-
token?: string;
|
|
198
|
-
requestTimeoutMs?: number;
|
|
199
|
-
}
|
|
200
|
-
declare const resetServerState: ({ baseUrl, token, requestTimeoutMs }: ResetServerStateInput) => Promise<boolean>;
|
|
201
|
-
|
|
202
|
-
interface ResolveTestBaseUrlOptions {
|
|
203
|
-
/** Project root containing node_modules/.luckystack/dev-server.json. */
|
|
204
|
-
cwd?: string;
|
|
205
|
-
/** Used when no explicit override or valid live advertisement exists. */
|
|
206
|
-
fallbackUrl?: string;
|
|
207
|
-
}
|
|
208
|
-
declare const resolveTestBaseUrl: (options?: ResolveTestBaseUrlOptions) => string;
|
|
209
|
-
|
|
210
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
211
|
-
interface ResolveTestEnvironmentInput {
|
|
212
|
-
/**
|
|
213
|
-
* Loads the consumer's default-exported `config.ts` object after `.env` files
|
|
214
|
-
* are available. Keeping this as a callback avoids hardcoding a consumer path
|
|
215
|
-
* inside the package and keeps `@luckystack/secret-manager` optional.
|
|
216
|
-
*/
|
|
217
|
-
loadProjectConfig?: () => MaybePromise<unknown>;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Load the project's env files and resolve optional secret-manager pointers for
|
|
221
|
-
* the TEST process. Call before importing integration-test modules that touch a
|
|
222
|
-
* database, Redis, or another env-backed SDK.
|
|
223
|
-
*/
|
|
224
|
-
declare const resolveTestEnvironment: (input?: ResolveTestEnvironmentInput) => Promise<void>;
|
|
225
|
-
|
|
226
|
-
interface SampleSchemaOptions {
|
|
227
|
-
/**
|
|
228
|
-
* Marker prefix applied to generated UNCONSTRAINED string values so any rows
|
|
229
|
-
* a sweep creates are identifiable + collision-free (finding #98). Strings
|
|
230
|
-
* that carry a format (email/url/uuid/datetime/…) or a check (min/max/
|
|
231
|
-
* length/regex) are left as-is, since prefixing could break the route's own
|
|
232
|
-
* validation and defeat the contract layer's "valid input" guarantee.
|
|
233
|
-
*/
|
|
234
|
-
stringPrefix?: string;
|
|
235
|
-
}
|
|
236
|
-
declare const sampleSchemaInput: (schema: z.ZodType, options?: SampleSchemaOptions) => unknown;
|
|
237
|
-
|
|
238
|
-
declare const TEST_DATA_PREFIX = "lstest_";
|
|
239
|
-
declare const createTestDataMarker: () => string;
|
|
240
|
-
|
|
241
|
-
declare const logContractResult: (result: ContractCheckResult) => void;
|
|
242
|
-
declare const logContractSummary: (summary: RunContractSummary) => void;
|
|
243
|
-
|
|
244
|
-
interface StreamChunkFrame {
|
|
245
|
-
/** Per-request correlation id stamped by the server. */
|
|
246
|
-
cb?: string;
|
|
247
|
-
/** Full route name (`sync/<page>/<name>/<version>`). */
|
|
248
|
-
fullName?: string;
|
|
249
|
-
/** Always `'stream'` for chunk frames. */
|
|
250
|
-
status?: 'stream';
|
|
251
|
-
/** Payload fields spread on top of the envelope. */
|
|
252
|
-
[key: string]: unknown;
|
|
253
|
-
}
|
|
254
|
-
interface StreamWatcher<TChunk extends StreamChunkFrame = StreamChunkFrame> {
|
|
255
|
-
/** Chunks received so far. Array reference is stable; entries are pushed in arrival order. */
|
|
256
|
-
readonly chunks: TChunk[];
|
|
257
|
-
/** Wait until `predicate(chunks)` returns true, or until timeout (default 5000ms). */
|
|
258
|
-
stopAt(predicate: (chunks: TChunk[]) => boolean, timeoutMs?: number): Promise<void>;
|
|
259
|
-
/** Wait until N total chunks received, or until timeout. */
|
|
260
|
-
waitForCount(n: number, timeoutMs?: number): Promise<void>;
|
|
261
|
-
/** Close socket B. Tests SHOULD call this in cleanup; ctx auto-closes all watchers when the test ends. */
|
|
262
|
-
close(): Promise<void>;
|
|
263
|
-
}
|
|
264
|
-
interface OpenStreamWatcherInput {
|
|
265
|
-
/** Server URL (same as `ctx`'s `baseUrl`). */
|
|
266
|
-
baseUrl: string;
|
|
267
|
-
/** Room to join as a pure subscriber. */
|
|
268
|
-
roomCode: string;
|
|
269
|
-
/** Active session token (used for `joinRoom` auth). May be null for routes that don't require auth. */
|
|
270
|
-
token: string | null;
|
|
271
|
-
/**
|
|
272
|
-
* Resolved route name `sync/<page>/<name>/<version>` — chunk frames are
|
|
273
|
-
* filtered by their `fullName` property so a watcher only surfaces chunks
|
|
274
|
-
* for the route its test is bound to.
|
|
275
|
-
*/
|
|
276
|
-
routeFullName: string;
|
|
277
|
-
/** Default 5000ms — overridable per `stopAt` / `waitForCount` call. */
|
|
278
|
-
defaultTimeoutMs?: number;
|
|
279
|
-
}
|
|
280
|
-
declare const openStreamWatcher: <TChunk extends StreamChunkFrame = StreamChunkFrame>(input: OpenStreamWatcherInput) => Promise<StreamWatcher<TChunk>>;
|
|
281
|
-
|
|
282
|
-
interface CustomTestCase {
|
|
283
|
-
name: string;
|
|
284
|
-
run: (ctx: TestContext) => Promise<void>;
|
|
285
|
-
/**
|
|
286
|
-
* Mark this case as a KNOWN, accepted failure (e.g. a documented bug not
|
|
287
|
-
* yet fixed, or a scenario the current implementation cannot satisfy). The
|
|
288
|
-
* string is the reason shown in the report. A case marked `expectedToFail`
|
|
289
|
-
* that throws is reported as `xfail` — counted separately, NOT a red
|
|
290
|
-
* failure. If it unexpectedly PASSES it is reported as `xpass` so the stale
|
|
291
|
-
* marker can be removed. Leave undefined for normal cases.
|
|
292
|
-
*/
|
|
293
|
-
expectedToFail?: string;
|
|
294
|
-
}
|
|
295
|
-
interface CustomTestResult {
|
|
296
|
-
routePath: string;
|
|
297
|
-
caseName: string;
|
|
298
|
-
status: 'pass' | 'fail' | 'xfail' | 'xpass';
|
|
299
|
-
durationMs: number;
|
|
300
|
-
reason?: string;
|
|
301
|
-
/** Documented reason when the case carried an `expectedToFail` marker. */
|
|
302
|
-
expectedToFail?: string;
|
|
303
|
-
}
|
|
304
|
-
interface RunCustomTestsSummary {
|
|
305
|
-
total: number;
|
|
306
|
-
passed: number;
|
|
307
|
-
failed: number;
|
|
308
|
-
/** Cases marked `expectedToFail` that failed as expected (known issues). */
|
|
309
|
-
xfailed: number;
|
|
310
|
-
/** Cases marked `expectedToFail` that unexpectedly passed (remove the marker). */
|
|
311
|
-
xpassed: number;
|
|
312
|
-
results: CustomTestResult[];
|
|
313
|
-
}
|
|
314
|
-
interface RunCustomTestsInput {
|
|
315
|
-
baseUrl: string;
|
|
316
|
-
/** Optional cookie name for the session token. Defaults to the project's configured cookie. */
|
|
317
|
-
sessionCookieName?: string;
|
|
318
|
-
/** Filter to a subset of routes — substring match against `<page>/<name>/<version>`. */
|
|
319
|
-
filter?: string;
|
|
320
|
-
/**
|
|
321
|
-
* Generated `apiMethodMap` so the harness sends each API route its declared
|
|
322
|
-
* HTTP method (e.g. logout is DELETE). Falls back to POST when absent.
|
|
323
|
-
*/
|
|
324
|
-
apiMethodMap?: ApiMethodMap$1;
|
|
325
|
-
/**
|
|
326
|
-
* Lazy consumer config for direct Layer-5 runs. Required so the public path
|
|
327
|
-
* cannot silently skip a configured secret manager; `runAllTests` prepares
|
|
328
|
-
* the environment separately before using the internal Layer-5 entrypoint.
|
|
329
|
-
*/
|
|
330
|
-
loadProjectConfig: NonNullable<ResolveTestEnvironmentInput['loadProjectConfig']>;
|
|
331
|
-
onResult?: (result: CustomTestResult) => void;
|
|
332
|
-
}
|
|
333
|
-
interface DiscoveredTestFile {
|
|
334
|
-
/** Absolute path to the test file. */
|
|
335
|
-
filePath: string;
|
|
336
|
-
/** `api` or `sync` — which transport this route uses. */
|
|
337
|
-
kind: 'api' | 'sync';
|
|
338
|
-
/** Route descriptor parsed from the filename + directory location. */
|
|
339
|
-
route: {
|
|
340
|
-
page: string;
|
|
341
|
-
name: string;
|
|
342
|
-
version: string;
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
declare const discoverCustomTestFiles: (srcDir?: string) => DiscoveredTestFile[];
|
|
346
|
-
interface TestContext {
|
|
347
|
-
/**
|
|
348
|
-
* Invoke the route under test. Page / name / version are baked in.
|
|
349
|
-
*
|
|
350
|
-
* `input` travels exactly like the real client sends it: as the JSON body
|
|
351
|
-
* for POST / PUT / DELETE routes, and as the `__luckystack_data` query-string
|
|
352
|
-
* value for GET routes (a GET cannot carry a body). Either way the server
|
|
353
|
-
* validates it as the route's `data`, so a GET route with required fields
|
|
354
|
-
* receives them.
|
|
355
|
-
*/
|
|
356
|
-
callApi: <TInput = unknown, TOutput = unknown>(input: TInput) => Promise<TOutput>;
|
|
357
|
-
callSync: <TInput = unknown, TOutput = unknown>(input: TInput, opts?: {
|
|
358
|
-
receiver?: string;
|
|
359
|
-
}) => Promise<TOutput>;
|
|
360
|
-
/**
|
|
361
|
-
* Open a second socket connection that joins `roomCode` as a pure
|
|
362
|
-
* subscriber and exposes the incoming chunk stream for assertions.
|
|
363
|
-
*
|
|
364
|
-
* The route is auto-derived from the test file location, so a watcher
|
|
365
|
-
* only surfaces chunks for the route this test belongs to. Multiple
|
|
366
|
-
* watchers per test are allowed; all are auto-closed when the test
|
|
367
|
-
* case finishes (whether it passes or throws).
|
|
368
|
-
*/
|
|
369
|
-
watchStream: <TChunk extends StreamChunkFrame = StreamChunkFrame>(roomCode: string) => Promise<StreamWatcher<TChunk>>;
|
|
370
|
-
session: {
|
|
371
|
-
login: (user?: {
|
|
372
|
-
email?: string;
|
|
373
|
-
id?: string;
|
|
374
|
-
name?: string;
|
|
375
|
-
}) => Promise<{
|
|
376
|
-
token: string;
|
|
377
|
-
userId: string;
|
|
378
|
-
}>;
|
|
379
|
-
logout: () => Promise<void>;
|
|
380
|
-
current: () => {
|
|
381
|
-
token: string | null;
|
|
382
|
-
userId: string | null;
|
|
383
|
-
};
|
|
384
|
-
};
|
|
385
|
-
prisma: ReturnType<typeof getPrismaClient>;
|
|
386
|
-
expect: TestExpect;
|
|
387
|
-
}
|
|
388
|
-
interface TestExpect {
|
|
389
|
-
eq: <T>(actual: T, expected: T, message?: string) => void;
|
|
390
|
-
ok: (value: unknown, message?: string) => void;
|
|
391
|
-
throws: (fn: () => Promise<unknown>, message?: string) => Promise<Error>;
|
|
392
|
-
matches: (value: string, pattern: RegExp, message?: string) => void;
|
|
393
|
-
}
|
|
394
|
-
declare const runCustomTests: (input: RunCustomTestsInput) => Promise<RunCustomTestsSummary>;
|
|
395
|
-
|
|
396
|
-
type ApiInputSchemas = Partial<Record<string, Partial<Record<string, Partial<Record<string, ZodType | undefined>>>>>>;
|
|
397
|
-
interface RunAllTestsInput {
|
|
398
|
-
apiMethodMap: ApiMethodMap$1;
|
|
399
|
-
/**
|
|
400
|
-
* Lazy loader for the consumer's default `config.ts` export. Required so
|
|
401
|
-
* runAllTests cannot silently skip a configured secret manager; resolution
|
|
402
|
-
* happens in THIS process before any layer or env-backed client is touched.
|
|
403
|
-
*/
|
|
404
|
-
loadProjectConfig: NonNullable<ResolveTestEnvironmentInput['loadProjectConfig']>;
|
|
405
|
-
apiMetaMap: ApiMetaMap;
|
|
406
|
-
apiInputSchemas: ApiInputSchemas;
|
|
407
|
-
baseUrl: string;
|
|
408
|
-
/** Cookie name for the session token. Defaults to the project's configured session cookie name (`projectConfig.http.sessionCookieName`). */
|
|
409
|
-
sessionCookieName?: string;
|
|
410
|
-
/** Auth token applied as a `Cookie` header to sweep-layer requests that need a session. */
|
|
411
|
-
authToken?: string;
|
|
412
|
-
/** Endpoints to skip from the sweep layers, e.g. routes that need a file upload. */
|
|
413
|
-
skip?: string[];
|
|
414
|
-
/** Substring filter applied to `<page>/<name>/<version>`. */
|
|
415
|
-
filter?: string;
|
|
416
|
-
/** Disable individual layers (faster local iteration). */
|
|
417
|
-
noSweep?: boolean;
|
|
418
|
-
noFuzz?: boolean;
|
|
419
|
-
noRateLimit?: boolean;
|
|
420
|
-
/**
|
|
421
|
-
* Disable the CSRF-enforcement layer. Defaults to ON (the layer runs) — but it
|
|
422
|
-
* can only probe past the auth guard with a session, so it is a no-op unless an
|
|
423
|
-
* `authToken` is supplied.
|
|
424
|
-
*/
|
|
425
|
-
noCsrf?: boolean;
|
|
426
|
-
noCustom?: boolean;
|
|
427
|
-
/**
|
|
428
|
-
* Token sent as `X-Test-Reset-Token` when the rate-limit layer resets the
|
|
429
|
-
* shared bucket between endpoints. The server's `/_test/reset` requires
|
|
430
|
-
* `TEST_RESET_TOKEN` to be set and matching — an unset/wrong token is 403, so
|
|
431
|
-
* `resetBetweenEndpoints` would silently no-op. Defaults to
|
|
432
|
-
* `process.env.TEST_RESET_TOKEN` so a CI run with the env set works with no
|
|
433
|
-
* extra wiring; pass explicitly to override.
|
|
434
|
-
*/
|
|
435
|
-
resetToken?: string;
|
|
436
|
-
/**
|
|
437
|
-
* Contract-test mutation safety (finding #98). When a reset token is
|
|
438
|
-
* available, the sweep POSTs `/_test/reset` ONCE before the first layer
|
|
439
|
-
* (clean slate — no real row the generated payloads could clobber) and ONCE
|
|
440
|
-
* after the last (drop whatever the sweep created, so no test data persists).
|
|
441
|
-
* Defaults to ON; set `false` to opt out. With no token the bookends are
|
|
442
|
-
* silently skipped with a logged note (they can't run — `/_test/reset` 403s).
|
|
443
|
-
*/
|
|
444
|
-
resetBookends?: boolean;
|
|
445
|
-
}
|
|
446
|
-
interface RunAllTestsSummary {
|
|
447
|
-
contract?: RunContractSummary;
|
|
448
|
-
auth?: RunContractSummary;
|
|
449
|
-
rateLimit?: RunContractSummary;
|
|
450
|
-
csrf?: RunContractSummary;
|
|
451
|
-
fuzz?: RunContractSummary;
|
|
452
|
-
custom?: RunCustomTestsSummary;
|
|
453
|
-
totalPassed: number;
|
|
454
|
-
totalFailed: number;
|
|
455
|
-
}
|
|
456
|
-
declare const runAllTests: (input: RunAllTestsInput) => Promise<RunAllTestsSummary>;
|
|
457
|
-
declare const logRunAllSummary: (summary: RunAllTestsSummary) => void;
|
|
458
|
-
|
|
459
|
-
interface TestLayerInput {
|
|
460
|
-
/** Resolved route name (`api/billing/getInvoice/v1`). */
|
|
461
|
-
endpoint: string;
|
|
462
|
-
/** Method when applicable, undefined for sync endpoints. */
|
|
463
|
-
method?: string;
|
|
464
|
-
/** Bearer token / session token to use for auth-aware checks. */
|
|
465
|
-
authToken?: string;
|
|
466
|
-
}
|
|
467
|
-
interface TestLayerResult {
|
|
468
|
-
passed: boolean;
|
|
469
|
-
/** Short reason key — i18n-style errorCode when failed. */
|
|
470
|
-
message?: string;
|
|
471
|
-
/** Optional extras for the reporter (latency, response sample, ...). */
|
|
472
|
-
metadata?: Record<string, unknown>;
|
|
473
|
-
}
|
|
474
|
-
interface TestLayer {
|
|
475
|
-
name: string;
|
|
476
|
-
run: (input: TestLayerInput) => Promise<TestLayerResult> | TestLayerResult;
|
|
477
|
-
}
|
|
478
|
-
interface TestFixture<TPayload = unknown> {
|
|
479
|
-
valid: TPayload[];
|
|
480
|
-
invalid: TPayload[];
|
|
481
|
-
}
|
|
482
|
-
interface TestResult {
|
|
483
|
-
layer: string;
|
|
484
|
-
endpoint: string;
|
|
485
|
-
passed: boolean;
|
|
486
|
-
message?: string;
|
|
487
|
-
durationMs?: number;
|
|
488
|
-
metadata?: Record<string, unknown>;
|
|
489
|
-
}
|
|
490
|
-
interface TestSummary {
|
|
491
|
-
totalLayers: number;
|
|
492
|
-
totalEndpoints: number;
|
|
493
|
-
passed: number;
|
|
494
|
-
failed: number;
|
|
495
|
-
results: TestResult[];
|
|
496
|
-
}
|
|
497
|
-
interface TestReporter {
|
|
498
|
-
/** Called once per individual TestResult as the runner progresses. */
|
|
499
|
-
onResult?: (result: TestResult) => void | Promise<void>;
|
|
500
|
-
/** Called once at the end with the aggregated summary. */
|
|
501
|
-
onSummary?: (summary: TestSummary) => void | Promise<void>;
|
|
502
|
-
/** Optional webhook the runner POSTs the summary to. */
|
|
503
|
-
webhookUrl?: string;
|
|
504
|
-
webhookAuth?: {
|
|
505
|
-
type: 'bearer';
|
|
506
|
-
token: string;
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Register a custom test layer. Re-registering the same name replaces
|
|
511
|
-
* the previous entry. Use for CORS enforcement, business-rule checks,
|
|
512
|
-
* custom auth schemes, multi-tenant isolation, GDPR data-flow checks.
|
|
513
|
-
*/
|
|
514
|
-
declare const registerTestLayer: (layer: TestLayer) => void;
|
|
515
|
-
declare const listTestLayers: () => TestLayer[];
|
|
516
|
-
/**
|
|
517
|
-
* Register a realistic payload fixture for a specific type key. The fuzz
|
|
518
|
-
* layer prefers these over schema-random generated inputs when a fixture
|
|
519
|
-
* exists for the endpoint's input type.
|
|
520
|
-
*
|
|
521
|
-
* `valid` payloads are used to verify happy-path behavior; `invalid`
|
|
522
|
-
* payloads probe the validator's error responses.
|
|
523
|
-
*/
|
|
524
|
-
declare const registerTestFixture: <TPayload = unknown>(typeKey: string, fixture: TestFixture<TPayload>) => void;
|
|
525
|
-
declare const getTestFixture: (typeKey: string) => TestFixture | undefined;
|
|
526
|
-
/**
|
|
527
|
-
* Register a test reporter. Set `null` to unregister. The runner calls
|
|
528
|
-
* `onResult` per individual result as the run progresses and `onSummary`
|
|
529
|
-
* once at the end. When `webhookUrl` is set, the runner additionally
|
|
530
|
-
* POSTs the JSON-serialised summary to that URL.
|
|
531
|
-
*/
|
|
532
|
-
declare const registerTestReporter: (newReporter: TestReporter | null) => void;
|
|
533
|
-
declare const getTestReporter: () => TestReporter | null;
|
|
534
|
-
declare const resetTestExtensionsForTests: () => void;
|
|
535
|
-
|
|
536
|
-
interface RunRegisteredLayersInput {
|
|
537
|
-
apiMethodMap: ApiMethodMap$1;
|
|
538
|
-
/** Session/bearer token forwarded to each layer's `run({ authToken })`. */
|
|
539
|
-
authToken?: string;
|
|
540
|
-
/**
|
|
541
|
-
* Endpoints to skip — matched against `<page>/<name>` (version-agnostic) and
|
|
542
|
-
* `<page>/<name>/<version>`, same convention as the built-in sweeps.
|
|
543
|
-
*/
|
|
544
|
-
skip?: string[];
|
|
545
|
-
}
|
|
546
|
-
declare const runRegisteredLayers: (input: RunRegisteredLayersInput) => Promise<TestSummary>;
|
|
547
|
-
|
|
548
|
-
declare const LAYER_KEYS: {
|
|
549
|
-
readonly contract: "contract";
|
|
550
|
-
readonly auth: "auth-enforcement";
|
|
551
|
-
readonly rateLimit: "rate-limit";
|
|
552
|
-
readonly csrf: "csrf-enforcement";
|
|
553
|
-
readonly fuzz: "fuzz";
|
|
554
|
-
readonly custom: "custom";
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
export { type ApiMetaEntry, type ApiMetaMap, type ApiMethodMap$1 as ApiMethodMap, type AuthEnforcementCheckInput, type ContractCheckInput, type ContractCheckResult, type CsrfEnforcementCheckInput, type CustomTestCase, type CustomTestResult, type EndpointDescriptor, type FuzzCheckInput, type HttpMethod, LAYER_KEYS, type OpenStreamWatcherInput, type RateLimitCheckInput, type ResetServerStateInput, type ResolveTestBaseUrlOptions, type ResolveTestEnvironmentInput, type RunAllTestsInput, type RunAllTestsSummary, type RunAuthEnforcementTestsInput, type RunContractSummary, type RunContractTestsInput, type RunCsrfEnforcementTestsInput, type RunCustomTestsInput, type RunCustomTestsSummary, type RunFuzzTestsInput, type RunRateLimitTestsInput, type RunRegisteredLayersInput, type SampleSchemaOptions, type StreamChunkFrame, type StreamWatcher, type SyncMethodMap, TEST_DATA_PREFIX, type TestContext, type TestExpect, type TestFixture, type TestLayer, type TestLayerInput, type TestLayerResult, type TestReporter, type TestResult, type TestSummary, createTestDataMarker, discoverCustomTestFiles, getTestFixture, getTestReporter, listTestLayers, logContractResult, logContractSummary, logRunAllSummary, openStreamWatcher, registerTestFixture, registerTestLayer, registerTestReporter, resetServerState, resetTestExtensionsForTests, resolveTestBaseUrl, resolveTestEnvironment, runAllTests, runAuthEnforcementCheck, runAuthEnforcementTests, runContractCheck, runContractTests, runCsrfEnforcementCheck, runCsrfEnforcementTests, runCustomTests, runFuzzCheck, runFuzzTests, runRateLimitCheck, runRateLimitTests, runRegisteredLayers, sampleSchemaInput, walkEndpoints, walkSyncEndpoints };
|
|
1
|
+
export { walkEndpoints, walkSyncEndpoints } from './walkEndpoints.js';
|
|
2
|
+
export { runContractCheck } from './contractCheck.js';
|
|
3
|
+
export { runContractTests } from './runContractTests.js';
|
|
4
|
+
export { runAuthEnforcementCheck } from './authEnforcementCheck.js';
|
|
5
|
+
export { runAuthEnforcementTests } from './runAuthEnforcementTests.js';
|
|
6
|
+
export { runRateLimitCheck } from './rateLimitCheck.js';
|
|
7
|
+
export { runRateLimitTests } from './runRateLimitTests.js';
|
|
8
|
+
export { runCsrfEnforcementCheck } from './csrfEnforcementCheck.js';
|
|
9
|
+
export { runCsrfEnforcementTests } from './runCsrfEnforcementTests.js';
|
|
10
|
+
export { runFuzzCheck } from './fuzzCheck.js';
|
|
11
|
+
export { runFuzzTests } from './runFuzzTests.js';
|
|
12
|
+
export { resetServerState } from './resetServerState.js';
|
|
13
|
+
export { sendProbe, createHttpProbeTransport, defaultProbeTransport } from './probeRequest.js';
|
|
14
|
+
export type { ProbeRequestInput, ProbeResponse, ProbeTransport, ProbeTransportRequest, HttpProbeTransportOptions, } from './probeRequest.js';
|
|
15
|
+
export { createSocketProbeTransport } from './socketProbeTransport.js';
|
|
16
|
+
export type { SocketProbeTransportOptions } from './socketProbeTransport.js';
|
|
17
|
+
export { createSampleInputFor } from './sampleInputFor.js';
|
|
18
|
+
export type { CreateSampleInputForOptions, InputSchemaMap } from './sampleInputFor.js';
|
|
19
|
+
export { resolveTestBaseUrl } from './resolveTestBaseUrl.js';
|
|
20
|
+
export type { ResolveTestBaseUrlOptions } from './resolveTestBaseUrl.js';
|
|
21
|
+
export { resolveTestEnvironment } from './resolveTestEnvironment.js';
|
|
22
|
+
export type { ResolveTestEnvironmentInput } from './resolveTestEnvironment.js';
|
|
23
|
+
export { sampleSchemaInput } from './schemaSampleInput.js';
|
|
24
|
+
export type { SampleSchemaOptions } from './schemaSampleInput.js';
|
|
25
|
+
export { TEST_DATA_PREFIX, createTestDataMarker } from './testDataMarker.js';
|
|
26
|
+
export { logContractResult, logContractSummary } from './reporter.js';
|
|
27
|
+
export type { EndpointDescriptor, HttpMethod, ContractCheckResult, RunContractSummary, SyncMethodMap, SyncMetaMap, SyncMetaEntry, ApiMethodMap, ApiMetaMap, ApiMetaEntry, } from './types.js';
|
|
28
|
+
export type { RunContractTestsInput } from './runContractTests.js';
|
|
29
|
+
export type { ContractCheckInput } from './contractCheck.js';
|
|
30
|
+
export type { AuthEnforcementCheckInput } from './authEnforcementCheck.js';
|
|
31
|
+
export type { RunAuthEnforcementTestsInput } from './runAuthEnforcementTests.js';
|
|
32
|
+
export type { RateLimitCheckInput } from './rateLimitCheck.js';
|
|
33
|
+
export type { RunRateLimitTestsInput } from './runRateLimitTests.js';
|
|
34
|
+
export type { CsrfEnforcementCheckInput } from './csrfEnforcementCheck.js';
|
|
35
|
+
export type { RunCsrfEnforcementTestsInput } from './runCsrfEnforcementTests.js';
|
|
36
|
+
export type { FuzzCheckInput } from './fuzzCheck.js';
|
|
37
|
+
export type { RunFuzzTestsInput } from './runFuzzTests.js';
|
|
38
|
+
export type { ResetServerStateInput } from './resetServerState.js';
|
|
39
|
+
export { runCustomTests, discoverCustomTestFiles, } from './customTests.js';
|
|
40
|
+
export type { CustomTestCase, CallSyncOptions, TestContext, TestExpect, CustomTestResult, RunCustomTestsInput, RunCustomTestsSummary, } from './customTests.js';
|
|
41
|
+
export { openStreamWatcher } from './streamWatcher.js';
|
|
42
|
+
export type { StreamWatcher, StreamChunkFrame, OpenStreamWatcherInput, } from './streamWatcher.js';
|
|
43
|
+
export { runAllTests, logRunAllSummary } from './runAllTests.js';
|
|
44
|
+
export type { RunAllTestsInput, RunAllTestsSummary } from './runAllTests.js';
|
|
45
|
+
export { registerTestLayer, listTestLayers, registerTestFixture, getTestFixture, registerTestReporter, getTestReporter, resetTestExtensionsForTests, } from './extensionRegistry.js';
|
|
46
|
+
export { runRegisteredLayers } from './runRegisteredLayers.js';
|
|
47
|
+
export type { RunRegisteredLayersInput } from './runRegisteredLayers.js';
|
|
48
|
+
export { LAYER_KEYS } from './testLayerHelpers.js';
|
|
49
|
+
export type { TestLayer, TestLayerInput, TestLayerResult, TestFixture, TestResult, TestSummary, TestReporter, } from './extensionRegistry.js';
|