Normalize instance lifecycle wiring (#25501)

This commit is contained in:
Kit Langton
2026-05-02 20:39:20 -04:00
committed by GitHub
parent a6464062b7
commit 7d91d3b1ed
71 changed files with 852 additions and 936 deletions
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test"
import { Effect } from "effect"
import path from "path"
import { Instance } from "../../src/project/instance"
import { WithInstance } from "../../src/project/with-instance"
import { Session as SessionNs } from "@/session/session"
import { MessageV2 } from "../../src/session/message-v2"
import { MessageID, PartID, type SessionID } from "../../src/session/schema"
@@ -123,7 +124,7 @@ async function addCompactionPart(sessionID: SessionID, messageID: MessageID, tai
describe("MessageV2.page", () => {
test("returns sync result", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -139,7 +140,7 @@ describe("MessageV2.page", () => {
})
test("pages backward with opaque cursors", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -167,7 +168,7 @@ describe("MessageV2.page", () => {
})
test("returns items in chronological order within a page", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -182,7 +183,7 @@ describe("MessageV2.page", () => {
})
test("returns empty items for session with no messages", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -198,7 +199,7 @@ describe("MessageV2.page", () => {
})
test("throws NotFoundError for non-existent session", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const fake = "non-existent-session" as SessionID
@@ -208,7 +209,7 @@ describe("MessageV2.page", () => {
})
test("handles exact limit boundary", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -225,7 +226,7 @@ describe("MessageV2.page", () => {
})
test("limit of 1 returns single newest message", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -242,7 +243,7 @@ describe("MessageV2.page", () => {
})
test("hydrates multiple parts per message", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -266,7 +267,7 @@ describe("MessageV2.page", () => {
})
test("accepts cursors from fractional timestamps", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -284,7 +285,7 @@ describe("MessageV2.page", () => {
})
test("messages with same timestamp are ordered by id", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -304,7 +305,7 @@ describe("MessageV2.page", () => {
})
test("does not return messages from other sessions", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const a = await svc.create({})
@@ -326,7 +327,7 @@ describe("MessageV2.page", () => {
})
test("large limit returns all messages without cursor", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -346,7 +347,7 @@ describe("MessageV2.page", () => {
describe("MessageV2.stream", () => {
test("yields items newest first", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -361,7 +362,7 @@ describe("MessageV2.stream", () => {
})
test("yields nothing for empty session", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -375,7 +376,7 @@ describe("MessageV2.stream", () => {
})
test("yields single message", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -391,7 +392,7 @@ describe("MessageV2.stream", () => {
})
test("hydrates parts for each yielded message", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -409,7 +410,7 @@ describe("MessageV2.stream", () => {
})
test("handles sets exceeding internal page size", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -426,7 +427,7 @@ describe("MessageV2.stream", () => {
})
test("is a sync generator", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -447,7 +448,7 @@ describe("MessageV2.stream", () => {
describe("MessageV2.parts", () => {
test("returns parts for a message", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -464,7 +465,7 @@ describe("MessageV2.parts", () => {
})
test("returns empty array for message with no parts", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -479,7 +480,7 @@ describe("MessageV2.parts", () => {
})
test("returns multiple parts in order", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -512,7 +513,7 @@ describe("MessageV2.parts", () => {
})
test("returns empty for non-existent message id", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
await svc.create({})
@@ -523,7 +524,7 @@ describe("MessageV2.parts", () => {
})
test("parts contain sessionID and messageID", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -541,7 +542,7 @@ describe("MessageV2.parts", () => {
describe("MessageV2.get", () => {
test("returns message with hydrated parts", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -560,7 +561,7 @@ describe("MessageV2.get", () => {
})
test("throws NotFoundError for non-existent message", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -575,7 +576,7 @@ describe("MessageV2.get", () => {
})
test("scopes by session id", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const a = await svc.create({})
@@ -593,7 +594,7 @@ describe("MessageV2.get", () => {
})
test("returns message with multiple parts", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -616,7 +617,7 @@ describe("MessageV2.get", () => {
})
test("returns assistant message with correct role", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -642,7 +643,7 @@ describe("MessageV2.get", () => {
})
test("returns message with zero parts", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -660,7 +661,7 @@ describe("MessageV2.get", () => {
describe("MessageV2.filterCompacted", () => {
test("returns all messages when no compaction", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -677,7 +678,7 @@ describe("MessageV2.filterCompacted", () => {
})
test("stops at compaction boundary and returns chronological order", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -721,7 +722,7 @@ describe("MessageV2.filterCompacted", () => {
})
test("does not break on compaction part without matching summary", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -739,7 +740,7 @@ describe("MessageV2.filterCompacted", () => {
})
test("skips assistant with error even if marked as summary", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -764,7 +765,7 @@ describe("MessageV2.filterCompacted", () => {
})
test("skips assistant without finish even if marked as summary", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -785,7 +786,7 @@ describe("MessageV2.filterCompacted", () => {
})
test("retains original tail when compaction stores tail_start_id", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -841,7 +842,7 @@ describe("MessageV2.filterCompacted", () => {
})
test("fork remaps compaction tail_start_id for filterCompacted", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -907,7 +908,7 @@ describe("MessageV2.filterCompacted", () => {
})
test("retains an assistant tail when compaction starts inside a turn", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -971,7 +972,7 @@ describe("MessageV2.filterCompacted", () => {
})
test("prefers latest compaction boundary when repeated compactions exist", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -1093,7 +1094,7 @@ describe("MessageV2.cursor", () => {
describe("MessageV2 consistency", () => {
test("page hydration matches get for each message", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -1112,7 +1113,7 @@ describe("MessageV2 consistency", () => {
})
test("parts from get match standalone parts call", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -1128,7 +1129,7 @@ describe("MessageV2 consistency", () => {
})
test("stream collects same messages as exhaustive page iteration", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})
@@ -1155,7 +1156,7 @@ describe("MessageV2 consistency", () => {
})
test("filterCompacted of full stream returns same as Array.from when no compaction", async () => {
await Instance.provide({
await WithInstance.provide({
directory: root,
fn: async () => {
const session = await svc.create({})