11// @effect -diagnostics nodeBuiltinImport:off - cleanup uses Node's retrying rm, which the FileSystem service does not expose.
2+ import * as NodeOS from "node:os" ;
3+
24import * as NodeServices from "@effect/platform-node/NodeServices" ;
35import { ClaudeSettings , type ServerProvider } from "@t3tools/contracts" ;
46import { vi } from "vite-plus/test" ;
@@ -110,7 +112,6 @@ it.effect("starts the CLI again only when a source of its command list changes",
110112 path . join ( config , "workflows" , "a.js" ) ,
111113 path . join ( config , "synced" , "account" , "a" , "SKILL.md" ) ,
112114 path . join ( config , "settings.json" ) ,
113- path . join ( config , "remote-settings.json" ) ,
114115 path . join ( config , "plugins" , "installed_plugins.json" ) ,
115116 path . join ( config , "plugins" , "synced" , "account" , ".marketplace-a.json" ) ,
116117 path . join ( config , "plugins" , "cache" , "market" , "plugin" , "1.0.0" , "commands" , "a.md" ) ,
@@ -199,13 +200,68 @@ it.effect("always starts the CLI when its sources cannot be vouched for", () =>
199200 } ) ;
200201
201202 yield * probesTwice ( yield * makeCommands ( { CLAUDE_CODE_PLUGIN_DIRS : "/elsewhere" } ) ) ;
203+ for ( const environment of [
204+ { CLAUDE_CODE_PLUGIN_USE_ZIP_CACHE : "1" } ,
205+ { CLAUDE_CODE_REMOTE_SETTINGS_PATH : "/elsewhere" } ,
206+ { GIT_DIR : "/elsewhere" } ,
207+ { GIT_COMMON_DIR : "/elsewhere" } ,
208+ { GIT_WORK_TREE : "/elsewhere" } ,
209+ { GIT_CEILING_DIRECTORIES : "/elsewhere" } ,
210+ ] ) {
211+ yield * probesTwice ( yield * makeCommands ( environment ) ) ;
212+ }
213+ yield * probesTwice ( yield * makeCommands ( ) ) . pipe (
214+ Effect . provideService ( HostProcess . Platform , "win32" ) ,
215+ ) ;
216+ yield * probesTwice ( yield * makeCommands ( { WSL_INTEROP : "/run/WSL/1_interop" } ) ) . pipe (
217+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
218+ ) ;
202219
220+ const fileSystem = yield * FileSystem . FileSystem ;
203221 const commands = yield * makeCommands ( ) ;
204222 const settings = path . join ( cwd , ".claude" , "settings.json" ) ;
205223 yield * write ( settings , '{"env":{"CLAUDE_CODE_PLUGIN_SEED_DIR":"/elsewhere"}}' ) ;
206224 yield * probesTwice ( commands ) ;
207225 yield * write ( settings , "{}" ) ;
208226
227+ yield * write ( settings , '{"env":{"\\u0043LAUDE_CODE_PLUGIN_CACHE_DIR":"/elsewhere"}}' ) ;
228+ yield * probesTwice ( commands ) ;
229+ yield * write ( settings , "{}" ) ;
230+
231+ for ( const plist of [
232+ `/Library/Managed Preferences/${ NodeOS . userInfo ( ) . username } /com.anthropic.claudecode.plist` ,
233+ "/Library/Managed Preferences/com.anthropic.claudecode.plist" ,
234+ ] ) {
235+ const fixturePlist = path . join ( root , "managed.plist" ) ;
236+ yield * write ( fixturePlist ) ;
237+ yield * probesTwice ( commands ) . pipe (
238+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
239+ Effect . provideService ( FileSystem . FileSystem , {
240+ ...fileSystem ,
241+ stat : ( entry ) => fileSystem . stat ( entry === plist ? fixturePlist : entry ) ,
242+ } ) ,
243+ ) ;
244+ }
245+
246+ for ( const contents of [
247+ '{"env":{"CLAUDE_CONFIG_DIR":"/elsewhere"}}' ,
248+ '{"env":{"HOME":"/elsewhere"}}' ,
249+ '{"env":{"USERPROFILE":"/elsewhere"}}' ,
250+ '{"permissions":{"additionalDirectories":["/elsewhere"]}}' ,
251+ '{"policyHelpers":{"macos":{"command":"helper"}}}' ,
252+ ] ) {
253+ yield * write ( settings , contents ) ;
254+ yield * probesTwice ( commands ) ;
255+ }
256+ yield * write ( settings , "{}" ) ;
257+
258+ const remoteSettings = path . join ( config , "remote-settings.json" ) ;
259+ yield * write ( remoteSettings , '{"env":{"CLAUDE_CODE_PLUGIN_CACHE_DIR":"/elsewhere"}}' ) ;
260+ yield * probesTwice ( commands ) ;
261+ yield * write ( remoteSettings , "{}" ) ;
262+ yield * probesTwice ( commands ) ;
263+ yield * fileSystem . remove ( remoteSettings ) ;
264+
209265 const redirectedPlugins = path . join ( root , "redirected-plugins" ) ;
210266 const redirectedCommand = path . join (
211267 redirectedPlugins ,
@@ -229,8 +285,10 @@ it.effect("always starts the CLI when its sources cannot be vouched for", () =>
229285 yield * write ( settingsPath , "{}" ) ;
230286 }
231287
288+ const managedPath = ( entry : string ) =>
289+ entry . replace ( / ^ \/ e t c \/ c l a u d e - c o d e (? = \/ | $ ) / , path . join ( root , "ClaudeCode" ) ) ;
232290 yield * Effect . gen ( function * ( ) {
233- const managedCommands = yield * makeCommands ( { PROGRAMDATA : root } ) ;
291+ const managedCommands = yield * makeCommands ( ) ;
234292 const dropIn = path . join ( root , "ClaudeCode" , "managed-settings.d" , "plugins.json" ) ;
235293 yield * write ( dropIn , "{}" ) ;
236294 const beforeManaged = probes ( ) ;
@@ -248,9 +306,30 @@ it.effect("always starts the CLI when its sources cannot be vouched for", () =>
248306 yield * managedCommands . get ( machine , cwd ) ;
249307 assert . strictEqual ( probes ( ) , beforeManagedEdit + 1 ) ;
250308 yield * write ( dropIn , "{}" ) ;
251- } ) . pipe ( Effect . provideService ( HostProcess . Platform , "win32" ) ) ;
309+ } ) . pipe (
310+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
311+ Effect . provideService ( FileSystem . FileSystem , {
312+ ...fileSystem ,
313+ stat : ( entry ) => fileSystem . stat ( managedPath ( entry ) ) ,
314+ readDirectory : ( entry ) => fileSystem . readDirectory ( managedPath ( entry ) ) ,
315+ readFileString : ( entry ) => fileSystem . readFileString ( managedPath ( entry ) ) ,
316+ } ) ,
317+ ) ;
252318
253319 const installed = path . join ( config , "plugins" , "installed_plugins.json" ) ;
320+ for ( const installPath of [
321+ path . join ( config , "plugins" , "marketplaces" , "a" ) ,
322+ path . join ( config , "plugins" , "store" , "a" ) ,
323+ path . join ( config , "plugins" ) ,
324+ ] ) {
325+ yield * write (
326+ installed ,
327+ JSON . stringify ( {
328+ plugins : { "a@b" : [ { installPath } ] } ,
329+ } ) ,
330+ ) ;
331+ yield * probesTwice ( commands ) ;
332+ }
254333 yield * write (
255334 installed ,
256335 JSON . stringify ( { plugins : { "a@b" : [ { installPath : path . join ( root , "elsewhere" ) } ] } } ) ,
0 commit comments