@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,505 +0,0 @@
1
- import { describe, expect, it } from 'bun:test'
2
-
3
- import {
4
- getPartialJsonDelta,
5
- parsePartialJsonObjectSingle,
6
- } from '../partial-json-delta'
7
-
8
- describe('parsePartialJsonObjectSingle', () => {
9
- describe('complete valid JSON', () => {
10
- it('should parse complete valid JSON', () => {
11
- const input = '{"name": "test", "value": 42}'
12
- const result = parsePartialJsonObjectSingle(input)
13
- expect(result).toEqual({
14
- lastParamComplete: true,
15
- params: { name: 'test', value: 42 },
16
- })
17
- })
18
-
19
- it('should parse empty object', () => {
20
- const input = '{}'
21
- const result = parsePartialJsonObjectSingle(input)
22
- expect(result).toEqual({ lastParamComplete: true, params: {} })
23
- })
24
-
25
- it('should parse nested objects', () => {
26
- const input = '{"user": {"name": "John", "age": 30}}'
27
- const result = parsePartialJsonObjectSingle(input)
28
- expect(result).toEqual({
29
- lastParamComplete: true,
30
- params: { user: { name: 'John', age: 30 } },
31
- })
32
- })
33
-
34
- it('should parse arrays', () => {
35
- const input = '{"items": [1, 2, 3]}'
36
- const result = parsePartialJsonObjectSingle(input)
37
- expect(result).toEqual({
38
- lastParamComplete: true,
39
- params: { items: [1, 2, 3] },
40
- })
41
- })
42
- })
43
-
44
- describe('incomplete JSON - missing closing brace', () => {
45
- it('should parse object missing final closing brace', () => {
46
- const input = '{"name": "test", "value": 42'
47
- const result = parsePartialJsonObjectSingle(input)
48
- expect(result).toEqual({
49
- lastParamComplete: true,
50
- params: { name: 'test' },
51
- })
52
- })
53
-
54
- it('should parse nested object missing final closing brace', () => {
55
- const input = '{"user": {"name": "John", "age": 30}'
56
- const result = parsePartialJsonObjectSingle(input)
57
- expect(result).toEqual({
58
- lastParamComplete: true,
59
- params: { user: { name: 'John', age: 30 } },
60
- })
61
- })
62
-
63
- it('should parse object with incomplete string value', () => {
64
- const input = '{"name": "test", "incomplete": "partial'
65
- const result = parsePartialJsonObjectSingle(input)
66
- expect(result).toEqual({
67
- lastParamComplete: false,
68
- params: { name: 'test', incomplete: 'partial' },
69
- })
70
- })
71
- })
72
-
73
- describe('incomplete JSON - trailing comma handling', () => {
74
- it('should handle trailing comma by removing last property', () => {
75
- const input = '{"name": "test", "value": 42, "incomplete":'
76
- const result = parsePartialJsonObjectSingle(input)
77
- expect(result).toEqual({
78
- lastParamComplete: true,
79
- params: { name: 'test', value: 42 },
80
- })
81
- })
82
-
83
- it('should handle multiple trailing commas', () => {
84
- const input = '{"a": 1, "b": 2, "c": 3, "d":'
85
- const result = parsePartialJsonObjectSingle(input)
86
- expect(result).toEqual({
87
- lastParamComplete: true,
88
- params: { a: 1, b: 2, c: 3 },
89
- })
90
- })
91
-
92
- it('should handle nested object with trailing comma', () => {
93
- const input = '{"user": {"name": "John", "age": 30}, "incomplete":'
94
- const result = parsePartialJsonObjectSingle(input)
95
- expect(result).toEqual({
96
- lastParamComplete: true,
97
- params: { user: { name: 'John', age: 30 } },
98
- })
99
- })
100
-
101
- it('should handle array with trailing comma', () => {
102
- const input = '{"items": [1, 2, 3], "incomplete":'
103
- const result = parsePartialJsonObjectSingle(input)
104
- expect(result).toEqual({
105
- lastParamComplete: true,
106
- params: { items: [1, 2, 3] },
107
- })
108
- })
109
- })
110
-
111
- describe('comma search optimization', () => {
112
- it('should efficiently find last valid comma in deeply nested incomplete JSON', () => {
113
- // This tests the O(n) backward comma search optimization
114
- const input = '{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "incomplete":'
115
- const result = parsePartialJsonObjectSingle(input)
116
- expect(result).toEqual({
117
- lastParamComplete: true,
118
- params: { a: 1, b: 2, c: 3, d: 4, e: 5 },
119
- })
120
- })
121
-
122
- it('should handle comma inside string value when searching backwards', () => {
123
- // Comma inside a string should not be treated as a separator
124
- const input = '{"message": "Hello, world", "incomplete":'
125
- const result = parsePartialJsonObjectSingle(input)
126
- expect(result).toEqual({
127
- lastParamComplete: true,
128
- params: { message: 'Hello, world' },
129
- })
130
- })
131
-
132
- it('should find valid comma after skipping invalid parse attempts', () => {
133
- // Multiple commas, need to find the right one
134
- const input = '{"x": [1, 2, 3], "y": {"a": 1, "b": 2}, "z":'
135
- const result = parsePartialJsonObjectSingle(input)
136
- expect(result).toEqual({
137
- lastParamComplete: true,
138
- params: { x: [1, 2, 3], y: { a: 1, b: 2 } },
139
- })
140
- })
141
- })
142
-
143
- describe('edge cases', () => {
144
- it('should return empty object for empty string', () => {
145
- const input = ''
146
- const result = parsePartialJsonObjectSingle(input)
147
- expect(result).toEqual({ lastParamComplete: true, params: {} })
148
- })
149
-
150
- it('should return empty object for invalid JSON', () => {
151
- const input = 'not json at all'
152
- const result = parsePartialJsonObjectSingle(input)
153
- expect(result).toEqual({ lastParamComplete: true, params: {} })
154
- })
155
-
156
- it('should return empty object for malformed JSON', () => {
157
- const input = '{"name": test}'
158
- const result = parsePartialJsonObjectSingle(input)
159
- expect(result).toEqual({ lastParamComplete: true, params: {} })
160
- })
161
-
162
- it('should handle JSON with only opening brace', () => {
163
- const input = '{'
164
- const result = parsePartialJsonObjectSingle(input)
165
- expect(result).toEqual({ lastParamComplete: true, params: {} })
166
- })
167
-
168
- it('should handle JSON with whitespace', () => {
169
- const input = ' {"name": "test"} '
170
- const result = parsePartialJsonObjectSingle(input)
171
- expect(result).toEqual({
172
- lastParamComplete: true,
173
- params: { name: 'test' },
174
- })
175
- })
176
-
177
- it('should handle complex nested incomplete JSON', () => {
178
- const input =
179
- '{"data": {"users": [{"name": "John"}, {"name": "Jane"}], "count": 2}, "meta":'
180
- const result = parsePartialJsonObjectSingle(input)
181
- expect(result).toEqual({
182
- lastParamComplete: true,
183
- params: {
184
- data: {
185
- users: [{ name: 'John' }, { name: 'Jane' }],
186
- count: 2,
187
- },
188
- },
189
- })
190
- })
191
- })
192
-
193
- describe('real-world streaming scenarios', () => {
194
- it('should handle partial JSON from streaming response', () => {
195
- const input =
196
- '{"status": "processing", "progress": 0.5, "message": "Working on'
197
- const result = parsePartialJsonObjectSingle(input)
198
- expect(result).toEqual({
199
- lastParamComplete: false,
200
- params: {
201
- status: 'processing',
202
- progress: 0.5,
203
- message: 'Working on',
204
- },
205
- })
206
- })
207
-
208
- it('should handle JSON with boolean and null values', () => {
209
- const input =
210
- '{"active": true, "deleted": false, "metadata": null, "incomplete":'
211
- const result = parsePartialJsonObjectSingle(input)
212
- expect(result).toEqual({
213
- lastParamComplete: true,
214
- params: { active: true, deleted: false, metadata: null },
215
- })
216
- })
217
-
218
- it('should handle JSON with numbers', () => {
219
- const input =
220
- '{"integer": 42, "float": 3.14, "negative": -10, "incomplete":'
221
- const result = parsePartialJsonObjectSingle(input)
222
- expect(result).toEqual({
223
- lastParamComplete: true,
224
- params: { integer: 42, float: 3.14, negative: -10 },
225
- })
226
- })
227
- })
228
- })
229
-
230
- describe('getPartialJsonDelta', () => {
231
- describe('input validation', () => {
232
- it('should throw error when content does not start with previous', () => {
233
- const content = '{"name": "test"}'
234
- const previous = '{"other": "value"}'
235
-
236
- expect(() => getPartialJsonDelta(content, previous)).toThrow(
237
- 'Content must be previous content plus new content',
238
- )
239
- })
240
-
241
- it('should work when content starts with previous', () => {
242
- const content = '{"name": "test", "value": 42}'
243
- const previous = '{"name": "test"'
244
-
245
- expect(() => getPartialJsonDelta(content, previous)).not.toThrow()
246
- })
247
- })
248
-
249
- describe('basic delta detection from streaming JSON', () => {
250
- it('should detect new properties added to empty object', () => {
251
- const content = '{ "name": "test", "value": 42 }'
252
- const previous = '{'
253
- const result = getPartialJsonDelta(content, previous)
254
-
255
- expect(result.delta).toEqual({ name: 'test', value: 42 })
256
- expect(result.result).toEqual({ name: 'test', value: 42 })
257
- expect(result.lastParam.key).toBe('value')
258
- expect(result.lastParam.complete).toBe(true)
259
- })
260
-
261
- it('should detect completion of partial string value', () => {
262
- const content = '{"name": "updated"}'
263
- const previous = '{"name": "upda'
264
- const result = getPartialJsonDelta(content, previous)
265
-
266
- expect(result.delta).toEqual({ name: 'ted' })
267
- expect(result.result).toEqual({ name: 'updated' })
268
- expect(result.lastParam.key).toBe('name')
269
- expect(result.lastParam.complete).toBe(true)
270
- })
271
-
272
- it('should return empty delta when no changes detected', () => {
273
- const content = '{"name": "test", "value": 42}'
274
- const previous = '{"name": "test", "value": 42'
275
- const result = getPartialJsonDelta(content, previous)
276
-
277
- expect(result.delta).toEqual({ value: 42 })
278
- expect(result.result).toEqual({ name: 'test', value: 42 })
279
- expect(result.lastParam.key).toBe('value')
280
- expect(result.lastParam.complete).toBe(true)
281
- })
282
-
283
- it('should detect new property being added', () => {
284
- const content = '{"name": "test", "value": 100}'
285
- const previous = '{"name": "test", "value": '
286
- const result = getPartialJsonDelta(content, previous)
287
-
288
- expect(result.delta).toEqual({ value: 100 })
289
- expect(result.result).toEqual({ name: 'test', value: 100 })
290
- expect(result.lastParam.key).toBe('value')
291
- expect(result.lastParam.complete).toBe(true)
292
- })
293
- })
294
-
295
- describe('string delta handling', () => {
296
- it('should return string slice for partial string updates', () => {
297
- const content = '{"message": "Hello World"}'
298
- const previous = '{"message": "Hello'
299
- const result = getPartialJsonDelta(content, previous)
300
-
301
- expect(result.delta).toEqual({ message: ' World' })
302
- expect(result.result).toEqual({ message: 'Hello World' })
303
- })
304
-
305
- it('should handle empty string to non-empty string', () => {
306
- const content = '{"message": "Hello"}'
307
- const previous = '{"message": "'
308
- const result = getPartialJsonDelta(content, previous)
309
-
310
- expect(result.delta).toEqual({ message: 'Hello' })
311
- expect(result.result).toEqual({ message: 'Hello' })
312
- })
313
-
314
- it('should handle new string property', () => {
315
- const content = '{"message": "Hello"}'
316
- const previous = '{'
317
- const result = getPartialJsonDelta(content, previous)
318
-
319
- expect(result.delta).toEqual({ message: 'Hello' })
320
- expect(result.result).toEqual({ message: 'Hello' })
321
- })
322
-
323
- it('should handle multi-line string streaming', () => {
324
- const content = '{"text": "Line 1\\nLine 2\\nLine 3"}'
325
- const previous = '{"text": "Line 1\\nLine'
326
- const result = getPartialJsonDelta(content, previous)
327
-
328
- expect(result.delta).toEqual({ text: ' 2\nLine 3' })
329
- expect(result.result).toEqual({ text: 'Line 1\nLine 2\nLine 3' })
330
- })
331
- })
332
-
333
- describe('non-string value changes', () => {
334
- it('should return full value for non-string changes', () => {
335
- const content = '{"count": 42}'
336
- const previous = '{"count": '
337
- const result = getPartialJsonDelta(content, previous)
338
-
339
- expect(result.delta).toEqual({ count: 42 })
340
- expect(result.result).toEqual({ count: 42 })
341
- })
342
-
343
- it('should handle boolean values', () => {
344
- const content = '{"active": true}'
345
- const previous = '{"active": '
346
- const result = getPartialJsonDelta(content, previous)
347
-
348
- expect(result.delta).toEqual({ active: true })
349
- expect(result.result).toEqual({ active: true })
350
- })
351
-
352
- it('should handle null values', () => {
353
- const content = '{"data": null}'
354
- const previous = '{"data": '
355
- const result = getPartialJsonDelta(content, previous)
356
-
357
- expect(result.delta).toEqual({ data: null })
358
- expect(result.result).toEqual({ data: null })
359
- })
360
-
361
- it('should handle array values', () => {
362
- const content = '{"items": [1, 2, 3]}'
363
- const previous = '{"items": '
364
- const result = getPartialJsonDelta(content, previous)
365
-
366
- expect(result.delta).toEqual({ items: [1, 2, 3] })
367
- expect(result.result).toEqual({ items: [1, 2, 3] })
368
- })
369
-
370
- it('should handle nested object values', () => {
371
- const content = '{"user": {"name": "John", "age": 30}}'
372
- const previous = '{"user": '
373
- const result = getPartialJsonDelta(content, previous)
374
-
375
- expect(result.delta).toEqual({ user: { name: 'John', age: 30 } })
376
- expect(result.result).toEqual({ user: { name: 'John', age: 30 } })
377
- })
378
- })
379
-
380
- describe('realistic streaming scenarios', () => {
381
- it('should handle progressive JSON building', () => {
382
- // Simulate streaming JSON construction
383
- let previous = '{'
384
- let content = '{"status": "processing"'
385
- let result = getPartialJsonDelta(content, previous)
386
-
387
- expect(result.delta).toEqual({ status: 'processing' })
388
- expect(result.result).toEqual({ status: 'processing' })
389
-
390
- // Add more content
391
- previous = content
392
- content = '{"status": "processing", "progress": 0.5'
393
- result = getPartialJsonDelta(content, previous)
394
-
395
- expect(result.delta).toEqual({})
396
- expect(result.result).toEqual({ status: 'processing' })
397
-
398
- // Complete the JSON
399
- previous = content
400
- content =
401
- '{"status": "processing", "progress": 0.5, "message": "Almost done"}'
402
- result = getPartialJsonDelta(content, previous)
403
-
404
- expect(result.delta).toEqual({ message: 'Almost done', progress: 0.5 })
405
- expect(result.result).toEqual({
406
- status: 'processing',
407
- progress: 0.5,
408
- message: 'Almost done',
409
- })
410
- })
411
-
412
- it('should handle streaming text completion', () => {
413
- const previous = '{"response": "The quick brown'
414
- const content =
415
- '{"response": "The quick brown fox jumps over the lazy dog"}'
416
- const result = getPartialJsonDelta(content, previous)
417
-
418
- expect(result.delta).toEqual({ response: ' fox jumps over the lazy dog' })
419
- expect(result.result).toEqual({
420
- response: 'The quick brown fox jumps over the lazy dog',
421
- })
422
- })
423
-
424
- it('should handle incomplete JSON with trailing comma', () => {
425
- const previous = '{"name": "test", "value": 42,'
426
- const content = '{"name": "test", "value": 42, "status": "complete"}'
427
- const result = getPartialJsonDelta(content, previous)
428
-
429
- expect(result.delta).toEqual({ status: 'complete' })
430
- expect(result.result).toEqual({
431
- name: 'test',
432
- value: 42,
433
- status: 'complete',
434
- })
435
- })
436
- })
437
-
438
- describe('lastParam tracking', () => {
439
- it('should track last parameter key and completion status', () => {
440
- const content = '{"name": "test", "value": 42}'
441
- const previous = '{'
442
- const result = getPartialJsonDelta(content, previous)
443
-
444
- expect(result.lastParam.key).toBe('value')
445
- expect(result.lastParam.complete).toBe(true)
446
- })
447
-
448
- it('should indicate incomplete last parameter', () => {
449
- const content = '{"name": "test", "message": "partial'
450
- const previous = '{'
451
- const result = getPartialJsonDelta(content, previous)
452
-
453
- expect(result.lastParam.key).toBe('message')
454
- expect(result.lastParam.complete).toBe(false)
455
- })
456
-
457
- it('should handle undefined key for empty object', () => {
458
- const content = '{}'
459
- const previous = '{'
460
- const result = getPartialJsonDelta(content, previous)
461
-
462
- expect(result.lastParam.key).toBeUndefined()
463
- expect(result.lastParam.complete).toBe(false)
464
- })
465
- })
466
-
467
- describe('edge cases', () => {
468
- it('should handle empty previous string', () => {
469
- const content = '{"name": "test"}'
470
- const previous = ''
471
-
472
- expect(() => getPartialJsonDelta(content, previous)).not.toThrow()
473
- const result = getPartialJsonDelta(content, previous)
474
- expect(result.delta).toEqual({ name: 'test' })
475
- })
476
-
477
- it('should handle identical content and previous', () => {
478
- const content = '{"name": "test"}'
479
- const previous = '{"name": "test"}'
480
- const result = getPartialJsonDelta(content, previous)
481
-
482
- expect(result.delta).toEqual({})
483
- expect(result.result).toEqual({ name: 'test' })
484
- })
485
-
486
- it('should handle malformed JSON gracefully', () => {
487
- const content = '{"name": test}' // Invalid JSON
488
- const previous = '{'
489
- const result = getPartialJsonDelta(content, previous)
490
-
491
- // Should return empty objects when JSON parsing fails
492
- expect(result.delta).toEqual({})
493
- expect(result.result).toEqual({})
494
- })
495
-
496
- it('should handle escaped quotes in strings', () => {
497
- const content = '{"message": "He said \\"Hello\\" to me"}'
498
- const previous = '{"message": "He said \\"Hello'
499
- const result = getPartialJsonDelta(content, previous)
500
-
501
- expect(result.delta).toEqual({ message: '" to me' })
502
- expect(result.result).toEqual({ message: 'He said "Hello" to me' })
503
- })
504
- })
505
- })
@@ -1,22 +0,0 @@
1
- import path from 'path'
2
-
3
- import { describe, expect, test } from 'bun:test'
4
-
5
- import { isPathInside } from '../path'
6
-
7
- describe('isPathInside', () => {
8
- test('accepts the root itself and a child when root ends in a separator', () => {
9
- const root = path.parse(process.cwd()).root
10
-
11
- expect(isPathInside(root, root)).toBe(true)
12
- expect(isPathInside(root, path.join(root, 'project.txt'))).toBe(true)
13
- })
14
-
15
- test('rejects parents, sibling prefixes, and other filesystem roots', () => {
16
- const root = path.resolve('workspace', 'project')
17
-
18
- expect(isPathInside(root, path.dirname(root))).toBe(false)
19
- expect(isPathInside(root, `${root}-private`)).toBe(false)
20
- expect(isPathInside(root, path.parse(root).root)).toBe(false)
21
- })
22
- })
@@ -1,90 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
-
3
- import {
4
- createProjectIgnoreFileReader,
5
- isProjectFileIgnored,
6
- } from '../project-ignore'
7
-
8
- function reader(files: Record<string, string>) {
9
- return async (filePath: string) => files[filePath] ?? null
10
- }
11
-
12
- describe('isProjectFileIgnored', () => {
13
- test('applies root and nested ignore rules with negation', async () => {
14
- const readIgnoreFile = reader({
15
- '.gitignore': 'private/\n*.sample\n',
16
- 'config/.gitignore': '*.template\n!.env.template\n',
17
- })
18
-
19
- expect(
20
- await isProjectFileIgnored({
21
- filePath: 'private/.env.example',
22
- readIgnoreFile,
23
- }),
24
- ).toBe(true)
25
- expect(
26
- await isProjectFileIgnored({
27
- filePath: 'config/.env.sample',
28
- readIgnoreFile,
29
- }),
30
- ).toBe(true)
31
- expect(
32
- await isProjectFileIgnored({
33
- filePath: 'config/.env.template',
34
- readIgnoreFile,
35
- }),
36
- ).toBe(false)
37
- })
38
-
39
- test('reads Anvil ignore files and rejects paths escaping the project', async () => {
40
- const readIgnoreFile = reader({ '.anvilignore': '.env.example\n' })
41
-
42
- expect(
43
- await isProjectFileIgnored({
44
- filePath: '.env.example',
45
- readIgnoreFile,
46
- }),
47
- ).toBe(true)
48
- expect(
49
- await isProjectFileIgnored({
50
- filePath: '../.env.example',
51
- readIgnoreFile,
52
- }),
53
- ).toBe(true)
54
- })
55
- })
56
-
57
- describe('createProjectIgnoreFileReader', () => {
58
- test('lists each directory once and reads only files that exist', async () => {
59
- const listed: string[] = []
60
- const read: string[] = []
61
- const readIgnoreFile = createProjectIgnoreFileReader({
62
- listDirectory: async (directory) => {
63
- listed.push(directory)
64
- return directory === '' ? ['.gitignore'] : []
65
- },
66
- readFile: async (filePath) => {
67
- read.push(filePath)
68
- return '*.secret\n'
69
- },
70
- })
71
-
72
- expect(await readIgnoreFile('.gitignore')).toBe('*.secret\n')
73
- expect(await readIgnoreFile('.anvilignore')).toBeNull()
74
- expect(listed).toEqual([''])
75
- expect(read).toEqual(['.gitignore'])
76
- })
77
-
78
- test('propagates errors when a listed ignore file is unreadable', async () => {
79
- const readIgnoreFile = createProjectIgnoreFileReader({
80
- listDirectory: async () => ['.gitignore'],
81
- readFile: async () => {
82
- throw new Error('permission denied')
83
- },
84
- })
85
-
86
- await expect(readIgnoreFile('.gitignore')).rejects.toThrow(
87
- 'permission denied',
88
- )
89
- })
90
- })