Skip to content

Fix nx run completions: use nx graph --file=stdout - #335

Merged
acarl005 merged 3 commits into
mainfrom
factory/nx-graph-file-stdout
Aug 13, 2026
Merged

Fix nx run completions: use nx graph --file=stdout#335
acarl005 merged 3 commits into
mainfrom
factory/nx-graph-file-stdout

Conversation

@warp-agent-staging

Copy link
Copy Markdown
Contributor

Summary

nx run <TAB> completions produce no suggestions on any currently-supported Nx version. Fixes warpdotdev/warp#4691 / APP-5384.

Only nx run is affected — nx build/serve/test/lint use the apps_and_libs generator (nx show projects), which was verified working and is left untouched.

Root cause

Two bugs in sequence in the workspace_targets generator (src/generators/nx.rs):

  1. Dec 2024 (PR Fully migrate to the CommandBuilder struct #166). nx graph --file $temp > /dev/null && cat $temp became ... 2>/dev/null && cat $temp. nx graph --file prints a human-readable banner on stdout when writing the file, so it stopped being discarded and got prepended to the JSON cat $temp printed, breaking serde_json parsing.
  2. Apr 2026 (PR Add completion spec: Nx project/target generators (nx) #251, APP-3498). Tried nx graph --print first, falling back to the (still-broken) tmpfile form. Nx 20.x and 21.0 declare --print but never consume it — nx ignores it and starts the interactive project-graph web server on 127.0.0.1:4211, which never exits. Because it never exits non-zero, the || fallback never runs.

Changes

  • Replace the --print-then-tmpfile chain with a single nx graph --file=stdout command. Nx has a special case for the literal stdout target that writes only the graph JSON to stdout — no confirmation banner, no interactive server — and it is understood by every Nx version tested (20.x-23.x). No fallback is needed since one form now covers the full supported range; keeping a fallback that's never reached correctly would just carry the latent bug forward.
  • Add regression tests: one asserting the exact built command string (so a future CommandBuilder refactor can't silently reintroduce a bad redirect the way PR Fully migrate to the CommandBuilder struct #166 did), one covering process_workspace_targets parsing real graph JSON into project:target suggestions, and one asserting parsing fails closed (no panic, empty results) if banner text ever precedes the JSON again.

Verification

Built a real Nx workspace (3 projects: admin-integrations, upsert-worker, utils, matching the original reporter's shape) and ran the actual generator command against both nx@20.3.0 (the reporter's exact version) and current nx@23.1.1:

$ nx graph --file=stdout
exit=0, stdout=2293 bytes, stderr=0 bytes
-> valid JSON on both 20.3.0 and 23.1.1
-> project:target suggestions: admin-integrations:build, admin-integrations:serve,
   upsert-worker:build, utils:lint, utils:test

Also reproduced the current bug for confirmation: nx graph --print on nx@20.3.0 hangs (exit=124 under a 20s timeout) with the daemon printing Project graph started at http://127.0.0.1:4211/projects; confirmed no listener remains on port 4211 after the fixed --file=stdout command runs.

Checks run:

  • cargo fmt -p warp-command-signatures -p warp-completion-metadata --check — pass
  • cargo clippy -p warp-command-signatures -p warp-completion-metadata --all-targets --all-features -- -D warnings — pass
  • cargo test --verbose -p warp-command-signatures -p warp-completion-metadata — 145 + 10 tests pass (including the 4 new/updated nx::tests)

Left alone (out of scope)

Triage (APP-5384) noted no timeout exists on generator execution (GeneratorContext::execute_command_at_pwdCommandExecutor::execute_command in warpdotdev/warp) and suspected a leaked nx graph process per completion attempt on the old --print path. This PR confirms that concern: timeout 20 nx graph --print had to be force-killed, and without an external timeout the process (and its web server on port 4211) would keep running indefinitely for every nx run<TAB> attempt on old Nx. That's a separate, larger fix in warpdotdev/warp's command execution path and is deliberately out of scope here per APP-5384.

Shipping to users

warpdotdev/warp pins this repo by commit rev in Cargo.toml (currently 32a7fd56, the exact commit this branch is based on), not by a published version, so merging this PR does not ship anything by itself. A follow-up PR bumping that rev (and Cargo.lock) in warpdotdev/warp is required — opened separately, see below.

The workspace_targets generator that powers `nx run <TAB>` completions
has been broken since Dec 2024 (PR #166) and was not actually fixed by
the Apr 2026 attempt (PR #251, APP-3498):

- PR #166 turned `nx graph --file $temp > /dev/null && cat $temp` into
  `... 2>/dev/null && cat $temp`, so nx's stdout banner from writing the
  file stopped being discarded and got prepended to the JSON, breaking
  parsing.
- PR #251 tried `nx graph --print` first, but Nx 20.x/21.0 declare that
  flag without consuming it: nx ignores it and starts the interactive
  project-graph web server on 127.0.0.1:4211, which never exits. Because
  it never exits non-zero, the `||` fallback (which still carried the
  original stdout bug) never ran.

`nx graph --file=stdout` is understood by every Nx version tested
(20.x-23.x, see APP-5384) and writes only the graph JSON to stdout, with
no confirmation banner and no interactive server. No fallback is
needed since a single form covers the supported version range, and a
fallback that's never reached correctly is worse than none.

Verified against real Nx workspaces on nx@20.3.0 (the original
reporter's version) and nx@23.1.1: both produce valid JSON and the
expected `project:target` suggestions, with no process left listening
on port 4211.

Fixes warpdotdev/warp#4691.

Co-Authored-By: Warp Agent <agent@warp.dev>
@warp-agent-staging

Copy link
Copy Markdown
Contributor Author

This PR was generated with Warp.

View run View conversation

@acarl005
acarl005 marked this pull request as ready for review August 13, 2026 23:48
@oz-for-oss

oz-for-oss Bot commented Aug 13, 2026

Copy link
Copy Markdown

@acarl005

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot 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.

Overview

This PR changes Nx workspace target generation to use nx graph --file=stdout and adds regression coverage for command construction, target parsing, fail-closed behavior on banner-prefixed output, and empty graphs.

Concerns

  • No blocking correctness, security, comment-quality, test-quality, or spec-drift concerns found in the provided diff. spec_context.md reports no approved or repository spec context.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread command-signatures/src/generators/nx.rs Outdated
@acarl005

Copy link
Copy Markdown
Contributor

@oz-agent delete the comment as requested in my last review. make sure you cover the whole line range.

@oz-by-warp

oz-by-warp Bot commented Aug 13, 2026

Copy link
Copy Markdown

Oz run started.

View conversation · View run in Oz

@oz-for-oss

oz-for-oss Bot commented Aug 13, 2026

Copy link
Copy Markdown

@acarl005

I'm working on changes requested in this PR (responding to a PR conversation comment).

You can view the conversation on Warp.

I pushed changes to this PR based on the comment.

Replied to and attempted to resolve 1 review comment that this run addressed.

Next steps:

  • Review the changes pushed to this PR.
  • Follow up with another comment if further adjustments are needed.

Powered by Oz

Addresses review feedback on PR #335: delete the multi-paragraph
rationale block above NX_WORKSPACE_TARGETS_COMMAND (the requested
line range), keeping only the one-line summary.

Co-Authored-By: Oz <oz-agent@warp.dev>
@oz-by-warp

oz-by-warp Bot commented Aug 13, 2026

Copy link
Copy Markdown

Deleted the whole comment block you flagged, covering the full requested line range (13–22 of command-signatures/src/generators/nx.rs) — all 10 lines of the --file=stdout / --print rationale paragraphs are gone. I also dropped the now-orphaned /// separator on line 12 so the remaining doc comment doesn't end in a dangling empty line; only the one-line summary /// Command that retrieves the Nx project graph with target information. remains above NX_WORKSPACE_TARGETS_COMMAND.

Verified after the deletion: cargo fmt --check clean, cargo clippy --all-targets --all-features -- -D warnings clean, and the nx tests pass (4/4, including test_workspace_targets_command_string).

Pushed as commit 13ffde9 to factory/nx-graph-file-stdout.

Co-Authored-By: Andy <acarl005@users.noreply.github.com>

Co-Authored-By: Oz <oz-agent@warp.dev>
@acarl005
acarl005 merged commit 491864c into main Aug 13, 2026
8 checks passed
@acarl005
acarl005 deleted the factory/nx-graph-file-stdout branch August 13, 2026 23:57
@acarl005 acarl005 self-assigned this Aug 13, 2026
warp-agent-staging Bot pushed a commit to warpdotdev/warp that referenced this pull request Aug 14, 2026
Points at warpdotdev/command-signatures#335, which fixes `nx run <TAB>`
completions (APP-5384 / #4691) by switching the
workspace_targets generator from the broken `nx graph --print` /
tmpfile fallback chain to `nx graph --file=stdout`.

NOTE: this currently pins the fix branch's tip commit so CI can build
and this diff can be reviewed ahead of time. command-signatures uses
squash-merge only, so once #335 merges this rev must be bumped again
to the resulting squash commit on main before this PR can land -- the
branch (and this commit) will no longer be reachable once GitHub
deletes it post-merge. Do not merge this PR until that follow-up bump
is made.

Co-Authored-By: Warp Agent <agent@warp.dev>
warp-agent-staging Bot pushed a commit to warpdotdev/warp that referenced this pull request Aug 14, 2026
Points at warpdotdev/command-signatures#335 (merged), which fixes
`nx run <TAB>` completions (APP-5384 / #4691) by
switching the workspace_targets generator from the broken
`nx graph --print` / tmpfile fallback chain to `nx graph --file=stdout`.

Co-Authored-By: Warp Agent <agent@warp.dev>
warp-agent-staging Bot pushed a commit to warpdotdev/warp that referenced this pull request Aug 14, 2026
Merged PRs:
- Fix nx run completions: use nx graph --file=stdout (warpdotdev/command-signatures#335)
- Add completion specs for yay and paru (AUR helpers) (warpdotdev/command-signatures#334)
- Fix yay/paru completion specs: -Pc field separators and -B/--build option
  placement (warpdotdev/command-signatures#336)
- Forward --context/--cluster/--user in kubectl generators (warpdotdev/command-signatures#331)

The kubectl change forwards a --context, --cluster or --user written on
the command line into the commands the completion generators run.
Without it, completions after a --context enumerated from the shell's
active context instead of the one on the line (#5186,
#3929). It also adds --user value completions and wires
--context/--cluster/--user up for kubecolor and oc.

Co-Authored-By: Warp Agent <agent@warp.dev>
acarl005 pushed a commit to warpdotdev/warp that referenced this pull request Aug 14, 2026
…--cluster/--user forwarding) (#15109)

## Description
Updates `warp-command-signatures` to `15debaeb`, the squash commit on
`command-signatures:main` for warpdotdev/command-signatures#331.

That PR fixes the last remaining symptom of #5186: a `--context` (or
`--cluster`, or `--user`) written on the command line was never
forwarded into the commands the kubectl completion generators run, so
later completions enumerated from the shell's active context instead of
the one on the line. With `kubectl --context staging-cluster --namespace
<TAB>`, the generator ran `kubectl … get namespace -o
custom-columns=:.metadata.name` with no `--context`. It now forwards
`--context`, `--cluster` and `--user`, mirroring the existing
`--kubeconfig` and `--namespace` handling. It also adds value completion
for `kubectl --user`, and wires `--context`/`--cluster`/`--user` up for
`kubecolor` and `oc`, which declared those options with no generator.

### Merged PRs
- Fix nx run completions: use nx graph --file=stdout
(warpdotdev/command-signatures#335)
- Add completion specs for yay and paru (AUR helpers)
(warpdotdev/command-signatures#334)
- Fix yay/paru completion specs: -Pc field separators and -B/--build
option placement (warpdotdev/command-signatures#336)
- Forward --context/--cluster/--user in kubectl generators
(warpdotdev/command-signatures#331)

## Linked Issue
Addresses #5186 (labeled `ready-to-implement`). Also addresses #3929,
which asks for this same context-forwarding behavior. Deliberately no
closing keyword — #5186 covers several symptoms and should be closed
manually with a note that the earlier parts landed in the June 2026
stable builds.
- [x] The linked issue is labeled `ready-to-spec` or
`ready-to-implement`.
- [ ] Where appropriate, screenshots or a short video of the
implementation are included below (especially for user-visible or UI
changes).

## Testing
The kubectl behavior is covered by unit tests in
warpdotdev/command-signatures#331, which assert the generated command
string rather than merely that completion happens — including an
`assert_eq` on the entire command for the reported case, and a tightened
`test_context_and_namespace_flags_before_subcommand` (it previously
passed a `--context` but only checked namespace forwarding, which is why
the earlier #247 fix missed this). That repo's `./script/presubmit` and
CI were green on merge: 174 tests, 33 of them kubectl-specific.

For this dependency bump:
- `cargo fmt --all --check` passes.
- `cargo clippy -p warp_completer --all-targets --tests -- -D warnings`
passes against the new rev.
- `cargo metadata --locked` accepts the lockfile, so `Cargo.lock` is in
sync; the lockfile diff is limited to the two `command-signatures`
source lines.
- `cargo tree -p warp_completer -i warp-command-signatures` confirms
`15debaeb` is what resolves.
- `cargo test -p warp_completer` reports 138 passed / 25 failed,
identical to `origin/master` with this change stashed. Those 25 failures
are pre-existing in this environment and unrelated to the bump. There
are no kubectl-specific tests in `warp_completer`.

- [ ] I have manually tested my changes locally with `./script/run`

### Screenshots / Videos
No capture taken. Exercising this path in a running client requires a
full client build against the bumped rev, which is expensive relative to
the value: warpdotdev/command-signatures#247 already carries screenshots
of the `--context`/`--cluster` value completion working, #331 carries
end-to-end evidence from real `kubectl` runs against a synthetic offline
kubeconfig, and the generated command is asserted precisely by unit
tests.

## Agent Mode
- [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode

<!--
## Changelog Entries for Stable
-->
CHANGELOG-IMPROVEMENT: Added completions for `yay` and `paru`, and
`kubectl --user` value completions.
CHANGELOG-BUG-FIX: Fixed `kubectl` completions ignoring a `--context`,
`--cluster` or `--user` written on the command line, so namespaces, pods
and other resources are now suggested from that cluster instead of the
shell's active context. `kubecolor` and `oc` now complete those flags
too, and `nx run` completions were fixed.

<!-- warp:pr-description-artifacts start -->
<!-- warp:pr-description-artifacts end -->

Co-authored-by: Warp Agent <agent@warp.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Common CLI tools better completion - Nx, npm, and more

2 participants