@q1k-oss/btree-workflows 0.0.1 → 0.0.2

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 (206) hide show
  1. package/README.md +13 -13
  2. package/dist/index.cjs +5011 -0
  3. package/dist/index.d.cts +3320 -0
  4. package/dist/index.d.ts +3320 -0
  5. package/dist/index.js +4879 -0
  6. package/package.json +33 -3
  7. package/.claude/settings.local.json +0 -31
  8. package/CLAUDE.md +0 -181
  9. package/behaviour-tree-workflows-landing/index.html +0 -16
  10. package/behaviour-tree-workflows-landing/package-lock.json +0 -2074
  11. package/behaviour-tree-workflows-landing/package.json +0 -31
  12. package/behaviour-tree-workflows-landing/public/favicon.svg +0 -17
  13. package/behaviour-tree-workflows-landing/src/App.css +0 -103
  14. package/behaviour-tree-workflows-landing/src/App.tsx +0 -176
  15. package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.css +0 -89
  16. package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.tsx +0 -64
  17. package/behaviour-tree-workflows-landing/src/components/ExampleSelector.css +0 -64
  18. package/behaviour-tree-workflows-landing/src/components/ExampleSelector.tsx +0 -34
  19. package/behaviour-tree-workflows-landing/src/components/ExecutionLog.css +0 -107
  20. package/behaviour-tree-workflows-landing/src/components/ExecutionLog.tsx +0 -85
  21. package/behaviour-tree-workflows-landing/src/components/Header.css +0 -50
  22. package/behaviour-tree-workflows-landing/src/components/Header.tsx +0 -26
  23. package/behaviour-tree-workflows-landing/src/components/StatusBadge.css +0 -45
  24. package/behaviour-tree-workflows-landing/src/components/StatusBadge.tsx +0 -15
  25. package/behaviour-tree-workflows-landing/src/components/Toolbar.css +0 -74
  26. package/behaviour-tree-workflows-landing/src/components/Toolbar.tsx +0 -53
  27. package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.css +0 -67
  28. package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.tsx +0 -192
  29. package/behaviour-tree-workflows-landing/src/components/YamlEditor.css +0 -18
  30. package/behaviour-tree-workflows-landing/src/components/YamlEditor.tsx +0 -96
  31. package/behaviour-tree-workflows-landing/src/lib/count-nodes.ts +0 -11
  32. package/behaviour-tree-workflows-landing/src/lib/execution-engine.ts +0 -96
  33. package/behaviour-tree-workflows-landing/src/lib/tree-layout.ts +0 -136
  34. package/behaviour-tree-workflows-landing/src/lib/yaml-examples.ts +0 -549
  35. package/behaviour-tree-workflows-landing/src/main.tsx +0 -9
  36. package/behaviour-tree-workflows-landing/src/stubs/activepieces.ts +0 -18
  37. package/behaviour-tree-workflows-landing/src/stubs/fs.ts +0 -24
  38. package/behaviour-tree-workflows-landing/src/stubs/path.ts +0 -16
  39. package/behaviour-tree-workflows-landing/src/stubs/temporal-activity.ts +0 -6
  40. package/behaviour-tree-workflows-landing/src/stubs/temporal-workflow.ts +0 -22
  41. package/behaviour-tree-workflows-landing/tsconfig.json +0 -25
  42. package/behaviour-tree-workflows-landing/vite.config.ts +0 -40
  43. package/demo-google-sheets.ts +0 -181
  44. package/demo-runtime-variables.ts +0 -174
  45. package/demo-template.ts +0 -208
  46. package/docs/ARCHITECTURE_SUMMARY.md +0 -613
  47. package/docs/NODE_REFERENCE.md +0 -504
  48. package/docs/README.md +0 -53
  49. package/docs/custom-nodes-architecture.md +0 -826
  50. package/docs/observability.md +0 -175
  51. package/docs/yaml-specification.md +0 -990
  52. package/examples/temporal/README.md +0 -117
  53. package/examples/temporal/activities.ts +0 -373
  54. package/examples/temporal/client.ts +0 -115
  55. package/examples/temporal/python-worker/activities.py +0 -339
  56. package/examples/temporal/python-worker/requirements.txt +0 -12
  57. package/examples/temporal/python-worker/worker.py +0 -106
  58. package/examples/temporal/worker.ts +0 -66
  59. package/examples/temporal/workflows.ts +0 -6
  60. package/examples/temporal/yaml-workflow-loader.ts +0 -105
  61. package/examples/yaml-test.ts +0 -97
  62. package/examples/yaml-workflows/01-simple-sequence.yaml +0 -25
  63. package/examples/yaml-workflows/02-parallel-timeout.yaml +0 -45
  64. package/examples/yaml-workflows/03-ecommerce-checkout.yaml +0 -94
  65. package/examples/yaml-workflows/04-ai-agent-workflow.yaml +0 -346
  66. package/examples/yaml-workflows/05-order-processing.yaml +0 -146
  67. package/examples/yaml-workflows/06-activity-test.yaml +0 -71
  68. package/examples/yaml-workflows/07-activity-simple-test.yaml +0 -43
  69. package/examples/yaml-workflows/08-file-processing.yaml +0 -141
  70. package/examples/yaml-workflows/09-http-request.yaml +0 -137
  71. package/examples/yaml-workflows/README.md +0 -211
  72. package/src/actions/code-execution.schema.ts +0 -27
  73. package/src/actions/code-execution.ts +0 -218
  74. package/src/actions/generate-file.test.ts +0 -516
  75. package/src/actions/generate-file.ts +0 -166
  76. package/src/actions/http-request.test.ts +0 -784
  77. package/src/actions/http-request.ts +0 -228
  78. package/src/actions/index.ts +0 -20
  79. package/src/actions/parse-file.test.ts +0 -448
  80. package/src/actions/parse-file.ts +0 -139
  81. package/src/actions/python-script.test.ts +0 -439
  82. package/src/actions/python-script.ts +0 -154
  83. package/src/base-node.test.ts +0 -511
  84. package/src/base-node.ts +0 -605
  85. package/src/behavior-tree.test.ts +0 -431
  86. package/src/behavior-tree.ts +0 -283
  87. package/src/blackboard.test.ts +0 -222
  88. package/src/blackboard.ts +0 -192
  89. package/src/composites/conditional.schema.ts +0 -19
  90. package/src/composites/conditional.test.ts +0 -309
  91. package/src/composites/conditional.ts +0 -129
  92. package/src/composites/for-each.schema.ts +0 -23
  93. package/src/composites/for-each.test.ts +0 -254
  94. package/src/composites/for-each.ts +0 -132
  95. package/src/composites/index.ts +0 -15
  96. package/src/composites/memory-sequence.schema.ts +0 -19
  97. package/src/composites/memory-sequence.test.ts +0 -223
  98. package/src/composites/memory-sequence.ts +0 -98
  99. package/src/composites/parallel.schema.ts +0 -28
  100. package/src/composites/parallel.test.ts +0 -502
  101. package/src/composites/parallel.ts +0 -157
  102. package/src/composites/reactive-sequence.schema.ts +0 -19
  103. package/src/composites/reactive-sequence.test.ts +0 -170
  104. package/src/composites/reactive-sequence.ts +0 -85
  105. package/src/composites/recovery.schema.ts +0 -19
  106. package/src/composites/recovery.test.ts +0 -366
  107. package/src/composites/recovery.ts +0 -90
  108. package/src/composites/selector.schema.ts +0 -19
  109. package/src/composites/selector.test.ts +0 -387
  110. package/src/composites/selector.ts +0 -85
  111. package/src/composites/sequence.schema.ts +0 -19
  112. package/src/composites/sequence.test.ts +0 -337
  113. package/src/composites/sequence.ts +0 -72
  114. package/src/composites/sub-tree.schema.ts +0 -21
  115. package/src/composites/sub-tree.test.ts +0 -893
  116. package/src/composites/sub-tree.ts +0 -177
  117. package/src/composites/while.schema.ts +0 -24
  118. package/src/composites/while.test.ts +0 -381
  119. package/src/composites/while.ts +0 -149
  120. package/src/data-store/index.ts +0 -10
  121. package/src/data-store/memory-store.ts +0 -161
  122. package/src/data-store/types.ts +0 -94
  123. package/src/debug/breakpoint.test.ts +0 -47
  124. package/src/debug/breakpoint.ts +0 -30
  125. package/src/debug/index.ts +0 -17
  126. package/src/debug/resume-point.test.ts +0 -49
  127. package/src/debug/resume-point.ts +0 -29
  128. package/src/decorators/delay.schema.ts +0 -21
  129. package/src/decorators/delay.test.ts +0 -261
  130. package/src/decorators/delay.ts +0 -140
  131. package/src/decorators/force-result.schema.ts +0 -32
  132. package/src/decorators/force-result.test.ts +0 -133
  133. package/src/decorators/force-result.ts +0 -63
  134. package/src/decorators/index.ts +0 -13
  135. package/src/decorators/invert.schema.ts +0 -19
  136. package/src/decorators/invert.test.ts +0 -135
  137. package/src/decorators/invert.ts +0 -42
  138. package/src/decorators/keep-running.schema.ts +0 -20
  139. package/src/decorators/keep-running.test.ts +0 -105
  140. package/src/decorators/keep-running.ts +0 -49
  141. package/src/decorators/precondition.schema.ts +0 -19
  142. package/src/decorators/precondition.test.ts +0 -351
  143. package/src/decorators/precondition.ts +0 -139
  144. package/src/decorators/repeat.schema.ts +0 -21
  145. package/src/decorators/repeat.test.ts +0 -187
  146. package/src/decorators/repeat.ts +0 -94
  147. package/src/decorators/run-once.schema.ts +0 -19
  148. package/src/decorators/run-once.test.ts +0 -140
  149. package/src/decorators/run-once.ts +0 -61
  150. package/src/decorators/soft-assert.schema.ts +0 -19
  151. package/src/decorators/soft-assert.test.ts +0 -107
  152. package/src/decorators/soft-assert.ts +0 -68
  153. package/src/decorators/timeout.schema.ts +0 -21
  154. package/src/decorators/timeout.test.ts +0 -274
  155. package/src/decorators/timeout.ts +0 -159
  156. package/src/errors.test.ts +0 -63
  157. package/src/errors.ts +0 -34
  158. package/src/events.test.ts +0 -347
  159. package/src/events.ts +0 -183
  160. package/src/index.ts +0 -80
  161. package/src/integrations/index.ts +0 -30
  162. package/src/integrations/integration-action.test.ts +0 -571
  163. package/src/integrations/integration-action.ts +0 -233
  164. package/src/integrations/piece-executor.ts +0 -320
  165. package/src/observability/execution-tracker.ts +0 -320
  166. package/src/observability/index.ts +0 -23
  167. package/src/observability/sinks.ts +0 -138
  168. package/src/observability/types.ts +0 -130
  169. package/src/registry-utils.ts +0 -147
  170. package/src/registry.test.ts +0 -466
  171. package/src/registry.ts +0 -334
  172. package/src/schemas/base.schema.ts +0 -104
  173. package/src/schemas/index.ts +0 -223
  174. package/src/schemas/integration.test.ts +0 -238
  175. package/src/schemas/tree-definition.schema.ts +0 -170
  176. package/src/schemas/validation.test.ts +0 -146
  177. package/src/schemas/validation.ts +0 -122
  178. package/src/scripting/index.ts +0 -22
  179. package/src/templates/template-loader.test.ts +0 -281
  180. package/src/templates/template-loader.ts +0 -152
  181. package/src/temporal-integration.test.ts +0 -213
  182. package/src/test-nodes.ts +0 -259
  183. package/src/types.ts +0 -503
  184. package/src/utilities/index.ts +0 -17
  185. package/src/utilities/log-message.test.ts +0 -275
  186. package/src/utilities/log-message.ts +0 -134
  187. package/src/utilities/regex-extract.test.ts +0 -138
  188. package/src/utilities/regex-extract.ts +0 -108
  189. package/src/utilities/variable-resolver.test.ts +0 -416
  190. package/src/utilities/variable-resolver.ts +0 -318
  191. package/src/utils/error-handler.test.ts +0 -117
  192. package/src/utils/error-handler.ts +0 -48
  193. package/src/utils/signal-check.test.ts +0 -234
  194. package/src/utils/signal-check.ts +0 -140
  195. package/src/yaml/errors.ts +0 -143
  196. package/src/yaml/index.ts +0 -30
  197. package/src/yaml/loader.ts +0 -39
  198. package/src/yaml/parser.ts +0 -286
  199. package/src/yaml/validation/semantic-validator.ts +0 -196
  200. package/templates/google-sheets/insert-row.yaml +0 -76
  201. package/templates/notification-sender.yaml +0 -33
  202. package/templates/order-validation.yaml +0 -44
  203. package/tsconfig.json +0 -24
  204. package/vitest.config.ts +0 -25
  205. package/workflows/order-processor.yaml +0 -59
  206. package/workflows/process-order-workflow.yaml +0 -142
@@ -1,571 +0,0 @@
1
- /**
2
- * IntegrationAction Node Tests
3
- */
4
-
5
- import { beforeEach, describe, expect, it, vi } from "vitest";
6
- import { ScopedBlackboard } from "../blackboard.js";
7
- import { Registry } from "../registry.js";
8
- import { type TemporalContext, NodeStatus } from "../types.js";
9
- import {
10
- IntegrationAction,
11
- type IntegrationActionConfig,
12
- type IntegrationContext,
13
- type TokenProvider,
14
- envTokenProvider,
15
- } from "./integration-action.js";
16
- import type { PieceAuth } from "./piece-executor.js";
17
-
18
- describe("IntegrationAction Node", () => {
19
- let blackboard: ScopedBlackboard;
20
- let registry: Registry;
21
- let context: IntegrationContext;
22
-
23
- // Mock token provider that returns a test token
24
- const mockTokenProvider: TokenProvider = vi.fn(async () => ({
25
- access_token: "test_token_123",
26
- }));
27
-
28
- beforeEach(() => {
29
- blackboard = new ScopedBlackboard();
30
- registry = new Registry();
31
- vi.clearAllMocks();
32
-
33
- context = {
34
- blackboard,
35
- treeRegistry: registry,
36
- timestamp: Date.now(),
37
- deltaTime: 0,
38
- tokenProvider: mockTokenProvider,
39
- tenantId: "tenant-123",
40
- userId: "user-456",
41
- };
42
- });
43
-
44
- describe("Construction and validation", () => {
45
- it("should create node with valid config", () => {
46
- const node = new IntegrationAction({
47
- id: "test-action",
48
- provider: "google-sheets",
49
- action: "append_row",
50
- inputs: { spreadsheetId: "123" },
51
- });
52
-
53
- expect(node).toBeDefined();
54
- expect(node.id).toBe("test-action");
55
- });
56
-
57
- it("should require provider", () => {
58
- expect(() => {
59
- new IntegrationAction({
60
- id: "test",
61
- action: "test",
62
- } as unknown as IntegrationActionConfig);
63
- }).toThrow(/requires provider/i);
64
- });
65
-
66
- it("should require action", () => {
67
- expect(() => {
68
- new IntegrationAction({
69
- id: "test",
70
- provider: "google-sheets",
71
- } as unknown as IntegrationActionConfig);
72
- }).toThrow(/requires action/i);
73
- });
74
-
75
- it("should accept empty inputs", () => {
76
- const node = new IntegrationAction({
77
- id: "test",
78
- provider: "slack",
79
- action: "send_message",
80
- });
81
- expect(node).toBeDefined();
82
- });
83
- });
84
-
85
- describe("Blackboard variable resolution", () => {
86
- it("should resolve simple ${bb.key} references", () => {
87
- blackboard.set("spreadsheetId", "sheet-123");
88
- blackboard.set("sheetName", "Orders");
89
-
90
- const node = new IntegrationAction({
91
- id: "test",
92
- provider: "google-sheets",
93
- action: "append_row",
94
- inputs: {
95
- spreadsheetId: "${bb.spreadsheetId}",
96
- sheetName: "${bb.sheetName}",
97
- },
98
- });
99
-
100
- // Access private method via any
101
- const resolvedInputs = (node as any).resolveInputs(context);
102
-
103
- expect(resolvedInputs.spreadsheetId).toBe("sheet-123");
104
- expect(resolvedInputs.sheetName).toBe("Orders");
105
- });
106
-
107
- it("should resolve nested ${bb.nested.key} references", () => {
108
- blackboard.set("user", {
109
- profile: {
110
- name: "John Doe",
111
- email: "john@example.com",
112
- },
113
- });
114
-
115
- const node = new IntegrationAction({
116
- id: "test",
117
- provider: "slack",
118
- action: "send_message",
119
- inputs: {
120
- text: "${bb.user.profile.name}",
121
- },
122
- });
123
-
124
- const resolvedInputs = (node as any).resolveInputs(context);
125
-
126
- expect(resolvedInputs.text).toBe("John Doe");
127
- });
128
-
129
- it("should handle template interpolation", () => {
130
- blackboard.set("orderId", "ORD-123");
131
- blackboard.set("customerName", "Jane");
132
-
133
- const node = new IntegrationAction({
134
- id: "test",
135
- provider: "slack",
136
- action: "send_message",
137
- inputs: {
138
- text: "New order ${bb.orderId} from ${bb.customerName}!",
139
- },
140
- });
141
-
142
- const resolvedInputs = (node as any).resolveInputs(context);
143
-
144
- expect(resolvedInputs.text).toBe("New order ORD-123 from Jane!");
145
- });
146
-
147
- it("should resolve arrays with ${bb.key} references", () => {
148
- blackboard.set("col1", "A");
149
- blackboard.set("col2", "B");
150
- blackboard.set("col3", "C");
151
-
152
- const node = new IntegrationAction({
153
- id: "test",
154
- provider: "google-sheets",
155
- action: "append_row",
156
- inputs: {
157
- values: ["${bb.col1}", "${bb.col2}", "${bb.col3}"],
158
- },
159
- });
160
-
161
- const resolvedInputs = (node as any).resolveInputs(context);
162
-
163
- expect(resolvedInputs.values).toEqual(["A", "B", "C"]);
164
- });
165
-
166
- it("should preserve non-string values", () => {
167
- blackboard.set("count", 42);
168
- blackboard.set("active", true);
169
-
170
- const node = new IntegrationAction({
171
- id: "test",
172
- provider: "test",
173
- action: "test",
174
- inputs: {
175
- // Full reference returns the actual value
176
- numericValue: "${bb.count}",
177
- boolValue: "${bb.active}",
178
- // Static values
179
- staticNum: 100,
180
- staticBool: false,
181
- },
182
- });
183
-
184
- const resolvedInputs = (node as any).resolveInputs(context);
185
-
186
- expect(resolvedInputs.numericValue).toBe(42);
187
- expect(resolvedInputs.boolValue).toBe(true);
188
- expect(resolvedInputs.staticNum).toBe(100);
189
- expect(resolvedInputs.staticBool).toBe(false);
190
- });
191
-
192
- it("should return empty string for undefined references in template", () => {
193
- const node = new IntegrationAction({
194
- id: "test",
195
- provider: "test",
196
- action: "test",
197
- inputs: {
198
- text: "Hello ${bb.undefinedKey}!",
199
- },
200
- });
201
-
202
- const resolvedInputs = (node as any).resolveInputs(context);
203
-
204
- expect(resolvedInputs.text).toBe("Hello !");
205
- });
206
-
207
- it("should return undefined for full undefined reference", () => {
208
- const node = new IntegrationAction({
209
- id: "test",
210
- provider: "test",
211
- action: "test",
212
- inputs: {
213
- value: "${bb.undefinedKey}",
214
- },
215
- });
216
-
217
- const resolvedInputs = (node as any).resolveInputs(context);
218
-
219
- expect(resolvedInputs.value).toBeUndefined();
220
- });
221
- });
222
-
223
- describe("Token provider integration", () => {
224
- it("should fail without token provider in context", async () => {
225
- const contextWithoutProvider: TemporalContext = {
226
- blackboard,
227
- treeRegistry: registry,
228
- timestamp: Date.now(),
229
- deltaTime: 0,
230
- };
231
-
232
- const node = new IntegrationAction({
233
- id: "test",
234
- provider: "google-sheets",
235
- action: "append_row",
236
- });
237
-
238
- const status = await node.tick(contextWithoutProvider);
239
-
240
- expect(status).toBe(NodeStatus.FAILURE);
241
- expect(node.lastError).toContain("No token provider");
242
- });
243
-
244
- it("should call token provider with correct arguments", async () => {
245
- // Mock the piece execution to avoid actual API calls
246
- vi.mock("./piece-executor.js", () => ({
247
- executePieceAction: vi.fn().mockResolvedValue({ success: true }),
248
- }));
249
-
250
- const node = new IntegrationAction({
251
- id: "test",
252
- provider: "slack",
253
- action: "send_message",
254
- connectionId: "conn-789",
255
- });
256
-
257
- // We expect failure due to piece not being installed, but token provider should be called
258
- await node.tick(context);
259
-
260
- expect(mockTokenProvider).toHaveBeenCalledWith(
261
- context,
262
- "slack",
263
- "conn-789"
264
- );
265
- });
266
- });
267
-
268
- describe("Result storage", () => {
269
- it("should store result in default key by default", async () => {
270
- // This test verifies the storeResult logic
271
- const node = new IntegrationAction({
272
- id: "my-action",
273
- provider: "test",
274
- action: "test",
275
- });
276
-
277
- // Verify default resultKey
278
- expect((node as any).resultKey).toBe("my-action.result");
279
- expect((node as any).storeResult).toBe(true);
280
- });
281
-
282
- it("should use custom result key when specified", () => {
283
- const node = new IntegrationAction({
284
- id: "test",
285
- provider: "test",
286
- action: "test",
287
- resultKey: "custom.result.key",
288
- });
289
-
290
- expect((node as any).resultKey).toBe("custom.result.key");
291
- });
292
-
293
- it("should not store result when storeResult is false", () => {
294
- const node = new IntegrationAction({
295
- id: "test",
296
- provider: "test",
297
- action: "test",
298
- storeResult: false,
299
- });
300
-
301
- expect((node as any).storeResult).toBe(false);
302
- });
303
- });
304
-
305
- describe("Node lifecycle", () => {
306
- it("should clone correctly", () => {
307
- const node = new IntegrationAction({
308
- id: "original",
309
- provider: "google-sheets",
310
- action: "append_row",
311
- inputs: { test: "value" },
312
- });
313
-
314
- const cloned = node.clone() as IntegrationAction;
315
-
316
- expect(cloned.id).toBe("original");
317
- expect((cloned as any).provider).toBe("google-sheets");
318
- expect((cloned as any).action).toBe("append_row");
319
- });
320
-
321
- it("should reset status correctly", async () => {
322
- const node = new IntegrationAction({
323
- id: "test",
324
- provider: "test",
325
- action: "test",
326
- });
327
-
328
- // Trigger failure (no token provider)
329
- await node.tick({
330
- blackboard,
331
- treeRegistry: registry,
332
- timestamp: Date.now(),
333
- deltaTime: 0,
334
- });
335
-
336
- expect(node.status()).toBe(NodeStatus.FAILURE);
337
-
338
- node.reset();
339
-
340
- expect(node.status()).toBe(NodeStatus.IDLE);
341
- expect(node.lastError).toBeUndefined();
342
- });
343
- });
344
- });
345
-
346
- describe("Activity execution mode", () => {
347
- let blackboard: ScopedBlackboard;
348
- let registry: Registry;
349
-
350
- // Mock token provider that returns a test token
351
- const mockTokenProvider: TokenProvider = vi.fn(async () => ({
352
- access_token: "test_token_123",
353
- }));
354
-
355
- beforeEach(() => {
356
- blackboard = new ScopedBlackboard();
357
- registry = new Registry();
358
- vi.clearAllMocks();
359
- });
360
-
361
- it("should use activity when provided in context", async () => {
362
- const mockActivity = vi.fn().mockResolvedValue({ success: true });
363
-
364
- const context: IntegrationContext = {
365
- blackboard,
366
- treeRegistry: registry,
367
- timestamp: Date.now(),
368
- deltaTime: 0,
369
- tokenProvider: mockTokenProvider,
370
- activities: { executePieceAction: mockActivity },
371
- };
372
-
373
- const node = new IntegrationAction({
374
- id: "test",
375
- provider: "google-sheets",
376
- action: "append_row",
377
- inputs: { spreadsheetId: "123" },
378
- });
379
-
380
- const status = await node.tick(context);
381
-
382
- expect(status).toBe(NodeStatus.SUCCESS);
383
- expect(mockActivity).toHaveBeenCalledWith(
384
- expect.objectContaining({
385
- provider: "google-sheets",
386
- action: "append_row",
387
- inputs: { spreadsheetId: "123" },
388
- auth: { access_token: "test_token_123" },
389
- })
390
- );
391
- });
392
-
393
- it("should fall back to inline execution without activity", async () => {
394
- // This test verifies that the node attempts inline execution when no activity is provided
395
- // Due to vi.mock in an earlier test, executePieceAction is mocked globally
396
- const context: IntegrationContext = {
397
- blackboard,
398
- treeRegistry: registry,
399
- timestamp: Date.now(),
400
- deltaTime: 0,
401
- tokenProvider: mockTokenProvider,
402
- activities: undefined, // No activities provided - should fall back to inline
403
- };
404
-
405
- const node = new IntegrationAction({
406
- id: "test",
407
- provider: "google-sheets",
408
- action: "append_row",
409
- inputs: { spreadsheetId: "123" },
410
- });
411
-
412
- // With the global mock, this will succeed via inline execution
413
- // The important thing is it doesn't fail with "no activity" error
414
- const status = await node.tick(context);
415
-
416
- // Succeeds because vi.mock mocks executePieceAction
417
- expect(status).toBe(NodeStatus.SUCCESS);
418
- // No error about missing activities
419
- expect(node.lastError).toBeUndefined();
420
- });
421
-
422
- it("should handle activity execution errors", async () => {
423
- const failingActivity = vi
424
- .fn()
425
- .mockRejectedValue(new Error("API timeout"));
426
-
427
- const context: IntegrationContext = {
428
- blackboard,
429
- treeRegistry: registry,
430
- timestamp: Date.now(),
431
- deltaTime: 0,
432
- tokenProvider: mockTokenProvider,
433
- activities: { executePieceAction: failingActivity },
434
- };
435
-
436
- const node = new IntegrationAction({
437
- id: "test",
438
- provider: "slack",
439
- action: "send_message",
440
- inputs: { channel: "#general", text: "Hello" },
441
- });
442
-
443
- const status = await node.tick(context);
444
-
445
- expect(status).toBe(NodeStatus.FAILURE);
446
- expect(node.lastError).toContain("API timeout");
447
- });
448
-
449
- it("should store activity result in blackboard", async () => {
450
- const mockActivity = vi.fn().mockResolvedValue({
451
- messageId: "msg-123",
452
- timestamp: "2024-01-15T10:30:00Z"
453
- });
454
-
455
- const context: IntegrationContext = {
456
- blackboard,
457
- treeRegistry: registry,
458
- timestamp: Date.now(),
459
- deltaTime: 0,
460
- tokenProvider: mockTokenProvider,
461
- activities: { executePieceAction: mockActivity },
462
- };
463
-
464
- const node = new IntegrationAction({
465
- id: "send-slack",
466
- provider: "slack",
467
- action: "send_message",
468
- inputs: { channel: "#general", text: "Hello" },
469
- resultKey: "slack.response",
470
- });
471
-
472
- await node.tick(context);
473
-
474
- expect(blackboard.get("slack.response")).toEqual({
475
- messageId: "msg-123",
476
- timestamp: "2024-01-15T10:30:00Z",
477
- });
478
- });
479
-
480
- it("should pass resolved inputs to activity", async () => {
481
- const mockActivity = vi.fn().mockResolvedValue({ success: true });
482
-
483
- blackboard.set("targetChannel", "#engineering");
484
- blackboard.set("userName", "Alice");
485
-
486
- const context: IntegrationContext = {
487
- blackboard,
488
- treeRegistry: registry,
489
- timestamp: Date.now(),
490
- deltaTime: 0,
491
- input: { messagePrefix: "Notification:" },
492
- tokenProvider: mockTokenProvider,
493
- activities: { executePieceAction: mockActivity },
494
- };
495
-
496
- const node = new IntegrationAction({
497
- id: "notify",
498
- provider: "slack",
499
- action: "send_message",
500
- inputs: {
501
- channel: "${bb.targetChannel}",
502
- text: "${input.messagePrefix} Hello ${bb.userName}!",
503
- },
504
- });
505
-
506
- await node.tick(context);
507
-
508
- expect(mockActivity).toHaveBeenCalledWith(
509
- expect.objectContaining({
510
- inputs: {
511
- channel: "#engineering",
512
- text: "Notification: Hello Alice!",
513
- },
514
- })
515
- );
516
- });
517
- });
518
-
519
- describe("envTokenProvider", () => {
520
- const originalEnv = process.env;
521
-
522
- beforeEach(() => {
523
- process.env = { ...originalEnv };
524
- });
525
-
526
- afterAll(() => {
527
- process.env = originalEnv;
528
- });
529
-
530
- it("should return access_token from environment", async () => {
531
- process.env.GOOGLE_SHEETS_ACCESS_TOKEN = "test_access_token";
532
-
533
- const auth = await envTokenProvider({} as any, "google-sheets");
534
-
535
- expect(auth).toEqual({ access_token: "test_access_token" });
536
- });
537
-
538
- it("should return api_key from environment", async () => {
539
- process.env.OPENAI_API_KEY = "sk-test-key";
540
-
541
- const auth = await envTokenProvider({} as any, "openai");
542
-
543
- expect(auth).toEqual({ api_key: "sk-test-key" });
544
- });
545
-
546
- it("should prefer access_token over api_key", async () => {
547
- process.env.SLACK_ACCESS_TOKEN = "xoxb-token";
548
- process.env.SLACK_API_KEY = "some-key";
549
-
550
- const auth = await envTokenProvider({} as any, "slack");
551
-
552
- expect(auth).toEqual({ access_token: "xoxb-token" });
553
- });
554
-
555
- it("should handle hyphens in provider name", async () => {
556
- process.env.GOOGLE_SHEETS_ACCESS_TOKEN = "test_token";
557
-
558
- const auth = await envTokenProvider({} as any, "google-sheets");
559
-
560
- expect(auth).toEqual({ access_token: "test_token" });
561
- });
562
-
563
- it("should throw if no token found", async () => {
564
- delete process.env.UNKNOWN_ACCESS_TOKEN;
565
- delete process.env.UNKNOWN_API_KEY;
566
-
567
- await expect(envTokenProvider({} as any, "unknown")).rejects.toThrow(
568
- /No token found/
569
- );
570
- });
571
- });