Skip to content

Allow submission payloads to be provided by file or standard input - #160

Open
Alexandre Zollinger Chohfi (azchohfi) wants to merge 1 commit into
mainfrom
azchohfi-submission-payload-from-file-or-stdin
Open

Allow submission payloads to be provided by file or standard input#160
Alexandre Zollinger Chohfi (azchohfi) wants to merge 1 commit into
mainfrom
azchohfi-submission-payload-from-file-or-stdin

Conversation

@azchohfi

Copy link
Copy Markdown
Collaborator

Fixes #151.

Problem

The submission JSON was only accepted as a positional command-line argument. Windows caps a command line at 32,767 characters (CreateProcess lpCommandLine), so any listing whose JSON exceeds that could not be updated through the CLI at all — the reporter's 7-language listing is 66,370 characters, roughly 2x the OS limit.

Program.cs already slurped standard input and appended it as an extra argv entry (present since the initial commit — it was the original answer to "don't paste 60 KB on the command line"). ff9c145 capped that read at 1 second because standard input can be redirected but never closed (CI agents, non-interactive shells, and under a debugger — hence the pre-existing !Debugger.IsAttached guard), which made ReadToEnd() block forever.

That cap is what makes the documented round-trip fail today: the read is cancelled and the payload is silently discarded, so msstore submission get … | msstore submission update … breaks whenever the producer takes longer than a second — which a network-backed submission get always does.

What changed

submission update, submission updateMetadata and flights submission update now resolve their payload in this order:

# Form Notes
1 --payload <file> / -p <file> New option, validated with AcceptExistingOnly()
2 - as the payload argument Reads all of standard input, waits indefinitely
3 Inline JSON Unchanged — existing scripts keep working
4 A path to an existing file Checked only after the JSON check, so inline payloads are never probed against the filesystem
5 Payload omitted + standard input redirected Replaces the old global slurp
msstore submission update <productId> --payload listing.json
msstore submission update <productId> listing.json
Get-Content -Raw listing.json | msstore submission update <productId> -
msstore submission get <productId> | msstore submission update <productId> -

Standard input reading moved out of Program.cs and into the commands that actually want a payload, and is now robust: it waits for the first character only (5 s on the implicit path, indefinitely for the explicit -), then reads to EOF with no deadline. That fixes both failure modes at once — no hang when standard input is redirected-but-empty, and no truncation when the producer is slow. Supplying both an inline payload and --payload is now an explicit error instead of one silently winning.

Verification

Behaviour of the real ConsoleReader against actual pipes:

Scenario Result
60,057-char payload piped in (≈2x the OS limit) Read in full, 8 ms
Producer that emits after 3 s, implicit path Read in full, identical SHA — old code dropped this
Producer that emits after 8 s, explicit - Read in full, identical SHA
Redirected, held open 20 s with no data Returns at 5,016 ms with a clear error, no hang
Redirected from NUL (CI style) Returns in 5 ms, no hang

12 new unit tests cover --payload, file-path arguments, -/standard input, implicit redirected input, both error paths, and a >32,767-character payload asserted end-to-end through the API mock. The existing inline-JSON tests are untouched and still pass, which is the backwards-compatibility guard.

dotnet build MSStore.CLI.sln is clean (0 warnings) and the full suite passes on both target frameworks apart from failures that reproduce unchanged on main (PublishCommandFor{WinUI,Maui}AppsShouldCallMSBuildIfWindows on net10.0, and the npm/yarn PackageCommand tests on net10.0-windows).

Follow-up

The published reference at MicrosoftDocs/windows-dev-docs-prhub/apps/publish/msstore-dev-cli/commands.md still documents the positional-only syntax and needs a separate docs PR. --help is already updated by this change.

The submission JSON was only accepted as a positional command-line
argument. Windows caps a command line at 32,767 characters, so any
listing whose JSON exceeds that could not be updated through the CLI at
all (a 7-language listing is easily 60 KB).

Program.cs already slurped standard input and appended it as an extra
argv entry, but that read was capped at 1 second to avoid blocking
forever when standard input is redirected but never written to (CI
agents, non-interactive shells, debuggers). The cap silently discarded
the payload whenever the producer was slower than that, which the
documented `submission get | submission update` round-trip always is.

The payload of `submission update`, `submission updateMetadata` and
`flights submission update` is now resolved in this order:

1. `--payload <file>` / `-p <file>`
2. `-` as the payload argument, to read all of standard input
3. inline JSON, exactly as before
4. a path to an existing file
5. no payload plus redirected standard input, to read all of it

The global slurp is replaced by standard input reading inside the
commands that want a payload. It waits for the first character only,
then reads to the end of the stream with no deadline, so it neither
hangs on an idle stream nor truncates a slow producer.

Fixes #151

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 52ff9b04-3c41-4040-8db2-c312aaa0b255

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds file and standard-input payload support to submission updates, avoiding command-line length limits.

Changes:

  • Adds centralized payload resolution for inline JSON, files, and stdin.
  • Updates three submission commands with --payload/-p.
  • Adds coverage for payload sources, errors, and large payloads.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
MSStore.CLI/Services/IConsoleReader.cs Extends the console input contract.
MSStore.CLI/Services/ConsoleReader.cs Implements timeout-aware stdin reading.
MSStore.CLI/Program.cs Removes global stdin argument injection.
MSStore.CLI/Helpers/PayloadResolver.cs Resolves payloads from supported sources.
MSStore.CLI/Commands/SubmissionCommand.cs Defines the shared payload option.
MSStore.CLI/Commands/Submission/UpdateMetadataCommand.cs Supports alternate metadata payload sources.
MSStore.CLI/Commands/Submission/UpdateCommand.cs Supports alternate product payload sources.
MSStore.CLI/Commands/Flights/Submission/UpdateCommand.cs Supports alternate flight payload sources.
MSStore.CLI.UnitTests/BaseCommandLineTest.cs Adds temporary payload-file support.
MSStore.CLI.UnitTests/SubmissionCommandPackagedUnitTests.cs Tests packaged submission payload handling.
MSStore.CLI.UnitTests/SubmissionCommandUnpackagedUnitTests.cs Tests unpackaged payload handling.
MSStore.CLI.UnitTests/FlightsSubmissionCommandUnitTests.cs Tests flight payload handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

/// The value that, when used in place of the payload argument, means "read the payload from
/// the standard input stream".
/// </summary>
internal const string StandardInputToken = "-";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we give this feature? As uses can save the data from slow produced into a file before and pass that file

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.

submission update takes the payload as a command-line argument, so a large listing cannot be updated at all

3 participants