fix(npm): respect npmrc for version lookups (#24016)

This commit is contained in:
Shoubhit Dash
2026-04-23 21:28:54 +05:30
committed by GitHub
parent eb7555d3c6
commit 9df7c78ebe
4 changed files with 171 additions and 34 deletions

View File

@@ -3,6 +3,7 @@ import { Effect, Layer, Stream } from "effect"
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
import { Installation } from "../../src/installation"
import { InstallationChannel } from "../../src/installation/version"
const encoder = new TextEncoder()
@@ -68,11 +69,15 @@ describe("installation", () => {
expect(result).toBe("4.0.0-beta.1")
})
test("reads npm registry versions", async () => {
test("reads npm versions via npm view", async () => {
const calls: string[][] = []
const layer = testLayer(
() => jsonResponse({ version: "1.5.0" }),
() => {
throw new Error("unexpected http request")
},
(cmd, args) => {
if (cmd === "npm" && args.includes("registry")) return "https://registry.npmjs.org\n"
calls.push([cmd, ...args])
if (cmd === "npm" && args[0] === "view") return '"1.5.0"\n'
return ""
},
)
@@ -81,18 +86,47 @@ describe("installation", () => {
Installation.Service.use((svc) => svc.latest("npm")).pipe(Effect.provide(layer)),
)
expect(result).toBe("1.5.0")
expect(calls).toContainEqual(["npm", "view", `opencode-ai@${InstallationChannel}`, "version", "--json"])
})
test("reads npm registry versions for bun method", async () => {
test("reads npm versions via bun pm view", async () => {
const calls: string[][] = []
const layer = testLayer(
() => jsonResponse({ version: "1.6.0" }),
() => "",
() => {
throw new Error("unexpected http request")
},
(cmd, args) => {
calls.push([cmd, ...args])
if (cmd === "bun" && args[0] === "pm") return '"1.6.0"\n'
return ""
},
)
const result = await Effect.runPromise(
Installation.Service.use((svc) => svc.latest("bun")).pipe(Effect.provide(layer)),
)
expect(result).toBe("1.6.0")
expect(calls).toContainEqual(["bun", "pm", "view", `opencode-ai@${InstallationChannel}`, "version", "--json"])
})
test("reads npm versions via pnpm view", async () => {
const calls: string[][] = []
const layer = testLayer(
() => {
throw new Error("unexpected http request")
},
(cmd, args) => {
calls.push([cmd, ...args])
if (cmd === "pnpm" && args[0] === "view") return '"1.7.0"\n'
return ""
},
)
const result = await Effect.runPromise(
Installation.Service.use((svc) => svc.latest("pnpm")).pipe(Effect.provide(layer)),
)
expect(result).toBe("1.7.0")
expect(calls).toContainEqual(["pnpm", "view", `opencode-ai@${InstallationChannel}`, "version", "--json"])
})
test("reads scoop manifest versions", async () => {