From aa52b89a97aee1c91ad7fccb271ce146e0eddc23 Mon Sep 17 00:00:00 2001 From: Agnik47 <140933190+Agnik47@users.noreply.github.com> Date: Sat, 8 Aug 2026 12:58:24 +0530 Subject: [PATCH] fix: run src/browser unit tests in CI and stabilize the vendor digest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `unit` vitest project excluded `src/browser/**/*.test.ts`, and no other project picked them up: `plugin` covers `plugins/*/test/**`, `e2e` lists individual files under `tests/e2e/`, and `smoke` covers `tests/smoke/**`. That left 44 test files (596 tests) covering CDP, snapshots, the Playwright sandbox and the local Cloak runtime out of every CI job. The exclude was introduced in #196 rather than #216 — that merge only dropped the `clis/**` half of the list after the adapter migration. Dropping the exclude also restores vitest's default excludes (node_modules, dist) and matches the other four projects, none of which set `exclude`. Enabling the tests surfaces a pre-existing Windows failure in `playwright-client-build.test.ts`, which shells out to `build-playwright-sandbox-client.mjs --check`. Two independent causes: - `vendorDigest()` hashes the relative path of each vendored file, built with `path.join()`, so entries hash as `client\artifact.ts` on Windows and `client/artifact.ts` elsewhere. The digest was therefore platform-dependent and could never match the pinned manifest on Windows. Normalizing the separator to `/` is a no-op on POSIX, so the pinned hash is unchanged. - The vendored sources and the generated bundle are compared byte-for-byte, so a CRLF checkout breaks both the digest and the "bundle is up to date" check. `.gitattributes` pins just those paths to LF. Refs #231 Co-Authored-By: Claude Opus 5 --- .gitattributes | 6 ++++++ scripts/build-playwright-sandbox-client.mjs | 4 ++-- vitest.config.ts | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a7f95a9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# The vendored Playwright client is verified by a byte-exact SHA-256 digest +# (scripts/build-playwright-sandbox-client.mjs), and the generated bundle is +# byte-compared against a fresh esbuild output. Both must therefore check out +# identically on every platform, regardless of core.autocrlf. +src/browser/run/playwright-client/vendor/** text eol=lf +src/browser/run/generated/playwright-client.js text eol=lf diff --git a/scripts/build-playwright-sandbox-client.mjs b/scripts/build-playwright-sandbox-client.mjs index 4e58a16..46b6ab2 100644 --- a/scripts/build-playwright-sandbox-client.mjs +++ b/scripts/build-playwright-sandbox-client.mjs @@ -1,7 +1,7 @@ import { createHash } from 'node:crypto'; import { mkdtemp, readFile, readdir, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; -import { join } from 'node:path'; +import { join, sep } from 'node:path'; import { build } from 'esbuild'; const output = 'src/browser/run/generated/playwright-client.js'; @@ -24,7 +24,7 @@ async function vendorDigest(directory) { await walk(directory); const hash = createHash('sha256'); for (const file of files.sort()) { - const entry = file.slice(directory.length + 1); + const entry = file.slice(directory.length + 1).split(sep).join('/'); hash.update(entry); hash.update('\0'); hash.update(await readFile(file)); diff --git a/vitest.config.ts b/vitest.config.ts index 45b8347..8a7df98 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -23,7 +23,6 @@ export default defineConfig({ test: { name: 'unit', include: ['src/**/*.test.ts'], - exclude: ['src/browser/**/*.test.ts'], sequence: { groupOrder: 0 }, }, },