Smoke runs in CI
A build with the smoke feature opens the real window, checks that the first page loaded, runs a script in it, and exits, for CI.
The smoke feature
A smoke run starts the application as a person would, in the system's real web view, checks its first page, and closes it, so CI finds what FakeOs cannot: a window that does not open, a server that refuses it, or a page that does not load. It needs a build with the smoke feature of hypersig_desktop and one of two environment variables set when the application starts:
cargo build --release -p example-notes --features hypersig_desktop/smoke
HYPERSIG_DESKTOP_SMOKE=1 target/release/example-notes| Variable | What the run does |
|---|---|
HYPERSIG_DESKTOP_SMOKE | Checks the first page and closes the application |
HYPERSIG_DESKTOP_SMOKE_SCRIPT | Checks the first page, then runs the JavaScript file the variable names and closes once it passes |
Either variable alone starts a run. HYPERSIG_DESKTOP_SMOKE may have any value, an empty one included, and HYPERSIG_DESKTOP_SMOKE_SCRIPT must name a file the application can read; set to an empty value, it counts as unset. A build without the feature ignores both, because the script runs in the page and can call every action the router declares. A release built without smoke therefore runs no file an environment variable names. CI builds with the feature as a separate build, and examples/notes ships its packages without it.
The check of the first page
The first page is the one App::run names. When its window is shown, the run writes one line to standard output, where N is the milliseconds since App::run was called:
hypersig_desktop: first page shown N ms after runThe run then checks that the page is one hypersig rendered. With HYPERSIG_DESKTOP_SMOKE alone, it closes the application once the check passes, and App::run returns Ok(()). The line is written before the check, so a run whose check fails writes it too. A run fails in these cases, and App::run returns an Err, so a main that returns it exits with a status other than 0:
| Cause | ErrorKind |
|---|---|
| The first page is not one hypersig rendered, as when the server refused the window | Smoke |
| A window's page did not finish loading within 10 seconds | Smoke |
The file HYPERSIG_DESKTOP_SMOKE_SCRIPT names cannot be read | Io |
A script that sets a verdict
With HYPERSIG_DESKTOP_SMOKE_SCRIPT, the run evaluates the file in the first page once the check passes, and in the page of every other window, whether it loaded before then or loads later. It then reads window.hypersigSmoke in the first page every 200 milliseconds, as a string:
"pass": the run writeshypersig_desktop: smoke script passed, closes the application, andApp::runreturnsOk(()).- Any other value: the run fails with
ErrorKind::Smoke, and the error's message holds the value, so a script can set the reason it failed. - Nothing, or an empty string, for 20 seconds after the script started: the run fails with
ErrorKind::Smoke.
The script below is the one CI runs in examples/notes, started with one file on the command line, so the application opens the list window and a window for that note. In the note's window, the script edits the text and clicks Save; in the list window, it waits for the save to reach the list over its stream. The page has loaded when the script runs, but the hypersig runtime may not have started on it yet, so the note's window waits a second before it types:
// The script CI's desktop job runs in each window of the notes example,
// started with one file, with HYPERSIG_DESKTOP_SMOKE_SCRIPT naming this file.
// The note's window, which the application opens for the file, edits the
// text and saves it; the list window passes once the save has reached it
// over its stream.
(() => {
if (location.pathname.startsWith("/notes/")) {
// The page has loaded, but the runtime may not have started on it yet.
setTimeout(() => {
const text = document.querySelector("textarea");
text.value = "Saved by the smoke run.\n";
text.dispatchEvent(new Event("input", { bubbles: true }));
[...document.querySelectorAll("button")].find((button) => button.textContent === "Save").click();
}, 1000);
return;
}
const deadline = Date.now() + 15_000;
const check = () => {
if (document.body.textContent.includes("1 saves")) window.hypersigSmoke = "pass";
else if (Date.now() > deadline) window.hypersigSmoke = "the save in the note's window did not reach the list";
else setTimeout(check, 100);
};
check();
})();A workflow
The workflow below takes the steps of this repository's desktop job that test, build, and run examples/notes on macOS, Windows, and Linux. A Linux runner has no display, so xvfb-run gives the window one, and the job installs WebKitGTK, which hypersig_desktop links on Linux. The last line checks the file the script saved, so the job fails if the save never reached the disk:
name: desktop
on: [push, pull_request]
jobs:
desktop:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: dtolnay/rust-toolchain@d124f86f28ff42855784ff3319f48ac182c248f8 # 1.99
# xvfb gives the window a display on a runner that has none.
- if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev libdbus-1-dev xvfb
- run: cargo test -p example-notes
- run: cargo build --release -p example-notes --features hypersig_desktop/smoke
- name: The notes example saves a file from a second window
shell: bash
env:
HYPERSIG_DESKTOP_SMOKE_SCRIPT: examples/notes/smoke.js
run: |
note="$RUNNER_TEMP/smoke-note.md"
echo "# Smoke" > "$note"
if [ "$RUNNER_OS" = Linux ]; then
xvfb-run -a target/release/example-notes "$note"
else
target/release/example-notes "$note"
fi
grep -q 'Saved by the smoke run.' "$note"Next
- Testing without a window:
FakeOs, for the handlers and pages undercargo test. - Packaging: the build that ships, without the
smokefeature.