mirror of
https://github.com/anomalyco/opencode.git
synced 2026-06-01 19:05:38 +00:00
test: migrate managed config fixtures
This commit is contained in:
@@ -104,6 +104,9 @@ async function writeManagedSettings(settings: object, filename = "opencode.json"
|
|||||||
await Filesystem.write(path.join(managedConfigDir, filename), JSON.stringify(settings))
|
await Filesystem.write(path.join(managedConfigDir, filename), JSON.stringify(settings))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const writeManagedSettingsEffect = (settings: object, filename?: string) =>
|
||||||
|
Effect.promise(() => writeManagedSettings(settings, filename))
|
||||||
|
|
||||||
async function writeConfig(dir: string, config: object, name = "opencode.json") {
|
async function writeConfig(dir: string, config: object, name = "opencode.json") {
|
||||||
await Filesystem.write(path.join(dir, name), JSON.stringify(config))
|
await Filesystem.write(path.join(dir, name), JSON.stringify(config))
|
||||||
}
|
}
|
||||||
@@ -1302,80 +1305,47 @@ it.instance("migrates legacy write tool to edit permission", () =>
|
|||||||
// Managed settings tests
|
// Managed settings tests
|
||||||
// Note: preload.ts sets OPENCODE_TEST_MANAGED_CONFIG which Global.Path.managedConfig uses
|
// Note: preload.ts sets OPENCODE_TEST_MANAGED_CONFIG which Global.Path.managedConfig uses
|
||||||
|
|
||||||
test("managed settings override user settings", async () => {
|
it.instance(
|
||||||
await using tmp = await tmpdir({
|
"managed settings override user settings",
|
||||||
init: async (dir) => {
|
Effect.gen(function* () {
|
||||||
await writeConfig(dir, {
|
yield* writeManagedSettingsEffect({
|
||||||
$schema: "https://opencode.ai/config.json",
|
$schema: "https://opencode.ai/config.json",
|
||||||
model: "user/model",
|
model: "managed/model",
|
||||||
share: "auto",
|
share: "disabled",
|
||||||
username: "testuser",
|
})
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await writeManagedSettings({
|
const config = yield* Config.Service.use((svc) => svc.get())
|
||||||
$schema: "https://opencode.ai/config.json",
|
expect(config.model).toBe("managed/model")
|
||||||
model: "managed/model",
|
expect(config.share).toBe("disabled")
|
||||||
share: "disabled",
|
expect(config.username).toBe("testuser")
|
||||||
})
|
}),
|
||||||
|
{ config: { model: "user/model", share: "auto", username: "testuser" } },
|
||||||
|
)
|
||||||
|
|
||||||
await withTestInstance({
|
it.instance(
|
||||||
directory: tmp.path,
|
"managed settings override project settings",
|
||||||
fn: async (ctx) => {
|
Effect.gen(function* () {
|
||||||
const config = await load(ctx)
|
yield* writeManagedSettingsEffect({
|
||||||
expect(config.model).toBe("managed/model")
|
$schema: "https://opencode.ai/config.json",
|
||||||
expect(config.share).toBe("disabled")
|
autoupdate: false,
|
||||||
expect(config.username).toBe("testuser")
|
disabled_providers: ["openai"],
|
||||||
},
|
})
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test("managed settings override project settings", async () => {
|
const config = yield* Config.Service.use((svc) => svc.get())
|
||||||
await using tmp = await tmpdir({
|
expect(config.autoupdate).toBe(false)
|
||||||
init: async (dir) => {
|
expect(config.disabled_providers).toEqual(["openai"])
|
||||||
await writeConfig(dir, {
|
}),
|
||||||
$schema: "https://opencode.ai/config.json",
|
{ config: { autoupdate: true, disabled_providers: [] } },
|
||||||
autoupdate: true,
|
)
|
||||||
disabled_providers: [],
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await writeManagedSettings({
|
it.instance(
|
||||||
$schema: "https://opencode.ai/config.json",
|
"missing managed settings file is not an error",
|
||||||
autoupdate: false,
|
Effect.gen(function* () {
|
||||||
disabled_providers: ["openai"],
|
const config = yield* Config.Service.use((svc) => svc.get())
|
||||||
})
|
expect(config.model).toBe("user/model")
|
||||||
|
}),
|
||||||
await withTestInstance({
|
{ config: { model: "user/model" } },
|
||||||
directory: tmp.path,
|
)
|
||||||
fn: async (ctx) => {
|
|
||||||
const config = await load(ctx)
|
|
||||||
expect(config.autoupdate).toBe(false)
|
|
||||||
expect(config.disabled_providers).toEqual(["openai"])
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test("missing managed settings file is not an error", async () => {
|
|
||||||
await using tmp = await tmpdir({
|
|
||||||
init: async (dir) => {
|
|
||||||
await writeConfig(dir, {
|
|
||||||
$schema: "https://opencode.ai/config.json",
|
|
||||||
model: "user/model",
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await withTestInstance({
|
|
||||||
directory: tmp.path,
|
|
||||||
fn: async (ctx) => {
|
|
||||||
const config = await load(ctx)
|
|
||||||
expect(config.model).toBe("user/model")
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it.instance("migrates legacy edit tool to edit permission", () =>
|
it.instance("migrates legacy edit tool to edit permission", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ Repeated setup work, long sleeps/timeouts, serial integration tests, filesystem/
|
|||||||
| `.opencode` agent and command file-loading cases can use Effect-aware instance fixtures | Migrated singular/plural agent and command markdown fixture cases to `it.instance` | 7.21s | 1.87s | keep | Parent baseline was noisy (7.42, 7.21, 2.83); after runs were stable at 1.87, 1.98, 1.83. Keep as cleanup with no broad claim. |
|
| `.opencode` agent and command file-loading cases can use Effect-aware instance fixtures | Migrated singular/plural agent and command markdown fixture cases to `it.instance` | 7.21s | 1.87s | keep | Parent baseline was noisy (7.42, 7.21, 2.83); after runs were stable at 1.87, 1.98, 1.83. Keep as cleanup with no broad claim. |
|
||||||
| Legacy tools and permission-order config cases can use Effect-aware instance fixtures | Migrated legacy `tools` migration and permission order cases to `it.instance` | 1.87s | 1.87s | keep | Neutral timing; removes more manual temp-instance plumbing from legacy config migration coverage. |
|
| Legacy tools and permission-order config cases can use Effect-aware instance fixtures | Migrated legacy `tools` migration and permission order cases to `it.instance` | 1.87s | 1.87s | keep | Neutral timing; removes more manual temp-instance plumbing from legacy config migration coverage. |
|
||||||
| Remaining simple config load cases can use Effect-aware instance fixtures | Migrated default config load and legacy TUI-key cases to `it.instance` | 7.78s | 6.39s | keep | Single baseline before edit; after median from three sequential reruns (5.76, 6.39, 6.53). Keep as cleanup with cautious timing. |
|
| Remaining simple config load cases can use Effect-aware instance fixtures | Migrated default config load and legacy TUI-key cases to `it.instance` | 7.78s | 6.39s | keep | Single baseline before edit; after median from three sequential reruns (5.76, 6.39, 6.53). Keep as cleanup with cautious timing. |
|
||||||
|
| Managed settings config cases can use Effect-aware instance fixtures | Migrated managed override and missing-managed-file cases to `it.instance` | 2.40s | 1.76s | keep | Single baseline before edit; after median from three sequential reruns (1.75, 1.76, 1.80). |
|
||||||
|
|
||||||
## Profiling Results
|
## Profiling Results
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user