Repository navigation
Report in JSON which warnings --deny promotes to errors - #1671
Conversation
|
Please don't let your LLM write a PR description for you. It looks like this is wrapping the actual report in a weird different layer which looks like it might be incompatible or would make it easier to make it incompatible with existing consumers in the future. It would be helpful if you can explain concisely (that is, in your own words) what the proposed solution is. |
|
Fair on the description — it was too long and it wasn't in my voice. I use an LLM to draft; the analysis and the runs behind it are mine, and I should have cut it down before posting. Sorry. Short version: The exit code is already right today. The JSON isn't: The patch adds one key next to the existing ones: "warning_summary": { "denied": 1, "allowed": 0, "deny": ["unmaintained"] }There is no extra layer around the report in the output. The one real consequence of I also deliberately did not do what the issue literally asks, which is to move denied warnings into |
Can you do some analysis on these options to discuss the different trade-offs and to be made? IMO moving warnings into |
|
Three options. What decides between them is what a A — summary key (what this PR does now). B — per-warning C — move denied warnings into
So The second cost of C is that the kind — My read: C for the advisory-backed kinds plus B's flag for yanked is coherent, but it is two shapes for one concept. B alone is one shape that covers all four kinds. A is the least invasive and the least useful of the three. If you are fine with yanked staying a warning, I will write C. Otherwise say B and I will write that instead. |
|
@djc gentle ping — the trade-off analysis you asked for is in my comment above: A (summary key, what the PR does now), B (per-warning |
|
@djc — a week on, so just the open question rather than more analysis. It reduces to one thing: whether you are fine with If yanked staying a warning is acceptable, I'll write C. If not, say B and I'll write that instead. Either is fine by me; I just don't want to guess and hand you the wrong shape. |
This sounds like the best option to me. I don't much care about anyone deserializing warnings with |
|
Agreed on B then — and no, I don't care about the empty case either. You're right that the caller already knows what |
|
Sorry, GitHub won't let me merge this due to conflicts. Can you rebase, and ideally squash all your commits into a single one? |
Expose a denied flag on each warning rejected by the configured warning policy, preserving the existing warning details in JSON reports. Cover the report behavior with focused regression tests. Assisted-by: OpenAI Codex Signed-off-by: Eljees <[email protected]>
cb10032 to
bf21c8f
Compare
Refs #376. @Shnatsel — you said a PR would be welcome; this is one shape of it, and I'd rather check the shape with you than assume.
First, what current
mainactually does. The MCVE from the issue (cpuid-bool = "0.2"):cargo audit --jsonvulnerabilities.found: false,warnings.unmaintained: 1cargo audit --deny warnings --jsonSo the exit code is already correct —
should_exit_with_failurecounts denied warnings regardless of output format. What's missing is that the JSON says nothing about it. The terminal output distinguishes the two cases (error: 1 denied warning found!versuswarning: 1 allowed warning found); the JSON doesn't, so a consumer that parses it — audit-check, which is the consequence the issue names — can't tell a denied warning from an allowed one.This carries that same fact across.
warning_summaryis added next to the existing keys:with
"denied": 0, "allowed": 1, "deny": []when nothing is denied. The numbers come from the existingcount_warnings, so the JSON and the terminal summary line can't drift apart. Thedenylist is there because the issue asks specifically for the.cargo/audit.tomlroute to work, and a consumer may want to know why something was denied — that case is covered and producesdeny: ["unmaintained", "unsound", "yanked"].The report is
#[serde(flatten)]-ed into the wrapper, so every pre-existing key stays exactly where it was — verified by comparing the two JSON bodies key by key. Terminal and SARIF output are untouched.On the shape. The issue says it expects the warning "to be promoted to an error in the json", i.e. moved into
vulnerabilities. I didn't do that, becauseWarningandVulnerabilityare different types and moving denied warnings would change what every existing--jsonconsumer sees, including ones that don't setdenyat all. An additive key can't break anyone. If you'd rather have the promotion — or a per-warning"denied": trueinstead of a summary — say which and I'll redo it; the change is small either way.cargo build,cargo fmt --check,cargo clippy(0 warnings, same as the clean tree) andcargo test -p cargo-auditare all green.AI-assisted (LLM used for drafting); the runs above are mine.