Repository navigation
Make the kit's functions global so closures can call them - #18
Merged
Merged
Conversation
When a script dot-sourced the kit and was run from a prompt
(.\script.ps1 or & script), the kit's functions existed only in that
script's scope. A .GetNewClosure() block can only see global functions,
so Invoke-PkProcessBatch - whose internal callbacks are closures -
failed every command ("Start-PkProcess is not recognized"), and so did
any caller closure that called a kit function. Under powershell -File it
worked, which is how every test ran, so this went unnoticed since v1.0.
The kit now also defines each of its functions globally when loaded.
README: notes the global functions, and that a closure can't call the
script's own functions when run from a prompt unless they're global.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The export walked every function in the file the kit's code sits in, so a script that pasted the kit in had its own functions made global, and one defined after the kit caused a 'Cannot find path' error at load (fatal under strict mode). The loop also ran in the caller's scope, overwriting and removing two of its variables. It now only exports Pk-named functions and Initialize-ParallelKit, from a child scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HalRiveria
added a commit
that referenced
this pull request
Oct 28, 2026
…cessTree Brings in the process-tree kill changes and the global functions so the help describes the behaviour they add: Stop-PkProcessTree takes several programs, and Invoke-PkProcessWithTimeout / the dispatcher's force-stop kill a program's children too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong. Suppose a script dot-sources the kit and is run from a prompt (
.\script.ps1, or& script). The kit's functions then exist only in that script's scope, and a.GetNewClosure()block can only see global functions. So:Invoke-PkProcessBatchfailed every command. Its internal callbacks are closures, and they couldn't findStart-PkProcess/New-PkBatchResult.Invoke-PkRun { ... }.GetNewClosure(), or a-ResultHandlerclosure usingWrite-PkMessage.Run with
powershell -File, everything worked. That's how the harness, CI and every earlier test ran, so this has been there since v1.0. It turned up when the host-check script was run from a Windows Terminal prompt.What changed.
Get-Helpstill works on the global copies.function global:Name.Testing. A new harness test runs a script in a fresh process through
-Command "& script", the way a prompt runs it. It checks:.GetNewClosure()block calling a kit function works.Both fail against
main("New-PkBatchResultis not recognized") and pass here. 219 assertions pass on Windows PowerShell 5.1 and PowerShell 7.6, and 220 when merged with #16. It merges cleanly with #13, #15, #16 and #17.🤖 Generated with Claude Code