fix(cli): restart stale clients after updates
This commit is contained in:
parent
f9d1d3b259
commit
910af9a122
13 changed files with 246 additions and 25 deletions
6
packages/cli/test/fixture/restart-child.ts
Normal file
6
packages/cli/test/fixture/restart-child.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
const stateFile = process.argv[2]
|
||||
const exit = Number(process.argv[3])
|
||||
const count = (await Bun.file(stateFile).exists()) ? Number(await Bun.file(stateFile).text()) : 0
|
||||
|
||||
await Bun.write(stateFile, String(count + 1))
|
||||
process.exit(exit || (count === 0 ? 75 : 0))
|
||||
43
packages/cli/test/launcher.test.ts
Normal file
43
packages/cli/test/launcher.test.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { expect, test } from "bun:test"
|
||||
import fs from "node:fs/promises"
|
||||
import os from "node:os"
|
||||
import path from "node:path"
|
||||
|
||||
const launcher = path.join(import.meta.dir, "../bin/opencode2.cjs")
|
||||
const fixture = path.join(import.meta.dir, "fixture/restart-child.ts")
|
||||
|
||||
test("restarts the installed binary once with the original arguments", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-launcher-"))
|
||||
const state = path.join(root, "count")
|
||||
|
||||
try {
|
||||
const child = Bun.spawn([process.execPath, launcher, fixture, state, "0"], {
|
||||
env: { ...process.env, OPENCODE_BIN_PATH: process.execPath },
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
})
|
||||
|
||||
expect(await child.exited).toBe(0)
|
||||
expect(await Bun.file(state).text()).toBe("2")
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test("bounds automatic restarts", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-launcher-"))
|
||||
const state = path.join(root, "count")
|
||||
|
||||
try {
|
||||
const child = Bun.spawn([process.execPath, launcher, fixture, state, "75"], {
|
||||
env: { ...process.env, OPENCODE_BIN_PATH: process.execPath },
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
})
|
||||
|
||||
expect(await child.exited).toBe(75)
|
||||
expect(await Bun.file(state).text()).toBe("2")
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
|
@ -7,6 +7,18 @@ import os from "node:os"
|
|||
import path from "node:path"
|
||||
import { ServiceConfig } from "../src/services/service-config"
|
||||
|
||||
test("only replaces older semantic versions", () => {
|
||||
expect(ServiceConfig.canReplaceVersion("1.0.0", "2.0.0")).toBe(true)
|
||||
expect(ServiceConfig.canReplaceVersion("2.0.0", "1.0.0")).toBe(false)
|
||||
expect(ServiceConfig.canReplaceVersion("1.0.0", "1.0.0")).toBe(false)
|
||||
expect(ServiceConfig.canReplaceVersion("0.0.0-next-9999", "0.0.0-next-15000")).toBe(true)
|
||||
expect(ServiceConfig.canReplaceVersion("0.0.0-next-15000", "0.0.0-next-9999")).toBe(false)
|
||||
expect(ServiceConfig.canReplaceVersion("0.0.0-next-15000.1", "0.0.0-next-15000.2")).toBe(true)
|
||||
expect(ServiceConfig.canReplaceVersion("0.0.0-next-15000.10", "0.0.0-next-15000.9")).toBe(false)
|
||||
expect(ServiceConfig.canReplaceVersion("0.0.0-next-15000.10", "0.0.0-next-15000.10")).toBe(false)
|
||||
expect(ServiceConfig.canReplaceVersion(undefined, "1.0.0")).toBe(true)
|
||||
})
|
||||
|
||||
test("local channel stores service config with the local service filename", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-service-"))
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue