Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/slack/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ let cachedBotId: string | null = null;
const swarmThreadRootCache = new Map<string, boolean>();
const SWARM_THREAD_ROOT_CACHE_MAX = 1000;

/** Reset Slack handler caches between tests that exercise production handlers. */
export function resetSlackHandlerCachesForTesting(): void {
cachedBotUserId = null;
cachedBotId = null;
swarmThreadRootCache.clear();
}

/**
* Pure check: does the given thread-root message belong to our own swarm bot?
* Exported for testing.
Expand Down
35 changes: 20 additions & 15 deletions src/tests/artifact-sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
} from "../artifact-sdk/server";
import { getBasePrompt } from "../prompts/base-prompt";

function restoreEnvValue(key: string, value: string | undefined): void {
if (value === undefined) delete process.env[key];
else process.env[key] = value;
}

// ─── Port allocation tests ──────────────────────────────────────────────

describe("getAvailablePort", () => {
Expand Down Expand Up @@ -132,9 +137,9 @@ describe("createArtifactServer", () => {
});

afterAll(() => {
process.env.AGENT_ID = originalEnv.AGENT_ID;
process.env.API_KEY = originalEnv.API_KEY;
process.env.MCP_BASE_URL = originalEnv.MCP_BASE_URL;
restoreEnvValue("AGENT_ID", originalEnv.AGENT_ID);
restoreEnvValue("API_KEY", originalEnv.API_KEY);
restoreEnvValue("MCP_BASE_URL", originalEnv.MCP_BASE_URL);
});

describe("factory return shape", () => {
Expand Down Expand Up @@ -596,9 +601,9 @@ describe("artifact CLI command", () => {
expect(output).toContain("https://test.lt.example.com");
} finally {
console.log = origLog;
process.env.MCP_BASE_URL = origEnv.MCP_BASE_URL;
process.env.API_KEY = origEnv.API_KEY;
process.env.AGENT_ID = origEnv.AGENT_ID;
restoreEnvValue("MCP_BASE_URL", origEnv.MCP_BASE_URL);
restoreEnvValue("API_KEY", origEnv.API_KEY);
restoreEnvValue("AGENT_ID", origEnv.AGENT_ID);
mockServer.stop();
}
});
Expand Down Expand Up @@ -627,9 +632,9 @@ describe("artifact CLI command", () => {
expect(output).toContain("No active artifacts");
} finally {
console.log = origLog;
process.env.MCP_BASE_URL = origEnv.MCP_BASE_URL;
process.env.API_KEY = origEnv.API_KEY;
process.env.AGENT_ID = origEnv.AGENT_ID;
restoreEnvValue("MCP_BASE_URL", origEnv.MCP_BASE_URL);
restoreEnvValue("API_KEY", origEnv.API_KEY);
restoreEnvValue("AGENT_ID", origEnv.AGENT_ID);
mockServer.stop();
}
});
Expand Down Expand Up @@ -679,9 +684,9 @@ describe("artifact CLI command", () => {
expect(output).toContain("No active artifacts");
} finally {
console.log = origLog;
process.env.MCP_BASE_URL = origEnv.MCP_BASE_URL;
process.env.API_KEY = origEnv.API_KEY;
process.env.AGENT_ID = origEnv.AGENT_ID;
restoreEnvValue("MCP_BASE_URL", origEnv.MCP_BASE_URL);
restoreEnvValue("API_KEY", origEnv.API_KEY);
restoreEnvValue("AGENT_ID", origEnv.AGENT_ID);
mockServer.stop();
}
});
Expand Down Expand Up @@ -736,9 +741,9 @@ describe("artifact CLI command", () => {
expect(output).toContain("stopped");
} finally {
console.log = origLog;
process.env.MCP_BASE_URL = origEnv.MCP_BASE_URL;
process.env.API_KEY = origEnv.API_KEY;
process.env.AGENT_ID = origEnv.AGENT_ID;
restoreEnvValue("MCP_BASE_URL", origEnv.MCP_BASE_URL);
restoreEnvValue("API_KEY", origEnv.API_KEY);
restoreEnvValue("AGENT_ID", origEnv.AGENT_ID);
mockServer.stop();
}
});
Expand Down
8 changes: 7 additions & 1 deletion src/tests/slack-assistant-comention-production.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ process.env.SLACK_RENDER_V2 = "false";

let createAssistantFn: typeof import("../slack/assistant").createAssistant;
let registerMessageHandlerFn: typeof import("../slack/handlers").registerMessageHandler;
let resetSlackHandlerCachesForTestingFn: typeof import("../slack/handlers").resetSlackHandlerCachesForTesting;

let createTaskWithSiblingAwarenessSpy: any;
let getAllAgentsSpy: any;
Expand Down Expand Up @@ -98,7 +99,11 @@ beforeAll(async () => {
installSpyImplementations();

({ createAssistant: createAssistantFn } = await import("../slack/assistant"));
({ registerMessageHandler: registerMessageHandlerFn } = await import("../slack/handlers"));
({
registerMessageHandler: registerMessageHandlerFn,
resetSlackHandlerCachesForTesting: resetSlackHandlerCachesForTestingFn,
} = await import("../slack/handlers"));
resetSlackHandlerCachesForTestingFn();
});

beforeEach(() => {
Expand All @@ -120,6 +125,7 @@ afterAll(() => {
restoreEnvValue("SLACK_ALLOWED_EMAIL_DOMAINS");
restoreEnvValue("SLACK_ALLOWED_USER_IDS");
mock.restore();
resetSlackHandlerCachesForTestingFn();
});

// ---------------------------------------------------------------------------
Expand Down