fix(opencode): enforce storage path invariants (#29666)

This commit is contained in:
Luke Parker
2026-06-02 10:54:41 +10:00
committed by GitHub
parent a821029258
commit f0c7febb02
15 changed files with 1993 additions and 17 deletions

View File

@@ -297,7 +297,7 @@ export const layer = Layer.effect(
.insert(ProjectTable)
.values({
id: result.id,
worktree: result.worktree,
worktree: AbsolutePath.make(result.worktree),
vcs: result.vcs ?? null,
name: result.name,
icon_url: result.icon?.url,
@@ -306,13 +306,13 @@ export const layer = Layer.effect(
time_created: result.time.created,
time_updated: result.time.updated,
time_initialized: result.time.initialized,
sandboxes: result.sandboxes,
sandboxes: result.sandboxes.map((sandbox) => AbsolutePath.make(sandbox)),
commands: result.commands,
})
.onConflictDoUpdate({
target: ProjectTable.id,
set: {
worktree: result.worktree,
worktree: AbsolutePath.make(result.worktree),
vcs: result.vcs ?? null,
name: result.name,
icon_url: result.icon?.url,
@@ -320,7 +320,7 @@ export const layer = Layer.effect(
icon_color: result.icon?.color,
time_updated: result.time.updated,
time_initialized: result.time.initialized,
sandboxes: result.sandboxes,
sandboxes: result.sandboxes.map((sandbox) => AbsolutePath.make(sandbox)),
commands: result.commands,
},
})
@@ -451,8 +451,9 @@ export const layer = Layer.effect(
const addSandbox = Effect.fn("Project.addSandbox")(function* (id: ProjectV2.ID, directory: string) {
const row = yield* db.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get().pipe(Effect.orDie)
if (!row) throw new Error(`Project not found: ${id}`)
const sandbox = AbsolutePath.make(directory)
const sboxes = [...row.sandboxes]
if (!sboxes.includes(directory)) sboxes.push(directory)
if (!sboxes.includes(sandbox)) sboxes.push(sandbox)
const result = yield* db
.update(ProjectTable)
.set({ sandboxes: sboxes, time_updated: Date.now() })
@@ -467,7 +468,8 @@ export const layer = Layer.effect(
const removeSandbox = Effect.fn("Project.removeSandbox")(function* (id: ProjectV2.ID, directory: string) {
const row = yield* db.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get().pipe(Effect.orDie)
if (!row) throw new Error(`Project not found: ${id}`)
const sboxes = row.sandboxes.filter((s) => s !== directory)
const sandbox = AbsolutePath.make(directory)
const sboxes = row.sandboxes.filter((s) => s !== sandbox)
const result = yield* db
.update(ProjectTable)
.set({ sandboxes: sboxes, time_updated: Date.now() })

View File

@@ -19,6 +19,7 @@ import { gte } from "drizzle-orm"
import { isNull } from "drizzle-orm"
import { desc } from "drizzle-orm"
import { like } from "drizzle-orm"
import { sql } from "drizzle-orm"
import { inArray } from "drizzle-orm"
import { lt } from "drizzle-orm"
import { or } from "drizzle-orm"
@@ -1047,7 +1048,10 @@ function listByProject(
}
if (input.path !== undefined) {
if (input.path) {
const conds = [eq(SessionTable.path, input.path), like(SessionTable.path, `${input.path}/%`)]
const conds = [
eq(SessionTable.path, input.path),
like(SessionTable.path, sql.param(`${input.path}/%`, SessionTable.path)),
]
conditions.push(
input.directory