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:
@@ -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"
|
"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": {
|
"phase0-instrumentation-ticket-checklist": {
|
||||||
"status": "completed",
|
"status": "completed",
|
||||||
"date": "2026-02-25",
|
"date": "2026-02-25",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function usage(): string {
|
|||||||
'',
|
'',
|
||||||
'Options:',
|
'Options:',
|
||||||
' --artifacts-dir <path> Artifacts directory (default: docs/plans/artifacts)',
|
' --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)',
|
' --apply Apply deletions (default: dry-run)',
|
||||||
' --report-tag <tag> Report tag suffix (default: current UTC date)',
|
' --report-tag <tag> Report tag suffix (default: current UTC date)',
|
||||||
' --write-default-artifacts Write report files to artifacts dir',
|
' --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');
|
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> {
|
async function main(): Promise<void> {
|
||||||
const { values } = parseArgs({
|
const { values } = parseArgs({
|
||||||
options: {
|
options: {
|
||||||
@@ -123,7 +134,7 @@ async function main(): Promise<void> {
|
|||||||
? `${defaultBaseName}.md`
|
? `${defaultBaseName}.md`
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const files = await readdir(artifactsDir);
|
const files = await readArtifactFileNames(artifactsDir);
|
||||||
const plan = planRollingPhase0ArtifactRetention(files, keepPerFamily);
|
const plan = planRollingPhase0ArtifactRetention(files, keepPerFamily);
|
||||||
|
|
||||||
if (apply) {
|
if (apply) {
|
||||||
|
|||||||
Reference in New Issue
Block a user