@herdctl/discord 1.0.6 → 1.0.7
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/dist/__tests__/auto-mode-handler.test.js +2 -2
- package/dist/__tests__/auto-mode-handler.test.js.map +1 -1
- package/dist/__tests__/discord-connector.test.js +12 -6
- package/dist/__tests__/discord-connector.test.js.map +1 -1
- package/dist/__tests__/error-handler.test.js +4 -4
- package/dist/__tests__/error-handler.test.js.map +1 -1
- package/dist/__tests__/errors.test.js +2 -2
- package/dist/__tests__/errors.test.js.map +1 -1
- package/dist/__tests__/logger.test.js +12 -4
- package/dist/__tests__/logger.test.js.map +1 -1
- package/dist/__tests__/manager.test.js +480 -120
- package/dist/__tests__/manager.test.js.map +1 -1
- package/dist/__tests__/mention-handler.test.js +19 -7
- package/dist/__tests__/mention-handler.test.js.map +1 -1
- package/dist/auto-mode-handler.d.ts +1 -1
- package/dist/auto-mode-handler.d.ts.map +1 -1
- package/dist/auto-mode-handler.js +1 -1
- package/dist/auto-mode-handler.js.map +1 -1
- package/dist/commands/__tests__/command-manager.test.js +1 -1
- package/dist/commands/__tests__/command-manager.test.js.map +1 -1
- package/dist/commands/__tests__/help.test.js +1 -1
- package/dist/commands/__tests__/help.test.js.map +1 -1
- package/dist/commands/__tests__/reset.test.js +1 -1
- package/dist/commands/__tests__/reset.test.js.map +1 -1
- package/dist/commands/__tests__/status.test.js +1 -1
- package/dist/commands/__tests__/status.test.js.map +1 -1
- package/dist/commands/command-manager.d.ts +1 -1
- package/dist/commands/command-manager.d.ts.map +1 -1
- package/dist/commands/command-manager.js +3 -6
- package/dist/commands/command-manager.js.map +1 -1
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/reset.d.ts.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/types.d.ts +1 -1
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/discord-connector.d.ts +3 -4
- package/dist/discord-connector.d.ts.map +1 -1
- package/dist/discord-connector.js +7 -10
- package/dist/discord-connector.js.map +1 -1
- package/dist/error-handler.d.ts.map +1 -1
- package/dist/error-handler.js +5 -7
- package/dist/error-handler.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +13 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -13
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +1 -3
- package/dist/logger.js.map +1 -1
- package/dist/manager.d.ts +1 -1
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +21 -13
- package/dist/manager.js.map +1 -1
- package/dist/mention-handler.d.ts +1 -1
- package/dist/mention-handler.d.ts.map +1 -1
- package/dist/mention-handler.js +1 -1
- package/dist/mention-handler.js.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/__tests__/formatting.test.js +5 -7
- package/dist/utils/__tests__/formatting.test.js.map +1 -1
- package/dist/utils/formatting.d.ts +1 -1
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils/formatting.js +1 -1
- package/dist/utils/formatting.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.js.map +1 -1
- package/package.json +5 -4
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Tests the DiscordManager class which manages Discord connectors
|
|
5
5
|
* for agents with chat.discord configured.
|
|
6
6
|
*/
|
|
7
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
8
7
|
import { EventEmitter } from "node:events";
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
9
9
|
import { DiscordManager } from "../manager.js";
|
|
10
10
|
// Mock logger
|
|
11
11
|
const mockLogger = {
|
|
@@ -32,7 +32,13 @@ function createMockContext(config = null) {
|
|
|
32
32
|
getCheckInterval: () => 1000,
|
|
33
33
|
emit: (event, ...args) => mockEmitter.emit(event, ...args),
|
|
34
34
|
getEmitter: () => mockEmitter,
|
|
35
|
-
trigger: vi.fn().mockResolvedValue({
|
|
35
|
+
trigger: vi.fn().mockResolvedValue({
|
|
36
|
+
jobId: "test-job",
|
|
37
|
+
agentName: "test",
|
|
38
|
+
scheduleName: null,
|
|
39
|
+
startedAt: new Date().toISOString(),
|
|
40
|
+
success: true,
|
|
41
|
+
}),
|
|
36
42
|
};
|
|
37
43
|
}
|
|
38
44
|
// Create a mock agent with Discord config
|
|
@@ -86,10 +92,7 @@ describe("DiscordManager", () => {
|
|
|
86
92
|
it("skips initialization when no agents have Discord configured", async () => {
|
|
87
93
|
const config = {
|
|
88
94
|
fleet: { name: "test-fleet" },
|
|
89
|
-
agents: [
|
|
90
|
-
createNonDiscordAgent("agent1"),
|
|
91
|
-
createNonDiscordAgent("agent2"),
|
|
92
|
-
],
|
|
95
|
+
agents: [createNonDiscordAgent("agent1"), createNonDiscordAgent("agent2")],
|
|
93
96
|
configPath: "/test/herdctl.yaml",
|
|
94
97
|
configDir: "/test",
|
|
95
98
|
};
|
|
@@ -102,8 +105,7 @@ describe("DiscordManager", () => {
|
|
|
102
105
|
await manager.initialize();
|
|
103
106
|
// Should either say "not installed" or "No agents with Discord configured"
|
|
104
107
|
const debugCalls = mockLogger.debug.mock.calls.map((c) => c[0]);
|
|
105
|
-
expect(debugCalls.some((msg) => msg.includes("not installed") ||
|
|
106
|
-
msg.includes("No agents with Discord configured"))).toBe(true);
|
|
108
|
+
expect(debugCalls.some((msg) => msg.includes("not installed") || msg.includes("No agents with Discord configured"))).toBe(true);
|
|
107
109
|
});
|
|
108
110
|
it("is idempotent - multiple calls only initialize once", async () => {
|
|
109
111
|
const config = {
|
|
@@ -118,7 +120,7 @@ describe("DiscordManager", () => {
|
|
|
118
120
|
await manager.initialize();
|
|
119
121
|
// The second call should return early without doing anything
|
|
120
122
|
// We can verify by checking the debug logs
|
|
121
|
-
const
|
|
123
|
+
const _debugCalls = mockLogger.debug.mock.calls.map((c) => c[0]);
|
|
122
124
|
// First init will log something, second call should not add more logs
|
|
123
125
|
// about initialization because it returns early
|
|
124
126
|
});
|
|
@@ -127,7 +129,13 @@ describe("DiscordManager", () => {
|
|
|
127
129
|
bot_token_env: "NONEXISTENT_BOT_TOKEN_VAR",
|
|
128
130
|
session_expiry_hours: 24,
|
|
129
131
|
log_level: "standard",
|
|
130
|
-
output: {
|
|
132
|
+
output: {
|
|
133
|
+
tool_results: true,
|
|
134
|
+
tool_result_max_length: 900,
|
|
135
|
+
system_status: true,
|
|
136
|
+
result_summary: false,
|
|
137
|
+
errors: true,
|
|
138
|
+
},
|
|
131
139
|
guilds: [],
|
|
132
140
|
};
|
|
133
141
|
const config = {
|
|
@@ -139,12 +147,12 @@ describe("DiscordManager", () => {
|
|
|
139
147
|
const ctx = createMockContext(config);
|
|
140
148
|
const manager = new DiscordManager(ctx);
|
|
141
149
|
// Clear the env var if it exists
|
|
142
|
-
const originalValue = process.env
|
|
143
|
-
delete process.env
|
|
150
|
+
const originalValue = process.env.NONEXISTENT_BOT_TOKEN_VAR;
|
|
151
|
+
delete process.env.NONEXISTENT_BOT_TOKEN_VAR;
|
|
144
152
|
await manager.initialize();
|
|
145
153
|
// Restore if it existed
|
|
146
154
|
if (originalValue !== undefined) {
|
|
147
|
-
process.env
|
|
155
|
+
process.env.NONEXISTENT_BOT_TOKEN_VAR = originalValue;
|
|
148
156
|
}
|
|
149
157
|
// The warning should only be logged if the discord package is available
|
|
150
158
|
// If the package is not available, it will log "not installed" first
|
|
@@ -417,7 +425,7 @@ describe.skip("DiscordManager response splitting", () => {
|
|
|
417
425
|
});
|
|
418
426
|
it("preserves code blocks when splitting", () => {
|
|
419
427
|
// Create a code block that spans beyond 2000 chars
|
|
420
|
-
const codeBlock =
|
|
428
|
+
const codeBlock = `\`\`\`typescript\n${"const x = 1;\n".repeat(200)}\`\`\``;
|
|
421
429
|
const result = manager.splitResponse(codeBlock);
|
|
422
430
|
expect(result.length).toBeGreaterThan(1);
|
|
423
431
|
// First chunk should close the code block
|
|
@@ -426,7 +434,7 @@ describe.skip("DiscordManager response splitting", () => {
|
|
|
426
434
|
expect(result[1]).toMatch(/^```typescript/);
|
|
427
435
|
});
|
|
428
436
|
it("preserves code blocks with no language specified", () => {
|
|
429
|
-
const codeBlock =
|
|
437
|
+
const codeBlock = `\`\`\`\n${"line of code\n".repeat(200)}\`\`\``;
|
|
430
438
|
const result = manager.splitResponse(codeBlock);
|
|
431
439
|
expect(result.length).toBeGreaterThan(1);
|
|
432
440
|
// First chunk should close the code block
|
|
@@ -446,7 +454,7 @@ describe.skip("DiscordManager response splitting", () => {
|
|
|
446
454
|
});
|
|
447
455
|
it("prefers paragraph breaks over line breaks", () => {
|
|
448
456
|
// Create text with both paragraph and line breaks
|
|
449
|
-
const paragraph1 = "First paragraph. ".repeat(50)
|
|
457
|
+
const paragraph1 = `${"First paragraph. ".repeat(50)}\n\n`;
|
|
450
458
|
const paragraph2 = "Second paragraph. ".repeat(50);
|
|
451
459
|
const text = paragraph1 + paragraph2;
|
|
452
460
|
if (text.length > 2000) {
|
|
@@ -458,7 +466,7 @@ describe.skip("DiscordManager response splitting", () => {
|
|
|
458
466
|
it("handles code block that opens and closes within split region", () => {
|
|
459
467
|
// Create text where a code block opens and then closes before split point
|
|
460
468
|
// This tests the code path where insideBlock becomes false after closing
|
|
461
|
-
const text =
|
|
469
|
+
const text = `Some intro text\n\`\`\`js\nconst x = 1;\n\`\`\`\nMore text here ${"padding ".repeat(250)}`;
|
|
462
470
|
const result = manager.splitResponse(text);
|
|
463
471
|
expect(result.length).toBeGreaterThanOrEqual(1);
|
|
464
472
|
// Should not break inside code block since it's closed
|
|
@@ -482,7 +490,7 @@ describe.skip("DiscordManager response splitting", () => {
|
|
|
482
490
|
});
|
|
483
491
|
it("handles multiple code blocks opening and closing", () => {
|
|
484
492
|
// Multiple code blocks that open and close
|
|
485
|
-
const text =
|
|
493
|
+
const text = `\`\`\`js\ncode1\n\`\`\`\n${"text ".repeat(100)}\n\`\`\`py\ncode2\n\`\`\`\n${"more ".repeat(200)}`;
|
|
486
494
|
const result = manager.splitResponse(text);
|
|
487
495
|
expect(result.length).toBeGreaterThanOrEqual(1);
|
|
488
496
|
result.forEach((chunk) => {
|
|
@@ -557,7 +565,7 @@ describe.skip("DiscordManager response splitting", () => {
|
|
|
557
565
|
const replyMock = vi.fn().mockImplementation(async (content) => {
|
|
558
566
|
calls.push(content);
|
|
559
567
|
});
|
|
560
|
-
const text =
|
|
568
|
+
const text = `First part.\n${"x".repeat(2000)}\nLast part.`;
|
|
561
569
|
await manager.sendResponse(replyMock, text);
|
|
562
570
|
// Verify order by checking first call starts with "First"
|
|
563
571
|
expect(calls[0]).toMatch(/^First/);
|
|
@@ -586,7 +594,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
586
594
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
587
595
|
session_expiry_hours: 24,
|
|
588
596
|
log_level: "standard",
|
|
589
|
-
output: {
|
|
597
|
+
output: {
|
|
598
|
+
tool_results: true,
|
|
599
|
+
tool_result_max_length: 900,
|
|
600
|
+
system_status: true,
|
|
601
|
+
result_summary: false,
|
|
602
|
+
errors: true,
|
|
603
|
+
},
|
|
590
604
|
guilds: [],
|
|
591
605
|
}),
|
|
592
606
|
],
|
|
@@ -607,7 +621,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
607
621
|
getCheckInterval: () => 1000,
|
|
608
622
|
emit: (event, ...args) => emitterWithTrigger.emit(event, ...args),
|
|
609
623
|
getEmitter: () => emitterWithTrigger,
|
|
610
|
-
trigger: vi.fn().mockResolvedValue({
|
|
624
|
+
trigger: vi.fn().mockResolvedValue({
|
|
625
|
+
jobId: "test-job",
|
|
626
|
+
agentName: "test",
|
|
627
|
+
scheduleName: null,
|
|
628
|
+
startedAt: new Date().toISOString(),
|
|
629
|
+
success: true,
|
|
630
|
+
}),
|
|
611
631
|
};
|
|
612
632
|
manager = new DiscordManager(mockContext);
|
|
613
633
|
});
|
|
@@ -625,7 +645,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
625
645
|
reconnectAttempts: 0,
|
|
626
646
|
lastError: null,
|
|
627
647
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
628
|
-
rateLimits: {
|
|
648
|
+
rateLimits: {
|
|
649
|
+
totalCount: 0,
|
|
650
|
+
lastRateLimitAt: null,
|
|
651
|
+
isRateLimited: false,
|
|
652
|
+
currentResetTime: 0,
|
|
653
|
+
},
|
|
629
654
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
630
655
|
});
|
|
631
656
|
mockConnector.agentName = "test-agent";
|
|
@@ -653,7 +678,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
653
678
|
reconnectAttempts: 0,
|
|
654
679
|
lastError: null,
|
|
655
680
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
656
|
-
rateLimits: {
|
|
681
|
+
rateLimits: {
|
|
682
|
+
totalCount: 0,
|
|
683
|
+
lastRateLimitAt: null,
|
|
684
|
+
isRateLimited: false,
|
|
685
|
+
currentResetTime: 0,
|
|
686
|
+
},
|
|
657
687
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
658
688
|
});
|
|
659
689
|
mockConnector.agentName = "test-agent";
|
|
@@ -695,7 +725,9 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
695
725
|
});
|
|
696
726
|
it("streams each assistant message immediately via onMessage callback", async () => {
|
|
697
727
|
// Create trigger mock that invokes onMessage callback with streaming content
|
|
698
|
-
const customTriggerMock = vi
|
|
728
|
+
const customTriggerMock = vi
|
|
729
|
+
.fn()
|
|
730
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
699
731
|
// Simulate streaming messages from the agent - each is sent immediately
|
|
700
732
|
if (options?.onMessage) {
|
|
701
733
|
await options.onMessage({ type: "assistant", content: "Hello! " });
|
|
@@ -715,7 +747,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
715
747
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
716
748
|
session_expiry_hours: 24,
|
|
717
749
|
log_level: "standard",
|
|
718
|
-
output: {
|
|
750
|
+
output: {
|
|
751
|
+
tool_results: true,
|
|
752
|
+
tool_result_max_length: 900,
|
|
753
|
+
system_status: true,
|
|
754
|
+
result_summary: false,
|
|
755
|
+
errors: true,
|
|
756
|
+
},
|
|
719
757
|
guilds: [],
|
|
720
758
|
}),
|
|
721
759
|
],
|
|
@@ -736,7 +774,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
736
774
|
getCheckInterval: () => 1000,
|
|
737
775
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
738
776
|
getEmitter: () => streamingEmitter,
|
|
739
|
-
trigger: vi.fn().mockResolvedValue({
|
|
777
|
+
trigger: vi.fn().mockResolvedValue({
|
|
778
|
+
jobId: "test-job",
|
|
779
|
+
agentName: "test",
|
|
780
|
+
scheduleName: null,
|
|
781
|
+
startedAt: new Date().toISOString(),
|
|
782
|
+
success: true,
|
|
783
|
+
}),
|
|
740
784
|
};
|
|
741
785
|
const streamingManager = new DiscordManager(streamingContext);
|
|
742
786
|
const mockConnector = new EventEmitter();
|
|
@@ -750,13 +794,20 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
750
794
|
reconnectAttempts: 0,
|
|
751
795
|
lastError: null,
|
|
752
796
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
753
|
-
rateLimits: {
|
|
797
|
+
rateLimits: {
|
|
798
|
+
totalCount: 0,
|
|
799
|
+
lastRateLimitAt: null,
|
|
800
|
+
isRateLimited: false,
|
|
801
|
+
currentResetTime: 0,
|
|
802
|
+
},
|
|
754
803
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
755
804
|
});
|
|
756
805
|
mockConnector.agentName = "streaming-agent";
|
|
757
806
|
mockConnector.sessionManager = {
|
|
758
807
|
getOrCreateSession: vi.fn().mockResolvedValue({ sessionId: "s1", isNew: false }),
|
|
759
|
-
getSession: vi
|
|
808
|
+
getSession: vi
|
|
809
|
+
.fn()
|
|
810
|
+
.mockResolvedValue({ sessionId: "s1", lastMessageAt: new Date().toISOString() }),
|
|
760
811
|
setSession: vi.fn().mockResolvedValue(undefined),
|
|
761
812
|
touchSession: vi.fn().mockResolvedValue(undefined),
|
|
762
813
|
getActiveSessionCount: vi.fn().mockResolvedValue(0),
|
|
@@ -800,7 +851,9 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
800
851
|
it("sends long streaming response with splitResponse", async () => {
|
|
801
852
|
// Create trigger mock that produces a long response
|
|
802
853
|
const longResponse = "This is a very long response. ".repeat(100); // About 3100 chars
|
|
803
|
-
const customTriggerMock = vi
|
|
854
|
+
const customTriggerMock = vi
|
|
855
|
+
.fn()
|
|
856
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
804
857
|
if (options?.onMessage) {
|
|
805
858
|
await options.onMessage({ type: "assistant", content: longResponse });
|
|
806
859
|
}
|
|
@@ -816,7 +869,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
816
869
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
817
870
|
session_expiry_hours: 24,
|
|
818
871
|
log_level: "standard",
|
|
819
|
-
output: {
|
|
872
|
+
output: {
|
|
873
|
+
tool_results: true,
|
|
874
|
+
tool_result_max_length: 900,
|
|
875
|
+
system_status: true,
|
|
876
|
+
result_summary: false,
|
|
877
|
+
errors: true,
|
|
878
|
+
},
|
|
820
879
|
guilds: [],
|
|
821
880
|
}),
|
|
822
881
|
],
|
|
@@ -837,7 +896,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
837
896
|
getCheckInterval: () => 1000,
|
|
838
897
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
839
898
|
getEmitter: () => streamingEmitter,
|
|
840
|
-
trigger: vi.fn().mockResolvedValue({
|
|
899
|
+
trigger: vi.fn().mockResolvedValue({
|
|
900
|
+
jobId: "test-job",
|
|
901
|
+
agentName: "test",
|
|
902
|
+
scheduleName: null,
|
|
903
|
+
startedAt: new Date().toISOString(),
|
|
904
|
+
success: true,
|
|
905
|
+
}),
|
|
841
906
|
};
|
|
842
907
|
const streamingManager = new DiscordManager(streamingContext);
|
|
843
908
|
const mockConnector = new EventEmitter();
|
|
@@ -851,13 +916,20 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
851
916
|
reconnectAttempts: 0,
|
|
852
917
|
lastError: null,
|
|
853
918
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
854
|
-
rateLimits: {
|
|
919
|
+
rateLimits: {
|
|
920
|
+
totalCount: 0,
|
|
921
|
+
lastRateLimitAt: null,
|
|
922
|
+
isRateLimited: false,
|
|
923
|
+
currentResetTime: 0,
|
|
924
|
+
},
|
|
855
925
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
856
926
|
});
|
|
857
927
|
mockConnector.agentName = "long-agent";
|
|
858
928
|
mockConnector.sessionManager = {
|
|
859
929
|
getOrCreateSession: vi.fn().mockResolvedValue({ sessionId: "s1", isNew: false }),
|
|
860
|
-
getSession: vi
|
|
930
|
+
getSession: vi
|
|
931
|
+
.fn()
|
|
932
|
+
.mockResolvedValue({ sessionId: "s1", lastMessageAt: new Date().toISOString() }),
|
|
861
933
|
setSession: vi.fn().mockResolvedValue(undefined),
|
|
862
934
|
touchSession: vi.fn().mockResolvedValue(undefined),
|
|
863
935
|
getActiveSessionCount: vi.fn().mockResolvedValue(0),
|
|
@@ -898,7 +970,9 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
898
970
|
});
|
|
899
971
|
it("streams tool results from user messages to Discord", async () => {
|
|
900
972
|
// Create trigger mock that sends assistant message with tool_use, then user message with tool_result
|
|
901
|
-
const customTriggerMock = vi
|
|
973
|
+
const customTriggerMock = vi
|
|
974
|
+
.fn()
|
|
975
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
902
976
|
if (options?.onMessage) {
|
|
903
977
|
// Claude decides to use Bash tool
|
|
904
978
|
await options.onMessage({
|
|
@@ -906,7 +980,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
906
980
|
message: {
|
|
907
981
|
content: [
|
|
908
982
|
{ type: "text", text: "Let me check that for you." },
|
|
909
|
-
{
|
|
983
|
+
{
|
|
984
|
+
type: "tool_use",
|
|
985
|
+
name: "Bash",
|
|
986
|
+
id: "tool-1",
|
|
987
|
+
input: { command: "ls -la /tmp" },
|
|
988
|
+
},
|
|
910
989
|
],
|
|
911
990
|
},
|
|
912
991
|
});
|
|
@@ -927,9 +1006,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
927
1006
|
await options.onMessage({
|
|
928
1007
|
type: "assistant",
|
|
929
1008
|
message: {
|
|
930
|
-
content: [
|
|
931
|
-
{ type: "text", text: "Here are the files in /tmp." },
|
|
932
|
-
],
|
|
1009
|
+
content: [{ type: "text", text: "Here are the files in /tmp." }],
|
|
933
1010
|
},
|
|
934
1011
|
});
|
|
935
1012
|
}
|
|
@@ -945,7 +1022,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
945
1022
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
946
1023
|
session_expiry_hours: 24,
|
|
947
1024
|
log_level: "standard",
|
|
948
|
-
output: {
|
|
1025
|
+
output: {
|
|
1026
|
+
tool_results: true,
|
|
1027
|
+
tool_result_max_length: 900,
|
|
1028
|
+
system_status: true,
|
|
1029
|
+
result_summary: false,
|
|
1030
|
+
errors: true,
|
|
1031
|
+
},
|
|
949
1032
|
guilds: [],
|
|
950
1033
|
}),
|
|
951
1034
|
],
|
|
@@ -966,7 +1049,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
966
1049
|
getCheckInterval: () => 1000,
|
|
967
1050
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
968
1051
|
getEmitter: () => streamingEmitter,
|
|
969
|
-
trigger: vi.fn().mockResolvedValue({
|
|
1052
|
+
trigger: vi.fn().mockResolvedValue({
|
|
1053
|
+
jobId: "test-job",
|
|
1054
|
+
agentName: "test",
|
|
1055
|
+
scheduleName: null,
|
|
1056
|
+
startedAt: new Date().toISOString(),
|
|
1057
|
+
success: true,
|
|
1058
|
+
}),
|
|
970
1059
|
};
|
|
971
1060
|
const streamingManager = new DiscordManager(streamingContext);
|
|
972
1061
|
const mockConnector = new EventEmitter();
|
|
@@ -980,7 +1069,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
980
1069
|
reconnectAttempts: 0,
|
|
981
1070
|
lastError: null,
|
|
982
1071
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
983
|
-
rateLimits: {
|
|
1072
|
+
rateLimits: {
|
|
1073
|
+
totalCount: 0,
|
|
1074
|
+
lastRateLimitAt: null,
|
|
1075
|
+
isRateLimited: false,
|
|
1076
|
+
currentResetTime: 0,
|
|
1077
|
+
},
|
|
984
1078
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
985
1079
|
});
|
|
986
1080
|
mockConnector.agentName = "tool-agent";
|
|
@@ -1043,7 +1137,9 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1043
1137
|
}, 10000);
|
|
1044
1138
|
it("streams tool results from top-level tool_use_result", async () => {
|
|
1045
1139
|
// Test the alternative SDK format where tool_use_result is at the top level
|
|
1046
|
-
const customTriggerMock = vi
|
|
1140
|
+
const customTriggerMock = vi
|
|
1141
|
+
.fn()
|
|
1142
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
1047
1143
|
if (options?.onMessage) {
|
|
1048
1144
|
await options.onMessage({
|
|
1049
1145
|
type: "user",
|
|
@@ -1062,7 +1158,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1062
1158
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
1063
1159
|
session_expiry_hours: 24,
|
|
1064
1160
|
log_level: "standard",
|
|
1065
|
-
output: {
|
|
1161
|
+
output: {
|
|
1162
|
+
tool_results: true,
|
|
1163
|
+
tool_result_max_length: 900,
|
|
1164
|
+
system_status: true,
|
|
1165
|
+
result_summary: false,
|
|
1166
|
+
errors: true,
|
|
1167
|
+
},
|
|
1066
1168
|
guilds: [],
|
|
1067
1169
|
}),
|
|
1068
1170
|
],
|
|
@@ -1083,7 +1185,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1083
1185
|
getCheckInterval: () => 1000,
|
|
1084
1186
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
1085
1187
|
getEmitter: () => streamingEmitter,
|
|
1086
|
-
trigger: vi.fn().mockResolvedValue({
|
|
1188
|
+
trigger: vi.fn().mockResolvedValue({
|
|
1189
|
+
jobId: "test-job",
|
|
1190
|
+
agentName: "test",
|
|
1191
|
+
scheduleName: null,
|
|
1192
|
+
startedAt: new Date().toISOString(),
|
|
1193
|
+
success: true,
|
|
1194
|
+
}),
|
|
1087
1195
|
};
|
|
1088
1196
|
const streamingManager = new DiscordManager(streamingContext);
|
|
1089
1197
|
const mockConnector = new EventEmitter();
|
|
@@ -1097,7 +1205,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1097
1205
|
reconnectAttempts: 0,
|
|
1098
1206
|
lastError: null,
|
|
1099
1207
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
1100
|
-
rateLimits: {
|
|
1208
|
+
rateLimits: {
|
|
1209
|
+
totalCount: 0,
|
|
1210
|
+
lastRateLimitAt: null,
|
|
1211
|
+
isRateLimited: false,
|
|
1212
|
+
currentResetTime: 0,
|
|
1213
|
+
},
|
|
1101
1214
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
1102
1215
|
});
|
|
1103
1216
|
mockConnector.agentName = "tool-agent-2";
|
|
@@ -1175,7 +1288,13 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1175
1288
|
getCheckInterval: () => 1000,
|
|
1176
1289
|
emit: (event, ...args) => errorEmitter.emit(event, ...args),
|
|
1177
1290
|
getEmitter: () => errorEmitter,
|
|
1178
|
-
trigger: vi.fn().mockResolvedValue({
|
|
1291
|
+
trigger: vi.fn().mockResolvedValue({
|
|
1292
|
+
jobId: "test-job",
|
|
1293
|
+
agentName: "test",
|
|
1294
|
+
scheduleName: null,
|
|
1295
|
+
startedAt: new Date().toISOString(),
|
|
1296
|
+
success: true,
|
|
1297
|
+
}),
|
|
1179
1298
|
};
|
|
1180
1299
|
const errorManager = new DiscordManager(errorContext);
|
|
1181
1300
|
const mockConnector = new EventEmitter();
|
|
@@ -1189,7 +1308,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1189
1308
|
reconnectAttempts: 0,
|
|
1190
1309
|
lastError: null,
|
|
1191
1310
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
1192
|
-
rateLimits: {
|
|
1311
|
+
rateLimits: {
|
|
1312
|
+
totalCount: 0,
|
|
1313
|
+
lastRateLimitAt: null,
|
|
1314
|
+
isRateLimited: false,
|
|
1315
|
+
currentResetTime: 0,
|
|
1316
|
+
},
|
|
1193
1317
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
1194
1318
|
});
|
|
1195
1319
|
mockConnector.agentName = "missing-agent";
|
|
@@ -1245,7 +1369,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1245
1369
|
reconnectAttempts: 0,
|
|
1246
1370
|
lastError: null,
|
|
1247
1371
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
1248
|
-
rateLimits: {
|
|
1372
|
+
rateLimits: {
|
|
1373
|
+
totalCount: 0,
|
|
1374
|
+
lastRateLimitAt: null,
|
|
1375
|
+
isRateLimited: false,
|
|
1376
|
+
currentResetTime: 0,
|
|
1377
|
+
},
|
|
1249
1378
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
1250
1379
|
});
|
|
1251
1380
|
mockConnector.agentName = "test-agent";
|
|
@@ -1278,7 +1407,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1278
1407
|
reconnectAttempts: 0,
|
|
1279
1408
|
lastError: null,
|
|
1280
1409
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
1281
|
-
rateLimits: {
|
|
1410
|
+
rateLimits: {
|
|
1411
|
+
totalCount: 0,
|
|
1412
|
+
lastRateLimitAt: null,
|
|
1413
|
+
isRateLimited: false,
|
|
1414
|
+
currentResetTime: 0,
|
|
1415
|
+
},
|
|
1282
1416
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
1283
1417
|
});
|
|
1284
1418
|
mockConnector.agentName = "test-agent";
|
|
@@ -1333,7 +1467,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1333
1467
|
reconnectAttempts: 0,
|
|
1334
1468
|
lastError: null,
|
|
1335
1469
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
1336
|
-
rateLimits: {
|
|
1470
|
+
rateLimits: {
|
|
1471
|
+
totalCount: 0,
|
|
1472
|
+
lastRateLimitAt: null,
|
|
1473
|
+
isRateLimited: false,
|
|
1474
|
+
currentResetTime: 0,
|
|
1475
|
+
},
|
|
1337
1476
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
1338
1477
|
});
|
|
1339
1478
|
mockConnector.agentName = "test-agent";
|
|
@@ -1387,7 +1526,12 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1387
1526
|
reconnectAttempts: 0,
|
|
1388
1527
|
lastError: null,
|
|
1389
1528
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
1390
|
-
rateLimits: {
|
|
1529
|
+
rateLimits: {
|
|
1530
|
+
totalCount: 0,
|
|
1531
|
+
lastRateLimitAt: null,
|
|
1532
|
+
isRateLimited: false,
|
|
1533
|
+
currentResetTime: 0,
|
|
1534
|
+
},
|
|
1391
1535
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
1392
1536
|
});
|
|
1393
1537
|
mockConnector.agentName = "unknown-agent";
|
|
@@ -1469,9 +1613,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1469
1613
|
const result = manager.extractMessageContent({
|
|
1470
1614
|
type: "assistant",
|
|
1471
1615
|
message: {
|
|
1472
|
-
content: [
|
|
1473
|
-
{ type: "tool_use", name: "some_tool" },
|
|
1474
|
-
],
|
|
1616
|
+
content: [{ type: "tool_use", name: "some_tool" }],
|
|
1475
1617
|
},
|
|
1476
1618
|
});
|
|
1477
1619
|
expect(result).toBeUndefined();
|
|
@@ -1582,9 +1724,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1582
1724
|
const result = manager.extractToolUseBlocks({
|
|
1583
1725
|
type: "assistant",
|
|
1584
1726
|
message: {
|
|
1585
|
-
content: [
|
|
1586
|
-
{ type: "tool_use", name: "some_tool" },
|
|
1587
|
-
],
|
|
1727
|
+
content: [{ type: "tool_use", name: "some_tool" }],
|
|
1588
1728
|
},
|
|
1589
1729
|
});
|
|
1590
1730
|
expect(result).toHaveLength(1);
|
|
@@ -1596,9 +1736,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1596
1736
|
const result = manager.extractToolUseBlocks({
|
|
1597
1737
|
type: "assistant",
|
|
1598
1738
|
message: {
|
|
1599
|
-
content: [
|
|
1600
|
-
{ type: "text", text: "Just a text response" },
|
|
1601
|
-
],
|
|
1739
|
+
content: [{ type: "text", text: "Just a text response" }],
|
|
1602
1740
|
},
|
|
1603
1741
|
});
|
|
1604
1742
|
expect(result).toHaveLength(0);
|
|
@@ -1626,7 +1764,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1626
1764
|
expect(result).toBe("ls -la");
|
|
1627
1765
|
});
|
|
1628
1766
|
it("truncates long Bash commands", () => {
|
|
1629
|
-
const longCommand =
|
|
1767
|
+
const longCommand = `echo ${"a".repeat(250)}`;
|
|
1630
1768
|
// @ts-expect-error - accessing private method for testing
|
|
1631
1769
|
const result = manager.getToolInputSummary("Bash", { command: longCommand });
|
|
1632
1770
|
expect(result).toContain("...");
|
|
@@ -1793,9 +1931,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1793
1931
|
const results = manager.extractToolResults({
|
|
1794
1932
|
type: "user",
|
|
1795
1933
|
message: {
|
|
1796
|
-
content: [
|
|
1797
|
-
{ type: "text", text: "Just a regular user message" },
|
|
1798
|
-
],
|
|
1934
|
+
content: [{ type: "text", text: "Just a regular user message" }],
|
|
1799
1935
|
},
|
|
1800
1936
|
});
|
|
1801
1937
|
expect(results).toHaveLength(0);
|
|
@@ -1816,29 +1952,32 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1816
1952
|
expect(embed.description).toContain("ls -la");
|
|
1817
1953
|
expect(embed.color).toBe(0x5865f2);
|
|
1818
1954
|
expect(embed.fields).toBeDefined();
|
|
1819
|
-
const fieldNames = embed.fields.map(f => f.name);
|
|
1955
|
+
const fieldNames = embed.fields.map((f) => f.name);
|
|
1820
1956
|
expect(fieldNames).toContain("Duration");
|
|
1821
1957
|
expect(fieldNames).toContain("Output");
|
|
1822
1958
|
expect(fieldNames).toContain("Result");
|
|
1823
1959
|
// Result field should contain the output in a code block
|
|
1824
|
-
const resultField = embed.fields.find(f => f.name === "Result");
|
|
1960
|
+
const resultField = embed.fields.find((f) => f.name === "Result");
|
|
1825
1961
|
expect(resultField.value).toContain("file1.txt");
|
|
1826
1962
|
});
|
|
1827
1963
|
it("builds embed with error color for error results", () => {
|
|
1828
1964
|
// @ts-expect-error - accessing private method for testing
|
|
1829
1965
|
const embed = manager.buildToolEmbed({ name: "Bash", input: { command: "rm -rf /" }, startTime: Date.now() - 500 }, { output: "Permission denied", isError: true });
|
|
1830
1966
|
expect(embed.color).toBe(0xef4444);
|
|
1831
|
-
const errorField = embed.fields.find(f => f.name === "Error");
|
|
1967
|
+
const errorField = embed.fields.find((f) => f.name === "Error");
|
|
1832
1968
|
expect(errorField).toBeDefined();
|
|
1833
1969
|
expect(errorField.value).toContain("Permission denied");
|
|
1834
1970
|
});
|
|
1835
1971
|
it("builds embed without tool_use info (fallback)", () => {
|
|
1836
1972
|
// @ts-expect-error - accessing private method for testing
|
|
1837
|
-
const embed = manager.buildToolEmbed(null, {
|
|
1973
|
+
const embed = manager.buildToolEmbed(null, {
|
|
1974
|
+
output: "some output",
|
|
1975
|
+
isError: false,
|
|
1976
|
+
});
|
|
1838
1977
|
expect(embed.title).toContain("Tool");
|
|
1839
1978
|
expect(embed.description).toBeUndefined();
|
|
1840
1979
|
// No Duration field when no tool_use info
|
|
1841
|
-
const fieldNames = embed.fields.map(f => f.name);
|
|
1980
|
+
const fieldNames = embed.fields.map((f) => f.name);
|
|
1842
1981
|
expect(fieldNames).not.toContain("Duration");
|
|
1843
1982
|
expect(fieldNames).toContain("Output");
|
|
1844
1983
|
});
|
|
@@ -1846,7 +1985,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1846
1985
|
const longOutput = "x".repeat(2000);
|
|
1847
1986
|
// @ts-expect-error - accessing private method for testing
|
|
1848
1987
|
const embed = manager.buildToolEmbed({ name: "Bash", input: { command: "cat bigfile" }, startTime: Date.now() - 100 }, { output: longOutput, isError: false });
|
|
1849
|
-
const resultField = embed.fields.find(f => f.name === "Result");
|
|
1988
|
+
const resultField = embed.fields.find((f) => f.name === "Result");
|
|
1850
1989
|
expect(resultField).toBeDefined();
|
|
1851
1990
|
expect(resultField.value).toContain("chars total");
|
|
1852
1991
|
// Total field value should fit in Discord embed field limit (1024)
|
|
@@ -1856,7 +1995,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1856
1995
|
const output = "x".repeat(1500);
|
|
1857
1996
|
// @ts-expect-error - accessing private method for testing
|
|
1858
1997
|
const embed = manager.buildToolEmbed({ name: "Read", input: { file_path: "/big.txt" }, startTime: Date.now() - 200 }, { output, isError: false });
|
|
1859
|
-
const outputField = embed.fields.find(f => f.name === "Output");
|
|
1998
|
+
const outputField = embed.fields.find((f) => f.name === "Output");
|
|
1860
1999
|
expect(outputField.value).toContain("k chars");
|
|
1861
2000
|
});
|
|
1862
2001
|
it("shows Read tool with file path in description", () => {
|
|
@@ -1868,7 +2007,7 @@ describe.skip("DiscordManager message handling", () => {
|
|
|
1868
2007
|
it("omits Result field for empty output", () => {
|
|
1869
2008
|
// @ts-expect-error - accessing private method for testing
|
|
1870
2009
|
const embed = manager.buildToolEmbed({ name: "Bash", input: { command: "true" }, startTime: Date.now() - 10 }, { output: " \n\n ", isError: false });
|
|
1871
|
-
const fieldNames = embed.fields.map(f => f.name);
|
|
2010
|
+
const fieldNames = embed.fields.map((f) => f.name);
|
|
1872
2011
|
expect(fieldNames).not.toContain("Result");
|
|
1873
2012
|
});
|
|
1874
2013
|
});
|
|
@@ -1887,7 +2026,9 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
1887
2026
|
mockSessionManager = {
|
|
1888
2027
|
agentName: "test-agent",
|
|
1889
2028
|
getOrCreateSession: vi.fn().mockResolvedValue({ sessionId: "session-123", isNew: false }),
|
|
1890
|
-
getSession: vi
|
|
2029
|
+
getSession: vi
|
|
2030
|
+
.fn()
|
|
2031
|
+
.mockResolvedValue({ sessionId: "session-123", lastMessageAt: new Date().toISOString() }),
|
|
1891
2032
|
setSession: vi.fn().mockResolvedValue(undefined),
|
|
1892
2033
|
touchSession: vi.fn().mockResolvedValue(undefined),
|
|
1893
2034
|
clearSession: vi.fn().mockResolvedValue(true),
|
|
@@ -1895,7 +2036,9 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
1895
2036
|
getActiveSessionCount: vi.fn().mockResolvedValue(5),
|
|
1896
2037
|
};
|
|
1897
2038
|
// Create a mock FleetManager (emitter) with trigger method
|
|
1898
|
-
triggerMock = vi
|
|
2039
|
+
triggerMock = vi
|
|
2040
|
+
.fn()
|
|
2041
|
+
.mockResolvedValue({ jobId: "job-123", success: true, sessionId: "sdk-session-456" });
|
|
1899
2042
|
emitterWithTrigger = Object.assign(new EventEmitter(), {
|
|
1900
2043
|
trigger: triggerMock,
|
|
1901
2044
|
});
|
|
@@ -1906,7 +2049,13 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
1906
2049
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
1907
2050
|
session_expiry_hours: 24,
|
|
1908
2051
|
log_level: "standard",
|
|
1909
|
-
output: {
|
|
2052
|
+
output: {
|
|
2053
|
+
tool_results: true,
|
|
2054
|
+
tool_result_max_length: 900,
|
|
2055
|
+
system_status: true,
|
|
2056
|
+
result_summary: false,
|
|
2057
|
+
errors: true,
|
|
2058
|
+
},
|
|
1910
2059
|
guilds: [],
|
|
1911
2060
|
}),
|
|
1912
2061
|
],
|
|
@@ -1927,7 +2076,13 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
1927
2076
|
getCheckInterval: () => 1000,
|
|
1928
2077
|
emit: (event, ...args) => emitterWithTrigger.emit(event, ...args),
|
|
1929
2078
|
getEmitter: () => emitterWithTrigger,
|
|
1930
|
-
trigger: vi.fn().mockResolvedValue({
|
|
2079
|
+
trigger: vi.fn().mockResolvedValue({
|
|
2080
|
+
jobId: "test-job",
|
|
2081
|
+
agentName: "test",
|
|
2082
|
+
scheduleName: null,
|
|
2083
|
+
startedAt: new Date().toISOString(),
|
|
2084
|
+
success: true,
|
|
2085
|
+
}),
|
|
1931
2086
|
};
|
|
1932
2087
|
manager = new DiscordManager(mockContext);
|
|
1933
2088
|
});
|
|
@@ -1944,7 +2099,12 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
1944
2099
|
reconnectAttempts: 0,
|
|
1945
2100
|
lastError: null,
|
|
1946
2101
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
1947
|
-
rateLimits: {
|
|
2102
|
+
rateLimits: {
|
|
2103
|
+
totalCount: 0,
|
|
2104
|
+
lastRateLimitAt: null,
|
|
2105
|
+
isRateLimited: false,
|
|
2106
|
+
currentResetTime: 0,
|
|
2107
|
+
},
|
|
1948
2108
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
1949
2109
|
});
|
|
1950
2110
|
mockConnector.agentName = "test-agent";
|
|
@@ -1996,7 +2156,12 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
1996
2156
|
reconnectAttempts: 0,
|
|
1997
2157
|
lastError: null,
|
|
1998
2158
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
1999
|
-
rateLimits: {
|
|
2159
|
+
rateLimits: {
|
|
2160
|
+
totalCount: 0,
|
|
2161
|
+
lastRateLimitAt: null,
|
|
2162
|
+
isRateLimited: false,
|
|
2163
|
+
currentResetTime: 0,
|
|
2164
|
+
},
|
|
2000
2165
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2001
2166
|
});
|
|
2002
2167
|
mockConnector.agentName = "test-agent";
|
|
@@ -2049,7 +2214,12 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
2049
2214
|
reconnectAttempts: 0,
|
|
2050
2215
|
lastError: null,
|
|
2051
2216
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2052
|
-
rateLimits: {
|
|
2217
|
+
rateLimits: {
|
|
2218
|
+
totalCount: 0,
|
|
2219
|
+
lastRateLimitAt: null,
|
|
2220
|
+
isRateLimited: false,
|
|
2221
|
+
currentResetTime: 0,
|
|
2222
|
+
},
|
|
2053
2223
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2054
2224
|
});
|
|
2055
2225
|
mockConnector.agentName = "test-agent";
|
|
@@ -2104,7 +2274,12 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
2104
2274
|
reconnectAttempts: 0,
|
|
2105
2275
|
lastError: null,
|
|
2106
2276
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2107
|
-
rateLimits: {
|
|
2277
|
+
rateLimits: {
|
|
2278
|
+
totalCount: 0,
|
|
2279
|
+
lastRateLimitAt: null,
|
|
2280
|
+
isRateLimited: false,
|
|
2281
|
+
currentResetTime: 0,
|
|
2282
|
+
},
|
|
2108
2283
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2109
2284
|
});
|
|
2110
2285
|
mockConnector.agentName = "test-agent";
|
|
@@ -2158,7 +2333,12 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
2158
2333
|
reconnectAttempts: 0,
|
|
2159
2334
|
lastError: null,
|
|
2160
2335
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2161
|
-
rateLimits: {
|
|
2336
|
+
rateLimits: {
|
|
2337
|
+
totalCount: 0,
|
|
2338
|
+
lastRateLimitAt: null,
|
|
2339
|
+
isRateLimited: false,
|
|
2340
|
+
currentResetTime: 0,
|
|
2341
|
+
},
|
|
2162
2342
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2163
2343
|
});
|
|
2164
2344
|
mockConnector.agentName = "test-agent";
|
|
@@ -2187,7 +2367,12 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
2187
2367
|
reconnectAttempts: 0,
|
|
2188
2368
|
lastError: null,
|
|
2189
2369
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2190
|
-
rateLimits: {
|
|
2370
|
+
rateLimits: {
|
|
2371
|
+
totalCount: 0,
|
|
2372
|
+
lastRateLimitAt: null,
|
|
2373
|
+
isRateLimited: false,
|
|
2374
|
+
currentResetTime: 0,
|
|
2375
|
+
},
|
|
2191
2376
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2192
2377
|
});
|
|
2193
2378
|
mockConnector.agentName = "test-agent";
|
|
@@ -2216,7 +2401,12 @@ describe.skip("DiscordManager session integration", () => {
|
|
|
2216
2401
|
reconnectAttempts: 0,
|
|
2217
2402
|
lastError: null,
|
|
2218
2403
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2219
|
-
rateLimits: {
|
|
2404
|
+
rateLimits: {
|
|
2405
|
+
totalCount: 0,
|
|
2406
|
+
lastRateLimitAt: null,
|
|
2407
|
+
isRateLimited: false,
|
|
2408
|
+
currentResetTime: 0,
|
|
2409
|
+
},
|
|
2220
2410
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2221
2411
|
});
|
|
2222
2412
|
mockConnector.agentName = "test-agent";
|
|
@@ -2248,7 +2438,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2248
2438
|
reconnectAttempts: 0,
|
|
2249
2439
|
lastError: "Connection failed",
|
|
2250
2440
|
botUser: null,
|
|
2251
|
-
rateLimits: {
|
|
2441
|
+
rateLimits: {
|
|
2442
|
+
totalCount: 0,
|
|
2443
|
+
lastRateLimitAt: null,
|
|
2444
|
+
isRateLimited: false,
|
|
2445
|
+
currentResetTime: 0,
|
|
2446
|
+
},
|
|
2252
2447
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2253
2448
|
});
|
|
2254
2449
|
mockConnector.agentName = "test-agent";
|
|
@@ -2278,7 +2473,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2278
2473
|
reconnectAttempts: 0,
|
|
2279
2474
|
lastError: null,
|
|
2280
2475
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2281
|
-
rateLimits: {
|
|
2476
|
+
rateLimits: {
|
|
2477
|
+
totalCount: 0,
|
|
2478
|
+
lastRateLimitAt: null,
|
|
2479
|
+
isRateLimited: false,
|
|
2480
|
+
currentResetTime: 0,
|
|
2481
|
+
},
|
|
2282
2482
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2283
2483
|
});
|
|
2284
2484
|
mockConnector.agentName = "test-agent";
|
|
@@ -2308,7 +2508,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2308
2508
|
reconnectAttempts: 0,
|
|
2309
2509
|
lastError: null,
|
|
2310
2510
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2311
|
-
rateLimits: {
|
|
2511
|
+
rateLimits: {
|
|
2512
|
+
totalCount: 0,
|
|
2513
|
+
lastRateLimitAt: null,
|
|
2514
|
+
isRateLimited: false,
|
|
2515
|
+
currentResetTime: 0,
|
|
2516
|
+
},
|
|
2312
2517
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2313
2518
|
});
|
|
2314
2519
|
connectedConnector.agentName = "connected-agent";
|
|
@@ -2326,7 +2531,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2326
2531
|
reconnectAttempts: 0,
|
|
2327
2532
|
lastError: "Failed",
|
|
2328
2533
|
botUser: null,
|
|
2329
|
-
rateLimits: {
|
|
2534
|
+
rateLimits: {
|
|
2535
|
+
totalCount: 0,
|
|
2536
|
+
lastRateLimitAt: null,
|
|
2537
|
+
isRateLimited: false,
|
|
2538
|
+
currentResetTime: 0,
|
|
2539
|
+
},
|
|
2330
2540
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2331
2541
|
});
|
|
2332
2542
|
disconnectedConnector.agentName = "disconnected-agent";
|
|
@@ -2364,7 +2574,13 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2364
2574
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
2365
2575
|
session_expiry_hours: 24,
|
|
2366
2576
|
log_level: "standard",
|
|
2367
|
-
output: {
|
|
2577
|
+
output: {
|
|
2578
|
+
tool_results: true,
|
|
2579
|
+
tool_result_max_length: 900,
|
|
2580
|
+
system_status: true,
|
|
2581
|
+
result_summary: false,
|
|
2582
|
+
errors: true,
|
|
2583
|
+
},
|
|
2368
2584
|
guilds: [],
|
|
2369
2585
|
}),
|
|
2370
2586
|
],
|
|
@@ -2385,7 +2601,13 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2385
2601
|
getCheckInterval: () => 1000,
|
|
2386
2602
|
emit: (event, ...args) => emitterWithTrigger.emit(event, ...args),
|
|
2387
2603
|
getEmitter: () => emitterWithTrigger,
|
|
2388
|
-
trigger: vi.fn().mockResolvedValue({
|
|
2604
|
+
trigger: vi.fn().mockResolvedValue({
|
|
2605
|
+
jobId: "test-job",
|
|
2606
|
+
agentName: "test",
|
|
2607
|
+
scheduleName: null,
|
|
2608
|
+
startedAt: new Date().toISOString(),
|
|
2609
|
+
success: true,
|
|
2610
|
+
}),
|
|
2389
2611
|
};
|
|
2390
2612
|
const manager = new DiscordManager(mockContext);
|
|
2391
2613
|
const mockConnector = new EventEmitter();
|
|
@@ -2399,7 +2621,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2399
2621
|
reconnectAttempts: 0,
|
|
2400
2622
|
lastError: null,
|
|
2401
2623
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2402
|
-
rateLimits: {
|
|
2624
|
+
rateLimits: {
|
|
2625
|
+
totalCount: 0,
|
|
2626
|
+
lastRateLimitAt: null,
|
|
2627
|
+
isRateLimited: false,
|
|
2628
|
+
currentResetTime: 0,
|
|
2629
|
+
},
|
|
2403
2630
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2404
2631
|
});
|
|
2405
2632
|
mockConnector.agentName = "test-agent";
|
|
@@ -2467,7 +2694,13 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2467
2694
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
2468
2695
|
session_expiry_hours: 24,
|
|
2469
2696
|
log_level: "standard",
|
|
2470
|
-
output: {
|
|
2697
|
+
output: {
|
|
2698
|
+
tool_results: true,
|
|
2699
|
+
tool_result_max_length: 900,
|
|
2700
|
+
system_status: true,
|
|
2701
|
+
result_summary: false,
|
|
2702
|
+
errors: true,
|
|
2703
|
+
},
|
|
2471
2704
|
guilds: [],
|
|
2472
2705
|
}),
|
|
2473
2706
|
],
|
|
@@ -2488,7 +2721,13 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2488
2721
|
getCheckInterval: () => 1000,
|
|
2489
2722
|
emit: (event, ...args) => emitterWithTrigger.emit(event, ...args),
|
|
2490
2723
|
getEmitter: () => emitterWithTrigger,
|
|
2491
|
-
trigger: vi.fn().mockResolvedValue({
|
|
2724
|
+
trigger: vi.fn().mockResolvedValue({
|
|
2725
|
+
jobId: "test-job",
|
|
2726
|
+
agentName: "test",
|
|
2727
|
+
scheduleName: null,
|
|
2728
|
+
startedAt: new Date().toISOString(),
|
|
2729
|
+
success: true,
|
|
2730
|
+
}),
|
|
2492
2731
|
};
|
|
2493
2732
|
const manager = new DiscordManager(mockContext);
|
|
2494
2733
|
const mockConnector = new EventEmitter();
|
|
@@ -2502,7 +2741,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2502
2741
|
reconnectAttempts: 0,
|
|
2503
2742
|
lastError: null,
|
|
2504
2743
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2505
|
-
rateLimits: {
|
|
2744
|
+
rateLimits: {
|
|
2745
|
+
totalCount: 0,
|
|
2746
|
+
lastRateLimitAt: null,
|
|
2747
|
+
isRateLimited: false,
|
|
2748
|
+
currentResetTime: 0,
|
|
2749
|
+
},
|
|
2506
2750
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2507
2751
|
});
|
|
2508
2752
|
mockConnector.agentName = "test-agent";
|
|
@@ -2573,7 +2817,13 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2573
2817
|
getCheckInterval: () => 1000,
|
|
2574
2818
|
emit: (event, ...args) => eventEmitter.emit(event, ...args),
|
|
2575
2819
|
getEmitter: () => eventEmitter,
|
|
2576
|
-
trigger: vi.fn().mockResolvedValue({
|
|
2820
|
+
trigger: vi.fn().mockResolvedValue({
|
|
2821
|
+
jobId: "test-job",
|
|
2822
|
+
agentName: "test",
|
|
2823
|
+
scheduleName: null,
|
|
2824
|
+
startedAt: new Date().toISOString(),
|
|
2825
|
+
success: true,
|
|
2826
|
+
}),
|
|
2577
2827
|
};
|
|
2578
2828
|
const manager = new DiscordManager(mockContext);
|
|
2579
2829
|
const mockConnector = new EventEmitter();
|
|
@@ -2587,7 +2837,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2587
2837
|
reconnectAttempts: 0,
|
|
2588
2838
|
lastError: null,
|
|
2589
2839
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2590
|
-
rateLimits: {
|
|
2840
|
+
rateLimits: {
|
|
2841
|
+
totalCount: 0,
|
|
2842
|
+
lastRateLimitAt: null,
|
|
2843
|
+
isRateLimited: false,
|
|
2844
|
+
currentResetTime: 0,
|
|
2845
|
+
},
|
|
2591
2846
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2592
2847
|
});
|
|
2593
2848
|
mockConnector.agentName = "test-agent";
|
|
@@ -2636,7 +2891,13 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2636
2891
|
getCheckInterval: () => 1000,
|
|
2637
2892
|
emit: () => true,
|
|
2638
2893
|
getEmitter: () => new EventEmitter(),
|
|
2639
|
-
trigger: vi.fn().mockResolvedValue({
|
|
2894
|
+
trigger: vi.fn().mockResolvedValue({
|
|
2895
|
+
jobId: "test-job",
|
|
2896
|
+
agentName: "test",
|
|
2897
|
+
scheduleName: null,
|
|
2898
|
+
startedAt: new Date().toISOString(),
|
|
2899
|
+
success: true,
|
|
2900
|
+
}),
|
|
2640
2901
|
};
|
|
2641
2902
|
const manager = new DiscordManager(mockContext);
|
|
2642
2903
|
const mockConnector = new EventEmitter();
|
|
@@ -2650,7 +2911,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2650
2911
|
reconnectAttempts: 0,
|
|
2651
2912
|
lastError: null,
|
|
2652
2913
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2653
|
-
rateLimits: {
|
|
2914
|
+
rateLimits: {
|
|
2915
|
+
totalCount: 0,
|
|
2916
|
+
lastRateLimitAt: null,
|
|
2917
|
+
isRateLimited: false,
|
|
2918
|
+
currentResetTime: 0,
|
|
2919
|
+
},
|
|
2654
2920
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2655
2921
|
});
|
|
2656
2922
|
mockConnector.agentName = "unknown-agent";
|
|
@@ -2714,7 +2980,13 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2714
2980
|
bot_token_env: "TEST_BOT_TOKEN",
|
|
2715
2981
|
session_expiry_hours: 24,
|
|
2716
2982
|
log_level: "standard",
|
|
2717
|
-
output: {
|
|
2983
|
+
output: {
|
|
2984
|
+
tool_results: true,
|
|
2985
|
+
tool_result_max_length: 900,
|
|
2986
|
+
system_status: true,
|
|
2987
|
+
result_summary: false,
|
|
2988
|
+
errors: true,
|
|
2989
|
+
},
|
|
2718
2990
|
guilds: [],
|
|
2719
2991
|
}),
|
|
2720
2992
|
],
|
|
@@ -2735,7 +3007,13 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2735
3007
|
getCheckInterval: () => 1000,
|
|
2736
3008
|
emit: (event, ...args) => emitterWithTrigger.emit(event, ...args),
|
|
2737
3009
|
getEmitter: () => emitterWithTrigger,
|
|
2738
|
-
trigger: vi.fn().mockResolvedValue({
|
|
3010
|
+
trigger: vi.fn().mockResolvedValue({
|
|
3011
|
+
jobId: "test-job",
|
|
3012
|
+
agentName: "test",
|
|
3013
|
+
scheduleName: null,
|
|
3014
|
+
startedAt: new Date().toISOString(),
|
|
3015
|
+
success: true,
|
|
3016
|
+
}),
|
|
2739
3017
|
};
|
|
2740
3018
|
const manager = new DiscordManager(mockContext);
|
|
2741
3019
|
const mockConnector = new EventEmitter();
|
|
@@ -2749,7 +3027,12 @@ describe.skip("DiscordManager lifecycle", () => {
|
|
|
2749
3027
|
reconnectAttempts: 0,
|
|
2750
3028
|
lastError: null,
|
|
2751
3029
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2752
|
-
rateLimits: {
|
|
3030
|
+
rateLimits: {
|
|
3031
|
+
totalCount: 0,
|
|
3032
|
+
lastRateLimitAt: null,
|
|
3033
|
+
isRateLimited: false,
|
|
3034
|
+
currentResetTime: 0,
|
|
3035
|
+
},
|
|
2753
3036
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2754
3037
|
});
|
|
2755
3038
|
mockConnector.agentName = "test-agent";
|
|
@@ -2803,7 +3086,9 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
2803
3086
|
vi.restoreAllMocks();
|
|
2804
3087
|
});
|
|
2805
3088
|
it("does not send tool result embeds when tool_results is disabled", async () => {
|
|
2806
|
-
const customTriggerMock = vi
|
|
3089
|
+
const customTriggerMock = vi
|
|
3090
|
+
.fn()
|
|
3091
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
2807
3092
|
if (options?.onMessage) {
|
|
2808
3093
|
// Claude decides to use Bash tool
|
|
2809
3094
|
await options.onMessage({
|
|
@@ -2883,7 +3168,13 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
2883
3168
|
getCheckInterval: () => 1000,
|
|
2884
3169
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
2885
3170
|
getEmitter: () => streamingEmitter,
|
|
2886
|
-
trigger: vi.fn().mockResolvedValue({
|
|
3171
|
+
trigger: vi.fn().mockResolvedValue({
|
|
3172
|
+
jobId: "test-job",
|
|
3173
|
+
agentName: "test",
|
|
3174
|
+
scheduleName: null,
|
|
3175
|
+
startedAt: new Date().toISOString(),
|
|
3176
|
+
success: true,
|
|
3177
|
+
}),
|
|
2887
3178
|
};
|
|
2888
3179
|
const manager = new DiscordManager(mockContext);
|
|
2889
3180
|
const mockConnector = new EventEmitter();
|
|
@@ -2897,7 +3188,12 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
2897
3188
|
reconnectAttempts: 0,
|
|
2898
3189
|
lastError: null,
|
|
2899
3190
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
2900
|
-
rateLimits: {
|
|
3191
|
+
rateLimits: {
|
|
3192
|
+
totalCount: 0,
|
|
3193
|
+
lastRateLimitAt: null,
|
|
3194
|
+
isRateLimited: false,
|
|
3195
|
+
currentResetTime: 0,
|
|
3196
|
+
},
|
|
2901
3197
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
2902
3198
|
});
|
|
2903
3199
|
mockConnector.agentName = "no-tool-results-agent";
|
|
@@ -2943,7 +3239,9 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
2943
3239
|
expect(embedCalls.length).toBe(0);
|
|
2944
3240
|
}, 10000);
|
|
2945
3241
|
it("sends system status embed when system_status is enabled", async () => {
|
|
2946
|
-
const customTriggerMock = vi
|
|
3242
|
+
const customTriggerMock = vi
|
|
3243
|
+
.fn()
|
|
3244
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
2947
3245
|
if (options?.onMessage) {
|
|
2948
3246
|
// Send a system status message
|
|
2949
3247
|
await options.onMessage({
|
|
@@ -3002,7 +3300,13 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3002
3300
|
getCheckInterval: () => 1000,
|
|
3003
3301
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
3004
3302
|
getEmitter: () => streamingEmitter,
|
|
3005
|
-
trigger: vi.fn().mockResolvedValue({
|
|
3303
|
+
trigger: vi.fn().mockResolvedValue({
|
|
3304
|
+
jobId: "test-job",
|
|
3305
|
+
agentName: "test",
|
|
3306
|
+
scheduleName: null,
|
|
3307
|
+
startedAt: new Date().toISOString(),
|
|
3308
|
+
success: true,
|
|
3309
|
+
}),
|
|
3006
3310
|
};
|
|
3007
3311
|
const manager = new DiscordManager(mockContext);
|
|
3008
3312
|
const mockConnector = new EventEmitter();
|
|
@@ -3016,7 +3320,12 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3016
3320
|
reconnectAttempts: 0,
|
|
3017
3321
|
lastError: null,
|
|
3018
3322
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
3019
|
-
rateLimits: {
|
|
3323
|
+
rateLimits: {
|
|
3324
|
+
totalCount: 0,
|
|
3325
|
+
lastRateLimitAt: null,
|
|
3326
|
+
isRateLimited: false,
|
|
3327
|
+
currentResetTime: 0,
|
|
3328
|
+
},
|
|
3020
3329
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
3021
3330
|
});
|
|
3022
3331
|
mockConnector.agentName = "system-status-agent";
|
|
@@ -3062,7 +3371,9 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3062
3371
|
expect(embed.description).toContain("Compacting context");
|
|
3063
3372
|
}, 10000);
|
|
3064
3373
|
it("does not send system status embed when system_status is disabled", async () => {
|
|
3065
|
-
const customTriggerMock = vi
|
|
3374
|
+
const customTriggerMock = vi
|
|
3375
|
+
.fn()
|
|
3376
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
3066
3377
|
if (options?.onMessage) {
|
|
3067
3378
|
await options.onMessage({
|
|
3068
3379
|
type: "system",
|
|
@@ -3120,7 +3431,13 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3120
3431
|
getCheckInterval: () => 1000,
|
|
3121
3432
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
3122
3433
|
getEmitter: () => streamingEmitter,
|
|
3123
|
-
trigger: vi.fn().mockResolvedValue({
|
|
3434
|
+
trigger: vi.fn().mockResolvedValue({
|
|
3435
|
+
jobId: "test-job",
|
|
3436
|
+
agentName: "test",
|
|
3437
|
+
scheduleName: null,
|
|
3438
|
+
startedAt: new Date().toISOString(),
|
|
3439
|
+
success: true,
|
|
3440
|
+
}),
|
|
3124
3441
|
};
|
|
3125
3442
|
const manager = new DiscordManager(mockContext);
|
|
3126
3443
|
const mockConnector = new EventEmitter();
|
|
@@ -3134,7 +3451,12 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3134
3451
|
reconnectAttempts: 0,
|
|
3135
3452
|
lastError: null,
|
|
3136
3453
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
3137
|
-
rateLimits: {
|
|
3454
|
+
rateLimits: {
|
|
3455
|
+
totalCount: 0,
|
|
3456
|
+
lastRateLimitAt: null,
|
|
3457
|
+
isRateLimited: false,
|
|
3458
|
+
currentResetTime: 0,
|
|
3459
|
+
},
|
|
3138
3460
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
3139
3461
|
});
|
|
3140
3462
|
mockConnector.agentName = "no-system-status-agent";
|
|
@@ -3177,7 +3499,9 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3177
3499
|
expect(embedCalls.length).toBe(0);
|
|
3178
3500
|
}, 10000);
|
|
3179
3501
|
it("sends result summary embed when result_summary is enabled", async () => {
|
|
3180
|
-
const customTriggerMock = vi
|
|
3502
|
+
const customTriggerMock = vi
|
|
3503
|
+
.fn()
|
|
3504
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
3181
3505
|
if (options?.onMessage) {
|
|
3182
3506
|
await options.onMessage({
|
|
3183
3507
|
type: "result",
|
|
@@ -3239,7 +3563,13 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3239
3563
|
getCheckInterval: () => 1000,
|
|
3240
3564
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
3241
3565
|
getEmitter: () => streamingEmitter,
|
|
3242
|
-
trigger: vi.fn().mockResolvedValue({
|
|
3566
|
+
trigger: vi.fn().mockResolvedValue({
|
|
3567
|
+
jobId: "test-job",
|
|
3568
|
+
agentName: "test",
|
|
3569
|
+
scheduleName: null,
|
|
3570
|
+
startedAt: new Date().toISOString(),
|
|
3571
|
+
success: true,
|
|
3572
|
+
}),
|
|
3243
3573
|
};
|
|
3244
3574
|
const manager = new DiscordManager(mockContext);
|
|
3245
3575
|
const mockConnector = new EventEmitter();
|
|
@@ -3253,7 +3583,12 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3253
3583
|
reconnectAttempts: 0,
|
|
3254
3584
|
lastError: null,
|
|
3255
3585
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
3256
|
-
rateLimits: {
|
|
3586
|
+
rateLimits: {
|
|
3587
|
+
totalCount: 0,
|
|
3588
|
+
lastRateLimitAt: null,
|
|
3589
|
+
isRateLimited: false,
|
|
3590
|
+
currentResetTime: 0,
|
|
3591
|
+
},
|
|
3257
3592
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
3258
3593
|
});
|
|
3259
3594
|
mockConnector.agentName = "result-summary-agent";
|
|
@@ -3304,7 +3639,9 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3304
3639
|
expect(fieldNames).toContain("Tokens");
|
|
3305
3640
|
}, 10000);
|
|
3306
3641
|
it("sends error embed for SDK error messages", async () => {
|
|
3307
|
-
const customTriggerMock = vi
|
|
3642
|
+
const customTriggerMock = vi
|
|
3643
|
+
.fn()
|
|
3644
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
3308
3645
|
if (options?.onMessage) {
|
|
3309
3646
|
await options.onMessage({
|
|
3310
3647
|
type: "error",
|
|
@@ -3361,7 +3698,13 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3361
3698
|
getCheckInterval: () => 1000,
|
|
3362
3699
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
3363
3700
|
getEmitter: () => streamingEmitter,
|
|
3364
|
-
trigger: vi.fn().mockResolvedValue({
|
|
3701
|
+
trigger: vi.fn().mockResolvedValue({
|
|
3702
|
+
jobId: "test-job",
|
|
3703
|
+
agentName: "test",
|
|
3704
|
+
scheduleName: null,
|
|
3705
|
+
startedAt: new Date().toISOString(),
|
|
3706
|
+
success: true,
|
|
3707
|
+
}),
|
|
3365
3708
|
};
|
|
3366
3709
|
const manager = new DiscordManager(mockContext);
|
|
3367
3710
|
const mockConnector = new EventEmitter();
|
|
@@ -3375,7 +3718,12 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3375
3718
|
reconnectAttempts: 0,
|
|
3376
3719
|
lastError: null,
|
|
3377
3720
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
3378
|
-
rateLimits: {
|
|
3721
|
+
rateLimits: {
|
|
3722
|
+
totalCount: 0,
|
|
3723
|
+
lastRateLimitAt: null,
|
|
3724
|
+
isRateLimited: false,
|
|
3725
|
+
currentResetTime: 0,
|
|
3726
|
+
},
|
|
3379
3727
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
3380
3728
|
});
|
|
3381
3729
|
mockConnector.agentName = "error-agent";
|
|
@@ -3421,7 +3769,9 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3421
3769
|
expect(embed.description).toBe("Something went wrong");
|
|
3422
3770
|
}, 10000);
|
|
3423
3771
|
it("does not send error embed when errors is disabled", async () => {
|
|
3424
|
-
const customTriggerMock = vi
|
|
3772
|
+
const customTriggerMock = vi
|
|
3773
|
+
.fn()
|
|
3774
|
+
.mockImplementation(async (_agentName, _scheduleName, options) => {
|
|
3425
3775
|
if (options?.onMessage) {
|
|
3426
3776
|
await options.onMessage({
|
|
3427
3777
|
type: "error",
|
|
@@ -3478,7 +3828,13 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3478
3828
|
getCheckInterval: () => 1000,
|
|
3479
3829
|
emit: (event, ...args) => streamingEmitter.emit(event, ...args),
|
|
3480
3830
|
getEmitter: () => streamingEmitter,
|
|
3481
|
-
trigger: vi.fn().mockResolvedValue({
|
|
3831
|
+
trigger: vi.fn().mockResolvedValue({
|
|
3832
|
+
jobId: "test-job",
|
|
3833
|
+
agentName: "test",
|
|
3834
|
+
scheduleName: null,
|
|
3835
|
+
startedAt: new Date().toISOString(),
|
|
3836
|
+
success: true,
|
|
3837
|
+
}),
|
|
3482
3838
|
};
|
|
3483
3839
|
const manager = new DiscordManager(mockContext);
|
|
3484
3840
|
const mockConnector = new EventEmitter();
|
|
@@ -3492,7 +3848,12 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3492
3848
|
reconnectAttempts: 0,
|
|
3493
3849
|
lastError: null,
|
|
3494
3850
|
botUser: { id: "bot1", username: "TestBot", discriminator: "0000" },
|
|
3495
|
-
rateLimits: {
|
|
3851
|
+
rateLimits: {
|
|
3852
|
+
totalCount: 0,
|
|
3853
|
+
lastRateLimitAt: null,
|
|
3854
|
+
isRateLimited: false,
|
|
3855
|
+
currentResetTime: 0,
|
|
3856
|
+
},
|
|
3496
3857
|
messageStats: { received: 0, sent: 0, ignored: 0 },
|
|
3497
3858
|
});
|
|
3498
3859
|
mockConnector.agentName = "no-errors-agent";
|
|
@@ -3541,8 +3902,7 @@ describe.skip("DiscordManager output configuration", () => {
|
|
|
3541
3902
|
// Long output that exceeds both custom and default limits
|
|
3542
3903
|
const longOutput = "x".repeat(600);
|
|
3543
3904
|
// @ts-expect-error - accessing private method for testing
|
|
3544
|
-
const embed = manager.buildToolEmbed({ name: "Bash", input: { command: "cat bigfile" }, startTime: Date.now() - 100 }, { output: longOutput, isError: false }, 400
|
|
3545
|
-
);
|
|
3905
|
+
const embed = manager.buildToolEmbed({ name: "Bash", input: { command: "cat bigfile" }, startTime: Date.now() - 100 }, { output: longOutput, isError: false }, 400);
|
|
3546
3906
|
const resultField = embed.fields.find((f) => f.name === "Result");
|
|
3547
3907
|
expect(resultField).toBeDefined();
|
|
3548
3908
|
// The result should be truncated, showing "chars total" suffix
|