@livestore/utils-dev 0.0.0-snapshot-d677008bdbdee9280bb55474e2e095d3d09a6d60 → 0.0.0-snapshot-7156ff2a7c67a5a9cdd850a5826201d068840f0c
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/dist/.tsbuildinfo.json +1 -1
- package/dist/node/mod.d.ts +0 -2
- package/dist/node/mod.d.ts.map +1 -1
- package/dist/node/mod.js +0 -2
- package/dist/node/mod.js.map +1 -1
- package/dist/{node/WranglerDevServer → wrangler}/WranglerDevServer.d.ts +3 -5
- package/dist/wrangler/WranglerDevServer.d.ts.map +1 -0
- package/dist/wrangler/WranglerDevServer.js +90 -0
- package/dist/wrangler/WranglerDevServer.js.map +1 -0
- package/dist/wrangler/WranglerDevServer.test.d.ts.map +1 -0
- package/dist/wrangler/WranglerDevServer.test.js +77 -0
- package/dist/wrangler/WranglerDevServer.test.js.map +1 -0
- package/dist/wrangler/fixtures/cf-worker.d.ts.map +1 -0
- package/dist/wrangler/fixtures/cf-worker.js.map +1 -0
- package/dist/wrangler/mod.d.ts +2 -0
- package/dist/wrangler/mod.d.ts.map +1 -0
- package/dist/wrangler/mod.js +2 -0
- package/dist/wrangler/mod.js.map +1 -0
- package/package.json +6 -3
- package/src/node/mod.ts +0 -7
- package/src/wrangler/WranglerDevServer.test.ts +133 -0
- package/src/wrangler/WranglerDevServer.ts +180 -0
- package/src/wrangler/mod.ts +6 -0
- package/dist/node/WranglerDevServer/WranglerDevServer.d.ts.map +0 -1
- package/dist/node/WranglerDevServer/WranglerDevServer.js +0 -150
- package/dist/node/WranglerDevServer/WranglerDevServer.js.map +0 -1
- package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts.map +0 -1
- package/dist/node/WranglerDevServer/WranglerDevServer.test.js +0 -179
- package/dist/node/WranglerDevServer/WranglerDevServer.test.js.map +0 -1
- package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts.map +0 -1
- package/dist/node/WranglerDevServer/fixtures/cf-worker.js.map +0 -1
- package/dist/node/WranglerDevServer/process-tree-manager.d.ts +0 -55
- package/dist/node/WranglerDevServer/process-tree-manager.d.ts.map +0 -1
- package/dist/node/WranglerDevServer/process-tree-manager.js +0 -178
- package/dist/node/WranglerDevServer/process-tree-manager.js.map +0 -1
- package/src/node/WranglerDevServer/WranglerDevServer.test.ts +0 -270
- package/src/node/WranglerDevServer/WranglerDevServer.ts +0 -302
- package/src/node/WranglerDevServer/process-tree-manager.ts +0 -263
- /package/dist/{node/WranglerDevServer → wrangler}/WranglerDevServer.test.d.ts +0 -0
- /package/dist/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.d.ts +0 -0
- /package/dist/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.js +0 -0
- /package/src/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.ts +0 -0
- /package/src/{node/WranglerDevServer → wrangler}/fixtures/wrangler.toml +0 -0
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { Command, Effect, Schema, Stream } from '@livestore/utils/effect';
|
|
2
|
-
export class ProcessTreeError extends Schema.TaggedError()('ProcessTreeError', {
|
|
3
|
-
cause: Schema.Unknown,
|
|
4
|
-
message: Schema.String,
|
|
5
|
-
pid: Schema.Number,
|
|
6
|
-
}) {
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Finds all child processes of a given parent PID
|
|
10
|
-
*/
|
|
11
|
-
export const findChildProcesses = (parentPid) => Effect.gen(function* () {
|
|
12
|
-
const result = yield* Command.make('ps', '-o', 'pid,ppid', '-ax').pipe(Command.start, Effect.flatMap((command) => command.stdout.pipe(Stream.decodeText('utf8'), Stream.runCollect, Effect.map((chunks) => Array.from(chunks).join('')))), Effect.catchAll(() => Effect.succeed('')));
|
|
13
|
-
if (!result)
|
|
14
|
-
return [];
|
|
15
|
-
const lines = result.split('\n');
|
|
16
|
-
const pattern = new RegExp(`^\\s*([0-9]+)\\s+${parentPid}\\s*$`);
|
|
17
|
-
const childPids = lines
|
|
18
|
-
.map((line) => {
|
|
19
|
-
const match = line.trim().match(pattern);
|
|
20
|
-
return match ? Number.parseInt(match[1], 10) : null;
|
|
21
|
-
})
|
|
22
|
-
.filter((pid) => pid !== null);
|
|
23
|
-
return childPids;
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* Recursively finds all descendants of a process
|
|
27
|
-
*/
|
|
28
|
-
export const findProcessTree = (rootPid) => Effect.gen(function* () {
|
|
29
|
-
const allPids = new Set([rootPid]);
|
|
30
|
-
const toProcess = [rootPid];
|
|
31
|
-
while (toProcess.length > 0) {
|
|
32
|
-
const currentPid = toProcess.pop();
|
|
33
|
-
const children = yield* findChildProcesses(currentPid);
|
|
34
|
-
for (const childPid of children) {
|
|
35
|
-
if (!allPids.has(childPid)) {
|
|
36
|
-
allPids.add(childPid);
|
|
37
|
-
toProcess.push(childPid);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return Array.from(allPids);
|
|
42
|
-
});
|
|
43
|
-
/**
|
|
44
|
-
* Checks if a process is running
|
|
45
|
-
*/
|
|
46
|
-
export const isProcessRunning = (pid) => Effect.sync(() => {
|
|
47
|
-
try {
|
|
48
|
-
process.kill(pid, 0);
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* Kills a process tree with escalating signals
|
|
57
|
-
*/
|
|
58
|
-
export const killProcessTree = (rootPid, options = {}) => Effect.gen(function* () {
|
|
59
|
-
const { timeout = 5000, signals = ['SIGTERM', 'SIGKILL'], includeRoot = true } = options;
|
|
60
|
-
// Find all processes in the tree
|
|
61
|
-
const allPids = yield* findProcessTree(rootPid);
|
|
62
|
-
const pidsToKill = includeRoot ? allPids : allPids.filter((pid) => pid !== rootPid);
|
|
63
|
-
if (pidsToKill.length === 0) {
|
|
64
|
-
return { killedPids: [], failedPids: [] };
|
|
65
|
-
}
|
|
66
|
-
const killedPids = [];
|
|
67
|
-
const failedPids = [];
|
|
68
|
-
// Try each signal with timeout
|
|
69
|
-
for (const signal of signals) {
|
|
70
|
-
// Check which processes are still running and not yet killed
|
|
71
|
-
const stillRunningChecks = yield* Effect.all(pidsToKill
|
|
72
|
-
.filter((pid) => !killedPids.includes(pid))
|
|
73
|
-
.map((pid) => isProcessRunning(pid).pipe(Effect.map((running) => ({ pid, running })))));
|
|
74
|
-
const remainingPids = stillRunningChecks.filter(({ running }) => running).map(({ pid }) => pid);
|
|
75
|
-
if (remainingPids.length === 0)
|
|
76
|
-
break;
|
|
77
|
-
// Send signal to all remaining processes
|
|
78
|
-
for (const pid of remainingPids) {
|
|
79
|
-
yield* Effect.sync(() => {
|
|
80
|
-
try {
|
|
81
|
-
process.kill(pid, signal);
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
// Process might already be dead, continue
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
// Wait for processes to terminate with polling
|
|
89
|
-
const waitStart = Date.now();
|
|
90
|
-
while (Date.now() - waitStart < timeout) {
|
|
91
|
-
const runningChecks = yield* Effect.all(remainingPids.map((pid) => isProcessRunning(pid).pipe(Effect.map((running) => ({ pid, running })))));
|
|
92
|
-
const stillRunning = runningChecks.filter(({ running }) => running).map(({ pid }) => pid);
|
|
93
|
-
if (stillRunning.length === 0) {
|
|
94
|
-
// All processes terminated
|
|
95
|
-
killedPids.push(...remainingPids);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
// Short sleep before checking again
|
|
99
|
-
yield* Effect.sleep('100 millis');
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// Check final status
|
|
103
|
-
const finalChecks = yield* Effect.all(pidsToKill.map((pid) => isProcessRunning(pid).pipe(Effect.map((running) => ({ pid, running })))));
|
|
104
|
-
for (const { pid, running } of finalChecks) {
|
|
105
|
-
if (!killedPids.includes(pid) && running) {
|
|
106
|
-
failedPids.push(pid);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return { killedPids, failedPids };
|
|
110
|
-
});
|
|
111
|
-
/**
|
|
112
|
-
* Finds orphaned processes by name pattern
|
|
113
|
-
*/
|
|
114
|
-
export const findOrphanedProcesses = (namePattern) => Effect.gen(function* () {
|
|
115
|
-
// Find processes that match the pattern and have init (PID 1) as parent
|
|
116
|
-
const result = yield* Command.make('ps', '-eo', 'pid,ppid,comm').pipe(Command.start, Effect.flatMap((command) => command.stdout.pipe(Stream.decodeText('utf8'), Stream.runCollect, Effect.map((chunks) => Array.from(chunks).join('')))), Effect.catchAll(() => Effect.succeed('')));
|
|
117
|
-
if (!result)
|
|
118
|
-
return [];
|
|
119
|
-
const lines = result.split('\n');
|
|
120
|
-
const patternRegex = new RegExp(namePattern);
|
|
121
|
-
const parentRegex = /^\s*(\d+)\s+1\s+/;
|
|
122
|
-
const orphanedPids = lines
|
|
123
|
-
.filter((line) => patternRegex.test(line))
|
|
124
|
-
.map((line) => {
|
|
125
|
-
const match = line.trim().match(parentRegex);
|
|
126
|
-
return match ? Number.parseInt(match[1], 10) : null;
|
|
127
|
-
})
|
|
128
|
-
.filter((pid) => pid !== null);
|
|
129
|
-
return orphanedPids;
|
|
130
|
-
});
|
|
131
|
-
/**
|
|
132
|
-
* Defensive cleanup for orphaned processes matching given patterns.
|
|
133
|
-
*
|
|
134
|
-
* This function provides fallback cleanup for edge cases where normal process
|
|
135
|
-
* termination mechanisms fail (e.g., hard crashes, SIGKILL before cleanup runs,
|
|
136
|
-
* or limitations in synchronous exit handlers). While proper process tree cleanup
|
|
137
|
-
* should prevent orphans in most cases, this serves as a safety net for scenarios
|
|
138
|
-
* where child processes become orphaned despite cleanup efforts.
|
|
139
|
-
*
|
|
140
|
-
* @param processPatterns - Array of process name patterns to search for (e.g., ['wrangler', 'workerd'])
|
|
141
|
-
* @returns Object with arrays of successfully cleaned and failed PIDs
|
|
142
|
-
*/
|
|
143
|
-
export const cleanupOrphanedProcesses = (processPatterns) => Effect.gen(function* () {
|
|
144
|
-
const cleaned = [];
|
|
145
|
-
const failed = [];
|
|
146
|
-
// Find all orphaned processes matching the patterns
|
|
147
|
-
const allOrphanedPids = [];
|
|
148
|
-
const patternCounts = {};
|
|
149
|
-
for (const pattern of processPatterns) {
|
|
150
|
-
const orphaned = yield* findOrphanedProcesses(pattern);
|
|
151
|
-
allOrphanedPids.push(...orphaned);
|
|
152
|
-
patternCounts[pattern] = orphaned.length;
|
|
153
|
-
}
|
|
154
|
-
if (allOrphanedPids.length === 0) {
|
|
155
|
-
return { cleaned, failed };
|
|
156
|
-
}
|
|
157
|
-
const patternSummary = Object.entries(patternCounts)
|
|
158
|
-
.map(([pattern, count]) => `${count} ${pattern}`)
|
|
159
|
-
.join(', ');
|
|
160
|
-
yield* Effect.logInfo(`Found ${allOrphanedPids.length} orphaned processes (${patternSummary}): ${allOrphanedPids.join(', ')}`);
|
|
161
|
-
for (const pid of allOrphanedPids) {
|
|
162
|
-
const result = yield* killProcessTree(pid, {
|
|
163
|
-
timeout: 2000,
|
|
164
|
-
signals: ['SIGTERM', 'SIGKILL'],
|
|
165
|
-
includeRoot: true,
|
|
166
|
-
}).pipe(Effect.orElse(() => Effect.succeed({ killedPids: [], failedPids: [pid] })));
|
|
167
|
-
if (result.failedPids.length === 0) {
|
|
168
|
-
cleaned.push(...result.killedPids);
|
|
169
|
-
yield* Effect.logInfo(`Cleaned up orphaned process tree starting with ${pid} (${result.killedPids.length} processes)`);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
failed.push(pid, ...result.failedPids);
|
|
173
|
-
yield* Effect.logWarning(`Failed to clean up some processes in tree ${pid}: ${result.failedPids.join(', ')}`);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return { cleaned, failed };
|
|
177
|
-
});
|
|
178
|
-
//# sourceMappingURL=process-tree-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":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AAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAEnF,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;YAClC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CACnB,kDAAkD,GAAG,KAAK,MAAM,CAAC,UAAU,CAAC,MAAM,aAAa,CAChG,CAAA;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;YACtC,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,6CAA6C,GAAG,KAAK,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC/G,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;AAC5B,CAAC,CAAC,CAAA"}
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import { Effect, Exit, FetchHttpClient, Fiber, Layer, Scope } from '@livestore/utils/effect'
|
|
2
|
-
import { getFreePort, PlatformNode } from '@livestore/utils/node'
|
|
3
|
-
import { Vitest } from '@livestore/utils-dev/node-vitest'
|
|
4
|
-
import { expect } from 'vitest'
|
|
5
|
-
import {
|
|
6
|
-
type StartWranglerDevServerArgs,
|
|
7
|
-
WranglerDevServerError,
|
|
8
|
-
WranglerDevServerService,
|
|
9
|
-
} from './WranglerDevServer.ts'
|
|
10
|
-
|
|
11
|
-
const testTimeout = 60_000
|
|
12
|
-
|
|
13
|
-
const withTestCtx = Vitest.makeWithTestCtx({
|
|
14
|
-
timeout: testTimeout,
|
|
15
|
-
makeLayer: () => PlatformNode.NodeContext.layer,
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const WranglerDevServerTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
|
|
19
|
-
WranglerDevServerService.Default({
|
|
20
|
-
cwd: `${import.meta.dirname}/fixtures`,
|
|
21
|
-
...args,
|
|
22
|
-
}).pipe(Layer.provide(FetchHttpClient.layer))
|
|
23
|
-
|
|
24
|
-
Vitest.describe('WranglerDevServer', { timeout: testTimeout }, () => {
|
|
25
|
-
Vitest.describe('Basic Operations', () => {
|
|
26
|
-
const withBasicTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
|
|
27
|
-
Vitest.makeWithTestCtx({
|
|
28
|
-
timeout: testTimeout,
|
|
29
|
-
makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
Vitest.scopedLive('should start wrangler dev server and return port', (test) =>
|
|
33
|
-
Effect.gen(function* () {
|
|
34
|
-
const server = yield* WranglerDevServerService
|
|
35
|
-
|
|
36
|
-
expect(server.port).toBeGreaterThan(0)
|
|
37
|
-
expect(server.url).toMatch(/http:\/\/localhost:\d+/)
|
|
38
|
-
expect(typeof server.processId).toBe('number')
|
|
39
|
-
expect(server.processId).toBeGreaterThan(0)
|
|
40
|
-
}).pipe(withBasicTest()(test)),
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
Vitest.scopedLive('should use specified port when provided', (test) =>
|
|
44
|
-
Effect.andThen(getFreePort, (port) =>
|
|
45
|
-
Effect.gen(function* () {
|
|
46
|
-
const server = yield* WranglerDevServerService
|
|
47
|
-
|
|
48
|
-
expect(server.port).toBe(port)
|
|
49
|
-
expect(server.url).toBe(`http://localhost:${port}`)
|
|
50
|
-
}).pipe(withBasicTest({ preferredPort: port })(test)),
|
|
51
|
-
),
|
|
52
|
-
)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
Vitest.describe('Resource Management', () => {
|
|
56
|
-
Vitest.scopedLive('should cleanup processes on scope close', (test) =>
|
|
57
|
-
Effect.gen(function* () {
|
|
58
|
-
let processId: number | undefined
|
|
59
|
-
|
|
60
|
-
// Create a separate scope for the server
|
|
61
|
-
const serverScope = yield* Scope.make()
|
|
62
|
-
|
|
63
|
-
const server = yield* Effect.provide(
|
|
64
|
-
WranglerDevServerService,
|
|
65
|
-
WranglerDevServerTest().pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
66
|
-
).pipe(Scope.extend(serverScope))
|
|
67
|
-
|
|
68
|
-
processId = server.processId
|
|
69
|
-
expect(processId).toBeGreaterThan(0)
|
|
70
|
-
expect(server.port).toBeGreaterThan(0)
|
|
71
|
-
expect(server.url).toMatch(/http:\/\/localhost:\d+/)
|
|
72
|
-
|
|
73
|
-
// Close scope to trigger cleanup
|
|
74
|
-
yield* Scope.close(serverScope, Exit.succeed(void 0))
|
|
75
|
-
|
|
76
|
-
// Wait for cleanup to complete
|
|
77
|
-
yield* Effect.sleep('2 seconds')
|
|
78
|
-
|
|
79
|
-
// Verify process is terminated
|
|
80
|
-
const isRunning2 = yield* Effect.promise(() => {
|
|
81
|
-
try {
|
|
82
|
-
process.kill(processId!, 0)
|
|
83
|
-
return Promise.resolve(true)
|
|
84
|
-
} catch {
|
|
85
|
-
return Promise.resolve(false)
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
expect(isRunning2).toBe(false)
|
|
89
|
-
}).pipe(withTestCtx(test)),
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
Vitest.scopedLive('should handle interruption with fast cleanup', (test) =>
|
|
93
|
-
Effect.gen(function* () {
|
|
94
|
-
let processId: number | undefined
|
|
95
|
-
|
|
96
|
-
const fiber = yield* Effect.fork(
|
|
97
|
-
Effect.provide(
|
|
98
|
-
Effect.gen(function* () {
|
|
99
|
-
const server = yield* WranglerDevServerService
|
|
100
|
-
processId = server.processId
|
|
101
|
-
yield* Effect.sleep('30 seconds') // Keep running
|
|
102
|
-
return server
|
|
103
|
-
}),
|
|
104
|
-
WranglerDevServerTest().pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
105
|
-
),
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
// Wait for server to start
|
|
109
|
-
yield* Effect.sleep('3 seconds')
|
|
110
|
-
|
|
111
|
-
expect(processId).toBeGreaterThan(0)
|
|
112
|
-
|
|
113
|
-
// Interrupt and measure cleanup time
|
|
114
|
-
const start = Date.now()
|
|
115
|
-
yield* Fiber.interrupt(fiber)
|
|
116
|
-
const elapsed = Date.now() - start
|
|
117
|
-
|
|
118
|
-
// Should use fast cleanup (500ms timeout) + some overhead
|
|
119
|
-
expect(elapsed).toBeLessThan(1500) // Allow some overhead
|
|
120
|
-
|
|
121
|
-
// Wait for cleanup to complete
|
|
122
|
-
yield* Effect.sleep('1 second')
|
|
123
|
-
|
|
124
|
-
// Verify process is terminated
|
|
125
|
-
const isRunningAfter = yield* Effect.promise(() => {
|
|
126
|
-
try {
|
|
127
|
-
process.kill(processId!, 0)
|
|
128
|
-
return Promise.resolve(true)
|
|
129
|
-
} catch {
|
|
130
|
-
return Promise.resolve(false)
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
expect(isRunningAfter).toBe(false)
|
|
134
|
-
}).pipe(withTestCtx(test)),
|
|
135
|
-
)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
Vitest.describe('Error Handling', () => {
|
|
139
|
-
const withErrorTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
|
|
140
|
-
Vitest.makeWithTestCtx({
|
|
141
|
-
timeout: testTimeout,
|
|
142
|
-
makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
Vitest.scopedLive('should handle missing wrangler.toml but should timeout', (test) =>
|
|
146
|
-
Effect.gen(function* () {
|
|
147
|
-
const error = yield* WranglerDevServerService.pipe(
|
|
148
|
-
Effect.provide(
|
|
149
|
-
WranglerDevServerTest({
|
|
150
|
-
cwd: '/tmp',
|
|
151
|
-
wranglerConfigPath: '/dev/null',
|
|
152
|
-
connectTimeout: '500 millis',
|
|
153
|
-
}).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
154
|
-
),
|
|
155
|
-
Effect.flip,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
expect(error).toBeInstanceOf(WranglerDevServerError)
|
|
159
|
-
}).pipe(Vitest.withTestCtx(test)),
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
Vitest.scopedLive('should handle invalid working directory', (test) =>
|
|
163
|
-
Effect.gen(function* () {
|
|
164
|
-
const result = yield* WranglerDevServerService.pipe(
|
|
165
|
-
Effect.provide(
|
|
166
|
-
WranglerDevServerTest({
|
|
167
|
-
cwd: '/completely/nonexistent/directory',
|
|
168
|
-
}).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
169
|
-
),
|
|
170
|
-
Effect.either,
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
expect(result._tag).toBe('Left')
|
|
174
|
-
if (result._tag === 'Left') {
|
|
175
|
-
expect(result.left).toBeInstanceOf(WranglerDevServerError)
|
|
176
|
-
}
|
|
177
|
-
}).pipe(Vitest.withTestCtx(test)),
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
Vitest.scopedLive('should timeout if server fails to start', (test) =>
|
|
181
|
-
Effect.gen(function* () {
|
|
182
|
-
// Create a command that will never output "Ready on"
|
|
183
|
-
const result = yield* WranglerDevServerService.pipe(
|
|
184
|
-
// Override the timeout for this test to be shorter
|
|
185
|
-
Effect.timeout('5 seconds'),
|
|
186
|
-
Effect.either,
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
// This might succeed or fail depending on actual wrangler behavior
|
|
190
|
-
// The main point is testing timeout functionality
|
|
191
|
-
expect(['Left', 'Right']).toContain(result._tag)
|
|
192
|
-
}).pipe(withErrorTest()(test)),
|
|
193
|
-
)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
Vitest.describe('Process Tree Cleanup', () => {
|
|
197
|
-
const withCleanupTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
|
|
198
|
-
Vitest.makeWithTestCtx({
|
|
199
|
-
timeout: testTimeout,
|
|
200
|
-
makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
Vitest.scopedLive('should clean up child workerd processes', (test) =>
|
|
204
|
-
Effect.gen(function* () {
|
|
205
|
-
let processId: number | undefined
|
|
206
|
-
|
|
207
|
-
const server = yield* WranglerDevServerService
|
|
208
|
-
processId = server.processId
|
|
209
|
-
|
|
210
|
-
// Wait for wrangler to spawn workerd children
|
|
211
|
-
yield* Effect.sleep('3 seconds')
|
|
212
|
-
|
|
213
|
-
// Find any child processes (workerd)
|
|
214
|
-
const children = yield* Effect.promise(async () => {
|
|
215
|
-
const { exec } = require('node:child_process')
|
|
216
|
-
const { promisify } = require('node:util')
|
|
217
|
-
const execAsync = promisify(exec)
|
|
218
|
-
|
|
219
|
-
try {
|
|
220
|
-
if (!processId) throw new Error('processId is undefined')
|
|
221
|
-
const { stdout } = await execAsync(`ps -o pid,ppid -ax | grep -E "^\\s*[0-9]+\\s+${processId}\\s*$"`)
|
|
222
|
-
return stdout
|
|
223
|
-
.trim()
|
|
224
|
-
.split('\n')
|
|
225
|
-
.map((line: string) => {
|
|
226
|
-
const match = line.trim().match(/^\s*(\d+)\s+\d+\s*$/)
|
|
227
|
-
return match?.[1] ? Number.parseInt(match[1], 10) : null
|
|
228
|
-
})
|
|
229
|
-
.filter((pid: number | null): pid is number => pid !== null)
|
|
230
|
-
} catch {
|
|
231
|
-
return []
|
|
232
|
-
}
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
console.log(`Found ${children.length} child processes:`, children)
|
|
236
|
-
|
|
237
|
-
// The scope will close here and should clean up all processes
|
|
238
|
-
}).pipe(withCleanupTest()(test)),
|
|
239
|
-
)
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
Vitest.describe('Service Pattern', () => {
|
|
243
|
-
const withServiceTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
|
|
244
|
-
Vitest.makeWithTestCtx({
|
|
245
|
-
timeout: testTimeout,
|
|
246
|
-
makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
Vitest.scopedLive('should work with service pattern', (test) =>
|
|
250
|
-
Effect.gen(function* () {
|
|
251
|
-
const server = yield* WranglerDevServerService
|
|
252
|
-
|
|
253
|
-
expect(server.port).toBeGreaterThan(0)
|
|
254
|
-
expect(server.url).toMatch(/http:\/\/localhost:\d+/)
|
|
255
|
-
expect(server.processId).toBeGreaterThan(0)
|
|
256
|
-
}).pipe(withServiceTest()(test)),
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
Vitest.scopedLive('should work with custom port via service', (test) =>
|
|
260
|
-
Effect.andThen(getFreePort, (port) =>
|
|
261
|
-
Effect.gen(function* () {
|
|
262
|
-
const server = yield* WranglerDevServerService
|
|
263
|
-
|
|
264
|
-
expect(server.port).toBe(port)
|
|
265
|
-
expect(server.url).toBe(`http://localhost:${port}`)
|
|
266
|
-
}).pipe(withServiceTest({ preferredPort: port })(test)),
|
|
267
|
-
),
|
|
268
|
-
)
|
|
269
|
-
})
|
|
270
|
-
})
|