Skip to content

fix(chisel): clean up stale session cache file on rename#15797

Open
Osraka wants to merge 6 commits into
foundry-rs:masterfrom
Osraka:fix/chisel-clean-stale-session-cache
Open

fix(chisel): clean up stale session cache file on rename#15797
Osraka wants to merge 6 commits into
foundry-rs:masterfrom
Osraka:fix/chisel-clean-stale-session-cache

Conversation

@Osraka

@Osraka Osraka commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closes #15796

What

When a saved Chisel session is saved again under a different ID, the new cache file is written but the old chisel-<id>.json file remains. This makes !list show a stale session and allows the old ID to be loaded.

This change removes the previous cache file after the renamed session is successfully written. Re-saving with the same ID is unchanged, and a missing old file is treated as a no-op.

Tests

  • Added a REPL regression test covering !save with two IDs, !list, !load <old-id>, and !load latest.
  • cargo test -p chisel --test it -- save_renamed_session_removes_stale_cache -- --exact
  • cargo test -p chisel
  • cargo fmt --all --check
  • git diff --check

The full package test was also run with network access for the Solc/Foundry fixtures.

@mablr mablr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rename behavior makes sense and the normal write-before-delete flow is correct, but the case-insensitive path collision and use of the real user cache in the regression test should be fixed before merge. Also, the documented focused command needs the module-qualified test name: repl::save_renamed_session_removes_stale_cache; as written, it runs 0 tests.

Comment thread crates/chisel/src/dispatcher.rs
Comment thread crates/chisel/tests/it/repl/mod.rs Outdated
Comment thread crates/chisel/tests/it/repl/mod.rs Outdated
@Osraka

Osraka commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in commit fd16fa0.

  • Compare the canonical old and newly written cache paths before removing the old ID, preserving the destination for case-only renames on case-insensitive filesystems.
  • Use collision-resistant cache IDs with Drop cleanup in the REPL regression tests.
  • Assert the new cache filename from !list via sendln_raw and load the new ID explicitly.

Validation:

  • cargo test -p chisel --lib (11 passed)
  • cargo fmt --all -- --check
  • git diff --check

The focused REPL integration test currently times out before the prompt in this macOS environment, before the rename scenario runs; the library suite and production binary compilation pass.

Comment thread crates/chisel/src/dispatcher.rs Outdated
@Osraka

Osraka commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up for the CI failure: the clippy job reported clippy::redundant-clone at crates/chisel/src/dispatcher.rs:295.

Fixed in commit 0fca37f by moving previous_id into the diverging write-error branch instead of cloning it. The maintainer merge commit was preserved before pushing this fix.

Validation:

  • cargo test -p chisel --test it repl::save_ -- --nocapture: 2 passed
  • cargo test -p chisel --test it repl::failed_save_restores_previous_session_id -- --exact --nocapture: 1 passed
  • cargo test -p chisel --lib: 11 passed
  • cargo fmt --all -- --check
  • git diff --check

The local toolchains do not have the clippy component installed, so the repository CI is the clippy verification for this one-line lint fix.

Comment thread crates/chisel/tests/it/repl/mod.rs Outdated

repl.sendln(&format!("!save {first_id}"));
// The nested path makes the write fail without touching the existing cache file.
repl.sendln_raw("!save invalid/id");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This failure fixture still depends on state in the real user cache: if ~/.foundry/cache/chisel/chisel-invalid/ already exists, this save succeeds instead of exercising rollback. Please build the missing parent from unique_cache_id (for example, <unique-id>/id) and assert the save error before consuming the prompt.

repl.sendln(&format!("!save {new_id}"));

// On case-insensitive filesystems, both IDs resolve to the same cache path.
repl.sendln_raw(&format!("!load {new_id}"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On a case-sensitive filesystem this only proves that the destination survives; it does not prove that the old lowercase cache was removed. An implementation that skips every case-only cleanup would pass while leaving both files. Please detect whether the two paths alias and, when they are distinct, also assert that loading old_id fails.

@Osraka

Osraka commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Addressed both follow-ups in d2aa655.

  • The failed-save fixture now uses a per-test missing parent (<unique-id>/id) and asserts the write error before consuming the prompt.
  • The case-only rename test now detects whether the two cache paths alias; when they are distinct, it also verifies that loading old_id fails.

Validation:

  • cargo test -p chisel --test it repl::save_case_only_rename_preserves_destination
  • cargo test -p chisel --test it repl::save_renamed_session_removes_stale_cache
  • cargo test -p chisel --test it repl::failed_save_restores_previous_session_id
  • cargo test -p chisel --lib
  • cargo +nightly fmt -p chisel --check
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

fix(chisel): remove stale cache file when renaming a session

3 participants