From 84262f9277f14fc3a493d46c31789942ea5cb55e Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:37:46 -0600 Subject: [PATCH] fix(www): make site tests pass on Windows (#62207) --- .gitattributes | 2 ++ services/www/site/test/install-commands.test.ts | 10 +++++++--- services/www/site/test/product-name.test.ts | 3 ++- services/www/site/test/server-bundle.test.ts | 7 +++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitattributes b/.gitattributes index 8e1fcf5679d..016137698d3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,3 +9,5 @@ packages/client/src/effect/generated/** linguist-generated packages/client/src/effect/api/** linguist-generated packages/core/src/**/*.txt text eol=lf packages/httpapi-codegen/test/generated/*.ts text eol=lf +# The site tests compare source text and humans.txt byte for byte, so Windows checkouts keep LF. +services/www/** text=auto eol=lf diff --git a/services/www/site/test/install-commands.test.ts b/services/www/site/test/install-commands.test.ts index af33d52a128..65a80a91ef4 100644 --- a/services/www/site/test/install-commands.test.ts +++ b/services/www/site/test/install-commands.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from "bun:test" +import path from "node:path" import { Glob } from "bun" import { desktopInstall, docsInstalls, installs, sdkInstalls } from "../src/lib/install-commands" @@ -13,7 +14,7 @@ const v1 = [ { name: "the AUR opencode package", pattern: /\b(paru|yay|pacman) -S opencode(?![\w-])/ }, ] -const app = new URL("..", import.meta.url).pathname +const app = path.join(import.meta.dir, "..") // Site copy and the sources of every generated text file (llms.txt, llms-full.txt, the .md pages, // the view-source comment, voice answers). Not .output: a stale build would fail the test. const roots = ["src", "public", "script"] @@ -25,7 +26,10 @@ const stored = new Set(["src/lib/github-snapshot.json"]) async function files() { const found = await Promise.all( roots.map((root) => - Array.fromAsync(new Glob(`${root}/**/*`).scan({ cwd: app, onlyFiles: true, dot: true })).catch(() => []), + Array.fromAsync(new Glob(`${root}/**/*`).scan({ cwd: app, onlyFiles: true, dot: true })).then( + (files) => files.map((file) => file.replaceAll("\\", "/")), + () => [], + ), ), ) return found.flat().filter((file) => text.test(file) && !stored.has(file) && !file.includes("node_modules")) @@ -55,7 +59,7 @@ describe("install commands", () => { const hits = ( await Promise.all( list.map(async (file) => - (await Bun.file(`${app}${file}`).text()).split("\n").flatMap((line, index) => + (await Bun.file(path.join(app, file)).text()).split("\n").flatMap((line, index) => // Comments may name the OpenCode 1 packages to explain why the site doesn't. /^\s*(\/\/|\*|\/\*)/.test(line) ? [] diff --git a/services/www/site/test/product-name.test.ts b/services/www/site/test/product-name.test.ts index 3cdf40cefba..fde2a94e310 100644 --- a/services/www/site/test/product-name.test.ts +++ b/services/www/site/test/product-name.test.ts @@ -52,7 +52,8 @@ function visibleText(file: string, source: string) { } async function scan(pattern: string, read: (file: string, source: string) => string[]) { - const files = await Array.fromAsync(new Glob(pattern).scan({ cwd: root })) + // Glob returns backslash paths on Windows; the allowlist uses forward slashes. + const files = (await Array.fromAsync(new Glob(pattern).scan({ cwd: root }))).map((file) => file.replaceAll("\\", "/")) const found = await Promise.all( files.map(async (file) => { const source = await Bun.file(path.join(root, file)).text() diff --git a/services/www/site/test/server-bundle.test.ts b/services/www/site/test/server-bundle.test.ts index 995c5ad3187..3b6fb0656bd 100644 --- a/services/www/site/test/server-bundle.test.ts +++ b/services/www/site/test/server-bundle.test.ts @@ -9,7 +9,10 @@ import { Glob } from "bun" // script/check-server-bundle.ts checks the built output too. const src = path.resolve(import.meta.dir, "..", "src") -const files = await Array.fromAsync(new Glob("**/*.{ts,tsx}").scan({ cwd: src })) +// Forward slashes on every platform, so they compare with import specifiers. +const files = (await Array.fromAsync(new Glob("**/*.{ts,tsx}").scan({ cwd: src }))).map((file) => + file.replaceAll("\\", "/"), +) const sources = new Map( await Promise.all(files.map(async (file) => [file, await Bun.file(path.join(src, file)).text()] as const)), ) @@ -33,7 +36,7 @@ const browserOnly = (() => { })() function specifiers(file: string, target: string) { - const relative = path.relative(path.dirname(file), target).replace(/\.tsx?$/, "") + const relative = path.posix.relative(path.posix.dirname(file), target).replace(/\.tsx?$/, "") return [relative.startsWith(".") ? relative : `./${relative}`, `~/${target.replace(/\.tsx?$/, "")}`] }