Repository navigation
fix(layout): layout.addElement refuses a parameter its element kind doesn't read (#3074) - #3189
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| /// list them: `frame`, which the ribbon sends with every kind (a text, picture, rectangle, ellipse, | ||
| /// circle, line or arrow has no frame to read it for, so it is dropped there still), and `name`, | ||
| /// which a kind that isn't a section says it ignores (`say_name_ignored`) rather than refuses. | ||
| const ADD_ACCEPTED_KEYS: &[&str] = &["frame", "name"]; |
There was a problem hiding this comment.
frame is accepted on every kind, but only some kinds read it. On a text, picture, rectangle, ellipse, circle, line or arrow a frame is still dropped without any notice. AGENTS.md's "Never silent" rule says a command that drops a parameter says so, and this leaves the one case the PR set out to fix. The PR description says the ribbon would have to stop sending it, and that change is small: in layout_groups, the add closure in crates/ui-egui/src/ribbon.rs (around line 3410) could set frame only for the kinds that read it (north arrow, scale bar, legend, colorbar, table, chart, grid, extent indicator). frame could then leave ADD_ACCEPTED_KEYS, so a script's frame on a text is refused like any other unread key.
Category: agents-md
| let mark = s.notice_mark(); | ||
| s.run("layout.addElement", &p).unwrap_or_else(|e| panic!("{kind}: {e}")); | ||
| let says: Vec<String> = said(&s, mark).into_iter().filter(|t| !t.contains("\"name\"")).collect(); | ||
| assert!(says.is_empty(), "{kind}: {says:?}"); |
There was a problem hiding this comment.
This assertion only shows that a listed key is accepted with no notice. A key that a kind's list names but that kind never reads would pass here too, and its value would be dropped silently, which is the failure this PR is meant to prevent. I checked each list by hand against add_element, restyle, chart_options and the helpers they call, and they match today. But nothing in the tests keeps them matching. Suggest that this test, for each listed key given a non-default value, also checks that the element changes compared with the same call without that key (or compares the serialised element). That makes a list that drifts from what the kind reads fail a test.
Category: quality
Code reviewScope: one file, Prior review threads: none were on the PR, so no earlier concerns were left alone. I could not run the tests (no shell here). The findings below come from reading the code and grepping callers. Bugs
Security
Performance
Quality
AGENTS.md
Change sizeCompared with the base branch (merge base 733f19b to PR head 4216ad8).
|
📖 Docs previewCommit |
Summary
layout.addElementof a north arrow, scale bar, legend, colorbar, text, dynamic text, picture, table, chart, rectangle, ellipse, circle, line or arrow accepted a parameter that kind does not read (another kind's, such asboldon a north arrow orstepandunitson a rectangle) and dropped it without a word. It is now refused before anything is read or added, naming the key and listing what that kind reads, as #3060 did for a grid and an extent indicator:layout.addElement: a north arrow takes no "bold" (it reads layout, kind, frame, x, y, w, h, background, style, fill, outline)
ADD_GRID_KEYS, checked byonly_add_keysonce, before the picture file is read.nullstill means not given. The refusals that were already there keep their messages and run first.name: a kind that isn't a section still says it ignores it, as before.frame: the ribbon sends it with every kind, so a text, picture, rectangle, ellipse, circle, line or arrow, which have no frame to read it for, still drop it silently. That one silent drop remains; the ribbon would have to stop sending it.?; this also covers the grid and the extent indicator.layout.updateandlayout.addFramedrop unread keys the same way (andlayout.publication's option objects);sectionalready checks its own keys. They are separate commands and are left for follow-ups.Surfaces
The command runs the same on the desktop, the browser, the command line, Python, the phone, the Assistant and MCP, plugins and saved tasks, so all of them get the refusal. The ribbon sends
layout,frameand each button's own keys, all accepted. Nothing is added, so there is nothing to undo or reopen: a refusal leaves the layout and the Undo history as they were. The parameter help already names the kind of each key and is unchanged;command-surface.txtis unchanged.Testing
crates/engine/src/cmd/layout/elements.rs:add_element_other_kinds_refuse_unread_parameters_without_mutating(failed before the change:unwrap_err()on anOk),add_element_other_kinds_read_every_listed_key_and_ignore_null_unread_ones(guards against refusing a key a kind reads) andadd_element_unread_key_is_shown_cut_and_without_control_characters.xtask rows, maturin + pytest: all passed.UI evidence
No visible UI change.
Related issue
Closes #3074
Builds on #2890 and #3060.
Summary by CodeRabbit
layout.addElementnow reports an error when an element receives non-null parameters it doesn’t support, including the element kind and accepted parameters.