Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
if (glm52 && model.api.npm === "@ai-sdk/openai-compatible") {
return {
high: { reasoningEffort: "high" },
max: { reasoningEffort: "max" },
xhigh: { reasoningEffort: "xhigh" },
}
}
if (glm52 && model.api.npm === "@ai-sdk/anthropic") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { InstanceRef, WorkspaceRef } from "@/effect/instance-ref"
import { InstanceStore } from "@/project/instance-store"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Effect, Layer } from "effect"
import { HttpServerResponse } from "effect/unstable/http"
import { HttpApiMiddleware } from "effect/unstable/httpapi"
Expand All @@ -26,7 +27,16 @@ function provideInstanceContext<E>(
): Effect.Effect<HttpServerResponse.HttpServerResponse, E, WorkspaceRouteContext> {
return Effect.gen(function* () {
const route = yield* WorkspaceRouteContext
const ctx = yield* store.load({ directory: decode(route.directory) })
const directory = decode(route.directory)
const fs = yield* FSUtil.Service
const exists = yield* fs.existsSafe(directory)
if (!exists) {
return HttpServerResponse.jsonUnsafe(
{ error: { message: `Directory does not exist: ${directory}` } },
{ status: 404 },
)
}
const ctx = yield* store.load({ directory })
return yield* effect.pipe(
Effect.provideService(InstanceRef, ctx),
Effect.provideService(WorkspaceRef, route.workspaceID),
Expand Down
6 changes: 3 additions & 3 deletions packages/opencode/test/provider/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2907,7 +2907,7 @@ describe("ProviderTransform.variants", () => {
})
expect(ProviderTransform.variants(model)).toEqual({
high: { reasoningEffort: "high" },
max: { reasoningEffort: "max" },
xhigh: { reasoningEffort: "xhigh" },
})
})

Expand All @@ -2923,7 +2923,7 @@ describe("ProviderTransform.variants", () => {
})
expect(ProviderTransform.variants(model)).toEqual({
high: { reasoningEffort: "high" },
max: { reasoningEffort: "max" },
xhigh: { reasoningEffort: "xhigh" },
})
}
})
Expand All @@ -2939,7 +2939,7 @@ describe("ProviderTransform.variants", () => {
})
expect(ProviderTransform.variants(model)).toEqual({
high: { reasoningEffort: "high" },
max: { reasoningEffort: "max" },
xhigh: { reasoningEffort: "xhigh" },
})
})

Expand Down
23 changes: 19 additions & 4 deletions packages/opencode/test/server/httpapi-instance-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,27 @@ describe("HttpApi instance context middleware", () => {
Effect.gen(function* () {
yield* serveProbe()

// Malformed percent-encoding (the trailing %A is incomplete). The
// middleware's decode() catches the URIError and falls back to the raw
// string so the request reaches the existence guard instead of crashing.
// The resulting path doesn't exist on disk, so we expect 404 — previously
// this returned 200 with a phantom instance for `<cwd>/%E0%A4%A`.
const response = yield* HttpClient.get("/probe?directory=%25E0%25A4%25A")

expect(response.status).toBe(200)
expect(yield* response.json).toMatchObject({
directory: path.join(process.cwd(), "%E0%A4%A"),
})
expect(response.status).toBe(404)
}),
)

it.live("rejects requests for directories that do not exist on disk", () =>
Effect.gen(function* () {
yield* serveProbe()

const stale = path.join(yield* tmpdirScoped(), "moved-away")
const response = yield* HttpClient.get(`/probe?directory=${encodeURIComponent(stale)}`)

expect(response.status).toBe(404)
const body = yield* response.json
expect(body).toMatchObject({ error: { message: expect.stringContaining(stale) } })
}),
)

Expand Down
Loading