-
Notifications
You must be signed in to change notification settings - Fork 24
CLI: add stdin support for instance validation #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ddb8312 to
9a040d7
Compare
|
Hi @jviotti , I’ve opened this PR and would appreciate a review when you have time. Thanks! |
|
Hey @Vaibhav701161 , sorry for the delay. It has been a hectic week. I'll try to get into it today |
|
I like the idea but I think there are some things to iron out:
I think for consistency, we can require the The other problem here will be line numbers. We should make sure all relevant commands handle standard input while still reporting line/column information and potentially some "special" file path like |
4d5ff3f to
112b374
Compare
|
Hey @jviotti , thanks a lot for the feedback. I’ve pushed an updated iteration that tries to address the concerns you mentioned:
|
f70d55d to
b9bb23e
Compare
|
Hi @jviotti , just a quick follow-up on this. |
|
|
||
| struct InputJSON { | ||
| std::filesystem::path first; | ||
| std::filesystem::path resolution_base; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is just a display name, maybe make a std::string? Otherwise <stdin> is not really a path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this still needs to be addressed?
test/validate/pass_stdin.sh
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split this test into multiple tests. If you see the other tests in the project, we have specific conventions and we always test a single thing per file. Plus you also want to add test for every other applicable command.
Finally, you didn't register this test in test/CMakeLists.txt, so it won't run at all
src/command_lint.cc
Outdated
| copy, sourcemeta::core::schema_walker, custom_resolver, | ||
| get_lint_callback(errors_array, entry, output_json), dialect, | ||
| sourcemeta::jsonschema::default_id(entry.first), | ||
| sourcemeta::core::URI::from_path(entry.resolution_base) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still definitely want to use sourcemeta::jsonschema::default_id here, to concentrate that logic in a single place. Maybe make such function take entry directly, so that inside we can decide to use entry.resolution_base or whatever?
src/command_lint.cc
Outdated
| custom_resolver, | ||
| get_lint_callback(errors_array, entry, output_json), dialect, | ||
| sourcemeta::jsonschema::default_id(entry.first), | ||
| sourcemeta::core::URI::from_path(entry.resolution_base) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
src/input.h
Outdated
| // TODO: Print a verbose message for what is getting parsed | ||
| auto parsed{read_file(canonical)}; | ||
| result.push_back({std::move(canonical), std::move(parsed.document), | ||
| auto canonical_copy{canonical}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this deletion was intended?
src/input.h
Outdated
| } | ||
| } | ||
| if (stdin_count > 1) { | ||
| throw std::runtime_error{"Standard input (-) can only be specified once"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| throw std::runtime_error{"Standard input (-) can only be specified once"}; | |
| throw std::runtime_error{"The standard input position argument `-` can only be specified once"}; |
src/input.h
Outdated
| std::size_t stdin_count{0}; | ||
| for (const auto &arg : arguments) { | ||
| if (arg == "-") { | ||
| stdin_count++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think counting all occurrences makes sense if you only want up to two. Maybe check that if you already got at least 2, then its an error and you can break?
test/validate/pass_stdin.sh
Outdated
| set +o errexit | ||
| cat "$TMP/schema.json" > "$TMP/schema_stdin.json" | ||
|
|
||
| OUTPUT=$("$1" validate - "$TMP/schema.json" < "$TMP/schema_stdin.json" 2>&1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the other shell scripts for the conventions on how we test stuff. Some obvious ones:
- We never capture into a variable. We pipe into a file and then
diffit - We never enable
set +o errexit - We never test more than one thing at once
Also your test is not registered in test/CMakeLists.txt so it won't run at all. But overall, split it so that there are multiple tests testing each one thing
Signed-off-by: Vaibhav mittal <[email protected]>
Signed-off-by: Vaibhav mittal <[email protected]>
Signed-off-by: Vaibhav mittal <[email protected]>
Signed-off-by: Vaibhav mittal <[email protected]>
Signed-off-by: Vaibhav mittal <[email protected]>
Signed-off-by: Vaibhav mittal <[email protected]>
b9bb23e to
77066a9
Compare
Signed-off-by: Vaibhav mittal <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 issues found across 12 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src/command_fmt.cc">
<violation number="1" location="src/command_fmt.cc:25">
P2: Use a structured error type from `error.h` instead of `std::runtime_error` for stdin not supported. This enables proper machine-readable JSON output when `--json` is passed, following the pattern of other error types like `YAMLInputError`.
(Based on your team's feedback about avoiding dynamically constructed exception messages and reusing centralized error wrapper types.) [FEEDBACK_USED]</violation>
</file>
<file name="src/input.h">
<violation number="1" location="src/input.h:151">
P2: Missing YAML fallback for stdin input. The PR description states "JSON-first, YAML fallback" but `read_from_stdin()` only parses JSON. This is inconsistent with file handling which falls back to YAML if JSON parsing fails. Note: implementing YAML fallback would require first buffering stdin (since it can only be read once), then attempting JSON parse, then falling back to YAML on failure.</violation>
</file>
<file name="test/validate/fail_stdin_multiple.sh">
<violation number="1" location="test/validate/fail_stdin_multiple.sh:25">
P2: Add a JSON error assertion for this failure case so the structured error output is validated alongside the text output.
(Based on your team's feedback about adding JSON variants for failure test cases.) [FEEDBACK_USED]</violation>
</file>
<file name="test/validate/fail_stdin_schema.sh">
<violation number="1" location="test/validate/fail_stdin_schema.sh:22">
P2: Add a JSON error assertion for this fail_* test so structured error output remains covered.
(Based on your team's feedback about adding JSON variants for failure test cases.) [FEEDBACK_USED]</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Adds stdin support for instance input to enable real-time editor diagnostics.
Fixes(#537)
src/input.h(JSON-first, YAML fallback).validateaccepts instances from stdin only; schemas must be file paths.$refagainst the current working directory.test/validate/pass_stdin.sh.sourcemeta/studio#61; addressessourcemeta/jsonschema#537.Refs: sourcemeta/studio#61, #537
*

Build and test: