Skip to content

Add Windows backend test preflight script#7799

Open
tianmind-studio wants to merge 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-backend-test-preflight-ps1
Open

Add Windows backend test preflight script#7799
tianmind-studio wants to merge 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-backend-test-preflight-ps1

Conversation

@tianmind-studio

Copy link
Copy Markdown
Contributor

Summary

  • Add backend/test-preflight.ps1, a PowerShell equivalent of the existing backend test-preflight.sh checks.
  • Check Python, pytest, black, key Python package imports, unit-test env defaults, optional integration env vars, optional Redis reachability, and test.sh file references.
  • Document both macOS/Linux and Windows preflight commands in backend/README.md.

Why

The backend setup docs already include Windows installation paths, but the backend test preflight helper only had a bash entrypoint. This gives Windows contributors a native PowerShell command to validate their backend test environment before running the full suite.

Testing

  • powershell -NoProfile -ExecutionPolicy Bypass -File .\test-preflight.ps1 -> 11 passed, 9 warnings, 0 failed in this Windows venv
  • git diff --check -- backend/test-preflight.ps1 backend/README.md
  • staged public-doc leakage scan for private/internal terms -> no matches

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds backend/test-preflight.ps1, a PowerShell equivalent of the existing test-preflight.sh, and documents both scripts in backend/README.md so Windows contributors can validate their test environment before running the full suite.

  • New script (test-preflight.ps1): Checks Python/pytest/black availability, imports key packages, verifies optional integration env vars, probes Redis reachability via redis-cli, and confirms all test.sh file references resolve — mirroring the bash script's logic faithfully.
  • README update: Adds a "Running Backend Test Preflight" section with shell-specific invocation examples for macOS/Linux and Windows.

Confidence Score: 3/5

The preflight script itself is read-only and safe, but the README example command will fail for most new Windows contributors before they can even run it.

The README documents . est-preflight.ps1 as the Windows invocation, but on a fresh Windows system with the default execution policy that command produces an access-denied error rather than running the script. A new contributor following the docs exactly would be blocked at the first step with a confusing PowerShell error, defeating the purpose of the preflight helper.

backend/README.md — the PowerShell invocation example needs the -ExecutionPolicy Bypass -File flags to work reliably across default Windows configurations.

Important Files Changed

Filename Overview
backend/test-preflight.ps1 New PowerShell preflight script mirroring the bash equivalent; logic is sound but Set-Location leaks the CWD change into the caller when dot-sourced.
backend/README.md Adds Windows preflight docs, but the example command omits -ExecutionPolicy Bypass and will fail on systems with the default Restricted execution policy.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([Start test-preflight.ps1]) --> B{Python found?}
    B -- Yes --> C[Record launcher path]
    B -- No --> D[FAIL: python not found]
    C --> E{pytest importable?}
    D --> E
    E -- Yes --> F[PASS: pytest version]
    E -- No --> G[FAIL: pytest missing]
    F --> H{black in PATH?}
    G --> H
    H -- Yes --> I[PASS: black]
    H -- No --> J[WARN: black missing]
    I & J --> K[Check 7 Python package imports]
    K --> L{All importable?}
    L -- No --> M[WARN per missing pkg]
    L -- Yes --> N[PASS per pkg]
    M & N --> O[Check ENCRYPTION_SECRET / integration env vars]
    O --> P{redis-cli in PATH?}
    P -- Yes --> Q{Redis PING OK?}
    Q -- Yes --> R[PASS: Redis connected]
    Q -- No --> S[WARN: not reachable]
    P -- No --> T[WARN: redis-cli missing]
    R & S & T --> U{unit test files exist?}
    U -- Yes --> V[PASS: N files found]
    U -- No --> W[FAIL: no unit tests]
    V & W --> X{test.sh exists?}
    X -- Yes --> Y[Parse pytest lines / check paths]
    Y --> Z{Any missing?}
    Z -- Yes --> AA[FAIL: missing refs]
    Z -- No --> AB[PASS: all refs resolve]
    X -- No --> AC[FAIL: test.sh not found]
    AA & AB & AC --> AD[Print summary]
    AD --> AE{FailCount > 0?}
    AE -- Yes --> AF([exit 1])
    AE -- No --> AG{WarnCount > 0?}
    AG -- Yes --> AH([exit 0 with warnings])
    AG -- No --> AI([exit 0 all clear])
Loading

Reviews (1): Last reviewed commit: "test(backend): add Windows preflight scr..." | Re-trigger Greptile

Comment thread backend/README.md
Comment on lines +127 to +130
Windows PowerShell:
```powershell
.\test-preflight.ps1
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The documented PowerShell command . est-preflight.ps1 will fail on most fresh Windows installs because the default execution policy is Restricted (and sometimes RemoteSigned), which blocks running .ps1 files directly. The PR description itself uses the full form with -ExecutionPolicy Bypass, which is the reliable cross-system invocation. Using the short form without that flag will produce a confusing "running scripts is disabled" error for new contributors.

Suggested change
Windows PowerShell:
```powershell
.\test-preflight.ps1
```
Windows PowerShell:
```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File .\test-preflight.ps1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ca5f7e8f8. The README now documents the reliable Windows invocation:

powershell -NoProfile -ExecutionPolicy Bypass -File .\test-preflight.ps1

I re-ran that exact command on Windows: 11 passed, 9 warnings, 0 failed.

Comment thread backend/test-preflight.ps1 Outdated
Comment on lines +5 to +6
$RootDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $RootDir

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Set-Location permanently changes the working directory of the calling PowerShell session if the script is dot-sourced (. . est-preflight.ps1). Wrapping with Push-Location / Pop-Location scopes the change to the script's execution and restores the caller's CWD on exit. Because the script has multiple exit paths, a try/finally block is the safest way to ensure Pop-Location always runs.

Suggested change
$RootDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $RootDir
$RootDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Push-Location $RootDir

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ca5f7e8f8. The script now uses Push-Location $RootDir and a finally { Pop-Location } block so the caller's CWD is restored even through the script's normal exit paths.

Re-verified with:

powershell -NoProfile -ExecutionPolicy Bypass -File .\test-preflight.ps1

Result: 11 passed, 9 warnings, 0 failed.

Copy link
Copy Markdown
Contributor Author

Addressed the Windows preflight review feedback in ca5f7e8f8:

  • Updated the README command to use powershell -NoProfile -ExecutionPolicy Bypass -File .\test-preflight.ps1, matching the reliable invocation for default Windows execution policies.
  • Changed the script to use Push-Location with a finally Pop-Location so the caller's working directory is restored even when the script exits through its normal result paths.

Re-verified on Windows:

powershell -NoProfile -ExecutionPolicy Bypass -File .\test-preflight.ps1

Result: 11 passed, 9 warnings, 0 failed. Also re-ran git diff --check -- backend/test-preflight.ps1 backend/README.md.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows test preflight tooling — approve only (new capability)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants