← Back to Pull requests

feat: add JSON and CSV output formats #7

Merged
ShivanshhhG merged 4 files (173 lines) on May 20, 2026 10:21 UTC
View on GitHub
ShivanshhhG ShivanshhhG commented on May 16, 2026 15:26 UTC
Author

This PR implements Issue #5 by adding support for JSON and CSV output formats.

Changes


  • Added --format flag to the CLI with pytest, json, and csv options.

  • - Implemented write_json and write_csv methods in KibanaTestGenerator.

  • - Added unit tests in tests/test_formats.py to verify all formats preserve redaction.

  • - Updated README.md with the new options.

  • Verification


  • Ran full test suite: All 61 tests PASSED.

  • - Manual verification: Confirmed valid JSON and CSV output using data/sample_kibana_export.json.
  • Diff: 173 lines (+166 / -7) across 4 files Reviewer: golikovichev Review duration: 5455m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.38) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.38 · 173 lines diff across 4 files
    0.38
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 5 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.309
    Real PR Conversation Timeline
    7 items
    golikovichev golikovichev commented on May 17, 2026 18:37 UTC
    Contributor

    Thanks @SHIVANSH-ux-ys, the shape is right. Backward-compatible --format flag, both new methods preserve redaction, the README table reads cleanly. One blocking item and two smaller things before merge.

    Blocking: json.dump needs ensure_ascii=False

    Both write_json and the inner json.dumps in write_csv default to ensure_ascii=True, which escapes every non-ASCII character into \uXXXX. That breaks Cyrillic content in URLs and bodies (and any other non-ASCII text the input may carry). It is the same kind of regression v1.0.1 fixed for the input path (issue #3, UnicodeDecodeError on non-ASCII input). Same shape now landing on the output side.

    Two-line fix:

    # write_json
    with open(output_path, "w", encoding="utf-8") as f:
        json.dump(data, f, indent=2, ensure_ascii=False)
    
    # write_csv (inner)
    row["headers"] = json.dumps(row.get("headers", {}), ensure_ascii=False)
    row["body"] = json.dumps(row.get("body"), ensure_ascii=False)
    

    Recommended: one Cyrillic test in tests/test_formats.py

    The repo already has a baseline tests/test_input_validation.py::test_cyrillic_in_url_and_body_parses from the v1.0.1 fix. Mirroring that on the output side prevents the regression above from sneaking back in. Rough shape:

    def test_write_json_preserves_cyrillic(tmp_path):
        entry = KibanaLogEntry(
            method="POST",
            url="/api/v1/пользователи/профиль",
            status=200,
            headers={"X-Запрос-Id": "значение"},
            body={"имя": "Михаил"},
        )
        output = tmp_path / "out.json"
        KibanaTestGenerator(tmp_path).write([entry], output, output_format="json")
        text = output.read_text(encoding="utf-8")
        assert "пользователи" in text
        assert "\\u" not in text  # ensure_ascii=False guard
    

    Smaller things

  • The hardcoded fieldnames = ["method", "url", "status", "duration", "headers", "body"] in write_csv will drift if KibanaLogEntry gains a field. Deriving from KibanaLogEntry.model_fields.keys() is a cheap future-proof.

  • Worth adding a test that an unsupported output_format raises ValueError rather than silently doing nothing. The dispatch already raises, just no test covers it.

  • Comment # templates dir not needed for json is true today, but if KibanaTestGenerator.__init__ ever starts validating templates upfront, the json/csv tests will start failing for an unrelated reason. Worth flagging in a docstring on write_json / write_csv that the constructor argument is unused for non-pytest formats, or pass templates=None explicitly.
  • Happy to merge once the ensure_ascii=False and Cyrillic test land. Push to the same branch and I will re-review.

    ShivanshhhG ShivanshhhG commented on May 18, 2026 05:36 UTC
    Author

    Hi @golikovichev,
    I've pushed the fixes and resolved the merge conflicts with the latest main branch..

    ShivanshhhG ShivanshhhG commented on May 18, 2026 05:44 UTC
    Author

    Hi @golikovichev,

    I've pushed the fixes and resolved the merge conflicts with the latest main branch!

    Specifically:
    1. Passed ensure_ascii=False in both the write_json and write_csv serializations so Cyrillic/non-ASCII characters are fully preserved in the output files.
    2. 2. Added a robust Cyrillic formatting test in tests/test_formats.py validating that raw Unicode content is intact in both formats without any escaping.
    3. 3. Merged the latest main upstream changes, combining the new --max-input-mb size guard with the --format selection cleanly.
    All 67 tests are passing. Let me know if you need anything else before merge!

    golikovichev golikovichev commented on May 18, 2026 23:58 UTC
    Contributor

    Thanks @SHIVANSH-ux-ys, both blocking items are addressed: ensure_ascii=False lands in write_json and the inner write_csv json.dumps, and test_cyrillic_output_formats mirrors the input-side guard from #3. The fix is correct.

    Three smaller items from the previous review are still open:

  • fieldnames in write_csv is still the hardcoded list. Deriving from KibanaLogEntry.model_fields.keys() keeps the CSV in sync if the entry model gains a field later.

  • No test asserts that output_format="bogus" raises ValueError. The dispatch already raises; just one short test that catches it would lock the behaviour in.

  • The # templates dir not needed for json comment in the new tests is still there. A one-line docstring on write_json / write_csv saying the constructor templates arg is unused for non-pytest formats is cleaner than the inline comment.
  • CI didn't run on this branch - first-time contributor workflow approval. I'll approve the run after these are in, and we can land it.

    ShivanshhhG ShivanshhhG commented on May 20, 2026 04:24 UTC
    Author

    "Thanks for the review! I've pushed a commit addressing those 3 remaining items. Let me know if everything looks good to go now."

    golikovichev golikovichev approved these changes on May 20, 2026 10:21 UTC
    Approved Reviewer

    Thanks @SHIVANSH-ux-ys, all three items addressed cleanly: fieldnames derived from KibanaLogEntry.model_fields, test_bogus_format_raises_error locks the dispatch behaviour, and the inline comments moved to docstrings on write_json and write_csv. CI matrix is green across the 12 OS / Python combinations. Squash-merging.

    Reviewers
    Assignees
    ShivanshhhG ShivanshhhG
    Labels
    risk: low confidence: 90.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.2% (MEDIUM) · Higher = larger blast radius
    38.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.0% · Lower = rushed or shallow review
    90.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.8% · Safe to merge
    3.8%