Skip to content

fix(gradle-plugin): run posthog-cli through cmd /c correctly on Windows - #982

Merged
turnipdabeets merged 2 commits into
mainfrom
fix/gradle-plugin-windows-cli
Nov 16, 2026
Merged

turnipdabeets merged 2 commits into
mainfrom
fix/gradle-plugin-windows-cli

Conversation

@turnipdabeets

@turnipdabeets turnipdabeets commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Fixes #981. On Windows, the plugin put cmd /c after the CLI as arguments, so every upload ran posthog-cli cmd /c exp proguard upload … and failed with unrecognized subcommand 'cmd'. This broke both ProGuard mapping and native symbol uploads on Windows, and it has done so since the ProGuard support first shipped (#316).

Now on Windows:

  • With the default posthog-cli, the plugin looks for posthog-cli.exe on PATH (the native release) and runs it directly, so arguments never pass through cmd. A & in the project path would otherwise split the command.
  • If there's no .exe on PATH, it runs cmd /c posthog-cli … so an npm posthog-cli.cmd shim still resolves. A .cmd always runs inside cmd anyway.
  • A configured .exe path runs directly. A configured non-.exe path goes through cmd /c.

macOS and Linux are unchanged.

Known limitation: a user-configured .cmd/.bat path that contains spaces can still hit cmd /c's quote stripping. That case is broken today too. Fixing it means layering extra quotes on top of Java's own, which I didn't want to ship without a Windows machine to check it on.

💚 How did you test it?

  • I moved the command-line building into a pure postHogCliCommandLine(executable, args, isWindows) function and added PostHogCliCommandLineTest. PostHogCliResolverTest also covers the Windows .exe lookup, with the Path key spelled the way Windows spells it. The test first ran against the old logic and reproduced the issue ([posthog-cli, cmd, /c, exp, …]), then passed with the fix.
  • ./gradlew :posthog-android-gradle-plugin:test :posthog-android-gradle-plugin:functionalTest spotlessCheck passes locally on macOS.
  • Not tested on Windows: CI has no Windows runner and I don't have a Windows machine. It would be great if the reporter could try a snapshot build.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Claude Code investigated Android Gradle plugin 1.8.0: ProGuard mapping upload fails on Windows (cmd /c passed as CLI arguments) #981, confirmed it from the source, wrote a failing unit test first, and then made the fix.
  • We considered dropping cmd /c entirely, since the reporter's CLI is a native .exe. We kept it because that would break npm-installed .cmd shims. The .exe exception covers the native install and paths with spaces.
  • After PostHog Review flagged that cmd treats a & in the path as a command separator, the default CLI now resolves posthog-cli.exe on PATH and skips cmd.
  • An independent review agent found no blocking issues. It flagged the .cmd-path-with-spaces case above, which I've left as a known limitation.

🤖 Generated with Claude Code

The Windows branch put `cmd /c` after the CLI as arguments, so uploads ran
`posthog-cli cmd /c …` and failed. Run `cmd /c <cli> …` instead, and run an
.exe directly.

Fixes #981
@turnipdabeets
turnipdabeets requested a review from a team as a code owner November 15, 2026 02:42
@turnipdabeets turnipdabeets self-assigned this Nov 15, 2026
@veria-ai

veria-ai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed acb7088: 1 Must fix.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

Resolve posthog-cli.exe on PATH so the default CLI skips cmd, which would
otherwise treat a `&` in the mapping path as a command separator. Only a
.cmd shim, which always runs inside cmd, still goes through cmd /c.

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code looks good; no qualifying findings. Verdict: correct.

@turnipdabeets
turnipdabeets merged commit 2733de8 into main Nov 16, 2026
17 checks passed
@turnipdabeets
turnipdabeets deleted the fix/gradle-plugin-windows-cli branch November 16, 2026 16:38
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.

Android Gradle plugin 1.8.0: ProGuard mapping upload fails on Windows (cmd /c passed as CLI arguments)

2 participants