Skip to content

fix(extension): VS Code Extension Scripts Missing Required CIHelpers Module + Packaging Script Testability #400

@katriendg

Description

@katriendg

Component

Other

Bug Description

When using the Extension, and in Windows/PowerShell.

The Generate-PrReference.ps1 script included in the VS Code extension package fails to execute because it depends on the CIHelpers.psm1 module located at scripts/lib/Modules/CIHelpers.psm1, which is not included in the extension package.

When users try to run the script from the installed extension directory, they encounter a module import error:

Import-Module: %USERPROFILE%\.vscode-insiders\extensions\ise-hve-essentials.hve-core-2.0.1\scripts\dev-tools\Generate-PrReference.ps1:29:1
Line |
  29 |  Import-Module (Join-Path $PSScriptRoot "../lib/Modules/CIHelpers.psm1 …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The specified module
     | '%USERPROFILE%\.vscode-insiders\extensions\ise-hve-essentials.hve-core-2.0.1\scripts\dev-tools\..\lib\Modules\CIHelpers.psm1' was not loaded because no valid module file was found in any module directory.

Expected Behavior

The Generate-PrReference.ps1 script should execute successfully when run from the extension installation directory. All required dependencies and modules should be included in the extension package.

Steps to Reproduce

  1. Install the HVE Core VS Code extension (ise-hve-essentials.hve-core)
  2. Navigate to a git repository (e.g., cd )
  3. Run the PR reference generation script from the extension:
    pwsh -File "%USERPROFILE%\.vscode-insiders\extensions\ise-hve-essentials.hve-core-2.0.1\scripts\dev-tools\Generate-PrReference.ps1" -BaseBranch "origin/main"
  4. Observe the import module error

Additional Context

Root Cause

The extension packaging process copies scripts/dev-tools to the extension but does not copy scripts/lib, which contains the required CIHelpers.psm1 module.

There is no corresponding copy operation for scripts/lib.

Additional Context

Affected Files:

Packaging Script Location:

Dependency:

The CIHelpers.psm1 module provides CI platform detection and output utilities used by multiple scripts in the dev-tools directory.

Note that scripts/lib/** is NOT included in the whitelist.

Potential Solutions:

  1. Add scripts/lib to .vscodeignore and Package-Extension.ps1 (Recommended):
  2. Make script standalone: Refactor Generate-PrReference.ps1 to not depend on external modules (increases maintenance burden)
  3. Bundle dependencies inline: Copy CIHelpers.psm1 directly into scripts/dev-tools/Modules/ directory (duplicates code)
  4. Document limitation: Update documentation to indicate the script can only run from source repository, not from extension installation (reduces utility)

Impact Scope

  • Affects Generate-PrReference.ps1 (confirmed)
  • Other scripts in scripts/dev-tools/ appear to be unaffected (no other modules dependencies found)

Scope Expansion: Packaging Script Testability

During code review, the following issues were identified in Package-Extension.ps1:

Problem Statement

The Invoke-PackageExtension function has:

  • ~200 lines of tightly coupled code
  • Cyclomatic complexity 18-22 (target: 8-10)
  • ~50% test coverage due to untestable platform-specific code paths
  • Silent failure modes that mask packaging issues

Target Metrics

Metric Current Target
Function length ~200 lines ~80 lines
Cyclomatic complexity 18-22 8-10
Test coverage ~50% 80%+

Refactoring Approach

Extract 8 pure/testable functions from the monolithic implementation:

Pure Functions (stateless, easily testable):

  • Test-PackagingInputsValid - Validates required paths, tools, environment
  • Get-PackagingDirectorySpec - Returns array of directory copy specifications
  • Get-PackagingFiles - Returns array of individual file copy specifications
  • Get-VsceArguments - Constructs argument array for vsce command

I/O Functions (mockable boundaries):

  • Copy-PackagingDirectories - Executes directory copies with progress
  • Invoke-VsceCommand - Wraps npx @vscode/vsce with UseWindowsWrapper parameter
  • Remove-PackagingArtifacts - Cleans up temporary files and folders
  • Restore-PackageJsonVersion - Restores original package.json after packaging

Acceptance Criteria

  • CIHelpers.psm1 included in extension package (original bug)
  • Explicit error when CIHelpers.psm1 is missing during packaging
  • Extracted functions have individual Pester test coverage
  • Platform-specific cmd /c wrapper logic is injectable for testing
  • Function complexity reduced to single responsibility per function

Metadata

Metadata

Labels

bugSomething isn't workingextensionVS Code extension packaging and publishingneeds-triageRequires triage and prioritization

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions