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:
+21
-3
@@ -1,6 +1,6 @@
|
||||
// Run the browser smoke tests in tests/smoke/. See docs/development.md#browser-smoke-tests.
|
||||
//
|
||||
// pnpm smoke [filter...] [--list] [--jobs N] [--timeout seconds] [--retries N] [--no-serve]
|
||||
// pnpm smoke [filter...] [--list] [--jobs N] [--timeout seconds] [--retries N] [--no-serve] [--csp]
|
||||
//
|
||||
// A filter selects the tests whose path contains it, for example `tabs` or `tables/drag`.
|
||||
// After the parallel run, the runner runs each failed test again, one at a time (--retries, default 1).
|
||||
@@ -11,6 +11,7 @@
|
||||
// A test that fails because of a known app defect states it near the top:
|
||||
// // @known-issue <the defect>
|
||||
// It still runs. A failure counts as "known". A pass counts as a failure, so remove the stale line.
|
||||
// --csp runs the tests under the app's content security policy (RUNESTONE_CSP=1). A test fails on any violation.
|
||||
import { spawn } from "node:child_process";
|
||||
import { createWriteStream, existsSync } from "node:fs";
|
||||
import { mkdir, readdir, readFile } from "node:fs/promises";
|
||||
@@ -39,9 +40,11 @@ const serve = !flag("--no-serve");
|
||||
const jobs = Math.max(1, Number(option("--jobs", "4")));
|
||||
const timeoutMs = Math.max(10, Number(option("--timeout", "180"))) * 1000;
|
||||
const retries = Math.max(0, Number(option("--retries", "1")));
|
||||
const csp = flag("--csp");
|
||||
const filters = args;
|
||||
|
||||
const env = { ...process.env, SMOKE_URL: process.env.SMOKE_URL || "http://127.0.0.1:1420" };
|
||||
if (csp) env.RUNESTONE_CSP = "1";
|
||||
const pluginRepos = env.RUNESTONE_PLUGIN_REPOS || path.join(root, "..");
|
||||
|
||||
async function findTests(dir) {
|
||||
@@ -109,11 +112,21 @@ async function reachable(url) {
|
||||
}
|
||||
}
|
||||
|
||||
/** True when the server sends the content security policy with the app page (see vite.config.js). */
|
||||
async function sendsPolicy(url) {
|
||||
try {
|
||||
const response = await fetch(url, { headers: { accept: "text/html" }, signal: AbortSignal.timeout(10000) });
|
||||
return response.headers.has("content-security-policy");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function startServer() {
|
||||
const vite = path.join(root, "node_modules", "vite", "bin", "vite.js");
|
||||
// Serve on the port in SMOKE_URL, so that two checkouts can run their tests at the same time.
|
||||
const port = new URL(env.SMOKE_URL).port || "1420";
|
||||
const server = spawn(process.execPath, [vite, "dev", "--port", port, "--strictPort"], { cwd: root, stdio: "ignore", windowsHide: true });
|
||||
const server = spawn(process.execPath, [vite, "dev", "--port", port, "--strictPort"], { cwd: root, env, stdio: "ignore", windowsHide: true });
|
||||
for (let waited = 0; waited < 60000; waited += 500) {
|
||||
if (await reachable(env.SMOKE_URL)) return server;
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
@@ -175,9 +188,14 @@ if (!(await reachable(env.SMOKE_URL))) {
|
||||
console.error(`Nothing serves ${env.SMOKE_URL}. Start pnpm dev, or run without --no-serve.`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`Starting the dev server at ${env.SMOKE_URL}...`);
|
||||
console.log(`Starting the dev server at ${env.SMOKE_URL}${csp ? " in CSP mode" : ""}...`);
|
||||
server = await startServer();
|
||||
}
|
||||
if (csp && !(await sendsPolicy(env.SMOKE_URL))) {
|
||||
server?.kill();
|
||||
console.error(`The server at ${env.SMOKE_URL} does not send a content security policy. Stop it, or set SMOKE_URL to a free port, so that --csp can start a server with RUNESTONE_CSP=1.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const results = [];
|
||||
const queue = plan.filter(item => !item.reasons.length);
|
||||
|
||||
Reference in New Issue
Block a user