feat(server): stream events across locations
This commit is contained in:
parent
57ce1b9ca8
commit
595cc91ddc
11 changed files with 2172 additions and 310 deletions
|
|
@ -734,11 +734,11 @@ const scenarios: Scenario[] = [
|
|||
.stream()
|
||||
.status(
|
||||
200,
|
||||
(ctx, result) =>
|
||||
(_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(!!ctx.directory && result.text.includes(ctx.directory), "v2 event should include the resolved location")
|
||||
check(!result.text.includes('"location"'), "v2 connection event should not be scoped to a location")
|
||||
}),
|
||||
"status",
|
||||
),
|
||||
|
|
|
|||
|
|
@ -21,10 +21,12 @@ function request(route: string, directory: string, init: RequestInit = {}) {
|
|||
const Event = Schema.Struct({
|
||||
id: Schema.String,
|
||||
type: Schema.String,
|
||||
location: Schema.Struct({
|
||||
directory: Schema.String,
|
||||
project: Schema.Struct({ id: Schema.String, directory: Schema.String }),
|
||||
}),
|
||||
location: Schema.optional(
|
||||
Schema.Struct({
|
||||
directory: Schema.String,
|
||||
project: Schema.Struct({ id: Schema.String, directory: Schema.String }),
|
||||
}),
|
||||
),
|
||||
data: Schema.Unknown,
|
||||
})
|
||||
|
||||
|
|
@ -64,17 +66,20 @@ describe("v2 location HttpApi", () => {
|
|||
}
|
||||
})
|
||||
|
||||
test("streams native EventV2 payloads with resolved locations", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
const response = await request("/api/event", tmp.path)
|
||||
test("streams native EventV2 payloads across locations", async () => {
|
||||
await using subscriber = await tmpdir({ git: true })
|
||||
await using publisher = await tmpdir({ git: true })
|
||||
const response = await request("/api/event", subscriber.path)
|
||||
const reader = response.body!.getReader()
|
||||
expect((await readEvent(reader)).type).toBe("server.connected")
|
||||
const connected = await readEvent(reader)
|
||||
expect(connected.type).toBe("server.connected")
|
||||
expect(connected.location).toBeUndefined()
|
||||
|
||||
const created = await request("/session", tmp.path, { method: "POST" })
|
||||
const created = await request("/session", publisher.path, { method: "POST" })
|
||||
expect(created.status).toBe(200)
|
||||
expect(await readEventType(reader, "session.created")).toMatchObject({
|
||||
type: "session.created",
|
||||
location: { directory: tmp.path, project: { directory: tmp.path } },
|
||||
location: { directory: publisher.path, project: { directory: publisher.path } },
|
||||
data: { sessionID: expect.any(String) },
|
||||
})
|
||||
await reader.cancel()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue