fix(core): skip dependency install in read-only config dirs (#12128)
This commit is contained in:
@@ -566,6 +566,67 @@ test("gets config directories", async () => {
|
||||
})
|
||||
})
|
||||
|
||||
test("does not try to install dependencies in read-only OPENCODE_CONFIG_DIR", async () => {
|
||||
if (process.platform === "win32") return
|
||||
|
||||
await using tmp = await tmpdir<string>({
|
||||
init: async (dir) => {
|
||||
const ro = path.join(dir, "readonly")
|
||||
await fs.mkdir(ro, { recursive: true })
|
||||
await fs.chmod(ro, 0o555)
|
||||
return ro
|
||||
},
|
||||
dispose: async (dir) => {
|
||||
const ro = path.join(dir, "readonly")
|
||||
await fs.chmod(ro, 0o755).catch(() => {})
|
||||
return ro
|
||||
},
|
||||
})
|
||||
|
||||
const prev = process.env.OPENCODE_CONFIG_DIR
|
||||
process.env.OPENCODE_CONFIG_DIR = tmp.extra
|
||||
|
||||
try {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
await Config.get()
|
||||
},
|
||||
})
|
||||
} finally {
|
||||
if (prev === undefined) delete process.env.OPENCODE_CONFIG_DIR
|
||||
else process.env.OPENCODE_CONFIG_DIR = prev
|
||||
}
|
||||
})
|
||||
|
||||
test("installs dependencies in writable OPENCODE_CONFIG_DIR", async () => {
|
||||
await using tmp = await tmpdir<string>({
|
||||
init: async (dir) => {
|
||||
const cfg = path.join(dir, "configdir")
|
||||
await fs.mkdir(cfg, { recursive: true })
|
||||
return cfg
|
||||
},
|
||||
})
|
||||
|
||||
const prev = process.env.OPENCODE_CONFIG_DIR
|
||||
process.env.OPENCODE_CONFIG_DIR = tmp.extra
|
||||
|
||||
try {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
await Config.get()
|
||||
},
|
||||
})
|
||||
|
||||
expect(await Bun.file(path.join(tmp.extra, "package.json")).exists()).toBe(true)
|
||||
expect(await Bun.file(path.join(tmp.extra, ".gitignore")).exists()).toBe(true)
|
||||
} finally {
|
||||
if (prev === undefined) delete process.env.OPENCODE_CONFIG_DIR
|
||||
else process.env.OPENCODE_CONFIG_DIR = prev
|
||||
}
|
||||
})
|
||||
|
||||
test("resolves scoped npm plugins in config", async () => {
|
||||
await using tmp = await tmpdir({
|
||||
init: async (dir) => {
|
||||
|
||||
Reference in New Issue
Block a user