@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,172 +0,0 @@
1
- import { describe, test, expect } from 'bun:test'
2
-
3
- import {
4
- withTimeout,
5
- getGlobalOscTimeout,
6
- getQueryOscTimeout,
7
- } from '../terminal-color-detection'
8
-
9
- /**
10
- * These tests document the timeout scenarios that could cause users to get stuck.
11
- * They verify that the timeout mechanisms work correctly.
12
- */
13
-
14
- describe('OSC Timeout Protection Scenarios', () => {
15
- describe('Scenario 1: Terminal ignores OSC queries entirely', () => {
16
- test('withTimeout returns fallback value when promise never resolves', async () => {
17
- // Simulate a terminal that ignores the OSC query completely
18
- const neverResolvingPromise = new Promise<string>(() => {
19
- // This promise never resolves, simulating a non-responsive terminal
20
- })
21
-
22
- const startTime = Date.now()
23
- const result = await withTimeout(neverResolvingPromise, 100, 'fallback')
24
- const elapsed = Date.now() - startTime
25
-
26
- expect(result).toBe('fallback')
27
- expect(elapsed).toBeGreaterThanOrEqual(100)
28
- expect(elapsed).toBeLessThan(200) // Should not hang
29
- })
30
-
31
- test('returns null theme when detection hangs', async () => {
32
- const hangingDetection = new Promise<'dark' | 'light' | null>(() => {})
33
-
34
- const result = await withTimeout(hangingDetection, 50, null)
35
- expect(result).toBeNull()
36
- })
37
- })
38
-
39
- describe('Scenario 2: Terminal responds very slowly', () => {
40
- test('withTimeout returns fallback for slow responses', async () => {
41
- const slowPromise = new Promise<string>((resolve) => {
42
- setTimeout(() => resolve('slow-response'), 500)
43
- })
44
-
45
- const result = await withTimeout(slowPromise, 100, 'timeout-fallback')
46
- expect(result).toBe('timeout-fallback')
47
- })
48
-
49
- test('withTimeout returns actual value for responses within timeout', async () => {
50
- const fastPromise = new Promise<string>((resolve) => {
51
- setTimeout(() => resolve('fast-response'), 10)
52
- })
53
-
54
- const result = await withTimeout(fastPromise, 100, 'timeout-fallback')
55
- expect(result).toBe('fast-response')
56
- })
57
- })
58
-
59
- describe('Scenario 3: Timeout hierarchy', () => {
60
- test('global timeout is greater than query timeout', () => {
61
- const queryTimeout = getQueryOscTimeout()
62
- const globalTimeout = getGlobalOscTimeout()
63
-
64
- // Global timeout should be greater than individual query timeout
65
- // to allow for retries and cleanup
66
- expect(globalTimeout).toBeGreaterThan(queryTimeout)
67
- })
68
- })
69
-
70
- describe('Scenario 4: Race conditions in cleanup', () => {
71
- test('multiple timeouts racing dont cause issues', async () => {
72
- // Create multiple promises that might complete at similar times
73
- const promises = Array.from({ length: 10 }, (_, i) =>
74
- withTimeout(
75
- new Promise<number>((resolve) =>
76
- setTimeout(() => resolve(i), Math.random() * 100),
77
- ),
78
- 50,
79
- -1,
80
- ),
81
- )
82
-
83
- const results = await Promise.all(promises)
84
-
85
- // All results should be either the resolved value or the timeout value
86
- for (const result of results) {
87
- expect(typeof result).toBe('number')
88
- }
89
- })
90
-
91
- test('cleanup happens even on timeout', async () => {
92
- // This test verifies that withTimeout properly cleans up its own timeout
93
- // even when the underlying promise doesn't resolve
94
- const neverResolves = new Promise<string>(() => {
95
- // This promise intentionally never resolves
96
- })
97
-
98
- // This should timeout and return the fallback value
99
- const result = await withTimeout(neverResolves, 50, 'timeout')
100
- expect(result).toBe('timeout')
101
-
102
- // Note: withTimeout cleans up its own setTimeout via the finally block
103
- // The underlying promise's resources would need to be cleaned up separately
104
- })
105
- })
106
-
107
- describe('Scenario 5: Subprocess detection safety', () => {
108
- test('global timeout is reasonable for user experience', () => {
109
- const globalTimeout = getGlobalOscTimeout()
110
-
111
- // Users shouldnt wait more than 3 seconds for theme detection
112
- expect(globalTimeout).toBeLessThanOrEqual(3000)
113
-
114
- // But it should be long enough to actually work
115
- expect(globalTimeout).toBeGreaterThanOrEqual(1000)
116
- })
117
-
118
- test('query timeout allows for network latency in SSH scenarios', () => {
119
- const queryTimeout = getQueryOscTimeout()
120
-
121
- // SSH terminals might have up to 200-300ms latency
122
- // Query timeout should accommodate this plus some buffer
123
- expect(queryTimeout).toBeGreaterThanOrEqual(300)
124
- })
125
- })
126
-
127
- describe('Scenario 6: Error handling', () => {
128
- test('rejected promises propagate through withTimeout', async () => {
129
- const rejectingPromise = Promise.reject(new Error('test error'))
130
-
131
- await expect(
132
- withTimeout(rejectingPromise, 100, 'fallback'),
133
- ).rejects.toThrow('test error')
134
- })
135
-
136
- test('timeout value can be any type', async () => {
137
- const hangingPromise = new Promise<{ theme: string }>(() => {})
138
-
139
- const objectResult = await withTimeout(hangingPromise, 50, {
140
- theme: 'default',
141
- })
142
- expect(objectResult).toEqual({ theme: 'default' })
143
-
144
- const hangingPromise2 = new Promise<number[]>(() => {})
145
- const arrayResult = await withTimeout(hangingPromise2, 50, [1, 2, 3])
146
- expect(arrayResult).toEqual([1, 2, 3])
147
- })
148
- })
149
-
150
- describe('Scenario 7: Stacked timeouts (defense in depth)', () => {
151
- test('inner timeout fires before outer timeout', async () => {
152
- const innerPromise = new Promise<string>(() => {})
153
- const innerResult = withTimeout(innerPromise, 30, 'inner-timeout')
154
-
155
- const outerPromise = withTimeout(innerResult, 100, 'outer-timeout')
156
-
157
- const result = await outerPromise
158
- // Inner timeout should fire first
159
- expect(result).toBe('inner-timeout')
160
- })
161
-
162
- test('outer timeout catches if inner timeout fails', async () => {
163
- // Simulate a case where inner timeout mechanism fails
164
- const brokenInnerPromise = new Promise<string>(() => {
165
- // This never resolves, simulating broken inner timeout
166
- })
167
-
168
- const result = await withTimeout(brokenInnerPromise, 50, 'outer-saved-us')
169
- expect(result).toBe('outer-saved-us')
170
- })
171
- })
172
- })
@@ -1,277 +0,0 @@
1
- import { describe, test, expect, beforeEach, afterEach } from 'bun:test'
2
-
3
- import { useChatStore } from '../../state/chat-store'
4
- import type { PendingImageAttachment } from '../../types/store'
5
- import {
6
- addClipboardPlaceholder,
7
- addPendingImageFromBase64,
8
- addPendingImageWithError,
9
- capturePendingAttachments,
10
- } from '../pending-attachments'
11
-
12
- /** Helper to get only image attachments from the unified pendingAttachments array */
13
- function getPendingImages(): PendingImageAttachment[] {
14
- return useChatStore
15
- .getState()
16
- .pendingAttachments.filter(
17
- (att): att is PendingImageAttachment => att.kind === 'image',
18
- )
19
- }
20
-
21
- describe('pending-attachments', () => {
22
- beforeEach(() => {
23
- // Reset the store before each test
24
- useChatStore.getState().clearPendingAttachments()
25
- })
26
-
27
- afterEach(() => {
28
- useChatStore.getState().clearPendingAttachments()
29
- })
30
-
31
- describe('addClipboardPlaceholder', () => {
32
- test('creates placeholder with processing status', () => {
33
- const placeholderPath = addClipboardPlaceholder()
34
-
35
- const pendingImages = getPendingImages()
36
- expect(pendingImages).toHaveLength(1)
37
- expect(pendingImages[0].path).toBe(placeholderPath)
38
- expect(pendingImages[0].status).toBe('processing')
39
- expect(pendingImages[0].filename).toBe('clipboard image')
40
- })
41
-
42
- test('generates unique placeholder paths', () => {
43
- const path1 = addClipboardPlaceholder()
44
- const path2 = addClipboardPlaceholder()
45
-
46
- expect(path1).not.toBe(path2)
47
- expect(path1).toContain('clipboard:pending-')
48
- expect(path2).toContain('clipboard:pending-')
49
- })
50
-
51
- test('multiple placeholders coexist in store', () => {
52
- addClipboardPlaceholder()
53
- addClipboardPlaceholder()
54
- addClipboardPlaceholder()
55
-
56
- const pendingImages = getPendingImages()
57
- expect(pendingImages).toHaveLength(3)
58
- expect(pendingImages.every((img) => img.status === 'processing')).toBe(
59
- true,
60
- )
61
- })
62
- })
63
-
64
- describe('addPendingImageFromBase64', () => {
65
- test('adds image with ready status', async () => {
66
- await addPendingImageFromBase64(
67
- 'base64data',
68
- 'image/png',
69
- 'test.png',
70
- '/tmp/test.png',
71
- )
72
-
73
- const pendingImages = getPendingImages()
74
- expect(pendingImages).toHaveLength(1)
75
- expect(pendingImages[0].status).toBe('ready')
76
- expect(pendingImages[0].filename).toBe('test.png')
77
- expect(pendingImages[0].processedImage?.base64).toBe('base64data')
78
- expect(pendingImages[0].processedImage?.mediaType).toBe('image/png')
79
- })
80
-
81
- test('uses clipboard path when tempPath not provided', async () => {
82
- await addPendingImageFromBase64('base64data', 'image/png', 'test.png')
83
-
84
- const pendingImages = getPendingImages()
85
- expect(pendingImages[0].path).toBe('clipboard:test.png')
86
- })
87
-
88
- test('calculates approximate size from base64', async () => {
89
- const base64Data = 'a'.repeat(1000) // 1000 base64 chars
90
- await addPendingImageFromBase64(base64Data, 'image/png', 'test.png')
91
-
92
- const pendingImages = getPendingImages()
93
- // Size should be approximately 750 bytes (3/4 of 1000)
94
- expect(pendingImages[0].size).toBe(750)
95
- })
96
- })
97
-
98
- describe('addPendingImageWithError', () => {
99
- test('adds image with error status', () => {
100
- addPendingImageWithError('/path/to/image.png', '❌ file not found')
101
-
102
- const pendingImages = getPendingImages()
103
- expect(pendingImages).toHaveLength(1)
104
- expect(pendingImages[0].status).toBe('error')
105
- expect(pendingImages[0].note).toBe('❌ file not found')
106
- expect(pendingImages[0].filename).toBe('image.png')
107
- })
108
- })
109
-
110
- describe('capturePendingAttachments', () => {
111
- test('returns and clears all pending attachments', () => {
112
- addClipboardPlaceholder()
113
- addClipboardPlaceholder()
114
-
115
- expect(getPendingImages()).toHaveLength(2)
116
-
117
- const captured = capturePendingAttachments()
118
-
119
- expect(captured).toHaveLength(2)
120
- expect(getPendingImages()).toHaveLength(0)
121
- })
122
-
123
- test('returns empty array when no pending attachments', () => {
124
- const captured = capturePendingAttachments()
125
- expect(captured).toHaveLength(0)
126
- })
127
- })
128
-
129
- describe('placeholder replacement flow', () => {
130
- test('placeholder can be updated via setState', () => {
131
- const placeholderPath = addClipboardPlaceholder()
132
-
133
- // Simulate what addPendingImageFromFile does when replacing placeholder
134
- useChatStore.setState((state) => ({
135
- pendingAttachments: state.pendingAttachments.map((att) =>
136
- att.kind === 'image' && att.path === placeholderPath
137
- ? { ...att, path: '/real/path.png', filename: 'screenshot.png' }
138
- : att,
139
- ),
140
- }))
141
-
142
- const pendingImages = getPendingImages()
143
- expect(pendingImages).toHaveLength(1)
144
- expect(pendingImages[0].path).toBe('/real/path.png')
145
- expect(pendingImages[0].filename).toBe('screenshot.png')
146
- expect(pendingImages[0].status).toBe('processing') // Still processing
147
- })
148
-
149
- test('status transitions from processing to ready', () => {
150
- const placeholderPath = addClipboardPlaceholder()
151
-
152
- // Simulate processing completion
153
- useChatStore.setState((state) => ({
154
- pendingAttachments: state.pendingAttachments.map((att) =>
155
- att.kind === 'image' && att.path === placeholderPath
156
- ? {
157
- ...att,
158
- status: 'ready' as const,
159
- processedImage: { base64: 'data', mediaType: 'image/png' },
160
- }
161
- : att,
162
- ),
163
- }))
164
-
165
- const pendingImages = getPendingImages()
166
- expect(pendingImages[0].status).toBe('ready')
167
- expect(pendingImages[0].processedImage).toBeDefined()
168
- })
169
-
170
- test('status transitions from processing to error', () => {
171
- const placeholderPath = addClipboardPlaceholder()
172
-
173
- // Simulate processing failure
174
- useChatStore.setState((state) => ({
175
- pendingAttachments: state.pendingAttachments.map((att) =>
176
- att.kind === 'image' && att.path === placeholderPath
177
- ? { ...att, status: 'error' as const, note: 'Processing failed' }
178
- : att,
179
- ),
180
- }))
181
-
182
- const pendingImages = getPendingImages()
183
- expect(pendingImages[0].status).toBe('error')
184
- expect(pendingImages[0].note).toBe('Processing failed')
185
- })
186
- })
187
-
188
- describe('mixed status scenarios', () => {
189
- test('can have images in different states simultaneously', async () => {
190
- // Add a processing placeholder
191
- const placeholder = addClipboardPlaceholder()
192
-
193
- // Add a ready image
194
- await addPendingImageFromBase64(
195
- 'data',
196
- 'image/png',
197
- 'ready.png',
198
- '/ready.png',
199
- )
200
-
201
- // Add an error image
202
- addPendingImageWithError('/error.png', '❌ error')
203
-
204
- const pendingImages = getPendingImages()
205
- expect(pendingImages).toHaveLength(3)
206
-
207
- const processing = pendingImages.find((img) => img.path === placeholder)
208
- const ready = pendingImages.find((img) => img.path === '/ready.png')
209
- const error = pendingImages.find((img) => img.path === '/error.png')
210
-
211
- expect(processing?.status).toBe('processing')
212
- expect(ready?.status).toBe('ready')
213
- expect(error?.status).toBe('error')
214
- })
215
-
216
- test('counting by status works correctly', () => {
217
- // Add 2 processing, 3 ready, 1 error
218
- addClipboardPlaceholder()
219
- addClipboardPlaceholder()
220
-
221
- useChatStore.getState().addPendingImage({
222
- path: '/ready1.png',
223
- filename: 'ready1.png',
224
- status: 'ready',
225
- })
226
- useChatStore.getState().addPendingImage({
227
- path: '/ready2.png',
228
- filename: 'ready2.png',
229
- status: 'ready',
230
- })
231
- useChatStore.getState().addPendingImage({
232
- path: '/ready3.png',
233
- filename: 'ready3.png',
234
- status: 'ready',
235
- })
236
-
237
- addPendingImageWithError('/error.png', '❌ error')
238
-
239
- const pendingImages = getPendingImages()
240
- const processingCount = pendingImages.filter(
241
- (img) => img.status === 'processing',
242
- ).length
243
- const readyCount = pendingImages.filter(
244
- (img) => img.status === 'ready',
245
- ).length
246
- const errorCount = pendingImages.filter(
247
- (img) => img.status === 'error',
248
- ).length
249
-
250
- expect(processingCount).toBe(2)
251
- expect(readyCount).toBe(3)
252
- expect(errorCount).toBe(1)
253
- })
254
- })
255
-
256
- describe('removePendingImage', () => {
257
- test('removes placeholder by path', () => {
258
- const placeholderPath = addClipboardPlaceholder()
259
- expect(getPendingImages()).toHaveLength(1)
260
-
261
- useChatStore.getState().removePendingImage(placeholderPath)
262
- expect(getPendingImages()).toHaveLength(0)
263
- })
264
-
265
- test('only removes matching path', () => {
266
- const path1 = addClipboardPlaceholder()
267
- const path2 = addClipboardPlaceholder()
268
- expect(getPendingImages()).toHaveLength(2)
269
-
270
- useChatStore.getState().removePendingImage(path1)
271
-
272
- const remaining = getPendingImages()
273
- expect(remaining).toHaveLength(1)
274
- expect(remaining[0].path).toBe(path2)
275
- })
276
- })
277
- })
@@ -1,51 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
-
3
- import { failedPollDelayMs, jitterPollIntervalMs } from '../polling-backoff'
4
-
5
- describe('polling backoff', () => {
6
- test('uses capped exponential windows with equal jitter', () => {
7
- const delay = (failures: number, random: number) =>
8
- failedPollDelayMs({
9
- consecutiveFailures: failures,
10
- random: () => random,
11
- })
12
-
13
- expect(delay(1, 0)).toBe(10_000)
14
- expect(delay(1, 1)).toBe(20_000)
15
- expect(delay(2, 0)).toBe(20_000)
16
- expect(delay(3, 1)).toBe(80_000)
17
- expect(delay(20, 0)).toBe(150_000)
18
- expect(delay(20, 1)).toBe(300_000)
19
- })
20
-
21
- test('jitters successful poll cadences around the requested interval', () => {
22
- expect(jitterPollIntervalMs({ intervalMs: 30_000, random: () => 0 })).toBe(
23
- 24_000,
24
- )
25
- expect(
26
- jitterPollIntervalMs({ intervalMs: 30_000, random: () => 0.5 }),
27
- ).toBe(30_000)
28
- expect(jitterPollIntervalMs({ intervalMs: 30_000, random: () => 1 })).toBe(
29
- 36_000,
30
- )
31
- })
32
-
33
- test('never schedules before a server Retry-After floor', () => {
34
- const delay = (random: number) =>
35
- failedPollDelayMs({
36
- consecutiveFailures: 1,
37
- retryAfterMs: 30_000,
38
- random: () => random,
39
- })
40
-
41
- expect(delay(0)).toBe(30_000)
42
- expect(delay(1)).toBe(36_000)
43
- expect(
44
- failedPollDelayMs({
45
- consecutiveFailures: 1,
46
- retryAfterMs: Number.MAX_VALUE,
47
- random: () => 1,
48
- }),
49
- ).toBe(300_000)
50
- })
51
- })
@@ -1,148 +0,0 @@
1
- import { describe, test, expect } from 'bun:test'
2
-
3
- import {
4
- resolveChatKeyboardAction,
5
- createDefaultChatKeyboardState,
6
- } from '../keyboard-actions'
7
- import { resolveQueuePanelAction } from '../queue-panel-actions'
8
-
9
- import type { KeyEvent } from '@opentui/core'
10
-
11
- const createKey = (overrides: Partial<KeyEvent> = {}): KeyEvent =>
12
- ({
13
- name: '',
14
- sequence: '',
15
- ctrl: false,
16
- meta: false,
17
- shift: false,
18
- option: false,
19
- ...overrides,
20
- }) as KeyEvent
21
-
22
- const browsing = { editing: false }
23
- const editing = { editing: true }
24
-
25
- describe('resolveQueuePanelAction', () => {
26
- test('arrows move the selection, modified arrows move the message', () => {
27
- expect(resolveQueuePanelAction(createKey({ name: 'up' }), browsing)).toEqual({
28
- type: 'select',
29
- delta: -1,
30
- })
31
- expect(
32
- resolveQueuePanelAction(createKey({ name: 'down' }), browsing),
33
- ).toEqual({ type: 'select', delta: 1 })
34
- expect(
35
- resolveQueuePanelAction(createKey({ name: 'up', shift: true }), browsing),
36
- ).toEqual({ type: 'move', delta: -1 })
37
- expect(
38
- resolveQueuePanelAction(
39
- createKey({ name: 'down', ctrl: true }),
40
- browsing,
41
- ),
42
- ).toEqual({ type: 'move', delta: 1 })
43
- })
44
-
45
- test('shift+J/K reorder for terminals that swallow modified arrows', () => {
46
- expect(
47
- resolveQueuePanelAction(
48
- createKey({ name: 'k', shift: true, sequence: 'K' }),
49
- browsing,
50
- ),
51
- ).toEqual({ type: 'move', delta: -1 })
52
- expect(
53
- resolveQueuePanelAction(
54
- createKey({ name: 'j', shift: true, sequence: 'J' }),
55
- browsing,
56
- ),
57
- ).toEqual({ type: 'move', delta: 1 })
58
- // Their unshifted twins still only move the cursor.
59
- expect(
60
- resolveQueuePanelAction(createKey({ name: 'k', sequence: 'k' }), browsing),
61
- ).toEqual({ type: 'select', delta: -1 })
62
- })
63
-
64
- test('edit, delete, promote, and close', () => {
65
- expect(resolveQueuePanelAction(createKey({ name: 'e' }), browsing)).toEqual({
66
- type: 'edit',
67
- })
68
- expect(
69
- resolveQueuePanelAction(createKey({ name: 'return' }), browsing),
70
- ).toEqual({ type: 'edit' })
71
- expect(resolveQueuePanelAction(createKey({ name: 'd' }), browsing)).toEqual({
72
- type: 'delete',
73
- })
74
- expect(
75
- resolveQueuePanelAction(createKey({ name: 'backspace' }), browsing),
76
- ).toEqual({ type: 'delete' })
77
- expect(resolveQueuePanelAction(createKey({ name: 't' }), browsing)).toEqual({
78
- type: 'move-to-top',
79
- })
80
- expect(
81
- resolveQueuePanelAction(createKey({ name: 'escape' }), browsing),
82
- ).toEqual({ type: 'close' })
83
- expect(
84
- resolveQueuePanelAction(createKey({ name: 'c', ctrl: true }), browsing),
85
- ).toEqual({ type: 'close' })
86
- })
87
-
88
- test('while editing, only the exits are the panel’s — the rest is typing', () => {
89
- expect(resolveQueuePanelAction(createKey({ name: 'escape' }), editing)).toEqual(
90
- { type: 'cancel-edit' },
91
- )
92
- expect(
93
- resolveQueuePanelAction(createKey({ name: 'c', ctrl: true }), editing),
94
- ).toEqual({ type: 'cancel-edit' })
95
-
96
- // Every shortcut letter has to reach the text input instead.
97
- for (const name of ['d', 'e', 'q', 't', 'j', 'k']) {
98
- expect(resolveQueuePanelAction(createKey({ name }), editing)).toEqual({
99
- type: 'none',
100
- })
101
- }
102
- expect(
103
- resolveQueuePanelAction(createKey({ name: 'backspace' }), editing),
104
- ).toEqual({ type: 'none' })
105
- expect(resolveQueuePanelAction(createKey({ name: 'up' }), editing)).toEqual({
106
- type: 'none',
107
- })
108
- })
109
- })
110
-
111
- describe('ctrl+q opens the queue editor', () => {
112
- const ctrlQ = createKey({ name: 'q', ctrl: true })
113
-
114
- test('opens when something is queued', () => {
115
- expect(
116
- resolveChatKeyboardAction(ctrlQ, {
117
- ...createDefaultChatKeyboardState(),
118
- queuedCount: 2,
119
- }),
120
- ).toEqual({ type: 'open-queue-panel' })
121
- })
122
-
123
- test('does nothing on an empty queue', () => {
124
- expect(
125
- resolveChatKeyboardAction(ctrlQ, createDefaultChatKeyboardState()),
126
- ).toEqual({ type: 'none' })
127
- })
128
-
129
- test('still opens with a half-typed message in the composer', () => {
130
- expect(
131
- resolveChatKeyboardAction(ctrlQ, {
132
- ...createDefaultChatKeyboardState(),
133
- inputValue: 'and another thing',
134
- cursorPosition: 17,
135
- queuedCount: 1,
136
- }),
137
- ).toEqual({ type: 'open-queue-panel' })
138
- })
139
-
140
- test('a bare q is not a shortcut', () => {
141
- expect(
142
- resolveChatKeyboardAction(createKey({ name: 'q', sequence: 'q' }), {
143
- ...createDefaultChatKeyboardState(),
144
- queuedCount: 2,
145
- }),
146
- ).toEqual({ type: 'none' })
147
- })
148
- })