Skip to content

Commit 11f8a1f

Browse files
committed
More fixes for PR review feedback
1 parent 0c70ffc commit 11f8a1f

File tree

10 files changed

+94
-14
lines changed

10 files changed

+94
-14
lines changed

client/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/advanced-security/codeql-development-mcp-server/client
22

3-
go 1.25.8
3+
go 1.25.6
44

55
require (
66
github.com/mark3labs/mcp-go v0.47.0

client/internal/testing/params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func buildToolParams(repoRoot, toolName, testCase, testDir string) (map[string]a
150150
params["query"] = filepath.Join(beforeDir, qlFiles[0])
151151

152152
case "codeql_resolve_queries":
153-
params["path"] = beforeDir
153+
params["directory"] = beforeDir
154154

155155
case "codeql_resolve_tests":
156156
params["tests"] = []string{beforeDir}

client/internal/testing/params_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ func TestBuildToolParams_ValidateCodeqlQuery(t *testing.T) {
6565
}
6666
}
6767

68+
func TestBuildToolParams_ResolveQueries_UsesDirectoryKey(t *testing.T) {
69+
dir := t.TempDir()
70+
testDir := filepath.Join(dir, "tools", "codeql_resolve_queries", "resolve_queries")
71+
os.MkdirAll(filepath.Join(testDir, "before"), 0o755)
72+
os.MkdirAll(filepath.Join(testDir, "after"), 0o755)
73+
74+
params, err := buildToolParams(dir, "codeql_resolve_queries", "resolve_queries", testDir)
75+
if err != nil {
76+
t.Fatalf("unexpected error: %v", err)
77+
}
78+
// The server schema expects "directory", not "path"
79+
if _, ok := params["directory"]; !ok {
80+
t.Errorf("expected params to contain 'directory' key, got keys: %v", params)
81+
}
82+
if _, ok := params["path"]; ok {
83+
t.Errorf("params should NOT contain 'path' key for codeql_resolve_queries; use 'directory' instead")
84+
}
85+
}
86+
6887
func TestBuildToolParams_ResolveLanguages(t *testing.T) {
6988
dir := t.TempDir()
7089
testDir := filepath.Join(dir, "tools", "codeql_resolve_languages", "list_languages")

client/internal/testing/runner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ func (r *Runner) Run() (bool, []TestResult) {
9595

9696
entries, err := os.ReadDir(testsDir)
9797
if err != nil {
98-
fmt.Fprintf(os.Stderr, "No integration tests directory found: %v\n", err)
99-
return true, nil
98+
errMsg := fmt.Sprintf("integration tests directory not found: %v", err)
99+
fmt.Fprintf(os.Stderr, "Error: %s\n", errMsg)
100+
r.recordResult("(fixtures)", "", false, errMsg, 0)
101+
return r.printSummary(), r.results
100102
}
101103

102104
var toolDirs []string

client/internal/testing/runner_test.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ func TestTruncate(t *testing.T) {
101101
func TestRunnerWithMockCaller(t *testing.T) {
102102
caller := newMockCaller()
103103

104+
// Create a valid repo root with an empty fixtures directory
105+
dir := t.TempDir()
106+
testsDir := filepath.Join(dir, "client", "integration-tests", "primitives", "tools")
107+
os.MkdirAll(testsDir, 0o755)
108+
104109
opts := RunnerOptions{
105-
RepoRoot: "/nonexistent",
110+
RepoRoot: dir,
106111
FilterTools: []string{"nonexistent_tool"},
107112
}
108113

@@ -111,9 +116,8 @@ func TestRunnerWithMockCaller(t *testing.T) {
111116
t.Fatal("NewRunner returned nil")
112117
}
113118

114-
// Running with nonexistent directory should not panic
119+
// Running with no matching tool dirs = all passed (vacuously true)
115120
allPassed, results := runner.Run()
116-
// No tests found = all passed (vacuously true)
117121
if !allPassed {
118122
t.Error("expected allPassed=true when no tests found")
119123
}
@@ -125,8 +129,13 @@ func TestRunnerWithMockCaller(t *testing.T) {
125129
func TestRunnerNoInstallPacks(t *testing.T) {
126130
caller := newMockCaller()
127131

132+
// Create a valid repo root with an empty fixtures directory
133+
dir := t.TempDir()
134+
testsDir := filepath.Join(dir, "client", "integration-tests", "primitives", "tools")
135+
os.MkdirAll(testsDir, 0o755)
136+
128137
opts := RunnerOptions{
129-
RepoRoot: "/nonexistent",
138+
RepoRoot: dir,
130139
NoInstallPacks: true,
131140
FilterTools: []string{"codeql_pack_install"},
132141
}
@@ -295,6 +304,28 @@ func TestValidateAssertions_MultipleBlocks(t *testing.T) {
295304
}
296305
}
297306

307+
func TestRunnerMissingFixturesDirFails(t *testing.T) {
308+
caller := newMockCaller()
309+
310+
// Point to a repo root that exists but has no client/integration-tests/primitives/tools
311+
dir := t.TempDir()
312+
313+
opts := RunnerOptions{
314+
RepoRoot: dir,
315+
}
316+
317+
runner := NewRunner(caller, opts)
318+
allPassed, results := runner.Run()
319+
320+
// A missing fixtures directory must be treated as a hard failure
321+
if allPassed {
322+
t.Error("expected allPassed=false when fixtures directory is missing")
323+
}
324+
if len(results) == 0 {
325+
t.Error("expected at least one failure result for missing fixtures directory")
326+
}
327+
}
328+
298329
func TestRunnerAssertionFailure(t *testing.T) {
299330
caller := newMockCaller()
300331
caller.results["mock_tool"] = mockResult{

server/dist/codeql-development-mcp-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190235,7 +190235,7 @@ var MonitoringConfigSchema = external_exports.object({
190235190235
enableMonitoringTools: external_exports.boolean().default(false),
190236190236
// Opt-in: session_* tools disabled by default for end-users
190237190237
enableAnnotationTools: external_exports.boolean().default(false)
190238-
// Opt-in: annotation_* and audit_* tools disabled by default
190238+
// Controls auto-caching behavior in result-processor; tools are always registered
190239190239
});
190240190240

190241190241
// src/lib/session-data-manager.ts

server/dist/codeql-development-mcp-server.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/tools/annotation-tools.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/**
22
* Annotation Tools — general-purpose notes and bookmarks on any entity.
33
*
4-
* Enabled by default. Can be disabled via ENABLE_ANNOTATION_TOOLS=false.
5-
* Uses the shared SqliteStore from the session data manager.
4+
* Always registered. Uses the shared SqliteStore from the session data manager.
65
*/
76

87
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';

server/src/types/monitoring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const MonitoringConfigSchema = z.object({
196196
archiveCompletedSessions: z.boolean().default(true),
197197
enableRecommendations: z.boolean().default(true),
198198
enableMonitoringTools: z.boolean().default(false), // Opt-in: session_* tools disabled by default for end-users
199-
enableAnnotationTools: z.boolean().default(false), // Opt-in: annotation_* and audit_* tools disabled by default
199+
enableAnnotationTools: z.boolean().default(false), // Controls auto-caching behavior in result-processor; tools are always registered
200200
});
201201

202202
export type MonitoringConfig = z.infer<typeof MonitoringConfigSchema>;

server/test/src/tools/annotation-tools.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ describe('Annotation Tools', () => {
5959
expect(mockServer.tool).toHaveBeenCalledTimes(6);
6060
});
6161

62+
it('should register all 6 annotation tools even when enableAnnotationTools is false', () => {
63+
vi.spyOn(sessionDataManager, 'getConfig').mockReturnValue({
64+
storageLocation: testStorageDir,
65+
autoTrackSessions: true,
66+
retentionDays: 90,
67+
includeCallParameters: true,
68+
includeCallResults: true,
69+
maxActiveSessionsPerQuery: 3,
70+
scoringFrequency: 'per_call',
71+
archiveCompletedSessions: true,
72+
enableAnnotationTools: false,
73+
enableRecommendations: true,
74+
enableMonitoringTools: false,
75+
});
76+
77+
registerAnnotationTools(mockServer);
78+
79+
const toolCalls = (mockServer.tool as any).mock.calls;
80+
const toolNames = toolCalls.map((call: any) => call[0]);
81+
82+
expect(toolNames).toContain('annotation_create');
83+
expect(toolNames).toContain('annotation_delete');
84+
expect(toolNames).toContain('annotation_get');
85+
expect(toolNames).toContain('annotation_list');
86+
expect(toolNames).toContain('annotation_search');
87+
expect(toolNames).toContain('annotation_update');
88+
expect(mockServer.tool).toHaveBeenCalledTimes(6);
89+
});
90+
6291
describe('tool schema validation', () => {
6392
beforeEach(() => {
6493
vi.spyOn(sessionDataManager, 'getConfig').mockReturnValue({

0 commit comments

Comments
 (0)