|
9 | 9 | RunId, |
10 | 10 | ScheduledTaskId, |
11 | 11 | ThreadId, |
| 12 | + TurnItemId, |
12 | 13 | } from "@t3tools/contracts"; |
13 | 14 | import * as DateTime from "effect/DateTime"; |
14 | 15 | import * as Effect from "effect/Effect"; |
@@ -205,6 +206,98 @@ it("readThread preserves caller access errors and prefers activity-run status ov |
205 | 206 | }).pipe(Effect.provide(layer), Effect.runPromise); |
206 | 207 | }); |
207 | 208 |
|
| 209 | +it("readThread pages cut-off text without splitting an emoji across pages", async () => { |
| 210 | + const text = "a😀bc"; |
| 211 | + const itemId = TurnItemId.make("turn-item-mcp-reasoning"); |
| 212 | + const projection = { |
| 213 | + thread: baseThread({ |
| 214 | + threadId: parentThreadId, |
| 215 | + title: "Parent", |
| 216 | + instanceId: parentInstanceId, |
| 217 | + model: "gpt-5.4", |
| 218 | + }), |
| 219 | + runs: [makeRun({ id: activeRunId, ordinal: 1, status: "running" })], |
| 220 | + visibleTurnItems: [], |
| 221 | + runtimeRequests: [], |
| 222 | + messages: [], |
| 223 | + contextTransfers: [], |
| 224 | + subagents: [], |
| 225 | + updatedAt: now, |
| 226 | + } as unknown as OrchestrationV2ThreadProjection; |
| 227 | + const row = { |
| 228 | + position: 0, |
| 229 | + visibility: "visible", |
| 230 | + sourceThreadId: parentThreadId, |
| 231 | + sourceItemId: itemId, |
| 232 | + item: { |
| 233 | + type: "reasoning", |
| 234 | + runId: activeRunId, |
| 235 | + status: "completed", |
| 236 | + title: null, |
| 237 | + text, |
| 238 | + updatedAt: now, |
| 239 | + }, |
| 240 | + }; |
| 241 | + |
| 242 | + const layer = layerOrchestratorService.pipe( |
| 243 | + Layer.provide( |
| 244 | + Layer.mergeAll( |
| 245 | + Layer.mock(ThreadManagementService.ThreadManagementService)({ |
| 246 | + getTimelinePage: () => |
| 247 | + Effect.succeed({ |
| 248 | + items: [row] as unknown as OrchestrationV2ThreadProjection["visibleTurnItems"], |
| 249 | + totalItems: 1, |
| 250 | + hasMore: false, |
| 251 | + }), |
| 252 | + getThreadRecords: () => Effect.succeed(projection), |
| 253 | + getProjectThreadRecords: () => Effect.succeed(projection), |
| 254 | + getThreadShell: () => |
| 255 | + Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell), |
| 256 | + } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>), |
| 257 | + ServerSettings.layerTest(), |
| 258 | + Layer.mock(ProviderRegistry.ProviderRegistry)({ |
| 259 | + getProviders: Effect.succeed([]), |
| 260 | + } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>), |
| 261 | + Layer.mock(ProjectService.ProjectService)({}), |
| 262 | + Layer.mock(SecretRequests.SecretRequests)({}), |
| 263 | + Layer.mock(RemoteDelegation.RemoteDelegation)({}), |
| 264 | + Layer.mock(ScheduledTaskService.ScheduledTaskService)({ |
| 265 | + list: () => Effect.succeed({ tasks: [] }), |
| 266 | + } satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>), |
| 267 | + Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({ |
| 268 | + list: () => Effect.succeed([]), |
| 269 | + } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>), |
| 270 | + NodeCrypto.layer, |
| 271 | + ), |
| 272 | + ), |
| 273 | + ); |
| 274 | + |
| 275 | + await Effect.gen(function* () { |
| 276 | + const service = yield* OrchestratorMcpService.OrchestratorMcpService; |
| 277 | + for (const [maxCharsPerItem, expected] of [ |
| 278 | + [2, ["a", "😀", "bc"]], |
| 279 | + [1, ["a", "😀", "b", "c"]], |
| 280 | + ] as const) { |
| 281 | + let textOffset = 0; |
| 282 | + for (const [index, text] of expected.entries()) { |
| 283 | + const result = yield* service.readThread(makeScope(), { |
| 284 | + threadId: parentThreadId, |
| 285 | + view: "activity", |
| 286 | + itemId, |
| 287 | + textOffset, |
| 288 | + maxCharsPerItem, |
| 289 | + }); |
| 290 | + textOffset += text.length; |
| 291 | + expect(result.items[0]).toMatchObject({ |
| 292 | + text, |
| 293 | + textTruncated: index < expected.length - 1, |
| 294 | + nextTextOffset: index < expected.length - 1 ? textOffset : null, |
| 295 | + }); |
| 296 | + } |
| 297 | + } |
| 298 | + }).pipe(Effect.provide(layer), Effect.runPromise); |
| 299 | +}); |
| 300 | + |
208 | 301 | it("taskStatus returns task.providerInstanceId rather than the driver kind", async () => { |
209 | 302 | const parentProjection = { |
210 | 303 | thread: baseThread({ |
|
0 commit comments