refactor(core): rename system context to instructions (#35583)
This commit is contained in:
parent
1a52e1118e
commit
91f1815732
62 changed files with 1482 additions and 1005 deletions
|
|
@ -2,9 +2,39 @@ import { Effect } from "effect"
|
|||
import { OpenCode as EffectOpenCode, type AppApi as EffectApi } from "../src/effect"
|
||||
|
||||
type EffectClient = Effect.Success<ReturnType<typeof EffectOpenCode.make>>
|
||||
type PromiseClient = ReturnType<typeof import("../src/promise").OpenCode.make>
|
||||
|
||||
declare const effectClient: EffectClient
|
||||
declare const promiseClient: PromiseClient
|
||||
|
||||
const effectApi: EffectApi<unknown> = effectClient
|
||||
|
||||
void effectApi
|
||||
declare const sessionID: Parameters<typeof effectApi.session.instructions.entry.list>[0]["sessionID"]
|
||||
|
||||
const effectList: Effect.Effect<
|
||||
ReadonlyArray<{ readonly key: string; readonly value: unknown }>,
|
||||
unknown
|
||||
> = effectApi.session.instructions.entry.list({ sessionID })
|
||||
const effectPut: Effect.Effect<void, unknown> = effectApi.session.instructions.entry.put({
|
||||
sessionID,
|
||||
key: "review-notes",
|
||||
value: { text: "Check the diff" },
|
||||
})
|
||||
const effectRemove: Effect.Effect<void, unknown> = effectApi.session.instructions.entry.remove({
|
||||
sessionID,
|
||||
key: "review-notes",
|
||||
})
|
||||
|
||||
const promiseList: Promise<ReadonlyArray<{ readonly key: string; readonly value: unknown }>> =
|
||||
promiseClient.session.instructions.entry.list({ sessionID: "ses_test" })
|
||||
const promisePut: Promise<void> = promiseClient.session.instructions.entry.put({
|
||||
sessionID: "ses_test",
|
||||
key: "review-notes",
|
||||
value: { text: "Check the diff" },
|
||||
})
|
||||
const promiseRemove: Promise<void> = promiseClient.session.instructions.entry.remove({
|
||||
sessionID: "ses_test",
|
||||
key: "review-notes",
|
||||
})
|
||||
|
||||
void [effectList, effectPut, effectRemove, promiseList, promisePut, promiseRemove]
|
||||
|
|
|
|||
|
|
@ -27,6 +27,57 @@ test("session.get returns the decoded Effect projection", async () => {
|
|||
expect(DateTime.toEpochMillis(result.time.created)).toBe(1_717_171_717_000)
|
||||
})
|
||||
|
||||
test("session instructions methods use the public HTTP contract", async () => {
|
||||
const requests: Array<{ method: string; url: string; body?: unknown }> = []
|
||||
const instructions = [{ key: "review-notes", value: { text: "Check the diff", priority: 1 } }]
|
||||
const httpClient = HttpClient.make((request) => {
|
||||
requests.push({
|
||||
method: request.method,
|
||||
url: request.url,
|
||||
body: request.body._tag === "Uint8Array" ? JSON.parse(new TextDecoder().decode(request.body.body)) : undefined,
|
||||
})
|
||||
return Effect.succeed(
|
||||
HttpClientResponse.fromWeb(
|
||||
request,
|
||||
request.method === "GET" ? Response.json({ data: instructions }) : new Response(null, { status: 204 }),
|
||||
),
|
||||
)
|
||||
})
|
||||
const result = await Effect.gen(function* () {
|
||||
const client = yield* OpenCode.make({ baseUrl: "http://localhost:3000" })
|
||||
const listed = yield* client.session.instructions.entry.list({ sessionID: Session.ID.make("ses_test") })
|
||||
yield* client.session.instructions.entry.put({
|
||||
sessionID: Session.ID.make("ses_test"),
|
||||
key: "review-notes",
|
||||
value: instructions[0].value,
|
||||
})
|
||||
yield* client.session.instructions.entry.remove({
|
||||
sessionID: Session.ID.make("ses_test"),
|
||||
key: "review-notes",
|
||||
})
|
||||
return listed
|
||||
}).pipe(Effect.provideService(HttpClient.HttpClient, httpClient), Effect.runPromise)
|
||||
|
||||
expect(result).toEqual(instructions)
|
||||
expect(requests).toEqual([
|
||||
{
|
||||
method: "GET",
|
||||
url: "http://localhost:3000/api/session/ses_test/instructions/entries",
|
||||
body: undefined,
|
||||
},
|
||||
{
|
||||
method: "PUT",
|
||||
url: "http://localhost:3000/api/session/ses_test/instructions/entries/review-notes",
|
||||
body: { value: { text: "Check the diff", priority: 1 } },
|
||||
},
|
||||
{
|
||||
method: "DELETE",
|
||||
url: "http://localhost:3000/api/session/ses_test/instructions/entries/review-notes",
|
||||
body: undefined,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test("event.subscribe exposes and decodes the native Effect event stream", async () => {
|
||||
const httpClient = HttpClient.make((request) =>
|
||||
Effect.succeed(
|
||||
|
|
|
|||
|
|
@ -148,6 +148,51 @@ test("session.get returns the wire projection", async () => {
|
|||
expect(result.time.created).toBe(1_717_171_717_000)
|
||||
})
|
||||
|
||||
test("session instructions methods use the public HTTP contract", async () => {
|
||||
const requests: Array<{ method: string; url: string; body?: unknown }> = []
|
||||
const instructions = [{ key: "review-notes", value: { text: "Check the diff", priority: 1 } }]
|
||||
const client = OpenCode.make({
|
||||
baseUrl: "http://localhost:3000",
|
||||
fetch: async (input, init) => {
|
||||
const request = input instanceof Request ? input : new Request(input, init)
|
||||
requests.push({
|
||||
method: request.method,
|
||||
url: request.url,
|
||||
body: request.method === "PUT" ? await request.json() : undefined,
|
||||
})
|
||||
if (request.method === "GET") return Response.json({ data: instructions })
|
||||
return new Response(null, { status: 204 })
|
||||
},
|
||||
})
|
||||
|
||||
const result = await client.session.instructions.entry.list({ sessionID: "ses_test" })
|
||||
await client.session.instructions.entry.put({
|
||||
sessionID: "ses_test",
|
||||
key: "review-notes",
|
||||
value: instructions[0].value,
|
||||
})
|
||||
await client.session.instructions.entry.remove({ sessionID: "ses_test", key: "review-notes" })
|
||||
|
||||
expect(result).toEqual(instructions)
|
||||
expect(requests).toEqual([
|
||||
{
|
||||
method: "GET",
|
||||
url: "http://localhost:3000/api/session/ses_test/instructions/entries",
|
||||
body: undefined,
|
||||
},
|
||||
{
|
||||
method: "PUT",
|
||||
url: "http://localhost:3000/api/session/ses_test/instructions/entries/review-notes",
|
||||
body: { value: { text: "Check the diff", priority: 1 } },
|
||||
},
|
||||
{
|
||||
method: "DELETE",
|
||||
url: "http://localhost:3000/api/session/ses_test/instructions/entries/review-notes",
|
||||
body: undefined,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test("event.subscribe exposes the Promise event stream wire projection", async () => {
|
||||
const client = OpenCode.make({
|
||||
baseUrl: "http://localhost:3000",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue