forked from ProverCoderAI/docker-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp-playwright.test.ts
More file actions
142 lines (124 loc) · 5.44 KB
/
mcp-playwright.test.ts
File metadata and controls
142 lines (124 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import * as FileSystem from "@effect/platform/FileSystem"
import * as Path from "@effect/platform/Path"
import { NodeContext } from "@effect/platform-node"
import { describe, expect, it } from "@effect/vitest"
import { Effect } from "effect"
import type { TemplateConfig } from "../../src/core/domain.js"
import { enableMcpPlaywrightProjectFiles } from "../../src/usecases/mcp-playwright.js"
import { prepareProjectFiles } from "../../src/usecases/actions/prepare-files.js"
const withTempDir = <A, E, R>(
use: (tempDir: string) => Effect.Effect<A, E, R>
): Effect.Effect<A, E, R | FileSystem.FileSystem> =>
Effect.scoped(
Effect.gen(function*(_) {
const fs = yield* _(FileSystem.FileSystem)
const tempDir = yield* _(
fs.makeTempDirectoryScoped({
prefix: "docker-git-mcp-playwright-"
})
)
return yield* _(use(tempDir))
})
)
const makeGlobalConfig = (root: string, path: Path.Path): TemplateConfig => ({
containerName: "dg-test",
serviceName: "dg-test",
sshUser: "dev",
sshPort: 2222,
repoUrl: "https://github.com/org/repo.git",
repoRef: "main",
targetDir: "/home/dev/org/repo",
volumeName: "dg-test-home",
dockerGitPath: path.join(root, ".docker-git"),
authorizedKeysPath: path.join(root, "authorized_keys"),
envGlobalPath: path.join(root, ".orch/env/global.env"),
envProjectPath: path.join(root, ".orch/env/project.env"),
codexAuthPath: path.join(root, ".orch/auth/codex"),
codexSharedAuthPath: path.join(root, ".orch/auth/codex-shared"),
codexHome: "/home/dev/.codex",
dockerNetworkMode: "shared",
dockerSharedNetworkName: "docker-git-shared",
enableMcpPlaywright: false,
pnpmVersion: "10.27.0"
})
const makeProjectConfig = (
outDir: string,
enableMcpPlaywright: boolean,
path: Path.Path
): TemplateConfig => ({
containerName: "dg-test",
serviceName: "dg-test",
sshUser: "dev",
sshPort: 2222,
repoUrl: "https://github.com/org/repo.git",
repoRef: "main",
targetDir: "/home/dev/org/repo",
volumeName: "dg-test-home",
dockerGitPath: path.join(outDir, ".docker-git"),
authorizedKeysPath: path.join(outDir, "authorized_keys"),
envGlobalPath: path.join(outDir, ".orch/env/global.env"),
envProjectPath: path.join(outDir, ".orch/env/project.env"),
codexAuthPath: path.join(outDir, ".orch/auth/codex"),
codexSharedAuthPath: path.join(outDir, ".orch/auth/codex-shared"),
codexHome: "/home/dev/.codex",
dockerNetworkMode: "shared",
dockerSharedNetworkName: "docker-git-shared",
enableMcpPlaywright,
pnpmVersion: "10.27.0"
})
const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" && value !== null
const readEnableMcpPlaywrightFlag = (value: unknown): boolean | undefined => {
if (!isRecord(value)) {
return undefined
}
const template = value.template
if (!isRecord(template)) {
return undefined
}
const flag = template.enableMcpPlaywright
return typeof flag === "boolean" ? flag : undefined
}
describe("enableMcpPlaywrightProjectFiles", () => {
it.effect("enables Playwright MCP for an existing project without rewriting env files", () =>
withTempDir((root) =>
Effect.gen(function*(_) {
const fs = yield* _(FileSystem.FileSystem)
const path = yield* _(Path.Path)
const outDir = path.join(root, "project")
const globalConfig = makeGlobalConfig(root, path)
const withoutMcp = makeProjectConfig(outDir, false, path)
yield* _(
prepareProjectFiles(outDir, root, globalConfig, withoutMcp, {
force: false,
forceEnv: false
})
)
const envProjectPath = path.join(outDir, ".orch/env/project.env")
yield* _(fs.writeFileString(envProjectPath, "# custom env\nCUSTOM_KEY=1\n"))
yield* _(enableMcpPlaywrightProjectFiles(outDir))
const envAfter = yield* _(fs.readFileString(envProjectPath))
expect(envAfter).toContain("CUSTOM_KEY=1")
const composeAfter = yield* _(fs.readFileString(path.join(outDir, "docker-compose.yml")))
expect(composeAfter).toContain("dg-test-browser")
expect(composeAfter).toContain('MCP_PLAYWRIGHT_ENABLE: "1"')
const dockerfileAfter = yield* _(fs.readFileString(path.join(outDir, "Dockerfile")))
expect(dockerfileAfter).toContain("@playwright/mcp")
// CHANGE: verify retry logic is included in docker-git-playwright-mcp wrapper
// WHY: issue-123 requires retry mechanism to handle browser sidecar startup delays
// QUOTE(issue-123): "Почему MCP сервер лежит с ошибкой?"
// REF: issue-123
expect(dockerfileAfter).toContain("MCP_PLAYWRIGHT_RETRY_ATTEMPTS")
expect(dockerfileAfter).toContain("MCP_PLAYWRIGHT_RETRY_DELAY")
expect(dockerfileAfter).toContain("fetch_cdp_version()")
expect(dockerfileAfter).toContain("waiting for browser sidecar")
const browserDockerfileExists = yield* _(fs.exists(path.join(outDir, "Dockerfile.browser")))
const startExtraExists = yield* _(fs.exists(path.join(outDir, "mcp-playwright-start-extra.sh")))
expect(browserDockerfileExists).toBe(true)
expect(startExtraExists).toBe(true)
const configAfterText = yield* _(fs.readFileString(path.join(outDir, "docker-git.json")))
const configAfter = yield* _(Effect.sync((): unknown => JSON.parse(configAfterText)))
expect(readEnableMcpPlaywrightFlag(configAfter)).toBe(true)
})
).pipe(Effect.provide(NodeContext.layer)))
})