Apply app updates automatically and survive proxy caching
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 29s

- Check for a new service worker on every return to the foreground and
  every 30 minutes; apply it in the background or just after launch,
  never with unsynced edits or an open sheet. The Update prompt remains.
- Register the worker at extension-less /sw (no-cache), so proxies that
  cache *.js regardless of headers cannot hide updates
- Return 404 for missing files instead of the HTML shell
- Tests for the static routes; smoke test covers /sw; document the Nginx
  Proxy Manager "Cache Assets" pitfall

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-10-22 11:19:30 -07:00
parent bb0bc430aa
commit 8f6981c8a2
7 changed files with 190 additions and 40 deletions

View file

@ -174,3 +174,43 @@ test("login is rate limited", async (t) => {
429,
);
});
test("static app: uncacheable worker route, shell fallback for routes, 404 for missing files", async (t) => {
const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = await import("node:fs");
const { tmpdir } = await import("node:os");
const { join } = await import("node:path");
const dist = mkdtempSync(join(tmpdir(), "calio-dist-"));
mkdirSync(join(dist, "assets"));
writeFileSync(join(dist, "index.html"), "<!doctype html><title>Calio</title>");
writeFileSync(join(dist, "sw.js"), "const CACHE='calio-test';");
writeFileSync(join(dist, "assets", "index-abc.js"), "console.log(1)");
const store = openDatabase(":memory:");
const app = createApp({
store,
username: "test",
passwordHash: hashPassword(password),
origin,
secureCookies: false,
dist,
});
const server = app.listen(0, "127.0.0.1");
await new Promise((resolve) => server.once("listening", resolve));
t.after(() => {
server.close();
store.close();
rmSync(dist, { recursive: true, force: true });
});
const base = `http://127.0.0.1:${server.address().port}`;
const worker = await fetch(base + "/sw");
assert.equal(worker.status, 200);
assert.match(worker.headers.get("content-type"), /javascript/);
assert.equal(worker.headers.get("cache-control"), "no-cache");
assert.equal(await worker.text(), "const CACHE='calio-test';");
assert.equal((await fetch(base + "/sw.js")).status, 200);
assert.equal((await fetch(base + "/assets/index-abc.js")).status, 200);
const missing = await fetch(base + "/assets/index-old.js");
assert.equal(missing.status, 404);
assert.doesNotMatch(missing.headers.get("content-type"), /html/);
const route = await fetch(base + "/weight");
assert.equal(route.status, 200);
assert.match(await route.text(), /<title>Calio/);
});