Query piped nodes when counting with -R/-F #22

Merged
benvin merged 2 commits from benvin/count-stdin-query into main 2026-10-13 21:04:18 +11:00
Member

With piped input, -C skipped the query and counted the piped lines' second column, so ... | node-lookup -R -C reported the upstream fact instead of each node's role.

  • query each piped node for -R/-F with -C and count the results
  • count piped lines directly only for bare -C with piped input; -C with -j/-1/-2 still requires -R/-F
  • validate flags before reading stdin so invalid combos never block on an open pipe
  • add tests for piped count paths, rejected combos and validation ordering
With piped input, `-C` skipped the query and counted the piped lines' second column, so `... | node-lookup -R -C` reported the upstream fact instead of each node's role. - query each piped node for `-R`/`-F` with `-C` and count the results - count piped lines directly only for bare `-C` with piped input; `-C` with `-j`/`-1`/`-2` still requires `-R`/`-F` - validate flags before reading stdin so invalid combos never block on an open pipe - add tests for piped count paths, rejected combos and validation ordering
unkin-agent added 1 commit 2026-10-13 20:38:58 +11:00
Query piped nodes for -R/-F with -C; count input only for bare -C
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
8b9ac394a0
Author
Member
  • main.go:360 — stdinReader (blocking Peek) now runs before the -R or -F must be used… validation. An invalid flag combo (e.g. -m foo) with an open, empty stdin pipe now hangs instead of erroring immediately (verified: sleep 3 | node-lookup -m foo times out; on main it errors) → run the validation first, only peek stdin after it passes (or derive passthrough without peeking until needed).
  • main.go:367 — piped bare -C -j now prints count lines instead of JSON (printf "a.x v1\n" | node-lookup -C -j → 1: v1); the jsonMode case used to win → exclude jsonMode from passthrough or reject the combo.
  • main_test.go:~920 — no test for -C piped with -F (only -R), and none for the new bare--C + -1/-2/-j interaction → add a -F case and pin the intended -j behaviour.
- main.go:360 — `stdinReader` (blocking `Peek`) now runs before the `-R or -F must be used…` validation. An invalid flag combo (e.g. `-m foo`) with an open, empty stdin pipe now hangs instead of erroring immediately (verified: `sleep 3 | node-lookup -m foo` times out; on main it errors) → run the validation first, only peek stdin after it passes (or derive `passthrough` without peeking until needed). - main.go:367 — piped bare `-C -j` now prints count lines instead of JSON (`printf "a.x v1\n" | node-lookup -C -j` → `1: v1`); the `jsonMode` case used to win → exclude `jsonMode` from `passthrough` or reject the combo. - main_test.go:~920 — no test for `-C` piped with `-F` (only `-R`), and none for the new bare-`-C` + `-1/-2/-j` interaction → add a `-F` case and pin the intended `-j` behaviour.
unkin-agent added 1 commit 2026-10-13 20:41:34 +11:00
validate flags before reading stdin and reject bare -C with -j/-1/-2
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
fae7dad630
Author
Member
  • main.go:~373 — bare -C with an open but empty stdin (sleep 3 | node-lookup -C) now blocks in stdinReader Peek. On main it returned the "-R or -F must be used" error immediately. This is the no-TTY agent/CI case → decide: accept the block (same as -R), or keep it fail-fast, and add a test for whichever you pick.
  • main_test.go — nit: no test pins bare -C on an open-but-empty pipe, which is the one validation-before-read path that can still block.
- main.go:~373 — bare `-C` with an open but empty stdin (`sleep 3 | node-lookup -C`) now blocks in `stdinReader` Peek. On main it returned the "-R or -F must be used" error immediately. This is the no-TTY agent/CI case → decide: accept the block (same as `-R`), or keep it fail-fast, and add a test for whichever you pick. - main_test.go — nit: no test pins bare `-C` on an open-but-empty pipe, which is the one validation-before-read path that can still block.
benvin merged commit 499903ab2b into main 2026-10-13 21:04:18 +11:00
benvin deleted branch benvin/count-stdin-query 2026-10-13 21:04:18 +11:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/node-lookup#22