Skip to content

Commit 49bae5d

Browse files
fix(desktop): make lint and unit-test gates work on Windows (#2943)
## Summary On a Windows checkout the desktop quality gate does not work. This fixes four defects in it. Two checks report success without examining anything, one fails on every file, and one reports violations that its own allowlist already covers. **1. `pnpm test` finds no tests and still exits 0.** The `test` script quotes the glob with single quotes. On Windows pnpm runs scripts through `cmd.exe`, which does not strip single quotes, so node receives them as part of the pattern and matches nothing. The run prints `# tests 0` and exits 0 — a silent green. Double quotes are stripped by `cmd.exe` and by POSIX shells alike, so Linux CI behaviour is unchanged. **2. Every text file is checked out as CRLF.** There is no `.gitattributes`, and `core.autocrlf=true` is the Git for Windows default. Biome formats with LF, so `biome check .` fails on 1632 of 1633 files. `desktop/src/features/messages/ui/virtuaWheelModePatch.test.mjs` fails too, because it matches `patches/*.patch` with `\n`-joined patterns. The stored blobs are already LF, so `eol=lf` adds no renormalisation churn — `git status` stays clean after the change. **3. `check:px-text` never finds its own allowlist.** `scripts/check-px-text-core.mjs` builds the key from `path.relative`, which returns `\` separators on Windows, while the allowlist in `desktop/scripts/check-px-text.mjs` is written with `/`. Nothing matches, so the check reports 5 false violations on a clean tree. **4. `check:file-sizes` examines nothing at all.** `findRule` compares against `` `${rule.root}${path.sep}` ``. The roots are multi-segment (`src/app`, `src/features`, `src-tauri/src`), so on Windows `src/app\` never matches `src\app\...`. No rule matches any file: the check walks 0 of 1097 files and exits 0. `scripts/check-pubkey-truncation-core.mjs` already normalises paths this way (`relativePath.split(path.sep).join("/")`). This applies the same idiom to the other two. ### Related issue None found — no open issue covers this. The closest open PR is #2758, which fixes a fifth Windows defect in `desktop/test-loader-hooks.mjs`; it is required before the desktop unit tests can pass here, and it does not overlap with these files. I checked the changed-file list of every open PR: none touch `.gitattributes`, `desktop/package.json`, `scripts/check-px-text-core.mjs` or `scripts/check-file-sizes-core.mjs`. ### Testing Windows 11 (10.0.26200), node 22.17.1, pnpm 11.4.0, clean checkout with the default `core.autocrlf=true`. | Command | Before | After | | --- | --- | --- | | `pnpm test` | `# tests 0`, exit 0 | 374 test files discovered, exit 1 | | `biome check .` | 1632 of 1633 files fail | 1633 checked, 0 errors | | `pnpm check:px-text` | 5 false violations | passes | | `pnpm check:file-sizes` | 0 of 1097 files examined, exit 0 | 1097 examined | `check:file-sizes` now reports `src-tauri/src/managed_agents/runtime.rs: 2220 lines (limit 2216)`. That violation is pre-existing and not introduced here — `main` currently fails on the same line in CI (Desktop Core, run 30185213010, commit 62a5c3c). Before this change Windows reported success while CI was red; now the Windows result agrees with CI. Desktop unit tests still fail on Windows until #2758 lands. With #2758 applied on top of this branch the full suite passes: 3515 tests, 0 failures. This change stops hiding those failures rather than fixing them. Signed-off-by: Seydi Charyyev <[email protected]> Co-authored-by: Will Pfleger <[email protected]>
1 parent 23dc2bf commit 49bae5d

4 files changed

Lines changed: 32 additions & 11 deletions

File tree

‎.gitattributes‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Git for Windows defaults to core.autocrlf=true, so without this every text
2+
# file lands in the working copy with CRLF. Biome formats with LF
3+
# (biome.json sets no lineEnding override), which fails `biome check` on
4+
# effectively every file, and
5+
# desktop/src/features/messages/ui/virtuaWheelModePatch.test.mjs asserts on
6+
# patches/*.patch with `\n`-joined patterns. Normalize to LF in the working
7+
# copy on every platform; the stored blobs are already LF.
8+
* text=auto eol=lf

‎desktop/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "biome lint .",
1515
"check": "biome check . && pnpm check:file-sizes && pnpm check:px-text && pnpm check:pubkey-truncation",
1616
"format": "biome format --write .",
17-
"test": "node --import ./test-loader.mjs --experimental-strip-types --test 'src/**/*.test.mjs'",
17+
"test": "node --import ./test-loader.mjs --experimental-strip-types --test \"src/**/*.test.mjs\"",
1818
"preview": "vite preview",
1919
"tauri": "tauri",
2020
"test:e2e": "pnpm build:e2e && playwright test",

‎scripts/check-file-sizes-core.mjs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import path from "node:path";
1010
* the two apps can never drift.
1111
*/
1212

13+
// `rules[].root` and the `overrides` keys are authored with `/`, but
14+
// path.relative yields `\` on Windows — so every comparison against them has
15+
// to happen in posix form or it silently matches nothing.
16+
function toPosixPath(relativePath) {
17+
return relativePath.split(path.sep).join("/");
18+
}
19+
1320
async function walkFiles(directory) {
1421
const entries = await fs.readdir(directory, { withFileTypes: true });
1522
const files = await Promise.all(
@@ -27,10 +34,8 @@ async function walkFiles(directory) {
2734
}
2835

2936
function findRule(rules, relativePath) {
30-
return rules.find((rule) => {
31-
const normalizedRoot = `${rule.root}${path.sep}`;
32-
return relativePath.startsWith(normalizedRoot);
33-
});
37+
const posixPath = toPosixPath(relativePath);
38+
return rules.find((rule) => posixPath.startsWith(`${rule.root}/`));
3439
}
3540

3641
function countLines(content) {
@@ -82,11 +87,15 @@ export async function runFileSizeCheck({
8287
continue;
8388
}
8489

85-
const limit = overrides.get(relativePath) ?? rule.maxLines;
90+
const limit = overrides.get(toPosixPath(relativePath)) ?? rule.maxLines;
8691
const content = await fs.readFile(filePath, "utf8");
8792
const lineCount = countLines(content);
8893
if (lineCount > limit) {
89-
violations.push({ limit, lineCount, relativePath });
94+
violations.push({
95+
limit,
96+
lineCount,
97+
relativePath: toPosixPath(relativePath),
98+
});
9099
}
91100
}
92101

‎scripts/check-px-text-core.mjs‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ export async function runPxTextCheck({
7575
const violations = [];
7676

7777
for (const filePath of candidateFiles) {
78-
const relativePath = path.relative(projectRoot, filePath);
79-
const rule = rules.find((r) =>
80-
relativePath.startsWith(`${r.root}${path.sep}`),
81-
);
78+
// `rules[].root` and the `overrides` keys are authored with `/`, but
79+
// path.relative yields `\` on Windows — so every comparison against them
80+
// has to happen in posix form or it silently matches nothing.
81+
const relativePath = path
82+
.relative(projectRoot, filePath)
83+
.split(path.sep)
84+
.join("/");
85+
const rule = rules.find((r) => relativePath.startsWith(`${r.root}/`));
8286
if (!rule) {
8387
continue;
8488
}

0 commit comments

Comments
 (0)