Skip to content

Commit 2f99c5a

Browse files
committed
address copilot comments
1 parent db75e4f commit 2f99c5a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/tools/args.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { z, type ZodString } from "zod";
22

3+
// Shared validation constants
4+
const NO_SLASH_REGEX = /^[^/]*$/;
5+
const NO_SLASH_ERROR = "String cannot contain '/'";
6+
37
export const CommonArgs = {
48
string: (): ZodString =>
59
z.string().regex(/^[\x20-\x7E]*$/, "String cannot contain special characters or Unicode symbols"),
@@ -19,21 +23,21 @@ export const AtlasArgs = {
1923
CommonArgs.string()
2024
.min(1, "Cluster name is required")
2125
.max(64, "Cluster name must be 64 characters or less")
22-
.regex(/^[^/]*$/, "String cannot contain '/'")
26+
.regex(NO_SLASH_REGEX, NO_SLASH_ERROR)
2327
.regex(/^[a-zA-Z0-9_-]+$/, "Cluster name can only contain letters, numbers, hyphens, and underscores"),
2428

2529
projectName: (): z.ZodString =>
2630
CommonArgs.string()
2731
.min(1, "Project name is required")
2832
.max(64, "Project name must be 64 characters or less")
29-
.regex(/^[^/]*$/, "String cannot contain '/'")
33+
.regex(NO_SLASH_REGEX, NO_SLASH_ERROR)
3034
.regex(/^[a-zA-Z0-9_-]+$/, "Project name can only contain letters, numbers, hyphens, and underscores"),
3135

3236
username: (): z.ZodString =>
3337
CommonArgs.string()
3438
.min(1, "Username is required")
3539
.max(100, "Username must be 100 characters or less")
36-
.regex(/^[^/]*$/, "String cannot contain '/'")
40+
.regex(NO_SLASH_REGEX, NO_SLASH_ERROR)
3741
.regex(/^[a-zA-Z0-9._-]+$/, "Username can only contain letters, numbers, dots, hyphens, and underscores"),
3842

3943
ipAddress: (): z.ZodString => CommonArgs.string().ip({ version: "v4" }),
@@ -50,6 +54,6 @@ export const AtlasArgs = {
5054
CommonArgs.string()
5155
.min(1, "Password is required")
5256
.max(100, "Password must be 100 characters or less")
53-
.regex(/^[^/]*$/, "String cannot contain '/'")
57+
.regex(NO_SLASH_REGEX, NO_SLASH_ERROR)
5458
.regex(/^[a-zA-Z0-9._-]+$/, "Password can only contain letters, numbers, dots, hyphens, and underscores"),
5559
};

tests/unit/args.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("Tool args", () => {
8181
);
8282
});
8383

84-
it("should not faile if the value is optional", () => {
84+
it("should not fail if the value is optional", () => {
8585
const schema = AtlasArgs.objectId("Custom Field").optional();
8686
expect(schema.parse(undefined)).toBeUndefined();
8787
});

0 commit comments

Comments
 (0)