Normalize instance lifecycle wiring (#25501)
This commit is contained in:
@@ -10,6 +10,7 @@ import { LLM } from "../../src/session/llm"
|
||||
import { SessionCompaction } from "../../src/session/compaction"
|
||||
import { Token } from "@/util/token"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { WithInstance } from "../../src/project/with-instance"
|
||||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import { Permission } from "../../src/permission"
|
||||
import { Plugin } from "../../src/plugin"
|
||||
@@ -792,7 +793,7 @@ describe("session.compaction.prune", () => {
|
||||
describe("session.compaction.process", () => {
|
||||
test("throws when parent is not a user message", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -822,7 +823,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("publishes compacted event on continue", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -872,7 +873,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("marks summary message as errored on compact result", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -910,7 +911,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("adds synthetic continue prompt when auto is enabled", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -951,7 +952,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("persists tail_start_id for retained recent turns", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -998,7 +999,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("shrinks retained tail to fit preserve token budget", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1047,7 +1048,7 @@ describe("session.compaction.process", () => {
|
||||
captured = JSON.stringify(input.messages)
|
||||
}),
|
||||
)
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1096,7 +1097,7 @@ describe("session.compaction.process", () => {
|
||||
captured = JSON.stringify(input.messages)
|
||||
}),
|
||||
)
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1155,7 +1156,7 @@ describe("session.compaction.process", () => {
|
||||
captured = JSON.stringify(input.messages)
|
||||
}),
|
||||
)
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1218,7 +1219,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("allows plugins to disable synthetic continue prompt", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1261,7 +1262,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("replays the prior user turn on overflow when earlier context exists", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1309,7 +1310,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("falls back to overflow guidance when no replayable turn exists", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1369,7 +1370,7 @@ describe("session.compaction.process", () => {
|
||||
)
|
||||
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1443,7 +1444,7 @@ describe("session.compaction.process", () => {
|
||||
const ready = defer()
|
||||
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1545,7 +1546,7 @@ describe("session.compaction.process", () => {
|
||||
)
|
||||
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1587,7 +1588,7 @@ describe("session.compaction.process", () => {
|
||||
)
|
||||
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1639,7 +1640,7 @@ describe("session.compaction.process", () => {
|
||||
)
|
||||
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1707,7 +1708,7 @@ describe("session.compaction.process", () => {
|
||||
stub.push(reply("summary one"))
|
||||
stub.push(reply("summary two"))
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
@@ -1779,7 +1780,7 @@ describe("session.compaction.process", () => {
|
||||
|
||||
test("ignores previous summaries when sizing the retained tail", async () => {
|
||||
await using tmp = await tmpdir()
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const session = await svc.create({})
|
||||
|
||||
@@ -6,6 +6,7 @@ import z from "zod"
|
||||
import { makeRuntime } from "../../src/effect/run-service"
|
||||
import { LLM } from "../../src/session/llm"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { WithInstance } from "../../src/project/with-instance"
|
||||
import { Provider } from "@/provider/provider"
|
||||
import { ProviderTransform } from "@/provider/transform"
|
||||
import { ModelsDev } from "@/provider/models"
|
||||
@@ -338,7 +339,7 @@ describe("session.llm.stream", () => {
|
||||
},
|
||||
})
|
||||
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const resolved = await getModel(ProviderID.make(providerID), ModelID.make(model.id))
|
||||
@@ -425,7 +426,7 @@ describe("session.llm.stream", () => {
|
||||
},
|
||||
})
|
||||
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const resolved = await getModel(ProviderID.make(providerID), ModelID.make(model.id))
|
||||
@@ -515,7 +516,7 @@ describe("session.llm.stream", () => {
|
||||
},
|
||||
})
|
||||
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const resolved = await getModel(ProviderID.make(providerID), ModelID.make(model.id))
|
||||
@@ -629,7 +630,7 @@ describe("session.llm.stream", () => {
|
||||
},
|
||||
})
|
||||
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const resolved = await getModel(ProviderID.openai, ModelID.make(model.id))
|
||||
@@ -745,7 +746,7 @@ describe("session.llm.stream", () => {
|
||||
},
|
||||
})
|
||||
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const resolved = await getModel(ProviderID.openai, ModelID.make(model.id))
|
||||
@@ -864,7 +865,7 @@ describe("session.llm.stream", () => {
|
||||
},
|
||||
})
|
||||
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const resolved = await getModel(ProviderID.make(providerID), ModelID.make(model.id))
|
||||
@@ -982,7 +983,7 @@ describe("session.llm.stream", () => {
|
||||
},
|
||||
})
|
||||
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const resolved = await getModel(ProviderID.make("anthropic"), ModelID.make(model.id))
|
||||
@@ -1223,7 +1224,7 @@ describe("session.llm.stream", () => {
|
||||
},
|
||||
})
|
||||
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const resolved = await getModel(ProviderID.make(providerID), ModelID.make(model.id))
|
||||
|
||||
@@ -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({})
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Session as SessionNs } from "@/session/session"
|
||||
import { Bus } from "../../src/bus"
|
||||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { WithInstance } from "../../src/project/with-instance"
|
||||
import { MessageV2 } from "../../src/session/message-v2"
|
||||
import { MessageID, PartID, type SessionID } from "../../src/session/schema"
|
||||
import { AppRuntime } from "../../src/effect/app-runtime"
|
||||
@@ -34,7 +35,7 @@ function updatePart<T extends MessageV2.Part>(part: T) {
|
||||
|
||||
describe("session.created event", () => {
|
||||
test("should emit session.created event when session is created", async () => {
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: projectRoot,
|
||||
fn: async () => {
|
||||
let eventReceived = false
|
||||
@@ -63,7 +64,7 @@ describe("session.created event", () => {
|
||||
})
|
||||
|
||||
test("session.created event should be emitted before session.updated", async () => {
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: projectRoot,
|
||||
fn: async () => {
|
||||
const events: string[] = []
|
||||
@@ -95,7 +96,7 @@ describe("step-finish token propagation via Bus event", () => {
|
||||
test(
|
||||
"non-zero tokens propagate through PartUpdated event",
|
||||
async () => {
|
||||
await Instance.provide({
|
||||
await WithInstance.provide({
|
||||
directory: projectRoot,
|
||||
fn: async () => {
|
||||
const info = await create({})
|
||||
@@ -166,7 +167,7 @@ describe("Session", () => {
|
||||
test("remove works without an instance", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
|
||||
const info = await Instance.provide({
|
||||
const info = await WithInstance.provide({
|
||||
directory: tmp.path,
|
||||
fn: () => create({ title: "remove-without-instance" }),
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Session } from "@/session/session"
|
||||
import { SessionPrompt } from "../../src/session/prompt"
|
||||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { WithInstance } from "../../src/project/with-instance"
|
||||
import { MessageV2 } from "../../src/session/message-v2"
|
||||
|
||||
const projectRoot = path.join(__dirname, "../..")
|
||||
@@ -15,7 +16,7 @@ const hasApiKey = !!process.env.ANTHROPIC_API_KEY
|
||||
|
||||
// Helper to run test within Instance context
|
||||
async function withInstance<T>(fn: () => Promise<T>): Promise<T> {
|
||||
return Instance.provide({
|
||||
return WithInstance.provide({
|
||||
directory: projectRoot,
|
||||
fn,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user