|
1 | 1 | import { assert, it } from "@effect/vitest"; |
2 | 2 | import { |
| 3 | + ContextTransferId, |
3 | 4 | MessageId, |
4 | 5 | ProjectId, |
5 | 6 | ProviderInstanceId, |
@@ -160,34 +161,56 @@ it.layer(layerTest)("ContextHandoffService legacy import", (it) => { |
160 | 161 | ); |
161 | 162 | }); |
162 | 163 |
|
163 | | -it("caps the side chat context block, keeping the newest parent items", () => { |
164 | | - const parentThreadId = ThreadId.make("thread:side-chat-parent"); |
165 | | - const digest = Array.from({ length: 60 }, (_, index) => |
166 | | - ContextHandoffService.summarizeDeltaItem( |
167 | | - importedItem({ |
| 164 | +it.effect("caps the side chat context block without summarizing discarded parent history", () => |
| 165 | + Effect.gen(function* () { |
| 166 | + const parentThreadId = ThreadId.make("thread:side-chat-parent"); |
| 167 | + let summarizedItems = 0; |
| 168 | + const parentItems = Array.from({ length: 60 }, (_, index) => ({ |
| 169 | + ...importedItem({ |
168 | 170 | role: index % 2 === 0 ? "user" : "assistant", |
169 | 171 | id: `parent-${index}`, |
170 | 172 | text: `item-${index} ${"x".repeat(300)}`, |
171 | 173 | ordinal: index, |
172 | 174 | }), |
173 | | - )!, |
174 | | - ); |
175 | | - const context = ContextHandoffService.makeSideChatContext({ parentThreadId, digest }); |
| 175 | + get text() { |
| 176 | + summarizedItems++; |
| 177 | + return `item-${index} ${"x".repeat(300)}`; |
| 178 | + }, |
| 179 | + })); |
| 180 | + const service = yield* ContextHandoffService.ContextHandoffServiceV2; |
| 181 | + const handoff = yield* service.prepareSideChatContext({ |
| 182 | + parentThreadId, |
| 183 | + threadId: ThreadId.make("thread:side-chat"), |
| 184 | + targetRunId: RunId.make("run:side-chat"), |
| 185 | + transferId: ContextTransferId.make("transfer:side-chat"), |
| 186 | + toProviderThreadId: ProviderThreadId.make("provider-thread:side-chat"), |
| 187 | + fromProviderInstanceId: ProviderInstanceId.make("codex"), |
| 188 | + toProviderInstanceId: ProviderInstanceId.make("codex"), |
| 189 | + coveredRunOrdinals: { from: 1, to: 1 }, |
| 190 | + parentItems, |
| 191 | + createdAt: DateTime.makeUnsafe(0), |
| 192 | + }); |
| 193 | + const context = handoff.summaryText; |
| 194 | + assert.isBelow(summarizedItems, parentItems.length); |
176 | 195 |
|
177 | | - assert.include(context, "- Earlier items truncated."); |
178 | | - assert.notInclude(context, "item-0 "); |
179 | | - assert.include(context, "- Assistant: item-59 "); |
180 | | - assert.isAtMost(context.length, 8_000); |
181 | | - assert.isTrue( |
182 | | - context.endsWith( |
183 | | - `Use t3_thread_read on thread ${parentThreadId} to see the main thread's live state.`, |
184 | | - ), |
185 | | - ); |
| 196 | + assert.include(context, "- Earlier items truncated."); |
| 197 | + assert.notInclude(context, "item-0 "); |
| 198 | + assert.include(context, "- Assistant: item-59 "); |
| 199 | + assert.isAtMost(context.length, 8_000); |
| 200 | + assert.isTrue( |
| 201 | + context.endsWith( |
| 202 | + `Use t3_thread_read on thread ${parentThreadId} to see the main thread's live state.`, |
| 203 | + ), |
| 204 | + ); |
186 | 205 |
|
187 | | - const framingOnly = ContextHandoffService.makeSideChatContext({ parentThreadId, digest: [] }); |
188 | | - assert.isTrue(framingOnly.startsWith("You are in a side chat beside the main thread.")); |
189 | | - assert.notInclude(framingOnly, "Main thread activity"); |
190 | | -}); |
| 206 | + const framingOnly = ContextHandoffService.makeSideChatContext({ |
| 207 | + parentThreadId, |
| 208 | + digest: [], |
| 209 | + }); |
| 210 | + assert.isTrue(framingOnly.startsWith("You are in a side chat beside the main thread.")); |
| 211 | + assert.notInclude(framingOnly, "Main thread activity"); |
| 212 | + }).pipe(Effect.provide(layerTest)), |
| 213 | +); |
191 | 214 |
|
192 | 215 | it("covers the run range of a very long delta", () => { |
193 | 216 | const runs = [ |
|
0 commit comments