Skip to content

fix(layout): layout.addElement refuses a parameter its element kind doesn't read (#3074) - #3189

Merged
Mavrick-F merged 1 commit into
opengeos:mainfrom
choupeanut:fix/3074-add-element-unread-keys
Nov 28, 2026
Merged

Mavrick-F merged 1 commit into
opengeos:mainfrom
choupeanut:fix/3074-add-element-unread-keys

Conversation

@choupeanut

@choupeanut choupeanut commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

layout.addElement of 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 as bold on a north arrow or step and units on 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)

  • One list of keys per kind beside ADD_GRID_KEYS, checked by only_add_keys once, before the picture file is read.
  • null still means not given. The refusals that were already there keep their messages and run first.
  • Two keys are accepted on every kind without being listed as read. 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.
  • The key shown in the error is cut to 40 characters and a control character is shown as ?; this also covers the grid and the extent indicator.
  • A script or saved command that gave a key its kind never read now gets an error instead of a silent success.
  • Not in this PR: layout.update and layout.addFrame drop unread keys the same way (and layout.publication's option objects); section already 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, frame and 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.txt is unchanged.

Testing

  • New tests in crates/engine/src/cmd/layout/elements.rs: add_element_other_kinds_refuse_unread_parameters_without_mutating (failed before the change: unwrap_err() on an Ok), add_element_other_kinds_read_every_listed_key_and_ignore_null_unread_ones (guards against refusing a key a kind reads) and add_element_unread_key_is_shown_cut_and_without_control_characters.
  • Local gate (this branch merged onto current main): pre-commit, fmt, clippy, nextest (CI profile) on the packages CI selects, layers, schema/fixtures, test hygiene, xtask rows, maturin + pytest: all passed.
  • Not run locally: the wasm build, macOS, Windows.

UI evidence

No visible UI change.

Related issue

Closes #3074
Builds on #2890 and #3060.

Summary by CodeRabbit

  • Bug Fixes
    • layout.addElement now reports an error when an element receives non-null parameters it doesn’t support, including the element kind and accepted parameters.
    • Invalid parameters are rejected before the layout or undo history changes.
    • Error messages display unusual control characters safely and shorten overly long parameter names.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

layout.addElement now checks parameters against accepted keys for standard element kinds before constructing an element. It allows frame and name across kinds, ignores null unread keys, and reports other unread keys with sanitized, shortened error text. Tests cover validation and confirm rejection does not mutate the layout or undo state.

Changes: layout.addElement validation

Layer / File(s) Summary
Accepted keys and validation
crates/engine/src/cmd/layout/elements.rs
Per-kind key lists define accepted parameters. only_add_keys rejects unread non-null keys and sanitizes long or control-character keys in errors. add_element validates before construction. Grid and extent-indicator checks use the updated helper signature. Tests cover accepted keys, rejection without layout or undo mutation, and error display.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • opengeos/RustGIS#3060 — It adds the same validation approach for grids and extent indicators; this PR extends that approach to other element kinds and updates the shared validation helper.

Suggested reviewers: jgregoriorincon

Merge Risk: Minimal · up to 4216a

layout.addElement now refuses unread non-null parameters for the remaining element kinds, with a clear error and no layout change. The inspected built-in callers stay compatible. Only external scripts that pass unrelated keys would now see errors, which is the intended behavior. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: layout.addElement now refuses parameters that the element kind does not read, and it references the issue number. It is specific, single-sentence, and matches the chan…
Description check Passed The description fills the Summary, Testing, UI evidence, and Related issue sections. The Summary explains the new per-kind key refusal, the accepted exceptions for name and frame, the 40-character tru…
Linked Issues check Passed Directly linked issue #3074 asks for per-kind key allow-lists on the remaining layout.addElement kinds, checked with only_add_keys before mutation, with null treated as not given. The reviewed head wi…
Out of Scope Changes check Passed The changes stay in the scope of #3074. They are limited to layout.addElement validation in crates/engine/src/cmd/layout/elements.rs, the only_add_keys helper signature (which gains an accepted-keys p…
Full details: Title check

Explanation

The title names the main change: layout.addElement now refuses parameters that the element kind does not read, and it references the issue number. It is specific, single-sentence, and matches the changeset. Its length (88 characters) is long but acceptable.

Full details: Description check

Explanation

The description fills the Summary, Testing, UI evidence, and Related issue sections. The Summary explains the new per-kind key refusal, the accepted exceptions for name and frame, the 40-character truncation, and the out-of-scope commands. Testing lists new tests and local gates, and states which checks were not run. The UI evidence section states no visible UI change, as the template requires. The Related issue section links #3074. The description follows the template structure and is mostly complete.

Full details: Linked Issues check

Explanation

Directly linked issue #3074 asks for per-kind key allow-lists on the remaining layout.addElement kinds, checked with only_add_keys before mutation, with null treated as not given. The reviewed head wires this in crates/engine/src/cmd/layout/elements.rs: add_element calls only_add_keys(p, what, keys, ADD_ACCEPTED_KEYS) from added_keys(kind) after the existing refusals and before element_background and the picture read. The shared check also covers the grid and extent indicator, as #3060 did. The error key display is cut to 40 characters with control characters shown as '?'. The PR reports three new tests covering refusal without mutation, every listed key being read, and safe key display. Limit: the tool output was truncated at 16000 bytes before the added_keys function body, so the per-kind key lists were not read directly. Their contents rest on the PR description and the visible wiring. The layout.update, layout.addFrame and layout.publication gaps named in the issue are excluded by the PR, as stated.

Full details: Out of Scope Changes check

Explanation

The changes stay in the scope of #3074. They are limited to layout.addElement validation in crates/engine/src/cmd/layout/elements.rs, the only_add_keys helper signature (which gains an accepted-keys parameter for name and frame), the shared key-display rule, and tests. The key display rule also applies to the grid and extent indicator checks; this follows from the shared only_add_keys function and is disclosed in the PR. The PR excludes layout.update, layout.addFrame and layout.publication, and the visible diff does not touch them. The truncated output did not show the full added_keys body, so the exact lists were not checked line by line.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each key in place,
And gives stray fields a clear “not this” face.
Nulls pass by without a sound,
Safe short errors hop around.
The layout stays just as it was.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 47262195-7b0f-4ecd-9a1e-7f30ee814d06
Commits

Reviewing files that changed from the base of the PR and between 9b0f0f9 and 4216ad8.

Files selected for processing: 1

  • crates/engine/src/cmd/layout/elements.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

/// 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"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:?}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Scope: one file, crates/engine/src/cmd/layout/elements.rs (+370/−6). It refuses a layout.addElement key that the element kind doesn't read (#3074). It adds per-kind key lists, passes an accepted list to only_add_keys, and shows the caller's key cut to 40 characters with control characters replaced.

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

  • None found. I checked each kind's list against what add_element and its helpers read: restyle (north arrow, scale bar), chart_options and chart_look_options, place, shape_width, corner_radius, element_dash, line_head, line_dir, given_num, the text helpers, frame_layer_name, colorbar_layer, the legend helpers and graphics::picture. Every key read is in its kind's list. Confidence: high.
  • Callers that send keys to layout.addElement (the ribbon's layout_groups, the picture senders in ui-egui/src/lib.rs, the print-layout skill, and the engine tests I grepped) send no key that a kind refuses. Confidence: medium, since this is a grep, not a run.

Security

  • None. The echoed key is sanitised and truncated. Only C0/C1 control characters are replaced (see Quality).

Performance

  • None. The new lookups are linear scans over short constant lists, run once per call.

Quality

  • Test gap (inline on line 1454): a listed key that its kind never reads would pass the "read every listed key" test silently.
  • Invisible format characters (bidi overrides such as U+202E, zero-width characters) are echoed as-is because only char::is_control is replaced. Low confidence that this matters, since the text only reaches an error message.
  • The doc comment on ADD_ACCEPTED_KEYS (elements.rs:898–901) reads awkwardly ("takes of any kind though a kind may not read them"). Nit.
  • The "Null counts as not given" loop in the same test module is hard to follow because of its added_keys(...) filter. Nit.
  • The frame-prefix rule in add_element_other_kinds_refuse_unread_parameters_without_mutating repeats what the lists already encode, so a list change also needs a test change. Nit.

AGENTS.md

  • The frame key is still silently dropped on text, picture, rectangle, ellipse, circle, line and arrow (inline on line 902). The PR discloses this. The fix is small and sits in ribbon.rs.
  • Not re-raised, since the PR states they are follow-ups: layout.update, layout.addFrame and layout.publication's option objects drop unread keys the same way. I confirmed that layout.addFrame and layout.update do not use only_add_keys.

Change size

Compared with the base branch (merge base 733f19b to PR head 4216ad8).

Measure Value
Files changed 1 (added 0, modified 1, removed 0, renamed 0)
Size before 52.8 KB
Size after 69.5 KB
Total size change +16.8 KB
Path Before After Change
crates/engine/src/cmd/layout/elements.rs 52.8 KB 69.5 KB +16.8 KB

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Commit 4216ad8 from a fork built, but isn't published until a maintainer adds the preview label (once per commit).

@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 28, 2026
Merged via the queue into opengeos:main with commit 4b28710 Nov 28, 2026
28 checks passed
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.

[Bug]: layout.addElement drops unread parameters silently on the remaining element kinds

2 participants