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
4 changes: 2 additions & 2 deletions .claude/skills/desktop-e2e-testing/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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'.
- It is written on the SDK (`e2e/src/sdk/`, one file per area) alone: no `author_id`, coordinate or duration. An act it lacks is a method of its area, with a line of doc; an expectation carries the sentence of what the person would see.
- 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 <name>` 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 <name>` 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/<journey>/`: 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`.
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion crates/app/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<dyn Opener + Send + Sync> {
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<dyn Opener + Send + Sync> {
platform::desktop::from_scenario()
}

#[cfg(not(feature = "e2e"))]
fn updater() -> Arc<dyn Updater + Send + Sync> {
platform::updater::system(&UPDATES)
Expand Down
17 changes: 17 additions & 0 deletions crates/platform/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Opener + Send + Sync> {
Arc::new(Scenario)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
35 changes: 19 additions & 16 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -6779,7 +6779,9 @@ event the close button sends (`ViewportCommand::Close` is pushed as the same
`ViewportEvent::Close`), and `--action tray:<entry>`, 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
Expand All @@ -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/<journey>/`, 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
Expand Down
6 changes: 6 additions & 0 deletions e2e/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions e2e/src/sdk/attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
67 changes: 67 additions & 0 deletions e2e/src/sdk/disk.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<PathBuf>> {
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)
}
22 changes: 22 additions & 0 deletions e2e/src/sdk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod board;
mod calc;
mod clipboard;
mod code;
mod disk;
mod drawing;
mod editor;
mod environments;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"));
Expand Down
10 changes: 9 additions & 1 deletion e2e/tests/12_looking_after_the_library.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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();
}
Loading
Loading