Refactor paired execution flow boundaries

This commit is contained in:
ejclaw
2026-04-07 00:45:17 +09:00
parent 0363021218
commit cbb6bc97c7
15 changed files with 1345 additions and 1116 deletions

View File

@@ -1,6 +1,9 @@
import { createHash } from 'crypto';
import fs from 'fs';
import path from 'path';
export {
computeVerificationSnapshotId,
resolveVerificationResponsesDir,
} from '../../../shared/verification-snapshot.js';
export const VERIFICATION_PROFILES = [
'test',
@@ -24,8 +27,6 @@ export interface VerificationResponse {
error?: string;
}
const SNAPSHOT_EXCLUDE_NAMES = new Set(['.git', 'node_modules', '.env']);
export function isVerificationProfile(
value: unknown,
): value is VerificationProfile {
@@ -35,47 +36,6 @@ export function isVerificationProfile(
);
}
function updateSnapshotHash(
hash: ReturnType<typeof createHash>,
repoDir: string,
currentPath: string,
): void {
const relPath = path.relative(repoDir, currentPath) || '.';
const stat = fs.lstatSync(currentPath);
if (stat.isDirectory()) {
if (relPath !== '.') {
hash.update(`dir\0${relPath}\0`);
}
for (const entry of fs.readdirSync(currentPath).sort()) {
if (SNAPSHOT_EXCLUDE_NAMES.has(entry)) continue;
updateSnapshotHash(hash, repoDir, path.join(currentPath, entry));
}
return;
}
if (stat.isSymbolicLink()) {
hash.update(`symlink\0${relPath}\0${fs.readlinkSync(currentPath)}\0`);
return;
}
if (stat.isFile()) {
hash.update(`file\0${relPath}\0`);
hash.update(fs.readFileSync(currentPath));
hash.update('\0');
}
}
export function computeVerificationSnapshotId(repoDir: string): string {
const hash = createHash('sha256');
updateSnapshotHash(hash, repoDir, repoDir);
return `fs:${hash.digest('hex').slice(0, 24)}`;
}
export function resolveVerificationResponsesDir(hostIpcDir: string): string {
return path.join(hostIpcDir, 'verification-responses');
}
export async function waitForVerificationResponse(
responseDir: string,
requestId: string,