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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user