@stackmemoryai/stackmemory 0.2.7 → 0.2.8
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/README.md +25 -8
- package/dist/scripts/cancel-duplicate-tasks.js +2 -1
- package/dist/scripts/cancel-duplicate-tasks.js.map +1 -1
- package/dist/scripts/list-linear-tasks.js +3 -4
- package/dist/scripts/list-linear-tasks.js.map +1 -1
- package/dist/scripts/merge-linear-duplicates-safe.js +4 -2
- package/dist/scripts/merge-linear-duplicates-safe.js.map +1 -1
- package/dist/scripts/show-linear-summary.js +4 -1
- package/dist/scripts/show-linear-summary.js.map +1 -1
- package/dist/scripts/status.js +6 -2
- package/dist/scripts/status.js.map +1 -1
- package/dist/src/cli/auto-detect.js.map +1 -1
- package/dist/src/cli/claude-sm.js.map +1 -1
- package/dist/src/cli/commands/config.d.ts +6 -0
- package/dist/src/cli/commands/config.d.ts.map +1 -0
- package/dist/src/cli/commands/config.js +224 -0
- package/dist/src/cli/commands/config.js.map +1 -0
- package/dist/src/cli/commands/linear.d.ts.map +1 -1
- package/dist/src/cli/commands/linear.js +123 -47
- package/dist/src/cli/commands/linear.js.map +1 -1
- package/dist/src/cli/index.d.ts.map +1 -1
- package/dist/src/cli/index.js +48 -1
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/core/config/config-manager.d.ts +95 -0
- package/dist/src/core/config/config-manager.d.ts.map +1 -0
- package/dist/src/core/config/config-manager.js +359 -0
- package/dist/src/core/config/config-manager.js.map +1 -0
- package/dist/src/core/config/types.d.ts +72 -0
- package/dist/src/core/config/types.d.ts.map +1 -0
- package/dist/src/core/config/types.js +127 -0
- package/dist/src/core/config/types.js.map +1 -0
- package/dist/src/core/context/compaction-handler.d.ts +119 -0
- package/dist/src/core/context/compaction-handler.d.ts.map +1 -0
- package/dist/src/core/context/compaction-handler.js +306 -0
- package/dist/src/core/context/compaction-handler.js.map +1 -0
- package/dist/src/core/context/model-aware-compaction.d.ts +101 -0
- package/dist/src/core/context/model-aware-compaction.d.ts.map +1 -0
- package/dist/src/core/context/model-aware-compaction.js +616 -0
- package/dist/src/core/context/model-aware-compaction.js.map +1 -0
- package/dist/src/core/query/query-parser.d.ts +104 -0
- package/dist/src/core/query/query-parser.d.ts.map +1 -0
- package/dist/src/core/query/query-parser.js +347 -0
- package/dist/src/core/query/query-parser.js.map +1 -0
- package/dist/src/core/retrieval/index.d.ts +8 -0
- package/dist/src/core/retrieval/index.d.ts.map +1 -0
- package/dist/src/core/retrieval/index.js +8 -0
- package/dist/src/core/retrieval/index.js.map +1 -0
- package/dist/src/core/retrieval/llm-context-retrieval.d.ts +71 -0
- package/dist/src/core/retrieval/llm-context-retrieval.d.ts.map +1 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js +545 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js.map +1 -0
- package/dist/src/core/retrieval/summary-generator.d.ts +63 -0
- package/dist/src/core/retrieval/summary-generator.d.ts.map +1 -0
- package/dist/src/core/retrieval/summary-generator.js +622 -0
- package/dist/src/core/retrieval/summary-generator.js.map +1 -0
- package/dist/src/core/retrieval/types.d.ts +257 -0
- package/dist/src/core/retrieval/types.d.ts.map +1 -0
- package/dist/src/core/retrieval/types.js +18 -0
- package/dist/src/core/retrieval/types.js.map +1 -0
- package/dist/src/core/trace/trace-detector.d.ts +108 -0
- package/dist/src/core/trace/trace-detector.d.ts.map +1 -0
- package/dist/src/core/trace/trace-detector.demo.d.ts +5 -0
- package/dist/src/core/trace/trace-detector.demo.d.ts.map +1 -0
- package/dist/src/core/trace/trace-detector.demo.js +145 -0
- package/dist/src/core/trace/trace-detector.demo.js.map +1 -0
- package/dist/src/core/trace/trace-detector.js +425 -0
- package/dist/src/core/trace/trace-detector.js.map +1 -0
- package/dist/src/core/trace/trace-store.d.ts +60 -0
- package/dist/src/core/trace/trace-store.d.ts.map +1 -0
- package/dist/src/core/trace/trace-store.js +323 -0
- package/dist/src/core/trace/trace-store.js.map +1 -0
- package/dist/src/core/trace/types.d.ts +81 -0
- package/dist/src/core/trace/types.d.ts.map +1 -0
- package/dist/src/core/trace/types.js +70 -0
- package/dist/src/core/trace/types.js.map +1 -0
- package/dist/src/integrations/linear/sync-manager.d.ts +76 -0
- package/dist/src/integrations/linear/sync-manager.d.ts.map +1 -0
- package/dist/src/integrations/linear/sync-manager.js +223 -0
- package/dist/src/integrations/linear/sync-manager.js.map +1 -0
- package/dist/src/integrations/mcp/server.d.ts +8 -0
- package/dist/src/integrations/mcp/server.d.ts.map +1 -1
- package/dist/src/integrations/mcp/server.js +368 -16
- package/dist/src/integrations/mcp/server.js.map +1 -1
- package/dist/src/integrations/mcp/trace-test.d.ts +5 -0
- package/dist/src/integrations/mcp/trace-test.d.ts.map +1 -0
- package/dist/src/integrations/mcp/trace-test.js +54 -0
- package/dist/src/integrations/mcp/trace-test.js.map +1 -0
- package/dist/src/services/config-service.d.ts +1 -1
- package/dist/src/services/config-service.d.ts.map +1 -1
- package/dist/src/services/config-service.js.map +1 -1
- package/dist/src/types/task.d.ts +11 -1
- package/dist/src/types/task.d.ts.map +1 -1
- package/dist/src/utils/logger.d.ts +4 -4
- package/dist/src/utils/logger.d.ts.map +1 -1
- package/dist/src/utils/logger.js.map +1 -1
- package/package.json +9 -8
- package/dist/attention-scoring/src/attention-tracker.d.ts +0 -79
- package/dist/attention-scoring/src/attention-tracker.d.ts.map +0 -1
- package/dist/attention-scoring/src/attention-tracker.js +0 -488
- package/dist/attention-scoring/src/attention-tracker.js.map +0 -1
- package/dist/attention-scoring/src/mcp-integration.d.ts +0 -56
- package/dist/attention-scoring/src/mcp-integration.d.ts.map +0 -1
- package/dist/attention-scoring/src/mcp-integration.js +0 -369
- package/dist/attention-scoring/src/mcp-integration.js.map +0 -1
- package/dist/index.js +0 -382
- package/dist/p2p-sync/src/p2p-sync.d.ts +0 -81
- package/dist/p2p-sync/src/p2p-sync.d.ts.map +0 -1
- package/dist/p2p-sync/src/p2p-sync.js +0 -457
- package/dist/p2p-sync/src/p2p-sync.js.map +0 -1
- package/dist/p2p-sync/src/team-context-sync.d.ts +0 -99
- package/dist/p2p-sync/src/team-context-sync.d.ts.map +0 -1
- package/dist/p2p-sync/src/team-context-sync.js +0 -491
- package/dist/p2p-sync/src/team-context-sync.js.map +0 -1
- package/dist/scripts/merge-linear-duplicates.d.ts +0 -7
- package/dist/scripts/merge-linear-duplicates.d.ts.map +0 -1
- package/dist/scripts/merge-linear-duplicates.js +0 -126
- package/dist/scripts/merge-linear-duplicates.js.map +0 -1
- package/dist/src/analytics/api/analytics-api.d.ts +0 -24
- package/dist/src/analytics/api/analytics-api.d.ts.map +0 -1
- package/dist/src/analytics/api/analytics-api.js +0 -279
- package/dist/src/analytics/api/analytics-api.js.map +0 -1
- package/dist/src/analytics/core/analytics-service.d.ts +0 -23
- package/dist/src/analytics/core/analytics-service.d.ts.map +0 -1
- package/dist/src/analytics/core/analytics-service.js +0 -160
- package/dist/src/analytics/core/analytics-service.js.map +0 -1
- package/dist/src/analytics/index.d.ts +0 -12
- package/dist/src/analytics/index.d.ts.map +0 -1
- package/dist/src/analytics/index.js +0 -11
- package/dist/src/analytics/index.js.map +0 -1
- package/dist/src/analytics/queries/metrics-queries.d.ts +0 -11
- package/dist/src/analytics/queries/metrics-queries.d.ts.map +0 -1
- package/dist/src/analytics/queries/metrics-queries.js +0 -179
- package/dist/src/analytics/queries/metrics-queries.js.map +0 -1
- package/dist/src/analytics/types/metrics.d.ts +0 -60
- package/dist/src/analytics/types/metrics.d.ts.map +0 -1
- package/dist/src/analytics/types/metrics.js +0 -2
- package/dist/src/analytics/types/metrics.js.map +0 -1
- package/dist/src/beads/beads-task-store.d.ts +0 -117
- package/dist/src/beads/beads-task-store.d.ts.map +0 -1
- package/dist/src/beads/beads-task-store.js +0 -318
- package/dist/src/beads/beads-task-store.js.map +0 -1
- package/dist/src/beads/task-aware-context.d.ts +0 -103
- package/dist/src/beads/task-aware-context.d.ts.map +0 -1
- package/dist/src/beads/task-aware-context.js +0 -395
- package/dist/src/beads/task-aware-context.js.map +0 -1
- package/dist/src/beads-task-store.d.ts +0 -117
- package/dist/src/beads-task-store.d.ts.map +0 -1
- package/dist/src/beads-task-store.js +0 -318
- package/dist/src/beads-task-store.js.map +0 -1
- package/dist/src/cli/__tests__/index.test.d.ts +0 -5
- package/dist/src/cli/__tests__/index.test.d.ts.map +0 -1
- package/dist/src/cli/__tests__/index.test.js +0 -726
- package/dist/src/cli/__tests__/index.test.js.map +0 -1
- package/dist/src/cli/analytics-viewer.d.ts +0 -3
- package/dist/src/cli/analytics-viewer.d.ts.map +0 -1
- package/dist/src/cli/analytics-viewer.js +0 -89
- package/dist/src/cli/analytics-viewer.js.map +0 -1
- package/dist/src/cli/cli.d.ts +0 -7
- package/dist/src/cli/cli.d.ts.map +0 -1
- package/dist/src/cli/cli.js +0 -704
- package/dist/src/cli/cli.js.map +0 -1
- package/dist/src/cli/project-commands.d.ts +0 -8
- package/dist/src/cli/project-commands.d.ts.map +0 -1
- package/dist/src/cli/project-commands.js +0 -212
- package/dist/src/cli/project-commands.js.map +0 -1
- package/dist/src/cli.d.ts +0 -7
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -73
- package/dist/src/cli.js.map +0 -1
- package/dist/src/core/context/__tests__/frame-manager.test.d.ts +0 -5
- package/dist/src/core/context/__tests__/frame-manager.test.d.ts.map +0 -1
- package/dist/src/core/context/__tests__/frame-manager.test.js +0 -892
- package/dist/src/core/context/__tests__/frame-manager.test.js.map +0 -1
- package/dist/src/core/error-handler.d.ts +0 -46
- package/dist/src/core/error-handler.d.ts.map +0 -1
- package/dist/src/core/error-handler.js +0 -212
- package/dist/src/core/error-handler.js.map +0 -1
- package/dist/src/core/errors/__tests__/error-handling.test.d.ts +0 -5
- package/dist/src/core/errors/__tests__/error-handling.test.d.ts.map +0 -1
- package/dist/src/core/errors/__tests__/error-handling.test.js +0 -239
- package/dist/src/core/errors/__tests__/error-handling.test.js.map +0 -1
- package/dist/src/core/frame-manager.d.ts +0 -106
- package/dist/src/core/frame-manager.d.ts.map +0 -1
- package/dist/src/core/frame-manager.js +0 -387
- package/dist/src/core/frame-manager.js.map +0 -1
- package/dist/src/core/logger.d.ts +0 -24
- package/dist/src/core/logger.d.ts.map +0 -1
- package/dist/src/core/logger.js +0 -121
- package/dist/src/core/logger.js.map +0 -1
- package/dist/src/core/logger.test.d.ts +0 -2
- package/dist/src/core/logger.test.d.ts.map +0 -1
- package/dist/src/core/logger.test.js +0 -31
- package/dist/src/core/logger.test.js.map +0 -1
- package/dist/src/core/progress-tracker.d.ts +0 -95
- package/dist/src/core/progress-tracker.d.ts.map +0 -1
- package/dist/src/core/progress-tracker.js +0 -178
- package/dist/src/core/progress-tracker.js.map +0 -1
- package/dist/src/core/project-manager.d.ts +0 -130
- package/dist/src/core/project-manager.d.ts.map +0 -1
- package/dist/src/core/project-manager.js +0 -582
- package/dist/src/core/project-manager.js.map +0 -1
- package/dist/src/core/update-checker.d.ts +0 -38
- package/dist/src/core/update-checker.d.ts.map +0 -1
- package/dist/src/core/update-checker.js +0 -156
- package/dist/src/core/update-checker.js.map +0 -1
- package/dist/src/error-handler.d.ts +0 -42
- package/dist/src/error-handler.d.ts.map +0 -1
- package/dist/src/error-handler.js +0 -155
- package/dist/src/error-handler.js.map +0 -1
- package/dist/src/features/tasks/__tests__/pebbles-task-store.test.d.ts +0 -5
- package/dist/src/features/tasks/__tests__/pebbles-task-store.test.d.ts.map +0 -1
- package/dist/src/features/tasks/__tests__/pebbles-task-store.test.js +0 -712
- package/dist/src/features/tasks/__tests__/pebbles-task-store.test.js.map +0 -1
- package/dist/src/frame-manager.d.ts +0 -106
- package/dist/src/frame-manager.d.ts.map +0 -1
- package/dist/src/frame-manager.js +0 -361
- package/dist/src/frame-manager.js.map +0 -1
- package/dist/src/integrations/browser-mcp.d.ts +0 -94
- package/dist/src/integrations/browser-mcp.d.ts.map +0 -1
- package/dist/src/integrations/browser-mcp.js +0 -431
- package/dist/src/integrations/browser-mcp.js.map +0 -1
- package/dist/src/integrations/linear/__tests__/auth.test.d.ts +0 -5
- package/dist/src/integrations/linear/__tests__/auth.test.d.ts.map +0 -1
- package/dist/src/integrations/linear/__tests__/auth.test.js +0 -517
- package/dist/src/integrations/linear/__tests__/auth.test.js.map +0 -1
- package/dist/src/integrations/linear/__tests__/sync-service.test.d.ts +0 -5
- package/dist/src/integrations/linear/__tests__/sync-service.test.d.ts.map +0 -1
- package/dist/src/integrations/linear/__tests__/sync-service.test.js +0 -700
- package/dist/src/integrations/linear/__tests__/sync-service.test.js.map +0 -1
- package/dist/src/integrations/linear-auth.d.ts +0 -99
- package/dist/src/integrations/linear-auth.d.ts.map +0 -1
- package/dist/src/integrations/linear-auth.js +0 -319
- package/dist/src/integrations/linear-auth.js.map +0 -1
- package/dist/src/integrations/linear-auto-sync.d.ts +0 -77
- package/dist/src/integrations/linear-auto-sync.d.ts.map +0 -1
- package/dist/src/integrations/linear-auto-sync.js +0 -268
- package/dist/src/integrations/linear-auto-sync.js.map +0 -1
- package/dist/src/integrations/linear-client.d.ts +0 -86
- package/dist/src/integrations/linear-client.d.ts.map +0 -1
- package/dist/src/integrations/linear-client.js +0 -277
- package/dist/src/integrations/linear-client.js.map +0 -1
- package/dist/src/integrations/linear-config.d.ts +0 -51
- package/dist/src/integrations/linear-config.d.ts.map +0 -1
- package/dist/src/integrations/linear-config.js +0 -103
- package/dist/src/integrations/linear-config.js.map +0 -1
- package/dist/src/integrations/linear-sync.d.ts +0 -97
- package/dist/src/integrations/linear-sync.d.ts.map +0 -1
- package/dist/src/integrations/linear-sync.js +0 -391
- package/dist/src/integrations/linear-sync.js.map +0 -1
- package/dist/src/integrations/mcp/__tests__/server.test.d.ts +0 -5
- package/dist/src/integrations/mcp/__tests__/server.test.d.ts.map +0 -1
- package/dist/src/integrations/mcp/__tests__/server.test.js +0 -790
- package/dist/src/integrations/mcp/__tests__/server.test.js.map +0 -1
- package/dist/src/logger.d.ts +0 -24
- package/dist/src/logger.d.ts.map +0 -1
- package/dist/src/logger.js +0 -120
- package/dist/src/logger.js.map +0 -1
- package/dist/src/mcp/mcp-server.d.ts +0 -40
- package/dist/src/mcp/mcp-server.d.ts.map +0 -1
- package/dist/src/mcp/mcp-server.js +0 -828
- package/dist/src/mcp/mcp-server.js.map +0 -1
- package/dist/src/mcp-server.d.ts +0 -32
- package/dist/src/mcp-server.d.ts.map +0 -1
- package/dist/src/mcp-server.js +0 -441
- package/dist/src/mcp-server.js.map +0 -1
- package/dist/src/pebbles/pebbles-task-store.d.ts +0 -117
- package/dist/src/pebbles/pebbles-task-store.d.ts.map +0 -1
- package/dist/src/pebbles/pebbles-task-store.js +0 -335
- package/dist/src/pebbles/pebbles-task-store.js.map +0 -1
- package/dist/src/pebbles/task-aware-context.d.ts +0 -103
- package/dist/src/pebbles/task-aware-context.d.ts.map +0 -1
- package/dist/src/pebbles/task-aware-context.js +0 -412
- package/dist/src/pebbles/task-aware-context.js.map +0 -1
- package/dist/src/railway/index.d.ts +0 -7
- package/dist/src/railway/index.d.ts.map +0 -1
- package/dist/src/railway/index.js +0 -401
- package/dist/src/railway/index.js.map +0 -1
- package/dist/src/runway/auth/auth-middleware.d.ts +0 -66
- package/dist/src/runway/auth/auth-middleware.d.ts.map +0 -1
- package/dist/src/runway/auth/auth-middleware.js +0 -337
- package/dist/src/runway/auth/auth-middleware.js.map +0 -1
- package/dist/src/runway/server/runway-mcp-server.d.ts +0 -46
- package/dist/src/runway/server/runway-mcp-server.d.ts.map +0 -1
- package/dist/src/runway/server/runway-mcp-server.js +0 -601
- package/dist/src/runway/server/runway-mcp-server.js.map +0 -1
- package/dist/src/runway.bak/auth/auth-middleware.d.ts +0 -66
- package/dist/src/runway.bak/auth/auth-middleware.d.ts.map +0 -1
- package/dist/src/runway.bak/auth/auth-middleware.js +0 -337
- package/dist/src/runway.bak/auth/auth-middleware.js.map +0 -1
- package/dist/src/runway.bak/server/runway-mcp-server.d.ts +0 -46
- package/dist/src/runway.bak/server/runway-mcp-server.d.ts.map +0 -1
- package/dist/src/runway.bak/server/runway-mcp-server.js +0 -601
- package/dist/src/runway.bak/server/runway-mcp-server.js.map +0 -1
- package/dist/src/task-aware-context.d.ts +0 -103
- package/dist/src/task-aware-context.d.ts.map +0 -1
- package/dist/src/task-aware-context.js +0 -395
- package/dist/src/task-aware-context.js.map +0 -1
|
@@ -1,790 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for StackMemory MCP Server - Local Instance
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
5
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
6
|
-
import Database from 'better-sqlite3';
|
|
7
|
-
import LocalStackMemoryMCP from '../server.js';
|
|
8
|
-
import { join } from 'path';
|
|
9
|
-
import { mkdtempSync, rmSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
10
|
-
import { tmpdir } from 'os';
|
|
11
|
-
// Mock the MCP SDK
|
|
12
|
-
vi.mock('@modelcontextprotocol/sdk/server/index.js', () => ({
|
|
13
|
-
Server: vi.fn().mockImplementation(() => ({
|
|
14
|
-
setRequestHandler: vi.fn(),
|
|
15
|
-
connect: vi.fn()
|
|
16
|
-
}))
|
|
17
|
-
}));
|
|
18
|
-
vi.mock('@modelcontextprotocol/sdk/server/stdio.js', () => ({
|
|
19
|
-
StdioServerTransport: vi.fn()
|
|
20
|
-
}));
|
|
21
|
-
// Mock child_process
|
|
22
|
-
vi.mock('child_process', () => ({
|
|
23
|
-
execSync: vi.fn(() => Buffer.from('mocked git output'))
|
|
24
|
-
}));
|
|
25
|
-
// Mock browser MCP integration
|
|
26
|
-
vi.mock('../../features/browser/browser-mcp.js', () => ({
|
|
27
|
-
BrowserMCPIntegration: vi.fn().mockImplementation(() => ({
|
|
28
|
-
initialize: vi.fn().mockResolvedValue(undefined)
|
|
29
|
-
}))
|
|
30
|
-
}));
|
|
31
|
-
// Mock Linear imports with dynamic imports
|
|
32
|
-
vi.mock('../../integrations/linear/auth.js', async () => {
|
|
33
|
-
const actual = await vi.importActual('../../integrations/linear/auth.js');
|
|
34
|
-
return {
|
|
35
|
-
...actual,
|
|
36
|
-
LinearAuthManager: vi.fn().mockImplementation(() => ({
|
|
37
|
-
loadTokens: vi.fn(),
|
|
38
|
-
isConfigured: vi.fn(() => false)
|
|
39
|
-
}))
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
vi.mock('../../integrations/linear/client.js', async () => {
|
|
43
|
-
const actual = await vi.importActual('../../integrations/linear/client.js');
|
|
44
|
-
return {
|
|
45
|
-
...actual,
|
|
46
|
-
LinearClient: vi.fn().mockImplementation(() => ({
|
|
47
|
-
getIssue: vi.fn(),
|
|
48
|
-
findIssueByIdentifier: vi.fn(),
|
|
49
|
-
updateIssue: vi.fn(),
|
|
50
|
-
getTeam: vi.fn(),
|
|
51
|
-
getWorkflowStates: vi.fn(),
|
|
52
|
-
getViewer: vi.fn(),
|
|
53
|
-
getIssues: vi.fn()
|
|
54
|
-
}))
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
vi.mock('../../integrations/linear/sync.js', async () => {
|
|
58
|
-
const actual = await vi.importActual('../../integrations/linear/sync.js');
|
|
59
|
-
return {
|
|
60
|
-
...actual,
|
|
61
|
-
LinearSyncEngine: vi.fn().mockImplementation(() => ({
|
|
62
|
-
sync: vi.fn()
|
|
63
|
-
})),
|
|
64
|
-
DEFAULT_SYNC_CONFIG: {
|
|
65
|
-
enabled: true,
|
|
66
|
-
direction: 'bidirectional',
|
|
67
|
-
conflictResolution: 'newest_wins'
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
describe('LocalStackMemoryMCP', () => {
|
|
72
|
-
let tempDir;
|
|
73
|
-
let mcpServer;
|
|
74
|
-
let mockServer;
|
|
75
|
-
let originalCwd;
|
|
76
|
-
let originalArgv;
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
// Setup temp directory
|
|
79
|
-
tempDir = mkdtempSync(join(tmpdir(), 'stackmemory-mcp-test-'));
|
|
80
|
-
originalCwd = process.cwd();
|
|
81
|
-
originalArgv = [...process.argv];
|
|
82
|
-
// Create .git directory to simulate git repo
|
|
83
|
-
const gitDir = join(tempDir, '.git');
|
|
84
|
-
mkdirSync(gitDir, { recursive: true });
|
|
85
|
-
writeFileSync(join(gitDir, 'config'), '[core]\n\trepositoryformatversion = 0');
|
|
86
|
-
// Create package.json
|
|
87
|
-
writeFileSync(join(tempDir, 'package.json'), JSON.stringify({
|
|
88
|
-
name: 'test-project',
|
|
89
|
-
version: '1.0.0'
|
|
90
|
-
}));
|
|
91
|
-
// Mock process.cwd() to return our temp directory
|
|
92
|
-
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
93
|
-
// Setup mock server
|
|
94
|
-
mockServer = {
|
|
95
|
-
setRequestHandler: vi.fn(),
|
|
96
|
-
connect: vi.fn()
|
|
97
|
-
};
|
|
98
|
-
Server.mockImplementation(() => mockServer);
|
|
99
|
-
});
|
|
100
|
-
afterEach(() => {
|
|
101
|
-
if (mcpServer) {
|
|
102
|
-
// Cleanup if needed
|
|
103
|
-
}
|
|
104
|
-
// Restore original process state
|
|
105
|
-
vi.spyOn(process, 'cwd').mockRestore();
|
|
106
|
-
process.argv = originalArgv;
|
|
107
|
-
// Cleanup temp directory
|
|
108
|
-
if (tempDir) {
|
|
109
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
110
|
-
}
|
|
111
|
-
vi.clearAllMocks();
|
|
112
|
-
});
|
|
113
|
-
describe('Initialization', () => {
|
|
114
|
-
it('should initialize server with correct project detection', () => {
|
|
115
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
116
|
-
expect(Server).toHaveBeenCalledWith({
|
|
117
|
-
name: 'stackmemory-local',
|
|
118
|
-
version: '0.1.0'
|
|
119
|
-
}, {
|
|
120
|
-
capabilities: {
|
|
121
|
-
tools: {}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
it('should create .stackmemory directory if it does not exist', () => {
|
|
126
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
127
|
-
const stackmemoryDir = join(tempDir, '.stackmemory');
|
|
128
|
-
expect(existsSync(stackmemoryDir)).toBe(true);
|
|
129
|
-
});
|
|
130
|
-
it('should initialize database and frame manager', () => {
|
|
131
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
132
|
-
const dbPath = join(tempDir, '.stackmemory', 'context.db');
|
|
133
|
-
expect(existsSync(dbPath)).toBe(true);
|
|
134
|
-
});
|
|
135
|
-
it('should handle missing .git directory gracefully', () => {
|
|
136
|
-
// Remove .git directory
|
|
137
|
-
rmSync(join(tempDir, '.git'), { recursive: true });
|
|
138
|
-
// Should still work, using current directory as project root
|
|
139
|
-
expect(() => {
|
|
140
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
141
|
-
}).not.toThrow();
|
|
142
|
-
});
|
|
143
|
-
it('should setup tool handlers correctly', () => {
|
|
144
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
145
|
-
// Should have called setRequestHandler at least twice (tools/list and tools/call)
|
|
146
|
-
expect(mockServer.setRequestHandler).toHaveBeenCalledTimes(2);
|
|
147
|
-
// Check for tools/list handler
|
|
148
|
-
const toolsListCall = mockServer.setRequestHandler.mock.calls.find((call) => call[0].parse({ method: 'tools/list' }).method === 'tools/list');
|
|
149
|
-
expect(toolsListCall).toBeDefined();
|
|
150
|
-
// Check for tools/call handler
|
|
151
|
-
const toolsCallCall = mockServer.setRequestHandler.mock.calls.find((call) => call[0].parse({ method: 'tools/call', params: { name: 'test', arguments: {} } }).method === 'tools/call');
|
|
152
|
-
expect(toolsCallCall).toBeDefined();
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe('Tool Listing', () => {
|
|
156
|
-
beforeEach(() => {
|
|
157
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
158
|
-
});
|
|
159
|
-
it('should list all available tools', async () => {
|
|
160
|
-
const toolsListHandler = mockServer.setRequestHandler.mock.calls[0][1];
|
|
161
|
-
const result = await toolsListHandler({ method: 'tools/list' });
|
|
162
|
-
expect(result.tools).toBeDefined();
|
|
163
|
-
expect(Array.isArray(result.tools)).toBe(true);
|
|
164
|
-
expect(result.tools.length).toBeGreaterThan(0);
|
|
165
|
-
// Check for essential tools
|
|
166
|
-
const toolNames = result.tools.map((tool) => tool.name);
|
|
167
|
-
expect(toolNames).toContain('get_context');
|
|
168
|
-
expect(toolNames).toContain('add_decision');
|
|
169
|
-
expect(toolNames).toContain('start_frame');
|
|
170
|
-
expect(toolNames).toContain('close_frame');
|
|
171
|
-
expect(toolNames).toContain('add_anchor');
|
|
172
|
-
expect(toolNames).toContain('get_hot_stack');
|
|
173
|
-
expect(toolNames).toContain('create_task');
|
|
174
|
-
expect(toolNames).toContain('update_task_status');
|
|
175
|
-
expect(toolNames).toContain('get_active_tasks');
|
|
176
|
-
});
|
|
177
|
-
it('should include Linear integration tools', async () => {
|
|
178
|
-
const toolsListHandler = mockServer.setRequestHandler.mock.calls[0][1];
|
|
179
|
-
const result = await toolsListHandler({ method: 'tools/list' });
|
|
180
|
-
const toolNames = result.tools.map((tool) => tool.name);
|
|
181
|
-
expect(toolNames).toContain('linear_sync');
|
|
182
|
-
expect(toolNames).toContain('linear_update_task');
|
|
183
|
-
expect(toolNames).toContain('linear_get_tasks');
|
|
184
|
-
expect(toolNames).toContain('linear_status');
|
|
185
|
-
});
|
|
186
|
-
it('should include proper tool schemas', async () => {
|
|
187
|
-
const toolsListHandler = mockServer.setRequestHandler.mock.calls[0][1];
|
|
188
|
-
const result = await toolsListHandler({ method: 'tools/list' });
|
|
189
|
-
const getContextTool = result.tools.find((tool) => tool.name === 'get_context');
|
|
190
|
-
expect(getContextTool).toBeDefined();
|
|
191
|
-
expect(getContextTool.description).toBeDefined();
|
|
192
|
-
expect(getContextTool.inputSchema).toBeDefined();
|
|
193
|
-
expect(getContextTool.inputSchema.type).toBe('object');
|
|
194
|
-
expect(getContextTool.inputSchema.properties).toBeDefined();
|
|
195
|
-
const startFrameTool = result.tools.find((tool) => tool.name === 'start_frame');
|
|
196
|
-
expect(startFrameTool.inputSchema.required).toContain('name');
|
|
197
|
-
expect(startFrameTool.inputSchema.required).toContain('type');
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
describe('Tool Execution - Context Management', () => {
|
|
201
|
-
let toolsCallHandler;
|
|
202
|
-
beforeEach(() => {
|
|
203
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
204
|
-
toolsCallHandler = mockServer.setRequestHandler.mock.calls[1][1];
|
|
205
|
-
});
|
|
206
|
-
it('should handle get_context tool', async () => {
|
|
207
|
-
const result = await toolsCallHandler({
|
|
208
|
-
method: 'tools/call',
|
|
209
|
-
params: {
|
|
210
|
-
name: 'get_context',
|
|
211
|
-
arguments: { query: 'test', limit: 5 }
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
expect(result.content).toBeDefined();
|
|
215
|
-
expect(Array.isArray(result.content)).toBe(true);
|
|
216
|
-
expect(result.content[0].type).toBe('text');
|
|
217
|
-
});
|
|
218
|
-
it('should handle add_decision tool', async () => {
|
|
219
|
-
const result = await toolsCallHandler({
|
|
220
|
-
method: 'tools/call',
|
|
221
|
-
params: {
|
|
222
|
-
name: 'add_decision',
|
|
223
|
-
arguments: { content: 'Test decision', type: 'decision' }
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
expect(result.content).toBeDefined();
|
|
227
|
-
expect(result.content[0].text).toContain('Added decision');
|
|
228
|
-
expect(result.content[0].text).toContain('Test decision');
|
|
229
|
-
});
|
|
230
|
-
it('should handle start_frame tool', async () => {
|
|
231
|
-
const result = await toolsCallHandler({
|
|
232
|
-
method: 'tools/call',
|
|
233
|
-
params: {
|
|
234
|
-
name: 'start_frame',
|
|
235
|
-
arguments: {
|
|
236
|
-
name: 'Test Frame',
|
|
237
|
-
type: 'task',
|
|
238
|
-
constraints: ['constraint1', 'constraint2']
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
expect(result.content).toBeDefined();
|
|
243
|
-
expect(result.content[0].text).toContain('Started task');
|
|
244
|
-
expect(result.content[0].text).toContain('Test Frame');
|
|
245
|
-
expect(result.content[0].text).toContain('Frame ID:');
|
|
246
|
-
expect(result.content[0].text).toContain('Stack depth:');
|
|
247
|
-
});
|
|
248
|
-
it('should handle close_frame tool', async () => {
|
|
249
|
-
// First start a frame
|
|
250
|
-
await toolsCallHandler({
|
|
251
|
-
method: 'tools/call',
|
|
252
|
-
params: {
|
|
253
|
-
name: 'start_frame',
|
|
254
|
-
arguments: { name: 'Test Frame', type: 'task' }
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
// Then close it
|
|
258
|
-
const result = await toolsCallHandler({
|
|
259
|
-
method: 'tools/call',
|
|
260
|
-
params: {
|
|
261
|
-
name: 'close_frame',
|
|
262
|
-
arguments: {
|
|
263
|
-
result: 'Completed successfully',
|
|
264
|
-
outputs: { key: 'value' }
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
expect(result.content).toBeDefined();
|
|
269
|
-
expect(result.content[0].text).toContain('Closed frame');
|
|
270
|
-
expect(result.content[0].text).toContain('Completed successfully');
|
|
271
|
-
});
|
|
272
|
-
it('should handle close_frame with no active frame', async () => {
|
|
273
|
-
const result = await toolsCallHandler({
|
|
274
|
-
method: 'tools/call',
|
|
275
|
-
params: {
|
|
276
|
-
name: 'close_frame',
|
|
277
|
-
arguments: { result: 'Test' }
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
expect(result.content[0].text).toContain('No active frame to close');
|
|
281
|
-
});
|
|
282
|
-
it('should handle add_anchor tool', async () => {
|
|
283
|
-
// First start a frame
|
|
284
|
-
await toolsCallHandler({
|
|
285
|
-
method: 'tools/call',
|
|
286
|
-
params: {
|
|
287
|
-
name: 'start_frame',
|
|
288
|
-
arguments: { name: 'Test Frame', type: 'task' }
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
// Then add an anchor
|
|
292
|
-
const result = await toolsCallHandler({
|
|
293
|
-
method: 'tools/call',
|
|
294
|
-
params: {
|
|
295
|
-
name: 'add_anchor',
|
|
296
|
-
arguments: {
|
|
297
|
-
type: 'FACT',
|
|
298
|
-
text: 'Important fact',
|
|
299
|
-
priority: 9
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
expect(result.content[0].text).toContain('Added FACT');
|
|
304
|
-
expect(result.content[0].text).toContain('Important fact');
|
|
305
|
-
expect(result.content[0].text).toContain('Anchor ID:');
|
|
306
|
-
});
|
|
307
|
-
it('should handle get_hot_stack tool', async () => {
|
|
308
|
-
// First start some frames
|
|
309
|
-
await toolsCallHandler({
|
|
310
|
-
method: 'tools/call',
|
|
311
|
-
params: {
|
|
312
|
-
name: 'start_frame',
|
|
313
|
-
arguments: { name: 'Root Frame', type: 'task' }
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
await toolsCallHandler({
|
|
317
|
-
method: 'tools/call',
|
|
318
|
-
params: {
|
|
319
|
-
name: 'start_frame',
|
|
320
|
-
arguments: { name: 'Child Frame', type: 'subtask' }
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
const result = await toolsCallHandler({
|
|
324
|
-
method: 'tools/call',
|
|
325
|
-
params: {
|
|
326
|
-
name: 'get_hot_stack',
|
|
327
|
-
arguments: { maxEvents: 10 }
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
expect(result.content[0].text).toContain('Active Call Stack');
|
|
331
|
-
expect(result.content[0].text).toContain('Root Frame');
|
|
332
|
-
expect(result.content[0].text).toContain('Child Frame');
|
|
333
|
-
expect(result.content[0].text).toContain('Total stack depth');
|
|
334
|
-
});
|
|
335
|
-
it('should handle get_hot_stack with no active frames', async () => {
|
|
336
|
-
const result = await toolsCallHandler({
|
|
337
|
-
method: 'tools/call',
|
|
338
|
-
params: {
|
|
339
|
-
name: 'get_hot_stack',
|
|
340
|
-
arguments: {}
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
expect(result.content[0].text).toContain('No active frames');
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
describe('Tool Execution - Task Management', () => {
|
|
347
|
-
let toolsCallHandler;
|
|
348
|
-
beforeEach(() => {
|
|
349
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
350
|
-
toolsCallHandler = mockServer.setRequestHandler.mock.calls[1][1];
|
|
351
|
-
// Start a frame for task operations
|
|
352
|
-
toolsCallHandler({
|
|
353
|
-
method: 'tools/call',
|
|
354
|
-
params: {
|
|
355
|
-
name: 'start_frame',
|
|
356
|
-
arguments: { name: 'Task Frame', type: 'task' }
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
it('should handle create_task tool', async () => {
|
|
361
|
-
const result = await toolsCallHandler({
|
|
362
|
-
method: 'tools/call',
|
|
363
|
-
params: {
|
|
364
|
-
name: 'create_task',
|
|
365
|
-
arguments: {
|
|
366
|
-
title: 'Test Task',
|
|
367
|
-
description: 'A test task',
|
|
368
|
-
priority: 'high',
|
|
369
|
-
estimatedEffort: 120,
|
|
370
|
-
tags: ['test', 'urgent']
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
expect(result.content[0].text).toContain('Created task');
|
|
375
|
-
expect(result.content[0].text).toContain('Test Task');
|
|
376
|
-
expect(result.content[0].text).toContain('ID:');
|
|
377
|
-
expect(result.content[0].text).toContain('tasks.jsonl');
|
|
378
|
-
});
|
|
379
|
-
it('should handle create_task without active frame', async () => {
|
|
380
|
-
// Close all frames first
|
|
381
|
-
await toolsCallHandler({
|
|
382
|
-
method: 'tools/call',
|
|
383
|
-
params: {
|
|
384
|
-
name: 'close_frame',
|
|
385
|
-
arguments: { result: 'closed' }
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
const result = await toolsCallHandler({
|
|
389
|
-
method: 'tools/call',
|
|
390
|
-
params: {
|
|
391
|
-
name: 'create_task',
|
|
392
|
-
arguments: { title: 'No Frame Task' }
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
expect(result.content[0].text).toContain('No active frame');
|
|
396
|
-
});
|
|
397
|
-
it('should handle update_task_status tool', async () => {
|
|
398
|
-
// First create a task
|
|
399
|
-
const createResult = await toolsCallHandler({
|
|
400
|
-
method: 'tools/call',
|
|
401
|
-
params: {
|
|
402
|
-
name: 'create_task',
|
|
403
|
-
arguments: { title: 'Update Test Task' }
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
// Extract task ID from response (simplified)
|
|
407
|
-
const taskIdMatch = createResult.content[0].text.match(/ID: (tsk-[a-f0-9]{8})/);
|
|
408
|
-
expect(taskIdMatch).toBeTruthy();
|
|
409
|
-
const taskId = taskIdMatch[1];
|
|
410
|
-
const result = await toolsCallHandler({
|
|
411
|
-
method: 'tools/call',
|
|
412
|
-
params: {
|
|
413
|
-
name: 'update_task_status',
|
|
414
|
-
arguments: {
|
|
415
|
-
taskId,
|
|
416
|
-
status: 'in_progress',
|
|
417
|
-
reason: 'Starting work'
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
expect(result.content[0].text).toContain('Updated task');
|
|
422
|
-
expect(result.content[0].text).toContain('in_progress');
|
|
423
|
-
expect(result.content[0].text).toContain('Starting work');
|
|
424
|
-
});
|
|
425
|
-
it('should handle update_task_status with invalid task', async () => {
|
|
426
|
-
const result = await toolsCallHandler({
|
|
427
|
-
method: 'tools/call',
|
|
428
|
-
params: {
|
|
429
|
-
name: 'update_task_status',
|
|
430
|
-
arguments: {
|
|
431
|
-
taskId: 'invalid-task-id',
|
|
432
|
-
status: 'completed'
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
expect(result.content[0].text).toContain('Failed to update task');
|
|
437
|
-
});
|
|
438
|
-
it('should handle get_active_tasks tool', async () => {
|
|
439
|
-
// Create some tasks
|
|
440
|
-
await toolsCallHandler({
|
|
441
|
-
method: 'tools/call',
|
|
442
|
-
params: {
|
|
443
|
-
name: 'create_task',
|
|
444
|
-
arguments: { title: 'Active Task 1', priority: 'high' }
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
await toolsCallHandler({
|
|
448
|
-
method: 'tools/call',
|
|
449
|
-
params: {
|
|
450
|
-
name: 'create_task',
|
|
451
|
-
arguments: { title: 'Active Task 2', priority: 'low' }
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
const result = await toolsCallHandler({
|
|
455
|
-
method: 'tools/call',
|
|
456
|
-
params: {
|
|
457
|
-
name: 'get_active_tasks',
|
|
458
|
-
arguments: {}
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
expect(result.content[0].text).toContain('Active Tasks');
|
|
462
|
-
expect(result.content[0].text).toContain('Active Task 1');
|
|
463
|
-
expect(result.content[0].text).toContain('Active Task 2');
|
|
464
|
-
expect(result.content[0].text).toContain('HIGH');
|
|
465
|
-
expect(result.content[0].text).toContain('LOW');
|
|
466
|
-
});
|
|
467
|
-
it('should handle get_active_tasks with no tasks', async () => {
|
|
468
|
-
const result = await toolsCallHandler({
|
|
469
|
-
method: 'tools/call',
|
|
470
|
-
params: {
|
|
471
|
-
name: 'get_active_tasks',
|
|
472
|
-
arguments: {}
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
expect(result.content[0].text).toContain('No active tasks');
|
|
476
|
-
});
|
|
477
|
-
it('should handle get_task_metrics tool', async () => {
|
|
478
|
-
// Create some tasks with different statuses
|
|
479
|
-
const taskId1 = await toolsCallHandler({
|
|
480
|
-
method: 'tools/call',
|
|
481
|
-
params: {
|
|
482
|
-
name: 'create_task',
|
|
483
|
-
arguments: { title: 'Metrics Task 1' }
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
const result = await toolsCallHandler({
|
|
487
|
-
method: 'tools/call',
|
|
488
|
-
params: {
|
|
489
|
-
name: 'get_task_metrics',
|
|
490
|
-
arguments: {}
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
expect(result.content[0].text).toContain('Task Metrics');
|
|
494
|
-
expect(result.content[0].text).toContain('Total Tasks');
|
|
495
|
-
expect(result.content[0].text).toContain('Completion Rate');
|
|
496
|
-
expect(result.content[0].text).toContain('By Status');
|
|
497
|
-
expect(result.content[0].text).toContain('By Priority');
|
|
498
|
-
});
|
|
499
|
-
it('should handle add_task_dependency tool', async () => {
|
|
500
|
-
// Create two tasks
|
|
501
|
-
const task1Result = await toolsCallHandler({
|
|
502
|
-
method: 'tools/call',
|
|
503
|
-
params: {
|
|
504
|
-
name: 'create_task',
|
|
505
|
-
arguments: { title: 'Dependency Task' }
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
const task2Result = await toolsCallHandler({
|
|
509
|
-
method: 'tools/call',
|
|
510
|
-
params: {
|
|
511
|
-
name: 'create_task',
|
|
512
|
-
arguments: { title: 'Dependent Task' }
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
// Extract task IDs
|
|
516
|
-
const task1Id = task1Result.content[0].text.match(/ID: (tsk-[a-f0-9]{8})/)[1];
|
|
517
|
-
const task2Id = task2Result.content[0].text.match(/ID: (tsk-[a-f0-9]{8})/)[1];
|
|
518
|
-
const result = await toolsCallHandler({
|
|
519
|
-
method: 'tools/call',
|
|
520
|
-
params: {
|
|
521
|
-
name: 'add_task_dependency',
|
|
522
|
-
arguments: {
|
|
523
|
-
taskId: task2Id,
|
|
524
|
-
dependsOnId: task1Id
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
expect(result.content[0].text).toContain('Added dependency');
|
|
529
|
-
expect(result.content[0].text).toContain(task2Id);
|
|
530
|
-
expect(result.content[0].text).toContain(task1Id);
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
describe('Tool Execution - Linear Integration', () => {
|
|
534
|
-
let toolsCallHandler;
|
|
535
|
-
beforeEach(() => {
|
|
536
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
537
|
-
toolsCallHandler = mockServer.setRequestHandler.mock.calls[1][1];
|
|
538
|
-
});
|
|
539
|
-
it('should handle linear_status tool when not configured', async () => {
|
|
540
|
-
const result = await toolsCallHandler({
|
|
541
|
-
method: 'tools/call',
|
|
542
|
-
params: {
|
|
543
|
-
name: 'linear_status',
|
|
544
|
-
arguments: {}
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
expect(result.content[0].text).toContain('Linear integration not configured');
|
|
548
|
-
expect(result.content[0].text).toContain('stackmemory linear setup');
|
|
549
|
-
});
|
|
550
|
-
it('should handle linear_sync tool when not authenticated', async () => {
|
|
551
|
-
const result = await toolsCallHandler({
|
|
552
|
-
method: 'tools/call',
|
|
553
|
-
params: {
|
|
554
|
-
name: 'linear_sync',
|
|
555
|
-
arguments: { direction: 'bidirectional' }
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
expect(result.content[0].text).toContain('Linear not authenticated');
|
|
559
|
-
});
|
|
560
|
-
it('should handle linear_update_task when not authenticated', async () => {
|
|
561
|
-
const result = await toolsCallHandler({
|
|
562
|
-
method: 'tools/call',
|
|
563
|
-
params: {
|
|
564
|
-
name: 'linear_update_task',
|
|
565
|
-
arguments: { issueId: 'STA-123', status: 'done' }
|
|
566
|
-
}
|
|
567
|
-
});
|
|
568
|
-
expect(result.content[0].text).toContain('Linear not authenticated');
|
|
569
|
-
});
|
|
570
|
-
it('should handle linear_get_tasks when not authenticated', async () => {
|
|
571
|
-
const result = await toolsCallHandler({
|
|
572
|
-
method: 'tools/call',
|
|
573
|
-
params: {
|
|
574
|
-
name: 'linear_get_tasks',
|
|
575
|
-
arguments: { status: 'todo', limit: 10 }
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
expect(result.content[0].text).toContain('Linear not authenticated');
|
|
579
|
-
});
|
|
580
|
-
it('should handle linear integration errors gracefully', async () => {
|
|
581
|
-
// Mock successful authentication but failed operation
|
|
582
|
-
const { LinearAuthManager } = await import('../../../integrations/linear/auth.js');
|
|
583
|
-
const mockAuthManager = LinearAuthManager;
|
|
584
|
-
mockAuthManager.mockImplementation(() => ({
|
|
585
|
-
loadTokens: vi.fn(() => ({ accessToken: 'test-token', expiresAt: Date.now() + 3600000 })),
|
|
586
|
-
isConfigured: vi.fn(() => true)
|
|
587
|
-
}));
|
|
588
|
-
const { LinearClient } = await import('../../../integrations/linear/client.js');
|
|
589
|
-
const mockClient = LinearClient;
|
|
590
|
-
mockClient.mockImplementation(() => ({
|
|
591
|
-
getViewer: vi.fn().mockRejectedValue(new Error('Network error'))
|
|
592
|
-
}));
|
|
593
|
-
const result = await toolsCallHandler({
|
|
594
|
-
method: 'tools/call',
|
|
595
|
-
params: {
|
|
596
|
-
name: 'linear_status',
|
|
597
|
-
arguments: {}
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
expect(result.content[0].text).toContain('connection failed');
|
|
601
|
-
});
|
|
602
|
-
});
|
|
603
|
-
describe('Error Handling', () => {
|
|
604
|
-
let toolsCallHandler;
|
|
605
|
-
beforeEach(() => {
|
|
606
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
607
|
-
toolsCallHandler = mockServer.setRequestHandler.mock.calls[1][1];
|
|
608
|
-
});
|
|
609
|
-
it('should handle unknown tool calls', async () => {
|
|
610
|
-
await expect(toolsCallHandler({
|
|
611
|
-
method: 'tools/call',
|
|
612
|
-
params: {
|
|
613
|
-
name: 'unknown_tool',
|
|
614
|
-
arguments: {}
|
|
615
|
-
}
|
|
616
|
-
})).rejects.toThrow('Unknown tool: unknown_tool');
|
|
617
|
-
});
|
|
618
|
-
it('should handle malformed tool arguments gracefully', async () => {
|
|
619
|
-
const result = await toolsCallHandler({
|
|
620
|
-
method: 'tools/call',
|
|
621
|
-
params: {
|
|
622
|
-
name: 'start_frame',
|
|
623
|
-
arguments: { name: 'Test' } // Missing required 'type'
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
// Should handle the missing type gracefully
|
|
627
|
-
expect(result).toBeDefined();
|
|
628
|
-
});
|
|
629
|
-
it('should maintain error context in responses', async () => {
|
|
630
|
-
const result = await toolsCallHandler({
|
|
631
|
-
method: 'tools/call',
|
|
632
|
-
params: {
|
|
633
|
-
name: 'add_anchor',
|
|
634
|
-
arguments: {
|
|
635
|
-
type: 'FACT',
|
|
636
|
-
text: 'Test fact'
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
// Should fail because no active frame
|
|
641
|
-
expect(result).toBeDefined();
|
|
642
|
-
});
|
|
643
|
-
});
|
|
644
|
-
describe('Project Detection and Context Loading', () => {
|
|
645
|
-
it('should detect git repository information', () => {
|
|
646
|
-
// Mock git commands
|
|
647
|
-
const { execSync } = require('child_process');
|
|
648
|
-
execSync.mockReturnValueOnce(Buffer.from('origin\thttps://github.com/user/repo.git'));
|
|
649
|
-
execSync.mockReturnValueOnce(Buffer.from('abc123 Initial commit\ndef456 Second commit'));
|
|
650
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
651
|
-
// Should have called git commands for project detection
|
|
652
|
-
expect(execSync).toHaveBeenCalledWith('git config --get remote.origin.url', expect.any(Object));
|
|
653
|
-
expect(execSync).toHaveBeenCalledWith('git log --oneline -10', expect.any(Object));
|
|
654
|
-
});
|
|
655
|
-
it('should handle missing git repository gracefully', () => {
|
|
656
|
-
const { execSync } = require('child_process');
|
|
657
|
-
execSync.mockImplementation(() => {
|
|
658
|
-
throw new Error('Not a git repository');
|
|
659
|
-
});
|
|
660
|
-
expect(() => {
|
|
661
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
662
|
-
}).not.toThrow();
|
|
663
|
-
});
|
|
664
|
-
it('should load README.md if present', () => {
|
|
665
|
-
const readmePath = join(tempDir, 'README.md');
|
|
666
|
-
writeFileSync(readmePath, '# Test Project\n\nThis is a test project for MCP server testing.');
|
|
667
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
668
|
-
// Should have loaded README content into context
|
|
669
|
-
expect(existsSync(readmePath)).toBe(true);
|
|
670
|
-
});
|
|
671
|
-
it('should handle missing README.md gracefully', () => {
|
|
672
|
-
// Ensure no README exists
|
|
673
|
-
const readmePath = join(tempDir, 'README.md');
|
|
674
|
-
if (existsSync(readmePath)) {
|
|
675
|
-
rmSync(readmePath);
|
|
676
|
-
}
|
|
677
|
-
expect(() => {
|
|
678
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
679
|
-
}).not.toThrow();
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
describe('Database Schema and Persistence', () => {
|
|
683
|
-
beforeEach(() => {
|
|
684
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
685
|
-
});
|
|
686
|
-
it('should create required database tables', () => {
|
|
687
|
-
const dbPath = join(tempDir, '.stackmemory', 'context.db');
|
|
688
|
-
const db = new Database(dbPath);
|
|
689
|
-
const tables = db.prepare(`
|
|
690
|
-
SELECT name FROM sqlite_master
|
|
691
|
-
WHERE type='table' AND name IN ('contexts', 'frames', 'attention_log')
|
|
692
|
-
`).all();
|
|
693
|
-
expect(tables).toHaveLength(3);
|
|
694
|
-
db.close();
|
|
695
|
-
});
|
|
696
|
-
it('should handle database initialization errors gracefully', () => {
|
|
697
|
-
// Mock Database constructor to throw error
|
|
698
|
-
const originalDatabase = Database;
|
|
699
|
-
vi.doMock('better-sqlite3', () => ({
|
|
700
|
-
default: vi.fn(() => {
|
|
701
|
-
throw new Error('Database error');
|
|
702
|
-
})
|
|
703
|
-
}));
|
|
704
|
-
expect(() => {
|
|
705
|
-
// This would fail in real usage but we test error handling
|
|
706
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
707
|
-
}).toThrow();
|
|
708
|
-
});
|
|
709
|
-
});
|
|
710
|
-
describe('Server Lifecycle', () => {
|
|
711
|
-
it('should start server successfully', async () => {
|
|
712
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
713
|
-
const mockTransport = { connect: vi.fn() };
|
|
714
|
-
vi.doMock('@modelcontextprotocol/sdk/server/stdio.js', () => ({
|
|
715
|
-
StdioServerTransport: vi.fn(() => mockTransport)
|
|
716
|
-
}));
|
|
717
|
-
mockServer.connect.mockResolvedValue(undefined);
|
|
718
|
-
await expect(mcpServer.start()).resolves.not.toThrow();
|
|
719
|
-
expect(mockServer.connect).toHaveBeenCalled();
|
|
720
|
-
});
|
|
721
|
-
it('should handle server start errors', async () => {
|
|
722
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
723
|
-
mockServer.connect.mockRejectedValue(new Error('Connection failed'));
|
|
724
|
-
await expect(mcpServer.start()).rejects.toThrow('Connection failed');
|
|
725
|
-
});
|
|
726
|
-
});
|
|
727
|
-
describe('Integration with Framework Components', () => {
|
|
728
|
-
beforeEach(() => {
|
|
729
|
-
mcpServer = new LocalStackMemoryMCP();
|
|
730
|
-
});
|
|
731
|
-
it('should integrate frame manager operations', async () => {
|
|
732
|
-
const toolsCallHandler = mockServer.setRequestHandler.mock.calls[1][1];
|
|
733
|
-
// Test frame lifecycle
|
|
734
|
-
const startResult = await toolsCallHandler({
|
|
735
|
-
method: 'tools/call',
|
|
736
|
-
params: {
|
|
737
|
-
name: 'start_frame',
|
|
738
|
-
arguments: { name: 'Integration Test', type: 'task' }
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
expect(startResult.content[0].text).toContain('Started task');
|
|
742
|
-
const hotStackResult = await toolsCallHandler({
|
|
743
|
-
method: 'tools/call',
|
|
744
|
-
params: {
|
|
745
|
-
name: 'get_hot_stack',
|
|
746
|
-
arguments: {}
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
expect(hotStackResult.content[0].text).toContain('Integration Test');
|
|
750
|
-
const closeResult = await toolsCallHandler({
|
|
751
|
-
method: 'tools/call',
|
|
752
|
-
params: {
|
|
753
|
-
name: 'close_frame',
|
|
754
|
-
arguments: { result: 'Integration complete' }
|
|
755
|
-
}
|
|
756
|
-
});
|
|
757
|
-
expect(closeResult.content[0].text).toContain('Closed frame');
|
|
758
|
-
});
|
|
759
|
-
it('should integrate task store operations', async () => {
|
|
760
|
-
const toolsCallHandler = mockServer.setRequestHandler.mock.calls[1][1];
|
|
761
|
-
// Start frame for task operations
|
|
762
|
-
await toolsCallHandler({
|
|
763
|
-
method: 'tools/call',
|
|
764
|
-
params: {
|
|
765
|
-
name: 'start_frame',
|
|
766
|
-
arguments: { name: 'Task Integration', type: 'task' }
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
// Create task
|
|
770
|
-
const createResult = await toolsCallHandler({
|
|
771
|
-
method: 'tools/call',
|
|
772
|
-
params: {
|
|
773
|
-
name: 'create_task',
|
|
774
|
-
arguments: { title: 'Integration Task' }
|
|
775
|
-
}
|
|
776
|
-
});
|
|
777
|
-
expect(createResult.content[0].text).toContain('Created task');
|
|
778
|
-
// Get active tasks
|
|
779
|
-
const activeResult = await toolsCallHandler({
|
|
780
|
-
method: 'tools/call',
|
|
781
|
-
params: {
|
|
782
|
-
name: 'get_active_tasks',
|
|
783
|
-
arguments: {}
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
expect(activeResult.content[0].text).toContain('Integration Task');
|
|
787
|
-
});
|
|
788
|
-
});
|
|
789
|
-
});
|
|
790
|
-
//# sourceMappingURL=server.test.js.map
|