6106cb64c7
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Has been cancelled
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Has been cancelled
nix-hashes / compute-hash (macos-15-intel, x86_64-darwin) (push) Has been cancelled
nix-hashes / compute-hash (macos-latest, aarch64-darwin) (push) Has been cancelled
nix-hashes / update-hashes (push) Has been cancelled
publish / version (push) Has been cancelled
publish / build-cli (push) Has been cancelled
publish / sign-cli-macos (push) Has been cancelled
publish / build-node-cli (map[host:blacksmith-4vcpu-ubuntu-2404 target:linux-x64]) (push) Has been cancelled
publish / build-node-cli (map[host:blacksmith-4vcpu-ubuntu-2404-arm target:linux-arm64]) (push) Has been cancelled
publish / build-node-cli (map[host:blacksmith-4vcpu-windows-2025 target:windows-arm64]) (push) Has been cancelled
publish / build-node-cli (map[host:blacksmith-4vcpu-windows-2025 target:windows-x64]) (push) Has been cancelled
publish / build-node-cli (map[host:macos-26 target:darwin-arm64]) (push) Has been cancelled
publish / sign-cli-windows (push) Has been cancelled
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=arm64 host:macos-26 platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Has been cancelled
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=x64 host:macos-26-intel platform_flag:--mac --x64 target:x86_64-apple-darwin]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404-arm platform_flag:--linux --arm64 target:aarch64-unknown-linux-gnu]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Has been cancelled
publish / build-electron (map[host:windows-2025 platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Has been cancelled
publish / publish (push) Has been cancelled
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import path from "node:path"
|
|
|
|
test("standalone server exits when its owner is killed", async () => {
|
|
const owner = Bun.spawn([process.execPath, path.join(import.meta.dir, "fixture/standalone-owner.ts")], {
|
|
cwd: path.join(import.meta.dir, ".."),
|
|
env: { ...process.env, OPENCODE_SERVER_USERNAME: "custom" },
|
|
stdin: "ignore",
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
})
|
|
const line = await Promise.race([
|
|
readLine(owner.stdout, "STANDALONE_READY "),
|
|
Bun.sleep(10_000).then(() => undefined),
|
|
])
|
|
const [, rawPID, url, status] = line?.split(" ") ?? []
|
|
const pid = Number(rawPID)
|
|
|
|
try {
|
|
expect(pid).toBeGreaterThan(0)
|
|
expect(url).toStartWith("http://127.0.0.1:")
|
|
expect(status).toBe("200")
|
|
expect(running(pid)).toBe(true)
|
|
|
|
owner.kill("SIGKILL")
|
|
await owner.exited
|
|
|
|
expect(await waitForExit(pid)).toBe(true)
|
|
} finally {
|
|
owner.kill("SIGKILL")
|
|
if (running(pid)) process.kill(pid, "SIGKILL")
|
|
}
|
|
})
|
|
|
|
async function readLine(stream: ReadableStream<Uint8Array>, prefix: string) {
|
|
const reader = stream.getReader()
|
|
const decoder = new TextDecoder()
|
|
const chunks: string[] = []
|
|
while (true) {
|
|
const result = await reader.read()
|
|
if (result.done) break
|
|
chunks.push(decoder.decode(result.value, { stream: true }))
|
|
const output = chunks.join("")
|
|
const line = output.split("\n").find((line) => line.startsWith(prefix))
|
|
if (line) {
|
|
reader.releaseLock()
|
|
return line
|
|
}
|
|
}
|
|
reader.releaseLock()
|
|
return (chunks.join("") + decoder.decode()).split("\n").find((line) => line.startsWith(prefix))
|
|
}
|
|
|
|
async function waitForExit(pid: number, attempts = 100): Promise<boolean> {
|
|
if (!running(pid)) return true
|
|
if (attempts === 0) return false
|
|
await Bun.sleep(50)
|
|
return waitForExit(pid, attempts - 1)
|
|
}
|
|
|
|
function running(pid: number) {
|
|
if (!Number.isSafeInteger(pid) || pid <= 0) return false
|
|
try {
|
|
process.kill(pid, 0)
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|