mirror of
https://github.com/anomalyco/opencode.git
synced 2026-09-05 17:37:55 +00:00
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { NodeServices } from "@effect/platform-node"
|
|
import { Effect } from "effect"
|
|
import { Command } from "effect/unstable/cli"
|
|
import { Commands } from "../../src/commands/commands"
|
|
import upgrade from "../../src/commands/handlers/upgrade"
|
|
import { Updater } from "../../src/services/updater"
|
|
|
|
const record = (event: unknown) => console.log(`EVENT ${JSON.stringify(event)}`)
|
|
|
|
await Effect.runPromise(
|
|
Command.runWith(Commands.commands.upgrade.spec.pipe(Command.withHandler(upgrade)), { version: "test" })(
|
|
process.argv.slice(2),
|
|
).pipe(
|
|
Effect.provideService(Updater.Service, {
|
|
check: () => Effect.die("Manual upgrades must not run the automatic update check"),
|
|
method: () =>
|
|
Effect.sync(() => {
|
|
record("method")
|
|
return Updater.methods.find((method) => method === (process.env.UPGRADE_TEST_METHOD ?? "npm"))
|
|
}),
|
|
latest: () =>
|
|
Effect.suspend(() => {
|
|
record("latest")
|
|
return process.env.UPGRADE_TEST_LATEST_ERROR
|
|
? Effect.fail(new Error("Update check failed"))
|
|
: Effect.succeed("0.0.0-beta-new")
|
|
}),
|
|
upgrade: (method, version) =>
|
|
Effect.suspend(() => {
|
|
record({ method, version })
|
|
return process.env.UPGRADE_TEST_INSTALL_ERROR ? Effect.fail(new Error("Permission denied")) : Effect.void
|
|
}),
|
|
}),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
)
|