Trim verification snapshot scope

This commit is contained in:
ejclaw
2026-04-08 03:49:54 +09:00
parent 6907a71483
commit c0f7f2c12d
4 changed files with 114 additions and 8 deletions

View File

@@ -2,6 +2,10 @@ export declare const VERIFICATION_SNAPSHOT_EXCLUDE_NAMES: ReadonlySet<string>;
export declare function isVerificationSnapshotExcludedName(
name: string,
): boolean;
export declare function isVerificationSnapshotExcludedPath(
repoDir: string,
currentPath: string,
): boolean;
export declare function computeVerificationSnapshotId(repoDir: string): string;
export declare function resolveVerificationResponsesDir(
hostIpcDir: string,

View File

@@ -3,15 +3,46 @@ import fs from 'fs';
import path from 'path';
export const VERIFICATION_SNAPSHOT_EXCLUDE_NAMES = new Set([
'.git',
'node_modules',
'.env',
]);
const VERIFICATION_SNAPSHOT_ROOT_EXCLUDE_NAMES = new Set([
'.git',
'.env',
'data',
'logs',
'cache',
'.ejclaw-reviewer-runtime',
]);
const VERIFICATION_SNAPSHOT_ROOT_EXCLUDE_PREFIXES = [
'store.local-backup-',
];
export function isVerificationSnapshotExcludedName(name) {
return VERIFICATION_SNAPSHOT_EXCLUDE_NAMES.has(name);
}
export function isVerificationSnapshotExcludedPath(repoDir, currentPath) {
const name = path.basename(currentPath);
if (isVerificationSnapshotExcludedName(name)) {
return true;
}
const relPath = path.relative(repoDir, currentPath);
const isRepoRootEntry = relPath !== '' && !relPath.includes(path.sep);
if (!isRepoRootEntry) {
return false;
}
return (
VERIFICATION_SNAPSHOT_ROOT_EXCLUDE_NAMES.has(name) ||
VERIFICATION_SNAPSHOT_ROOT_EXCLUDE_PREFIXES.some((prefix) =>
name.startsWith(prefix),
)
);
}
function updateVerificationSnapshotHash(hash, repoDir, currentPath) {
const relPath = path.relative(repoDir, currentPath) || '.';
const stat = fs.lstatSync(currentPath);
@@ -21,8 +52,9 @@ function updateVerificationSnapshotHash(hash, repoDir, currentPath) {
hash.update(`dir\0${relPath}\0`);
}
for (const entry of fs.readdirSync(currentPath).sort()) {
if (isVerificationSnapshotExcludedName(entry)) continue;
updateVerificationSnapshotHash(hash, repoDir, path.join(currentPath, entry));
const nextPath = path.join(currentPath, entry);
if (isVerificationSnapshotExcludedPath(repoDir, nextPath)) continue;
updateVerificationSnapshotHash(hash, repoDir, nextPath);
}
return;
}