Compare commits

...
Author SHA1 Message Date
Dax 87fb4b50a0 fix(cli): refresh version before manual update 2026-09-16 02:50:05 +00:00
4 changed files with 18 additions and 6 deletions
@@ -93,7 +93,7 @@ export default Runtime.handler(Commands, (input) =>
{ signal },
),
check: (signal) => runPromise(Fiber.join(update).pipe(Effect.flatMap(() => updater.check())), { signal }),
apply: (version) => runPromise(updater.apply(version)),
apply: () => runPromise(updater.apply()),
},
packages: {
prepare: (spec, install = true) => runPromise(install ? npm.add(spec) : npm.resolve(spec)),
+4 -2
View File
@@ -15,7 +15,7 @@ export type CheckResult = RunResult | { readonly type: "unavailable"; readonly m
export interface Interface {
readonly run: () => Effect.Effect<RunResult | undefined>
readonly check: () => Effect.Effect<CheckResult | undefined, Error>
readonly apply: (version: string) => Effect.Effect<void, Error>
readonly apply: () => Effect.Effect<string, Error>
readonly method: () => Effect.Effect<Method | undefined>
readonly latest: () => Effect.Effect<string, Error>
readonly upgrade: (method: Method, version: string) => Effect.Effect<void, Error>
@@ -264,8 +264,10 @@ const make = Effect.gen(function* () {
return true
})
const apply = Effect.fn("cli.updater.apply")(function* (version: string) {
const apply = Effect.fn("cli.updater.apply")(function* () {
const version = yield* latest()
if (!(yield* install(version))) return yield* Effect.fail(new Error("Installation method not found"))
return version
})
const check = Effect.fn("cli.updater.check")(function* () {
+10
View File
@@ -200,6 +200,16 @@ it.live("install failures expose stderr and process errors do not report success
expect(missing.commands).toHaveLength(1)
}),
)
it.live("manual apply refreshes the latest version before installing", () =>
Effect.gen(function* () {
const test = yield* fixture((command) => ({
stdout: Buffer.from(command.command === "npm" ? "@opencode/cli@2.3.3" : ""),
}))
expect(yield* test.updater.apply()).toBe("2.3.4")
expect(test.commands.at(-1)).toEqual(["npm", "install", "--global", "--force", "@opencode/cli@2.3.4"])
}),
)
;(["npm", "pnpm", "bun", "yarn", undefined] as const).forEach((method) => {
it.live(`method detection identifies ${method ?? "an unknown installation"} using the V2 package`, () =>
Effect.gen(function* () {
@@ -21,7 +21,7 @@ export type UpdateSource = {
readonly check: (
signal: AbortSignal,
) => Promise<ClientNotice | { readonly type: "unavailable"; readonly message: string } | undefined>
readonly apply: (version: string) => Promise<void>
readonly apply: () => Promise<string>
}
export const { use: useUpdateNotification, provider: UpdateNotificationProvider } = createSimpleContext({
@@ -65,8 +65,8 @@ export const { use: useUpdateNotification, provider: UpdateNotificationProvider
const current = state()
if (!updater || !current || current.type !== "available") return
setState({ type: "installing", version: current.version })
await updater.apply(current.version).then(
() => setState({ type: "installed", version: current.version }),
await updater.apply().then(
(version) => setState({ type: "installed", version }),
(error) => setState({ type: "failed", message: errorMessage(error) }),
)
}