Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(verify): keep the function-size ratchet passing on a Windows checkout

garrytan72795c65f0d6
diff --git a/.gitattributes b/.gitattributes
index a077452218..a6d22a5742 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -28,6 +28,12 @@
# removes the whole class for anyone working here.
*.md text eol=lf
+# Ratchet baselines (scripts/*.tsv) get the pin too: their parsers split rows
+# on LF, so under a CRLF checkout every row's last field ends in "\r", no
+# baseline row matches, and verify reports every grandfathered entry as a new
+# violation on a clean checkout.
+*.tsv text eol=lf
+
# Native source hashes and prebuilds must survive Windows checkout unchanged.
native/locks/** text eol=lf
native/locks/prebuilds/*.node binary
diff --git a/scripts/check-function-size.ts b/scripts/check-function-size.ts
index c070d2ac81..220ee67b9b 100644
--- a/scripts/check-function-size.ts
+++ b/scripts/check-function-size.ts
@@ -253,6 +253,7 @@ function baseBaselineText(): { text: string | null; source: string } {
return { text, source: text === null ? `${source}: no baseline yet (seed)` : source };
}
+const repoRelative = (abs: string) => relative(ROOT, abs).replace(/\\/g, '/');
const keyOf = (path: string, name: string) => `${path}\t${name}`;
const normalized = (s: string) => s.replace(/\s+/g, ' ').trim();
@@ -265,7 +266,7 @@ const normalized = (s: string) => s.replace(/\s+/g, ' ').trim();
*/
function moveNormalized(text: string, path: string): string {
const resolved = text.replace(/(['"])(\.\.?\/[^'"\n]*)\1/g, (_m, q: string, spec: string) =>
- `${q}@${relative(ROOT, resolve(dirname(join(ROOT, path)), spec))}${q}`);
+ `${q}@${repoRelative(resolve(dirname(join(ROOT, path)), spec))}${q}`);
return normalized(resolved).replace(/^export /, '');
}
@@ -286,7 +287,7 @@ function preambleOf(text: string): string {
function main(): number {
const t0 = performance.now();
const args = process.argv.slice(2);
- const measured = srcFiles(ROOT).flatMap((f) => measureSource(relative(ROOT, f), readFileSync(f, 'utf8')));
+ const measured = srcFiles(ROOT).flatMap((f) => measureSource(repoRelative(f), readFileSync(f, 'utf8')));
const byKey = new Map(measured.map((m) => [keyOf(m.path, m.name), m]));
const problems: string[] = [];
if (!existsSync(BASELINE)) {
diff --git a/test/scripts/tsv-eol.test.ts b/test/scripts/tsv-eol.test.ts
new file mode 100644
index 0000000000..e8b39368cb
--- /dev/null
+++ b/test/scripts/tsv-eol.test.ts
@@ -0,0 +1,20 @@
+/**
+ * The ratchet baselines (scripts/*.tsv) are parsed by splitting on LF. Git for Windows checks out with
+ * core.autocrlf=true, which would leave "\r" on each row and make verify report every baseline row as a
+ * new violation on a clean checkout (#8641), so .gitattributes pins every tracked TSV to eol=lf.
+ */
+import { expect, test } from 'bun:test';
+import { execFileSync } from 'node:child_process';
+import { resolve } from 'node:path';
+
+const ROOT = resolve(import.meta.dir, '..', '..');
+const git = (...args: string[]) => execFileSync('git', args, { cwd: ROOT, encoding: 'utf8' });
+
+test('every tracked TSV checks out with LF endings whatever core.autocrlf says', () => {
+ const tsvs = git('ls-files', '-z', '--', '*.tsv').split('\0').filter(Boolean);
+ expect(tsvs).toContain('scripts/function-size-baseline.tsv');
+ const attrs = git('check-attr', '-z', 'eol', '--', ...tsvs).split('\0');
+ const notLf: string[] = [];
+ for (let i = 0; i + 2 < attrs.length; i += 3) if (attrs[i + 2] !== 'lf') notLf.push(`${attrs[i]}: ${attrs[i + 2]}`);
+ expect(notLf).toEqual([]);
+});