Skip to content

Commit acfbdd3

Browse files
authored
Merge pull request #5047 from modelcontextprotocol/v2/chore/1149-windows-ci
chore(ci): run the test suites on Windows runners
2 parents 87a395a + 57d37ac commit acfbdd3

9 files changed

Lines changed: 183 additions & 38 deletions

File tree

‎.github/workflows/python.yml‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,36 @@ jobs:
9999
- name: Coverage
100100
run: npm run coverage:py -- ${{ matrix.package }}
101101

102+
# The test suites on Windows (#1149), beside the Ubuntu `test` legs. Only
103+
# pytest: ruff, pyright and the build do not depend on the OS.
104+
test-windows:
105+
timeout-minutes: 20
106+
needs: [detect-packages]
107+
strategy:
108+
fail-fast: false
109+
matrix:
110+
package: ${{ fromJson(needs.detect-packages.outputs.packages) }}
111+
name: Test ${{ matrix.package }} (Windows)
112+
runs-on: windows-latest
113+
steps:
114+
- uses: actions/checkout@v6
115+
116+
- name: Install uv
117+
uses: astral-sh/setup-uv@v7
118+
119+
- name: Set up Python
120+
uses: actions/setup-python@v7
121+
with:
122+
python-version-file: "src/${{ matrix.package }}/.python-version"
123+
124+
- name: Install dependencies
125+
working-directory: src/${{ matrix.package }}
126+
run: uv sync --locked --all-extras --dev
127+
128+
- name: Run pytest
129+
working-directory: src/${{ matrix.package }}
130+
run: uv run --frozen pytest
131+
102132
build:
103133
timeout-minutes: 10
104134
needs: [detect-packages, test]

‎.github/workflows/typescript.yml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,37 @@ jobs:
122122
working-directory: src/${{ matrix.package }}
123123
run: npm run coverage
124124

125+
# The test suites on Windows (#1149). Every other job runs on Ubuntu, so
126+
# Windows-only code paths (drive letters, UNC shares, no O_NOFOLLOW, rename
127+
# over a locked file) were only ever exercised by mocking `path.win32`. This
128+
# leg runs each server's own `npm test` on a real Windows runner. It is tests
129+
# only: format, lint, typecheck and coverage do not depend on the OS and stay
130+
# in the Ubuntu legs above.
131+
test-windows:
132+
timeout-minutes: 20
133+
needs: [detect-packages]
134+
strategy:
135+
fail-fast: false
136+
matrix:
137+
package: ${{ fromJson(needs.detect-packages.outputs.packages) }}
138+
name: Test ${{ matrix.package }} (Windows)
139+
runs-on: windows-latest
140+
steps:
141+
- uses: actions/checkout@v6
142+
143+
- uses: actions/setup-node@v7
144+
with:
145+
node-version: 22
146+
cache: npm
147+
148+
# The same install as the `validate` leg; its `prepare` builds `dist/`.
149+
- name: Install dependencies
150+
run: npm ci --workspace src/${{ matrix.package }} --include-workspace-root
151+
152+
- name: Run tests
153+
working-directory: src/${{ matrix.package }}
154+
run: npm test
155+
125156
# The boot smoke (#4871): every server started the way a client starts it —
126157
# the built `dist/index.js` for the TypeScript servers, the console script
127158
# through `uv run` for the Python ones — over each transport it implements,

‎docs/quality-gate.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ your machine. It is the strongest predictor of a green CI there is here, though
2222
not a proof: CI runs on Linux, on a fresh `npm ci`, with Node 22 and each
2323
Python server's pinned interpreter.
2424

25+
**The one exception is the Windows legs** (#1149): `test-windows` in both
26+
workflows runs each server's test suite (`npm test`, `pytest`) on a
27+
`windows-latest` runner. The gate runs the same suites, but only on your
28+
machine's OS, so a Windows-only failure (a drive letter, a UNC path, a missing
29+
`O_NOFOLLOW`, a locked file) shows up first in CI. When a PR touches
30+
platform-specific code, wait for those legs, not just the gate.
31+
2532
The inner-loop commands are subsets. They are for speed while working, and are
2633
never a substitute for the gate.
2734

‎src/filesystem/__tests__/path-validation.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ describe("Path Validation", () => {
369369

370370
// But only on the same filesystem root
371371
if (path.sep === "\\") {
372-
expect(isPathWithinAllowedDirectories("D:\\other", ["/"])).toBe(false);
372+
// "/" resolves to the current drive's root, so use another drive.
373+
const otherDrive = /^D:/i.test(path.resolve("/")) ? "E:" : "D:";
374+
expect(
375+
isPathWithinAllowedDirectories(`${otherDrive}\\other`, ["/"]),
376+
).toBe(false);
373377
}
374378
});
375379
});

‎src/filesystem/__tests__/roots-utils.test.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ describe("getValidRootDirectories", () => {
2727

2828
beforeEach(() => {
2929
vi.spyOn(console, "error").mockImplementation(() => {});
30-
testDir1 = realpathSync(mkdtempSync(join(tmpdir(), "mcp-roots-test1-")));
31-
testDir2 = realpathSync(mkdtempSync(join(tmpdir(), "mcp-roots-test2-")));
32-
testDir3 = realpathSync(mkdtempSync(join(tmpdir(), "mcp-roots-test3-")));
30+
// realpathSync.native, like the fs.promises.realpath the code uses,
31+
// expands a Windows 8.3 short name (RUNNER~1) in os.tmpdir(); the JS
32+
// realpathSync does not.
33+
testDir1 = realpathSync.native(
34+
mkdtempSync(join(tmpdir(), "mcp-roots-test1-")),
35+
);
36+
testDir2 = realpathSync.native(
37+
mkdtempSync(join(tmpdir(), "mcp-roots-test2-")),
38+
);
39+
testDir3 = realpathSync.native(
40+
mkdtempSync(join(tmpdir(), "mcp-roots-test3-")),
41+
);
3342
testFile = join(testDir1, "test-file.txt");
3443
writeFileSync(testFile, "test content");
3544
});
@@ -61,7 +70,7 @@ describe("getValidRootDirectories", () => {
6170
});
6271

6372
it("expands ~ and ~/ in a plain path to the home directory", async () => {
64-
const home = realpathSync(homedir());
73+
const home = realpathSync.native(homedir());
6574
expect(await getValidRootDirectories([{ uri: "~" }])).toEqual([home]);
6675
expect(await getValidRootDirectories([{ uri: "~/" }])).toEqual([home]);
6776
});

‎src/filesystem/__tests__/server-paths.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ describe("symlinks", () => {
213213
it("reports a realpath failure other than ENOENT as is", async () => {
214214
await fs.writeFile(path.join(dir, "file.txt"), "");
215215
const result = await read(path.join(dir, "file.txt", "child"));
216-
expect(textOf(result)).toMatch(/^ENOTDIR: not a directory, realpath/);
216+
// Windows reports the failing syscall as scandir rather than realpath.
217+
expect(textOf(result)).toMatch(
218+
process.platform === "win32"
219+
? /^ENOTDIR: not a directory/
220+
: /^ENOTDIR: not a directory, realpath/,
221+
);
217222
});
218223
});
219224

‎src/filesystem/__tests__/server-tools.test.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ describe("read_multiple_files", () => {
484484
);
485485
expect(parts[2]).toBe(`${b}:\nbeta\n`);
486486
expect(parts[3]).toBe(
487-
`/etc/hostname: Error - Access denied - path outside allowed directories: /etc/hostname not in ${dir}`,
487+
`/etc/hostname: Error - Access denied - path outside allowed directories: ${path.resolve("/etc/hostname")} not in ${dir}`,
488488
);
489489
});
490490

@@ -541,7 +541,10 @@ describe("write_file", () => {
541541
expect(await fs.readFile(file, "utf-8")).toBe("new");
542542
expect(after.ino).toBe(before.ino);
543543
expect(after.birthtimeMs).toBe(before.birthtimeMs);
544-
expect(after.mode & 0o777).toBe(0o640);
544+
// Windows has no POSIX mode bits: a writable file always reports 666.
545+
expect(after.mode & 0o777).toBe(
546+
process.platform === "win32" ? 0o666 : 0o640,
547+
);
545548
});
546549

547550
it("keeps a hard link on overwrite (#4512)", async () => {
@@ -971,7 +974,10 @@ describe("edit_file", () => {
971974
expect(await fs.readFile(file, "utf-8")).toContain("return 2;");
972975
expect(after.ino).toBe(before.ino);
973976
expect(after.birthtimeMs).toBe(before.birthtimeMs);
974-
expect(after.mode & 0o777).toBe(0o600);
977+
// Windows has no POSIX mode bits: a writable file always reports 666.
978+
expect(after.mode & 0o777).toBe(
979+
process.platform === "win32" ? 0o666 : 0o600,
980+
);
975981
});
976982

977983
it("keeps a hard link on edit (#4512)", async () => {
@@ -1357,7 +1363,10 @@ describe("get_file_info", () => {
13571363
expect(lines[0]).toBe("size: 5");
13581364
expect(lines[4]).toBe("isDirectory: false");
13591365
expect(lines[5]).toBe("isFile: true");
1360-
expect(lines[6]).toBe("permissions: 640");
1366+
// Windows has no POSIX mode bits: a writable file always reports 666.
1367+
expect(lines[6]).toBe(
1368+
process.platform === "win32" ? "permissions: 666" : "permissions: 640",
1369+
);
13611370
// Dates are rendered with Date#toString, in the server's local time zone.
13621371
expect(lines[2]).toMatch(/^modified: \w{3} \w{3} \d{2} \d{4} /);
13631372
});

‎src/git/tests/conftest.py‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
assertion is then made on what a client receives over the wire.
77
"""
88

9+
import os
910
import shutil
11+
import stat
1012
from collections.abc import AsyncIterator, Iterator
1113
from contextlib import asynccontextmanager
1214
from pathlib import Path
@@ -28,6 +30,7 @@
2830
def test_repository(tmp_path: Path) -> Iterator[git.Repo]:
2931
repo_path = tmp_path / "temp_test_repo"
3032
test_repo = git.Repo.init(repo_path)
33+
disable_autocrlf(test_repo)
3134

3235
Path(repo_path / "test.txt").write_text("test")
3336
test_repo.index.add(["test.txt"])
@@ -39,16 +42,47 @@ def test_repository(tmp_path: Path) -> Iterator[git.Repo]:
3942
# their cwd is inside the repository, so rmtree fails with WinError 32
4043
# (#4855, unblocks #1149).
4144
test_repo.close()
42-
shutil.rmtree(repo_path)
45+
rmtree(repo_path)
46+
47+
48+
def disable_autocrlf(repo: git.Repo) -> None:
49+
"""Commit and check out bytes unchanged, whatever the host's git config.
50+
51+
Git for Windows defaults to `core.autocrlf=true`, which rewrites the
52+
fixtures' LF line endings to CRLF in the working tree, so diffs and `show`
53+
output carry CRLF there and nowhere else. Set it repo-locally, before
54+
anything is committed, so every OS sees the same bytes.
55+
"""
56+
with repo.config_writer() as config:
57+
config.set_value("core", "autocrlf", "false")
58+
59+
60+
def _clear_readonly_and_retry(func: Any, path: str, _exc_info: Any) -> None:
61+
# Git writes object files read-only; on Windows that makes them
62+
# undeletable (WinError 5) until the read-only bit is cleared.
63+
os.chmod(path, stat.S_IWRITE)
64+
func(path)
65+
66+
67+
def rmtree(path: Path) -> None:
68+
"""`shutil.rmtree` that also removes git's read-only files on Windows.
69+
70+
Uses `onerror`, not `onexc`: the server pins Python 3.10, and `onexc` is
71+
3.12+.
72+
"""
73+
shutil.rmtree(path, onerror=_clear_readonly_and_retry)
4374

4475

4576
def make_repo(path: Path) -> git.Repo:
4677
"""A repository on branch `main` with one commit of `test.txt`."""
4778
repo = git.Repo.init(path, initial_branch="main")
79+
disable_autocrlf(repo)
4880
with repo.config_writer() as config:
4981
config.set_value("user", "name", "Test User")
5082
config.set_value("user", "email", "test@example.com")
51-
(path / "test.txt").write_text("line 1\nline 2\nline 3\nline 4\nline 5\n")
83+
(path / "test.txt").write_text(
84+
"line 1\nline 2\nline 3\nline 4\nline 5\n", newline="\n"
85+
)
5286
repo.index.add(["test.txt"])
5387
repo.index.commit("initial commit")
5488
return repo

0 commit comments

Comments
 (0)