@pikku/queue-bullmq 0.12.8 → 0.12.10

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.
@@ -1,9 +1,10 @@
1
1
  import type { ConnectionOptions, JobsOptions } from 'bullmq';
2
2
  import type Bull from 'bullmq';
3
3
  import { Queue, QueueEvents } from 'bullmq';
4
- import type { QueueJob, QueueService } from '@pikku/core/queue';
4
+ import type { QueueInspection, QueueJob, QueueJobRecord, QueueJobStatus, QueueService } from '@pikku/core/queue';
5
5
  import type { JobOptions } from '@pikku/core/queue';
6
6
  export declare const mapPikkuJobToBull: (options?: JobOptions) => JobsOptions;
7
+ export declare const mapBullJobToRecord: (job: Bull.Job, status: QueueJobStatus) => QueueJobRecord;
7
8
  /**
8
9
  * Bull/Redis queue service implementation
9
10
  * Supports job results, retries, and most queue features
@@ -12,8 +13,8 @@ export declare class BullQueueService implements QueueService {
12
13
  private redisConnectionOptions;
13
14
  readonly name = "bull";
14
15
  readonly supportsResults = true;
15
- protected queues: Map<string, Queue<any, any, string, any, any, string, Bull.RedisQueueBackend>>;
16
- protected queueEvents: Map<string, QueueEvents<any>>;
16
+ protected queues: Map<string, Queue<any, any, string, any, any, string, Bull.RedisQueueBackend, ConnectionOptions>>;
17
+ protected queueEvents: Map<string, QueueEvents<any, Bull.RedisQueueBackend, ConnectionOptions>>;
17
18
  constructor(redisConnectionOptions?: ConnectionOptions);
18
19
  /**
19
20
  * Create a Bull queue with translated configuration
@@ -23,6 +24,9 @@ export declare class BullQueueService implements QueueService {
23
24
  * Add a job to the queue
24
25
  */
25
26
  add<In>(queueName: string, data: In, options?: JobOptions): Promise<string>;
27
+ inspect(queueName: string, opts?: {
28
+ limit?: number;
29
+ }): Promise<QueueInspection>;
26
30
  /**
27
31
  * Get job by ID
28
32
  */
@@ -30,6 +30,24 @@ export const mapPikkuJobToBull = (options) => {
30
30
  }
31
31
  return bullOptions;
32
32
  };
33
+ const INSPECTED_STATES = [
34
+ 'waiting',
35
+ 'active',
36
+ 'delayed',
37
+ 'completed',
38
+ 'failed',
39
+ ];
40
+ export const mapBullJobToRecord = (job, status) => ({
41
+ jobId: job.id,
42
+ status,
43
+ attemptsMade: job.attemptsMade,
44
+ maxAttempts: job.opts.attempts ?? 1,
45
+ createdAt: new Date(job.timestamp),
46
+ processedAt: job.processedOn ? new Date(job.processedOn) : null,
47
+ finishedAt: job.finishedOn ? new Date(job.finishedOn) : null,
48
+ durationMs: job.finishedOn && job.processedOn ? job.finishedOn - job.processedOn : null,
49
+ error: job.failedReason || null,
50
+ });
33
51
  /**
34
52
  * Bull/Redis queue service implementation
35
53
  * Supports job results, retries, and most queue features
@@ -76,6 +94,16 @@ export class BullQueueService {
76
94
  }
77
95
  return bullJob.id;
78
96
  }
97
+ async inspect(queueName, opts) {
98
+ const queue = await this.createQueue(queueName);
99
+ const limit = opts?.limit ?? 50;
100
+ const counts = (await queue.getJobCounts(...INSPECTED_STATES));
101
+ const recent = (await Promise.all(INSPECTED_STATES.map(async (status) => (await queue.getJobs([status], 0, limit - 1)).map((job) => mapBullJobToRecord(job, status)))))
102
+ .flat()
103
+ .sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
104
+ .slice(0, limit);
105
+ return { counts, recent };
106
+ }
79
107
  /**
80
108
  * Get job by ID
81
109
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/queue-bullmq",
3
- "version": "0.12.8",
3
+ "version": "0.12.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/pikkujs/pikku.git",
@@ -16,18 +16,24 @@
16
16
  "tsc": "tsc",
17
17
  "test": "bash run-tests.sh",
18
18
  "ncu": "npx npm-check-updates",
19
- "build": "tsc -b",
19
+ "build": "bun run clean && tsc -b",
20
20
  "release": "npm run build && npm test",
21
- "prepublishOnly": "bun run build"
21
+ "prepublishOnly": "bun run build",
22
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
22
23
  },
23
24
  "peerDependencies": {
24
- "@pikku/core": "^0.12.108"
25
+ "@pikku/core": "^0.12.144"
25
26
  },
26
27
  "dependencies": {
27
- "bullmq": "^6.1.1",
28
+ "bullmq": "^6.3.16",
28
29
  "ioredis": "^6.0.0"
29
30
  },
30
31
  "exports": {
31
- ".": "./dist/index.js"
32
- }
32
+ ".": "./dist/index.js",
33
+ "./package.json": "./package.json"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "!dist/**/*.tsbuildinfo"
38
+ ]
33
39
  }
package/CHANGELOG.md DELETED
@@ -1,377 +0,0 @@
1
- ## 0.12.8
2
-
3
- ### Patch Changes
4
-
5
- - 4c7a1b5: Run the monorepo's own scripts through bun instead of yarn. What moves is the
6
- package manager each package's `prepublishOnly` and build scripts invoke, plus
7
- the two manifest fixes bun needs to resolve the tree: `uWebSockets.js` is
8
- declared with an explicit `github:` specifier, and `@pikku/uws-handler` marks
9
- its `uWebSockets.js` peer optional so a bun install of a consumer that brings
10
- its own uWS app does not try to fetch it from the registry.
11
-
12
- Three published behaviours change, all of them cases where an isolated
13
- `node_modules` or bun as the runtime had been papered over by yarn's hoisting:
14
-
15
- - `@pikku/migrator-sql` turns foreign keys on when it opens a sqlite database
16
- through bun. `node:sqlite` enforces them by default and `bun:sqlite` does not,
17
- which silently turned every `ON DELETE CASCADE` into a no-op under
18
- `bunx --bun pikku`.
19
- - `@pikku/cli` resolves a deploy provider against the project being deployed
20
- rather than against wherever the CLI itself is installed, which is what its
21
- own "is not installed" error asks the user to arrange.
22
- - `@pikku/cli` treats a specifier a runtime hands straight back — bun does this
23
- for the modules it implements itself — as not resolved from the project, so
24
- it falls back rather than loading the runtime's own copy.
25
-
26
- - Updated dependencies [4c7a1b5]
27
- - @pikku/core@0.12.108
28
-
29
- ## 0.12.7
30
-
31
- ### Patch Changes
32
-
33
- - 266e3bc: One door per name: `@pikku/core/ecosystem/*` and the package root are gone
34
-
35
- `@pikku/core` published every module twice. `ecosystem/http` re-exported
36
- `./http`, `ecosystem/services` re-exported `./services`, and a name was
37
- reachable through either — so every addition had to be made in two places, and a
38
- consumer's import said nothing about what it actually used. The package root was
39
- the same problem at a larger scale: a single barrel of 206 names that no bundler
40
- could take apart, and the one specifier that revealed nothing at all.
41
-
42
- Both are deleted. Every name now lives on the subpath that owns it, and every
43
- import carries that subpath — `@pikku/core/http`, `@pikku/core/services`,
44
- `@pikku/core/errors`, `@pikku/core/types`.
45
-
46
- Deleting the facades meant the raw subpaths had to become a superset of them,
47
- which they were not: the facade tree had accumulated 25 names with no raw home
48
- and about 26 more filed under a different area than the module they came from.
49
- Those names moved to the area that owns them, and three areas were published as
50
- new entry points rather than left on a root that is going away — `./types` (the
51
- shared type surface, the largest single destination), `./state` and
52
- `./classification`.
53
-
54
- `./classification` is one door onto one subject: what a value is and how it must
55
- be handled. Its three halves would each have been an entry point — the brands
56
- and manifest types, the stored-form helpers (`hashToken`, `unsafeAsSealed` and
57
- friends), and `SecretValue` — split by whether a name happens to be a type or a
58
- value, which is the same defect as the facades. The duration and versioned-id
59
- helpers went to `./utils`, which already published, and `PikkuRequest` went to
60
- `./function`: it is the transport-agnostic request base, not an HTTP one — HTTP
61
- has `PikkuHTTPAbstractRequest`, and the only thing outside core that extends
62
- `PikkuRequest` is Azure's timer request.
63
-
64
- `./types` inherited the root barrel's habit before it inherited its contents, so
65
- the names with an owner elsewhere were moved off it. The middleware types and the
66
- five middleware factories — `pikkuMiddleware`, `pikkuMiddlewareFactory`,
67
- `pikkuChannelMiddleware`, `pikkuChannelMiddlewareFactory` and
68
- `pikkuAgentMiddleware`, runtime values on a types entry point — are now
69
- `@pikku/core/middleware`; the function meta types are `@pikku/core/function`;
70
- `SerializedError` is `@pikku/core/errors`; and the generic TypeScript helpers
71
- (`MakeRequired`, `PickRequired`, `PickOptional`, `RequireAtLeastOne`,
72
- `JSONPrimitive`, `JSONValue`) are `@pikku/core/utils`. What is left on `./types`
73
- is the vocabulary the wirings share, which no single module owns.
74
-
75
- `pikku` was itself a root barrel — `export * from '@pikku/core'` — and
76
- now exports only the services it bundles.
77
-
78
- One module survives at the old specifier, and only for the bootstrap:
79
- `packages/cli` is generated by the _published_ CLI pinned in its `build.sh`, and
80
- that CLI still writes a bare `@pikku/core` into the files it generates for the
81
- CLI itself. `bootstrap-compat/root.ts` carries the eight types it names, a test
82
- in core fails if that list grows, and it goes when the pin moves to a CLI
83
- released from this branch. The adapter names the pinned CLI reaches for —
84
- `pikkuState` and `CreateWireServices` — are rewritten to `@pikku/core/state` and
85
- `@pikku/core/types` by the same `build.sh` patch pass, so no second shim is
86
- needed for them.
87
-
88
- A guard test keeps the root shut: it parses imports and rejects a bare
89
- `@pikku/core` rather than grepping for it, because several tests hold a user's
90
- file as a template literal, where `import … from '@pikku/core'` is fixture text
91
- rather than an import this repo makes.
92
-
93
- An agent scaffold a project generated under an older CLI is refreshed rather
94
- than left to fail: `pikku all` already deleted one importing an entry point
95
- `@pikku/core` no longer publishes, and the `#pikku` hub joins that list.
96
- Without it a project that scaffolds the agent endpoint but
97
- declares no agents keeps the old file forever — the generator that would rewrite
98
- it only runs when agents exist, and the file being present is what stops it
99
- being regenerated as missing.
100
-
101
- `pikku new addon` also wrote a tsconfig `paths` map naming only the deleted hub.
102
- An addon's `imports` map points into `dist`, so `paths` is what resolves
103
- `#pikku/<leaf>` for the addon's own source build — it now names the two leaf
104
- patterns, in both the addon and its test harness.
105
-
106
- - 786dae5: Bump every dependency whose latest release is a major across the monorepo, and
107
- port the code the majors broke: `cookie` 2's `parseCookie`/`stringifySetCookie`
108
- API in `@pikku/core` and the three runtime HTTP adapters, and assistant-ui 0.15's
109
- store client in `@pikku/assistant-ui`.
110
- - 6eef0a0: Bump every dependency to its latest compatible minor/patch across the monorepo.
111
- - Updated dependencies [7722ceb]
112
- - Updated dependencies [375c1ff]
113
- - Updated dependencies [02a70cd]
114
- - Updated dependencies [aeef159]
115
- - Updated dependencies [a281de6]
116
- - Updated dependencies [266e3bc]
117
- - Updated dependencies [02a70cd]
118
- - Updated dependencies [786dae5]
119
- - Updated dependencies [6eef0a0]
120
- - Updated dependencies [3561d67]
121
- - Updated dependencies [a91c433]
122
- - Updated dependencies [02a70cd]
123
- - Updated dependencies [9537f74]
124
- - Updated dependencies [2b57ca8]
125
- - Updated dependencies [266e3bc]
126
- - Updated dependencies [9fce0f1]
127
- - Updated dependencies [83683a0]
128
- - Updated dependencies [456c88b]
129
- - Updated dependencies [456c88b]
130
- - Updated dependencies [c127273]
131
- - @pikku/core@0.12.85
132
-
133
- ## 0.12.6
134
-
135
- ### Patch Changes
136
-
137
- - 6794681: Publish the ecosystem surface as per-area sub-barrels under `@pikku/core/ecosystem/*`, and point generated code, the CLI, the inspector and the runtime adapters at them.
138
-
139
- 348 names that only generated code, the toolchain or a runtime adapter ever imports now have a second home on `@pikku/core/ecosystem/<area>` — one sub-barrel per area, matching how core already publishes its entrypoints, so no single barrel grows without bound and a consumer only pulls in the area it uses.
140
-
141
- This step is additive: every name is still exported from the entrypoint it was published from before, so nothing downstream breaks. Removing them from the app-facing barrels is a later change, and needs a release carrying `./ecosystem/*` first.
142
-
143
- - Updated dependencies [7406bfe]
144
- - Updated dependencies [6794681]
145
- - @pikku/core@0.12.84
146
-
147
- ## 0.12.5
148
-
149
- ### Patch Changes
150
-
151
- - e3d4454: Add job groups, so one shared queue can stay fair without splitting into one
152
- queue per producer.
153
-
154
- A job may now carry `group: { id, tier }`, and a worker may cap how many jobs
155
- of any one group run at once via `groupConcurrency`. On pg-boss this maps to
156
- `localGroupConcurrency`, which excludes at-capacity groups from the fetch query
157
- itself, so a capped group costs nothing rather than being fetched and restored.
158
- BullMQ declares it unsupported (groups are a BullMQ Pro feature) — being
159
- push-based, it can simply use a queue per group at no polling cost.
160
-
161
- Workflow services accept a `queueStrategy`. The default `'per-workflow'` is
162
- unchanged: every workflow gets its own `wf-orchestrator-*` / `wf-step-*` queue,
163
- which is also what lets serverless providers deploy one unit per workflow. The
164
- new `'shared-groups'` routes every workflow through the shared
165
- orchestrator/step-worker queues and isolates them by group instead, so a
166
- monolith runs one set of pollers rather than one per workflow — on a
167
- pull-based backend with dozens of workflows that is the difference between
168
- hundreds of poll loops and twenty. It is for single-process runtimes only; a
169
- per-unit serverless deploy still needs the per-workflow queues to route to its
170
- units.
171
-
172
- - Updated dependencies [24252b8]
173
- - Updated dependencies [e3d4454]
174
- - @pikku/core@0.12.69
175
-
176
- ## 0.12.4
177
-
178
- ### Patch Changes
179
-
180
- - 41ce2cb: Upgrade to TypeScript 6 and raise the minimum Node.js version to 22.
181
-
182
- All packages now build against `typescript@^6.0.3` and declare `engines.node >= 22`. Internal tooling (`ts-json-schema-generator`, `zod-to-ts`) was bumped to TypeScript 6-compatible releases.
183
-
184
- - Updated dependencies [41ce2cb]
185
- - @pikku/core@0.12.44
186
-
187
- ## 0.12.3
188
-
189
- ### Patch Changes
190
-
191
- - 92cd5b1: feat(workflow): workflow-owned step retries + stable invocationId
192
-
193
- The workflow — not the queue — now owns step retry policy, and each step
194
- invocation gets a stable idempotency key.
195
- - **Default `retries: 5` with exponential backoff.** A step with no `retries`
196
- previously inherited the queue's bare default (e.g. pg-boss `retry_limit 2`,
197
- no backoff) so retries fired instantly and couldn't outlast a transient
198
- outage. Retries now default to 5 with backoff, resolved at the workflow layer.
199
- - **`retries: 0` is honored.** Dispatch previously passed `undefined` options
200
- for `retries: 0`, letting the queue re-run a non-idempotent step up to its own
201
- default. The resolved policy now always sets `attempts` (`retries: 0` →
202
- `attempts: 1`), so the queue never second-guesses the workflow. The persisted
203
- step retries and the dispatched `attempts` are resolved together so
204
- "retries exhausted" and "no more redeliveries" are the same event.
205
- - **`workflowStep.invocationId`** — a deterministic, dependency-free
206
- `uuidv5(runId:stepName)` handed to every step. Unlike `stepId` (minted per
207
- attempt), it is identical across retries, so a step can dedupe on it
208
- (`ON CONFLICT (invocationId)`, Stripe idempotency keys, etc.).
209
- - **queue-bullmq**: `mapPikkuJobToBull` now maps `backoff` (previously dropped,
210
- so a step's backoff silently never applied on Redis), and `registerQueues`
211
- throws a clear error when no logger is available (matching queue-pg-boss).
212
- - **Dispatch failures are recoverable, not fatal.** A step is now marked
213
- `scheduled` only _after_ it is successfully handed to its transport (queue or
214
- scheduler) — a failed hand-off leaves it `pending` so a replay re-dispatches
215
- it, instead of stranding it in `scheduled` (replay would pause forever on a
216
- job that was never enqueued). A transport outage (e.g. pg-boss momentarily
217
- down) is surfaced as a new `WorkflowDispatchException`, which the orchestrator
218
- treats as transient: the run is left running and the orchestrator job is
219
- rethrown for redelivery (it replays idempotently from the snapshot) rather
220
- than the whole run being marked `failed`. The orchestrator job now also
221
- carries its own retry policy, so this holds even when the orchestrator queue
222
- is configured `retry_limit 0`. A genuine step error still fails the run.
223
- - **Same step name can be invoked multiple times in one run.** Step rows are now
224
- keyed per _invocation_: the Nth reach of a step name in a replay resolves to a
225
- physical key (`name` for the first, `name#N` for repeats), so a literal
226
- duplicate name no longer clobbers the earlier step's state. The first reach
227
- keeps the bare name, so existing rows, graph-node matching and `invocationId`s
228
- are unchanged. Ordinals are derived deterministically from DSL execution order
229
- and reset each replay.
230
- - **Step provenance (`fromStepName`) + graph cycles.** Every step now records
231
- the predecessor it was scheduled from (`fromStepName`; entry steps have none),
232
- persisted on the step row across all stores (in-memory, kysely, redis,
233
- mongodb, cloudflare DO) and carried in the queued payload. The DSL wire
234
- exposes the derived `fromInvocationId` (`uuidv5(runId:fromStepName)`) so
235
- consumers get the stable predecessor key without a second persisted id —
236
- `fromStepName` is the source of truth (it is replay-deterministic; `stepId`,
237
- minted per row, is not). This makes the walked path reconstructable even when
238
- a node is reached more than once: in `a → b → a → c` the second `a` is a
239
- distinct ordinal instance (`a#1`) whose `fromStepName` is `b`.
240
- The graph runner now supports **cycles**: a forward edge into an
241
- already-started node still collapses to a single run (joins/diamonds are
242
- unchanged), but a _back-edge_ — one whose target can reach its source — fires
243
- a fresh ordinal instance, so a node can loop back to itself. Termination is
244
- the graph's responsibility (branch routing must converge); the engine enforces
245
- no visit cap.
246
-
247
- - Updated dependencies [92cd5b1]
248
- - @pikku/core@0.12.38
249
-
250
- ## 0.12.0
251
-
252
- ## 0.12.2
253
-
254
- ### Patch Changes
255
-
256
- - 3e04565: chore: update dependencies to latest minor/patch versions
257
- - Updated dependencies [cc4c9e9]
258
- - Updated dependencies [3e04565]
259
- - @pikku/core@0.12.2
260
-
261
- ## 0.12.1
262
-
263
- ### Patch Changes
264
-
265
- - e04531f: Code quality improvements: resolve oxlint warnings and apply autofixes across the codebase (unused bindings, unnecessary constructors, prefer `const` over `let`, etc.). No behaviour changes.
266
- - Updated dependencies [62a8725]
267
- - Updated dependencies [a3bdb0d]
268
- - Updated dependencies [e0349ff]
269
- - Updated dependencies [62a8725]
270
- - Updated dependencies [e04531f]
271
- - Updated dependencies [62a8725]
272
- - Updated dependencies [a83efb8]
273
- - Updated dependencies [8eed717]
274
- - Updated dependencies [62a8725]
275
- - Updated dependencies [62a8725]
276
- - Updated dependencies [62a8725]
277
- - @pikku/core@0.12.1
278
-
279
- ### New Features
280
-
281
- - Recurring cron scheduled tasks support via `BullSchedulerService`
282
- - `setServices()`, `start()`, `stop()` lifecycle methods on scheduler and queue workers
283
-
284
- ## 0.11.0
285
-
286
- ## 0.11.2
287
-
288
- ### Patch Changes
289
-
290
- - db9c7bf: Simplify CreateWireServices type signature for custom Config compatibility
291
- - Updated dependencies [db9c7bf]
292
- - @pikku/core@0.11.2
293
-
294
- ### Fixes
295
-
296
- - ddd87eaf: Simplify CreateWireServices type signature for custom Config compatibility
297
-
298
- ## 0.11.1
299
-
300
- ### Patch Changes
301
-
302
- - 4b811db: chore: updating all dependencies
303
- - 06e1a31: breaking: change session services to wire services
304
- - Updated dependencies [4b811db]
305
- - Updated dependencies [e12a00c]
306
- - Updated dependencies [4579434]
307
- - Updated dependencies [28aeb7f]
308
- - Updated dependencies [ce902b1]
309
- - Updated dependencies [06e1a31]
310
- - @pikku/core@0.11.1
311
-
312
- ### Minor Changes
313
-
314
- - Add scheduler service implementation
315
- - Add service factory for queue and scheduler creation
316
-
317
- # @pikku/queue-bullmq
318
-
319
- ## 0.10.0
320
-
321
- This release includes significant improvements across the framework including tree-shaking support, middleware/permission factories, enhanced CLI functionality, improved TypeScript type safety, and comprehensive test strategies.
322
-
323
- For complete details, see https://pikku.dev/changelogs/0_10_0.md
324
-
325
- ## 0.9.5-next.0
326
-
327
- ### Patch Changes
328
-
329
- - Updated dependencies
330
- - @pikku/core@0.9.12-next.0
331
-
332
- ## 0.9.4
333
-
334
- ### Patch Changes
335
-
336
- - 3bb5824: fix: forcing release to see if dist is generated
337
- - Updated dependencies [99c2b3a]
338
- - @pikku/core@0.9.9
339
-
340
- ## 0.9.3
341
-
342
- ### Patch Changes
343
-
344
- - c18800d: feat: adding queue and scheduledTask to interactions
345
- - Updated dependencies [c18800d]
346
- - @pikku/core@0.9.4
347
-
348
- ## 0.9.2
349
-
350
- ### Patch Changes
351
-
352
- - a5905a9: chore: updating all dependencies
353
- - Updated dependencies [1256238]
354
- - Updated dependencies [6cf8efd]
355
- - Updated dependencies [d3a9a09]
356
- - Updated dependencies [840e078]
357
- - Updated dependencies [667d23c]
358
- - Updated dependencies [a5905a9]
359
- - @pikku/core@0.9.2
360
-
361
- ## 0.9.1
362
-
363
- ### Patch Changes
364
-
365
- - fdb1593: core: bumping everything with a patch to sync up the major release inconsistencies in dependencies
366
- - Updated dependencies [fdb1593]
367
- - @pikku/core@0.9.1
368
-
369
- ## 0.9.0
370
-
371
- ### Breaking Changes
372
-
373
- - Normalized all transports to use "wirings" instead of events/routes/transports for consistency across the framework
374
-
375
- ## 0.8.0
376
-
377
- - **BullMQ Integration**: BullMQ queue service implementation for high-performance Redis-based job queues
package/run-tests.sh DELETED
@@ -1,68 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Enable nullglob to handle cases where no files match the pattern
4
- shopt -s nullglob
5
-
6
- # Initialize variables for options
7
- watch_mode=false
8
- coverage_mode=false
9
-
10
- # Parse command-line options
11
- while [[ $# -gt 0 ]]; do
12
- case $1 in
13
- --watch)
14
- watch_mode=true
15
- shift
16
- ;;
17
- --coverage)
18
- coverage_mode=true
19
- shift
20
- ;;
21
- *)
22
- echo "Unknown option: $1"
23
- exit 1
24
- ;;
25
- esac
26
- done
27
-
28
- # Define the pattern to match your test files
29
- pattern="src/*.test.ts"
30
-
31
- # Expand the pattern into an array of files
32
- files=($(find src -type f -name "*.test.ts"))
33
-
34
- # Check if any files matched the pattern
35
- if [ ${#files[@]} -eq 0 ]; then
36
- echo "No test files found matching pattern: $pattern"
37
- if [ "${STRICT_TEST_DISCOVERY}" = "1" ]; then
38
- exit 1
39
- fi
40
- exit 0
41
- fi
42
-
43
- # Construct the bun command
44
- #
45
- # --parallel gives every test file its own worker process, which is what node's
46
- # `--test` did. Several suites keep module-level caches (a TypeScript program, a
47
- # temp fixture directory) that a shared process would leak between files.
48
- #
49
- # --timeout because bun caps a test at 5s by default where node had no cap, and
50
- # the suites that build real TypeScript programs run well past that.
51
- bun_cmd=(bun test --parallel --timeout 120000)
52
-
53
- # Append options based on flags
54
- if [ "$watch_mode" = true ]; then
55
- # --watch reruns in one process; parallel workers have nothing to watch.
56
- bun_cmd=(bun test --watch --timeout 120000)
57
- fi
58
-
59
- if [ "$coverage_mode" = true ]; then
60
- # --coverage-dir=. keeps lcov.info at the package root: CI merges every
61
- # package's report by prefixing its SF paths with the file's own directory,
62
- # so a nested coverage/ directory would re-root them one level too deep.
63
- bun_cmd+=(--coverage --coverage-reporter=lcov --coverage-reporter=text --coverage-dir=.)
64
- export PIKKU_TEST_COVERAGE=1
65
- fi
66
-
67
- # Execute the bun command with the expanded list of files
68
- "${bun_cmd[@]}" "${files[@]}"