Skip to content

Loudly reject JSONL on fmt and lint --fix - #885

Merged
jviotti merged 3 commits into
mainfrom
jsonl
Sep 24, 2026
Merged

jviotti merged 3 commits into
mainfrom
jsonl

Conversation

@jviotti

@jviotti jviotti commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

Review in cubic

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@augmentcode

augmentcode Bot commented Sep 24, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR adds explicit multi-document input handling to CLI input parsing.

Changes:

  • Recognizes JSONL and YAML multi-document streams from files, directories, and standard input.
  • Emits individual InputJSON entries with document indexes and multi-document metadata.
  • Preserves YAML position tracking across document boundaries.
  • Rejects multi-document input for fmt and lint --fix with a dedicated error type.
  • Adds centralized exception rendering and the unsupported-operation exit code for that error.
  • Refactors file handling into a shared helper to cover direct files and directory traversal consistently.
  • Adds CLI coverage for JSONL, YAML streams, stdin, directory inputs, and structured error output.

Technical Notes: Regular linting and validation can process each document independently, while rewrite-oriented commands reject ambiguous multi-document sources.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode 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.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/input.h Outdated
inline auto at_end_of_stream(std::istream &stream) -> bool {
auto character{stream.peek()};
while (character != std::char_traits<char>::eof() &&
std::isspace(static_cast<unsigned char>(character)) != 0) {

@augmentcode augmentcode Bot Sep 24, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/input.h:175: std::isspace accepts characters such as form-feed and vertical-tab that JSON does not define as whitespace. Consequently, stdin containing a valid JSON value followed only by \f is accepted as a single JSON document here, whereas the JSON/JSONL parsers correctly reject that trailing byte.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread src/input.h Outdated
return result;
}

// Standard input that carries more than one JSON document is JSONL

@augmentcode augmentcode Bot Sep 24, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/input.h:307: A valid YAML stream whose first document is also valid JSON but has no initial --- is routed here instead of to the YAML parser; for example, {"foo": "first"}\n---\nfoo: second is valid multi-document YAML but JSONL rejects the --- line. This makes the new stdin multi-document YAML support depend on an optional first-document marker.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 16 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/input.h">

<violation number="1" location="src/input.h:280">
P1: This fallback classifies newline-delimited JSON on stdin as YAML before JSONL gets a chance to parse it. Move the JSONL attempt before the YAML fallback so `lint --fix` rejects JSONL as multiple documents and downstream commands retain the correct input type.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/input.h Outdated
.positions = std::move(positions),
.property_storage = std::move(property_storage),
.yaml = true};
documents = read_yaml_documents(yaml_stream);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: This fallback classifies newline-delimited JSON on stdin as YAML before JSONL gets a chance to parse it. Move the JSONL attempt before the YAML fallback so lint --fix rejects JSONL as multiple documents and downstream commands retain the correct input type.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/input.h, line 280:

<comment>This fallback classifies newline-delimited JSON on stdin as YAML before JSONL gets a chance to parse it. Move the JSONL attempt before the YAML fallback so `lint --fix` rejects JSONL as multiple documents and downstream commands retain the correct input type.</comment>

<file context>
@@ -204,38 +258,199 @@ inline auto read_file(const std::filesystem::path &path) -> ParsedJSON {
-              .positions = std::move(positions),
-              .property_storage = std::move(property_storage),
-              .yaml = true};
+      documents = read_yaml_documents(yaml_stream);
     } catch (...) {
       throw sourcemeta::core::JSONFileParseError(stdin_path(), json_error);
</file context>

Comment thread test/format/fail_json_multidocument_stdin.clitest
Comment thread src/input.h Outdated
Comment thread src/input.h
Comment thread test/bundle/fail_stdin_multidocument.clitest
Comment thread test/lint/pass_lint_stdin_multidocument.clitest Outdated
Comment thread test/lint/pass_lint_stdin_multidocument.clitest Outdated
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 7 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread test/format/fail_stdin_non_json_whitespace.clitest
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
jviotti merged commit 5b8c9fd into main Sep 24, 2026
16 checks passed
@jviotti
jviotti deleted the jsonl branch September 24, 2026 19:13
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.

1 participant