retestkit 1.4.1 → 1.5.0
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 +59 -40
- package/dist/config.js +8 -8
- package/dist/config.js.map +1 -1
- package/dist/logger.js +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +21 -21
- package/dist/prompts/index.js.map +1 -1
- package/dist/prompts/templates/mcp/retest-crawl.md +7 -0
- package/{src/prompts/templates/mcp/webtest-discover-flows.md → dist/prompts/templates/mcp/retest-discover-flows.md} +1 -1
- package/{src/prompts/templates/mcp/webtest-discover.md → dist/prompts/templates/mcp/retest-discover.md} +2 -2
- package/dist/prompts/templates/mcp/retest-full-workflow.md +12 -0
- package/{src/prompts/templates/mcp/webtest-generate-tests.md → dist/prompts/templates/mcp/retest-generate-tests.md} +1 -1
- package/{src/prompts/templates/mcp/webtest-run-test.md → dist/prompts/templates/mcp/retest-run-test.md} +1 -1
- package/{src/prompts/templates/mcp/webtest-start.md → dist/prompts/templates/mcp/retest-start.md} +1 -1
- package/{src → dist}/prompts/templates/sampling/system-prefix.md +1 -1
- package/dist/resources/index.js +7 -7
- package/dist/resources/index.js.map +1 -1
- package/dist/schemas/config.js +2 -2
- package/dist/schemas/config.js.map +1 -1
- package/dist/security/index.js +1 -1
- package/dist/security/index.js.map +1 -1
- package/dist/server.js +3 -3
- package/dist/server.js.map +1 -1
- package/dist/test-utils/mock-context.js +22 -22
- package/dist/test-utils/mock-context.js.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +5 -5
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/retest/crawl.d.ts.map +1 -0
- package/dist/tools/{webtest → retest}/crawl.js +7 -7
- package/dist/tools/retest/crawl.js.map +1 -0
- package/dist/tools/retest/discover-features.d.ts.map +1 -0
- package/dist/tools/{webtest → retest}/discover-features.js +6 -6
- package/dist/tools/retest/discover-features.js.map +1 -0
- package/dist/tools/retest/discover-flows.d.ts.map +1 -0
- package/dist/tools/{webtest → retest}/discover-flows.js +6 -6
- package/dist/tools/retest/discover-flows.js.map +1 -0
- package/dist/tools/retest/generate-tests.d.ts.map +1 -0
- package/dist/tools/{webtest → retest}/generate-tests.js +5 -5
- package/dist/tools/retest/generate-tests.js.map +1 -0
- package/dist/tools/retest/index.d.ts.map +1 -0
- package/dist/tools/retest/index.js.map +1 -0
- package/dist/tools/retest/run-test-case.d.ts.map +1 -0
- package/dist/tools/{webtest → retest}/run-test-case.js +3 -3
- package/dist/tools/retest/run-test-case.js.map +1 -0
- package/dist/tools/retest/schemas.d.ts.map +1 -0
- package/dist/tools/retest/schemas.js.map +1 -0
- package/dist/tools/retest/start-analysis.d.ts.map +1 -0
- package/dist/tools/{webtest → retest}/start-analysis.js +5 -5
- package/dist/tools/retest/start-analysis.js.map +1 -0
- package/dist/workspace/index.js +8 -8
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/types.d.ts +2 -2
- package/dist/workspace/types.d.ts.map +1 -1
- package/package.json +6 -2
- package/.claude/commands/openspec/apply.md +0 -23
- package/.claude/commands/openspec/archive.md +0 -27
- package/.claude/commands/openspec/proposal.md +0 -28
- package/.gemini/commands/openspec/apply.toml +0 -21
- package/.gemini/commands/openspec/archive.toml +0 -25
- package/.gemini/commands/openspec/proposal.toml +0 -26
- package/.github/prompts/openspec-apply.prompt.md +0 -22
- package/.github/prompts/openspec-archive.prompt.md +0 -26
- package/.github/prompts/openspec-proposal.prompt.md +0 -27
- package/.github/workflows/release.yml +0 -33
- package/.kilocode/workflows/openspec-apply.md +0 -17
- package/.kilocode/workflows/openspec-archive.md +0 -21
- package/.kilocode/workflows/openspec-proposal.md +0 -22
- package/.mcp.json +0 -23
- package/.opencode/command/openspec-apply.md +0 -25
- package/.opencode/command/openspec-archive.md +0 -28
- package/.opencode/command/openspec-proposal.md +0 -30
- package/.roo/commands/openspec-apply.md +0 -20
- package/.roo/commands/openspec-archive.md +0 -24
- package/.roo/commands/openspec-proposal.md +0 -25
- package/.vscode/mcp.json +0 -23
- package/AGENTS.md +0 -18
- package/CLAUDE.md +0 -18
- package/dist/tools/webtest/crawl.d.ts.map +0 -1
- package/dist/tools/webtest/crawl.js.map +0 -1
- package/dist/tools/webtest/discover-features.d.ts.map +0 -1
- package/dist/tools/webtest/discover-features.js.map +0 -1
- package/dist/tools/webtest/discover-flows.d.ts.map +0 -1
- package/dist/tools/webtest/discover-flows.js.map +0 -1
- package/dist/tools/webtest/generate-tests.d.ts.map +0 -1
- package/dist/tools/webtest/generate-tests.js.map +0 -1
- package/dist/tools/webtest/index.d.ts.map +0 -1
- package/dist/tools/webtest/index.js.map +0 -1
- package/dist/tools/webtest/run-test-case.d.ts.map +0 -1
- package/dist/tools/webtest/run-test-case.js.map +0 -1
- package/dist/tools/webtest/schemas.d.ts.map +0 -1
- package/dist/tools/webtest/schemas.js.map +0 -1
- package/dist/tools/webtest/start-analysis.d.ts.map +0 -1
- package/dist/tools/webtest/start-analysis.js.map +0 -1
- package/openspec/AGENTS.md +0 -456
- package/openspec/changes/archive/2025-12-18-add-hybrid-artifact-paths/proposal.md +0 -33
- package/openspec/changes/archive/2025-12-18-add-hybrid-artifact-paths/specs/webtest-resources/spec.md +0 -27
- package/openspec/changes/archive/2025-12-18-add-hybrid-artifact-paths/specs/webtest-tools/spec.md +0 -304
- package/openspec/changes/archive/2025-12-18-add-hybrid-artifact-paths/tasks.md +0 -43
- package/openspec/changes/archive/2025-12-18-add-mcp-server-foundation/design.md +0 -209
- package/openspec/changes/archive/2025-12-18-add-mcp-server-foundation/proposal.md +0 -41
- package/openspec/changes/archive/2025-12-18-add-mcp-server-foundation/specs/mcp-server-core/spec.md +0 -183
- package/openspec/changes/archive/2025-12-18-add-mcp-server-foundation/tasks.md +0 -112
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/design.md +0 -333
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/proposal.md +0 -66
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/mcp-server-core/spec.md +0 -129
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-lifecycle/spec.md +0 -138
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-logging/spec.md +0 -211
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-prompts/spec.md +0 -157
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-resources/spec.md +0 -213
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-sampling/spec.md +0 -257
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/specs/webtest-tools/spec.md +0 -501
- package/openspec/changes/archive/2025-12-18-add-webtest-orchestrator/tasks.md +0 -264
- package/openspec/changes/archive/2025-12-18-allow-analysis-of-incomplete-crawls/proposal.md +0 -24
- package/openspec/changes/archive/2025-12-18-allow-analysis-of-incomplete-crawls/specs/webtest-tools/spec.md +0 -80
- package/openspec/changes/archive/2025-12-18-allow-analysis-of-incomplete-crawls/tasks.md +0 -8
- package/openspec/changes/archive/2025-12-18-fix-crawl-loop-stability/design.md +0 -90
- package/openspec/changes/archive/2025-12-18-fix-crawl-loop-stability/proposal.md +0 -28
- package/openspec/changes/archive/2025-12-18-fix-crawl-loop-stability/specs/webtest-sampling/spec.md +0 -90
- package/openspec/changes/archive/2025-12-18-fix-crawl-loop-stability/tasks.md +0 -33
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/design.md +0 -558
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/proposal.md +0 -119
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/specs/webtest-resources/spec.md +0 -109
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/specs/webtest-tools/spec.md +0 -121
- package/openspec/changes/archive/2025-12-18-use-markdown-artifacts/tasks.md +0 -133
- package/openspec/changes/extract-prompts-to-markdown/design.md +0 -86
- package/openspec/changes/extract-prompts-to-markdown/proposal.md +0 -50
- package/openspec/changes/extract-prompts-to-markdown/specs/webtest-prompts/spec.md +0 -74
- package/openspec/changes/extract-prompts-to-markdown/tasks.md +0 -40
- package/openspec/changes/refactor-webtest-naming/design.md +0 -95
- package/openspec/changes/refactor-webtest-naming/proposal.md +0 -66
- package/openspec/changes/refactor-webtest-naming/specs/webtest-prompts/spec.md +0 -79
- package/openspec/changes/refactor-webtest-naming/specs/webtest-resources/spec.md +0 -80
- package/openspec/changes/refactor-webtest-naming/specs/webtest-sampling/spec.md +0 -122
- package/openspec/changes/refactor-webtest-naming/specs/webtest-tools/spec.md +0 -113
- package/openspec/changes/refactor-webtest-naming/tasks.md +0 -119
- package/openspec/changes/rename-package-to-retest/proposal.md +0 -52
- package/openspec/changes/rename-package-to-retest/specs/mcp-server-core/spec.md +0 -53
- package/openspec/changes/rename-package-to-retest/specs/retest-lifecycle/spec.md +0 -68
- package/openspec/changes/rename-package-to-retest/specs/retest-logging/spec.md +0 -35
- package/openspec/changes/rename-package-to-retest/specs/retest-prompts/spec.md +0 -159
- package/openspec/changes/rename-package-to-retest/specs/retest-resources/spec.md +0 -251
- package/openspec/changes/rename-package-to-retest/specs/retest-sampling/spec.md +0 -99
- package/openspec/changes/rename-package-to-retest/specs/retest-tools/spec.md +0 -295
- package/openspec/changes/rename-package-to-retest/tasks.md +0 -71
- package/openspec/project.md +0 -31
- package/openspec/specs/mcp-server-core/spec.md +0 -178
- package/openspec/specs/webtest-lifecycle/spec.md +0 -136
- package/openspec/specs/webtest-logging/spec.md +0 -209
- package/openspec/specs/webtest-prompts/spec.md +0 -155
- package/openspec/specs/webtest-resources/spec.md +0 -248
- package/openspec/specs/webtest-sampling/spec.md +0 -344
- package/openspec/specs/webtest-tools/spec.md +0 -282
- package/release.config.js +0 -9
- package/src/config.test.ts +0 -96
- package/src/config.ts +0 -32
- package/src/elicitation/index.test.ts +0 -399
- package/src/elicitation/index.ts +0 -171
- package/src/elicitation/types.ts +0 -68
- package/src/index.ts +0 -83
- package/src/lifecycle/index.test.ts +0 -260
- package/src/lifecycle/index.ts +0 -101
- package/src/logger.redaction.test.ts +0 -322
- package/src/logger.test.ts +0 -123
- package/src/logger.ts +0 -229
- package/src/playwright-client/index.ts +0 -392
- package/src/playwright-client/types.ts +0 -99
- package/src/progress/index.test.ts +0 -327
- package/src/progress/index.ts +0 -170
- package/src/progress/types.ts +0 -25
- package/src/prompts/index.test.ts +0 -451
- package/src/prompts/index.ts +0 -246
- package/src/prompts/loader.test.ts +0 -100
- package/src/prompts/loader.ts +0 -59
- package/src/prompts/templates/mcp/webtest-crawl.md +0 -7
- package/src/prompts/templates/mcp/webtest-full-workflow.md +0 -12
- package/src/resources/index.ts +0 -250
- package/src/resources/subscriptions.ts +0 -37
- package/src/sampling/index.test.ts +0 -414
- package/src/sampling/index.ts +0 -286
- package/src/sampling/prompts.ts +0 -194
- package/src/sampling/types.ts +0 -60
- package/src/schemas/config.ts +0 -39
- package/src/security/index.test.ts +0 -441
- package/src/security/index.ts +0 -361
- package/src/security/security-scenarios.test.ts +0 -468
- package/src/server.ts +0 -211
- package/src/test-utils/index.ts +0 -6
- package/src/test-utils/mock-context.ts +0 -426
- package/src/test-utils/mock-playwright-client.ts +0 -422
- package/src/tools/index.ts +0 -11
- package/src/tools/webtest/crawl.test.ts +0 -834
- package/src/tools/webtest/crawl.ts +0 -901
- package/src/tools/webtest/discover-features.ts +0 -412
- package/src/tools/webtest/discover-flows.ts +0 -408
- package/src/tools/webtest/generate-tests.test.ts +0 -532
- package/src/tools/webtest/generate-tests.ts +0 -425
- package/src/tools/webtest/index.ts +0 -7
- package/src/tools/webtest/integration.test.ts +0 -536
- package/src/tools/webtest/run-test-case.test.ts +0 -659
- package/src/tools/webtest/run-test-case.ts +0 -508
- package/src/tools/webtest/schemas.ts +0 -201
- package/src/tools/webtest/start-analysis.test.ts +0 -151
- package/src/tools/webtest/start-analysis.ts +0 -158
- package/src/transports/http.ts +0 -19
- package/src/transports/index.ts +0 -30
- package/src/transports/stdio.ts +0 -7
- package/src/types/capabilities.test.ts +0 -193
- package/src/types/capabilities.ts +0 -50
- package/src/types/context.ts +0 -21
- package/src/types/tool.ts +0 -11
- package/src/workspace/index.ts +0 -945
- package/src/workspace/markdown.ts +0 -272
- package/src/workspace/types.ts +0 -186
- package/tests/integration/server.test.ts +0 -89
- package/tests/integration/tools.test.ts +0 -99
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -9
- package/vitest.integration.config.ts +0 -10
- /package/{src → dist}/prompts/templates/sampling/crawl-action.md +0 -0
- /package/{src → dist}/prompts/templates/sampling/feature-discovery.md +0 -0
- /package/{src → dist}/prompts/templates/sampling/flow-discovery.md +0 -0
- /package/{src → dist}/prompts/templates/sampling/page-content-wrapper.md +0 -0
- /package/{src → dist}/prompts/templates/sampling/test-evaluation.md +0 -0
- /package/{src → dist}/prompts/templates/sampling/test-generation.md +0 -0
- /package/dist/tools/{webtest → retest}/crawl.d.ts +0 -0
- /package/dist/tools/{webtest → retest}/discover-features.d.ts +0 -0
- /package/dist/tools/{webtest → retest}/discover-flows.d.ts +0 -0
- /package/dist/tools/{webtest → retest}/generate-tests.d.ts +0 -0
- /package/dist/tools/{webtest → retest}/index.d.ts +0 -0
- /package/dist/tools/{webtest → retest}/index.js +0 -0
- /package/dist/tools/{webtest → retest}/run-test-case.d.ts +0 -0
- /package/dist/tools/{webtest → retest}/schemas.d.ts +0 -0
- /package/dist/tools/{webtest → retest}/schemas.js +0 -0
- /package/dist/tools/{webtest → retest}/start-analysis.d.ts +0 -0
|
@@ -1,426 +0,0 @@
|
|
|
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
|
-
}
|