Skip to content

Commit a6e8fb9

Browse files
ScottN-PVclaude
andcommitted
test(server): cover Claude skill dispatch with images and steering
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 3a92473 commit a6e8fb9

1 file changed

Lines changed: 161 additions & 55 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 161 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,66 +1739,75 @@ describe("ClaudeAdapterV2 attachments", () => {
17391739
});
17401740

17411741
describe("ClaudeAdapterV2 skill dispatch", () => {
1742+
const makeSkillDispatchHarness = Effect.gen(function* () {
1743+
const fileSystem = yield* FileSystem.FileSystem;
1744+
const path = yield* Path.Path;
1745+
const claudeHome = yield* fileSystem.makeTempDirectoryScoped({
1746+
prefix: "t3-claude-v2-skills-home-",
1747+
});
1748+
yield* fileSystem.makeDirectory(path.join(claudeHome, "skills", "implement"), {
1749+
recursive: true,
1750+
});
1751+
yield* fileSystem.writeFileString(
1752+
path.join(claudeHome, "skills", "implement", "SKILL.md"),
1753+
"---\ndescription: Implement the requested change\n---\nImplement it.\n",
1754+
);
1755+
const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
1756+
prefix: "t3-claude-v2-skills-attachments-",
1757+
});
1758+
const offeredMessages: Array<SDKUserMessage> = [];
1759+
const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
1760+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1761+
settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: claudeHome },
1762+
environment: {},
1763+
attachmentsDir,
1764+
fileSystem,
1765+
path,
1766+
crypto: yield* Crypto.Crypto,
1767+
idAllocator: yield* IdAllocator.IdAllocatorV2,
1768+
queryRunner: {
1769+
allocateSessionId: Effect.succeed("native-thread-claude-skills"),
1770+
open: () =>
1771+
Effect.succeed({
1772+
messages: Stream.never,
1773+
offer: (message) =>
1774+
Effect.sync(() => {
1775+
offeredMessages.push(message);
1776+
}),
1777+
setModel: () => Effect.void,
1778+
setPermissionMode: () => Effect.void,
1779+
stopTask: () => Effect.void,
1780+
interrupt: Effect.void,
1781+
close: Effect.void,
1782+
}),
1783+
forkSession: () => Effect.die("unused forkSession"),
1784+
subagentLaunchToolUseId: () => Effect.succeed(null),
1785+
assertComplete: Effect.void,
1786+
},
1787+
});
1788+
const threadId = ThreadId.make("thread-claude-skills");
1789+
const runtime = yield* adapter.openSession({
1790+
threadId,
1791+
providerSessionId: ProviderSessionId.make("provider-session-claude-skills"),
1792+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1793+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1794+
});
1795+
const providerThread = yield* runtime.ensureThread({
1796+
threadId,
1797+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1798+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1799+
});
1800+
return { attachmentsDir, offeredMessages, providerThread, runtime, threadId };
1801+
});
1802+
17421803
// Claude Code moves the expanded command ahead of earlier text blocks, so a
17431804
// leading block holding only the words before the chip reaches the model as
17441805
// a cut-off sentence (#13256).
17451806
it.effect("keeps the full request ahead of a mid-sentence skill command", () =>
17461807
Effect.scoped(
17471808
Effect.gen(function* () {
1748-
const fileSystem = yield* FileSystem.FileSystem;
1749-
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1750-
const path = yield* Path.Path;
1751-
const claudeHome = yield* fileSystem.makeTempDirectoryScoped({
1752-
prefix: "t3-claude-v2-skills-home-",
1753-
});
1754-
yield* fileSystem.makeDirectory(path.join(claudeHome, "skills", "implement"), {
1755-
recursive: true,
1756-
});
1757-
yield* fileSystem.writeFileString(
1758-
path.join(claudeHome, "skills", "implement", "SKILL.md"),
1759-
"---\ndescription: Implement the requested change\n---\nImplement it.\n",
1760-
);
1761-
const offeredMessages: Array<SDKUserMessage> = [];
1762-
const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({
1763-
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1764-
settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: claudeHome },
1765-
environment: {},
1766-
attachmentsDir: yield* fileSystem.makeTempDirectoryScoped({
1767-
prefix: "t3-claude-v2-skills-attachments-",
1768-
}),
1769-
fileSystem,
1770-
path,
1771-
idAllocator,
1772-
queryRunner: {
1773-
allocateSessionId: Effect.succeed("native-thread-claude-skills"),
1774-
open: () =>
1775-
Effect.succeed({
1776-
messages: Stream.never,
1777-
offer: (message) =>
1778-
Effect.sync(() => {
1779-
offeredMessages.push(message);
1780-
}),
1781-
setModel: () => Effect.void,
1782-
interrupt: Effect.void,
1783-
close: Effect.void,
1784-
}),
1785-
forkSession: () => Effect.die("unused forkSession"),
1786-
subagentLaunchToolUseId: () => Effect.succeed(null),
1787-
assertComplete: Effect.void,
1788-
},
1789-
});
1790-
const threadId = ThreadId.make("thread-claude-skills");
1791-
const runtime = yield* adapter.openSession({
1792-
threadId,
1793-
providerSessionId: ProviderSessionId.make("provider-session-claude-skills"),
1794-
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1795-
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1796-
});
1797-
const providerThread = yield* runtime.ensureThread({
1798-
threadId,
1799-
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1800-
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1801-
});
1809+
const { offeredMessages, providerThread, runtime, threadId } =
1810+
yield* makeSkillDispatchHarness;
18021811

18031812
yield* runtime.startTurn(
18041813
makeClaudeTestTurnInput({
@@ -1815,7 +1824,104 @@ describe("ClaudeAdapterV2 skill dispatch", () => {
18151824
{ type: "text", text: "Ultrathink:\nyou will /implement fixes" },
18161825
{ type: "text", text: "/implement fixes" },
18171826
]);
1818-
}).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
1827+
}).pipe(
1828+
Effect.provide(
1829+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1830+
),
1831+
),
1832+
),
1833+
);
1834+
1835+
it.effect("keeps the full request ahead of images and the skill command", () =>
1836+
Effect.scoped(
1837+
Effect.gen(function* () {
1838+
const fileSystem = yield* FileSystem.FileSystem;
1839+
const path = yield* Path.Path;
1840+
const { attachmentsDir, offeredMessages, providerThread, runtime, threadId } =
1841+
yield* makeSkillDispatchHarness;
1842+
const attachment = ChatImageAttachment.make({
1843+
type: "image",
1844+
id: ChatAttachmentId.make("thread-claude-skills-12345678-1234-1234-1234-123456789abc"),
1845+
name: "screen.png",
1846+
mimeType: "image/png",
1847+
sizeBytes: 4,
1848+
});
1849+
const attachmentPath = path.join(attachmentsDir, attachmentRelativePath(attachment)!);
1850+
yield* fileSystem.writeFile(attachmentPath, Uint8Array.from([1, 2, 3, 4]));
1851+
1852+
yield* runtime.startTurn(
1853+
makeClaudeTestTurnInput({
1854+
threadId,
1855+
providerThread,
1856+
now: yield* DateTime.now,
1857+
attemptId: RunAttemptId.make("attempt-claude-skills-image"),
1858+
text: "please $implement this screenshot",
1859+
attachments: [attachment],
1860+
}),
1861+
);
1862+
1863+
const attachmentNote = `[Attached image "screen.png" is saved at: ${attachmentPath}]`;
1864+
assert.deepEqual(offeredMessages[0]?.message.content, [
1865+
{
1866+
type: "text",
1867+
text: `Ultrathink:\nplease /implement this screenshot\n\n${attachmentNote}`,
1868+
},
1869+
{ type: "image", source: { type: "base64", media_type: "image/png", data: "AQIDBA==" } },
1870+
{ type: "text", text: `/implement this screenshot\n\n${attachmentNote}` },
1871+
]);
1872+
}).pipe(
1873+
Effect.provide(
1874+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1875+
),
1876+
),
1877+
),
1878+
);
1879+
1880+
it.effect("keeps the full request ahead of a skill command sent as steering", () =>
1881+
Effect.scoped(
1882+
Effect.gen(function* () {
1883+
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1884+
const { offeredMessages, providerThread, runtime, threadId } =
1885+
yield* makeSkillDispatchHarness;
1886+
const attemptId = RunAttemptId.make("attempt-claude-skills-steer");
1887+
yield* runtime.startTurn(
1888+
makeClaudeTestTurnInput({
1889+
threadId,
1890+
providerThread,
1891+
now: yield* DateTime.now,
1892+
attemptId,
1893+
text: "look at the failing tests",
1894+
attachments: [],
1895+
}),
1896+
);
1897+
1898+
yield* runtime.steerTurn({
1899+
threadId,
1900+
runId: RunId.make(`run-${attemptId}`),
1901+
providerThread,
1902+
providerTurnId: idAllocator.derive.providerTurn({
1903+
driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
1904+
nativeTurnId: `turn:${attemptId}`,
1905+
}),
1906+
message: {
1907+
createdBy: "user",
1908+
creationSource: "web",
1909+
messageId: MessageId.make("message-claude-skills-steer"),
1910+
text: "then $implement the fixes",
1911+
attachments: [],
1912+
},
1913+
});
1914+
1915+
assert.equal(offeredMessages[1]?.priority, "now");
1916+
assert.deepEqual(offeredMessages[1]?.message.content, [
1917+
{ type: "text", text: "Ultrathink:\nthen /implement the fixes" },
1918+
{ type: "text", text: "/implement the fixes" },
1919+
]);
1920+
}).pipe(
1921+
Effect.provide(
1922+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1923+
),
1924+
),
18191925
),
18201926
);
18211927
});

0 commit comments

Comments
 (0)