fix: remove open execution record caps and preserve recovery history

This commit is contained in:
Agent Workbench Dev
2026-11-07 03:17:05 +08:00
parent affd733d03
commit 32780bee8d
22 changed files with 595 additions and 74 deletions
+15
View File
@@ -41,4 +41,19 @@ export class ArtifactStore {
if (bytes.length !== artifact.bytes || createHash('sha256').update(bytes).digest('hex') !== artifact.sha256) throw new Error('执行工件校验失败,实际结果需要核对。');
return bytes;
}
verify(artifact) {
if (!/^[a-f0-9]{2}\/[a-f0-9]{64}\.blob$/.test(artifact.relative)) throw new Error('执行工件路径无效。');
const file = path.join(this.root, artifact.relative);
if (fs.lstatSync(path.dirname(file)).isSymbolicLink() || fs.lstatSync(file).isSymbolicLink()) throw new Error('执行工件不能是链接。');
const handle = fs.openSync(file, 'r');
try {
const stat = fs.fstatSync(handle);
if (!stat.isFile() || stat.size !== artifact.bytes) throw new Error('执行工件校验失败,实际结果需要核对。');
const hash = createHash('sha256'), buffer = Buffer.allocUnsafe(Math.min(1024 * 1024, Math.max(1, stat.size)));
let length = 0, bytes;
while ((bytes = fs.readSync(handle, buffer, 0, buffer.length, null)) > 0) { length += bytes; hash.update(buffer.subarray(0, bytes)); }
if (length !== artifact.bytes || hash.digest('hex') !== artifact.sha256) throw new Error('执行工件校验失败,实际结果需要核对。');
return { bytes: length, sha256: artifact.sha256 };
} finally { fs.closeSync(handle); }
}
}