| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874 |
- /**
- * End-to-end exerciser for the Effect HttpApi routes.
- *
- * The goal is not to be a normal unit test file. This is a route-coverage harness:
- * every public route should have a small scenario that proves the route decodes
- * requests, uses the right instance context, mutates storage when expected, and
- * returns the expected response shape.
- *
- * The script intentionally isolates `OPENCODE_DB` before importing modules that touch
- * storage. Scenarios may create/delete sessions and reset the database after each run,
- * so this must never point at a developer's real session database.
- *
- * DSL shape:
- * - `http.protected.get/post/...` starts a scenario for one OpenAPI route key.
- * - `.seeded(...)` creates typed per-scenario state using Effect helpers on `ctx`.
- * - `.at(...)` builds the request from that typed state.
- * - `.json(...)` / `.jsonEffect(...)` assert response shape and optional side effects.
- * - `.mutating()` tells the runner to reset isolated state after destructive routes.
- */
- import { Effect } from "effect"
- import { OpenApi } from "effect/unstable/httpapi"
- import { TestLLMServer } from "../../lib/llm-server"
- import path from "path"
- import { array, boolean, check, isRecord, message, object, stable } from "./assertions"
- import { controlledPtyInput, http, route } from "./dsl"
- import {
- cleanupExercisePaths,
- exerciseConfigDirectory,
- exerciseDataDirectory,
- exerciseDatabasePath,
- exerciseGlobalRoot,
- } from "./environment"
- import { color, printHeader, printResults } from "./report"
- import { coverageResult, parseOptions, routeKey, routeKeys, selectedScenarios } from "./routing"
- import { runScenario } from "./runner"
- import { disposeApps } from "./backend"
- import { runtime } from "./runtime"
- import { type Scenario } from "./types"
- function cursor(input: Record<string, unknown>) {
- return Buffer.from(JSON.stringify(input)).toString("base64url")
- }
- function data(validate: (value: any) => void) {
- return (body: any) => {
- object(body)
- validate(body.data)
- }
- }
- function locationData(validate: (value: any) => void) {
- return (body: any) => {
- object(body)
- object(body.location)
- object(body.location.project)
- validate(body.data)
- }
- }
- const scenarios: Scenario[] = [
- http.protected
- .get("/global/health", "global.health")
- .global()
- .json(200, (body) => {
- object(body)
- check(body.healthy === true, "server should report healthy")
- }),
- http.protected
- .get("/global/event", "global.event")
- .global()
- .stream()
- .status(
- 200,
- (_ctx, result) =>
- Effect.sync(() => {
- check(result.contentType.includes("text/event-stream"), "global event should be an SSE stream")
- check(result.text.includes("server.connected"), "global event should emit initial connection event")
- }),
- "status",
- ),
- http.protected.get("/global/config", "global.config.get").global().json(),
- http.protected
- .patch("/global/config", "global.config.update")
- .global()
- .seeded(() =>
- Effect.promise(() =>
- Bun.write(
- path.join(exerciseConfigDirectory, "opencode.jsonc"),
- JSON.stringify({ username: "httpapi-global" }, null, 2),
- ),
- ),
- )
- .at(() => ({ path: "/global/config", body: { username: "httpapi-global" } }))
- .jsonEffect(
- 200,
- (body) =>
- Effect.gen(function* () {
- object(body)
- check(body.username === "httpapi-global", "global config update should return patched config")
- const text = yield* Effect.promise(() =>
- Bun.file(path.join(exerciseConfigDirectory, "opencode.jsonc")).text(),
- )
- check(text.includes('"username": "httpapi-global"'), "global config update should write isolated config file")
- }),
- "status",
- ),
- http.protected
- .post("/global/dispose", "global.dispose")
- .global()
- .mutating()
- .json(
- 200,
- (body) => {
- check(body === true, "global dispose should return true")
- },
- "status",
- ),
- http.protected.get("/path", "path.get").json(200, (body, ctx) => {
- object(body)
- check(body.directory === ctx.directory, "directory should resolve from x-opencode-directory")
- check(body.worktree === ctx.directory, "worktree should resolve from x-opencode-directory")
- }),
- http.protected.get("/vcs", "vcs.get").json(),
- http.protected.get("/vcs/status", "vcs.status").json(200, array),
- http.protected
- .get("/vcs/diff", "vcs.diff")
- .at((ctx) => ({ path: "/vcs/diff?mode=git", headers: ctx.headers() }))
- .json(200, array),
- http.protected.get("/vcs/diff/raw", "vcs.diff.raw").status(
- 200,
- (_ctx, result) =>
- Effect.sync(() => {
- check(typeof result.text === "string", "raw VCS diff should return text")
- }),
- "status",
- ),
- http.protected
- .post("/vcs/apply", "vcs.apply")
- .inProject({ git: false })
- .at((ctx) => ({ path: "/vcs/apply", headers: ctx.headers(), body: { patch: "" } }))
- .status(400, undefined, "status"),
- http.protected.get("/command", "command.list").json(200, array, "status"),
- http.protected.get("/agent", "app.agents").json(200, array, "status"),
- http.protected.get("/skill", "app.skills").json(200, array, "status"),
- http.protected.get("/lsp", "lsp.status").json(200, array),
- http.protected.get("/formatter", "formatter.status").json(200, array),
- http.protected.get("/config", "config.get").json(200, undefined, "status"),
- http.protected
- .patch("/config", "config.update")
- .mutating()
- .at((ctx) => ({ path: "/config", headers: ctx.headers(), body: { username: "httpapi-local" } }))
- .json(
- 200,
- (body) => {
- object(body)
- check(body.username === "httpapi-local", "local config update should return patched config")
- },
- "status",
- ),
- http.protected
- .patch("/config", "config.update.invalid")
- .at((ctx) => ({ path: "/config", headers: ctx.headers(), body: { username: 1 } }))
- .status(400),
- http.protected.get("/config/providers", "config.providers").json(),
- http.protected.get("/project", "project.list").json(200, array, "status"),
- http.protected.get("/project/current", "project.current").json(
- 200,
- (body, ctx) => {
- object(body)
- check(body.worktree === ctx.directory, "current project should resolve from scenario directory")
- },
- "status",
- ),
- http.protected
- .patch("/project/{projectID}", "project.update")
- .mutating()
- .seeded((ctx) => ctx.project())
- .at((ctx) => ({
- path: route("/project/{projectID}", { projectID: ctx.state.id }),
- headers: ctx.headers(),
- body: { name: "HTTP API Project", commands: { start: "bun --version" } },
- }))
- .json(
- 200,
- (body) => {
- object(body)
- check(body.name === "HTTP API Project", "project update should return patched name")
- check(
- isRecord(body.commands) && body.commands.start === "bun --version",
- "project update should return patched command",
- )
- },
- "status",
- ),
- http.protected
- .patch("/project/{projectID}", "project.update.missing")
- .mutating()
- .at((ctx) => ({
- path: route("/project/{projectID}", { projectID: "project_httpapi_missing" }),
- headers: ctx.headers(),
- body: { name: "Missing Project" },
- }))
- .json(404, object, "status"),
- http.protected
- .post("/project/git/init", "project.initGit")
- .mutating()
- .inProject({ git: false })
- .json(
- 200,
- (body, ctx) => {
- object(body)
- check(body.worktree === ctx.directory, "git init should return current project")
- check(body.vcs === "git", "git init should mark the project as git-backed")
- },
- "status",
- ),
- http.protected
- .get("/project/{projectID}/directories", "project.directories")
- .seeded((ctx) => ctx.project())
- .at((ctx) => ({
- path: route("/project/{projectID}/directories", { projectID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .json(200, array, "status"),
- http.protected
- .post("/experimental/project/{projectID}/copy/generate-name", "experimental.projectCopy.generateName")
- .seeded((ctx) => ctx.project())
- .at((ctx) => ({
- path: route("/experimental/project/{projectID}/copy/generate-name", { projectID: ctx.state.id }),
- headers: ctx.headers(),
- body: {},
- }))
- .json(200, (body) => {
- object(body)
- check(typeof body.name === "string" && body.name.length > 0, "generated copy name should be non-empty")
- }),
- http.protected
- .post("/experimental/project/{projectID}/copy", "experimental.projectCopy.create")
- .seeded((ctx) => ctx.project())
- .at((ctx) => ({
- path: route("/experimental/project/{projectID}/copy", { projectID: ctx.state.id }),
- headers: ctx.headers(),
- body: {},
- }))
- .status(400),
- http.protected
- .delete("/experimental/project/{projectID}/copy", "experimental.projectCopy.remove")
- .seeded((ctx) => ctx.project())
- .at((ctx) => ({
- path: route("/experimental/project/{projectID}/copy", { projectID: ctx.state.id }),
- headers: ctx.headers(),
- body: {},
- }))
- .status(400),
- http.protected
- .post("/experimental/project/{projectID}/copy/refresh", "experimental.projectCopy.refresh")
- .mutating()
- .seeded((ctx) => ctx.project())
- .at((ctx) => ({
- path: route("/experimental/project/{projectID}/copy/refresh", { projectID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .status(204, undefined, "status"),
- http.protected.get("/provider", "provider.list").json(),
- http.protected.get("/provider/auth", "provider.auth").json(),
- http.protected
- .post("/provider/{providerID}/oauth/authorize", "provider.oauth.authorize")
- .at((ctx) => ({
- path: route("/provider/{providerID}/oauth/authorize", { providerID: "httpapi" }),
- headers: ctx.headers(),
- body: { method: "bad" },
- }))
- .status(400),
- http.protected
- .post("/provider/{providerID}/oauth/callback", "provider.oauth.callback")
- .at((ctx) => ({
- path: route("/provider/{providerID}/oauth/callback", { providerID: "httpapi" }),
- headers: ctx.headers(),
- body: { method: "bad" },
- }))
- .status(400),
- http.protected.get("/permission", "permission.list").json(200, array),
- http.protected
- .post("/permission/{requestID}/reply", "permission.reply.invalid")
- .at((ctx) => ({
- path: route("/permission/{requestID}/reply", { requestID: "per_httpapi" }),
- headers: ctx.headers(),
- body: { reply: "bad" },
- }))
- .status(400),
- http.protected
- .post("/permission/{requestID}/reply", "permission.reply")
- .at((ctx) => ({
- path: route("/permission/{requestID}/reply", { requestID: "per_httpapi" }),
- headers: ctx.headers(),
- body: { reply: "once" },
- }))
- .json(404, object, "status"),
- http.protected.get("/question", "question.list").json(200, array),
- http.protected
- .post("/question/{requestID}/reply", "question.reply.invalid")
- .at((ctx) => ({
- path: route("/question/{requestID}/reply", { requestID: "que_httpapi_reply" }),
- headers: ctx.headers(),
- body: { answers: "Yes" },
- }))
- .status(400),
- http.protected
- .post("/question/{requestID}/reply", "question.reply")
- .at((ctx) => ({
- path: route("/question/{requestID}/reply", { requestID: "que_httpapi_reply" }),
- headers: ctx.headers(),
- body: { answers: [["Yes"]] },
- }))
- .json(404, object, "status"),
- http.protected
- .post("/question/{requestID}/reject", "question.reject")
- .at((ctx) => ({
- path: route("/question/{requestID}/reject", { requestID: "que_httpapi_reject" }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/file", "file.list")
- .seeded((ctx) => ctx.file("hello.txt", "hello\n"))
- .at((ctx) => ({ path: `/file?${new URLSearchParams({ path: "." })}`, headers: ctx.headers() }))
- .json(200, array),
- http.protected
- .get("/file/content", "file.read")
- .seeded((ctx) => ctx.file("hello.txt", "hello\n"))
- .at((ctx) => ({ path: `/file/content?${new URLSearchParams({ path: "hello.txt" })}`, headers: ctx.headers() }))
- .json(200, (body) => {
- object(body)
- check(body.content === "hello", `content should match seeded file: ${JSON.stringify(body)}`)
- }),
- http.protected
- .get("/file/content", "file.read.missing")
- .at((ctx) => ({ path: `/file/content?${new URLSearchParams({ path: "missing.txt" })}`, headers: ctx.headers() }))
- .json(200, (body) => {
- object(body)
- check(body.type === "text" && body.content === "", "missing file content should return an empty text result")
- }),
- http.protected.get("/file/status", "file.status").json(200, array),
- http.protected
- .get("/find", "find.text")
- .seeded((ctx) => ctx.file("hello.txt", "hello\n"))
- .at((ctx) => ({ path: `/find?${new URLSearchParams({ pattern: "hello" })}`, headers: ctx.headers() }))
- .json(200, array),
- http.protected
- .get("/find/file", "find.files")
- .seeded((ctx) => ctx.file("hello.txt", "hello\n"))
- .at((ctx) => ({
- path: `/find/file?${new URLSearchParams({ query: "hello", dirs: "false" })}`,
- headers: ctx.headers(),
- }))
- .json(200, array),
- http.protected
- .get("/find/symbol", "find.symbols")
- .seeded((ctx) => ctx.file("hello.ts", "export const hello = 1\n"))
- .at((ctx) => ({ path: `/find/symbol?${new URLSearchParams({ query: "hello" })}`, headers: ctx.headers() }))
- .json(200, array),
- http.protected
- .get("/event", "event.stream")
- .stream()
- .status(
- 200,
- (_ctx, result) =>
- Effect.sync(() => {
- check(result.contentType.includes("text/event-stream"), "event should be an SSE stream")
- check(result.text.includes("server.connected"), "event should emit initial connection event")
- }),
- "status",
- ),
- http.protected.get("/mcp", "mcp.status").json(),
- http.protected
- .post("/mcp", "mcp.add")
- .mutating()
- .at((ctx) => ({
- path: "/mcp",
- headers: ctx.headers(),
- body: { name: "httpapi-disabled", config: { type: "local", command: ["bun", "--version"], enabled: false } },
- }))
- .json(
- 200,
- (body) => {
- object(body)
- object(body["httpapi-disabled"])
- check(body["httpapi-disabled"].status === "disabled", "disabled MCP server should be added without spawning")
- },
- "status",
- ),
- http.protected
- .post("/mcp", "mcp.add.invalid")
- .at((ctx) => ({
- path: "/mcp",
- headers: ctx.headers(),
- body: { name: "httpapi-invalid", config: { type: "invalid" } },
- }))
- .status(400),
- http.protected
- .post("/mcp/{name}/auth", "mcp.auth.start")
- .at((ctx) => ({ path: route("/mcp/{name}/auth", { name: "httpapi-missing" }), headers: ctx.headers() }))
- .json(404, object, "status"),
- http.protected
- .delete("/mcp/{name}/auth", "mcp.auth.remove")
- .mutating()
- .at((ctx) => ({ path: route("/mcp/{name}/auth", { name: "httpapi-missing" }), headers: ctx.headers() }))
- .json(404, object, "status"),
- http.protected
- .post("/mcp/{name}/auth/authenticate", "mcp.auth.authenticate")
- .at((ctx) => ({
- path: route("/mcp/{name}/auth/authenticate", { name: "httpapi-missing" }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .post("/mcp/{name}/auth/callback", "mcp.auth.callback")
- .at((ctx) => ({
- path: route("/mcp/{name}/auth/callback", { name: "httpapi-missing" }),
- headers: ctx.headers(),
- body: { code: "code" },
- }))
- .json(404, object, "status"),
- http.protected
- .post("/mcp/{name}/connect", "mcp.connect")
- .mutating()
- .at((ctx) => ({ path: route("/mcp/{name}/connect", { name: "httpapi-missing" }), headers: ctx.headers() }))
- .json(404, object, "status"),
- http.protected
- .post("/mcp/{name}/disconnect", "mcp.disconnect")
- .mutating()
- .at((ctx) => ({ path: route("/mcp/{name}/disconnect", { name: "httpapi-missing" }), headers: ctx.headers() }))
- .json(404, object, "status"),
- http.protected.get("/pty/shells", "pty.shells").json(200, array),
- http.protected.get("/pty", "pty.list").json(200, array),
- http.protected
- .post("/pty", "pty.create")
- .mutating()
- .at((ctx) => ({ path: "/pty", headers: ctx.headers(), body: controlledPtyInput("HTTP API PTY") }))
- .json(
- 200,
- (body, ctx) => {
- object(body)
- check(body.title === "HTTP API PTY", "PTY create should return requested title")
- check(body.command === "/bin/sh", "PTY create should use controlled shell command")
- check(body.cwd === ctx.directory, "PTY create should default cwd to scenario directory")
- },
- "status",
- ),
- http.protected
- .post("/pty", "pty.create.invalid")
- .at((ctx) => ({ path: "/pty", headers: ctx.headers(), body: { command: 1 } }))
- .status(400),
- http.protected
- .post("/pty/{ptyID}/connect-token", "pty.connectToken.invalid")
- .at((ctx) => ({
- path: route("/pty/{ptyID}/connect-token", { ptyID: "pty_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .status(403, undefined, "status"),
- http.protected
- .get("/pty/{ptyID}", "pty.get")
- .at((ctx) => ({ path: route("/pty/{ptyID}", { ptyID: "pty_httpapi_missing" }), headers: ctx.headers() }))
- .status(404),
- http.protected
- .put("/pty/{ptyID}", "pty.update")
- .mutating()
- .at((ctx) => ({
- path: route("/pty/{ptyID}", { ptyID: "pty_httpapi_missing" }),
- headers: ctx.headers(),
- body: { size: { rows: 0, cols: 0 } },
- }))
- .status(400),
- http.protected
- .delete("/pty/{ptyID}", "pty.remove")
- .mutating()
- .at((ctx) => ({ path: route("/pty/{ptyID}", { ptyID: "pty_httpapi_missing" }), headers: ctx.headers() }))
- .json(404, object, "status"),
- http.protected
- .get("/pty/{ptyID}/connect", "pty.connect")
- .at((ctx) => ({ path: route("/pty/{ptyID}/connect", { ptyID: "pty_httpapi_missing" }), headers: ctx.headers() }))
- .status(404, undefined, "none"),
- http.protected.get("/experimental/console", "experimental.console.get").json(),
- http.protected.get("/experimental/console/orgs", "experimental.console.listOrgs").json(),
- http.protected
- .post("/experimental/console/switch", "experimental.console.switchOrg")
- .at((ctx) => ({
- path: "/experimental/console/switch",
- headers: ctx.headers(),
- body: { accountID: "httpapi-account", orgID: "httpapi-org" },
- }))
- .status(400, undefined, "none"),
- http.protected.get("/experimental/workspace/adapter", "experimental.workspace.adapter.list").json(200, array),
- http.protected.get("/experimental/workspace", "experimental.workspace.list").json(200, array),
- http.protected.get("/experimental/workspace/status", "experimental.workspace.status").json(200, array),
- http.protected
- .post("/experimental/workspace", "experimental.workspace.create")
- .at((ctx) => ({ path: "/experimental/workspace", headers: ctx.headers(), body: {} }))
- .status(400),
- http.protected
- .post("/experimental/workspace/sync-list", "experimental.workspace.syncList")
- .status(204, undefined, "status"),
- http.protected
- .delete("/experimental/workspace/{id}", "experimental.workspace.remove")
- .mutating()
- .at((ctx) => ({
- path: route("/experimental/workspace/{id}", { id: "wrk_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .status(200),
- http.protected
- .post("/experimental/workspace/warp", "experimental.workspace.warp")
- .at((ctx) => ({
- path: "/experimental/workspace/warp",
- headers: ctx.headers(),
- body: {},
- }))
- .status(400),
- http.protected
- .post("/experimental/control-plane/move-session", "experimental.controlPlane.moveSession")
- .global()
- .at(() => ({
- path: "/experimental/control-plane/move-session",
- body: {},
- }))
- .status(400),
- http.protected
- .get("/experimental/tool", "tool.list")
- .at((ctx) => ({
- path: `/experimental/tool?${new URLSearchParams({ provider: "opencode", model: "test" })}`,
- headers: ctx.headers(),
- }))
- .json(200, array, "status"),
- http.protected.get("/experimental/tool/ids", "tool.ids").json(200, array),
- http.protected.get("/experimental/worktree", "worktree.list").json(200, array),
- http.protected
- .post("/experimental/worktree", "worktree.create")
- .mutating()
- .at((ctx) => ({ path: "/experimental/worktree", headers: ctx.headers(), body: { name: "api-dsl" } }))
- .jsonEffect(
- 200,
- (body, ctx) =>
- Effect.gen(function* () {
- object(body)
- check(typeof body.directory === "string", "created worktree should include directory")
- yield* ctx.worktreeRemove(body.directory)
- }),
- "status",
- ),
- http.protected
- .post("/experimental/worktree", "worktree.create.invalid")
- .at((ctx) => ({ path: "/experimental/worktree", headers: ctx.headers(), body: { name: 1 } }))
- .status(400),
- http.protected
- .delete("/experimental/worktree", "worktree.remove")
- .mutating()
- .seeded((ctx) => ctx.worktree({ name: "api-remove" }))
- .at((ctx) => ({ path: "/experimental/worktree", headers: ctx.headers(), body: { directory: ctx.state.directory } }))
- .json(200, (body) => {
- check(body === true, "worktree remove should return true")
- }),
- http.protected
- .post("/experimental/worktree/reset", "worktree.reset")
- .mutating()
- .seeded((ctx) => ctx.worktree({ name: "api-reset" }))
- .at((ctx) => ({
- path: "/experimental/worktree/reset",
- headers: ctx.headers(),
- body: { directory: ctx.state.directory },
- }))
- .jsonEffect(200, (body, ctx) =>
- Effect.gen(function* () {
- check(body === true, "worktree reset should return true")
- yield* ctx.worktreeRemove(ctx.state.directory)
- }),
- ),
- http.protected
- .get("/experimental/session", "experimental.session.list")
- .at((ctx) => ({ path: "/experimental/session?roots=false&archived=false", headers: ctx.headers() }))
- .json(200, array),
- http.protected.get("/experimental/capabilities", "experimental.capabilities.get").json(200, (body) => {
- check(
- typeof body === "object" && body !== null && "backgroundSubagents" in body && body.backgroundSubagents === true,
- "capabilities should report background subagents as available",
- )
- }),
- http.protected
- .post("/experimental/session/{sessionID}/background", "experimental.session.background")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Background route owner" }))
- .at((ctx) => ({
- path: route("/experimental/session/{sessionID}/background", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .json(200, (body) => {
- check(body === false, "background route should be a no-op without running subagents")
- }),
- http.protected.get("/experimental/resource", "experimental.resource.list").json(),
- http.protected
- .post("/sync/history", "sync.history.list")
- .at((ctx) => ({ path: "/sync/history", headers: ctx.headers(), body: {} }))
- .json(200, array),
- http.protected
- .post("/sync/replay", "sync.replay")
- .at((ctx) => ({ path: "/sync/replay", headers: ctx.headers(), body: { directory: ctx.directory, events: [] } }))
- .status(400),
- http.protected
- .post("/sync/steal", "sync.steal.invalid")
- .at((ctx) => ({ path: "/sync/steal", headers: ctx.headers(), body: {} }))
- .status(400, undefined, "status"),
- http.protected
- .post("/sync/start", "sync.start")
- .mutating()
- .preserveDatabase()
- .json(200, (body) => {
- check(body === true, "sync start should return true when no workspace sessions exist")
- }),
- http.protected
- .post("/instance/dispose", "instance.dispose")
- .mutating()
- .json(200, (body) => {
- check(body === true, "instance dispose should return true")
- }),
- http.protected
- .post("/log", "app.log")
- .global()
- .at(() => ({ path: "/log", body: { service: "httpapi-exercise", level: "info", message: "route coverage" } }))
- .json(200, (body) => {
- check(body === true, "log route should return true")
- }),
- http.protected
- .put("/auth/{providerID}", "auth.set")
- .global()
- .at(() => ({ path: route("/auth/{providerID}", { providerID: "test" }), body: { type: "api", key: "test-key" } }))
- .jsonEffect(200, (body) =>
- Effect.gen(function* () {
- check(body === true, "auth set should return true")
- const auth = yield* Effect.promise(() => Bun.file(path.join(exerciseDataDirectory, "auth.json")).json())
- object(auth)
- check(isRecord(auth.test) && auth.test.key === "test-key", "auth set should write isolated auth file")
- }),
- ),
- http.protected
- .delete("/auth/{providerID}", "auth.remove")
- .global()
- .seeded(() =>
- Effect.promise(() =>
- Bun.write(
- path.join(exerciseDataDirectory, "auth.json"),
- JSON.stringify({ test: { type: "api", key: "remove-me" } }),
- ),
- ),
- )
- .at(() => ({ path: route("/auth/{providerID}", { providerID: "test" }) }))
- .jsonEffect(200, (body) =>
- Effect.gen(function* () {
- check(body === true, "auth remove should return true")
- const auth = yield* Effect.promise(() => Bun.file(path.join(exerciseDataDirectory, "auth.json")).json())
- object(auth)
- check(auth.test === undefined, "auth remove should delete provider from isolated auth file")
- }),
- ),
- http.protected.get("/api/health", "v2.health.get").json(200, (body) => {
- object(body)
- check(body.healthy === true, "v2 server should report healthy")
- }),
- http.protected.get("/api/location", "v2.location.get").json(200, object),
- http.protected.get("/api/agent", "v2.agent.list").json(200, locationData(array)),
- http.protected.get("/api/model", "v2.model.list").json(200, locationData(array)),
- // The default model may be undefined in the exercise environment, so only the location envelope is asserted.
- http.protected.get("/api/model/default", "v2.model.default").json(200, object),
- http.protected.get("/api/provider", "v2.provider.list").json(200, locationData(array)),
- http.protected.get("/api/integration", "v2.integration.list").json(200, locationData(array)),
- http.protected
- .get("/api/integration/{integrationID}", "v2.integration.get")
- .at((ctx) => ({
- path: route("/api/integration/{integrationID}", { integrationID: "missing" }),
- headers: ctx.headers(),
- }))
- .json(200, object),
- http.protected
- .post("/api/integration/{integrationID}/connect/key", "v2.integration.connect.key")
- .at((ctx) => ({
- path: route("/api/integration/{integrationID}/connect/key", { integrationID: "missing" }),
- headers: ctx.headers(),
- body: { key: "test" },
- }))
- .status(500, undefined, "status"),
- http.protected
- .post("/api/integration/{integrationID}/connect/oauth", "v2.integration.connect.oauth")
- .at((ctx) => ({
- path: route("/api/integration/{integrationID}/connect/oauth", { integrationID: "missing" }),
- headers: ctx.headers(),
- body: { methodID: "missing", inputs: {} },
- }))
- .status(500, undefined, "status"),
- http.protected
- .get("/api/integration/attempt/{attemptID}", "v2.integration.attempt.status")
- .at((ctx) => ({
- path: route("/api/integration/attempt/{attemptID}", { attemptID: "con_missing" }),
- headers: ctx.headers(),
- }))
- .status(500, undefined, "status"),
- http.protected
- .post("/api/integration/attempt/{attemptID}/complete", "v2.integration.attempt.complete")
- .at((ctx) => ({
- path: route("/api/integration/attempt/{attemptID}/complete", { attemptID: "con_missing" }),
- headers: ctx.headers(),
- body: {},
- }))
- .status(500, undefined, "status"),
- http.protected
- .delete("/api/integration/attempt/{attemptID}", "v2.integration.attempt.cancel")
- .at((ctx) => ({
- path: route("/api/integration/attempt/{attemptID}", { attemptID: "con_missing" }),
- headers: ctx.headers(),
- }))
- .status(204, undefined, "status"),
- http.protected
- .delete("/api/credential/{credentialID}", "v2.credential.remove")
- .at((ctx) => ({
- path: route("/api/credential/{credentialID}", { credentialID: "cred_missing" }),
- headers: ctx.headers(),
- }))
- .status(204, undefined, "status"),
- http.protected
- .patch("/api/credential/{credentialID}", "v2.credential.update")
- .at((ctx) => ({
- path: route("/api/credential/{credentialID}", { credentialID: "cred_missing" }),
- headers: ctx.headers(),
- body: { label: "Work" },
- }))
- .status(204, undefined, "status"),
- http.protected.get("/api/command", "v2.command.list").json(200, locationData(array)),
- http.protected.get("/api/skill", "v2.skill.list").json(200, locationData(array)),
- http.protected
- .get("/api/event", "v2.event.subscribe")
- .stream()
- .status(
- 200,
- (_ctx, result) =>
- Effect.sync(() => {
- check(result.contentType.includes("text/event-stream"), "v2 event should be an SSE stream")
- check(result.text.includes("server.connected"), "v2 event should emit initial connection event")
- check(!result.text.includes('"location"'), "v2 connection event should not be scoped to a location")
- }),
- "status",
- ),
- http.protected
- .get("/api/fs/read/*", "v2.fs.read")
- .seeded((ctx) => ctx.file("hello.txt", "hello\n"))
- .at((ctx) => ({ path: "/api/fs/read/hello.txt", headers: ctx.headers() }))
- .status(
- 200,
- (_ctx, result) =>
- Effect.sync(() => {
- check(result.text === "hello\n", "v2 fs read should return the file body")
- check(result.contentType.includes("text/plain"), "v2 fs read should return the file content type")
- }),
- "status",
- ),
- http.protected.get("/api/fs/list", "v2.fs.list").json(200, locationData(array)),
- http.protected
- .get("/api/fs/find", "v2.fs.find")
- .seeded((ctx) => ctx.file("hello.txt", "hello\n"))
- .at((ctx) => ({ path: "/api/fs/find?query=hello&type=file", headers: ctx.headers() }))
- .json(200, locationData(array)),
- http.protected.get("/api/pty", "v2.pty.list").json(200, locationData(array)),
- http.protected
- .post("/api/pty", "v2.pty.create")
- .mutating()
- .at((ctx) => ({ path: "/api/pty", headers: ctx.headers(), body: controlledPtyInput("HTTP API V2 PTY") }))
- .json(200, locationData(object)),
- http.protected
- .get("/api/pty/{ptyID}", "v2.pty.get")
- .at((ctx) => ({ path: route("/api/pty/{ptyID}", { ptyID: "pty_httpapi_missing" }), headers: ctx.headers() }))
- .json(404, object, "status"),
- http.protected
- .put("/api/pty/{ptyID}", "v2.pty.update")
- .mutating()
- .at((ctx) => ({
- path: route("/api/pty/{ptyID}", { ptyID: "pty_httpapi_missing" }),
- headers: ctx.headers(),
- body: { title: "missing" },
- }))
- .json(404, object, "status"),
- http.protected
- .delete("/api/pty/{ptyID}", "v2.pty.remove")
- .mutating()
- .at((ctx) => ({ path: route("/api/pty/{ptyID}", { ptyID: "pty_httpapi_missing" }), headers: ctx.headers() }))
- .json(404, object, "status"),
- http.protected
- .post("/api/pty/{ptyID}/connect-token", "v2.pty.connectToken")
- .at((ctx) => ({
- path: route("/api/pty/{ptyID}/connect-token", { ptyID: "pty_httpapi_missing" }),
- headers: { ...ctx.headers(), "x-opencode-ticket": "1" },
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/pty/{ptyID}/connect", "v2.pty.connect")
- .at((ctx) => ({
- path: route("/api/pty/{ptyID}/connect", { ptyID: "pty_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .status(404, undefined, "none"),
- http.protected.get("/api/reference", "v2.reference.list").json(200, object),
- http.protected
- .get("/api/provider/{providerID}", "v2.provider.get")
- .at((ctx) => ({ path: route("/api/provider/{providerID}", { providerID: "missing" }), headers: ctx.headers() }))
- .json(404, object, "status"),
- http.protected.get("/api/permission/request", "v2.permission.request.list").json(200, (body) => {
- object(body)
- object(body.location)
- array(body.data)
- }),
- http.protected.get("/api/question/request", "v2.question.request.list").json(200, (body) => {
- object(body)
- object(body.location)
- array(body.data)
- }),
- http.protected.get("/api/form/request", "v2.form.request.list").json(200, (body) => {
- object(body)
- object(body.location)
- array(body.data)
- }),
- http.protected
- .get("/api/session/{sessionID}/form", "v2.session.form.list")
- .seeded((ctx) => ctx.session({ title: "Form list owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/form", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .json(200, data(array)),
- http.protected
- .post("/api/session/{sessionID}/form", "v2.session.form.create")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Form create owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/form", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: {
- title: "External form",
- fields: [{ key: "authorization", type: "external", url: "https://example.com/form" }],
- },
- }))
- .json(200, (body) => {
- object(body)
- object(body.data)
- check(typeof body.data.id === "string", "form create should return an ID")
- array(body.data.fields)
- object(body.data.fields[0])
- check(body.data.fields[0].type === "external", "form create should preserve the external field")
- }),
- http.protected
- .get("/api/session/{sessionID}/form/{formID}", "v2.session.form.get")
- .seeded((ctx) => ctx.session({ title: "Form get owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/form/{formID}", { sessionID: ctx.state.id, formID: "frm_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/form/{formID}/state", "v2.session.form.state")
- .seeded((ctx) => ctx.session({ title: "Form state owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/form/{formID}/state", {
- sessionID: ctx.state.id,
- formID: "frm_httpapi_missing",
- }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .post("/api/session/{sessionID}/form/{formID}/reply", "v2.session.form.reply")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Form reply owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/form/{formID}/reply", {
- sessionID: ctx.state.id,
- formID: "frm_httpapi_missing",
- }),
- headers: ctx.headers(),
- body: { answer: {} },
- }))
- .json(404, object, "status"),
- http.protected
- .post("/api/session/{sessionID}/form/{formID}/cancel", "v2.session.form.cancel")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Form cancel owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/form/{formID}/cancel", {
- sessionID: ctx.state.id,
- formID: "frm_httpapi_missing",
- }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .post("/api/session/{sessionID}/permission", "v2.session.permission.create")
- .seeded((ctx) => ctx.session({ title: "Permission create owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/permission", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: { action: "read", resources: [".env"] },
- }))
- .json(200, (body) => {
- object(body)
- object(body.data)
- check(typeof body.data.id === "string", "permission create should return an ID")
- check(body.data.effect === "ask", "permission create should create a pending request")
- }),
- http.protected
- .get("/api/session/{sessionID}/permission", "v2.session.permission.list")
- .seeded((ctx) => ctx.session({ title: "Permission list owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/permission", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .json(200, data(array)),
- http.protected
- .get("/api/session/{sessionID}/permission/{requestID}", "v2.session.permission.get")
- .seeded((ctx) => ctx.session({ title: "Permission get owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/permission/{requestID}", {
- sessionID: ctx.state.id,
- requestID: "per_httpapi_missing",
- }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/question", "v2.session.question.list")
- .seeded((ctx) => ctx.session({ title: "Question list owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/question", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .json(200, data(array)),
- http.protected
- .post("/api/session/{sessionID}/permission/{requestID}/reply", "v2.session.permission.reply")
- .seeded((ctx) => ctx.session({ title: "Permission owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/permission/{requestID}/reply", {
- sessionID: ctx.state.id,
- requestID: "per_httpapi_missing",
- }),
- headers: ctx.headers(),
- body: { reply: "once" },
- }))
- .json(404, object, "status"),
- http.protected
- .post("/api/session/{sessionID}/question/{requestID}/reply", "v2.session.question.reply")
- .seeded((ctx) => ctx.session({ title: "Question reply owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/question/{requestID}/reply", {
- sessionID: ctx.state.id,
- requestID: "que_httpapi_missing",
- }),
- headers: ctx.headers(),
- body: { answers: [] },
- }))
- .json(404, object, "status"),
- http.protected
- .post("/api/session/{sessionID}/question/{requestID}/reject", "v2.session.question.reject")
- .seeded((ctx) => ctx.session({ title: "Question reject owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/question/{requestID}/reject", {
- sessionID: ctx.state.id,
- requestID: "que_httpapi_missing",
- }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected.get("/api/permission/saved", "v2.permission.saved.list").json(200, (body) => {
- object(body)
- array(body.data)
- }),
- http.protected
- .delete("/api/permission/saved/{id}", "v2.permission.saved.remove")
- .at((ctx) => ({ path: route("/api/permission/saved/{id}", { id: "psv_httpapi_missing" }), headers: ctx.headers() }))
- .status(204, undefined, "status"),
- http.protected
- .get("/api/session", "v2.session.list")
- .at((ctx) => ({ path: "/api/session?roots=true", headers: ctx.headers() }))
- .json(
- 200,
- (body) => {
- object(body)
- array(body.data)
- object(body.cursor)
- },
- "none",
- ),
- http.protected
- .get("/api/session", "v2.session.list.filters")
- .at((ctx) => ({
- path: `/api/session?${new URLSearchParams({
- limit: "2",
- order: "asc",
- path: ".",
- roots: "false",
- start: "0",
- search: "missing",
- directory: ctx.directory ?? "",
- })}`,
- headers: ctx.headers(),
- }))
- .json(
- 200,
- (body) => {
- object(body)
- array(body.data)
- object(body.cursor)
- },
- "none",
- ),
- http.protected
- .get("/api/session", "v2.session.list.cursor")
- .at((ctx) => ({
- path: `/api/session?${new URLSearchParams({
- limit: "2",
- cursor: cursor({
- order: "desc",
- directory: ctx.directory,
- anchor: { id: "ses_httpapi_missing", time: 0, direction: "next" },
- }),
- })}`,
- headers: ctx.headers(),
- }))
- .json(
- 200,
- (body) => {
- object(body)
- array(body.data)
- object(body.cursor)
- },
- "none",
- ),
- http.protected
- .get("/api/session", "v2.session.list.cursor.invalid")
- .at((ctx) => ({
- path: `/api/session?${new URLSearchParams({
- cursor: "invalid",
- })}`,
- headers: ctx.headers(),
- }))
- .status(400, undefined, "none"),
- http.protected.get("/api/session/active", "v2.session.active").json(200, data(object), "none"),
- http.protected
- .post("/api/session", "v2.session.create")
- .at((ctx) => ({
- path: "/api/session",
- headers: { ...ctx.headers(), "content-type": "application/json" },
- body: {},
- }))
- .json(200, data(object)),
- http.protected
- .get("/api/session/{sessionID}", "v2.session.get")
- .seeded((ctx) => ctx.session({ title: "Session get" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .json(200, data(object)),
- http.protected
- .post("/api/session/{sessionID}/agent", "v2.session.switchAgent")
- .seeded((ctx) => ctx.session({ title: "Switch agent" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/agent", { sessionID: ctx.state.id }),
- headers: { ...ctx.headers(), "content-type": "application/json" },
- body: { agent: "plan" },
- }))
- .status(204, undefined, "none"),
- http.protected
- .post("/api/session/{sessionID}/model", "v2.session.switchModel")
- .seeded((ctx) => ctx.session({ title: "Switch model" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/model", { sessionID: ctx.state.id }),
- headers: { ...ctx.headers(), "content-type": "application/json" },
- body: { model: { providerID: "opencode", id: "big-pickle" } },
- }))
- .status(204, undefined, "none"),
- http.protected
- .get("/api/session/{sessionID}/context", "v2.session.context")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/context", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/pending", "v2.session.pending.list")
- .seeded((ctx) => ctx.session({ title: "Pending list owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/pending", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .json(200, data(array)),
- http.protected
- .post("/api/session/{sessionID}/revert/stage", "v2.session.revert.stage")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/revert/stage", { sessionID: "ses_httpapi_missing" }),
- headers: { ...ctx.headers(), "content-type": "application/json" },
- body: { messageID: "msg_httpapi_missing" },
- }))
- .json(404, object, "status"),
- http.protected
- .post("/api/session/{sessionID}/revert/clear", "v2.session.revert.clear")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/revert/clear", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .post("/api/session/{sessionID}/revert/commit", "v2.session.revert.commit")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/revert/commit", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/message", "v2.session.messages")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/message", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/message", "v2.session.messages.params")
- .at((ctx) => ({
- path: `${route("/api/session/{sessionID}/message", { sessionID: "ses_httpapi_missing" })}?${new URLSearchParams({
- limit: "2",
- order: "asc",
- })}`,
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/message", "v2.session.messages.cursor")
- .at((ctx) => ({
- path: `${route("/api/session/{sessionID}/message", { sessionID: "ses_httpapi_missing" })}?${new URLSearchParams({
- limit: "2",
- directory: ctx.directory ?? "",
- cursor: cursor({ id: "msg_httpapi_missing", time: 0, order: "desc", direction: "next" }),
- })}`,
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/message", "v2.session.messages.cursor.invalid")
- .seeded((ctx) => ctx.session({ title: "Invalid message cursor owner" }))
- .at((ctx) => ({
- path: `${route("/api/session/{sessionID}/message", { sessionID: ctx.state.id })}?${new URLSearchParams({
- cursor: cursor({ id: "msg_httpapi_missing", time: 0, order: "desc", direction: "next" }),
- order: "asc",
- })}`,
- headers: ctx.headers(),
- }))
- .status(400, undefined, "none"),
- http.protected
- .get("/api/session/{sessionID}/history", "v2.session.history")
- .seeded((ctx) => ctx.session({ title: "Session history" }))
- .at((ctx) => ({
- path: `${route("/api/session/{sessionID}/history", { sessionID: ctx.state.id })}?${new URLSearchParams({
- after: "0",
- limit: "2",
- })}`,
- headers: ctx.headers(),
- }))
- .json(
- 200,
- (body) => {
- object(body)
- array(body.data)
- check(typeof body.hasMore === "boolean", "Expected a history exhaustion signal")
- },
- "none",
- ),
- http.protected
- .get("/api/session/{sessionID}/history", "v2.session.history.missing")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/history", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/history", "v2.session.history.invalid")
- .seeded((ctx) => ctx.session({ title: "Invalid history sequence" }))
- .at((ctx) => ({
- path: `${route("/api/session/{sessionID}/history", { sessionID: ctx.state.id })}?after=-1`,
- headers: ctx.headers(),
- }))
- .json(400, object, "status"),
- http.protected
- .get("/api/session/{sessionID}/event", "v2.session.events.missing")
- .at((ctx) => ({
- path: `${route("/api/session/{sessionID}/event", { sessionID: "ses_httpapi_missing" })}?after=0`,
- headers: ctx.headers(),
- }))
- .status(404, undefined, "status"),
- http.protected
- .post("/api/session/{sessionID}/interrupt", "v2.session.interrupt")
- .seeded((ctx) => ctx.session({ title: "Interrupt session" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/interrupt", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .status(204, undefined, "none"),
- http.protected
- .get("/api/session/{sessionID}/message/{messageID}", "v2.session.message.missing")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/message/{messageID}", {
- sessionID: "ses_httpapi_missing",
- messageID: "msg_httpapi_missing",
- }),
- headers: ctx.headers(),
- }))
- .json(404, object, "status"),
- http.protected
- .post("/api/session/{sessionID}/prompt", "v2.session.prompt.invalid")
- .seeded((ctx) => ctx.session({ title: "Invalid prompt owner" }))
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/prompt", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: {},
- }))
- .status(400, undefined, "none"),
- http.protected
- .post("/api/session/{sessionID}/compact", "v2.session.compact")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/compact", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .status(404, undefined, "status"),
- http.protected
- .post("/api/session/{sessionID}/wait", "v2.session.wait")
- .at((ctx) => ({
- path: route("/api/session/{sessionID}/wait", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .status(404, undefined, "status"),
- http.protected
- .get("/session", "session.list")
- .seeded((ctx) => ctx.session({ title: "List me" }))
- .at((ctx) => ({ path: "/session?roots=true", headers: ctx.headers() }))
- .json(200, (body, ctx) => {
- array(body)
- check(
- body.some((item) => isRecord(item) && item.id === ctx.state.id && item.title === "List me"),
- "seeded session should be listed",
- )
- }),
- http.protected
- .get("/session/status", "session.status")
- .seeded((ctx) => ctx.session({ title: "Status session" }))
- .json(200, object),
- http.protected
- .post("/session", "session.create")
- .mutating()
- .at((ctx) => ({ path: "/session", headers: ctx.headers(), body: { title: "Created session" } }))
- .json(
- 200,
- (body, ctx) => {
- object(body)
- check(body.title === "Created session", "created session should use requested title")
- check(body.directory === ctx.directory, "created session should use scenario directory")
- },
- "status",
- ),
- http.protected
- .get("/session/{sessionID}", "session.get")
- .seeded((ctx) => ctx.session({ title: "Get me" }))
- .at((ctx) => ({ path: route("/session/{sessionID}", { sessionID: ctx.state.id }), headers: ctx.headers() }))
- .json(200, (body, ctx) => {
- object(body)
- check(body.id === ctx.state.id, "should return requested session")
- check(body.title === "Get me", "should preserve seeded title")
- }),
- http.protected
- .get("/session/{sessionID}", "session.get.missing")
- .at((ctx) => ({
- path: route("/session/{sessionID}", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .status(404),
- http.protected
- .patch("/session/{sessionID}", "session.update")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Before rename" }))
- .at((ctx) => ({
- path: route("/session/{sessionID}", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: { title: "After rename" },
- }))
- .json(
- 200,
- (body) => {
- object(body)
- check(body.title === "After rename", "updated session should use new title")
- },
- "status",
- ),
- http.protected
- .patch("/session/{sessionID}", "session.update.invalid")
- .mutating()
- .at((ctx) => ({
- path: route("/session/{sessionID}", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- body: { title: 1 },
- }))
- .status(400),
- http.protected
- .delete("/session/{sessionID}", "session.delete")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Delete me" }))
- .at((ctx) => ({ path: route("/session/{sessionID}", { sessionID: ctx.state.id }), headers: ctx.headers() }))
- .jsonEffect(200, (body, ctx) =>
- Effect.gen(function* () {
- check(body === true, "delete should return true")
- check((yield* ctx.sessionGet(ctx.state.id)) === undefined, "deleted session should not remain in storage")
- }),
- ),
- http.protected
- .get("/session/{sessionID}/children", "session.children")
- .seeded((ctx) =>
- Effect.gen(function* () {
- const parent = yield* ctx.session({ title: "Parent" })
- const child = yield* ctx.session({ title: "Child", parentID: parent.id })
- return { parent, child }
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/children", { sessionID: ctx.state.parent.id }),
- headers: ctx.headers(),
- }))
- .json(200, (body, ctx) => {
- array(body)
- check(
- body.some((item) => isRecord(item) && item.id === ctx.state.child.id && item.parentID === ctx.state.parent.id),
- "children should include seeded child",
- )
- }),
- http.protected
- .get("/session/{sessionID}/diff", "session.diff")
- .seeded((ctx) => ctx.session({ title: "Diff session" }))
- .at((ctx) => ({ path: route("/session/{sessionID}/diff", { sessionID: ctx.state.id }), headers: ctx.headers() }))
- .json(200, array),
- http.protected
- .get("/session/{sessionID}/message", "session.messages")
- .seeded((ctx) => ctx.session({ title: "Messages session" }))
- .at((ctx) => ({ path: route("/session/{sessionID}/message", { sessionID: ctx.state.id }), headers: ctx.headers() }))
- .json(200, (body) => {
- array(body)
- check(body.length === 0, "new session should have no messages")
- }),
- http.protected
- .get("/session/{sessionID}/message/{messageID}", "session.message")
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Message get session" })
- const message = yield* ctx.message(session.id, { text: "read me" })
- return { session, message }
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/message/{messageID}", {
- sessionID: ctx.state.session.id,
- messageID: ctx.state.message.info.id,
- }),
- headers: ctx.headers(),
- }))
- .json(200, (body, ctx) => {
- object(body)
- check(isRecord(body.info) && body.info.id === ctx.state.message.info.id, "should return requested message")
- check(
- Array.isArray(body.parts) && body.parts.some((part) => isRecord(part) && part.id === ctx.state.message.part.id),
- "message should include seeded part",
- )
- }),
- http.protected
- .patch("/session/{sessionID}/message/{messageID}/part/{partID}", "part.update")
- .mutating()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Part update session" })
- const message = yield* ctx.message(session.id, { text: "before" })
- return { session, message }
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/message/{messageID}/part/{partID}", {
- sessionID: ctx.state.session.id,
- messageID: ctx.state.message.info.id,
- partID: ctx.state.message.part.id,
- }),
- headers: ctx.headers(),
- body: { ...ctx.state.message.part, text: "after" },
- }))
- .json(
- 200,
- (body) => {
- object(body)
- check(body.type === "text" && body.text === "after", "updated part should be returned")
- },
- "status",
- ),
- http.protected
- .delete("/session/{sessionID}/message/{messageID}/part/{partID}", "part.delete")
- .mutating()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Part delete session" })
- const message = yield* ctx.message(session.id, { text: "delete part" })
- return { session, message }
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/message/{messageID}/part/{partID}", {
- sessionID: ctx.state.session.id,
- messageID: ctx.state.message.info.id,
- partID: ctx.state.message.part.id,
- }),
- headers: ctx.headers(),
- }))
- .jsonEffect(200, (body, ctx) =>
- Effect.gen(function* () {
- check(body === true, "delete part should return true")
- const messages = yield* ctx.messages(ctx.state.session.id)
- check(messages[0]?.parts.length === 0, "deleted part should not remain on message")
- }),
- ),
- http.protected
- .delete("/session/{sessionID}/message/{messageID}", "session.deleteMessage")
- .mutating()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Message delete session" })
- const message = yield* ctx.message(session.id, { text: "delete message" })
- return { session, message }
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/message/{messageID}", {
- sessionID: ctx.state.session.id,
- messageID: ctx.state.message.info.id,
- }),
- headers: ctx.headers(),
- }))
- .jsonEffect(200, (body, ctx) =>
- Effect.gen(function* () {
- check(body === true, "delete message should return true")
- check((yield* ctx.messages(ctx.state.session.id)).length === 0, "deleted message should not remain")
- }),
- ),
- http.protected
- .post("/session/{sessionID}/fork", "session.fork")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Fork source" }))
- .at((ctx) => ({
- path: route("/session/{sessionID}/fork", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: {},
- }))
- .json(
- 200,
- (body) => {
- object(body)
- check(typeof body.id === "string", "fork should return a session")
- },
- "status",
- ),
- http.protected
- .post("/session/{sessionID}/abort", "session.abort")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Abort session" }))
- .at((ctx) => ({ path: route("/session/{sessionID}/abort", { sessionID: ctx.state.id }), headers: ctx.headers() }))
- .json(200, (body) => {
- check(body === true, "abort should return true")
- }),
- http.protected
- .post("/session/{sessionID}/abort", "session.abort.missing")
- .at((ctx) => ({
- path: route("/session/{sessionID}/abort", { sessionID: "ses_httpapi_missing" }),
- headers: ctx.headers(),
- }))
- .json(200, (body) => {
- check(body === true, "missing session abort should remain a no-op success")
- }),
- http.protected
- .post("/session/{sessionID}/init", "session.init")
- .preserveDatabase()
- .withLlm()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Init session" })
- const message = yield* ctx.message(session.id, { text: "initialize" })
- yield* ctx.llmText("initialized")
- yield* ctx.llmText("initialized")
- return { session, message }
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/init", { sessionID: ctx.state.session.id }),
- headers: ctx.headers(),
- body: { providerID: "test", modelID: "test-model", messageID: ctx.state.message.info.id },
- }))
- .jsonEffect(200, (body, ctx) =>
- Effect.gen(function* () {
- check(body === true, "init should return true")
- yield* ctx.llmWait(1)
- }),
- ),
- http.protected
- .post("/session/{sessionID}/message", "session.prompt")
- .preserveDatabase()
- .withLlm()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "LLM prompt session" })
- yield* ctx.llmText("fake assistant")
- yield* ctx.llmText("fake assistant")
- return session
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/message", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: {
- agent: "build",
- model: { providerID: "test", modelID: "test-model" },
- parts: [{ type: "text", text: "hello llm" }],
- },
- }))
- .jsonEffect(
- 200,
- (body, ctx) =>
- Effect.gen(function* () {
- object(body)
- check(isRecord(body.info) && body.info.role === "assistant", "prompt should return assistant message")
- check(
- Array.isArray(body.parts) && body.parts.some((part) => isRecord(part) && part.text === "fake assistant"),
- "assistant message should use fake LLM text",
- )
- yield* ctx.llmWait(1)
- }),
- "status",
- ),
- http.protected
- .post("/session/{sessionID}/prompt_async", "session.prompt_async")
- .preserveDatabase()
- .withLlm()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Async prompt session" })
- yield* ctx.llmText("fake async assistant")
- yield* ctx.llmText("fake async assistant")
- return session
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/prompt_async", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: {
- agent: "build",
- model: { providerID: "test", modelID: "test-model" },
- parts: [{ type: "text", text: "hello async" }],
- },
- }))
- .status(204, (ctx) =>
- Effect.gen(function* () {
- yield* ctx.llmWait(1)
- }),
- ),
- http.protected
- .post("/session/{sessionID}/command", "session.command")
- .preserveDatabase()
- .withLlm()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Command session" })
- yield* ctx.llmText("command done")
- yield* ctx.llmText("command done")
- return session
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/command", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: { command: "init", arguments: "", model: "test/test-model" },
- }))
- .jsonEffect(
- 200,
- (body, ctx) =>
- Effect.gen(function* () {
- object(body)
- check(isRecord(body.info) && body.info.role === "assistant", "command should return assistant message")
- yield* ctx.llmWait(1)
- }),
- "status",
- ),
- http.protected
- .post("/session/{sessionID}/shell", "session.shell")
- .preserveDatabase()
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Shell session" }))
- .at((ctx) => ({
- path: route("/session/{sessionID}/shell", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: { agent: "build", model: { providerID: "test", modelID: "test-model" }, command: "printf shell-ok" },
- }))
- .json(
- 200,
- (body) => {
- object(body)
- check(isRecord(body.info) && body.info.role === "assistant", "shell should return assistant message")
- check(
- Array.isArray(body.parts) && body.parts.some((part) => isRecord(part) && part.type === "tool"),
- "shell should return a tool part",
- )
- },
- "status",
- ),
- http.protected
- .post("/session/{sessionID}/summarize", "session.summarize")
- .preserveDatabase()
- .withLlm()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Summarize session" })
- yield* ctx.message(session.id, { text: "summarize this work" })
- const summary = [
- "## Objective",
- "- Exercise session summarize.",
- "",
- "## Important Details",
- "- Use fake LLM.",
- "- Keep route local.",
- "- Test fixture: test/server/httpapi-exercise/index.ts.",
- "",
- "## Work State",
- "- Completed: Summary generated.",
- "- Active: (none)",
- "- Blocked: (none)",
- "",
- "## Next Move",
- "1. (none)",
- ].join("\n")
- yield* ctx.llmText(summary)
- yield* ctx.llmText(summary)
- return session
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/summarize", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- body: { providerID: "test", modelID: "test-model", auto: false },
- }))
- .jsonEffect(
- 200,
- (body, ctx) =>
- Effect.gen(function* () {
- check(body === true, "summarize should return true")
- const messages = yield* ctx.messages(ctx.state.id)
- check(
- messages.some((message) => message.info.role === "assistant" && message.info.summary === true),
- "summarize should create a summary assistant message",
- )
- yield* ctx.llmWait(1)
- }),
- "status",
- ),
- http.protected
- .post("/session/{sessionID}/revert", "session.revert")
- .mutating()
- .seeded((ctx) =>
- Effect.gen(function* () {
- const session = yield* ctx.session({ title: "Revert session" })
- const message = yield* ctx.message(session.id, { text: "revert me" })
- return { session, message }
- }),
- )
- .at((ctx) => ({
- path: route("/session/{sessionID}/revert", { sessionID: ctx.state.session.id }),
- headers: ctx.headers(),
- body: { messageID: ctx.state.message.info.id },
- }))
- .json(
- 200,
- (body, ctx) => {
- object(body)
- check(body.id === ctx.state.session.id, "revert should return the session")
- check(
- isRecord(body.revert) && body.revert.messageID === ctx.state.message.info.id,
- "revert should record reverted message",
- )
- },
- "status",
- ),
- http.protected
- .post("/session/{sessionID}/unrevert", "session.unrevert")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Unrevert session" }))
- .at((ctx) => ({
- path: route("/session/{sessionID}/unrevert", { sessionID: ctx.state.id }),
- headers: ctx.headers(),
- }))
- .json(
- 200,
- (body, ctx) => {
- object(body)
- check(body.id === ctx.state.id, "unrevert should return the session")
- },
- "status",
- ),
- http.protected
- .post("/session/{sessionID}/permissions/{permissionID}", "permission.respond")
- .seeded((ctx) => ctx.session({ title: "Deprecated permission session" }))
- .at((ctx) => ({
- path: route("/session/{sessionID}/permissions/{permissionID}", {
- sessionID: ctx.state.id,
- permissionID: "per_httpapi_deprecated",
- }),
- headers: ctx.headers(),
- body: { response: "once" },
- }))
- .json(404, object, "status"),
- http.protected
- .post("/session/{sessionID}/share", "session.share")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Share session" }))
- .at((ctx) => ({ path: route("/session/{sessionID}/share", { sessionID: ctx.state.id }), headers: ctx.headers() }))
- .json(
- 200,
- (body, ctx) => {
- object(body)
- check(body.id === ctx.state.id, "share should return the session")
- },
- "status",
- ),
- http.protected
- .delete("/session/{sessionID}/share", "session.unshare")
- .mutating()
- .seeded((ctx) => ctx.session({ title: "Unshare session" }))
- .at((ctx) => ({ path: route("/session/{sessionID}/share", { sessionID: ctx.state.id }), headers: ctx.headers() }))
- .json(
- 200,
- (body, ctx) => {
- object(body)
- check(body.id === ctx.state.id, "unshare should return the session")
- },
- "status",
- ),
- http.protected
- .post("/tui/append-prompt", "tui.appendPrompt")
- .at((ctx) => ({ path: "/tui/append-prompt", headers: ctx.headers(), body: { text: "hello" } }))
- .json(200, boolean, "status"),
- http.protected
- .post("/tui/select-session", "tui.selectSession.invalid")
- .at((ctx) => ({ path: "/tui/select-session", headers: ctx.headers(), body: { sessionID: "invalid" } }))
- .status(400),
- http.protected.post("/tui/open-help", "tui.openHelp").json(200, boolean, "status"),
- http.protected.post("/tui/open-sessions", "tui.openSessions").json(200, boolean, "status"),
- http.protected.post("/tui/open-themes", "tui.openThemes").json(200, boolean, "status"),
- http.protected.post("/tui/open-models", "tui.openModels").json(200, boolean, "status"),
- http.protected.post("/tui/submit-prompt", "tui.submitPrompt").json(200, boolean, "status"),
- http.protected.post("/tui/clear-prompt", "tui.clearPrompt").json(200, boolean, "status"),
- http.protected
- .post("/tui/execute-command", "tui.executeCommand")
- .at((ctx) => ({ path: "/tui/execute-command", headers: ctx.headers(), body: { command: "agent_cycle" } }))
- .json(200, boolean, "status"),
- http.protected
- .post("/tui/show-toast", "tui.showToast")
- .at((ctx) => ({
- path: "/tui/show-toast",
- headers: ctx.headers(),
- body: { title: "Exercise", message: "covered", variant: "info", duration: 1000 },
- }))
- .json(200, boolean, "status"),
- http.protected
- .post("/tui/publish", "tui.publish")
- .at((ctx) => ({
- path: "/tui/publish",
- headers: ctx.headers(),
- body: { type: "tui.prompt.append", properties: { text: "published" } },
- }))
- .json(200, boolean, "status"),
- http.protected
- .post("/tui/select-session", "tui.selectSession")
- .seeded((ctx) => ctx.session({ title: "TUI select" }))
- .at((ctx) => ({ path: "/tui/select-session", headers: ctx.headers(), body: { sessionID: ctx.state.id } }))
- .json(200, boolean, "status"),
- http.protected
- .post("/tui/control/response", "tui.control.response")
- .at((ctx) => ({ path: "/tui/control/response", headers: ctx.headers(), body: { ok: true } }))
- .json(200, boolean, "status"),
- http.protected
- .get("/tui/control/next", "tui.control.next")
- .mutating()
- .seeded((ctx) => ctx.tuiRequest({ path: "/tui/exercise", body: { text: "queued" } }))
- .json(
- 200,
- (body) => {
- object(body)
- check(body.path === "/tui/exercise", "control next should return queued path")
- object(body.body)
- check(body.body.text === "queued", "control next should return queued body")
- },
- "status",
- ),
- http.protected
- .post("/global/upgrade", "global.upgrade")
- .global()
- .probe({ path: "/global/upgrade", body: { target: 1 } })
- .at(() => ({ path: "/global/upgrade", body: { target: 1 } }))
- .status(400),
- ]
- const llmScenarios = new Set([
- "session.init",
- "session.prompt",
- "session.prompt_async",
- "session.command",
- "session.summarize",
- ])
- const main = Effect.gen(function* () {
- yield* Effect.addFinalizer(() => Effect.promise(() => disposeApps()).pipe(Effect.andThen(cleanupExercisePaths)))
- const options = parseOptions(Bun.argv.slice(2))
- const modules = yield* Effect.promise(() => runtime())
- const effectRoutes = routeKeys(OpenApi.fromApi(modules.PublicApi))
- const selected = selectedScenarios(options, scenarios)
- const missing = effectRoutes.filter((route) => !scenarios.some((scenario) => route === routeKey(scenario)))
- const extra = scenarios.filter((scenario) => !effectRoutes.includes(routeKey(scenario)))
- for (const scenario of scenarios) {
- if (scenario.kind === "active" && llmScenarios.has(scenario.name) && !scenario.project?.llm) {
- return yield* Effect.fail(new Error(`${scenario.name} must use TestLLMServer via .withLlm()`))
- }
- }
- printHeader(options, effectRoutes, selected, missing, extra, {
- database: exerciseDatabasePath,
- global: exerciseGlobalRoot,
- })
- const results =
- options.mode === "coverage"
- ? selected.map(coverageResult)
- : yield* Effect.forEach(
- selected,
- (scenario) =>
- Effect.gen(function* () {
- if (options.progress) console.log(`${color.dim}RUN ${routeKey(scenario)} ${scenario.name}${color.reset}`)
- return yield* runScenario(options)(scenario)
- }),
- { concurrency: 1 },
- )
- printResults(results, missing, extra)
- if (results.some((result) => result.status === "fail"))
- return yield* Effect.fail(new Error("one or more scenarios failed"))
- if (options.failOnSkip && results.some((result) => result.status === "skip"))
- return yield* Effect.fail(new Error("one or more scenarios are skipped"))
- if (options.failOnMissing && missing.length > 0)
- return yield* Effect.fail(new Error("one or more routes have no scenario"))
- return undefined
- })
- Effect.runPromise(main.pipe(Effect.provide(TestLLMServer.layer), Effect.scoped)).then(
- () => process.exit(0),
- (error: unknown) => {
- console.error(`${color.red}${message(error)}${color.reset}`)
- process.exit(1)
- },
- )
|