Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(vibe-tests): setup-integrity cases run one analysis each (#9976)

Christopher Chedeau4d7dca6ec750
diff --git a/internal/vibe-tests/setup-test/setup-integrity.mjs b/internal/vibe-tests/setup-test/setup-integrity.mjs
index 47e0d15e59..b1bc698cc6 100644
--- a/internal/vibe-tests/setup-test/setup-integrity.mjs
+++ b/internal/vibe-tests/setup-test/setup-integrity.mjs
@@ -195,6 +195,13 @@ function updateFramed(hash, label, bytes) {
hash.update('\0');
}
+function untrackedEntries(appDir) {
+ return untrackedPaths(appDir).map(relativePath => ({
+ path: relativePath,
+ ...untrackedEntry(appDir, relativePath),
+ }));
+}
+
function digestDiff(patch, untracked) {
const hash = crypto.createHash('sha256');
updateFramed(hash, 'format', 'setup-integrity-v1');
@@ -746,6 +753,20 @@ function findingsFor(relativePath, lines, maskedSpans, importantLines) {
return findings;
}
+/**
+ * The `diffSha256` that `analyzeSetupIntegrity` reports for the working tree,
+ * from only the git reads the digest needs. A caller that only attests a
+ * working tree uses it instead of a full analysis.
+ */
+export function setupDiffSha256(appDir) {
+ const resolvedAppDir = path.resolve(appDir);
+ assertRepositoryRoot(resolvedAppDir);
+ return digestDiff(
+ trackedPatch(resolvedAppDir),
+ untrackedEntries(resolvedAppDir),
+ );
+}
+
/**
* Analyze the working tree relative to its committed pre-agent HEAD.
* This function only invokes read-only Git commands and reads file bytes.
@@ -755,10 +776,7 @@ export function analyzeSetupIntegrity(appDir, attestedDiffSha256) {
assertRepositoryRoot(resolvedAppDir);
const patch = trackedPatch(resolvedAppDir);
- const untracked = untrackedPaths(resolvedAppDir).map(relativePath => ({
- path: relativePath,
- ...untrackedEntry(resolvedAppDir, relativePath),
- }));
+ const untracked = untrackedEntries(resolvedAppDir);
const untrackedByPath = new Map(untracked.map(file => [file.path, file]));
const tracked = trackedNumstat(resolvedAppDir);
// Each git command is a process launch, so a file's baseline and its
diff --git a/internal/vibe-tests/setup-test/setup-integrity.test.mjs b/internal/vibe-tests/setup-test/setup-integrity.test.mjs
index 640d1f6f79..f5b2a360de 100644
--- a/internal/vibe-tests/setup-test/setup-integrity.test.mjs
+++ b/internal/vibe-tests/setup-test/setup-integrity.test.mjs
@@ -5,10 +5,11 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
-import {afterAll, afterEach, describe, expect, it} from 'vitest';
+import {afterAll, afterEach, beforeAll, describe, expect, it} from 'vitest';
import {
analyzeSetupIntegrity,
pairedModeArmSpans,
+ setupDiffSha256,
substantiveLineDelta,
WHOLESALE_REPLACEMENT_THRESHOLD,
} from './setup-integrity.mjs';
@@ -37,9 +38,13 @@ function write(directory, relativePath, content) {
fs.writeFileSync(file, content);
}
-// The baseline repository is built once and copied for each test. A copy
-// costs no git launch, and each launch is slow on a loaded machine.
+// The baseline repository is built once, before the tests, and copied for
+// each test. A copy costs no git launch, and each launch is slow on a loaded
+// machine.
let baselineRepository = null;
+beforeAll(() => {
+ baselineRepository = baseline();
+});
afterAll(() => {
if (baselineRepository !== null) {
fs.rmSync(baselineRepository, {recursive: true, force: true});
@@ -47,9 +52,6 @@ afterAll(() => {
});
function repository() {
- if (baselineRepository === null) {
- baselineRepository = baseline();
- }
const directory = fs.mkdtempSync(
path.join(os.tmpdir(), 'setup-integrity-test-'),
);
@@ -113,7 +115,7 @@ function addValidAstryxChange(directory) {
}
function attest(directory) {
- return analyzeSetupIntegrity(directory).diffSha256;
+ return setupDiffSha256(directory);
}
function kinds(result) {