From 6a9285d1f544f3a052c03c4d024aba8eeefdf41c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 18:35:55 +0000 Subject: [PATCH] test: tighten byte count and file identity coverage --- src/infra/file-identity.test.ts | 82 ++++++++++++++++++++++--------- src/infra/json-utf8-bytes.test.ts | 26 ++++++++-- 2 files changed, 81 insertions(+), 27 deletions(-) diff --git a/src/infra/file-identity.test.ts b/src/infra/file-identity.test.ts index 12b3029cda1..2a28255a1ac 100644 --- a/src/infra/file-identity.test.ts +++ b/src/infra/file-identity.test.ts @@ -6,28 +6,64 @@ function stat(dev: number | bigint, ino: number | bigint): FileIdentityStat { } describe("sameFileIdentity", () => { - it("accepts exact dev+ino match", () => { - expect(sameFileIdentity(stat(7, 11), stat(7, 11), "linux")).toBe(true); - }); - - it("rejects inode mismatch", () => { - expect(sameFileIdentity(stat(7, 11), stat(7, 12), "linux")).toBe(false); - }); - - it("rejects dev mismatch on non-windows", () => { - expect(sameFileIdentity(stat(7, 11), stat(8, 11), "linux")).toBe(false); - }); - - it("accepts win32 dev mismatch when either side is 0", () => { - expect(sameFileIdentity(stat(0, 11), stat(8, 11), "win32")).toBe(true); - expect(sameFileIdentity(stat(7, 11), stat(0, 11), "win32")).toBe(true); - }); - - it("keeps dev strictness on win32 when both dev values are non-zero", () => { - expect(sameFileIdentity(stat(7, 11), stat(8, 11), "win32")).toBe(false); - }); - - it("handles bigint stats", () => { - expect(sameFileIdentity(stat(0n, 11n), stat(8n, 11n), "win32")).toBe(true); + it.each([ + { + name: "accepts exact dev+ino match", + left: stat(7, 11), + right: stat(7, 11), + platform: "linux" as const, + expected: true, + }, + { + name: "rejects inode mismatch", + left: stat(7, 11), + right: stat(7, 12), + platform: "linux" as const, + expected: false, + }, + { + name: "rejects dev mismatch on non-windows", + left: stat(7, 11), + right: stat(8, 11), + platform: "linux" as const, + expected: false, + }, + { + name: "keeps dev strictness on linux when one side is zero", + left: stat(0, 11), + right: stat(8, 11), + platform: "linux" as const, + expected: false, + }, + { + name: "accepts win32 dev mismatch when either side is 0", + left: stat(0, 11), + right: stat(8, 11), + platform: "win32" as const, + expected: true, + }, + { + name: "accepts win32 dev mismatch when right side is 0", + left: stat(7, 11), + right: stat(0, 11), + platform: "win32" as const, + expected: true, + }, + { + name: "keeps dev strictness on win32 when both dev values are non-zero", + left: stat(7, 11), + right: stat(8, 11), + platform: "win32" as const, + expected: false, + }, + { + name: "handles bigint stats", + left: stat(0n, 11n), + right: stat(8n, 11n), + platform: "win32" as const, + expected: true, + }, + ])("$name", ({ left, right, platform, expected }) => { + expect(sameFileIdentity(left, right, platform)).toBe(expected); }); }); diff --git a/src/infra/json-utf8-bytes.test.ts b/src/infra/json-utf8-bytes.test.ts index 3418359ae5f..e2f8e217be0 100644 --- a/src/infra/json-utf8-bytes.test.ts +++ b/src/infra/json-utf8-bytes.test.ts @@ -2,10 +2,24 @@ import { describe, expect, it } from "vitest"; import { jsonUtf8Bytes } from "./json-utf8-bytes.js"; describe("jsonUtf8Bytes", () => { - it("returns utf8 byte length for serializable values", () => { - expect(jsonUtf8Bytes({ a: "x", b: [1, 2, 3] })).toBe( - Buffer.byteLength(JSON.stringify({ a: "x", b: [1, 2, 3] }), "utf8"), - ); + it.each([ + { + name: "object payloads", + value: { a: "x", b: [1, 2, 3] }, + expected: Buffer.byteLength(JSON.stringify({ a: "x", b: [1, 2, 3] }), "utf8"), + }, + { + name: "strings", + value: "hello", + expected: Buffer.byteLength(JSON.stringify("hello"), "utf8"), + }, + { + name: "undefined via string fallback", + value: undefined, + expected: Buffer.byteLength("undefined", "utf8"), + }, + ])("returns utf8 byte length for $name", ({ value, expected }) => { + expect(jsonUtf8Bytes(value)).toBe(expected); }); it("falls back to string conversion when JSON serialization throws", () => { @@ -13,4 +27,8 @@ describe("jsonUtf8Bytes", () => { circular.self = circular; expect(jsonUtf8Bytes(circular)).toBe(Buffer.byteLength("[object Object]", "utf8")); }); + + it("uses string conversion for BigInt serialization failures", () => { + expect(jsonUtf8Bytes(12n)).toBe(Buffer.byteLength("12", "utf8")); + }); });