retestkit 1.4.1
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/.claude/commands/openspec/apply.md +23 -0
- package/.claude/commands/openspec/archive.md +27 -0
- package/.claude/commands/openspec/proposal.md +28 -0
- package/.gemini/commands/openspec/apply.toml +21 -0
- package/.gemini/commands/openspec/archive.toml +25 -0
- package/.gemini/commands/openspec/proposal.toml +26 -0
- package/.github/prompts/openspec-apply.prompt.md +22 -0
- package/.github/prompts/openspec-archive.prompt.md +26 -0
- package/.github/prompts/openspec-proposal.prompt.md +27 -0
- package/.github/workflows/release.yml +33 -0
- package/.kilocode/workflows/openspec-apply.md +17 -0
- package/.kilocode/workflows/openspec-archive.md +21 -0
- package/.kilocode/workflows/openspec-proposal.md +22 -0
- package/.mcp.json +23 -0
- package/.opencode/command/openspec-apply.md +25 -0
- package/.opencode/command/openspec-archive.md +28 -0
- package/.opencode/command/openspec-proposal.md +30 -0
- package/.roo/commands/openspec-apply.md +20 -0
- package/.roo/commands/openspec-archive.md +24 -0
- package/.roo/commands/openspec-proposal.md +25 -0
- package/.vscode/mcp.json +23 -0
- package/AGENTS.md +18 -0
- package/CLAUDE.md +18 -0
- package/LICENSE +65 -0
- package/README.md +303 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +27 -0
- package/dist/config.js.map +1 -0
- package/dist/elicitation/index.d.ts +17 -0
- package/dist/elicitation/index.d.ts.map +1 -0
- package/dist/elicitation/index.js +118 -0
- package/dist/elicitation/index.js.map +1 -0
- package/dist/elicitation/types.d.ts +35 -0
- package/dist/elicitation/types.d.ts.map +1 -0
- package/dist/elicitation/types.js +39 -0
- package/dist/elicitation/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle/index.d.ts +31 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/lifecycle/index.js +61 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/logger.d.ts +21 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +182 -0
- package/dist/logger.js.map +1 -0
- package/dist/playwright-client/index.d.ts +29 -0
- package/dist/playwright-client/index.d.ts.map +1 -0
- package/dist/playwright-client/index.js +288 -0
- package/dist/playwright-client/index.js.map +1 -0
- package/dist/playwright-client/types.d.ts +44 -0
- package/dist/playwright-client/types.d.ts.map +1 -0
- package/dist/playwright-client/types.js +49 -0
- package/dist/playwright-client/types.js.map +1 -0
- package/dist/progress/index.d.ts +39 -0
- package/dist/progress/index.d.ts.map +1 -0
- package/dist/progress/index.js +106 -0
- package/dist/progress/index.js.map +1 -0
- package/dist/progress/types.d.ts +24 -0
- package/dist/progress/types.d.ts.map +1 -0
- package/dist/progress/types.js +2 -0
- package/dist/progress/types.js.map +1 -0
- package/dist/prompts/index.d.ts +19 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +207 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/loader.d.ts +20 -0
- package/dist/prompts/loader.d.ts.map +1 -0
- package/dist/prompts/loader.js +47 -0
- package/dist/prompts/loader.js.map +1 -0
- package/dist/resources/index.d.ts +27 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +186 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/subscriptions.d.ts +10 -0
- package/dist/resources/subscriptions.d.ts.map +1 -0
- package/dist/resources/subscriptions.js +23 -0
- package/dist/resources/subscriptions.js.map +1 -0
- package/dist/sampling/index.d.ts +11 -0
- package/dist/sampling/index.d.ts.map +1 -0
- package/dist/sampling/index.js +201 -0
- package/dist/sampling/index.js.map +1 -0
- package/dist/sampling/prompts.d.ts +56 -0
- package/dist/sampling/prompts.d.ts.map +1 -0
- package/dist/sampling/prompts.js +124 -0
- package/dist/sampling/prompts.js.map +1 -0
- package/dist/sampling/types.d.ts +57 -0
- package/dist/sampling/types.d.ts.map +1 -0
- package/dist/sampling/types.js +2 -0
- package/dist/sampling/types.js.map +1 -0
- package/dist/schemas/config.d.ts +40 -0
- package/dist/schemas/config.d.ts.map +1 -0
- package/dist/schemas/config.js +30 -0
- package/dist/schemas/config.js.map +1 -0
- package/dist/security/index.d.ts +38 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +281 -0
- package/dist/security/index.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +142 -0
- package/dist/server.js.map +1 -0
- package/dist/test-utils/index.d.ts +6 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/index.js +6 -0
- package/dist/test-utils/index.js.map +1 -0
- package/dist/test-utils/mock-context.d.ts +64 -0
- package/dist/test-utils/mock-context.d.ts.map +1 -0
- package/dist/test-utils/mock-context.js +347 -0
- package/dist/test-utils/mock-context.js.map +1 -0
- package/dist/test-utils/mock-playwright-client.d.ts +62 -0
- package/dist/test-utils/mock-playwright-client.d.ts.map +1 -0
- package/dist/test-utils/mock-playwright-client.js +315 -0
- package/dist/test-utils/mock-playwright-client.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/webtest/crawl.d.ts +46 -0
- package/dist/tools/webtest/crawl.d.ts.map +1 -0
- package/dist/tools/webtest/crawl.js +678 -0
- package/dist/tools/webtest/crawl.js.map +1 -0
- package/dist/tools/webtest/discover-features.d.ts +30 -0
- package/dist/tools/webtest/discover-features.d.ts.map +1 -0
- package/dist/tools/webtest/discover-features.js +343 -0
- package/dist/tools/webtest/discover-features.js.map +1 -0
- package/dist/tools/webtest/discover-flows.d.ts +29 -0
- package/dist/tools/webtest/discover-flows.d.ts.map +1 -0
- package/dist/tools/webtest/discover-flows.js +341 -0
- package/dist/tools/webtest/discover-flows.js.map +1 -0
- package/dist/tools/webtest/generate-tests.d.ts +54 -0
- package/dist/tools/webtest/generate-tests.d.ts.map +1 -0
- package/dist/tools/webtest/generate-tests.js +364 -0
- package/dist/tools/webtest/generate-tests.js.map +1 -0
- package/dist/tools/webtest/index.d.ts +8 -0
- package/dist/tools/webtest/index.d.ts.map +1 -0
- package/dist/tools/webtest/index.js +8 -0
- package/dist/tools/webtest/index.js.map +1 -0
- package/dist/tools/webtest/run-test-case.d.ts +28 -0
- package/dist/tools/webtest/run-test-case.d.ts.map +1 -0
- package/dist/tools/webtest/run-test-case.js +420 -0
- package/dist/tools/webtest/run-test-case.js.map +1 -0
- package/dist/tools/webtest/schemas.d.ts +175 -0
- package/dist/tools/webtest/schemas.d.ts.map +1 -0
- package/dist/tools/webtest/schemas.js +156 -0
- package/dist/tools/webtest/schemas.js.map +1 -0
- package/dist/tools/webtest/start-analysis.d.ts +16 -0
- package/dist/tools/webtest/start-analysis.d.ts.map +1 -0
- package/dist/tools/webtest/start-analysis.js +137 -0
- package/dist/tools/webtest/start-analysis.js.map +1 -0
- package/dist/transports/http.d.ts +8 -0
- package/dist/transports/http.d.ts.map +1 -0
- package/dist/transports/http.js +9 -0
- package/dist/transports/http.js.map +1 -0
- package/dist/transports/index.d.ts +14 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/dist/transports/index.js +20 -0
- package/dist/transports/index.js.map +1 -0
- package/dist/transports/stdio.d.ts +4 -0
- package/dist/transports/stdio.d.ts.map +1 -0
- package/dist/transports/stdio.js +6 -0
- package/dist/transports/stdio.js.map +1 -0
- package/dist/types/capabilities.d.ts +18 -0
- package/dist/types/capabilities.d.ts.map +1 -0
- package/dist/types/capabilities.js +35 -0
- package/dist/types/capabilities.js.map +1 -0
- package/dist/types/context.d.ts +20 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/tool.d.ts +10 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +2 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/workspace/index.d.ts +99 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +648 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/markdown.d.ts +50 -0
- package/dist/workspace/markdown.d.ts.map +1 -0
- package/dist/workspace/markdown.js +210 -0
- package/dist/workspace/markdown.js.map +1 -0
- package/dist/workspace/types.d.ts +173 -0
- package/dist/workspace/types.d.ts.map +1 -0
- package/dist/workspace/types.js +2 -0
- package/dist/workspace/types.js.map +1 -0
- package/openspec/AGENTS.md +456 -0
- package/openspec/changes/archive/2025-12-18-add-hybrid-artifact-paths/proposal.md +33 -0
- package/openspec/changes/archive/2025-12-18-add-hybrid-artifact-paths/specs/webtest-resources/spec.md +27 -0
- package/openspec/changes/archive/2025-12-18-add-hybrid-artifact-paths/specs/webtest-tools/spec.md +304 -0
- package/openspec/changes/archive/2025-12-18-add-hybrid-artifact-paths/tasks.md +43 -0
- package/openspec/changes/archive/2025-12-18-add-mcp-server-foundation/design.md +209 -0
- package/openspec/changes/archive/2025-12-18-add-mcp-server-foundation/proposal.md +41 -0
- package/openspec/changes/archive/2025-12-18-add-mcp-server-foundation/specs/mcp-server-core/spec.md +183 -0
- package/openspec/changes/archive/2025-12-18-add-mcp-server-foundation/tasks.md +112 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/design.md +333 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/proposal.md +66 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/mcp-server-core/spec.md +129 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-lifecycle/spec.md +138 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-logging/spec.md +211 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-prompts/spec.md +157 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-resources/spec.md +213 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-sampling/spec.md +257 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-tools/spec.md +501 -0
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/tasks.md +264 -0
- package/openspec/changes/archive/2025-12-18-allow-analysis-of-incomplete-crawls/proposal.md +24 -0
- package/openspec/changes/archive/2025-12-18-allow-analysis-of-incomplete-crawls/specs/webtest-tools/spec.md +80 -0
- package/openspec/changes/archive/2025-12-18-allow-analysis-of-incomplete-crawls/tasks.md +8 -0
- package/openspec/changes/archive/2025-12-18-fix-crawl-loop-stability/design.md +90 -0
- package/openspec/changes/archive/2025-12-18-fix-crawl-loop-stability/proposal.md +28 -0
- package/openspec/changes/archive/2025-12-18-fix-crawl-loop-stability/specs/webtest-sampling/spec.md +90 -0
- package/openspec/changes/archive/2025-12-18-fix-crawl-loop-stability/tasks.md +33 -0
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/design.md +558 -0
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/proposal.md +119 -0
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/specs/webtest-resources/spec.md +109 -0
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/specs/webtest-tools/spec.md +121 -0
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/tasks.md +133 -0
- package/openspec/changes/extract-prompts-to-markdown/design.md +86 -0
- package/openspec/changes/extract-prompts-to-markdown/proposal.md +50 -0
- package/openspec/changes/extract-prompts-to-markdown/specs/webtest-prompts/spec.md +74 -0
- package/openspec/changes/extract-prompts-to-markdown/tasks.md +40 -0
- package/openspec/changes/refactor-webtest-naming/design.md +95 -0
- package/openspec/changes/refactor-webtest-naming/proposal.md +66 -0
- package/openspec/changes/refactor-webtest-naming/specs/webtest-prompts/spec.md +79 -0
- package/openspec/changes/refactor-webtest-naming/specs/webtest-resources/spec.md +80 -0
- package/openspec/changes/refactor-webtest-naming/specs/webtest-sampling/spec.md +122 -0
- package/openspec/changes/refactor-webtest-naming/specs/webtest-tools/spec.md +113 -0
- package/openspec/changes/refactor-webtest-naming/tasks.md +119 -0
- package/openspec/changes/rename-package-to-retest/proposal.md +52 -0
- package/openspec/changes/rename-package-to-retest/specs/mcp-server-core/spec.md +53 -0
- package/openspec/changes/rename-package-to-retest/specs/retest-lifecycle/spec.md +68 -0
- package/openspec/changes/rename-package-to-retest/specs/retest-logging/spec.md +35 -0
- package/openspec/changes/rename-package-to-retest/specs/retest-prompts/spec.md +159 -0
- package/openspec/changes/rename-package-to-retest/specs/retest-resources/spec.md +251 -0
- package/openspec/changes/rename-package-to-retest/specs/retest-sampling/spec.md +99 -0
- package/openspec/changes/rename-package-to-retest/specs/retest-tools/spec.md +295 -0
- package/openspec/changes/rename-package-to-retest/tasks.md +71 -0
- package/openspec/project.md +31 -0
- package/openspec/specs/mcp-server-core/spec.md +178 -0
- package/openspec/specs/webtest-lifecycle/spec.md +136 -0
- package/openspec/specs/webtest-logging/spec.md +209 -0
- package/openspec/specs/webtest-prompts/spec.md +155 -0
- package/openspec/specs/webtest-resources/spec.md +248 -0
- package/openspec/specs/webtest-sampling/spec.md +344 -0
- package/openspec/specs/webtest-tools/spec.md +282 -0
- package/package.json +54 -0
- package/release.config.js +9 -0
- package/src/config.test.ts +96 -0
- package/src/config.ts +32 -0
- package/src/elicitation/index.test.ts +399 -0
- package/src/elicitation/index.ts +171 -0
- package/src/elicitation/types.ts +68 -0
- package/src/index.ts +83 -0
- package/src/lifecycle/index.test.ts +260 -0
- package/src/lifecycle/index.ts +101 -0
- package/src/logger.redaction.test.ts +322 -0
- package/src/logger.test.ts +123 -0
- package/src/logger.ts +229 -0
- package/src/playwright-client/index.ts +392 -0
- package/src/playwright-client/types.ts +99 -0
- package/src/progress/index.test.ts +327 -0
- package/src/progress/index.ts +170 -0
- package/src/progress/types.ts +25 -0
- package/src/prompts/index.test.ts +451 -0
- package/src/prompts/index.ts +246 -0
- package/src/prompts/loader.test.ts +100 -0
- package/src/prompts/loader.ts +59 -0
- package/src/prompts/templates/mcp/webtest-crawl.md +7 -0
- package/src/prompts/templates/mcp/webtest-discover-flows.md +11 -0
- package/src/prompts/templates/mcp/webtest-discover.md +12 -0
- package/src/prompts/templates/mcp/webtest-full-workflow.md +12 -0
- package/src/prompts/templates/mcp/webtest-generate-tests.md +11 -0
- package/src/prompts/templates/mcp/webtest-run-test.md +11 -0
- package/src/prompts/templates/mcp/webtest-start.md +8 -0
- package/src/prompts/templates/sampling/crawl-action.md +35 -0
- package/src/prompts/templates/sampling/feature-discovery.md +27 -0
- package/src/prompts/templates/sampling/flow-discovery.md +29 -0
- package/src/prompts/templates/sampling/page-content-wrapper.md +5 -0
- package/src/prompts/templates/sampling/system-prefix.md +12 -0
- package/src/prompts/templates/sampling/test-evaluation.md +17 -0
- package/src/prompts/templates/sampling/test-generation.md +31 -0
- package/src/resources/index.ts +250 -0
- package/src/resources/subscriptions.ts +37 -0
- package/src/sampling/index.test.ts +414 -0
- package/src/sampling/index.ts +286 -0
- package/src/sampling/prompts.ts +194 -0
- package/src/sampling/types.ts +60 -0
- package/src/schemas/config.ts +39 -0
- package/src/security/index.test.ts +441 -0
- package/src/security/index.ts +361 -0
- package/src/security/security-scenarios.test.ts +468 -0
- package/src/server.ts +211 -0
- package/src/test-utils/index.ts +6 -0
- package/src/test-utils/mock-context.ts +426 -0
- package/src/test-utils/mock-playwright-client.ts +422 -0
- package/src/tools/index.ts +11 -0
- package/src/tools/webtest/crawl.test.ts +834 -0
- package/src/tools/webtest/crawl.ts +901 -0
- package/src/tools/webtest/discover-features.ts +412 -0
- package/src/tools/webtest/discover-flows.ts +408 -0
- package/src/tools/webtest/generate-tests.test.ts +532 -0
- package/src/tools/webtest/generate-tests.ts +425 -0
- package/src/tools/webtest/index.ts +7 -0
- package/src/tools/webtest/integration.test.ts +536 -0
- package/src/tools/webtest/run-test-case.test.ts +659 -0
- package/src/tools/webtest/run-test-case.ts +508 -0
- package/src/tools/webtest/schemas.ts +201 -0
- package/src/tools/webtest/start-analysis.test.ts +151 -0
- package/src/tools/webtest/start-analysis.ts +158 -0
- package/src/transports/http.ts +19 -0
- package/src/transports/index.ts +30 -0
- package/src/transports/stdio.ts +7 -0
- package/src/types/capabilities.test.ts +193 -0
- package/src/types/capabilities.ts +50 -0
- package/src/types/context.ts +21 -0
- package/src/types/tool.ts +11 -0
- package/src/workspace/index.ts +945 -0
- package/src/workspace/markdown.ts +272 -0
- package/src/workspace/types.ts +186 -0
- package/tests/integration/server.test.ts +89 -0
- package/tests/integration/tools.test.ts +99 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +9 -0
- package/vitest.integration.config.ts +10 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createServer as createHttpServer } from "node:http";
|
|
3
|
+
import { loadConfig } from "./config.js";
|
|
4
|
+
import { createLogger } from "./logger.js";
|
|
5
|
+
import { createServer } from "./server.js";
|
|
6
|
+
import { createTransport } from "./transports/index.js";
|
|
7
|
+
|
|
8
|
+
async function main(): Promise<void> {
|
|
9
|
+
// Load and validate configuration
|
|
10
|
+
let config;
|
|
11
|
+
try {
|
|
12
|
+
config = loadConfig();
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error(
|
|
15
|
+
"Configuration error:",
|
|
16
|
+
error instanceof Error ? error.message : error
|
|
17
|
+
);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const logger = createLogger(config.logLevel);
|
|
22
|
+
logger.info("Starting server", { transport: config.transport });
|
|
23
|
+
|
|
24
|
+
// Create MCP server with all components
|
|
25
|
+
const { server, cleanup } = createServer(config, logger);
|
|
26
|
+
|
|
27
|
+
// Create transport based on configuration
|
|
28
|
+
const transportResult = createTransport(config, logger);
|
|
29
|
+
|
|
30
|
+
// Set up graceful shutdown
|
|
31
|
+
const shutdown = async (signal: string) => {
|
|
32
|
+
logger.info("Received shutdown signal", { signal });
|
|
33
|
+
try {
|
|
34
|
+
await cleanup();
|
|
35
|
+
await server.close();
|
|
36
|
+
logger.info("Server closed gracefully");
|
|
37
|
+
process.exit(0);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
logger.error("Error during shutdown", {
|
|
40
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
41
|
+
});
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
47
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
48
|
+
|
|
49
|
+
// Connect based on transport type
|
|
50
|
+
if (transportResult.type === "stdio") {
|
|
51
|
+
await server.connect(transportResult.transport);
|
|
52
|
+
logger.info("Server connected via stdio");
|
|
53
|
+
} else {
|
|
54
|
+
// HTTP transport requires an HTTP server
|
|
55
|
+
const httpServer = createHttpServer(async (req, res) => {
|
|
56
|
+
// Handle MCP requests
|
|
57
|
+
if (req.method === "POST") {
|
|
58
|
+
await transportResult.transport.handleRequest(req, res);
|
|
59
|
+
} else if (req.method === "GET") {
|
|
60
|
+
// Health check endpoint
|
|
61
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
62
|
+
res.end(JSON.stringify({ status: "ok" }));
|
|
63
|
+
} else {
|
|
64
|
+
res.writeHead(405);
|
|
65
|
+
res.end();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await server.connect(transportResult.transport);
|
|
70
|
+
|
|
71
|
+
httpServer.listen(transportResult.port, () => {
|
|
72
|
+
logger.info("Server listening", {
|
|
73
|
+
transport: "http",
|
|
74
|
+
port: transportResult.port,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main().catch((error) => {
|
|
81
|
+
console.error("Fatal error:", error);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
parseClientCapabilities,
|
|
4
|
+
getServerCapabilities,
|
|
5
|
+
checkCapability,
|
|
6
|
+
REQUIRED_PROTOCOL_VERSION,
|
|
7
|
+
type InitializeResult,
|
|
8
|
+
} from "./index.js";
|
|
9
|
+
import type { Logger } from "../logger.js";
|
|
10
|
+
|
|
11
|
+
describe("lifecycle", () => {
|
|
12
|
+
let mockLogger: Logger;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
mockLogger = {
|
|
16
|
+
debug: vi.fn(),
|
|
17
|
+
info: vi.fn(),
|
|
18
|
+
warn: vi.fn(),
|
|
19
|
+
error: vi.fn(),
|
|
20
|
+
setLevel: vi.fn(),
|
|
21
|
+
withCorrelation: vi.fn().mockReturnThis(),
|
|
22
|
+
} as unknown as Logger;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("parseClientCapabilities", () => {
|
|
26
|
+
it("parses full capabilities correctly", () => {
|
|
27
|
+
const initResult: InitializeResult = {
|
|
28
|
+
protocolVersion: "2025-06-18",
|
|
29
|
+
capabilities: {
|
|
30
|
+
sampling: {},
|
|
31
|
+
elicitation: {},
|
|
32
|
+
logging: {},
|
|
33
|
+
resources: {
|
|
34
|
+
listChanged: true,
|
|
35
|
+
subscribe: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
clientInfo: {
|
|
39
|
+
name: "TestClient",
|
|
40
|
+
version: "1.0.0",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const caps = parseClientCapabilities(initResult, mockLogger);
|
|
45
|
+
|
|
46
|
+
expect(caps.sampling).toBe(true);
|
|
47
|
+
expect(caps.elicitation).toBe(true);
|
|
48
|
+
expect(caps.logging).toBe(true);
|
|
49
|
+
expect(caps.resourcesListChanged).toBe(true);
|
|
50
|
+
expect(caps.resourcesSubscribe).toBe(true);
|
|
51
|
+
expect(caps.progress).toBe(true); // Linked to sampling
|
|
52
|
+
expect(caps.protocolVersion).toBe("2025-06-18");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("handles missing capabilities", () => {
|
|
56
|
+
const initResult: InitializeResult = {
|
|
57
|
+
protocolVersion: "2025-06-18",
|
|
58
|
+
capabilities: {},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const caps = parseClientCapabilities(initResult, mockLogger);
|
|
62
|
+
|
|
63
|
+
expect(caps.sampling).toBe(false);
|
|
64
|
+
expect(caps.elicitation).toBe(false);
|
|
65
|
+
expect(caps.logging).toBe(false);
|
|
66
|
+
expect(caps.resourcesListChanged).toBe(false);
|
|
67
|
+
expect(caps.resourcesSubscribe).toBe(false);
|
|
68
|
+
expect(caps.progress).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("disables elicitation for older protocol versions", () => {
|
|
72
|
+
const initResult: InitializeResult = {
|
|
73
|
+
protocolVersion: "2024-12-01",
|
|
74
|
+
capabilities: {
|
|
75
|
+
sampling: {},
|
|
76
|
+
elicitation: {},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const caps = parseClientCapabilities(initResult, mockLogger);
|
|
81
|
+
|
|
82
|
+
expect(caps.sampling).toBe(true);
|
|
83
|
+
expect(caps.elicitation).toBe(false); // Disabled due to old protocol
|
|
84
|
+
expect(mockLogger.warn).toHaveBeenCalledWith(
|
|
85
|
+
"Running in degraded mode due to older protocol version",
|
|
86
|
+
expect.any(Object)
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("enables elicitation for required protocol version", () => {
|
|
91
|
+
const initResult: InitializeResult = {
|
|
92
|
+
protocolVersion: REQUIRED_PROTOCOL_VERSION,
|
|
93
|
+
capabilities: {
|
|
94
|
+
elicitation: {},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const caps = parseClientCapabilities(initResult, mockLogger);
|
|
99
|
+
|
|
100
|
+
expect(caps.elicitation).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("enables elicitation for newer protocol versions", () => {
|
|
104
|
+
const initResult: InitializeResult = {
|
|
105
|
+
protocolVersion: "2025-12-01",
|
|
106
|
+
capabilities: {
|
|
107
|
+
elicitation: {},
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const caps = parseClientCapabilities(initResult, mockLogger);
|
|
112
|
+
|
|
113
|
+
expect(caps.elicitation).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("links progress to sampling capability", () => {
|
|
117
|
+
const withSampling: InitializeResult = {
|
|
118
|
+
protocolVersion: "2025-06-18",
|
|
119
|
+
capabilities: { sampling: {} },
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const withoutSampling: InitializeResult = {
|
|
123
|
+
protocolVersion: "2025-06-18",
|
|
124
|
+
capabilities: {},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const capsWithSampling = parseClientCapabilities(withSampling, mockLogger);
|
|
128
|
+
const capsWithoutSampling = parseClientCapabilities(
|
|
129
|
+
withoutSampling,
|
|
130
|
+
mockLogger
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(capsWithSampling.progress).toBe(true);
|
|
134
|
+
expect(capsWithoutSampling.progress).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("handles missing protocolVersion", () => {
|
|
138
|
+
const initResult: InitializeResult = {
|
|
139
|
+
protocolVersion: "",
|
|
140
|
+
capabilities: {},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const caps = parseClientCapabilities(initResult, mockLogger);
|
|
144
|
+
|
|
145
|
+
// Empty string is treated as falsy and defaults to "unknown"
|
|
146
|
+
expect(caps.protocolVersion).toBe("unknown");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("logs warning when sampling unavailable", () => {
|
|
150
|
+
const initResult: InitializeResult = {
|
|
151
|
+
protocolVersion: "2025-06-18",
|
|
152
|
+
capabilities: {},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
parseClientCapabilities(initResult, mockLogger);
|
|
156
|
+
|
|
157
|
+
expect(mockLogger.warn).toHaveBeenCalledWith(
|
|
158
|
+
"Sampling not available - AI-powered features will use fallback mode",
|
|
159
|
+
expect.any(Object)
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("logs info when elicitation unavailable", () => {
|
|
164
|
+
const initResult: InitializeResult = {
|
|
165
|
+
protocolVersion: "2025-06-18",
|
|
166
|
+
capabilities: { sampling: {} },
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
parseClientCapabilities(initResult, mockLogger);
|
|
170
|
+
|
|
171
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
172
|
+
"Elicitation not available - user decisions via tool output",
|
|
173
|
+
expect.any(Object)
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("logs detected capabilities", () => {
|
|
178
|
+
const initResult: InitializeResult = {
|
|
179
|
+
protocolVersion: "2025-06-18",
|
|
180
|
+
capabilities: {
|
|
181
|
+
sampling: {},
|
|
182
|
+
logging: {},
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
parseClientCapabilities(initResult, mockLogger);
|
|
187
|
+
|
|
188
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
189
|
+
"Client capabilities detected",
|
|
190
|
+
expect.objectContaining({
|
|
191
|
+
sampling: true,
|
|
192
|
+
logging: true,
|
|
193
|
+
})
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe("getServerCapabilities", () => {
|
|
199
|
+
it("returns correct server capabilities", () => {
|
|
200
|
+
const caps = getServerCapabilities();
|
|
201
|
+
|
|
202
|
+
expect(caps).toEqual({
|
|
203
|
+
tools: {},
|
|
204
|
+
resources: {
|
|
205
|
+
listChanged: true,
|
|
206
|
+
subscribe: true,
|
|
207
|
+
},
|
|
208
|
+
prompts: {},
|
|
209
|
+
logging: {},
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("advertises resource capabilities", () => {
|
|
214
|
+
const caps = getServerCapabilities();
|
|
215
|
+
|
|
216
|
+
expect(caps.resources.listChanged).toBe(true);
|
|
217
|
+
expect(caps.resources.subscribe).toBe(true);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe("checkCapability", () => {
|
|
222
|
+
it("returns true for enabled capabilities", () => {
|
|
223
|
+
const caps = {
|
|
224
|
+
sampling: true,
|
|
225
|
+
elicitation: true,
|
|
226
|
+
logging: false,
|
|
227
|
+
progress: true,
|
|
228
|
+
resourcesListChanged: false,
|
|
229
|
+
resourcesSubscribe: false,
|
|
230
|
+
protocolVersion: "2025-06-18",
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
expect(checkCapability(caps, "sampling")).toBe(true);
|
|
234
|
+
expect(checkCapability(caps, "elicitation")).toBe(true);
|
|
235
|
+
expect(checkCapability(caps, "progress")).toBe(true);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("returns false for disabled capabilities", () => {
|
|
239
|
+
const caps = {
|
|
240
|
+
sampling: false,
|
|
241
|
+
elicitation: false,
|
|
242
|
+
logging: false,
|
|
243
|
+
progress: false,
|
|
244
|
+
resourcesListChanged: false,
|
|
245
|
+
resourcesSubscribe: false,
|
|
246
|
+
protocolVersion: "2025-06-18",
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
expect(checkCapability(caps, "sampling")).toBe(false);
|
|
250
|
+
expect(checkCapability(caps, "elicitation")).toBe(false);
|
|
251
|
+
expect(checkCapability(caps, "logging")).toBe(false);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe("REQUIRED_PROTOCOL_VERSION", () => {
|
|
256
|
+
it("is set to expected version", () => {
|
|
257
|
+
expect(REQUIRED_PROTOCOL_VERSION).toBe("2025-06-18");
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Logger } from "../logger.js";
|
|
2
|
+
import {
|
|
3
|
+
type ClientCapabilities,
|
|
4
|
+
DEFAULT_CAPABILITIES,
|
|
5
|
+
} from "../types/capabilities.js";
|
|
6
|
+
|
|
7
|
+
export const REQUIRED_PROTOCOL_VERSION = "2025-06-18";
|
|
8
|
+
|
|
9
|
+
export interface InitializeResult {
|
|
10
|
+
protocolVersion: string;
|
|
11
|
+
capabilities: {
|
|
12
|
+
sampling?: Record<string, unknown>;
|
|
13
|
+
elicitation?: Record<string, unknown>;
|
|
14
|
+
logging?: Record<string, unknown>;
|
|
15
|
+
resources?: {
|
|
16
|
+
listChanged?: boolean;
|
|
17
|
+
subscribe?: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
clientInfo?: {
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function parseClientCapabilities(
|
|
27
|
+
initResult: InitializeResult,
|
|
28
|
+
logger: Logger
|
|
29
|
+
): ClientCapabilities {
|
|
30
|
+
const caps = initResult.capabilities || {};
|
|
31
|
+
const protocolVersion = initResult.protocolVersion || "unknown";
|
|
32
|
+
|
|
33
|
+
const clientCaps: ClientCapabilities = {
|
|
34
|
+
...DEFAULT_CAPABILITIES,
|
|
35
|
+
protocolVersion,
|
|
36
|
+
sampling: !!caps.sampling,
|
|
37
|
+
logging: !!caps.logging,
|
|
38
|
+
resourcesListChanged: !!caps.resources?.listChanged,
|
|
39
|
+
resourcesSubscribe: !!caps.resources?.subscribe,
|
|
40
|
+
// Elicitation requires protocol version 2025-06-18+
|
|
41
|
+
elicitation:
|
|
42
|
+
!!caps.elicitation && protocolVersion >= REQUIRED_PROTOCOL_VERSION,
|
|
43
|
+
// Progress is typically available if sampling is available
|
|
44
|
+
progress: !!caps.sampling,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Log capability detection
|
|
48
|
+
logger.info("Client capabilities detected", {
|
|
49
|
+
protocolVersion,
|
|
50
|
+
sampling: clientCaps.sampling,
|
|
51
|
+
elicitation: clientCaps.elicitation,
|
|
52
|
+
logging: clientCaps.logging,
|
|
53
|
+
resourcesListChanged: clientCaps.resourcesListChanged,
|
|
54
|
+
resourcesSubscribe: clientCaps.resourcesSubscribe,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Warn about degraded mode
|
|
58
|
+
if (protocolVersion < REQUIRED_PROTOCOL_VERSION) {
|
|
59
|
+
logger.warn("Running in degraded mode due to older protocol version", {
|
|
60
|
+
clientVersion: protocolVersion,
|
|
61
|
+
requiredVersion: REQUIRED_PROTOCOL_VERSION,
|
|
62
|
+
disabledFeatures: ["elicitation"],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!clientCaps.sampling) {
|
|
67
|
+
logger.warn(
|
|
68
|
+
"Sampling not available - AI-powered features will use fallback mode",
|
|
69
|
+
{
|
|
70
|
+
fallbackBehavior: "manual prompts via resources",
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!clientCaps.elicitation) {
|
|
76
|
+
logger.info("Elicitation not available - user decisions via tool output", {
|
|
77
|
+
fallbackBehavior: "questions in tool response",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return clientCaps;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function getServerCapabilities() {
|
|
85
|
+
return {
|
|
86
|
+
tools: {},
|
|
87
|
+
resources: {
|
|
88
|
+
listChanged: true,
|
|
89
|
+
subscribe: true,
|
|
90
|
+
},
|
|
91
|
+
prompts: {},
|
|
92
|
+
logging: {},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function checkCapability(
|
|
97
|
+
caps: ClientCapabilities,
|
|
98
|
+
capability: keyof Omit<ClientCapabilities, "protocolVersion">
|
|
99
|
+
): boolean {
|
|
100
|
+
return caps[capability];
|
|
101
|
+
}
|