@shivaedev/test-kits 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +83 -0
  3. package/dist/jobs/adapters/expireAttempt.d.ts +4 -0
  4. package/dist/jobs/adapters/expireAttempt.d.ts.map +1 -0
  5. package/dist/jobs/adapters/expireAttempt.js +17 -0
  6. package/dist/jobs/adapters/expireAttempt.js.map +1 -0
  7. package/dist/jobs/adapters/queueSignal.d.ts +7 -0
  8. package/dist/jobs/adapters/queueSignal.d.ts.map +1 -0
  9. package/dist/jobs/adapters/queueSignal.js +29 -0
  10. package/dist/jobs/adapters/queueSignal.js.map +1 -0
  11. package/dist/jobs/adapters/quotedSchema.d.ts +2 -0
  12. package/dist/jobs/adapters/quotedSchema.d.ts.map +1 -0
  13. package/dist/jobs/adapters/quotedSchema.js +4 -0
  14. package/dist/jobs/adapters/quotedSchema.js.map +1 -0
  15. package/dist/jobs/adapters/testingClient.d.ts +13 -0
  16. package/dist/jobs/adapters/testingClient.d.ts.map +1 -0
  17. package/dist/jobs/adapters/testingClient.js +99 -0
  18. package/dist/jobs/adapters/testingClient.js.map +1 -0
  19. package/dist/jobs/adapters/testingController.d.ts +80 -0
  20. package/dist/jobs/adapters/testingController.d.ts.map +1 -0
  21. package/dist/jobs/adapters/testingController.js +121 -0
  22. package/dist/jobs/adapters/testingController.js.map +1 -0
  23. package/dist/jobs/adapters/testingDueNow.d.ts +7 -0
  24. package/dist/jobs/adapters/testingDueNow.d.ts.map +1 -0
  25. package/dist/jobs/adapters/testingDueNow.js +26 -0
  26. package/dist/jobs/adapters/testingDueNow.js.map +1 -0
  27. package/dist/jobs/adapters/testingEngine.d.ts +8 -0
  28. package/dist/jobs/adapters/testingEngine.d.ts.map +1 -0
  29. package/dist/jobs/adapters/testingEngine.js +12 -0
  30. package/dist/jobs/adapters/testingEngine.js.map +1 -0
  31. package/dist/jobs/adapters/testingExpirations.d.ts +8 -0
  32. package/dist/jobs/adapters/testingExpirations.d.ts.map +1 -0
  33. package/dist/jobs/adapters/testingExpirations.js +27 -0
  34. package/dist/jobs/adapters/testingExpirations.js.map +1 -0
  35. package/dist/jobs/adapters/testingInspectionClient.d.ts +6 -0
  36. package/dist/jobs/adapters/testingInspectionClient.d.ts.map +1 -0
  37. package/dist/jobs/adapters/testingInspectionClient.js +52 -0
  38. package/dist/jobs/adapters/testingInspectionClient.js.map +1 -0
  39. package/dist/jobs/adapters/testingSignal.d.ts +12 -0
  40. package/dist/jobs/adapters/testingSignal.d.ts.map +1 -0
  41. package/dist/jobs/adapters/testingSignal.js +28 -0
  42. package/dist/jobs/adapters/testingSignal.js.map +1 -0
  43. package/dist/jobs/adapters/testingTime.d.ts +10 -0
  44. package/dist/jobs/adapters/testingTime.d.ts.map +1 -0
  45. package/dist/jobs/adapters/testingTime.js +18 -0
  46. package/dist/jobs/adapters/testingTime.js.map +1 -0
  47. package/dist/jobs/error.d.ts +22 -0
  48. package/dist/jobs/error.d.ts.map +1 -0
  49. package/dist/jobs/error.js +9 -0
  50. package/dist/jobs/error.js.map +1 -0
  51. package/dist/jobs/internal/adapters/testingFetches.d.ts +7 -0
  52. package/dist/jobs/internal/adapters/testingFetches.d.ts.map +1 -0
  53. package/dist/jobs/internal/adapters/testingFetches.js +30 -0
  54. package/dist/jobs/internal/adapters/testingFetches.js.map +1 -0
  55. package/dist/jobs/internal/testingIdle.d.ts +17 -0
  56. package/dist/jobs/internal/testingIdle.d.ts.map +1 -0
  57. package/dist/jobs/internal/testingIdle.js +18 -0
  58. package/dist/jobs/internal/testingIdle.js.map +1 -0
  59. package/dist/jobs/internal/testingOperation.d.ts +6 -0
  60. package/dist/jobs/internal/testingOperation.d.ts.map +1 -0
  61. package/dist/jobs/internal/testingOperation.js +13 -0
  62. package/dist/jobs/internal/testingOperation.js.map +1 -0
  63. package/dist/jobs/internal/testingSchedules.d.ts +14 -0
  64. package/dist/jobs/internal/testingSchedules.d.ts.map +1 -0
  65. package/dist/jobs/internal/testingSchedules.js +20 -0
  66. package/dist/jobs/internal/testingSchedules.js.map +1 -0
  67. package/dist/jobs/internal/testingWaits.d.ts +21 -0
  68. package/dist/jobs/internal/testingWaits.d.ts.map +1 -0
  69. package/dist/jobs/internal/testingWaits.js +53 -0
  70. package/dist/jobs/internal/testingWaits.js.map +1 -0
  71. package/dist/jobs/testing.d.ts +89 -0
  72. package/dist/jobs/testing.d.ts.map +1 -0
  73. package/dist/jobs/testing.js +12 -0
  74. package/dist/jobs/testing.js.map +1 -0
  75. package/package.json +16 -13
  76. package/src/jobs/adapters/expireAttempt.ts +27 -0
  77. package/src/jobs/adapters/queueSignal.ts +30 -0
  78. package/src/jobs/adapters/quotedSchema.ts +3 -0
  79. package/src/jobs/adapters/testingClient.ts +121 -0
  80. package/src/jobs/adapters/testingController.ts +138 -0
  81. package/src/jobs/adapters/testingDueNow.ts +32 -0
  82. package/src/jobs/adapters/testingEngine.ts +14 -0
  83. package/src/jobs/adapters/testingExpirations.ts +33 -0
  84. package/src/jobs/adapters/testingInspectionClient.ts +71 -0
  85. package/src/jobs/adapters/testingSignal.ts +34 -0
  86. package/src/jobs/adapters/testingTime.ts +25 -0
  87. package/src/jobs/error.ts +17 -0
  88. package/src/jobs/internal/adapters/testingFetches.ts +36 -0
  89. package/src/jobs/internal/testingIdle.ts +36 -0
  90. package/src/jobs/internal/testingOperation.ts +19 -0
  91. package/src/jobs/internal/testingSchedules.ts +35 -0
  92. package/src/jobs/internal/testingWaits.ts +95 -0
  93. package/src/jobs/testing.ts +31 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0 - 2026-11-04
4
+
5
+ ### Added
6
+
7
+ - Provide the pg-boss testing controller in test-kits, using jobs’ public client and inspection service with the real PostgreSQL engine.
8
+
9
+ ### Changed
10
+
11
+ - Require Effect 4.0.7 and its matching companion packages. Install the 4.0.7 Effect stack together.
12
+
3
13
  ## 0.3.1 - 2026-11-04
4
14
 
5
15
  ### Changed
package/README.md CHANGED
@@ -53,6 +53,89 @@ Import `withChangeCoverage`, `expectPublished`, `UnannouncedWrites`, `PublishedK
53
53
 
54
54
  Import `watchHints`, `heard`, `layerMemoryProtocol` and the `HintViewer` type from `@shivaedev/test-kits/contract/testing.ts`. `watchHints(stream)` starts a scoped listener and waits for its first hint. `heard(viewer, keys, { within }?)` reports whether a delivered changed hint contains all requested keys, using a one-second Effect-clock deadline by default. `layerMemoryProtocol(group)` connects the native RPC client and server in-process; provide the real group's handlers and middleware.
55
55
 
56
+ ### Jobs
57
+
58
+ `linkedWorkerSpans(sender, spans)` from `@shivaedev/test-kits/jobs/testing.ts` reads native recorded Effect spans and returns the pg-boss consumer spans whose links match both the sender's `traceId` and `spanId`. It returns every matching attempt, including retries, and no matches before a worker runs. An untraced job has no sender link. Settle the workers before reading their completed attempts; this readout does not wait or read queue storage.
59
+
60
+ `testing.ts` gives story kits a controller for one real pg-boss client. Create a fresh controller per runtime, pass its `clientFactory` to `pgBossLayer`, and keep that Layer scoped as usual. `jobs(queue, options?)` returns jobs-owned `Job` metadata with `data` decoded through the queue's Schema, including traced payloads. For a scheduled run with no payload, pass `{ name: Cleanup.name, schema: Schema.Null }` to read `data: null`. Invalid durable data fails with `PgBossPayloadError`; decoding services remain in the Effect's requirements.
61
+
62
+ This producer story uses the `SendEmail` definition and `Jobs` service from above. `databaseUrl` points to the story's PostgreSQL database:
63
+
64
+ ```ts
65
+ import { Context, Effect, Layer, Option } from "effect";
66
+ import { TestClock } from "effect/testing";
67
+ import { expect } from "vitest";
68
+ import { storyKit } from "@shivaedev/test-story/server/storyKit.ts";
69
+ import { pgBossLayer } from "@shivaedev/jobs/server/service.ts";
70
+ import { makePgBossTesting, testRetryPolicy } from "@shivaedev/test-kits/jobs/testing.ts";
71
+
72
+ const emailStories = storyKit({
73
+ clock: "test",
74
+ *create() {
75
+ const testing = makePgBossTesting({ clock: yield* TestClock.testClockWith(Effect.succeed), retryPolicy: testRetryPolicy });
76
+ const context = yield* Layer.build(
77
+ Jobs.layer({ jobs: [SendEmail] }).pipe(Layer.provide(pgBossLayer({ connectionString: databaseUrl, clientFactory: testing.clientFactory }))),
78
+ );
79
+ return { jobs: Context.get(context, Jobs), testing };
80
+ },
81
+ name: "queued email",
82
+ stages: ["ready"],
83
+ verbs: ({ jobs, testing }) => ({
84
+ enqueue: (userId: number) => jobs.enqueue(SendEmail, { userId }),
85
+ testing,
86
+ }),
87
+ });
88
+
89
+ emailStories.it("decodes the queued email", [], function* ({ enqueue, testing }) {
90
+ const id = Option.getOrThrow(yield* enqueue(42));
91
+ expect(yield* testing.jobs(SendEmail)).toMatchObject([{ id, data: { userId: 42 }, state: "created" }]);
92
+ });
93
+ ```
94
+
95
+ Set `retryPolicy: testRetryPolicy` through the controller to override queue and send settings with `retryDelay: 0` and `retryBackoff: false`. A failing worker can then exhaust its native retries without production backoff. The policy applies to subsequently sent jobs; it does not rewrite jobs already stored.
96
+
97
+ To pass time, use the controller's `timePasses` verb with the same native story `TestClock`:
98
+
99
+ ```ts
100
+ import { Effect } from "effect";
101
+ import { TestClock } from "effect/testing";
102
+ import { makePgBossTesting } from "@shivaedev/test-kits/jobs/testing.ts";
103
+
104
+ const testing = makePgBossTesting({ clock: yield* TestClock.testClockWith(Effect.succeed) });
105
+ yield* testing.timePasses("1 day");
106
+ ```
107
+
108
+ The controller advances the application clock and pg-boss's PostgreSQL clock together, wakes due workers and waits for their settlement. A `RetryAt` later than the new time remains deferred. Provide `testing.clientFactory` to the jobs Layer as above, and use an isolated database for each story. Passing time first waits for existing work to settle; release a held handler before advancing this controller. Supply the story clock so both the application and pg-boss stay under the kit's control.
109
+
110
+ `schedules()` lists registered schedules as `{ name, cron, timezone }` entries from PostgreSQL. `trigger(schedule)` takes a schedule definition, such as `Cleanup`, and enqueues one run now using its stored schedule data and options. It returns the run ID, or null when pg-boss suppresses the send. Register `Cleanup.run(effect)` in the testing Layer first, then yield `testing.trigger(Cleanup)` and `testing.waitForIdle` before observing the Effect's result. An unregistered schedule fails with `PgBossTestingError` (`operation: "trigger"`).
111
+
112
+ `refreshQueueStats(queue?)` requests a native pg-boss supervisor pass for one queue, or all queues when omitted, before reading cached counts through the jobs service's `health`. Like the service method, it performs native queue maintenance and respects pg-boss monitor intervals and backoff.
113
+
114
+ `failNextSend(queue)` arms one send failure for that queue. The next valid `enqueue` fails with the usual typed `PgBossError` (`operation: "enqueue"`); the following send proceeds normally.
115
+
116
+ `expireAfter(queue, n)` takes a positive attempt count: configure it before enqueueing to limit subsequent jobs to `n` attempts. Each successful send keeps its own expiry rule; later changes and duplicate-ID sends do not alter pending jobs. Earlier attempts run the handler normally; on attempt `n`, the controller expires the claimed job instead of invoking its handler. PostgreSQL supervision performs the terminal failure and dead lettering. A job that succeeds earlier completes normally.
117
+
118
+ `expireIn(queue, duration)` takes an Effect `Duration.Input`, such as `"1 second"`, and sets the expiry of subsequent sends, rounded up to whole seconds. Durations below one second or nonfinite durations fail with `PgBossTestingError` (`operation: "expireIn"`). Earlier sends retain their expiry, and later calls and duplicate-ID sends do not change stored jobs. Both expiry controls also apply to runs sent by `trigger(schedule)`. It can be combined with `expireAfter`: one sets each attempt's time budget, the other limits attempts. A stuck handler is interrupted at its deadline, and the same worker can fetch its retry after pg-boss fails the attempt. The testing expiry hooks support pg-boss schema version 46.
119
+
120
+ `runDueNow(queue)` makes future jobs in the queue's `created` or `retry` state due at the database's current time and wakes local workers. It includes delayed sends (`startAfter`), native retries and `RetryAt` deferrals. Yield `waitForIdle` afterwards before observing handler results; future jobs do not hold that wait open. It leaves active and terminal jobs and other queues unchanged.
121
+
122
+ `deferred(queue)` returns waiting deferrals as `{ at: DateTime.Utc, reason: string }[]`. `runDeferredNow(queue)` pulls those jobs forward to the database’s current time and wakes local workers without waiting for their original due time. Read `revision` before reading deferrals and use `waitForChange(revision)` as with other controls.
123
+
124
+ `checkBatchWindow(queue, millisecondsPerJob)` checks that the declared sequential batch fits strictly inside the stored queue expiry window. `schemaVersion` reads the installed version, and `checkSchemaVersion(expected)` fails when it differs. Import `PgBossTestingError` and `PgBossWaitError` from `@shivaedev/test-kits/jobs/error.ts`. Test control, read and check failures use `PgBossTestingError` with `operation`, optional `queue` and a redacted `original`.
125
+
126
+ `snapshot(queues)` reads the unfinished jobs of several queues in one query, so the result is one consistent PostgreSQL snapshot. It returns jobs in the `created`, `retry`, `active` and `failed` states, never completed ones, oldest first by creation. A waiting `RetryAt` job reads as `deferred` while its `startAfter` is in the future; once due, it reads as `retry` until claimed. A retry after a handler failure reads as `retry` even when its next attempt is in the future. Each entry has the job's `id`, `queue` (the definition's name), `state`, `startAfter` as a UTC `DateTime` and `data` decoded by that queue's Schema. Only unfinished rows are decoded, so a completed job whose stored data the Schema no longer accepts does not fail the read; invalid unfinished data fails with `PgBossPayloadError`.
127
+
128
+ `waitForIdle` discovers queues from the jobs registered in the controller's Layer, including producer-only definitions and schedules; it takes no queue list. It completes when none of those queues has an active job or an unblocked job ready to fetch, including work claimed by another client. Ready jobs keep the wait open even when no local worker runs them. A terminal native worker timeout lets the wait complete after pg-boss fails the job. Jobs whose `startAfter` is in the future do not hold the wait open. While a local fetched batch has no settlement yet, the wait reads nothing and waits for the next local change; otherwise it checks PostgreSQL on local changes and committed job-change notifications from other clients. A kit settles by yielding `waitForIdle` and then reading jobs once. As with any idle snapshot, a producer can enqueue more work after the wait returns.
129
+
130
+ A kit can also capture `revision` before reading jobs and yield `waitForChange(revision)` when its condition is unmet. The wait resumes after a local send, settlement or worker fetch, and when a local worker returns to idle as `waitForIdle` defines it, including terminal native worker timeouts. It also resumes immediately if a change occurred between the read and the wait. Local deferral settlements advance its revision before the worker continues the batch. It also observes committed job-change notifications from other clients through the inspection service. Future scheduled work and external writes that emit no job notification need their own wake source. Stories should retain a bounded test timeout.
131
+
132
+ `untilJob(queue, id, state)` waits that way for one job: it reads the job, waits for the next change when the job is in another state, and returns the job with `data` decoded through the queue's Schema once it reaches `state`. It also accepts `{ name, schema: Schema.Null }` for a triggered schedule's run. `fetchesPass(queue, n)` completes once `n` worker fetches on the queue that began after the wait started have finished, whether or not they claimed anything, so a story can show that a job stayed untaken by fetches that could have claimed it. Each fetch also counts as a change for `waitForChange`. Both waits give up after `within` (default 20 seconds) on the caller's Effect clock, so a story forks the wait and advances its `TestClock` to exercise a timeout, and fail with `PgBossWaitError`, whose message names what the wait expected and what it last saw:
133
+
134
+ ```ts
135
+ yield* testing.untilJob(SendEmail, id, "completed", { within: "5 seconds" });
136
+ // Gave up after 5s waiting until job <id> in send-email is completed; last seen: retry
137
+ ```
138
+
56
139
  ### Development setup
57
140
 
58
141
  Install `@shivaedev/test-kits` as a development dependency alongside `effect`, Better Auth and the runtime packages used by the kit. The package depends on `@shivaedev/test-story` and `@shivaedev/test-sql`; runtime packages are peers. The [story-testing skill](https://github.com/ShivaeDev/platform/blob/main/packages/skills/skills/story-testing/SKILL.md) describes how to compose an application's facade and prove its behavior.
@@ -0,0 +1,4 @@
1
+ import type { EngineClient } from "@shivaedev/jobs/server/engineClient.ts";
2
+ import type { WorkerJob } from "@shivaedev/jobs/server/job.ts";
3
+ export declare function expireAttempt(client: EngineClient, schema: string, job: Pick<WorkerJob<unknown>, "name" | "id" | "retryCount">, cause?: "expiry" | "heartbeat"): Promise<void>;
4
+ //# sourceMappingURL=expireAttempt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expireAttempt.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/expireAttempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,wBAAsB,aAAa,CAClC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,CAAC,EAC3D,KAAK,GAAE,QAAQ,GAAG,WAAsB,GACtC,OAAO,CAAC,IAAI,CAAC,CAiBf"}
@@ -0,0 +1,17 @@
1
+ import { quotedSchema } from "./quotedSchema.js";
2
+ export async function expireAttempt(client, schema, job, cause = "expiry") {
3
+ if ((await client.schemaVersion()) !== 46) {
4
+ throw new Error("Testing expiry requires pg-boss schema version 46");
5
+ }
6
+ const quoted = quotedSchema(schema);
7
+ const timestamp = cause === "expiry" ? "started_on" : "heartbeat_on";
8
+ const seconds = cause === "expiry" ? "expire_seconds" : "heartbeat_seconds";
9
+ await client.getDb().executeSql(`UPDATE ${quoted}.job SET ${timestamp} = ${quoted}.job_now() - (${seconds} + 1) * interval '1 second'
10
+ WHERE name = $1 AND id = $2 AND retry_count = $3 AND state = 'active'`, [job.name, job.id, job.retryCount]);
11
+ // Supervision owns expiry and dead lettering; make its claim due with the job's deadline.
12
+ await client
13
+ .getDb()
14
+ .executeSql(`UPDATE ${quoted}.queue SET monitor_claim_on = ${quoted}.job_now() - interval '1 week' WHERE name = $1`, [job.name]);
15
+ await client.supervise(job.name);
16
+ }
17
+ //# sourceMappingURL=expireAttempt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expireAttempt.js","sourceRoot":"","sources":["../../../src/jobs/adapters/expireAttempt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,MAAoB,EACpB,MAAc,EACd,GAA2D,EAC3D,KAAK,GAA2B,QAAQ;IAExC,IAAI,CAAC,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC;IACrE,MAAM,OAAO,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,mBAAmB,CAAC;IAC5E,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,UAAU,CAC9B,UAAU,MAAM,YAAY,SAAS,MAAM,MAAM,iBAAiB,OAAO;wEACH,EACtE,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC,CAClC,CAAC;IACF,0FAA0F;IAC1F,MAAM,MAAM;SACV,KAAK,EAAE;SACP,UAAU,CAAC,UAAU,MAAM,iCAAiC,MAAM,gDAAgD,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAClI,MAAM,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Effect } from "effect";
2
+ export declare function queueSignal(): {
3
+ changed(): void;
4
+ revision: Effect.Effect<number, never, never>;
5
+ waitForChange: (after: number) => Effect.Effect<number>;
6
+ };
7
+ //# sourceMappingURL=queueSignal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queueSignal.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/queueSignal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,wBAAgB,WAAW;IAIzB,OAAO;IASP,QAAQ;IACR,aAAa,UAAU,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;EAatD"}
@@ -0,0 +1,29 @@
1
+ import { Effect } from "effect";
2
+ export function queueSignal() {
3
+ let revision = 0;
4
+ const listeners = new Set();
5
+ return {
6
+ changed() {
7
+ revision += 1;
8
+ // A resumed waiter can wait again synchronously; it must wait for the next change, not this one.
9
+ const waiting = [...listeners];
10
+ listeners.clear();
11
+ for (const listener of waiting) {
12
+ listener(revision);
13
+ }
14
+ },
15
+ revision: Effect.sync(() => revision),
16
+ waitForChange: (after) => Effect.callback((resume) => {
17
+ if (revision !== after) {
18
+ resume(Effect.succeed(revision));
19
+ return;
20
+ }
21
+ function listener(current) {
22
+ resume(Effect.succeed(current));
23
+ }
24
+ listeners.add(listener);
25
+ return Effect.sync(() => listeners.delete(listener));
26
+ }),
27
+ };
28
+ }
29
+ //# sourceMappingURL=queueSignal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queueSignal.js","sourceRoot":"","sources":["../../../src/jobs/adapters/queueSignal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,UAAU,WAAW;IAC1B,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,MAAM,SAAS,GAAG,IAAI,GAAG,EAA8B,CAAC;IACxD,OAAO;QACN,OAAO;YACN,QAAQ,IAAI,CAAC,CAAC;YACd,iGAAiG;YACjG,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC;YAC/B,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,KAAK,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;gBAChC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACpB,CAAC;QACF,CAAC;QACD,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC;QACrC,aAAa,EAAE,CAAC,KAAa,EAAyB,EAAE,CACvD,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1B,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;gBACxB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACjC,OAAO;YACR,CAAC;YACD,SAAS,QAAQ,CAAC,OAAe;gBAChC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;YACjC,CAAC;YACD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC;KACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function quotedSchema(schema: string): string;
2
+ //# sourceMappingURL=quotedSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quotedSchema.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/quotedSchema.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,4 @@
1
+ export function quotedSchema(schema) {
2
+ return `"${schema.replaceAll('"', '""')}"`;
3
+ }
4
+ //# sourceMappingURL=quotedSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quotedSchema.js","sourceRoot":"","sources":["../../../src/jobs/adapters/quotedSchema.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,MAAc;IAC1C,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { EngineClient } from "@shivaedev/jobs/server/engineClient.ts";
2
+ import type { EnqueueOptions } from "@shivaedev/jobs/server/enqueueOptions.ts";
3
+ import type { TestingWork } from "#jobs/internal/testingIdle.ts";
4
+ export interface TestingControls {
5
+ readonly changed: () => void;
6
+ readonly expirations: Map<string, number>;
7
+ readonly expirySeconds: Map<string, number>;
8
+ readonly failures: Set<string>;
9
+ readonly retryPolicy: Pick<EnqueueOptions, "retryBackoff" | "retryDelay">;
10
+ readonly work: TestingWork;
11
+ }
12
+ export declare function testingClient(client: EngineClient, schema: string, controls: TestingControls): EngineClient;
13
+ //# sourceMappingURL=testingClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testingClient.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/testingClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAI/E,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE/E,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC;IAC1E,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC3B;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,YAAY,CAsG3G"}
@@ -0,0 +1,99 @@
1
+ import { Effect } from "effect";
2
+ import { testingEngine } from "#jobs/adapters/testingEngine.ts";
3
+ import { testingExpirations } from "#jobs/adapters/testingExpirations.ts";
4
+ export function testingClient(client, schema, controls) {
5
+ const engine = testingEngine(client, schema);
6
+ const expirations = testingExpirations(client);
7
+ async function update(request, data, options) {
8
+ const result = typeof request === "string" ? await client.update(request, data, options) : await client.update(request);
9
+ controls.changed();
10
+ return result;
11
+ }
12
+ const overrides = {
13
+ complete: async (...args) => {
14
+ const result = await client.complete(...args);
15
+ controls.changed();
16
+ return result;
17
+ },
18
+ createQueue: (name, options) => {
19
+ if (options?.deadLetter !== undefined) {
20
+ controls.work.queues.add(name);
21
+ }
22
+ const { retryDelayMax, ...rest } = options ?? {};
23
+ return client.createQueue(name, {
24
+ ...rest,
25
+ ...(controls.retryPolicy.retryBackoff === false || retryDelayMax === undefined ? {} : { retryDelayMax }),
26
+ ...controls.retryPolicy,
27
+ });
28
+ },
29
+ fail: async (...args) => {
30
+ const result = await client.fail(...args);
31
+ controls.changed();
32
+ return result;
33
+ },
34
+ retry: async (...args) => {
35
+ const result = await client.retry(...args);
36
+ controls.changed();
37
+ return result;
38
+ },
39
+ send: async (name, data, options) => {
40
+ if (controls.failures.delete(name)) {
41
+ throw new Error("Injected pg-boss send failure");
42
+ }
43
+ const attempts = controls.expirations.get(name);
44
+ const expireInSeconds = controls.expirySeconds.get(name);
45
+ const { retryDelayMax, ...rest } = options ?? {};
46
+ const id = await expirations.send(name, data, {
47
+ ...rest,
48
+ ...(controls.retryPolicy.retryBackoff === false || retryDelayMax === undefined ? {} : { retryDelayMax }),
49
+ ...controls.retryPolicy,
50
+ ...(attempts === undefined ? {} : { retryLimit: attempts - 1 }),
51
+ ...(expireInSeconds === undefined ? {} : { expireInSeconds }),
52
+ }, attempts);
53
+ controls.changed();
54
+ return id;
55
+ },
56
+ update,
57
+ updateQueue: (name, options) => client.updateQueue(name, {
58
+ ...options,
59
+ ...controls.retryPolicy,
60
+ ...(controls.retryPolicy.retryBackoff === false ? { retryDelayMax: null } : {}),
61
+ }),
62
+ work: async (name, options, handler) => client.work(name, options, async (jobs) => {
63
+ const batch = { jobs: new Map(jobs.map((job) => [job.id, job.retryCount])), name, settled: false };
64
+ controls.work.batches.add(batch);
65
+ controls.changed();
66
+ try {
67
+ const ready = [];
68
+ for (const job of jobs) {
69
+ const attempts = await expirations.attemptsFor(job);
70
+ if (attempts !== undefined && job.retryCount + 1 >= attempts) {
71
+ await Effect.runPromise(engine.expireAttempt(job));
72
+ }
73
+ else {
74
+ ready.push(job);
75
+ }
76
+ }
77
+ if (ready.length > 0) {
78
+ await handler(ready);
79
+ }
80
+ }
81
+ finally {
82
+ controls.work.batches.delete(batch);
83
+ controls.changed();
84
+ }
85
+ }),
86
+ };
87
+ const wrapped = new Proxy(client, {
88
+ get(target, property) {
89
+ if (Object.hasOwn(overrides, property)) {
90
+ const override = Reflect.get(overrides, property);
91
+ return override;
92
+ }
93
+ const value = Reflect.get(target, property);
94
+ return typeof value === "function" ? value.bind(target) : value;
95
+ },
96
+ });
97
+ return wrapped;
98
+ }
99
+ //# sourceMappingURL=testingClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testingClient.js","sourceRoot":"","sources":["../../../src/jobs/adapters/testingClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAY1E,MAAM,UAAU,aAAa,CAAC,MAAoB,EAAE,MAAc,EAAE,QAAyB;IAC5F,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE7C,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAG/C,KAAK,UAAU,MAAM,CAAC,OAAqC,EAAE,IAAoB,EAAE,OAA6B;QAC/G,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACxH,QAAQ,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAA0B;QACxC,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,C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,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE;QACjC,GAAG,CAAC,MAAM,EAAE,QAAQ;YACnB,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC;gBACxC,MAAM,QAAQ,GAAY,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBAC3D,OAAO,QAAQ,CAAC;YACjB,CAAC;YACD,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACjE,CAAC;KACD,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AAChB,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { Duration, Effect, type Schema } from "effect";
2
+ import type { JobReadOptions, PgBossClientFactory } from "@shivaedev/jobs/server/client.ts";
3
+ import type { JobPayloadSchema, QueueDefinition } from "@shivaedev/jobs/server/definition.ts";
4
+ import type { SnapshotQueue } from "@shivaedev/jobs/server/inspection.ts";
5
+ import { PgBossTestingError } from "#jobs/error.ts";
6
+ import type { PgBossTestingOptions } from "#jobs/testing.ts";
7
+ export declare function testingController(settings?: PgBossTestingOptions): {
8
+ runDeferredNow: (queue: Pick<QueueDefinition, "name">) => Effect.Effect<void, PgBossTestingError, never>;
9
+ runDueNow: (queue: Pick<QueueDefinition, "name">) => Effect.Effect<void, PgBossTestingError, never>;
10
+ timePasses: (duration: Duration.Input) => Effect.Effect<undefined, PgBossTestingError, never>;
11
+ schedules: () => Effect.Effect<{
12
+ cron: string;
13
+ name: string;
14
+ timezone: string;
15
+ }[], PgBossTestingError, never>;
16
+ trigger: (schedule: Pick<import("@shivaedev/jobs/server/definition.ts").ScheduleDefinition, "name" | "scheduleOptions">) => Effect.Effect<string | null, PgBossTestingError, never>;
17
+ fetchesPass: (queue: Pick<QueueDefinition, "name">, count: number, options?: import("#jobs/testing.ts").PgBossTestingWaitOptions) => Effect.Effect<unknown, PgBossTestingError | import("#jobs/error.ts").PgBossWaitError, never>;
18
+ untilJob: <TName extends string, TPayload extends JobPayloadSchema | typeof Schema.Null>(queue: {
19
+ readonly name: TName;
20
+ readonly schema: TPayload;
21
+ }, id: string, state: import("@shivaedev/jobs/server/job.ts").JobState, options?: import("#jobs/testing.ts").PgBossTestingWaitOptions) => Effect.Effect<import("@shivaedev/jobs/server/job.ts").Job<TPayload["Type"]>, import("@shivaedev/jobs/server/error.ts").PgBossPayloadError | PgBossTestingError | import("#jobs/error.ts").PgBossWaitError, TPayload["DecodingServices"]>;
22
+ deferred: (queue: Pick<QueueDefinition, "name">) => Effect.Effect<{
23
+ at: import("effect/DateTime").Utc;
24
+ reason: string;
25
+ }[], PgBossTestingError, never>;
26
+ checkBatchWindow: (queue: Pick<QueueDefinition, "name" | "workerOptions">, millisecondsPerJob: number) => Effect.Effect<void, PgBossTestingError, never>;
27
+ checkSchemaVersion: (expected: number) => Effect.Effect<void, PgBossTestingError, never>;
28
+ clientFactory: PgBossClientFactory;
29
+ expireAfter: (queue: Pick<QueueDefinition, "name">, attempts: number) => Effect.Effect<void, PgBossTestingError, never>;
30
+ expireIn: (queue: Pick<QueueDefinition, "name">, duration: Duration.Input) => Effect.Effect<void, PgBossTestingError, never>;
31
+ failNextSend: (queue: Pick<QueueDefinition, "name">) => Effect.Effect<void, never, never>;
32
+ jobs: <TName extends string, TPayload extends JobPayloadSchema | typeof Schema.Null>(queue: {
33
+ readonly name: TName;
34
+ readonly schema: TPayload;
35
+ }, readOptions?: JobReadOptions) => Effect.Effect<{
36
+ expireInSeconds: number;
37
+ groupId?: string | null;
38
+ groupTier?: string | null;
39
+ heartbeatSeconds: number | null;
40
+ id: string;
41
+ name: string;
42
+ retryCount: number;
43
+ signal: AbortSignal;
44
+ blocked: boolean;
45
+ blocking: boolean;
46
+ completedOn: Date | null;
47
+ createdOn: Date;
48
+ deadLetter: string;
49
+ deleteAfterSeconds: number;
50
+ heartbeatOn: Date | null;
51
+ keepUntil: Date;
52
+ output: object | null;
53
+ pendingDependencies: number;
54
+ policy: string;
55
+ priority: number;
56
+ retryBackoff: boolean;
57
+ retryDelay: number;
58
+ retryDelayMax?: number;
59
+ retryLimit: number;
60
+ singletonKey: string | null;
61
+ singletonOn: Date | null;
62
+ sourceCreatedOn: Date | null;
63
+ sourceId: string | null;
64
+ sourceName: string | null;
65
+ sourceOutput: object | null;
66
+ sourceRetryCount: number | null;
67
+ sourceRootId: string | null;
68
+ startAfter: Date;
69
+ startedOn: Date | null;
70
+ state: import("@shivaedev/jobs/server/job.ts").JobState;
71
+ data: TPayload["Type"];
72
+ }[], import("@shivaedev/jobs/server/error.ts").PgBossPayloadError | PgBossTestingError, TPayload["DecodingServices"]>;
73
+ refreshQueueStats: (queue?: Pick<QueueDefinition, "name">) => Effect.Effect<void, PgBossTestingError, never>;
74
+ revision: Effect.Effect<number, never, never>;
75
+ schemaVersion: Effect.Effect<number | null, PgBossTestingError, never>;
76
+ snapshot: <const TQueues extends readonly SnapshotQueue[]>(queues: TQueues) => Effect.Effect<readonly import("@shivaedev/jobs/server/inspection.ts").UnfinishedJob<TQueues[number]>[], import("@shivaedev/jobs/server/error.ts").PgBossPayloadError | PgBossTestingError, TQueues[number]["schema"]["DecodingServices"]>;
77
+ waitForChange: (after: number) => Effect.Effect<number, never, never>;
78
+ waitForIdle: Effect.Effect<void, PgBossTestingError, never>;
79
+ };
80
+ //# sourceMappingURL=testingController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testingController.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/testingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAY,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGjE,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5F,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAE9F,OAAO,KAAK,EAA2B,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAInG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAMpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,wBAAgB,iBAAiB,CAAC,QAAQ,GAAE,oBAAyB;;;;;;;;;;;;;;;sBAkDjD,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC;;;;8BAIrB,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,eAAe,CAAC,sBAAsB,MAAM;mCAqBtE,MAAM;;yBAOhB,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,YAAY,MAAM;sBAUlD,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,YAAY,QAAQ,CAAC,KAAK;0BAWnD,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC;WAC5C,KAAK,SAAS,MAAM,EAAE,QAAQ,SAAS,gBAAgB,GAAG,OAAO,MAAM,CAAC,IAAI,SAC3E;QAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;KAAE,gBAC5C,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAED,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC;;;eAI9C,KAAK,CAAC,OAAO,SAAS,SAAS,aAAa,EAAE,UAAU,OAAO;;;EAM3E"}
@@ -0,0 +1,121 @@
1
+ import { Duration, Effect, Redacted } from "effect";
2
+ import { TestClock as PgBossTestClock } from "pg-boss";
3
+ import { defaultClientFactory } from "@shivaedev/jobs/server/adapters/defaultClientFactory.ts";
4
+ import { testingClient } from "#jobs/adapters/testingClient.ts";
5
+ import { testingDueNow } from "#jobs/adapters/testingDueNow.ts";
6
+ import { testingTime } from "#jobs/adapters/testingTime.ts";
7
+ import { PgBossTestingError } from "#jobs/error.ts";
8
+ import { testingFetches } from "#jobs/internal/adapters/testingFetches.ts";
9
+ import { testingIdle } from "#jobs/internal/testingIdle.ts";
10
+ import { testingInspection, testingOperation } from "#jobs/internal/testingOperation.ts";
11
+ import { testingSchedules } from "#jobs/internal/testingSchedules.ts";
12
+ import { testingWaits } from "#jobs/internal/testingWaits.ts";
13
+ import { testingInspectionClient } from "./testingInspectionClient.js";
14
+ import { testingSignal } from "./testingSignal.js";
15
+ export function testingController(settings = {}) {
16
+ const clock = settings.clock === undefined ? undefined : new PgBossTestClock(settings.clock.currentTimeMillisUnsafe());
17
+ let current;
18
+ let fetches;
19
+ let schema = "pgboss";
20
+ const signal = testingSignal();
21
+ let observed;
22
+ const work = { batches: new Set(), queues: new Set() };
23
+ const controls = {
24
+ changed: signal.changed,
25
+ expirations: new Map(),
26
+ expirySeconds: new Map(),
27
+ failures: new Set(),
28
+ retryPolicy: settings.retryPolicy ?? {},
29
+ work,
30
+ };
31
+ function client() {
32
+ if (current === undefined) {
33
+ throw new Error("Provide the testing clientFactory to a jobs Layer first");
34
+ }
35
+ return current;
36
+ }
37
+ function inspection() {
38
+ if (observed === undefined) {
39
+ throw new Error("Provide the testing clientFactory to a jobs Layer first");
40
+ }
41
+ return observed;
42
+ }
43
+ const clientFactory = (clientOptions) => {
44
+ if (current !== undefined) {
45
+ throw new Error("A testing controller owns one jobs client; create a controller per runtime");
46
+ }
47
+ schema = clientOptions.schema ?? "pgboss";
48
+ current = defaultClientFactory({ ...clientOptions, ...(clock === undefined ? {} : { clock }) });
49
+ fetches = testingFetches(current.getDb(), signal.changed);
50
+ current = testingClient(current, schema, controls);
51
+ return testingInspectionClient(current, schema, work, signal.changed, (reads, changes) => {
52
+ observed = reads;
53
+ signal.observe(changes);
54
+ });
55
+ };
56
+ const wake = Effect.sync(() => {
57
+ if (clock !== undefined) {
58
+ for (const worker of client().getWipData()) {
59
+ client().notifyWorker(worker.id);
60
+ }
61
+ }
62
+ });
63
+ const idle = testingIdle(inspection, work, signal, wake);
64
+ return {
65
+ deferred: (queue) => Effect.suspend(() => testingInspection("deferred", inspection().deferred(queue), queue.name)),
66
+ ...testingDueNow(client, () => schema, signal.changed),
67
+ ...testingSchedules(client, inspection),
68
+ ...testingWaits(inspection, () => fetches, signal),
69
+ checkBatchWindow: (queue, millisecondsPerJob) => testingOperation("checkBatchWindow", async () => {
70
+ const stored = await Effect.runPromise(inspection().queue(queue));
71
+ if (stored === null) {
72
+ throw new Error("Queue is not registered");
73
+ }
74
+ if (stored.expireInSeconds === undefined) {
75
+ throw new Error("Queue has no expiry window");
76
+ }
77
+ if (!Number.isFinite(millisecondsPerJob) || millisecondsPerJob < 0) {
78
+ throw new RangeError("Job duration must be nonnegative and finite");
79
+ }
80
+ const required = (queue.workerOptions.batchSize ?? 10) * millisecondsPerJob;
81
+ if (required >= stored.expireInSeconds * 1000) {
82
+ throw new Error("Sequential batch work must fit within the queue expiry window");
83
+ }
84
+ }, queue.name),
85
+ checkSchemaVersion: (expected) => testingOperation("checkSchemaVersion", async () => {
86
+ if ((await Effect.runPromise(inspection().schemaVersion())) !== expected) {
87
+ throw new Error(`Expected pg-boss schema version ${expected}`);
88
+ }
89
+ }),
90
+ clientFactory,
91
+ expireAfter: (queue, attempts) => Effect.try({
92
+ catch: (original) => new PgBossTestingError({ operation: "expireAfter", original: Redacted.make(original), queue: queue.name }),
93
+ try: () => {
94
+ if (!Number.isSafeInteger(attempts) || attempts < 1) {
95
+ throw new RangeError("Attempts must be a positive integer");
96
+ }
97
+ controls.expirations.set(queue.name, attempts);
98
+ },
99
+ }),
100
+ expireIn: (queue, duration) => Effect.try({
101
+ catch: (original) => new PgBossTestingError({ operation: "expireIn", original: Redacted.make(original), queue: queue.name }),
102
+ try: () => {
103
+ const milliseconds = Duration.toMillis(Duration.fromInputUnsafe(duration));
104
+ if (!Number.isFinite(milliseconds) || milliseconds < 1000) {
105
+ throw new RangeError("Expiry must be finite and at least one second");
106
+ }
107
+ controls.expirySeconds.set(queue.name, Math.ceil(milliseconds / 1000));
108
+ },
109
+ }),
110
+ failNextSend: (queue) => Effect.sync(() => controls.failures.add(queue.name)).pipe(Effect.asVoid),
111
+ jobs: (queue, readOptions) => Effect.suspend(() => testingInspection("jobs", inspection().jobs(queue, readOptions), queue.name)),
112
+ refreshQueueStats: (queue) => testingOperation("refreshQueueStats", () => client().supervise(queue?.name), queue?.name),
113
+ revision: signal.revision,
114
+ schemaVersion: Effect.suspend(() => testingInspection("schemaVersion", inspection().schemaVersion())),
115
+ snapshot: (queues) => Effect.suspend(() => testingInspection("snapshot", inspection().snapshot(queues))),
116
+ waitForChange: signal.waitForChange,
117
+ waitForIdle: idle,
118
+ ...testingTime(settings.clock, clock, idle),
119
+ };
120
+ }
121
+ //# sourceMappingURL=testingController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testingController.js","sourceRoot":"","sources":["../../../src/jobs/adapters/testingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAe,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yDAAyD,CAAC;AAK/F,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAuB,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAChG,OAAO,EAAoB,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC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OAAO,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,UAAU,EAAE,UAAU,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACnF,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,WAAW,EAAE,IAAI;QACjB,GAAG,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC;KAC3C,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { QueueDefinition } from "@shivaedev/jobs/server/definition.ts";
2
+ import type { EngineClient } from "@shivaedev/jobs/server/engineClient.ts";
3
+ export declare function testingDueNow(client: () => EngineClient, schema: () => string, changed: () => void): {
4
+ runDeferredNow: (queue: Pick<QueueDefinition, "name">) => import("effect/Effect").Effect<void, import("../error.ts").PgBossTestingError, never>;
5
+ runDueNow: (queue: Pick<QueueDefinition, "name">) => import("effect/Effect").Effect<void, import("../error.ts").PgBossTestingError, never>;
6
+ };
7
+ //# sourceMappingURL=testingDueNow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testingDueNow.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/testingDueNow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAI3E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,YAAY,EAAE,MAAM,EAAE,MAAM,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI;IAuBjG,cAAc,UAAU,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC;IACrD,SAAS,UAAU,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC;EAEjD"}
@@ -0,0 +1,26 @@
1
+ import { testingOperation } from "#jobs/internal/testingOperation.ts";
2
+ import { quotedSchema } from "./quotedSchema.js";
3
+ export function testingDueNow(client, schema, changed) {
4
+ function makeDue(queue, deferredOnly) {
5
+ return testingOperation(deferredOnly ? "runDeferredNow" : "runDueNow", async () => {
6
+ const quoted = quotedSchema(schema());
7
+ const condition = deferredOnly
8
+ ? "state = 'retry' AND output ? 'jobDeferral' AND started_on IS NULL"
9
+ : `state IN ('created', 'retry') AND start_after > ${quoted}.job_now()`;
10
+ await client()
11
+ .getDb()
12
+ .executeSql(`UPDATE ${quoted}.job SET start_after = ${quoted}.job_now() WHERE name = $1 AND ${condition}`, [queue.name]);
13
+ changed();
14
+ for (const worker of client()
15
+ .getWipData()
16
+ .filter((candidate) => candidate.name === queue.name)) {
17
+ client().notifyWorker(worker.id);
18
+ }
19
+ }, queue.name);
20
+ }
21
+ return {
22
+ runDeferredNow: (queue) => makeDue(queue, true),
23
+ runDueNow: (queue) => makeDue(queue, false),
24
+ };
25
+ }
26
+ //# sourceMappingURL=testingDueNow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testingDueNow.js","sourceRoot":"","sources":["../../../src/jobs/adapters/testingDueNow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,UAAU,aAAa,CAAC,MAA0B,EAAE,MAAoB,EAAE,OAAmB;IAClG,SAAS,OAAO,CAAC,KAAoC,EAAE,YAAqB;QAC3E,OAAO,gBAAgB,CACtB,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,WAAW,EAC7C,KAAK,IAAI,EAAE;YACV,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;YACtC,MAAM,SAAS,GAAG,YAAY;gBAC7B,CAAC,CAAC,mEAAmE;gBACrE,CAAC,CAAC,mDAAmD,MAAM,YAAY,CAAC;YACzE,MAAM,MAAM,EAAE;iBACZ,KAAK,EAAE;iBACP,UAAU,CAAC,UAAU,MAAM,0BAA0B,MAAM,kCAAkC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1H,OAAO,EAAE,CAAC;YACV,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE;iBAC3B,UAAU,EAAE;iBACZ,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxD,MAAM,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAClC,CAAC;QACF,CAAC,EACD,KAAK,CAAC,IAAI,CACV,CAAC;IACH,CAAC;IACD,OAAO;QACN,cAAc,EAAE,CAAC,KAAoC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC;QAC9E,SAAS,EAAE,CAAC,KAAoC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;KAC1E,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Effect } from "effect";
2
+ import type { EngineClient } from "@shivaedev/jobs/server/engineClient.ts";
3
+ import { PgBossTestingError } from "#jobs/error.ts";
4
+ import { expireAttempt } from "./expireAttempt.ts";
5
+ export declare function testingEngine(client: EngineClient, schema: string): {
6
+ expireAttempt: (job: Parameters<typeof expireAttempt>[2], cause?: "expiry" | "heartbeat") => Effect.Effect<void, PgBossTestingError, never>;
7
+ };
8
+ //# sourceMappingURL=testingEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testingEngine.d.ts","sourceRoot":"","sources":["../../../src/jobs/adapters/testingEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAEhE,aAAa,QAAQ,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,UAAU,QAAQ,GAAG,WAAW;EAMzF"}