opencode-swarm-plugin 0.44.0 → 0.44.1
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.
- package/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.ts +16 -10
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.js +7644 -62599
- package/dist/plugin.js +23766 -78721
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-review.d.ts.map +1 -1
- package/package.json +17 -5
- package/.changeset/swarm-insights-data-layer.md +0 -63
- package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
- package/.hive/analysis/session-data-quality-audit.md +0 -320
- package/.hive/eval-results.json +0 -483
- package/.hive/issues.jsonl +0 -138
- package/.hive/memories.jsonl +0 -729
- package/.opencode/eval-history.jsonl +0 -327
- package/.turbo/turbo-build.log +0 -9
- package/CHANGELOG.md +0 -2286
- package/SCORER-ANALYSIS.md +0 -598
- package/docs/analysis/subagent-coordination-patterns.md +0 -902
- package/docs/analysis-socratic-planner-pattern.md +0 -504
- package/docs/planning/ADR-001-monorepo-structure.md +0 -171
- package/docs/planning/ADR-002-package-extraction.md +0 -393
- package/docs/planning/ADR-003-performance-improvements.md +0 -451
- package/docs/planning/ADR-004-message-queue-features.md +0 -187
- package/docs/planning/ADR-005-devtools-observability.md +0 -202
- package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
- package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
- package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
- package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
- package/docs/planning/ROADMAP.md +0 -368
- package/docs/semantic-memory-cli-syntax.md +0 -123
- package/docs/swarm-mail-architecture.md +0 -1147
- package/docs/testing/context-recovery-test.md +0 -470
- package/evals/ARCHITECTURE.md +0 -1189
- package/evals/README.md +0 -768
- package/evals/compaction-prompt.eval.ts +0 -149
- package/evals/compaction-resumption.eval.ts +0 -289
- package/evals/coordinator-behavior.eval.ts +0 -307
- package/evals/coordinator-session.eval.ts +0 -154
- package/evals/evalite.config.ts.bak +0 -15
- package/evals/example.eval.ts +0 -31
- package/evals/fixtures/cass-baseline.ts +0 -217
- package/evals/fixtures/compaction-cases.ts +0 -350
- package/evals/fixtures/compaction-prompt-cases.ts +0 -311
- package/evals/fixtures/coordinator-sessions.ts +0 -328
- package/evals/fixtures/decomposition-cases.ts +0 -105
- package/evals/lib/compaction-loader.test.ts +0 -248
- package/evals/lib/compaction-loader.ts +0 -320
- package/evals/lib/data-loader.evalite-test.ts +0 -289
- package/evals/lib/data-loader.test.ts +0 -345
- package/evals/lib/data-loader.ts +0 -281
- package/evals/lib/llm.ts +0 -115
- package/evals/scorers/compaction-prompt-scorers.ts +0 -145
- package/evals/scorers/compaction-scorers.ts +0 -305
- package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
- package/evals/scorers/coordinator-discipline.ts +0 -325
- package/evals/scorers/index.test.ts +0 -146
- package/evals/scorers/index.ts +0 -328
- package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
- package/evals/scorers/outcome-scorers.ts +0 -349
- package/evals/swarm-decomposition.eval.ts +0 -121
- package/examples/commands/swarm.md +0 -745
- package/examples/plugin-wrapper-template.ts +0 -2515
- package/examples/skills/hive-workflow/SKILL.md +0 -212
- package/examples/skills/skill-creator/SKILL.md +0 -223
- package/examples/skills/swarm-coordination/SKILL.md +0 -292
- package/global-skills/cli-builder/SKILL.md +0 -344
- package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
- package/global-skills/learning-systems/SKILL.md +0 -644
- package/global-skills/skill-creator/LICENSE.txt +0 -202
- package/global-skills/skill-creator/SKILL.md +0 -352
- package/global-skills/skill-creator/references/output-patterns.md +0 -82
- package/global-skills/skill-creator/references/workflows.md +0 -28
- package/global-skills/swarm-coordination/SKILL.md +0 -995
- package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
- package/global-skills/swarm-coordination/references/strategies.md +0 -138
- package/global-skills/system-design/SKILL.md +0 -213
- package/global-skills/testing-patterns/SKILL.md +0 -430
- package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
- package/opencode-swarm-plugin-0.30.7.tgz +0 -0
- package/opencode-swarm-plugin-0.31.0.tgz +0 -0
- package/scripts/cleanup-test-memories.ts +0 -346
- package/scripts/init-skill.ts +0 -222
- package/scripts/migrate-unknown-sessions.ts +0 -349
- package/scripts/validate-skill.ts +0 -204
- package/src/agent-mail.ts +0 -1724
- package/src/anti-patterns.test.ts +0 -1167
- package/src/anti-patterns.ts +0 -448
- package/src/compaction-capture.integration.test.ts +0 -257
- package/src/compaction-hook.test.ts +0 -838
- package/src/compaction-hook.ts +0 -1204
- package/src/compaction-observability.integration.test.ts +0 -139
- package/src/compaction-observability.test.ts +0 -187
- package/src/compaction-observability.ts +0 -324
- package/src/compaction-prompt-scorers.test.ts +0 -475
- package/src/compaction-prompt-scoring.ts +0 -300
- package/src/contributor-tools.test.ts +0 -133
- package/src/contributor-tools.ts +0 -201
- package/src/dashboard.test.ts +0 -611
- package/src/dashboard.ts +0 -462
- package/src/error-enrichment.test.ts +0 -403
- package/src/error-enrichment.ts +0 -219
- package/src/eval-capture.test.ts +0 -1015
- package/src/eval-capture.ts +0 -929
- package/src/eval-gates.test.ts +0 -306
- package/src/eval-gates.ts +0 -218
- package/src/eval-history.test.ts +0 -508
- package/src/eval-history.ts +0 -214
- package/src/eval-learning.test.ts +0 -378
- package/src/eval-learning.ts +0 -360
- package/src/eval-runner.test.ts +0 -223
- package/src/eval-runner.ts +0 -402
- package/src/export-tools.test.ts +0 -476
- package/src/export-tools.ts +0 -257
- package/src/hive.integration.test.ts +0 -2241
- package/src/hive.ts +0 -1628
- package/src/index.ts +0 -940
- package/src/learning.integration.test.ts +0 -1815
- package/src/learning.ts +0 -1079
- package/src/logger.test.ts +0 -189
- package/src/logger.ts +0 -135
- package/src/mandate-promotion.test.ts +0 -473
- package/src/mandate-promotion.ts +0 -239
- package/src/mandate-storage.integration.test.ts +0 -601
- package/src/mandate-storage.test.ts +0 -578
- package/src/mandate-storage.ts +0 -794
- package/src/mandates.ts +0 -540
- package/src/memory-tools.test.ts +0 -195
- package/src/memory-tools.ts +0 -344
- package/src/memory.integration.test.ts +0 -334
- package/src/memory.test.ts +0 -158
- package/src/memory.ts +0 -527
- package/src/model-selection.test.ts +0 -188
- package/src/model-selection.ts +0 -68
- package/src/observability-tools.test.ts +0 -359
- package/src/observability-tools.ts +0 -871
- package/src/output-guardrails.test.ts +0 -438
- package/src/output-guardrails.ts +0 -381
- package/src/pattern-maturity.test.ts +0 -1160
- package/src/pattern-maturity.ts +0 -525
- package/src/planning-guardrails.test.ts +0 -491
- package/src/planning-guardrails.ts +0 -438
- package/src/plugin.ts +0 -23
- package/src/post-compaction-tracker.test.ts +0 -251
- package/src/post-compaction-tracker.ts +0 -237
- package/src/query-tools.test.ts +0 -636
- package/src/query-tools.ts +0 -324
- package/src/rate-limiter.integration.test.ts +0 -466
- package/src/rate-limiter.ts +0 -774
- package/src/replay-tools.test.ts +0 -496
- package/src/replay-tools.ts +0 -240
- package/src/repo-crawl.integration.test.ts +0 -441
- package/src/repo-crawl.ts +0 -610
- package/src/schemas/cell-events.test.ts +0 -347
- package/src/schemas/cell-events.ts +0 -807
- package/src/schemas/cell.ts +0 -257
- package/src/schemas/evaluation.ts +0 -166
- package/src/schemas/index.test.ts +0 -199
- package/src/schemas/index.ts +0 -286
- package/src/schemas/mandate.ts +0 -232
- package/src/schemas/swarm-context.ts +0 -115
- package/src/schemas/task.ts +0 -161
- package/src/schemas/worker-handoff.test.ts +0 -302
- package/src/schemas/worker-handoff.ts +0 -131
- package/src/sessions/agent-discovery.test.ts +0 -137
- package/src/sessions/agent-discovery.ts +0 -112
- package/src/sessions/index.ts +0 -15
- package/src/skills.integration.test.ts +0 -1192
- package/src/skills.test.ts +0 -643
- package/src/skills.ts +0 -1549
- package/src/storage.integration.test.ts +0 -341
- package/src/storage.ts +0 -884
- package/src/structured.integration.test.ts +0 -817
- package/src/structured.test.ts +0 -1046
- package/src/structured.ts +0 -762
- package/src/swarm-decompose.test.ts +0 -188
- package/src/swarm-decompose.ts +0 -1302
- package/src/swarm-deferred.integration.test.ts +0 -157
- package/src/swarm-deferred.test.ts +0 -38
- package/src/swarm-insights.test.ts +0 -214
- package/src/swarm-insights.ts +0 -459
- package/src/swarm-mail.integration.test.ts +0 -970
- package/src/swarm-mail.ts +0 -739
- package/src/swarm-orchestrate.integration.test.ts +0 -282
- package/src/swarm-orchestrate.test.ts +0 -548
- package/src/swarm-orchestrate.ts +0 -3084
- package/src/swarm-prompts.test.ts +0 -1270
- package/src/swarm-prompts.ts +0 -2077
- package/src/swarm-research.integration.test.ts +0 -701
- package/src/swarm-research.test.ts +0 -698
- package/src/swarm-research.ts +0 -472
- package/src/swarm-review.integration.test.ts +0 -285
- package/src/swarm-review.test.ts +0 -879
- package/src/swarm-review.ts +0 -709
- package/src/swarm-strategies.ts +0 -407
- package/src/swarm-worktree.test.ts +0 -501
- package/src/swarm-worktree.ts +0 -575
- package/src/swarm.integration.test.ts +0 -2377
- package/src/swarm.ts +0 -38
- package/src/tool-adapter.integration.test.ts +0 -1221
- package/src/tool-availability.ts +0 -461
- package/tsconfig.json +0 -28
|
@@ -1,970 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for swarm-mail.ts (embedded implementation)
|
|
3
|
-
*
|
|
4
|
-
* These tests run against the embedded PGLite database.
|
|
5
|
-
* No external server required - everything runs in-process.
|
|
6
|
-
*
|
|
7
|
-
* Run with: pnpm test:integration
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { randomUUID } from "node:crypto";
|
|
11
|
-
import { mkdir, rm } from "node:fs/promises";
|
|
12
|
-
import { join } from "node:path";
|
|
13
|
-
import { tmpdir } from "node:os";
|
|
14
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
15
|
-
import {
|
|
16
|
-
getSwarmMailLibSQL,
|
|
17
|
-
clearAdapterCache,
|
|
18
|
-
} from "swarm-mail";
|
|
19
|
-
import {
|
|
20
|
-
swarmmail_init,
|
|
21
|
-
swarmmail_send,
|
|
22
|
-
swarmmail_inbox,
|
|
23
|
-
swarmmail_read_message,
|
|
24
|
-
swarmmail_reserve,
|
|
25
|
-
swarmmail_release,
|
|
26
|
-
swarmmail_ack,
|
|
27
|
-
swarmmail_health,
|
|
28
|
-
clearSessionState,
|
|
29
|
-
} from "./swarm-mail";
|
|
30
|
-
|
|
31
|
-
// ============================================================================
|
|
32
|
-
// Test Configuration
|
|
33
|
-
// ============================================================================
|
|
34
|
-
|
|
35
|
-
/** Generate unique test database path per test run */
|
|
36
|
-
function testDbPath(prefix = "swarm-mail"): string {
|
|
37
|
-
return join(tmpdir(), `${prefix}-${randomUUID()}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Track paths created during test for cleanup */
|
|
41
|
-
let testPaths: string[] = [];
|
|
42
|
-
|
|
43
|
-
function trackPath(path: string): string {
|
|
44
|
-
testPaths.push(path);
|
|
45
|
-
return path;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let TEST_DB_PATH: string;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Generate a unique test context to avoid state collisions between tests
|
|
52
|
-
*/
|
|
53
|
-
function createTestContext() {
|
|
54
|
-
const id = `test-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
55
|
-
return {
|
|
56
|
-
sessionID: id,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Mock tool context
|
|
62
|
-
*/
|
|
63
|
-
interface MockToolContext {
|
|
64
|
-
sessionID: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Helper to execute tool and parse JSON response
|
|
69
|
-
*/
|
|
70
|
-
async function executeTool<T>(
|
|
71
|
-
tool: { execute: (args: unknown, ctx: unknown) => Promise<string> },
|
|
72
|
-
args: unknown,
|
|
73
|
-
ctx: MockToolContext,
|
|
74
|
-
): Promise<T> {
|
|
75
|
-
const result = await tool.execute(args, ctx);
|
|
76
|
-
return JSON.parse(result) as T;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ============================================================================
|
|
80
|
-
// Test Lifecycle Hooks
|
|
81
|
-
// ============================================================================
|
|
82
|
-
|
|
83
|
-
beforeEach(async () => {
|
|
84
|
-
testPaths = [];
|
|
85
|
-
TEST_DB_PATH = trackPath(testDbPath());
|
|
86
|
-
// Create directory for test database
|
|
87
|
-
await mkdir(TEST_DB_PATH, { recursive: true });
|
|
88
|
-
// Clear adapter cache to ensure clean state
|
|
89
|
-
clearAdapterCache();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
afterEach(async () => {
|
|
93
|
-
// Clear all cached adapters
|
|
94
|
-
clearAdapterCache();
|
|
95
|
-
|
|
96
|
-
// Clean up all test database directories
|
|
97
|
-
for (const path of testPaths) {
|
|
98
|
-
try {
|
|
99
|
-
await rm(path, { recursive: true, force: true });
|
|
100
|
-
} catch {
|
|
101
|
-
// Ignore errors during cleanup
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
testPaths = [];
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// ============================================================================
|
|
108
|
-
// Health Check Tests
|
|
109
|
-
// ============================================================================
|
|
110
|
-
|
|
111
|
-
describe("swarm-mail integration (embedded)", () => {
|
|
112
|
-
describe("swarmmail_health", () => {
|
|
113
|
-
it("returns healthy when database is initialized", async () => {
|
|
114
|
-
const ctx = createTestContext();
|
|
115
|
-
|
|
116
|
-
const result = await executeTool<{
|
|
117
|
-
healthy: boolean;
|
|
118
|
-
database: string;
|
|
119
|
-
stats: { events: number; agents: number; messages: number };
|
|
120
|
-
}>(swarmmail_health, {}, ctx);
|
|
121
|
-
|
|
122
|
-
expect(result.healthy).toBe(true);
|
|
123
|
-
expect(result.database).toBeTruthy();
|
|
124
|
-
expect(result.stats).toBeDefined();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("includes session info when initialized", async () => {
|
|
128
|
-
const ctx = createTestContext();
|
|
129
|
-
|
|
130
|
-
// Initialize session
|
|
131
|
-
await executeTool(
|
|
132
|
-
swarmmail_init,
|
|
133
|
-
{ project_path: TEST_DB_PATH, agent_name: "HealthAgent" },
|
|
134
|
-
ctx,
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const result = await executeTool<{
|
|
138
|
-
healthy: boolean;
|
|
139
|
-
session: {
|
|
140
|
-
agent_name: string;
|
|
141
|
-
project_key: string;
|
|
142
|
-
reservations: number;
|
|
143
|
-
};
|
|
144
|
-
}>(swarmmail_health, {}, ctx);
|
|
145
|
-
|
|
146
|
-
expect(result.healthy).toBe(true);
|
|
147
|
-
expect(result.session).toBeDefined();
|
|
148
|
-
expect(result.session.agent_name).toBe("HealthAgent");
|
|
149
|
-
expect(result.session.reservations).toBe(0);
|
|
150
|
-
|
|
151
|
-
clearSessionState(ctx.sessionID);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// ============================================================================
|
|
156
|
-
// Initialization Tests
|
|
157
|
-
// ============================================================================
|
|
158
|
-
|
|
159
|
-
describe("swarmmail_init", () => {
|
|
160
|
-
it("creates agent and returns name and project_key", async () => {
|
|
161
|
-
const ctx = createTestContext();
|
|
162
|
-
|
|
163
|
-
const result = await executeTool<{
|
|
164
|
-
agent_name: string;
|
|
165
|
-
project_key: string;
|
|
166
|
-
message: string;
|
|
167
|
-
}>(swarmmail_init, { project_path: TEST_DB_PATH }, ctx);
|
|
168
|
-
|
|
169
|
-
expect(result.agent_name).toBeTruthy();
|
|
170
|
-
expect(result.project_key).toBe(TEST_DB_PATH);
|
|
171
|
-
expect(result.message).toContain(result.agent_name);
|
|
172
|
-
|
|
173
|
-
clearSessionState(ctx.sessionID);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("generates unique agent name when not provided", async () => {
|
|
177
|
-
const ctx1 = createTestContext();
|
|
178
|
-
const ctx2 = createTestContext();
|
|
179
|
-
|
|
180
|
-
const result1 = await executeTool<{ agent_name: string }>(
|
|
181
|
-
swarmmail_init,
|
|
182
|
-
{ project_path: TEST_DB_PATH },
|
|
183
|
-
ctx1,
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
const result2 = await executeTool<{ agent_name: string }>(
|
|
187
|
-
swarmmail_init,
|
|
188
|
-
{ project_path: TEST_DB_PATH },
|
|
189
|
-
ctx2,
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
// Both should have adjective+noun style names
|
|
193
|
-
expect(result1.agent_name).toMatch(/^[A-Z][a-z]+[A-Z][a-z]+$/);
|
|
194
|
-
expect(result2.agent_name).toMatch(/^[A-Z][a-z]+[A-Z][a-z]+$/);
|
|
195
|
-
expect(result1.agent_name).not.toBe(result2.agent_name);
|
|
196
|
-
|
|
197
|
-
clearSessionState(ctx1.sessionID);
|
|
198
|
-
clearSessionState(ctx2.sessionID);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("uses provided agent name when specified", async () => {
|
|
202
|
-
const ctx = createTestContext();
|
|
203
|
-
const customName = "BlueLake";
|
|
204
|
-
|
|
205
|
-
const result = await executeTool<{ agent_name: string }>(
|
|
206
|
-
swarmmail_init,
|
|
207
|
-
{ project_path: TEST_DB_PATH, agent_name: customName },
|
|
208
|
-
ctx,
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
expect(result.agent_name).toBe(customName);
|
|
212
|
-
|
|
213
|
-
clearSessionState(ctx.sessionID);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("returns existing session if already initialized", async () => {
|
|
217
|
-
const ctx = createTestContext();
|
|
218
|
-
|
|
219
|
-
const result1 = await executeTool<{
|
|
220
|
-
agent_name: string;
|
|
221
|
-
already_initialized?: boolean;
|
|
222
|
-
}>(swarmmail_init, { project_path: TEST_DB_PATH }, ctx);
|
|
223
|
-
|
|
224
|
-
const result2 = await executeTool<{
|
|
225
|
-
agent_name: string;
|
|
226
|
-
already_initialized?: boolean;
|
|
227
|
-
}>(swarmmail_init, { project_path: TEST_DB_PATH }, ctx);
|
|
228
|
-
|
|
229
|
-
expect(result1.agent_name).toBe(result2.agent_name);
|
|
230
|
-
expect(result2.already_initialized).toBe(true);
|
|
231
|
-
|
|
232
|
-
clearSessionState(ctx.sessionID);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// ============================================================================
|
|
237
|
-
// Messaging Tests
|
|
238
|
-
// ============================================================================
|
|
239
|
-
|
|
240
|
-
describe("swarmmail_send", () => {
|
|
241
|
-
it("sends message to another agent", async () => {
|
|
242
|
-
const senderCtx = createTestContext();
|
|
243
|
-
const recipientCtx = createTestContext();
|
|
244
|
-
|
|
245
|
-
// Initialize both agents
|
|
246
|
-
await executeTool<{ agent_name: string }>(
|
|
247
|
-
swarmmail_init,
|
|
248
|
-
{ project_path: TEST_DB_PATH, agent_name: "Sender" },
|
|
249
|
-
senderCtx,
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
const recipient = await executeTool<{ agent_name: string }>(
|
|
253
|
-
swarmmail_init,
|
|
254
|
-
{ project_path: TEST_DB_PATH, agent_name: "Recipient" },
|
|
255
|
-
recipientCtx,
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
// Send message
|
|
259
|
-
const result = await executeTool<{
|
|
260
|
-
success: boolean;
|
|
261
|
-
message_id: number;
|
|
262
|
-
thread_id?: string;
|
|
263
|
-
recipient_count: number;
|
|
264
|
-
}>(
|
|
265
|
-
swarmmail_send,
|
|
266
|
-
{
|
|
267
|
-
to: [recipient.agent_name],
|
|
268
|
-
subject: "Test message",
|
|
269
|
-
body: "This is a test message body",
|
|
270
|
-
thread_id: "bd-test-123",
|
|
271
|
-
importance: "normal",
|
|
272
|
-
},
|
|
273
|
-
senderCtx,
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
expect(result.success).toBe(true);
|
|
277
|
-
expect(result.message_id).toBeGreaterThan(0);
|
|
278
|
-
expect(result.thread_id).toBe("bd-test-123");
|
|
279
|
-
expect(result.recipient_count).toBe(1);
|
|
280
|
-
|
|
281
|
-
clearSessionState(senderCtx.sessionID);
|
|
282
|
-
clearSessionState(recipientCtx.sessionID);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it("sends urgent message with ack_required", async () => {
|
|
286
|
-
const senderCtx = createTestContext();
|
|
287
|
-
const recipientCtx = createTestContext();
|
|
288
|
-
|
|
289
|
-
await executeTool(
|
|
290
|
-
swarmmail_init,
|
|
291
|
-
{ project_path: TEST_DB_PATH, agent_name: "UrgentSender" },
|
|
292
|
-
senderCtx,
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
const recipient = await executeTool<{ agent_name: string }>(
|
|
296
|
-
swarmmail_init,
|
|
297
|
-
{ project_path: TEST_DB_PATH, agent_name: "UrgentRecipient" },
|
|
298
|
-
recipientCtx,
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
const result = await executeTool<{
|
|
302
|
-
success: boolean;
|
|
303
|
-
message_id: number;
|
|
304
|
-
}>(
|
|
305
|
-
swarmmail_send,
|
|
306
|
-
{
|
|
307
|
-
to: [recipient.agent_name],
|
|
308
|
-
subject: "Urgent: Action required",
|
|
309
|
-
body: "Please acknowledge this message",
|
|
310
|
-
importance: "urgent",
|
|
311
|
-
ack_required: true,
|
|
312
|
-
},
|
|
313
|
-
senderCtx,
|
|
314
|
-
);
|
|
315
|
-
|
|
316
|
-
expect(result.success).toBe(true);
|
|
317
|
-
expect(result.message_id).toBeGreaterThan(0);
|
|
318
|
-
|
|
319
|
-
clearSessionState(senderCtx.sessionID);
|
|
320
|
-
clearSessionState(recipientCtx.sessionID);
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it("returns error when not initialized", async () => {
|
|
324
|
-
const ctx = createTestContext();
|
|
325
|
-
|
|
326
|
-
const result = await executeTool<{ error?: string }>(
|
|
327
|
-
swarmmail_send,
|
|
328
|
-
{
|
|
329
|
-
to: ["SomeAgent"],
|
|
330
|
-
subject: "Test",
|
|
331
|
-
body: "Body",
|
|
332
|
-
},
|
|
333
|
-
ctx,
|
|
334
|
-
);
|
|
335
|
-
|
|
336
|
-
expect(result.error).toContain("not initialized");
|
|
337
|
-
|
|
338
|
-
clearSessionState(ctx.sessionID);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
// ============================================================================
|
|
343
|
-
// Inbox Tests
|
|
344
|
-
// ============================================================================
|
|
345
|
-
|
|
346
|
-
describe("swarmmail_inbox", () => {
|
|
347
|
-
it("fetches messages without bodies by default (context-safe)", async () => {
|
|
348
|
-
const senderCtx = createTestContext();
|
|
349
|
-
const recipientCtx = createTestContext();
|
|
350
|
-
|
|
351
|
-
await executeTool<{ agent_name: string }>(
|
|
352
|
-
swarmmail_init,
|
|
353
|
-
{ project_path: TEST_DB_PATH, agent_name: "InboxSender" },
|
|
354
|
-
senderCtx,
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
const recipient = await executeTool<{ agent_name: string }>(
|
|
358
|
-
swarmmail_init,
|
|
359
|
-
{ project_path: TEST_DB_PATH, agent_name: "InboxRecipient" },
|
|
360
|
-
recipientCtx,
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
// Send a message
|
|
364
|
-
await executeTool(
|
|
365
|
-
swarmmail_send,
|
|
366
|
-
{
|
|
367
|
-
to: [recipient.agent_name],
|
|
368
|
-
subject: "Inbox test message",
|
|
369
|
-
body: "This body should NOT be included by default",
|
|
370
|
-
},
|
|
371
|
-
senderCtx,
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
// Fetch inbox
|
|
375
|
-
const result = await executeTool<{
|
|
376
|
-
messages: Array<{
|
|
377
|
-
id: number;
|
|
378
|
-
from: string;
|
|
379
|
-
subject: string;
|
|
380
|
-
body?: string;
|
|
381
|
-
}>;
|
|
382
|
-
total: number;
|
|
383
|
-
note: string;
|
|
384
|
-
}>(swarmmail_inbox, {}, recipientCtx);
|
|
385
|
-
|
|
386
|
-
expect(result.messages.length).toBeGreaterThan(0);
|
|
387
|
-
const testMsg = result.messages.find(
|
|
388
|
-
(m) => m.subject === "Inbox test message",
|
|
389
|
-
);
|
|
390
|
-
expect(testMsg).toBeDefined();
|
|
391
|
-
expect(testMsg?.from).toBe("InboxSender");
|
|
392
|
-
// Body should NOT be included
|
|
393
|
-
expect(testMsg?.body).toBeUndefined();
|
|
394
|
-
expect(result.note).toContain("swarmmail_read_message");
|
|
395
|
-
|
|
396
|
-
clearSessionState(senderCtx.sessionID);
|
|
397
|
-
clearSessionState(recipientCtx.sessionID);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it("enforces MAX_INBOX_LIMIT (5) constraint", async () => {
|
|
401
|
-
const senderCtx = createTestContext();
|
|
402
|
-
const recipientCtx = createTestContext();
|
|
403
|
-
|
|
404
|
-
await executeTool<{ agent_name: string }>(
|
|
405
|
-
swarmmail_init,
|
|
406
|
-
{ project_path: TEST_DB_PATH, agent_name: "LimitSender" },
|
|
407
|
-
senderCtx,
|
|
408
|
-
);
|
|
409
|
-
|
|
410
|
-
const recipient = await executeTool<{ agent_name: string }>(
|
|
411
|
-
swarmmail_init,
|
|
412
|
-
{ project_path: TEST_DB_PATH, agent_name: "LimitRecipient" },
|
|
413
|
-
recipientCtx,
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
// Send 8 messages (more than limit)
|
|
417
|
-
for (let i = 0; i < 8; i++) {
|
|
418
|
-
await executeTool(
|
|
419
|
-
swarmmail_send,
|
|
420
|
-
{
|
|
421
|
-
to: [recipient.agent_name],
|
|
422
|
-
subject: `Limit test message ${i}`,
|
|
423
|
-
body: `Message body ${i}`,
|
|
424
|
-
},
|
|
425
|
-
senderCtx,
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// Request 10 messages (should be capped at 5)
|
|
430
|
-
const result = await executeTool<{
|
|
431
|
-
messages: Array<{ id: number }>;
|
|
432
|
-
}>(swarmmail_inbox, { limit: 10 }, recipientCtx);
|
|
433
|
-
|
|
434
|
-
// Should be capped at 5
|
|
435
|
-
expect(result.messages.length).toBeLessThanOrEqual(5);
|
|
436
|
-
|
|
437
|
-
clearSessionState(senderCtx.sessionID);
|
|
438
|
-
clearSessionState(recipientCtx.sessionID);
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it("filters urgent messages when urgent_only is true", async () => {
|
|
442
|
-
const senderCtx = createTestContext();
|
|
443
|
-
const recipientCtx = createTestContext();
|
|
444
|
-
|
|
445
|
-
await executeTool<{ agent_name: string }>(
|
|
446
|
-
swarmmail_init,
|
|
447
|
-
{ project_path: TEST_DB_PATH, agent_name: "UrgentFilterSender" },
|
|
448
|
-
senderCtx,
|
|
449
|
-
);
|
|
450
|
-
|
|
451
|
-
const recipient = await executeTool<{ agent_name: string }>(
|
|
452
|
-
swarmmail_init,
|
|
453
|
-
{ project_path: TEST_DB_PATH, agent_name: "UrgentFilterRecipient" },
|
|
454
|
-
recipientCtx,
|
|
455
|
-
);
|
|
456
|
-
|
|
457
|
-
// Send normal and urgent messages
|
|
458
|
-
await executeTool(
|
|
459
|
-
swarmmail_send,
|
|
460
|
-
{
|
|
461
|
-
to: [recipient.agent_name],
|
|
462
|
-
subject: "Normal message",
|
|
463
|
-
body: "Not urgent",
|
|
464
|
-
importance: "normal",
|
|
465
|
-
},
|
|
466
|
-
senderCtx,
|
|
467
|
-
);
|
|
468
|
-
|
|
469
|
-
await executeTool(
|
|
470
|
-
swarmmail_send,
|
|
471
|
-
{
|
|
472
|
-
to: [recipient.agent_name],
|
|
473
|
-
subject: "Urgent message",
|
|
474
|
-
body: "Very urgent!",
|
|
475
|
-
importance: "urgent",
|
|
476
|
-
},
|
|
477
|
-
senderCtx,
|
|
478
|
-
);
|
|
479
|
-
|
|
480
|
-
// Fetch only urgent messages
|
|
481
|
-
const result = await executeTool<{
|
|
482
|
-
messages: Array<{ subject: string; importance: string }>;
|
|
483
|
-
}>(swarmmail_inbox, { urgent_only: true }, recipientCtx);
|
|
484
|
-
|
|
485
|
-
// All returned messages should be urgent
|
|
486
|
-
for (const msg of result.messages) {
|
|
487
|
-
expect(msg.importance).toBe("urgent");
|
|
488
|
-
}
|
|
489
|
-
expect(result.messages.some((m) => m.subject === "Urgent message")).toBe(
|
|
490
|
-
true,
|
|
491
|
-
);
|
|
492
|
-
|
|
493
|
-
clearSessionState(senderCtx.sessionID);
|
|
494
|
-
clearSessionState(recipientCtx.sessionID);
|
|
495
|
-
});
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
// ============================================================================
|
|
499
|
-
// Read Message Tests
|
|
500
|
-
// ============================================================================
|
|
501
|
-
|
|
502
|
-
describe("swarmmail_read_message", () => {
|
|
503
|
-
it("returns full message body when reading by ID", async () => {
|
|
504
|
-
const senderCtx = createTestContext();
|
|
505
|
-
const recipientCtx = createTestContext();
|
|
506
|
-
|
|
507
|
-
await executeTool<{ agent_name: string }>(
|
|
508
|
-
swarmmail_init,
|
|
509
|
-
{ project_path: TEST_DB_PATH, agent_name: "ReadSender" },
|
|
510
|
-
senderCtx,
|
|
511
|
-
);
|
|
512
|
-
|
|
513
|
-
const recipient = await executeTool<{ agent_name: string }>(
|
|
514
|
-
swarmmail_init,
|
|
515
|
-
{ project_path: TEST_DB_PATH, agent_name: "ReadRecipient" },
|
|
516
|
-
recipientCtx,
|
|
517
|
-
);
|
|
518
|
-
|
|
519
|
-
// Send a message
|
|
520
|
-
const sent = await executeTool<{ message_id: number }>(
|
|
521
|
-
swarmmail_send,
|
|
522
|
-
{
|
|
523
|
-
to: [recipient.agent_name],
|
|
524
|
-
subject: "Read test message",
|
|
525
|
-
body: "This message body should be returned",
|
|
526
|
-
},
|
|
527
|
-
senderCtx,
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
// Read the message
|
|
531
|
-
const result = await executeTool<{
|
|
532
|
-
id: number;
|
|
533
|
-
from: string;
|
|
534
|
-
subject: string;
|
|
535
|
-
body: string;
|
|
536
|
-
}>(swarmmail_read_message, { message_id: sent.message_id }, recipientCtx);
|
|
537
|
-
|
|
538
|
-
expect(result.id).toBe(sent.message_id);
|
|
539
|
-
expect(result.from).toBe("ReadSender");
|
|
540
|
-
expect(result.subject).toBe("Read test message");
|
|
541
|
-
expect(result.body).toBe("This message body should be returned");
|
|
542
|
-
|
|
543
|
-
clearSessionState(senderCtx.sessionID);
|
|
544
|
-
clearSessionState(recipientCtx.sessionID);
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
it("returns error when message not found", async () => {
|
|
548
|
-
const ctx = createTestContext();
|
|
549
|
-
|
|
550
|
-
await executeTool(
|
|
551
|
-
swarmmail_init,
|
|
552
|
-
{ project_path: TEST_DB_PATH, agent_name: "NotFoundAgent" },
|
|
553
|
-
ctx,
|
|
554
|
-
);
|
|
555
|
-
|
|
556
|
-
const result = await executeTool<{ error?: string }>(
|
|
557
|
-
swarmmail_read_message,
|
|
558
|
-
{ message_id: 99999 },
|
|
559
|
-
ctx,
|
|
560
|
-
);
|
|
561
|
-
|
|
562
|
-
expect(result.error).toContain("not found");
|
|
563
|
-
|
|
564
|
-
clearSessionState(ctx.sessionID);
|
|
565
|
-
});
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
// ============================================================================
|
|
569
|
-
// File Reservation Tests
|
|
570
|
-
// ============================================================================
|
|
571
|
-
|
|
572
|
-
describe("swarmmail_reserve", () => {
|
|
573
|
-
it("grants file reservations", async () => {
|
|
574
|
-
const ctx = createTestContext();
|
|
575
|
-
|
|
576
|
-
await executeTool(
|
|
577
|
-
swarmmail_init,
|
|
578
|
-
{ project_path: TEST_DB_PATH, agent_name: "ReserveAgent" },
|
|
579
|
-
ctx,
|
|
580
|
-
);
|
|
581
|
-
|
|
582
|
-
const result = await executeTool<{
|
|
583
|
-
granted: Array<{
|
|
584
|
-
id: number;
|
|
585
|
-
path_pattern: string;
|
|
586
|
-
exclusive: boolean;
|
|
587
|
-
}>;
|
|
588
|
-
conflicts?: Array<{ path: string; holders: string[] }>;
|
|
589
|
-
}>(
|
|
590
|
-
swarmmail_reserve,
|
|
591
|
-
{
|
|
592
|
-
paths: ["src/auth/**", "src/config.ts"],
|
|
593
|
-
reason: "bd-test-123: Working on auth",
|
|
594
|
-
exclusive: true,
|
|
595
|
-
ttl_seconds: 3600,
|
|
596
|
-
},
|
|
597
|
-
ctx,
|
|
598
|
-
);
|
|
599
|
-
|
|
600
|
-
expect(result.granted.length).toBe(2);
|
|
601
|
-
expect(result.conflicts).toBeUndefined();
|
|
602
|
-
expect(result.granted[0].exclusive).toBe(true);
|
|
603
|
-
|
|
604
|
-
clearSessionState(ctx.sessionID);
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
it("detects conflicts with exclusive reservations", async () => {
|
|
608
|
-
const agent1Ctx = createTestContext();
|
|
609
|
-
const agent2Ctx = createTestContext();
|
|
610
|
-
|
|
611
|
-
await executeTool(
|
|
612
|
-
swarmmail_init,
|
|
613
|
-
{ project_path: TEST_DB_PATH, agent_name: "ConflictAgent1" },
|
|
614
|
-
agent1Ctx,
|
|
615
|
-
);
|
|
616
|
-
|
|
617
|
-
await executeTool(
|
|
618
|
-
swarmmail_init,
|
|
619
|
-
{ project_path: TEST_DB_PATH, agent_name: "ConflictAgent2" },
|
|
620
|
-
agent2Ctx,
|
|
621
|
-
);
|
|
622
|
-
|
|
623
|
-
const conflictPath = "src/conflict.ts";
|
|
624
|
-
|
|
625
|
-
// Agent 1 reserves the file
|
|
626
|
-
const result1 = await executeTool<{
|
|
627
|
-
granted: Array<{ id: number }>;
|
|
628
|
-
}>(
|
|
629
|
-
swarmmail_reserve,
|
|
630
|
-
{
|
|
631
|
-
paths: [conflictPath],
|
|
632
|
-
exclusive: true,
|
|
633
|
-
},
|
|
634
|
-
agent1Ctx,
|
|
635
|
-
);
|
|
636
|
-
|
|
637
|
-
expect(result1.granted.length).toBe(1);
|
|
638
|
-
|
|
639
|
-
// Agent 2 tries to reserve the same file
|
|
640
|
-
const result2 = await executeTool<{
|
|
641
|
-
granted: Array<{ id: number }>;
|
|
642
|
-
conflicts?: Array<{ path: string; holders: string[] }>;
|
|
643
|
-
warning?: string;
|
|
644
|
-
}>(
|
|
645
|
-
swarmmail_reserve,
|
|
646
|
-
{
|
|
647
|
-
paths: [conflictPath],
|
|
648
|
-
exclusive: true,
|
|
649
|
-
},
|
|
650
|
-
agent2Ctx,
|
|
651
|
-
);
|
|
652
|
-
|
|
653
|
-
// Should still grant but report conflicts
|
|
654
|
-
expect(result2.granted.length).toBeGreaterThan(0);
|
|
655
|
-
expect(result2.conflicts).toBeDefined();
|
|
656
|
-
expect(result2.conflicts?.length).toBeGreaterThan(0);
|
|
657
|
-
expect(result2.warning).toContain("already reserved");
|
|
658
|
-
|
|
659
|
-
clearSessionState(agent1Ctx.sessionID);
|
|
660
|
-
clearSessionState(agent2Ctx.sessionID);
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
it("returns error when not initialized", async () => {
|
|
664
|
-
const ctx = createTestContext();
|
|
665
|
-
|
|
666
|
-
const result = await executeTool<{ error?: string }>(
|
|
667
|
-
swarmmail_reserve,
|
|
668
|
-
{
|
|
669
|
-
paths: ["src/test.ts"],
|
|
670
|
-
},
|
|
671
|
-
ctx,
|
|
672
|
-
);
|
|
673
|
-
|
|
674
|
-
expect(result.error).toContain("not initialized");
|
|
675
|
-
|
|
676
|
-
clearSessionState(ctx.sessionID);
|
|
677
|
-
});
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
// ============================================================================
|
|
681
|
-
// Release Reservation Tests
|
|
682
|
-
// ============================================================================
|
|
683
|
-
|
|
684
|
-
describe("swarmmail_release", () => {
|
|
685
|
-
it("releases all reservations for an agent", async () => {
|
|
686
|
-
const ctx = createTestContext();
|
|
687
|
-
|
|
688
|
-
await executeTool(
|
|
689
|
-
swarmmail_init,
|
|
690
|
-
{ project_path: TEST_DB_PATH, agent_name: "ReleaseAgent" },
|
|
691
|
-
ctx,
|
|
692
|
-
);
|
|
693
|
-
|
|
694
|
-
// Create reservations
|
|
695
|
-
await executeTool(
|
|
696
|
-
swarmmail_reserve,
|
|
697
|
-
{
|
|
698
|
-
paths: ["src/release-test-1.ts", "src/release-test-2.ts"],
|
|
699
|
-
exclusive: true,
|
|
700
|
-
},
|
|
701
|
-
ctx,
|
|
702
|
-
);
|
|
703
|
-
|
|
704
|
-
// Release all
|
|
705
|
-
const result = await executeTool<{
|
|
706
|
-
released: number;
|
|
707
|
-
released_at: string;
|
|
708
|
-
}>(swarmmail_release, {}, ctx);
|
|
709
|
-
|
|
710
|
-
expect(result.released).toBe(2);
|
|
711
|
-
expect(result.released_at).toBeTruthy();
|
|
712
|
-
|
|
713
|
-
clearSessionState(ctx.sessionID);
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
it("releases specific paths only", async () => {
|
|
717
|
-
const ctx = createTestContext();
|
|
718
|
-
|
|
719
|
-
await executeTool(
|
|
720
|
-
swarmmail_init,
|
|
721
|
-
{ project_path: TEST_DB_PATH, agent_name: "SpecificReleaseAgent" },
|
|
722
|
-
ctx,
|
|
723
|
-
);
|
|
724
|
-
|
|
725
|
-
const path1 = "src/specific-release-1.ts";
|
|
726
|
-
const path2 = "src/specific-release-2.ts";
|
|
727
|
-
|
|
728
|
-
// Create reservations
|
|
729
|
-
await executeTool(
|
|
730
|
-
swarmmail_reserve,
|
|
731
|
-
{
|
|
732
|
-
paths: [path1, path2],
|
|
733
|
-
exclusive: true,
|
|
734
|
-
},
|
|
735
|
-
ctx,
|
|
736
|
-
);
|
|
737
|
-
|
|
738
|
-
// Release only one path
|
|
739
|
-
const result = await executeTool<{ released: number }>(
|
|
740
|
-
swarmmail_release,
|
|
741
|
-
{ paths: [path1] },
|
|
742
|
-
ctx,
|
|
743
|
-
);
|
|
744
|
-
|
|
745
|
-
expect(result.released).toBe(1);
|
|
746
|
-
|
|
747
|
-
clearSessionState(ctx.sessionID);
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
it("releases by reservation IDs", async () => {
|
|
751
|
-
const ctx = createTestContext();
|
|
752
|
-
|
|
753
|
-
await executeTool(
|
|
754
|
-
swarmmail_init,
|
|
755
|
-
{ project_path: TEST_DB_PATH, agent_name: "IdReleaseAgent" },
|
|
756
|
-
ctx,
|
|
757
|
-
);
|
|
758
|
-
|
|
759
|
-
// Create reservations
|
|
760
|
-
const reserve = await executeTool<{
|
|
761
|
-
granted: Array<{ id: number }>;
|
|
762
|
-
}>(
|
|
763
|
-
swarmmail_reserve,
|
|
764
|
-
{
|
|
765
|
-
paths: ["src/id-release-1.ts", "src/id-release-2.ts"],
|
|
766
|
-
exclusive: true,
|
|
767
|
-
},
|
|
768
|
-
ctx,
|
|
769
|
-
);
|
|
770
|
-
|
|
771
|
-
const firstId = reserve.granted[0].id;
|
|
772
|
-
|
|
773
|
-
// Release by ID
|
|
774
|
-
const result = await executeTool<{ released: number }>(
|
|
775
|
-
swarmmail_release,
|
|
776
|
-
{ reservation_ids: [firstId] },
|
|
777
|
-
ctx,
|
|
778
|
-
);
|
|
779
|
-
|
|
780
|
-
expect(result.released).toBe(1);
|
|
781
|
-
|
|
782
|
-
clearSessionState(ctx.sessionID);
|
|
783
|
-
});
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
// ============================================================================
|
|
787
|
-
// Acknowledge Message Tests
|
|
788
|
-
// ============================================================================
|
|
789
|
-
|
|
790
|
-
describe("swarmmail_ack", () => {
|
|
791
|
-
it("acknowledges a message requiring acknowledgement", async () => {
|
|
792
|
-
const senderCtx = createTestContext();
|
|
793
|
-
const recipientCtx = createTestContext();
|
|
794
|
-
|
|
795
|
-
const sender = await executeTool<{ agent_name: string }>(
|
|
796
|
-
swarmmail_init,
|
|
797
|
-
{ project_path: TEST_DB_PATH, agent_name: "AckSender" },
|
|
798
|
-
senderCtx,
|
|
799
|
-
);
|
|
800
|
-
|
|
801
|
-
const recipient = await executeTool<{ agent_name: string }>(
|
|
802
|
-
swarmmail_init,
|
|
803
|
-
{ project_path: TEST_DB_PATH, agent_name: "AckRecipient" },
|
|
804
|
-
recipientCtx,
|
|
805
|
-
);
|
|
806
|
-
|
|
807
|
-
// Send message requiring ack
|
|
808
|
-
const sent = await executeTool<{ message_id: number }>(
|
|
809
|
-
swarmmail_send,
|
|
810
|
-
{
|
|
811
|
-
to: [recipient.agent_name],
|
|
812
|
-
subject: "Please acknowledge",
|
|
813
|
-
body: "This requires acknowledgement",
|
|
814
|
-
ack_required: true,
|
|
815
|
-
},
|
|
816
|
-
senderCtx,
|
|
817
|
-
);
|
|
818
|
-
|
|
819
|
-
// Acknowledge
|
|
820
|
-
const result = await executeTool<{
|
|
821
|
-
acknowledged: boolean;
|
|
822
|
-
acknowledged_at: string;
|
|
823
|
-
}>(swarmmail_ack, { message_id: sent.message_id }, recipientCtx);
|
|
824
|
-
|
|
825
|
-
expect(result.acknowledged).toBe(true);
|
|
826
|
-
expect(result.acknowledged_at).toBeTruthy();
|
|
827
|
-
|
|
828
|
-
clearSessionState(senderCtx.sessionID);
|
|
829
|
-
clearSessionState(recipientCtx.sessionID);
|
|
830
|
-
});
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
// ============================================================================
|
|
834
|
-
// Multi-Agent Coordination Tests
|
|
835
|
-
// ============================================================================
|
|
836
|
-
|
|
837
|
-
describe("multi-agent coordination", () => {
|
|
838
|
-
it("enables communication between multiple agents", async () => {
|
|
839
|
-
const coordCtx = createTestContext();
|
|
840
|
-
const worker1Ctx = createTestContext();
|
|
841
|
-
const worker2Ctx = createTestContext();
|
|
842
|
-
|
|
843
|
-
await executeTool<{ agent_name: string }>(
|
|
844
|
-
swarmmail_init,
|
|
845
|
-
{ project_path: TEST_DB_PATH, agent_name: "Coordinator" },
|
|
846
|
-
coordCtx,
|
|
847
|
-
);
|
|
848
|
-
|
|
849
|
-
await executeTool<{ agent_name: string }>(
|
|
850
|
-
swarmmail_init,
|
|
851
|
-
{ project_path: TEST_DB_PATH, agent_name: "Worker1" },
|
|
852
|
-
worker1Ctx,
|
|
853
|
-
);
|
|
854
|
-
|
|
855
|
-
await executeTool<{ agent_name: string }>(
|
|
856
|
-
swarmmail_init,
|
|
857
|
-
{ project_path: TEST_DB_PATH, agent_name: "Worker2" },
|
|
858
|
-
worker2Ctx,
|
|
859
|
-
);
|
|
860
|
-
|
|
861
|
-
// Coordinator broadcasts to workers
|
|
862
|
-
await executeTool(
|
|
863
|
-
swarmmail_send,
|
|
864
|
-
{
|
|
865
|
-
to: ["Worker1", "Worker2"],
|
|
866
|
-
subject: "Task assignment",
|
|
867
|
-
body: "Please complete your subtasks",
|
|
868
|
-
thread_id: "bd-epic-123",
|
|
869
|
-
importance: "high",
|
|
870
|
-
},
|
|
871
|
-
coordCtx,
|
|
872
|
-
);
|
|
873
|
-
|
|
874
|
-
// Verify both workers received the message
|
|
875
|
-
const worker1Inbox = await executeTool<{
|
|
876
|
-
messages: Array<{ subject: string }>;
|
|
877
|
-
}>(swarmmail_inbox, {}, worker1Ctx);
|
|
878
|
-
|
|
879
|
-
const worker2Inbox = await executeTool<{
|
|
880
|
-
messages: Array<{ subject: string }>;
|
|
881
|
-
}>(swarmmail_inbox, {}, worker2Ctx);
|
|
882
|
-
|
|
883
|
-
expect(
|
|
884
|
-
worker1Inbox.messages.some((m) => m.subject === "Task assignment"),
|
|
885
|
-
).toBe(true);
|
|
886
|
-
expect(
|
|
887
|
-
worker2Inbox.messages.some((m) => m.subject === "Task assignment"),
|
|
888
|
-
).toBe(true);
|
|
889
|
-
|
|
890
|
-
clearSessionState(coordCtx.sessionID);
|
|
891
|
-
clearSessionState(worker1Ctx.sessionID);
|
|
892
|
-
clearSessionState(worker2Ctx.sessionID);
|
|
893
|
-
});
|
|
894
|
-
|
|
895
|
-
it("prevents file conflicts in swarm scenarios", async () => {
|
|
896
|
-
const worker1Ctx = createTestContext();
|
|
897
|
-
const worker2Ctx = createTestContext();
|
|
898
|
-
|
|
899
|
-
await executeTool<{ agent_name: string }>(
|
|
900
|
-
swarmmail_init,
|
|
901
|
-
{ project_path: TEST_DB_PATH, agent_name: "SwarmWorker1" },
|
|
902
|
-
worker1Ctx,
|
|
903
|
-
);
|
|
904
|
-
|
|
905
|
-
await executeTool<{ agent_name: string }>(
|
|
906
|
-
swarmmail_init,
|
|
907
|
-
{ project_path: TEST_DB_PATH, agent_name: "SwarmWorker2" },
|
|
908
|
-
worker2Ctx,
|
|
909
|
-
);
|
|
910
|
-
|
|
911
|
-
const path1 = "src/swarm/file1.ts";
|
|
912
|
-
const path2 = "src/swarm/file2.ts";
|
|
913
|
-
|
|
914
|
-
// Worker 1 reserves file 1
|
|
915
|
-
const res1 = await executeTool<{
|
|
916
|
-
granted: Array<{ id: number }>;
|
|
917
|
-
conflicts?: unknown[];
|
|
918
|
-
}>(
|
|
919
|
-
swarmmail_reserve,
|
|
920
|
-
{
|
|
921
|
-
paths: [path1],
|
|
922
|
-
exclusive: true,
|
|
923
|
-
reason: "bd-subtask-1",
|
|
924
|
-
},
|
|
925
|
-
worker1Ctx,
|
|
926
|
-
);
|
|
927
|
-
|
|
928
|
-
// Worker 2 reserves file 2
|
|
929
|
-
const res2 = await executeTool<{
|
|
930
|
-
granted: Array<{ id: number }>;
|
|
931
|
-
conflicts?: unknown[];
|
|
932
|
-
}>(
|
|
933
|
-
swarmmail_reserve,
|
|
934
|
-
{
|
|
935
|
-
paths: [path2],
|
|
936
|
-
exclusive: true,
|
|
937
|
-
reason: "bd-subtask-2",
|
|
938
|
-
},
|
|
939
|
-
worker2Ctx,
|
|
940
|
-
);
|
|
941
|
-
|
|
942
|
-
// Both should succeed (no conflicts)
|
|
943
|
-
expect(res1.granted.length).toBe(1);
|
|
944
|
-
expect(res1.conflicts).toBeUndefined();
|
|
945
|
-
expect(res2.granted.length).toBe(1);
|
|
946
|
-
expect(res2.conflicts).toBeUndefined();
|
|
947
|
-
|
|
948
|
-
// Worker 1 tries to reserve file 2 (should conflict)
|
|
949
|
-
const conflict = await executeTool<{
|
|
950
|
-
granted?: Array<{ id: number }>;
|
|
951
|
-
conflicts?: Array<{ path: string; holders: string[] }>;
|
|
952
|
-
warning?: string;
|
|
953
|
-
}>(
|
|
954
|
-
swarmmail_reserve,
|
|
955
|
-
{
|
|
956
|
-
paths: [path2],
|
|
957
|
-
exclusive: true,
|
|
958
|
-
},
|
|
959
|
-
worker1Ctx,
|
|
960
|
-
);
|
|
961
|
-
|
|
962
|
-
expect(conflict.conflicts).toBeDefined();
|
|
963
|
-
expect(conflict.conflicts?.length).toBeGreaterThan(0);
|
|
964
|
-
expect(conflict.warning).toContain("already reserved");
|
|
965
|
-
|
|
966
|
-
clearSessionState(worker1Ctx.sessionID);
|
|
967
|
-
clearSessionState(worker2Ctx.sessionID);
|
|
968
|
-
});
|
|
969
|
-
});
|
|
970
|
-
});
|