@vybestack/llxprt-code-core 0.1.18-nightly.250811.b0db22c6 → 0.1.18-nightly.250812.12fa8ad2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (485) hide show
  1. package/README.md +49 -2
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/auth/anthropic-device-flow.d.ts +53 -0
  6. package/dist/src/auth/anthropic-device-flow.js +208 -0
  7. package/dist/src/auth/anthropic-device-flow.js.map +1 -0
  8. package/dist/src/auth/token-store.js +11 -7
  9. package/dist/src/auth/token-store.js.map +1 -1
  10. package/dist/src/config/config.d.ts +7 -1
  11. package/dist/src/config/config.js +42 -4
  12. package/dist/src/config/config.js.map +1 -1
  13. package/dist/src/config/profileManager.d.ts +14 -4
  14. package/dist/src/config/profileManager.js +90 -11
  15. package/dist/src/config/profileManager.js.map +1 -1
  16. package/dist/src/core/contentGenerator.d.ts +2 -1
  17. package/dist/src/core/contentGenerator.js +1 -0
  18. package/dist/src/core/contentGenerator.js.map +1 -1
  19. package/dist/src/index.d.ts +6 -0
  20. package/dist/src/index.js +5 -0
  21. package/dist/src/index.js.map +1 -1
  22. package/dist/src/providers/BaseProvider.d.ts +51 -0
  23. package/dist/src/providers/BaseProvider.js +136 -1
  24. package/dist/src/providers/BaseProvider.js.map +1 -1
  25. package/dist/src/providers/IProvider.d.ts +1 -0
  26. package/dist/src/providers/LoggingProviderWrapper.d.ts +1 -0
  27. package/dist/src/providers/LoggingProviderWrapper.js +3 -0
  28. package/dist/src/providers/LoggingProviderWrapper.js.map +1 -1
  29. package/dist/src/providers/ProviderManager.d.ts +0 -1
  30. package/dist/src/providers/ProviderManager.js +23 -14
  31. package/dist/src/providers/ProviderManager.js.map +1 -1
  32. package/dist/src/providers/anthropic/AnthropicProvider.d.ts +20 -6
  33. package/dist/src/providers/anthropic/AnthropicProvider.js +172 -26
  34. package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -1
  35. package/dist/src/providers/gemini/GeminiProvider.d.ts +4 -0
  36. package/dist/src/providers/gemini/GeminiProvider.js +33 -1
  37. package/dist/src/providers/gemini/GeminiProvider.js.map +1 -1
  38. package/dist/src/providers/openai/OpenAIProvider.d.ts +32 -0
  39. package/dist/src/providers/openai/OpenAIProvider.js +200 -13
  40. package/dist/src/providers/openai/OpenAIProvider.js.map +1 -1
  41. package/dist/src/providers/openai/RESPONSES_API_MODELS.d.ts +1 -1
  42. package/dist/src/providers/openai/RESPONSES_API_MODELS.js +1 -0
  43. package/dist/src/providers/openai/RESPONSES_API_MODELS.js.map +1 -1
  44. package/dist/src/providers/openai/syntheticToolResponses.d.ts +52 -0
  45. package/dist/src/providers/openai/syntheticToolResponses.js +129 -0
  46. package/dist/src/providers/openai/syntheticToolResponses.js.map +1 -0
  47. package/dist/src/settings/SettingsService.d.ts +32 -0
  48. package/dist/src/settings/SettingsService.js +204 -0
  49. package/dist/src/settings/SettingsService.js.map +1 -0
  50. package/dist/src/settings/settingsServiceInstance.d.ts +12 -0
  51. package/dist/src/settings/settingsServiceInstance.js +24 -0
  52. package/dist/src/settings/settingsServiceInstance.js.map +1 -0
  53. package/dist/src/settings/types.d.ts +141 -0
  54. package/dist/src/settings/types.js +5 -0
  55. package/dist/src/settings/types.js.map +1 -0
  56. package/package.json +4 -2
  57. package/dist/src/auth/auth-integration.spec.d.ts +0 -6
  58. package/dist/src/auth/auth-integration.spec.js +0 -384
  59. package/dist/src/auth/auth-integration.spec.js.map +0 -1
  60. package/dist/src/auth/precedence.test.d.ts +0 -6
  61. package/dist/src/auth/precedence.test.js +0 -374
  62. package/dist/src/auth/precedence.test.js.map +0 -1
  63. package/dist/src/auth/qwen-device-flow.spec.d.ts +0 -6
  64. package/dist/src/auth/qwen-device-flow.spec.js +0 -793
  65. package/dist/src/auth/qwen-device-flow.spec.js.map +0 -1
  66. package/dist/src/auth/token-store.spec.d.ts +0 -6
  67. package/dist/src/auth/token-store.spec.js +0 -405
  68. package/dist/src/auth/token-store.spec.js.map +0 -1
  69. package/dist/src/code_assist/converter.test.d.ts +0 -6
  70. package/dist/src/code_assist/converter.test.js +0 -279
  71. package/dist/src/code_assist/converter.test.js.map +0 -1
  72. package/dist/src/code_assist/oauth2.test.d.ts +0 -6
  73. package/dist/src/code_assist/oauth2.test.js +0 -370
  74. package/dist/src/code_assist/oauth2.test.js.map +0 -1
  75. package/dist/src/code_assist/server.test.d.ts +0 -6
  76. package/dist/src/code_assist/server.test.js +0 -134
  77. package/dist/src/code_assist/server.test.js.map +0 -1
  78. package/dist/src/code_assist/setup.test.d.ts +0 -6
  79. package/dist/src/code_assist/setup.test.js +0 -65
  80. package/dist/src/code_assist/setup.test.js.map +0 -1
  81. package/dist/src/config/config.alwaysAllow.test.d.ts +0 -6
  82. package/dist/src/config/config.alwaysAllow.test.js +0 -84
  83. package/dist/src/config/config.alwaysAllow.test.js.map +0 -1
  84. package/dist/src/config/config.ephemeral.test.d.ts +0 -6
  85. package/dist/src/config/config.ephemeral.test.js +0 -152
  86. package/dist/src/config/config.ephemeral.test.js.map +0 -1
  87. package/dist/src/config/config.test.d.ts +0 -6
  88. package/dist/src/config/config.test.js +0 -369
  89. package/dist/src/config/config.test.js.map +0 -1
  90. package/dist/src/config/endpoints.test.d.ts +0 -6
  91. package/dist/src/config/endpoints.test.js +0 -196
  92. package/dist/src/config/endpoints.test.js.map +0 -1
  93. package/dist/src/config/flashFallback.test.d.ts +0 -6
  94. package/dist/src/config/flashFallback.test.js +0 -91
  95. package/dist/src/config/flashFallback.test.js.map +0 -1
  96. package/dist/src/core/client.test.d.ts +0 -6
  97. package/dist/src/core/client.test.js +0 -1323
  98. package/dist/src/core/client.test.js.map +0 -1
  99. package/dist/src/core/contentGenerator.test.d.ts +0 -6
  100. package/dist/src/core/contentGenerator.test.js +0 -103
  101. package/dist/src/core/contentGenerator.test.js.map +0 -1
  102. package/dist/src/core/coreToolScheduler.test.d.ts +0 -6
  103. package/dist/src/core/coreToolScheduler.test.js +0 -637
  104. package/dist/src/core/coreToolScheduler.test.js.map +0 -1
  105. package/dist/src/core/geminiChat.test.d.ts +0 -6
  106. package/dist/src/core/geminiChat.test.js +0 -425
  107. package/dist/src/core/geminiChat.test.js.map +0 -1
  108. package/dist/src/core/googleGenAIWrapper.test.d.ts +0 -6
  109. package/dist/src/core/googleGenAIWrapper.test.js +0 -104
  110. package/dist/src/core/googleGenAIWrapper.test.js.map +0 -1
  111. package/dist/src/core/logger.test.d.ts +0 -6
  112. package/dist/src/core/logger.test.js +0 -467
  113. package/dist/src/core/logger.test.js.map +0 -1
  114. package/dist/src/core/nonInteractiveToolExecutor.test.d.ts +0 -6
  115. package/dist/src/core/nonInteractiveToolExecutor.test.js +0 -165
  116. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +0 -1
  117. package/dist/src/core/prompts-async.test.d.ts +0 -6
  118. package/dist/src/core/prompts-async.test.js +0 -115
  119. package/dist/src/core/prompts-async.test.js.map +0 -1
  120. package/dist/src/core/prompts.test.d.ts +0 -6
  121. package/dist/src/core/prompts.test.js +0 -68
  122. package/dist/src/core/prompts.test.js.map +0 -1
  123. package/dist/src/core/subagent.test.d.ts +0 -6
  124. package/dist/src/core/subagent.test.js +0 -510
  125. package/dist/src/core/subagent.test.js.map +0 -1
  126. package/dist/src/core/tokenLimits.test.d.ts +0 -6
  127. package/dist/src/core/tokenLimits.test.js +0 -66
  128. package/dist/src/core/tokenLimits.test.js.map +0 -1
  129. package/dist/src/core/turn.test.d.ts +0 -6
  130. package/dist/src/core/turn.test.js +0 -366
  131. package/dist/src/core/turn.test.js.map +0 -1
  132. package/dist/src/hooks/tool-render-suppression-hook.test.d.ts +0 -6
  133. package/dist/src/hooks/tool-render-suppression-hook.test.js +0 -59
  134. package/dist/src/hooks/tool-render-suppression-hook.test.js.map +0 -1
  135. package/dist/src/ide/ide-installer.test.d.ts +0 -6
  136. package/dist/src/ide/ide-installer.test.js +0 -55
  137. package/dist/src/ide/ide-installer.test.js.map +0 -1
  138. package/dist/src/ide/ideContext.test.d.ts +0 -6
  139. package/dist/src/ide/ideContext.test.js +0 -265
  140. package/dist/src/ide/ideContext.test.js.map +0 -1
  141. package/dist/src/index.test.d.ts +0 -6
  142. package/dist/src/index.test.js +0 -12
  143. package/dist/src/index.test.js.map +0 -1
  144. package/dist/src/integration-tests/oauth-integration.spec.d.ts +0 -6
  145. package/dist/src/integration-tests/oauth-integration.spec.js +0 -518
  146. package/dist/src/integration-tests/oauth-integration.spec.js.map +0 -1
  147. package/dist/src/integration-tests/oauth-simple-test.spec.d.ts +0 -1
  148. package/dist/src/integration-tests/oauth-simple-test.spec.js +0 -88
  149. package/dist/src/integration-tests/oauth-simple-test.spec.js.map +0 -1
  150. package/dist/src/integration-tests/todo-system.test.d.ts +0 -6
  151. package/dist/src/integration-tests/todo-system.test.js +0 -46
  152. package/dist/src/integration-tests/todo-system.test.js.map +0 -1
  153. package/dist/src/mcp/google-auth-provider.test.d.ts +0 -6
  154. package/dist/src/mcp/google-auth-provider.test.js +0 -54
  155. package/dist/src/mcp/google-auth-provider.test.js.map +0 -1
  156. package/dist/src/mcp/oauth-provider.test.d.ts +0 -6
  157. package/dist/src/mcp/oauth-provider.test.js +0 -602
  158. package/dist/src/mcp/oauth-provider.test.js.map +0 -1
  159. package/dist/src/mcp/oauth-token-storage.test.d.ts +0 -6
  160. package/dist/src/mcp/oauth-token-storage.test.js +0 -205
  161. package/dist/src/mcp/oauth-token-storage.test.js.map +0 -1
  162. package/dist/src/mcp/oauth-utils.test.d.ts +0 -6
  163. package/dist/src/mcp/oauth-utils.test.js +0 -144
  164. package/dist/src/mcp/oauth-utils.test.js.map +0 -1
  165. package/dist/src/parsers/TextToolCallParser.multibyte.test.d.ts +0 -1
  166. package/dist/src/parsers/TextToolCallParser.multibyte.test.js +0 -42
  167. package/dist/src/parsers/TextToolCallParser.multibyte.test.js.map +0 -1
  168. package/dist/src/parsers/TextToolCallParser.test.d.ts +0 -1
  169. package/dist/src/parsers/TextToolCallParser.test.js +0 -225
  170. package/dist/src/parsers/TextToolCallParser.test.js.map +0 -1
  171. package/dist/src/prompt-config/TemplateEngine.test.d.ts +0 -1
  172. package/dist/src/prompt-config/TemplateEngine.test.js +0 -494
  173. package/dist/src/prompt-config/TemplateEngine.test.js.map +0 -1
  174. package/dist/src/prompt-config/prompt-cache.test.d.ts +0 -6
  175. package/dist/src/prompt-config/prompt-cache.test.js +0 -437
  176. package/dist/src/prompt-config/prompt-cache.test.js.map +0 -1
  177. package/dist/src/prompt-config/prompt-installer.test.d.ts +0 -7
  178. package/dist/src/prompt-config/prompt-installer.test.js +0 -503
  179. package/dist/src/prompt-config/prompt-installer.test.js.map +0 -1
  180. package/dist/src/prompt-config/prompt-loader.test.d.ts +0 -5
  181. package/dist/src/prompt-config/prompt-loader.test.js +0 -413
  182. package/dist/src/prompt-config/prompt-loader.test.js.map +0 -1
  183. package/dist/src/prompt-config/prompt-resolver.test.d.ts +0 -1
  184. package/dist/src/prompt-config/prompt-resolver.test.js +0 -529
  185. package/dist/src/prompt-config/prompt-resolver.test.js.map +0 -1
  186. package/dist/src/prompt-config/prompt-service.test.d.ts +0 -1
  187. package/dist/src/prompt-config/prompt-service.test.js +0 -811
  188. package/dist/src/prompt-config/prompt-service.test.js.map +0 -1
  189. package/dist/src/providers/BaseProvider.test.d.ts +0 -6
  190. package/dist/src/providers/BaseProvider.test.js +0 -472
  191. package/dist/src/providers/BaseProvider.test.js.map +0 -1
  192. package/dist/src/providers/ProviderManager.gemini-switch.test.d.ts +0 -6
  193. package/dist/src/providers/ProviderManager.gemini-switch.test.js +0 -57
  194. package/dist/src/providers/ProviderManager.gemini-switch.test.js.map +0 -1
  195. package/dist/src/providers/ProviderManager.test.d.ts +0 -6
  196. package/dist/src/providers/ProviderManager.test.js +0 -284
  197. package/dist/src/providers/ProviderManager.test.js.map +0 -1
  198. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.d.ts +0 -6
  199. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js +0 -273
  200. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js.map +0 -1
  201. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.d.ts +0 -1
  202. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.js +0 -48
  203. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.js.map +0 -1
  204. package/dist/src/providers/anthropic/AnthropicProvider.test.d.ts +0 -1
  205. package/dist/src/providers/anthropic/AnthropicProvider.test.js +0 -487
  206. package/dist/src/providers/anthropic/AnthropicProvider.test.js.map +0 -1
  207. package/dist/src/providers/gemini/GeminiProvider.integration.test.d.ts +0 -6
  208. package/dist/src/providers/gemini/GeminiProvider.integration.test.js +0 -126
  209. package/dist/src/providers/gemini/GeminiProvider.integration.test.js.map +0 -1
  210. package/dist/src/providers/gemini/GeminiProvider.test.d.ts +0 -6
  211. package/dist/src/providers/gemini/GeminiProvider.test.js +0 -136
  212. package/dist/src/providers/gemini/GeminiProvider.test.js.map +0 -1
  213. package/dist/src/providers/integration/multi-provider.integration.test.d.ts +0 -6
  214. package/dist/src/providers/integration/multi-provider.integration.test.js +0 -308
  215. package/dist/src/providers/integration/multi-provider.integration.test.js.map +0 -1
  216. package/dist/src/providers/openai/ConversationCache.accumTokens.test.d.ts +0 -1
  217. package/dist/src/providers/openai/ConversationCache.accumTokens.test.js +0 -97
  218. package/dist/src/providers/openai/ConversationCache.accumTokens.test.js.map +0 -1
  219. package/dist/src/providers/openai/ConversationCache.test.d.ts +0 -1
  220. package/dist/src/providers/openai/ConversationCache.test.js +0 -113
  221. package/dist/src/providers/openai/ConversationCache.test.js.map +0 -1
  222. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.d.ts +0 -1
  223. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.js +0 -189
  224. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.js.map +0 -1
  225. package/dist/src/providers/openai/OpenAIProvider.integration.test.d.ts +0 -6
  226. package/dist/src/providers/openai/OpenAIProvider.integration.test.js +0 -125
  227. package/dist/src/providers/openai/OpenAIProvider.integration.test.js.map +0 -1
  228. package/dist/src/providers/openai/OpenAIProvider.responses.test.d.ts +0 -1
  229. package/dist/src/providers/openai/OpenAIProvider.responses.test.js +0 -350
  230. package/dist/src/providers/openai/OpenAIProvider.responses.test.js.map +0 -1
  231. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.d.ts +0 -1
  232. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.js +0 -213
  233. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.js.map +0 -1
  234. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.d.ts +0 -1
  235. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js +0 -59
  236. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js.map +0 -1
  237. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.d.ts +0 -6
  238. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js +0 -105
  239. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js.map +0 -1
  240. package/dist/src/providers/openai/OpenAIProvider.switch.test.d.ts +0 -1
  241. package/dist/src/providers/openai/OpenAIProvider.switch.test.js +0 -256
  242. package/dist/src/providers/openai/OpenAIProvider.switch.test.js.map +0 -1
  243. package/dist/src/providers/openai/OpenAIProvider.test.d.ts +0 -16
  244. package/dist/src/providers/openai/OpenAIProvider.test.js +0 -621
  245. package/dist/src/providers/openai/OpenAIProvider.test.js.map +0 -1
  246. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.d.ts +0 -1
  247. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.js +0 -210
  248. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.js.map +0 -1
  249. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.d.ts +0 -1
  250. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.js +0 -65
  251. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.js.map +0 -1
  252. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.d.ts +0 -1
  253. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.js +0 -129
  254. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.js.map +0 -1
  255. package/dist/src/providers/openai/buildResponsesRequest.test.d.ts +0 -1
  256. package/dist/src/providers/openai/buildResponsesRequest.test.js +0 -406
  257. package/dist/src/providers/openai/buildResponsesRequest.test.js.map +0 -1
  258. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.d.ts +0 -1
  259. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.js +0 -50
  260. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.js.map +0 -1
  261. package/dist/src/providers/openai/estimateRemoteTokens.test.d.ts +0 -1
  262. package/dist/src/providers/openai/estimateRemoteTokens.test.js +0 -125
  263. package/dist/src/providers/openai/estimateRemoteTokens.test.js.map +0 -1
  264. package/dist/src/providers/openai/openai-oauth.spec.d.ts +0 -16
  265. package/dist/src/providers/openai/openai-oauth.spec.js +0 -544
  266. package/dist/src/providers/openai/openai-oauth.spec.js.map +0 -1
  267. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.d.ts +0 -1
  268. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.js +0 -192
  269. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.js.map +0 -1
  270. package/dist/src/providers/openai/parseResponsesStream.test.d.ts +0 -1
  271. package/dist/src/providers/openai/parseResponsesStream.test.js +0 -151
  272. package/dist/src/providers/openai/parseResponsesStream.test.js.map +0 -1
  273. package/dist/src/services/fileDiscoveryService.test.d.ts +0 -6
  274. package/dist/src/services/fileDiscoveryService.test.js +0 -143
  275. package/dist/src/services/fileDiscoveryService.test.js.map +0 -1
  276. package/dist/src/services/gitService.test.d.ts +0 -6
  277. package/dist/src/services/gitService.test.js +0 -209
  278. package/dist/src/services/gitService.test.js.map +0 -1
  279. package/dist/src/services/loopDetectionService.test.d.ts +0 -6
  280. package/dist/src/services/loopDetectionService.test.js +0 -484
  281. package/dist/src/services/loopDetectionService.test.js.map +0 -1
  282. package/dist/src/services/shellExecutionService.multibyte.test.d.ts +0 -6
  283. package/dist/src/services/shellExecutionService.multibyte.test.js +0 -72
  284. package/dist/src/services/shellExecutionService.multibyte.test.js.map +0 -1
  285. package/dist/src/services/shellExecutionService.test.d.ts +0 -6
  286. package/dist/src/services/shellExecutionService.test.js +0 -272
  287. package/dist/src/services/shellExecutionService.test.js.map +0 -1
  288. package/dist/src/services/shellExecutionService.windows.multibyte.test.d.ts +0 -6
  289. package/dist/src/services/shellExecutionService.windows.multibyte.test.js +0 -98
  290. package/dist/src/services/shellExecutionService.windows.multibyte.test.js.map +0 -1
  291. package/dist/src/services/shellExecutionService.windows.test.d.ts +0 -6
  292. package/dist/src/services/shellExecutionService.windows.test.js +0 -79
  293. package/dist/src/services/shellExecutionService.windows.test.js.map +0 -1
  294. package/dist/src/services/tool-call-tracker-service.test.d.ts +0 -6
  295. package/dist/src/services/tool-call-tracker-service.test.js +0 -99
  296. package/dist/src/services/tool-call-tracker-service.test.js.map +0 -1
  297. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +0 -6
  298. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +0 -187
  299. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +0 -1
  300. package/dist/src/telemetry/loggers.test.d.ts +0 -6
  301. package/dist/src/telemetry/loggers.test.js +0 -573
  302. package/dist/src/telemetry/loggers.test.js.map +0 -1
  303. package/dist/src/telemetry/metrics.test.d.ts +0 -6
  304. package/dist/src/telemetry/metrics.test.js +0 -212
  305. package/dist/src/telemetry/metrics.test.js.map +0 -1
  306. package/dist/src/telemetry/telemetry.test.d.ts +0 -6
  307. package/dist/src/telemetry/telemetry.test.js +0 -54
  308. package/dist/src/telemetry/telemetry.test.js.map +0 -1
  309. package/dist/src/telemetry/uiTelemetry.test.d.ts +0 -6
  310. package/dist/src/telemetry/uiTelemetry.test.js +0 -518
  311. package/dist/src/telemetry/uiTelemetry.test.js.map +0 -1
  312. package/dist/src/tools/ToolFormatter.test.d.ts +0 -16
  313. package/dist/src/tools/ToolFormatter.test.js +0 -349
  314. package/dist/src/tools/ToolFormatter.test.js.map +0 -1
  315. package/dist/src/tools/ToolFormatter.toResponsesTool.test.d.ts +0 -1
  316. package/dist/src/tools/ToolFormatter.toResponsesTool.test.js +0 -241
  317. package/dist/src/tools/ToolFormatter.toResponsesTool.test.js.map +0 -1
  318. package/dist/src/tools/diffOptions.test.d.ts +0 -6
  319. package/dist/src/tools/diffOptions.test.js +0 -119
  320. package/dist/src/tools/diffOptions.test.js.map +0 -1
  321. package/dist/src/tools/edit.test.d.ts +0 -6
  322. package/dist/src/tools/edit.test.js +0 -689
  323. package/dist/src/tools/edit.test.js.map +0 -1
  324. package/dist/src/tools/glob.test.d.ts +0 -6
  325. package/dist/src/tools/glob.test.js +0 -332
  326. package/dist/src/tools/glob.test.js.map +0 -1
  327. package/dist/src/tools/grep.test.d.ts +0 -6
  328. package/dist/src/tools/grep.test.js +0 -272
  329. package/dist/src/tools/grep.test.js.map +0 -1
  330. package/dist/src/tools/ls.test.d.ts +0 -6
  331. package/dist/src/tools/ls.test.js +0 -357
  332. package/dist/src/tools/ls.test.js.map +0 -1
  333. package/dist/src/tools/mcp-client.test.d.ts +0 -6
  334. package/dist/src/tools/mcp-client.test.js +0 -617
  335. package/dist/src/tools/mcp-client.test.js.map +0 -1
  336. package/dist/src/tools/mcp-tool.test.d.ts +0 -6
  337. package/dist/src/tools/mcp-tool.test.js +0 -501
  338. package/dist/src/tools/mcp-tool.test.js.map +0 -1
  339. package/dist/src/tools/memoryTool.test.d.ts +0 -6
  340. package/dist/src/tools/memoryTool.test.js +0 -266
  341. package/dist/src/tools/memoryTool.test.js.map +0 -1
  342. package/dist/src/tools/modifiable-tool.test.d.ts +0 -6
  343. package/dist/src/tools/modifiable-tool.test.js +0 -193
  344. package/dist/src/tools/modifiable-tool.test.js.map +0 -1
  345. package/dist/src/tools/read-file.test.d.ts +0 -6
  346. package/dist/src/tools/read-file.test.js +0 -319
  347. package/dist/src/tools/read-file.test.js.map +0 -1
  348. package/dist/src/tools/read-many-files.test.d.ts +0 -6
  349. package/dist/src/tools/read-many-files.test.js +0 -644
  350. package/dist/src/tools/read-many-files.test.js.map +0 -1
  351. package/dist/src/tools/shell.multibyte.test.d.ts +0 -6
  352. package/dist/src/tools/shell.multibyte.test.js +0 -75
  353. package/dist/src/tools/shell.multibyte.test.js.map +0 -1
  354. package/dist/src/tools/shell.test.d.ts +0 -6
  355. package/dist/src/tools/shell.test.js +0 -367
  356. package/dist/src/tools/shell.test.js.map +0 -1
  357. package/dist/src/tools/todo-pause.spec.d.ts +0 -6
  358. package/dist/src/tools/todo-pause.spec.js +0 -287
  359. package/dist/src/tools/todo-pause.spec.js.map +0 -1
  360. package/dist/src/tools/todo-read.test.d.ts +0 -6
  361. package/dist/src/tools/todo-read.test.js +0 -162
  362. package/dist/src/tools/todo-read.test.js.map +0 -1
  363. package/dist/src/tools/todo-schemas.test.d.ts +0 -6
  364. package/dist/src/tools/todo-schemas.test.js +0 -341
  365. package/dist/src/tools/todo-schemas.test.js.map +0 -1
  366. package/dist/src/tools/todo-store.test.d.ts +0 -6
  367. package/dist/src/tools/todo-store.test.js +0 -169
  368. package/dist/src/tools/todo-store.test.js.map +0 -1
  369. package/dist/src/tools/todo-write.test.d.ts +0 -6
  370. package/dist/src/tools/todo-write.test.js +0 -226
  371. package/dist/src/tools/todo-write.test.js.map +0 -1
  372. package/dist/src/tools/tool-registry.test.d.ts +0 -6
  373. package/dist/src/tools/tool-registry.test.js +0 -468
  374. package/dist/src/tools/tool-registry.test.js.map +0 -1
  375. package/dist/src/tools/tools.test.d.ts +0 -6
  376. package/dist/src/tools/tools.test.js +0 -117
  377. package/dist/src/tools/tools.test.js.map +0 -1
  378. package/dist/src/tools/web-fetch.integration.test.d.ts +0 -6
  379. package/dist/src/tools/web-fetch.integration.test.js +0 -532
  380. package/dist/src/tools/web-fetch.integration.test.js.map +0 -1
  381. package/dist/src/tools/web-search.test.d.ts +0 -6
  382. package/dist/src/tools/web-search.test.js +0 -230
  383. package/dist/src/tools/web-search.test.js.map +0 -1
  384. package/dist/src/tools/write-file.test.d.ts +0 -6
  385. package/dist/src/tools/write-file.test.js +0 -465
  386. package/dist/src/tools/write-file.test.js.map +0 -1
  387. package/dist/src/utils/bfsFileSearch.test.d.ts +0 -6
  388. package/dist/src/utils/bfsFileSearch.test.js +0 -191
  389. package/dist/src/utils/bfsFileSearch.test.js.map +0 -1
  390. package/dist/src/utils/editCorrector.test.d.ts +0 -6
  391. package/dist/src/utils/editCorrector.test.js +0 -564
  392. package/dist/src/utils/editCorrector.test.js.map +0 -1
  393. package/dist/src/utils/editor.test.d.ts +0 -6
  394. package/dist/src/utils/editor.test.js +0 -445
  395. package/dist/src/utils/editor.test.js.map +0 -1
  396. package/dist/src/utils/environmentContext.test.d.ts +0 -6
  397. package/dist/src/utils/environmentContext.test.js +0 -139
  398. package/dist/src/utils/environmentContext.test.js.map +0 -1
  399. package/dist/src/utils/errorReporting.test.d.ts +0 -6
  400. package/dist/src/utils/errorReporting.test.js +0 -130
  401. package/dist/src/utils/errorReporting.test.js.map +0 -1
  402. package/dist/src/utils/fileUtils.test.d.ts +0 -6
  403. package/dist/src/utils/fileUtils.test.js +0 -363
  404. package/dist/src/utils/fileUtils.test.js.map +0 -1
  405. package/dist/src/utils/filesearch/crawlCache.test.d.ts +0 -6
  406. package/dist/src/utils/filesearch/crawlCache.test.js +0 -103
  407. package/dist/src/utils/filesearch/crawlCache.test.js.map +0 -1
  408. package/dist/src/utils/filesearch/fileSearch.test.d.ts +0 -6
  409. package/dist/src/utils/filesearch/fileSearch.test.js +0 -654
  410. package/dist/src/utils/filesearch/fileSearch.test.js.map +0 -1
  411. package/dist/src/utils/filesearch/ignore.test.d.ts +0 -6
  412. package/dist/src/utils/filesearch/ignore.test.js +0 -57
  413. package/dist/src/utils/filesearch/ignore.test.js.map +0 -1
  414. package/dist/src/utils/filesearch/result-cache.test.d.ts +0 -6
  415. package/dist/src/utils/filesearch/result-cache.test.js +0 -47
  416. package/dist/src/utils/filesearch/result-cache.test.js.map +0 -1
  417. package/dist/src/utils/flashFallback.integration.test.d.ts +0 -6
  418. package/dist/src/utils/flashFallback.integration.test.js +0 -120
  419. package/dist/src/utils/flashFallback.integration.test.js.map +0 -1
  420. package/dist/src/utils/generateContentResponseUtilities.test.d.ts +0 -6
  421. package/dist/src/utils/generateContentResponseUtilities.test.js +0 -273
  422. package/dist/src/utils/generateContentResponseUtilities.test.js.map +0 -1
  423. package/dist/src/utils/getFolderStructure.test.d.ts +0 -6
  424. package/dist/src/utils/getFolderStructure.test.js +0 -282
  425. package/dist/src/utils/getFolderStructure.test.js.map +0 -1
  426. package/dist/src/utils/gitIgnoreParser.test.d.ts +0 -6
  427. package/dist/src/utils/gitIgnoreParser.test.js +0 -154
  428. package/dist/src/utils/gitIgnoreParser.test.js.map +0 -1
  429. package/dist/src/utils/memoryDiscovery.test.d.ts +0 -6
  430. package/dist/src/utils/memoryDiscovery.test.js +0 -181
  431. package/dist/src/utils/memoryDiscovery.test.js.map +0 -1
  432. package/dist/src/utils/memoryImportProcessor.test.d.ts +0 -6
  433. package/dist/src/utils/memoryImportProcessor.test.js +0 -715
  434. package/dist/src/utils/memoryImportProcessor.test.js.map +0 -1
  435. package/dist/src/utils/nextSpeakerChecker.test.d.ts +0 -6
  436. package/dist/src/utils/nextSpeakerChecker.test.js +0 -172
  437. package/dist/src/utils/nextSpeakerChecker.test.js.map +0 -1
  438. package/dist/src/utils/partUtils.test.d.ts +0 -6
  439. package/dist/src/utils/partUtils.test.js +0 -130
  440. package/dist/src/utils/partUtils.test.js.map +0 -1
  441. package/dist/src/utils/paths.test.d.ts +0 -6
  442. package/dist/src/utils/paths.test.js +0 -153
  443. package/dist/src/utils/paths.test.js.map +0 -1
  444. package/dist/src/utils/retry.test.d.ts +0 -6
  445. package/dist/src/utils/retry.test.js +0 -322
  446. package/dist/src/utils/retry.test.js.map +0 -1
  447. package/dist/src/utils/safeJsonStringify.test.d.ts +0 -6
  448. package/dist/src/utils/safeJsonStringify.test.js +0 -61
  449. package/dist/src/utils/safeJsonStringify.test.js.map +0 -1
  450. package/dist/src/utils/sanitization.test.d.ts +0 -6
  451. package/dist/src/utils/sanitization.test.js +0 -81
  452. package/dist/src/utils/sanitization.test.js.map +0 -1
  453. package/dist/src/utils/schemaValidator.test.d.ts +0 -6
  454. package/dist/src/utils/schemaValidator.test.js +0 -146
  455. package/dist/src/utils/schemaValidator.test.js.map +0 -1
  456. package/dist/src/utils/secure-browser-launcher.test.d.ts +0 -6
  457. package/dist/src/utils/secure-browser-launcher.test.js +0 -149
  458. package/dist/src/utils/secure-browser-launcher.test.js.map +0 -1
  459. package/dist/src/utils/shell-utils.shellReplacement.test.d.ts +0 -6
  460. package/dist/src/utils/shell-utils.shellReplacement.test.js +0 -149
  461. package/dist/src/utils/shell-utils.shellReplacement.test.js.map +0 -1
  462. package/dist/src/utils/shell-utils.test.d.ts +0 -6
  463. package/dist/src/utils/shell-utils.test.js +0 -200
  464. package/dist/src/utils/shell-utils.test.js.map +0 -1
  465. package/dist/src/utils/summarizer.test.d.ts +0 -6
  466. package/dist/src/utils/summarizer.test.js +0 -131
  467. package/dist/src/utils/summarizer.test.js.map +0 -1
  468. package/dist/src/utils/systemEncoding.test.d.ts +0 -6
  469. package/dist/src/utils/systemEncoding.test.js +0 -368
  470. package/dist/src/utils/systemEncoding.test.js.map +0 -1
  471. package/dist/src/utils/toolOutputLimiter.test.d.ts +0 -6
  472. package/dist/src/utils/toolOutputLimiter.test.js +0 -164
  473. package/dist/src/utils/toolOutputLimiter.test.js.map +0 -1
  474. package/dist/src/utils/unicodeUtils.test.d.ts +0 -6
  475. package/dist/src/utils/unicodeUtils.test.js +0 -120
  476. package/dist/src/utils/unicodeUtils.test.js.map +0 -1
  477. package/dist/src/utils/user_account.test.d.ts +0 -6
  478. package/dist/src/utils/user_account.test.js +0 -153
  479. package/dist/src/utils/user_account.test.js.map +0 -1
  480. package/dist/src/utils/user_id.test.d.ts +0 -6
  481. package/dist/src/utils/user_id.test.js +0 -21
  482. package/dist/src/utils/user_id.test.js.map +0 -1
  483. package/dist/src/utils/workspaceContext.test.d.ts +0 -6
  484. package/dist/src/utils/workspaceContext.test.js +0 -209
  485. package/dist/src/utils/workspaceContext.test.js.map +0 -1
@@ -1,689 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- /* eslint-disable @typescript-eslint/no-explicit-any */
7
- const mockEnsureCorrectEdit = vi.hoisted(() => vi.fn());
8
- const mockGenerateJson = vi.hoisted(() => vi.fn());
9
- const mockOpenDiff = vi.hoisted(() => vi.fn());
10
- import { IDEConnectionStatus } from '../ide/ide-client.js';
11
- vi.mock('../utils/editCorrector.js', () => ({
12
- ensureCorrectEdit: mockEnsureCorrectEdit,
13
- }));
14
- vi.mock('../core/client.js', () => ({
15
- GeminiClient: vi.fn().mockImplementation(() => ({
16
- generateJson: mockGenerateJson,
17
- })),
18
- }));
19
- vi.mock('../utils/editor.js', () => ({
20
- openDiff: mockOpenDiff,
21
- }));
22
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
23
- import { applyReplacement, EditTool } from './edit.js';
24
- import { ToolConfirmationOutcome } from './tools.js';
25
- import { ToolErrorType } from './tool-error.js';
26
- import path from 'path';
27
- import fs from 'fs';
28
- import os from 'os';
29
- import { ApprovalMode } from '../config/config.js';
30
- import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
31
- describe('EditTool', () => {
32
- let tool;
33
- let tempDir;
34
- let rootDir;
35
- let mockConfig;
36
- let geminiClient;
37
- beforeEach(() => {
38
- vi.restoreAllMocks();
39
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'edit-tool-test-'));
40
- rootDir = path.join(tempDir, 'root');
41
- fs.mkdirSync(rootDir);
42
- geminiClient = {
43
- generateJson: mockGenerateJson, // mockGenerateJson is already defined and hoisted
44
- };
45
- mockConfig = {
46
- getGeminiClient: vi.fn().mockReturnValue(geminiClient),
47
- getTargetDir: () => rootDir,
48
- getApprovalMode: vi.fn(),
49
- setApprovalMode: vi.fn(),
50
- getWorkspaceContext: () => createMockWorkspaceContext(rootDir),
51
- getIdeClient: () => undefined,
52
- getIdeMode: () => false,
53
- getIdeModeFeature: () => false,
54
- // getGeminiConfig: () => ({ apiKey: 'test-api-key' }), // This was not a real Config method
55
- // Add other properties/methods of Config if EditTool uses them
56
- // Minimal other methods to satisfy Config type if needed by EditTool constructor or other direct uses:
57
- getApiKey: () => 'test-api-key',
58
- getModel: () => 'test-model',
59
- getSandbox: () => false,
60
- getDebugMode: () => false,
61
- getQuestion: () => undefined,
62
- getFullContext: () => false,
63
- getToolDiscoveryCommand: () => undefined,
64
- getToolCallCommand: () => undefined,
65
- getMcpServerCommand: () => undefined,
66
- getMcpServers: () => undefined,
67
- getUserAgent: () => 'test-agent',
68
- getUserMemory: () => '',
69
- setUserMemory: vi.fn(),
70
- getLlxprtMdFileCount: () => 0,
71
- setLlxprtMdFileCount: vi.fn(),
72
- getConversationLoggingEnabled: () => false,
73
- getToolRegistry: () => ({}), // Minimal mock for ToolRegistry
74
- };
75
- // Reset mocks before each test
76
- mockConfig.getApprovalMode.mockClear();
77
- // Default to not skipping confirmation
78
- mockConfig.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
79
- // Reset mocks and set default implementation for ensureCorrectEdit
80
- mockEnsureCorrectEdit.mockReset();
81
- mockEnsureCorrectEdit.mockImplementation(async (_, currentContent, params) => {
82
- let occurrences = 0;
83
- if (params.old_string && currentContent) {
84
- // Simple string counting for the mock
85
- let index = currentContent.indexOf(params.old_string);
86
- while (index !== -1) {
87
- occurrences++;
88
- index = currentContent.indexOf(params.old_string, index + 1);
89
- }
90
- }
91
- else if (params.old_string === '') {
92
- occurrences = 0; // Creating a new file
93
- }
94
- return Promise.resolve({ params, occurrences });
95
- });
96
- // Default mock for generateJson to return the snippet unchanged
97
- mockGenerateJson.mockReset();
98
- mockGenerateJson.mockImplementation(async (contents, schema) => {
99
- // The problematic_snippet is the last part of the user's content
100
- const userContent = contents.find((c) => c.role === 'user');
101
- let promptText = '';
102
- if (userContent && userContent.parts) {
103
- promptText = userContent.parts
104
- .filter((p) => typeof p.text === 'string')
105
- .map((p) => p.text)
106
- .join('\n');
107
- }
108
- const snippetMatch = promptText.match(/Problematic target snippet:\n```\n([\s\S]*?)\n```/);
109
- const problematicSnippet = snippetMatch && snippetMatch[1] ? snippetMatch[1] : '';
110
- if (schema.properties?.corrected_target_snippet) {
111
- return Promise.resolve({
112
- corrected_target_snippet: problematicSnippet,
113
- });
114
- }
115
- if (schema.properties?.corrected_new_string) {
116
- // For new_string correction, we might need more sophisticated logic,
117
- // but for now, returning original is a safe default if not specified by a test.
118
- const originalNewStringMatch = promptText.match(/original_new_string \(what was intended to replace original_old_string\):\n```\n([\s\S]*?)\n```/);
119
- const originalNewString = originalNewStringMatch && originalNewStringMatch[1]
120
- ? originalNewStringMatch[1]
121
- : '';
122
- return Promise.resolve({ corrected_new_string: originalNewString });
123
- }
124
- return Promise.resolve({}); // Default empty object if schema doesn't match
125
- });
126
- tool = new EditTool(mockConfig);
127
- });
128
- afterEach(() => {
129
- fs.rmSync(tempDir, { recursive: true, force: true });
130
- });
131
- describe('applyReplacement', () => {
132
- // Test the exported applyReplacement function
133
- it('should return newString if isNewFile is true', () => {
134
- expect(applyReplacement(null, 'old', 'new', true)).toBe('new');
135
- expect(applyReplacement('existing', 'old', 'new', true)).toBe('new');
136
- });
137
- it('should return newString if currentContent is null and oldString is empty (defensive)', () => {
138
- expect(applyReplacement(null, '', 'new', false)).toBe('new');
139
- });
140
- it('should return empty string if currentContent is null and oldString is not empty (defensive)', () => {
141
- expect(applyReplacement(null, 'old', 'new', false)).toBe('');
142
- });
143
- it('should replace oldString with newString in currentContent', () => {
144
- expect(applyReplacement('hello old world old', 'old', 'new', false)).toBe('hello new world new');
145
- });
146
- it('should return currentContent if oldString is empty and not a new file', () => {
147
- expect(applyReplacement('hello world', '', 'new', false)).toBe('hello world');
148
- });
149
- });
150
- describe('validateToolParams', () => {
151
- it('should return null for valid params', () => {
152
- const params = {
153
- file_path: path.join(rootDir, 'test.txt'),
154
- old_string: 'old',
155
- new_string: 'new',
156
- };
157
- // No error should be thrown when building with valid params
158
- expect(() => tool.build(params)).not.toThrow();
159
- });
160
- it('should return error for relative path', () => {
161
- const params = {
162
- file_path: 'test.txt',
163
- old_string: 'old',
164
- new_string: 'new',
165
- };
166
- expect(() => tool.build(params)).toThrow(/File path must be absolute/);
167
- });
168
- it('should return error for path outside root', () => {
169
- const params = {
170
- file_path: path.join(tempDir, 'outside-root.txt'),
171
- old_string: 'old',
172
- new_string: 'new',
173
- };
174
- expect(() => tool.build(params)).toThrow(/File path must be within one of the workspace directories/);
175
- });
176
- });
177
- describe('shouldConfirmExecute', () => {
178
- const testFile = 'edit_me.txt';
179
- let filePath;
180
- beforeEach(() => {
181
- filePath = path.join(rootDir, testFile);
182
- });
183
- it('should return false if params are invalid', async () => {
184
- const params = {
185
- file_path: 'relative.txt',
186
- old_string: 'old',
187
- new_string: 'new',
188
- };
189
- // Invalid params should throw during build
190
- expect(() => tool.build(params)).toThrow(/File path must be absolute/);
191
- });
192
- it('should request confirmation for valid edit', async () => {
193
- fs.writeFileSync(filePath, 'some old content here');
194
- const params = {
195
- file_path: filePath,
196
- old_string: 'old',
197
- new_string: 'new',
198
- };
199
- // ensureCorrectEdit will be called by shouldConfirmExecute
200
- mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 1 });
201
- const invocation = tool.build(params);
202
- const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
203
- expect(confirmation).toEqual(expect.objectContaining({
204
- title: `Confirm Edit: ${testFile}`,
205
- fileName: testFile,
206
- fileDiff: expect.any(String),
207
- }));
208
- });
209
- it('should return false if old_string is not found (ensureCorrectEdit returns 0)', async () => {
210
- fs.writeFileSync(filePath, 'some content here');
211
- const params = {
212
- file_path: filePath,
213
- old_string: 'not_found',
214
- new_string: 'new',
215
- };
216
- mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 0 });
217
- const invocation = tool.build(params);
218
- expect(await invocation.shouldConfirmExecute(new AbortController().signal)).toBe(false);
219
- });
220
- it('should return false if multiple occurrences of old_string are found (ensureCorrectEdit returns > 1)', async () => {
221
- fs.writeFileSync(filePath, 'old old content here');
222
- const params = {
223
- file_path: filePath,
224
- old_string: 'old',
225
- new_string: 'new',
226
- };
227
- mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 2 });
228
- const invocation = tool.build(params);
229
- expect(await invocation.shouldConfirmExecute(new AbortController().signal)).toBe(false);
230
- });
231
- it('should request confirmation for creating a new file (empty old_string)', async () => {
232
- const newFileName = 'new_file.txt';
233
- const newFilePath = path.join(rootDir, newFileName);
234
- const params = {
235
- file_path: newFilePath,
236
- old_string: '',
237
- new_string: 'new file content',
238
- };
239
- // ensureCorrectEdit might not be called if old_string is empty,
240
- // as shouldConfirmExecute handles this for diff generation.
241
- // If it is called, it should return 0 occurrences for a new file.
242
- mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 0 });
243
- const invocation = tool.build(params);
244
- const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
245
- expect(confirmation).toEqual(expect.objectContaining({
246
- title: `Confirm Edit: ${newFileName}`,
247
- fileName: newFileName,
248
- fileDiff: expect.any(String),
249
- }));
250
- });
251
- it('should use corrected params from ensureCorrectEdit for diff generation', async () => {
252
- const originalContent = 'This is the original string to be replaced.';
253
- const originalOldString = 'original string';
254
- const originalNewString = 'new string';
255
- const correctedOldString = 'original string to be replaced'; // More specific
256
- const correctedNewString = 'completely new string'; // Different replacement
257
- const expectedFinalContent = 'This is the completely new string.';
258
- fs.writeFileSync(filePath, originalContent);
259
- const params = {
260
- file_path: filePath,
261
- old_string: originalOldString,
262
- new_string: originalNewString,
263
- };
264
- // The main beforeEach already calls mockEnsureCorrectEdit.mockReset()
265
- // Set a specific mock for this test case
266
- let mockCalled = false;
267
- mockEnsureCorrectEdit.mockImplementationOnce(async (_, content, p, client) => {
268
- mockCalled = true;
269
- expect(content).toBe(originalContent);
270
- expect(p).toBe(params);
271
- expect(client).toBe(geminiClient);
272
- return {
273
- params: {
274
- file_path: filePath,
275
- old_string: correctedOldString,
276
- new_string: correctedNewString,
277
- },
278
- occurrences: 1,
279
- };
280
- });
281
- const invocation = tool.build(params);
282
- const confirmation = (await invocation.shouldConfirmExecute(new AbortController().signal));
283
- expect(mockCalled).toBe(true); // Check if the mock implementation was run
284
- // expect(mockEnsureCorrectEdit).toHaveBeenCalledWith(originalContent, params, expect.anything()); // Keep this commented for now
285
- expect(confirmation).toEqual(expect.objectContaining({
286
- title: `Confirm Edit: ${testFile}`,
287
- fileName: testFile,
288
- }));
289
- // Check that the diff is based on the corrected strings leading to the new state
290
- expect(confirmation.fileDiff).toContain(`-${originalContent}`);
291
- expect(confirmation.fileDiff).toContain(`+${expectedFinalContent}`);
292
- // Verify that applying the correctedOldString and correctedNewString to originalContent
293
- // indeed produces the expectedFinalContent, which is what the diff should reflect.
294
- const patchedContent = originalContent.replace(correctedOldString, // This was the string identified by ensureCorrectEdit for replacement
295
- correctedNewString);
296
- expect(patchedContent).toBe(expectedFinalContent);
297
- });
298
- });
299
- describe('execute', () => {
300
- const testFile = 'execute_me.txt';
301
- let filePath;
302
- beforeEach(() => {
303
- filePath = path.join(rootDir, testFile);
304
- // Default for execute tests, can be overridden
305
- mockEnsureCorrectEdit.mockImplementation(async (_, content, params) => {
306
- let occurrences = 0;
307
- if (params.old_string && content) {
308
- let index = content.indexOf(params.old_string);
309
- while (index !== -1) {
310
- occurrences++;
311
- index = content.indexOf(params.old_string, index + 1);
312
- }
313
- }
314
- else if (params.old_string === '') {
315
- occurrences = 0;
316
- }
317
- return { params, occurrences };
318
- });
319
- });
320
- it('should return error if params are invalid', async () => {
321
- const params = {
322
- file_path: 'relative.txt',
323
- old_string: 'old',
324
- new_string: 'new',
325
- };
326
- // Invalid params should throw during build
327
- expect(() => tool.build(params)).toThrow(/File path must be absolute/);
328
- });
329
- it('should edit an existing file and return diff with fileName', async () => {
330
- const initialContent = 'This is some old text.';
331
- const newContent = 'This is some new text.'; // old -> new
332
- fs.writeFileSync(filePath, initialContent, 'utf8');
333
- const params = {
334
- file_path: filePath,
335
- old_string: 'old',
336
- new_string: 'new',
337
- };
338
- // Specific mock for this test's execution path in calculateEdit
339
- // ensureCorrectEdit is NOT called by calculateEdit, only by shouldConfirmExecute
340
- // So, the default mockEnsureCorrectEdit should correctly return 1 occurrence for 'old' in initialContent
341
- // Simulate confirmation by setting shouldAlwaysEdit
342
- tool.shouldAlwaysEdit = true;
343
- const invocation = tool.build(params);
344
- const result = await invocation.execute(new AbortController().signal);
345
- tool.shouldAlwaysEdit = false; // Reset for other tests
346
- expect(result.llmContent).toMatch(/Successfully modified file/);
347
- expect(fs.readFileSync(filePath, 'utf8')).toBe(newContent);
348
- const display = result.returnDisplay;
349
- expect(display.fileDiff).toMatch(initialContent);
350
- expect(display.fileDiff).toMatch(newContent);
351
- expect(display.fileName).toBe(testFile);
352
- });
353
- it('should create a new file if old_string is empty and file does not exist, and return created message', async () => {
354
- const newFileName = 'brand_new_file.txt';
355
- const newFilePath = path.join(rootDir, newFileName);
356
- const fileContent = 'Content for the new file.';
357
- const params = {
358
- file_path: newFilePath,
359
- old_string: '',
360
- new_string: fileContent,
361
- };
362
- mockConfig.getApprovalMode.mockReturnValueOnce(ApprovalMode.AUTO_EDIT);
363
- const invocation = tool.build(params);
364
- const result = await invocation.execute(new AbortController().signal);
365
- expect(result.llmContent).toMatch(/Created new file/);
366
- expect(fs.existsSync(newFilePath)).toBe(true);
367
- expect(fs.readFileSync(newFilePath, 'utf8')).toBe(fileContent);
368
- expect(result.returnDisplay).toBe(`Created ${newFileName}`);
369
- });
370
- it('should return error if old_string is not found in file', async () => {
371
- fs.writeFileSync(filePath, 'Some content.', 'utf8');
372
- const params = {
373
- file_path: filePath,
374
- old_string: 'nonexistent',
375
- new_string: 'replacement',
376
- };
377
- // The default mockEnsureCorrectEdit will return 0 occurrences for 'nonexistent'
378
- const invocation = tool.build(params);
379
- const result = await invocation.execute(new AbortController().signal);
380
- expect(result.llmContent).toMatch(/0 occurrences found for old_string in/);
381
- expect(result.returnDisplay).toMatch(/Failed to edit, could not find the string to replace./);
382
- });
383
- it('should return error if multiple occurrences of old_string are found', async () => {
384
- fs.writeFileSync(filePath, 'multiple old old strings', 'utf8');
385
- const params = {
386
- file_path: filePath,
387
- old_string: 'old',
388
- new_string: 'new',
389
- };
390
- // The default mockEnsureCorrectEdit will return 2 occurrences for 'old'
391
- const invocation = tool.build(params);
392
- const result = await invocation.execute(new AbortController().signal);
393
- expect(result.llmContent).toMatch(/Expected 1 occurrence but found 2 for old_string in file/);
394
- expect(result.returnDisplay).toMatch(/Failed to edit, expected 1 occurrence but found 2/);
395
- });
396
- it('should successfully replace multiple occurrences when expected_replacements specified', async () => {
397
- fs.writeFileSync(filePath, 'old text old text old text', 'utf8');
398
- const params = {
399
- file_path: filePath,
400
- old_string: 'old',
401
- new_string: 'new',
402
- expected_replacements: 3,
403
- };
404
- // Simulate confirmation by setting shouldAlwaysEdit
405
- tool.shouldAlwaysEdit = true;
406
- const invocation = tool.build(params);
407
- const result = await invocation.execute(new AbortController().signal);
408
- tool.shouldAlwaysEdit = false; // Reset for other tests
409
- expect(result.llmContent).toMatch(/Successfully modified file/);
410
- expect(fs.readFileSync(filePath, 'utf8')).toBe('new text new text new text');
411
- const display = result.returnDisplay;
412
- expect(display.fileDiff).toMatch(/old text old text old text/);
413
- expect(display.fileDiff).toMatch(/new text new text new text/);
414
- expect(display.fileName).toBe(testFile);
415
- });
416
- it('should return error if expected_replacements does not match actual occurrences', async () => {
417
- fs.writeFileSync(filePath, 'old text old text', 'utf8');
418
- const params = {
419
- file_path: filePath,
420
- old_string: 'old',
421
- new_string: 'new',
422
- expected_replacements: 3, // Expecting 3 but only 2 exist
423
- };
424
- const invocation = tool.build(params);
425
- const result = await invocation.execute(new AbortController().signal);
426
- expect(result.llmContent).toMatch(/Expected 3 occurrences but found 2 for old_string in file/);
427
- expect(result.returnDisplay).toMatch(/Failed to edit, expected 3 occurrences but found 2/);
428
- });
429
- it('should return error if trying to create a file that already exists (empty old_string)', async () => {
430
- fs.writeFileSync(filePath, 'Existing content', 'utf8');
431
- const params = {
432
- file_path: filePath,
433
- old_string: '',
434
- new_string: 'new content',
435
- };
436
- const invocation = tool.build(params);
437
- const result = await invocation.execute(new AbortController().signal);
438
- expect(result.llmContent).toMatch(/File already exists, cannot create/);
439
- expect(result.returnDisplay).toMatch(/Attempted to create a file that already exists/);
440
- });
441
- it('should include modification message when proposed content is modified', async () => {
442
- const initialContent = 'This is some old text.';
443
- fs.writeFileSync(filePath, initialContent, 'utf8');
444
- const params = {
445
- file_path: filePath,
446
- old_string: 'old',
447
- new_string: 'new',
448
- modified_by_user: true,
449
- };
450
- mockConfig.getApprovalMode.mockReturnValueOnce(ApprovalMode.AUTO_EDIT);
451
- const invocation = tool.build(params);
452
- const result = await invocation.execute(new AbortController().signal);
453
- expect(result.llmContent).toMatch(/User modified the `new_string` content/);
454
- });
455
- it('should not include modification message when proposed content is not modified', async () => {
456
- const initialContent = 'This is some old text.';
457
- fs.writeFileSync(filePath, initialContent, 'utf8');
458
- const params = {
459
- file_path: filePath,
460
- old_string: 'old',
461
- new_string: 'new',
462
- modified_by_user: false,
463
- };
464
- mockConfig.getApprovalMode.mockReturnValueOnce(ApprovalMode.AUTO_EDIT);
465
- const invocation = tool.build(params);
466
- const result = await invocation.execute(new AbortController().signal);
467
- expect(result.llmContent).not.toMatch(/User modified the `new_string` content/);
468
- });
469
- it('should not include modification message when modified_by_user is not provided', async () => {
470
- const initialContent = 'This is some old text.';
471
- fs.writeFileSync(filePath, initialContent, 'utf8');
472
- const params = {
473
- file_path: filePath,
474
- old_string: 'old',
475
- new_string: 'new',
476
- };
477
- mockConfig.getApprovalMode.mockReturnValueOnce(ApprovalMode.AUTO_EDIT);
478
- const invocation = tool.build(params);
479
- const result = await invocation.execute(new AbortController().signal);
480
- expect(result.llmContent).not.toMatch(/User modified the `new_string` content/);
481
- });
482
- it('should return error if old_string and new_string are identical', async () => {
483
- const initialContent = 'This is some identical text.';
484
- fs.writeFileSync(filePath, initialContent, 'utf8');
485
- const params = {
486
- file_path: filePath,
487
- old_string: 'identical',
488
- new_string: 'identical',
489
- };
490
- const invocation = tool.build(params);
491
- const result = await invocation.execute(new AbortController().signal);
492
- expect(result.llmContent).toMatch(/No changes to apply/);
493
- expect(result.returnDisplay).toMatch(/No changes to apply/);
494
- });
495
- });
496
- describe('Error Scenarios', () => {
497
- const testFile = 'error_test.txt';
498
- let filePath;
499
- beforeEach(() => {
500
- filePath = path.join(rootDir, testFile);
501
- });
502
- it('should return FILE_NOT_FOUND error', async () => {
503
- const params = {
504
- file_path: filePath,
505
- old_string: 'any',
506
- new_string: 'new',
507
- };
508
- const invocation = tool.build(params);
509
- const result = await invocation.execute(new AbortController().signal);
510
- expect(result.error?.type).toBe(ToolErrorType.FILE_NOT_FOUND);
511
- });
512
- it('should return ATTEMPT_TO_CREATE_EXISTING_FILE error', async () => {
513
- fs.writeFileSync(filePath, 'existing content', 'utf8');
514
- const params = {
515
- file_path: filePath,
516
- old_string: '',
517
- new_string: 'new content',
518
- };
519
- const invocation = tool.build(params);
520
- const result = await invocation.execute(new AbortController().signal);
521
- expect(result.error?.type).toBe(ToolErrorType.ATTEMPT_TO_CREATE_EXISTING_FILE);
522
- });
523
- it('should return NO_OCCURRENCE_FOUND error', async () => {
524
- fs.writeFileSync(filePath, 'content', 'utf8');
525
- const params = {
526
- file_path: filePath,
527
- old_string: 'not-found',
528
- new_string: 'new',
529
- };
530
- const invocation = tool.build(params);
531
- const result = await invocation.execute(new AbortController().signal);
532
- expect(result.error?.type).toBe(ToolErrorType.EDIT_NO_OCCURRENCE_FOUND);
533
- });
534
- it('should return EXPECTED_OCCURRENCE_MISMATCH error', async () => {
535
- fs.writeFileSync(filePath, 'one one two', 'utf8');
536
- const params = {
537
- file_path: filePath,
538
- old_string: 'one',
539
- new_string: 'new',
540
- expected_replacements: 3,
541
- };
542
- const invocation = tool.build(params);
543
- const result = await invocation.execute(new AbortController().signal);
544
- expect(result.error?.type).toBe(ToolErrorType.EDIT_EXPECTED_OCCURRENCE_MISMATCH);
545
- });
546
- it('should return NO_CHANGE error', async () => {
547
- fs.writeFileSync(filePath, 'content', 'utf8');
548
- const params = {
549
- file_path: filePath,
550
- old_string: 'content',
551
- new_string: 'content',
552
- };
553
- const invocation = tool.build(params);
554
- const result = await invocation.execute(new AbortController().signal);
555
- expect(result.error?.type).toBe(ToolErrorType.EDIT_NO_CHANGE);
556
- });
557
- it('should return INVALID_PARAMETERS error for relative path', async () => {
558
- const params = {
559
- file_path: 'relative/path.txt',
560
- old_string: 'a',
561
- new_string: 'b',
562
- };
563
- // Invalid params should throw during build
564
- expect(() => tool.build(params)).toThrow(/File path must be absolute/);
565
- });
566
- it('should return FILE_WRITE_FAILURE on write error', async () => {
567
- fs.writeFileSync(filePath, 'content', 'utf8');
568
- // Make file readonly to trigger a write error
569
- fs.chmodSync(filePath, '444');
570
- const params = {
571
- file_path: filePath,
572
- old_string: 'content',
573
- new_string: 'new content',
574
- };
575
- const invocation = tool.build(params);
576
- const result = await invocation.execute(new AbortController().signal);
577
- expect(result.error?.type).toBe(ToolErrorType.FILE_WRITE_FAILURE);
578
- });
579
- });
580
- describe('getDescription', () => {
581
- it('should return "No file changes to..." if old_string and new_string are the same', () => {
582
- const testFileName = 'test.txt';
583
- const params = {
584
- file_path: path.join(rootDir, testFileName),
585
- old_string: 'identical_string',
586
- new_string: 'identical_string',
587
- };
588
- // shortenPath will be called internally, resulting in just the file name
589
- const invocation = tool.build(params);
590
- expect(invocation.getDescription()).toBe(`No file changes to ${testFileName}`);
591
- });
592
- it('should return a snippet of old and new strings if they are different', () => {
593
- const testFileName = 'test.txt';
594
- const params = {
595
- file_path: path.join(rootDir, testFileName),
596
- old_string: 'this is the old string value',
597
- new_string: 'this is the new string value',
598
- };
599
- // shortenPath will be called internally, resulting in just the file name
600
- // The snippets are truncated at 30 chars + '...'
601
- const invocation = tool.build(params);
602
- expect(invocation.getDescription()).toBe(`${testFileName}: this is the old string value => this is the new string value`);
603
- });
604
- it('should handle very short strings correctly in the description', () => {
605
- const testFileName = 'short.txt';
606
- const params = {
607
- file_path: path.join(rootDir, testFileName),
608
- old_string: 'old',
609
- new_string: 'new',
610
- };
611
- const invocation = tool.build(params);
612
- expect(invocation.getDescription()).toBe(`${testFileName}: old => new`);
613
- });
614
- it('should truncate long strings in the description', () => {
615
- const testFileName = 'long.txt';
616
- const params = {
617
- file_path: path.join(rootDir, testFileName),
618
- old_string: 'this is a very long old string that will definitely be truncated',
619
- new_string: 'this is a very long new string that will also be truncated',
620
- };
621
- const invocation = tool.build(params);
622
- expect(invocation.getDescription()).toBe(`${testFileName}: this is a very long old string... => this is a very long new string...`);
623
- });
624
- });
625
- describe('workspace boundary validation', () => {
626
- it('should validate paths are within workspace root', () => {
627
- const validPath = {
628
- file_path: path.join(rootDir, 'file.txt'),
629
- old_string: 'old',
630
- new_string: 'new',
631
- };
632
- // Valid params should not throw
633
- expect(() => tool.build(validPath)).not.toThrow();
634
- });
635
- it('should reject paths outside workspace root', () => {
636
- const invalidPath = {
637
- file_path: '/etc/passwd',
638
- old_string: 'root',
639
- new_string: 'hacked',
640
- };
641
- expect(() => tool.build(invalidPath)).toThrow(/File path must be within one of the workspace directories/);
642
- });
643
- });
644
- describe('IDE mode', () => {
645
- const testFile = 'edit_me.txt';
646
- let filePath;
647
- let ideClient;
648
- beforeEach(() => {
649
- filePath = path.join(rootDir, testFile);
650
- ideClient = {
651
- openDiff: vi.fn(),
652
- getConnectionStatus: vi.fn().mockReturnValue({
653
- status: IDEConnectionStatus.Connected,
654
- }),
655
- };
656
- mockConfig.getIdeMode = () => true;
657
- mockConfig.getIdeModeFeature = () => true;
658
- mockConfig.getIdeClient = () => ideClient;
659
- });
660
- it('should call ideClient.openDiff and update params on confirmation', async () => {
661
- const initialContent = 'some old content here';
662
- const newContent = 'some new content here';
663
- const modifiedContent = 'some modified content here';
664
- fs.writeFileSync(filePath, initialContent);
665
- const params = {
666
- file_path: filePath,
667
- old_string: 'old',
668
- new_string: 'new',
669
- };
670
- mockEnsureCorrectEdit.mockResolvedValueOnce({
671
- params: { ...params, old_string: 'old', new_string: 'new' },
672
- occurrences: 1,
673
- });
674
- ideClient.openDiff.mockResolvedValueOnce({
675
- status: 'accepted',
676
- content: modifiedContent,
677
- });
678
- const invocation = tool.build(params);
679
- const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
680
- expect(ideClient.openDiff).toHaveBeenCalledWith(filePath, newContent);
681
- if (confirmation && 'onConfirm' in confirmation) {
682
- await confirmation.onConfirm(ToolConfirmationOutcome.ProceedOnce);
683
- }
684
- expect(params.old_string).toBe(initialContent);
685
- expect(params.new_string).toBe(modifiedContent);
686
- });
687
- });
688
- });
689
- //# sourceMappingURL=edit.test.js.map