@@ -317,16 +317,23 @@ describe("AntigravityAdapterV2 harness recovery", () => { |
317 | 317 | }); |
318 | 318 |
|
319 | 319 | describe("AntigravityAdapterV2 compaction", () => { |
320 | | - it.live.each([false, true])( |
321 | | - "negotiates native goals (%s) without enabling manual compaction", |
322 | | - (nativeGoals) => |
| 320 | + it.live.each([ |
| 321 | + { nativeGoals: false, compact: false }, |
| 322 | + { nativeGoals: true, compact: false }, |
| 323 | + { nativeGoals: false, compact: true }, |
| 324 | + ])( |
| 325 | + "negotiates native goals ($nativeGoals) and advertised compaction ($compact)", |
| 326 | + ({ nativeGoals, compact }) => |
323 | 327 | Effect.gen(function* () { |
324 | 328 | const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; |
| 329 | + const fileSystem = yield* FileSystem.FileSystem; |
325 | 330 | const path = yield* Path.Path; |
326 | 331 | const crypto = yield* SecureRandom.SecureRandom; |
327 | 332 | const mockAgentPath = yield* path.fromFileUrl( |
328 | 333 | new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), |
329 | 334 | ); |
| 335 | + const logs = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-ag-compact-" }); |
| 336 | + const requestLog = path.join(logs, "requests.ndjson"); |
330 | 337 | const instanceId = ProviderInstanceId.make("antigravity-compaction-test"); |
331 | 338 | const goalSupport = yield* Ref.make(false); |
332 | 339 | const startupMilestone = yield* Deferred.make<void>(); |
@@ -346,7 +353,11 @@ describe("AntigravityAdapterV2 compaction", () => { |
346 | 353 | command: process.execPath, |
347 | 354 | args: [mockAgentPath], |
348 | 355 | cwd: input.cwd, |
349 | | - env: { T3_ACP_ANTIGRAVITY: "1" }, |
| 356 | + env: { |
| 357 | + T3_ACP_ANTIGRAVITY: "1", |
| 358 | + T3_ACP_AVAILABLE_COMMANDS: compact ? "compact" : "", |
| 359 | + T3_ACP_REQUEST_LOG_PATH: requestLog, |
| 360 | + }, |
350 | 361 | }, |
351 | 362 | }).pipe( |
352 | 363 | Effect.provideService(SecureRandom.SecureRandom, crypto), |
@@ -375,28 +386,72 @@ describe("AntigravityAdapterV2 compaction", () => { |
375 | 386 | ) |
376 | 387 | : Effect.void, |
377 | 388 | }); |
| 389 | + const threadId = ThreadId.make("thread-antigravity-compaction"); |
| 390 | + const modelSelection = { instanceId, model: "gemini-test-low" } as const; |
| 391 | + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ |
| 392 | + runtimeMode: "full-access", |
| 393 | + interactionMode: "default", |
| 394 | + cwd: process.cwd(), |
| 395 | + }); |
378 | 396 | const opening = yield* adapter |
379 | 397 | .openSession({ |
380 | | - threadId: ThreadId.make("thread-antigravity-compaction"), |
| 398 | + threadId, |
381 | 399 | providerSessionId: ProviderSessionId.make("provider-session-antigravity-compaction"), |
382 | | - modelSelection: { instanceId, model: "gemini-test-low" }, |
383 | | - runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ |
384 | | - runtimeMode: "full-access", |
385 | | - interactionMode: "default", |
386 | | - cwd: process.cwd(), |
387 | | - }), |
| 400 | + modelSelection, |
| 401 | + runtimePolicy, |
388 | 402 | }) |
389 | 403 | .pipe(Effect.forkScoped); |
390 | 404 | yield* Deferred.await(startupMilestone); |
391 | 405 | yield* Deferred.succeed(consumeStartupCommands, undefined); |
392 | 406 | const session = yield* Fiber.join(opening); |
393 | 407 | assert.deepEqual(yield* Ref.get(workspaceCommands), { |
394 | | - names: ["plan", "logout"], |
| 408 | + names: compact ? ["compact"] : ["plan", "logout"], |
395 | 409 | cwd: process.cwd(), |
396 | 410 | }); |
397 | | - assert.isUndefined(session.compactThread); |
| 411 | + const compactThread = session.compactThread; |
| 412 | + assert.isDefined(compactThread); |
398 | 413 | assert.equal(session.providerSession.capabilities.turns.supportsNativeGoals, nativeGoals); |
399 | 414 | assert.equal((yield* adapter.getCapabilities()).turns.supportsNativeGoals, nativeGoals); |
| 415 | + const providerThread = yield* session.ensureThread({ |
| 416 | + threadId, |
| 417 | + modelSelection, |
| 418 | + runtimePolicy, |
| 419 | + }); |
| 420 | + const turnInput = makeTurnInput({ |
| 421 | + threadId, |
| 422 | + providerThread, |
| 423 | + instanceId, |
| 424 | + modelSelection, |
| 425 | + runtimePolicy, |
| 426 | + now: yield* DateTime.now, |
| 427 | + messageText: "Compact the conversation.", |
| 428 | + }); |
| 429 | + if (compact) { |
| 430 | + yield* compactThread!(turnInput); |
| 431 | + const events = yield* session.events.pipe( |
| 432 | + Stream.takeUntil((event) => event.type === "turn.terminal"), |
| 433 | + Stream.runCollect, |
| 434 | + ); |
| 435 | + assert.isTrue( |
| 436 | + events.some( |
| 437 | + (event) => |
| 438 | + event.type === "turn_item.updated" && |
| 439 | + event.turnItem.type === "compaction" && |
| 440 | + event.turnItem.status === "completed", |
| 441 | + ), |
| 442 | + ); |
| 443 | + } else { |
| 444 | + const error = yield* compactThread!(turnInput).pipe(Effect.flip); |
| 445 | + assert.instanceOf(error, ProviderAdapter.ProviderAdapterTurnStartError); |
| 446 | + assert.instanceOf(error.cause, ProviderAdapter.ProviderCompactionUnsupportedError); |
| 447 | + } |
| 448 | + const prompts = (yield* fileSystem.readFileString(requestLog)) |
| 449 | + .trim() |
| 450 | + .split("\n") |
| 451 | + .map((line) => JSON.parse(line) as { method?: string; params?: { prompt?: unknown } }) |
| 452 | + .filter((request) => request.method === "session/prompt") |
| 453 | + .map((request) => request.params?.prompt); |
| 454 | + assert.deepEqual(prompts, compact ? [[{ type: "text", text: "/compact" }]] : []); |
400 | 455 | }).pipe(Effect.provide(layerSession)), |
401 | 456 | ); |
402 | 457 | }); |
|