T-23: Benchmark self-tests hash every untracked file in the worktree and fail on unreadable ones
This commit is contained in:
parent
b9536a7740
commit
f3fc80daa5
1 changed files with 31 additions and 0 deletions
|
|
@ -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<T>(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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue