test(opencode): restore config coverage parity
This commit is contained in:
parent
8890121da0
commit
ed95ba73f4
3 changed files with 74 additions and 24 deletions
1
bun.lock
1
bun.lock
|
|
@ -274,7 +274,6 @@
|
||||||
"@sentry/solid": "catalog:",
|
"@sentry/solid": "catalog:",
|
||||||
"@sentry/vite-plugin": "catalog:",
|
"@sentry/vite-plugin": "catalog:",
|
||||||
"@solid-primitives/i18n": "2.2.1",
|
"@solid-primitives/i18n": "2.2.1",
|
||||||
"@solid-primitives/scheduled": "1.5.3",
|
|
||||||
"@solid-primitives/storage": "catalog:",
|
"@solid-primitives/storage": "catalog:",
|
||||||
"@solidjs/meta": "catalog:",
|
"@solidjs/meta": "catalog:",
|
||||||
"@solidjs/router": "0.15.4",
|
"@solidjs/router": "0.15.4",
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@
|
||||||
"@sentry/solid": "catalog:",
|
"@sentry/solid": "catalog:",
|
||||||
"@sentry/vite-plugin": "catalog:",
|
"@sentry/vite-plugin": "catalog:",
|
||||||
"@solid-primitives/i18n": "2.2.1",
|
"@solid-primitives/i18n": "2.2.1",
|
||||||
"@solid-primitives/scheduled": "1.5.3",
|
|
||||||
"@solid-primitives/storage": "catalog:",
|
"@solid-primitives/storage": "catalog:",
|
||||||
"@solidjs/meta": "catalog:",
|
"@solidjs/meta": "catalog:",
|
||||||
"@solidjs/router": "0.15.4",
|
"@solidjs/router": "0.15.4",
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,7 @@ const clear = (wait = false) => Effect.runPromise(clearEffect(wait))
|
||||||
// Get managed config directory from environment (set in preload.ts)
|
// Get managed config directory from environment (set in preload.ts)
|
||||||
const managedConfigDir = process.env.OPENCODE_TEST_MANAGED_CONFIG_DIR!
|
const managedConfigDir = process.env.OPENCODE_TEST_MANAGED_CONFIG_DIR!
|
||||||
const originalTestToken = process.env.TEST_TOKEN
|
const originalTestToken = process.env.TEST_TOKEN
|
||||||
|
const originalConsoleToken = process.env.OPENCODE_CONSOLE_TOKEN
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await clear(true)
|
await clear(true)
|
||||||
|
|
@ -137,6 +138,8 @@ afterEach(async () => {
|
||||||
await fs.rm(managedConfigDir, { force: true, recursive: true }).catch(() => {})
|
await fs.rm(managedConfigDir, { force: true, recursive: true }).catch(() => {})
|
||||||
if (originalTestToken === undefined) delete process.env.TEST_TOKEN
|
if (originalTestToken === undefined) delete process.env.TEST_TOKEN
|
||||||
else process.env.TEST_TOKEN = originalTestToken
|
else process.env.TEST_TOKEN = originalTestToken
|
||||||
|
if (originalConsoleToken === undefined) delete process.env.OPENCODE_CONSOLE_TOKEN
|
||||||
|
else process.env.OPENCODE_CONSOLE_TOKEN = originalConsoleToken
|
||||||
await clear(true)
|
await clear(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -163,14 +166,14 @@ const withGlobalConfigDir = <A, E, R>(dir: string, effect: Effect.Effect<A, E, R
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const previous = Global.Path.config
|
const previous = Global.Path.config
|
||||||
;(Global.Path as { config: string }).config = dir
|
;(Global.Path as { config: string }).config = dir
|
||||||
yield* clearEffect()
|
yield* clearEffect(true)
|
||||||
return previous
|
return previous
|
||||||
}),
|
}),
|
||||||
() => effect,
|
() => effect,
|
||||||
(previous) =>
|
(previous) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
;(Global.Path as { config: string }).config = previous
|
;(Global.Path as { config: string }).config = previous
|
||||||
yield* clearEffect()
|
yield* clearEffect(true)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -190,10 +193,11 @@ const withConfigTree = <A, E, R>(
|
||||||
) =>
|
) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const root = yield* tmpdirScoped()
|
const root = yield* tmpdirScoped()
|
||||||
|
const global = yield* tmpdirScoped()
|
||||||
const directory = path.join(root, "project")
|
const directory = path.join(root, "project")
|
||||||
yield* Effect.all(
|
yield* Effect.all(
|
||||||
[
|
[
|
||||||
input.global ? writeConfigEffect(root, schemaConfig(input.global)) : undefined,
|
input.global ? writeConfigEffect(global, schemaConfig(input.global)) : undefined,
|
||||||
input.project ? writeConfigEffect(directory, schemaConfig(input.project)) : undefined,
|
input.project ? writeConfigEffect(directory, schemaConfig(input.project)) : undefined,
|
||||||
input.local ? writeConfigEffect(path.join(directory, ".opencode"), schemaConfig(input.local)) : undefined,
|
input.local ? writeConfigEffect(path.join(directory, ".opencode"), schemaConfig(input.local)) : undefined,
|
||||||
].filter(
|
].filter(
|
||||||
|
|
@ -201,7 +205,7 @@ const withConfigTree = <A, E, R>(
|
||||||
),
|
),
|
||||||
{ concurrency: "unbounded" },
|
{ concurrency: "unbounded" },
|
||||||
)
|
)
|
||||||
return yield* withInstanceDir(directory, effect)
|
return yield* withGlobalConfigDir(global, withInstanceDir(directory, effect))
|
||||||
})
|
})
|
||||||
|
|
||||||
const wellKnown = (input: {
|
const wellKnown = (input: {
|
||||||
|
|
@ -952,6 +956,25 @@ it.effect("merges plugin arrays from global and local configs", () =>
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
it.effect("global config remains global when project config is disabled", () =>
|
||||||
|
withConfigTree(
|
||||||
|
{
|
||||||
|
global: { model: "global/model", plugin: ["global-plugin"] },
|
||||||
|
project: { model: "project/model" },
|
||||||
|
local: { model: "local/model" },
|
||||||
|
},
|
||||||
|
withProcessEnv(
|
||||||
|
"OPENCODE_DISABLE_PROJECT_CONFIG",
|
||||||
|
"true",
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const config = yield* Config.use.get()
|
||||||
|
expect(config.model).toBe("global/model")
|
||||||
|
expect(config.plugin_origins?.find((item) => item.spec === "global-plugin")?.scope).toBe("global")
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
it.instance("does not error when only custom agent is a subagent", () =>
|
it.instance("does not error when only custom agent is a subagent", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const test = yield* TestInstance
|
const test = yield* TestInstance
|
||||||
|
|
@ -1130,6 +1153,16 @@ it.instance(
|
||||||
{ config: { autoupdate: true, disabled_providers: [] } },
|
{ config: { autoupdate: true, disabled_providers: [] } },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
it.instance("managed jsonc settings override managed json settings", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
yield* writeManagedSettingsEffect({ model: "managed/json" })
|
||||||
|
yield* writeManagedSettingsEffect({ model: "managed/jsonc" }, "opencode.jsonc")
|
||||||
|
|
||||||
|
const config = yield* Config.use.get()
|
||||||
|
expect(config.model).toBe("managed/jsonc")
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
it.instance(
|
it.instance(
|
||||||
"missing managed settings file is not an error",
|
"missing managed settings file is not an error",
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
|
|
@ -1439,14 +1472,16 @@ test("remote well-known config can use FetchHttpClient layer", async () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await provideTmpdirInstance(() =>
|
await provideTmpdirInstance(
|
||||||
Config.Service.use((svc) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Config.Service.use((svc) =>
|
||||||
const config = yield* svc.get()
|
Effect.gen(function* () {
|
||||||
expect(fetchedUrl).toBe(`${server.url.origin}/.well-known/opencode`)
|
const config = yield* svc.get()
|
||||||
expect(config.mcp?.jira?.enabled).toBe(true)
|
expect(fetchedUrl).toBe(`${server.url.origin}/.well-known/opencode`)
|
||||||
}),
|
expect(config.mcp?.jira?.enabled).toBe(true)
|
||||||
),
|
}),
|
||||||
|
),
|
||||||
|
{ git: true },
|
||||||
).pipe(
|
).pipe(
|
||||||
Effect.scoped,
|
Effect.scoped,
|
||||||
Effect.provide(
|
Effect.provide(
|
||||||
|
|
@ -1488,6 +1523,26 @@ templatedHeaderWellKnown.it.instance("wellknown remote_config supports templated
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const remotePrecedenceWellKnown = wellKnown({
|
||||||
|
config: {
|
||||||
|
mcp: { confluence: { type: "remote", url: "https://confluence.example.com/mcp", enabled: false } },
|
||||||
|
},
|
||||||
|
remoteConfig: { url: "https://config.example.com/{env:TEST_TOKEN}/opencode.json" },
|
||||||
|
remote: {
|
||||||
|
config: { mcp: { confluence: { type: "remote", url: "https://confluence.example.com/mcp", enabled: true } } },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
remotePrecedenceWellKnown.it.instance(
|
||||||
|
"wellknown remote_config url tokens and nested config override embedded config",
|
||||||
|
() =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const config = yield* Config.use.get()
|
||||||
|
expect(remotePrecedenceWellKnown.seen.remote).toBe("https://config.example.com/test-token/opencode.json")
|
||||||
|
expect(config.mcp?.confluence?.enabled).toBe(true)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
const envIsolationWellKnown = wellKnown({
|
const envIsolationWellKnown = wellKnown({
|
||||||
remoteConfig: {
|
remoteConfig: {
|
||||||
url: "https://config.example.com/opencode.json",
|
url: "https://config.example.com/opencode.json",
|
||||||
|
|
@ -1501,16 +1556,13 @@ const envIsolationWellKnown = wellKnown({
|
||||||
envIsolationWellKnown.it.instance(
|
envIsolationWellKnown.it.instance(
|
||||||
"wellknown token env substitution does not mutate process env",
|
"wellknown token env substitution does not mutate process env",
|
||||||
() =>
|
() =>
|
||||||
withProcessEnv(
|
Effect.gen(function* () {
|
||||||
"TEST_TOKEN",
|
process.env.TEST_TOKEN = "preexisting-token"
|
||||||
"preexisting-token",
|
const config = yield* Config.use.get()
|
||||||
Effect.gen(function* () {
|
expect(envIsolationWellKnown.seen.authorization).toBe("Bearer test-token")
|
||||||
const config = yield* Config.use.get()
|
expect(config.username).toBe("test-token")
|
||||||
expect(envIsolationWellKnown.seen.authorization).toBe("Bearer test-token")
|
expect(process.env.TEST_TOKEN).toBe("preexisting-token")
|
||||||
expect(config.username).toBe("test-token")
|
}),
|
||||||
expect(process.env.TEST_TOKEN).toBe("preexisting-token")
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
{ git: true, config: { username: "{env:TEST_TOKEN}" } },
|
{ git: true, config: { username: "{env:TEST_TOKEN}" } },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue