Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/app/e2e/regression/review.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ test("a rejected Git init releases its session's button without showing an error
await expect(init).toBeEnabled()
})

test("opens file picker launchers when randomUUID is unavailable on insecure HTTP origins", async ({ page }) => {
await page.addInitScript(() => {
Object.defineProperty(globalThis, "isSecureContext", { configurable: true, value: false })
Object.defineProperty(globalThis.crypto, "randomUUID", { configurable: true, value: undefined })
})

await openSession(page, {
name: "ReviewOpenFileInsecure",
seed: { panes: { ses_reviewopenfileinsecure: { review: true } } },
})

const panel = page.locator("#review-panel")
const tab = panel.getByRole("tab", { name: "Open file", exact: true })
await openFileLauncher(panel)
await expect(tab).toHaveAttribute("aria-selected", "true")
await expect(panel.getByRole("combobox", { name: "Filter files" })).toBeFocused()

await openFileLauncher(panel)
await expect(tab).toHaveCount(2)
})

test("open file tab browses, searches, and tracks missing files", async ({ page }) => {
const searches: { query: string; dirs?: string; limit?: number; directory: string }[] = []
const directory = "C:/OpenCode/ReviewOpenFile"
Expand Down
16 changes: 1 addition & 15 deletions packages/app/src/runtime/persistence/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
const fallback = () => Math.random().toString(16).slice(2)

export function uuid() {
const c = globalThis.crypto

if (!c || typeof c.randomUUID !== "function") return fallback()

if (typeof globalThis.isSecureContext === "boolean" && !globalThis.isSecureContext) return fallback()

try {
return c.randomUUID()
} catch {
return fallback()
}
}
export { uuid } from "@opencode/util/uuid"
3 changes: 2 additions & 1 deletion packages/gui-plugins/src/file/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
type Plugin,
} from "@opencode/plugin/gui"
import { artifactKind } from "@opencode/util/artifact"
import { uuid } from "@opencode/util/uuid"
import { resolveArtifactPath } from "./artifact"
import { FileContext, type FileShared } from "./context"
import type { OpenApp } from "./apps"
Expand Down Expand Up @@ -167,7 +168,7 @@ const setup: Plugin.Setup<typeof File> = (ctx) => {

if (selected || layout.narrow())
layout.open(`file:${selected ?? OPEN}`, session, { tab: "preview", background: options?.background })
else layout.open(`file:${OPEN}:${crypto.randomUUID()}`, session, { tab: "select" })
else layout.open(`file:${OPEN}:${uuid()}`, session, { tab: "select" })

if (!options?.background && layout.narrow() && !layout.side.opened(session)) layout.side.toggle(session)
})
Expand Down
15 changes: 15 additions & 0 deletions packages/util/src/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fallback = () => Math.random().toString(16).slice(2)

export function uuid() {
const c = globalThis.crypto

if (!c || typeof c.randomUUID !== "function") return fallback()

if (typeof globalThis.isSecureContext === "boolean" && !globalThis.isSecureContext) return fallback()

try {
return c.randomUUID()
} catch {
return fallback()
}
}
Loading