mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-01 13:14:34 +00:00
fix(core): drop undefined permission metadata values before publishing requests (#54090)
This commit is contained in:
parent
de19af9263
commit
1b2c720cba
2 changed files with 33 additions and 2 deletions
|
|
@ -195,7 +195,11 @@ const layer = Layer.effect(
|
|||
action: input.action,
|
||||
resources: input.resources,
|
||||
save: input.save,
|
||||
metadata: input.metadata,
|
||||
// Tools copy optional inputs straight into metadata; undefined values are not JSON and would
|
||||
// fail the HttpApi response encoder when clients list pending requests.
|
||||
metadata:
|
||||
input.metadata &&
|
||||
Object.fromEntries(Object.entries(input.metadata).filter(([, value]) => value !== undefined)),
|
||||
source: input.source,
|
||||
message,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { Cause, Deferred, Effect, Fiber, Layer } from "effect"
|
||||
import { Cause, Deferred, Effect, Fiber, Layer, Schema } from "effect"
|
||||
import { Agent } from "@opencode/core/agent"
|
||||
import { Database } from "@opencode/core/database/database"
|
||||
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
|
||||
|
|
@ -296,6 +296,33 @@ describe("Permission", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("drops undefined metadata values so pending requests encode as JSON", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* setup()
|
||||
// Tools copy optional model inputs straight into metadata, so omitted inputs arrive as undefined values.
|
||||
const { service, request } = yield* waitForRequest({
|
||||
action: "glob",
|
||||
resources: ["/project"],
|
||||
metadata: { root: "/project", path: undefined, hidden: undefined, limit: undefined },
|
||||
})
|
||||
expect(request.metadata).toStrictEqual({ root: "/project" })
|
||||
expect(yield* service.forSession(request.sessionID)).toEqual([request])
|
||||
// HttpApi encodes JSON success bodies through Schema.toCodecJson, which rejects undefined values in Unknown.
|
||||
const encode = Schema.encodeEffect(Schema.toCodecJson(Schema.Struct({ data: Schema.Array(Permission.Request) })))
|
||||
expect(yield* encode({ data: yield* service.forSession(request.sessionID) })).toEqual({
|
||||
data: [
|
||||
{
|
||||
id: request.id,
|
||||
sessionID: request.sessionID,
|
||||
action: "glob",
|
||||
resources: ["/project"],
|
||||
metadata: { root: "/project" },
|
||||
},
|
||||
],
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("defects when an asked permission is declined", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* setup()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue