From c426899eea07dae152cd5fcc2a2c52bddc5ab7f2 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 08:40:47 -0600 Subject: [PATCH] Add warning test to detect duplicate table names in schema (#1) * Initial plan * Fix redundant ratelimit schema declaration Co-authored-by: bharxhav <70275374+bharxhav@users.noreply.github.com> * Add comment documenting the duplicate rateLimit issue Co-authored-by: bharxhav <70275374+bharxhav@users.noreply.github.com> * Revert manual schema fix and add warning test for duplicate table names Co-authored-by: bharxhav <70275374+bharxhav@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bharxhav <70275374+bharxhav@users.noreply.github.com> --- src/component/schema.test.ts | 66 ++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/component/schema.test.ts diff --git a/src/component/schema.test.ts b/src/component/schema.test.ts new file mode 100644 index 0000000..e46f34f --- /dev/null +++ b/src/component/schema.test.ts @@ -0,0 +1,66 @@ +import { describe, it, expect } from "vitest"; +import { tables } from "./schema"; + +describe("Schema Validation", () => { + it("should not have duplicate table names (case-insensitive)", () => { + const tableNames = Object.keys(tables); + const lowerCaseNames = tableNames.map((name) => name.toLowerCase()); + const uniqueLowerCaseNames = new Set(lowerCaseNames); + + const duplicates: string[] = []; + lowerCaseNames.forEach((lowerName, index) => { + const firstIndex = lowerCaseNames.indexOf(lowerName); + if (firstIndex !== index && !duplicates.includes(lowerName)) { + duplicates.push(lowerName); + } + }); + + if (duplicates.length > 0) { + const duplicateDetails = duplicates.map((dup) => { + const originalNames = tableNames.filter( + (name) => name.toLowerCase() === dup + ); + return `"${originalNames.join('" and "')}"`; + }); + + expect.fail( + `Found duplicate table names (case-insensitive): ${duplicateDetails.join(", ")}.\n` + + `Convex tables are case-sensitive, but having similar names can cause confusion.\n` + + `This likely indicates a bug in the schema generation process.` + ); + } + + expect(lowerCaseNames.length).toBe(uniqueLowerCaseNames.size); + }); + + it("should warn about potential naming conflicts", () => { + const tableNames = Object.keys(tables); + const warnings: string[] = []; + + // Check for very similar names (e.g., rateLimit vs ratelimit) + for (let i = 0; i < tableNames.length; i++) { + for (let j = i + 1; j < tableNames.length; j++) { + const name1 = tableNames[i]; + const name2 = tableNames[j]; + + // Check if names differ only in case + if (name1.toLowerCase() === name2.toLowerCase()) { + warnings.push( + `Table names "${name1}" and "${name2}" differ only in casing` + ); + } + } + } + + // If there are warnings, the test should fail + if (warnings.length > 0) { + expect.fail( + `Schema naming conflicts detected:\n` + + warnings.map((w) => ` - ${w}`).join("\n") + + `\n\nPlease ensure table names are distinct even when case is ignored.` + ); + } + + expect(warnings.length).toBe(0); + }); +});