Skip to content

Commit 2cae2e7

Browse files
committed
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into gagik/schema-default
2 parents 80e02c0 + 1c49353 commit 2cae2e7

File tree

4 files changed

+225
-209
lines changed

4 files changed

+225
-209
lines changed

.github/workflows/code-health-fork.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
run: npm ci
3636
- name: Run tests
3737
run: npm test
38+
env:
39+
SKIP_ATLAS_TESTS: "true"
40+
SKIP_ATLAS_LOCAL_TESTS: "true"
3841
- name: Upload test results
3942
if: always() && matrix.os == 'ubuntu-latest'
4043
uses: actions/upload-artifact@v4

eslint-rules/enforce-zod-v4.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export default {
2323
create(context) {
2424
const currentFilePath = path.resolve(context.getFilename());
2525

26-
if (currentFilePath === configFilePath || currentFilePath === schemasFilePath) {
26+
// Only allow zod v4 import in config.ts
27+
if (currentFilePath === configFilePath) {
2728
return {};
2829
}
2930

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import path from "path";
2+
import { RuleTester } from "eslint";
3+
import { describe, it } from "vitest";
4+
import tsParser from "@typescript-eslint/parser";
5+
import rule from "./enforce-zod-v4.js";
6+
7+
const ROOT = process.cwd();
8+
const resolve = (p) => path.resolve(ROOT, p);
9+
10+
const ruleTester = new RuleTester({
11+
languageOptions: {
12+
parser: tsParser,
13+
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
14+
},
15+
});
16+
17+
describe("enforce-zod-v4", () => {
18+
it("should allow zod/v4 imports in config.ts", () => {
19+
ruleTester.run("enforce-zod-v4", rule, {
20+
valid: [
21+
{
22+
filename: resolve("src/common/config.ts"),
23+
code: 'import { z } from "zod/v4";\n',
24+
},
25+
{
26+
filename: resolve("src/common/config.ts"),
27+
code: 'import * as z from "zod/v4";\n',
28+
},
29+
{
30+
filename: resolve("src/common/config.ts"),
31+
code: 'import type { ZodType } from "zod/v4";\n',
32+
},
33+
],
34+
invalid: [],
35+
});
36+
});
37+
38+
it("should allow regular zod imports in other files", () => {
39+
ruleTester.run("enforce-zod-v4", rule, {
40+
valid: [
41+
{
42+
filename: resolve("src/tools/tool.ts"),
43+
code: 'import { z } from "zod";\n',
44+
},
45+
{
46+
filename: resolve("src/resources/resource.ts"),
47+
code: 'import * as z from "zod";\n',
48+
},
49+
{
50+
filename: resolve("src/some/module.ts"),
51+
code: 'import type { ZodType } from "zod";\n',
52+
},
53+
],
54+
invalid: [],
55+
});
56+
});
57+
58+
it("should allow non-zod imports in any file", () => {
59+
ruleTester.run("enforce-zod-v4", rule, {
60+
valid: [
61+
{
62+
filename: resolve("src/tools/tool.ts"),
63+
code: 'import { something } from "some-package";\n',
64+
},
65+
{
66+
filename: resolve("src/common/config.ts"),
67+
code: 'import path from "path";\n',
68+
},
69+
{
70+
filename: resolve("src/resources/resource.ts"),
71+
code: 'import { Logger } from "./logger.js";\n',
72+
},
73+
],
74+
invalid: [],
75+
});
76+
});
77+
78+
it("should report error when zod/v4 is imported in files other than config.ts", () => {
79+
ruleTester.run("enforce-zod-v4", rule, {
80+
valid: [],
81+
invalid: [
82+
{
83+
filename: resolve("src/tools/tool.ts"),
84+
code: 'import { z } from "zod/v4";\n',
85+
errors: [
86+
{
87+
messageId: "enforceZodV4",
88+
data: { importPath: "zod/v4" },
89+
},
90+
],
91+
},
92+
{
93+
filename: resolve("src/resources/resource.ts"),
94+
code: 'import * as z from "zod/v4";\n',
95+
errors: [
96+
{
97+
messageId: "enforceZodV4",
98+
data: { importPath: "zod/v4" },
99+
},
100+
],
101+
},
102+
{
103+
filename: resolve("src/some/module.ts"),
104+
code: 'import type { ZodType } from "zod/v4";\n',
105+
errors: [
106+
{
107+
messageId: "enforceZodV4",
108+
data: { importPath: "zod/v4" },
109+
},
110+
],
111+
},
112+
{
113+
filename: resolve("tests/unit/toolBase.test.ts"),
114+
code: 'import { z } from "zod/v4";\n',
115+
errors: [
116+
{
117+
messageId: "enforceZodV4",
118+
data: { importPath: "zod/v4" },
119+
},
120+
],
121+
},
122+
],
123+
});
124+
});
125+
126+
it("should handle multiple imports in a single file", () => {
127+
ruleTester.run("enforce-zod-v4", rule, {
128+
valid: [
129+
{
130+
filename: resolve("src/common/config.ts"),
131+
code: `import { z } from "zod/v4";
132+
import path from "path";
133+
import type { UserConfig } from "./types.js";
134+
`,
135+
},
136+
],
137+
invalid: [
138+
{
139+
filename: resolve("src/tools/tool.ts"),
140+
code: `import { z } from "zod/v4";
141+
import path from "path";
142+
`,
143+
errors: [
144+
{
145+
messageId: "enforceZodV4",
146+
data: { importPath: "zod/v4" },
147+
},
148+
],
149+
},
150+
],
151+
});
152+
});
153+
});

0 commit comments

Comments
 (0)