Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
- run: cargo +${{ matrix.rust }} test --locked
- run: cargo +${{ matrix.rust }} run --locked --example retry_command
- run: cargo +${{ matrix.rust }} run --locked --example context_walkthrough
- run: cargo +${{ matrix.rust }} run --locked --example nested_cancel
- run: cargo +${{ matrix.rust }} run --locked --example canonical_save
- run: python3 tools/context_evidence.py --check
- run: cargo +${{ matrix.rust }} fmt --check
- run: cargo +${{ matrix.rust }} clippy --locked --all-targets -- -D warnings
Expand All @@ -23,3 +25,15 @@ jobs:
run: |
crate_version=$(python3 -c "import tomllib; print(tomllib.load(open('Cargo.toml', 'rb'))['package']['version'])")
cargo +${{ matrix.rust }} test --locked --manifest-path "target/package/edit-session-$crate_version/Cargo.toml"
toolkit-boundaries:
name: Published toolkit boundary recipes
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- run: rustup toolchain install 1.99.1 --profile minimal --component rustfmt,clippy
- name: Install the Slint recipe font dependency
run: sudo apt-get update && sudo apt-get install -y libfontconfig1-dev
- run: cargo +1.99.1 test --locked --manifest-path examples/toolkit-boundaries/Cargo.toml --all-features --jobs 2
- run: cargo +1.99.1 fmt --manifest-path examples/toolkit-boundaries/Cargo.toml --check
- run: cargo +1.99.1 clippy --locked --manifest-path examples/toolkit-boundaries/Cargo.toml --all-features --all-targets -- -D warnings
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ test = true
name = "helper_comparison"
test = true

[[example]]
name = "nested_cancel"
test = true

[[example]]
name = "canonical_save"
test = true

[[example]]
name = "request_generation"
test = true

[lints.rust]
unsafe_code = "forbid"

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ library: `no_std`, zero runtime dependencies, Rust 1.88+.

**[First example](#same-value-different-edit)** · **[Try recovery](#retry-after-a-rejected-command)** · **[Install](#use-from-another-project)** · **[Evidence](#evidence-and-trade-offs)** · **[License](#license)**

[Toolkit boundary recipes](examples/toolkit-boundaries/README.md) exercise the published crate with eight Rust UI ecosystems: local drafts, stale callbacks, recycled IDs and effect previews. Each recipe states what its native tests do and do not cover.

## Same value, different edit

![An executable example: an old draft starts at revision 42. Another edit changes the value from 100 to 120; Undo restores 100 at revision 44. The old draft remains stale, including after Reset.](docs/assets/context-walkthrough.svg)
Expand Down Expand Up @@ -84,6 +86,10 @@ with your revision and a short sequence of calls, or read the [1.x compatibility

## Retry after a rejected command

[Two more host boundaries](docs/DRAFT_BOUNDARIES.md) cover Cancel inside a parent
form and reloading the canonical value after a successful save. They include a
local-helper comparison and ten model tests; they do not claim upstream adoption.

[Run the recovery example](docs/RECOVERY.md): it keeps the draft and raw fields open
when a host command is denied, checks freshness again on retry, and closes only after
success or a checked no-op. **Eight example tests pass** alongside the 16 lifecycle
Expand Down Expand Up @@ -322,3 +328,7 @@ Licensed under either the [MIT license](LICENSE-MIT) or the
[Apache License, Version 2.0](LICENSE-APACHE), at your option.
Unless explicitly stated otherwise, contributions submitted for inclusion are offered
under the same dual license.

[Request generation and draft context](docs/request-generation.md) separates late
background results from stale document commits. It includes eight model tests
and explains when a local ticket guard is sufficient without this dependency.
71 changes: 71 additions & 0 deletions docs/DRAFT_BOUNDARIES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Nested Cancel and canonical saves

Two runnable host models exercise existing `edit-session` APIs. They are not GUI
tests of the applications below, accepted integrations, or evidence that a new
dependency is better than a small local helper. No library API was added.

## Cancel the confirmation, keep the parent form

[COSMIC Settings #1718](https://github.com/pop-os/cosmic-settings/issues/1718)
reports losing a new shortcut's name and command when cancelling a replacement
confirmation. At [the inspected source](https://github.com/pop-os/cosmic-settings/blob/6aaf30d69ec3ed64eeb1d441ef5fe0a2017b3fe6/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs),
`ReplaceCancel` resets the parent `add_shortcut` state.

```sh
cargo run --locked --example nested_cancel
cargo test --locked --example nested_cancel
```

The [example](../examples/nested_cancel.rs) separates three decisions:

1. Cancel replacement: retain name and command, clear the disputed combination,
and leave the parent draft open for another combination.
2. Cancel the whole form: discard the draft without a host write.
3. Confirm: check the current value and configuration revision immediately before
the serialized host command. A stale draft stays open and does not overwrite.

Tests exercise both `EditSession` and a correct local helper against the same host.
Both must behave identically. The library does not decide which dialog was
cancelled: application state still owns that distinction. The separate reported
Reassign problem is not claimed fixed by this model. For a new-target workflow,
the host must additionally own target allocation and binding-conflict resolution;
this example models one fixed settings target.

## Display what the host actually saved

[spotatui #1063](https://github.com/LargeModGames/spotatui/issues/1063) describes
visible settings that differ from the accepted configuration after clamping or
rejection. [PR #1092](https://github.com/LargeModGames/spotatui/pull/1092) already
addresses the application; this example is not a competing patch.

```sh
cargo run --locked --example canonical_save
cargo run --locked --example canonical_save -- --interactive
cargo test --locked --example canonical_save
```

In the terminal form, enter `edit`, then `set 90 +`. The saved fields still show
`10` and `>`. Enter `cancel` to discard that draft. Open it again with `edit`,
enter `set 500 +`, then `save`. The host clamps the increment to 100. The saved
fields and the next draft both show `100` and `+`. Enter `quit` from the saved view.

The [example](../examples/canonical_save.rs) keeps raw fields until the host accepts
the write. On success it reloads the canonical value: entering `500` produces a
saved and displayed `100`. A rejected icon or failed write keeps the draft and
the previous saved snapshot. A retry checks freshness again. A successful save
starts an explicitly new session against the new revision; Reset is not used to
silently rebase a stale proposal.

The host model only accepts one printable ASCII icon and simulates an atomic
write. It does not implement terminal character width or a filesystem transaction.
A real host must handle partial storage failures, permissions and rollback itself.
Using `finish` before a fallible command would consume the draft too early here;
the example borrows `preview` after `check` and rebuilds only after success.

## Acceptance and cost

The two examples add ten tests, separate from existing lifecycle/consumer tests.
These are model-level regressions, not a reproduction of either application UI.
Keep the native application regression even if adopting the crate. First try a
local helper; sharing a lifecycle across several forms may justify the dependency,
but less code or faster execution has not been measured here.
37 changes: 37 additions & 0 deletions docs/request-generation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Request generation and draft context

A background job has two independent questions:

1. Does this result belong to the request still shown by the UI?
2. Is the document still the one on which the draft was based?

[`request_generation.rs`](../examples/request_generation.rs) uses a host-owned
monotonic ticket for the first question and `EditSession` context for the second.
Cancel closes the request. Starting another request gets a new ticket, even if
its path and initial value are identical. Both stale successes and stale errors
are discarded before they can change the replacement draft. A matching result
cannot authorize a later commit after a document switch or Undo.

```sh
cargo test --locked --example request_generation
cargo run --locked --example request_generation
cargo test --locked --example helper_comparison
```

Eight deterministic model tests cover cancellation, replacement, late success,
late failure, duplicate results, document/revision changes, no-op confirmation,
and counter exhaustion. No worker, filesystem, archive installer or application
GUI runs here. These tests are not evidence that a third-party application bug
has been fixed.

The essential request filter can be a small local enum and counter. Edit-session
does not manage worker cancellation, route result messages, close host
transactions, refresh a painter's render cache, or roll back external effects.
Use the existing host command/history engine for those jobs. If stale worker
results are the only problem, a new dependency is unnecessary.

For a draft that also needs validation, preview and context checks, the library
can provide that separate lifecycle. [`helper_comparison.rs`](../examples/helper_comparison.rs)
checks the same commit/Cancel behavior with a local helper and with edit-session.
[`retry_command.rs`](../examples/retry_command.rs) shows how to retain a draft
when the host rejects a command. No performance or code-size advantage is claimed.
Loading