From e40ee997a8ba595d23558b018231d71ac14c2345 Mon Sep 17 00:00:00 2001 From: Valentin Millet <34792012+vmillet-dev@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:33:32 +0100 Subject: [PATCH] E2E: a journey checks nothing written is readable on the disk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Journey 14 writes every sealed kind, quits and reads the whole profile; an opened attachment's plain copy goes at the exit and before the gate after a crash. Journey 12 ends by reading what it set aside. In the e2e flavour, « open with » starts no program. --- .claude/skills/desktop-e2e-testing/SKILL.md | 4 +- CLAUDE.md | 2 +- crates/app/src/desktop.rs | 14 +- crates/platform/src/desktop.rs | 17 ++ docs/architecture.md | 35 +++-- e2e/src/driver.rs | 6 + e2e/src/sdk/attachments.rs | 5 + e2e/src/sdk/disk.rs | 67 ++++++++ e2e/src/sdk/mod.rs | 22 +++ e2e/tests/12_looking_after_the_library.rs | 10 +- e2e/tests/14_nothing_readable_on_the_disk.rs | 154 +++++++++++++++++++ 11 files changed, 315 insertions(+), 21 deletions(-) create mode 100644 e2e/src/sdk/disk.rs create mode 100644 e2e/tests/14_nothing_readable_on_the_disk.rs diff --git a/.claude/skills/desktop-e2e-testing/SKILL.md b/.claude/skills/desktop-e2e-testing/SKILL.md index 980c3f78e..6be984373 100644 --- a/.claude/skills/desktop-e2e-testing/SKILL.md +++ b/.claude/skills/desktop-e2e-testing/SKILL.md @@ -5,7 +5,7 @@ description: Use when writing, running or debugging an end-to-end journey of the # Desktop e2e -`CONTRIBUTING.md` → "The end-to-end journeys" says how to run, watch, mend and extend them; `docs/architecture.md` → "The journeys, on the assembled window" lists the thirteen and what the driver does. What is worth knowing before touching one: +`CONTRIBUTING.md` → "The end-to-end journeys" says how to run, watch, mend and extend them; `docs/architecture.md` → "The journeys, on the assembled window" lists the fourteen and what the driver does. What is worth knowing before touching one: - Build the flavour first, every time `crates/` changed: `cargo build -p app --features e2e --target-dir target/e2e` (its own target directory: no other build overwrites it). Then `cargo test -p e2e --test NN_name` for one journey, `cargo test -p e2e` for all — what CI runs on each OS. `cargo test --workspace` runs with `--exclude e2e`. - A journey is `e2e/tests/NN_name.rs`: one `#[test]` of named `step`s, what the person does then what they see. A nominal path goes into the journey it belongs to, as a step; a new file only for a new goal (15 at most). Branches, edge cases and error codes are unit tests'. @@ -13,7 +13,7 @@ description: Use when writing, running or debugging an end-to-end journey of the - Inside the SDK: `expect` (reads the tree until it holds), `click`, `fill`, `fill_nth` and `replace` (wait for the keyboard), `click_until` (a click the screen can lose), `place` (waits for a control to hold still), `reach` and `scroll_to`. Wait on what the act changes, not on what was already there: the last answer, a toast, a row of the same name. `std::thread::sleep` is refused by `e2e/clippy.toml`. - Controls are addressed by `author_id`, never by a translated text: the language is the machine's (CI runs in English). A journey that must read a word chooses its language first (`prefs().choose_language`). Missing an id? Give the widget one through `widgets::address` / `widgets::interact`. - The window is 1440 × 900 at most (`window().widen()`), 1280 wide under CI's Xvfb, 1024 × 768 on Windows after a full screen: call `widen()` again after a presentation, and click what is in view. -- What the protocol cannot reach goes through the flavour's doors: a global action is `--action ` from a second launch; a file dialog answers the path `files().answer` wrote; updates come from `App::open_before_an_update`'s server. A file dropped from the explorer is not injectable: go through *Attach*. +- What the protocol cannot reach goes through the flavour's doors: a global action is `--action ` from a second launch; a file dialog answers the path `files().answer` wrote; updates come from `App::open_before_an_update`'s server; « open with » starts no program, and `disk()` reads what was handed over. A file dropped from the explorer is not injectable: go through *Attach*. - A failure leaves `failure.png` and the application's log in `target/e2e/scenarios//`: read them before changing the step, and decide whether the application or the journey is wrong. CI uploads the same folder per platform. - Never point a journey at a real profile. The inspection port has no authentication; the flavour never becomes a release. - Lint: `cargo clippy --workspace --all-targets --all-features -- -D warnings`. diff --git a/CLAUDE.md b/CLAUDE.md index ba8ee6f11..a04db939c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -23,7 +23,7 @@ Principles: - Cargo workspace: `cargo check|build|test --workspace`, `cargo clippy --workspace --all-targets --all-features -- -D warnings` (⚠️ `--all-features` is what compiles the `e2e` flavour), `cargo fmt --all --check`, `cargo bench -p engine` (not in CI; `autobenches = false` is load-bearing; → "Benchmarks"). Every external dependency is declared once, in the root `[workspace.dependencies]`; a crate takes it with `dep.workspace = true` and adds only its own features (D33). Toolchain pinned in `rust-toolchain.toml`; `unsafe_code` forbidden in every crate (D7), `clippy::pedantic` denied. - No Node project at the root: the release scripts have no dependency. `node --test "scripts/*.test.mjs"` · `cargo run -p app --example icons` (writes `crates/app/icons/`; ⚠️ small `.ico` sizes come from `icons/source/`) · `node scripts/prettier.mjs` (copies the Prettier it pins into `crates/text/prettier/`, the formatter compiled in). Markdown, JSON and YAML have no formatter. The request-script libraries are bundled by `crates/engine/sandbox/build.mjs`, from that folder's own `package.json`. - Website (`website/`, Angular, devnotes.fr; its own `package.json`, outside the Cargo workspace): from `website/`, `npm ci` · `npm start` (port 4300) · `npm run build` (fetches the latest release, prerenders to `website/dist/`, checks every page and its download links) · `npm test` · `npm run lint` · `npm run test:scripts`. `website.yml` publishes it when `website/` or `docs/content/` changes on `main`, and after each release. → "The website". -- E2E: `cargo build -p app --features e2e --target-dir target/e2e`, then `cargo test -p e2e` (thirteen journeys in `e2e/tests/`, one after the other; `--test 01_first_day` for one; `cargo test --workspace --exclude e2e` otherwise). A journey is written on the SDK (`e2e/src/sdk/`) alone, with no `author_id`, coordinate or duration of its own (`CONTRIBUTING.md`). → "The journeys, on the assembled window". +- E2E: `cargo build -p app --features e2e --target-dir target/e2e`, then `cargo test -p e2e` (fourteen journeys in `e2e/tests/`, one after the other; `--test 01_first_day` for one; `cargo test --workspace --exclude e2e` otherwise). A journey is written on the SDK (`e2e/src/sdk/`) alone, with no `author_id`, coordinate or duration of its own (`CONTRIBUTING.md`). → "The journeys, on the assembled window". - Release is a `workflow_dispatch` after a version bump; the version is `[workspace.package] version` in `Cargo.toml` alone (D27), so a bump touches `Cargo.toml` and `Cargo.lock` (`cargo update --workspace`); `scripts/version.mjs` refuses a release where they disagree. `release.yml` runs `prepare` (checks, changelog written, nothing pushed) → `package` (`package.yml`: a job a system, one action a format under `.github/actions/package/`, signed and checked) → `finalize` (commit, tag, atomic push, release page): ⚠️ the irreversible last, so a failed release leaves nothing to undo. `packages.yml` calls `package.yml` on pull requests, then installs and updates. ⚠️ A version branch (`dev/x.y.z`) reaches `main` by a merge commit, never a squash: the release notes read what the merge brings. → "Releasing", `docs/releasing.md`. ## Things that will bite you diff --git a/crates/app/src/desktop.rs b/crates/app/src/desktop.rs index 6d06f0f4f..d9d31a401 100644 --- a/crates/app/src/desktop.rs +++ b/crates/app/src/desktop.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use engine::app_info::METADATA; use platform::autostart::Autostart; +use platform::desktop::Opener; use platform::dialog::FileDialog; use platform::shortcuts::Shortcuts; use platform::tray::{NoTray, Picture, Tray}; @@ -32,10 +33,21 @@ pub(crate) fn start(preferences: &Preferences, inbox: &Inbox) -> ui::Desktop { dialog: dialog(inbox.clone()), updater: updater(), clipboard: platform::clipboard::system(), - opener: platform::desktop::system(), + opener: opener(), } } +#[cfg(not(feature = "e2e"))] +fn opener() -> Arc { + platform::desktop::system() +} + +/// A scenario starts no program of the machine: what an attachment opens is read on the disk. +#[cfg(feature = "e2e")] +fn opener() -> Arc { + platform::desktop::from_scenario() +} + #[cfg(not(feature = "e2e"))] fn updater() -> Arc { platform::updater::system(&UPDATES) diff --git a/crates/platform/src/desktop.rs b/crates/platform/src/desktop.rs index 036baeff5..691bf4015 100644 --- a/crates/platform/src/desktop.rs +++ b/crates/platform/src/desktop.rs @@ -30,6 +30,23 @@ impl Opener for NoOpener { } } +/// The `e2e` flavour's: starts no program and says it did. A scenario reads on the disk what was +/// handed over; a program of the machine would outlive it. +#[cfg(feature = "e2e")] +pub struct Scenario; + +#[cfg(feature = "e2e")] +impl Opener for Scenario { + fn open(&self, _path: &Path) -> io::Result<()> { + Ok(()) + } +} + +#[cfg(feature = "e2e")] +pub fn from_scenario() -> Arc { + Arc::new(Scenario) +} + #[cfg(test)] mod tests { use super::*; diff --git a/docs/architecture.md b/docs/architecture.md index 9989abfbd..94ea849e8 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -6779,7 +6779,9 @@ event the close button sends (`ViewportCommand::Close` is pushed as the same `ViewportEvent::Close`), and `--action tray:`, what the tray's menu hands over; `platform::dialog::from_scenario`, a file dialog answering the path `DEVNOTES_E2E_DIALOG`'s file holds; `DEVNOTES_E2E_UPDATES`, where a new version is looked for -(`platform::updater::scenario`). Whether the window is out of sight is `window-shown` or +(`platform::updater::scenario`); `platform::desktop::from_scenario`, an « open with » that starts +no program, so an attachment opened leaves its plain copy for the journey to read under the +profile. Whether the window is out of sight is `window-shown` or `window-hidden` in the tree (`app::sight`), and `window-put-away` how many times it went, read from the commands the application sent: the same answer on every system, whatever its window manager does. ⚠️ macOS minimises a closed window, and a minimised window paints nothing: eframe @@ -6806,21 +6808,22 @@ process to end its queue drained, and starts it again on the same profile. The j go to a server of the suite's own (`server.rs`), never to the network. A failed journey leaves its last screen and the application's log in `target/e2e/scenarios//`, beside its captures. -| Journey | What is walked | -| ------------------------------ | -------------------------------------------------------------------------- | -| `01_first_day` | the first launch, the library made, the samples, the documentation | -| `02_snippet_to_paste` | a snippet written, found, filled and copied, a JSON explored | -| `03_keeping_a_note` | attachments, versions, the trash and undo, drafts over a relaunch | -| `04_other_kinds` | a Note, a todo list, a calculation and a drawing | -| `05_finding` | the search, the filters, the selection and the tags | -| `06_spaces_and_board` | spaces, folders and the board | -| `07_reaching_from_anywhere` | a second launch, the palette, the clipboard, the tray, the window put away | -| `08_tools` | the tools' home, the catalogue as one table, what is kept, the files | -| `09_calling_an_api` | collections, requests, answers, environments, code, the history | -| `10_scripts_and_runs` | scripts, tests, what stops a send, a collection run | -| `11_libraries_and_transfer` | several libraries, exports and imports | -| `12_looking_after_the_library` | the phrase, the copies, a damaged file, a forgotten phrase | -| `13_making_it_mine` | the preferences, the keys, the areas, the window, an update | +| Journey | What is walked | +| --------------------------------- | --------------------------------------------------------------------------- | +| `01_first_day` | the first launch, the library made, the samples, the documentation | +| `02_snippet_to_paste` | a snippet written, found, filled and copied, a JSON explored | +| `03_keeping_a_note` | attachments, versions, the trash and undo, drafts over a relaunch | +| `04_other_kinds` | a Note, a todo list, a calculation and a drawing | +| `05_finding` | the search, the filters, the selection and the tags | +| `06_spaces_and_board` | spaces, folders and the board | +| `07_reaching_from_anywhere` | a second launch, the palette, the clipboard, the tray, the window put away | +| `08_tools` | the tools' home, the catalogue as one table, what is kept, the files | +| `09_calling_an_api` | collections, requests, answers, environments, code, the history | +| `10_scripts_and_runs` | scripts, tests, what stops a send, a collection run | +| `11_libraries_and_transfer` | several libraries, exports and imports | +| `12_looking_after_the_library` | the phrase, the copies, a damaged file, a forgotten phrase | +| `13_making_it_mine` | the preferences, the keys, the areas, the window, an update | +| `14_nothing_readable_on_the_disk` | every sealed kind written, the profile read from outside, a plain copy gone | One file per journey, one `#[test]` of named steps (`e2e::step`): `cargo test -p e2e --test 01_first_day` runs one, `cargo test -p e2e` all of them, one file after diff --git a/e2e/src/driver.rs b/e2e/src/driver.rs index 57369dfa0..e1bb9cd33 100644 --- a/e2e/src/driver.rs +++ b/e2e/src/driver.rs @@ -229,6 +229,12 @@ impl Driver { assert!(ended.success(), "the application ended with {ended}"); } + /// Ends the process at once, as a crash does: nothing is written on the way out. + pub(crate) fn kill(&mut self) { + self.child.kill().expect("the application is killed"); + let _ = self.child.wait(); + } + /// A second launch on the same profile, asking for `action`: it hands it over and exits. pub(crate) fn hand_over(&self, action: Option<&str>) { let mut command = Command::new(binary()); diff --git a/e2e/src/sdk/attachments.rs b/e2e/src/sdk/attachments.rs index c9e6c324c..3e4602989 100644 --- a/e2e/src/sdk/attachments.rs +++ b/e2e/src/sdk/attachments.rs @@ -15,6 +15,11 @@ impl Attachments<'_> { self.0.click("attachment-add", "the button that attaches a file"); } + /// Opens a file as the desktop would, by its name: a plain copy is written under the profile. + pub fn open(&mut self, n: usize) { + self.0.click_nth("attachment-open", n, "the file's name"); + } + /// Pastes a picture in the note. pub fn paste_picture(&mut self) { let picture = Arc::new(ColorImage::filled([8, 8], Color32::RED)); diff --git a/e2e/src/sdk/disk.rs b/e2e/src/sdk/disk.rs new file mode 100644 index 000000000..863127b86 --- /dev/null +++ b/e2e/src/sdk/disk.rs @@ -0,0 +1,67 @@ +use std::io; +use std::path::{Path, PathBuf}; + +use super::App; +use crate::current_step; + +/// What DevNotes leaves on the disk: its profile, read from outside, as anyone holding the machine +/// would read it. +pub struct Disk<'a>(pub(super) &'a mut App); + +/// The library's database, which a scan that read nothing would never meet. +const DATABASE: &str = "devnotes.sqlite3"; + +impl Disk<'_> { + /// No file of the profile says any of these words, in what it holds or in its name. Read while + /// DevNotes is closed or at its gate, when every file can be read: one that cannot fails. + pub fn expect_nowhere(&mut self, words: &[&str], says: &str) { + let profile = self.0.profile().to_owned(); + let step = current_step(); + let files = files_under(&profile).unwrap_or_else(|error| panic!("« {step} »: {says} — {error}")); + let read_a_database = files.iter().any(|file| file.file_name().is_some_and(|name| name == DATABASE)); + assert!(read_a_database, "« {step} »: {says} — the profile holds no database to read"); + for file in &files { + let bytes = std::fs::read(file).unwrap_or_else(|error| { + panic!("« {step} »: {says} — {} cannot be read: {error}", file.display()) + }); + if let Some(word) = words.iter().find(|word| says_word(&profile, file, &bytes, word)) { + panic!("« {step} »: {says} — {} says « {word} »", file.display()); + } + } + } + + /// A file of the profile says this word, once DevNotes has written it. What SQLite holds while + /// DevNotes runs is not read. + pub fn expect_somewhere(&mut self, word: &str, says: &str) { + let profile = self.0.profile().to_owned(); + self.0.expect(says, |_| { + let files = files_under(&profile).unwrap_or_default(); + files + .iter() + .any(|file| std::fs::read(file).is_ok_and(|bytes| says_word(&profile, file, &bytes, word))) + }); + } +} + +/// Whether a file says a word, in its bytes or in its path under the profile. +fn says_word(profile: &Path, file: &Path, bytes: &[u8], word: &str) -> bool { + let name = file.strip_prefix(profile).unwrap_or(file).to_string_lossy(); + name.contains(word) || bytes.windows(word.len()).any(|window| window == word.as_bytes()) +} + +/// Every file under a folder, at any depth. +fn files_under(folder: &Path) -> io::Result> { + let mut files = Vec::new(); + let mut folders = vec![folder.to_owned()]; + while let Some(folder) = folders.pop() { + for entry in std::fs::read_dir(&folder)? { + let path = entry?.path(); + if path.is_dir() { + folders.push(path); + } else { + files.push(path); + } + } + } + Ok(files) +} diff --git a/e2e/src/sdk/mod.rs b/e2e/src/sdk/mod.rs index bf2f830f2..e5943cbfb 100644 --- a/e2e/src/sdk/mod.rs +++ b/e2e/src/sdk/mod.rs @@ -7,6 +7,7 @@ mod board; mod calc; mod clipboard; mod code; +mod disk; mod drawing; mod editor; mod environments; @@ -45,6 +46,7 @@ pub use board::{Board, Place}; pub use calc::Calc; pub use clipboard::Clipboard; pub use code::Code; +pub use disk::Disk; pub use drawing::{Drawing, Spot, Tool}; pub use editor::Editor; pub use egui::Key; @@ -378,6 +380,11 @@ impl App { Files(self) } + /// What DevNotes leaves on the disk, read from outside. + pub fn disk(&mut self) -> Disk<'_> { + Disk(self) + } + /// Presses a shortcut. pub fn press(&mut self, shortcut: Shortcut) { let (key, modifiers) = shortcut.keys(); @@ -436,6 +443,21 @@ impl App { self.gate().unlock(PASSPHRASE); } + /// Quits, reads the disk while DevNotes is closed, and starts it again: the gate asks. + pub fn while_closed(&mut self, read: impl FnOnce(&mut Disk<'_>)) { + self.driver.hand_over(Some("quit")); + self.driver.ended(); + read(&mut self.disk()); + self.start_again(); + } + + /// DevNotes ends without a word, as in a crash, and is started again: the gate asks. + pub fn crash_and_launch_again(&mut self) { + self.driver.kill(); + self.start_again(); + self.expect("the gate lists its libraries", |tree| tree.has("vault-library")); + } + /// Quits, has the library's database damaged while DevNotes is closed, and starts it again. pub fn relaunch_damaged(&mut self) { self.driver.hand_over(Some("quit")); diff --git a/e2e/tests/12_looking_after_the_library.rs b/e2e/tests/12_looking_after_the_library.rs index 8a90c8c95..3e2ec4e99 100644 --- a/e2e/tests/12_looking_after_the_library.rs +++ b/e2e/tests/12_looking_after_the_library.rs @@ -1,5 +1,6 @@ //! Journey 12, « Looking after the library »: its phrase changed, a copy put back, a damaged file -//! set aside and a forgotten phrase. It ends on a profile with no library. +//! set aside and a forgotten phrase, none of what it sets aside readable. It ends on a profile with +//! no library. use e2e::{App, PASSPHRASE, Sample, step}; @@ -89,5 +90,12 @@ fn looking_after_the_library() { app.gate().expect_place_told("archived", "the place of the old one is told"); }); + step("what was set aside reads nothing of what was written, nor either phrase", || { + app.while_closed(|disk| { + let written = [LATER, "echo later", PASSPHRASE, NEXT]; + disk.expect_nowhere(&written, "the libraries replaced, damaged and archived stay sealed"); + }); + }); + app.quit(); } diff --git a/e2e/tests/14_nothing_readable_on_the_disk.rs b/e2e/tests/14_nothing_readable_on_the_disk.rs new file mode 100644 index 000000000..b02f0e7ad --- /dev/null +++ b/e2e/tests/14_nothing_readable_on_the_disk.rs @@ -0,0 +1,154 @@ +//! Journey 14, « Nothing readable on the disk »: something of every kind DevNotes seals is written, +//! and the whole profile is read from outside, as anyone holding the machine would read it — the +//! database and its copies, the logs, the preferences. An attachment opened is the one plain copy, +//! and it goes with DevNotes, even after a crash. + +use e2e::{App, Area, Body, Method, PASSPHRASE, Shortcut, Spot, step}; + +// Each a word nothing else on the disk says: read there, it was written in the clear. +const SNIPPET: &str = "larkspur-snippet"; +const CODE: &str = "larkspur-code"; +const CONTEXT: &str = "larkspur-context"; +const FIELD: &str = "larkspur-field"; +const NOTE: &str = "larkspur-note"; +const TEXT: &str = "larkspur-text"; +const LIST: &str = "larkspur-list"; +const TASK: &str = "larkspur-task"; +const SHEET: &str = "larkspur-sheet"; +const RATE: &str = "larkspur_rate"; +const SKETCH: &str = "larkspur-sketch"; +const DRAWN: &str = "larkspur-drawn"; +const SPACE: &str = "larkspur-space"; +const FOLDER: &str = "larkspur-folder"; +const FILE: &str = "larkspur-file.txt"; +const BYTES: &str = "larkspur-bytes"; +const GLOBAL: &str = "larkspur-global"; +const SEARCHED: &str = "larkspur-searched"; +const COLLECTION: &str = "larkspur-collection"; +const REQUEST: &str = "larkspur-request"; +const ADDRESS: &str = "larkspur-address"; +const HEADER: &str = "larkspur-header"; +const BODY: &str = "larkspur-body"; +const SECRET: &str = "larkspur-secret"; +/// Plain by design, as SQL filters on it: read on the disk, it proves the scan reads the database. +const TAG: &str = "larkspur-tag"; + +const WRITTEN: [&str; 25] = [ + SNIPPET, CODE, CONTEXT, FIELD, NOTE, TEXT, LIST, TASK, SHEET, RATE, SKETCH, DRAWN, SPACE, FOLDER, FILE, + BYTES, GLOBAL, SEARCHED, COLLECTION, REQUEST, ADDRESS, HEADER, BODY, SECRET, PASSPHRASE, +]; +/// What an opened attachment's plain copy says. +const COPY: [&str; 2] = [FILE, BYTES]; + +#[test] +fn nothing_readable_on_the_disk() { + let mut app = App::open("14_nothing_readable_on_the_disk"); + let api = app.serve_api(); + app.window().widen(); + + everything_sealed(&mut app, &api); + an_attachment_opened(&mut app); + after_a_crash(&mut app); + + app.quit(); +} + +fn everything_sealed(app: &mut App, api: &str) { + step("a note of each kind is written, in a space and a folder of its own", || { + app.files().put(FILE, BYTES.as_bytes()); + app.rail().new_space(SPACE); + app.rail().new_folder(FOLDER); + app.rail().open_folder(FOLDER); + app.press(Shortcut::NewSnippet); + app.editor().type_title(SNIPPET); + app.editor().type_code(&format!("echo {CODE} {{{{host}}}}")); + app.editor().type_context(CONTEXT); + app.editor().add_tag(TAG); + app.editor().close(); + app.notes().write_note(NOTE, TEXT); + app.notes().write_todo_list(LIST, TASK); + app.press(Shortcut::NewCalculation); + app.editor().type_title(SHEET); + app.editor().type_code(&format!("{RATE} = 12\n{RATE} * 2")); + app.editor().close(); + app.press(Shortcut::NewDrawing); + app.editor().type_title(SKETCH); + app.drawing().write(DRAWN, Spot::Middle); + app.editor().close(); + app.notes().expect_cards(5, "the five notes are cards"); + }); + + step("a file is attached, a field filled, a global variable set and a word searched", || { + app.notes().open(SNIPPET); + app.attachments().add(FILE); + app.attachments().expect(1, "the file is attached"); + app.editor().close(); + app.notes().copy_filled(SNIPPET); + app.fields().type_value(0, FIELD); + app.fields().copy(); + app.clipboard() + .expect(&format!("echo {CODE} {FIELD}"), "the snippet is copied, filled"); + app.prefs().open(); + app.prefs().go_to(e2e::Page::Variables); + app.prefs().add_variable("region", GLOBAL); + app.prefs().close(); + app.notes().search(SEARCHED); + app.notes().expect_nothing_found("nothing answers the word"); + app.notes().clear_search(); + }); + + step("a request is sent with a header, a body and an environment's secret, and saved", || { + app.window().go_to(Area::Http); + app.environments().open(); + app.environments().create("Local"); + app.environments().add_secret("token", SECRET); + app.environments().leave(); + app.environments().choose("Local"); + app.http().new_collection(COLLECTION); + app.http().new_request(COLLECTION, REQUEST); + app.request().type_url(&format!("{api}/echo?{ADDRESS}&key={{{{token}}}}")); + app.request().type_header(&format!("X-Trace: {HEADER}")); + app.request().choose_method(Method::Post); + app.request().type_body(Body::Json(&format!("{{\"k\": \"{BODY}\"}}"))); + app.request().send(); + app.response().expect_body(BODY, "it left with its body"); + app.response().expect_body(SECRET, "and the environment's secret"); + app.request().save(); + app.window().go_to(Area::Notes); + }); + + step("closed, the profile reads none of it, nor the passphrase", || { + app.while_closed(|disk| { + disk.expect_nowhere(&WRITTEN, "no file of the profile says what was written"); + }); + app.disk() + .expect_somewhere(TAG, "the tag, plain by design, is read: the scan reads the database"); + app.gate().unlock(PASSPHRASE); + app.notes().expect_card(SNIPPET, "the library opens on what was written"); + }); +} + +fn an_attachment_opened(app: &mut App) { + step("an attachment opened is a plain copy while DevNotes runs, gone once it is closed", || { + app.notes().open(SNIPPET); + app.attachments().open(0); + app.disk().expect_somewhere(BYTES, "the plain copy is under the profile"); + app.editor().close(); + app.while_closed(|disk| disk.expect_nowhere(©, "the copy went with DevNotes")); + app.gate().unlock(PASSPHRASE); + }); +} + +fn after_a_crash(app: &mut App) { + step("after a crash, the plain copy is gone before the gate is passed", || { + app.notes().open(SNIPPET); + app.attachments().open(0); + app.disk().expect_somewhere(BYTES, "the plain copy is under the profile"); + app.crash_and_launch_again(); + app.disk().expect_nowhere(©, "the copy is gone, the library still shut"); + app.gate().unlock(PASSPHRASE); + app.notes().open(SNIPPET); + app.attachments().expect(1, "the file is still attached, sealed"); + app.editor().close(); + }); +}