Shell environment variables: environment(name, value) on the fluent API and --env NAME=VALUE on the CLI (winrs -env) - #156
Conversation
…AME=VALUE (#137) The WSMan Create request now carries an optional rsp:Environment block, placed per the MS-WSMV Shell_Type schema sequence (Environment, then WorkingDirectory, then the stream declarations). Like the working directory, the environment is shell-scoped: it is honored by the client's first command and replayed with its original values when a reaped shell is silently recreated. - Fluent API: CommandRequest.environment(name, value), repeatable, insertion order preserved, values XML-escaped. - SPI: environment-aware default overloads on WindowsRemoteExecutor that delegate to the historical entry points when no variable is set and refuse (never silently drop) otherwise. - CLI: --env NAME=VALUE, repeatable, split on the first '=', valid for the command and shell subcommands (winrs -env parity). - Docs: commands.md option table, cli.md options table, --help line. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe3fbf32d3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…e shell (#137) When .environment(...) is combined with .upload(...), the ShellFileCopy transfer commands run first and are what actually creates (and pins the settings of) the remote shell; the environment was discarded after preparation and the real command silently ran without it. ShellFileCopy.copyLocalFilesToRemote now takes the shell environment and threads it into every command leg: whichever leg creates the shell pins it, and the caller's command inherits it. The historical entry point delegates with no environment, so the legacy WinRMCommandExecutor and custom executors are unaffected. Tests: transfer legs carry the environment (ShellFileCopyTest), and an end-to-end wire test asserts the Create request of an upload-created shell carries the rsp:Environment block (WinRMClientTest). Addresses the Codex review on PR #156. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
@codex please review again |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Closes #137.
What
The WSMan
Createrequest can now carry the optionalrsp:Environmentblock:Fluent API
Same contract as
workingDirectory(String): the environment is shell-scoped, honored when the shell is created — i.e. by the client's first command — with insertion order preserved, names validated non-blank, and values XML-escaped.Pinning semantics (the #133 invariant)
The environment is pinned by the first command (defensively copied) and replayed with its ORIGINAL values when the server reaps the shell and the client silently recreates it — a recreation stays invisible, for the working directory and the environment alike.
Element order
Per the MS-WSMV Shell_Type schema sequence, the
rsp:Shellbody now emitsEnvironment, thenWorkingDirectory, thenInputStreams/OutputStreams(the order of the protocol's own Create example). Note:WorkingDirectorypreviously came after the stream declarations; the schema order is asserted by the wire tests, but a run against a real Windows host is still advisable.SPI
WindowsRemoteExecutorgains environment-aware default overloads ofexecuteCommandandstartCommandthat delegate to the historical entry points when no variable is requested, and throwUnsupportedOperationExceptionotherwise — an executor unaware of the variant keeps working, and variables are never silently dropped.CLI
--env NAME=VALUE, repeatable (winrs-style), split on the first=(the value may itself contain=), valid forcommandandshell, usage error otherwise:Tests
rsp:Environmentblock (content, escaping, insertion order, schema element order) on Create, via FakeWsmanServer.=split, usage errors, wql rejection) and end-to-end CLI wire tests forexecandshell.Docs
commands.mdoption table,cli.mdoptions table, and one--helpline.🤖 Generated with Claude Code