test(server): document child workspace placement overrides

This commit is contained in:
Kit Langton 2026-11-04 14:54:31 -08:00
parent 837e48c4f1
commit ebaf0e7657
4 changed files with 48 additions and 6 deletions

View file

@ -308,7 +308,7 @@ const layer = Layer.effect(
subpath: RelativePath.make(path.relative(project.directory, location.directory).replaceAll("\\", "/")),
title: input.title,
agent: input.agent,
// Placement overrides do not change the inherited host policies.
// Children inherit metadata and permissions even when placed at another location.
metadata: input.metadata ?? parent?.metadata,
permissions: input.permissions ?? parent?.permissions,
model: input.model,

View file

@ -1059,7 +1059,7 @@
}
}
},
"description": "Create a session at the requested location. A parentID creates a linked child session; when location is omitted, the child inherits its parent's location. An explicit location takes precedence. Metadata and permissions still inherit when omitted. List by parentID without a directory filter to include children in other locations.",
"description": "Create a session at the requested location. A parentID creates a linked child session; when location is omitted, the child inherits its parent's full location. An explicit location takes precedence. The public location is directory-only: supplying it selects local placement, even when the directory matches a parent with an internal workspace ID. Metadata and permissions still inherit when omitted. List by parentID without a directory filter to include children in other locations.",
"summary": "Create session",
"requestBody": {
"content": {

View file

@ -180,7 +180,7 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
identifier: "session.create",
summary: "Create session",
description:
"Create a session at the requested location. A parentID creates a linked child session; when location is omitted, the child inherits its parent's location. An explicit location takes precedence. Metadata and permissions still inherit when omitted. List by parentID without a directory filter to include children in other locations.",
"Create a session at the requested location. A parentID creates a linked child session; when location is omitted, the child inherits its parent's full location. An explicit location takes precedence. The public location is directory-only: supplying it selects local placement, even when the directory matches a parent with an internal workspace ID. Metadata and permissions still inherit when omitted. List by parentID without a directory filter to include children in other locations.",
}),
),
)

View file

@ -1,17 +1,59 @@
import { expect } from "bun:test"
import { Session } from "@opencode/schema/session"
import { Session } from "@opencode/core/session"
import { AbsolutePath } from "@opencode/schema/schema"
import { Workspace } from "@opencode/schema/workspace"
import { OpenCode } from "@opencode/client"
import { Effect, Schema } from "effect"
import { Context, Effect, Layer, Schema } from "effect"
import { HttpEffect, HttpRouter, HttpServer } from "effect/http"
import path from "path"
import { it } from "../../core/test/lib/effect"
import { tmpdirScoped } from "../../core/test/fixture/tmpdir"
import { ServerFetch } from "../src/fetch"
import { createEmbeddedRoutes } from "../src/routes"
const SessionResponse = Schema.Struct({ data: Schema.toEncoded(Session.Info) })
const SessionsResponse = Schema.Struct({ data: Schema.Array(Schema.toEncoded(Session.Info)) })
it.live("an explicit HTTP location selects local placement while omission preserves the parent's workspace", () =>
Effect.gen(function* () {
const tmp = yield* tmpdirScoped()
const context = yield* Layer.build(
createEmbeddedRoutes({
app: { version: "test" },
database: { path: ":memory:" },
fs: { filewatcher: false },
}).pipe(Layer.provide(HttpServer.layerServices)),
)
const sessions = Context.get(context, Session.Service)
const handler = Context.get(context, HttpRouter.HttpRouter)
.asHttpEffect()
.pipe(HttpEffect.toWebHandlerWith(context))
const parent = yield* sessions.create({
location: { directory: AbsolutePath.make(tmp.path), workspaceID: Workspace.ID.make("wrk_parent") },
})
const create = (location?: { directory: string }) =>
Effect.promise(async () => {
const response = await handler(
new Request("http://opencode.local/api/session", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ parentID: parent.id, location }),
}),
)
expect(response.status).toBe(200)
return Session.ID.make(Schema.decodeUnknownSync(SessionResponse)(await response.json()).data.id)
})
const inherited = yield* sessions.get(yield* create())
const explicit = yield* sessions.get(yield* create({ directory: `${tmp.path}${path.sep}` }))
expect(inherited.location).toEqual(parent.location)
expect(explicit.location.directory).toBe(parent.location.directory)
expect(explicit.location.workspaceID).toBeUndefined()
}).pipe(Effect.scoped),
)
it.live("creates a child at its parent's location and lists it under the parent", () =>
Effect.gen(function* () {
const tmp = yield* tmpdirScoped()
const handler = yield* ServerFetch.make({
app: { version: "test" },
database: { path: ":memory:" },
@ -29,7 +71,7 @@ it.live("creates a child at its parent's location and lists it under the parent"
expect(response.status).toBe(200)
return Schema.decodeUnknownSync(SessionResponse)(await response.json()).data
})
const parent = yield* create({ title: "Parent" })
const parent = yield* create({ title: "Parent", location: { directory: tmp.path } })
const child = yield* create({ parentID: parent.id, title: "Child" })
const response = yield* Effect.promise(() =>
handler(new Request(`http://opencode.local/api/session?parentID=${parent.id}`)),