Skip to content

Commit 9526a4d

Browse files
committed
address comment: use length in objectId
1 parent 4db1b1f commit 9526a4d

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/tools/args.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export const AtlasArgs = {
2525
z
2626
.string()
2727
.min(1, `${fieldName} is required`)
28-
.regex(/^[0-9a-fA-F]{24}$/, `${fieldName} must be a valid 24-character hexadecimal string`),
28+
.length(24, `${fieldName} must be exactly 24 characters`)
29+
.regex(/^[0-9a-fA-F]+$/, `${fieldName} must contain only hexadecimal characters`),
2930

3031
projectId: (): z.ZodString => AtlasArgs.objectId("projectId"),
3132

tests/unit/args.test.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ describe("Tool args", () => {
8383

8484
it("should provide custom field name in error messages", () => {
8585
const schema = AtlasArgs.objectId("Custom Field");
86-
expect(() => schema.parse("invalid")).toThrow(
87-
"Custom Field must be a valid 24-character hexadecimal string"
88-
);
86+
expect(() => schema.parse("invalid")).toThrow("Custom Field must be exactly 24 characters");
8987
});
9088

9189
it("should not fail if the value is optional", () => {
@@ -108,15 +106,13 @@ describe("Tool args", () => {
108106

109107
it("should reject invalid project IDs", () => {
110108
const schema = AtlasArgs.projectId();
111-
expect(() => schema.parse("invalid")).toThrow(
112-
"projectId must be a valid 24-character hexadecimal string"
113-
);
109+
expect(() => schema.parse("invalid")).toThrow("projectId must be exactly 24 characters");
114110
expect(() => schema.parse("507f1f77bc*86cd79943901")).toThrow(
115-
"projectId must be a valid 24-character hexadecimal string"
111+
"projectId must contain only hexadecimal characters"
116112
);
117113
expect(() => schema.parse("")).toThrow("projectId is required");
118114
expect(() => schema.parse("507f1f77/bcf86cd799439011")).toThrow(
119-
"projectId must be a valid 24-character hexadecimal string"
115+
"projectId must contain only hexadecimal characters"
120116
);
121117
});
122118
});
@@ -130,9 +126,7 @@ describe("Tool args", () => {
130126

131127
it("should reject invalid organization IDs", () => {
132128
const schema = AtlasArgs.organizationId();
133-
expect(() => schema.parse("invalid")).toThrow(
134-
"organizationId must be a valid 24-character hexadecimal string"
135-
);
129+
expect(() => schema.parse("invalid")).toThrow("organizationId must be exactly 24 characters");
136130
});
137131
});
138132

0 commit comments

Comments
 (0)