Plug-ins: a failed install check ends while a run holds the documents

A check whose module fails in the worker now ends at once while a dialog
is open, a run holds the documents or a script runs: its worker is
terminated and the status bar says why. Only a checked install waits.

packaging/web/README.md lists everything a Content Security Policy must
allow: the inline start-up script Trunk writes into index.html,
'wasm-unsafe-eval' for WebAssembly, and the plug-in worker.
This commit is contained in:
dotCooCoo committed 2026-11-22 13:25:43 -08:00
1 parent d998e7245d
commit e2c2776655
3 files changed
+42 -6

No files matched your search

+7 -1
View File
@@ -593,7 +593,13 @@ fn poll_checks(app: &mut VectorcraftApp) {
let dialog = app.ui.dialog.is_some() || app.session.plugin_calls_open() || app.session.script_running();
let checked = loop {
if dialog {
break c.worker.watch(t).map(Err);
if let Some(e) = c.worker.watch(t) {
break Some(Err(e));
}
// A failed check ends at once; only a checked install waits.
if !matches!(c.worker.inbox.borrow().messages.front(), Some(FromWorker::Checked(Err(_)))) {
break None;
}
}
match c.worker.next(t) {
Err(e) => break Some(Err(e)),
+21
View File
@@ -874,6 +874,27 @@ fn on_the_web_a_checked_install_waits_for_the_run_that_holds_the_documents() {
registry::remove(id);
}
/// A check that fails while a run holds the documents ends at once: its worker is terminated and
/// the status bar says why, while the run goes on holding them.
#[test]
fn on_the_web_a_failed_check_ends_while_a_run_holds_the_documents() {
let (mut app, fake) = web_app();
let (bad_id, caller) = ("test.ui.web.failswhileheld", "test.ui.web.failswhileheld.caller");
install_caller(&mut app, caller, TRIANGLE);
let traps = wat::parse_str(tpl::module(&tpl::manifest(bad_id, "filter", "{}"), tpl::ECHO, "(start $s) (func $s unreachable)", 1)).unwrap();
app.run("ui.installPlugin", json!({"dataBase64": vectorcraft_format::base64_encode(&traps)})).unwrap();
app.run("plugin.dialog", json!({"id": caller})).unwrap();
fake.ready(0);
plugin_runs::poll(&mut app);
fake.serve(0);
plugin_runs::poll(&mut app);
assert!(fake.worker(0).terminated.get(), "the check's worker ends");
assert!(app.ui.status.contains("trapped"), "{}", app.ui.status);
assert!(app.session.plugin_calls_open(), "the run still holds the documents");
assert!(registry::get(bad_id).is_none());
app.run("plugin.cancelRuns", json!({})).unwrap();
}
/// The progress window shows the run that holds the documents at once, with Cancel only, also when
/// a run that started before it is running.
#[test]
+14 -5
View File
@@ -33,11 +33,20 @@ files need revalidation.
`vectorcraft-web-<hash>` `.wasm` and `.js` files, and `no-cache` on `index.html` and the
`vectorcraft-plugin-worker` files. The page refuses a cached worker whose messages differ from
its own, and plug-ins then fail to install and run until the browser fetches the new worker.
- **Content Security Policy:** a site that sends one needs `worker-src 'self'` for the plug-in
worker. Without `worker-src`, the browser uses `child-src`, then `script-src`, then
`default-src` ([CSP Level 3](https://www.w3.org/TR/CSP3/)), so a `script-src` that allows the
site's own scripts is enough only when the policy sets neither `worker-src` nor `child-src`.
When the policy blocks the worker, the app runs, and plug-ins fail to install and run.
- **Content Security Policy:** a site that sends one must allow three things
([CSP Level 3](https://www.w3.org/TR/CSP3/)):
- The inline `<script type="module">` that Trunk writes into `index.html` to start the app.
`script-src 'self'` alone blocks it, and the app does not start. A hash of that script
allows it, but the script changes with each build, so the hash must be taken from the
build you deploy.
- WebAssembly compilation: a `script-src` needs `'wasm-unsafe-eval'`, on the page and on the
plug-in worker files. Without it the app does not start, and plug-ins fail to install and
run.
- The plug-in worker: `worker-src 'self'`. Without `worker-src`, the browser uses
`child-src`, then `script-src`, then `default-src`, so a `script-src` that allows the
site's own scripts is enough only when the policy sets neither `worker-src` nor
`child-src`. When the policy blocks the worker, the app runs, and plug-ins fail to install
and run.
- **HTTPS:** WebGPU (and the clipboard) only work in a secure context, which means `https://`
or `http://localhost`. Over plain HTTP elsewhere, the app falls back to WebGL2.
- **No special isolation headers:** VectorCraft doesn't use `SharedArrayBuffer`, so it doesn't