@alumbwe/anvil 1.0.41 → 1.0.49

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 (241) hide show
  1. package/bin/anvil.js +18 -0
  2. package/package.json +13 -6
  3. package/src/agents/bundled-agents.generated.ts +1 -1
  4. package/src/entry.ts +5 -0
  5. package/src/index.tsx +27 -4
  6. package/src/login/plain-login.ts +60 -0
  7. package/src/login/supabase-auth.ts +346 -0
  8. package/src/pre-init/client-env.ts +17 -0
  9. package/src/utils/anvil-client.ts +4 -0
  10. package/src/utils/auth.ts +16 -4
  11. package/src/utils/client-env-defaults.ts +28 -0
  12. package/src/utils/config-dir.ts +1 -1
  13. package/vendor/@anvil/common/src/constants/deepseek-direct.ts +30 -1
  14. package/vendor/@anvil/common/src/util/project-ignore.ts +4 -3
  15. package/vendor/@anvil/sdk/dist/index.cjs +46 -10
  16. package/vendor/@anvil/sdk/dist/index.mjs +46 -10
  17. package/src/commands/__tests__/anvil-command-aliases.test.ts +0 -56
  18. package/src/commands/__tests__/bash-command.test.ts +0 -445
  19. package/src/commands/__tests__/command-args.test.ts +0 -349
  20. package/src/commands/__tests__/copy-conversation-clipboard.test.ts +0 -108
  21. package/src/commands/__tests__/copy-conversation.test.ts +0 -226
  22. package/src/commands/__tests__/diagnostics-command.test.ts +0 -35
  23. package/src/commands/__tests__/image.test.ts +0 -99
  24. package/src/commands/__tests__/init.test.ts +0 -456
  25. package/src/commands/__tests__/new-command-rotates-chat.test.ts +0 -91
  26. package/src/commands/__tests__/process-diagnostics.test.ts +0 -54
  27. package/src/commands/__tests__/prompt-builders.test.ts +0 -28
  28. package/src/commands/__tests__/router-input.test.ts +0 -298
  29. package/src/components/__tests__/ad-banner.test.tsx +0 -83
  30. package/src/components/__tests__/anvil-landing-heading-row.test.tsx +0 -91
  31. package/src/components/__tests__/anvil-model-selector.test.tsx +0 -519
  32. package/src/components/__tests__/anvil-offer-invariants.test.ts +0 -54
  33. package/src/components/__tests__/anvil-takeover-prompt.test.tsx +0 -212
  34. package/src/components/__tests__/chat-input-bar.test.tsx +0 -130
  35. package/src/components/__tests__/grid-layout.integration.test.tsx +0 -304
  36. package/src/components/__tests__/grid-layout.test.tsx +0 -1051
  37. package/src/components/__tests__/message-block.completion.test.tsx +0 -104
  38. package/src/components/__tests__/message-block.streaming.test.tsx +0 -78
  39. package/src/components/__tests__/message-with-agents.test.tsx +0 -579
  40. package/src/components/__tests__/multiline-input.test.tsx +0 -1132
  41. package/src/components/__tests__/queue-panel.test.tsx +0 -398
  42. package/src/components/__tests__/selectable-list.test.ts +0 -232
  43. package/src/components/__tests__/status-bar.test.tsx +0 -44
  44. package/src/components/__tests__/status-indicator.test.tsx +0 -204
  45. package/src/components/__tests__/terminal-thinking-orb.test.tsx +0 -111
  46. package/src/components/__tests__/user-error-banner.test.tsx +0 -102
  47. package/src/components/ask-user/__tests__/multiple-choice-form.test.ts +0 -432
  48. package/src/components/ask-user/__tests__/validation.test.ts +0 -213
  49. package/src/components/tools/__tests__/apply-patch.test.tsx +0 -84
  50. package/src/components/tools/__tests__/code-search.test.tsx +0 -45
  51. package/src/components/tools/__tests__/gravity-index.test.ts +0 -76
  52. package/src/components/tools/__tests__/render-ui.test.tsx +0 -92
  53. package/src/components/tools/__tests__/run-terminal-command.test.ts +0 -233
  54. package/src/contexts/__tests__/chat-runtime-context.test.tsx +0 -149
  55. package/src/data/slash-commands.test.ts +0 -24
  56. package/src/hooks/__tests__/holds-live-anvil-slot.test.ts +0 -49
  57. package/src/hooks/__tests__/session-fetch-signal.test.ts +0 -63
  58. package/src/hooks/__tests__/use-activity-query.test.ts +0 -1000
  59. package/src/hooks/__tests__/use-ask-user-bridge.test.ts +0 -176
  60. package/src/hooks/__tests__/use-auth-query.test.ts +0 -21
  61. package/src/hooks/__tests__/use-chat-input-remount.test.tsx +0 -66
  62. package/src/hooks/__tests__/use-clipboard.test.tsx +0 -73
  63. package/src/hooks/__tests__/use-connection-status.test.ts +0 -112
  64. package/src/hooks/__tests__/use-directory-browser.test.ts +0 -203
  65. package/src/hooks/__tests__/use-gravity-ad.test.ts +0 -73
  66. package/src/hooks/__tests__/use-grid-layout.test.ts +0 -349
  67. package/src/hooks/__tests__/use-input-history.test.ts +0 -699
  68. package/src/hooks/__tests__/use-message-queue-editing.test.tsx +0 -209
  69. package/src/hooks/__tests__/use-message-queue.test.tsx +0 -71
  70. package/src/hooks/__tests__/use-path-tab-completion.test.ts +0 -315
  71. package/src/hooks/__tests__/use-queue-controls.test.ts +0 -68
  72. package/src/hooks/__tests__/use-queue-ui.test.tsx +0 -83
  73. package/src/hooks/__tests__/use-searchable-list.test.ts +0 -359
  74. package/src/hooks/__tests__/use-send-message-timer.test.ts +0 -146
  75. package/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +0 -361
  76. package/src/hooks/__tests__/use-suggestion-engine.test.ts +0 -485
  77. package/src/hooks/__tests__/use-terminal-focus.test.ts +0 -66
  78. package/src/hooks/__tests__/use-terminal-layout.test.ts +0 -675
  79. package/src/hooks/__tests__/use-timeout.test.ts +0 -330
  80. package/src/hooks/__tests__/use-usage-query.test.ts +0 -502
  81. package/src/hooks/__tests__/use-user-details-query.test.ts +0 -195
  82. package/src/hooks/helpers/__tests__/send-message.test.ts +0 -1918
  83. package/src/init/__tests__/init-direnv.test.ts +0 -526
  84. package/src/state/__tests__/chat-store-focus.test.ts +0 -22
  85. package/src/state/__tests__/feedback-store.test.ts +0 -257
  86. package/src/utils/__tests__/active-run.test.ts +0 -140
  87. package/src/utils/__tests__/activity-tracker.test.ts +0 -440
  88. package/src/utils/__tests__/agent-display.test.ts +0 -139
  89. package/src/utils/__tests__/analytics-client.test.ts +0 -262
  90. package/src/utils/__tests__/anonymous-id.test.ts +0 -74
  91. package/src/utils/__tests__/anvil-api.test.ts +0 -578
  92. package/src/utils/__tests__/anvil-instance-owner.test.ts +0 -69
  93. package/src/utils/__tests__/anvil-model-navigation.test.ts +0 -102
  94. package/src/utils/__tests__/anvil-premium-reset.test.ts +0 -79
  95. package/src/utils/__tests__/anvil-referral-cache.test.ts +0 -116
  96. package/src/utils/__tests__/anvil-session-api.test.ts +0 -215
  97. package/src/utils/__tests__/anvil-session-display.test.ts +0 -23
  98. package/src/utils/__tests__/anvil-streak-line.test.ts +0 -217
  99. package/src/utils/__tests__/arrays.test.ts +0 -264
  100. package/src/utils/__tests__/bash-context-processor.test.ts +0 -38
  101. package/src/utils/__tests__/block-processor.test.ts +0 -810
  102. package/src/utils/__tests__/chat-history.test.ts +0 -203
  103. package/src/utils/__tests__/chat-input-key-intercept.test.ts +0 -40
  104. package/src/utils/__tests__/chat-meta.test.ts +0 -130
  105. package/src/utils/__tests__/clipboard-linux.test.ts +0 -359
  106. package/src/utils/__tests__/clipboard.test.ts +0 -910
  107. package/src/utils/__tests__/code-search-summary.test.ts +0 -84
  108. package/src/utils/__tests__/collapse-helpers.test.ts +0 -1109
  109. package/src/utils/__tests__/error-handling.test.ts +0 -658
  110. package/src/utils/__tests__/exit-cleanly.test.ts +0 -110
  111. package/src/utils/__tests__/feedback-helpers.test.ts +0 -444
  112. package/src/utils/__tests__/feedback-submission.test.ts +0 -26
  113. package/src/utils/__tests__/fetch-usage.test.ts +0 -355
  114. package/src/utils/__tests__/fingerprint.test.ts +0 -144
  115. package/src/utils/__tests__/fixtures/terminal-command-broker-child.ts +0 -7
  116. package/src/utils/__tests__/fixtures/terminal-command-broker-entry.ts +0 -3
  117. package/src/utils/__tests__/fixtures/terminal-command-broker-owner.ts +0 -33
  118. package/src/utils/__tests__/format-elapsed-time.test.ts +0 -103
  119. package/src/utils/__tests__/format-timeout.test.ts +0 -87
  120. package/src/utils/__tests__/image-dimensions.test.ts +0 -249
  121. package/src/utils/__tests__/image-processor.test.ts +0 -209
  122. package/src/utils/__tests__/implementor-helpers.test.ts +0 -1458
  123. package/src/utils/__tests__/keyboard-actions.test.ts +0 -660
  124. package/src/utils/__tests__/layout-helpers.test.ts +0 -36
  125. package/src/utils/__tests__/lazy-response-ads.test.ts +0 -167
  126. package/src/utils/__tests__/log-shipper.test.ts +0 -53
  127. package/src/utils/__tests__/markdown-renderer.test.tsx +0 -421
  128. package/src/utils/__tests__/message-block-helpers.test.ts +0 -1263
  129. package/src/utils/__tests__/message-updater.test.ts +0 -645
  130. package/src/utils/__tests__/osc-timeout-scenarios.test.ts +0 -172
  131. package/src/utils/__tests__/pending-attachments.test.ts +0 -277
  132. package/src/utils/__tests__/polling-backoff.test.ts +0 -51
  133. package/src/utils/__tests__/queue-panel-actions.test.ts +0 -148
  134. package/src/utils/__tests__/run-state-storage.test.ts +0 -919
  135. package/src/utils/__tests__/safe-json.test.ts +0 -77
  136. package/src/utils/__tests__/sdk-event-handlers.test.ts +0 -685
  137. package/src/utils/__tests__/send-message-helpers.test.ts +0 -1898
  138. package/src/utils/__tests__/send-message-timer.test.ts +0 -64
  139. package/src/utils/__tests__/settings.test.ts +0 -99
  140. package/src/utils/__tests__/strings.test.ts +0 -192
  141. package/src/utils/__tests__/terminal-color-detection.test.ts +0 -425
  142. package/src/utils/__tests__/terminal-command-broker.test.ts +0 -528
  143. package/src/utils/__tests__/terminal-enter-detection.test.ts +0 -77
  144. package/src/utils/__tests__/terminal-io.test.ts +0 -137
  145. package/src/utils/__tests__/terminal-protocol-controller.test.ts +0 -119
  146. package/src/utils/__tests__/text-layout.test.ts +0 -82
  147. package/src/utils/__tests__/theme-platform-detection.test.ts +0 -125
  148. package/src/utils/__tests__/think-tag-parser.test.ts +0 -159
  149. package/src/utils/__tests__/trace-writer.test.ts +0 -223
  150. package/src/utils/__tests__/trim-chat-logs.test.ts +0 -78
  151. package/src/utils/__tests__/usage-banner-state.test.ts +0 -298
  152. package/src/utils/__tests__/validation-error-formatting.test.ts +0 -126
  153. package/src/utils/__tests__/windows-terminal-health.test.ts +0 -101
  154. package/src/utils/__tests__/write-file-atomic.test.ts +0 -127
  155. package/vendor/@anvil/common/src/__tests__/agent-validation.test.ts +0 -846
  156. package/vendor/@anvil/common/src/__tests__/anvil-model-availability.test.ts +0 -101
  157. package/vendor/@anvil/common/src/__tests__/anvil-models.test.ts +0 -1408
  158. package/vendor/@anvil/common/src/__tests__/anvil-public-data-use-copy.test.ts +0 -258
  159. package/vendor/@anvil/common/src/__tests__/anvil-referral-tiers.test.ts +0 -48
  160. package/vendor/@anvil/common/src/__tests__/anvil-spend-ceilings.test.ts +0 -282
  161. package/vendor/@anvil/common/src/__tests__/anvil-trust.test.ts +0 -526
  162. package/vendor/@anvil/common/src/__tests__/deepseek-direct.test.ts +0 -68
  163. package/vendor/@anvil/common/src/__tests__/disposable-email.test.ts +0 -132
  164. package/vendor/@anvil/common/src/__tests__/dynamic-agent-template-schema.test.ts +0 -422
  165. package/vendor/@anvil/common/src/__tests__/env-ci.test.ts +0 -167
  166. package/vendor/@anvil/common/src/__tests__/env-process.test.ts +0 -145
  167. package/vendor/@anvil/common/src/__tests__/foreign-client-shipped-agents.test.ts +0 -234
  168. package/vendor/@anvil/common/src/__tests__/foreign-client-signals.test.ts +0 -379
  169. package/vendor/@anvil/common/src/__tests__/free-agents.test.ts +0 -807
  170. package/vendor/@anvil/common/src/__tests__/gravity-capi.test.ts +0 -154
  171. package/vendor/@anvil/common/src/__tests__/handlesteps-parsing.test.ts +0 -246
  172. package/vendor/@anvil/common/src/__tests__/kimi-k3-god-only.test.ts +0 -77
  173. package/vendor/@anvil/common/src/__tests__/model-config.test.ts +0 -89
  174. package/vendor/@anvil/common/src/__tests__/project-file-tree.test.ts +0 -298
  175. package/vendor/@anvil/common/src/__tests__/provisioned-model-tiers.test.ts +0 -116
  176. package/vendor/@anvil/common/src/__tests__/reasoning-effort.test.ts +0 -167
  177. package/vendor/@anvil/common/src/__tests__/reddit-capi.test.ts +0 -132
  178. package/vendor/@anvil/common/src/__tests__/response-ad-positions.test.ts +0 -72
  179. package/vendor/@anvil/common/src/__tests__/user-state.test.ts +0 -30
  180. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding-gate.test.ts +0 -63
  181. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding.test.ts +0 -246
  182. package/vendor/@anvil/common/src/constants/__tests__/cf-worker-signals.test.ts +0 -106
  183. package/vendor/@anvil/common/src/testing/TESTING_PATTERNS.md +0 -351
  184. package/vendor/@anvil/common/src/testing/anvil-offer-invariants.ts +0 -169
  185. package/vendor/@anvil/common/src/testing/errors.ts +0 -33
  186. package/vendor/@anvil/common/src/testing/fixtures/agent-runtime.ts +0 -334
  187. package/vendor/@anvil/common/src/testing/impl/agent-runtime.ts +0 -6
  188. package/vendor/@anvil/common/src/testing/index.ts +0 -84
  189. package/vendor/@anvil/common/src/testing/mock-modules.ts +0 -53
  190. package/vendor/@anvil/common/src/testing/mock-types.ts +0 -123
  191. package/vendor/@anvil/common/src/testing/mocks/analytics.ts +0 -261
  192. package/vendor/@anvil/common/src/testing/mocks/child-process.ts +0 -93
  193. package/vendor/@anvil/common/src/testing/mocks/crypto.ts +0 -218
  194. package/vendor/@anvil/common/src/testing/mocks/database.ts +0 -337
  195. package/vendor/@anvil/common/src/testing/mocks/fetch.ts +0 -219
  196. package/vendor/@anvil/common/src/testing/mocks/filesystem.ts +0 -166
  197. package/vendor/@anvil/common/src/testing/mocks/index.ts +0 -101
  198. package/vendor/@anvil/common/src/testing/mocks/logger.ts +0 -135
  199. package/vendor/@anvil/common/src/testing/mocks/stream.ts +0 -313
  200. package/vendor/@anvil/common/src/testing/mocks/timers.ts +0 -132
  201. package/vendor/@anvil/common/src/testing/mocks/tree-sitter.ts +0 -127
  202. package/vendor/@anvil/common/src/testing/setup.ts +0 -282
  203. package/vendor/@anvil/common/src/tools/__tests__/compile-tool-definitions.test.ts +0 -34
  204. package/vendor/@anvil/common/src/tools/params/__tests__/coerce-to-array.test.ts +0 -213
  205. package/vendor/@anvil/common/src/tools/params/__tests__/read-docs.test.ts +0 -47
  206. package/vendor/@anvil/common/src/tools/params/__tests__/render-ui.test.ts +0 -65
  207. package/vendor/@anvil/common/src/tools/params/tool/__tests__/run-terminal-command-timeout.test.ts +0 -49
  208. package/vendor/@anvil/common/src/types/__tests__/dynamic-agent-template.test.ts +0 -20
  209. package/vendor/@anvil/common/src/util/__tests__/ad-user-agent.test.ts +0 -26
  210. package/vendor/@anvil/common/src/util/__tests__/analytics-dispatcher.test.ts +0 -122
  211. package/vendor/@anvil/common/src/util/__tests__/analytics-log.test.ts +0 -102
  212. package/vendor/@anvil/common/src/util/__tests__/analytics-sampling.test.ts +0 -143
  213. package/vendor/@anvil/common/src/util/__tests__/anvil-streak.test.ts +0 -202
  214. package/vendor/@anvil/common/src/util/__tests__/anvil-usage-summary.test.ts +0 -193
  215. package/vendor/@anvil/common/src/util/__tests__/axiom-only-log.test.ts +0 -140
  216. package/vendor/@anvil/common/src/util/__tests__/client-user-agent.test.ts +0 -148
  217. package/vendor/@anvil/common/src/util/__tests__/engagement-tracker.test.ts +0 -115
  218. package/vendor/@anvil/common/src/util/__tests__/env-file-path.test.ts +0 -57
  219. package/vendor/@anvil/common/src/util/__tests__/error-abort.test.ts +0 -774
  220. package/vendor/@anvil/common/src/util/__tests__/error-api-details.test.ts +0 -206
  221. package/vendor/@anvil/common/src/util/__tests__/file-read-limits.test.ts +0 -173
  222. package/vendor/@anvil/common/src/util/__tests__/format-code-search.test.ts +0 -60
  223. package/vendor/@anvil/common/src/util/__tests__/log-mirror.test.ts +0 -31
  224. package/vendor/@anvil/common/src/util/__tests__/messages.test.ts +0 -1252
  225. package/vendor/@anvil/common/src/util/__tests__/partial-json-delta.test.ts +0 -505
  226. package/vendor/@anvil/common/src/util/__tests__/path.test.ts +0 -22
  227. package/vendor/@anvil/common/src/util/__tests__/project-ignore.test.ts +0 -90
  228. package/vendor/@anvil/common/src/util/__tests__/promise.test.ts +0 -325
  229. package/vendor/@anvil/common/src/util/__tests__/rate-limit.test.ts +0 -28
  230. package/vendor/@anvil/common/src/util/__tests__/reddit-anvil-retention.test.ts +0 -130
  231. package/vendor/@anvil/common/src/util/__tests__/saxy.test.ts +0 -1008
  232. package/vendor/@anvil/common/src/util/__tests__/split-data.test.ts +0 -289
  233. package/vendor/@anvil/common/src/util/__tests__/string.test.ts +0 -239
  234. package/vendor/@anvil/common/src/util/__tests__/thread-title.test.ts +0 -70
  235. package/vendor/@anvil/common/src/util/__tests__/tool-result-media-order.test.ts +0 -108
  236. package/vendor/@anvil/common/src/util/__tests__/ttft-histogram.test.ts +0 -180
  237. package/vendor/@anvil/common/src/util/__tests__/with-timeout.test.ts +0 -24
  238. package/vendor/@anvil/common/src/util/__tests__/zoned-time.test.ts +0 -88
  239. package/vendor/@anvil/common/src/util/skills.test.ts +0 -44
  240. package/vendor/@anvil/sdk/dist/index.cjs.map +0 -440
  241. package/vendor/@anvil/sdk/dist/index.mjs.map +0 -440
@@ -1,167 +0,0 @@
1
- import { describe, test, expect, afterEach } from 'bun:test'
2
-
3
- import { getCiEnv, ciEnv, isCI } from '../env-ci'
4
- import { createTestCiEnv } from '../testing-env-ci'
5
-
6
- describe('env-ci', () => {
7
- describe('getCiEnv', () => {
8
- const originalEnv = { ...process.env }
9
-
10
- afterEach(() => {
11
- // Restore original env
12
- Object.keys(process.env).forEach((key) => {
13
- if (!(key in originalEnv)) {
14
- delete process.env[key]
15
- }
16
- })
17
- Object.assign(process.env, originalEnv)
18
- })
19
-
20
- test('returns current process.env values for CI', () => {
21
- process.env.CI = 'true'
22
- const env = getCiEnv()
23
- expect(env.CI).toBe('true')
24
- })
25
-
26
- test('returns current process.env values for GITHUB_ACTIONS', () => {
27
- process.env.GITHUB_ACTIONS = 'true'
28
- const env = getCiEnv()
29
- expect(env.GITHUB_ACTIONS).toBe('true')
30
- })
31
-
32
- test('returns current process.env values for ANVIL_API_KEY', () => {
33
- process.env.ANVIL_API_KEY = 'test-key-123'
34
- const env = getCiEnv()
35
- expect(env.ANVIL_API_KEY).toBe('test-key-123')
36
- })
37
-
38
- test('returns current process.env values for ANVIL_GITHUB_TOKEN', () => {
39
- process.env.ANVIL_GITHUB_TOKEN = 'ghp_test_token'
40
- const env = getCiEnv()
41
- expect(env.ANVIL_GITHUB_TOKEN).toBe('ghp_test_token')
42
- })
43
-
44
- test('returns undefined for unset env vars', () => {
45
- delete process.env.RENDER
46
- const env = getCiEnv()
47
- expect(env.RENDER).toBeUndefined()
48
- })
49
-
50
- test('returns a snapshot that does not change when process.env changes', () => {
51
- process.env.CI = 'true'
52
- const env = getCiEnv()
53
- process.env.CI = 'false'
54
- // The snapshot should still have the old value
55
- expect(env.CI).toBe('true')
56
- })
57
- })
58
-
59
- describe('ciEnv', () => {
60
- test('is a CiEnv object', () => {
61
- expect(ciEnv).toBeDefined()
62
- expect(typeof ciEnv).toBe('object')
63
- })
64
-
65
- test('contains expected keys', () => {
66
- expect('CI' in ciEnv).toBe(true)
67
- expect('GITHUB_ACTIONS' in ciEnv).toBe(true)
68
- expect('ANVIL_API_KEY' in ciEnv).toBe(true)
69
- expect('ANVIL_GITHUB_TOKEN' in ciEnv).toBe(true)
70
- })
71
- })
72
-
73
- describe('isCI', () => {
74
- const originalEnv = { ...process.env }
75
-
76
- afterEach(() => {
77
- // Restore original env
78
- Object.keys(process.env).forEach((key) => {
79
- if (!(key in originalEnv)) {
80
- delete process.env[key]
81
- }
82
- })
83
- Object.assign(process.env, originalEnv)
84
- })
85
-
86
- test('returns true when CI=true', () => {
87
- process.env.CI = 'true'
88
- delete process.env.GITHUB_ACTIONS
89
- expect(isCI()).toBe(true)
90
- })
91
-
92
- test('returns true when CI=1', () => {
93
- process.env.CI = '1'
94
- delete process.env.GITHUB_ACTIONS
95
- expect(isCI()).toBe(true)
96
- })
97
-
98
- test('returns true when GITHUB_ACTIONS=true', () => {
99
- delete process.env.CI
100
- process.env.GITHUB_ACTIONS = 'true'
101
- expect(isCI()).toBe(true)
102
- })
103
-
104
- test('returns false when neither CI nor GITHUB_ACTIONS is set', () => {
105
- delete process.env.CI
106
- delete process.env.GITHUB_ACTIONS
107
- expect(isCI()).toBe(false)
108
- })
109
-
110
- test('returns false when CI=false', () => {
111
- process.env.CI = 'false'
112
- delete process.env.GITHUB_ACTIONS
113
- expect(isCI()).toBe(false)
114
- })
115
- })
116
-
117
- describe('createTestCiEnv', () => {
118
- test('returns a CiEnv with default test values', () => {
119
- const env = createTestCiEnv()
120
- expect(env.ANVIL_API_KEY).toBe('test-api-key')
121
- })
122
-
123
- test('returns undefined for most vars by default', () => {
124
- const env = createTestCiEnv()
125
- expect(env.CI).toBeUndefined()
126
- expect(env.GITHUB_ACTIONS).toBeUndefined()
127
- expect(env.RENDER).toBeUndefined()
128
- expect(env.IS_PULL_REQUEST).toBeUndefined()
129
- expect(env.ANVIL_GITHUB_TOKEN).toBeUndefined()
130
- })
131
-
132
- test('allows overriding specific values', () => {
133
- const env = createTestCiEnv({
134
- CI: 'true',
135
- GITHUB_ACTIONS: 'true',
136
- })
137
- expect(env.CI).toBe('true')
138
- expect(env.GITHUB_ACTIONS).toBe('true')
139
- // Other values should still have defaults
140
- expect(env.ANVIL_API_KEY).toBe('test-api-key')
141
- })
142
-
143
- test('allows overriding default values', () => {
144
- const env = createTestCiEnv({
145
- ANVIL_API_KEY: 'custom-api-key',
146
- })
147
- expect(env.ANVIL_API_KEY).toBe('custom-api-key')
148
- })
149
-
150
- test('allows setting all CI-related vars for CI simulation', () => {
151
- const env = createTestCiEnv({
152
- CI: 'true',
153
- GITHUB_ACTIONS: 'true',
154
- RENDER: 'true',
155
- IS_PULL_REQUEST: 'true',
156
- ANVIL_GITHUB_TOKEN: 'ghp_simulated_token',
157
- ANVIL_API_KEY: 'test-api-key-override',
158
- })
159
- expect(env.CI).toBe('true')
160
- expect(env.GITHUB_ACTIONS).toBe('true')
161
- expect(env.RENDER).toBe('true')
162
- expect(env.IS_PULL_REQUEST).toBe('true')
163
- expect(env.ANVIL_GITHUB_TOKEN).toBe('ghp_simulated_token')
164
- expect(env.ANVIL_API_KEY).toBe('test-api-key-override')
165
- })
166
- })
167
- })
@@ -1,145 +0,0 @@
1
- import { describe, test, expect, afterEach } from 'bun:test'
2
-
3
- import { getProcessEnv, processEnv } from '../env-process'
4
- import { createTestProcessEnv } from '../testing-env-process'
5
-
6
- describe('env-process', () => {
7
- describe('getProcessEnv', () => {
8
- const originalEnv = { ...process.env }
9
-
10
- afterEach(() => {
11
- // Restore original env
12
- Object.keys(process.env).forEach((key) => {
13
- if (!(key in originalEnv)) {
14
- delete process.env[key]
15
- }
16
- })
17
- Object.assign(process.env, originalEnv)
18
- })
19
-
20
- test('returns current process.env values for SHELL', () => {
21
- process.env.SHELL = '/bin/zsh'
22
- const env = getProcessEnv()
23
- expect(env.SHELL).toBe('/bin/zsh')
24
- })
25
-
26
- test('returns current process.env values for HOME', () => {
27
- process.env.HOME = '/Users/testuser'
28
- const env = getProcessEnv()
29
- expect(env.HOME).toBe('/Users/testuser')
30
- })
31
-
32
- test('returns current process.env values for TERM', () => {
33
- process.env.TERM = 'xterm-256color'
34
- const env = getProcessEnv()
35
- expect(env.TERM).toBe('xterm-256color')
36
- })
37
-
38
- test('returns current process.env values for TERM_PROGRAM', () => {
39
- process.env.TERM_PROGRAM = 'iTerm.app'
40
- const env = getProcessEnv()
41
- expect(env.TERM_PROGRAM).toBe('iTerm.app')
42
- })
43
-
44
- test('returns current process.env values for NODE_ENV', () => {
45
- process.env.NODE_ENV = 'development'
46
- const env = getProcessEnv()
47
- expect(env.NODE_ENV).toBe('development')
48
- })
49
-
50
- test('returns undefined for unset env vars', () => {
51
- delete process.env.KITTY_WINDOW_ID
52
- const env = getProcessEnv()
53
- expect(env.KITTY_WINDOW_ID).toBeUndefined()
54
- })
55
-
56
- test('returns current process.env values for ANVIL_IS_BINARY', () => {
57
- process.env.ANVIL_IS_BINARY = 'true'
58
- const env = getProcessEnv()
59
- expect(env.ANVIL_IS_BINARY).toBe('true')
60
- })
61
-
62
- test('returns a snapshot that does not change when process.env changes', () => {
63
- process.env.SHELL = '/bin/bash'
64
- const env = getProcessEnv()
65
- process.env.SHELL = '/bin/zsh'
66
- // The snapshot should still have the old value
67
- expect(env.SHELL).toBe('/bin/bash')
68
- })
69
- })
70
-
71
- describe('processEnv', () => {
72
- test('is a ProcessEnv object', () => {
73
- expect(processEnv).toBeDefined()
74
- expect(typeof processEnv).toBe('object')
75
- })
76
-
77
- test('contains expected keys', () => {
78
- expect('SHELL' in processEnv).toBe(true)
79
- expect('HOME' in processEnv).toBe(true)
80
- expect('TERM' in processEnv).toBe(true)
81
- expect('NODE_ENV' in processEnv).toBe(true)
82
- expect('PATH' in processEnv).toBe(true)
83
- })
84
- })
85
-
86
- describe('createTestProcessEnv', () => {
87
- test('returns a ProcessEnv with default test values', () => {
88
- const env = createTestProcessEnv()
89
- expect(env.HOME).toBe('/home/test')
90
- expect(env.NODE_ENV).toBe('test')
91
- expect(env.TERM).toBe('xterm-256color')
92
- expect(env.PATH).toBe('/usr/bin')
93
- })
94
-
95
- test('returns undefined for most vars by default', () => {
96
- const env = createTestProcessEnv()
97
- expect(env.SHELL).toBeUndefined()
98
- expect(env.COMSPEC).toBeUndefined()
99
- expect(env.TERM_PROGRAM).toBeUndefined()
100
- expect(env.KITTY_WINDOW_ID).toBeUndefined()
101
- expect(env.ANVIL_IS_BINARY).toBeUndefined()
102
- })
103
-
104
- test('allows overriding specific values', () => {
105
- const env = createTestProcessEnv({
106
- SHELL: '/bin/fish',
107
- TERM_PROGRAM: 'vscode',
108
- })
109
- expect(env.SHELL).toBe('/bin/fish')
110
- expect(env.TERM_PROGRAM).toBe('vscode')
111
- // Other values should still have defaults
112
- expect(env.HOME).toBe('/home/test')
113
- expect(env.NODE_ENV).toBe('test')
114
- })
115
-
116
- test('allows overriding default values', () => {
117
- const env = createTestProcessEnv({
118
- HOME: '/custom/home',
119
- NODE_ENV: 'production',
120
- })
121
- expect(env.HOME).toBe('/custom/home')
122
- expect(env.NODE_ENV).toBe('production')
123
- })
124
-
125
- test('allows setting ANVIL_IS_BINARY for binary mode tests', () => {
126
- const env = createTestProcessEnv({
127
- ANVIL_IS_BINARY: 'true',
128
- ANVIL_CLI_VERSION: '1.0.0',
129
- })
130
- expect(env.ANVIL_IS_BINARY).toBe('true')
131
- expect(env.ANVIL_CLI_VERSION).toBe('1.0.0')
132
- })
133
-
134
- test('allows setting terminal-specific vars', () => {
135
- const env = createTestProcessEnv({
136
- TERM_PROGRAM: 'iTerm.app',
137
- KITTY_WINDOW_ID: '12345',
138
- SIXEL_SUPPORT: 'true',
139
- })
140
- expect(env.TERM_PROGRAM).toBe('iTerm.app')
141
- expect(env.KITTY_WINDOW_ID).toBe('12345')
142
- expect(env.SIXEL_SUPPORT).toBe('true')
143
- })
144
- })
145
- })
@@ -1,234 +0,0 @@
1
- import { readdirSync, readFileSync, statSync } from 'node:fs'
2
- import { join, relative } from 'node:path'
3
-
4
- import { describe, expect, test } from 'bun:test'
5
-
6
- import { ANVIL_ROOT_AGENT_IDS } from '../constants/free-agents'
7
- import {
8
- detectForeignAnvilClient,
9
- ANVIL_CUSTOM_TOOL_NAMES,
10
- } from '../constants/foreign-client-signals'
11
-
12
- /**
13
- * Nothing we ship may be mistaken for a third-party client.
14
- *
15
- * The downgrade now runs unconditionally with no flag to disable it, so a
16
- * anvil agent the detector flags is served a different model in production
17
- * with no way to switch it off short of a revert and redeploy. This has already
18
- * happened twice, both silently:
19
- *
20
- * - `researcher-web` offers `['web_search', 'read_url']` and was flagged on
21
- * 100% of its 334,042 requests from 4,821 users over 30 days.
22
- * - `anvil-desktop-autorun` offers only the custom tool `decide`, so it had
23
- * no signature tool at all — 2,904 requests from 41 users.
24
- *
25
- * Both were found by querying production, which is the wrong place to find
26
- * them. This scans the source instead, so the next one fails CI.
27
- *
28
- * Reading source with a regex is crude, and the real hazard is that it quietly
29
- * stops matching and the test passes on an empty set — hence the floor below
30
- * and the named spot checks.
31
- */
32
-
33
- const REPO_ROOT = join(import.meta.dir, '..', '..', '..')
34
-
35
- /** Where agent definitions live. */
36
- const SEARCH_ROOTS = [
37
- 'agents',
38
- '.agents',
39
- 'anvil',
40
- 'anvil-desktop/src',
41
- 'web/src',
42
- 'common/src',
43
- 'sdk/src',
44
- 'cli/src',
45
- ]
46
-
47
- /**
48
- * Definitions that cannot reach the downgrade, with the property that makes
49
- * that true. `mustContain` is the load-bearing part: if the reason stops
50
- * holding, this fails rather than the exclusion silently outliving it.
51
- */
52
- const EXCLUDED: Array<{ path: string; mustContain: string; why: string }> = [
53
- {
54
- path: 'anvil/e2e/agent/anvil-tester.ts',
55
- mustContain: "model: 'anthropic/claude-sonnet-4.5'",
56
- why:
57
- 'e2e harness pinned to a paid Anthropic model. The downgrade only runs ' +
58
- 'on free-mode requests, and a free-mode request for a non-free model is ' +
59
- 'rejected by isFreeModeAllowedAgentModel long before the detector. It ' +
60
- 'also had 0 production requests over 30 days. If it ever moves to a ' +
61
- 'free model this exclusion stops applying and the test says so.',
62
- },
63
- ]
64
-
65
- /**
66
- * The regex only sees literal names. A declaration built at runtime is invisible
67
- * to it, which is precisely how `decide` slipped through — so custom tools are
68
- * asserted separately below rather than assumed covered here.
69
- */
70
- const TOOL_NAMES_DECLARATION = /toolNames:\s*\[([^\]]*)\]/g
71
- const QUOTED_NAME = /'([^']+)'|"([^"]+)"/g
72
-
73
- /** Below this, assume the scan broke rather than that we deleted 20 agents. */
74
- const MINIMUM_DECLARATIONS = 25
75
-
76
- type Declaration = { file: string; names: string[]; ids: string[] }
77
-
78
- function collectSourceFiles(): string[] {
79
- const files: string[] = []
80
- const walk = (dir: string) => {
81
- let entries: string[]
82
- try {
83
- entries = readdirSync(dir)
84
- } catch {
85
- return
86
- }
87
- for (const entry of entries) {
88
- if (entry === 'node_modules' || entry === '.next' || entry === 'dist') {
89
- continue
90
- }
91
- const path = join(dir, entry)
92
- if (statSync(path).isDirectory()) {
93
- walk(path)
94
- continue
95
- }
96
- // Test files carry deliberately-foreign fixtures; they are not shipped.
97
- if (
98
- path.endsWith('.ts') &&
99
- !path.includes('__tests__') &&
100
- !path.endsWith('.test.ts')
101
- ) {
102
- files.push(path)
103
- }
104
- }
105
- }
106
- for (const root of SEARCH_ROOTS) walk(join(REPO_ROOT, root))
107
- return files
108
- }
109
-
110
- function collectDeclarations(): Declaration[] {
111
- const excluded = new Set(EXCLUDED.map((entry) => entry.path))
112
- const declarations: Declaration[] = []
113
- for (const file of collectSourceFiles()) {
114
- const relativePath = relative(REPO_ROOT, file)
115
- if (excluded.has(relativePath)) continue
116
- const source = readFileSync(file, 'utf8')
117
- const ids = [...source.matchAll(/\bid:\s*'([^']+)'/g)].map((m) => m[1]!)
118
- for (const match of source.matchAll(TOOL_NAMES_DECLARATION)) {
119
- const names = [...match[1]!.matchAll(QUOTED_NAME)].map(
120
- (name) => name[1] ?? name[2]!,
121
- )
122
- // Empty declarations are kept, not filtered. `toolNames: []` on a ROOT is
123
- // precisely what the root test below must catch, and dropping it here
124
- // made that test vacuous — a root with an empty toolset simply vanished
125
- // from the scan and the assertion passed over nothing.
126
- declarations.push({ file: relativePath, names, ids })
127
- }
128
- }
129
- return declarations
130
- }
131
-
132
- const DECLARATIONS = collectDeclarations()
133
-
134
- function asToolSchemas(names: string[]) {
135
- return names.map((name) => ({ type: 'function', function: { name } }))
136
- }
137
-
138
- describe('no shipped anvil agent is flagged as a foreign client', () => {
139
- test('the scan actually found our agents', () => {
140
- // Guards the failure mode where a reformat stops the regex matching and
141
- // every assertion below passes over an empty set.
142
- expect(DECLARATIONS.length).toBeGreaterThanOrEqual(MINIMUM_DECLARATIONS)
143
- })
144
-
145
- test.each(DECLARATIONS.map((d): [string, Declaration] => [d.file, d]))(
146
- '%s',
147
- (_file, declaration) => {
148
- const verdict = detectForeignAnvilClient({
149
- tools: asToolSchemas(declaration.names),
150
- })
151
- // Surface the toolset in the failure, since the fix is almost always
152
- // "this agent's tools are all generic — give it a distinctive one, or
153
- // add the missing name back to the signature".
154
- expect({
155
- file: declaration.file,
156
- names: declaration.names,
157
- signal: verdict.signal,
158
- }).toEqual({
159
- file: declaration.file,
160
- names: declaration.names,
161
- signal: null,
162
- })
163
- },
164
- )
165
-
166
- test.each([
167
- ['researcher-web', 'agents/researcher/researcher-web.ts'],
168
- ['desktop autorun', 'anvil-desktop/src/server/services/autorun.ts'],
169
- ['glob-matcher', 'agents/file-explorer/glob-matcher.ts'],
170
- ])('still covers %s, which the scan must not silently drop', (_name, path) => {
171
- // The first two are the agents this test exists because of. The third has
172
- // exactly one signature tool (`glob` is generic, `set_output` is not), so
173
- // it is the closest thing we ship to the failure mode.
174
- expect(DECLARATIONS.some((d) => d.file === path)).toBe(true)
175
- })
176
-
177
- test('every root agent we ship declares tools', () => {
178
- // `root_agent_no_tools` downgrades any ROOT agent request that offers no
179
- // tools, on the grounds that our roots are agentic by definition. A root
180
- // shipped with an empty toolset would therefore have every one of its
181
- // requests downgraded in production, with no flag to turn it off.
182
- const roots = new Set<string>(ANVIL_ROOT_AGENT_IDS)
183
- const shippedRoots = DECLARATIONS.filter((d) =>
184
- d.ids.some((id) => roots.has(id)),
185
- )
186
- // The scan must actually be finding roots, or this passes vacuously.
187
- expect(shippedRoots.length).toBeGreaterThan(0)
188
- // Name the offending file in the failure, since "a root declares no tools"
189
- // is useless without knowing which one.
190
- expect(
191
- shippedRoots
192
- .filter((d) => d.names.length === 0)
193
- .map((d) => `${d.file} (${d.ids.join(', ')})`),
194
- ).toEqual([])
195
- })
196
-
197
- test.each([...ANVIL_CUSTOM_TOOL_NAMES])(
198
- 'custom tool %s clears on its own',
199
- (name) => {
200
- // Custom tools are registered at runtime through customToolDefinitions,
201
- // so the source scan cannot see them. An agent offering one and nothing
202
- // else — which is exactly what desktop autorun does — has no signature
203
- // tool unless it is enumerated.
204
- expect(
205
- detectForeignAnvilClient({ tools: asToolSchemas([name]) }).signal,
206
- ).toBeNull()
207
- },
208
- )
209
-
210
- test('custom tools appended to a real toolset stay cleared', () => {
211
- // How the chat surface composes: base-chat's tools plus per-turn image and
212
- // document tools (anvil/web/src/server/chat/agent.ts). The additions are
213
- // caller-named and arbitrary, so this must not depend on recognising them.
214
- expect(
215
- detectForeignAnvilClient({
216
- tools: asToolSchemas([
217
- 'spawn_agents',
218
- 'gravity_index',
219
- 'render_ui',
220
- 'suggest_followups',
221
- 'read_attached_image_abc123',
222
- 'read_attached_doc_def456',
223
- ]),
224
- }).signal,
225
- ).toBeNull()
226
- })
227
-
228
- test.each(EXCLUDED)('exclusion of $path still holds', (entry) => {
229
- // An exclusion outliving its reason is how a real false positive gets
230
- // waved through, so the reason is asserted rather than just written down.
231
- const source = readFileSync(join(REPO_ROOT, entry.path), 'utf8')
232
- expect(source).toContain(entry.mustContain)
233
- })
234
- })