Skip to content

Commit 7e67478

Browse files
feat: Update documentation for BeforeAll/AfterAll scripts to clarify intended use and provide examples for managing external test resources
1 parent f02098b commit 7e67478

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

specs/001-building-on-this/data-model.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,21 @@ This document defines the data structures, contracts, and entities for the setup
8383

8484
**BeforeAll.ps1**:
8585
- **Location**: `tests/BeforeAll.ps1` (root tests folder only)
86-
- **Purpose**: Setup test environment before all test matrix jobs
86+
- **Purpose**: Setup external test resources before all test matrix jobs - resources that are independent of test platform/OS
87+
- **Intended Use**: Deploy cloud infrastructure via APIs, create external database instances, initialize test data in third-party services
88+
- **NOT Intended For**: OS-specific dependencies, platform-specific test files, test-specific resources for individual matrix combinations
8789
- **Execution Context**: Runs in tests directory with full access to environment secrets
8890
- **Error Handling**: Failures halt testing workflow
89-
- **Example Use Cases**: Deploy test infrastructure, initialize test data, configure test environment
91+
- **Example Use Cases**: Deploy Azure/AWS resources via APIs, create external PostgreSQL databases, initialize SaaS test accounts
9092

9193
**AfterAll.ps1**:
9294
- **Location**: `tests/AfterAll.ps1` (root tests folder only)
93-
- **Purpose**: Cleanup test environment after all test matrix jobs
95+
- **Purpose**: Cleanup external test resources after all test matrix jobs - resources that are independent of test platform/OS
96+
- **Intended Use**: Remove cloud infrastructure via APIs, delete external database instances, cleanup test data in third-party services
97+
- **NOT Intended For**: OS-specific cleanup, platform-specific file removal, test-specific cleanup for individual matrix combinations
9498
- **Execution Context**: Runs in tests directory with full access to environment secrets
9599
- **Error Handling**: Failures logged but don't halt workflow
96-
- **Example Use Cases**: Remove test resources, cleanup databases, tear down test infrastructure
100+
- **Example Use Cases**: Delete Azure/AWS resources via APIs, remove external databases, cleanup SaaS test accounts
97101

98102
**Script Contract**:
99103
- Scripts can access all environment variables (secrets)

specs/001-building-on-this/plan.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
- Phase 3-4: Implementation execution (manual or via tools)
3232

3333
## Summary
34-
Extract BeforeAll/AfterAll test setup/teardown logic from Test-ModuleLocal.yml into a reusable local composite action. This reduces workflow duplication, improves maintainability, and enables reuse across workflows. The single composite action will accept a mode parameter (before/after) to control which script to execute (BeforeAll.ps1 or AfterAll.ps1) and error handling behavior. The action will be located at `.github/actions/setup-test/action.yml` and will integrate with existing PSModule/GitHub-Script and PSModule/Install-PSModuleHelpers actions.
34+
Extract BeforeAll/AfterAll test setup/teardown logic from Test-ModuleLocal.yml into a reusable local composite action. This reduces workflow duplication, improves maintainability, and enables reuse across workflows. The single composite action will accept a mode parameter (before/after) to control which script to execute (BeforeAll.ps1 or AfterAll.ps1) and error handling behavior. The action will be located at `.github/actions/setup-test/action.yml` and will integrate with existing PSModule/GitHub-Script and PSModule/Install-PSModuleHelpers actions. Documentation will clearly explain that BeforeAll/AfterAll scripts are intended for managing external test resources (cloud infrastructure, external databases, third-party services) that are independent of the test platform/OS, while test-specific resources should be created within the tests themselves.
3535

3636
## Technical Context
3737
**Language/Version**: PowerShell 7.4+ (GitHub Actions composite actions)
@@ -260,7 +260,12 @@ The /tasks command will load `.specify/templates/tasks-template.md` and generate
260260

261261
**From documentation requirements**:
262262
- Task: Update Process-PSModule README with composite action documentation
263-
- Task: Update Template-PSModule with example usage
263+
- Task: Create comprehensive BeforeAll/AfterAll usage documentation explaining:
264+
* Intended purpose: external test resource setup (cloud infrastructure, external databases, third-party services via APIs)
265+
* Clear distinction: external resources in BeforeAll/AfterAll vs. test-specific resources within tests
266+
* Examples: deploying Azure resources, initializing external databases, creating test data in SaaS platforms
267+
* Guidance on when to use BeforeAll/AfterAll vs. in-test setup for OS/platform-specific resources
268+
- Task: Update Template-PSModule with example BeforeAll/AfterAll scripts showing external resource management
264269
- Task: Create migration guide for nested script consolidation
265270
- Task: Update .github/copilot-instructions.md (already done in Phase 1)
266271

@@ -274,12 +279,12 @@ The /tasks command will load `.specify/templates/tasks-template.md` and generate
274279
- action.yml structure and script logic can be developed in parallel
275280
- Different test scenarios can be validated in parallel
276281

277-
**Estimated Task Count**: ~30-35 tasks
282+
**Estimated Task Count**: ~32-37 tasks
278283
- Setup: 2 tasks (directory structure, test repository)
279284
- Composite Action: 8-10 tasks (action.yml, script implementation)
280285
- Workflow Integration: 4 tasks (modify jobs, verify dependencies)
281286
- Testing: 7 tasks (integration test scenarios)
282-
- Documentation: 4 tasks (README, migration guide, templates)
287+
- Documentation: 6 tasks (README, usage documentation, examples, migration guide, templates)
283288

284289
**Task Priorities**:
285290
- P0 (Critical Path): Composite action implementation, workflow integration

specs/001-building-on-this/quickstart.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,45 @@
88

99
This quickstart provides a minimal integration path and validation steps for the setup-test composite action. Follow these steps to verify the feature works as expected.
1010

11+
## Intended Use Case (FR-021)
12+
13+
**BeforeAll/AfterAll scripts are designed for managing external test resources** that are independent of the test platform/OS. These scripts should:
14+
15+
**DO use for**:
16+
- Deploying cloud infrastructure via APIs (Azure, AWS, GCP)
17+
- Creating external database instances or schemas
18+
- Initializing test data in third-party SaaS platforms
19+
- Setting up API test environments
20+
- Configuring external services that all tests will use
21+
22+
**DON'T use for**:
23+
- Installing OS-specific dependencies (do this in test setup)
24+
- Creating platform-specific test files (do this within tests)
25+
- Test-specific resources for individual matrix combinations (do this in tests)
26+
27+
**Example BeforeAll.ps1** (External Resources):
28+
```powershell
29+
# Deploy Azure resources for testing
30+
Write-Host "Creating Azure test resources..."
31+
az group create --name "test-rg-$env:GITHUB_RUN_ID" --location eastus
32+
az storage account create --name "teststorage$env:GITHUB_RUN_ID" --resource-group "test-rg-$env:GITHUB_RUN_ID"
33+
34+
# Initialize external database
35+
Write-Host "Creating test database..."
36+
Invoke-RestMethod -Uri "https://api.example.com/databases" -Method POST -Body @{name="test-db-$env:GITHUB_RUN_ID"}
37+
```
38+
39+
**Example AfterAll.ps1** (Cleanup External Resources):
40+
```powershell
41+
# Remove Azure resources
42+
Write-Host "Cleaning up Azure test resources..."
43+
az group delete --name "test-rg-$env:GITHUB_RUN_ID" --yes --no-wait
44+
45+
# Delete external database
46+
Write-Host "Removing test database..."
47+
Invoke-RestMethod -Uri "https://api.example.com/databases/test-db-$env:GITHUB_RUN_ID" -Method DELETE
48+
```
49+
1150
## Prerequisites
1251

1352
- Process-PSModule repository checked out on branch `001-building-on-this`

0 commit comments

Comments
 (0)