opencode-swarm-plugin 0.44.0 → 0.44.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 (215) hide show
  1. package/bin/swarm.serve.test.ts +6 -4
  2. package/bin/swarm.ts +18 -12
  3. package/dist/compaction-prompt-scoring.js +139 -0
  4. package/dist/eval-capture.js +12811 -0
  5. package/dist/hive.d.ts.map +1 -1
  6. package/dist/hive.js +14834 -0
  7. package/dist/index.d.ts +18 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +7743 -62593
  10. package/dist/plugin.js +24052 -78907
  11. package/dist/swarm-orchestrate.d.ts.map +1 -1
  12. package/dist/swarm-prompts.d.ts.map +1 -1
  13. package/dist/swarm-prompts.js +39407 -0
  14. package/dist/swarm-review.d.ts.map +1 -1
  15. package/dist/swarm-validation.d.ts +127 -0
  16. package/dist/swarm-validation.d.ts.map +1 -0
  17. package/dist/validators/index.d.ts +7 -0
  18. package/dist/validators/index.d.ts.map +1 -0
  19. package/dist/validators/schema-validator.d.ts +58 -0
  20. package/dist/validators/schema-validator.d.ts.map +1 -0
  21. package/package.json +17 -5
  22. package/.changeset/swarm-insights-data-layer.md +0 -63
  23. package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
  24. package/.hive/analysis/session-data-quality-audit.md +0 -320
  25. package/.hive/eval-results.json +0 -483
  26. package/.hive/issues.jsonl +0 -138
  27. package/.hive/memories.jsonl +0 -729
  28. package/.opencode/eval-history.jsonl +0 -327
  29. package/.turbo/turbo-build.log +0 -9
  30. package/CHANGELOG.md +0 -2286
  31. package/SCORER-ANALYSIS.md +0 -598
  32. package/docs/analysis/subagent-coordination-patterns.md +0 -902
  33. package/docs/analysis-socratic-planner-pattern.md +0 -504
  34. package/docs/planning/ADR-001-monorepo-structure.md +0 -171
  35. package/docs/planning/ADR-002-package-extraction.md +0 -393
  36. package/docs/planning/ADR-003-performance-improvements.md +0 -451
  37. package/docs/planning/ADR-004-message-queue-features.md +0 -187
  38. package/docs/planning/ADR-005-devtools-observability.md +0 -202
  39. package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
  40. package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
  41. package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
  42. package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
  43. package/docs/planning/ROADMAP.md +0 -368
  44. package/docs/semantic-memory-cli-syntax.md +0 -123
  45. package/docs/swarm-mail-architecture.md +0 -1147
  46. package/docs/testing/context-recovery-test.md +0 -470
  47. package/evals/ARCHITECTURE.md +0 -1189
  48. package/evals/README.md +0 -768
  49. package/evals/compaction-prompt.eval.ts +0 -149
  50. package/evals/compaction-resumption.eval.ts +0 -289
  51. package/evals/coordinator-behavior.eval.ts +0 -307
  52. package/evals/coordinator-session.eval.ts +0 -154
  53. package/evals/evalite.config.ts.bak +0 -15
  54. package/evals/example.eval.ts +0 -31
  55. package/evals/fixtures/cass-baseline.ts +0 -217
  56. package/evals/fixtures/compaction-cases.ts +0 -350
  57. package/evals/fixtures/compaction-prompt-cases.ts +0 -311
  58. package/evals/fixtures/coordinator-sessions.ts +0 -328
  59. package/evals/fixtures/decomposition-cases.ts +0 -105
  60. package/evals/lib/compaction-loader.test.ts +0 -248
  61. package/evals/lib/compaction-loader.ts +0 -320
  62. package/evals/lib/data-loader.evalite-test.ts +0 -289
  63. package/evals/lib/data-loader.test.ts +0 -345
  64. package/evals/lib/data-loader.ts +0 -281
  65. package/evals/lib/llm.ts +0 -115
  66. package/evals/scorers/compaction-prompt-scorers.ts +0 -145
  67. package/evals/scorers/compaction-scorers.ts +0 -305
  68. package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
  69. package/evals/scorers/coordinator-discipline.ts +0 -325
  70. package/evals/scorers/index.test.ts +0 -146
  71. package/evals/scorers/index.ts +0 -328
  72. package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
  73. package/evals/scorers/outcome-scorers.ts +0 -349
  74. package/evals/swarm-decomposition.eval.ts +0 -121
  75. package/examples/commands/swarm.md +0 -745
  76. package/examples/plugin-wrapper-template.ts +0 -2515
  77. package/examples/skills/hive-workflow/SKILL.md +0 -212
  78. package/examples/skills/skill-creator/SKILL.md +0 -223
  79. package/examples/skills/swarm-coordination/SKILL.md +0 -292
  80. package/global-skills/cli-builder/SKILL.md +0 -344
  81. package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
  82. package/global-skills/learning-systems/SKILL.md +0 -644
  83. package/global-skills/skill-creator/LICENSE.txt +0 -202
  84. package/global-skills/skill-creator/SKILL.md +0 -352
  85. package/global-skills/skill-creator/references/output-patterns.md +0 -82
  86. package/global-skills/skill-creator/references/workflows.md +0 -28
  87. package/global-skills/swarm-coordination/SKILL.md +0 -995
  88. package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
  89. package/global-skills/swarm-coordination/references/strategies.md +0 -138
  90. package/global-skills/system-design/SKILL.md +0 -213
  91. package/global-skills/testing-patterns/SKILL.md +0 -430
  92. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
  93. package/opencode-swarm-plugin-0.30.7.tgz +0 -0
  94. package/opencode-swarm-plugin-0.31.0.tgz +0 -0
  95. package/scripts/cleanup-test-memories.ts +0 -346
  96. package/scripts/init-skill.ts +0 -222
  97. package/scripts/migrate-unknown-sessions.ts +0 -349
  98. package/scripts/validate-skill.ts +0 -204
  99. package/src/agent-mail.ts +0 -1724
  100. package/src/anti-patterns.test.ts +0 -1167
  101. package/src/anti-patterns.ts +0 -448
  102. package/src/compaction-capture.integration.test.ts +0 -257
  103. package/src/compaction-hook.test.ts +0 -838
  104. package/src/compaction-hook.ts +0 -1204
  105. package/src/compaction-observability.integration.test.ts +0 -139
  106. package/src/compaction-observability.test.ts +0 -187
  107. package/src/compaction-observability.ts +0 -324
  108. package/src/compaction-prompt-scorers.test.ts +0 -475
  109. package/src/compaction-prompt-scoring.ts +0 -300
  110. package/src/contributor-tools.test.ts +0 -133
  111. package/src/contributor-tools.ts +0 -201
  112. package/src/dashboard.test.ts +0 -611
  113. package/src/dashboard.ts +0 -462
  114. package/src/error-enrichment.test.ts +0 -403
  115. package/src/error-enrichment.ts +0 -219
  116. package/src/eval-capture.test.ts +0 -1015
  117. package/src/eval-capture.ts +0 -929
  118. package/src/eval-gates.test.ts +0 -306
  119. package/src/eval-gates.ts +0 -218
  120. package/src/eval-history.test.ts +0 -508
  121. package/src/eval-history.ts +0 -214
  122. package/src/eval-learning.test.ts +0 -378
  123. package/src/eval-learning.ts +0 -360
  124. package/src/eval-runner.test.ts +0 -223
  125. package/src/eval-runner.ts +0 -402
  126. package/src/export-tools.test.ts +0 -476
  127. package/src/export-tools.ts +0 -257
  128. package/src/hive.integration.test.ts +0 -2241
  129. package/src/hive.ts +0 -1628
  130. package/src/index.ts +0 -940
  131. package/src/learning.integration.test.ts +0 -1815
  132. package/src/learning.ts +0 -1079
  133. package/src/logger.test.ts +0 -189
  134. package/src/logger.ts +0 -135
  135. package/src/mandate-promotion.test.ts +0 -473
  136. package/src/mandate-promotion.ts +0 -239
  137. package/src/mandate-storage.integration.test.ts +0 -601
  138. package/src/mandate-storage.test.ts +0 -578
  139. package/src/mandate-storage.ts +0 -794
  140. package/src/mandates.ts +0 -540
  141. package/src/memory-tools.test.ts +0 -195
  142. package/src/memory-tools.ts +0 -344
  143. package/src/memory.integration.test.ts +0 -334
  144. package/src/memory.test.ts +0 -158
  145. package/src/memory.ts +0 -527
  146. package/src/model-selection.test.ts +0 -188
  147. package/src/model-selection.ts +0 -68
  148. package/src/observability-tools.test.ts +0 -359
  149. package/src/observability-tools.ts +0 -871
  150. package/src/output-guardrails.test.ts +0 -438
  151. package/src/output-guardrails.ts +0 -381
  152. package/src/pattern-maturity.test.ts +0 -1160
  153. package/src/pattern-maturity.ts +0 -525
  154. package/src/planning-guardrails.test.ts +0 -491
  155. package/src/planning-guardrails.ts +0 -438
  156. package/src/plugin.ts +0 -23
  157. package/src/post-compaction-tracker.test.ts +0 -251
  158. package/src/post-compaction-tracker.ts +0 -237
  159. package/src/query-tools.test.ts +0 -636
  160. package/src/query-tools.ts +0 -324
  161. package/src/rate-limiter.integration.test.ts +0 -466
  162. package/src/rate-limiter.ts +0 -774
  163. package/src/replay-tools.test.ts +0 -496
  164. package/src/replay-tools.ts +0 -240
  165. package/src/repo-crawl.integration.test.ts +0 -441
  166. package/src/repo-crawl.ts +0 -610
  167. package/src/schemas/cell-events.test.ts +0 -347
  168. package/src/schemas/cell-events.ts +0 -807
  169. package/src/schemas/cell.ts +0 -257
  170. package/src/schemas/evaluation.ts +0 -166
  171. package/src/schemas/index.test.ts +0 -199
  172. package/src/schemas/index.ts +0 -286
  173. package/src/schemas/mandate.ts +0 -232
  174. package/src/schemas/swarm-context.ts +0 -115
  175. package/src/schemas/task.ts +0 -161
  176. package/src/schemas/worker-handoff.test.ts +0 -302
  177. package/src/schemas/worker-handoff.ts +0 -131
  178. package/src/sessions/agent-discovery.test.ts +0 -137
  179. package/src/sessions/agent-discovery.ts +0 -112
  180. package/src/sessions/index.ts +0 -15
  181. package/src/skills.integration.test.ts +0 -1192
  182. package/src/skills.test.ts +0 -643
  183. package/src/skills.ts +0 -1549
  184. package/src/storage.integration.test.ts +0 -341
  185. package/src/storage.ts +0 -884
  186. package/src/structured.integration.test.ts +0 -817
  187. package/src/structured.test.ts +0 -1046
  188. package/src/structured.ts +0 -762
  189. package/src/swarm-decompose.test.ts +0 -188
  190. package/src/swarm-decompose.ts +0 -1302
  191. package/src/swarm-deferred.integration.test.ts +0 -157
  192. package/src/swarm-deferred.test.ts +0 -38
  193. package/src/swarm-insights.test.ts +0 -214
  194. package/src/swarm-insights.ts +0 -459
  195. package/src/swarm-mail.integration.test.ts +0 -970
  196. package/src/swarm-mail.ts +0 -739
  197. package/src/swarm-orchestrate.integration.test.ts +0 -282
  198. package/src/swarm-orchestrate.test.ts +0 -548
  199. package/src/swarm-orchestrate.ts +0 -3084
  200. package/src/swarm-prompts.test.ts +0 -1270
  201. package/src/swarm-prompts.ts +0 -2077
  202. package/src/swarm-research.integration.test.ts +0 -701
  203. package/src/swarm-research.test.ts +0 -698
  204. package/src/swarm-research.ts +0 -472
  205. package/src/swarm-review.integration.test.ts +0 -285
  206. package/src/swarm-review.test.ts +0 -879
  207. package/src/swarm-review.ts +0 -709
  208. package/src/swarm-strategies.ts +0 -407
  209. package/src/swarm-worktree.test.ts +0 -501
  210. package/src/swarm-worktree.ts +0 -575
  211. package/src/swarm.integration.test.ts +0 -2377
  212. package/src/swarm.ts +0 -38
  213. package/src/tool-adapter.integration.test.ts +0 -1221
  214. package/src/tool-availability.ts +0 -461
  215. package/tsconfig.json +0 -28
@@ -1,601 +0,0 @@
1
- /**
2
- * Integration tests for mandate_* tools
3
- *
4
- * Tests the complete tool execution flow through tool.execute():
5
- * - mandate_file: Submit mandates
6
- * - mandate_vote: Cast votes with promotion logic
7
- * - mandate_query: Semantic search
8
- * - mandate_list: List with filters
9
- * - mandate_stats: Statistics calculation
10
- *
11
- * ## Test Pattern
12
- * - Call tool.execute() directly (simulates plugin invocation)
13
- * - Use InMemoryMandateStorage for isolation
14
- * - Test happy paths and real-world workflows
15
- * - Unit tests cover storage implementation details
16
- */
17
-
18
- import type { ToolContext } from "@opencode-ai/plugin";
19
- import { afterEach, beforeEach, describe, expect, it } from "bun:test";
20
- import {
21
- mandate_file,
22
- mandate_list,
23
- mandate_query,
24
- mandate_stats,
25
- mandate_vote,
26
- } from "./mandates";
27
- import {
28
- type MandateStorage,
29
- createMandateStorage,
30
- resetMandateStorage,
31
- setMandateStorage,
32
- } from "./mandate-storage";
33
-
34
- // Mock ToolContext for tool execution
35
- const mockCtx = {} as ToolContext;
36
-
37
- // Test storage instance
38
- let storage: MandateStorage;
39
-
40
- describe("Mandate Tools Integration", () => {
41
- beforeEach(async () => {
42
- // Create isolated in-memory storage for each test
43
- storage = createMandateStorage({ backend: "memory" });
44
- setMandateStorage(storage);
45
- });
46
-
47
- afterEach(async () => {
48
- // Clean up
49
- await resetMandateStorage();
50
- });
51
-
52
- // ============================================================================
53
- // mandate_file - Create and Store Mandate
54
- // ============================================================================
55
-
56
- describe("mandate_file integration", () => {
57
- it("creates mandate entry successfully", async () => {
58
- const result = await mandate_file.execute(
59
- {
60
- content: "Always use Effect for async operations",
61
- content_type: "tip",
62
- tags: ["async", "effect", "best-practices"],
63
- },
64
- mockCtx,
65
- );
66
-
67
- const parsed = JSON.parse(result);
68
- expect(parsed.success).toBe(true);
69
- expect(parsed.mandate).toBeDefined();
70
- expect(parsed.mandate.id).toContain("mandate-");
71
- expect(parsed.mandate.content).toBe("Always use Effect for async operations");
72
- expect(parsed.mandate.status).toBe("candidate");
73
- });
74
-
75
- it("supports all content types", async () => {
76
- const types = ["idea", "tip", "lore", "snippet", "feature_request"] as const;
77
-
78
- for (const type of types) {
79
- const result = await mandate_file.execute(
80
- {
81
- content: `Test ${type}`,
82
- content_type: type,
83
- tags: [],
84
- },
85
- mockCtx,
86
- );
87
-
88
- const parsed = JSON.parse(result);
89
- expect(parsed.success).toBe(true);
90
- expect(parsed.mandate.content_type).toBe(type);
91
- }
92
- });
93
-
94
- it("supports metadata for snippets", async () => {
95
- const result = await mandate_file.execute(
96
- {
97
- content: 'const retry = <T>(fn: () => Promise<T>, n: number) => fn().catch(e => n > 0 ? retry(fn, n - 1) : Promise.reject(e));',
98
- content_type: "snippet",
99
- tags: ["typescript"],
100
- metadata: { language: "typescript", category: "retry" },
101
- },
102
- mockCtx,
103
- );
104
-
105
- const parsed = JSON.parse(result);
106
- expect(parsed.success).toBe(true);
107
- expect(parsed.mandate.metadata).toEqual({
108
- language: "typescript",
109
- category: "retry",
110
- });
111
- });
112
-
113
- it("generates unique IDs", async () => {
114
- const results = await Promise.all([
115
- mandate_file.execute(
116
- { content: "M1", content_type: "tip", tags: [] },
117
- mockCtx,
118
- ),
119
- mandate_file.execute(
120
- { content: "M2", content_type: "tip", tags: [] },
121
- mockCtx,
122
- ),
123
- mandate_file.execute(
124
- { content: "M3", content_type: "tip", tags: [] },
125
- mockCtx,
126
- ),
127
- ]);
128
-
129
- const ids = results.map((r) => JSON.parse(r).mandate.id);
130
- const uniqueIds = new Set(ids);
131
- expect(uniqueIds.size).toBe(3);
132
- });
133
- });
134
-
135
- // ============================================================================
136
- // mandate_vote - Cast Votes with Promotion
137
- // ============================================================================
138
-
139
- describe("mandate_vote integration", () => {
140
- let mandateId: string;
141
-
142
- beforeEach(async () => {
143
- // Create a mandate to vote on
144
- const createResult = await mandate_file.execute(
145
- {
146
- content: "Use TDD for all new features",
147
- content_type: "tip",
148
- tags: ["testing"],
149
- },
150
- mockCtx,
151
- );
152
- mandateId = JSON.parse(createResult).mandate.id;
153
- });
154
-
155
- it("casts upvote successfully with promotion data", async () => {
156
- const result = await mandate_vote.execute(
157
- {
158
- mandate_id: mandateId,
159
- vote_type: "upvote",
160
- agent_name: "TestAgent",
161
- },
162
- mockCtx,
163
- );
164
-
165
- const parsed = JSON.parse(result);
166
- expect(parsed.success).toBe(true);
167
- expect(parsed.vote).toBeDefined();
168
- expect(parsed.vote.vote_type).toBe("upvote");
169
- expect(parsed.promotion).toBeDefined();
170
- expect(parsed.promotion.score).toBeDefined();
171
- });
172
-
173
- it("casts downvote successfully", async () => {
174
- const result = await mandate_vote.execute(
175
- {
176
- mandate_id: mandateId,
177
- vote_type: "downvote",
178
- agent_name: "TestAgent",
179
- },
180
- mockCtx,
181
- );
182
-
183
- const parsed = JSON.parse(result);
184
- expect(parsed.success).toBe(true);
185
- expect(parsed.vote.vote_type).toBe("downvote");
186
- });
187
-
188
- it("defaults weight to 1.0", async () => {
189
- const result = await mandate_vote.execute(
190
- {
191
- mandate_id: mandateId,
192
- vote_type: "upvote",
193
- agent_name: "TestAgent",
194
- },
195
- mockCtx,
196
- );
197
-
198
- const parsed = JSON.parse(result);
199
- expect(parsed.success).toBe(true);
200
- // Tool hardcodes weight to 1.0 (see mandates.ts line 170)
201
- expect(parsed.vote.weight).toBe(1.0);
202
- });
203
-
204
- it("prevents duplicate votes from same agent", async () => {
205
- // First vote succeeds
206
- const result1 = await mandate_vote.execute(
207
- {
208
- mandate_id: mandateId,
209
- vote_type: "upvote",
210
- agent_name: "Agent1",
211
- },
212
- mockCtx,
213
- );
214
- expect(JSON.parse(result1).success).toBe(true);
215
-
216
- // Second vote from same agent fails
217
- await expect(
218
- mandate_vote.execute(
219
- {
220
- mandate_id: mandateId,
221
- vote_type: "downvote",
222
- agent_name: "Agent1",
223
- },
224
- mockCtx,
225
- ),
226
- ).rejects.toThrow("already voted");
227
- });
228
-
229
- it("allows different agents to vote", async () => {
230
- const result1 = await mandate_vote.execute(
231
- {
232
- mandate_id: mandateId,
233
- vote_type: "upvote",
234
- agent_name: "Agent1",
235
- },
236
- mockCtx,
237
- );
238
- expect(JSON.parse(result1).success).toBe(true);
239
-
240
- const result2 = await mandate_vote.execute(
241
- {
242
- mandate_id: mandateId,
243
- vote_type: "upvote",
244
- agent_name: "Agent2",
245
- },
246
- mockCtx,
247
- );
248
- expect(JSON.parse(result2).success).toBe(true);
249
- });
250
- });
251
-
252
- // ============================================================================
253
- // mandate_query - Semantic Search
254
- // ============================================================================
255
-
256
- describe("mandate_query integration", () => {
257
- beforeEach(async () => {
258
- // Create searchable mandates
259
- await mandate_file.execute(
260
- {
261
- content: "Always use Effect for async operations",
262
- content_type: "tip",
263
- tags: ["async", "effect"],
264
- },
265
- mockCtx,
266
- );
267
- await mandate_file.execute(
268
- {
269
- content: "Prefer semantic memory for persistence",
270
- content_type: "tip",
271
- tags: ["storage"],
272
- },
273
- mockCtx,
274
- );
275
- });
276
-
277
- it("searches by content text", async () => {
278
- const result = await mandate_query.execute(
279
- { query: "Effect" },
280
- mockCtx,
281
- );
282
-
283
- const parsed = JSON.parse(result);
284
- expect(parsed.count).toBeGreaterThanOrEqual(1);
285
- expect(parsed.results.length).toBeGreaterThanOrEqual(1);
286
- expect(parsed.results[0]).toHaveProperty("content");
287
- expect(parsed.results[0]).toHaveProperty("score");
288
- });
289
-
290
- it("limits results", async () => {
291
- const result = await mandate_query.execute(
292
- { query: "tip", limit: 1 },
293
- mockCtx,
294
- );
295
-
296
- const parsed = JSON.parse(result);
297
- expect(parsed.results.length).toBeLessThanOrEqual(1);
298
- });
299
-
300
- it("returns empty for non-matching query", async () => {
301
- const result = await mandate_query.execute(
302
- { query: "nonexistent123xyz" },
303
- mockCtx,
304
- );
305
-
306
- const parsed = JSON.parse(result);
307
- expect(parsed.count).toBe(0);
308
- });
309
- });
310
-
311
- // ============================================================================
312
- // mandate_list - List with Filters
313
- // ============================================================================
314
-
315
- describe("mandate_list integration", () => {
316
- beforeEach(async () => {
317
- await mandate_file.execute(
318
- { content: "Tip 1", content_type: "tip", tags: [] },
319
- mockCtx,
320
- );
321
- await mandate_file.execute(
322
- { content: "Idea 1", content_type: "idea", tags: [] },
323
- mockCtx,
324
- );
325
- await mandate_file.execute(
326
- { content: "Lore 1", content_type: "lore", tags: [] },
327
- mockCtx,
328
- );
329
- });
330
-
331
- it("lists all mandates when no filter", async () => {
332
- const result = await mandate_list.execute({}, mockCtx);
333
-
334
- const parsed = JSON.parse(result);
335
- expect(parsed.count).toBe(3);
336
- expect(parsed.results.length).toBe(3);
337
- });
338
-
339
- it("filters by content_type", async () => {
340
- const result = await mandate_list.execute(
341
- { content_type: "tip" },
342
- mockCtx,
343
- );
344
-
345
- const parsed = JSON.parse(result);
346
- expect(parsed.count).toBe(1);
347
- expect(parsed.results[0].content_type).toBe("tip");
348
- });
349
-
350
- it("filters by status", async () => {
351
- const result = await mandate_list.execute(
352
- { status: "candidate" },
353
- mockCtx,
354
- );
355
-
356
- const parsed = JSON.parse(result);
357
- // All new mandates start as candidate
358
- expect(parsed.count).toBe(3);
359
- });
360
-
361
- it("returns empty list when no matches", async () => {
362
- const result = await mandate_list.execute(
363
- { status: "mandate" }, // No mandates promoted yet
364
- mockCtx,
365
- );
366
-
367
- const parsed = JSON.parse(result);
368
- expect(parsed.count).toBe(0);
369
- });
370
- });
371
-
372
- // ============================================================================
373
- // mandate_stats - Statistics
374
- // ============================================================================
375
-
376
- describe("mandate_stats integration", () => {
377
- it("returns zero stats for empty storage", async () => {
378
- const result = await mandate_stats.execute({}, mockCtx);
379
-
380
- const parsed = JSON.parse(result);
381
- expect(parsed.total_mandates).toBe(0);
382
- expect(parsed.by_status).toBeDefined();
383
- expect(parsed.by_content_type).toBeDefined();
384
- expect(parsed.total_votes).toBe(0);
385
- });
386
-
387
- it("counts mandates by status", async () => {
388
- await mandate_file.execute(
389
- { content: "Tip 1", content_type: "tip", tags: [] },
390
- mockCtx,
391
- );
392
- await mandate_file.execute(
393
- { content: "Tip 2", content_type: "tip", tags: [] },
394
- mockCtx,
395
- );
396
-
397
- const result = await mandate_stats.execute({}, mockCtx);
398
-
399
- const parsed = JSON.parse(result);
400
- expect(parsed.total_mandates).toBe(2);
401
- expect(parsed.by_status.candidate).toBe(2);
402
- });
403
-
404
- it("counts mandates by content type", async () => {
405
- await mandate_file.execute(
406
- { content: "Tip 1", content_type: "tip", tags: [] },
407
- mockCtx,
408
- );
409
- await mandate_file.execute(
410
- { content: "Idea 1", content_type: "idea", tags: [] },
411
- mockCtx,
412
- );
413
-
414
- const result = await mandate_stats.execute({}, mockCtx);
415
-
416
- const parsed = JSON.parse(result);
417
- expect(parsed.by_content_type.tip).toBe(1);
418
- expect(parsed.by_content_type.idea).toBe(1);
419
- });
420
-
421
- it("counts total votes after voting", async () => {
422
- // Create mandate
423
- const createResult = await mandate_file.execute(
424
- { content: "Test", content_type: "tip", tags: [] },
425
- mockCtx,
426
- );
427
- const mandateId = JSON.parse(createResult).mandate.id;
428
-
429
- // Cast votes
430
- await mandate_vote.execute(
431
- {
432
- mandate_id: mandateId,
433
- vote_type: "upvote",
434
- agent_name: "Agent1",
435
- },
436
- mockCtx,
437
- );
438
- await mandate_vote.execute(
439
- {
440
- mandate_id: mandateId,
441
- vote_type: "upvote",
442
- agent_name: "Agent2",
443
- },
444
- mockCtx,
445
- );
446
-
447
- const result = await mandate_stats.execute({}, mockCtx);
448
-
449
- const parsed = JSON.parse(result);
450
- expect(parsed.total_votes).toBe(2);
451
- });
452
- });
453
-
454
- // ============================================================================
455
- // Integration: Complete Workflows
456
- // ============================================================================
457
-
458
- describe("Complete voting workflow", () => {
459
- it("file → vote → query → stats workflow", async () => {
460
- // 1. File a mandate
461
- const createResult = await mandate_file.execute(
462
- {
463
- content: "Always write integration tests",
464
- content_type: "tip",
465
- tags: ["testing"],
466
- },
467
- mockCtx,
468
- );
469
- const mandateId = JSON.parse(createResult).mandate.id;
470
-
471
- // 2. Cast votes
472
- await mandate_vote.execute(
473
- {
474
- mandate_id: mandateId,
475
- vote_type: "upvote",
476
- agent_name: "Agent1",
477
- },
478
- mockCtx,
479
- );
480
- await mandate_vote.execute(
481
- {
482
- mandate_id: mandateId,
483
- vote_type: "upvote",
484
- agent_name: "Agent2",
485
- },
486
- mockCtx,
487
- );
488
-
489
- // 3. Query finds it
490
- const queryResult = await mandate_query.execute(
491
- { query: "integration tests" },
492
- mockCtx,
493
- );
494
- const query = JSON.parse(queryResult);
495
- expect(query.count).toBeGreaterThanOrEqual(1);
496
-
497
- // 4. Stats reflect votes
498
- const statsResult = await mandate_stats.execute({}, mockCtx);
499
- const stats = JSON.parse(statsResult);
500
- expect(stats.total_votes).toBe(2);
501
- expect(stats.total_mandates).toBe(1);
502
- });
503
-
504
- it("supports multiple mandates with independent voting", async () => {
505
- // Create multiple mandates
506
- const create1 = await mandate_file.execute(
507
- { content: "Mandate 1", content_type: "tip", tags: [] },
508
- mockCtx,
509
- );
510
- const create2 = await mandate_file.execute(
511
- { content: "Mandate 2", content_type: "idea", tags: [] },
512
- mockCtx,
513
- );
514
-
515
- const mandate1Id = JSON.parse(create1).mandate.id;
516
- const mandate2Id = JSON.parse(create2).mandate.id;
517
-
518
- // Vote on both (different agents)
519
- await mandate_vote.execute(
520
- {
521
- mandate_id: mandate1Id,
522
- vote_type: "upvote",
523
- agent_name: "Agent1",
524
- },
525
- mockCtx,
526
- );
527
- await mandate_vote.execute(
528
- {
529
- mandate_id: mandate2Id,
530
- vote_type: "downvote",
531
- agent_name: "Agent1",
532
- },
533
- mockCtx,
534
- );
535
-
536
- // Stats show correct counts
537
- const statsResult = await mandate_stats.execute({}, mockCtx);
538
- const stats = JSON.parse(statsResult);
539
- expect(stats.total_votes).toBe(2);
540
- expect(stats.total_mandates).toBe(2);
541
- });
542
- });
543
-
544
- // ============================================================================
545
- // Edge Cases
546
- // ============================================================================
547
-
548
- describe("Edge cases and error handling", () => {
549
- it("handles unicode and special characters", async () => {
550
- const result = await mandate_file.execute(
551
- {
552
- content: "Use emoji for clarity 🎉 和 你好",
553
- content_type: "tip",
554
- tags: ["unicode"],
555
- },
556
- mockCtx,
557
- );
558
-
559
- const parsed = JSON.parse(result);
560
- expect(parsed.success).toBe(true);
561
- expect(parsed.mandate.content).toContain("🎉");
562
- });
563
-
564
- it("handles empty tags array", async () => {
565
- const result = await mandate_file.execute(
566
- {
567
- content: "No tags mandate",
568
- content_type: "tip",
569
- tags: [],
570
- },
571
- mockCtx,
572
- );
573
-
574
- const parsed = JSON.parse(result);
575
- expect(parsed.success).toBe(true);
576
- expect(parsed.mandate.tags).toEqual([]);
577
- });
578
-
579
- it("handles large metadata objects", async () => {
580
- const largeMetadata = {
581
- key1: "value1",
582
- nested: { deep: { object: "value" } },
583
- array: [1, 2, 3, 4, 5],
584
- };
585
-
586
- const result = await mandate_file.execute(
587
- {
588
- content: "Mandate with metadata",
589
- content_type: "snippet",
590
- tags: [],
591
- metadata: largeMetadata,
592
- },
593
- mockCtx,
594
- );
595
-
596
- const parsed = JSON.parse(result);
597
- expect(parsed.success).toBe(true);
598
- expect(parsed.mandate.metadata).toEqual(largeMetadata);
599
- });
600
- });
601
- });