Skip to content

Commit 4a3c35b

Browse files
committed
Fix reviewed Coder sync regressions and add focused coverage
1 parent 6f0b13f commit 4a3c35b

25 files changed

Lines changed: 625 additions & 127 deletions

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,39 @@ describe("ProviderCommandReactor", () => {
671671
expect(thread?.session?.runtimeMode).toBe("approval-required");
672672
});
673673

674+
it("sends an attached /compact as a normal first turn even though projections omit attachments", async () => {
675+
const harness = await createHarness();
676+
await harness.runEffect(
677+
harness.engine.dispatch({
678+
type: "thread.meta.update",
679+
commandId: CommandId.make("seed-attached-compact"),
680+
threadId: ThreadId.make("thread-1"),
681+
title: "/compact",
682+
}),
683+
);
684+
const attachments = [
685+
{ type: "image" as const, id: "12345678-1234-4123-8123-123456789abc.png" },
686+
];
687+
await harness.runEffect(
688+
harness.engine.dispatch({
689+
type: "thread.turn.start",
690+
commandId: CommandId.make("cmd-attached-compact"),
691+
threadId: ThreadId.make("thread-1"),
692+
message: { messageId: asMessageId("attached-compact"), role: "user", text: "/compact" },
693+
attachments,
694+
titleSeed: "/compact",
695+
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
696+
runtimeMode: "approval-required",
697+
createdAt: "2026-01-01T00:00:00.000Z",
698+
}),
699+
);
700+
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
701+
await harness.drain();
702+
expect(harness.compactThread).not.toHaveBeenCalled();
703+
expect(harness.sendTurn.mock.calls[0]?.[0]).toMatchObject({ input: "/compact", attachments });
704+
await waitFor(() => harness.generateThreadTitle.mock.calls.length === 1);
705+
});
706+
674707
it("routes /compact through provider compaction without starting a normal turn", async () => {
675708
const harness = await createHarness();
676709
const threadId = ThreadId.make("thread-1");

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function toNonEmptyProviderInput(value: string | undefined): string | undefined
7777
const isCompactCommandMessage = (message: {
7878
readonly role: string;
7979
readonly text: string;
80-
readonly attachments?: ReadonlyArray<unknown>;
80+
readonly attachments?: ReadonlyArray<unknown> | undefined;
8181
}): boolean =>
8282
message.role === "user" &&
8383
(message.attachments?.length ?? 0) === 0 &&
@@ -1178,9 +1178,15 @@ const make = Effect.gen(function* () {
11781178

11791179
yield* ensureThreadWorktree(thread);
11801180

1181-
const isCompactCommand = isCompactCommandMessage(message);
1181+
// The Coder projection omits attachments; the turn intent owns them.
1182+
const isCompactCommand = isCompactCommandMessage({
1183+
...message,
1184+
attachments: event.payload.attachments,
1185+
});
11821186
const nonCompactUserMessageCount = thread.messages.filter(
1183-
(entry) => entry.role === "user" && !isCompactCommandMessage(entry),
1187+
(entry) =>
1188+
entry.role === "user" &&
1189+
!(entry.id === message.id ? isCompactCommand : isCompactCommandMessage(entry)),
11841190
).length;
11851191
if (nonCompactUserMessageCount === 1 && !isCompactCommand) {
11861192
const project = yield* resolveProject(thread.projectId);

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ describe("ProviderRuntimeIngestion", () => {
20882088
expect(message?.streaming).toBe(false);
20892089
});
20902090

2091-
it("flushes and completes buffered assistant text when user input is requested", async () => {
2091+
it("flushes async question text and preserves message-response routing without item.completed", async () => {
20922092
const harness = await createHarness();
20932093
const now = "2026-01-01T00:00:00.000Z";
20942094

@@ -2129,6 +2129,7 @@ describe("ProviderRuntimeIngestion", () => {
21292129
turnId: asTurnId("turn-buffered-user-input-flush"),
21302130
requestId: ApprovalRequestId.make("req-buffered-user-input-flush"),
21312131
payload: {
2132+
responseMode: "message",
21322133
questions: [
21332134
{
21342135
id: "choice",
@@ -2153,6 +2154,12 @@ describe("ProviderRuntimeIngestion", () => {
21532154
entry.id === "assistant:item-buffered-user-input-flush",
21542155
);
21552156
expect(message?.streaming).toBe(false);
2157+
expect(
2158+
thread.activities.find(
2159+
(activity: ProviderRuntimeTestActivity) =>
2160+
activity.id === "evt-user-input-requested-buffered-user-input-flush",
2161+
)?.payload,
2162+
).toMatchObject({ responseMode: "message" });
21562163
});
21572164

21582165
it("does not create assistant segments for whitespace-only buffered text at approval boundaries", async () => {

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ export function runtimeEventToActivities(
513513
payload: {
514514
...(event.requestId ? { requestId: event.requestId } : {}),
515515
questions: event.payload.questions,
516+
...(event.payload.responseMode ? { responseMode: event.payload.responseMode } : {}),
516517
},
517518
turnId: toTurnId(event.turnId) ?? null,
518519
...maybeSequence,

‎apps/server/src/provider/Layers/ClaudeCapabilitiesProbe.test.ts‎

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,51 @@ it.layer(NodeServices.layer)("Claude authentication status", (it) => {
4747
auth: "unknown",
4848
status: "warning",
4949
},
50+
{
51+
name: "API-key authentication succeeds",
52+
output: '{"loggedIn":true}',
53+
code: 0,
54+
auth: "authenticated",
55+
status: "ready",
56+
tokenSource: "apiKey",
57+
backendType: "apiKey",
58+
},
59+
{
60+
name: "failed API-key auth retains identity without claiming readiness",
61+
output: '{"loggedIn":false}',
62+
code: 1,
63+
auth: "unauthenticated",
64+
status: "error",
65+
tokenSource: "apiKey",
66+
backendType: "apiKey",
67+
},
68+
{
69+
name: "Bedrock authentication succeeds",
70+
output: '{"loggedIn":true}',
71+
code: 0,
72+
auth: "authenticated",
73+
status: "ready",
74+
apiProvider: "bedrock",
75+
backendType: "bedrock",
76+
},
77+
{
78+
name: "Bedrock auth failure does not suggest OAuth login",
79+
output: '{"loggedIn":false}',
80+
code: 1,
81+
auth: "unauthenticated",
82+
status: "error",
83+
apiProvider: "bedrock",
84+
backendType: "bedrock",
85+
},
86+
{
87+
name: "unknown Bedrock auth retains identity without trusting initialization",
88+
output: "{}",
89+
code: 0,
90+
auth: "unknown",
91+
status: "warning",
92+
apiProvider: "bedrock",
93+
backendType: "bedrock",
94+
},
5095
]) {
5196
it.effect(testCase.name, () =>
5297
Effect.gen(function* () {
@@ -71,8 +116,8 @@ it.layer(NodeServices.layer)("Claude authentication status", (it) => {
71116
Effect.succeed({
72117
73118
subscriptionType: "pro",
74-
tokenSource: "oauth",
75-
apiProvider: "firstParty",
119+
tokenSource: "tokenSource" in testCase ? testCase.tokenSource : "oauth",
120+
apiProvider: "apiProvider" in testCase ? testCase.apiProvider : "firstParty",
76121
models: [],
77122
slashCommands: [],
78123
autoModeDisabled: true,
@@ -85,6 +130,12 @@ it.layer(NodeServices.layer)("Claude authentication status", (it) => {
85130
assert.equal(result.status, testCase.status);
86131
if (testCase.auth !== "authenticated") assert.equal(result.auth.email, undefined);
87132
assert.equal(result.message?.includes("private invalid output") ?? false, false);
133+
if ("backendType" in testCase) {
134+
assert.equal(result.auth.type, testCase.backendType);
135+
assert.equal(result.message?.includes("claude auth login") ?? false, false);
136+
} else if (testCase.auth !== "authenticated") {
137+
assert.equal(result.auth.type, undefined);
138+
}
88139
}),
89140
);
90141
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as NodeServices from "@effect/platform-node/NodeServices";
2+
import { assert, it } from "@effect/vitest";
3+
import { ClaudeSettings } from "@t3tools/contracts";
4+
import * as Deferred from "effect/Deferred";
5+
import * as Effect from "effect/Effect";
6+
import * as Fiber from "effect/Fiber";
7+
import * as Schema from "effect/Schema";
8+
import * as TestClock from "effect/testing/TestClock";
9+
import { vi } from "vite-plus/test";
10+
11+
const query = vi.hoisted(() => vi.fn());
12+
vi.mock("../Drivers/ClaudeCli.ts", async (importOriginal) => ({
13+
...(await importOriginal<typeof import("../Drivers/ClaudeCli.ts")>()),
14+
query,
15+
}));
16+
17+
import { probeClaudeCapabilities } from "./ClaudeProvider.ts";
18+
19+
it.layer(NodeServices.layer)("Claude optional probe deadlines", (it) => {
20+
it.effect("does not discard slow successful initialization while optional usage is pending", () =>
21+
Effect.gen(function* () {
22+
const initialized = yield* Deferred.make<void>();
23+
const usageStarted = yield* Deferred.make<void>();
24+
let finishInit!: (value: unknown) => void;
25+
let finishUsage!: (value: unknown) => void;
26+
let aborted = false;
27+
const getUsage = vi.fn(() => {
28+
Deferred.doneUnsafe(usageStarted, Effect.void);
29+
return new Promise((resolve) => {
30+
finishUsage = resolve;
31+
});
32+
});
33+
query.mockImplementation(({ options }) => {
34+
options.abortController.signal.addEventListener("abort", () => {
35+
aborted = true;
36+
});
37+
return {
38+
initializationResult: () => {
39+
Deferred.doneUnsafe(initialized, Effect.void);
40+
return new Promise((resolve) => {
41+
finishInit = resolve;
42+
});
43+
},
44+
getSettings: async () => ({}),
45+
getUsage,
46+
};
47+
});
48+
const fiber = yield* probeClaudeCapabilities(Schema.decodeSync(ClaudeSettings)({})).pipe(
49+
Effect.forkScoped,
50+
);
51+
yield* Deferred.await(initialized);
52+
yield* TestClock.adjust("24 seconds");
53+
finishInit({ account: { tokenSource: "oauth" }, commands: [], models: [] });
54+
yield* Deferred.await(usageStarted);
55+
assert.deepEqual(getUsage.mock.calls[0], [5_000]);
56+
yield* TestClock.adjust("2 seconds");
57+
assert.equal(aborted, false);
58+
finishUsage({ rate_limits_available: false });
59+
const result = yield* Fiber.join(fiber);
60+
assert.equal(result?.tokenSource, "oauth");
61+
assert.equal(aborted, true);
62+
}).pipe(Effect.scoped),
63+
);
64+
});

0 commit comments

Comments
 (0)