@luckystack/test-runner 0.7.3 → 0.7.5

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.
@@ -124,6 +124,35 @@ Type-to-sample table:
124
124
 
125
125
  This is NOT a property-based generator. It always returns the same value for the same schema. Swap in `fast-check` if you need randomized fuzz that respects the schema.
126
126
 
127
+ ### `resolveTestBaseUrl(options?)`
128
+
129
+ Resolve the live server target for test entrypoints. Priority is: non-empty `TEST_BASE_URL`, a valid integer port from `<cwd>/node_modules/.luckystack/dev-server.json` whose owner PID is still alive, then `fallbackUrl` (default `http://localhost:80`). Generated projects pass `http://localhost:${ports.backend}` as the fallback, so config changes, dev auto-increment hops, and stale crash leftovers remain truthful.
130
+
131
+ ```ts
132
+ resolveTestBaseUrl(options?: {
133
+ cwd?: string;
134
+ fallbackUrl?: string;
135
+ }): string
136
+ ```
137
+
138
+ This helper does not start or probe a server; connection failures remain visible to the actual test layer.
139
+
140
+ ### `resolveTestEnvironment(input?)`
141
+
142
+ Prepare the **test process** before DB/Redis-backed integration tests run. It first calls core's `loadEnvFiles()`. When `loadProjectConfig` returns a config with a non-empty `secretManager.url`, it dynamically loads the optional `@luckystack/secret-manager` peer and runs `initSecretManager({ ...config.secretManager, source: 'remote' })`.
143
+
144
+ ```ts
145
+ await resolveTestEnvironment({
146
+ loadProjectConfig: async () => (await import('./config')).default,
147
+ });
148
+ ```
149
+
150
+ `runAllTests` calls this automatically through its required `loadProjectConfig` callback. The official scaffolded `scripts/testAll.ts` supplies it. The callback is lazy deliberately: `.env` and `.env.local` must load before `config.ts` reads `LUCKYSTACK_SECRET_MANAGER_URL`.
151
+
152
+ This is a separate process from the live server. Resolving `DATABASE_URL` during server boot does **not** resolve it for Layer-5 `ctx.prisma` calls. If a secret-manager URL is configured but the package cannot load, resolution fails loudly before any layer runs instead of handing a raw `DATABASE_URL_V<n>` pointer to Prisma.
153
+
154
+ For a custom Vitest integration setup, call `resolveTestEnvironment` from a setup file before importing modules that construct env-backed clients. Direct Layer-5 callers must pass the same lazy loader to `runCustomTests({ ..., loadProjectConfig })`; it resolves before discovery/import. Both orchestrator APIs reject a missing loader at runtime, including from untyped JavaScript. `runAllTests` uses an internal already-prepared Layer-5 entrypoint, so the custom layer does not reload `.env.local` pointers over freshly resolved values.
155
+
127
156
  ## Types
128
157
 
129
158
  ```ts
@@ -154,6 +183,15 @@ interface RunContractSummary {
154
183
  skipped: number;
155
184
  results: ContractCheckResult[];
156
185
  }
186
+
187
+ interface ResolveTestEnvironmentInput {
188
+ loadProjectConfig?: () => unknown | Promise<unknown>;
189
+ }
190
+
191
+ interface RunCustomTestsInput {
192
+ // other Layer-5 options omitted
193
+ loadProjectConfig: NonNullable<ResolveTestEnvironmentInput['loadProjectConfig']>;
194
+ }
157
195
  ```
158
196
 
159
197
  `responseStatus: 'unknown'` only appears on failed results when the JSON either failed to parse or did not carry a `status` field. `errorCode` is set on pass results when `responseStatus === 'error'` and on fail results when the auth/rate-limit layers' `errorCode` mismatch path runs (contract layer never sets it on fail).
@@ -178,11 +216,13 @@ import {
178
216
  runContractTests,
179
217
  logContractResult,
180
218
  logContractSummary,
219
+ resolveTestBaseUrl,
181
220
  } from '@luckystack/test-runner';
221
+ import { ports } from './config.ports';
182
222
 
183
223
  const summary = await runContractTests({
184
224
  apiMethodMap,
185
- baseUrl: process.env.TEST_BASE_URL ?? 'http://127.0.0.1:80',
225
+ baseUrl: resolveTestBaseUrl({ fallbackUrl: `http://localhost:${ports.backend}` }),
186
226
  onResult: logContractResult,
187
227
  });
188
228
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luckystack/test-runner",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -54,16 +54,20 @@
54
54
  "test": "vitest run"
55
55
  },
56
56
  "dependencies": {
57
- "@luckystack/core": "^0.7.3"
57
+ "@luckystack/core": "^0.7.5"
58
58
  },
59
59
  "peerDependencies": {
60
- "@luckystack/login": "^0.7.3",
60
+ "@luckystack/login": "^0.7.5",
61
+ "@luckystack/secret-manager": "^0.7.5",
61
62
  "socket.io-client": "^4.8.0",
62
63
  "zod": "^4.0.0"
63
64
  },
64
65
  "peerDependenciesMeta": {
65
66
  "@luckystack/login": {
66
67
  "optional": true
68
+ },
69
+ "@luckystack/secret-manager": {
70
+ "optional": true
67
71
  }
68
72
  }
69
73
  }