fix(audit): expand home paths across phase0 CLI scripts
Apply HOME-based ~ expansion to summarize/drift/prune audit scripts for input/output path flags to match capture behavior and avoid literal ~/ path bugs. Architecture/protocol diagrams reviewed; no updates needed for this path-resolution change.
This commit is contained in:
@@ -176,6 +176,17 @@ function formatFreshnessHours(value: number | null): string {
|
||||
return `${Math.round(value * 100) / 100}`;
|
||||
}
|
||||
|
||||
function expandHomePath(pathValue: string): string {
|
||||
if (!pathValue.startsWith('~')) {
|
||||
return pathValue;
|
||||
}
|
||||
const home = process.env.HOME;
|
||||
if (!home) {
|
||||
return pathValue;
|
||||
}
|
||||
return resolve(home, pathValue.slice(1));
|
||||
}
|
||||
|
||||
async function writeOutput(pathValue: string, output: string): Promise<void> {
|
||||
await mkdir(dirname(pathValue), { recursive: true });
|
||||
await writeFile(pathValue, `${output}\n`, 'utf8');
|
||||
@@ -370,7 +381,7 @@ async function main(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
const artifactsDir = resolve(values['artifacts-dir'] ?? 'docs/plans/artifacts');
|
||||
const artifactsDir = resolve(expandHomePath(values['artifacts-dir'] ?? 'docs/plans/artifacts'));
|
||||
const backends = parseBackends(values.backend);
|
||||
const candidateTag = values.tag
|
||||
? normalizeArtifactTag(values.tag, '--tag')
|
||||
@@ -388,12 +399,12 @@ async function main(): Promise<void> {
|
||||
|
||||
const defaultBaseName = resolve(artifactsDir, `phase0_baseline_live_backend_drift_${reportTag}`);
|
||||
const summaryJsonOut = values['summary-json-out']
|
||||
? resolve(values['summary-json-out'])
|
||||
? resolve(expandHomePath(values['summary-json-out']))
|
||||
: writeDefaultArtifacts
|
||||
? `${defaultBaseName}.json`
|
||||
: undefined;
|
||||
const summaryMdOut = values['summary-md-out']
|
||||
? resolve(values['summary-md-out'])
|
||||
? resolve(expandHomePath(values['summary-md-out']))
|
||||
: writeDefaultArtifacts
|
||||
? `${defaultBaseName}.md`
|
||||
: undefined;
|
||||
@@ -497,7 +508,7 @@ async function main(): Promise<void> {
|
||||
}
|
||||
|
||||
if (values.out) {
|
||||
await writeOutput(resolve(values.out), output);
|
||||
await writeOutput(resolve(expandHomePath(values.out)), output);
|
||||
} else {
|
||||
process.stdout.write(`${output}\n`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user