From 4fa22d33fe3904c4ce61de4f05d94567c16d376b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 27 Sep 2026 03:58:06 +0000 Subject: [PATCH] Fix Vercel deploy: move a test out of the api function tree api/ranked/challenge.test.ts deployed as a 13th serverless function, over the Hobby plan's 12. Tests under api/ now live in api/_lib, and a guard test fails if the function count goes over the limit again. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018xNjY7412Rp5bFuw5h69yu --- api/_lib/function-count.test.ts | 27 +++++++++++++++++++ .../ranked-challenge.test.ts} | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 api/_lib/function-count.test.ts rename api/{ranked/challenge.test.ts => _lib/ranked-challenge.test.ts} (94%) diff --git a/api/_lib/function-count.test.ts b/api/_lib/function-count.test.ts new file mode 100644 index 0000000..186cc9f --- /dev/null +++ b/api/_lib/function-count.test.ts @@ -0,0 +1,27 @@ +import { readdirSync, statSync } from "node:fs"; +import { join, relative } from "node:path"; +import { describe, expect, it } from "vitest"; + +// Vercel's Hobby plan deploys at most 12 functions; every .ts under api/ +// outside _-prefixed folders counts, tests included, and one more fails the deploy. +const HOBBY_LIMIT = 12; +const API_ROOT = join(__dirname, ".."); + +function functionFiles(dir: string): string[] { + return readdirSync(dir).flatMap((name) => { + const path = join(dir, name); + if (name.startsWith("_") || name.startsWith(".")) return []; + if (statSync(path).isDirectory()) return functionFiles(path); + return /\.(ts|js|mjs)$/.test(name) && !name.endsWith(".d.ts") ? [relative(API_ROOT, path)] : []; + }); +} + +describe("api functions", () => { + it("stay within the Vercel Hobby limit", () => { + expect(functionFiles(API_ROOT).length).toBeLessThanOrEqual(HOBBY_LIMIT); + }); + + it("do not include tests (they would deploy as functions)", () => { + expect(functionFiles(API_ROOT).filter((file) => file.includes(".test."))).toEqual([]); + }); +}); diff --git a/api/ranked/challenge.test.ts b/api/_lib/ranked-challenge.test.ts similarity index 94% rename from api/ranked/challenge.test.ts rename to api/_lib/ranked-challenge.test.ts index cfc0522..df0e695 100644 --- a/api/ranked/challenge.test.ts +++ b/api/_lib/ranked-challenge.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { selectSnippetCode } from "./challenge"; +import { selectSnippetCode } from "../ranked/challenge"; import { isWithinLengthSpec } from "../../src/utils/ranking"; import type { SnippetLength } from "../../src/types";