@stratal/testing 0.0.27 → 0.1.1

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 (54) hide show
  1. package/CHANGELOG.md +570 -0
  2. package/README.md +137 -36
  3. package/dist/database/index.d.mts +2 -2
  4. package/dist/database/index.mjs +2 -2
  5. package/dist/database-Rojs69r3.mjs +453 -0
  6. package/dist/database-Rojs69r3.mjs.map +1 -0
  7. package/dist/{decorate-B7nr7eBl.mjs → decorate-RQD1h28J.mjs} +1 -1
  8. package/dist/feature-flags/index.mjs +1 -1
  9. package/dist/{feature-flags-BiLhfSGh.mjs → feature-flags-CZ1a4M2g.mjs} +2 -2
  10. package/dist/{feature-flags-BiLhfSGh.mjs.map → feature-flags-CZ1a4M2g.mjs.map} +1 -1
  11. package/dist/index-B8Mw1Dxk.d.mts +175 -0
  12. package/dist/index-B8Mw1Dxk.d.mts.map +1 -0
  13. package/dist/{index-CrHzUDKX.d.mts → index-D7FM6EKp.d.mts} +21 -3
  14. package/dist/index-D7FM6EKp.d.mts.map +1 -0
  15. package/dist/index-qgWNJRdC.d.mts.map +1 -1
  16. package/dist/index.d.mts +105 -46
  17. package/dist/index.d.mts.map +1 -1
  18. package/dist/index.mjs +218 -108
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/mocks/cloudflare-workers.d.mts +24 -0
  21. package/dist/mocks/cloudflare-workers.d.mts.map +1 -0
  22. package/dist/mocks/cloudflare-workers.mjs +28 -0
  23. package/dist/mocks/cloudflare-workers.mjs.map +1 -0
  24. package/dist/mocks/index.d.mts +2 -2
  25. package/dist/mocks/index.mjs +2 -2
  26. package/dist/mocks/noop-rate-limiter-store.d.mts +1 -3
  27. package/dist/mocks/noop-rate-limiter-store.d.mts.map +1 -1
  28. package/dist/mocks/zenstack-language.d.mts +26 -29
  29. package/dist/mocks/zenstack-language.d.mts.map +1 -1
  30. package/dist/mocks/zenstack-language.mjs +1 -1
  31. package/dist/mocks/zenstack-language.mjs.map +1 -1
  32. package/dist/storage/index.d.mts +1 -1
  33. package/dist/storage/index.mjs +1 -1
  34. package/dist/{storage-DhoxWqyF.mjs → storage-BiGamMA8.mjs} +73 -6
  35. package/dist/storage-BiGamMA8.mjs.map +1 -0
  36. package/dist/test-worker-exports-dCRARYEc.d.mts +144 -0
  37. package/dist/test-worker-exports-dCRARYEc.d.mts.map +1 -0
  38. package/dist/test-workers-cache-D02Pt_dE.mjs +183 -0
  39. package/dist/test-workers-cache-D02Pt_dE.mjs.map +1 -0
  40. package/dist/vitest-plugin/index.d.mts +14 -28
  41. package/dist/vitest-plugin/index.d.mts.map +1 -1
  42. package/dist/vitest-plugin/index.mjs +32 -20
  43. package/dist/vitest-plugin/index.mjs.map +1 -1
  44. package/package.json +30 -21
  45. package/dist/database-B02eYKhE.mjs +0 -334
  46. package/dist/database-B02eYKhE.mjs.map +0 -1
  47. package/dist/index-BIr5nLof.d.mts +0 -122
  48. package/dist/index-BIr5nLof.d.mts.map +0 -1
  49. package/dist/index-CrHzUDKX.d.mts.map +0 -1
  50. package/dist/storage-DhoxWqyF.mjs.map +0 -1
  51. package/dist/test-email-provider-B7cjj97-.d.mts +0 -21
  52. package/dist/test-email-provider-B7cjj97-.d.mts.map +0 -1
  53. package/dist/test-email-provider-Dr-nhE0x.mjs +0 -34
  54. package/dist/test-email-provider-Dr-nhE0x.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["http","HttpResponse"],"sources":["../src/core/override/provider-override-builder.ts","../src/core/http/locale-helper.ts","../src/auth/acting-as.ts","../src/core/http/path-utils.ts","../src/core/http/test-response.ts","../src/core/http/test-http-request.ts","../src/core/http/test-http-client.ts","../src/core/quarry/test-command-result.ts","../src/core/quarry/test-command-request.ts","../src/core/sse/test-sse-connection.ts","../src/core/sse/test-sse-request.ts","../src/core/ws/test-ws-connection.ts","../src/core/ws/test-ws-request.ts","../src/core/testing-module.ts","../src/core/testing-module-builder.ts","../src/core/test.ts","../src/core/http/mock-fetch.ts","../src/errors/test-error.ts","../src/errors/setup-error.ts"],"sourcesContent":["import { type Container } from 'stratal/di'\nimport { type InjectionToken } from 'stratal/module'\nimport type { TestingModuleBuilder } from '../testing-module-builder'\n\n/**\n * Provider override configuration\n */\nexport interface ProviderOverrideConfig<T = unknown> {\n token: InjectionToken<T>\n type: 'value' | 'class' | 'factory' | 'existing'\n implementation: T | (new (...args: unknown[]) => T) | ((container: Container) => T) | InjectionToken<T>\n}\n\n/**\n * Fluent builder for provider overrides\n *\n * Provides a NestJS-style API for overriding providers in tests.\n *\n * @example\n * ```typescript\n * const module = await Test.createTestingModule({\n * imports: [RegistrationModule],\n * })\n * .overrideProvider(EMAIL_TOKENS.EmailService)\n * .useValue(mockEmailService)\n * .compile()\n * ```\n */\nexport class ProviderOverrideBuilder<T> {\n constructor(\n private readonly parent: TestingModuleBuilder,\n private readonly token: InjectionToken<T>\n ) { }\n\n /**\n * Use a static value as the provider\n *\n * The value will be registered directly in the container.\n *\n * @param value - The value to use as the provider\n * @returns The parent TestingModuleBuilder for chaining\n */\n useValue(value: T): TestingModuleBuilder {\n return this.parent.addProviderOverride({\n token: this.token,\n type: 'value',\n implementation: value,\n })\n }\n\n /**\n * Use a class as the provider\n *\n * The class will be registered as a singleton.\n *\n * @param cls - The class constructor to use as the provider\n * @returns The parent TestingModuleBuilder for chaining\n */\n useClass(cls: new (...args: unknown[]) => T): TestingModuleBuilder {\n return this.parent.addProviderOverride({\n token: this.token,\n type: 'class',\n implementation: cls,\n })\n }\n\n /**\n * Use a factory function as the provider\n *\n * The factory receives the container and should return the provider instance.\n *\n * @param factory - Factory function that creates the provider\n * @returns The parent TestingModuleBuilder for chaining\n */\n useFactory(factory: (container: Container) => T): TestingModuleBuilder {\n return this.parent.addProviderOverride({\n token: this.token,\n type: 'factory',\n implementation: factory,\n })\n }\n\n /**\n * Use an existing token as the provider (alias)\n *\n * The override token will resolve to the same instance as the target token.\n *\n * @param existingToken - The token to alias\n * @returns The parent TestingModuleBuilder for chaining\n *\n * @example\n * ```typescript\n * const module = await Test.createTestingModule({\n * imports: [MyModule],\n * })\n * .overrideProvider(ABSTRACT_TOKEN)\n * .useExisting(ConcreteService)\n * .compile()\n * ```\n */\n useExisting(existingToken: InjectionToken<T>): TestingModuleBuilder {\n return this.parent.addProviderOverride({\n token: this.token,\n type: 'existing',\n implementation: existingToken,\n })\n }\n}\n","import type { DetectionStrategy, I18nModuleOptions } from 'stratal/i18n'\nimport { I18N_TOKENS } from 'stratal/i18n'\nimport type { TestingModule } from '../testing-module'\n\n/**\n * Resolve the configured detection strategy from the testing module's DI container.\n * Falls back to 'cookie' if I18n is not configured.\n */\nexport function resolveLocaleStrategy(module: TestingModule): DetectionStrategy {\n try {\n const options = module.get<I18nModuleOptions>(I18N_TOKENS.Options)\n const detection = options.detection\n if (detection && 'strategy' in detection && detection.strategy) {\n return detection.strategy\n }\n return 'cookie'\n } catch {\n return 'cookie'\n }\n}\n\n/**\n * Apply locale to request headers based on detection strategy.\n */\nexport function applyLocaleToHeaders(\n headers: Headers,\n locale: string,\n strategy: DetectionStrategy,\n): void {\n switch (strategy) {\n case 'cookie':\n headers.set('Cookie', `locale=${locale}`)\n break\n case 'header':\n headers.set('Accept-Language', locale)\n break\n }\n}\n\n/**\n * Apply locale to URL based on detection strategy.\n */\nexport function applyLocaleToUrl(\n url: URL,\n locale: string,\n strategy: DetectionStrategy,\n): void {\n if (strategy === 'querystring') {\n url.searchParams.set('locale', locale)\n }\n}\n","import { runWithEndpointContext, type AuthEndpointContext } from '@better-auth/core/context'\nimport type { AuthService } from '@stratal/framework/auth'\nimport { type GenericEndpointContext } from 'better-auth'\nimport { setSessionCookie } from 'better-auth/cookies'\nimport { convertSetCookieToCookie } from 'better-auth/test'\n\nasync function makeSignature(value: string, secret: string): Promise<string> {\n const algorithm = { name: 'HMAC', hash: 'SHA-256' }\n const secretBuf = new TextEncoder().encode(secret)\n const key = await crypto.subtle.importKey('raw', secretBuf, algorithm, false, ['sign'])\n const signature = await crypto.subtle.sign(algorithm.name, key, new TextEncoder().encode(value))\n return btoa(String.fromCharCode(...new Uint8Array(signature)))\n}\n\nfunction buildCookieString(name: string, value: string, options: Record<string, unknown> = {}): string {\n const encodedValue = encodeURIComponent(value)\n let str = `${name}=${encodedValue}`\n if (options.path) str += `; Path=${options.path as string}`\n if (options.httpOnly) str += '; HttpOnly'\n if (options.secure) str += '; Secure'\n if (options.sameSite) str += `; SameSite=${options.sameSite as string}`\n if (options.maxAge !== undefined) str += `; Max-Age=${Math.floor(options.maxAge as number)}`\n return str\n}\n\n/**\n * ActingAs\n *\n * Creates authentication sessions for testing.\n * Uses Better Auth's internalAdapter to create real database sessions.\n *\n * @example\n * ```typescript\n * const actingAs = new ActingAs(authService)\n * const headers = await actingAs.createSessionForUser({ id: 'user-123' })\n * ```\n */\nexport class ActingAs {\n constructor(private readonly authService: AuthService) { }\n\n async createSessionForUser(user: { id: string }): Promise<Headers> {\n const auth = this.authService.auth\n const ctx = await auth.$context\n\n const secret = ctx.secret\n\n // Mirror production: session writes always happen inside a Better Auth\n // endpoint, so database hooks receive the endpoint context (e.g. for\n // internalAdapter lookups). The cast bridges better-auth's own generic\n // variance — `$context` is typed with the instance's concrete plugin\n // registry while AuthEndpointContext expects the default generics (same\n // impedance as the GenericEndpointContext cast below).\n const session = await runWithEndpointContext(\n { context: ctx } as unknown as AuthEndpointContext,\n () =>\n ctx.internalAdapter.createSession(\n user.id,\n undefined,\n { ipAddress: '127.0.0.1', userAgent: 'test-client' }\n )\n )\n\n const dbUser = await ctx.internalAdapter.findUserById(user.id)\n if (!dbUser) {\n throw new Error(`User not found: ${user.id}`)\n }\n\n const responseHeaders = new Headers()\n const mockCtx = {\n context: ctx,\n getSignedCookie: () => null,\n setSignedCookie: async (name: string, value: string, _secret: string, options: Record<string, unknown> = {}) => {\n const signature = await makeSignature(value, secret)\n const signedValue = `${value}.${signature}`\n responseHeaders.append('Set-Cookie', buildCookieString(name, signedValue, options))\n },\n setCookie: (name: string, value: string, options: Record<string, unknown> = {}) => {\n responseHeaders.append('Set-Cookie', buildCookieString(name, value, options))\n },\n }\n\n await setSessionCookie(mockCtx as unknown as GenericEndpointContext, { session, user: dbUser }, false)\n return convertSetCookieToCookie(responseHeaders)\n }\n}\n","/**\n * Get value at dot-notation path.\n */\nexport function getValueAtPath(obj: unknown, path: string): unknown {\n const parts = path.split('.')\n let current: unknown = obj\n\n for (const part of parts) {\n if (current === null || current === undefined) {\n return undefined\n }\n current = (current as Record<string, unknown>)[part]\n }\n\n return current\n}\n\n/**\n * Check if a path exists in the object (even if value is null/undefined).\n */\nexport function hasValueAtPath(obj: unknown, path: string): boolean {\n const parts = path.split('.')\n let current: unknown = obj\n\n for (const part of parts) {\n if (current === null || current === undefined) {\n return false\n }\n\n if (typeof current !== 'object') {\n return false\n }\n\n const record = current as Record<string, unknown>\n\n if (!(part in record)) {\n return false\n }\n\n current = record[part]\n }\n\n return true\n}\n","import { Macroable } from 'stratal/macroable'\nimport { expect } from 'vitest'\nimport { getValueAtPath, hasValueAtPath } from './path-utils'\n\n/**\n * TestResponse\n *\n * Wrapper around Response with assertion methods.\n *\n * @example\n * ```typescript\n * response\n * .assertOk()\n * .assertStatus(200)\n * .assertJsonPath('data.id', userId)\n * ```\n */\nexport class TestResponse extends Macroable {\n private jsonData: unknown = null\n private textData: string | null = null\n\n constructor(private readonly response: Response) {\n super()\n }\n\n /**\n * Get the raw Response object.\n */\n get raw(): Response {\n return this.response\n }\n\n /**\n * Get the response status code.\n */\n get status(): number {\n return this.response.status\n }\n\n /**\n * Get response headers.\n */\n get headers(): Headers {\n return this.response.headers\n }\n\n /**\n * Get the response body as JSON.\n */\n async json<T = unknown>(): Promise<T> {\n if (this.jsonData === null) {\n this.jsonData = await this.response.clone().json()\n }\n return this.jsonData as T\n }\n\n /**\n * Get the response body as text.\n */\n async text(): Promise<string> {\n this.textData ??= await this.response.clone().text()\n return this.textData\n }\n\n // ============================================================\n // Status Assertions\n // ============================================================\n\n /**\n * Assert response status is 200 OK.\n */\n assertOk(): this {\n return this.assertStatus(200)\n }\n\n /**\n * Assert response status is 201 Created.\n */\n assertCreated(): this {\n return this.assertStatus(201)\n }\n\n /**\n * Assert response status is 204 No Content.\n */\n assertNoContent(): this {\n return this.assertStatus(204)\n }\n\n /**\n * Assert response status is 400 Bad Request.\n */\n assertBadRequest(): this {\n return this.assertStatus(400)\n }\n\n /**\n * Assert response status is 401 Unauthorized.\n */\n assertUnauthorized(): this {\n return this.assertStatus(401)\n }\n\n /**\n * Assert response status is 403 Forbidden.\n */\n assertForbidden(): this {\n return this.assertStatus(403)\n }\n\n /**\n * Assert response status is 404 Not Found.\n */\n assertNotFound(): this {\n return this.assertStatus(404)\n }\n\n /**\n * Assert response status is 422 Unprocessable Entity.\n */\n assertUnprocessable(): this {\n return this.assertStatus(422)\n }\n\n /**\n * Assert response status is 500 Internal Server Error.\n */\n assertServerError(): this {\n return this.assertStatus(500)\n }\n\n /**\n * Assert response has the given status code.\n */\n assertStatus(expected: number): this {\n expect(\n this.response.status,\n `Expected status ${expected}, got ${this.response.status}`\n ).toBe(expected)\n return this\n }\n\n /**\n * Assert response status is in the 2xx success range.\n */\n assertSuccessful(): this {\n expect(\n this.response.status >= 200 && this.response.status < 300,\n `Expected successful status (2xx), got ${this.response.status}`\n ).toBe(true)\n return this\n }\n\n // ============================================================\n // JSON Assertions\n // ============================================================\n\n /**\n * Assert JSON response contains the given data.\n */\n async assertJson(expected: Record<string, unknown>): Promise<this> {\n const actual = await this.json<Record<string, unknown>>()\n\n for (const [key, value] of Object.entries(expected)) {\n expect(\n actual[key],\n `Expected JSON key \"${key}\" to be ${JSON.stringify(value)}, got ${JSON.stringify(actual[key])}`\n ).toStrictEqual(value)\n }\n\n return this\n }\n\n /**\n * Assert JSON response has value at the given path.\n *\n * @param path - Dot-notation path (e.g., 'data.user.id')\n * @param expected - Expected value at path\n */\n async assertJsonPath(path: string, expected: unknown): Promise<this> {\n const json = await this.json()\n const actual = getValueAtPath(json, path)\n\n expect(\n actual,\n `Expected JSON path \"${path}\" to be ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`\n ).toStrictEqual(expected)\n\n return this\n }\n\n /**\n * Assert JSON response structure matches the given schema.\n */\n async assertJsonStructure(structure: string[]): Promise<this> {\n const json = await this.json<Record<string, unknown>>()\n\n for (const key of structure) {\n expect(\n key in json,\n `Expected JSON to have key \"${key}\", got keys: ${JSON.stringify(Object.keys(json))}`\n ).toBe(true)\n }\n\n return this\n }\n\n /**\n * Assert a JSON path exists (value can be anything, including null).\n *\n * @param path - Dot-notation path (e.g., 'data.user.id')\n */\n async assertJsonPathExists(path: string): Promise<this> {\n const json = await this.json()\n const exists = hasValueAtPath(json, path)\n\n expect(\n exists,\n `Expected JSON path \"${path}\" to exist`\n ).toBe(true)\n\n return this\n }\n\n /**\n * Assert a JSON path does not exist.\n *\n * @param path - Dot-notation path (e.g., 'data.user.deletedAt')\n */\n async assertJsonPathMissing(path: string): Promise<this> {\n const json = await this.json()\n const exists = hasValueAtPath(json, path)\n\n expect(\n exists,\n `Expected JSON path \"${path}\" to not exist`\n ).toBe(false)\n\n return this\n }\n\n /**\n * Assert JSON value at path matches a custom predicate.\n *\n * @param path - Dot-notation path (e.g., 'data.items')\n * @param matcher - Predicate function to validate the value\n */\n async assertJsonPathMatches(\n path: string,\n matcher: (value: unknown) => boolean\n ): Promise<this> {\n const json = await this.json()\n const value = getValueAtPath(json, path)\n\n expect(\n matcher(value),\n `Expected JSON path \"${path}\" to match predicate, got ${JSON.stringify(value)}`\n ).toBe(true)\n\n return this\n }\n\n /**\n * Assert string value at path contains a substring.\n *\n * @param path - Dot-notation path (e.g., 'data.message')\n * @param substring - Substring to search for\n */\n async assertJsonPathContains(path: string, substring: string): Promise<this> {\n const json = await this.json()\n const value = getValueAtPath(json, path)\n\n expect(\n typeof value === 'string',\n `Expected JSON path \"${path}\" to be a string, got ${typeof value}`\n ).toBe(true)\n\n expect(\n (value as string).includes(substring),\n `Expected JSON path \"${path}\" to contain \"${substring}\", got \"${String(value)}\"`\n ).toBe(true)\n\n return this\n }\n\n /**\n * Assert array value at path includes a specific item.\n *\n * @param path - Dot-notation path (e.g., 'data.tags')\n * @param item - Item to search for in the array\n */\n async assertJsonPathIncludes(path: string, item: unknown): Promise<this> {\n const json = await this.json()\n const value = getValueAtPath(json, path)\n\n expect(\n Array.isArray(value),\n `Expected JSON path \"${path}\" to be an array, got ${typeof value}`\n ).toBe(true)\n\n expect(\n (value as unknown[]).includes(item),\n `Expected JSON path \"${path}\" to include ${JSON.stringify(item)}`\n ).toBe(true)\n\n return this\n }\n\n /**\n * Assert array length at path equals the expected count.\n *\n * @param path - Dot-notation path (e.g., 'data.items')\n * @param count - Expected array length\n */\n async assertJsonPathCount(path: string, count: number): Promise<this> {\n const json = await this.json()\n const value = getValueAtPath(json, path)\n\n expect(\n Array.isArray(value),\n `Expected JSON path \"${path}\" to be an array, got ${typeof value}`\n ).toBe(true)\n\n expect(\n (value as unknown[]).length,\n `Expected JSON path \"${path}\" to have ${count} items, got ${(value as unknown[]).length}`\n ).toBe(count)\n\n return this\n }\n\n /**\n * Assert multiple JSON paths at once (batch assertion).\n *\n * @param expectations - Object mapping paths to expected values\n */\n async assertJsonPaths(expectations: Record<string, unknown>): Promise<this> {\n const json = await this.json()\n\n for (const [path, expected] of Object.entries(expectations)) {\n const actual = getValueAtPath(json, path)\n expect(\n actual,\n `Expected JSON path \"${path}\" to be ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`\n ).toStrictEqual(expected)\n }\n\n return this\n }\n\n // ============================================================\n // Header Assertions\n // ============================================================\n\n /**\n * Assert response has the given header.\n */\n assertHeader(name: string, expected?: string): this {\n const actual = this.response.headers.get(name)\n\n expect(\n actual !== null,\n `Expected header \"${name}\" to be present`\n ).toBe(true)\n\n if (expected !== undefined) {\n expect(\n actual,\n `Expected header \"${name}\" to be \"${expected}\", got \"${actual}\"`\n ).toBe(expected)\n }\n\n return this\n }\n\n /**\n * Assert response does not have the given header.\n */\n assertHeaderMissing(name: string): this {\n const actual = this.response.headers.get(name)\n\n expect(\n actual,\n `Expected header \"${name}\" to be absent, but got \"${actual}\"`\n ).toBeNull()\n\n return this\n }\n\n}\n","import type { AuthService } from '@stratal/framework/auth'\nimport { AUTH_SERVICE } from '@stratal/framework/auth'\nimport type { DetectionStrategy } from 'stratal/i18n'\nimport { Macroable } from 'stratal/macroable'\nimport { ActingAs } from '../../auth'\nimport type { TestingModule } from '../testing-module'\nimport { applyLocaleToHeaders, applyLocaleToUrl, resolveLocaleStrategy } from './locale-helper'\nimport { TestResponse } from './test-response'\n\n/**\n * TestHttpRequest\n *\n * Request builder with fluent API for configuring test HTTP requests.\n *\n * @example\n * ```typescript\n * const response = await module.http\n * .post('/api/v1/register')\n * .withBody({ name: 'Test School' })\n * .withHeaders({ 'X-Custom': 'value' })\n * .send()\n * ```\n *\n * @example Authenticated request\n * ```typescript\n * const response = await module.http\n * .get('/api/v1/profile')\n * .actingAs({ id: user.id })\n * .send()\n * ```\n */\nexport class TestHttpRequest extends Macroable {\n\tprotected body: unknown = null\n\tprotected requestHeaders: Headers\n\tprotected actingAsUser: { id: string } | null = null\n\tprotected authResolver: ((module: TestingModule, user: { id: string }) => Promise<Headers>) | null = null\n\tprotected localeConfig: { locale: string; strategy: DetectionStrategy } | null\n\n\tconstructor(\n\t\tprotected readonly method: string,\n\t\tprotected readonly path: string,\n\t\theaders: Headers,\n\t\tprotected readonly module: TestingModule,\n\t\tprotected readonly host: string | null = null,\n\t\tlocaleConfig: { locale: string; strategy: DetectionStrategy } | null = null,\n\t) {\n\t\tsuper()\n\t\tthis.requestHeaders = new Headers(headers)\n\t\tthis.localeConfig = localeConfig\n\t}\n\n\t/**\n\t * Set the request body\n\t */\n\twithBody(data: unknown): this {\n\t\tthis.body = data\n\t\treturn this\n\t}\n\n\t/**\n\t * Add headers to the request\n\t */\n\twithHeaders(headers: Record<string, string>): this {\n\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\tthis.requestHeaders.set(key, value)\n\t\t}\n\t\treturn this\n\t}\n\n\t/**\n\t * Set the locale for this request.\n\t * If strategy is not provided, resolves from the module's I18n configuration.\n\t *\n\t * @param locale - Locale code (e.g., 'en', 'fr')\n\t * @param strategy - Detection strategy override\n\t */\n\twithLocale(locale: string, strategy?: DetectionStrategy): this {\n\t\tconst resolved = strategy ?? resolveLocaleStrategy(this.module)\n\t\tthis.localeConfig = { locale, strategy: resolved }\n\t\tapplyLocaleToHeaders(this.requestHeaders, locale, resolved)\n\t\treturn this\n\t}\n\n\t/**\n\t * Set Content-Type to application/json\n\t */\n\tasJson(): this {\n\t\tthis.requestHeaders.set('Content-Type', 'application/json')\n\t\treturn this\n\t}\n\n\t/**\n\t * Authenticate the request as a specific user\n\t */\n\tactingAs(user: { id: string }): this {\n\t\tthis.actingAsUser = user\n\t\tthis.authResolver = null\n\t\treturn this\n\t}\n\n\t/**\n\t * Send the request and return response\n\t *\n\t * Calls module.fetch() - NOT SELF.fetch()\n\t */\n\tasync send(): Promise<TestResponse> {\n\t\tawait this.applyAuthentication()\n\n\t\t// Auto-set Content-Type for body\n\t\tif (this.body && !this.requestHeaders.has('Content-Type')) {\n\t\t\tthis.requestHeaders.set('Content-Type', 'application/json')\n\t\t}\n\n\t\t// Build request\n\t\tconst url = new URL(this.path, `http://${this.host ?? 'localhost'}`)\n\n\t\t// Apply locale to URL for querystring strategy\n\t\tif (this.localeConfig) {\n\t\t\tapplyLocaleToUrl(url, this.localeConfig.locale, this.localeConfig.strategy)\n\t\t}\n\n\t\tconst request = new Request(url.toString(), {\n\t\t\tmethod: this.method,\n\t\t\theaders: this.requestHeaders,\n\t\t\tbody: this.body ? JSON.stringify(this.body) : null,\n\t\t})\n\n\t\t// Call module.fetch() - NO SELF.fetch()\n\t\tconst response = await this.module.fetch(request)\n\t\treturn new TestResponse(response)\n\t}\n\n\tprotected async applyAuthentication(): Promise<void> {\n\t\tif (!this.actingAsUser) return\n\n\t\tif (this.authResolver) {\n\t\t\tconst headers = await this.authResolver(this.module, this.actingAsUser)\n\t\t\tfor (const [key, value] of headers.entries()) {\n\t\t\t\tthis.requestHeaders.set(key, value)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tawait this.module.runInRequestScope(async () => {\n\t\t\tconst authService = this.module.get<AuthService>(AUTH_SERVICE)\n\t\t\tconst actingAs = new ActingAs(authService)\n\t\t\tconst authHeaders = await actingAs.createSessionForUser(this.actingAsUser!)\n\n\t\t\tfor (const [key, value] of authHeaders.entries()) {\n\t\t\t\tthis.requestHeaders.set(key, value)\n\t\t\t}\n\t\t})\n\t}\n}\n","import type { DetectionStrategy } from 'stratal/i18n'\nimport type { TestingModule } from '../testing-module'\nimport { applyLocaleToHeaders, resolveLocaleStrategy } from './locale-helper'\nimport { TestHttpRequest } from './test-http-request'\n\n/**\n * TestHttpClient\n *\n * Fluent HTTP client for making test requests.\n *\n * @example\n * ```typescript\n * const response = await module.http\n * .forHost('example.com')\n * .post('/api/v1/users')\n * .withBody({ name: 'Test' })\n * .send()\n *\n * response.assertCreated()\n * ```\n */\nexport class TestHttpClient {\n private defaultHeaders: Headers\n private host: string | null\n private localeConfig: { locale: string; strategy: DetectionStrategy } | null\n\n constructor(\n private readonly module: TestingModule,\n host: string | null = null,\n headers: Headers = new Headers(),\n localeConfig: { locale: string; strategy: DetectionStrategy } | null = null,\n ) {\n this.host = host\n this.defaultHeaders = headers\n this.localeConfig = localeConfig\n }\n\n /**\n * Set the host for the request (returns a new client).\n * Also sets the Host header to ensure domain routing works\n * even when the runtime reads the header instead of the URL host.\n */\n forHost(host: string): TestHttpClient {\n const newHeaders = new Headers(this.defaultHeaders)\n newHeaders.set('Host', host)\n return new TestHttpClient(this.module, host, newHeaders, this.localeConfig)\n }\n\n /**\n * Set default headers for all requests (returns a new client)\n */\n withHeaders(headers: Record<string, string>): TestHttpClient {\n const newHeaders = new Headers(this.defaultHeaders)\n for (const [key, value] of Object.entries(headers)) {\n newHeaders.set(key, value)\n }\n return new TestHttpClient(this.module, this.host, newHeaders, this.localeConfig)\n }\n\n /**\n * Set the locale for all requests from this client (returns a new client).\n * If strategy is not provided, resolves from the module's I18n configuration.\n *\n * @param locale - Locale code (e.g., 'en', 'fr')\n * @param strategy - Detection strategy override\n */\n withLocale(locale: string, strategy?: DetectionStrategy): TestHttpClient {\n const resolved = strategy ?? resolveLocaleStrategy(this.module)\n const newHeaders = new Headers(this.defaultHeaders)\n applyLocaleToHeaders(newHeaders, locale, resolved)\n return new TestHttpClient(this.module, this.host, newHeaders, { locale, strategy: resolved })\n }\n\n /**\n * Create a GET request\n */\n get(path: string): TestHttpRequest {\n return this.createRequest('GET', path)\n }\n\n /**\n * Create a POST request\n */\n post(path: string): TestHttpRequest {\n return this.createRequest('POST', path)\n }\n\n /**\n * Create a PUT request\n */\n put(path: string): TestHttpRequest {\n return this.createRequest('PUT', path)\n }\n\n /**\n * Create a PATCH request\n */\n patch(path: string): TestHttpRequest {\n return this.createRequest('PATCH', path)\n }\n\n /**\n * Create a DELETE request\n */\n delete(path: string): TestHttpRequest {\n return this.createRequest('DELETE', path)\n }\n\n private createRequest(method: string, path: string): TestHttpRequest {\n return new TestHttpRequest(method, path, this.defaultHeaders, this.module, this.host, this.localeConfig)\n }\n}\n","import type { CommandResult } from 'stratal/quarry'\nimport { expect } from 'vitest'\n\n/**\n * Fluent assertion wrapper for command results.\n *\n * @example\n * ```typescript\n * const result = await module\n * .quarry('users:create')\n * .withInput({ email: 'test@example.com' })\n * .run()\n *\n * result.assertSuccessful()\n * result.assertOutputContains('User created')\n * ```\n */\nexport class TestCommandResult {\n constructor(private readonly result: CommandResult) {}\n\n get exitCode(): number {\n return this.result.exitCode\n }\n\n get output(): string[] {\n return this.result.output\n }\n\n get errors(): string[] {\n return this.result.errors\n }\n\n assertSuccessful(): this {\n expect(this.result.exitCode, `Expected exit code 0, got ${this.result.exitCode}. Errors: ${this.result.errors.join(', ')}`).toBe(0)\n expect(this.result.errors, 'Expected no errors').toHaveLength(0)\n return this\n }\n\n assertFailed(exitCode?: number): this {\n if (exitCode !== undefined) {\n expect(this.result.exitCode, `Expected exit code ${exitCode}, got ${this.result.exitCode}`).toBe(exitCode)\n } else {\n expect(this.result.exitCode, 'Expected non-zero exit code').not.toBe(0)\n }\n return this\n }\n\n assertExitCode(code: number): this {\n expect(this.result.exitCode, `Expected exit code ${code}, got ${this.result.exitCode}`).toBe(code)\n return this\n }\n\n assertOutputContains(text: string): this {\n const joined = this.result.output.join('\\n')\n expect(joined, `Expected output to contain \"${text}\"`).toContain(text)\n return this\n }\n\n assertOutputMissing(text: string): this {\n const joined = this.result.output.join('\\n')\n expect(joined, `Expected output NOT to contain \"${text}\"`).not.toContain(text)\n return this\n }\n\n assertErrorContains(text: string): this {\n const joined = this.result.errors.join('\\n')\n expect(joined, `Expected errors to contain \"${text}\"`).toContain(text)\n return this\n }\n\n assertErrorMissing(text: string): this {\n const joined = this.result.errors.join('\\n')\n expect(joined, `Expected errors NOT to contain \"${text}\"`).not.toContain(text)\n return this\n }\n}\n","import type { CommandInput } from 'stratal/quarry'\nimport type { TestingModule } from '../testing-module'\nimport { TestCommandResult } from './test-command-result'\n\n/**\n * Fluent builder for testing Quarry commands.\n *\n * @example\n * ```typescript\n * const result = await module\n * .quarry('users:create')\n * .withInput({ email: 'test@example.com', admin: true })\n * .run()\n *\n * result.assertSuccessful()\n * result.assertOutputContains('User created')\n * ```\n */\nexport class TestCommandRequest {\n private _input: CommandInput = {}\n\n constructor(\n private readonly commandName: string,\n private readonly module: TestingModule,\n ) {}\n\n /**\n * Set the flat input for the command.\n */\n withInput(input: CommandInput): this {\n this._input = { ...input }\n return this\n }\n\n /**\n * Execute the command and return a TestCommandResult for assertions.\n */\n async run(): Promise<TestCommandResult> {\n const result = await this.module.application.handleCommand(this.commandName, this._input)\n return new TestCommandResult(result)\n }\n}\n","import { expect } from \"vitest\"\n\n/**\n * Represents a parsed SSE event\n */\nexport interface TestSseEvent {\n\tdata: string\n\tevent?: string\n\tid?: string\n\tretry?: number\n}\n\n/**\n * TestSseConnection\n *\n * Live SSE connection wrapper with assertion helpers for testing.\n *\n * @example\n * ```typescript\n * const sse = await module.sse('/streaming/sse').connect()\n * await sse.assertEvent({ event: 'message', data: 'hello', id: '1' })\n * await sse.waitForEnd()\n * ```\n */\nexport class TestSseConnection {\n\tprivate readonly eventQueue: TestSseEvent[] = []\n\tprivate eventWaiters: ((event: TestSseEvent) => void)[] = []\n\tprivate streamEnded = false\n\tprivate endWaiters: (() => void)[] = []\n\n\tconstructor(private readonly response: Response) {\n\t\tthis.startReading()\n\t}\n\n\t/**\n\t * Wait for the next SSE event\n\t */\n\tasync waitForEvent(timeout = 5000): Promise<TestSseEvent> {\n\t\tif (this.eventQueue.length > 0) {\n\t\t\treturn this.eventQueue.shift()!\n\t\t}\n\n\t\tif (this.streamEnded) {\n\t\t\tthrow new Error('SSE: stream has ended, no more events')\n\t\t}\n\n\t\treturn new Promise<TestSseEvent>((resolve, reject) => {\n\t\t\tconst waiter = (event: TestSseEvent) => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tresolve(event)\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst index = this.eventWaiters.indexOf(waiter)\n\t\t\t\tif (index !== -1) this.eventWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`SSE: no event received within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\tthis.eventWaiters.push(waiter)\n\t\t})\n\t}\n\n\t/**\n\t * Wait for the stream to end\n\t */\n\tasync waitForEnd(timeout = 5000): Promise<void> {\n\t\tif (this.streamEnded) return\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst waiter = () => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tresolve()\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst index = this.endWaiters.indexOf(waiter)\n\t\t\t\tif (index !== -1) this.endWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`SSE: stream did not end within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\tthis.endWaiters.push(waiter)\n\t\t})\n\t}\n\n\t/**\n\t * Collect all remaining events until the stream ends\n\t */\n\tasync collectEvents(timeout = 5000): Promise<TestSseEvent[]> {\n\t\tconst events: TestSseEvent[] = []\n\n\t\tif (this.streamEnded) {\n\t\t\treturn [...this.eventQueue.splice(0)]\n\t\t}\n\n\t\treturn new Promise<TestSseEvent[]>((resolve, reject) => {\n\t\t\t// Listen for new events until stream ends\n\t\t\tconst originalDispatch = this.dispatchEvent.bind(this)\n\t\t\tthis.dispatchEvent = (event: TestSseEvent) => {\n\t\t\t\tevents.push(event)\n\t\t\t\toriginalDispatch(event)\n\t\t\t}\n\n\t\t\tconst endWaiter = () => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tthis.dispatchEvent = originalDispatch\n\t\t\t\tresolve(events)\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.dispatchEvent = originalDispatch\n\t\t\t\tconst index = this.endWaiters.indexOf(endWaiter)\n\t\t\t\tif (index !== -1) this.endWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`SSE: stream did not end within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\t// Drain any queued events first\n\t\t\tevents.push(...this.eventQueue.splice(0))\n\n\t\t\tthis.endWaiters.push(endWaiter)\n\t\t})\n\t}\n\n\t/**\n\t * Assert that the next event matches the expected partial shape\n\t */\n\tasync assertEvent(expected: Partial<TestSseEvent>, timeout = 5000): Promise<void> {\n\t\tconst event = await this.waitForEvent(timeout)\n\t\texpect(event).toMatchObject(expected)\n\t}\n\n\t/**\n\t * Assert that the next event's data matches the expected string\n\t */\n\tasync assertEventData(expected: string, timeout = 5000): Promise<void> {\n\t\tconst event = await this.waitForEvent(timeout)\n\t\texpect(event.data, `Expected SSE data \"${expected}\", got \"${event.data}\"`).toBe(expected)\n\t}\n\n\t/**\n\t * Assert that the next event's data is JSON matching the expected value\n\t */\n\tasync assertJsonEventData<T>(expected: T, timeout = 5000): Promise<void> {\n\t\tconst event = await this.waitForEvent(timeout)\n\t\tconst parsed = JSON.parse(event.data) as unknown\n\t\texpect(parsed).toEqual(expected)\n\t}\n\n\t/**\n\t * Access the raw Response\n\t */\n\tget raw(): Response {\n\t\treturn this.response\n\t}\n\n\tprivate startReading(): void {\n\t\tconst body = this.response.body\n\t\tif (!body) {\n\t\t\tthis.streamEnded = true\n\t\t\treturn\n\t\t}\n\n\t\tconst reader = body.getReader() as ReadableStreamDefaultReader<Uint8Array>\n\t\tconst decoder = new TextDecoder()\n\t\tlet buffer = ''\n\n\t\tconst read = async (): Promise<void> => {\n\t\t\ttry {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\t\t\t\twhile (true) {\n\t\t\t\t\tconst { done, value } = await reader.read()\n\n\t\t\t\t\tif (done) {\n\t\t\t\t\t\t// Parse any remaining buffered data\n\t\t\t\t\t\tif (buffer.trim()) {\n\t\t\t\t\t\t\tconst event = this.parseEvent(buffer)\n\t\t\t\t\t\t\tif (event) this.dispatchEvent(event)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.streamEnded = true\n\t\t\t\t\t\tfor (const waiter of this.endWaiters) {\n\t\t\t\t\t\t\twaiter()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.endWaiters = []\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tbuffer += decoder.decode(value, { stream: true })\n\n\t\t\t\t\t// Split on double newlines (SSE event boundary)\n\t\t\t\t\tconst parts = buffer.split('\\n\\n')\n\t\t\t\t\t// Last part may be incomplete, keep it in the buffer\n\t\t\t\t\tbuffer = parts.pop()!\n\n\t\t\t\t\tfor (const part of parts) {\n\t\t\t\t\t\tif (!part.trim()) continue\n\t\t\t\t\t\tconst event = this.parseEvent(part)\n\t\t\t\t\t\tif (event) this.dispatchEvent(event)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tthis.streamEnded = true\n\t\t\t\tfor (const waiter of this.endWaiters) {\n\t\t\t\t\twaiter()\n\t\t\t\t}\n\t\t\t\tthis.endWaiters = []\n\t\t\t}\n\t\t}\n\n\t\tvoid read()\n\t}\n\n\tprivate parseEvent(raw: string): TestSseEvent | null {\n\t\tconst lines = raw.split('\\n')\n\t\tconst dataLines: string[] = []\n\t\tlet event: string | undefined\n\t\tlet id: string | undefined\n\t\tlet retry: number | undefined\n\n\t\tfor (const line of lines) {\n\t\t\tif (line.startsWith(':')) continue // comment line\n\n\t\t\tconst colonIndex = line.indexOf(':')\n\t\t\tif (colonIndex === -1) continue\n\n\t\t\tconst field = line.slice(0, colonIndex)\n\t\t\t// Strip optional leading space after colon\n\t\t\tconst value = line[colonIndex + 1] === ' ' ? line.slice(colonIndex + 2) : line.slice(colonIndex + 1)\n\n\t\t\tswitch (field) {\n\t\t\t\tcase 'data':\n\t\t\t\t\tdataLines.push(value)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'event':\n\t\t\t\t\tevent = value\n\t\t\t\t\tbreak\n\t\t\t\tcase 'id':\n\t\t\t\t\tid = value\n\t\t\t\t\tbreak\n\t\t\t\tcase 'retry': {\n\t\t\t\t\tconst parsed = parseInt(value, 10)\n\t\t\t\t\tif (!isNaN(parsed)) retry = parsed\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (dataLines.length === 0) return null\n\n\t\tconst result: TestSseEvent = { data: dataLines.join('\\n') }\n\t\tif (event !== undefined) result.event = event\n\t\tif (id !== undefined) result.id = id\n\t\tif (retry !== undefined) result.retry = retry\n\n\t\treturn result\n\t}\n\n\tprivate dispatchEvent(event: TestSseEvent): void {\n\t\tif (this.eventWaiters.length > 0) {\n\t\t\tthis.eventWaiters.shift()!(event)\n\t\t} else {\n\t\t\tthis.eventQueue.push(event)\n\t\t}\n\t}\n}\n","import type { AuthService } from '@stratal/framework/auth'\nimport { AUTH_SERVICE } from '@stratal/framework/auth'\nimport type { DetectionStrategy } from 'stratal/i18n'\nimport { expect } from 'vitest'\nimport { ActingAs } from '../../auth'\nimport type { TestingModule } from '../testing-module'\nimport { applyLocaleToHeaders, resolveLocaleStrategy } from '../http/locale-helper'\nimport { TestSseConnection } from './test-sse-connection'\n\n/**\n * TestSseRequest\n *\n * Builder for SSE connection requests. Follows the TestWsRequest pattern.\n *\n * @example\n * ```typescript\n * const sse = await module.sse('/streaming/sse').connect()\n * await sse.assertEvent({ event: 'message', data: 'hello' })\n * await sse.waitForEnd()\n * ```\n *\n * @example Authenticated SSE\n * ```typescript\n * const sse = await module.sse('/streaming/sse').actingAs({ id: user.id }).connect()\n * ```\n */\nexport class TestSseRequest {\n\tprivate requestHeaders: Headers = new Headers()\n\tprivate actingAsUser: { id: string } | null = null\n\n\tconstructor(\n\t\tprivate readonly path: string,\n\t\tprivate readonly module: TestingModule,\n\t) { }\n\n\t/**\n\t * Add custom headers to the request\n\t */\n\twithHeaders(headers: Record<string, string>): this {\n\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\tthis.requestHeaders.set(key, value)\n\t\t}\n\t\treturn this\n\t}\n\n\t/**\n\t * Set the locale for this SSE connection.\n\t * If strategy is not provided, resolves from the module's I18n configuration.\n\t */\n\twithLocale(locale: string, strategy?: DetectionStrategy): this {\n\t\tconst resolved = strategy ?? resolveLocaleStrategy(this.module)\n\t\tapplyLocaleToHeaders(this.requestHeaders, locale, resolved)\n\t\treturn this\n\t}\n\n\t/**\n\t * Authenticate the SSE connection as a specific user\n\t */\n\tactingAs(user: { id: string }): this {\n\t\tthis.actingAsUser = user\n\t\treturn this\n\t}\n\n\t/**\n\t * Send the request and return a live SSE connection\n\t */\n\tasync connect(): Promise<TestSseConnection> {\n\t\tawait this.applyAuthentication()\n\n\t\tthis.requestHeaders.set('Accept', 'text/event-stream')\n\n\t\tconst url = new URL(this.path, 'http://localhost')\n\t\tconst request = new Request(url.toString(), {\n\t\t\theaders: this.requestHeaders,\n\t\t})\n\n\t\tconst response = await this.module.fetch(request)\n\n\t\texpect(\n\t\t\tresponse.status,\n\t\t\t`Expected status 200, got ${response.status}`,\n\t\t).toBe(200)\n\n\t\tconst contentType = response.headers.get('content-type') ?? ''\n\t\texpect(\n\t\t\tcontentType.includes('text/event-stream'),\n\t\t\t`Expected content-type \"text/event-stream\", got \"${contentType}\"`,\n\t\t).toBe(true)\n\n\t\treturn new TestSseConnection(response)\n\t}\n\n\tprivate async applyAuthentication(): Promise<void> {\n\t\tif (!this.actingAsUser) return\n\n\t\tawait this.module.runInRequestScope(async () => {\n\t\t\tconst authService = this.module.get<AuthService>(AUTH_SERVICE)\n\t\t\tconst actingAs = new ActingAs(authService)\n\t\t\tconst authHeaders = this.actingAsUser ? await actingAs.createSessionForUser(this.actingAsUser) : new Headers()\n\n\t\t\tfor (const [key, value] of authHeaders.entries()) {\n\t\t\t\tthis.requestHeaders.set(key, value)\n\t\t\t}\n\t\t})\n\t}\n}\n","import { expect } from \"vitest\";\n\n/**\n * TestWsConnection\n *\n * Live WebSocket connection wrapper with assertion helpers for testing.\n *\n * @example\n * ```typescript\n * const ws = await module.ws('/ws/chat').connect()\n * ws.send('hello')\n * await ws.assertMessage('echo:hello')\n * ws.close()\n * await ws.waitForClose()\n * ```\n */\nexport class TestWsConnection {\n\tprivate readonly messageQueue: (string | ArrayBuffer)[] = []\n\tprivate messageWaiters: ((data: string | ArrayBuffer) => void)[] = []\n\tprivate closeEvent: { code?: number; reason?: string } | null = null\n\tprivate closeWaiters: ((event: { code?: number; reason?: string }) => void)[] = []\n\n\tconstructor(private readonly ws: WebSocket) {\n\t\tthis.ws.addEventListener('message', (event: MessageEvent) => {\n\t\t\tconst data = event.data as string | ArrayBuffer\n\t\t\tif (this.messageWaiters.length > 0) {\n\t\t\t\tthis.messageWaiters.shift()!(data)\n\t\t\t} else {\n\t\t\t\tthis.messageQueue.push(data)\n\t\t\t}\n\t\t})\n\n\t\tthis.ws.addEventListener('close', (event: CloseEvent) => {\n\t\t\tthis.closeEvent = { code: event.code, reason: event.reason }\n\t\t\tfor (const waiter of this.closeWaiters) {\n\t\t\t\twaiter(this.closeEvent)\n\t\t\t}\n\t\t\tthis.closeWaiters = []\n\t\t})\n\t}\n\n\t/**\n\t * Send a message through the WebSocket\n\t */\n\tsend(data: string | ArrayBuffer | Uint8Array): void {\n\t\tthis.ws.send(data)\n\t}\n\n\t/**\n\t * Close the WebSocket connection\n\t */\n\tclose(code?: number, reason?: string): void {\n\t\tthis.ws.close(code, reason)\n\t}\n\n\t/**\n\t * Wait for the next message, returning its data\n\t */\n\tasync waitForMessage(timeout = 5000): Promise<string | ArrayBuffer> {\n\t\tif (this.messageQueue.length > 0) {\n\t\t\treturn this.messageQueue.shift()!\n\t\t}\n\n\t\treturn new Promise<string | ArrayBuffer>((resolve, reject) => {\n\t\t\tconst waiter = (data: string | ArrayBuffer) => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tresolve(data)\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst index = this.messageWaiters.indexOf(waiter)\n\t\t\t\tif (index !== -1) this.messageWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`WebSocket: no message received within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\tthis.messageWaiters.push(waiter)\n\t\t})\n\t}\n\n\t/**\n\t * Wait for the connection to close\n\t */\n\tasync waitForClose(timeout = 5000): Promise<{ code?: number; reason?: string }> {\n\t\tif (this.closeEvent) {\n\t\t\treturn this.closeEvent\n\t\t}\n\n\t\treturn new Promise<{ code?: number; reason?: string }>((resolve, reject) => {\n\t\t\tconst waiter = (event: { code?: number; reason?: string }) => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tresolve(event)\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst index = this.closeWaiters.indexOf(waiter)\n\t\t\t\tif (index !== -1) this.closeWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`WebSocket: connection did not close within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\tthis.closeWaiters.push(waiter)\n\t\t})\n\t}\n\n\t/**\n\t * Assert that the next message equals the expected value\n\t */\n\tasync assertMessage(expected: string, timeout = 5000): Promise<void> {\n\t\tconst data = await this.waitForMessage(timeout)\n\t\tconst message = typeof data === 'string' ? data : '[ArrayBuffer]'\n\t\texpect(message, `Expected WebSocket message \"${expected}\", got \"${message}\"`).toBe(expected)\n\t}\n\n\t/**\n\t * Assert that the connection closes, optionally with an expected code\n\t */\n\tasync assertClosed(expectedCode?: number, timeout = 5000): Promise<void> {\n\t\tconst event = await this.waitForClose(timeout)\n\t\tif (expectedCode !== undefined) {\n\t\t\texpect(event.code, `Expected close code ${expectedCode}, got ${event.code}`).toBe(expectedCode)\n\t\t}\n\t}\n\n\t/**\n\t * Access the raw Cloudflare WebSocket\n\t */\n\tget raw(): WebSocket {\n\t\treturn this.ws\n\t}\n}\n","import type { AuthService } from '@stratal/framework/auth'\nimport { AUTH_SERVICE } from '@stratal/framework/auth'\nimport type { DetectionStrategy } from 'stratal/i18n'\nimport { expect } from 'vitest'\nimport { ActingAs } from '../../auth'\nimport type { TestingModule } from '../testing-module'\nimport { applyLocaleToHeaders, resolveLocaleStrategy } from '../http/locale-helper'\nimport { TestWsConnection } from './test-ws-connection'\n\n/**\n * TestWsRequest\n *\n * Builder for WebSocket upgrade requests. Follows the TestHttpRequest pattern.\n *\n * @example\n * ```typescript\n * const ws = await module.ws('/ws/chat').connect()\n * ws.send('hello')\n * await ws.assertMessage('echo:hello')\n * ws.close()\n * ```\n *\n * @example Authenticated WebSocket\n * ```typescript\n * const ws = await module.ws('/ws/chat').actingAs({ id: user.id }).connect()\n * ```\n */\nexport class TestWsRequest {\n\tprivate requestHeaders: Headers = new Headers()\n\tprivate actingAsUser: { id: string } | null = null\n\n\tconstructor(\n\t\tprivate readonly path: string,\n\t\tprivate readonly module: TestingModule,\n\t) { }\n\n\t/**\n\t * Add custom headers to the upgrade request\n\t */\n\twithHeaders(headers: Record<string, string>): this {\n\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\tthis.requestHeaders.set(key, value)\n\t\t}\n\t\treturn this\n\t}\n\n\t/**\n\t * Set the locale for this WebSocket connection.\n\t * If strategy is not provided, resolves from the module's I18n configuration.\n\t */\n\twithLocale(locale: string, strategy?: DetectionStrategy): this {\n\t\tconst resolved = strategy ?? resolveLocaleStrategy(this.module)\n\t\tapplyLocaleToHeaders(this.requestHeaders, locale, resolved)\n\t\treturn this\n\t}\n\n\t/**\n\t * Authenticate the WebSocket connection as a specific user\n\t */\n\tactingAs(user: { id: string }): this {\n\t\tthis.actingAsUser = user\n\t\treturn this\n\t}\n\n\t/**\n\t * Send the upgrade request and return a live WebSocket connection\n\t */\n\tasync connect(): Promise<TestWsConnection> {\n\t\tawait this.applyAuthentication()\n\n\t\tthis.requestHeaders.set('Upgrade', 'websocket')\n\t\tthis.requestHeaders.set('Connection', 'Upgrade')\n\t\tthis.requestHeaders.set('Sec-WebSocket-Key', 'dGhlIHNhbXBsZSBub25jZQ==')\n\t\tthis.requestHeaders.set('Sec-WebSocket-Version', '13')\n\n\t\tconst url = new URL(this.path, 'http://localhost')\n\t\tconst request = new Request(url.toString(), {\n\t\t\theaders: this.requestHeaders,\n\t\t})\n\n\t\tconst response = await this.module.fetch(request)\n\n\t\texpect(\n\t\t\tresponse.status,\n\t\t\t`Expected status 101 (Switching Protocols), got ${response.status}`,\n\t\t).toBe(101)\n\n\t\tconst ws = (response as Response & { webSocket: WebSocket | null }).webSocket\n\t\tif (!ws) {\n\t\t\tthrow new Error('Response did not include a WebSocket connection')\n\t\t}\n\n\t\tws.accept()\n\n\t\treturn new TestWsConnection(ws)\n\t}\n\n\tprivate async applyAuthentication(): Promise<void> {\n\t\tif (!this.actingAsUser) return\n\n\t\tawait this.module.runInRequestScope(async () => {\n\t\t\tconst authService = this.module.get<AuthService>(AUTH_SERVICE)\n\t\t\tconst actingAs = new ActingAs(authService)\n\t\t\tconst authHeaders = this.actingAsUser ? await actingAs.createSessionForUser(this.actingAsUser) : new Headers()\n\n\t\t\tfor (const [key, value] of authHeaders.entries()) {\n\t\t\t\tthis.requestHeaders.set(key, value)\n\t\t\t}\n\t\t})\n\t}\n}\n","import type { ConnectionName, DatabaseService } from '@stratal/framework/database'\nimport { connectionSymbol } from '@stratal/framework/database'\nimport type { Application, Constructor, StratalEnv, StratalExecutionContext } from 'stratal'\nimport { DI_TOKENS, type Container } from 'stratal/di'\nimport type { ResolvedEmailMessage } from 'stratal/email'\nimport { type InjectionToken } from 'stratal/module'\nimport { SEEDER_TOKENS, SeederError, type Seeder, type SeederRegistry } from 'stratal/seeder'\nimport { STORAGE_TOKENS } from 'stratal/storage'\nimport { expect } from 'vitest'\nimport { dropDatabase } from '../database'\nimport { FEATURE_FLAG_SERVICE_TOKEN, type FakeFeatureFlagService } from '../feature-flags'\nimport type { FakeStorageService } from '../storage'\nimport type { TestEmailProvider } from '../mocks/test-email-provider'\nimport { TestHttpClient } from './http/test-http-client'\nimport { TestCommandRequest } from './quarry/test-command-request'\nimport { TestSseRequest } from './sse/test-sse-request'\nimport { TestWsRequest } from './ws/test-ws-request'\n\n/**\n * TestingModule\n *\n * Provides access to the test application, container, HTTP client, and utilities.\n *\n * @example\n * ```typescript\n * const module = await Test.createTestingModule({\n * modules: [RegistrationModule],\n * }).compile()\n *\n * // Make HTTP requests\n * const response = await module.http\n * .post('/api/v1/register')\n * .withBody({ ... })\n * .send()\n *\n * // Access services\n * const service = module.get(REGISTRATION_TOKENS.RegistrationService)\n *\n * // Database utilities\n * await module.truncateDb()\n * await module.seed(UserSeeder)\n * await module.assertDatabaseHas('user', { email: 'test@example.com' })\n *\n * // Cleanup\n * await module.close()\n * ```\n */\n/**\n * Identifies a per-file database created for test isolation, so it can be\n * dropped on teardown. Produced by the testing module builder.\n */\nexport interface IsolatedDatabase {\n /** Name of the cloned database. */\n name: string\n /** Admin (maintenance-database) connection string used to drop it. */\n adminConnectionString: string\n}\n\nexport class TestingModule {\n private _http: TestHttpClient | null = null\n private readonly _requestContainer: Container\n\n constructor(\n private readonly app: Application,\n private readonly env: StratalEnv,\n private readonly ctx: StratalExecutionContext,\n private readonly isolatedDatabase: IsolatedDatabase | null = null,\n private readonly testEmailProvider: TestEmailProvider | null = null,\n ) {\n const mockContext = this.app.createMockRouterContext()\n this._requestContainer = this.app.container.createRequestScope(mockContext)\n }\n\n /**\n * Emails recorded by the default {@link TestEmailProvider}, in send order.\n * Empty when the email provider factory was overridden.\n */\n get sentEmails(): ResolvedEmailMessage[] {\n return this.testEmailProvider?.sent ?? []\n }\n\n /**\n * Resolve a service from the container\n */\n get<T>(token: InjectionToken<T>): T {\n return this._requestContainer.resolve(token)\n }\n\n /**\n * Get HTTP test client for making requests\n */\n get http(): TestHttpClient {\n this._http ??= new TestHttpClient(this)\n return this._http\n }\n\n\n /**\n * Get Inertia test client for making Inertia requests\n */\n get inertia(): TestHttpClient {\n return this.http.withHeaders({ 'X-Inertia': 'true', 'X-Inertia-Version': '1' })\n }\n\n /**\n * Get fake storage service for assertions\n */\n get storage(): FakeStorageService {\n return this.get<FakeStorageService>(STORAGE_TOKENS.StorageService)\n }\n\n /**\n * Get the fake feature-flag service to configure flags in tests\n * (e.g. `module.featureFlags.set('my-flag', true)`).\n */\n get featureFlags(): FakeFeatureFlagService {\n return this.get<FakeFeatureFlagService>(FEATURE_FLAG_SERVICE_TOKEN)\n }\n\n /**\n * Create a WebSocket test request builder for the given path\n */\n ws(path: string): TestWsRequest {\n return new TestWsRequest(path, this)\n }\n\n /**\n * Create an SSE test request builder for the given path\n */\n sse(path: string): TestSseRequest {\n return new TestSseRequest(path, this)\n }\n\n /**\n * Create a Quarry command test request builder\n */\n quarry(name: string): TestCommandRequest {\n return new TestCommandRequest(name, this)\n }\n\n /**\n * Get Application instance\n */\n get application(): Application {\n return this.app\n }\n\n /**\n * Get DI Container (request-scoped)\n */\n get container(): Container {\n return this._requestContainer\n }\n\n /**\n * Execute an HTTP request through HonoApp\n */\n async fetch(request: Request): Promise<Response> {\n const hono = await this.app.ensureHono()\n return hono.fetch(request, this.env, this.ctx as ExecutionContext)\n }\n\n /**\n * Run callback in request scope (for DB operations, service access)\n */\n async runInRequestScope<T>(callback: (container: Container) => T | Promise<T>): Promise<T> {\n const mockContext = this.app.createMockRouterContext()\n return this.app.container.runInRequestScope(mockContext, callback)\n }\n\n /**\n * Get database service instance (resolved in request scope)\n */\n getDb(): DatabaseService\n getDb<K extends ConnectionName>(name: K): DatabaseService<K>\n getDb(name?: string): unknown {\n const token = name ? connectionSymbol(name) : DI_TOKENS.Database\n return this._requestContainer.resolve(token)\n }\n\n /**\n * Truncate all non-prisma tables in the database\n */\n async truncateDb(name?: ConnectionName): Promise<void> {\n const db = this.getDb(name!)\n const tables = await db.$queryRaw<{ tablename: string }[]>`\n SELECT tablename::text as tablename FROM pg_tables\n WHERE schemaname = current_schema()\n AND tablename NOT LIKE '_prisma%'\n `\n if (tables.length === 0) return\n const tableList = tables.map((t) => `\"${t.tablename}\"`).join(', ')\n await db.$executeRawUnsafe(`TRUNCATE ${tableList} RESTART IDENTITY CASCADE`)\n }\n\n /**\n * Run seeders by class constructor in the request-scoped container\n */\n async seed(...SeederClasses: Constructor<Seeder>[]): Promise<void> {\n const registry = this._requestContainer.resolve<SeederRegistry>(SEEDER_TOKENS.SeederRegistry)\n for (const SeederClass of SeederClasses) {\n if (!registry.has(SeederClass)) {\n throw new SeederError(`Seeder \"${SeederClass.name}\" is not registered`)\n }\n await registry.run(SeederClass, { container: this._requestContainer })\n }\n }\n\n /**\n * Assert that a record exists in the database\n */\n async assertDatabaseHas(table: string, data: Record<string, unknown>, name?: ConnectionName): Promise<void> {\n const db = this.getDb(name!)\n const model = (db as unknown as Record<string, unknown>)[table] as { findFirst: (opts: unknown) => Promise<unknown> }\n const result = await model.findFirst({ where: data })\n expect(result, `Expected ${table} with ${JSON.stringify(data)}`).not.toBeNull()\n }\n\n /**\n * Assert that a record does not exist in the database\n */\n async assertDatabaseMissing(table: string, data: Record<string, unknown>, name?: ConnectionName): Promise<void> {\n const db = this.getDb(name!)\n const model = (db as unknown as Record<string, unknown>)[table] as { findFirst: (opts: unknown) => Promise<unknown> }\n const result = await model.findFirst({ where: data })\n expect(result, `Expected ${table} NOT to have ${JSON.stringify(data)}`).toBeNull()\n }\n\n /**\n * Assert the number of records in a table\n */\n async assertDatabaseCount(table: string, expected: number, name?: ConnectionName): Promise<void> {\n const db = this.getDb(name!)\n const model = (db as unknown as Record<string, unknown>)[table] as { count: () => Promise<number> }\n const actual = await model.count()\n expect(actual, `Expected ${table} count ${expected}, got ${actual}`).toBe(expected)\n }\n\n /**\n * Cleanup - call in afterAll\n */\n async close(): Promise<void> {\n await this._requestContainer.dispose()\n try {\n await this.app.shutdown()\n }\n finally {\n // Drop the per-file database AFTER shutdown so the app's pool connection is\n // released; `WITH (FORCE)` evicts any that lingers. Runs even if shutdown\n // throws, otherwise a failed shutdown would leak the database until the\n // next run's stale-database sweep.\n //\n // A drop failure here is non-fatal: the next run's connection-guarded sweep\n // reclaims the database. Swallow it (warn only) so a passing suite isn't\n // marked failed by a teardown hiccup.\n if (this.isolatedDatabase) {\n try {\n await dropDatabase(this.isolatedDatabase.adminConnectionString, this.isolatedDatabase.name)\n } catch (error) {\n console.warn(\n `[stratal-testing] Failed to drop isolated test database \"${this.isolatedDatabase.name}\"; ` +\n 'it will be reclaimed by the next run\\'s stale-database sweep.',\n error,\n )\n }\n }\n }\n }\n}\n","import {\n Application,\n type ApplicationConfig,\n type Constructor,\n type StratalEnv,\n type StratalExecutionContext,\n} from 'stratal'\nimport type { ExceptionHandler } from 'stratal/errors'\nimport { type Container } from 'stratal/di'\nimport { LogLevel } from 'stratal/logger'\nimport { type InjectionToken, Module, type ModuleClass, type ModuleOptions } from 'stratal/module'\nimport { EMAIL_TOKENS } from 'stratal/email'\nimport { RATE_LIMITER_TOKENS } from 'stratal/rate-limiter'\nimport { STORAGE_TOKENS } from 'stratal/storage'\nimport {\n BINDING_ENV_VAR,\n buildConnectionString,\n createDatabaseFromTemplate,\n DEFAULT_DB_BINDING,\n deriveAdminConnectionString,\n deriveDbName,\n deriveTemplateName,\n dropDatabase,\n ISOLATION_ENV_VAR,\n normalizeIsolation,\n} from '../database'\nimport { FakeStorageService } from '../storage'\nimport { NoopRateLimiterStore } from '../mocks/noop-rate-limiter-store'\nimport { TestEmailProvider } from '../mocks/test-email-provider'\nimport { FEATURE_FLAG_SERVICE_TOKEN, FakeFeatureFlagService } from '../feature-flags'\nimport { ProviderOverrideBuilder, type ProviderOverrideConfig } from './override'\nimport { Test } from './test'\nimport { TestingModule, type IsolatedDatabase } from './testing-module'\n\n/**\n * Configuration for creating a testing module\n *\n * Extends ModuleOptions to support all module properties like NestJS.\n *\n * @example\n * ```typescript\n * const module = await Test.createTestingModule({\n * imports: [RegistrationModule, GeoModule],\n * providers: [{ provide: MOCK_TOKEN, useValue: mockValue }],\n * controllers: [TestController],\n * }).compile()\n * ```\n */\nexport interface TestingModuleConfig extends ModuleOptions {\n /** Optional environment overrides */\n env?: Partial<StratalEnv>\n /** Logging configuration. Defaults: level=ERROR, formatter='json' */\n logging?: ApplicationConfig['logging']\n /**\n * Custom exception handler. Mirrors `ApplicationConfig.exceptionHandler`.\n * Must be passed at compile time — `overrideProvider(DI_TOKENS.ExceptionHandler)`\n * cannot replace it because the framework resolves the handler during\n * `initialize()` (before overrides apply).\n */\n exceptionHandler?: Constructor<ExceptionHandler>\n}\n\n/**\n * Builder for creating test modules with provider overrides\n */\nexport class TestingModuleBuilder {\n private overrides: ProviderOverrideConfig<object>[] = []\n\n constructor(private config: TestingModuleConfig) { }\n\n /**\n * Override a provider with a custom implementation\n */\n overrideProvider<T>(token: InjectionToken<T>): ProviderOverrideBuilder<T> {\n return new ProviderOverrideBuilder(this, token)\n }\n\n /**\n * Add a provider override (internal use by ProviderOverrideBuilder)\n *\n * @internal\n */\n addProviderOverride<T>(override: ProviderOverrideConfig<T>): this {\n this.overrides.push(override as ProviderOverrideConfig<object>)\n return this\n }\n\n /**\n * Merge additional environment bindings\n */\n withEnv(env: Partial<StratalEnv>): this {\n this.config.env = { ...this.config.env, ...env }\n return this\n }\n\n private async getCloudflareWorkers() {\n try {\n return await import('cloudflare:workers')\n } catch {\n return null\n }\n }\n\n /**\n * Compile the testing module\n *\n * Creates the Application, applies overrides, initializes, and returns TestingModule.\n */\n async compile(): Promise<TestingModule> {\n const cf = await this.getCloudflareWorkers()\n\n const env = { ...cf?.env, ...this.config.env } as StratalEnv\n const ctx: StratalExecutionContext = {\n waitUntil: cf ? cf.waitUntil : (p) => {\n p.catch(() => {\n //\n })\n },\n }\n\n // When database isolation is enabled, clone the migrated template into a\n // fresh per-file database and point this app's DB binding at it. The clone\n // is dropped in TestingModule.close(). No-op in 'shared' mode or when the\n // app has no DB binding.\n const isolatedDb = await this.setupIsolatedDatabase(env)\n\n // Everything between the clone above and returning the TestingModule (which\n // owns the drop via close()) can throw — module init, overrides, etc. If it\n // does, nothing would ever drop the freshly cloned database. Drop it (FORCE)\n // on failure before rethrowing so a compile() error doesn't leak a database.\n let app: Application | null = null\n try {\n // Build root module from config\n const baseModules = Test.getBaseModules()\n const allImports = [...baseModules, ...(this.config.imports ?? [])]\n\n const rootModule = this.createTestRootModule({\n imports: allImports,\n providers: this.config.providers,\n controllers: this.config.controllers,\n consumers: this.config.consumers,\n jobs: this.config.jobs,\n })\n\n app = new Application({\n module: rootModule,\n logging: {\n level: this.config.logging?.level ?? LogLevel.ERROR,\n formatter: this.config.logging?.formatter ?? 'pretty',\n },\n env,\n ctx,\n exceptionHandler: this.config.exceptionHandler,\n })\n\n await app.initialize()\n\n // Auto-register FakeStorageService after initialize so it replaces module-registered StorageService\n app.container.registerSingleton(STORAGE_TOKENS.StorageService, FakeStorageService)\n\n // Auto-register FakeFeatureFlagService so feature-gated code resolves without a\n // real Cloudflare Flagship binding. Inert for apps that don't use feature flags.\n app.container.registerSingleton(FEATURE_FLAG_SERVICE_TOKEN, FakeFeatureFlagService)\n\n // Disable rate limiting: suites fire many requests from one \"IP\" in\n // seconds and would trip production limiter budgets (and Better Auth's\n // built-in per-path limits, which share this store). Override the token\n // back to a real store to test limiting behavior explicitly.\n app.container.registerSingleton(RATE_LIMITER_TOKENS.Store, NoopRateLimiterStore)\n\n // Auto-register TestEmailProvider: the sync queue provider runs\n // EmailConsumer inline on dispatch, which would otherwise open a real\n // SMTP connection from the test worker. Recorded messages are exposed\n // via `module.sentEmails`; the user overrides below still replace this.\n const testEmailProvider = new TestEmailProvider()\n app.container.registerValue(EMAIL_TOKENS.EmailProviderFactory, {\n create: () => testEmailProvider,\n })\n\n // Apply user overrides AFTER initialize so they replace module-registered providers\n for (const override of this.overrides) {\n switch (override.type) {\n case 'value':\n app.container.registerValue(override.token, override.implementation)\n break\n case 'class':\n app.container.registerSingleton(\n override.token,\n override.implementation as Constructor\n )\n break\n case 'factory':\n app.container.registerFactory(\n override.token,\n override.implementation as (c: Container) => object\n )\n break\n case 'existing':\n app.container.registerExisting(\n override.token,\n override.implementation as InjectionToken<object>\n )\n break\n }\n }\n\n // Routing init is lazy in production (first fetch keeps cold starts\n // lean), but tests may resolve request-scoped router services before\n // any fetch — e.g. ActingAs minting a session resolves AUTH_OPTIONS,\n // whose factory can inject ROUTER_TOKENS.Uri. Initialize eagerly so\n // test ordering can never matter. Runs last: singleton resolution\n // caches by token without invalidation, so anything resolved here\n // would permanently shadow auto-mocks and user overrides.\n await app.ensureHono()\n\n return new TestingModule(app, env, ctx, isolatedDb, testEmailProvider)\n } catch (error) {\n // Tear down the partially built Application so module-held resources\n // (DB pools, timers) don't outlive a failed compile().\n if (app) {\n await app.shutdown().catch(() => {\n // Best-effort cleanup for partially initialized apps.\n })\n }\n if (isolatedDb) {\n await dropDatabase(isolatedDb.adminConnectionString, isolatedDb.name).catch(() => {\n // Best-effort cleanup; the next run's stale-database sweep is the backstop.\n })\n }\n throw error\n }\n }\n\n /**\n * When `STRATAL_TEST_DB_ISOLATION=database`, create a fresh database cloned\n * from the migrated template and rewrite the Hyperdrive binding's\n * `connectionString` to target it. The binding name is configurable via\n * `stratalTest({ database: { binding } })` (defaults to `DB`). Returns the\n * created name + admin connection so `close()` can drop it, or `null` when\n * isolation is off. Throws if isolation is on but the binding is missing — a\n * misconfiguration, not a case to skip.\n */\n private async setupIsolatedDatabase(env: StratalEnv): Promise<IsolatedDatabase | null> {\n const bindings = env as unknown as Record<string, unknown>\n const isolation = normalizeIsolation(bindings[ISOLATION_ENV_VAR] as string | undefined)\n if (isolation !== 'database') return null\n\n const bindingName = (bindings[BINDING_ENV_VAR] as string | undefined) ?? DEFAULT_DB_BINDING\n const db = bindings[bindingName] as { connectionString?: string } | undefined\n const base = db?.connectionString\n if (!base) {\n throw new Error(\n `Database isolation is 'database' but no \\`${bindingName}\\` Hyperdrive binding with a connectionString was found. ` +\n `Provide it via \\`stratalTest({ miniflare: { hyperdrives: { ${bindingName} } } })\\`, or set isolation to 'shared'.`,\n )\n }\n\n const adminConnectionString = deriveAdminConnectionString(base)\n const name = deriveDbName(base)\n await createDatabaseFromTemplate(adminConnectionString, name, deriveTemplateName(base))\n\n // Point the binding at the per-file database by overriding only its\n // connectionString. Clone with the original prototype + descriptors so the\n // Hyperdrive binding's methods (e.g. `connect()`) and other fields survive,\n // and never mutate the shared cloudflare env object.\n const isolated = Object.create(\n Object.getPrototypeOf(db) as object | null,\n Object.getOwnPropertyDescriptors(db),\n ) as Record<string, unknown>\n Object.defineProperty(isolated, 'connectionString', {\n value: buildConnectionString(base, name),\n enumerable: true,\n configurable: true,\n writable: true,\n })\n bindings[bindingName] = isolated\n\n return { name, adminConnectionString }\n }\n\n /**\n * Create a test root module with the given options\n */\n private createTestRootModule(options: ModuleOptions): ModuleClass {\n @Module(options)\n class TestRootModule { }\n return TestRootModule\n }\n}\n","import { type DynamicModule, type ModuleClass } from 'stratal/module'\nimport { TestingModuleBuilder, type TestingModuleConfig } from './testing-module-builder'\n\n/**\n * Test\n *\n * Static class for creating testing modules.\n * Provides a NestJS-style API for configuring test modules.\n *\n * @example\n * ```typescript\n * // In vitest.setup.ts:\n * Test.setBaseModules([CoreModule])\n *\n * // In test files:\n * const module = await Test.createTestingModule({\n * imports: [RegistrationModule, GeoModule],\n * })\n * .overrideProvider(EMAIL_TOKENS.EmailService)\n * .useValue(mockEmailService)\n * .compile()\n * ```\n */\nexport class Test {\n /**\n * Base modules to include in all test modules\n * Set once in vitest.setup.ts\n */\n private static baseModules: (ModuleClass | DynamicModule)[] = []\n\n /**\n * Set base modules to include in all test modules\n * Should be called once in vitest.setup.ts\n *\n * @param modules - Modules to include before test-specific modules (e.g., CoreModule)\n */\n static setBaseModules(modules: (ModuleClass | DynamicModule)[]): void {\n this.baseModules = modules\n }\n\n /**\n * Get base modules\n */\n static getBaseModules(): (ModuleClass | DynamicModule)[] {\n return this.baseModules\n }\n\n /**\n * Create a testing module builder\n *\n * @param config - Configuration with modules and optional env overrides\n * @returns TestingModuleBuilder for configuring and compiling the module\n */\n static createTestingModule(config: TestingModuleConfig): TestingModuleBuilder {\n return new TestingModuleBuilder(config)\n }\n}\n","import { http, HttpResponse, type RequestHandler } from 'msw'\nimport { setupServer, type SetupServer } from 'msw/node'\nimport type { MockErrorOptions, MockJsonOptions } from './fetch-mock.types'\n\ntype HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options'\n\n/**\n * MSW-based fetch mock for declarative HTTP mocking in tests.\n *\n * Replaces the old Cloudflare `fetchMock` (undici MockAgent) with MSW's `setupServer`.\n * Works in both Node.js and workerd test environments.\n *\n * @example\n * ```typescript\n * import { createMockFetch } from '@stratal/testing'\n *\n * const mock = createMockFetch()\n *\n * beforeAll(() => mock.listen())\n * afterEach(() => mock.reset())\n * afterAll(() => mock.close())\n *\n * it('should mock external API', async () => {\n * mock.mockJsonResponse('https://api.example.com/data', { success: true })\n *\n * const response = await fetch('https://api.example.com/data')\n * const json = await response.json()\n *\n * expect(json.success).toBe(true)\n * })\n * ```\n */\nexport class MockFetch {\n private server: SetupServer\n\n constructor(handlers: RequestHandler[] = []) {\n this.server = setupServer(...handlers)\n }\n\n /** Start intercepting. Call in beforeAll/beforeEach. */\n listen() {\n this.server.listen({ onUnhandledRequest: 'error' })\n }\n\n /** Reset runtime handlers. Call in afterEach. */\n reset() {\n this.server.resetHandlers()\n }\n\n /** Stop intercepting. Call in afterAll. */\n close() {\n this.server.close()\n }\n\n /** Add runtime handler(s) for a single test. */\n use(...handlers: RequestHandler[]) {\n this.server.use(...handlers)\n }\n\n /**\n * Mock a JSON response.\n *\n * @param url - Full URL to mock (e.g., 'https://api.example.com/users')\n * @param data - JSON data to return\n * @param options - HTTP method, status code, headers\n *\n * @example\n * ```typescript\n * mock.mockJsonResponse('https://api.example.com/users', { users: [] })\n * mock.mockJsonResponse('https://api.example.com/users', { created: true }, { method: 'POST', status: 201 })\n * ```\n */\n mockJsonResponse(url: string, data: Record<string, unknown> | unknown[], options: MockJsonOptions = {}) {\n const method = (options.method ?? 'GET').toLowerCase() as HttpMethod\n const handler = http[method](url, () =>\n HttpResponse.json(data, {\n status: options.status ?? 200,\n headers: options.headers,\n }),\n )\n this.server.use(handler)\n }\n\n /**\n * Mock an error response.\n *\n * @param url - Full URL to mock\n * @param status - HTTP error status code\n * @param message - Optional error message\n * @param options - HTTP method, headers\n *\n * @example\n * ```typescript\n * mock.mockError('https://api.example.com/fail', 401, 'Unauthorized')\n * mock.mockError('https://api.example.com/fail', 500, 'Server Error', { method: 'POST' })\n * ```\n */\n mockError(url: string, status: number, message?: string, options: MockErrorOptions = {}) {\n const method = (options.method ?? 'GET').toLowerCase() as HttpMethod\n const body = message ? { error: message } : undefined\n this.server.use(\n http[method](url, () =>\n HttpResponse.json(body, { status, headers: options.headers }),\n ),\n )\n }\n}\n\n/**\n * Factory function to create a new MockFetch instance\n *\n * @param handlers - Optional initial MSW request handlers\n * @returns A new MockFetch instance\n *\n * @example\n * ```typescript\n * import { createMockFetch } from '@stratal/testing'\n *\n * const mock = createMockFetch()\n *\n * beforeAll(() => mock.listen())\n * afterEach(() => mock.reset())\n * afterAll(() => mock.close())\n * ```\n */\nexport function createMockFetch(handlers?: RequestHandler[]): MockFetch {\n return new MockFetch(handlers)\n}\n","/**\n * Base error class for all test framework errors.\n * Extends from Error and allows easy identification via `instanceof`.\n */\nexport class TestError extends Error {\n constructor(\n message: string,\n public readonly cause?: Error\n ) {\n super(message)\n this.name = 'TestError'\n\n // Maintain proper stack trace\n Error.captureStackTrace(this, this.constructor)\n }\n}\n","import { TestError } from './test-error'\n\n/**\n * Error thrown when test setup fails.\n * Examples: schema creation failure, migration failure, application bootstrap failure.\n */\nexport class TestSetupError extends TestError {\n constructor(message: string, cause?: Error) {\n super(`Test setup failed: ${message}`, cause)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,0BAAb,MAAwC;CAEnB;CACA;CAFnB,YACE,QACA,OACA;EAFiB,KAAA,SAAA;EACA,KAAA,QAAA;CACf;;;;;;;;;CAUJ,SAAS,OAAgC;EACvC,OAAO,KAAK,OAAO,oBAAoB;GACrC,OAAO,KAAK;GACZ,MAAM;GACN,gBAAgB;EAClB,CAAC;CACH;;;;;;;;;CAUA,SAAS,KAA0D;EACjE,OAAO,KAAK,OAAO,oBAAoB;GACrC,OAAO,KAAK;GACZ,MAAM;GACN,gBAAgB;EAClB,CAAC;CACH;;;;;;;;;CAUA,WAAW,SAA4D;EACrE,OAAO,KAAK,OAAO,oBAAoB;GACrC,OAAO,KAAK;GACZ,MAAM;GACN,gBAAgB;EAClB,CAAC;CACH;;;;;;;;;;;;;;;;;;;CAoBA,YAAY,eAAwD;EAClE,OAAO,KAAK,OAAO,oBAAoB;GACrC,OAAO,KAAK;GACZ,MAAM;GACN,gBAAgB;EAClB,CAAC;CACH;AACF;;;;;;;ACnGA,SAAgB,sBAAsB,QAA0C;CAC9E,IAAI;EAEF,MAAM,YADU,OAAO,IAAuB,YAAY,OAClC,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ACVD,OAAK,QAAQ,WACXC,eAAa,KAAK,MAAM;GAAE;GAAQ,SAAS,QAAQ;EAAQ,CAAC,CAC9D,CACF;CACF;AACF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,gBAAgB,UAAwC;CACtE,OAAO,IAAI,UAAU,QAAQ;AAC/B;;;;;;;AC3HA,IAAa,YAAb,cAA+B,MAAM;CAGjB;CAFlB,YACE,SACA,OACA;EACA,MAAM,OAAO;EAFG,KAAA,QAAA;EAGhB,KAAK,OAAO;EAGZ,MAAM,kBAAkB,MAAM,KAAK,WAAW;CAChD;AACF;;;;;;;ACTA,IAAa,iBAAb,cAAoC,UAAU;CAC5C,YAAY,SAAiB,OAAe;EAC1C,MAAM,sBAAsB,WAAW,KAAK;CAC9C;AACF"}
1
+ {"version":3,"file":"index.mjs","names":["http","HttpResponse"],"sources":["../src/core/override/provider-override-builder.ts","../src/errors/test-error.ts","../src/errors/setup-error.ts","../src/core/http/locale-helper.ts","../src/auth/acting-as.ts","../src/core/http/path-utils.ts","../src/core/http/test-response.ts","../src/core/http/test-http-request.ts","../src/core/http/test-http-client.ts","../src/core/quarry/test-command-result.ts","../src/core/quarry/test-command-request.ts","../src/core/sse/test-sse-connection.ts","../src/core/sse/test-sse-request.ts","../src/core/ws/test-ws-connection.ts","../src/core/ws/test-ws-request.ts","../src/core/testing-module.ts","../src/core/testing-module-builder.ts","../src/core/test.ts","../src/core/http/mock-fetch.ts"],"sourcesContent":["import { type Container } from 'stratal/di'\nimport { type InjectionToken } from 'stratal/module'\nimport type { TestingModuleBuilder } from '../testing-module-builder'\n\n/**\n * Provider override configuration\n */\nexport interface ProviderOverrideConfig<T = unknown> {\n token: InjectionToken<T>\n type: 'value' | 'class' | 'factory' | 'existing'\n implementation: T | (new (...args: unknown[]) => T) | ((container: Container) => T) | InjectionToken<T>\n}\n\n/**\n * Fluent builder for provider overrides\n *\n * Provides a NestJS-style API for overriding providers in tests.\n *\n * @example\n * ```typescript\n * const module = await Test.createTestingModule({\n * imports: [RegistrationModule],\n * })\n * .overrideProvider(EMAIL_TOKENS.EmailService)\n * .useValue(mockEmailService)\n * .compile()\n * ```\n */\nexport class ProviderOverrideBuilder<T> {\n constructor(\n private readonly parent: TestingModuleBuilder,\n private readonly token: InjectionToken<T>\n ) { }\n\n /**\n * Use a static value as the provider\n *\n * The value will be registered directly in the container.\n *\n * @param value - The value to use as the provider\n * @returns The parent TestingModuleBuilder for chaining\n */\n useValue(value: T): TestingModuleBuilder {\n return this.parent.addProviderOverride({\n token: this.token,\n type: 'value',\n implementation: value,\n })\n }\n\n /**\n * Use a class as the provider\n *\n * The class will be registered as a singleton.\n *\n * @param cls - The class constructor to use as the provider\n * @returns The parent TestingModuleBuilder for chaining\n */\n useClass(cls: new (...args: unknown[]) => T): TestingModuleBuilder {\n return this.parent.addProviderOverride({\n token: this.token,\n type: 'class',\n implementation: cls,\n })\n }\n\n /**\n * Use a factory function as the provider\n *\n * The factory receives the container and should return the provider instance.\n *\n * @param factory - Factory function that creates the provider\n * @returns The parent TestingModuleBuilder for chaining\n */\n useFactory(factory: (container: Container) => T): TestingModuleBuilder {\n return this.parent.addProviderOverride({\n token: this.token,\n type: 'factory',\n implementation: factory,\n })\n }\n\n /**\n * Use an existing token as the provider (alias)\n *\n * The override token will resolve to the same instance as the target token.\n *\n * @param existingToken - The token to alias\n * @returns The parent TestingModuleBuilder for chaining\n *\n * @example\n * ```typescript\n * const module = await Test.createTestingModule({\n * imports: [MyModule],\n * })\n * .overrideProvider(ABSTRACT_TOKEN)\n * .useExisting(ConcreteService)\n * .compile()\n * ```\n */\n useExisting(existingToken: InjectionToken<T>): TestingModuleBuilder {\n return this.parent.addProviderOverride({\n token: this.token,\n type: 'existing',\n implementation: existingToken,\n })\n }\n}\n","/**\n * Base error class for all test framework errors.\n * Extends from Error and allows easy identification via `instanceof`.\n */\nexport class TestError extends Error {\n constructor(\n message: string,\n public readonly cause?: Error\n ) {\n super(message)\n this.name = 'TestError'\n\n // Maintain proper stack trace\n Error.captureStackTrace(this, this.constructor)\n }\n}\n","import { TestError } from './test-error'\n\n/**\n * Error thrown when test setup fails.\n * Examples: schema creation failure, migration failure, application bootstrap failure.\n */\nexport class TestSetupError extends TestError {\n constructor(message: string, cause?: Error) {\n super(`Test setup failed: ${message}`, cause)\n }\n}\n","import type { DetectionStrategy, I18nModuleOptions } from 'stratal/i18n'\nimport { I18N_TOKENS } from 'stratal/i18n'\nimport type { TestingModule } from '../testing-module'\n\n/**\n * Resolve the configured detection strategy from the testing module's DI container.\n * Falls back to 'cookie' if I18n is not configured.\n */\nexport function resolveLocaleStrategy(module: TestingModule): DetectionStrategy {\n try {\n const options = module.get<I18nModuleOptions>(I18N_TOKENS.Options)\n const detection = options.detection\n if (detection && 'strategy' in detection && detection.strategy) {\n return detection.strategy\n }\n return 'cookie'\n } catch {\n return 'cookie'\n }\n}\n\n/**\n * Apply locale to request headers based on detection strategy.\n */\nexport function applyLocaleToHeaders(\n headers: Headers,\n locale: string,\n strategy: DetectionStrategy,\n): void {\n switch (strategy) {\n case 'cookie':\n headers.set('Cookie', `locale=${locale}`)\n break\n case 'header':\n headers.set('Accept-Language', locale)\n break\n }\n}\n\n/**\n * Apply locale to URL based on detection strategy.\n */\nexport function applyLocaleToUrl(\n url: URL,\n locale: string,\n strategy: DetectionStrategy,\n): void {\n if (strategy === 'querystring') {\n url.searchParams.set('locale', locale)\n }\n}\n","import { runWithEndpointContext } from '@better-auth/core/context'\nimport type { AuthService } from '@stratal/framework/auth'\nimport { type GenericEndpointContext } from 'better-auth'\nimport { setSessionCookie } from 'better-auth/cookies'\nimport { convertSetCookieToCookie } from 'better-auth/test'\n\nasync function makeSignature(value: string, secret: string): Promise<string> {\n const algorithm = { name: 'HMAC', hash: 'SHA-256' }\n const secretBuf = new TextEncoder().encode(secret)\n const key = await crypto.subtle.importKey('raw', secretBuf, algorithm, false, ['sign'])\n const signature = await crypto.subtle.sign(algorithm.name, key, new TextEncoder().encode(value))\n return btoa(String.fromCharCode(...new Uint8Array(signature)))\n}\n\nfunction buildCookieString(name: string, value: string, options: Record<string, unknown> = {}): string {\n const encodedValue = encodeURIComponent(value)\n let str = `${name}=${encodedValue}`\n if (options.path) str += `; Path=${options.path as string}`\n if (options.httpOnly) str += '; HttpOnly'\n if (options.secure) str += '; Secure'\n if (options.sameSite) str += `; SameSite=${options.sameSite as string}`\n if (options.maxAge !== undefined) str += `; Max-Age=${Math.floor(options.maxAge as number)}`\n return str\n}\n\n/**\n * ActingAs\n *\n * Creates authentication sessions for testing.\n * Uses Better Auth's internalAdapter to create real database sessions.\n *\n * @example\n * ```typescript\n * const actingAs = new ActingAs(authService)\n * const headers = await actingAs.createSessionForUser({ id: 'user-123' })\n * ```\n */\nexport class ActingAs {\n constructor(private readonly authService: AuthService) { }\n\n async createSessionForUser(user: { id: string }): Promise<Headers> {\n const auth = this.authService.auth\n const ctx = await auth.$context\n\n const secret = ctx.secret\n\n // Mirror production: session writes always happen inside a Better Auth\n // endpoint, so database hooks receive the endpoint context (e.g. for\n // internalAdapter lookups).\n const session = await runWithEndpointContext(\n { context: ctx },\n () =>\n ctx.internalAdapter.createSession(\n user.id,\n undefined,\n { ipAddress: '127.0.0.1', userAgent: 'test-client' }\n )\n )\n\n const dbUser = await ctx.internalAdapter.findUserById(user.id)\n if (!dbUser) {\n throw new Error(`User not found: ${user.id}`)\n }\n\n const responseHeaders = new Headers()\n const mockCtx = {\n context: ctx,\n getSignedCookie: () => null,\n setSignedCookie: async (name: string, value: string, _secret: string, options: Record<string, unknown> = {}) => {\n const signature = await makeSignature(value, secret)\n const signedValue = `${value}.${signature}`\n responseHeaders.append('Set-Cookie', buildCookieString(name, signedValue, options))\n },\n setCookie: (name: string, value: string, options: Record<string, unknown> = {}) => {\n responseHeaders.append('Set-Cookie', buildCookieString(name, value, options))\n },\n }\n\n await setSessionCookie(mockCtx as unknown as GenericEndpointContext, { session, user: dbUser }, false)\n return convertSetCookieToCookie(responseHeaders)\n }\n}\n","/**\n * Get value at dot-notation path.\n */\nexport function getValueAtPath(obj: unknown, path: string): unknown {\n const parts = path.split('.')\n let current: unknown = obj\n\n for (const part of parts) {\n if (current === null || current === undefined) {\n return undefined\n }\n current = (current as Record<string, unknown>)[part]\n }\n\n return current\n}\n\n/**\n * Check if a path exists in the object (even if value is null/undefined).\n */\nexport function hasValueAtPath(obj: unknown, path: string): boolean {\n const parts = path.split('.')\n let current: unknown = obj\n\n for (const part of parts) {\n if (current === null || current === undefined) {\n return false\n }\n\n if (typeof current !== 'object') {\n return false\n }\n\n const record = current as Record<string, unknown>\n\n if (!(part in record)) {\n return false\n }\n\n current = record[part]\n }\n\n return true\n}\n","import { Macroable } from 'stratal/macroable'\nimport { expect } from 'vitest'\nimport { getValueAtPath, hasValueAtPath } from './path-utils'\n\n/**\n * TestResponse\n *\n * Wrapper around Response with assertion methods.\n *\n * @example\n * ```typescript\n * response\n * .assertOk()\n * .assertStatus(200)\n * .assertJsonPath('data.id', userId)\n * ```\n */\nexport class TestResponse extends Macroable {\n private jsonData: unknown = null\n private textData: string | null = null\n\n constructor(private readonly response: Response) {\n super()\n }\n\n /**\n * Get the raw Response object.\n */\n get raw(): Response {\n return this.response\n }\n\n /**\n * Get the response status code.\n */\n get status(): number {\n return this.response.status\n }\n\n /**\n * Get response headers.\n */\n get headers(): Headers {\n return this.response.headers\n }\n\n /**\n * Get the response body as JSON.\n */\n async json<T = unknown>(): Promise<T> {\n if (this.jsonData === null) {\n this.jsonData = await this.response.clone().json()\n }\n return this.jsonData as T\n }\n\n /**\n * Get the response body as text.\n */\n async text(): Promise<string> {\n this.textData ??= await this.response.clone().text()\n return this.textData\n }\n\n // ============================================================\n // Status Assertions\n // ============================================================\n\n /**\n * Assert response status is 200 OK.\n */\n assertOk(): this {\n return this.assertStatus(200)\n }\n\n /**\n * Assert response status is 201 Created.\n */\n assertCreated(): this {\n return this.assertStatus(201)\n }\n\n /**\n * Assert response status is 204 No Content.\n */\n assertNoContent(): this {\n return this.assertStatus(204)\n }\n\n /**\n * Assert response status is 400 Bad Request.\n */\n assertBadRequest(): this {\n return this.assertStatus(400)\n }\n\n /**\n * Assert response status is 401 Unauthorized.\n */\n assertUnauthorized(): this {\n return this.assertStatus(401)\n }\n\n /**\n * Assert response status is 403 Forbidden.\n */\n assertForbidden(): this {\n return this.assertStatus(403)\n }\n\n /**\n * Assert response status is 404 Not Found.\n */\n assertNotFound(): this {\n return this.assertStatus(404)\n }\n\n /**\n * Assert response status is 422 Unprocessable Entity.\n */\n assertUnprocessable(): this {\n return this.assertStatus(422)\n }\n\n /**\n * Assert response status is 500 Internal Server Error.\n */\n assertServerError(): this {\n return this.assertStatus(500)\n }\n\n /**\n * Assert response has the given status code.\n */\n assertStatus(expected: number): this {\n expect(\n this.response.status,\n `Expected status ${expected}, got ${this.response.status}`\n ).toBe(expected)\n return this\n }\n\n /**\n * Assert response status is in the 2xx success range.\n */\n assertSuccessful(): this {\n expect(\n this.response.status >= 200 && this.response.status < 300,\n `Expected successful status (2xx), got ${this.response.status}`\n ).toBe(true)\n return this\n }\n\n // ============================================================\n // JSON Assertions\n // ============================================================\n\n /**\n * Assert JSON response contains the given data.\n */\n async assertJson(expected: Record<string, unknown>): Promise<this> {\n const actual = await this.json<Record<string, unknown>>()\n\n for (const [key, value] of Object.entries(expected)) {\n expect(\n actual[key],\n `Expected JSON key \"${key}\" to be ${JSON.stringify(value)}, got ${JSON.stringify(actual[key])}`\n ).toStrictEqual(value)\n }\n\n return this\n }\n\n /**\n * Assert JSON response has value at the given path.\n *\n * @param path - Dot-notation path (e.g., 'data.user.id')\n * @param expected - Expected value at path\n */\n async assertJsonPath(path: string, expected: unknown): Promise<this> {\n const json = await this.json()\n const actual = getValueAtPath(json, path)\n\n expect(\n actual,\n `Expected JSON path \"${path}\" to be ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`\n ).toStrictEqual(expected)\n\n return this\n }\n\n /**\n * Assert JSON response structure matches the given schema.\n */\n async assertJsonStructure(structure: string[]): Promise<this> {\n const json = await this.json<Record<string, unknown>>()\n\n for (const key of structure) {\n expect(\n key in json,\n `Expected JSON to have key \"${key}\", got keys: ${JSON.stringify(Object.keys(json))}`\n ).toBe(true)\n }\n\n return this\n }\n\n /**\n * Assert a JSON path exists (value can be anything, including null).\n *\n * @param path - Dot-notation path (e.g., 'data.user.id')\n */\n async assertJsonPathExists(path: string): Promise<this> {\n const json = await this.json()\n const exists = hasValueAtPath(json, path)\n\n expect(\n exists,\n `Expected JSON path \"${path}\" to exist`\n ).toBe(true)\n\n return this\n }\n\n /**\n * Assert a JSON path does not exist.\n *\n * @param path - Dot-notation path (e.g., 'data.user.deletedAt')\n */\n async assertJsonPathMissing(path: string): Promise<this> {\n const json = await this.json()\n const exists = hasValueAtPath(json, path)\n\n expect(\n exists,\n `Expected JSON path \"${path}\" to not exist`\n ).toBe(false)\n\n return this\n }\n\n /**\n * Assert JSON value at path matches a custom predicate.\n *\n * @param path - Dot-notation path (e.g., 'data.items')\n * @param matcher - Predicate function to validate the value\n */\n async assertJsonPathMatches(\n path: string,\n matcher: (value: unknown) => boolean\n ): Promise<this> {\n const json = await this.json()\n const value = getValueAtPath(json, path)\n\n expect(\n matcher(value),\n `Expected JSON path \"${path}\" to match predicate, got ${JSON.stringify(value)}`\n ).toBe(true)\n\n return this\n }\n\n /**\n * Assert string value at path contains a substring.\n *\n * @param path - Dot-notation path (e.g., 'data.message')\n * @param substring - Substring to search for\n */\n async assertJsonPathContains(path: string, substring: string): Promise<this> {\n const json = await this.json()\n const value = getValueAtPath(json, path)\n\n expect(\n typeof value === 'string',\n `Expected JSON path \"${path}\" to be a string, got ${typeof value}`\n ).toBe(true)\n\n expect(\n (value as string).includes(substring),\n `Expected JSON path \"${path}\" to contain \"${substring}\", got \"${String(value)}\"`\n ).toBe(true)\n\n return this\n }\n\n /**\n * Assert array value at path includes a specific item.\n *\n * @param path - Dot-notation path (e.g., 'data.tags')\n * @param item - Item to search for in the array\n */\n async assertJsonPathIncludes(path: string, item: unknown): Promise<this> {\n const json = await this.json()\n const value = getValueAtPath(json, path)\n\n expect(\n Array.isArray(value),\n `Expected JSON path \"${path}\" to be an array, got ${typeof value}`\n ).toBe(true)\n\n expect(\n (value as unknown[]).includes(item),\n `Expected JSON path \"${path}\" to include ${JSON.stringify(item)}`\n ).toBe(true)\n\n return this\n }\n\n /**\n * Assert array length at path equals the expected count.\n *\n * @param path - Dot-notation path (e.g., 'data.items')\n * @param count - Expected array length\n */\n async assertJsonPathCount(path: string, count: number): Promise<this> {\n const json = await this.json()\n const value = getValueAtPath(json, path)\n\n expect(\n Array.isArray(value),\n `Expected JSON path \"${path}\" to be an array, got ${typeof value}`\n ).toBe(true)\n\n expect(\n (value as unknown[]).length,\n `Expected JSON path \"${path}\" to have ${count} items, got ${(value as unknown[]).length}`\n ).toBe(count)\n\n return this\n }\n\n /**\n * Assert multiple JSON paths at once (batch assertion).\n *\n * @param expectations - Object mapping paths to expected values\n */\n async assertJsonPaths(expectations: Record<string, unknown>): Promise<this> {\n const json = await this.json()\n\n for (const [path, expected] of Object.entries(expectations)) {\n const actual = getValueAtPath(json, path)\n expect(\n actual,\n `Expected JSON path \"${path}\" to be ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`\n ).toStrictEqual(expected)\n }\n\n return this\n }\n\n // ============================================================\n // Header Assertions\n // ============================================================\n\n /**\n * Assert response has the given header.\n */\n assertHeader(name: string, expected?: string): this {\n const actual = this.response.headers.get(name)\n\n expect(\n actual !== null,\n `Expected header \"${name}\" to be present`\n ).toBe(true)\n\n if (expected !== undefined) {\n expect(\n actual,\n `Expected header \"${name}\" to be \"${expected}\", got \"${actual}\"`\n ).toBe(expected)\n }\n\n return this\n }\n\n /**\n * Assert response does not have the given header.\n */\n assertHeaderMissing(name: string): this {\n const actual = this.response.headers.get(name)\n\n expect(\n actual,\n `Expected header \"${name}\" to be absent, but got \"${actual}\"`\n ).toBeNull()\n\n return this\n }\n\n}\n","import type { AuthService } from '@stratal/framework/auth'\nimport { AUTH_SERVICE } from '@stratal/framework/auth'\nimport type { DetectionStrategy } from 'stratal/i18n'\nimport { Macroable } from 'stratal/macroable'\nimport { ActingAs } from '../../auth'\nimport type { TestingModule } from '../testing-module'\nimport { applyLocaleToHeaders, applyLocaleToUrl, resolveLocaleStrategy } from './locale-helper'\nimport { TestResponse } from './test-response'\n\n/**\n * TestHttpRequest\n *\n * Request builder with fluent API for configuring test HTTP requests.\n *\n * @example\n * ```typescript\n * const response = await module.http\n * .post('/api/v1/register')\n * .withBody({ name: 'Test School' })\n * .withHeaders({ 'X-Custom': 'value' })\n * .send()\n * ```\n *\n * @example Authenticated request\n * ```typescript\n * const response = await module.http\n * .get('/api/v1/profile')\n * .actingAs({ id: user.id })\n * .send()\n * ```\n */\nexport class TestHttpRequest extends Macroable {\n\tprotected body: unknown = null\n\tprotected requestHeaders: Headers\n\tprotected actingAsUser: { id: string } | null = null\n\tprotected authResolver: ((module: TestingModule, user: { id: string }) => Promise<Headers>) | null = null\n\tprotected localeConfig: { locale: string; strategy: DetectionStrategy } | null\n\n\tconstructor(\n\t\tprotected readonly method: string,\n\t\tprotected readonly path: string,\n\t\theaders: Headers,\n\t\tprotected readonly module: TestingModule,\n\t\tprotected readonly host: string | null = null,\n\t\tlocaleConfig: { locale: string; strategy: DetectionStrategy } | null = null,\n\t) {\n\t\tsuper()\n\t\tthis.requestHeaders = new Headers(headers)\n\t\tthis.localeConfig = localeConfig\n\t}\n\n\t/**\n\t * Set the request body\n\t */\n\twithBody(data: unknown): this {\n\t\tthis.body = data\n\t\treturn this\n\t}\n\n\t/**\n\t * Add headers to the request\n\t */\n\twithHeaders(headers: Record<string, string>): this {\n\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\tthis.requestHeaders.set(key, value)\n\t\t}\n\t\treturn this\n\t}\n\n\t/**\n\t * Set the locale for this request.\n\t * If strategy is not provided, resolves from the module's I18n configuration.\n\t *\n\t * @param locale - Locale code (e.g., 'en', 'fr')\n\t * @param strategy - Detection strategy override\n\t */\n\twithLocale(locale: string, strategy?: DetectionStrategy): this {\n\t\tconst resolved = strategy ?? resolveLocaleStrategy(this.module)\n\t\tthis.localeConfig = { locale, strategy: resolved }\n\t\tapplyLocaleToHeaders(this.requestHeaders, locale, resolved)\n\t\treturn this\n\t}\n\n\t/**\n\t * Set Content-Type to application/json\n\t */\n\tasJson(): this {\n\t\tthis.requestHeaders.set('Content-Type', 'application/json')\n\t\treturn this\n\t}\n\n\t/**\n\t * Authenticate the request as a specific user\n\t */\n\tactingAs(user: { id: string }): this {\n\t\tthis.actingAsUser = user\n\t\tthis.authResolver = null\n\t\treturn this\n\t}\n\n\t/**\n\t * Send the request and return response\n\t *\n\t * Calls module.fetch() - NOT SELF.fetch()\n\t */\n\tasync send(): Promise<TestResponse> {\n\t\tawait this.applyAuthentication()\n\n\t\t// Auto-set Content-Type for body\n\t\tif (this.body && !this.requestHeaders.has('Content-Type')) {\n\t\t\tthis.requestHeaders.set('Content-Type', 'application/json')\n\t\t}\n\n\t\t// Build request\n\t\tconst url = new URL(this.path, `http://${this.host ?? 'localhost'}`)\n\n\t\t// Apply locale to URL for querystring strategy\n\t\tif (this.localeConfig) {\n\t\t\tapplyLocaleToUrl(url, this.localeConfig.locale, this.localeConfig.strategy)\n\t\t}\n\n\t\tconst request = new Request(url.toString(), {\n\t\t\tmethod: this.method,\n\t\t\theaders: this.requestHeaders,\n\t\t\tbody: this.body ? JSON.stringify(this.body) : null,\n\t\t})\n\n\t\t// Call module.fetch() - NO SELF.fetch()\n\t\tconst response = await this.module.fetch(request)\n\t\treturn new TestResponse(response)\n\t}\n\n\tprotected async applyAuthentication(): Promise<void> {\n\t\tif (!this.actingAsUser) return\n\n\t\tif (this.authResolver) {\n\t\t\tconst headers = await this.authResolver(this.module, this.actingAsUser)\n\t\t\tfor (const [key, value] of headers.entries()) {\n\t\t\t\tthis.requestHeaders.set(key, value)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tawait this.module.runInRequestScope(async () => {\n\t\t\tconst authService = this.module.get<AuthService>(AUTH_SERVICE)\n\t\t\tconst actingAs = new ActingAs(authService)\n\t\t\tconst authHeaders = await actingAs.createSessionForUser(this.actingAsUser!)\n\n\t\t\tfor (const [key, value] of authHeaders.entries()) {\n\t\t\t\tthis.requestHeaders.set(key, value)\n\t\t\t}\n\t\t})\n\t}\n}\n","import type { DetectionStrategy } from 'stratal/i18n'\nimport type { TestingModule } from '../testing-module'\nimport { applyLocaleToHeaders, resolveLocaleStrategy } from './locale-helper'\nimport { TestHttpRequest } from './test-http-request'\n\n/**\n * TestHttpClient\n *\n * Fluent HTTP client for making test requests.\n *\n * @example\n * ```typescript\n * const response = await module.http\n * .forHost('example.com')\n * .post('/api/v1/users')\n * .withBody({ name: 'Test' })\n * .send()\n *\n * response.assertCreated()\n * ```\n */\nexport class TestHttpClient {\n private defaultHeaders: Headers\n private host: string | null\n private localeConfig: { locale: string; strategy: DetectionStrategy } | null\n\n constructor(\n private readonly module: TestingModule,\n host: string | null = null,\n headers: Headers = new Headers(),\n localeConfig: { locale: string; strategy: DetectionStrategy } | null = null,\n ) {\n this.host = host\n this.defaultHeaders = headers\n this.localeConfig = localeConfig\n }\n\n /**\n * Set the host for the request (returns a new client).\n * Also sets the Host header to ensure domain routing works\n * even when the runtime reads the header instead of the URL host.\n */\n forHost(host: string): TestHttpClient {\n const newHeaders = new Headers(this.defaultHeaders)\n newHeaders.set('Host', host)\n return new TestHttpClient(this.module, host, newHeaders, this.localeConfig)\n }\n\n /**\n * Set default headers for all requests (returns a new client)\n */\n withHeaders(headers: Record<string, string>): TestHttpClient {\n const newHeaders = new Headers(this.defaultHeaders)\n for (const [key, value] of Object.entries(headers)) {\n newHeaders.set(key, value)\n }\n return new TestHttpClient(this.module, this.host, newHeaders, this.localeConfig)\n }\n\n /**\n * Set the locale for all requests from this client (returns a new client).\n * If strategy is not provided, resolves from the module's I18n configuration.\n *\n * @param locale - Locale code (e.g., 'en', 'fr')\n * @param strategy - Detection strategy override\n */\n withLocale(locale: string, strategy?: DetectionStrategy): TestHttpClient {\n const resolved = strategy ?? resolveLocaleStrategy(this.module)\n const newHeaders = new Headers(this.defaultHeaders)\n applyLocaleToHeaders(newHeaders, locale, resolved)\n return new TestHttpClient(this.module, this.host, newHeaders, { locale, strategy: resolved })\n }\n\n /**\n * Create a GET request\n */\n get(path: string): TestHttpRequest {\n return this.createRequest('GET', path)\n }\n\n /**\n * Create a POST request\n */\n post(path: string): TestHttpRequest {\n return this.createRequest('POST', path)\n }\n\n /**\n * Create a PUT request\n */\n put(path: string): TestHttpRequest {\n return this.createRequest('PUT', path)\n }\n\n /**\n * Create a PATCH request\n */\n patch(path: string): TestHttpRequest {\n return this.createRequest('PATCH', path)\n }\n\n /**\n * Create a DELETE request\n */\n delete(path: string): TestHttpRequest {\n return this.createRequest('DELETE', path)\n }\n\n private createRequest(method: string, path: string): TestHttpRequest {\n return new TestHttpRequest(method, path, this.defaultHeaders, this.module, this.host, this.localeConfig)\n }\n}\n","import type { CommandResult } from 'stratal/quarry'\nimport { expect } from 'vitest'\n\n/**\n * Fluent assertion wrapper for command results.\n *\n * @example\n * ```typescript\n * const result = await module\n * .quarry('users:create')\n * .withInput({ email: 'test@example.com' })\n * .run()\n *\n * result.assertSuccessful()\n * result.assertOutputContains('User created')\n * ```\n */\nexport class TestCommandResult {\n constructor(private readonly result: CommandResult) {}\n\n get exitCode(): number {\n return this.result.exitCode\n }\n\n get output(): string[] {\n return this.result.output\n }\n\n get errors(): string[] {\n return this.result.errors\n }\n\n assertSuccessful(): this {\n expect(this.result.exitCode, `Expected exit code 0, got ${this.result.exitCode}. Errors: ${this.result.errors.join(', ')}`).toBe(0)\n expect(this.result.errors, 'Expected no errors').toHaveLength(0)\n return this\n }\n\n assertFailed(exitCode?: number): this {\n if (exitCode !== undefined) {\n expect(this.result.exitCode, `Expected exit code ${exitCode}, got ${this.result.exitCode}`).toBe(exitCode)\n } else {\n expect(this.result.exitCode, 'Expected non-zero exit code').not.toBe(0)\n }\n return this\n }\n\n assertExitCode(code: number): this {\n expect(this.result.exitCode, `Expected exit code ${code}, got ${this.result.exitCode}`).toBe(code)\n return this\n }\n\n assertOutputContains(text: string): this {\n const joined = this.result.output.join('\\n')\n expect(joined, `Expected output to contain \"${text}\"`).toContain(text)\n return this\n }\n\n assertOutputMissing(text: string): this {\n const joined = this.result.output.join('\\n')\n expect(joined, `Expected output NOT to contain \"${text}\"`).not.toContain(text)\n return this\n }\n\n assertErrorContains(text: string): this {\n const joined = this.result.errors.join('\\n')\n expect(joined, `Expected errors to contain \"${text}\"`).toContain(text)\n return this\n }\n\n assertErrorMissing(text: string): this {\n const joined = this.result.errors.join('\\n')\n expect(joined, `Expected errors NOT to contain \"${text}\"`).not.toContain(text)\n return this\n }\n}\n","import type { CommandInput } from 'stratal/quarry'\nimport type { TestingModule } from '../testing-module'\nimport { TestCommandResult } from './test-command-result'\n\n/**\n * Fluent builder for testing Quarry commands.\n *\n * @example\n * ```typescript\n * const result = await module\n * .quarry('users:create')\n * .withInput({ email: 'test@example.com', admin: true })\n * .run()\n *\n * result.assertSuccessful()\n * result.assertOutputContains('User created')\n * ```\n */\nexport class TestCommandRequest {\n private _input: CommandInput = {}\n\n constructor(\n private readonly commandName: string,\n private readonly module: TestingModule,\n ) {}\n\n /**\n * Set the flat input for the command.\n */\n withInput(input: CommandInput): this {\n this._input = { ...input }\n return this\n }\n\n /**\n * Execute the command and return a TestCommandResult for assertions.\n */\n async run(): Promise<TestCommandResult> {\n const result = await this.module.application.handleCommand(this.commandName, this._input)\n return new TestCommandResult(result)\n }\n}\n","import { expect } from \"vitest\"\n\n/**\n * Represents a parsed SSE event\n */\nexport interface TestSseEvent {\n\tdata: string\n\tevent?: string\n\tid?: string\n\tretry?: number\n}\n\n/**\n * TestSseConnection\n *\n * Live SSE connection wrapper with assertion helpers for testing.\n *\n * @example\n * ```typescript\n * const sse = await module.sse('/streaming/sse').connect()\n * await sse.assertEvent({ event: 'message', data: 'hello', id: '1' })\n * await sse.waitForEnd()\n * ```\n */\nexport class TestSseConnection {\n\tprivate readonly eventQueue: TestSseEvent[] = []\n\tprivate eventWaiters: ((event: TestSseEvent) => void)[] = []\n\tprivate streamEnded = false\n\tprivate endWaiters: (() => void)[] = []\n\n\tconstructor(private readonly response: Response) {\n\t\tthis.startReading()\n\t}\n\n\t/**\n\t * Wait for the next SSE event\n\t */\n\tasync waitForEvent(timeout = 5000): Promise<TestSseEvent> {\n\t\tif (this.eventQueue.length > 0) {\n\t\t\treturn this.eventQueue.shift()!\n\t\t}\n\n\t\tif (this.streamEnded) {\n\t\t\tthrow new Error('SSE: stream has ended, no more events')\n\t\t}\n\n\t\treturn new Promise<TestSseEvent>((resolve, reject) => {\n\t\t\tconst waiter = (event: TestSseEvent) => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tresolve(event)\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst index = this.eventWaiters.indexOf(waiter)\n\t\t\t\tif (index !== -1) this.eventWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`SSE: no event received within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\tthis.eventWaiters.push(waiter)\n\t\t})\n\t}\n\n\t/**\n\t * Wait for the stream to end\n\t */\n\tasync waitForEnd(timeout = 5000): Promise<void> {\n\t\tif (this.streamEnded) return\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst waiter = () => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tresolve()\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst index = this.endWaiters.indexOf(waiter)\n\t\t\t\tif (index !== -1) this.endWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`SSE: stream did not end within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\tthis.endWaiters.push(waiter)\n\t\t})\n\t}\n\n\t/**\n\t * Collect all remaining events until the stream ends\n\t */\n\tasync collectEvents(timeout = 5000): Promise<TestSseEvent[]> {\n\t\tconst events: TestSseEvent[] = []\n\n\t\tif (this.streamEnded) {\n\t\t\treturn [...this.eventQueue.splice(0)]\n\t\t}\n\n\t\treturn new Promise<TestSseEvent[]>((resolve, reject) => {\n\t\t\t// Listen for new events until stream ends\n\t\t\tconst originalDispatch = this.dispatchEvent.bind(this)\n\t\t\tthis.dispatchEvent = (event: TestSseEvent) => {\n\t\t\t\tevents.push(event)\n\t\t\t\toriginalDispatch(event)\n\t\t\t}\n\n\t\t\tconst endWaiter = () => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tthis.dispatchEvent = originalDispatch\n\t\t\t\tresolve(events)\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.dispatchEvent = originalDispatch\n\t\t\t\tconst index = this.endWaiters.indexOf(endWaiter)\n\t\t\t\tif (index !== -1) this.endWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`SSE: stream did not end within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\t// Drain any queued events first\n\t\t\tevents.push(...this.eventQueue.splice(0))\n\n\t\t\tthis.endWaiters.push(endWaiter)\n\t\t})\n\t}\n\n\t/**\n\t * Assert that the next event matches the expected partial shape\n\t */\n\tasync assertEvent(expected: Partial<TestSseEvent>, timeout = 5000): Promise<void> {\n\t\tconst event = await this.waitForEvent(timeout)\n\t\texpect(event).toMatchObject(expected)\n\t}\n\n\t/**\n\t * Assert that the next event's data matches the expected string\n\t */\n\tasync assertEventData(expected: string, timeout = 5000): Promise<void> {\n\t\tconst event = await this.waitForEvent(timeout)\n\t\texpect(event.data, `Expected SSE data \"${expected}\", got \"${event.data}\"`).toBe(expected)\n\t}\n\n\t/**\n\t * Assert that the next event's data is JSON matching the expected value\n\t */\n\tasync assertJsonEventData<T>(expected: T, timeout = 5000): Promise<void> {\n\t\tconst event = await this.waitForEvent(timeout)\n\t\tconst parsed = JSON.parse(event.data) as unknown\n\t\texpect(parsed).toEqual(expected)\n\t}\n\n\t/**\n\t * Access the raw Response\n\t */\n\tget raw(): Response {\n\t\treturn this.response\n\t}\n\n\tprivate startReading(): void {\n\t\tconst body = this.response.body\n\t\tif (!body) {\n\t\t\tthis.streamEnded = true\n\t\t\treturn\n\t\t}\n\n\t\tconst reader = body.getReader() as ReadableStreamDefaultReader<Uint8Array>\n\t\tconst decoder = new TextDecoder()\n\t\tlet buffer = ''\n\n\t\tconst read = async (): Promise<void> => {\n\t\t\ttry {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\t\t\t\twhile (true) {\n\t\t\t\t\tconst { done, value } = await reader.read()\n\n\t\t\t\t\tif (done) {\n\t\t\t\t\t\t// Parse any remaining buffered data\n\t\t\t\t\t\tif (buffer.trim()) {\n\t\t\t\t\t\t\tconst event = this.parseEvent(buffer)\n\t\t\t\t\t\t\tif (event) this.dispatchEvent(event)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.streamEnded = true\n\t\t\t\t\t\tfor (const waiter of this.endWaiters) {\n\t\t\t\t\t\t\twaiter()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.endWaiters = []\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tbuffer += decoder.decode(value, { stream: true })\n\n\t\t\t\t\t// Split on double newlines (SSE event boundary)\n\t\t\t\t\tconst parts = buffer.split('\\n\\n')\n\t\t\t\t\t// Last part may be incomplete, keep it in the buffer\n\t\t\t\t\tbuffer = parts.pop()!\n\n\t\t\t\t\tfor (const part of parts) {\n\t\t\t\t\t\tif (!part.trim()) continue\n\t\t\t\t\t\tconst event = this.parseEvent(part)\n\t\t\t\t\t\tif (event) this.dispatchEvent(event)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tthis.streamEnded = true\n\t\t\t\tfor (const waiter of this.endWaiters) {\n\t\t\t\t\twaiter()\n\t\t\t\t}\n\t\t\t\tthis.endWaiters = []\n\t\t\t}\n\t\t}\n\n\t\tvoid read()\n\t}\n\n\tprivate parseEvent(raw: string): TestSseEvent | null {\n\t\tconst lines = raw.split('\\n')\n\t\tconst dataLines: string[] = []\n\t\tlet event: string | undefined\n\t\tlet id: string | undefined\n\t\tlet retry: number | undefined\n\n\t\tfor (const line of lines) {\n\t\t\tif (line.startsWith(':')) continue // comment line\n\n\t\t\tconst colonIndex = line.indexOf(':')\n\t\t\tif (colonIndex === -1) continue\n\n\t\t\tconst field = line.slice(0, colonIndex)\n\t\t\t// Strip optional leading space after colon\n\t\t\tconst value = line[colonIndex + 1] === ' ' ? line.slice(colonIndex + 2) : line.slice(colonIndex + 1)\n\n\t\t\tswitch (field) {\n\t\t\t\tcase 'data':\n\t\t\t\t\tdataLines.push(value)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'event':\n\t\t\t\t\tevent = value\n\t\t\t\t\tbreak\n\t\t\t\tcase 'id':\n\t\t\t\t\tid = value\n\t\t\t\t\tbreak\n\t\t\t\tcase 'retry': {\n\t\t\t\t\tconst parsed = parseInt(value, 10)\n\t\t\t\t\tif (!isNaN(parsed)) retry = parsed\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (dataLines.length === 0) return null\n\n\t\tconst result: TestSseEvent = { data: dataLines.join('\\n') }\n\t\tif (event !== undefined) result.event = event\n\t\tif (id !== undefined) result.id = id\n\t\tif (retry !== undefined) result.retry = retry\n\n\t\treturn result\n\t}\n\n\tprivate dispatchEvent(event: TestSseEvent): void {\n\t\tif (this.eventWaiters.length > 0) {\n\t\t\tthis.eventWaiters.shift()!(event)\n\t\t} else {\n\t\t\tthis.eventQueue.push(event)\n\t\t}\n\t}\n}\n","import type { AuthService } from '@stratal/framework/auth'\nimport { AUTH_SERVICE } from '@stratal/framework/auth'\nimport type { DetectionStrategy } from 'stratal/i18n'\nimport { expect } from 'vitest'\nimport { ActingAs } from '../../auth'\nimport type { TestingModule } from '../testing-module'\nimport { applyLocaleToHeaders, resolveLocaleStrategy } from '../http/locale-helper'\nimport { TestSseConnection } from './test-sse-connection'\n\n/**\n * TestSseRequest\n *\n * Builder for SSE connection requests. Follows the TestWsRequest pattern.\n *\n * @example\n * ```typescript\n * const sse = await module.sse('/streaming/sse').connect()\n * await sse.assertEvent({ event: 'message', data: 'hello' })\n * await sse.waitForEnd()\n * ```\n *\n * @example Authenticated SSE\n * ```typescript\n * const sse = await module.sse('/streaming/sse').actingAs({ id: user.id }).connect()\n * ```\n */\nexport class TestSseRequest {\n\tprivate requestHeaders: Headers = new Headers()\n\tprivate actingAsUser: { id: string } | null = null\n\n\tconstructor(\n\t\tprivate readonly path: string,\n\t\tprivate readonly module: TestingModule,\n\t) { }\n\n\t/**\n\t * Add custom headers to the request\n\t */\n\twithHeaders(headers: Record<string, string>): this {\n\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\tthis.requestHeaders.set(key, value)\n\t\t}\n\t\treturn this\n\t}\n\n\t/**\n\t * Set the locale for this SSE connection.\n\t * If strategy is not provided, resolves from the module's I18n configuration.\n\t */\n\twithLocale(locale: string, strategy?: DetectionStrategy): this {\n\t\tconst resolved = strategy ?? resolveLocaleStrategy(this.module)\n\t\tapplyLocaleToHeaders(this.requestHeaders, locale, resolved)\n\t\treturn this\n\t}\n\n\t/**\n\t * Authenticate the SSE connection as a specific user\n\t */\n\tactingAs(user: { id: string }): this {\n\t\tthis.actingAsUser = user\n\t\treturn this\n\t}\n\n\t/**\n\t * Send the request and return a live SSE connection\n\t */\n\tasync connect(): Promise<TestSseConnection> {\n\t\tawait this.applyAuthentication()\n\n\t\tthis.requestHeaders.set('Accept', 'text/event-stream')\n\n\t\tconst url = new URL(this.path, 'http://localhost')\n\t\tconst request = new Request(url.toString(), {\n\t\t\theaders: this.requestHeaders,\n\t\t})\n\n\t\tconst response = await this.module.fetch(request)\n\n\t\texpect(\n\t\t\tresponse.status,\n\t\t\t`Expected status 200, got ${response.status}`,\n\t\t).toBe(200)\n\n\t\tconst contentType = response.headers.get('content-type') ?? ''\n\t\texpect(\n\t\t\tcontentType.includes('text/event-stream'),\n\t\t\t`Expected content-type \"text/event-stream\", got \"${contentType}\"`,\n\t\t).toBe(true)\n\n\t\treturn new TestSseConnection(response)\n\t}\n\n\tprivate async applyAuthentication(): Promise<void> {\n\t\tif (!this.actingAsUser) return\n\n\t\tawait this.module.runInRequestScope(async () => {\n\t\t\tconst authService = this.module.get<AuthService>(AUTH_SERVICE)\n\t\t\tconst actingAs = new ActingAs(authService)\n\t\t\tconst authHeaders = this.actingAsUser ? await actingAs.createSessionForUser(this.actingAsUser) : new Headers()\n\n\t\t\tfor (const [key, value] of authHeaders.entries()) {\n\t\t\t\tthis.requestHeaders.set(key, value)\n\t\t\t}\n\t\t})\n\t}\n}\n","import { expect } from \"vitest\";\n\n/**\n * TestWsConnection\n *\n * Live WebSocket connection wrapper with assertion helpers for testing.\n *\n * @example\n * ```typescript\n * const ws = await module.ws('/ws/chat').connect()\n * ws.send('hello')\n * await ws.assertMessage('echo:hello')\n * ws.close()\n * await ws.waitForClose()\n * ```\n */\nexport class TestWsConnection {\n\tprivate readonly messageQueue: (string | ArrayBuffer)[] = []\n\tprivate messageWaiters: ((data: string | ArrayBuffer) => void)[] = []\n\tprivate closeEvent: { code?: number; reason?: string } | null = null\n\tprivate closeWaiters: ((event: { code?: number; reason?: string }) => void)[] = []\n\n\tconstructor(private readonly ws: WebSocket) {\n\t\tthis.ws.addEventListener('message', (event: MessageEvent) => {\n\t\t\tconst data = event.data as string | ArrayBuffer\n\t\t\tif (this.messageWaiters.length > 0) {\n\t\t\t\tthis.messageWaiters.shift()!(data)\n\t\t\t} else {\n\t\t\t\tthis.messageQueue.push(data)\n\t\t\t}\n\t\t})\n\n\t\tthis.ws.addEventListener('close', (event: CloseEvent) => {\n\t\t\tthis.closeEvent = { code: event.code, reason: event.reason }\n\t\t\tfor (const waiter of this.closeWaiters) {\n\t\t\t\twaiter(this.closeEvent)\n\t\t\t}\n\t\t\tthis.closeWaiters = []\n\t\t})\n\t}\n\n\t/**\n\t * Send a message through the WebSocket\n\t */\n\tsend(data: string | ArrayBuffer | Uint8Array): void {\n\t\tthis.ws.send(data)\n\t}\n\n\t/**\n\t * Close the WebSocket connection\n\t */\n\tclose(code?: number, reason?: string): void {\n\t\tthis.ws.close(code, reason)\n\t}\n\n\t/**\n\t * Wait for the next message, returning its data\n\t */\n\tasync waitForMessage(timeout = 5000): Promise<string | ArrayBuffer> {\n\t\tif (this.messageQueue.length > 0) {\n\t\t\treturn this.messageQueue.shift()!\n\t\t}\n\n\t\treturn new Promise<string | ArrayBuffer>((resolve, reject) => {\n\t\t\tconst waiter = (data: string | ArrayBuffer) => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tresolve(data)\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst index = this.messageWaiters.indexOf(waiter)\n\t\t\t\tif (index !== -1) this.messageWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`WebSocket: no message received within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\tthis.messageWaiters.push(waiter)\n\t\t})\n\t}\n\n\t/**\n\t * Wait for the connection to close\n\t */\n\tasync waitForClose(timeout = 5000): Promise<{ code?: number; reason?: string }> {\n\t\tif (this.closeEvent) {\n\t\t\treturn this.closeEvent\n\t\t}\n\n\t\treturn new Promise<{ code?: number; reason?: string }>((resolve, reject) => {\n\t\t\tconst waiter = (event: { code?: number; reason?: string }) => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tresolve(event)\n\t\t\t}\n\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst index = this.closeWaiters.indexOf(waiter)\n\t\t\t\tif (index !== -1) this.closeWaiters.splice(index, 1)\n\t\t\t\treject(new Error(`WebSocket: connection did not close within ${timeout}ms`))\n\t\t\t}, timeout)\n\n\t\t\tthis.closeWaiters.push(waiter)\n\t\t})\n\t}\n\n\t/**\n\t * Assert that the next message equals the expected value\n\t */\n\tasync assertMessage(expected: string, timeout = 5000): Promise<void> {\n\t\tconst data = await this.waitForMessage(timeout)\n\t\tconst message = typeof data === 'string' ? data : '[ArrayBuffer]'\n\t\texpect(message, `Expected WebSocket message \"${expected}\", got \"${message}\"`).toBe(expected)\n\t}\n\n\t/**\n\t * Assert that the connection closes, optionally with an expected code\n\t */\n\tasync assertClosed(expectedCode?: number, timeout = 5000): Promise<void> {\n\t\tconst event = await this.waitForClose(timeout)\n\t\tif (expectedCode !== undefined) {\n\t\t\texpect(event.code, `Expected close code ${expectedCode}, got ${event.code}`).toBe(expectedCode)\n\t\t}\n\t}\n\n\t/**\n\t * Access the raw Cloudflare WebSocket\n\t */\n\tget raw(): WebSocket {\n\t\treturn this.ws\n\t}\n}\n","import type { AuthService } from '@stratal/framework/auth'\nimport { AUTH_SERVICE } from '@stratal/framework/auth'\nimport type { DetectionStrategy } from 'stratal/i18n'\nimport { expect } from 'vitest'\nimport { ActingAs } from '../../auth'\nimport type { TestingModule } from '../testing-module'\nimport { applyLocaleToHeaders, resolveLocaleStrategy } from '../http/locale-helper'\nimport { TestWsConnection } from './test-ws-connection'\n\n/**\n * TestWsRequest\n *\n * Builder for WebSocket upgrade requests. Follows the TestHttpRequest pattern.\n *\n * @example\n * ```typescript\n * const ws = await module.ws('/ws/chat').connect()\n * ws.send('hello')\n * await ws.assertMessage('echo:hello')\n * ws.close()\n * ```\n *\n * @example Authenticated WebSocket\n * ```typescript\n * const ws = await module.ws('/ws/chat').actingAs({ id: user.id }).connect()\n * ```\n */\nexport class TestWsRequest {\n\tprivate requestHeaders: Headers = new Headers()\n\tprivate actingAsUser: { id: string } | null = null\n\n\tconstructor(\n\t\tprivate readonly path: string,\n\t\tprivate readonly module: TestingModule,\n\t) { }\n\n\t/**\n\t * Add custom headers to the upgrade request\n\t */\n\twithHeaders(headers: Record<string, string>): this {\n\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\tthis.requestHeaders.set(key, value)\n\t\t}\n\t\treturn this\n\t}\n\n\t/**\n\t * Set the locale for this WebSocket connection.\n\t * If strategy is not provided, resolves from the module's I18n configuration.\n\t */\n\twithLocale(locale: string, strategy?: DetectionStrategy): this {\n\t\tconst resolved = strategy ?? resolveLocaleStrategy(this.module)\n\t\tapplyLocaleToHeaders(this.requestHeaders, locale, resolved)\n\t\treturn this\n\t}\n\n\t/**\n\t * Authenticate the WebSocket connection as a specific user\n\t */\n\tactingAs(user: { id: string }): this {\n\t\tthis.actingAsUser = user\n\t\treturn this\n\t}\n\n\t/**\n\t * Send the upgrade request and return a live WebSocket connection\n\t */\n\tasync connect(): Promise<TestWsConnection> {\n\t\tawait this.applyAuthentication()\n\n\t\tthis.requestHeaders.set('Upgrade', 'websocket')\n\t\tthis.requestHeaders.set('Connection', 'Upgrade')\n\t\tthis.requestHeaders.set('Sec-WebSocket-Key', 'dGhlIHNhbXBsZSBub25jZQ==')\n\t\tthis.requestHeaders.set('Sec-WebSocket-Version', '13')\n\n\t\tconst url = new URL(this.path, 'http://localhost')\n\t\tconst request = new Request(url.toString(), {\n\t\t\theaders: this.requestHeaders,\n\t\t})\n\n\t\tconst response = await this.module.fetch(request)\n\n\t\texpect(\n\t\t\tresponse.status,\n\t\t\t`Expected status 101 (Switching Protocols), got ${response.status}`,\n\t\t).toBe(101)\n\n\t\tconst ws = (response as Response & { webSocket: WebSocket | null }).webSocket\n\t\tif (!ws) {\n\t\t\tthrow new Error('Response did not include a WebSocket connection')\n\t\t}\n\n\t\tws.accept()\n\n\t\treturn new TestWsConnection(ws)\n\t}\n\n\tprivate async applyAuthentication(): Promise<void> {\n\t\tif (!this.actingAsUser) return\n\n\t\tawait this.module.runInRequestScope(async () => {\n\t\t\tconst authService = this.module.get<AuthService>(AUTH_SERVICE)\n\t\t\tconst actingAs = new ActingAs(authService)\n\t\t\tconst authHeaders = this.actingAsUser ? await actingAs.createSessionForUser(this.actingAsUser) : new Headers()\n\n\t\t\tfor (const [key, value] of authHeaders.entries()) {\n\t\t\t\tthis.requestHeaders.set(key, value)\n\t\t\t}\n\t\t})\n\t}\n}\n","import type { ConnectionName, DatabaseService } from '@stratal/framework/database'\nimport { connectionSymbol } from '@stratal/framework/database'\nimport type { Application, Constructor, StratalEnv, StratalExecutionContext } from 'stratal'\nimport { DI_TOKENS, type Container } from 'stratal/di'\nimport type { ResolvedEmailMessage } from 'stratal/email'\nimport { type InjectionToken } from 'stratal/module'\nimport { SEEDER_TOKENS, SeederError, type Seeder, type SeederRegistry } from 'stratal/seeder'\nimport { STORAGE_TOKENS } from 'stratal/storage'\nimport { expect } from 'vitest'\nimport { buildTableDiscoverySql, buildTruncateSql, type ResetOptions } from '../database'\nimport { FEATURE_FLAG_SERVICE_TOKEN, type FakeFeatureFlagService } from '../feature-flags'\nimport type { FakeStorageService } from '../storage'\nimport { TestSetupError } from '../errors'\nimport type { TestEmailProvider } from '../mocks/test-email-provider'\nimport type { TestWorkerExports } from '../mocks/test-worker-exports'\nimport type { TestWorkersCache } from '../mocks/test-workers-cache'\nimport { TestHttpClient } from './http/test-http-client'\nimport { TestCommandRequest } from './quarry/test-command-request'\nimport { TestSseRequest } from './sse/test-sse-request'\nimport { TestWsRequest } from './ws/test-ws-request'\n\n/**\n * TestingModule\n *\n * Provides access to the test application, container, HTTP client, and utilities.\n *\n * @example\n * ```typescript\n * const module = await Test.createTestingModule({\n * modules: [RegistrationModule],\n * }).compile()\n *\n * // Make HTTP requests\n * const response = await module.http\n * .post('/api/v1/register')\n * .withBody({ ... })\n * .send()\n *\n * // Access services\n * const service = module.get(REGISTRATION_TOKENS.RegistrationService)\n *\n * // Database utilities\n * await module.truncateDb()\n * await module.seed(UserSeeder)\n * await module.assertDatabaseHas('user', { email: 'test@example.com' })\n *\n * // Cleanup\n * await module.close()\n * ```\n */\nexport class TestingModule {\n private _http: TestHttpClient | null = null\n private readonly _requestContainer: Container\n\n constructor(\n private readonly app: Application,\n private readonly env: StratalEnv,\n private readonly ctx: StratalExecutionContext,\n private readonly testEmailProvider: TestEmailProvider | null = null,\n private readonly pendingTasks: Promise<unknown>[] = [],\n private readonly testWorkersCache: TestWorkersCache | undefined = undefined,\n private readonly testWorkerExports: TestWorkerExports | undefined = undefined,\n ) {\n const mockContext = this.app.createMockRouterContext()\n this._requestContainer = this.app.container.createRequestScope(mockContext)\n }\n\n /**\n * Emails recorded by the default {@link TestEmailProvider}, in send order.\n * Empty when the email provider factory was overridden.\n */\n get sentEmails(): ResolvedEmailMessage[] {\n return this.testEmailProvider?.sent ?? []\n }\n\n /**\n * Resolve a service from the container\n */\n get<T>(token: InjectionToken<T>): T {\n return this._requestContainer.resolve(token)\n }\n\n /**\n * Get HTTP test client for making requests\n */\n get http(): TestHttpClient {\n this._http ??= new TestHttpClient(this)\n return this._http\n }\n\n\n /**\n * Get Inertia test client for making Inertia requests\n *\n * Sends no `X-Inertia-Version`. It used to send `'1'`, which meant any app configuring a real\n * asset version had every request from this client read as a stale client and answered with a\n * version-mismatch 409 — an entire Inertia suite failing on a value the tests never chose. The\n * check needs a version from BOTH sides, so omitting it here leaves the app under test in charge\n * rather than this header.\n *\n * A test that wants the mismatch path asks for it:\n * `module.inertia.withHeaders({ 'X-Inertia-Version': 'stale' })`.\n */\n get inertia(): TestHttpClient {\n return this.http.withHeaders({ 'X-Inertia': 'true' })\n }\n\n /**\n * Get fake storage service for assertions\n */\n get storage(): FakeStorageService {\n return this.get<FakeStorageService>(STORAGE_TOKENS.StorageService)\n }\n\n /**\n * Get the fake feature-flag service to configure flags in tests\n * (e.g. `module.featureFlags.set('my-flag', true)`).\n */\n get featureFlags(): FakeFeatureFlagService {\n return this.get<FakeFeatureFlagService>(FEATURE_FLAG_SERVICE_TOKEN)\n }\n\n /**\n * The default `ctx.cache` stub — present unless this module was compiled\n * with `cache: false`. Assert `@PurgesCache` routes purged what they should\n * via `module.cache.purges`, in call order.\n *\n * @throws {TestSetupError} This module was compiled with `cache: false`,\n * so there is no stub to inspect.\n */\n get cache(): TestWorkersCache {\n if (!this.testWorkersCache) {\n throw new TestSetupError(\n 'module.cache is unavailable because this module was compiled with `cache: false`. ' +\n 'Remove that option to use the default ctx.cache stub.',\n )\n }\n return this.testWorkersCache\n }\n\n /**\n * The default `ctx.exports` stub — present unless this module was compiled\n * with `cache: false`.\n *\n * Assert which requests the response-cache gateway forwarded to the cached\n * entrypoint, and with which resolved partitions, via\n * `module.gateway.loopbacks` — in call order, mirroring\n * `module.cache.purges`. An empty `loopbacks` is the assertion for every\n * fail-closed case: an unresolved partition, a non-GET, or a `@Cacheable`\n * route with no `partitionBy` all run inline and never appear here.\n *\n * @throws {TestSetupError} This module was compiled with `cache: false`,\n * so there is no stub to inspect.\n */\n get gateway(): TestWorkerExports {\n if (!this.testWorkerExports) {\n throw new TestSetupError(\n 'module.gateway is unavailable because this module was compiled with `cache: false`. ' +\n 'Remove that option to use the default ctx.exports stub.',\n )\n }\n return this.testWorkerExports\n }\n\n /**\n * Create a WebSocket test request builder for the given path\n */\n ws(path: string): TestWsRequest {\n return new TestWsRequest(path, this)\n }\n\n /**\n * Create an SSE test request builder for the given path\n */\n sse(path: string): TestSseRequest {\n return new TestSseRequest(path, this)\n }\n\n /**\n * Create a Quarry command test request builder\n */\n quarry(name: string): TestCommandRequest {\n return new TestCommandRequest(name, this)\n }\n\n /**\n * Get Application instance\n */\n get application(): Application {\n return this.app\n }\n\n /**\n * Get DI Container (request-scoped)\n */\n get container(): Container {\n return this._requestContainer\n }\n\n /**\n * Execute an HTTP request through HonoApp\n */\n async fetch(request: Request): Promise<Response> {\n const hono = await this.app.ensureHono()\n const response = await hono.fetch(request, this.env, this.ctx as ExecutionContext)\n // The Workers runtime keeps a request alive until its `ctx.waitUntil` promises settle. Mirror that\n // here: await the work THIS request deferred (e.g. a non-blocking event listener's DB write\n // dispatched via waitUntil) before returning. Otherwise it stays in flight past the response and\n // can still be running against a shared resource (e.g. a connection pool) at the next request or at\n // `close()`, where disposing that resource could hang.\n await this.flushDeferredWork()\n return response\n }\n\n /**\n * Drain background work the most recent request(s) deferred via `ctx.waitUntil`, including any\n * follow-up tasks those tasks enqueue. Settles each (errors are surfaced by the work itself, not\n * here) so deferred side-effects don't outlive the request that triggered them.\n */\n private async flushDeferredWork(): Promise<void> {\n while (this.pendingTasks.length > 0) {\n const batch = this.pendingTasks.splice(0)\n await Promise.allSettled(batch)\n }\n }\n\n /**\n * Run callback in request scope (for DB operations, service access)\n */\n async runInRequestScope<T>(callback: (container: Container) => T | Promise<T>): Promise<T> {\n const mockContext = this.app.createMockRouterContext()\n return this.app.container.runInRequestScope(mockContext, callback)\n }\n\n /**\n * Get database service instance (resolved in request scope)\n */\n getDb(): DatabaseService\n getDb<K extends ConnectionName>(name: K): DatabaseService<K>\n getDb(name?: string): unknown {\n const token = name ? connectionSymbol(name) : DI_TOKENS.Database\n return this._requestContainer.resolve(token)\n }\n\n /**\n * Truncate mutable tables in the connection's schema(s), honoring a preserve-list.\n * Migration bookkeeping (`_prisma%`) is always preserved.\n */\n async truncateDb(name?: ConnectionName, opts: ResetOptions = {}): Promise<void> {\n const db = this.getDb(name!)\n const rows = await db.$queryRawUnsafe<{ schemaname: string; tablename: string }[]>(\n buildTableDiscoverySql(opts.schemas ?? [], opts.preserve ?? []),\n )\n const sql = buildTruncateSql(rows.map((t) => ({ schema: t.schemaname, table: t.tablename })))\n if (sql) await db.$executeRawUnsafe(sql)\n }\n\n /**\n * Run seeders by class constructor in the request-scoped container\n */\n async seed(...SeederClasses: Constructor<Seeder>[]): Promise<void> {\n const registry = this._requestContainer.resolve<SeederRegistry>(SEEDER_TOKENS.SeederRegistry)\n for (const SeederClass of SeederClasses) {\n if (!registry.has(SeederClass)) {\n throw new SeederError(`Seeder \"${SeederClass.name}\" is not registered`)\n }\n await registry.run(SeederClass, { container: this._requestContainer })\n }\n }\n\n /**\n * Assert that a record exists in the database\n */\n async assertDatabaseHas(table: string, data: Record<string, unknown>, name?: ConnectionName): Promise<void> {\n const db = this.getDb(name!)\n const model = (db as unknown as Record<string, unknown>)[table] as { findFirst: (opts: unknown) => Promise<unknown> }\n const result = await model.findFirst({ where: data })\n expect(result, `Expected ${table} with ${JSON.stringify(data)}`).not.toBeNull()\n }\n\n /**\n * Assert that a record does not exist in the database\n */\n async assertDatabaseMissing(table: string, data: Record<string, unknown>, name?: ConnectionName): Promise<void> {\n const db = this.getDb(name!)\n const model = (db as unknown as Record<string, unknown>)[table] as { findFirst: (opts: unknown) => Promise<unknown> }\n const result = await model.findFirst({ where: data })\n expect(result, `Expected ${table} NOT to have ${JSON.stringify(data)}`).toBeNull()\n }\n\n /**\n * Assert the number of records in a table\n */\n async assertDatabaseCount(table: string, expected: number, name?: ConnectionName): Promise<void> {\n const db = this.getDb(name!)\n const model = (db as unknown as Record<string, unknown>)[table] as { count: () => Promise<number> }\n const actual = await model.count()\n expect(actual, `Expected ${table} count ${expected}, got ${actual}`).toBe(expected)\n }\n\n /**\n * Cleanup - call in afterAll\n */\n async close(): Promise<void> {\n // Drain work deferred via `ctx.waitUntil` BEFORE tearing anything down. `fetch()` already drains\n // per call, but the non-HTTP helpers (`ws`/`sse`/`quarry`) share the same `pendingTasks`, so a\n // suite that exclusively uses those can reach `close()` with DB writes still in flight. Disposing\n // the pool under them races teardown — a write hits an already-`end()`ed pool, or hangs holding a\n // connection. HTTP suites are unaffected; this only matters for deferred work outside a `fetch()`.\n await this.flushDeferredWork()\n await this._requestContainer.dispose()\n await this.app.shutdown()\n }\n}\n","import {\n Application,\n type ApplicationConfig,\n type Constructor,\n type StratalEnv,\n type StratalExecutionContext,\n} from 'stratal'\nimport type { ExceptionHandler } from 'stratal/errors'\nimport { type Container } from 'stratal/di'\nimport { LogLevel } from 'stratal/logger'\nimport { markGatewayMode } from 'stratal/response-cache'\nimport { type InjectionToken, Module, type ModuleClass, type ModuleOptions } from 'stratal/module'\nimport { EMAIL_TOKENS } from 'stratal/email'\nimport { RATE_LIMITER_TOKENS } from 'stratal/rate-limiter'\nimport { STORAGE_TOKENS } from 'stratal/storage'\nimport { BINDING_ENV_VAR, leaseWorkerDatabase, type WorkerDatabaseLease } from '../database'\nimport { FakeStorageService } from '../storage'\nimport { NoopRateLimiterStore } from '../mocks/noop-rate-limiter-store'\nimport { TestEmailProvider } from '../mocks/test-email-provider'\nimport { TestWorkerExports } from '../mocks/test-worker-exports'\nimport { TestWorkersCache } from '../mocks/test-workers-cache'\nimport { FEATURE_FLAG_SERVICE_TOKEN, FakeFeatureFlagService } from '../feature-flags'\nimport { ProviderOverrideBuilder, type ProviderOverrideConfig } from './override'\nimport { Test } from './test'\nimport { TestingModule } from './testing-module'\n\n/**\n * This isolate's worker-database lease, per base connection string. The pool\n * runs each test file in its own isolate (`isolate: true`), so the first\n * `compile()` in a file leases and clones a database and later compiles in the\n * same file reuse it. The lease ends when the pool disposes the isolate.\n */\nconst workerDatabases = new Map<string, Promise<WorkerDatabaseLease>>()\n\n/**\n * Configuration for creating a testing module\n *\n * Extends ModuleOptions to support all module properties like NestJS.\n *\n * @example\n * ```typescript\n * const module = await Test.createTestingModule({\n * imports: [RegistrationModule, GeoModule],\n * providers: [{ provide: MOCK_TOKEN, useValue: mockValue }],\n * controllers: [TestController],\n * }).compile()\n * ```\n */\nexport interface TestingModuleConfig extends ModuleOptions {\n /** Optional environment overrides */\n env?: Partial<StratalEnv>\n /** Logging configuration. Defaults: level=ERROR, formatter='json' */\n logging?: ApplicationConfig['logging']\n /**\n * Custom exception handler. Mirrors `ApplicationConfig.exceptionHandler`.\n * Must be passed at compile time — `overrideProvider(DI_TOKENS.ExceptionHandler)`\n * cannot replace it because the framework resolves the handler during\n * `initialize()` (before overrides apply).\n */\n exceptionHandler?: Constructor<ExceptionHandler>\n /**\n * Trailing-slash canonicalisation. Mirrors `ApplicationConfig.trailingSlash`,\n * so it takes the same bare mode or `{ mode, exclude }` object. Defaults to\n * the framework default, `'ignore'`.\n *\n * A testing module builds its own `Application` and never runs the app's\n * entry file, so an app that canonicalises URLs there only does so in\n * production unless its suite repeats the setting here. Left unset, every\n * route assertion checks a URL shape that configuration would never emit,\n * and neither the 308 redirect nor any `exclude` entry is exercised.\n */\n trailingSlash?: ApplicationConfig['trailingSlash']\n /**\n * URI versioning. Mirrors `ApplicationConfig.versioning`, and is subject to\n * the same constraint as {@link TestingModuleConfig.trailingSlash}: unset,\n * routes register at their unversioned path, which an app configuring a\n * version prefix never serves.\n */\n versioning?: ApplicationConfig['versioning']\n /**\n * Set to `false` to compile without a `ctx.cache` stub, reproducing a\n * runtime where Workers Caching is genuinely unconfigured. Neither\n * Miniflare nor workerd populates `ExecutionContext.cache` on its own, so by\n * default `@stratal/testing` supplies a stub — a `@Cacheable`/`@PurgesCache`\n * route otherwise 500s on its very first request (`ResponseCacheConfigError`).\n * `cache: false` opts back into that failure, for testing the boot guard\n * itself. See {@link TestWorkersCache}, exposed via `module.cache`.\n */\n cache?: false\n}\n\n/**\n * Builder for creating test modules with provider overrides\n */\nexport class TestingModuleBuilder {\n private overrides: ProviderOverrideConfig<object>[] = []\n\n constructor(private config: TestingModuleConfig) { }\n\n /**\n * Override a provider with a custom implementation\n */\n overrideProvider<T>(token: InjectionToken<T>): ProviderOverrideBuilder<T> {\n return new ProviderOverrideBuilder(this, token)\n }\n\n /**\n * Add a provider override (internal use by ProviderOverrideBuilder)\n *\n * @internal\n */\n addProviderOverride<T>(override: ProviderOverrideConfig<T>): this {\n this.overrides.push(override as ProviderOverrideConfig<object>)\n return this\n }\n\n /**\n * Merge additional environment bindings\n */\n withEnv(env: Partial<StratalEnv>): this {\n this.config.env = { ...this.config.env, ...env }\n return this\n }\n\n private async getCloudflareWorkers() {\n try {\n return await import('cloudflare:workers')\n } catch {\n return null\n }\n }\n\n /**\n * Compile the testing module\n *\n * Creates the Application, applies overrides, initializes, and returns TestingModule.\n */\n async compile(): Promise<TestingModule> {\n const cf = await this.getCloudflareWorkers()\n\n const env = { ...cf?.env, ...this.config.env } as StratalEnv\n // Track work deferred via `ctx.waitUntil` so the test HTTP client can await a request's deferred\n // tail before moving on — matching the Workers runtime, which keeps a request alive until its\n // `waitUntil` promises settle. Without this, background work a request defers (e.g. a non-blocking\n // event listener's DB write) stays in flight past the response and can still be running against a\n // shared resource at teardown — risking a hang when that resource is disposed.\n const pendingTasks: Promise<unknown>[] = []\n // Neither Miniflare nor workerd ever populates `ExecutionContext.cache`, so\n // without this every `@Cacheable` route in a test serves uncached and\n // stamped `private, no-store`, and a spec asserting what the route declares\n // reads what an unconfigured runtime produces instead. Install a stub by\n // default — recording every purge spec for `module.cache.purges` — and opt\n // out via `cache: false` to reproduce that genuinely-unconfigured runtime.\n const testWorkersCache = this.config.cache === false ? undefined : new TestWorkersCache()\n // Same defect class, one layer up: workerd never populates\n // `ExecutionContext.exports` here either, so an app configuring\n // `gateway: { entrypoint }` would fail its boot verification on the first\n // request of every suite. The stub answers for any export name and\n // re-runs the loopback through this same app in cached mode; calls are\n // recorded on `module.gateway.loopbacks`.\n const testWorkerExports = this.config.cache === false\n ? undefined\n : new TestWorkerExports(testWorkersCache)\n const ctx: StratalExecutionContext = {\n waitUntil: (promise) => {\n pendingTasks.push(Promise.resolve(promise).catch(() => undefined))\n cf?.waitUntil?.(promise)\n },\n cache: testWorkersCache,\n exports: testWorkerExports?.context,\n }\n\n // The testing module drives `HonoApp#fetch` directly rather than through\n // `Stratal.fetch`, so it has to supply the gateway mark itself — without\n // it the dispatch middleware is a no-op and a consumer's partitioned\n // routes would silently never be exercised in their own tests. Harmless\n // for every app that configures no gateway: the route table is empty, so\n // the middleware costs one check.\n markGatewayMode(ctx)\n\n // Point this app's DB binding at its worker's database, creating that\n // database from the template on the slot's first compile. No-op when the\n // app has no DB binding.\n await this.attachWorkerDatabase(env)\n\n let app: Application | null = null\n try {\n // Build root module from config\n const baseModules = Test.getBaseModules()\n const allImports = [...baseModules, ...(this.config.imports ?? [])]\n\n const rootModule = this.createTestRootModule({\n imports: allImports,\n providers: this.config.providers,\n controllers: this.config.controllers,\n consumers: this.config.consumers,\n jobs: this.config.jobs,\n })\n\n app = new Application({\n module: rootModule,\n logging: {\n level: this.config.logging?.level ?? LogLevel.ERROR,\n formatter: this.config.logging?.formatter ?? 'pretty',\n },\n env,\n ctx,\n exceptionHandler: this.config.exceptionHandler,\n trailingSlash: this.config.trailingSlash,\n versioning: this.config.versioning,\n })\n\n await app.initialize()\n\n // Auto-register FakeStorageService after initialize so it replaces module-registered StorageService\n app.container.registerSingleton(STORAGE_TOKENS.StorageService, FakeStorageService)\n\n // Auto-register FakeFeatureFlagService so feature-gated code resolves without a\n // real Cloudflare Flagship binding. Inert for apps that don't use feature flags.\n app.container.registerSingleton(FEATURE_FLAG_SERVICE_TOKEN, FakeFeatureFlagService)\n\n // Disable rate limiting: suites fire many requests from one \"IP\" in\n // seconds and would trip production limiter budgets (and Better Auth's\n // built-in per-path limits, which share this store). Override the token\n // back to a real store to test limiting behavior explicitly.\n app.container.registerSingleton(RATE_LIMITER_TOKENS.Store, NoopRateLimiterStore)\n\n // Auto-register TestEmailProvider: the sync queue provider runs\n // EmailConsumer inline on dispatch, which would otherwise open a real\n // SMTP connection from the test worker. Recorded messages are exposed\n // via `module.sentEmails`; the user overrides below still replace this.\n const testEmailProvider = new TestEmailProvider()\n app.container.registerValue(EMAIL_TOKENS.EmailProviderFactory, {\n create: () => testEmailProvider,\n })\n\n // Apply user overrides AFTER initialize so they replace module-registered providers\n for (const override of this.overrides) {\n switch (override.type) {\n case 'value':\n app.container.registerValue(override.token, override.implementation)\n break\n case 'class':\n app.container.registerSingleton(\n override.token,\n override.implementation as Constructor\n )\n break\n case 'factory':\n app.container.registerFactory(\n override.token,\n override.implementation as (c: Container) => object\n )\n break\n case 'existing':\n app.container.registerExisting(\n override.token,\n override.implementation as InjectionToken<object>\n )\n break\n }\n }\n\n // Routing init is lazy in production (first fetch keeps cold starts\n // lean), but tests may resolve request-scoped router services before\n // any fetch — e.g. ActingAs minting a session resolves AUTH_OPTIONS,\n // whose factory can inject ROUTER_TOKENS.Uri. Initialize eagerly so\n // test ordering can never matter. Runs last: singleton resolution\n // caches by token without invalidation, so anything resolved here\n // would permanently shadow auto-mocks and user overrides.\n await app.ensureHono()\n\n // Serve a loopback the way the real cached entrypoint does: the *same*\n // Hono app, an execution context that is deliberately NOT gateway-marked\n // (so it cannot dispatch again), and the props the gateway resolved.\n testWorkerExports?.setHandler(async (request, props) => {\n const hono = await app!.ensureHono()\n const cachedCtx: StratalExecutionContext = {\n waitUntil: ctx.waitUntil.bind(ctx),\n cache: testWorkersCache,\n exports: ctx.exports,\n props,\n }\n return hono.fetch(request, env, cachedCtx as ExecutionContext)\n })\n\n return new TestingModule(\n app,\n env,\n ctx,\n testEmailProvider,\n pendingTasks,\n testWorkersCache,\n testWorkerExports,\n )\n } catch (error) {\n // Tear down the partially built Application so module-held resources\n // (DB pools, timers) don't outlive a failed compile().\n if (app) {\n await app.shutdown().catch(() => {\n // Best-effort cleanup for partially initialized apps.\n })\n }\n throw error\n }\n }\n\n /**\n * Point this app's Hyperdrive binding at the database this file leased,\n * leasing it on the file's first compile. Returns nothing to clean up — the\n * lease ends with the isolate. No-op when the consumer didn't opt into\n * `stratalTest({ database })`; throws if they did but no connection string is\n * configured (a misconfiguration that would otherwise silently skip isolation).\n */\n private async attachWorkerDatabase(env: StratalEnv): Promise<void> {\n const bindings = env as unknown as Record<string, unknown>\n // `BINDING_ENV_VAR` is injected only when the consumer opted into database\n // isolation via `stratalTest({ database })`. Absent → plain app, nothing to\n // isolate.\n const bindingName = bindings[BINDING_ENV_VAR] as string | undefined\n if (!bindingName) return\n const db = bindings[bindingName] as { connectionString?: string } | undefined\n const base = db?.connectionString\n if (!base) {\n throw new Error(\n `[stratal-testing] stratalTest({ database }) is enabled but no \\`${bindingName}\\` ` +\n 'Hyperdrive binding with a connectionString was found. Provide it via ' +\n `miniflare.hyperdrives (e.g. { ${bindingName}: DATABASE_URL }), or drop the \\`database\\` option.`,\n )\n }\n\n let lease = workerDatabases.get(base)\n if (!lease) {\n lease = leaseWorkerDatabase(base).catch((error: unknown) => {\n // Don't let one transient failure poison every later compile in this file.\n workerDatabases.delete(base)\n throw error\n })\n workerDatabases.set(base, lease)\n }\n const { connectionString } = await lease\n\n const isolated = Object.create(\n Object.getPrototypeOf(db) as object | null,\n Object.getOwnPropertyDescriptors(db),\n ) as Record<string, unknown>\n Object.defineProperty(isolated, 'connectionString', {\n value: connectionString,\n enumerable: true,\n configurable: true,\n writable: true,\n })\n bindings[bindingName] = isolated\n }\n\n /**\n * Create a test root module with the given options\n */\n private createTestRootModule(options: ModuleOptions): ModuleClass {\n @Module(options)\n class TestRootModule { }\n return TestRootModule\n }\n}\n","import { type DynamicModule, type ModuleClass } from 'stratal/module'\nimport { TestingModuleBuilder, type TestingModuleConfig } from './testing-module-builder'\n\n/**\n * Test\n *\n * Static class for creating testing modules.\n * Provides a NestJS-style API for configuring test modules.\n *\n * @example\n * ```typescript\n * // In vitest.setup.ts:\n * Test.setBaseModules([CoreModule])\n *\n * // In test files:\n * const module = await Test.createTestingModule({\n * imports: [RegistrationModule, GeoModule],\n * })\n * .overrideProvider(EMAIL_TOKENS.EmailService)\n * .useValue(mockEmailService)\n * .compile()\n * ```\n */\nexport class Test {\n /**\n * Base modules to include in all test modules\n * Set once in vitest.setup.ts\n */\n private static baseModules: (ModuleClass | DynamicModule)[] = []\n\n /**\n * Set base modules to include in all test modules\n * Should be called once in vitest.setup.ts\n *\n * @param modules - Modules to include before test-specific modules (e.g., CoreModule)\n */\n static setBaseModules(modules: (ModuleClass | DynamicModule)[]): void {\n this.baseModules = modules\n }\n\n /**\n * Get base modules\n */\n static getBaseModules(): (ModuleClass | DynamicModule)[] {\n return this.baseModules\n }\n\n /**\n * Create a testing module builder\n *\n * @param config - Configuration with modules and optional env overrides\n * @returns TestingModuleBuilder for configuring and compiling the module\n */\n static createTestingModule(config: TestingModuleConfig): TestingModuleBuilder {\n return new TestingModuleBuilder(config)\n }\n}\n","import { http, HttpResponse, type RequestHandler } from 'msw'\nimport { setupServer, type SetupServer } from 'msw/node'\nimport type { MockErrorOptions, MockJsonOptions } from './fetch-mock.types'\n\ntype HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options'\n\n/**\n * MSW-based fetch mock for declarative HTTP mocking in tests.\n *\n * Replaces the old Cloudflare `fetchMock` (undici MockAgent) with MSW's `setupServer`.\n * Works in both Node.js and workerd test environments.\n *\n * @example\n * ```typescript\n * import { createMockFetch } from '@stratal/testing'\n *\n * const mock = createMockFetch()\n *\n * beforeAll(() => mock.listen())\n * afterEach(() => mock.reset())\n * afterAll(() => mock.close())\n *\n * it('should mock external API', async () => {\n * mock.mockJsonResponse('https://api.example.com/data', { success: true })\n *\n * const response = await fetch('https://api.example.com/data')\n * const json = await response.json()\n *\n * expect(json.success).toBe(true)\n * })\n * ```\n */\nexport class MockFetch {\n private server: SetupServer\n\n constructor(handlers: RequestHandler[] = []) {\n this.server = setupServer(...handlers)\n }\n\n /** Start intercepting. Call in beforeAll/beforeEach. */\n listen() {\n this.server.listen({ onUnhandledRequest: 'error' })\n }\n\n /** Reset runtime handlers. Call in afterEach. */\n reset() {\n this.server.resetHandlers()\n }\n\n /** Stop intercepting. Call in afterAll. */\n close() {\n this.server.close()\n }\n\n /** Add runtime handler(s) for a single test. */\n use(...handlers: RequestHandler[]) {\n this.server.use(...handlers)\n }\n\n /**\n * Mock a JSON response.\n *\n * @param url - Full URL to mock (e.g., 'https://api.example.com/users')\n * @param data - JSON data to return\n * @param options - HTTP method, status code, headers\n *\n * @example\n * ```typescript\n * mock.mockJsonResponse('https://api.example.com/users', { users: [] })\n * mock.mockJsonResponse('https://api.example.com/users', { created: true }, { method: 'POST', status: 201 })\n * ```\n */\n mockJsonResponse(url: string, data: Record<string, unknown> | unknown[], options: MockJsonOptions = {}) {\n const method = (options.method ?? 'GET').toLowerCase() as HttpMethod\n const handler = http[method](url, () =>\n HttpResponse.json(data, {\n status: options.status ?? 200,\n headers: options.headers,\n }),\n )\n this.server.use(handler)\n }\n\n /**\n * Mock an error response.\n *\n * @param url - Full URL to mock\n * @param status - HTTP error status code\n * @param message - Optional error message\n * @param options - HTTP method, headers\n *\n * @example\n * ```typescript\n * mock.mockError('https://api.example.com/fail', 401, 'Unauthorized')\n * mock.mockError('https://api.example.com/fail', 500, 'Server Error', { method: 'POST' })\n * ```\n */\n mockError(url: string, status: number, message?: string, options: MockErrorOptions = {}) {\n const method = (options.method ?? 'GET').toLowerCase() as HttpMethod\n const body = message ? { error: message } : undefined\n this.server.use(\n http[method](url, () =>\n HttpResponse.json(body, { status, headers: options.headers }),\n ),\n )\n }\n}\n\n/**\n * Factory function to create a new MockFetch instance\n *\n * @param handlers - Optional initial MSW request handlers\n * @returns A new MockFetch instance\n *\n * @example\n * ```typescript\n * import { createMockFetch } from '@stratal/testing'\n *\n * const mock = createMockFetch()\n *\n * beforeAll(() => mock.listen())\n * afterEach(() => mock.reset())\n * afterAll(() => mock.close())\n * ```\n */\nexport function createMockFetch(handlers?: RequestHandler[]): MockFetch {\n return new MockFetch(handlers)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,0BAAb,MAAwC;CAEnB;CACA;CAFnB,YACE,QACA,OACA;EAFiB,KAAA,SAAA;EACA,KAAA,QAAA;CACf;;;;;;;;;CAUJ,SAAS,OAAgC;EACvC,OAAO,KAAK,OAAO,oBAAoB;GACrC,OAAO,KAAK;GACZ,MAAM;GACN,gBAAgB;EAClB,CAAC;CACH;;;;;;;;;CAUA,SAAS,KAA0D;EACjE,OAAO,KAAK,OAAO,oBAAoB;GACrC,OAAO,KAAK;GACZ,MAAM;GACN,gBAAgB;EAClB,CAAC;CACH;;;;;;;;;CAUA,WAAW,SAA4D;EACrE,OAAO,KAAK,OAAO,oBAAoB;GACrC,OAAO,KAAK;GACZ,MAAM;GACN,gBAAgB;EAClB,CAAC;CACH;;;;;;;;;;;;;;;;;;;CAoBA,YAAY,eAAwD;EAClE,OAAO,KAAK,OAAO,oBAAoB;GACrC,OAAO,KAAK;GACZ,MAAM;GACN,gBAAgB;EAClB,CAAC;CACH;AACF;;;;;;;ACvGA,IAAa,YAAb,cAA+B,MAAM;CAGjB;CAFlB,YACE,SACA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CAAC;CACpD;;CAGA,QAAQ;EACN,KAAK,OAAO,cAAc;CAC5B;;CAGA,QAAQ;EACN,KAAK,OAAO,MAAM;CACpB;;CAGA,IAAI,GAAG,UAA4B;EACjC,KAAK,OAAO,IAAI,GAAG,QAAQ;CAC7B;;;;;;;;;;;;;;CAeA,iBAAiB,KAAa,MAA2C,UAA2B,CAAC,GAAG;EACtG,MAAM,UAAU,QAAQ,UAAU,MAAA,CAAO,YAAY;EACrD,MAAM,UAAUA,OAAK,OAAO,CAAC,WAC3BC,eAAa,KAAK,MAAM;GACtB,QAAQ,QAAQ,UAAU;GAC1B,SAAS,QAAQ;EACnB,CAAC,CACH;EACA,KAAK,OAAO,IAAI,OAAO;CACzB;;;;;;;;;;;;;;;CAgBA,UAAU,KAAa,QAAgB,SAAkB,UAA4B,CAAC,GAAG;EACvF,MAAM,UAAU,QAAQ,UAAU,MAAA,CAAO,YAAY;EACrD,MAAM,OAAO,UAAU,EAAE,OAAO,QAAQ,IAAI,KAAA;EAC5C,KAAK,OAAO,IACVD,OAAK,OAAO,CAAC,WACXC,eAAa,KAAK,MAAM;GAAE;GAAQ,SAAS,QAAQ;EAAQ,CAAC,CAC9D,CACF;CACF;AACF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,gBAAgB,UAAwC;CACtE,OAAO,IAAI,UAAU,QAAQ;AAC/B"}
@@ -0,0 +1,24 @@
1
+ //#region src/mocks/cloudflare-workers.d.ts
2
+ /**
3
+ * Stub for the `cloudflare:workers` runtime built-in, which has no Node
4
+ * resolution. Alias `cloudflare:workers` to this module in the vitest config of
5
+ * any package whose **node** test project imports code that statically imports
6
+ * `cloudflare:workers` (e.g. `stratal/cache`'s `waitUntil`):
7
+ *
8
+ * ```ts
9
+ * resolve: { alias: { 'cloudflare:workers': '@stratal/testing/mocks/cloudflare-workers' } }
10
+ * ```
11
+ *
12
+ * Tests that run in miniflare get the real module and must NOT alias this.
13
+ * Specs asserting behaviour mock it with `vi.mock` / `vi.doMock`, which takes
14
+ * precedence over the alias.
15
+ */
16
+ /** Runs the work synchronously so assertions on the underlying call still see it. */
17
+ export declare function waitUntil(promise: Promise<unknown>): void;
18
+ export declare const env: Record<string, unknown>;
19
+ export declare class WorkerEntrypoint {}
20
+ export declare class WorkflowEntrypoint {}
21
+ export declare class DurableObject {}
22
+ export declare class RpcTarget {}
23
+ //#endregion
24
+ //# sourceMappingURL=cloudflare-workers.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-workers.d.mts","names":[],"sources":["../../src/mocks/cloudflare-workers.ts"],"mappings":";;;;;;;;;;;;;;;;wBAgBgB,UAAU,SAAS;qBAMtB,KAAK;qBAEL;qBACA;qBACA;qBACA"}
@@ -0,0 +1,28 @@
1
+ //#region src/mocks/cloudflare-workers.ts
2
+ /**
3
+ * Stub for the `cloudflare:workers` runtime built-in, which has no Node
4
+ * resolution. Alias `cloudflare:workers` to this module in the vitest config of
5
+ * any package whose **node** test project imports code that statically imports
6
+ * `cloudflare:workers` (e.g. `stratal/cache`'s `waitUntil`):
7
+ *
8
+ * ```ts
9
+ * resolve: { alias: { 'cloudflare:workers': '@stratal/testing/mocks/cloudflare-workers' } }
10
+ * ```
11
+ *
12
+ * Tests that run in miniflare get the real module and must NOT alias this.
13
+ * Specs asserting behaviour mock it with `vi.mock` / `vi.doMock`, which takes
14
+ * precedence over the alias.
15
+ */
16
+ /** Runs the work synchronously so assertions on the underlying call still see it. */
17
+ function waitUntil(promise) {
18
+ Promise.resolve(promise).catch(() => {});
19
+ }
20
+ const env = {};
21
+ var WorkerEntrypoint = class {};
22
+ var WorkflowEntrypoint = class {};
23
+ var DurableObject = class {};
24
+ var RpcTarget = class {};
25
+ //#endregion
26
+ export { DurableObject, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint, env, waitUntil };
27
+
28
+ //# sourceMappingURL=cloudflare-workers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-workers.mjs","names":[],"sources":["../../src/mocks/cloudflare-workers.ts"],"sourcesContent":["/**\n * Stub for the `cloudflare:workers` runtime built-in, which has no Node\n * resolution. Alias `cloudflare:workers` to this module in the vitest config of\n * any package whose **node** test project imports code that statically imports\n * `cloudflare:workers` (e.g. `stratal/cache`'s `waitUntil`):\n *\n * ```ts\n * resolve: { alias: { 'cloudflare:workers': '@stratal/testing/mocks/cloudflare-workers' } }\n * ```\n *\n * Tests that run in miniflare get the real module and must NOT alias this.\n * Specs asserting behaviour mock it with `vi.mock` / `vi.doMock`, which takes\n * precedence over the alias.\n */\n\n/** Runs the work synchronously so assertions on the underlying call still see it. */\nexport function waitUntil(promise: Promise<unknown>): void {\n void Promise.resolve(promise).catch(() => {\n /* swallow rejections in tests; specs that care assert via their own mock */\n })\n}\n\nexport const env: Record<string, unknown> = {}\n\nexport class WorkerEntrypoint {}\nexport class WorkflowEntrypoint {}\nexport class DurableObject {}\nexport class RpcTarget {}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,UAAU,SAAiC;CACzD,QAAa,QAAQ,OAAO,CAAC,CAAC,YAAY,CAE1C,CAAC;AACH;AAEA,MAAa,MAA+B,CAAC;AAE7C,IAAa,mBAAb,MAA8B,CAAC;AAC/B,IAAa,qBAAb,MAAgC,CAAC;AACjC,IAAa,gBAAb,MAA2B,CAAC;AAC5B,IAAa,YAAb,MAAuB,CAAC"}
@@ -1,3 +1,3 @@
1
- import { t as TestEmailProvider } from "../test-email-provider-B7cjj97-.mjs";
1
+ import { i as TestEmailProvider, n as TestWorkerExports, r as TestWorkersCache, t as LoopbackCall } from "../test-worker-exports-dCRARYEc.mjs";
2
2
  import { DeepMocked, PartialFuncReturn, createMock } from "@golevelup/ts-vitest";
3
- export { type DeepMocked, type PartialFuncReturn, TestEmailProvider, createMock };
3
+ export { type DeepMocked, type LoopbackCall, type PartialFuncReturn, TestEmailProvider, TestWorkerExports, TestWorkersCache, createMock };
@@ -1,3 +1,3 @@
1
- import { t as TestEmailProvider } from "../test-email-provider-Dr-nhE0x.mjs";
1
+ import { n as TestWorkerExports, r as TestEmailProvider, t as TestWorkersCache } from "../test-workers-cache-D02Pt_dE.mjs";
2
2
  import { createMock } from "@golevelup/ts-vitest";
3
- export { TestEmailProvider, createMock };
3
+ export { TestEmailProvider, TestWorkerExports, TestWorkersCache, createMock };