fix(telegram): stage full proof artifacts safely

This commit is contained in:
Vincent Koc
2026-06-20 18:47:02 +02:00
parent 1989726eb6
commit 32cbaecd09
2 changed files with 64 additions and 1 deletions

View File

@@ -1930,6 +1930,35 @@ function writeSession(pathname: string, session: SessionFile) {
fs.chmodSync(pathname, 0o600);
}
const FULL_ARTIFACT_JSON_NAMES = new Set([
"probe.json",
"status.json",
"telegram-user-crabbox-proof-summary.json",
"telegram-user-crabbox-session-summary.json",
]);
const FULL_ARTIFACT_FILE_EXTENSIONS = new Set([".gif", ".log", ".md", ".mp4", ".png"]);
export function stageFullSessionArtifacts(outputDir: string) {
const publishDir = path.join(outputDir, "publish-full-artifacts");
fs.rmSync(publishDir, { force: true, recursive: true });
fs.mkdirSync(publishDir, { recursive: true });
for (const entry of fs.readdirSync(outputDir, { withFileTypes: true })) {
if (!entry.isFile()) {
continue;
}
const extension = path.extname(entry.name);
const isPublishableArtifact =
FULL_ARTIFACT_FILE_EXTENSIONS.has(extension) || FULL_ARTIFACT_JSON_NAMES.has(entry.name);
if (!isPublishableArtifact) {
continue;
}
fs.copyFileSync(path.join(outputDir, entry.name), path.join(publishDir, entry.name));
}
return publishDir;
}
function readSession(root: string, opts: Options, outputDir: string) {
const pathname = sessionPath(root, opts, outputDir);
if (!fs.existsSync(pathname)) {
@@ -2462,7 +2491,7 @@ async function publishSessionArtifacts(root: string, opts: Options, outputDir: s
);
const publishGifPath = fs.existsSync(croppedMotionGifPath) ? croppedMotionGifPath : motionGifPath;
const publishDir = opts.publishFullArtifacts
? session.outputDir
? stageFullSessionArtifacts(session.outputDir)
: path.join(session.outputDir, "publish-gif-only");
if (!opts.publishFullArtifacts) {
if (!fs.existsSync(publishGifPath)) {