fix(audit): tolerate missing phase0 artifact dir in prune

Treat missing artifacts dir as empty input for prune planning/apply workflows on fresh hosts; keep report output behavior intact. Architecture/protocol diagrams reviewed; no updates needed for this script robustness change.
This commit is contained in:
William Valentin
2026-02-27 13:28:40 -08:00
parent bfa857f074
commit c91262ac30
2 changed files with 24 additions and 2 deletions
+11
View File
@@ -593,6 +593,17 @@
],
"test_status": "pnpm typecheck + node --import tsx/esm scripts/check-phase0-baseline-backend-drift.ts --artifacts-dir docs/plans/artifacts --backend native,native --format json + synthetic-audit capture smoke check passing"
},
"phase0-live-baseline-prune-missing-dir-resilience": {
"status": "completed",
"date": "2026-02-27",
"updated": "2026-02-27",
"summary": "Hardened prune CLI behavior for fresh hosts by treating a missing artifacts directory as an empty artifact set (instead of failing with ENOENT), while preserving report generation behavior.",
"files_modified": [
"scripts/prune-phase0-baseline-artifacts.ts",
"docs/plans/state.json"
],
"test_status": "pnpm typecheck + node --import tsx/esm scripts/prune-phase0-baseline-artifacts.ts --artifacts-dir <missing-dir> --format json passing"
},
"phase0-instrumentation-ticket-checklist": {
"status": "completed",
"date": "2026-02-25",
+13 -2
View File
@@ -15,7 +15,7 @@ function usage(): string {
'',
'Options:',
' --artifacts-dir <path> Artifacts directory (default: docs/plans/artifacts)',
' --keep-per-family <num> Keep newest rolling tags per family (default: 8)',
' --keep-per-family <integer> Keep newest rolling tags per family (default: 8)',
' --apply Apply deletions (default: dry-run)',
' --report-tag <tag> Report tag suffix (default: current UTC date)',
' --write-default-artifacts Write report files to artifacts dir',
@@ -78,6 +78,17 @@ async function writeTextFile(pathValue: string, contents: string): Promise<void>
await writeFile(pathValue, `${contents}\n`, 'utf8');
}
async function readArtifactFileNames(artifactsDir: string): Promise<string[]> {
try {
return await readdir(artifactsDir);
} catch (error) {
if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') {
return [];
}
throw error;
}
}
async function main(): Promise<void> {
const { values } = parseArgs({
options: {
@@ -123,7 +134,7 @@ async function main(): Promise<void> {
? `${defaultBaseName}.md`
: undefined;
const files = await readdir(artifactsDir);
const files = await readArtifactFileNames(artifactsDir);
const plan = planRollingPhase0ArtifactRetention(files, keepPerFamily);
if (apply) {