[UPDATE PRIMITIVE] Improve error handling and relative file path support for prompts#145
[UPDATE PRIMITIVE] Improve error handling and relative file path support for prompts#145
Conversation
- Add resolvePromptFilePath() utility that resolves relative paths against workspace root and returns user-friendly warnings for invalid paths - Update all 9 prompt handlers with file path parameters to resolve paths and embed warnings in the response instead of throwing protocol errors - Add integration test in mcp-test-suite.js for explain_codeql_query with invalid path - Add file-based integration test fixtures in primitives/prompts/ - Add 10 unit tests for resolvePromptFilePath and handler path resolution Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
… assertions Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
|
@copilot Following TDD methodology, add at least one extension integration test that catches the error handling behavior of at least one MCP-hosted prompt (e.g. |
Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
…alid paths Add mcp-prompt-e2e.integration.test.ts to the VS Code extension test suite that spawns the real MCP server inside the Extension Development Host and verifies that prompts return user-friendly warnings (not protocol errors) when given invalid file paths: - explain_codeql_query with nonexistent relative path returns "does not exist" - explain_codeql_query with valid absolute path returns no warning - document_codeql_query with nonexistent path returns "does not exist" - Server lists prompts including explain_codeql_query Register the new test in esbuild.config.js so it is bundled for CI. Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Added in 50150ef. New file
The test follows the same real-server-spawn pattern as |
- Add resolvePromptFilePath() utility that resolves relative paths against workspace root and returns user-friendly warnings for invalid paths - Update all 9 prompt handlers with file path parameters to resolve paths and embed warnings in the response instead of throwing protocol errors - Add integration test in mcp-test-suite.js for explain_codeql_query with invalid path - Add file-based integration test fixtures in primitives/prompts/ - Add 10 unit tests for resolvePromptFilePath and handler path resolution Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
… assertions Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
…alid paths Add mcp-prompt-e2e.integration.test.ts to the VS Code extension test suite that spawns the real MCP server inside the Extension Development Host and verifies that prompts return user-friendly warnings (not protocol errors) when given invalid file paths: - explain_codeql_query with nonexistent relative path returns "does not exist" - explain_codeql_query with valid absolute path returns no warning - document_codeql_query with nonexistent path returns "does not exist" - Server lists prompts including explain_codeql_query Register the new test in esbuild.config.js so it is bundled for CI. Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
…f github.com:advanced-security/codeql-development-mcp-server into copilot/improve-error-handling-relative-path-support
Applies "npm install --workspaces" in order to update package-lock.json to correctly mark peer dependencies as '"peer": true'.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files
|
📝 Update Information
Primitive Details
✅ ALLOWED FILES:
server/src/**/*.ts)server/test/**/*.ts)client/src/**/*.js,client/integration-tests/**)extensions/vscode/test/suite/*.integration.test.ts)extensions/vscode/esbuild.config.js)🚫 FORBIDDEN FILES: None included.
🛑 MANDATORY PR VALIDATION CHECKLIST
Update Metadata
🎯 Changes Description
Current Behavior
Prompt handlers pass user-supplied file paths straight through as opaque strings. A relative or nonexistent path silently propagates into the LLM context, and in some cases triggers a cryptic MCP protocol error that only surfaces after the user has filled in all required and optional inputs.
Updated Behavior
All file path parameters are resolved against
getUserWorkspaceDir(). Invalid paths (empty, traversal, outside workspace, nonexistent) produce a⚠warning embedded in the prompt response — never a thrown exception.Motivation
VS Code slash commands should fail early with useful messages, and workspace-relative paths should just work.
🔄 Before vs. After Comparison
Functionality Changes
API Changes
No schema changes.
resolvePromptFilePathis a new exported utility:Output Format Changes
🧪 Testing & Validation
Test Coverage Updates
resolvePromptFilePath+ 4 handler-level tests + 4 extension integration testsValidation Scenarios
testGetPromptWithInvalidPathinmcp-test-suite.jsvalidates end-to-end via MCP clientmcp-prompt-e2e.integration.test.tsspawns the real MCP server inside the VS Code Extension Development Host and verifies prompts return warnings (not protocol errors) for invalid pathsTest Results
testGetPromptWithInvalidPathpasses; new extension e2e prompt tests pass📋 Implementation Details
Files Modified
server/src/prompts/workflow-prompts.ts— addedresolvePromptFilePath(), updated 9 handlersserver/test/src/prompts/workflow-prompts.test.ts— 10 new testsclient/src/lib/mcp-test-suite.js—testGetPromptWithInvalidPath()client/integration-tests/primitives/prompts/explain_codeql_query/invalid_query_path/extensions/vscode/test/suite/mcp-prompt-e2e.integration.test.ts— 4 e2e tests that spawn the real MCP server in the Extension Development Host and verify prompt error handlingextensions/vscode/esbuild.config.js— registered new test file for bundlingCode Changes Summary
Dependencies
path,fsfrom Node stdlib and existinggetUserWorkspaceDir🔍 Quality Improvements
Bug Fixes (if applicable)
resolvePromptFilePath()resolves relative paths and returns advisory warningsCode Quality Enhancements
resolvePromptFilePathis independently testable with workspace root injection🔗 References
Related Issues/PRs
🚀 Compatibility & Migration
Backward Compatibility
API Evolution
⚠messages replace protocol-level exceptions👥 Review Guidelines
For Reviewers
Testing Instructions
📊 Impact Assessment
Server Impact
resolvePromptFilePathruns per-requestexistsSynccall per path parameter (advisory only)AI Assistant Impact
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.