From 31630a28c5e2ccbd0f71df360ed5689182103cf1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 13:48:15 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20test:=20add=20edge=20case=20?= =?UTF-8?q?coverage=20for=20base64Url=20in=20serve.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add robust unit tests for base64Url in tests/serve.test.js - Wrap server.listen in require.main === module to prevent port collisions during testing - Export base64Url conditionally for testing Co-authored-by: megawron <52606827+megawron@users.noreply.github.com> --- serve.js | 32 +++++++++++++++++++------------- tests/serve.test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 tests/serve.test.js diff --git a/serve.js b/serve.js index 0fe3dcc..a294666 100644 --- a/serve.js +++ b/serve.js @@ -334,16 +334,22 @@ const server = http.createServer((req, res) => { } }); -server.listen(PORT, () => { - console.log(`\x1b[32m[ZeroCMS] Server running at http://localhost:${PORT}\x1b[0m`); - console.log(`\x1b[33mOpen http://localhost:${PORT} to start the CMS.\x1b[0m`); - if (CLIENT_ID === 'YOUR_CLIENT_ID') { - console.log(`\x1b[31m[!] GITHUB_CLIENT_ID is not configured. OAuth will not work.\x1b[0m`); - } - if (!APP_ID) { - console.log(`\x1b[33m[!] GITHUB_APP_ID not found. Organization support disabled.\x1b[0m`); - } - if (!PRIVATE_KEY) { - console.log(`\x1b[33m[!] GITHUB_PRIVATE_KEY not found. Organization support disabled.\x1b[0m`); - } -}); +if (require.main === module) { + server.listen(PORT, () => { + console.log(`\x1b[32m[ZeroCMS] Server running at http://localhost:${PORT}\x1b[0m`); + console.log(`\x1b[33mOpen http://localhost:${PORT} to start the CMS.\x1b[0m`); + if (CLIENT_ID === 'YOUR_CLIENT_ID') { + console.log(`\x1b[31m[!] GITHUB_CLIENT_ID is not configured. OAuth will not work.\x1b[0m`); + } + if (!APP_ID) { + console.log(`\x1b[33m[!] GITHUB_APP_ID not found. Organization support disabled.\x1b[0m`); + } + if (!PRIVATE_KEY) { + console.log(`\x1b[33m[!] GITHUB_PRIVATE_KEY not found. Organization support disabled.\x1b[0m`); + } + }); +} + +if (typeof module !== 'undefined') { + module.exports.base64Url = base64Url; +} diff --git a/tests/serve.test.js b/tests/serve.test.js new file mode 100644 index 0000000..748a0d9 --- /dev/null +++ b/tests/serve.test.js @@ -0,0 +1,30 @@ +const { test, expect } = require("bun:test"); +const { base64Url } = require("../serve.js"); + +test("base64Url handles standard string", () => { + expect(base64Url("hello world")).toBe("aGVsbG8gd29ybGQ"); +}); + +test("base64Url handles empty string", () => { + expect(base64Url("")).toBe(""); +}); + +test("base64Url replaces + with -", () => { + // String.fromCharCode(0, 190) creates a string whose standard base64 encoding contains '+' + // The standard base64 is AMK+ + const input = String.fromCharCode(0, 190); + expect(base64Url(input)).toBe("AMK-"); +}); + +test("base64Url replaces / with _", () => { + // String.fromCharCode(128, 63) creates a string whose standard base64 encoding contains '/' + // The standard base64 is woA/ + const input = String.fromCharCode(128, 63); + expect(base64Url(input)).toBe("woA_"); +}); + +test("base64Url removes =", () => { + // 'a' has standard base64 encoding 'YQ==' + // The two '=' should be removed + expect(base64Url("a")).toBe("YQ"); +}); From 44e30258f4ccecbf9b93be22c1cac94995b2b578 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 14:38:08 +0000 Subject: [PATCH 2/2] fix: resolve Bun.build failure caused by missing wasm files - Updated `build.mjs` to use recursive `cp` instead of iterating and checking with `readdir` directly, which fixes `EISDIR` errors - Marked generated WASM JS and binary files as external in the Bun builder configuration to prevent CI resolution errors when the artifacts aren't built - Verified that `serve.test.js` remains intact and `base64Url` runs accurately. Co-authored-by: megawron <52606827+megawron@users.noreply.github.com> --- build.mjs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/build.mjs b/build.mjs index 26ae01c..6cb79e6 100644 --- a/build.mjs +++ b/build.mjs @@ -1,4 +1,4 @@ -import { rm, mkdir, readdir } from "node:fs/promises"; +import { rm, mkdir, cp } from "node:fs/promises"; import { join } from "node:path"; const DIST = "dist"; @@ -21,7 +21,7 @@ async function build() { minify: true, sourcemap: "external", target: "browser", - external: ["/lib/*"], + external: ["/lib/*", "*/zerocms_tagger.js", "*/zerocms_tagger_bg.wasm"], }); if (!result.success) { @@ -31,12 +31,7 @@ async function build() { // 3. Copy Static Libraries console.log("📂 Copying libraries..."); - const libs = await readdir("lib"); - for (const lib of libs) { - const src = join("lib", lib); - const dest = join(DIST, "lib", lib); - await Bun.write(dest, Bun.file(src)); - } + await cp("lib", join(DIST, "lib"), { recursive: true }); // Extract the generated hashed file name from Bun's output const jsOutput = result.outputs.find(out => out.path.endsWith('.js'));