377 lines
31 KiB
Markdown
377 lines
31 KiB
Markdown
# Development guide
|
|
|
|
[RuneStone](../README.md) · [Builds](builds.md) · [Releases](releases.md) · [Plugin development](plugin-development.md) · [Interface design](ui-design.md)
|
|
|
|
This guide is for developers who change RuneStone's source code. To use the app, see the [user guide](user-guide.md).
|
|
|
|
## Run from source
|
|
|
|
### Requirements
|
|
|
|
- Node.js 24 or later, and pnpm 10.
|
|
- A current stable Rust toolchain.
|
|
- The [Tauri prerequisites](https://v2.tauri.app/start/prerequisites/) for your platform.
|
|
On Windows, these are the Microsoft C++ Build Tools and WebView2.
|
|
On Linux, use the [Linux development guide](linux.md).
|
|
|
|
### First run
|
|
|
|
1. Clone the repository: `https://github.com/kwyvern-gh/RuneStone.git`.
|
|
2. In the repository folder, run `pnpm install --frozen-lockfile`.
|
|
3. Prepare the browser runtime. See [Built-in browser runtime](#built-in-browser-runtime).
|
|
4. Run `pnpm tauri dev`.
|
|
5. In the app, use the folder button to open a test workspace.
|
|
|
|
The first launch compiles the Rust app and its dependencies. Later launches reuse the Cargo cache in `src-tauri/target/`.
|
|
Do not run `cargo clean` as part of normal work.
|
|
|
|
## Daily workflow
|
|
|
|
`pnpm tauri dev` starts Vite on port 1420 through `beforeDevCommand` in `src-tauri/tauri.conf.json`. Then it opens the app in a native window.
|
|
Do not start a separate `pnpm dev` for this workflow.
|
|
|
|
| Change | What happens |
|
|
| --- | --- |
|
|
| Svelte, TypeScript, or CSS in `src/` | Vite updates the window. No Rust build. |
|
|
| Rust code in `src-tauri/src/` | Cargo rebuilds the changed code, and Tauri restarts the app. |
|
|
| Rust dependencies or build settings | Cargo compiles the affected crates. This can take several minutes. |
|
|
| JavaScript dependencies, after a pull | Stop the session, run `pnpm install --frozen-lockfile`, and start it again. |
|
|
| Tauri configuration, capabilities, or Vite configuration | Restart `pnpm tauri dev`. The content security policy applies only to a built app, not to `pnpm tauri dev`. See [Content security policy](plugin-host.md#content-security-policy). |
|
|
| A plugin in a sibling repository | Build and package that plugin, then install the new ZIP through Settings. See [Build examples](plugin-development.md#build-examples). |
|
|
| Installer or release behavior | Use the [build guide](builds.md). |
|
|
|
|
The app reads and writes real files. Use a test workspace with sample documents.
|
|
Save open documents before a change that restarts the app. A Rust restart ends terminal sessions.
|
|
An installed copy of RuneStone does not show source changes. Use the window that `pnpm tauri dev` opens.
|
|
|
|
To see frontend errors, press Ctrl+Shift+I in the development window to open the web inspector.
|
|
Rust errors appear in the terminal that runs `pnpm tauri dev`.
|
|
|
|
## Architecture
|
|
|
|
RuneStone is a Tauri 2 app. A Rust host gives native services to a Svelte 5 and TypeScript interface.
|
|
CodeMirror drives the editor. Each open document has one editor state, and Write and Source are two configurations of it.
|
|
Windows is the primary platform. macOS and Linux builds are experimental.
|
|
|
|
### Desktop host: `src-tauri/src/`
|
|
|
|
| Module | Responsibility |
|
|
| --- | --- |
|
|
| `lib.rs` | App setup, command registration, window events |
|
|
| `error.rs`, `fsutil.rs` | The shared error type, and the shared file mechanics: name and link checks, limited reads, atomic writes |
|
|
| `workspace.rs` | The workspace root of each window, path checks, atomic saves, the file watcher, search |
|
|
| `plugins.rs` | Plugin package review, installation, enable state, removal, and recovery |
|
|
| `plugin_sources.rs` | Plugin downloads from Gitea releases |
|
|
| `git.rs` | The Git service of the Git feature. It runs the `git` program. |
|
|
| `features.rs` | Reads the old plugin packages of the native features one time, for the first-start migration. It changes no plugin file. |
|
|
| `pty.rs`, `terminal_platform.rs` | The shell sessions of the Terminal feature, the shell search, and terminal windows. A session belongs to the window and the page that opened it. |
|
|
| `browser.rs` | The process of the built-in browser engine |
|
|
| `backgrounds.rs` | The image folder of the Background feature: the folder dialog, the kept folder (`background-folder.json` in the app data folder), the image list and reads, the sidecar file, and the folder migration from the Background Slideshow plugin |
|
|
| `spelling.rs` | Spelling suggestions from the operating system (Windows) |
|
|
| `settings.rs`, `theme.rs` | The Settings window and theme export |
|
|
| `preferences.rs` | The settings file of the user. It reads, writes, and migrates the file, and replaces a damaged file. |
|
|
| `tab_transfer.rs` | Tab transfer between windows. The offers stay in memory. |
|
|
| `completion.rs` | A local proxy to a completion model server |
|
|
|
|
The interface calls Rust commands through Tauri `invoke`. Most calls go through the wrappers in `src/lib/workspace/api.ts`.
|
|
A new command needs an entry in `generate_handler!` in `lib.rs`, in the command list in `src-tauri/build.rs`, and in the capability files in `src-tauri/capabilities/`.
|
|
`default.json` must list every command. `settings.json` and `browser.json` list subsets. See [Window capabilities](plugin-host.md#window-capabilities).
|
|
|
|
### Interface: `src/lib/`
|
|
|
|
| Folder | Responsibility |
|
|
| --- | --- |
|
|
| `layout/` | The app shell: `Workbench.svelte` holds the state and the commands, and `WorkbenchHeader`, `PluginRibbon`, `LeftPane`, `DocumentArea`, `RightPane`, and `StatusBar` draw its regions. `ViewModes` is the Write, Source, and Read control of each document pane. Also the file tree, tabs, panes, Settings, and dialogs |
|
|
| `editor/` | The document editor (`DocumentEditor.svelte`) with its Write and Source configurations, Markdown lists, tables, links, images, and editor menus |
|
|
| `formulas/` | Table formulas: the parser and evaluator (`engine.ts`), the rendered results, the formula help, and the `tableFormulas` setting (`index.ts`) |
|
|
| `workspace/` | Tauri wrappers, document buffers, the workspace session (`session.svelte.ts`: marks, renames, change events, and the note index), paths, templates, and tab transfer (`tabTransfer.ts`) |
|
|
| `settings/` | The settings store (`store.ts`), and the code that moves the old browser values to the settings file (`migration.ts`) |
|
|
| `plugins/` | The plugin runtime, the host types (`sdk.ts`, which also exports the SDK types), and Settings → Plug-ins |
|
|
| `browser/` | The interface of the built-in browser |
|
|
| `features/` | The native features with an off switch: the catalog (`catalog.ts`), the switches (`state.ts`), the first-start migration, the loader, the launch rules, and the Background settings (`backgroundSettings.ts`). Each feature has a folder: `git/`, `background/`, `terminal/`, `pdf/`, and `pm/`. The main-bundle files of Terminal are `terminalKeys.ts`, `terminalSettings.ts`, `terminalHost.ts`, `TerminalHost.svelte`, and `TerminalSettings.svelte`. The main-bundle files of Project Management are `pmSettings.ts`, `pmBoards.ts`, and `ProjectManagementSettings.svelte`. See [Native features](#native-features). |
|
|
| `completion/` | Contracts and services that plugins use |
|
|
| `git/` | The Git service and its types, for the Git feature and the line history in the status bar |
|
|
| `theme/` | Appearance settings, palettes, and the theme tokens (`tokens.css`) |
|
|
| `ui/` | Shared menus, pickers, and action icons |
|
|
| `i18n/` | Interface text in English, French, Japanese, and Simplified Chinese |
|
|
|
|
### Other folders
|
|
|
|
| Folder | Content |
|
|
| --- | --- |
|
|
| `browser-runtime/` | The browser engine, its tests, filter lists, and third-party notices |
|
|
| `packages/plugin-sdk/` | The plugin SDK `@runestone/plugin-sdk`. See [Plugin SDK](#plugin-sdk). |
|
|
| `tests/unit/<area>/` | Unit tests (`*.spec.ts`) that run in Node |
|
|
| `tests/smoke/<area>/` | Browser smoke tests (`*.smoke.mjs`) and their shared harness in `_harness/` |
|
|
| `tests/native/` | Tests that attach to a running desktop app |
|
|
| `scripts/` | Build, release, package, and audit tools, and the smoke test runner |
|
|
| `fixtures/` | A sample workspace (`fixtures/sample/`), a sample plugin, and a completion test page |
|
|
| `design/` | Icon drafts |
|
|
| `docs/` | User and developer documentation |
|
|
|
|
### Where data lives
|
|
|
|
| Data | Location |
|
|
| --- | --- |
|
|
| Documents | Ordinary files in the workspace folder |
|
|
| Workspace state: tab order, pins, bookmarks, templates, and the boards, cards, labels, and images of Project Management (`.runestone/pm/`) | `.runestone/` in the workspace |
|
|
| Installed plugins and their settings | The app data folder. See [plugin storage](plugin-host.md#storage-and-recovery). |
|
|
| Preferences: general settings, appearance, custom themes, display language, feature switches, Background, Terminal, Project Management | `settings.json` in the app config folder |
|
|
| The image folder of Background | `background-folder.json` in the app data folder. The image of the image source stays in the WebView storage (IndexedDB). |
|
|
| Browser profiles, bookmarks, history, browser settings, and Chromium caches | `browser/` in the local app data folder. On Windows, this is `%LOCALAPPDATA%\com.runestone.app\browser\`. See [Built-in browser runtime](#built-in-browser-runtime). |
|
|
| Window layout, the open tabs of each workspace, and the view state of each Project Management tab (`runestone.pm.viewStates`) | The WebView storage (`localStorage`) of the app. RuneStone can lose these values without harm. |
|
|
|
|
#### The settings file
|
|
|
|
`src-tauri/src/preferences.rs` keeps the preferences in `settings.json` in the Tauri `app_config_dir()`.
|
|
On Windows, this is `%APPDATA%\com.runestone.app\`, the same folder as the app data.
|
|
On macOS, it is `~/Library/Application Support/<identifier>/`. On Linux, it is `~/.config/<identifier>/`.
|
|
|
|
```json
|
|
{
|
|
"schema": 1,
|
|
"revision": 12,
|
|
"general": { "autosaveEnabled": true, "autosaveSeconds": 5, "showInternalFolder": false, "tableFormulas": true },
|
|
"appearance": { "theme": "default", "mode": "dark" },
|
|
"customThemes": [],
|
|
"customThemesLegacy": [],
|
|
"language": "en",
|
|
"features": { "git": true, "background": true, "terminal": true, "pdf": true, "pm": true },
|
|
"background": { "source": "folder", "seconds": 60, "order": "name", "paused": false, "targets": ["app"], "overlay": 0, "position": "center", "size": "cover" },
|
|
"terminal": { "defaultProfile": "", "fontSize": 13, "scrollback": 10000, "cursorBlink": true },
|
|
"projectManagement": { "priorityLevels": 3 }
|
|
}
|
|
```
|
|
|
|
| Rule | Detail |
|
|
| --- | --- |
|
|
| Sections | `general`, `appearance`, `customThemes`, `customThemesLegacy` (the original version 1 themes), `language`, `features` (the switches of the native features), `background` (the source, the timing, the targets, and the folder layout of Background), and `terminal` (the default profile, the font size, the scrollback, and the cursor of Terminal). `projectManagement` holds the priority levels of Project Management. The host does not interpret their values. The frontend normalizes each section. |
|
|
| Size | At most 8 MiB in total. The appearance can hold an image data URL of up to 3,000,000 characters. |
|
|
| Writes | `settings_write` replaces one section. The host writes a complete temporary file and renames it. Then it sends `settings-changed` to all windows with the section, the revision, and the value. |
|
|
| Damaged file | The host moves the file to `settings.corrupt-<seconds>.json` and writes a new file with the defaults. The first window that reads the settings shows a message one time. |
|
|
| First start | When no file exists, the window reads the old `localStorage` keys and normalizes their values. The keys are `runestone.settings`, `runestone.appearance`, `runestone.custom-themes`, `runestone.custom-themes.legacy`, and `runestone.language`. `settings_migrate` writes the values only when no file exists. RuneStone keeps the old keys for one release, but does not use them. |
|
|
| Browser preview | Without the desktop host (`pnpm dev`), the preferences stay in `localStorage` under the old keys. |
|
|
|
|
Each window loads all sections one time before its first render (`src/routes/+layout.ts`).
|
|
After that, `src/lib/settings/store.ts` reads the sections from memory and tells subscribers about changes.
|
|
|
|
## Product boundaries
|
|
|
|
- Workspace documents stay ordinary local files. Users keep access to them when plugins are disabled.
|
|
- The core includes Markdown table editing, rendering, and table formulas.
|
|
- Native file access, file watching, search, Git, and terminals belong in Rust.
|
|
- Built-in features with an off switch live in `src/lib/features/`. Other optional features ship as plugins. The [plugin development reference](plugin-development.md) defines the package format and the API.
|
|
- For sync, prefer a local Git clone. Do not use a live network share as the sync path.
|
|
|
|
These stay outside the product:
|
|
|
|
- A plugin marketplace
|
|
- Compatibility with Obsidian or VS Code plugins
|
|
- Cloud sync, live collaboration, or a mobile app
|
|
- A debugger or a full IDE
|
|
- Automatic commits on save
|
|
|
|
Track plans and roadmaps in RuneStone Project Management, not in these docs.
|
|
|
|
## Checks
|
|
|
|
Run these commands from the repository folder. They do not need an installer.
|
|
|
|
| Command | Checks |
|
|
| --- | --- |
|
|
| `pnpm check` | Svelte and TypeScript types of the app, the unit tests (`tests/tsconfig.json`), the plugin SDK, and the example plugin. Then the catalog audit. See [Interface text](#interface-text). |
|
|
| `pnpm test` | Unit tests in `tests/unit/` |
|
|
| `cargo test --manifest-path src-tauri/Cargo.toml --lib` | Rust unit tests |
|
|
| `pnpm smoke` | Browser smoke tests. See [Browser smoke tests](#browser-smoke-tests). |
|
|
| `pnpm build` | The production frontend build |
|
|
| `pnpm check:menus` | The inventory of menu surfaces. See [Interface design](ui-design.md). |
|
|
| `pnpm check:features` | A full build. It fails when a native feature module loads at start. See [Native features](#native-features). |
|
|
|
|
To run one test file, use `node --experimental-strip-types --import ./tests/unit/_svelte/register.mjs --test tests/unit/tables/selection.spec.ts`.
|
|
The `--import` hook compiles `.svelte.ts` modules, so a test can import them.
|
|
For type errors while you edit, run `pnpm check:watch`.
|
|
|
|
Some tests need files from outside this repository. Without those files, the tests skip and state the reason:
|
|
|
|
- `tests/unit/release/installerVersion.spec.ts` needs the NSIS compiler that the Tauri CLI downloads on Windows.
|
|
- The Rust terminal tests start the real shells on the computer.
|
|
|
|
### Interface text
|
|
|
|
All text that a user reads goes through the catalog in `src/lib/i18n/messages.ts`. Each row has the English key and the French, Japanese, and Simplified Chinese text.
|
|
|
|
1. Translate the text with `$t("…")` in a Svelte component or `tr("…")` in a TypeScript module.
|
|
2. For a value in the text, use a placeholder: `tr("Created {path}", { path })`. Do not join strings.
|
|
3. When a variable carries a key to the call, mark the key where you write it: `message("Bold")`.
|
|
4. Add a catalog row with all four languages.
|
|
|
|
Errors of the plugin API stay in English, because they are for plugin developers.
|
|
`pnpm check` runs `scripts/i18nAudit.mjs`. It fails for a key that the catalog does not have, a catalog key that the code does not use, and a row without all translations.
|
|
|
|
## Native features
|
|
|
|
Git, Background, Terminal, PDF Viewer, and Project Management are native features: host code with an off switch in **Settings → Features**. They do not use the plugin API.
|
|
|
|
| Part | File |
|
|
| --- | --- |
|
|
| The catalog: ID, old plugin ID, name, views, commands, and document types | `src/lib/features/catalog.ts` |
|
|
| The switches: the `features` settings section | `src/lib/features/state.ts` |
|
|
| The first start: each switch takes the state of the old plugin package, or the default of the feature when `followsPackage` is false | `src/lib/features/migration.ts` and `src-tauri/src/features.rs` |
|
|
| One import at first need in each window | `src/lib/features/loader.ts` |
|
|
| A start without a view: the launch rules, also the rule for browser windows | `src/lib/features/launch.ts` |
|
|
| Views, commands, and document tabs in the workbench | `src/lib/features/session.ts` and `src/lib/plugins/external.ts` |
|
|
| The feature code | `src/lib/features/<feature>/index.ts` and its components |
|
|
|
|
- The catalog holds only static data, so the main bundle stays small. The feature code loads when the user first opens a view, a tab, or a command of the feature. An off feature loads nothing.
|
|
- A command without a view loads the feature and calls `FeatureInstance.run`. A launch rule starts the instance at once when it wants it, and again after each change of its settings.
|
|
- Background has a launch rule: it loads when the `background` section selects a folder, or an image that exists. Its settings section and its "has a source" test are in `src/lib/features/backgroundSettings.ts`, in the main bundle. It also runs in browser windows. In the settings window, only its settings component loads (`mountSettings`).
|
|
- The first start makes the `background` section from the kept settings of the Background Slideshow plugin and from the old background image. `background_migrate` copies the folder of the old plugin grant to the host only when the host has no folder.
|
|
- Terminal has no view and no launch rule. `TerminalHost.svelte` puts the panel in the workbench and in the terminal window, and the first use loads the module. `terminalKeys.ts` holds the shortcuts and the Help rows. Settings → Terminal (`TerminalSettings.svelte`) loads no xterm.
|
|
- `@xterm/xterm` and `@xterm/addon-fit` are host dependencies. `pnpm check:features` keeps them out of the start chunks.
|
|
- PDF Viewer has a document type and no view. The file tree marks PDF files through `identifyPdf` in `src/lib/features/pdfDocument.ts`, in the main bundle. The first PDF tab loads the module and calls `FeatureInstance.mountDocument`. Each tab reads its file with `workspace_read_bytes` and starts its own PDF.js worker. Closing the tab, or Off, stops the worker.
|
|
- `pdfjs-dist` is a host dependency. `src/lib/features/pdf/engine.ts` loads the minified build. The worker, the character maps, the standard fonts, and the image decoders are Vite assets of the app, so PDF.js makes no network request. `build.assetsInlineLimit` in `vite.config.js` keeps these files out of the code.
|
|
- Project Management has one editor view, `planning`, with `launch: true`. The view pattern `board-<hex of the board ID>` gives each board its own tab. Its ribbon button in `PluginRibbon.svelte` calls the launch, which opens the default board of the workspace or All tasks. It has no command.
|
|
- Project Management reads and writes only `.runestone/pm/`. `storage/legacy.ts` finds data in the old format of visible notes. The interface then offers the migration, with backups in `.runestone/pm/backups/`. It migrates only after the user chooses it.
|
|
- Project Management deletes no files. A description draft is `.runestone/pm/drafts/<hex of the card ID>.json`. The data of its unsaved images is in `<hex of the card ID>.images.json` in the same folder. Thus a text change does not write the images again.
|
|
Only a save of the description or the card writes `.runestone/pm/images/<image ID>.json`. **Save** and **Cancel** of the description replace the draft and its image record with empty records. As a result, a discarded draft leaves no image file.
|
|
- `pm/storage/` and `pm/model/` stay pure TypeScript without host modules, so the `runestone-project-management` skill can bundle them. They mark their user-visible text with `message()` from `storage/message.ts` and keep it in English. The interface translates that text with `localize()` in `pm/ui/text.ts`.
|
|
- The `projectManagement` section holds the priority levels (`pmSettings.ts`). The default board is `defaultBoardId` in `.runestone/pm/workspace.json`, so each workspace has its own. Appearance → Background reads the board list from the same file through `pmBoards.ts`, without the feature code.
|
|
- The first start makes the `projectManagement` section from the kept settings of the Project Management plugin. When `localStorage` has no view states, it also copies the view states of the plugin.
|
|
- `yaml` is a host dependency of Project Management. The card descriptions use the markdown-it of the host.
|
|
- [THIRD_PARTY_NOTICES.md](../THIRD_PARTY_NOTICES.md) gives the version, license, and source of each third-party package that a feature includes. Update it when you add or update such a package.
|
|
- The first start makes the `terminal` section from the `runestone.terminal` key of `localStorage`, which the Terminal plugin wrote. The old key stays.
|
|
- Before Terminal goes off, Settings asks `pty_running` for the shells of all windows. Off closes the sessions of each window.
|
|
- Host code never imports a feature folder statically. `pnpm check:features` builds the app. It fails when a feature module, or a library that only a feature needs, is in a chunk that loads at start.
|
|
- Saved tabs and tab transfers keep the ID of the old plugin package as the owner ID, for example `runestone.git`. `builtInPackages` in `external.ts` lists the old package, so it never loads.
|
|
- Off stops the feature at once in each window and closes its views. The loaded module stays in memory until the window reloads.
|
|
- To add a feature, add its entry to `catalog.ts`, its import to `loader.ts`, its folder to `FEATURE_FOLDERS` in `scripts/featureChunks.mjs`, and its old plugin ID to `LEGACY_PACKAGES` in `src-tauri/src/features.rs`. Add a launch rule only when the feature must run without a view.
|
|
|
|
## Plugin SDK
|
|
|
|
The plugin SDK in `packages/plugin-sdk/` is the only source of the public plugin types.
|
|
The host imports it with relative paths in `src/lib/plugins/sdk.ts`, `src/lib/ui/actionIcons.ts`, and `src/lib/ui/tooltip.ts`.
|
|
Change a public type in the SDK, not in the host. Keep host-only types, such as the native transports, in `src/lib/plugins/sdk.ts`.
|
|
The menu types in `src/lib/ui/actionMenu.ts` and `src/lib/ui/managedActionMenu.ts` are the exception: they keep their own declarations.
|
|
`tests/unit/sdk/features.spec.ts` makes sure that their types and the SDK menu types are the same.
|
|
The SDK source must not import host files. It must use only TypeScript syntax that Node.js can remove, because the unit tests load it directly.
|
|
|
|
| Command | Result |
|
|
| --- | --- |
|
|
| `pnpm sdk:build` | Compiles the SDK into `packages/plugin-sdk/dist/` with declaration files. The folder is outside Git. |
|
|
| `pnpm release:sdk --release-url <url> --version <version> [--dry-run]` | Builds the SDK and writes its package file and `sdk.json` in `releases/plugin-sdk/<version>/`. See [SDK releases](releases.md#sdk-releases). |
|
|
|
|
`pnpm check` type checks the SDK with `packages/plugin-sdk/tsconfig.json` and the example plugin with `fixtures/plugins/tsconfig.json`.
|
|
`pnpm test` runs the SDK tests in `tests/unit/sdk/` and the release script tests in `tests/unit/release/releaseSdk.spec.ts`.
|
|
|
|
## Browser smoke tests
|
|
|
|
Smoke tests run the real interface in headless Chromium with a mock of the desktop host.
|
|
They do not replace tests in the native app. Real folder access, file writes, and terminals need `pnpm tauri dev`.
|
|
|
|
| Command | Runs |
|
|
| --- | --- |
|
|
| `pnpm smoke` | All smoke tests, four at a time |
|
|
| `pnpm smoke tabs tables/drag` | The tests whose path contains one of the filters |
|
|
| `pnpm smoke --list` | Nothing. It lists each test, its requirements, and why a test would skip. |
|
|
| `pnpm smoke --csp` | All smoke tests under the content security policy of the app. A test fails on any policy violation. |
|
|
|
|
The runner starts the Vite server when nothing serves `SMOKE_URL`, and stops it at the end.
|
|
Use `--no-serve` to require a running server, `--jobs <n>` to change the number of parallel tests, and `--timeout <seconds>` to change the limit for each test (default 180).
|
|
After the parallel run, the runner runs each failed test one more time, alone. A test that passes then is reported as `flaky`. It does not fail the run, but the summary lists it. Use `--retries 0` to turn this off.
|
|
Each test writes its output to `output/smoke/logs/<area>__<name>.log`. Screenshots go to `output/smoke/<area>/<name>/`.
|
|
|
|
Playwright is a development dependency. When its own Chromium is not installed, the runner uses an installed Chrome or Edge.
|
|
To use the Playwright browser, run `pnpm exec playwright install chromium`.
|
|
|
|
A test states what it needs near its top. The runner skips the test, with the reason, when a requirement is missing:
|
|
|
|
| Line | Requirement |
|
|
| --- | --- |
|
|
| `// @requires repo:RuneStone_Local_Autocomplete/src` | A file or folder in a sibling plugin checkout |
|
|
| `// @requires electron` | The browser engine dependencies. Run `npm ci --prefix browser-runtime`. |
|
|
| `// @known-issue <defect>` | The test fails because of a known app defect. The run reports it as `known`. If the test passes, the run fails, so that someone removes the line. |
|
|
|
|
| Variable | Use |
|
|
| --- | --- |
|
|
| `SMOKE_URL` | The frontend address. The default is `http://127.0.0.1:1420`. When the runner starts Vite, it uses the port of this address, so two checkouts can run tests at the same time. |
|
|
| `RUNESTONE_PLUGIN_REPOS` | The folder of the sibling plugin checkouts. The default is the parent folder of this repository. |
|
|
| `RUNESTONE_CSP` | `1` sends and checks the content security policy. `--csp` sets it. |
|
|
| `CHROME_PATH` | A Chromium browser for Playwright |
|
|
| `PLAYWRIGHT_MODULE` | A different Playwright package |
|
|
|
|
To write a smoke test, start from an existing test in the same area. The harness in `tests/smoke/_harness/index.mjs` starts the browser, mocks the Tauri commands, and gives an in-memory workspace.
|
|
|
|
The harness also has default handlers for the settings file, for tab transfers, and for the `pty_*` shells of Terminal. All pages of one browser context share them.
|
|
The mock shell sends its output through the channel of `pty_open`. To send more, use `window.__TEST__.pty.output(id, text)` and `window.__TEST__.pty.exit(id, code)`.
|
|
To seed preferences, set the old `localStorage` keys before the first load. The app then migrates them.
|
|
To read or change a section later, use `window.__TEST__.settings(section)` and `window.__TEST__.writeSettings(section, value)`.
|
|
A failed test saves `failure.png` in its output folder and prints the page console errors and warnings.
|
|
You can also run one test file directly while `pnpm dev` runs, for example `node tests/smoke/tabs/order.smoke.mjs`.
|
|
|
|
### CSP mode
|
|
|
|
`--csp` sets `RUNESTONE_CSP=1`. With this variable, `vite.config.js` sends the policy from `src-tauri/tauri.conf.json` as a `Content-Security-Policy` header with each HTML page, as the installed app does.
|
|
It adds only what the dev server needs:
|
|
|
|
| Directive | Addition | Reason |
|
|
| --- | --- | --- |
|
|
| `script-src` | The SHA-256 hash of each inline script in the page | Tauri adds the same hashes in the installed app. The SvelteKit start script is inline. |
|
|
| `connect-src` | `ws://<address of the page>` | The Vite hot-reload WebSocket |
|
|
|
|
The harness records the `securitypolicyviolation` events of each page and frame, and fails the test when there is one. Violations inside workers do not reach the harness.
|
|
The runner refuses to use a server at `SMOKE_URL` that does not send the policy. Stop that server, or set `SMOKE_URL` to a free port.
|
|
The smoke tests do not replace a check in the installed app. The page there is the Tauri web view, and some plugins are not in the smoke tests. See [Content security policy](plugin-host.md#content-security-policy).
|
|
|
|
The tests in `tests/native/` attach to a running desktop app through the WebView2 remote-debugging port, and `pnpm smoke` does not run them.
|
|
Set `NATIVE_CDP_URL` to the debugging address, for example `http://127.0.0.1:9224`.
|
|
Before you start the app, set `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=<port>`. Each file states its port and variables at the top.
|
|
|
|
## Built-in browser runtime
|
|
|
|
The browser interface is in `src/lib/browser/`. The browser engine, its tests, and its notices are in `browser-runtime/`.
|
|
The engine is a separate download. Users install it on first use. To build and publish it, see [Build the browser engine](builds.md#build-the-browser-engine).
|
|
|
|
1. Run `npm ci --prefix browser-runtime`.
|
|
2. Run `pnpm browser:check` and `pnpm browser:test`.
|
|
3. Run `pnpm browser:test:engine` for the native engine tests.
|
|
4. Run `npm --prefix browser-runtime run package`.
|
|
5. Run `pnpm browser:stage` to use this engine in `pnpm tauri dev`.
|
|
|
|
Each browser window gets a session token at startup. Native requests check that token, and cleanup revokes it.
|
|
|
|
### Engine download
|
|
|
|
Each host build pins one engine version in `src-tauri/browser-engine.json`: the version, the protocol, and the URL, size, and SHA-256 hash for each platform.
|
|
A platform key is the operating system and the processor, for example `windows-x86_64`. Without an entry for its platform, the host reports that no engine is available.
|
|
|
|
On request, `src-tauri/src/browser_engine.rs` downloads the ZIP over HTTPS into `browser-engine/.download/` in the local app data folder. A redirect must also use HTTPS.
|
|
The host stops when the size or the SHA-256 hash differs from the pin. It extracts the ZIP into a new folder, refuses unsafe paths and links, and needs the engine program at the root of the archive.
|
|
Then it writes `installed.json` and renames the folder to `browser-engine/<version>/`. It removes the other versions.
|
|
At each start, the host compares `installed.json` with the pin. It does not hash the files again. **Install from file** applies the same size, hash, and archive checks to a local ZIP.
|
|
|
|
| Engine | When the host starts it |
|
|
| --- | --- |
|
|
| `src-tauri/browser-engine/`, from `pnpm browser:stage` | Debug builds without a manifest override |
|
|
| `browser-engine/<version>/` in the local app data folder | Release builds, and debug builds with `RUNESTONE_BROWSER_ENGINE_MANIFEST` |
|
|
|
|
`RUNESTONE_BROWSER_ENGINE_MANIFEST` names a manifest file for a native test. Only debug builds read it. With it, the host also accepts HTTP links, for a local test server.
|
|
|
|
The engine sends `protocol` and `version` with its `ready` event. The host stops an engine with a different protocol.
|
|
`PROTOCOL` in `browser_engine.rs` and the `ready` event in `browser-runtime/src/engine-main.mjs` must change together. After a change, package and stage the engine again.
|
|
|
|
The browser data is in the Tauri `app_local_data_dir()`. Releases up to 0.1.48 kept it in `app_data_dir()`, which roams on Windows.
|
|
Before the engine starts, `src-tauri/src/browser.rs` moves an old `browser` folder to the new place. Across volumes, it copies the folder and then deletes the old one.
|
|
If the new folder exists, the host uses it and leaves the old folder. If the move fails, the engine does not start, and the error names both folders.
|
|
On macOS and Linux, the two folders are the same, so nothing moves.
|
|
|
|
## Development help
|
|
|
|
| Problem | Action |
|
|
| --- | --- |
|
|
| Port 1420 is in use | Stop the other development server, then try again. Vite uses a fixed port. |
|
|
| The window shows the old interface | Look for compile errors in the terminal. Restart `pnpm tauri dev` if necessary. |
|
|
| A page says that desktop features need `pnpm tauri dev` | You opened the Vite server in a browser. Use the native window. |
|
|
| Windows cannot find `link.exe` | Install the C++ build tools and the Windows SDK from the Tauri prerequisites. Open a new terminal. |
|
|
| A smoke test cannot find Chromium | Run `pnpm exec playwright install chromium`, or set `CHROME_PATH` to an installed browser. |
|
|
| `cargo test --offline` reports missing crates | Run the command without `--offline` one time while you are online. |
|