Testing
The project ships a modular test runner with automatic suite discovery. The same *.Tests.ps1 suites run under Pester 5 when it is installed and under a bundled zero-dependency native engine otherwise.
Runner architecture
flowchart TD
A["tests/RunTests.bat<br/>PATH pwsh launcher"] --> B["tests/Run-Tests.ps1"]
B --> C["Discover tests/suites/*.Tests.ps1"]
B --> D{Engine}
D -- "Pester 5 installed or --pester" --> E["Invoke-Pester per suite"]
D -- "no Pester or --native" --> F["tests/helpers/TestHarness.ps1"]
F --> G["native Describe / It / Should shim"]
E --> H["Per-suite results"]
G --> H
H --> I["Totals, status, exit code"]
The runner has two modes:
- TUI when a real console is available and no CLI flag is passed.
- Headless for
--list,--all,--suite, and CI.
Running the suite
tests\RunTests.bat
tests\RunTests.bat --list
tests\RunTests.bat --all
tests\RunTests.bat --suite catalog,paths
tests\RunTests.bat --suite 01,05 --verbose
tests\RunTests.bat --all --pester
tests\RunTests.bat --all --native
tests\RunTests.bat --help
| Flag | Effect |
|---|---|
--list | List every discovered suite with its number, slug, and title |
--all | Run every suite |
--suite <names> | Run suites by number, slug, or title keyword; comma- or semicolon-separated |
--pester | Force Pester 5; fail if it is not installed |
--native | Force the bundled engine |
--verbose | Show per-case timings |
--no-pause | Skip the return-to-menu pause in the TUI |
The runner exits 0 when every case passes and 1 when any case fails.
TUI keys
| Key | Action |
|---|---|
↑ / ↓ | Move the selection |
Enter | Run the selected suite |
1–9, 0 | Jump to a suite by number |
A | Run all suites |
P | Toggle Pester 5 / native engine (when Pester is available) |
V | Toggle verbose timings |
Q / Esc | Quit |
Suite inventory
| Suite | Slug | Focus |
|---|---|---|
01_SyntaxAndDocs | 01_syntaxanddocs | Parses every project .ps1; entry points, launcher hygiene, documentation set, catalog-count alignment |
02_Catalog | 02_catalog | Five modules, twenty-four actions, unique IDs, required fields, search, menu reachability |
03_Paths | 03_paths | Normalization, drive roots, protected paths, scan roots, containment, validation |
04_Junctions | 04_junctions | Missing/not-a-junction/active/orphaned/empty classification, discovery, summary, stale filter |
05_Operations | 05_operations | Create, retarget rollback, repair, remove, empty-target deletion, dry-run, cleanup |
06_Inventory | 06_inventory | JSON/CSV export, empty CSV, dry-run export, round-trip import, restore guards, backup |
07_Cli | 07_cli | Help, list, search, inspect, create/retarget/remove, dry-run cleanup, usage errors, destructive refusal |
08_CrossVolume | 08_crossvolume | Alternate-volume targets, native results, alternate-volume link attempts, separator normalization |
Engine selection
flowchart TD
A[Start] --> B{--pester?}
B -- yes --> C{Pester 5 available?}
C -- no --> X[Error with install hint]
C -- yes --> P[Pester 5]
B -- no --> D{--native?}
D -- yes --> N[Native engine]
D -- no --> E{Pester 5 installed?}
E -- yes --> P
E -- no --> N
The native engine is not a mock of the product. It is a small test harness that implements the subset of Pester the suites use:
BeforeAll,BeforeEach,AfterEach;Describe,It;ShouldwithBe,BeTrue,BeFalse,BeNullOrEmpty,BeGreaterOrEqual,BeLessOrEqual,Match,Contain,BeIn,Throw, and-Not.
If a suite uses a Pester feature outside this subset, it will pass under Pester 5 and fail under the native engine. Keep suites inside the shared subset so both engines behave identically.
Test harness API
tests/helpers/TestHarness.ps1 exposes:
| Function | Purpose |
|---|---|
Get-WjmTestRepoRoot | Resolve the repository root from tests/helpers |
Get-WjmTestCoreModulePaths | Read src/core/manifest.ps1 and return the product’s load order |
Invoke-WjmNativeSuiteFile | Run one suite with the native shim and return pass/fail counts |
The native shim removes any loaded Pester module first, so an older Windows PowerShell Pester cannot hijack the shim when pwsh starts without a clean module path.
Junction test kit
tests/helpers/JunctionTestKit.ps1 provides capability-based fixtures. It follows the same rule as the product: do not gate on filesystem type.
| Function | Purpose |
|---|---|
New-WjmTestWorkspace | Create a temp workspace with target, target2, link, and link2 |
Get-WjmTestAlternateVolumeRoot | Return a second ready fixed volume, or '' |
New-WjmTestFile | Write a fixture file, creating parents |
New-WjmTestJunction | Try New-Item -ItemType Junction, then mklink /J for broken-target cases |
Remove-WjmTestJunction | Detach a link non-recursively, then fall back to rmdir |
Remove-WjmTestWorkspace | Detach links first, then remove the workspace tree |
Design rules
- Attempt, then inspect. A test performs the operation and asserts on the native result instead of skipping because a volume is “not NTFS”.
- Links live where creation is most likely to succeed. Workspaces use the current user’s temp directory.
- Targets may live elsewhere. When a second fixed volume exists, the kit creates a cross-volume target. If the volume rejects directory creation, the alternate paths are left empty rather than faked.
- Cleanup never follows a reparse point. Links are detached before the workspace tree is removed.
Broken junctions
New-Item -ItemType Junction refuses to create a link to a missing target. Broken-junction coverage therefore uses cmd.exe /c mklink /J, which can create the link anyway. This is a testing concern only; the product still surfaces whatever Windows reports.
Writing a suite
- Add
tests/suites/NN_Name.Tests.ps1. - Start with
#Requires -Version 7.0. - In
BeforeAll, resolve the repo root, loadTestHarness.ps1andJunctionTestKit.ps1, then dot-source every core module viaGet-WjmTestCoreModulePaths. - Use
DescribeandIt. UseBeforeEach/AfterEachfor fixtures and cleanup. - Use junction fixtures for filesystem cases and plain temp files where a junction is not required.
- Assert behavior and result fields, not console formatting.
- Run under both engines when possible:
tests\RunTests.bat --suite NN --native
tests\RunTests.bat --suite NN --pester
The runner auto-discovers new files; no registration is required.
Continuous integration
The test workflow runs on Windows with PowerShell 7 and exercises both engines:
- checkout;
- install Pester 5;
- run
tests\Run-Tests.ps1 --all --native --no-pause; - run
tests\Run-Tests.ps1 --all --pester --no-pause.
Running both engines keeps the native shim in sync with the Pester suites. The cross-volume suite is written to pass when only one volume exists: it attempts the operation and asserts on the observed native result.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
Pester 5+ is not installed | --pester was forced | Install Pester 5 or use --native |
| A suite passes in Pester but fails natively | The suite uses a Pester feature outside the shim subset | Rewrite the assertion using the supported set |
| Junction tests fail with access denied | The temp location or parent requires different ACLs | Run the session where the user can write the temp tree |
| Cross-volume case is skipped-looking | No second fixed volume exists | Expected; the test asserts on the native outcome, not a skip |
Related documentation
- Architecture — module layering and result contracts.
- Core modules — the functions the suites exercise.
- Action catalog — catalog invariants checked by suite 02.
- Research: junction behavior — platform evidence behind the fixture rules.