From f3fc80daa5d093119ee13828cdfb0cf16cda8e0d Mon Sep 17 00:00:00 2001 From: Studio Date: Fri, 27 Nov 2026 12:48:31 -0500 Subject: [PATCH] T-23: Benchmark self-tests hash every untracked file in the worktree and fail on unreadable ones --- scripts/test/benchmark-research.test.ts | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scripts/test/benchmark-research.test.ts b/scripts/test/benchmark-research.test.ts index 0d98fd7b..26f26e22 100644 --- a/scripts/test/benchmark-research.test.ts +++ b/scripts/test/benchmark-research.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from 'bun:test'; +import { createHash } from 'node:crypto'; import { chmodSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; @@ -36,6 +37,9 @@ function withTempGitRepo(fn: (repoDir: string, protectForCleanup: (path: stri }; try { runGit(repoDir, ['init']); + const emptyExcludesPath = join(repoDir, '.git', 'info', 'exclude'); + writeFileSync(emptyExcludesPath, ''); + runGit(repoDir, ['config', 'core.excludesFile', emptyExcludesPath]); writeFileSync(join(repoDir, 'tracked.txt'), 'tracked-v1\n'); runGit(repoDir, ['add', 'tracked.txt']); runGit(repoDir, [ @@ -66,6 +70,18 @@ function fsError(code: string, path: string): NodeJS.ErrnoException { return error; } +function sha256(data: Uint8Array | string): string { + return createHash('sha256').update(data).digest('hex'); +} + +function expectedSourceSha256(entries: [string, string][]): string { + const hash = createHash('sha256'); + for (const [path, entry] of [...entries].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) { + hash.update(JSON.stringify([path, entry])); + } + return hash.digest('hex'); +} + describe('existing-path research benchmark', () => { test('fixture is seeded, ordered, hash-verified and detached by real dataset preparation', async () => { for (const assets of [1, 10]) { @@ -219,6 +235,12 @@ describe('existing-path research benchmark', () => { const second = identity({ sourceRoot: repoDir, readSourceFile }); expect(Object.keys(first)).toEqual(['source', 'native', 'runtime', 'host']); expect(first.source.contentSha256).toBe(second.source.contentSha256); + expect(first.source.contentSha256).toBe( + expectedSourceSha256([ + ['.bash_profile', 'unreadable'], + ['tracked.txt', sha256(readFileSync(trackedPath))], + ]) + ); expect(first.source.files).toBe(2); expect(first.source.dirty).toBe(true); expect(first.source.scope).toContain('unreadable'); @@ -299,6 +321,12 @@ describe('existing-path research benchmark', () => { const first = identity({ sourceRoot: repoDir }); const second = identity({ sourceRoot: repoDir }); expect(first.source.contentSha256).toBe(second.source.contentSha256); + expect(first.source.contentSha256).toBe( + expectedSourceSha256([ + ['tracked.txt', sha256(readFileSync(trackedPath))], + ['unreadable-untracked.txt', 'unreadable'], + ]) + ); expect(first.source.files).toBe(2); writeFileSync(trackedPath, 'tracked-v2\n'); @@ -318,6 +346,9 @@ describe('existing-path research benchmark', () => { rmSync(trackedPath); const afterDelete = identity({ sourceRoot: repoDir }); expect(afterDelete.source.contentSha256).not.toBe(beforeDelete.source.contentSha256); + expect(afterDelete.source.contentSha256).toBe( + expectedSourceSha256([['tracked.txt', 'deleted']]) + ); expect(afterDelete.source.files).toBe(1); expect(afterDelete.source.dirty).toBe(true); });