Skip to content

feat(layout): write layout files with a format header (#2277) - #2805

Merged
jgregoriorincon merged 1 commit into
opengeos:mainfrom
jgregoriorincon:feat/2277-layout-file-header
Nov 23, 2026
Merged

jgregoriorincon merged 1 commit into
opengeos:mainfrom
jgregoriorincon:feat/2277-layout-file-header

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Layout files (.rgislayout) are now written with a format header, as map and layer files are: "format": 2 and, when the layout's elements use something an older reader would draw without and save again without, "requires" naming it. This is the writer half of #2277; the reader went out in v0.8.0 with #2527, so a released RustGIS already refuses such a file by name instead of opening it and losing the element's background, ink, wrap, chart settings, frame border or text size.

  • layout_capabilities (crates/engine/src/project_capabilities.rs) holds the layout element checks that Project::required_capabilities made inline. The project and the layout file both call it, so a layout element capability added later is required in both places. The project's requires is unchanged, in the same order.
  • layout_file_bytes writes {format, requires, ...layout} with the same Item header as map_file_bytes. It stays indented, as layout files have always been, so the header is the only change to the file. It never requires crs-wkt: a layout holds no coordinate system, only a measured grid's as text.
  • layout.save (desktop, CLI, Python, scripts, tasks: every caller of the command) and the browser download of Save Layout File (ui.saveLayout) both write through it, so the two give the same bytes. The phone (ui-touch) has no layout save. No command, parameter or help text changes.
  • A layout file requires only what its own elements use: not what another layout of the project uses, nor what a saved command does (the file holds neither).
  • docs/maintaining.md: the "Layout files are not covered ([Feature]: Layout files (.rgislayout): a checked format header, so an older RustGIS refuses what it can't keep #2277)" sentences are gone, and the backgrounds paragraph says what layout files now carry. The imported_layout_uses doc comment says a layout file read from a path brings its own header.

Releases before v0.8.0 still read a headed file as before, ignoring the header. That limit is why the writer waited for a release carrying the reader.

#2666 (open) adds a layout capability, layout-scale-bar-details, inline in Project::required_capabilities. Whichever of the two merges second moves it into layout_capabilities, so layout files require it too.

Testing

  • New tests in crates/engine/src/tests/layout_files.rs:
    • a_saved_layout_file_requires_what_its_elements_use_and_reads_back_the_same: for eleven layout fixtures in schema/fixtures/, which cover the nine capabilities (layout_chart_look and layout_chart_stack need two at once, with layout-chart-data) plus one fixture that needs none, the file's requires equals the requires written in the fixture, not one worked out again by the code under test. Imported into that project without its layout, the layout is the same, and saved again the file is byte for byte the same.
    • a_layout_file_requires_nothing_for_other_layouts_or_saved_commands: a second, plain layout of a project with a background and a saved wrap command writes no requires. The layout with the background requires only that.
  • New test in crates/ui-egui/src/lib.rs: layout_download_is_the_saved_layout_file. The browser download gives the same bytes as layout.save, header included.
  • Each new test failed before the change for the stated reason (no format in the file) and passes after.
  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo nextest run --workspace (9189 passed; the two DuckDB tests that need a local DuckDB left out), doctests, cargo xtask layers and cargo xtask schema --check: all pass.

UI evidence

No visible UI change.

Related issue

Closes #2277

Summary by CodeRabbit

  • New Features
    • Saved layout files now include format and feature-requirement information, helping the app identify layouts that need capabilities it does not support.
  • Bug Fixes
    • Layouts saved from the command line and downloaded from the app now use the same file format and metadata.
    • Layout imports now determine required features from the layout file’s header or, for inline layouts, from the layout content.

Layout files (.rgislayout) are now written as map and layer files are:
{"format": 2, "requires": [...], ...layout}, requiring what the layout's
elements use that an older reader would draw without and save again
without. The reader shipped in v0.8.0 (opengeos#2527), so a released RustGIS
refuses such a file by name instead of losing what it can't keep.

The layout element checks move from Project::required_capabilities into
layout_capabilities, which the project and layout_file_bytes both call;
the project's requires is unchanged. layout.save and the browser download
of Save Layout File write through layout_file_bytes.

Closes opengeos#2277
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Layout files now use a shared serializer that writes a format header and capabilities inferred from layout elements. The command-line save and UI download paths use that serializer. Tests and documentation cover the resulting metadata and compatibility rules.

Changes: Layout file metadata

Layer / File(s) Summary
Capability metadata and serialization
crates/engine/src/project_capabilities.rs, crates/engine/src/project.rs
The shared serializer writes pretty-printed JSON with a format header and capabilities inferred from layout elements. Capability aggregation uses the layout capability helper.
Save and download paths, validation, and format guidance
crates/engine/src/cmd/layout.rs, crates/ui-egui/src/lib.rs, crates/engine/src/tests/layout_files.rs, docs/maintaining.md, docs/user-guide/workspace.md
layout.save and ui.saveLayout use the shared serializer. Tests check metadata, round trips, and matching output. Documentation covers layout file requirements and compatibility behavior.

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

Change: Feature · Severity of issue fixed: Medium

Possibly related issues

  • opengeos/RustGIS#1405 — This PR adds a format header and capability requirements to layout files, a saved-file safeguard tracked by the issue.
  • opengeos/RustGIS#1853 — The PR uses the shared capability mechanism also used by project format 2.
  • opengeos/RustGIS#2008 — This PR adds the requested header and requirements list to standalone layout files.
  • opengeos/RustGIS#2487 — The layout capability checks include chart capabilities that saved layout files need to record when used.

Possibly related PRs

  • opengeos/RustGIS#2489 — This PR’s layout capability checks determine whether chart capabilities from the chart-option changes are included in saved layout files.

Suggested reviewers: giswqs, elpidioassinaturas

Merge Risk: Minimal · up to d3f91

Layout files now carry a format header and a list of required capabilities. The command-line save and the browser download write identical bytes. Older releases keep ignoring the header, and the compatible reader already rejects unknown requirements by name. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(layout): write layout files with a format header (#2277)" names the main change: layout files are now written with a format header. The changeset adds the "format" 2 header and "requir…
Description check Passed The description follows the template. It has a Summary that explains the change and why it is needed, and a Testing section that lists new tests and the checks run. The UI evidence section states 'No …
Linked Issues check Passed Directly linked issue #2277 has one active coding objective set. Its staged plan has a reader step and a writer step.

Writer step (implemented in this PR): The PR description and the change summary s…
Out of Scope Changes check Passed The changes relate to #2277. The Project::required_capabilities refactor moves inline layout checks into the shared layout_capabilities function. The PR says the project requires output is uncha…
Full details: Title check

Explanation

The title "feat(layout): write layout files with a format header (#2277)" names the main change: layout files are now written with a format header. The changeset adds the "format" 2 header and "requires" list to .rgislayout writing in layout.save and ui.saveLayout, which matches the title.

Full details: Description check

Explanation

The description follows the template. It has a Summary that explains the change and why it is needed, and a Testing section that lists new tests and the checks run. The UI evidence section states 'No visible UI change.', as the template allows. The Related issue section says 'Closes #2277'.

Full details: Linked Issues check

Explanation

Directly linked issue #2277 has one active coding objective set. Its staged plan has a reader step and a writer step.

Writer step (implemented in this PR): The PR description and the change summary show that layout_file_bytes (crates/engine/src/project_capabilities.rs) writes {format, requires, ...layout} with the Item header used by map_file_bytes. requires is computed from the layout's elements through layout_capabilities. layout.save (crates/engine/src/cmd/layout.rs) and the browser download ui.saveLayout (crates/ui-egui/src/lib.rs) both call it. The new tests cover eleven fixtures, check requires against fixture data, check import and resave round-trip, check that other layouts and saved commands add no requirement, and check that the download bytes equal layout.save bytes. This matches the issue's writer requirement and its round-trip test requirement.

Reader step: The PR states that the reader (check_format on layout import, refusal by name, legacy headerless files still open) shipped in v0.8.0 with #2527, and the changed layout.import documentation refers to the file header. I did not independently read the base reader code; the diff read was unavailable. This part therefore rests on the PR description and the layout.import documentation change.

The issue's alternatives section is design context, not a requirement. No unmet coding requirement is found in the evidence reviewed.

Full details: Out of Scope Changes check

Explanation

The changes relate to #2277. The Project::required_capabilities refactor moves inline layout checks into the shared layout_capabilities function. The PR says the project requires output is unchanged and in the same order. This is needed so that layout files and projects use one predicate. The layout_file_bytes re-export in crates/engine/src/project.rs and the layout.save call change are the writer path. The tests in crates/engine/src/tests/layout_files.rs and crates/ui-egui/src/lib.rs verify that writer. The docs changes in docs/maintaining.md and docs/user-guide/workspace.md describe the new header and remove the 'not covered (#2277)' statements. No unrelated feature, command, parameter, or UI change is shown. The PR states that the phone UI has no layout save and that no command or help text changes.

Limit: the whole-PR diff read was unavailable, so this verdict relies on the change summary and the PR description.

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 packs a layout neat,
With format tucked in, clear and sweet.
Each feature gets its name,
So saved files keep the same.
Two paths share the bytes they meet.

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: 2ce55efd-99fb-4320-9466-cf98a5a6c610
Commits

Reviewing files that changed from the base of the PR and between 1210bb0 and d3f91fa.

Files selected for processing: 7

  • crates/engine/src/cmd/layout.rs
  • crates/engine/src/project.rs
  • crates/engine/src/project_capabilities.rs
  • crates/engine/src/tests/layout_files.rs
  • crates/ui-egui/src/lib.rs
  • docs/maintaining.md
  • docs/user-guide/workspace.md

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

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Overall the change is sound. I found no bugs, security problems or AGENTS.md breaks. I did not build or run the tests (no shell in this review), so the test results below are from reading the code.

Bugs

  • None found. I checked the writer and reader paths:
    • layout.save and the browser download (ui.saveLayout) now produce the same bytes through layout_file_bytes.
    • layout.import reads the header through check_format, which refuses newer formats and unknown requires entries by name. Confidence: high.
    • Layout has no deny_unknown_fields, and its field names don't collide with format or requires, so the flattened header doesn't break the round trip. Confidence: high.
    • Project::required_capabilities now gets the same names in the same order as before (the loop only adds names not already present). Confidence: high.

Security

  • None found.

Performance

  • Nit, low impact: layout_capabilities builds an array of nine elements().any(...) results, so every scan runs eagerly. The old !required.contains(..) && any(..) form short-circuited. This is still a handful of linear passes over the elements at project-save time, so it's negligible. Confidence: high that it's true, low that it matters.

Quality

  • No substantive issues. The new tests read well, and the docs changes match the code.

AGENTS.md

  • None found. I checked:
    • No unwrap, expect or panic in non-test code.
    • Errors propagate through ?, so nothing is silently dropped.
    • No command, parameter or help text changed, so the command-surface snapshot is unaffected.
    • Nothing added is desktop-only, so the wasm build is unaffected.
    • The docs no longer say layout files are "not covered".

Prior concerns

  • There are no earlier review threads on this PR, so none were left alone.

Change size

Compared with main (merge base 3119075 to PR head d3f91fa).

Files changed Added Modified Removed Renamed Size before Size after Total size change
7 0 7 0 0 1.22 MB 1.23 MB +5.2 KB
Path Before After Change
crates/engine/src/tests/layout_files.rs 3.1 KB 7.2 KB +4.1 KB
crates/ui-egui/src/lib.rs 549.7 KB 551.1 KB +1.4 KB
docs/maintaining.md 18.0 KB 17.6 KB -399 B
crates/engine/src/project.rs 149.6 KB 149.7 KB +41 B
crates/engine/src/cmd/layout.rs 372.7 KB 372.6 KB -30 B
crates/engine/src/project_capabilities.rs 106.9 KB 106.9 KB +21 B
docs/user-guide/workspace.md 54.5 KB 54.5 KB +8 B

@jgregoriorincon
jgregoriorincon marked this pull request as ready for review November 23, 2026 20:00
@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2805/
Web app https://preview.rustgis.app/pr-2805/app/
Commit d3f91fa

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security issues, or AGENTS.md violations in this PR. I did not post any inline comments. There were no earlier review threads, so no concerns were skipped.

Bugs

None found. Confidence: high. Checked:

  • layout_file_bytes writes {format, requires, ...layout} through Item, which flattens the payload, so the file still reads back with Layout.
  • layout.import runs check_format on both text and path reads, so the new header is enforced on the read side.
  • report.rs reads layout text through layout::import, so it gets the same header check.
  • The refactored required_capabilities keeps the same capability names and order, and the fixture-based tests assert that order.
  • to_vec_pretty produces the same bytes as the old to_string_pretty, so the layout file changes only by its header.
  • The grid crs is an EPSG-style code string, so the "no crs-wkt" claim in the doc comment holds.

Security

None found. Confidence: high.

Performance

None found. Confidence: high. layout_capabilities now runs all nine element scans on each project requires check, where the old code could short-circuit. The element counts are small, so the cost is negligible.

Quality

None worth an inline comment. Two notes for the maintainers:

AGENTS.md

None found. Confidence: high. The PR updates the docs that said layout files were not covered, covers the browser and desktop paths through one function, and adds tests in both directions (headed and unheaded, one layout and several). It needs no schema regeneration, since layout files are not project saves and no layout-file schema exists.

Change size

Compared: the whole PR against main (merge base 3119075 to PR head d3f91fa).

Measure Value
Files changed 7 (0 added, 7 modified, 0 removed, 0 renamed)
Size before 1.2 MB
Size after 1.2 MB
Total size change +5.2 KB
Path Before After Change
crates/engine/src/tests/layout_files.rs 3.1 KB 7.3 KB +4.1 KB
crates/ui-egui/src/lib.rs 549.7 KB 551.1 KB +1.4 KB
docs/maintaining.md 17.9 KB 17.6 KB -399 B
crates/engine/src/project.rs 149.6 KB 149.7 KB +41 B
crates/engine/src/cmd/layout.rs 372.7 KB 372.6 KB -30 B
crates/engine/src/project_capabilities.rs 106.9 KB 106.9 KB +21 B
docs/user-guide/workspace.md 54.5 KB 54.5 KB +8 B

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Nov 23, 2026
Merged via the queue into opengeos:main with commit 691e265 Nov 23, 2026
28 checks passed
@jgregoriorincon
jgregoriorincon deleted the feat/2277-layout-file-header branch November 23, 2026 20:28
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.

[Feature]: Layout files (.rgislayout): a checked format header, so an older RustGIS refuses what it can't keep

1 participant