mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(browser): distinguish unattached inventory from unexecuted actions
This commit is contained in:
parent
bbb8ac1e8d
commit
7fe1f810a2
3 changed files with 9 additions and 5 deletions
|
|
@ -427,7 +427,7 @@ it.live("without a deny, a session with no desktop hears that it is disconnected
|
|||
const status = (yield* browser.call("build", detached.id)).output
|
||||
expect(status).toMatchObject({ connected: false, message: expect.stringContaining("retry only after it attaches") })
|
||||
for (const [op, input] of [["preview", { path: "page.html" }], ["preview", { path: "missing.html" }], ["wait", { tabID: tab.id, selector: "#done" }], ["snapshot", { tabID: missingTab }]] as const)
|
||||
expect((yield* browser.run(op, input, "build", detached.id)).output).toEqual(status)
|
||||
expect((yield* browser.run(op, input, "build", detached.id).pipe(Effect.flip)).message).toStartWith("[browser.not_attached]")
|
||||
expect(browser.commands.count).toBe(0)
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ it.live("HTML preview passes the checked relative path and requires a usable tab
|
|||
}),
|
||||
)
|
||||
|
||||
it.live("preview fails for a missing file, and returns attachment status without a desktop", () =>
|
||||
it.live("preview fails for a missing file; an unattached inventory stays iterable and actions do not report success", () =>
|
||||
Effect.gen(function* () {
|
||||
const browser = yield* setup((action) => success(action.type === "preview" ? { path: action.path } : tab))
|
||||
yield* Effect.promise(() => Bun.write(join(browser.directory, "chart.svg"), "<svg/>"))
|
||||
|
|
@ -307,6 +307,7 @@ it.live("preview fails for a missing file, and returns attachment status without
|
|||
|
||||
const detached = yield* setup(() => success(tab), { attach: false })
|
||||
yield* Effect.promise(() => Bun.write(join(detached.directory, "chart.svg"), "<svg/>"))
|
||||
expect(JSON.parse(yield* detached.run(`return await tools.browser.preview({ path: "chart.svg" })`))).toMatchObject({ connected: false })
|
||||
expect(JSON.parse(yield* detached.run(`const s = await tools.browser.tabs.list({}); return { ...s, tabs: s.tabs.map(t => t.id) }`))).toMatchObject({ connected: false, tabs: [], focusedTabID: null })
|
||||
expect(yield* detached.run(`try { await tools.browser.click({ tabID: "${tabID}", ref: "e1" }); return "Done" } catch (error) { return error.message }`)).toStartWith("[browser.not_attached]")
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -146,7 +146,10 @@ export const register = Effect.fn("BrowserTools.register")(function* (
|
|||
const action = input.type === "wait" ? { ...input, plan: yield* parse(() => waitPlan(input)) } : yield* parse(() => normalizeAction(input))
|
||||
const paths = "paths" in action ? action.paths.map((path) => BrowserFiles.uploadPath(ctx.location.directory, path)) : undefined
|
||||
const approved = yield* connection.authorize(tool, action, paths ?? (action.type === "preview" ? [action.path] : undefined))
|
||||
if (approved.connected === false) return { output: approved, content: [{ type: "text" as const, text: approved.message }] }
|
||||
if (approved.connected === false) {
|
||||
if (action.type === "tabs.list") return { output: { ...approved, tabs: [], focusedTabID: null }, content: [{ type: "text" as const, text: approved.message }] }
|
||||
return yield* new Tool.Error({ metadata: { code: "not_attached" }, message: `[browser.not_attached] ${approved.message}` })
|
||||
}
|
||||
if (action.type === "wait") return yield* wait(action.tabID, action.plan, tool, approved)
|
||||
if (action.type === "preview" && ctx.location.workspaceID) return yield* new Tool.Error({ message: "Browser preview requires a server-local workspace." })
|
||||
const checked = action.type === "preview" ? { ...action, path: yield* previewable(action.path, tool) } : action
|
||||
|
|
@ -182,7 +185,7 @@ export const register = Effect.fn("BrowserTools.register")(function* (
|
|||
name: operation.name.slice(separator + 1),
|
||||
description: operation.description,
|
||||
input: operation.input,
|
||||
output: Schema.Union([operation.output, Schema.Struct({ connected: Schema.Literal(false), message: Schema.String })]),
|
||||
output: operation.name === "tabs.list" ? Schema.Struct({ ...Browser.State.fields, connected: Schema.optional(Schema.Literal(false)), message: Schema.optional(Schema.String) }) : operation.output,
|
||||
options: {
|
||||
namespace: separator < 0 ? "browser" : `browser.${operation.name.slice(0, separator)}`,
|
||||
permission: "browser",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue