Skip to content

fix(tests): stop a test from waiting for input at a prompt - #94

Open
fadwen wants to merge 1 commit into
mainfrom
fix/test-prompt
Open

fadwen wants to merge 1 commit into
mainfrom
fix/test-prompt

Conversation

@fadwen

@fadwen fadwen commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #93. One test of New-IslFinding left out a mandatory parameter and expected an error. PowerShell raises that error only in a host that cannot prompt; in one that can, it asks for the value, and ./Tests/Invoke-Tests.ps1 waited at that test for as long as nobody answered. The CI jobs have no input to read, so they never showed it.

This pull request is independent of the others and is based on main.

Changes

  • Tests/Unit/Private/New-IslFinding.Tests.ps1 reads the four mandatory parameters from the command with Should-HaveParameter -Mandatory, as the other test files do. The assertion on -Severity Fatal stays: every mandatory parameter is given there, so the validation fails without a prompt.
  • New Tests/Unit/Module.Prompt.Tests.ps1. It parses every test file under Tests and Validation/Tests and fails for a call to a function of the module, private ones included, that gives none of its parameter sets all of its mandatory parameters. A parameter counts as given by name, by an unambiguous prefix, by an alias or by position. A call with a splat or with pipeline input is not judged. Six cases check the scan itself on sample text.
  • CHANGELOG entry under Fixed.

Verification

  • The test file run with its standard input connected to a pipe that stays open and empty, in a new process: on main it was still waiting after 60 seconds, under PowerShell 7.6.10 and under Windows PowerShell 5.1.26100; with this change it ended with 3 passed, under both.
  • The two test files: 11 passed, 0 failed, on PowerShell 7.6.10 and on Windows PowerShell 5.1.26100.
  • The scan on main reports New-IslFinding.Tests.ps1:25 New-IslFinding without Context and nothing else in the 91 test files.
  • PSScriptAnalyzer on the two test files: 0 findings. No line over 115 characters.
  • The full suites were not run locally for this change; quality-gates.yml runs them on this pull request.

Notes

  • How it was found: a local run of the whole suite, started with its input attached to an open pipe, wrote nothing for 20 minutes. The call stack of the idle process, read by attaching to it, ended at line 25 of the test file.
  • The scan does not see a call made through a variable (& $command) or a parameter that a splat was meant to carry and does not. Neither occurs in the test files today.

A test of New-IslFinding left out the mandatory -Context and expected
an error. PowerShell raises that error only in a host that cannot
prompt. In one that can, it asks for the value, and the suite waited
there: at a console, and wherever the standard input stayed open. The
CI steps have no input to read, so they never showed it.

The test reads the mandatory parameters from the command instead. A
new test parses every test file and fails for a call to a function of
the module that leaves out a mandatory parameter, so that such a call
fails where it is written and not where the suite happens to run.

Closes #93.
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.

A test waits for input when the host can prompt for a mandatory parameter

1 participant