Skip to content

Commit 38e10eb

Browse files
fix(opencode): ignore unknown config fields (#41312)
1 parent fe82a1b commit 38e10eb

2 files changed

Lines changed: 10 additions & 33 deletions

File tree

‎packages/opencode/src/config/parse.ts‎

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,11 @@ export function schema<S extends EffectSchema.Decoder<unknown, never>>(
3737
data: unknown,
3838
source: string,
3939
): DeepMutable<S["Type"]> {
40-
const extra = topLevelExtraKeys(schema, data)
41-
if (extra.length) {
42-
throw new InvalidError({
43-
path: source,
44-
issues: [
45-
{
46-
code: "unrecognized_keys",
47-
keys: extra,
48-
path: [],
49-
message: `Unrecognized key${extra.length === 1 ? "" : "s"}: ${extra.join(", ")}`,
50-
},
51-
],
52-
})
53-
}
54-
55-
const decoded = EffectSchema.decodeUnknownExit(schema)(data, { errors: "all", propertyOrder: "original" })
40+
const decoded = EffectSchema.decodeUnknownExit(schema)(data, {
41+
errors: "all",
42+
onExcessProperty: "ignore",
43+
propertyOrder: "original",
44+
})
5645
if (Exit.isSuccess(decoded)) return decoded.value as DeepMutable<S["Type"]>
5746
const error = Cause.squash(decoded.cause)
5847

@@ -70,10 +59,3 @@ export function schema<S extends EffectSchema.Decoder<unknown, never>>(
7059
{ cause: error },
7160
)
7261
}
73-
74-
function topLevelExtraKeys(schema: EffectSchema.Top, data: unknown) {
75-
if (typeof data !== "object" || data === null || Array.isArray(data)) return []
76-
if (schema.ast._tag !== "Objects" || schema.ast.indexSignatures.length > 0) return []
77-
const known = new Set(schema.ast.propertySignatures.map((item) => String(item.name)))
78-
return Object.keys(data).filter((key) => !known.has(key))
79-
}

‎packages/opencode/test/config/config.test.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,12 @@ accountTokenIt.instance("resolves env templates in account config with account t
597597
}),
598598
)
599599

600-
it.instance("validates config schema and throws on invalid fields", () =>
600+
it.instance("validates config schema and throws on invalid values", () =>
601601
Effect.gen(function* () {
602602
const test = yield* TestInstance
603603
yield* writeConfigEffect(test.directory, {
604604
$schema: "https://opencode.ai/config.json",
605-
invalid_field: "should cause error",
605+
model: 42,
606606
})
607607
const exit = yield* Config.use.get().pipe(Effect.exit)
608608
expect(Exit.isFailure(exit)).toBe(true)
@@ -1331,7 +1331,7 @@ it.instance("permission config preserves user key order", () =>
13311331
}),
13321332
)
13331333

1334-
test("config parser preserves permission order while rejecting unknown top-level keys", () => {
1334+
test("config parser preserves permission order while ignoring unknown top-level keys", () => {
13351335
const config = ConfigParse.schema(
13361336
ConfigV1.Info,
13371337
{
@@ -1340,18 +1340,13 @@ test("config parser preserves permission order while rejecting unknown top-level
13401340
"*": "deny",
13411341
edit: "ask",
13421342
},
1343+
plugins: ["example"],
13431344
},
13441345
"test",
13451346
)
13461347

13471348
expect(Object.keys(config.permission!)).toEqual(["bash", "*", "edit"])
1348-
try {
1349-
ConfigParse.schema(ConfigV1.Info, { invalid_field: true }, "test")
1350-
throw new Error("expected config parse to fail")
1351-
} catch (err) {
1352-
const error = err as { data?: { issues?: Array<{ code?: string; keys?: string[]; path?: string[] }> } }
1353-
expect(error.data?.issues?.[0]).toMatchObject({ code: "unrecognized_keys", keys: ["invalid_field"], path: [] })
1354-
}
1349+
expect(config).not.toHaveProperty("plugins")
13551350
})
13561351

13571352
// MCP config merging tests

0 commit comments

Comments
 (0)