Conversation
The dict branch of the single-output conversion called click.echo() without the output file, so the JSON went to stdout and the file given with --output/-o was never written, although the command exited 0. Pass the output file like all other result types do. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The change is minimal, consistent with existing output handling, and includes a focused regression test that fails on main and passes with the fix.
Review effort: Lite
Findings: None
What changed in this PR
This PR fixes sigma convert so that when a backend’s convert() returns a plain dict, the CLI correctly honors --output/-o by writing the JSON to the provided output file instead of always emitting to stdout.
Changes:
- Pass the
outputfile handle toclick.echo()for thedictresult branch insigma/cli/convert.py. - Add a regression test that monkeypatches the test backend to return a
dictand asserts the JSON is written to the-ofile (and not stdout).
| File | Description |
|---|---|
sigma/cli/convert.py |
Fixes the dict output path to write via the configured --output/-o stream. |
tests/test_convert.py |
Adds coverage ensuring dict results are written to the output file rather than stdout. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BLUF
dictfromconvert(), the result is always printed to stdout.--output/-ois ignored.sigma convert -t <backend> -f <dict format> -o result.json rules/exits 0, butresult.jsonis never created and the JSON goes to the terminal or pipe instead.outputtoclick.echo()in the dict branch, like every other result branch already does. This is a one-line change.convert()is monkeypatched to return a dict) checks that the JSON lands in the-ofile and not on stdout. It fails onmainand passes with the fix.Priority: medium
Details
Root cause:
sigma/cli/convert.py:584-585The
str,bytes, list-of-str and list-of-dict branches (convert.py:556,563,569,575-583) all passoutput. After the fix:No backend in this repository's test environment returns a plain
dict, so the test simulates one by monkeypatchingTextQueryTestBackend.convert. The rest of the CLI code runs unchanged.Testing
tests/test_convert.py::test_convert_output_dict_to_file. It fails onmainbecause the JSON is on stdout and the file is empty.poetry.lock: pySigma 1.4.0, click 8.4.2, pyparsing 3.3.2):pytest --cov=sigma→ 119 passed, 1 skipped.🤖 Generated with Claude Code