effect(installation): migrate to AppProcess.run (#27188)
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { Effect, Layer, Schema, Context, Stream } from "effect"
|
import { Effect, Layer, Schema, Context, Stream } from "effect"
|
||||||
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
|
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
|
||||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
|
||||||
import { withTransientReadRetry } from "@/util/effect-http-client"
|
import { withTransientReadRetry } from "@/util/effect-http-client"
|
||||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
|
import { ChildProcess } from "effect/unstable/process"
|
||||||
|
import { AppProcess } from "@opencode-ai/core/process"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { BusEvent } from "@/bus/bus-event"
|
import { BusEvent } from "@/bus/bus-event"
|
||||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||||
@@ -85,246 +85,235 @@ export interface Interface {
|
|||||||
|
|
||||||
export class Service extends Context.Service<Service, Interface>()("@opencode/Installation") {}
|
export class Service extends Context.Service<Service, Interface>()("@opencode/Installation") {}
|
||||||
|
|
||||||
export const layer: Layer.Layer<Service, never, HttpClient.HttpClient | ChildProcessSpawner.ChildProcessSpawner> =
|
export const layer: Layer.Layer<Service, never, HttpClient.HttpClient | AppProcess.Service> = Layer.effect(
|
||||||
Layer.effect(
|
Service,
|
||||||
Service,
|
Effect.gen(function* () {
|
||||||
Effect.gen(function* () {
|
const http = yield* HttpClient.HttpClient
|
||||||
const http = yield* HttpClient.HttpClient
|
const httpOk = HttpClient.filterStatusOk(withTransientReadRetry(http))
|
||||||
const httpOk = HttpClient.filterStatusOk(withTransientReadRetry(http))
|
const appProcess = yield* AppProcess.Service
|
||||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
|
|
||||||
|
|
||||||
const text = Effect.fnUntraced(
|
const text = Effect.fnUntraced(
|
||||||
function* (cmd: string[], opts?: { cwd?: string; env?: Record<string, string> }) {
|
function* (cmd: string[], opts?: { cwd?: string; env?: Record<string, string> }) {
|
||||||
const proc = ChildProcess.make(cmd[0], cmd.slice(1), {
|
const result = yield* appProcess.run(
|
||||||
|
ChildProcess.make(cmd[0], cmd.slice(1), {
|
||||||
cwd: opts?.cwd,
|
cwd: opts?.cwd,
|
||||||
env: opts?.env,
|
env: opts?.env,
|
||||||
extendEnv: true,
|
extendEnv: true,
|
||||||
})
|
}),
|
||||||
const handle = yield* spawner.spawn(proc)
|
)
|
||||||
const out = yield* Stream.mkString(Stream.decodeText(handle.stdout))
|
return result.stdout.toString("utf8")
|
||||||
yield* handle.exitCode
|
},
|
||||||
return out
|
Effect.catch(() => Effect.succeed("")),
|
||||||
},
|
)
|
||||||
Effect.scoped,
|
|
||||||
Effect.catch(() => Effect.succeed("")),
|
|
||||||
)
|
|
||||||
|
|
||||||
const run = Effect.fnUntraced(
|
const run = Effect.fnUntraced(
|
||||||
function* (cmd: string[], opts?: { cwd?: string; env?: Record<string, string> }) {
|
function* (cmd: string[], opts?: { cwd?: string; env?: Record<string, string> }) {
|
||||||
const proc = ChildProcess.make(cmd[0], cmd.slice(1), {
|
const result = yield* appProcess.run(
|
||||||
|
ChildProcess.make(cmd[0], cmd.slice(1), {
|
||||||
cwd: opts?.cwd,
|
cwd: opts?.cwd,
|
||||||
env: opts?.env,
|
env: opts?.env,
|
||||||
extendEnv: true,
|
extendEnv: true,
|
||||||
})
|
}),
|
||||||
const handle = yield* spawner.spawn(proc)
|
)
|
||||||
const [stdout, stderr] = yield* Effect.all(
|
return {
|
||||||
[Stream.mkString(Stream.decodeText(handle.stdout)), Stream.mkString(Stream.decodeText(handle.stderr))],
|
code: result.exitCode,
|
||||||
{ concurrency: 2 },
|
stdout: result.stdout.toString("utf8"),
|
||||||
)
|
stderr: result.stderr.toString("utf8"),
|
||||||
const code = yield* handle.exitCode
|
}
|
||||||
return { code, stdout, stderr }
|
},
|
||||||
},
|
Effect.catch(() => Effect.succeed({ code: 1, stdout: "", stderr: "" })),
|
||||||
Effect.scoped,
|
)
|
||||||
Effect.catch(() => Effect.succeed({ code: ChildProcessSpawner.ExitCode(1), stdout: "", stderr: "" })),
|
|
||||||
)
|
|
||||||
|
|
||||||
const getBrewFormula = Effect.fnUntraced(function* () {
|
const getBrewFormula = Effect.fnUntraced(function* () {
|
||||||
const tapFormula = yield* text(["brew", "list", "--formula", "anomalyco/tap/opencode"])
|
const tapFormula = yield* text(["brew", "list", "--formula", "anomalyco/tap/opencode"])
|
||||||
if (tapFormula.includes("opencode")) return "anomalyco/tap/opencode"
|
if (tapFormula.includes("opencode")) return "anomalyco/tap/opencode"
|
||||||
const coreFormula = yield* text(["brew", "list", "--formula", "opencode"])
|
const coreFormula = yield* text(["brew", "list", "--formula", "opencode"])
|
||||||
if (coreFormula.includes("opencode")) return "opencode"
|
if (coreFormula.includes("opencode")) return "opencode"
|
||||||
return "opencode"
|
return "opencode"
|
||||||
})
|
})
|
||||||
|
|
||||||
const upgradeCurl = Effect.fnUntraced(
|
const upgradeCurl = Effect.fnUntraced(function* (target: string) {
|
||||||
function* (target: string) {
|
const response = yield* httpOk.execute(HttpClientRequest.get("https://opencode.ai/install"))
|
||||||
const response = yield* httpOk.execute(HttpClientRequest.get("https://opencode.ai/install"))
|
const body = yield* response.text
|
||||||
const body = yield* response.text
|
const bodyBytes = new TextEncoder().encode(body)
|
||||||
const bodyBytes = new TextEncoder().encode(body)
|
const result = yield* appProcess.run(
|
||||||
const proc = ChildProcess.make("bash", [], {
|
ChildProcess.make("bash", [], {
|
||||||
stdin: Stream.make(bodyBytes),
|
stdin: Stream.make(bodyBytes),
|
||||||
env: { VERSION: target },
|
env: { VERSION: target },
|
||||||
extendEnv: true,
|
extendEnv: true,
|
||||||
})
|
|
||||||
const handle = yield* spawner.spawn(proc)
|
|
||||||
const [stdout, stderr] = yield* Effect.all(
|
|
||||||
[Stream.mkString(Stream.decodeText(handle.stdout)), Stream.mkString(Stream.decodeText(handle.stderr))],
|
|
||||||
{ concurrency: 2 },
|
|
||||||
)
|
|
||||||
const code = yield* handle.exitCode
|
|
||||||
return { code, stdout, stderr }
|
|
||||||
},
|
|
||||||
Effect.scoped,
|
|
||||||
Effect.orDie,
|
|
||||||
)
|
|
||||||
|
|
||||||
const result: Interface = {
|
|
||||||
info: Effect.fn("Installation.info")(function* () {
|
|
||||||
return {
|
|
||||||
version: InstallationVersion,
|
|
||||||
latest: yield* result.latest(),
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
method: Effect.fn("Installation.method")(function* () {
|
)
|
||||||
if (process.execPath.includes(path.join(".opencode", "bin"))) return "curl" as Method
|
return {
|
||||||
if (process.execPath.includes(path.join(".local", "bin"))) return "curl" as Method
|
code: result.exitCode,
|
||||||
const exec = process.execPath.toLowerCase()
|
stdout: result.stdout.toString("utf8"),
|
||||||
|
stderr: result.stderr.toString("utf8"),
|
||||||
|
}
|
||||||
|
}, Effect.orDie)
|
||||||
|
|
||||||
const checks: Array<{ name: Method; command: () => Effect.Effect<string> }> = [
|
const result: Interface = {
|
||||||
{ name: "npm", command: () => text(["npm", "list", "-g", "--depth=0"]) },
|
info: Effect.fn("Installation.info")(function* () {
|
||||||
{ name: "yarn", command: () => text(["yarn", "global", "list"]) },
|
return {
|
||||||
{ name: "pnpm", command: () => text(["pnpm", "list", "-g", "--depth=0"]) },
|
version: InstallationVersion,
|
||||||
{ name: "bun", command: () => text(["bun", "pm", "ls", "-g"]) },
|
latest: yield* result.latest(),
|
||||||
{ name: "brew", command: () => text(["brew", "list", "--formula", "opencode"]) },
|
}
|
||||||
{ name: "scoop", command: () => text(["scoop", "list", "opencode"]) },
|
}),
|
||||||
{ name: "choco", command: () => text(["choco", "list", "--limit-output", "opencode"]) },
|
method: Effect.fn("Installation.method")(function* () {
|
||||||
]
|
if (process.execPath.includes(path.join(".opencode", "bin"))) return "curl" as Method
|
||||||
|
if (process.execPath.includes(path.join(".local", "bin"))) return "curl" as Method
|
||||||
|
const exec = process.execPath.toLowerCase()
|
||||||
|
|
||||||
checks.sort((a, b) => {
|
const checks: Array<{ name: Method; command: () => Effect.Effect<string> }> = [
|
||||||
const aMatches = exec.includes(a.name)
|
{ name: "npm", command: () => text(["npm", "list", "-g", "--depth=0"]) },
|
||||||
const bMatches = exec.includes(b.name)
|
{ name: "yarn", command: () => text(["yarn", "global", "list"]) },
|
||||||
if (aMatches && !bMatches) return -1
|
{ name: "pnpm", command: () => text(["pnpm", "list", "-g", "--depth=0"]) },
|
||||||
if (!aMatches && bMatches) return 1
|
{ name: "bun", command: () => text(["bun", "pm", "ls", "-g"]) },
|
||||||
return 0
|
{ name: "brew", command: () => text(["brew", "list", "--formula", "opencode"]) },
|
||||||
})
|
{ name: "scoop", command: () => text(["scoop", "list", "opencode"]) },
|
||||||
|
{ name: "choco", command: () => text(["choco", "list", "--limit-output", "opencode"]) },
|
||||||
|
]
|
||||||
|
|
||||||
for (const check of checks) {
|
checks.sort((a, b) => {
|
||||||
const output = yield* check.command()
|
const aMatches = exec.includes(a.name)
|
||||||
const installedName =
|
const bMatches = exec.includes(b.name)
|
||||||
check.name === "brew" || check.name === "choco" || check.name === "scoop" ? "opencode" : "opencode-ai"
|
if (aMatches && !bMatches) return -1
|
||||||
if (output.includes(installedName)) {
|
if (!aMatches && bMatches) return 1
|
||||||
return check.name
|
return 0
|
||||||
}
|
})
|
||||||
|
|
||||||
|
for (const check of checks) {
|
||||||
|
const output = yield* check.command()
|
||||||
|
const installedName =
|
||||||
|
check.name === "brew" || check.name === "choco" || check.name === "scoop" ? "opencode" : "opencode-ai"
|
||||||
|
if (output.includes(installedName)) {
|
||||||
|
return check.name
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return "unknown" as Method
|
return "unknown" as Method
|
||||||
}),
|
}),
|
||||||
latest: Effect.fn("Installation.latest")(function* (installMethod?: Method) {
|
latest: Effect.fn("Installation.latest")(function* (installMethod?: Method) {
|
||||||
const detectedMethod = installMethod || (yield* result.method())
|
const detectedMethod = installMethod || (yield* result.method())
|
||||||
|
|
||||||
if (detectedMethod === "brew") {
|
if (detectedMethod === "brew") {
|
||||||
const formula = yield* getBrewFormula()
|
const formula = yield* getBrewFormula()
|
||||||
if (formula.includes("/")) {
|
if (formula.includes("/")) {
|
||||||
const infoJson = yield* text(["brew", "info", "--json=v2", formula])
|
const infoJson = yield* text(["brew", "info", "--json=v2", formula])
|
||||||
const info = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(BrewInfoV2))(infoJson)
|
const info = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(BrewInfoV2))(infoJson)
|
||||||
return info.formulae[0].versions.stable
|
return info.formulae[0].versions.stable
|
||||||
}
|
|
||||||
const response = yield* httpOk.execute(
|
|
||||||
HttpClientRequest.get("https://formulae.brew.sh/api/formula/opencode.json").pipe(
|
|
||||||
HttpClientRequest.acceptJson,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
const data = yield* HttpClientResponse.schemaBodyJson(BrewFormula)(response)
|
|
||||||
return data.versions.stable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (detectedMethod === "npm" || detectedMethod === "bun" || detectedMethod === "pnpm") {
|
|
||||||
const response = yield* httpOk.execute(
|
|
||||||
HttpClientRequest.get(
|
|
||||||
`${yield* NpmConfig.registry(process.cwd())}/opencode-ai/${InstallationChannel}`,
|
|
||||||
).pipe(HttpClientRequest.acceptJson),
|
|
||||||
)
|
|
||||||
const data = yield* HttpClientResponse.schemaBodyJson(NpmPackage)(response)
|
|
||||||
return data.version
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detectedMethod === "choco") {
|
|
||||||
const response = yield* httpOk.execute(
|
|
||||||
HttpClientRequest.get(
|
|
||||||
"https://community.chocolatey.org/api/v2/Packages?$filter=Id%20eq%20%27opencode%27%20and%20IsLatestVersion&$select=Version",
|
|
||||||
).pipe(HttpClientRequest.setHeaders({ Accept: "application/json;odata=verbose" })),
|
|
||||||
)
|
|
||||||
const data = yield* HttpClientResponse.schemaBodyJson(ChocoPackage)(response)
|
|
||||||
return data.d.results[0].Version
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detectedMethod === "scoop") {
|
|
||||||
const response = yield* httpOk.execute(
|
|
||||||
HttpClientRequest.get(
|
|
||||||
"https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/opencode.json",
|
|
||||||
).pipe(HttpClientRequest.setHeaders({ Accept: "application/json" })),
|
|
||||||
)
|
|
||||||
const data = yield* HttpClientResponse.schemaBodyJson(ScoopManifest)(response)
|
|
||||||
return data.version
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = yield* httpOk.execute(
|
const response = yield* httpOk.execute(
|
||||||
HttpClientRequest.get("https://api.github.com/repos/anomalyco/opencode/releases/latest").pipe(
|
HttpClientRequest.get("https://formulae.brew.sh/api/formula/opencode.json").pipe(
|
||||||
HttpClientRequest.acceptJson,
|
HttpClientRequest.acceptJson,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
const data = yield* HttpClientResponse.schemaBodyJson(GitHubRelease)(response)
|
const data = yield* HttpClientResponse.schemaBodyJson(BrewFormula)(response)
|
||||||
return data.tag_name.replace(/^v/, "")
|
return data.versions.stable
|
||||||
}, Effect.orDie),
|
}
|
||||||
upgrade: Effect.fn("Installation.upgrade")(function* (m: Method, target: string) {
|
|
||||||
let upgradeResult: { code: ChildProcessSpawner.ExitCode; stdout: string; stderr: string } | undefined
|
if (detectedMethod === "npm" || detectedMethod === "bun" || detectedMethod === "pnpm") {
|
||||||
switch (m) {
|
const response = yield* httpOk.execute(
|
||||||
case "curl":
|
HttpClientRequest.get(
|
||||||
upgradeResult = yield* upgradeCurl(target)
|
`${yield* NpmConfig.registry(process.cwd())}/opencode-ai/${InstallationChannel}`,
|
||||||
break
|
).pipe(HttpClientRequest.acceptJson),
|
||||||
case "npm":
|
)
|
||||||
upgradeResult = yield* run(["npm", "install", "-g", `opencode-ai@${target}`])
|
const data = yield* HttpClientResponse.schemaBodyJson(NpmPackage)(response)
|
||||||
break
|
return data.version
|
||||||
case "pnpm":
|
}
|
||||||
upgradeResult = yield* run(["pnpm", "install", "-g", `opencode-ai@${target}`])
|
|
||||||
break
|
if (detectedMethod === "choco") {
|
||||||
case "bun":
|
const response = yield* httpOk.execute(
|
||||||
upgradeResult = yield* run(["bun", "install", "-g", `opencode-ai@${target}`])
|
HttpClientRequest.get(
|
||||||
break
|
"https://community.chocolatey.org/api/v2/Packages?$filter=Id%20eq%20%27opencode%27%20and%20IsLatestVersion&$select=Version",
|
||||||
case "brew": {
|
).pipe(HttpClientRequest.setHeaders({ Accept: "application/json;odata=verbose" })),
|
||||||
const formula = yield* getBrewFormula()
|
)
|
||||||
const env = { HOMEBREW_NO_AUTO_UPDATE: "1" }
|
const data = yield* HttpClientResponse.schemaBodyJson(ChocoPackage)(response)
|
||||||
if (formula.includes("/")) {
|
return data.d.results[0].Version
|
||||||
const tap = yield* run(["brew", "tap", "anomalyco/tap"], { env })
|
}
|
||||||
if (tap.code !== 0) {
|
|
||||||
upgradeResult = tap
|
if (detectedMethod === "scoop") {
|
||||||
|
const response = yield* httpOk.execute(
|
||||||
|
HttpClientRequest.get(
|
||||||
|
"https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/opencode.json",
|
||||||
|
).pipe(HttpClientRequest.setHeaders({ Accept: "application/json" })),
|
||||||
|
)
|
||||||
|
const data = yield* HttpClientResponse.schemaBodyJson(ScoopManifest)(response)
|
||||||
|
return data.version
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = yield* httpOk.execute(
|
||||||
|
HttpClientRequest.get("https://api.github.com/repos/anomalyco/opencode/releases/latest").pipe(
|
||||||
|
HttpClientRequest.acceptJson,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
const data = yield* HttpClientResponse.schemaBodyJson(GitHubRelease)(response)
|
||||||
|
return data.tag_name.replace(/^v/, "")
|
||||||
|
}, Effect.orDie),
|
||||||
|
upgrade: Effect.fn("Installation.upgrade")(function* (m: Method, target: string) {
|
||||||
|
let upgradeResult: { code: number; stdout: string; stderr: string } | undefined
|
||||||
|
switch (m) {
|
||||||
|
case "curl":
|
||||||
|
upgradeResult = yield* upgradeCurl(target)
|
||||||
|
break
|
||||||
|
case "npm":
|
||||||
|
upgradeResult = yield* run(["npm", "install", "-g", `opencode-ai@${target}`])
|
||||||
|
break
|
||||||
|
case "pnpm":
|
||||||
|
upgradeResult = yield* run(["pnpm", "install", "-g", `opencode-ai@${target}`])
|
||||||
|
break
|
||||||
|
case "bun":
|
||||||
|
upgradeResult = yield* run(["bun", "install", "-g", `opencode-ai@${target}`])
|
||||||
|
break
|
||||||
|
case "brew": {
|
||||||
|
const formula = yield* getBrewFormula()
|
||||||
|
const env = { HOMEBREW_NO_AUTO_UPDATE: "1" }
|
||||||
|
if (formula.includes("/")) {
|
||||||
|
const tap = yield* run(["brew", "tap", "anomalyco/tap"], { env })
|
||||||
|
if (tap.code !== 0) {
|
||||||
|
upgradeResult = tap
|
||||||
|
break
|
||||||
|
}
|
||||||
|
const repo = yield* text(["brew", "--repo", "anomalyco/tap"])
|
||||||
|
const dir = repo.trim()
|
||||||
|
if (dir) {
|
||||||
|
const pull = yield* run(["git", "pull", "--ff-only"], { cwd: dir, env })
|
||||||
|
if (pull.code !== 0) {
|
||||||
|
upgradeResult = pull
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
const repo = yield* text(["brew", "--repo", "anomalyco/tap"])
|
|
||||||
const dir = repo.trim()
|
|
||||||
if (dir) {
|
|
||||||
const pull = yield* run(["git", "pull", "--ff-only"], { cwd: dir, env })
|
|
||||||
if (pull.code !== 0) {
|
|
||||||
upgradeResult = pull
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
upgradeResult = yield* run(["brew", "upgrade", formula], { env })
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
case "choco":
|
upgradeResult = yield* run(["brew", "upgrade", formula], { env })
|
||||||
upgradeResult = yield* run(["choco", "upgrade", "opencode", `--version=${target}`, "-y"])
|
break
|
||||||
break
|
|
||||||
case "scoop":
|
|
||||||
upgradeResult = yield* run(["scoop", "install", `opencode@${target}`])
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
return yield* new UpgradeFailedError({ stderr: `Unknown method: ${m}` })
|
|
||||||
}
|
}
|
||||||
if (!upgradeResult || upgradeResult.code !== 0) {
|
case "choco":
|
||||||
const stderr = m === "choco" ? "not running from an elevated command shell" : upgradeResult?.stderr || ""
|
upgradeResult = yield* run(["choco", "upgrade", "opencode", `--version=${target}`, "-y"])
|
||||||
return yield* new UpgradeFailedError({ stderr })
|
break
|
||||||
}
|
case "scoop":
|
||||||
log.info("upgraded", {
|
upgradeResult = yield* run(["scoop", "install", `opencode@${target}`])
|
||||||
method: m,
|
break
|
||||||
target,
|
default:
|
||||||
stdout: upgradeResult.stdout,
|
return yield* new UpgradeFailedError({ stderr: `Unknown method: ${m}` })
|
||||||
stderr: upgradeResult.stderr,
|
}
|
||||||
})
|
if (!upgradeResult || upgradeResult.code !== 0) {
|
||||||
yield* text([process.execPath, "--version"])
|
const stderr = m === "choco" ? "not running from an elevated command shell" : upgradeResult?.stderr || ""
|
||||||
}),
|
return yield* new UpgradeFailedError({ stderr })
|
||||||
}
|
}
|
||||||
|
log.info("upgraded", {
|
||||||
|
method: m,
|
||||||
|
target,
|
||||||
|
stdout: upgradeResult.stdout,
|
||||||
|
stderr: upgradeResult.stderr,
|
||||||
|
})
|
||||||
|
yield* text([process.execPath, "--version"])
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
return Service.of(result)
|
return Service.of(result)
|
||||||
}),
|
}),
|
||||||
)
|
|
||||||
|
|
||||||
export const defaultLayer = layer.pipe(
|
|
||||||
Layer.provide(FetchHttpClient.layer),
|
|
||||||
Layer.provide(CrossSpawnSpawner.defaultLayer),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const defaultLayer = layer.pipe(Layer.provide(FetchHttpClient.layer), Layer.provide(AppProcess.defaultLayer))
|
||||||
|
|
||||||
const { runPromise } = makeRuntime(Service, defaultLayer)
|
const { runPromise } = makeRuntime(Service, defaultLayer)
|
||||||
|
|
||||||
export const latest = (...args: Parameters<Interface["latest"]>) => runPromise((s) => s.latest(...args))
|
export const latest = (...args: Parameters<Interface["latest"]>) => runPromise((s) => s.latest(...args))
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstab
|
|||||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
|
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
|
||||||
import { Installation } from "../../src/installation"
|
import { Installation } from "../../src/installation"
|
||||||
import { InstallationChannel } from "@opencode-ai/core/installation/version"
|
import { InstallationChannel } from "@opencode-ai/core/installation/version"
|
||||||
|
import { AppProcess } from "@opencode-ai/core/process"
|
||||||
import { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
|
||||||
const encoder = new TextEncoder()
|
const encoder = new TextEncoder()
|
||||||
@@ -47,7 +48,8 @@ function testLayer(
|
|||||||
httpHandler: (request: HttpClientRequest.HttpClientRequest) => Response,
|
httpHandler: (request: HttpClientRequest.HttpClientRequest) => Response,
|
||||||
spawnHandler?: (cmd: string, args: readonly string[]) => string,
|
spawnHandler?: (cmd: string, args: readonly string[]) => string,
|
||||||
) {
|
) {
|
||||||
return Installation.layer.pipe(Layer.provide(mockHttpClient(httpHandler)), Layer.provide(mockSpawner(spawnHandler)))
|
const appProcess = AppProcess.layer.pipe(Layer.provide(mockSpawner(spawnHandler)))
|
||||||
|
return Installation.layer.pipe(Layer.provide(mockHttpClient(httpHandler)), Layer.provide(appProcess))
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("installation", () => {
|
describe("installation", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user