Skip to content

feat(script): load a script file into the Script pane (#2397) - #2401

Draft
jgregoriorincon wants to merge 1 commit into
opengeos:mainfrom
jgregoriorincon:feat/script-load
Draft

jgregoriorincon wants to merge 1 commit into
opengeos:mainfrom
jgregoriorincon:feat/script-load

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Script pane gets a Load… button beside Commands…, so a script kept on disk no longer has to be pasted in by hand.

  • On the desktop it opens the system file picker (Script *.txt, All files). In the browser and on Android/iOS it asks the shell's picker through a new "script" purpose, whose file comes back marked with SCRIPT_PICK, the same way shortcut files are routed.
  • Loading replaces the pane's script and empties its results, run count and Details window, as Clear and the Session log's Open in Script Pane do (both go through open_script), so Ctrl+Z (⌘+Z) brings the previous script back.
  • Refused with a notice, leaving the script unchanged: a file that isn't UTF-8 text, a file over 1 MB (the assistant's command-file limit; the desktop reads at most 1 MB + 1 byte), and a pick that lands while a run is under way. The button is disabled during a run, with the same hover text as Clear.
  • A browser/phone pick reaches open_picked, which has no egui::Context, so the text waits in Workflow.script_picked and RustGisApp::logic opens it right after reading the inbox, in the same frame.

Surfaces: desktop, browser and phone. The CLI, Python and the assistant are not affected: Load… is a pane-local action, like Clear, not a command.

Testing

  • New tests: analysispane::tests::load_reads_a_script_file_in_place_of_the_panes (desktop picker: cancel, non-UTF-8 file, valid file, Ctrl+Z restores the old script, disabled during a run) and analysispane::tests::a_script_from_the_shells_picker_opens_in_the_pane (shell picker: "script" purpose, cancel, non-UTF-8, over 1 MB, valid file, refused during a run). The mobile mark("script") mapping is covered in a_dxf_request_keeps_its_id_in_its_mark.
  • cargo fmt --all --check, cargo clippy -p rustgis-ui-egui -p rustgis-mobile -p rustgis-web --all-targets -- -D warnings, cargo nextest run on the workspace (7692 passed, 26 skipped), doctests and cargo xtask layers: all pass.
  • cargo check -p rustgis-web --target wasm32-unknown-unknown: passes.
  • Manual on the desktop: Load… with a valid file, a Latin-1 file and a cancelled picker, then Ctrl+Z restores the previous script.

UI evidence

Before / after: the Script pane's buttons.

2397-before 2397-after

Related issue

Closes #2397

@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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 script file the shell's picker read for Load…, kept for [`RustGisApp::logic`] to open once
/// the inbox is read. A file that isn't UTF-8 text, or one landing while a run is under
/// way, is refused and said, and the pane's script stays.
pub(crate) fn script_picked(app: &mut RustGisApp, bytes: &[u8]) -> Result<Value, String> {

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.

Performance / size limit (medium confidence). In the browser, the 1 MB check runs only after the whole picked file has been read into memory. read_together in apps/rustgis-web/src/web.rs (around line 489) reads each file with parts::read_file before this function sees it, and only the shortcut purpose is refused on file.size() before that read. A multi-hundred-MB file picked for Load… is therefore fully read into wasm memory and then refused.

Suggested fix: in read_together, extend the pre-read size check from shortcut to the script purpose (for example let script = mark == rustgis_ui_egui::SCRIPT_PICK; and if (shortcut || script) && file.size() > …), with the same notice pattern. Give the script limit its own notice, or refuse with the script message, so the user is told why. The new a_script_from_the_shells_picker_opens_in_the_pane test calls open_picked directly, so it never exercises this path. A test that covers the size refusal before the read would be useful.

if bytes.len() > SCRIPT_FILE_MAX_BYTES {
return Err(tl!("The script file is larger than 1 MB").to_string());
}
std::str::from_utf8(bytes).map(str::to_owned).map_err(|_| tl!("The file isn't UTF-8 text").to_string())

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.

Bug (medium-high confidence): a UTF-8 byte-order mark makes the first line fail. Windows Notepad and some other editors write .txt files with a UTF-8 BOM (EF BB BF). That BOM decodes to U+FEFF, which is not Unicode White_Space, so str::trim() in script_line (crates/engine/src/parameters.rs:26) doesn't remove it. The first command then becomes \u{feff}map.zoomFull, and the run fails on line 1 with an unknown-command error. The file is refused as a valid script even though it is UTF-8. The other text readers in crates/data/src/io.rs already strip a leading BOM.

Suggested fix: strip the BOM before the UTF-8 check. The replacement below is for this line only:

Suggested change
std::str::from_utf8(bytes).map(str::to_owned).map_err(|_| tl!("The file isn't UTF-8 text").to_string())
let bytes = bytes.strip_prefix(b"\xEF\xBB\xBF").unwrap_or(bytes);
std::str::from_utf8(bytes).map(str::to_owned).map_err(|_| tl!("The file isn't UTF-8 text").to_string())

Please add a test for it: a BOM-prefixed file should load and run, with no notice. The same file without the BOM should give the same script.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • A UTF-8 byte-order mark makes the first command fail. Notepad-style files start with U+FEFF, which str::trim() does not remove, so line 1 becomes an unknown command. Refused with an error rather than silently, but a valid file can't be loaded. Inline comment posted at crates/ui-egui/src/analysispane.rs:1899 with a suggested fix. Confidence: medium-high.

Security

  • None found.

Performance

  • In the browser, a picked file is read in full before the 1 MB check. The shortcut path refuses on file.size() first, and the script path doesn't. Inline comment posted at crates/ui-egui/src/analysispane.rs:1881. Confidence: medium.

Quality (grouped nits; left for the release quality pass)

  • The UTF-8 and size refusal notices don't name the file, so the user can't tell which file was refused.
  • SCRIPT_FILE_MAX_BYTES is a separate constant, though its doc says it mirrors the assistant's command-file limit. Reuse that constant if one exists.
  • open_script refuses silently if a run started between the pick and the frame that opens it. Unlikely, but a notice would match the other refusals.
  • The new desktop test removes its temp directory only on success.
  • The analysis.md paragraph is awkwardly hard-wrapped around "It is off while a run is / under way too."

AGENTS.md

  • No violations found. Notices are routed through Session::notify, the browser and phone wiring follows the SHORTCUT_PICK pattern, and the UI-only action is correctly kept out of the command registry.
  • Test gaps: no test covers a BOM, and none covers the browser's size refusal before the read.

Prior review threads: none on this PR, so no earlier concerns were left alone.

Change size

Compared with the base branch: the whole PR against main (merge base 7e9718e to PR head 9ad95ac).

Measure Value
Files changed 5 (added 0, modified 5, removed 0, renamed 0)
Size before 871.7 KB
Size after 881.6 KB
Total size change +9.9 KB
Path Before After Change
crates/ui-egui/src/analysispane.rs 137.2 KB 145.7 KB +8.5 KB
crates/ui-egui/src/lib.rs 483.3 KB 484.0 KB +711 B
docs/user-guide/analysis.md 165.1 KB 165.5 KB +376 B
apps/rustgis-web/src/web.rs 71.9 KB 72.1 KB +208 B
apps/rustgis-mobile/src/lib.rs 14.3 KB 14.4 KB +123 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2401/
Web app https://preview.rustgis.app/pr-2401/app/
Commit 9ad95ac

GitHub Pages takes a minute or two to publish a new commit.

This branch has not been deployed

No deployments
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]: Load a script file into the Script pane

1 participant