Cache plugin package hashes, add a content security policy, and limit browser windows
Plugin runtime cost: - Remove the timed plugin scan. Windows scan at start, on focus, on Refresh, and on plugins-changed. - Keep one package check for each plugin folder. Read and hash the files again only when the entry names, sizes, or modification times change. Enable and load always read all files. An asset read checks the SHA-256 hash of its file. - A changed package still stops and needs a new enable decision. Add tests for the cache, for changes that keep the metadata, and for the enable decision. - Replace the 50 ms wait loops of update and removal with a condition variable. The limit stays at 10 seconds. Command names, arguments, and results do not change. Content security policy: - Set app.security.csp in tauri.conf.json. Keep Tauri from adding nonces to style-src. - Add CSP mode to the smoke tests (pnpm smoke --csp). The dev server sends the same policy with each HTML page, and the harness fails a test on a policy violation. - Decode data URLs without fetch in the background frame test. Capabilities: - Give browser windows their own capability. They load no installed plugin. Add a unit test and a browser window smoke test for the command set. Document the scans, the hash cache, the policy, and the window capabilities.
This commit is contained in:
+18
-1
@@ -36,7 +36,7 @@ Do not start a separate `pnpm dev` for this workflow.
|
||||
| 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`. |
|
||||
| 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). |
|
||||
|
||||
@@ -74,6 +74,7 @@ Windows is the primary platform. macOS and Linux builds are experimental.
|
||||
|
||||
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/`
|
||||
|
||||
@@ -193,6 +194,7 @@ They do not replace tests in the native app. Real folder access, file writes, an
|
||||
| `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).
|
||||
@@ -216,6 +218,7 @@ A test states what it needs near its top. The runner skips the test, with the re
|
||||
| `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_TERMINAL_DIST` | The compiled Terminal plugin. The default is `RuneStone_Terminal/dist` in that folder. |
|
||||
| `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 |
|
||||
|
||||
@@ -227,6 +230,20 @@ To read or change a section later, use `window.__TEST__.settings(section)` and `
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user