Skip to content

Commit ee4e386

Browse files
author
saiganakato
committed
test: clean audit dry-run artifacts
1 parent 9e8f590 commit ee4e386

2 files changed

Lines changed: 67 additions & 25 deletions

File tree

scripts/tests/run-regulation-tests.ps1

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ function Assert-ExitCode([string]$name, [int]$expected, [scriptblock]$block) {
4747
}
4848

4949
$fixture = Join-Path $Shelf "scripts\tests\fixtures\minimal-docs-repo"
50+
$trackedIgnoredFixture = Join-Path $Shelf "scripts\tests\fixtures\tracked-ignored-repo"
51+
$deltaDryRunSlug = "delta-orchestrator-dry-run"
52+
$fixtureSlug = "minimal-docs-repo"
53+
$shelfDryRunSlug = "shelf-orchestrator-dry-run"
54+
55+
function Remove-GeneratedTestArtifacts {
56+
$generatedPaths = @(
57+
(Join-Path $Shelf "audits\$deltaDryRunSlug"),
58+
(Join-Path $Shelf "audits\$fixtureSlug"),
59+
(Join-Path $Shelf "audits\$shelfDryRunSlug"),
60+
(Join-Path $fixture ".git"),
61+
(Join-Path $trackedIgnoredFixture ".git"),
62+
(Join-Path $trackedIgnoredFixture "local-only.secret"),
63+
(Join-Path $Shelf "scripts\tests\fixtures\quickstart-isolated-repo\out")
64+
)
65+
66+
foreach ($generatedPath in $generatedPaths) {
67+
if (Test-Path -LiteralPath $generatedPath) {
68+
Remove-Item -LiteralPath $generatedPath -Recurse -Force
69+
}
70+
}
71+
}
72+
73+
Remove-GeneratedTestArtifacts
5074

5175
Assert-ExitCode "validate-regulation-index" 0 {
5276
& (Join-Path $Shelf "scripts\validate-regulation-index.ps1") -ShelfPath $Shelf
@@ -68,14 +92,13 @@ Assert-ExitCode "check-gitignore-consistency on fixture" 0 {
6892
& (Join-Path $Shelf "scripts\check-gitignore-consistency.ps1") -RepoPath $fixture
6993
}
7094

71-
$trackedIgnoredFixture = Join-Path $Shelf "scripts\tests\fixtures\tracked-ignored-repo"
7295
if (-not (Test-Path (Join-Path $trackedIgnoredFixture ".git"))) {
7396
Push-Location $trackedIgnoredFixture
7497
Set-Content -Path "local-only.secret" -Value "fixture-secret=tracked-but-ignored" -NoNewline
75-
git init | Out-Null
76-
git add README.md LICENSE SECURITY.md .gitignore
77-
git add -f local-only.secret
78-
git -c user.email="fixture@test" -c user.name="fixture" commit -m "init tracked-ignored fixture" | Out-Null
98+
git -c "safe.directory=$trackedIgnoredFixture" init | Out-Null
99+
git -c "safe.directory=$trackedIgnoredFixture" add README.md LICENSE SECURITY.md .gitignore
100+
git -c "safe.directory=$trackedIgnoredFixture" add -f local-only.secret
101+
git -c "safe.directory=$trackedIgnoredFixture" -c user.email="fixture@test" -c user.name="fixture" commit -m "init tracked-ignored fixture" | Out-Null
79102
Pop-Location
80103
}
81104

@@ -92,19 +115,18 @@ Assert-Pass "collect-audit-evidence completes after blocked gitignore" {
92115
$presentHead = (Invoke-TestGit -RepoPath $Shelf rev-parse HEAD)
93116
# v1.1.4 -> present always includes audit.manifest.yml change (v1.1.5); stable across future commits
94117
$manifestPriorHead = (Invoke-TestGit -RepoPath $Shelf rev-parse 'v1.1.4^{commit}')
95-
96118
Assert-ExitCode "run-delta-audit allowed (no changes)" 0 {
97119
& (Join-Path $Shelf "scripts\run-delta-audit.ps1") `
98120
-RepoPath $Shelf `
99-
-AuditSlug "github-optimization" `
121+
-AuditSlug $deltaDryRunSlug `
100122
-PriorHead $presentHead `
101123
-SkipShelfValidation
102124
}
103125

104126
Assert-ExitCode "run-delta-audit invalidates manifest change" 2 {
105127
& (Join-Path $Shelf "scripts\run-delta-audit.ps1") `
106128
-RepoPath $Shelf `
107-
-AuditSlug "github-optimization" `
129+
-AuditSlug $deltaDryRunSlug `
108130
-PriorHead $manifestPriorHead `
109131
-SkipShelfValidation
110132
}
@@ -177,13 +199,12 @@ foreach ($policy in $requiredPolicies) {
177199

178200
if (-not (Test-Path (Join-Path $fixture ".git"))) {
179201
Push-Location $fixture
180-
git init | Out-Null
181-
git add README.md LICENSE SECURITY.md .gitignore
182-
git -c user.email="fixture@test" -c user.name="fixture" commit -m "init minimal docs fixture" | Out-Null
202+
git -c "safe.directory=$fixture" init | Out-Null
203+
git -c "safe.directory=$fixture" add README.md LICENSE SECURITY.md .gitignore
204+
git -c "safe.directory=$fixture" -c user.email="fixture@test" -c user.name="fixture" commit -m "init minimal docs fixture" | Out-Null
183205
Pop-Location
184206
}
185207

186-
$fixtureSlug = "minimal-docs-repo"
187208
$fixtureReport = Join-Path $Shelf "audits\$fixtureSlug\audit-report.md"
188209
if (Test-Path $fixtureReport) { Remove-Item $fixtureReport -Force }
189210

@@ -202,7 +223,6 @@ Assert-Pass "fixture audit-report scaffolded" {
202223
}
203224

204225
# Use a dedicated dry-run slug - never delete audits/github-optimization/ (real dogfood output).
205-
$shelfDryRunSlug = "shelf-orchestrator-dry-run"
206226
$shelfDryRunReport = Join-Path $Shelf "audits\$shelfDryRunSlug\audit-report.md"
207227
if (Test-Path $shelfDryRunReport) { Remove-Item $shelfDryRunReport -Force }
208228

@@ -220,6 +240,8 @@ Assert-Pass "shelf orchestrator dry-run report scaffolded" {
220240
}
221241
}
222242

243+
Remove-GeneratedTestArtifacts
244+
223245
Write-Output ""
224246
if ($failures -eq 0) {
225247
Write-Output "regulation-tests: PASS"

scripts/tests/run-regulation-tests.sh

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,39 @@ run_exit() {
3434
}
3535

3636
FIXTURE="$SHELF/scripts/tests/fixtures/minimal-docs-repo"
37+
TRACKED_IGNORED="$SHELF/scripts/tests/fixtures/tracked-ignored-repo"
38+
DELTA_DRY_RUN_SLUG="delta-orchestrator-dry-run"
39+
FIXTURE_SLUG="minimal-docs-repo"
40+
SHELF_DRY_RUN_SLUG="shelf-orchestrator-dry-run"
41+
42+
cleanup_generated() {
43+
rm -rf \
44+
"$SHELF/audits/$DELTA_DRY_RUN_SLUG" \
45+
"$SHELF/audits/$FIXTURE_SLUG" \
46+
"$SHELF/audits/$SHELF_DRY_RUN_SLUG" \
47+
"$FIXTURE/.git" \
48+
"$TRACKED_IGNORED/.git" \
49+
"$TRACKED_IGNORED/local-only.secret" \
50+
"$SHELF/scripts/tests/fixtures/quickstart-isolated-repo/out"
51+
}
52+
53+
fixture_git() {
54+
git -C "$1" -c "safe.directory=$1" "${@:2}"
55+
}
56+
57+
cleanup_generated
3758

3859
run_pass "validate-regulation-index" bash "$SHELF/scripts/validate-regulation-index.sh" "$SHELF"
3960
run_exit "check-tracked-files on shelf" 0 bash "$SHELF/scripts/check-tracked-files.sh" "$SHELF"
4061
run_exit "check-tracked-files on fixture" 0 bash "$SHELF/scripts/check-tracked-files.sh" "$FIXTURE"
4162
run_exit "check-gitignore-consistency on shelf" 0 bash "$SHELF/scripts/check-gitignore-consistency.sh" "$SHELF"
4263
run_exit "check-gitignore-consistency on fixture" 0 bash "$SHELF/scripts/check-gitignore-consistency.sh" "$FIXTURE"
43-
TRACKED_IGNORED="$SHELF/scripts/tests/fixtures/tracked-ignored-repo"
4464
if [[ ! -d "$TRACKED_IGNORED/.git" ]]; then
4565
printf '%s' 'fixture-secret=tracked-but-ignored' >"$TRACKED_IGNORED/local-only.secret"
46-
git -C "$TRACKED_IGNORED" init
47-
git -C "$TRACKED_IGNORED" add README.md LICENSE SECURITY.md .gitignore
48-
git -C "$TRACKED_IGNORED" add -f local-only.secret
49-
git -C "$TRACKED_IGNORED" -c user.email=fixture@test -c user.name=fixture commit -m "init tracked-ignored fixture"
66+
fixture_git "$TRACKED_IGNORED" init
67+
fixture_git "$TRACKED_IGNORED" add README.md LICENSE SECURITY.md .gitignore
68+
fixture_git "$TRACKED_IGNORED" add -f local-only.secret
69+
fixture_git "$TRACKED_IGNORED" -c user.email=fixture@test -c user.name=fixture commit -m "init tracked-ignored fixture"
5070
fi
5171
run_exit "check-gitignore-consistency blocked tracked-ignored fixture" 1 \
5272
bash "$SHELF/scripts/check-gitignore-consistency.sh" "$TRACKED_IGNORED"
@@ -65,9 +85,9 @@ PRESENT_HEAD="$(git -C "$SHELF" rev-parse HEAD)"
6585
# v1.1.4 -> present always includes audit.manifest.yml change (v1.1.5); stable across future commits
6686
MANIFEST_PRIOR_HEAD="$(git -C "$SHELF" rev-parse "v1.1.4^{commit}")"
6787
SKIP_SHELF_VALIDATION=1 run_exit "run-delta-audit allowed (no changes)" 0 \
68-
bash "$SHELF/scripts/run-delta-audit.sh" "$SHELF" "" release github-optimization "$PRESENT_HEAD"
88+
bash "$SHELF/scripts/run-delta-audit.sh" "$SHELF" "" release "$DELTA_DRY_RUN_SLUG" "$PRESENT_HEAD"
6989
SKIP_SHELF_VALIDATION=1 run_exit "run-delta-audit invalidates manifest change" 2 \
70-
bash "$SHELF/scripts/run-delta-audit.sh" "$SHELF" "" release github-optimization "$MANIFEST_PRIOR_HEAD"
90+
bash "$SHELF/scripts/run-delta-audit.sh" "$SHELF" "" release "$DELTA_DRY_RUN_SLUG" "$MANIFEST_PRIOR_HEAD"
7191
run_exit "run-audit-quickstart missing manifest exits 2" 2 bash "$SHELF/scripts/run-audit-quickstart.sh" "$FIXTURE"
7292
QUICKSTART_FIXTURE="$SHELF/scripts/tests/fixtures/quickstart-manifest-repo"
7393
run_exit "run-audit-quickstart with manifest exits 0" 0 bash "$SHELF/scripts/run-audit-quickstart.sh" "$QUICKSTART_FIXTURE"
@@ -111,24 +131,24 @@ do
111131
done
112132

113133
if [[ ! -d "$FIXTURE/.git" ]]; then
114-
git -C "$FIXTURE" init
115-
git -C "$FIXTURE" add README.md LICENSE SECURITY.md .gitignore
116-
git -C "$FIXTURE" -c user.email=fixture@test -c user.name=fixture commit -m "init minimal docs fixture"
134+
fixture_git "$FIXTURE" init
135+
fixture_git "$FIXTURE" add README.md LICENSE SECURITY.md .gitignore
136+
fixture_git "$FIXTURE" -c user.email=fixture@test -c user.name=fixture commit -m "init minimal docs fixture"
117137
fi
118138

119-
FIXTURE_SLUG="minimal-docs-repo"
120139
rm -f "$SHELF/audits/$FIXTURE_SLUG/audit-report.md"
121140
run_exit "run-full-audit dry-run on fixture" 0 \
122141
bash "$SHELF/scripts/run-full-audit.sh" "$FIXTURE" "" public-prep pre-public "$FIXTURE_SLUG"
123142
run_pass "fixture audit-report scaffolded" test -f "$SHELF/audits/$FIXTURE_SLUG/audit-report.md"
124143

125144
# Dedicated dry-run slug - never delete audits/github-optimization/ (real dogfood output).
126-
SHELF_DRY_RUN_SLUG="shelf-orchestrator-dry-run"
127145
rm -f "$SHELF/audits/$SHELF_DRY_RUN_SLUG/audit-report.md"
128146
run_exit "run-full-audit dry-run on shelf root" 0 \
129147
bash "$SHELF/scripts/run-full-audit.sh" "$SHELF" "" public-prep pre-public "$SHELF_DRY_RUN_SLUG"
130148
run_pass "shelf orchestrator dry-run report scaffolded" test -f "$SHELF/audits/$SHELF_DRY_RUN_SLUG/audit-report.md"
131149

150+
cleanup_generated
151+
132152
echo
133153
if [[ "$failures" -eq 0 ]]; then
134154
echo "regulation-tests: PASS"

0 commit comments

Comments
 (0)