Skip to content

Rework the Input files tab: detect simulators, choose files to run, fix downloads - #2490

Open
martastn wants to merge 30 commits into
masterfrom
2479-rework-the-input-files-tab-detect-simulators-choose-files-to-run-fix-downloads
Open

martastn wants to merge 30 commits into
masterfrom
2479-rework-the-input-files-tab-detect-simulators-choose-files-to-run-fix-downloads

Conversation

@martastn

@martastn martastn commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2479

Changes:

  • One shared state for input files and the run selection. InputFilesContextProvider holds the files, the selection, the simulator to run and where the files came from. The Input files tab and the run form are two views of it, so a checkbox in the tab and a chip in the run form always agree. All updates are based on the latest state, so files added while a dialog is open or a conversion is running are not lost.

  • The converter decides which simulator can run. detect_simulators and REQUIRED_INPUT_FILES from the converter run in Pyodide. Only file names are sent to the converter. The UI keeps no copy of the rules. A simulator can run when all its required files are present and selected:

    • SHIELD-HIT12A: beam.dat, geo.dat, mat.dat, detect.dat
    • FLUKA: fl_sim.inp
    • Geant4: geometry.gdml, run.mac

    Any other file is allowed with any simulator and never blocks a run. File content is not checked.

    If the converter can't check the files (e.g. an outdated cached wheel), the tab and the run form show "Couldn't check the input files. Reload the page…" instead of "Checking files…" forever.

  • Input files tab

    • Starts empty. Files come from Generate from editor, Upload files or Create empty files.
    • Each file shows the simulator that requires it, an Include in run checkbox, and download, clear and delete buttons.
    • Overwriting a file, and clearing or deleting a non-empty one, asks first and offers to download the current content (one file as is, several as a zip). Dialogs are asked one at a time.
    • Upload files unpacks .zip files, so Download all can be uploaded back. Binary files are skipped with a message. The same file can be picked again after deleting it.
    • Names that look like a misnamed required file get a Rename to … button: a downloaded copy (fl_sim (1).inp), other letter case (BEAM.DAT) or an extra .txt extension (fl_sim.inp.txt).
    • After an upload or a rename, the simulator switches when the added files fit only one simulator. Other added files (e.g. notes.txt) keep the simulator chosen by hand. Files added before Pyodide is ready switch it once the converter has loaded.
    • Run with these input files is removed.
  • Run form (source Input Files Data)

    • Shows file chips. Clicking a chip includes or excludes the file.

    • Simulators that can't run are greyed out, with the reason ("Missing fl_sim.inp"), also for screen readers.

    • Select required files selects the required files of the chosen simulator.

    • Start simulation stays disabled, with the reason shown, until the run can start. The file selection stays visible with Use batch config.

    • Number of primary particles is disabled for input files, because the number is read from the files.

    • Geant4 always runs in direct mode, even if Batch Run was chosen before switching to it.

    • The source follows where the files came from. After another project is loaded or the editor is cleared, the form switches to Editor Project Data. Choosing the older files shows "These input files were added before the current project was loaded."

    • The default simulation name follows the source:

      • Editor Project Data: the project title;
      • Input Files Data: the title of the project the files were generated from, the title of the past simulation for Use these input files, or "Input files" for uploaded and empty files.

      A typed name is kept, also when switching tabs.

  • Downloads

    • Download opens "Save as" with the exact name where the browser supports it, and falls back to a normal download otherwise.
    • Download all downloads one zip (fflate). The zip is named after the project or past simulation, the simulator and a timestamp; the files inside keep their exact names.
  • Fixes outside the tab

    • Input file names from the server are no longer converted to camelCase (fl_sim.inp came back as flSim.inp), so Use these input files works for FLUKA.
    • Reset Camera has its own signal instead of editorCleared, which now means only that the project was cleared.
    • @testing-library/react is added back as a dev dependency (removed in remove unused @testing-library/react dependency #2514 as unused): the new InputFilesContextProvider test uses it.

Known limitation: for runs from input files the backend still guesses the simulator from file names instead of sim_type, so a FLUKA run with beam.dat or a second .inp file among the selected files is run incorrectly. This needs a backend fix.

Tests:

  • npx tsc --noEmit, npm run build
  • CI=true npm test (the converter E2E tests need npm start running)
  • New unit tests:
    • InputFilesContextProvider.test.tsx: simulator switching, detection errors, files from another project, files title, lost-content dialogs;
    • readInputFiles.test.ts: zip upload, binary files;
    • saveInputFiles.test.ts: zip names;
    • Notation.test.ts: file names in input_files.
  • Manual check:
    • SHIELD-HIT12A, FLUKA and Geant4 files, mixed sets, a downloaded copy and empty files;
    • upload before Pyodide is ready, a zip round trip, loading another project after Generate;
    • Reset Camera, Use batch config, Use these input files from a past FLUKA simulation.

@martastn martastn linked an issue Nov 4, 2026 that may be closed by this pull request
10 tasks
@martastn martastn self-assigned this Nov 4, 2026
@martastn
martastn marked this pull request as ready for review November 16, 2026 18:27
…ut-files-tab-detect-simulators-choose-files-to-run-fix-downloads

# Conflicts:
#	package-lock.json
#	package.json
#	src/WrapperApp/components/Simulation/RunSimulationForm.tsx
…ut-files-tab-detect-simulators-choose-files-to-run-fix-downloads
…ut-files-tab-detect-simulators-choose-files-to-run-fix-downloads
@grzanka

grzanka commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Review

Given the size, I focused on the shared state, the detection bridge, file reading and writing, the camelCase fix, and the submit path. I only skimmed the UI.

Looks correct

  • The converter dependency is satisfied. The submodule is bumped to converter 47dfd98, which is merged in Add simulator detection for input files converter#272. converter.api exports both detect_simulators and REQUIRED_INPUT_FILES. The keys there (shieldhit/fluka/geant4) match the SimulatorType values.
  • Only file names are sent for detection, with empty contents. The result is ignored if the file list changed while detection was running (the names key plus the current flag). The Pyodide objects are released with toJsAndDestroy.
  • The context provider handles out-of-date state well. It reads the latest values through refs, applies updates based on the current state, and queues the confirm dialogs one at a time. Files added while a dialog is open aren't lost.
  • The camelCase fix is limited to input_files. I checked the other direction too: the upload sends input_files outside the snake_case conversion, so file names go to the server unchanged.
  • The viewportsReset signal is a good cleanup. editorCleared now only means the project was cleared, which the new "files from another project" logic depends on.
  • The tests are good. The context provider, zip reading, zip names and Notation all have new tests, and @testing-library/react is added back on purpose.

Issues / suggestions

  1. The known backend limitation can be guarded against in the UI. The PR says the backend still guesses the simulator from file names, so a FLUKA run with a selected beam.dat runs incorrectly. The UI already knows which simulator requires each file (detection.files[name].simulator). Until the backend uses sim_type, the form could block the run, or show a warning, when the selection includes required files of another simulator. Otherwise this fails silently on the server. A backend issue should be linked from the PR.

  2. The detection error never goes away. detectionError is set when a check fails and never cleared, and InputEditorPanel shows it whenever it's set. After one temporary failure, the tab keeps showing "Couldn't check the input files…" even after later checks succeed. Clear it when a check succeeds.

  3. Files can be lost or changed during zip upload without a warning:

    • Entries are stored by base name, so a/beam.dat and b/beam.dat in one zip overwrite each other. They should be reported, like binary files are.
    • strFromU8 decodes as UTF-8, so a non-UTF-8 text file (e.g. Latin-1 comments in old SHIELD-HIT inputs) gets its accented characters replaced with � without any message.

    Both are rare, but a warning in the same message as the skipped binary files would be cheap.

  4. saveInputFile downloads the file anyway if saving fails. If showSaveFilePicker succeeds but createWritable/write fails (e.g. permission denied), the fallback starts a normal download after the user already picked a location. A short error message would be better than a surprise second download.

  5. The PR is too large to review well. About 2.3k lines in 24 commits. The independent fixes could be separate small PRs that merge first:

    • the Notation input_files fix
    • the viewportsReset signal
    • saveInputFiles / Download all

    That would leave this PR as the tab and run-form rework only. Otherwise, a squash merge with a clear message is a must.

  6. RunSimulationForm.tsx grew to about 700 lines (+522/−353). The file-chip selection block and the reason the run is blocked (unavailableReason / checkSelection) could move into their own component and hook. That would make the form easier to test.

Minor

  • handleRunSimulationClick still changes editorJson.beam.numberOfParticles directly. This was already the case before the PR, but the code was touched, so it could make a copy instead.
  • fromConverterDetection / requiredInputFiles assume the converter's output has the right shape without checking. That's acceptable since the submodule is pinned, but a basic shape check would make the "outdated cached wheel" case fail with a clear error.

Verdict: It's a solid, well-tested rework, and the design (one shared state, the converter owns the rules) is right. I'd want points 1 and 2 fixed before merging. Points 3–4 are small improvements, and 5–6 are about making the PR easier to review.

🤖 Generated with Claude Code

@martastn

Copy link
Copy Markdown
Contributor Author

Fixed:
2. The error now belongs to the file list that failed, so it disappears once a later check succeeds.
3. The upload warning now also lists files with the same name (only the last one is kept) and files that are not UTF-8 (characters replaced with �).
4. If a location was picked but writing fails, an error is shown and the file is not downloaded again. If the picker itself is not available, the file is still downloaded.
Minor: the primaries count now goes into a copy of the editor JSON.

@martastn
martastn force-pushed the 2479-rework-the-input-files-tab-detect-simulators-choose-files-to-run-fix-downloads branch from f277cd1 to 7cfdf4e Compare November 19, 2026 21:25
…ut-files-tab-detect-simulators-choose-files-to-run-fix-downloads
…ut-files-tab-detect-simulators-choose-files-to-run-fix-downloads

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.

Rework the Input files tab: detect simulators, choose files to run, fix downloads

2 participants