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
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock context utilities for testing webtest tools
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { vi } from "vitest";
|
|
6
|
+
import type { Logger } from "../logger.js";
|
|
7
|
+
import type { Config } from "../schemas/config.js";
|
|
8
|
+
import type { ClientCapabilities } from "../types/capabilities.js";
|
|
9
|
+
import type { WorkspaceManager } from "../workspace/index.js";
|
|
10
|
+
import type { ResourceManager } from "../resources/index.js";
|
|
11
|
+
import type { SamplingClient } from "../sampling/index.js";
|
|
12
|
+
import type { ElicitationClient } from "../elicitation/index.js";
|
|
13
|
+
import type { ProgressEmitter, CancellationRegistry } from "../progress/index.js";
|
|
14
|
+
import type { SecurityValidator } from "../security/index.js";
|
|
15
|
+
import type { PlaywrightClient } from "../playwright-client/index.js";
|
|
16
|
+
import {
|
|
17
|
+
createMockPlaywrightClient,
|
|
18
|
+
createEcommerceMock,
|
|
19
|
+
type MockPlaywrightClient,
|
|
20
|
+
} from "./mock-playwright-client.js";
|
|
21
|
+
|
|
22
|
+
// MockContext interface is defined at the end of the file
|
|
23
|
+
|
|
24
|
+
export function createMockLogger(): Logger {
|
|
25
|
+
return {
|
|
26
|
+
debug: vi.fn(),
|
|
27
|
+
info: vi.fn(),
|
|
28
|
+
warn: vi.fn(),
|
|
29
|
+
error: vi.fn(),
|
|
30
|
+
setLevel: vi.fn(),
|
|
31
|
+
withCorrelation: vi.fn().mockReturnThis(),
|
|
32
|
+
} as unknown as Logger;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function createMockConfig(overrides: Partial<Config> = {}): Config {
|
|
36
|
+
return {
|
|
37
|
+
transport: "stdio" as const,
|
|
38
|
+
port: 3000,
|
|
39
|
+
logLevel: "info" as const,
|
|
40
|
+
workspaceDir: "/tmp/webtest-workspaces",
|
|
41
|
+
playwrightMcpCommand: "npx",
|
|
42
|
+
playwrightMcpArgs: ["@playwright/mcp@latest"],
|
|
43
|
+
checkpointInterval: 5,
|
|
44
|
+
screenshotFormat: "png" as const,
|
|
45
|
+
screenshotQuality: 80,
|
|
46
|
+
defaultMaxSteps: 50,
|
|
47
|
+
defaultMaxMinutes: 30,
|
|
48
|
+
defaultMaxPages: 20,
|
|
49
|
+
...overrides,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createMockCapabilities(
|
|
54
|
+
overrides: Partial<ClientCapabilities> = {}
|
|
55
|
+
): ClientCapabilities {
|
|
56
|
+
return {
|
|
57
|
+
sampling: true,
|
|
58
|
+
elicitation: true,
|
|
59
|
+
logging: true,
|
|
60
|
+
progress: true,
|
|
61
|
+
resourcesListChanged: true,
|
|
62
|
+
resourcesSubscribe: true,
|
|
63
|
+
protocolVersion: "2025-06-18",
|
|
64
|
+
...overrides,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function createMockWorkspaceManager(): WorkspaceManager {
|
|
69
|
+
const workspaces: Map<string, any> = new Map();
|
|
70
|
+
const crawls: Map<string, any> = new Map();
|
|
71
|
+
const runs: Map<string, any> = new Map();
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
createWorkspace: vi.fn().mockImplementation(async (params) => {
|
|
75
|
+
const analysisId = `analysis-${Date.now()}`;
|
|
76
|
+
const workspacePath = `/tmp/webtest-workspaces/${analysisId}`;
|
|
77
|
+
workspaces.set(analysisId, {
|
|
78
|
+
analysisId,
|
|
79
|
+
url: params.url,
|
|
80
|
+
domain: new URL(params.url).hostname,
|
|
81
|
+
focus: params.focus,
|
|
82
|
+
createdAt: new Date().toISOString(),
|
|
83
|
+
updatedAt: new Date().toISOString(),
|
|
84
|
+
status: "active",
|
|
85
|
+
limits: params.limits,
|
|
86
|
+
crawls: [],
|
|
87
|
+
runs: [],
|
|
88
|
+
});
|
|
89
|
+
return { analysisId, workspacePath };
|
|
90
|
+
}),
|
|
91
|
+
|
|
92
|
+
getWorkspacePath: vi.fn().mockImplementation((analysisId) => {
|
|
93
|
+
return `/tmp/webtest-workspaces/${analysisId}`;
|
|
94
|
+
}),
|
|
95
|
+
|
|
96
|
+
workspaceExists: vi.fn().mockImplementation(async (analysisId) => {
|
|
97
|
+
return workspaces.has(analysisId);
|
|
98
|
+
}),
|
|
99
|
+
|
|
100
|
+
readWorkspaceIndex: vi.fn().mockImplementation(async (analysisId) => {
|
|
101
|
+
const workspace = workspaces.get(analysisId);
|
|
102
|
+
if (!workspace) throw new Error(`Workspace ${analysisId} not found`);
|
|
103
|
+
return workspace;
|
|
104
|
+
}),
|
|
105
|
+
|
|
106
|
+
updateWorkspaceIndex: vi.fn().mockImplementation(async (analysisId, update) => {
|
|
107
|
+
const workspace = workspaces.get(analysisId);
|
|
108
|
+
if (workspace) {
|
|
109
|
+
Object.assign(workspace, update, { updatedAt: new Date().toISOString() });
|
|
110
|
+
}
|
|
111
|
+
}),
|
|
112
|
+
|
|
113
|
+
createCrawl: vi.fn().mockImplementation(async (analysisId, params) => {
|
|
114
|
+
const crawlId = `crawl-${Date.now()}`;
|
|
115
|
+
const crawlPath = `/tmp/webtest-workspaces/${analysisId}/crawls/${crawlId}`;
|
|
116
|
+
const crawlIndex = {
|
|
117
|
+
crawlId,
|
|
118
|
+
analysisId,
|
|
119
|
+
goal: params.goal,
|
|
120
|
+
strategy: params.strategy,
|
|
121
|
+
status: "in_progress",
|
|
122
|
+
startedAt: new Date().toISOString(),
|
|
123
|
+
budget: {
|
|
124
|
+
...params.limits,
|
|
125
|
+
stepsUsed: 0,
|
|
126
|
+
pagesVisited: 0,
|
|
127
|
+
},
|
|
128
|
+
pages: [],
|
|
129
|
+
actionHistory: [],
|
|
130
|
+
loopDetection: {
|
|
131
|
+
domSignatures: {},
|
|
132
|
+
urlVisits: {},
|
|
133
|
+
recentActions: [],
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
crawls.set(`${analysisId}:${crawlId}`, crawlIndex);
|
|
137
|
+
|
|
138
|
+
// Update workspace
|
|
139
|
+
const workspace = workspaces.get(analysisId);
|
|
140
|
+
if (workspace) {
|
|
141
|
+
workspace.crawls.push({
|
|
142
|
+
crawlId,
|
|
143
|
+
goal: params.goal,
|
|
144
|
+
status: "in_progress",
|
|
145
|
+
startedAt: crawlIndex.startedAt,
|
|
146
|
+
pagesVisited: 0,
|
|
147
|
+
stepsExecuted: 0,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return { crawlId, crawlPath };
|
|
152
|
+
}),
|
|
153
|
+
|
|
154
|
+
getCrawlPath: vi.fn().mockImplementation((analysisId, crawlId) => {
|
|
155
|
+
return `/tmp/webtest-workspaces/${analysisId}/crawls/${crawlId}`;
|
|
156
|
+
}),
|
|
157
|
+
|
|
158
|
+
readCrawlIndex: vi.fn().mockImplementation(async (analysisId, crawlId) => {
|
|
159
|
+
const crawl = crawls.get(`${analysisId}:${crawlId}`);
|
|
160
|
+
if (!crawl) throw new Error(`Crawl ${crawlId} not found`);
|
|
161
|
+
return crawl;
|
|
162
|
+
}),
|
|
163
|
+
|
|
164
|
+
updateCrawlIndex: vi.fn().mockImplementation(async (analysisId, crawlId, update) => {
|
|
165
|
+
const crawl = crawls.get(`${analysisId}:${crawlId}`);
|
|
166
|
+
if (crawl) {
|
|
167
|
+
Object.assign(crawl, update);
|
|
168
|
+
}
|
|
169
|
+
}),
|
|
170
|
+
|
|
171
|
+
savePage: vi.fn().mockImplementation(async (analysisId, crawlId, page) => {
|
|
172
|
+
const pageId = `page-${Date.now()}`;
|
|
173
|
+
const pagesDir = `/tmp/webtest-workspaces/${analysisId}/crawls/${crawlId}/pages/${pageId}`;
|
|
174
|
+
const pageRef = {
|
|
175
|
+
pageId,
|
|
176
|
+
url: page.url,
|
|
177
|
+
title: page.title,
|
|
178
|
+
capturedAt: new Date().toISOString(),
|
|
179
|
+
snapshotFilePath: `${pagesDir}/snapshot.json`,
|
|
180
|
+
snapshotUri: `webtest://${analysisId}/crawls/${crawlId}/pages/${pageId}/snapshot.json`,
|
|
181
|
+
screenshotFilePath: `${pagesDir}/screenshot.png`,
|
|
182
|
+
screenshotUri: `webtest://${analysisId}/crawls/${crawlId}/pages/${pageId}/screenshot.png`,
|
|
183
|
+
domFilePath: `${pagesDir}/dom.html`,
|
|
184
|
+
domUri: `webtest://${analysisId}/crawls/${crawlId}/pages/${pageId}/dom.html`,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const crawl = crawls.get(`${analysisId}:${crawlId}`);
|
|
188
|
+
if (crawl) {
|
|
189
|
+
crawl.pages.push(pageRef);
|
|
190
|
+
crawl.budget.pagesVisited = crawl.pages.length;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return pageRef;
|
|
194
|
+
}),
|
|
195
|
+
|
|
196
|
+
saveCheckpoint: vi.fn().mockResolvedValue(undefined),
|
|
197
|
+
loadCheckpoint: vi.fn().mockResolvedValue(null),
|
|
198
|
+
recordAction: vi.fn().mockResolvedValue(undefined),
|
|
199
|
+
saveAnalysis: vi.fn().mockImplementation(async (analysisId) => ({
|
|
200
|
+
appAnalysisFilePath: `/tmp/webtest-workspaces/${analysisId}/analysis/app-analysis.md`,
|
|
201
|
+
appAnalysisUri: `webtest://${analysisId}/analysis/app-analysis.md`,
|
|
202
|
+
flowsFilePath: `/tmp/webtest-workspaces/${analysisId}/analysis/flows.md`,
|
|
203
|
+
flowsUri: `webtest://${analysisId}/analysis/flows.md`,
|
|
204
|
+
})),
|
|
205
|
+
saveTests: vi.fn().mockImplementation(async (analysisId, tests) => ({
|
|
206
|
+
testsFilePath: `/tmp/webtest-workspaces/${analysisId}/tests/tests.md`,
|
|
207
|
+
testsUri: `webtest://${analysisId}/tests/tests.md`,
|
|
208
|
+
testCount: (tests.frontmatter as any)?.tests?.length || 0,
|
|
209
|
+
})),
|
|
210
|
+
createTestRun: vi.fn().mockImplementation(async (analysisId, params) => {
|
|
211
|
+
const runId = `run-${Date.now()}`;
|
|
212
|
+
const runPath = `/tmp/webtest-workspaces/${analysisId}/runs/${runId}`;
|
|
213
|
+
runs.set(`${analysisId}:${runId}`, {
|
|
214
|
+
runId,
|
|
215
|
+
analysisId,
|
|
216
|
+
testCaseId: params.testCaseId,
|
|
217
|
+
testName: params.testName,
|
|
218
|
+
status: "in_progress",
|
|
219
|
+
startedAt: new Date().toISOString(),
|
|
220
|
+
steps: [],
|
|
221
|
+
});
|
|
222
|
+
return { runId, runPath };
|
|
223
|
+
}),
|
|
224
|
+
getTestRunPath: vi.fn().mockImplementation((analysisId, runId) => {
|
|
225
|
+
return `/tmp/webtest-workspaces/${analysisId}/runs/${runId}`;
|
|
226
|
+
}),
|
|
227
|
+
readTestRunIndex: vi.fn().mockImplementation(async (analysisId, runId) => {
|
|
228
|
+
const run = runs.get(`${analysisId}:${runId}`);
|
|
229
|
+
if (!run) throw new Error(`Run ${runId} not found`);
|
|
230
|
+
return run;
|
|
231
|
+
}),
|
|
232
|
+
updateTestRunIndex: vi.fn().mockResolvedValue(undefined),
|
|
233
|
+
saveTestStepEvidence: vi.fn().mockImplementation(async (analysisId, runId, stepNumber) => ({
|
|
234
|
+
screenshotFilePath: `/tmp/webtest-workspaces/${analysisId}/runs/${runId}/steps/${stepNumber}/screenshot.png`,
|
|
235
|
+
screenshotUri: `webtest://${analysisId}/runs/${runId}/steps/${stepNumber}/screenshot.png`,
|
|
236
|
+
snapshotFilePath: `/tmp/webtest-workspaces/${analysisId}/runs/${runId}/steps/${stepNumber}/snapshot.json`,
|
|
237
|
+
snapshotUri: `webtest://${analysisId}/runs/${runId}/steps/${stepNumber}/snapshot.json`,
|
|
238
|
+
})),
|
|
239
|
+
listWorkspaces: vi.fn().mockResolvedValue([]),
|
|
240
|
+
} as unknown as WorkspaceManager;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function createMockResourceManager(): ResourceManager & { [key: string]: any } {
|
|
244
|
+
return {
|
|
245
|
+
notifyListChanged: vi.fn(),
|
|
246
|
+
notifyResourceUpdated: vi.fn(),
|
|
247
|
+
readResource: vi.fn().mockResolvedValue({
|
|
248
|
+
text: JSON.stringify({
|
|
249
|
+
url: "https://shop.example.com",
|
|
250
|
+
title: "Mock Page",
|
|
251
|
+
content: "<html><body>Mock content</body></html>",
|
|
252
|
+
}),
|
|
253
|
+
}),
|
|
254
|
+
} as unknown as ResourceManager;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function createMockSamplingClient(
|
|
258
|
+
responseGenerator?: (
|
|
259
|
+
systemPrompt: string,
|
|
260
|
+
userPrompt: string
|
|
261
|
+
) => unknown
|
|
262
|
+
): SamplingClient {
|
|
263
|
+
return {
|
|
264
|
+
hasSampling: vi.fn().mockReturnValue(true),
|
|
265
|
+
createMessage: vi.fn().mockImplementation(async (options) => {
|
|
266
|
+
if (responseGenerator) {
|
|
267
|
+
const data = responseGenerator(options.systemPrompt, options.userPrompt);
|
|
268
|
+
return { success: true, data, rawResponse: JSON.stringify(data) };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Default: return a simple action
|
|
272
|
+
return {
|
|
273
|
+
success: true,
|
|
274
|
+
data: {
|
|
275
|
+
actions: [],
|
|
276
|
+
reasoning: "Mock response",
|
|
277
|
+
goalProgress: "Making progress",
|
|
278
|
+
goalComplete: false,
|
|
279
|
+
},
|
|
280
|
+
rawResponse: "{}",
|
|
281
|
+
};
|
|
282
|
+
}),
|
|
283
|
+
} as unknown as SamplingClient;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function createMockElicitationClient(): ElicitationClient {
|
|
287
|
+
return {
|
|
288
|
+
hasElicitation: vi.fn().mockReturnValue(true),
|
|
289
|
+
elicit: vi.fn().mockResolvedValue({ success: true, selectedValue: "accept" }),
|
|
290
|
+
createCookieConsentRequest: vi.fn(),
|
|
291
|
+
createModalBlockingRequest: vi.fn(),
|
|
292
|
+
createAmbiguousNavigationRequest: vi.fn(),
|
|
293
|
+
createAuthRequiredRequest: vi.fn(),
|
|
294
|
+
} as unknown as ElicitationClient;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function createMockProgressEmitter(): ProgressEmitter {
|
|
298
|
+
return {
|
|
299
|
+
emit: vi.fn(),
|
|
300
|
+
hasProgress: vi.fn().mockReturnValue(true),
|
|
301
|
+
} as unknown as ProgressEmitter;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function createMockCancellationRegistry(): CancellationRegistry {
|
|
305
|
+
const cancelled = new Set<string>();
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
register: vi.fn(),
|
|
309
|
+
unregister: vi.fn(),
|
|
310
|
+
isCancelled: vi.fn().mockImplementation((id) => cancelled.has(id)),
|
|
311
|
+
cancel: vi.fn().mockImplementation((id) => cancelled.add(id)),
|
|
312
|
+
checkCancelled: vi.fn().mockImplementation((id) => {
|
|
313
|
+
if (cancelled.has(id)) {
|
|
314
|
+
throw new Error(`Request ${id} was cancelled`);
|
|
315
|
+
}
|
|
316
|
+
}),
|
|
317
|
+
} as unknown as CancellationRegistry;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function createMockSecurityValidator(): SecurityValidator {
|
|
321
|
+
return {
|
|
322
|
+
validateDomain: vi.fn().mockReturnValue({ valid: true }),
|
|
323
|
+
validateAction: vi.fn().mockReturnValue({ valid: true }),
|
|
324
|
+
detectInjectionAttempt: vi.fn().mockReturnValue({ detected: false }),
|
|
325
|
+
detectExfiltrationAttempt: vi.fn().mockReturnValue({ detected: false }),
|
|
326
|
+
} as unknown as SecurityValidator;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export interface MockContext {
|
|
330
|
+
config: Config;
|
|
331
|
+
logger: Logger;
|
|
332
|
+
capabilities: ClientCapabilities;
|
|
333
|
+
playwrightClient: MockPlaywrightClient;
|
|
334
|
+
workspaceManager: WorkspaceManager & { [key: string]: any };
|
|
335
|
+
resourceManager: ResourceManager & { [key: string]: any };
|
|
336
|
+
samplingClient: SamplingClient & { [key: string]: any };
|
|
337
|
+
elicitationClient: ElicitationClient & { [key: string]: any };
|
|
338
|
+
progressEmitter: ProgressEmitter & { [key: string]: any };
|
|
339
|
+
cancellationRegistry: CancellationRegistry & { [key: string]: any };
|
|
340
|
+
securityValidator: SecurityValidator & { [key: string]: any };
|
|
341
|
+
// Test helper properties
|
|
342
|
+
testAnalysisId: string;
|
|
343
|
+
testCrawlId: string;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Create a complete mock context for testing webtest tools
|
|
348
|
+
*/
|
|
349
|
+
export function createMockContext(
|
|
350
|
+
overrides: Partial<{
|
|
351
|
+
config: Partial<Config>;
|
|
352
|
+
capabilities: Partial<ClientCapabilities>;
|
|
353
|
+
samplingResponseGenerator: (
|
|
354
|
+
systemPrompt: string,
|
|
355
|
+
userPrompt: string
|
|
356
|
+
) => unknown;
|
|
357
|
+
playwrightPages: Record<string, import("./mock-playwright-client.js").MockPage>;
|
|
358
|
+
}> = {}
|
|
359
|
+
): MockContext {
|
|
360
|
+
const playwrightClient = createMockPlaywrightClient({
|
|
361
|
+
pages: overrides.playwrightPages || createEcommerceMock(),
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// Use date-time format for test IDs (matches new workspace folder naming)
|
|
365
|
+
const testAnalysisId = "2024-01-15_10-30";
|
|
366
|
+
const testCrawlId = "2024-01-15_10-30-45";
|
|
367
|
+
|
|
368
|
+
const workspaceManager = createMockWorkspaceManager();
|
|
369
|
+
|
|
370
|
+
// Pre-register test workspace
|
|
371
|
+
(workspaceManager.workspaceExists as any).mockResolvedValue(true);
|
|
372
|
+
(workspaceManager.readWorkspaceIndex as any).mockResolvedValue({
|
|
373
|
+
url: "https://shop.example.com",
|
|
374
|
+
domain: "shop.example.com",
|
|
375
|
+
focus: "Test focus",
|
|
376
|
+
crawls: [
|
|
377
|
+
{
|
|
378
|
+
crawlId: testCrawlId,
|
|
379
|
+
goal: "Explore",
|
|
380
|
+
status: "completed",
|
|
381
|
+
startedAt: new Date().toISOString(),
|
|
382
|
+
completedAt: new Date().toISOString(),
|
|
383
|
+
pagesVisited: 2,
|
|
384
|
+
stepsExecuted: 5,
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
runs: [],
|
|
388
|
+
limits: {
|
|
389
|
+
maxSteps: 50,
|
|
390
|
+
maxMinutes: 30,
|
|
391
|
+
maxPages: 20,
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
(workspaceManager.readCrawlIndex as any).mockResolvedValue({
|
|
396
|
+
crawlId: testCrawlId,
|
|
397
|
+
goal: "Explore",
|
|
398
|
+
strategy: "goal_directed",
|
|
399
|
+
status: "completed",
|
|
400
|
+
pages: [
|
|
401
|
+
{
|
|
402
|
+
pageId: "page-1",
|
|
403
|
+
url: "https://shop.example.com",
|
|
404
|
+
title: "Home",
|
|
405
|
+
snapshotUri: `webtest://${testAnalysisId}/crawls/${testCrawlId}/pages/page-1/snapshot.md`,
|
|
406
|
+
},
|
|
407
|
+
],
|
|
408
|
+
actionHistory: [],
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
return {
|
|
412
|
+
config: createMockConfig(overrides.config),
|
|
413
|
+
logger: createMockLogger(),
|
|
414
|
+
capabilities: createMockCapabilities(overrides.capabilities),
|
|
415
|
+
playwrightClient,
|
|
416
|
+
workspaceManager,
|
|
417
|
+
resourceManager: createMockResourceManager(),
|
|
418
|
+
samplingClient: createMockSamplingClient(overrides.samplingResponseGenerator),
|
|
419
|
+
elicitationClient: createMockElicitationClient(),
|
|
420
|
+
progressEmitter: createMockProgressEmitter(),
|
|
421
|
+
cancellationRegistry: createMockCancellationRegistry(),
|
|
422
|
+
securityValidator: createMockSecurityValidator(),
|
|
423
|
+
testAnalysisId,
|
|
424
|
+
testCrawlId,
|
|
425
|
+
};
|
|
426
|
+
}
|