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,476 +0,0 @@
1
- /**
2
- * RED PHASE: Export Tools Tests
3
- *
4
- * Tests for exporting cell events to:
5
- * 1. OTLP (OpenTelemetry Protocol) - distributed tracing format
6
- * 2. CSV - spreadsheet/analysis format
7
- * 3. JSON - generic interchange format
8
- *
9
- * These tests SHOULD FAIL because export-tools.ts doesn't exist yet.
10
- * Implementation comes in GREEN phase.
11
- */
12
-
13
- import { describe, test, expect } from "bun:test";
14
- import { exportToOTLP, exportToCSV, exportToJSON } from "./export-tools.js";
15
- import type { CellEvent } from "./schemas/cell-events.js";
16
-
17
- // ============================================================================
18
- // Test Fixtures - Known Event Data
19
- // ============================================================================
20
-
21
- /**
22
- * Fixture: Cell created event with known timestamp
23
- */
24
- const fixtureCreated: CellEvent = {
25
- type: "cell_created",
26
- project_key: "/test/project",
27
- timestamp: 1735142400000, // 2024-12-25 12:00:00 UTC
28
- cell_id: "test-epic-abc123",
29
- title: "Implement authentication",
30
- description: "Add OAuth2 flow with JWT tokens",
31
- issue_type: "feature",
32
- priority: 2,
33
- created_by: "BlueOcean",
34
- metadata: {
35
- epic_id: "test-epic-parent",
36
- strategy: "feature-based",
37
- },
38
- };
39
-
40
- /**
41
- * Fixture: Cell status changed event
42
- */
43
- const fixtureStatusChanged: CellEvent = {
44
- type: "cell_status_changed",
45
- project_key: "/test/project",
46
- timestamp: 1735142460000, // 1 minute after creation
47
- cell_id: "test-epic-abc123",
48
- from_status: "open",
49
- to_status: "in_progress",
50
- changed_by: "BlueOcean",
51
- };
52
-
53
- /**
54
- * Fixture: Cell closed event with special characters in reason
55
- */
56
- const fixtureClosedWithSpecialChars: CellEvent = {
57
- type: "cell_closed",
58
- project_key: "/test/project",
59
- timestamp: 1735146000000, // 1 hour after creation
60
- cell_id: "test-epic-abc123",
61
- reason: 'Completed: implemented OAuth2, added "refresh token" logic, tested with mock provider',
62
- closed_by: "BlueOcean",
63
- files_touched: ["src/auth/oauth.ts", "src/auth/jwt.ts"],
64
- duration_ms: 3600000, // 1 hour
65
- };
66
-
67
- /**
68
- * Fixture: Cell with commas and quotes in title (CSV edge case)
69
- */
70
- const fixtureCsvEdgeCase: CellEvent = {
71
- type: "cell_created",
72
- project_key: "/test/project",
73
- timestamp: 1735142400000,
74
- cell_id: "test-csv-edge",
75
- title: 'Fix bug in parser: handle "quoted strings", commas, and newlines',
76
- issue_type: "bug",
77
- priority: 1,
78
- };
79
-
80
- // ============================================================================
81
- // OTLP Export Tests
82
- // ============================================================================
83
-
84
- describe("exportToOTLP", () => {
85
- test("produces valid OpenTelemetry JSON structure", () => {
86
- const events = [fixtureCreated, fixtureStatusChanged, fixtureClosedWithSpecialChars];
87
- const otlp = exportToOTLP(events);
88
-
89
- // Should have top-level OTLP structure
90
- expect(otlp).toHaveProperty("resourceSpans");
91
- expect(Array.isArray(otlp.resourceSpans)).toBe(true);
92
- expect(otlp.resourceSpans.length).toBeGreaterThan(0);
93
-
94
- // First resource span should have scope and spans
95
- const resourceSpan = otlp.resourceSpans[0];
96
- expect(resourceSpan).toHaveProperty("resource");
97
- expect(resourceSpan).toHaveProperty("scopeSpans");
98
- expect(Array.isArray(resourceSpan.scopeSpans)).toBe(true);
99
-
100
- // Scope should identify swarm
101
- const scopeSpan = resourceSpan.scopeSpans[0];
102
- expect(scopeSpan.scope.name).toBe("swarm");
103
- });
104
-
105
- test("maps epic_id to trace_id (hex string)", () => {
106
- const events = [fixtureCreated];
107
- const otlp = exportToOTLP(events);
108
-
109
- const spans = otlp.resourceSpans[0].scopeSpans[0].spans;
110
- expect(spans.length).toBeGreaterThan(0);
111
-
112
- const span = spans[0];
113
- expect(span).toHaveProperty("traceId");
114
- expect(typeof span.traceId).toBe("string");
115
-
116
- // trace_id should be hex string derived from epic_id
117
- // Epic ID from metadata: "test-epic-parent"
118
- expect(span.traceId).toMatch(/^[0-9a-f]+$/);
119
- expect(span.traceId.length).toBe(32); // OTLP trace_id is 16 bytes = 32 hex chars
120
- });
121
-
122
- test("maps cell_id to span_id (hex string)", () => {
123
- const events = [fixtureCreated];
124
- const otlp = exportToOTLP(events);
125
-
126
- const spans = otlp.resourceSpans[0].scopeSpans[0].spans;
127
- const span = spans[0];
128
-
129
- expect(span).toHaveProperty("spanId");
130
- expect(typeof span.spanId).toBe("string");
131
-
132
- // span_id should be hex string derived from cell_id
133
- // Cell ID: "test-epic-abc123"
134
- expect(span.spanId).toMatch(/^[0-9a-f]+$/);
135
- expect(span.spanId.length).toBe(16); // OTLP span_id is 8 bytes = 16 hex chars
136
- });
137
-
138
- test("maps timestamp to startTimeUnixNano", () => {
139
- const events = [fixtureCreated];
140
- const otlp = exportToOTLP(events);
141
-
142
- const spans = otlp.resourceSpans[0].scopeSpans[0].spans;
143
- const span = spans[0];
144
-
145
- expect(span).toHaveProperty("startTimeUnixNano");
146
-
147
- // Should be string representation of nanoseconds
148
- // fixtureCreated.timestamp = 1735142400000 ms
149
- // In nanoseconds: 1735142400000 * 1_000_000
150
- const expectedNano = "1735142400000000000";
151
- expect(span.startTimeUnixNano).toBe(expectedNano);
152
- });
153
-
154
- test("maps event type to span name", () => {
155
- const events = [fixtureCreated, fixtureStatusChanged, fixtureClosedWithSpecialChars];
156
- const otlp = exportToOTLP(events);
157
-
158
- const spans = otlp.resourceSpans[0].scopeSpans[0].spans;
159
-
160
- // Should have 3 spans, one per event
161
- expect(spans.length).toBe(3);
162
-
163
- // Event types become span names
164
- expect(spans[0].name).toBe("cell_created");
165
- expect(spans[1].name).toBe("cell_status_changed");
166
- expect(spans[2].name).toBe("cell_closed");
167
- });
168
-
169
- test("includes event payload as span attributes", () => {
170
- const events = [fixtureCreated];
171
- const otlp = exportToOTLP(events);
172
-
173
- const spans = otlp.resourceSpans[0].scopeSpans[0].spans;
174
- const span = spans[0];
175
-
176
- expect(span).toHaveProperty("attributes");
177
- expect(Array.isArray(span.attributes)).toBe(true);
178
-
179
- // Should include key event fields as attributes
180
- const attrs = span.attributes;
181
-
182
- // Find specific attributes by key
183
- const titleAttr = attrs.find((a: { key: string }) => a.key === "cell.title");
184
- expect(titleAttr).toBeDefined();
185
- expect(titleAttr.value.stringValue).toBe("Implement authentication");
186
-
187
- const priorityAttr = attrs.find((a: { key: string }) => a.key === "cell.priority");
188
- expect(priorityAttr).toBeDefined();
189
- expect(priorityAttr.value.intValue).toBe(2);
190
-
191
- const typeAttr = attrs.find((a: { key: string }) => a.key === "cell.type");
192
- expect(typeAttr).toBeDefined();
193
- expect(typeAttr.value.stringValue).toBe("feature");
194
- });
195
-
196
- test("handles events with missing epic_id in metadata", () => {
197
- // Event without epic_id - should derive trace_id from project_key
198
- const eventWithoutEpic: CellEvent = {
199
- type: "cell_created",
200
- project_key: "/test/project",
201
- timestamp: 1735142400000,
202
- cell_id: "standalone-cell",
203
- title: "Standalone task",
204
- issue_type: "task",
205
- priority: 1,
206
- };
207
-
208
- const otlp = exportToOTLP([eventWithoutEpic]);
209
- const spans = otlp.resourceSpans[0].scopeSpans[0].spans;
210
- const span = spans[0];
211
-
212
- // Should still have valid trace_id (derived from project_key)
213
- expect(span.traceId).toMatch(/^[0-9a-f]{32}$/);
214
- expect(span.spanId).toMatch(/^[0-9a-f]{16}$/);
215
- });
216
-
217
- test("preserves event ordering in spans array", () => {
218
- const events = [fixtureCreated, fixtureStatusChanged, fixtureClosedWithSpecialChars];
219
- const otlp = exportToOTLP(events);
220
-
221
- const spans = otlp.resourceSpans[0].scopeSpans[0].spans;
222
-
223
- // Spans should be in same order as input events
224
- expect(spans[0].name).toBe("cell_created");
225
- expect(spans[1].name).toBe("cell_status_changed");
226
- expect(spans[2].name).toBe("cell_closed");
227
-
228
- // Timestamps should be monotonically increasing
229
- const t0 = BigInt(spans[0].startTimeUnixNano);
230
- const t1 = BigInt(spans[1].startTimeUnixNano);
231
- const t2 = BigInt(spans[2].startTimeUnixNano);
232
-
233
- expect(t1).toBeGreaterThan(t0);
234
- expect(t2).toBeGreaterThan(t1);
235
- });
236
- });
237
-
238
- // ============================================================================
239
- // CSV Export Tests
240
- // ============================================================================
241
-
242
- describe("exportToCSV", () => {
243
- test("includes CSV headers", () => {
244
- const events = [fixtureCreated];
245
- const csv = exportToCSV(events);
246
-
247
- const lines = csv.split("\n");
248
-
249
- // First line should be headers
250
- expect(lines[0]).toBe("id,type,timestamp,project_key,cell_id,payload");
251
- });
252
-
253
- test("escapes commas in payload fields", () => {
254
- const events = [fixtureCsvEdgeCase];
255
- const csv = exportToCSV(events);
256
-
257
- const lines = csv.split("\n");
258
-
259
- // Title has commas: 'Fix bug in parser: handle "quoted strings", commas, and newlines'
260
- // CSV should quote the entire payload field
261
- const dataLine = lines[1];
262
-
263
- // Should contain quoted payload with escaped inner quotes
264
- expect(dataLine).toContain('"');
265
-
266
- // Should NOT have unquoted commas in payload (would break CSV parsing)
267
- // The payload field itself should be wrapped in quotes if it contains commas
268
- const fields = dataLine.match(/("(?:[^"]|"")*"|[^,]*)/g);
269
- expect(fields).toBeDefined();
270
-
271
- // Last non-empty field (payload) should be quoted
272
- const nonEmptyFields = fields!.filter((f) => f !== "");
273
- const payloadField = nonEmptyFields[nonEmptyFields.length - 1];
274
- expect(payloadField.startsWith('"')).toBe(true);
275
- });
276
-
277
- test("escapes double quotes in payload", () => {
278
- const events = [fixtureCsvEdgeCase];
279
- const csv = exportToCSV(events);
280
-
281
- const lines = csv.split("\n");
282
- const dataLine = lines[1];
283
-
284
- // Original title: 'Fix bug in parser: handle "quoted strings", commas, and newlines'
285
- // In CSV, inner quotes should be escaped as ""
286
- expect(dataLine).toContain('""quoted strings""');
287
- });
288
-
289
- test("one event per line (no embedded newlines)", () => {
290
- const events = [fixtureCreated, fixtureStatusChanged, fixtureClosedWithSpecialChars];
291
- const csv = exportToCSV(events);
292
-
293
- const lines = csv.split("\n").filter((line) => line.trim() !== "");
294
-
295
- // Header + 3 data lines
296
- expect(lines.length).toBe(4);
297
-
298
- // Each line should have same number of commas (field separators)
299
- const headerCommas = (lines[0].match(/,/g) || []).length;
300
-
301
- for (let i = 1; i < lines.length; i++) {
302
- // Count commas in line (should match header comma count)
303
- // This validates no embedded commas broke the structure
304
- const lineCommas = (lines[i].match(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/g) || []).length;
305
- expect(lineCommas).toBe(headerCommas);
306
- }
307
- });
308
-
309
- test("serializes payload as JSON string", () => {
310
- const events = [fixtureCreated];
311
- const csv = exportToCSV(events);
312
-
313
- const lines = csv.split("\n");
314
- const dataLine = lines[1];
315
-
316
- // Payload should be JSON representation of event (minus headers)
317
- // Should include fields like title, description, priority, etc.
318
- expect(dataLine).toContain("Implement authentication");
319
- expect(dataLine).toContain("OAuth2");
320
- });
321
-
322
- test("handles empty events array", () => {
323
- const csv = exportToCSV([]);
324
-
325
- // Should still have headers, no data lines
326
- const lines = csv.split("\n").filter((line) => line.trim() !== "");
327
- expect(lines.length).toBe(1);
328
- expect(lines[0]).toBe("id,type,timestamp,project_key,cell_id,payload");
329
- });
330
-
331
- test("includes all event fields in payload", () => {
332
- const events = [fixtureClosedWithSpecialChars];
333
- const csv = exportToCSV(events);
334
-
335
- const lines = csv.split("\n");
336
- const dataLine = lines[1];
337
-
338
- // Should include all event-specific fields
339
- expect(dataLine).toContain("files_touched");
340
- expect(dataLine).toContain("duration_ms");
341
- expect(dataLine).toContain("3600000"); // Duration value
342
- });
343
- });
344
-
345
- // ============================================================================
346
- // JSON Export Tests
347
- // ============================================================================
348
-
349
- describe("exportToJSON", () => {
350
- test("produces valid JSON array", () => {
351
- const events = [fixtureCreated, fixtureStatusChanged];
352
- const json = exportToJSON(events);
353
-
354
- // Should be parseable JSON
355
- expect(() => JSON.parse(json)).not.toThrow();
356
-
357
- const parsed = JSON.parse(json);
358
-
359
- // Should be an array
360
- expect(Array.isArray(parsed)).toBe(true);
361
- expect(parsed.length).toBe(2);
362
- });
363
-
364
- test("preserves all event fields", () => {
365
- const events = [fixtureCreated];
366
- const json = exportToJSON(events);
367
- const parsed = JSON.parse(json);
368
-
369
- const event = parsed[0];
370
-
371
- // All fields from fixture should be present
372
- expect(event.type).toBe("cell_created");
373
- expect(event.project_key).toBe("/test/project");
374
- expect(event.timestamp).toBe(1735142400000);
375
- expect(event.cell_id).toBe("test-epic-abc123");
376
- expect(event.title).toBe("Implement authentication");
377
- expect(event.description).toBe("Add OAuth2 flow with JWT tokens");
378
- expect(event.issue_type).toBe("feature");
379
- expect(event.priority).toBe(2);
380
- expect(event.created_by).toBe("BlueOcean");
381
- expect(event.metadata).toEqual({
382
- epic_id: "test-epic-parent",
383
- strategy: "feature-based",
384
- });
385
- });
386
-
387
- test("preserves event type discriminators", () => {
388
- const events = [fixtureCreated, fixtureStatusChanged, fixtureClosedWithSpecialChars];
389
- const json = exportToJSON(events);
390
- const parsed = JSON.parse(json);
391
-
392
- // Each event should maintain its type
393
- expect(parsed[0].type).toBe("cell_created");
394
- expect(parsed[1].type).toBe("cell_status_changed");
395
- expect(parsed[2].type).toBe("cell_closed");
396
-
397
- // Type-specific fields should be preserved
398
- expect(parsed[1].from_status).toBe("open");
399
- expect(parsed[1].to_status).toBe("in_progress");
400
-
401
- expect(parsed[2].reason).toContain("OAuth2");
402
- expect(parsed[2].files_touched).toEqual(["src/auth/oauth.ts", "src/auth/jwt.ts"]);
403
- });
404
-
405
- test("pretty-prints with 2-space indentation", () => {
406
- const events = [fixtureCreated];
407
- const json = exportToJSON(events);
408
-
409
- // Should have newlines (pretty-printed)
410
- expect(json).toContain("\n");
411
-
412
- // Should use 2-space indentation
413
- const lines = json.split("\n");
414
-
415
- // Find a nested field line (e.g., "type": "cell_created")
416
- const typeLine = lines.find((line) => line.includes('"type"'));
417
- expect(typeLine).toBeDefined();
418
-
419
- // Should start with 2 spaces (array item) + 2 spaces (object property) = 4 spaces
420
- expect(typeLine).toMatch(/^\s{4}"/);
421
- });
422
-
423
- test("handles empty events array", () => {
424
- const json = exportToJSON([]);
425
-
426
- // Should be empty array
427
- const parsed = JSON.parse(json);
428
- expect(Array.isArray(parsed)).toBe(true);
429
- expect(parsed.length).toBe(0);
430
-
431
- // Pretty-printed empty array
432
- expect(json).toBe("[]");
433
- });
434
-
435
- test("maintains event ordering", () => {
436
- const events = [fixtureCreated, fixtureStatusChanged, fixtureClosedWithSpecialChars];
437
- const json = exportToJSON(events);
438
- const parsed = JSON.parse(json);
439
-
440
- // Order should match input
441
- expect(parsed[0].type).toBe("cell_created");
442
- expect(parsed[1].type).toBe("cell_status_changed");
443
- expect(parsed[2].type).toBe("cell_closed");
444
-
445
- // Timestamps should be in order
446
- expect(parsed[0].timestamp).toBe(1735142400000);
447
- expect(parsed[1].timestamp).toBe(1735142460000);
448
- expect(parsed[2].timestamp).toBe(1735146000000);
449
- });
450
-
451
- test("handles special characters in strings", () => {
452
- const events = [fixtureCsvEdgeCase];
453
- const json = exportToJSON(events);
454
- const parsed = JSON.parse(json);
455
-
456
- // Special chars should be preserved via JSON escaping
457
- const title = parsed[0].title;
458
- expect(title).toBe('Fix bug in parser: handle "quoted strings", commas, and newlines');
459
-
460
- // JSON should use \" for quotes
461
- expect(json).toContain('\\"quoted strings\\"');
462
- });
463
-
464
- test("serializes metadata objects correctly", () => {
465
- const events = [fixtureCreated];
466
- const json = exportToJSON(events);
467
- const parsed = JSON.parse(json);
468
-
469
- const metadata = parsed[0].metadata;
470
-
471
- // Should be an object, not a string
472
- expect(typeof metadata).toBe("object");
473
- expect(metadata.epic_id).toBe("test-epic-parent");
474
- expect(metadata.strategy).toBe("feature-based");
475
- });
476
- });