@shivaedev/server 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +7 -7
- package/package.json +13 -17
- package/dist/testing/HostProcessError.d.ts +0 -10
- package/dist/testing/HostProcessError.d.ts.map +0 -1
- package/dist/testing/HostProcessError.js +0 -4
- package/dist/testing/HostProcessError.js.map +0 -1
- package/dist/testing/adapters/hostProcess.d.ts +0 -24
- package/dist/testing/adapters/hostProcess.d.ts.map +0 -1
- package/dist/testing/adapters/hostProcess.js +0 -111
- package/dist/testing/adapters/hostProcess.js.map +0 -1
- package/dist/testing/adapters/hostProcessReadouts.d.ts +0 -10
- package/dist/testing/adapters/hostProcessReadouts.d.ts.map +0 -1
- package/dist/testing/adapters/hostProcessReadouts.js +0 -26
- package/dist/testing/adapters/hostProcessReadouts.js.map +0 -1
- package/dist/testing/hostProcess.d.ts +0 -26
- package/dist/testing/hostProcess.d.ts.map +0 -1
- package/dist/testing/hostProcess.js +0 -56
- package/dist/testing/hostProcess.js.map +0 -1
- package/dist/testing/hostProcessChild.d.ts +0 -7
- package/dist/testing/hostProcessChild.d.ts.map +0 -1
- package/dist/testing/hostProcessChild.js +0 -19
- package/dist/testing/hostProcessChild.js.map +0 -1
- package/dist/testing/hostProcessProtocol.d.ts +0 -20
- package/dist/testing/hostProcessProtocol.d.ts.map +0 -1
- package/dist/testing/hostProcessProtocol.js +0 -11
- package/dist/testing/hostProcessProtocol.js.map +0 -1
- package/dist/testing/hostProcessReadouts.d.ts +0 -7
- package/dist/testing/hostProcessReadouts.d.ts.map +0 -1
- package/dist/testing/hostProcessReadouts.js +0 -37
- package/dist/testing/hostProcessReadouts.js.map +0 -1
- package/dist/testing/hostTime.d.ts +0 -9
- package/dist/testing/hostTime.d.ts.map +0 -1
- package/dist/testing/hostTime.js +0 -27
- package/dist/testing/hostTime.js.map +0 -1
- package/src/testing/HostProcessError.ts +0 -6
- package/src/testing/adapters/hostProcess.ts +0 -122
- package/src/testing/adapters/hostProcessReadouts.ts +0 -29
- package/src/testing/hostProcess.ts +0 -69
- package/src/testing/hostProcessChild.ts +0 -25
- package/src/testing/hostProcessProtocol.ts +0 -11
- package/src/testing/hostProcessReadouts.ts +0 -46
- package/src/testing/hostTime.ts +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.26.0 - 2026-11-05
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- `testing/*` helpers move under `@shivaedev/test-kits/host/`, dropping the host prefix from filenames: use `process.ts`, `processChild.ts`, `processReadouts.ts`, `processProtocol.ts`, `ProcessError.ts` and `time.ts`. Change imports to those paths; server no longer declares test-sql as a peer.
|
|
8
|
+
|
|
3
9
|
## 0.25.0 - 2026-11-04
|
|
4
10
|
|
|
5
11
|
### Fixed
|
package/README.md
CHANGED
|
@@ -268,7 +268,7 @@ The host defaults to `config.connectionTTL: "10 minutes"` and `config.idleTimeou
|
|
|
268
268
|
|
|
269
269
|
Database pool maintenance, worker-release coordination and change-listener heartbeats, deadlines, retries and renewal use the live clock. A story can advance its application clock by days while the host and job worker keep running; handlers and jobs still see the advanced application time. For stories about database lifecycle timers, pass the story's native `Clock.Clock` service as `config.clock` on `appDatabase` or `appHost`. This option applies to worker-release timers and both application and separate listener pools; it does not change the application clock or migration wait timers.
|
|
270
270
|
|
|
271
|
-
To pass worker-release time in a story, build `hostTime()` from `@shivaedev/
|
|
271
|
+
To pass worker-release time in a story, build `hostTime()` from `@shivaedev/test-kits/host/time.ts` under a native `TestClock`, then provide its `layer` to the worker host. `timePasses(duration)` advances that clock, writes the worker's lease heartbeat at the new time and waits for its release check. Production leases retain PostgreSQL's wall clock. Give separate worker processes the same starting timestamp. When an old worker drains a deliberately held job, advance it with `{ poll: false }` to write its heartbeat without waiting for the drain, then advance the replacement normally. After killing a worker, advance only the replacement; the crashed lease then expires on story time.
|
|
272
272
|
|
|
273
273
|
For a deployment behind a proxy, set `HOST=0.0.0.0` and `TRUSTED_PROXY` to a comma-separated list of proxy peer IPs or CIDR ranges (IPv4 or IPv6), or use `config.host` and `config.trustedProxy`. Only matching peers may supply `X-Forwarded-Host` and `X-Forwarded-Proto` (`http` or `https`) for the guard's same-origin check; the proxy must overwrite both headers and preserve Origin. A single authority is required, and comma-separated forwarding chains are refused. IPv4-mapped IPv6 peers match their IPv4 address. A session host bound to a non-loopback address refuses to boot without `TRUSTED_PROXY` or `config.trustedProxy`, with a typed `TrustedProxyRequired` error from `@shivaedev/server/TrustedProxyRequired.ts` naming both settings and how to supply proxy peer addresses or CIDR ranges. Local loopback hosts keep working without proxy trust; `policy: "loopback"` does not use proxy trust. Malformed addresses or ranges fail `appHost` startup with a typed `ConfigError`. The starter's Railway deployment works out of the box: its web configuration supplies `TRUSTED_PROXY=100.64.0.0/10` and `AUTH_CLIENT_IP_HEADER=x-real-ip`, so matching peers supply forwarded client IPs for auth and the HTTPS authority for RPC origin checks. Set `PUBLIC_URL` to the app's HTTPS URL for secure session cookies. NDJSON and the application's session Origin policy still apply. See the [deployment quickstart](https://github.com/ShivaeDev/platform/blob/main/docs/framework/quickstart.md#deploy).
|
|
274
274
|
|
|
@@ -423,18 +423,18 @@ The signal aborts on an additional signal, socket close, incomplete request clos
|
|
|
423
423
|
|
|
424
424
|
### Stories against a child host
|
|
425
425
|
|
|
426
|
-
`hostProcess(options)` from `@shivaedev/
|
|
426
|
+
`hostProcess(options)` from `@shivaedev/test-kits/host/process.ts` is a scoped kit for an application's real Node host process. It forks `options.module` with `args`, `cwd`, an explicit child environment in `env` and Node flags in `execArgv`. It waits for an IPC readiness message; stdout is ignored and stderr is inherited. Closing the owning Effect scope kills the child and waits for its exit. `stop()` does the same when a story needs to restart the host sooner.
|
|
427
427
|
|
|
428
|
-
In the child entry point, build the app host Layer, then run `reportHostReady` from `@shivaedev/
|
|
428
|
+
In the child entry point, build the app host Layer, then run `reportHostReady` from `@shivaedev/test-kits/host/processChild.ts` with that Layer's context. It reads `HttpServer`, reports the listening URL and process ID over IPC, and fails if there is no parent IPC channel. The child must install its signal handlers before reporting readiness. After a handler finishes its work, run `acknowledgeHostSignal(signal)` from the same module. `signal(signal)` in the parent sends the OS signal and waits for that signal's IPC acknowledgement. Deliver signals sequentially, using signals the child handles; signals that kill or suspend a process cannot be acknowledged.
|
|
429
429
|
|
|
430
|
-
For a restart story, pass the current host's `stop()` Effect as the replacement's `beforeStart` option. In the replacement child, run `awaitHostStart` from `@shivaedev/
|
|
430
|
+
For a restart story, pass the current host's `stop()` Effect as the replacement's `beforeStart` option. In the replacement child, run `awaitHostStart` from `@shivaedev/test-kits/host/processChild.ts` before building the app host Layer. This handshake lets the replacement finish loading its modules while the current host still serves requests. The parent runs `beforeStart` after the child reports preparation, then releases the child with `SIGUSR2` and waits for normal readiness. Reserve that signal until `awaitHostStart` completes.
|
|
431
431
|
|
|
432
432
|
Wrap the kit in the application's story vocabulary:
|
|
433
433
|
|
|
434
434
|
```ts
|
|
435
435
|
import { expect } from "vitest";
|
|
436
436
|
import { storyKit } from "@shivaedev/test-story/server/storyKit.ts";
|
|
437
|
-
import { hostProcess } from "@shivaedev/
|
|
437
|
+
import { hostProcess } from "@shivaedev/test-kits/host/process.ts";
|
|
438
438
|
|
|
439
439
|
const host = storyKit({
|
|
440
440
|
name: "application host",
|
|
@@ -453,9 +453,9 @@ host.it("the running application answers health checks", [], function* ({ health
|
|
|
453
453
|
});
|
|
454
454
|
```
|
|
455
455
|
|
|
456
|
-
`health()` requests `/health` and returns `{ status, body, headers }`. `headers(path)` returns the named path's response headers as a lowercase-keyed record. Both use real HTTP and leave redirects visible. The host's normal health semantics apply: reachable PostgreSQL produces 200; a host without a database produces 503. `url` and `pid` identify the ready child. Launch, signal and HTTP failures use the typed `HostProcessError` from `@shivaedev/
|
|
456
|
+
`health()` requests `/health` and returns `{ status, body, headers }`. `headers(path)` returns the named path's response headers as a lowercase-keyed record. Both use real HTTP and leave redirects visible. The host's normal health semantics apply: reachable PostgreSQL produces 200; a host without a database produces 503. `url` and `pid` identify the ready child. Launch, signal and HTTP failures use the typed `HostProcessError` from `@shivaedev/test-kits/host/ProcessError.ts`, with `operation` and the original `cause`. A child exit before readiness or signal acknowledgement fails the waiting action. A live child that never reports the expected message stays pending until its owning story is interrupted or times out.
|
|
457
457
|
|
|
458
|
-
For lifecycle observations, acquire `hostProcessReadouts` from `@shivaedev/
|
|
458
|
+
For lifecycle observations, acquire `hostProcessReadouts` from `@shivaedev/test-kits/host/processReadouts.ts` in the child before reporting readiness. Keep its scope open until shutdown reporting finishes. Wrap a running Effect with `readouts.work(name, effect)` and a finalizer's Effect with `readouts.finalizer(name, effect)`. These wrappers observe the Effects the application runs; they do not discover uninstrumented work or finalizers. The parent's `activeWork()` returns names in start order, removing each item when it ends, including interrupted work and overlapping items with the same name. `finalizers()` returns names in completion order.
|
|
459
459
|
|
|
460
460
|
Wrap disposal of the host scope or runtime with `readouts.shutdown(dispose)`, then acknowledge the application's shutdown signal. `shutdownDuration()` returns `null` before shutdown completes and elapsed milliseconds afterwards, including finalizer time. The parent retains the completed shutdown's readouts after the child process and its owning scope close; `activeWork()` then returns the work that was active when shutdown began. Forced termination without a completed shutdown report cannot provide these observations.
|
|
461
461
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "The Effect application host: HTTP and RPC serving, health, OTLP export, database and migrations, and development mode",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,25 +46,25 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@shivaedev/changes": "0.10.1",
|
|
49
|
-
"@shivaedev/contract": "0.
|
|
49
|
+
"@shivaedev/contract": "0.37.0",
|
|
50
50
|
"@shivaedev/errors": "0.9.1",
|
|
51
|
-
"@shivaedev/http": "0.
|
|
52
|
-
"@shivaedev/identity": "0.26.
|
|
51
|
+
"@shivaedev/http": "0.7.0",
|
|
52
|
+
"@shivaedev/identity": "0.26.2",
|
|
53
53
|
"@shivaedev/local-postgres": "0.14.1",
|
|
54
|
-
"@shivaedev/sql": "0.
|
|
54
|
+
"@shivaedev/sql": "0.41.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@effect/platform-node": "4.0.7",
|
|
58
58
|
"@effect/sql-pg": "4.0.7",
|
|
59
59
|
"@effect/vitest": "4.0.7",
|
|
60
60
|
"@shivaedev/access": "0.5.1",
|
|
61
|
-
"@shivaedev/admin": "0.20.
|
|
62
|
-
"@shivaedev/jobs": "0.37.
|
|
63
|
-
"@shivaedev/quality": "0.
|
|
64
|
-
"@shivaedev/rate-limit": "0.5.
|
|
65
|
-
"@shivaedev/test-kits": "0.
|
|
66
|
-
"@shivaedev/test-sql": "0.
|
|
67
|
-
"@shivaedev/test-story": "0.
|
|
61
|
+
"@shivaedev/admin": "0.20.4",
|
|
62
|
+
"@shivaedev/jobs": "0.37.1",
|
|
63
|
+
"@shivaedev/quality": "0.63.0",
|
|
64
|
+
"@shivaedev/rate-limit": "0.5.3",
|
|
65
|
+
"@shivaedev/test-kits": "0.6.0",
|
|
66
|
+
"@shivaedev/test-sql": "0.22.0",
|
|
67
|
+
"@shivaedev/test-story": "0.40.0",
|
|
68
68
|
"@types/node": "24.19.2",
|
|
69
69
|
"better-auth": "1.7.14",
|
|
70
70
|
"effect": "4.0.7",
|
|
@@ -76,8 +76,7 @@
|
|
|
76
76
|
"@effect/platform-node": "4.0.7",
|
|
77
77
|
"@effect/sql-pg": "4.0.7",
|
|
78
78
|
"@effect/vitest": "4.0.7",
|
|
79
|
-
"@shivaedev/admin": "0.20.
|
|
80
|
-
"@shivaedev/test-sql": "0.21.2",
|
|
79
|
+
"@shivaedev/admin": "0.20.4",
|
|
81
80
|
"better-auth": "1.7.14",
|
|
82
81
|
"effect": "4.0.7"
|
|
83
82
|
},
|
|
@@ -94,9 +93,6 @@
|
|
|
94
93
|
"@shivaedev/admin": {
|
|
95
94
|
"optional": true
|
|
96
95
|
},
|
|
97
|
-
"@shivaedev/test-sql": {
|
|
98
|
-
"optional": true
|
|
99
|
-
},
|
|
100
96
|
"better-auth": {
|
|
101
97
|
"optional": true
|
|
102
98
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare const HostProcessError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
2
|
-
readonly _tag: "HostProcessError";
|
|
3
|
-
} & Readonly<A>;
|
|
4
|
-
export declare class HostProcessError extends HostProcessError_base<{
|
|
5
|
-
readonly operation: "launch" | "signal" | "request" | "readout";
|
|
6
|
-
readonly cause: unknown;
|
|
7
|
-
}> {
|
|
8
|
-
}
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=HostProcessError.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HostProcessError.d.ts","sourceRoot":"","sources":["../../src/testing/HostProcessError.ts"],"names":[],"mappings":";;;AAEA,qBAAa,gBAAiB,SAAQ,sBAAqC;IAC1E,QAAQ,CAAC,SAAS,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACxB,CAAC;CAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HostProcessError.js","sourceRoot":"","sources":["../../src/testing/HostProcessError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,MAAM,OAAO,gBAAiB,SAAQ,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAGvE;CAAG"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type ChildProcess } from "node:child_process";
|
|
2
|
-
import { type Redacted, Schema } from "effect";
|
|
3
|
-
export interface HostProcessOptions {
|
|
4
|
-
readonly args?: readonly string[];
|
|
5
|
-
readonly cwd?: string;
|
|
6
|
-
readonly databaseUrl?: Redacted.Redacted<string>;
|
|
7
|
-
readonly env?: NodeJS.ProcessEnv;
|
|
8
|
-
readonly execArgv?: readonly string[];
|
|
9
|
-
readonly module: string | URL;
|
|
10
|
-
}
|
|
11
|
-
export declare function forkHost(options: HostProcessOptions, databaseUrl?: string): ChildProcess;
|
|
12
|
-
export declare function receiveHostMessage<A>(child: ChildProcess, schema: Schema.Codec<A>, signal: AbortSignal, action?: () => void): Promise<A>;
|
|
13
|
-
export declare function stopHost(child: ChildProcess): Promise<void>;
|
|
14
|
-
export declare function sendHostMessage(message: unknown): Promise<void>;
|
|
15
|
-
export declare function sendHostReady(url: string): Promise<void>;
|
|
16
|
-
export declare function waitForHostStart(signal: AbortSignal): Promise<void>;
|
|
17
|
-
export declare function hostResponse(url: string, path: string, signal: AbortSignal): Promise<{
|
|
18
|
-
body: string;
|
|
19
|
-
headers: {
|
|
20
|
-
[k: string]: string;
|
|
21
|
-
};
|
|
22
|
-
status: number;
|
|
23
|
-
}>;
|
|
24
|
-
//# sourceMappingURL=hostProcess.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcess.d.ts","sourceRoot":"","sources":["../../../src/testing/adapters/hostProcess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAA0B,MAAM,oBAAoB,CAAC;AAG/E,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC;CAC9B;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,EAAE,WAAW,CAAC,EAAE,MAAM,gBAQzE;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,MAAM,IAAI,cAyC3H;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,iBAQ3C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,iBAQ/C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,iBAExC;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,iBAyBnD;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;;;;;;GAGhF"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { fork } from "node:child_process";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { Option, Schema } from "effect";
|
|
5
|
-
export function forkHost(options, databaseUrl) {
|
|
6
|
-
const settings = {
|
|
7
|
-
cwd: options.cwd,
|
|
8
|
-
env: databaseUrl === undefined ? options.env : { ...options.env, "DATABASE_URL": databaseUrl },
|
|
9
|
-
execArgv: [...(options.execArgv ?? [])],
|
|
10
|
-
stdio: ["ignore", "ignore", "inherit", "ipc"],
|
|
11
|
-
};
|
|
12
|
-
return fork(typeof options.module === "string" ? options.module : fileURLToPath(options.module), [...(options.args ?? [])], settings);
|
|
13
|
-
}
|
|
14
|
-
export function receiveHostMessage(child, schema, signal, action) {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
function cleanup() {
|
|
17
|
-
child.off("message", message);
|
|
18
|
-
child.off("exit", exited);
|
|
19
|
-
child.off("error", failed);
|
|
20
|
-
signal.removeEventListener("abort", aborted);
|
|
21
|
-
}
|
|
22
|
-
function failed(cause) {
|
|
23
|
-
cleanup();
|
|
24
|
-
reject(cause);
|
|
25
|
-
}
|
|
26
|
-
function exited(code, delivered) {
|
|
27
|
-
failed(new Error(`Host exited (${delivered ?? code}) before IPC acknowledgement`));
|
|
28
|
-
}
|
|
29
|
-
function aborted() {
|
|
30
|
-
failed(signal.reason);
|
|
31
|
-
}
|
|
32
|
-
function message(value) {
|
|
33
|
-
const decoded = Schema.decodeUnknownOption(schema)(value);
|
|
34
|
-
if (Option.isSome(decoded)) {
|
|
35
|
-
cleanup();
|
|
36
|
-
resolve(decoded.value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
child.on("message", message);
|
|
40
|
-
child.once("exit", exited);
|
|
41
|
-
child.once("error", failed);
|
|
42
|
-
signal.addEventListener("abort", aborted, { once: true });
|
|
43
|
-
if (signal.aborted) {
|
|
44
|
-
aborted();
|
|
45
|
-
}
|
|
46
|
-
else if (child.exitCode !== null || child.signalCode !== null) {
|
|
47
|
-
exited(child.exitCode, child.signalCode);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
try {
|
|
51
|
-
action?.();
|
|
52
|
-
}
|
|
53
|
-
catch (cause) {
|
|
54
|
-
failed(cause);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
export function stopHost(child) {
|
|
60
|
-
if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) {
|
|
61
|
-
return Promise.resolve();
|
|
62
|
-
}
|
|
63
|
-
return new Promise((resolve) => {
|
|
64
|
-
child.once("exit", () => resolve());
|
|
65
|
-
child.kill("SIGKILL");
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
export function sendHostMessage(message) {
|
|
69
|
-
return new Promise((resolve, reject) => {
|
|
70
|
-
if (process.send === undefined) {
|
|
71
|
-
reject(new Error("Host process needs a parent IPC channel"));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
process.send(message, (error) => (error === null ? resolve() : reject(error)));
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
export function sendHostReady(url) {
|
|
78
|
-
return sendHostMessage({ pid: process.pid, type: "host-ready", url });
|
|
79
|
-
}
|
|
80
|
-
export function waitForHostStart(signal) {
|
|
81
|
-
return new Promise((resolve, reject) => {
|
|
82
|
-
function cleanup() {
|
|
83
|
-
process.off("SIGUSR2", start);
|
|
84
|
-
signal.removeEventListener("abort", aborted);
|
|
85
|
-
}
|
|
86
|
-
function failed(cause) {
|
|
87
|
-
cleanup();
|
|
88
|
-
reject(cause);
|
|
89
|
-
}
|
|
90
|
-
function start() {
|
|
91
|
-
cleanup();
|
|
92
|
-
resolve();
|
|
93
|
-
}
|
|
94
|
-
function aborted() {
|
|
95
|
-
failed(signal.reason);
|
|
96
|
-
}
|
|
97
|
-
process.once("SIGUSR2", start);
|
|
98
|
-
signal.addEventListener("abort", aborted, { once: true });
|
|
99
|
-
if (signal.aborted) {
|
|
100
|
-
aborted();
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
void sendHostMessage({ type: "host-prepared" }).catch(failed);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
export async function hostResponse(url, path, signal) {
|
|
108
|
-
const response = await fetch(new URL(path, url), { redirect: "manual", signal });
|
|
109
|
-
return { body: await response.text(), headers: Object.fromEntries(response.headers), status: response.status };
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=hostProcess.js.map
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,EAAE,CAAC,CAAC;IACjF,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AAChH,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ChildProcess } from "node:child_process";
|
|
2
|
-
import { HostReadouts } from "#testing/hostProcessProtocol.ts";
|
|
3
|
-
export declare function listenHostReadouts(read: () => typeof HostReadouts.Type): () => NodeJS.Process;
|
|
4
|
-
export declare function collectHostReadouts(child: ChildProcess): (signal: AbortSignal) => Promise<{
|
|
5
|
-
readonly activeWork: readonly string[];
|
|
6
|
-
readonly finalizers: readonly string[];
|
|
7
|
-
readonly shutdownDuration: number | null;
|
|
8
|
-
readonly type: "host-readouts";
|
|
9
|
-
}>;
|
|
10
|
-
//# sourceMappingURL=hostProcessReadouts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessReadouts.d.ts","sourceRoot":"","sources":["../../../src/testing/adapters/hostProcessReadouts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAG/D,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,OAAO,YAAY,CAAC,IAAI,wBAQtE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,YAQtC,WAAW;;;;;GAI3B"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
import { Option, Predicate, Schema } from "effect";
|
|
3
|
-
import { HostReadouts } from "#testing/hostProcessProtocol.ts";
|
|
4
|
-
import { receiveHostMessage } from "./hostProcess.js";
|
|
5
|
-
export function listenHostReadouts(read) {
|
|
6
|
-
function requested(message) {
|
|
7
|
-
if (Predicate.hasProperty(message, "type") && message.type === "host-readouts") {
|
|
8
|
-
process.send?.(read());
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
process.on("message", requested);
|
|
12
|
-
return () => process.off("message", requested);
|
|
13
|
-
}
|
|
14
|
-
export function collectHostReadouts(child) {
|
|
15
|
-
let completed;
|
|
16
|
-
child.on("message", (message) => {
|
|
17
|
-
const decoded = Schema.decodeUnknownOption(HostReadouts)(message);
|
|
18
|
-
if (Option.isSome(decoded) && decoded.value.shutdownDuration !== null) {
|
|
19
|
-
completed = decoded.value;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return (signal) => completed === undefined
|
|
23
|
-
? receiveHostMessage(child, HostReadouts, signal, () => child.send({ type: "host-readouts" }))
|
|
24
|
-
: Promise.resolve(completed);
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=hostProcessReadouts.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessReadouts.js","sourceRoot":"","sources":["../../../src/testing/adapters/hostProcessReadouts.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,UAAU,kBAAkB,CAAC,IAAoC;IACtE,SAAS,SAAS,CAAC,OAAgB;QAClC,IAAI,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;YAChF,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACxB,CAAC;IACF,CAAC;IACD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAmB;IACtD,IAAI,SAA+C,CAAC;IACpD,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAgB,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC;QAClE,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;YACvE,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,CAAC;IACF,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,MAAmB,EAAE,EAAE,CAC9B,SAAS,KAAK,SAAS;QACtB,CAAC,CAAC,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC;QAC9F,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import { type HostProcessOptions } from "#testing/adapters/hostProcess.ts";
|
|
3
|
-
import { HostProcessError } from "./HostProcessError.ts";
|
|
4
|
-
export declare const hostProcess: <E = never, R = never>(options: HostProcessOptions & {
|
|
5
|
-
readonly beforeStart?: Effect.Effect<void, E, R>;
|
|
6
|
-
}) => Effect.Effect<{
|
|
7
|
-
activeWork: () => Effect.Effect<readonly string[], HostProcessError, never>;
|
|
8
|
-
disconnectIdlePostgres: () => Effect.Effect<void, never, never>;
|
|
9
|
-
finalizers: () => Effect.Effect<readonly string[], HostProcessError, never>;
|
|
10
|
-
headers: (path: string) => Effect.Effect<{
|
|
11
|
-
[k: string]: string;
|
|
12
|
-
}, HostProcessError, never>;
|
|
13
|
-
health: () => Effect.Effect<{
|
|
14
|
-
body: string;
|
|
15
|
-
headers: {
|
|
16
|
-
[k: string]: string;
|
|
17
|
-
};
|
|
18
|
-
status: number;
|
|
19
|
-
}, HostProcessError, never>;
|
|
20
|
-
pid: number;
|
|
21
|
-
shutdownDuration: () => Effect.Effect<number | null, HostProcessError, never>;
|
|
22
|
-
signal: (delivered: NodeJS.Signals) => Effect.Effect<void, HostProcessError, never>;
|
|
23
|
-
stop: () => Effect.Effect<void, never, never>;
|
|
24
|
-
url: string;
|
|
25
|
-
}, E | HostProcessError, R | import("effect/Scope").Scope>;
|
|
26
|
-
//# sourceMappingURL=hostProcess.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcess.d.ts","sourceRoot":"","sources":["../../src/testing/hostProcess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAY,KAAK,kBAAkB,EAA8C,MAAM,kCAAkC,CAAC;AAEjI,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,eAAO,MAAM,WAAW,GAAmD,CAAC,UAAU,CAAC;2BAC/B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;;;;;oBA8C/D,MAAM;;;;;;;;;;;;wBAIF,MAAM,CAAC,OAAO;;;0DAWlC,CAAC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Effect, Redacted, Schema } from "effect";
|
|
2
|
-
import { forkHost, hostResponse, receiveHostMessage, stopHost } from "#testing/adapters/hostProcess.ts";
|
|
3
|
-
import { collectHostReadouts } from "#testing/adapters/hostProcessReadouts.ts";
|
|
4
|
-
import { HostProcessError } from "./HostProcessError.js";
|
|
5
|
-
import { HostPrepared, HostReady, HostSignal } from "./hostProcessProtocol.js";
|
|
6
|
-
export const hostProcess = Effect.fn("HostProcess.hostProcess")(function* (options) {
|
|
7
|
-
const databaseUrl = options.databaseUrl;
|
|
8
|
-
const database = databaseUrl === undefined
|
|
9
|
-
? undefined
|
|
10
|
-
: yield* Effect.promise(() => import("@shivaedev/test-sql/server/disconnectProxy.ts")).pipe(Effect.flatMap(({ disconnectProxy }) => disconnectProxy(Redacted.value(databaseUrl))));
|
|
11
|
-
const child = yield* Effect.acquireRelease(Effect.try({ catch: (cause) => new HostProcessError({ cause, operation: "launch" }), try: () => forkHost(options, database?.url) }), (acquired) => Effect.promise(() => stopHost(acquired)));
|
|
12
|
-
const read = collectHostReadouts(child);
|
|
13
|
-
if (options.beforeStart !== undefined) {
|
|
14
|
-
yield* Effect.tryPromise({
|
|
15
|
-
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
16
|
-
try: (signal) => receiveHostMessage(child, HostPrepared, signal),
|
|
17
|
-
});
|
|
18
|
-
yield* options.beforeStart;
|
|
19
|
-
}
|
|
20
|
-
const { pid, url } = yield* Effect.tryPromise({
|
|
21
|
-
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
22
|
-
try: (signal) => receiveHostMessage(child, HostReady, signal, options.beforeStart === undefined ? undefined : () => child.kill("SIGUSR2")),
|
|
23
|
-
});
|
|
24
|
-
function response(path) {
|
|
25
|
-
return Effect.tryPromise({
|
|
26
|
-
catch: (cause) => new HostProcessError({ cause, operation: "request" }),
|
|
27
|
-
try: (signal) => hostResponse(url, path, signal),
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function readouts() {
|
|
31
|
-
return Effect.tryPromise({
|
|
32
|
-
catch: (cause) => new HostProcessError({ cause, operation: "readout" }),
|
|
33
|
-
try: read,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
activeWork: () => readouts().pipe(Effect.map((state) => state.activeWork)),
|
|
38
|
-
disconnectIdlePostgres: () => Effect.suspend(() => database === undefined
|
|
39
|
-
? Effect.die(new Error("Launch the host with databaseUrl before disconnecting PostgreSQL"))
|
|
40
|
-
: Effect.sync(database.disconnect)),
|
|
41
|
-
finalizers: () => readouts().pipe(Effect.map((state) => state.finalizers)),
|
|
42
|
-
headers: (path) => response(path).pipe(Effect.map((answer) => answer.headers)),
|
|
43
|
-
health: () => response("/health"),
|
|
44
|
-
pid,
|
|
45
|
-
shutdownDuration: () => readouts().pipe(Effect.map((state) => state.shutdownDuration)),
|
|
46
|
-
signal: (delivered) => Effect.tryPromise({
|
|
47
|
-
catch: (cause) => new HostProcessError({ cause, operation: "signal" }),
|
|
48
|
-
try: (signal) => receiveHostMessage(child, HostSignal.pipe(Schema.check(Schema.makeFilter((ack) => ack.signal === delivered))), signal, () => {
|
|
49
|
-
child.kill(delivered);
|
|
50
|
-
}),
|
|
51
|
-
}).pipe(Effect.asVoid),
|
|
52
|
-
stop: () => Effect.promise(() => stopHost(child)),
|
|
53
|
-
url,
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
//# sourceMappingURL=hostProcess.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcess.js","sourceRoot":"","sources":["../../src/testing/hostProcess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAA2B,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjI,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE/E,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAC,QAAQ,CAAC,EACxE,OAAkF;IAEl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I,CAAC,SAAS,CAAC,CAAC;YACvB,CAAC,CAAC;SACH,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QACvB,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjD,GAAG;KACH,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import { HttpServer } from "effect/http";
|
|
3
|
-
import { HostProcessError } from "#testing/HostProcessError.ts";
|
|
4
|
-
export declare const awaitHostStart: Effect.Effect<void, HostProcessError, never>;
|
|
5
|
-
export declare const reportHostReady: Effect.Effect<void, HostProcessError, HttpServer.HttpServer>;
|
|
6
|
-
export declare function acknowledgeHostSignal(signal: NodeJS.Signals): Effect.Effect<void, HostProcessError, never>;
|
|
7
|
-
//# sourceMappingURL=hostProcessChild.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessChild.d.ts","sourceRoot":"","sources":["../../src/testing/hostProcessChild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,eAAO,MAAM,cAAc,8CAGzB,CAAC;AAEH,eAAO,MAAM,eAAe,8DAO3B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,gDAK3D"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import { HttpServer } from "effect/http";
|
|
3
|
-
import { sendHostMessage, sendHostReady, waitForHostStart } from "#testing/adapters/hostProcess.ts";
|
|
4
|
-
import { HostProcessError } from "#testing/HostProcessError.ts";
|
|
5
|
-
export const awaitHostStart = Effect.tryPromise({
|
|
6
|
-
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
7
|
-
try: waitForHostStart,
|
|
8
|
-
});
|
|
9
|
-
export const reportHostReady = HttpServer.HttpServer.pipe(Effect.flatMap((server) => Effect.tryPromise({
|
|
10
|
-
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
11
|
-
try: () => sendHostReady(HttpServer.formatAddress(server.address)),
|
|
12
|
-
})));
|
|
13
|
-
export function acknowledgeHostSignal(signal) {
|
|
14
|
-
return Effect.tryPromise({
|
|
15
|
-
catch: (cause) => new HostProcessError({ cause, operation: "signal" }),
|
|
16
|
-
try: () => sendHostMessage({ signal, type: "host-signal" }),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=hostProcessChild.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessChild.js","sourceRoot":"","sources":["../../src/testing/hostProcessChild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC;IAC/C,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtE,GAAG,EAAE,gBAAgB;CACrB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CACxD,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CACzB,MAAM,CAAC,UAAU,CAAC;IACjB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;CAClE,CAAC,CACF,CACD,CAAC;AAEF,MAAM,UAAU,qBAAqB,CAAC,MAAsB;IAC3D,OAAO,MAAM,CAAC,UAAU,CAAC;QACxB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;QACtE,GAAG,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;KAC3D,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
export declare const HostReady: Schema.Struct<{
|
|
3
|
-
readonly pid: Schema.Number;
|
|
4
|
-
readonly type: Schema.Literal<"host-ready">;
|
|
5
|
-
readonly url: Schema.String;
|
|
6
|
-
}>;
|
|
7
|
-
export declare const HostPrepared: Schema.Struct<{
|
|
8
|
-
readonly type: Schema.Literal<"host-prepared">;
|
|
9
|
-
}>;
|
|
10
|
-
export declare const HostSignal: Schema.Struct<{
|
|
11
|
-
readonly signal: Schema.String;
|
|
12
|
-
readonly type: Schema.Literal<"host-signal">;
|
|
13
|
-
}>;
|
|
14
|
-
export declare const HostReadouts: Schema.Struct<{
|
|
15
|
-
readonly activeWork: Schema.$Array<Schema.String>;
|
|
16
|
-
readonly finalizers: Schema.$Array<Schema.String>;
|
|
17
|
-
readonly shutdownDuration: Schema.NullOr<Schema.Number>;
|
|
18
|
-
readonly type: Schema.Literal<"host-readouts">;
|
|
19
|
-
}>;
|
|
20
|
-
//# sourceMappingURL=hostProcessProtocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessProtocol.d.ts","sourceRoot":"","sources":["../../src/testing/hostProcessProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,SAAS;;;;EAAgG,CAAC;AACvH,eAAO,MAAM,YAAY;;EAA2D,CAAC;AACrF,eAAO,MAAM,UAAU;;;EAAgF,CAAC;AACxG,eAAO,MAAM,YAAY;;;;;EAKvB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
export const HostReady = Schema.Struct({ pid: Schema.Number, type: Schema.Literal("host-ready"), url: Schema.String });
|
|
3
|
-
export const HostPrepared = Schema.Struct({ type: Schema.Literal("host-prepared") });
|
|
4
|
-
export const HostSignal = Schema.Struct({ signal: Schema.String, type: Schema.Literal("host-signal") });
|
|
5
|
-
export const HostReadouts = Schema.Struct({
|
|
6
|
-
activeWork: Schema.Array(Schema.String),
|
|
7
|
-
finalizers: Schema.Array(Schema.String),
|
|
8
|
-
shutdownDuration: Schema.NullOr(Schema.Number),
|
|
9
|
-
type: Schema.Literal("host-readouts"),
|
|
10
|
-
});
|
|
11
|
-
//# sourceMappingURL=hostProcessProtocol.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessProtocol.js","sourceRoot":"","sources":["../../src/testing/hostProcessProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AACvH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;AACrF,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;AACxG,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC;CACrC,CAAC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
export declare const hostProcessReadouts: Effect.Effect<{
|
|
3
|
-
finalizer: <A, E, R>(name: string, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
4
|
-
shutdown: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
5
|
-
work: <A, E, R>(name: string, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
6
|
-
}, never, import("effect/Scope").Scope>;
|
|
7
|
-
//# sourceMappingURL=hostProcessReadouts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessReadouts.d.ts","sourceRoot":"","sources":["../../src/testing/hostProcessReadouts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKjD,eAAO,MAAM,mBAAmB;gBAsBlB,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,MAAM,UAAU,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;eACtD,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;WAM3C,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,MAAM,UAAU,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;uCAW5D,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Clock, Duration, Effect } from "effect";
|
|
2
|
-
import { sendHostMessage } from "#testing/adapters/hostProcess.ts";
|
|
3
|
-
import { listenHostReadouts } from "#testing/adapters/hostProcessReadouts.ts";
|
|
4
|
-
import { HostProcessError } from "./HostProcessError.js";
|
|
5
|
-
export const hostProcessReadouts = Effect.gen(function* () {
|
|
6
|
-
const active = new Map();
|
|
7
|
-
const finalizers = [];
|
|
8
|
-
let shutdownDuration = null;
|
|
9
|
-
let shutdownWork;
|
|
10
|
-
function read() {
|
|
11
|
-
return { activeWork: shutdownWork ?? [...active.values()], finalizers: [...finalizers], shutdownDuration, type: "host-readouts" };
|
|
12
|
-
}
|
|
13
|
-
function finishShutdown(started) {
|
|
14
|
-
return Effect.gen(function* () {
|
|
15
|
-
shutdownDuration = Duration.toMillis(Duration.nanos((yield* Clock.currentTimeNanos) - started));
|
|
16
|
-
yield* Effect.tryPromise({
|
|
17
|
-
catch: (cause) => new HostProcessError({ cause, operation: "readout" }),
|
|
18
|
-
try: () => sendHostMessage(read()),
|
|
19
|
-
}).pipe(Effect.orDie);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
yield* Effect.acquireRelease(Effect.sync(() => listenHostReadouts(read)), (close) => Effect.sync(close));
|
|
23
|
-
return {
|
|
24
|
-
finalizer: (name, effect) => effect.pipe(Effect.ensuring(Effect.sync(() => finalizers.push(name)))),
|
|
25
|
-
shutdown: (effect) => Effect.gen(function* () {
|
|
26
|
-
shutdownWork = [...active.values()];
|
|
27
|
-
const started = yield* Clock.currentTimeNanos;
|
|
28
|
-
return yield* effect.pipe(Effect.ensuring(finishShutdown(started)));
|
|
29
|
-
}),
|
|
30
|
-
work: (name, effect) => Effect.acquireUseRelease(Effect.sync(() => {
|
|
31
|
-
const id = Symbol(name);
|
|
32
|
-
active.set(id, name);
|
|
33
|
-
return id;
|
|
34
|
-
}), () => effect, (id) => Effect.sync(() => active.delete(id))),
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
//# sourceMappingURL=hostProcessReadouts.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessReadouts.js","sourceRoot":"","sources":["../../src/testing/hostProcessReadouts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACtD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,IAAI,gBAAgB,GAAkB,IAAI,CAAC;IAC3C,IAAI,YAA2C,CAAC;IAChD,SAAS,IAAI;QACZ,OAAO,EAAE,UAAU,EAAE,YAAY,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,UAAU,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,eAAwB,EAAE,CAAC;IAC5I,CAAC;IACD,SAAS,cAAc,CAAC,OAAe;QACtC,OAAO,MAAM,CAAC,GAAG,C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cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC;QACH,IAAI,EAAE,CAAU,IAAY,EAAE,MAA8B,EAAE,EAAE,CAC/D,MAAM,CAAC,iBAAiB,CACvB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;YAChB,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACrB,OAAO,EAAE,CAAC;QACX,CAAC,CAAC,EACF,GAAG,EAAE,CAAC,MAAM,EACZ,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAC5C;KACF,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Duration, Effect, Layer } from "effect";
|
|
2
|
-
import { WorkerReleaseTesting } from "@shivaedev/sql/testing/WorkerRelease.ts";
|
|
3
|
-
export declare const hostTime: () => Effect.Effect<{
|
|
4
|
-
layer: Layer.Layer<WorkerReleaseTesting, never, never>;
|
|
5
|
-
timePasses: (duration: Duration.Input, options?: {
|
|
6
|
-
readonly poll?: boolean;
|
|
7
|
-
}) => Effect.Effect<void, import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
8
|
-
}, never, never>;
|
|
9
|
-
//# sourceMappingURL=hostTime.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostTime.d.ts","sourceRoot":"","sources":["../../src/testing/hostTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,eAAO,MAAM,QAAQ;;2BAiBI,QAAQ,CAAC,KAAK,YAAY;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE;gBAW5E,CAAC"}
|
package/dist/testing/hostTime.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Effect, Layer } from "effect";
|
|
2
|
-
import { TestClock } from "effect/testing";
|
|
3
|
-
import { WorkerReleaseTesting } from "@shivaedev/sql/testing/WorkerRelease.ts";
|
|
4
|
-
export const hostTime = Effect.fn("HostTime.hostTime")(function* () {
|
|
5
|
-
const clock = yield* TestClock.testClockWith(Effect.succeed);
|
|
6
|
-
const ticks = new Set();
|
|
7
|
-
return {
|
|
8
|
-
layer: Layer.succeed(WorkerReleaseTesting, {
|
|
9
|
-
clock,
|
|
10
|
-
register: (tick) => Effect.acquireRelease(Effect.sync(() => {
|
|
11
|
-
ticks.add(tick);
|
|
12
|
-
}), () => Effect.sync(() => {
|
|
13
|
-
ticks.delete(tick);
|
|
14
|
-
})).pipe(Effect.asVoid),
|
|
15
|
-
}),
|
|
16
|
-
timePasses: (duration, options) => Effect.gen(function* () {
|
|
17
|
-
yield* clock.adjust(duration);
|
|
18
|
-
for (const tick of ticks) {
|
|
19
|
-
yield* tick.heartbeat;
|
|
20
|
-
if (options?.poll !== false) {
|
|
21
|
-
yield* tick.poll;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}),
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
//# sourceMappingURL=hostTime.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostTime.js","sourceRoot":"","sources":["../../src/testing/hostTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC;IAC/D,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+D,CAAC;IACrF,OAAO;QACN,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,oBAAoB,EAAE;YAC1C,KAAK;YACL,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAClB,MAAM,CAAC,cAAc,CACpB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;gBAChB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC,CAAC,EACF,GAAG,EAAE,CACJ,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;gBAChB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACpB,CAAC,CAAC,CACH,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;SACtB,CAAC;QACF,UAAU,EAAE,CAAC,QAAwB,EAAE,OAAqC,EAAE,EAAE,CAC/E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC1B,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;gBACtB,IAAI,OAAO,EAAE,IAAI,KAAK,KAAK,EAAE,CAAC;oBAC7B,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;gBAClB,CAAC;YACF,CAAC;QACF,CAAC,CAAC;KACH,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { type ChildProcess, type ForkOptions, fork } from "node:child_process";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { Option, type Redacted, Schema } from "effect";
|
|
5
|
-
|
|
6
|
-
export interface HostProcessOptions {
|
|
7
|
-
readonly args?: readonly string[];
|
|
8
|
-
readonly cwd?: string;
|
|
9
|
-
readonly databaseUrl?: Redacted.Redacted<string>;
|
|
10
|
-
readonly env?: NodeJS.ProcessEnv;
|
|
11
|
-
readonly execArgv?: readonly string[];
|
|
12
|
-
readonly module: string | URL;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function forkHost(options: HostProcessOptions, databaseUrl?: string) {
|
|
16
|
-
const settings: ForkOptions = {
|
|
17
|
-
cwd: options.cwd,
|
|
18
|
-
env: databaseUrl === undefined ? options.env : { ...options.env, "DATABASE_URL": databaseUrl },
|
|
19
|
-
execArgv: [...(options.execArgv ?? [])],
|
|
20
|
-
stdio: ["ignore", "ignore", "inherit", "ipc"],
|
|
21
|
-
};
|
|
22
|
-
return fork(typeof options.module === "string" ? options.module : fileURLToPath(options.module), [...(options.args ?? [])], settings);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function receiveHostMessage<A>(child: ChildProcess, schema: Schema.Codec<A>, signal: AbortSignal, action?: () => void) {
|
|
26
|
-
return new Promise<A>((resolve, reject) => {
|
|
27
|
-
function cleanup() {
|
|
28
|
-
child.off("message", message);
|
|
29
|
-
child.off("exit", exited);
|
|
30
|
-
child.off("error", failed);
|
|
31
|
-
signal.removeEventListener("abort", aborted);
|
|
32
|
-
}
|
|
33
|
-
function failed(cause: unknown) {
|
|
34
|
-
cleanup();
|
|
35
|
-
reject(cause);
|
|
36
|
-
}
|
|
37
|
-
function exited(code: number | null, delivered: NodeJS.Signals | null) {
|
|
38
|
-
failed(new Error(`Host exited (${delivered ?? code}) before IPC acknowledgement`));
|
|
39
|
-
}
|
|
40
|
-
function aborted() {
|
|
41
|
-
failed(signal.reason);
|
|
42
|
-
}
|
|
43
|
-
function message(value: unknown) {
|
|
44
|
-
const decoded = Schema.decodeUnknownOption(schema)(value);
|
|
45
|
-
if (Option.isSome(decoded)) {
|
|
46
|
-
cleanup();
|
|
47
|
-
resolve(decoded.value);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
child.on("message", message);
|
|
51
|
-
child.once("exit", exited);
|
|
52
|
-
child.once("error", failed);
|
|
53
|
-
signal.addEventListener("abort", aborted, { once: true });
|
|
54
|
-
if (signal.aborted) {
|
|
55
|
-
aborted();
|
|
56
|
-
} else if (child.exitCode !== null || child.signalCode !== null) {
|
|
57
|
-
exited(child.exitCode, child.signalCode);
|
|
58
|
-
} else {
|
|
59
|
-
try {
|
|
60
|
-
action?.();
|
|
61
|
-
} catch (cause) {
|
|
62
|
-
failed(cause);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function stopHost(child: ChildProcess) {
|
|
69
|
-
if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) {
|
|
70
|
-
return Promise.resolve();
|
|
71
|
-
}
|
|
72
|
-
return new Promise<void>((resolve) => {
|
|
73
|
-
child.once("exit", () => resolve());
|
|
74
|
-
child.kill("SIGKILL");
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function sendHostMessage(message: unknown) {
|
|
79
|
-
return new Promise<void>((resolve, reject) => {
|
|
80
|
-
if (process.send === undefined) {
|
|
81
|
-
reject(new Error("Host process needs a parent IPC channel"));
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
process.send(message, (error) => (error === null ? resolve() : reject(error)));
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function sendHostReady(url: string) {
|
|
89
|
-
return sendHostMessage({ pid: process.pid, type: "host-ready", url });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function waitForHostStart(signal: AbortSignal) {
|
|
93
|
-
return new Promise<void>((resolve, reject) => {
|
|
94
|
-
function cleanup() {
|
|
95
|
-
process.off("SIGUSR2", start);
|
|
96
|
-
signal.removeEventListener("abort", aborted);
|
|
97
|
-
}
|
|
98
|
-
function failed(cause: unknown) {
|
|
99
|
-
cleanup();
|
|
100
|
-
reject(cause);
|
|
101
|
-
}
|
|
102
|
-
function start() {
|
|
103
|
-
cleanup();
|
|
104
|
-
resolve();
|
|
105
|
-
}
|
|
106
|
-
function aborted() {
|
|
107
|
-
failed(signal.reason);
|
|
108
|
-
}
|
|
109
|
-
process.once("SIGUSR2", start);
|
|
110
|
-
signal.addEventListener("abort", aborted, { once: true });
|
|
111
|
-
if (signal.aborted) {
|
|
112
|
-
aborted();
|
|
113
|
-
} else {
|
|
114
|
-
void sendHostMessage({ type: "host-prepared" }).catch(failed);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export async function hostResponse(url: string, path: string, signal: AbortSignal) {
|
|
120
|
-
const response = await fetch(new URL(path, url), { redirect: "manual", signal });
|
|
121
|
-
return { body: await response.text(), headers: Object.fromEntries(response.headers), status: response.status };
|
|
122
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { ChildProcess } from "node:child_process";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import { Option, Predicate, Schema } from "effect";
|
|
4
|
-
import { HostReadouts } from "#testing/hostProcessProtocol.ts";
|
|
5
|
-
import { receiveHostMessage } from "./hostProcess.ts";
|
|
6
|
-
|
|
7
|
-
export function listenHostReadouts(read: () => typeof HostReadouts.Type) {
|
|
8
|
-
function requested(message: unknown) {
|
|
9
|
-
if (Predicate.hasProperty(message, "type") && message.type === "host-readouts") {
|
|
10
|
-
process.send?.(read());
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
process.on("message", requested);
|
|
14
|
-
return () => process.off("message", requested);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function collectHostReadouts(child: ChildProcess) {
|
|
18
|
-
let completed: typeof HostReadouts.Type | undefined;
|
|
19
|
-
child.on("message", (message: unknown) => {
|
|
20
|
-
const decoded = Schema.decodeUnknownOption(HostReadouts)(message);
|
|
21
|
-
if (Option.isSome(decoded) && decoded.value.shutdownDuration !== null) {
|
|
22
|
-
completed = decoded.value;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return (signal: AbortSignal) =>
|
|
26
|
-
completed === undefined
|
|
27
|
-
? receiveHostMessage(child, HostReadouts, signal, () => child.send({ type: "host-readouts" }))
|
|
28
|
-
: Promise.resolve(completed);
|
|
29
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Effect, Redacted, Schema } from "effect";
|
|
2
|
-
import { forkHost, type HostProcessOptions, hostResponse, receiveHostMessage, stopHost } from "#testing/adapters/hostProcess.ts";
|
|
3
|
-
import { collectHostReadouts } from "#testing/adapters/hostProcessReadouts.ts";
|
|
4
|
-
import { HostProcessError } from "./HostProcessError.ts";
|
|
5
|
-
import { HostPrepared, HostReady, HostSignal } from "./hostProcessProtocol.ts";
|
|
6
|
-
|
|
7
|
-
export const hostProcess = Effect.fn("HostProcess.hostProcess")(function* <E = never, R = never>(
|
|
8
|
-
options: HostProcessOptions & { readonly beforeStart?: Effect.Effect<void, E, R> },
|
|
9
|
-
) {
|
|
10
|
-
const databaseUrl = options.databaseUrl;
|
|
11
|
-
const database =
|
|
12
|
-
databaseUrl === undefined
|
|
13
|
-
? undefined
|
|
14
|
-
: yield* Effect.promise(() => import("@shivaedev/test-sql/server/disconnectProxy.ts")).pipe(
|
|
15
|
-
Effect.flatMap(({ disconnectProxy }) => disconnectProxy(Redacted.value(databaseUrl))),
|
|
16
|
-
);
|
|
17
|
-
const child = yield* Effect.acquireRelease(
|
|
18
|
-
Effect.try({ catch: (cause) => new HostProcessError({ cause, operation: "launch" }), try: () => forkHost(options, database?.url) }),
|
|
19
|
-
(acquired) => Effect.promise(() => stopHost(acquired)),
|
|
20
|
-
);
|
|
21
|
-
const read = collectHostReadouts(child);
|
|
22
|
-
if (options.beforeStart !== undefined) {
|
|
23
|
-
yield* Effect.tryPromise({
|
|
24
|
-
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
25
|
-
try: (signal) => receiveHostMessage(child, HostPrepared, signal),
|
|
26
|
-
});
|
|
27
|
-
yield* options.beforeStart;
|
|
28
|
-
}
|
|
29
|
-
const { pid, url } = yield* Effect.tryPromise({
|
|
30
|
-
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
31
|
-
try: (signal) => receiveHostMessage(child, HostReady, signal, options.beforeStart === undefined ? undefined : () => child.kill("SIGUSR2")),
|
|
32
|
-
});
|
|
33
|
-
function response(path: string) {
|
|
34
|
-
return Effect.tryPromise({
|
|
35
|
-
catch: (cause) => new HostProcessError({ cause, operation: "request" }),
|
|
36
|
-
try: (signal) => hostResponse(url, path, signal),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function readouts() {
|
|
40
|
-
return Effect.tryPromise({
|
|
41
|
-
catch: (cause) => new HostProcessError({ cause, operation: "readout" }),
|
|
42
|
-
try: read,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
activeWork: () => readouts().pipe(Effect.map((state) => state.activeWork)),
|
|
47
|
-
disconnectIdlePostgres: () =>
|
|
48
|
-
Effect.suspend(() =>
|
|
49
|
-
database === undefined
|
|
50
|
-
? Effect.die(new Error("Launch the host with databaseUrl before disconnecting PostgreSQL"))
|
|
51
|
-
: Effect.sync(database.disconnect),
|
|
52
|
-
),
|
|
53
|
-
finalizers: () => readouts().pipe(Effect.map((state) => state.finalizers)),
|
|
54
|
-
headers: (path: string) => response(path).pipe(Effect.map((answer) => answer.headers)),
|
|
55
|
-
health: () => response("/health"),
|
|
56
|
-
pid,
|
|
57
|
-
shutdownDuration: () => readouts().pipe(Effect.map((state) => state.shutdownDuration)),
|
|
58
|
-
signal: (delivered: NodeJS.Signals) =>
|
|
59
|
-
Effect.tryPromise({
|
|
60
|
-
catch: (cause) => new HostProcessError({ cause, operation: "signal" }),
|
|
61
|
-
try: (signal) =>
|
|
62
|
-
receiveHostMessage(child, HostSignal.pipe(Schema.check(Schema.makeFilter((ack) => ack.signal === delivered))), signal, () => {
|
|
63
|
-
child.kill(delivered);
|
|
64
|
-
}),
|
|
65
|
-
}).pipe(Effect.asVoid),
|
|
66
|
-
stop: () => Effect.promise(() => stopHost(child)),
|
|
67
|
-
url,
|
|
68
|
-
};
|
|
69
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import { HttpServer } from "effect/http";
|
|
3
|
-
import { sendHostMessage, sendHostReady, waitForHostStart } from "#testing/adapters/hostProcess.ts";
|
|
4
|
-
import { HostProcessError } from "#testing/HostProcessError.ts";
|
|
5
|
-
|
|
6
|
-
export const awaitHostStart = Effect.tryPromise({
|
|
7
|
-
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
8
|
-
try: waitForHostStart,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
export const reportHostReady = HttpServer.HttpServer.pipe(
|
|
12
|
-
Effect.flatMap((server) =>
|
|
13
|
-
Effect.tryPromise({
|
|
14
|
-
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
15
|
-
try: () => sendHostReady(HttpServer.formatAddress(server.address)),
|
|
16
|
-
}),
|
|
17
|
-
),
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
export function acknowledgeHostSignal(signal: NodeJS.Signals) {
|
|
21
|
-
return Effect.tryPromise({
|
|
22
|
-
catch: (cause) => new HostProcessError({ cause, operation: "signal" }),
|
|
23
|
-
try: () => sendHostMessage({ signal, type: "host-signal" }),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
|
|
3
|
-
export const HostReady = Schema.Struct({ pid: Schema.Number, type: Schema.Literal("host-ready"), url: Schema.String });
|
|
4
|
-
export const HostPrepared = Schema.Struct({ type: Schema.Literal("host-prepared") });
|
|
5
|
-
export const HostSignal = Schema.Struct({ signal: Schema.String, type: Schema.Literal("host-signal") });
|
|
6
|
-
export const HostReadouts = Schema.Struct({
|
|
7
|
-
activeWork: Schema.Array(Schema.String),
|
|
8
|
-
finalizers: Schema.Array(Schema.String),
|
|
9
|
-
shutdownDuration: Schema.NullOr(Schema.Number),
|
|
10
|
-
type: Schema.Literal("host-readouts"),
|
|
11
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Clock, Duration, Effect } from "effect";
|
|
2
|
-
import { sendHostMessage } from "#testing/adapters/hostProcess.ts";
|
|
3
|
-
import { listenHostReadouts } from "#testing/adapters/hostProcessReadouts.ts";
|
|
4
|
-
import { HostProcessError } from "./HostProcessError.ts";
|
|
5
|
-
|
|
6
|
-
export const hostProcessReadouts = Effect.gen(function* () {
|
|
7
|
-
const active = new Map<symbol, string>();
|
|
8
|
-
const finalizers: string[] = [];
|
|
9
|
-
let shutdownDuration: number | null = null;
|
|
10
|
-
let shutdownWork: readonly string[] | undefined;
|
|
11
|
-
function read() {
|
|
12
|
-
return { activeWork: shutdownWork ?? [...active.values()], finalizers: [...finalizers], shutdownDuration, type: "host-readouts" as const };
|
|
13
|
-
}
|
|
14
|
-
function finishShutdown(started: bigint) {
|
|
15
|
-
return Effect.gen(function* () {
|
|
16
|
-
shutdownDuration = Duration.toMillis(Duration.nanos((yield* Clock.currentTimeNanos) - started));
|
|
17
|
-
yield* Effect.tryPromise({
|
|
18
|
-
catch: (cause) => new HostProcessError({ cause, operation: "readout" }),
|
|
19
|
-
try: () => sendHostMessage(read()),
|
|
20
|
-
}).pipe(Effect.orDie);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
yield* Effect.acquireRelease(
|
|
24
|
-
Effect.sync(() => listenHostReadouts(read)),
|
|
25
|
-
(close) => Effect.sync(close),
|
|
26
|
-
);
|
|
27
|
-
return {
|
|
28
|
-
finalizer: <A, E, R>(name: string, effect: Effect.Effect<A, E, R>) => effect.pipe(Effect.ensuring(Effect.sync(() => finalizers.push(name)))),
|
|
29
|
-
shutdown: <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
30
|
-
Effect.gen(function* () {
|
|
31
|
-
shutdownWork = [...active.values()];
|
|
32
|
-
const started = yield* Clock.currentTimeNanos;
|
|
33
|
-
return yield* effect.pipe(Effect.ensuring(finishShutdown(started)));
|
|
34
|
-
}),
|
|
35
|
-
work: <A, E, R>(name: string, effect: Effect.Effect<A, E, R>) =>
|
|
36
|
-
Effect.acquireUseRelease(
|
|
37
|
-
Effect.sync(() => {
|
|
38
|
-
const id = Symbol(name);
|
|
39
|
-
active.set(id, name);
|
|
40
|
-
return id;
|
|
41
|
-
}),
|
|
42
|
-
() => effect,
|
|
43
|
-
(id) => Effect.sync(() => active.delete(id)),
|
|
44
|
-
),
|
|
45
|
-
};
|
|
46
|
-
});
|
package/src/testing/hostTime.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type Duration, Effect, Layer } from "effect";
|
|
2
|
-
import { TestClock } from "effect/testing";
|
|
3
|
-
import { WorkerReleaseTesting } from "@shivaedev/sql/testing/WorkerRelease.ts";
|
|
4
|
-
|
|
5
|
-
export const hostTime = Effect.fn("HostTime.hostTime")(function* () {
|
|
6
|
-
const clock = yield* TestClock.testClockWith(Effect.succeed);
|
|
7
|
-
const ticks = new Set<Parameters<typeof WorkerReleaseTesting.Service.register>[0]>();
|
|
8
|
-
return {
|
|
9
|
-
layer: Layer.succeed(WorkerReleaseTesting, {
|
|
10
|
-
clock,
|
|
11
|
-
register: (tick) =>
|
|
12
|
-
Effect.acquireRelease(
|
|
13
|
-
Effect.sync(() => {
|
|
14
|
-
ticks.add(tick);
|
|
15
|
-
}),
|
|
16
|
-
() =>
|
|
17
|
-
Effect.sync(() => {
|
|
18
|
-
ticks.delete(tick);
|
|
19
|
-
}),
|
|
20
|
-
).pipe(Effect.asVoid),
|
|
21
|
-
}),
|
|
22
|
-
timePasses: (duration: Duration.Input, options?: { readonly poll?: boolean }) =>
|
|
23
|
-
Effect.gen(function* () {
|
|
24
|
-
yield* clock.adjust(duration);
|
|
25
|
-
for (const tick of ticks) {
|
|
26
|
-
yield* tick.heartbeat;
|
|
27
|
-
if (options?.poll !== false) {
|
|
28
|
-
yield* tick.poll;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
});
|