@livestore/utils-dev 0.4.0-dev.3 → 0.4.0-dev.6

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 (62) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/node/DockerComposeService/DockerComposeService.d.ts +48 -0
  3. package/dist/node/DockerComposeService/DockerComposeService.d.ts.map +1 -0
  4. package/dist/node/DockerComposeService/DockerComposeService.js +107 -0
  5. package/dist/node/DockerComposeService/DockerComposeService.js.map +1 -0
  6. package/dist/node/DockerComposeService/DockerComposeService.test.d.ts +2 -0
  7. package/dist/node/DockerComposeService/DockerComposeService.test.d.ts.map +1 -0
  8. package/dist/node/DockerComposeService/DockerComposeService.test.js +64 -0
  9. package/dist/node/DockerComposeService/DockerComposeService.test.js.map +1 -0
  10. package/dist/node/WranglerDevServer/WranglerDevServer.d.ts +52 -0
  11. package/dist/node/WranglerDevServer/WranglerDevServer.d.ts.map +1 -0
  12. package/dist/node/WranglerDevServer/WranglerDevServer.js +122 -0
  13. package/dist/node/WranglerDevServer/WranglerDevServer.js.map +1 -0
  14. package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts +2 -0
  15. package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts.map +1 -0
  16. package/dist/node/WranglerDevServer/WranglerDevServer.test.js +179 -0
  17. package/dist/node/WranglerDevServer/WranglerDevServer.test.js.map +1 -0
  18. package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts +8 -0
  19. package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts.map +1 -0
  20. package/dist/node/WranglerDevServer/fixtures/cf-worker.js +11 -0
  21. package/dist/node/WranglerDevServer/fixtures/cf-worker.js.map +1 -0
  22. package/dist/node/WranglerDevServer/process-tree-manager.d.ts +55 -0
  23. package/dist/node/WranglerDevServer/process-tree-manager.d.ts.map +1 -0
  24. package/dist/node/WranglerDevServer/process-tree-manager.js +178 -0
  25. package/dist/node/WranglerDevServer/process-tree-manager.js.map +1 -0
  26. package/dist/node/cmd.d.ts +27 -0
  27. package/dist/node/cmd.d.ts.map +1 -0
  28. package/dist/node/cmd.js +55 -0
  29. package/dist/node/cmd.js.map +1 -0
  30. package/dist/node/mod.d.ts +6 -26
  31. package/dist/node/mod.d.ts.map +1 -1
  32. package/dist/node/mod.js +6 -54
  33. package/dist/node/mod.js.map +1 -1
  34. package/dist/node/vitest-docker-compose-setup.d.ts +32 -0
  35. package/dist/node/vitest-docker-compose-setup.d.ts.map +1 -0
  36. package/dist/node/vitest-docker-compose-setup.js +131 -0
  37. package/dist/node/vitest-docker-compose-setup.js.map +1 -0
  38. package/dist/node/vitest-wrangler-setup.d.ts +27 -0
  39. package/dist/node/vitest-wrangler-setup.d.ts.map +1 -0
  40. package/dist/node/vitest-wrangler-setup.js +96 -0
  41. package/dist/node/vitest-wrangler-setup.js.map +1 -0
  42. package/dist/node-vitest/Vitest.d.ts +37 -3
  43. package/dist/node-vitest/Vitest.d.ts.map +1 -1
  44. package/dist/node-vitest/Vitest.js +81 -4
  45. package/dist/node-vitest/Vitest.js.map +1 -1
  46. package/dist/node-vitest/Vitest.test.d.ts +2 -0
  47. package/dist/node-vitest/Vitest.test.d.ts.map +1 -0
  48. package/dist/node-vitest/Vitest.test.js +59 -0
  49. package/dist/node-vitest/Vitest.test.js.map +1 -0
  50. package/package.json +7 -9
  51. package/src/node/DockerComposeService/DockerComposeService.test.ts +91 -0
  52. package/src/node/DockerComposeService/DockerComposeService.ts +252 -0
  53. package/src/node/DockerComposeService/test-fixtures/docker-compose.yml +4 -0
  54. package/src/node/WranglerDevServer/WranglerDevServer.test.ts +266 -0
  55. package/src/node/WranglerDevServer/WranglerDevServer.ts +266 -0
  56. package/src/node/WranglerDevServer/fixtures/cf-worker.ts +11 -0
  57. package/src/node/WranglerDevServer/fixtures/wrangler.toml +11 -0
  58. package/src/node/WranglerDevServer/process-tree-manager.ts +263 -0
  59. package/src/node/cmd.ts +99 -0
  60. package/src/node/mod.ts +20 -111
  61. package/src/node-vitest/Vitest.test.ts +101 -0
  62. package/src/node-vitest/Vitest.ts +173 -9
@@ -0,0 +1,48 @@
1
+ import { type CommandExecutor, Duration, Effect, type PlatformError, Schema, type Scope, Stream } from '@livestore/utils/effect';
2
+ declare const DockerComposeError_base: Schema.TaggedErrorClass<DockerComposeError, "DockerComposeError", {
3
+ readonly _tag: Schema.tag<"DockerComposeError">;
4
+ } & {
5
+ cause: typeof Schema.Defect;
6
+ message: typeof Schema.String;
7
+ }>;
8
+ export declare class DockerComposeError extends DockerComposeError_base {
9
+ }
10
+ export interface DockerComposeArgs {
11
+ readonly cwd: string;
12
+ readonly serviceName?: string;
13
+ }
14
+ export interface StartOptions {
15
+ readonly detached?: boolean;
16
+ readonly env?: Record<string, string>;
17
+ readonly healthCheck?: {
18
+ readonly url: string;
19
+ readonly timeout?: Duration.Duration;
20
+ readonly interval?: Duration.Duration;
21
+ };
22
+ }
23
+ export interface LogsOptions {
24
+ readonly follow?: boolean;
25
+ readonly tail?: number;
26
+ readonly since?: string;
27
+ }
28
+ export interface DockerComposeOperations {
29
+ readonly pull: Effect.Effect<void, DockerComposeError | PlatformError.PlatformError>;
30
+ readonly start: (options?: StartOptions) => Effect.Effect<void, DockerComposeError | PlatformError.PlatformError, Scope.Scope>;
31
+ readonly stop: Effect.Effect<void, DockerComposeError | PlatformError.PlatformError>;
32
+ readonly logs: (options?: LogsOptions) => Stream.Stream<string, DockerComposeError | PlatformError.PlatformError, Scope.Scope>;
33
+ }
34
+ declare const DockerComposeService_base: Effect.Service.Class<DockerComposeService, "DockerComposeService", {
35
+ readonly scoped: (args: DockerComposeArgs) => Effect.Effect<{
36
+ pull: Effect.Effect<void, DockerComposeError | PlatformError.PlatformError, never>;
37
+ start: (options?: StartOptions) => Effect.Effect<void, DockerComposeError | PlatformError.PlatformError, Scope.Scope>;
38
+ stop: Effect.Effect<void, DockerComposeError | PlatformError.PlatformError, never>;
39
+ logs: (options?: LogsOptions) => Stream.Stream<string, DockerComposeError, never>;
40
+ }, never, CommandExecutor.CommandExecutor>;
41
+ }>;
42
+ export declare class DockerComposeService extends DockerComposeService_base {
43
+ }
44
+ export declare const startDockerComposeServicesScoped: (args: DockerComposeArgs & {
45
+ healthCheck?: StartOptions["healthCheck"];
46
+ }) => Effect.Effect<void, DockerComposeError | PlatformError.PlatformError, DockerComposeService | CommandExecutor.CommandExecutor | Scope.Scope>;
47
+ export {};
48
+ //# sourceMappingURL=DockerComposeService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DockerComposeService.d.ts","sourceRoot":"","sources":["../../../src/node/DockerComposeService/DockerComposeService.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACpB,QAAQ,EACR,MAAM,EACN,KAAK,aAAa,EAElB,MAAM,EACN,KAAK,KAAK,EACV,MAAM,EACP,MAAM,yBAAyB,CAAA;;;;;;;AAEhC,qBAAa,kBAAmB,SAAQ,uBAGtC;CAAG;AAEL,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,QAAQ,CAAC,WAAW,CAAC,EAAE;QACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;QACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAA;QACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAA;KACtC,CAAA;CACF;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAA;IACpF,QAAQ,CAAC,KAAK,EAAE,CACd,OAAO,CAAC,EAAE,YAAY,KACnB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,aAAa,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;IACvF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAA;IACpF,QAAQ,CAAC,IAAI,EAAE,CACb,OAAO,CAAC,EAAE,WAAW,KAClB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,aAAa,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;CAC1F;;4BAGgB,iBAAiB;;0BA4BJ,YAAY;;yBAyEb,WAAW;;;AAtGxC,qBAAa,oBAAqB,SAAQ,yBA6IxC;CAAG;AAyCL,eAAO,MAAM,gCAAgC,GAC3C,MAAM,iBAAiB,GAAG;IACxB,WAAW,CAAC,EAAE,YAAY,CAAC,aAAa,CAAC,CAAA;CAC1C,KACA,MAAM,CAAC,MAAM,CACd,IAAI,EACJ,kBAAkB,GAAG,aAAa,CAAC,aAAa,EAChD,oBAAoB,GAAG,eAAe,CAAC,eAAe,GAAG,KAAK,CAAC,KAAK,CAYlE,CAAA"}
@@ -0,0 +1,107 @@
1
+ import { omitUndefineds } from '@livestore/utils';
2
+ import { Command, Duration, Effect, Schedule, Schema, Stream, } from '@livestore/utils/effect';
3
+ export class DockerComposeError extends Schema.TaggedError()('DockerComposeError', {
4
+ cause: Schema.Defect,
5
+ message: Schema.String,
6
+ }) {
7
+ }
8
+ export class DockerComposeService extends Effect.Service()('DockerComposeService', {
9
+ scoped: (args) => Effect.gen(function* () {
10
+ const { cwd, serviceName } = args;
11
+ const commandExecutorContext = yield* Effect.context();
12
+ const pull = Effect.gen(function* () {
13
+ yield* Effect.log(`Pulling Docker Compose images in ${cwd}`);
14
+ yield* Command.make('docker', 'compose', 'pull').pipe(Command.workingDirectory(cwd), Command.exitCode, Effect.flatMap((exitCode) => exitCode === 0
15
+ ? Effect.void
16
+ : Effect.fail(new DockerComposeError({
17
+ cause: new Error(`Docker compose pull failed with exit code ${exitCode}`),
18
+ message: `Docker compose pull failed with exit code ${exitCode}`,
19
+ }))), Effect.provide(commandExecutorContext));
20
+ yield* Effect.log(`Successfully pulled Docker Compose images`);
21
+ }).pipe(Effect.withSpan('pullDockerComposeImages'));
22
+ const start = (options = {}) => Effect.gen(function* () {
23
+ const { detached = true, healthCheck } = options;
24
+ // Build start command
25
+ const baseArgs = ['docker', 'compose', 'up'];
26
+ if (detached)
27
+ baseArgs.push('-d');
28
+ if (serviceName)
29
+ baseArgs.push(serviceName);
30
+ const command = yield* Command.make(baseArgs[0], ...baseArgs.slice(1)).pipe(Command.workingDirectory(cwd), Command.env(options.env ?? {}), Command.start, Effect.catchAll((cause) => Effect.fail(new DockerComposeError({
31
+ cause,
32
+ message: `Failed to start Docker Compose services in ${cwd}`,
33
+ }))), Effect.provide(commandExecutorContext));
34
+ // Wait for command completion
35
+ yield* command.exitCode.pipe(Effect.flatMap((exitCode) => exitCode === 0
36
+ ? Effect.void
37
+ : Effect.fail(new DockerComposeError({
38
+ cause: new Error(`Docker compose exited with code ${exitCode}`),
39
+ message: `Docker Compose failed to start with exit code ${exitCode}`,
40
+ }))), Effect.provide(commandExecutorContext));
41
+ // Perform health check if requested
42
+ if (healthCheck) {
43
+ yield* performHealthCheck(healthCheck).pipe(Effect.provide(commandExecutorContext));
44
+ }
45
+ yield* Effect.log(`Docker Compose services started successfully in ${cwd}`);
46
+ }).pipe(Effect.withSpan('startDockerCompose'));
47
+ const stop = Effect.gen(function* () {
48
+ yield* Effect.log(`Stopping Docker Compose services in ${cwd}`);
49
+ const stopCommand = serviceName
50
+ ? Command.make('docker', 'compose', 'stop', serviceName)
51
+ : Command.make('docker', 'compose', 'stop');
52
+ yield* stopCommand.pipe(Command.workingDirectory(cwd), Command.exitCode, Effect.flatMap((exitCode) => exitCode === 0
53
+ ? Effect.void
54
+ : Effect.fail(new DockerComposeError({
55
+ cause: new Error(`Docker compose stop exited with code ${exitCode}`),
56
+ message: `Failed to stop Docker Compose services`,
57
+ }))), Effect.provide(commandExecutorContext));
58
+ yield* Effect.log(`Docker Compose services stopped successfully`);
59
+ }).pipe(Effect.withSpan('stopDockerCompose'));
60
+ const logs = (options = {}) => Effect.gen(function* () {
61
+ const { follow = false, tail, since } = options;
62
+ const baseArgs = ['docker', 'compose', 'logs'];
63
+ if (follow)
64
+ baseArgs.push('-f');
65
+ if (tail)
66
+ baseArgs.push('--tail', tail.toString());
67
+ if (since)
68
+ baseArgs.push('--since', since);
69
+ if (serviceName)
70
+ baseArgs.push(serviceName);
71
+ const command = yield* Command.make(baseArgs[0], ...baseArgs.slice(1)).pipe(Command.workingDirectory(cwd), Command.start, Effect.catchAll((cause) => Effect.fail(new DockerComposeError({
72
+ cause,
73
+ message: `Failed to read Docker Compose logs in ${cwd}`,
74
+ }))), Effect.provide(commandExecutorContext));
75
+ return command.stdout.pipe(Stream.decodeText('utf8'), Stream.splitLines, Stream.mapError((cause) => new DockerComposeError({
76
+ cause,
77
+ message: `Error reading Docker Compose logs in ${cwd}`,
78
+ })));
79
+ }).pipe(Stream.unwrapScoped);
80
+ return { pull, start, stop, logs };
81
+ }),
82
+ }) {
83
+ }
84
+ const performHealthCheck = ({ url, timeout = Duration.minutes(2), interval = Duration.seconds(2), }) => Effect.gen(function* () {
85
+ yield* Effect.log(`Performing health check on ${url}`);
86
+ const checkHealth = Command.make('curl', '-f', '-s', url).pipe(Command.exitCode, Effect.map((code) => code === 0), Effect.catchAll(() => Effect.succeed(false)));
87
+ const healthCheck = checkHealth.pipe(Effect.repeat({
88
+ while: (healthy) => !healthy,
89
+ schedule: Schedule.fixed(interval),
90
+ }), Effect.timeout(timeout), Effect.catchAll(() => Effect.fail(new DockerComposeError({
91
+ cause: new Error('Health check timeout'),
92
+ message: `Health check failed for ${url} after ${Duration.toMillis(timeout)}ms`,
93
+ }))));
94
+ yield* healthCheck;
95
+ yield* Effect.log(`Health check passed for ${url}`);
96
+ });
97
+ // Convenience function for scoped Docker Compose operations with automatic cleanup
98
+ export const startDockerComposeServicesScoped = (args) => Effect.gen(function* () {
99
+ const dockerCompose = yield* DockerComposeService;
100
+ // Start the services
101
+ yield* dockerCompose.start({
102
+ ...omitUndefineds({ healthCheck: args.healthCheck ? args.healthCheck : undefined }),
103
+ });
104
+ // Add cleanup finalizer to the current scope
105
+ yield* Effect.addFinalizer(() => dockerCompose.stop.pipe(Effect.orDie));
106
+ });
107
+ //# sourceMappingURL=DockerComposeService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DockerComposeService.js","sourceRoot":"","sources":["../../../src/node/DockerComposeService/DockerComposeService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EACL,OAAO,EAEP,QAAQ,EACR,MAAM,EAEN,QAAQ,EACR,MAAM,EAEN,MAAM,GACP,MAAM,yBAAyB,CAAA;AAEhC,MAAM,OAAO,kBAAmB,SAAQ,MAAM,CAAC,WAAW,EAAsB,CAAC,oBAAoB,EAAE;IACrG,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAkCL,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,OAAO,EAAwB,CAAC,sBAAsB,EAAE;IACvG,MAAM,EAAE,CAAC,IAAuB,EAAE,EAAE,CAClC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,EAAE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,2BAA2B,GAAG,UAAU,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI;KAChF,CAAC,CACH,CACF,CACF,CAAA;IAED,KAAK,CAAC,CAAC,WAAW,CAAA;IAClB,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAA;AACrD,CAAC,CAAC,CAAA;AAEJ,mFAAmF;AACnF,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,IAEC,EAKD,EAAE,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,oBAAoB,CAAA;IAEjD,qBAAqB;IACrB,KAAK,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC;QACzB,GAAG,cAAc,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;KACpF,CAAC,CAAA;IAEF,6CAA6C;IAC7C,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AACzE,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DockerComposeService.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DockerComposeService.test.d.ts","sourceRoot":"","sources":["../../../src/node/DockerComposeService/DockerComposeService.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ import path from 'node:path';
2
+ import { Duration, Effect, Layer, Stream } from '@livestore/utils/effect';
3
+ import { PlatformNode } from '@livestore/utils/node';
4
+ import { Vitest } from '@livestore/utils-dev/node-vitest';
5
+ import { expect } from 'vitest';
6
+ import { DockerComposeService } from "./DockerComposeService.js";
7
+ const testTimeout = 30_000;
8
+ const testFixturePath = path.join(import.meta.dirname, 'test-fixtures');
9
+ const DockerComposeTest = (args = {}) => DockerComposeService.Default({
10
+ cwd: testFixturePath,
11
+ ...args,
12
+ });
13
+ Vitest.describe('DockerComposeService', { timeout: testTimeout }, () => {
14
+ Vitest.describe('Basic Operations', () => {
15
+ const withBasicTest = (args = {}) => Vitest.makeWithTestCtx({
16
+ timeout: testTimeout,
17
+ makeLayer: () => DockerComposeTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
18
+ });
19
+ Vitest.scopedLive('can pull docker images', (test) => Effect.gen(function* () {
20
+ const dockerCompose = yield* DockerComposeService;
21
+ // Test that pull operation works (should succeed for hello-world image)
22
+ yield* dockerCompose.pull;
23
+ }).pipe(withBasicTest()(test)));
24
+ Vitest.scopedLive('can start and stop docker compose services', (test) => Effect.gen(function* () {
25
+ const dockerCompose = yield* DockerComposeService;
26
+ // Start the service
27
+ yield* dockerCompose.start({ detached: true });
28
+ // Stop the service
29
+ yield* dockerCompose.stop;
30
+ }).pipe(withBasicTest({ serviceName: 'hello-world' })(test)));
31
+ Vitest.scopedLive('can get logs from docker compose services', (test) => Effect.gen(function* () {
32
+ const dockerCompose = yield* DockerComposeService;
33
+ // Start the service first
34
+ yield* dockerCompose.start({ detached: true });
35
+ // Get logs (should contain at least the "Hello from Docker!" message)
36
+ const firstLogLine = yield* dockerCompose.logs().pipe(Stream.runHead);
37
+ expect(firstLogLine._tag).toBe('Some');
38
+ // Stop the service
39
+ yield* dockerCompose.stop;
40
+ }).pipe(withBasicTest({ serviceName: 'hello-world' })(test)));
41
+ });
42
+ Vitest.describe('Health Check Operations', () => {
43
+ const withHealthCheckTest = (args = {}) => Vitest.makeWithTestCtx({
44
+ timeout: testTimeout,
45
+ makeLayer: () => DockerComposeTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
46
+ });
47
+ Vitest.scopedLive('handles health check timeout gracefully', (test) => Effect.gen(function* () {
48
+ const dockerCompose = yield* DockerComposeService;
49
+ // Test starting with a health check that will timeout (invalid URL)
50
+ const result = yield* dockerCompose
51
+ .start({
52
+ detached: true,
53
+ healthCheck: {
54
+ url: 'http://localhost:99999/nonexistent',
55
+ timeout: Duration.seconds(2),
56
+ },
57
+ })
58
+ .pipe(Effect.either);
59
+ // Should fail due to health check timeout
60
+ expect(result._tag).toBe('Left');
61
+ }).pipe(withHealthCheckTest({ serviceName: 'hello-world' })(test)));
62
+ });
63
+ });
64
+ //# sourceMappingURL=DockerComposeService.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DockerComposeService.test.js","sourceRoot":"","sources":["../../../src/node/DockerComposeService/DockerComposeService.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAA0B,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAExF,MAAM,WAAW,GAAG,MAAM,CAAA;AAC1B,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;AAEvE,MAAM,iBAAiB,GAAG,CAAC,OAAmC,EAAE,EAAE,EAAE,CAClE,oBAAoB,CAAC,OAAO,CAAC;IAC3B,GAAG,EAAE,eAAe;IACpB,GAAG,IAAI;CACR,CAAC,CAAA;AAEJ,MAAM,CAAC,QAAQ,CAAC,sBAAsB,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;IACrE,MAAM,CAAC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QACvC,MAAM,aAAa,GAAG,CAAC,OAAmC,EAAE,EA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CAAC,MAAM,CAAC,CAAA;YAEtB,0CAA0C;YAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAClC,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CACnE,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,52 @@
1
+ import { Duration, Effect, HttpClient, Schema } from '@livestore/utils/effect';
2
+ declare const WranglerDevServerError_base: Schema.TaggedErrorClass<WranglerDevServerError, "WranglerDevServerError", {
3
+ readonly _tag: Schema.tag<"WranglerDevServerError">;
4
+ } & {
5
+ cause: typeof Schema.Unknown;
6
+ message: typeof Schema.String;
7
+ port: typeof Schema.Number;
8
+ }>;
9
+ /**
10
+ * Error type for WranglerDevServer operations
11
+ */
12
+ export declare class WranglerDevServerError extends WranglerDevServerError_base {
13
+ }
14
+ /**
15
+ * WranglerDevServer instance interface
16
+ */
17
+ export interface WranglerDevServer {
18
+ readonly port: number;
19
+ readonly url: string;
20
+ readonly processId: number;
21
+ }
22
+ /**
23
+ * Configuration for starting WranglerDevServer
24
+ */
25
+ export interface StartWranglerDevServerArgs {
26
+ wranglerConfigPath?: string;
27
+ cwd: string;
28
+ port?: number;
29
+ /** @default false */
30
+ showLogs?: boolean;
31
+ connectTimeout?: Duration.DurationInput;
32
+ }
33
+ declare const WranglerDevServerService_base: Effect.Service.Class<WranglerDevServerService, "WranglerDevServerService", {
34
+ readonly scoped: (args: StartWranglerDevServerArgs) => Effect.Effect<{
35
+ port: number;
36
+ url: string;
37
+ processId: import("@effect/platform/CommandExecutor").ProcessId;
38
+ }, WranglerDevServerError, import("@effect/platform/CommandExecutor").CommandExecutor | import("effect/Scope").Scope | HttpClient.HttpClient>;
39
+ }>;
40
+ /**
41
+ * WranglerDevServer as an Effect.Service.
42
+ *
43
+ * This service provides the WranglerDevServer properties and can be accessed
44
+ * directly to get port, url, and processId.
45
+ *
46
+ * TODO: Allow for config to be passed in via code instead of `wrangler.toml` file
47
+ * (would need to be placed in temporary file as wrangler only accepts files as config)
48
+ */
49
+ export declare class WranglerDevServerService extends WranglerDevServerService_base {
50
+ }
51
+ export {};
52
+ //# sourceMappingURL=WranglerDevServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WranglerDevServer.d.ts","sourceRoot":"","sources":["../../../src/node/WranglerDevServer/WranglerDevServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,QAAQ,EACR,MAAM,EAEN,UAAU,EAGV,MAAM,EAEP,MAAM,yBAAyB,CAAA;;;;;;;;AAIhC;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,2BAI1C;CAAG;AAEL;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAA;CACxC;;4BAYgB,0BAA0B;;;;;;AAV3C;;;;;;;;GAQG;AACH,qBAAa,wBAAyB,SAAQ,6BA6I5C;CAAG"}
@@ -0,0 +1,122 @@
1
+ import * as path from 'node:path';
2
+ import { IS_CI } from '@livestore/utils';
3
+ import { Command, Duration, Effect, Exit, HttpClient, Schedule, Schema, Stream, } from '@livestore/utils/effect';
4
+ import { getFreePort } from '@livestore/utils/node';
5
+ import { cleanupOrphanedProcesses, killProcessTree } from "./process-tree-manager.js";
6
+ /**
7
+ * Error type for WranglerDevServer operations
8
+ */
9
+ export class WranglerDevServerError extends Schema.TaggedError()('WranglerDevServerError', {
10
+ cause: Schema.Unknown,
11
+ message: Schema.String,
12
+ port: Schema.Number,
13
+ }) {
14
+ }
15
+ /**
16
+ * WranglerDevServer as an Effect.Service.
17
+ *
18
+ * This service provides the WranglerDevServer properties and can be accessed
19
+ * directly to get port, url, and processId.
20
+ *
21
+ * TODO: Allow for config to be passed in via code instead of `wrangler.toml` file
22
+ * (would need to be placed in temporary file as wrangler only accepts files as config)
23
+ */
24
+ export class WranglerDevServerService extends Effect.Service()('WranglerDevServerService', {
25
+ scoped: (args) => Effect.gen(function* () {
26
+ const showLogs = args.showLogs ?? false;
27
+ // Clean up any orphaned processes before starting (defensive cleanup)
28
+ yield* cleanupOrphanedProcesses(['wrangler', 'workerd']).pipe(Effect.tap((result) => showLogs && (result.cleaned.length > 0 || result.failed.length > 0)
29
+ ? Effect.logInfo(`Cleanup result: ${result.cleaned.length} cleaned, ${result.failed.length} failed`)
30
+ : Effect.void), Effect.ignore);
31
+ // Allocate port
32
+ const port = args.port ??
33
+ (yield* getFreePort.pipe(Effect.mapError((cause) => new WranglerDevServerError({ cause, message: 'Failed to get free port', port: -1 }))));
34
+ yield* Effect.annotateCurrentSpan({ port });
35
+ // Resolve config path
36
+ const configPath = path.resolve(args.wranglerConfigPath ?? path.join(args.cwd, 'wrangler.toml'));
37
+ // Start wrangler process using Effect Command
38
+ const process = yield* Command.make('bunx', 'wrangler', 'dev', '--port', port.toString(), '--config', configPath).pipe(Command.workingDirectory(args.cwd), Command.stdout('pipe'), Command.stderr('pipe'), Command.start, Effect.catchAllCause((error) => new WranglerDevServerError({
39
+ cause: error,
40
+ message: `Failed to start wrangler process in directory: ${args.cwd}`,
41
+ port,
42
+ })), Effect.withSpan('WranglerDevServerService:startProcess'));
43
+ if (showLogs) {
44
+ yield* process.stderr.pipe(Stream.decodeText('utf8'), Stream.tapLogWithLabel('wrangler:stderr'), Stream.runDrain, Effect.forkScoped);
45
+ }
46
+ const processId = process.pid;
47
+ // We need to keep the `stdout` stream open, as we drain it in the waitForReady function
48
+ // Otherwise we'll get a EPIPE error
49
+ const stdout = yield* Stream.broadcastDynamic(process.stdout, 100);
50
+ // Register cleanup finalizer with intelligent timeout handling
51
+ yield* Effect.addFinalizer((exit) => Effect.gen(function* () {
52
+ const isInterrupted = Exit.isInterrupted(exit);
53
+ if (showLogs) {
54
+ yield* Effect.logDebug(`Cleaning up wrangler process ${processId}, interrupted: ${isInterrupted}`);
55
+ }
56
+ // yield* Effect.logDebug(`Cleaning up wrangler process ${processId}, interrupted: ${isInterrupted}`)
57
+ // Check if process is still running
58
+ const isRunning = yield* process.isRunning;
59
+ if (isRunning) {
60
+ // Use our enhanced process tree cleanup
61
+ yield* killProcessTree(processId, {
62
+ timeout: isInterrupted ? 500 : 3000, // Fast cleanup on interruption
63
+ signals: ['SIGTERM', 'SIGKILL'],
64
+ includeRoot: true,
65
+ }).pipe(Effect.tap((result) => showLogs
66
+ ? Effect.logDebug(`Cleaned up ${result.killedPids.length} processes, ${result.failedPids.length} failed`)
67
+ : Effect.void), Effect.mapError((error) => new WranglerDevServerError({
68
+ cause: error,
69
+ message: `Failed to kill process tree for PID ${processId}`,
70
+ port: 0,
71
+ })), Effect.ignore);
72
+ // Also kill the command process handle
73
+ yield* process.kill();
74
+ }
75
+ else if (showLogs) {
76
+ yield* Effect.logDebug(`Process ${processId} already terminated`);
77
+ }
78
+ }).pipe(Effect.withSpan('WranglerDevServerService:cleanupProcess'), Effect.timeout('5 seconds'), // Don't let cleanup hang forever
79
+ Effect.ignoreLogged));
80
+ // Wait for server to be ready
81
+ yield* waitForReady({ stdout, showLogs });
82
+ const url = `http://localhost:${port}`;
83
+ // Use longer timeout in CI environments to account for slower startup times
84
+ const defaultTimeout = Duration.seconds(IS_CI ? 15 : 5);
85
+ yield* verifyHttpConnectivity({ url, showLogs, connectTimeout: args.connectTimeout ?? defaultTimeout });
86
+ if (showLogs) {
87
+ yield* Effect.logDebug(`Wrangler dev server ready and accepting connections on port ${port}`);
88
+ }
89
+ return {
90
+ port,
91
+ url,
92
+ processId,
93
+ };
94
+ }).pipe(Effect.withSpan('WranglerDevServerService', {
95
+ attributes: { port: args.port ?? 'auto', cwd: args.cwd },
96
+ })),
97
+ }) {
98
+ }
99
+ /**
100
+ * Waits for Wrangler server to be ready by monitoring stdout for "Ready on" message
101
+ */
102
+ const waitForReady = ({ stdout, showLogs, }) => stdout.pipe(Stream.decodeText('utf8'), Stream.splitLines, Stream.tap((line) => (showLogs ? Effect.logDebug(`[wrangler] ${line}`) : Effect.void)), Stream.takeUntil((line) => line.includes('Ready on')), Stream.runDrain, Effect.timeout('30 seconds'), Effect.mapError((error) => new WranglerDevServerError({
103
+ cause: error,
104
+ message: 'Wrangler server failed to start within timeout',
105
+ port: 0,
106
+ })));
107
+ /**
108
+ * Verifies the server is actually accepting HTTP connections by making a test request
109
+ */
110
+ const verifyHttpConnectivity = ({ url, showLogs, connectTimeout, }) => Effect.gen(function* () {
111
+ const client = yield* HttpClient.HttpClient;
112
+ if (showLogs) {
113
+ yield* Effect.logDebug(`Verifying HTTP connectivity to ${url}`);
114
+ }
115
+ // Try to connect with retries using exponential backoff
116
+ yield* client.get(url).pipe(Effect.retryOrElse(Schedule.exponential('50 millis', 2).pipe(Schedule.jittered, Schedule.intersect(Schedule.elapsed.pipe(Schedule.whileOutput(Duration.lessThanOrEqualTo(connectTimeout)))), Schedule.compose(Schedule.count)), (error, attemptCount) => Effect.fail(new WranglerDevServerError({
117
+ cause: error,
118
+ message: `Failed to establish HTTP connection to Wrangler server at ${url} after ${attemptCount} attempts (timeout: ${Duration.toMillis(connectTimeout)}ms)`,
119
+ port: 0,
120
+ }))), Effect.tap(() => (showLogs ? Effect.logDebug(`HTTP connectivity verified for ${url}`) : Effect.void)), Effect.asVoid, Effect.withSpan('verifyHttpConnectivity'));
121
+ });
122
+ //# sourceMappingURL=WranglerDevServer.js.map
@@ -0,0 +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0 +1 @@
1
+ {"version":3,"file":"WranglerDevServer.test.d.ts","sourceRoot":"","sources":["../../../src/node/WranglerDevServer/WranglerDevServer.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,179 @@
1
+ import { Effect, Exit, FetchHttpClient, Fiber, Layer, Scope } from '@livestore/utils/effect';
2
+ import { PlatformNode } from '@livestore/utils/node';
3
+ import { Vitest } from '@livestore/utils-dev/node-vitest';
4
+ import { expect } from 'vitest';
5
+ import { WranglerDevServerError, WranglerDevServerService, } from "./WranglerDevServer.js";
6
+ const testTimeout = 60_000;
7
+ const withTestCtx = Vitest.makeWithTestCtx({
8
+ timeout: testTimeout,
9
+ makeLayer: () => PlatformNode.NodeContext.layer,
10
+ });
11
+ const WranglerDevServerTest = (args = {}) => WranglerDevServerService.Default({
12
+ cwd: `${import.meta.dirname}/fixtures`,
13
+ ...args,
14
+ }).pipe(Layer.provide(FetchHttpClient.layer));
15
+ Vitest.describe('WranglerDevServer', { timeout: testTimeout }, () => {
16
+ Vitest.describe('Basic Operations', () => {
17
+ const withBasicTest = (args = {}) => Vitest.makeWithTestCtx({
18
+ timeout: testTimeout,
19
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
20
+ });
21
+ Vitest.scopedLive('should start wrangler dev server and return port', (test) => Effect.gen(function* () {
22
+ const server = yield* WranglerDevServerService;
23
+ expect(server.port).toBeGreaterThan(0);
24
+ expect(server.url).toMatch(/http:\/\/localhost:\d+/);
25
+ expect(typeof server.processId).toBe('number');
26
+ expect(server.processId).toBeGreaterThan(0);
27
+ }).pipe(withBasicTest()(test)));
28
+ Vitest.scopedLive('should use specified port when provided', (test) => Effect.gen(function* () {
29
+ const server = yield* WranglerDevServerService;
30
+ expect(server.port).toBe(54443);
31
+ expect(server.url).toBe(`http://localhost:54443`);
32
+ }).pipe(withBasicTest({ port: 54443 })(test)));
33
+ });
34
+ Vitest.describe('Resource Management', () => {
35
+ Vitest.scopedLive('should cleanup processes on scope close', (test) => Effect.gen(function* () {
36
+ let processId;
37
+ // Create a separate scope for the server
38
+ const serverScope = yield* Scope.make();
39
+ const server = yield* Effect.provide(WranglerDevServerService, WranglerDevServerTest().pipe(Layer.provide(PlatformNode.NodeContext.layer))).pipe(Scope.extend(serverScope));
40
+ processId = server.processId;
41
+ expect(processId).toBeGreaterThan(0);
42
+ expect(server.port).toBeGreaterThan(0);
43
+ expect(server.url).toMatch(/http:\/\/localhost:\d+/);
44
+ // Close scope to trigger cleanup
45
+ yield* Scope.close(serverScope, Exit.succeed(void 0));
46
+ // Wait for cleanup to complete
47
+ yield* Effect.sleep('2 seconds');
48
+ // Verify process is terminated
49
+ const isRunning2 = yield* Effect.promise(() => {
50
+ try {
51
+ process.kill(processId, 0);
52
+ return Promise.resolve(true);
53
+ }
54
+ catch {
55
+ return Promise.resolve(false);
56
+ }
57
+ });
58
+ expect(isRunning2).toBe(false);
59
+ }).pipe(withTestCtx(test)));
60
+ Vitest.scopedLive('should handle interruption with fast cleanup', (test) => Effect.gen(function* () {
61
+ let processId;
62
+ const fiber = yield* Effect.fork(Effect.provide(Effect.gen(function* () {
63
+ const server = yield* WranglerDevServerService;
64
+ processId = server.processId;
65
+ yield* Effect.sleep('30 seconds'); // Keep running
66
+ return server;
67
+ }), WranglerDevServerTest().pipe(Layer.provide(PlatformNode.NodeContext.layer))));
68
+ // Wait for server to start
69
+ yield* Effect.sleep('3 seconds');
70
+ expect(processId).toBeGreaterThan(0);
71
+ // Interrupt and measure cleanup time
72
+ const start = Date.now();
73
+ yield* Fiber.interrupt(fiber);
74
+ const elapsed = Date.now() - start;
75
+ // Should use fast cleanup (500ms timeout) + some overhead
76
+ expect(elapsed).toBeLessThan(1500); // Allow some overhead
77
+ // Wait for cleanup to complete
78
+ yield* Effect.sleep('1 second');
79
+ // Verify process is terminated
80
+ const isRunningAfter = yield* Effect.promise(() => {
81
+ try {
82
+ process.kill(processId, 0);
83
+ return Promise.resolve(true);
84
+ }
85
+ catch {
86
+ return Promise.resolve(false);
87
+ }
88
+ });
89
+ expect(isRunningAfter).toBe(false);
90
+ }).pipe(withTestCtx(test)));
91
+ });
92
+ Vitest.describe('Error Handling', () => {
93
+ const withErrorTest = (args = {}) => Vitest.makeWithTestCtx({
94
+ timeout: testTimeout,
95
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
96
+ });
97
+ Vitest.scopedLive('should handle missing wrangler.toml but should timeout', (test) => Effect.gen(function* () {
98
+ const error = yield* WranglerDevServerService.pipe(Effect.provide(WranglerDevServerTest({
99
+ cwd: '/tmp',
100
+ wranglerConfigPath: '/dev/null',
101
+ connectTimeout: '500 millis',
102
+ }).pipe(Layer.provide(PlatformNode.NodeContext.layer))), Effect.flip);
103
+ expect(error).toBeInstanceOf(WranglerDevServerError);
104
+ }).pipe(Vitest.withTestCtx(test)));
105
+ Vitest.scopedLive('should handle invalid working directory', (test) => Effect.gen(function* () {
106
+ const result = yield* WranglerDevServerService.pipe(Effect.provide(WranglerDevServerTest({
107
+ cwd: '/completely/nonexistent/directory',
108
+ }).pipe(Layer.provide(PlatformNode.NodeContext.layer))), Effect.either);
109
+ expect(result._tag).toBe('Left');
110
+ if (result._tag === 'Left') {
111
+ expect(result.left).toBeInstanceOf(WranglerDevServerError);
112
+ }
113
+ }).pipe(Vitest.withTestCtx(test)));
114
+ Vitest.scopedLive('should timeout if server fails to start', (test) => Effect.gen(function* () {
115
+ // Create a command that will never output "Ready on"
116
+ const result = yield* WranglerDevServerService.pipe(
117
+ // Override the timeout for this test to be shorter
118
+ Effect.timeout('5 seconds'), Effect.either);
119
+ // This might succeed or fail depending on actual wrangler behavior
120
+ // The main point is testing timeout functionality
121
+ expect(['Left', 'Right']).toContain(result._tag);
122
+ }).pipe(withErrorTest()(test)));
123
+ });
124
+ Vitest.describe('Process Tree Cleanup', () => {
125
+ const withCleanupTest = (args = {}) => Vitest.makeWithTestCtx({
126
+ timeout: testTimeout,
127
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
128
+ });
129
+ Vitest.scopedLive('should clean up child workerd processes', (test) => Effect.gen(function* () {
130
+ let processId;
131
+ const server = yield* WranglerDevServerService;
132
+ processId = server.processId;
133
+ // Wait for wrangler to spawn workerd children
134
+ yield* Effect.sleep('3 seconds');
135
+ // Find any child processes (workerd)
136
+ const children = yield* Effect.promise(async () => {
137
+ const { exec } = require('node:child_process');
138
+ const { promisify } = require('node:util');
139
+ const execAsync = promisify(exec);
140
+ try {
141
+ if (!processId)
142
+ throw new Error('processId is undefined');
143
+ const { stdout } = await execAsync(`ps -o pid,ppid -ax | grep -E "^\\s*[0-9]+\\s+${processId}\\s*$"`);
144
+ return stdout
145
+ .trim()
146
+ .split('\n')
147
+ .map((line) => {
148
+ const match = line.trim().match(/^\s*(\d+)\s+\d+\s*$/);
149
+ return match?.[1] ? Number.parseInt(match[1], 10) : null;
150
+ })
151
+ .filter((pid) => pid !== null);
152
+ }
153
+ catch {
154
+ return [];
155
+ }
156
+ });
157
+ console.log(`Found ${children.length} child processes:`, children);
158
+ // The scope will close here and should clean up all processes
159
+ }).pipe(withCleanupTest()(test)));
160
+ });
161
+ Vitest.describe('Service Pattern', () => {
162
+ const withServiceTest = (args = {}) => Vitest.makeWithTestCtx({
163
+ timeout: testTimeout,
164
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
165
+ });
166
+ Vitest.scopedLive('should work with service pattern', (test) => Effect.gen(function* () {
167
+ const server = yield* WranglerDevServerService;
168
+ expect(server.port).toBeGreaterThan(0);
169
+ expect(server.url).toMatch(/http:\/\/localhost:\d+/);
170
+ expect(server.processId).toBeGreaterThan(0);
171
+ }).pipe(withServiceTest()(test)));
172
+ Vitest.scopedLive('should work with custom port via service', (test) => Effect.gen(function* () {
173
+ const server = yield* WranglerDevServerService;
174
+ expect(server.port).toBe(54444);
175
+ expect(server.url).toBe('http://localhost:54444');
176
+ }).pipe(withServiceTest({ port: 54444 })(test)));
177
+ });
178
+ });
179
+ //# sourceMappingURL=WranglerDevServer.test.js.map