@@ -4,6 +4,7 @@ import { vi } from "vite-plus/test";
44import * as Deferred from "effect/Deferred" ;
55import * as Fiber from "effect/Fiber" ;
66import * as TestClock from "effect/testing/TestClock" ;
7+ import * as NodeOS from "node:os" ;
78import { ClaudeSettings } from "@t3tools/contracts" ;
89import * as NodeFSP from "node:fs/promises" ;
910import * as NodeServices from "@effect/platform-node/NodeServices" ;
@@ -13,6 +14,7 @@ import * as FileSystem from "effect/FileSystem";
1314import * as Path from "effect/Path" ;
1415import * as Schema from "effect/Schema" ;
1516
17+ import { makeClaudeCapabilitiesProbeContext } from "../Drivers/ClaudeHome.ts" ;
1618import {
1719 buildClaudeCapabilitiesProbeQueryOptions ,
1820 CLAUDE_CAPABILITIES_PROBE_SETTING_SOURCES ,
@@ -33,12 +35,14 @@ it("isolates Claude capability probes without dropping workspace setting sources
3335 ENABLE_CLAUDEAI_MCP_SERVERS : "true" ,
3436 FORCE_CODE_TERMINAL : "1" ,
3537 } ,
36- cwd : "/workspace/project" ,
38+ cwd : "/config/claude" ,
39+ workspaceCwd : "/workspace/project" ,
3740 } ) ;
3841
3942 assert . deepEqual ( options . mcpServers , { } ) ;
4043 assert . equal ( options . strictMcpConfig , true ) ;
41- assert . equal ( options . cwd , "/workspace/project" ) ;
44+ assert . equal ( options . cwd , "/config/claude" ) ;
45+ assert . deepEqual ( options . additionalDirectories , [ "/workspace/project" ] ) ;
4246 assert . deepEqual ( options . settingSources , [ ...CLAUDE_CAPABILITIES_PROBE_SETTING_SOURCES ] ) ;
4347 assert . deepEqual ( options . settings , { disableAllHooks : true } ) ;
4448 assert . deepEqual ( options . allowedTools , [ ] ) ;
@@ -53,13 +57,14 @@ it("isolates Claude capability probes without dropping workspace setting sources
5357} ) ;
5458
5559it . layer ( NodeServices . layer ) ( "Claude capability probe SDK boundary" , ( it ) => {
56- it . effect ( "serializes strict no-MCP options and still resolves account capabilities " , ( ) =>
60+ it . effect ( "runs from an existing neutral cwd when the Claude config dir is missing " , ( ) =>
5761 Effect . gen ( function * ( ) {
5862 const fs = yield * FileSystem . FileSystem ;
5963 const path = yield * Path . Path ;
6064 const tempDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-claude-probe-sdk-" } ) ;
6165 const executablePath = path . join ( tempDir , "fake-claude.mjs" ) ;
6266 const invocationPath = path . join ( tempDir , "invocation.json" ) ;
67+ const claudeConfigDir = path . join ( tempDir , "missing-claude-config" ) ;
6368 // The probe aborts the SDK without awaiting the child's exit, and on
6469 // Windows a directory that is still some process's cwd cannot be
6570 // removed. Keep the workspace outside the scoped directory and let it
@@ -97,6 +102,7 @@ it.layer(NodeServices.layer)("Claude capability probe SDK boundary", (it) => {
97102 "writeFileSync(process.env.T3_PROBE_INVOCATION_PATH, JSON.stringify({" ,
98103 " args," ,
99104 " cwd: process.cwd()," ,
105+ " configDir: process.env.CLAUDE_CONFIG_DIR," ,
100106 " connectorEnv: process.env.ENABLE_CLAUDEAI_MCP_SERVERS," ,
101107 " mcpConfig," ,
102108 "}));" ,
@@ -135,15 +141,25 @@ it.layer(NodeServices.layer)("Claude capability probe SDK boundary", (it) => {
135141 ) ;
136142 yield * fs . chmod ( executablePath , 0o755 ) ;
137143
138- const capabilities = yield * probeClaudeCapabilities (
139- decodeClaudeSettings ( { binaryPath : executablePath } ) ,
144+ const settings = decodeClaudeSettings ( {
145+ binaryPath : executablePath ,
146+ homePath : claudeConfigDir ,
147+ } ) ;
148+ const context = yield * makeClaudeCapabilitiesProbeContext (
149+ settings ,
140150 {
141151 ...process . env ,
142152 T3_PROBE_INVOCATION_PATH : invocationPath ,
143153 ENABLE_CLAUDEAI_MCP_SERVERS : "true" ,
144154 } ,
145155 workspaceCwd ,
146156 ) ;
157+ const capabilities = yield * probeClaudeCapabilities (
158+ settings ,
159+ context . environment ,
160+ context . cwd ,
161+ workspaceCwd ,
162+ ) ;
147163
148164 assert . deepEqual ( capabilities , {
149165@@ -167,16 +183,22 @@ it.layer(NodeServices.layer)("Claude capability probe SDK boundary", (it) => {
167183 const invocation = JSON . parse ( yield * fs . readFileString ( invocationPath ) ) as {
168184 readonly args : ReadonlyArray < string > ;
169185 readonly cwd : string ;
186+ readonly configDir : string ;
170187 readonly connectorEnv : string ;
171188 readonly mcpConfig : unknown ;
172189 } ;
173- assert . equal ( invocation . cwd , yield * fs . realPath ( workspaceCwd ) ) ;
190+ assert . equal ( invocation . cwd , yield * fs . realPath ( NodeOS . tmpdir ( ) ) ) ;
191+ assert . notEqual ( invocation . cwd , yield * fs . realPath ( workspaceCwd ) ) ;
192+ assert . equal ( invocation . configDir , path . resolve ( claudeConfigDir ) ) ;
174193 assert . equal ( invocation . connectorEnv , "false" ) ;
175194 assert . equal ( invocation . args . includes ( "--strict-mcp-config" ) , true ) ;
176195 assert . equal ( invocation . args . includes ( "--mcp-config" ) , false ) ;
177196 assert . equal ( invocation . mcpConfig , undefined ) ;
178197
179198 assert . equal ( invocation . args . includes ( "--setting-sources=user,project,local" ) , true ) ;
199+ const addDirectoryFlagIndex = invocation . args . indexOf ( "--add-dir" ) ;
200+ assert . notEqual ( addDirectoryFlagIndex , - 1 ) ;
201+ assert . equal ( invocation . args [ addDirectoryFlagIndex + 1 ] , workspaceCwd ) ;
180202
181203 const settingsFlagIndex = invocation . args . indexOf ( "--settings" ) ;
182204 assert . notEqual ( settingsFlagIndex , - 1 ) ;
0 commit comments