Manual cleanup was needed in the psmodule-user, psmodule-test-org, and psmodule-test-org2 test accounts because repositories from the GitHub module test suite were still present after test runs.
Request
What happens
Repository-backed integration tests sometimes leave behind repositories after the run finishes. This appears to happen after failed runs and may also happen after successful runs, which means the test accounts gradually accumulate stale repositories across all of the test owners.
This is operationally noisy, makes it harder to reason about the current test state, and eventually forces manual cleanup of the shared test accounts. The problem appears to date back a long way rather than being limited to a recent change.
What is expected
A test run should clean up the repositories it created regardless of whether the run passes, fails, or is re-run. Repository cleanup should be deterministic and scoped to the current run so that shared test accounts do not accumulate stale repositories over time.
Acceptance criteria
- No manual repository cleanup is needed after normal test runs in
psmodule-user, psmodule-test-org, or psmodule-test-org2
- Repository-backed tests clean up the repositories created for the current run even when a test fails partway through
- Cleanup is deterministic and scoped by run ID rather than broad prefix scans over all repositories in an owner
- The repository lifecycle logic is consistent across setup, per-test execution, and teardown
- The suite has coverage that would catch regressions where repositories are left behind again
Technical decisions
Authoritative lifecycle scripts: tests/BeforeAll.ps1 and tests/AfterAll.ps1 should remain the authoritative setup and teardown surfaces for per-run test repositories. They already use deterministic names based on {TestName}-{OS}-{TokenType}-{GITHUB_RUN_ID}.
Cleanup strategy: Cleanup should use deterministic name lookups such as Get-GitHubRepository -Name / Get-GitHubRepository -Owner ... -Name rather than listing all repositories and deleting by prefix. That keeps teardown scoped to the exact repositories for the current run and matches the current global setup/teardown approach.
Consistency with test instructions: tests/.github/instructions/tests.instructions.md already describes deterministic per-run repositories and global teardown. Any remaining inline cleanup in individual test files should be aligned with that contract instead of using older prefix-based cleanup patterns.
Primary investigation target: tests/Repositories.Tests.ps1 still contains inline cleanup that lists repositories by prefix in both BeforeAll and AfterAll, while tests/AfterAll.ps1 already uses deterministic cleanup. Start by reconciling those paths and then audit the rest of the repository-backed tests for similar legacy cleanup code.
Failure handling: Cleanup must still run when a test fails mid-file. If per-file setup creates companion resources such as extra repositories or teams, teardown should remove those resources using the same deterministic naming scheme.
Verification approach: Add or update tests around the setup/teardown scripts and the repository-backed test files so the suite asserts the expected cleanup contract instead of relying on manual inspection of the test accounts.
Implementation plan
Cleanup flow
Failure and rerun behavior
Tests and documentation
Manual cleanup was needed in the
psmodule-user,psmodule-test-org, andpsmodule-test-org2test accounts because repositories from the GitHub module test suite were still present after test runs.Request
What happens
Repository-backed integration tests sometimes leave behind repositories after the run finishes. This appears to happen after failed runs and may also happen after successful runs, which means the test accounts gradually accumulate stale repositories across all of the test owners.
This is operationally noisy, makes it harder to reason about the current test state, and eventually forces manual cleanup of the shared test accounts. The problem appears to date back a long way rather than being limited to a recent change.
What is expected
A test run should clean up the repositories it created regardless of whether the run passes, fails, or is re-run. Repository cleanup should be deterministic and scoped to the current run so that shared test accounts do not accumulate stale repositories over time.
Acceptance criteria
psmodule-user,psmodule-test-org, orpsmodule-test-org2Technical decisions
Authoritative lifecycle scripts:
tests/BeforeAll.ps1andtests/AfterAll.ps1should remain the authoritative setup and teardown surfaces for per-run test repositories. They already use deterministic names based on{TestName}-{OS}-{TokenType}-{GITHUB_RUN_ID}.Cleanup strategy: Cleanup should use deterministic name lookups such as
Get-GitHubRepository -Name/Get-GitHubRepository -Owner ... -Namerather than listing all repositories and deleting by prefix. That keeps teardown scoped to the exact repositories for the current run and matches the current global setup/teardown approach.Consistency with test instructions:
tests/.github/instructions/tests.instructions.mdalready describes deterministic per-run repositories and global teardown. Any remaining inline cleanup in individual test files should be aligned with that contract instead of using older prefix-based cleanup patterns.Primary investigation target:
tests/Repositories.Tests.ps1still contains inline cleanup that lists repositories by prefix in bothBeforeAllandAfterAll, whiletests/AfterAll.ps1already uses deterministic cleanup. Start by reconciling those paths and then audit the rest of the repository-backed tests for similar legacy cleanup code.Failure handling: Cleanup must still run when a test fails mid-file. If per-file setup creates companion resources such as extra repositories or teams, teardown should remove those resources using the same deterministic naming scheme.
Verification approach: Add or update tests around the setup/teardown scripts and the repository-backed test files so the suite asserts the expected cleanup contract instead of relying on manual inspection of the test accounts.
Implementation plan
Cleanup flow
tests/Repositories.Tests.ps1to stop listing repositories by prefix and use deterministic per-run cleanup insteadtests/BeforeAll.ps1andtests/AfterAll.ps1Failure and rerun behavior
GITHUB_RUN_IDTests and documentation