11import { assert, it } from "@effect/vitest";
22import {
3+ ChatAttachmentId,
34 CommandId,
45 MessageId,
56 EventId,
@@ -432,6 +433,7 @@ const composerSelection = {
432433const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function* (
433434 name: string,
434435 canRestart = false,
436+ steeringAcceptsAttachments = true,
435437) {
436438 const cwd = yield* checkpointWorkspace(name);
437439 const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
@@ -443,6 +445,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
443445 ...CodexProviderCapabilitiesV2.turns,
444446 supportsActiveSteering: true,
445447 supportsSteeringByInterruptRestart: canRestart,
448+ activeSteeringAcceptsAttachments: steeringAcceptsAttachments,
446449 },
447450 };
448451 const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = {
@@ -453,28 +456,33 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
453456 openSession: (input) =>
454457 Effect.gen(function* () {
455458 const now = yield* DateTime.now;
459+ const turnUpdated = (
460+ turn: ProviderAdapter.ProviderAdapterV2TurnInput,
461+ status: "running" | "interrupted",
462+ ) =>
463+ Queue.offer(events, {
464+ type: "provider_turn.updated",
465+ driver,
466+ providerTurn: {
467+ id: ProviderTurnId.make(`provider-turn:${turn.attemptId}`),
468+ providerThreadId: turn.providerThread.id,
469+ nodeId: turn.rootNodeId,
470+ runAttemptId: turn.attemptId,
471+ nativeTurnRef: {
472+ driver,
473+ nativeId: `native:${turn.attemptId}`,
474+ strength: "strong",
475+ },
476+ ordinal: turn.providerTurnOrdinal,
477+ status,
478+ startedAt: now,
479+ completedAt: status === "running" ? null : now,
480+ },
481+ });
456482 const startTurn = (turn: ProviderAdapter.ProviderAdapterV2TurnInput) =>
457483 Effect.gen(function* () {
458484 started.push(turn);
459- yield* Queue.offer(events, {
460- type: "provider_turn.updated",
461- driver,
462- providerTurn: {
463- id: ProviderTurnId.make(`provider-turn:${turn.attemptId}`),
464- providerThreadId: turn.providerThread.id,
465- nodeId: turn.rootNodeId,
466- runAttemptId: turn.attemptId,
467- nativeTurnRef: {
468- driver,
469- nativeId: `native:${turn.attemptId}`,
470- strength: "strong",
471- },
472- ordinal: turn.providerTurnOrdinal,
473- status: "running",
474- startedAt: now,
475- completedAt: null,
476- },
477- });
485+ yield* turnUpdated(turn, "running");
478486 });
479487 return {
480488 instanceId,
@@ -518,7 +526,14 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
518526 Effect.sync(() => {
519527 steered.push(turn.message.text);
520528 }),
521- interruptTurn: () => Effect.void,
529+ interruptTurn: ({ providerTurnId }) =>
530+ Effect.forEach(
531+ started.filter(
532+ (turn) => ProviderTurnId.make(`provider-turn:${turn.attemptId}`) === providerTurnId,
533+ ),
534+ (turn) => turnUpdated(turn, "interrupted"),
535+ { discard: true },
536+ ),
522537 respondToRuntimeRequest: () => Effect.void,
523538 readThreadSnapshot: () => Effect.die("unused"),
524539 rollbackThread: () => Effect.die("unused"),
@@ -785,6 +800,52 @@ it.effect(
785800 ),
786801);
787802
803+ it.effect("restarts the turn for an image when native steering takes text only", () =>
804+ Effect.scoped(
805+ Effect.gen(function* () {
806+ const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness(
807+ "steering-text-only-attachment",
808+ true,
809+ false,
810+ );
811+ yield* Effect.gen(function* () {
812+ const orchestrator = yield* Orchestrator.OrchestratorV2;
813+ const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
814+ const threadId = yield* startFirstTurn;
815+ yield* orchestrator.dispatch({
816+ type: "message.dispatch",
817+ commandId: CommandId.make("steer-image"),
818+ threadId,
819+ messageId: MessageId.make("message:steer-image"),
820+ text: "look at this",
821+ attachments: [
822+ {
823+ type: "image",
824+ id: ChatAttachmentId.make("steer-image"),
825+ name: "screenshot.png",
826+ mimeType: "image/png",
827+ sizeBytes: 4,
828+ },
829+ ],
830+ modelSelection: runSelection,
831+ dispatchMode: { type: "steer_active", targetRunId: started[0]!.runId },
832+ createdBy: "user",
833+ creationSource: "web",
834+ });
835+ yield* worker.drain();
836+ assert.deepEqual(steered, []);
837+ assert.deepEqual(
838+ started.map((turn) => [turn.message.text, turn.message.attachments.length]),
839+ [
840+ ["first", 0],
841+ ["look at this", 1],
842+ ],
843+ );
844+ }).pipe(Effect.provide(layer));
845+ }),
846+ ),
847+ );
848+
788849it.effect("starts a steer that missed the turn on the saved next-turn selection", () =>
789850 Effect.scoped(
790851 Effect.gen(function* () {
0 commit comments