Skip to content

chore: finish PowerShell script audit for issue #25#447

Open
EnmaJim wants to merge 32 commits into
andresharpe:mainfrom
EnmaJim:chore/issue-25-script-audit
Open

chore: finish PowerShell script audit for issue #25#447
EnmaJim wants to merge 32 commits into
andresharpe:mainfrom
EnmaJim:chore/issue-25-script-audit

Conversation

@EnmaJim
Copy link
Copy Markdown
Contributor

@EnmaJim EnmaJim commented May 25, 2026

Linked issue

Closes #25

Summary of changes

Completes the three remaining acceptance criteria on the script audit:
error handling, UTF-8 file encoding, and logging-helper consistency.

  • Error handling standardised. Every .ps1 entry-point now sets
    Set-StrictMode -Version 3.0 and $ErrorActionPreference = 'Stop',
    variables are initialised before try blocks so strict-mode reads
    on early throw no longer surface as "property cannot be found",
    optional JSON-RPC and workflow-manifest fields are guarded under
    strict mode, and empty/silent-discard catch blocks have been
    replaced with Write-BotLog calls (atlassian-download, InboxWatcher
    worker log, ui/server port probe, etc.).
  • UTF-8 handling verified. Every Set-Content / Add-Content /
    Out-File call now declares -Encoding utf8NoBOM, and
    .gitattributes pins LF line endings for *.ps1, *.psm1,
    *.psd1.
  • Logging helpers consistent. Write-Warning and bare error
    prints in long-running paths are routed through Write-BotLog, and
    the strict-mode leak that broke /api/state (dot-sourcing a script
    with top-level Set-StrictMode from Get-BotState) is fixed at
    source: dot-sourceable scripts keep strict mode inside function
    bodies.
  • Regression guards. Three new Layer-1 test files lock the rules
    in place so the audit cannot silently regress:
    • tests/Test-ErrorHandling.ps1 - entry-point directives + no
      empty / silent-discard catch blocks.
    • tests/Test-FileEncoding.ps1 - no BOM, explicit -Encoding,
      .gitattributes LF declarations.
    • tests/Test-DotSourceIsolation.ps1 - dot-sourced .ps1 files
      must not leak strict mode into the caller (runtime probe + AST
      lint).
  • Workflow + Claude CLI robustness. Surfacing exit code/stderr on
    stdin write failure, regenerating the Claude session ID per retry
    attempt, cleaning session artefacts between retries, and a
    background stderr drain so worktree git chatter no longer leaks
    into pipelines.

Screenshots / recordings

Not applicable - no UI changes.

Testing notes

  • pwsh tests/Test-ErrorHandling.ps1 - all rules pass.
  • pwsh tests/Test-FileEncoding.ps1 - all rules pass.
  • pwsh tests/Run-Tests.ps1 - full Layer-1 + component + workflow
    suites green, including the new Test-WorkflowSessionRetry,
    Test-RuntimeHelpers, Test-RouteHandlerSmoke, and
    Test-McpHelpers.

Checklist

  • Tests added or updated
  • Docs updated (if behaviour changed) - none required, behaviour
    unchanged
  • Linked issue exists
  • Follows the contribution guide

EnmaJim added 28 commits May 20, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

Script audit — full quality review of all PowerShell scripts

1 participant