Format verification runtime cleanup

This commit is contained in:
ejclaw
2026-04-08 05:31:27 +09:00
parent edd5b45d99
commit 46274f2372
2 changed files with 44 additions and 18 deletions

View File

@@ -73,11 +73,17 @@ describe('verification helpers', () => {
); );
fs.mkdirSync(path.join(repoDir, 'dist'), { recursive: true }); fs.mkdirSync(path.join(repoDir, 'dist'), { recursive: true });
fs.writeFileSync(path.join(repoDir, '.env'), 'SECRET=1\n'); fs.writeFileSync(path.join(repoDir, '.env'), 'SECRET=1\n');
fs.writeFileSync(path.join(repoDir, 'dist', 'index.js'), 'export const x = 1;\n'); fs.writeFileSync(
path.join(repoDir, 'dist', 'index.js'),
'export const x = 1;\n',
);
const first = computeVerificationSnapshot(repoDir).snapshotId; const first = computeVerificationSnapshot(repoDir).snapshotId;
fs.writeFileSync(path.join(repoDir, '.env'), 'SECRET=2\n'); fs.writeFileSync(path.join(repoDir, '.env'), 'SECRET=2\n');
fs.writeFileSync(path.join(repoDir, 'dist', 'index.js'), 'export const x = 2;\n'); fs.writeFileSync(
path.join(repoDir, 'dist', 'index.js'),
'export const x = 2;\n',
);
const second = computeVerificationSnapshot(repoDir).snapshotId; const second = computeVerificationSnapshot(repoDir).snapshotId;
fs.writeFileSync( fs.writeFileSync(
path.join(repoDir, 'src', 'index.ts'), path.join(repoDir, 'src', 'index.ts'),
@@ -212,12 +218,15 @@ describe('verification helpers', () => {
packageManager: 'bun@1.3.11', packageManager: 'bun@1.3.11',
scripts: { scripts: {
typecheck: typecheck:
'node -e "process.stdout.write(\'typecheck:\' + (process.env.CI || \'missing\'))"', "node -e \"process.stdout.write('typecheck:' + (process.env.CI || 'missing'))\"",
}, },
}), }),
); );
fs.writeFileSync(path.join(repoDir, 'bun.lock'), ''); fs.writeFileSync(path.join(repoDir, 'bun.lock'), '');
fs.writeFileSync(path.join(repoDir, 'node_modules', '.bin', 'placeholder'), ''); fs.writeFileSync(
path.join(repoDir, 'node_modules', '.bin', 'placeholder'),
'',
);
fs.writeFileSync( fs.writeFileSync(
path.join(repoDir, 'src', 'index.ts'), path.join(repoDir, 'src', 'index.ts'),
'export const value = 1;\n', 'export const value = 1;\n',
@@ -260,14 +269,18 @@ describe('verification helpers', () => {
}), }),
); );
fs.writeFileSync(path.join(repoDir, 'bun.lock'), ''); fs.writeFileSync(path.join(repoDir, 'bun.lock'), '');
fs.writeFileSync(path.join(repoDir, 'node_modules', '.bin', 'placeholder'), ''); fs.writeFileSync(
path.join(repoDir, 'node_modules', '.bin', 'placeholder'),
'',
);
ensureWorkspaceDependenciesInstalled(repoDir); ensureWorkspaceDependenciesInstalled(repoDir);
const previousSecret = process.env.EJCLAW_VERIFICATION_SECRET; const previousSecret = process.env.EJCLAW_VERIFICATION_SECRET;
process.env.EJCLAW_VERIFICATION_SECRET = 'top-secret'; process.env.EJCLAW_VERIFICATION_SECRET = 'top-secret';
try { try {
const expectedSnapshotId = computeVerificationSnapshot(repoDir).snapshotId; const expectedSnapshotId =
computeVerificationSnapshot(repoDir).snapshotId;
const result = await runVerificationRequest( const result = await runVerificationRequest(
{ {
requestId: 'req-direct-typecheck-secret', requestId: 'req-direct-typecheck-secret',
@@ -303,12 +316,15 @@ describe('verification helpers', () => {
name: 'verification-direct-mutate', name: 'verification-direct-mutate',
packageManager: 'bun@1.3.11', packageManager: 'bun@1.3.11',
scripts: { scripts: {
test: 'node -e "require(\'node:fs\').writeFileSync(\'src/generated.txt\', \'x\\\\n\')"', test: "node -e \"require('node:fs').writeFileSync('src/generated.txt', 'x\\\\n')\"",
}, },
}), }),
); );
fs.writeFileSync(path.join(repoDir, 'bun.lock'), ''); fs.writeFileSync(path.join(repoDir, 'bun.lock'), '');
fs.writeFileSync(path.join(repoDir, 'node_modules', '.bin', 'placeholder'), ''); fs.writeFileSync(
path.join(repoDir, 'node_modules', '.bin', 'placeholder'),
'',
);
fs.writeFileSync( fs.writeFileSync(
path.join(repoDir, 'src', 'index.ts'), path.join(repoDir, 'src', 'index.ts'),
'export const value = 1;\n', 'export const value = 1;\n',
@@ -329,7 +345,9 @@ describe('verification helpers', () => {
expect(result.exitCode).toBe(1); expect(result.exitCode).toBe(1);
expect(result.error).toContain('Workspace changed during verification'); expect(result.error).toContain('Workspace changed during verification');
expect(result.snapshotId).not.toBe(expectedSnapshotId); expect(result.snapshotId).not.toBe(expectedSnapshotId);
expect(fs.existsSync(path.join(repoDir, 'src', 'generated.txt'))).toBe(true); expect(fs.existsSync(path.join(repoDir, 'src', 'generated.txt'))).toBe(
true,
);
}); });
it('allows build verification to write excluded output directories', async () => { it('allows build verification to write excluded output directories', async () => {
@@ -346,12 +364,16 @@ describe('verification helpers', () => {
name: 'verification-build-direct', name: 'verification-build-direct',
packageManager: 'bun@1.3.11', packageManager: 'bun@1.3.11',
scripts: { scripts: {
build: 'node -e "require(\'node:fs\').mkdirSync(\'dist\', { recursive: true }); require(\'node:fs\').writeFileSync(\'dist/output.js\', \'ok\\\\n\')"', build:
"node -e \"require('node:fs').mkdirSync('dist', { recursive: true }); require('node:fs').writeFileSync('dist/output.js', 'ok\\\\n')\"",
}, },
}), }),
); );
fs.writeFileSync(path.join(repoDir, 'bun.lock'), ''); fs.writeFileSync(path.join(repoDir, 'bun.lock'), '');
fs.writeFileSync(path.join(repoDir, 'node_modules', '.bin', 'placeholder'), ''); fs.writeFileSync(
path.join(repoDir, 'node_modules', '.bin', 'placeholder'),
'',
);
fs.writeFileSync( fs.writeFileSync(
path.join(repoDir, 'src', 'index.ts'), path.join(repoDir, 'src', 'index.ts'),
'export const value = 1;\n', 'export const value = 1;\n',
@@ -372,8 +394,8 @@ describe('verification helpers', () => {
expect(result.exitCode).toBe(0); expect(result.exitCode).toBe(0);
expect(result.runtimeVersion).toMatch(/^host:bun@/); expect(result.runtimeVersion).toMatch(/^host:bun@/);
expect(result.snapshotId).toBe(expectedSnapshotId); expect(result.snapshotId).toBe(expectedSnapshotId);
expect(fs.readFileSync(path.join(repoDir, 'dist', 'output.js'), 'utf-8')).toBe( expect(
'ok\n', fs.readFileSync(path.join(repoDir, 'dist', 'output.js'), 'utf-8'),
); ).toBe('ok\n');
}); });
}); });

View File

@@ -325,10 +325,14 @@ export async function runVerificationRequest(
try { try {
try { try {
const { stdout, stderr } = await execFileCapture(command.file, command.args, { const { stdout, stderr } = await execFileCapture(
cwd: repoDir, command.file,
env: directExecution.env, command.args,
}); {
cwd: repoDir,
env: directExecution.env,
},
);
const afterSnapshot = computeVerificationSnapshot(repoDir); const afterSnapshot = computeVerificationSnapshot(repoDir);
if (afterSnapshot.snapshotId !== beforeSnapshot.snapshotId) { if (afterSnapshot.snapshotId !== beforeSnapshot.snapshotId) {
return { return {