mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
test: align platform and endpoint expectations (#48916)
This commit is contained in:
committed by
GitHub
Unverified
parent
93a37958a7
commit
223b0271e6
@@ -30,7 +30,7 @@ for (const shared of [true, false]) {
|
||||
sessions: [{ id: sessionID, projectID, directory: workspace, title }],
|
||||
pageMessages: () => ({ items: [] }),
|
||||
})
|
||||
await page.route("**/api/mcp**", async (route) => {
|
||||
await page.route(/\/api\/(?:experimental\/)?mcp(?:[/?]|$)/, async (route) => {
|
||||
if (route.request().method() === "OPTIONS") return route.fallback()
|
||||
const url = new URL(route.request().url())
|
||||
const target = url.searchParams.get("location[directory]") ?? directory
|
||||
@@ -109,7 +109,7 @@ for (const surface of ["popover", "dialog"] as const) {
|
||||
sessions: [{ id: sessionID, projectID, directory: workspace, title }],
|
||||
pageMessages: () => ({ items: [] }),
|
||||
})
|
||||
await page.route("**/api/mcp**", async (route) => {
|
||||
await page.route(/\/api\/(?:experimental\/)?mcp(?:[/?]|$)/, async (route) => {
|
||||
if (route.request().method() === "OPTIONS") return route.fallback()
|
||||
const url = new URL(route.request().url())
|
||||
const target = url.searchParams.get("location[directory]") ?? directory
|
||||
|
||||
@@ -343,7 +343,7 @@ async function openDraft(page: Page, worktree = "main", options: { git?: boolean
|
||||
(route) => route.fulfill({ json: { location: { directory }, data: { branch: {} } } }),
|
||||
)
|
||||
}
|
||||
await page.route("**/api/mcp**", async (route) => {
|
||||
await page.route(/\/api\/(?:experimental\/)?mcp(?:[/?]|$)/, async (route) => {
|
||||
if (route.request().method() === "OPTIONS") return route.fallback()
|
||||
const url = new URL(route.request().url())
|
||||
const target = url.searchParams.get("location[directory]") ?? directory
|
||||
|
||||
@@ -6,7 +6,7 @@ test("every MCP row hit area toggles exactly once and keeps the submenu open", a
|
||||
await mockStressTimeline(page)
|
||||
const state = { enabled: true }
|
||||
const writes: string[] = []
|
||||
await page.route("**/api/mcp**", (route) => {
|
||||
await page.route(/\/api\/(?:experimental\/)?mcp(?:[/?]|$)/, (route) => {
|
||||
if (route.request().method() === "OPTIONS") return route.fallback()
|
||||
const url = new URL(route.request().url())
|
||||
const directory = url.searchParams.get("location[directory]")
|
||||
@@ -72,7 +72,7 @@ test("MCP authentication starts before a slow resource catalog finishes", async
|
||||
const attempts: string[] = []
|
||||
const resources = Promise.withResolvers<void>()
|
||||
await context.route("https://auth.example.test/**", (route) => route.fulfill({ body: "Sign in" }))
|
||||
await page.route("**/api/mcp**", async (route) => {
|
||||
await page.route(/\/api\/(?:experimental\/)?mcp(?:[/?]|$)/, async (route) => {
|
||||
if (route.request().method() === "OPTIONS") return route.fallback()
|
||||
const url = new URL(route.request().url())
|
||||
if (url.pathname.endsWith("/connect")) {
|
||||
|
||||
@@ -236,6 +236,7 @@ describe("acp service directory behavior", () => {
|
||||
headers: [{ name: "Authorization", value: "Bearer x" }],
|
||||
}
|
||||
let created = 0
|
||||
const mcp = "/api/experimental/mcp/"
|
||||
await using fixture = makeACPFixture({
|
||||
fetch(request) {
|
||||
if (request.method === "POST" && request.path === "/api/session") {
|
||||
@@ -245,7 +246,7 @@ describe("acp service directory behavior", () => {
|
||||
if (request.method === "GET" && request.path === "/api/session/ses_1") {
|
||||
return Response.json({ data: makeSession("ses_1") })
|
||||
}
|
||||
if (request.method === "PUT" && request.path.startsWith("/api/mcp/")) {
|
||||
if (request.method === "PUT" && request.path.startsWith(mcp)) {
|
||||
return new Response(null, { status: 204 })
|
||||
}
|
||||
return undefined
|
||||
@@ -257,9 +258,9 @@ describe("acp service directory behavior", () => {
|
||||
await fixture.service.resumeSession({ cwd: "/workspace", sessionId: "ses_1", mcpServers: [changed] })
|
||||
await fixture.service.newSession({ cwd: "/workspace", mcpServers: [local] })
|
||||
|
||||
const adds = fixture.requests.filter((request) => request.method === "PUT" && request.path.startsWith("/api/mcp/"))
|
||||
const adds = fixture.requests.filter((request) => request.method === "PUT" && request.path.startsWith(mcp))
|
||||
expect(adds).toHaveLength(4)
|
||||
expect(adds.filter((request) => request.path === "/api/mcp/tools").map((request) => request.body)).toEqual([
|
||||
expect(adds.filter((request) => request.path === `${mcp}tools`).map((request) => request.body)).toEqual([
|
||||
{
|
||||
config: {
|
||||
type: "local",
|
||||
@@ -282,7 +283,7 @@ describe("acp service directory behavior", () => {
|
||||
},
|
||||
},
|
||||
])
|
||||
expect(adds.find((request) => request.path === "/api/mcp/docs")?.body).toEqual({
|
||||
expect(adds.find((request) => request.path === `${mcp}docs`)?.body).toEqual({
|
||||
config: {
|
||||
type: "remote",
|
||||
url: "https://example.com/mcp",
|
||||
|
||||
@@ -24,7 +24,8 @@ describe("acp service", () => {
|
||||
if (url.pathname === "/api/command")
|
||||
return Response.json({ location, data: [{ name: "review", template: "" }] })
|
||||
if (url.pathname === "/api/session" && request.method === "POST") return Response.json({ data: session })
|
||||
if (url.pathname === "/api/mcp/docs" && request.method === "PUT") return new Response(null, { status: 204 })
|
||||
if (url.pathname === "/api/experimental/mcp/docs" && request.method === "PUT")
|
||||
return new Response(null, { status: 204 })
|
||||
return new Response(null, { status: 404 })
|
||||
},
|
||||
})
|
||||
@@ -53,7 +54,7 @@ describe("acp service", () => {
|
||||
expect(result.configOptions?.map((option) => option.id)).toEqual(["model", "effort", "mode"])
|
||||
expect(requests).toContainEqual({
|
||||
method: "PUT",
|
||||
path: "/api/mcp/docs",
|
||||
path: "/api/experimental/mcp/docs",
|
||||
body: {
|
||||
config: { type: "local", command: ["bun", "docs.ts"], environment: { TOKEN: "x" } },
|
||||
},
|
||||
|
||||
@@ -1250,7 +1250,7 @@ test("ctrl+c dismisses autocomplete and shell mode before exiting", async () =>
|
||||
expect(setup.renderer.isDestroyed).toBe(false)
|
||||
})
|
||||
|
||||
test.each(["manual", "select"] as const)(
|
||||
test.skipIf(process.platform === "win32").each(["manual", "select"] as const)(
|
||||
"selection copy and pane management respect %s mode in the prompt and terminal pane",
|
||||
async (copy) => {
|
||||
const setup = await createTestRenderer({ width: 100, height: 30, useThread: false, kittyKeyboard: true })
|
||||
|
||||
@@ -204,7 +204,7 @@ test("hides account rename and delete actions while the add account row is selec
|
||||
}
|
||||
})
|
||||
|
||||
test("uses the active location for integration data and credential requests", async () => {
|
||||
test("uses the active location for integration data without scoping credential requests", async () => {
|
||||
const location = { directory: "/remote/project" }
|
||||
const fixture = await renderIntegration(location)
|
||||
|
||||
@@ -216,6 +216,7 @@ test("uses the active location for integration data and credential requests", as
|
||||
await fixture.app.waitFor(() => fixture.requests.length === 1)
|
||||
expect(fixture.locations).toContainEqual(location)
|
||||
expect(fixture.locations.at(-1)).toEqual(location)
|
||||
expect(fixture.credentialQueries).toEqual([""])
|
||||
} finally {
|
||||
fixture.app.renderer.destroy()
|
||||
}
|
||||
@@ -225,6 +226,7 @@ async function renderIntegration(activeLocation?: LocationRef) {
|
||||
const events = createEventStream()
|
||||
const requests: Array<{ method: string; path: string; body?: { label: string } }> = []
|
||||
const locations: LocationRef[] = []
|
||||
const credentialQueries: string[] = []
|
||||
const reads = { integration: 0, model: 0, provider: 0 }
|
||||
let accounts = [
|
||||
{ type: "credential" as const, id: "cred_personal", label: "Personal" },
|
||||
@@ -268,7 +270,7 @@ async function renderIntegration(activeLocation?: LocationRef) {
|
||||
}
|
||||
|
||||
if (request.method === "POST" && /^\/api\/credential\/[^/]+\/activate$/.test(url.pathname)) {
|
||||
locations.push(requestedLocation)
|
||||
credentialQueries.push(url.search)
|
||||
const id = url.pathname.split("/")[3]
|
||||
const active = accounts.find((account) => account.id === id)
|
||||
if (!active) throw new Error(`unknown credential: ${id}`)
|
||||
@@ -360,6 +362,7 @@ async function renderIntegration(activeLocation?: LocationRef) {
|
||||
reads,
|
||||
requests,
|
||||
locations,
|
||||
credentialQueries,
|
||||
get accounts() {
|
||||
return accounts
|
||||
},
|
||||
|
||||
@@ -6,7 +6,9 @@ import { Global } from "@opencode/util/global"
|
||||
import { createEventStream, createFetch, directory, json } from "./fixture/tui-client"
|
||||
import { tmpdir } from "./fixture/fixture"
|
||||
|
||||
test.each([80, 120, 180])("session wheel scrolling preserves pane focus at width %s", async (width) => {
|
||||
test
|
||||
.skipIf(process.platform === "win32")
|
||||
.each([80, 120, 180])("session wheel scrolling preserves pane focus at width %s", async (width) => {
|
||||
await using state = await tmpdir()
|
||||
const setup = await createTestRenderer({ width, height: 36, useThread: false, kittyKeyboard: true })
|
||||
setup.renderer.start()
|
||||
|
||||
Reference in New Issue
Block a user