Files
quiver-launcher/e2e/web/settings.test.js
T
CuddleBear92andClaude Opus 5.5 d38273b474 Cache: an opt-in download cache, to install again without downloading and to back up releases (#509)
* Cache: an opt-in download cache, to install again without downloading and to back up releases

A new Settings section, Cache, keeps the release files Quiver downloads, off
unless the player turns it on, in a folder of their choosing (by default
`cache` in the data folder, beside a portable copy). What it keeps:

- Installed only: each app's file as it installs; a newer version replaces
  the one before. Check now keeps the installed version of every app, and
  an app's menu has Cache now. Never downloads by itself otherwise.
- Selected titles: the newest release of the apps turned on from Manage on
  their pages or their menus, listed at the foot of the page with their
  pictures and the room they take, largest first.
- Every latest: the newest release of every app in the catalog.
- Hoarder: every release of every app, for archiving.

"Keep every system's files" keeps a release's builds for every system, not
only this computer's. Every latest and Hoarder warn of the storage and
bandwidth they take. The modes that download by themselves do it in the
background, one file at a time, a minute after the launcher starts and
every 6 hours, only what fits in the storage limit (5 GB to 1 TB, or
Unlimited), which rotates out the least recently used files but never one
of a version installed now. Clear orphans removes, when asked, the files of
apps no longer selected or installed.

An install takes its file from the cache when it's there, checked against
its SHA-256 first, so reinstalling or going back to a version works offline;
a cache that can't be read or written never fails an install. Files are kept
as `<app slug>/<version>/<file>` and never move, which an IPFS node could
later reference in place (Kubo's filestore); index.json knows each by its
SHA-256, keeps one copy of a file several apps share, and names a file whose
host gave it no extension for what's in it.

Downloads has a Download cache section: the file under way with its
progress and Stop, then what was kept or couldn't be, by app, version and
file. A fetch comes in as `.incoming/<app>/<version>/<file>`, so an
antivirus that flags it names the release; a file taken away as it
downloads shows as Removed by your antivirus, with Copy details for
reporting it. What a launcher closed mid-download leaves is cleared as it
starts.

Tests: cache.rs and install.rs (keeping, taking back checked, rotation,
Installed only, readable folders and moving older ones, a blocked fetch,
installing again from the cache with the host gone), cache.ts and
cache-fetch.ts, and settings.test.js's window for the list's ninth section.
The strings are translated in all 10 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G8hjgDXWjcy1WDZkgKpLqs

* Cache: install from it offline, and keep each app's source code

- Offline, an install (or Reinstall) no longer stops at "Couldn't reach
  quiverlauncher.com" when the download cache has the app: the launcher still
  asks the site first, as ever, and only when there's no answer goes by the
  versions the cache keeps (the catalog's verified one first, else the
  newest), each file checked against its SHA-256 before it goes in. The
  index now keeps each file's architecture, to pick the right build offline.
- "Keep source code" keeps, for each app the cache keeps, the source code of
  the release it keeps (the installed one, or the newest), as its host
  archives the tag: GitHub, GitLab, Gitea/Forgejo or Bitbucket, named
  `<repository>-<tag>-source.zip` beside its builds. There's no checksum to
  check it against, so it's kept by its own SHA-256, the app's latest alone.
  Release feeds have no such archive.

Tests: cache.rs and install.rs (source kept, latest alone, no checksum only
for source, architecture), cache.ts and cache-fetch.ts, and e2e
cache-offline.test.js: offline, an app installs from the cache's file of it;
with nothing kept, the site can't be reached as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G8hjgDXWjcy1WDZkgKpLqs

* Cache: each app's README kept, with its pictures, for its page while quiverlauncher.com can't be reached

An app's README comes from quiverlauncher.com (its copy of the project's,
`fetchedAt` when it last read it), else straight from its host; offline,
neither came, nor did its pictures, which load from the host. For the apps
the download cache keeps, it's now kept as `<cache>/<app>/readme.zip`, beside
its versions' folders: readme.json and the pictures it shows (images/), in
one zip written whole.

- Online, the page always shows the README as the site has it now, and keeps
  it in place of the copy before when it changed (its text and the addresses
  its paths resolve against, by SHA-256). The cache's runs keep it too.
- Only when the site can't be reached at all (not when it has none), the page
  shows the copy kept, its pictures from the zip, under a note that it's the
  copy saved on its date.
- It goes with the app's last file, and with Clear cache; a README cut off as
  it was written is cleared as the launcher starts. At most 40 pictures, 10 MB
  each and 50 MB in all.

packages/ui's Markdown takes `images` (pictures to show in place of those the
README links to) and exports readmeImages (the pictures it shows, resolved);
both optional, so the website's pages are as they were.

Tests: cache.rs (kept beside the versions, read back with its pictures, kept
again when it changes, gone with the app), markdown.test.tsx, cache.ts and
cache-fetch.ts, and e2e cache-offline.test.js: online the site's README,
kept; offline the copy, with its picture and the note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G8hjgDXWjcy1WDZkgKpLqs

* Put the translations back in the order lingui extract writes them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015HpW13GV1ZRn9GXkNWTbiG

* Cache: say a download failed as it did, not that an antivirus removed it

A cache fetch said "blocked" (Removed by your antivirus) whenever its file wasn't
there after an error, which is also true of every failure before the file is
written: a 404, a refusal, no connection. Now only a file that was there and
went as it came is blocked; the rest say why, as an install does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015HpW13GV1ZRn9GXkNWTbiG

* Cache: a newer release takes the place of an app's older one in Every latest and Selected titles

These modes never let an app's older versions go, and a fetch never makes room,
so once the cache was full each new release was left out as not fitting and the
cache kept old builds. Now the app's older files make room for its newest and go
once it's in, never a file another app or version shares, nor one installed now.
Hoarder still keeps every version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015HpW13GV1ZRn9GXkNWTbiG

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-22 18:39:29 +11:00

239 lines
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Settings and Downloads with a controller, and the library's background Settings chooses. (controller.js has what these share.)
*/
import { test } from "node:test";
import assert from "node:assert/strict";
import { openApp } from "./app.js";
import { app, back, everything, installed, open, page, pause, s, where, useSharedApp } from "./controller.js";
import * as reach from "../reach.js";
useSharedApp();
test("into Settings' list from the section beside it, the d-pad lands on the section open", async () => {
await page.locator(".topbar button[aria-label='Settings']").click();
await page.locator(".settings-nav").waitFor();
await page.locator('.settings-nav [data-section="updates"]').click();
await pause(100);
await reach.pressOn(app, ".settings-pane button, .settings-pane input, .settings-pane select", "DPadLeft");
assert.equal(await app.execute(() => document.activeElement?.getAttribute("data-section")), "updates");
});
test("the player's picture shows behind the library's grid and nowhere else, and Settings chooses it", async () => {
const picture = "/home/player/Pictures/wall.png";
const s2 = await openApp({ state: { ...installed, pickBackground: picture } });
const { page: p, app: a } = s2;
const behind = p.locator(".library-background img");
const settingsOpen = async (name) => {
await p.locator(".topbar button[aria-label='Settings']").click();
await p.locator(".settings-nav button", { hasText: name }).first().click();
};
try {
await p.locator(".library-grid").waitFor();
assert.equal(await behind.count(), 0, "none until the player chooses one");
await settingsOpen("Library");
const setting = p.locator('section[aria-label="Library background"]');
await setting.waitFor();
await reach.install(a);
assert.doesNotMatch(await reach.pressOn(a, 'section[aria-label="Library background"] button', "South", { text: "Choose a picture…" }), /^not reached/);
await setting.getByText("wall.png").waitFor();
const preview = setting.locator(".background-preview img");
await preview.waitFor();
await setting.locator('input[type="range"]').fill("60");
await s2.until(() => preview.evaluate((i) => i.style.opacity === "0.6"));
await s2.page.locator(".topbar nav button", { hasText: "Library" }).click();
await behind.waitFor({ state: "attached" });
assert.equal(await behind.evaluate((i) => i.style.opacity), "0.6");
const placed = await behind.evaluate((i) => {
const bar = document.querySelector(".topbar").getBoundingClientRect();
const card = document.querySelector(".library-tile").getBoundingClientRect();
const box = i.getBoundingClientRect();
return { wide: box.width === innerWidth, tall: box.height === innerHeight, shown: i.naturalWidth > 0, overBar: document.elementFromPoint(bar.x + bar.width / 2, bar.y + bar.height / 2) === i, overCard: document.elementFromPoint(card.x + card.width / 2, card.y + card.height / 2) === i };
});
assert.deepEqual(placed, { wide: true, tall: true, shown: true, overBar: false, overCard: false });
const scroller = p.locator(".shell > main");
await scroller.evaluate((m) => m.scrollTo(0, 200));
assert.equal(await behind.evaluate((i) => i.getBoundingClientRect().y), 0, "stays put as the cards scroll");
await p.locator(".topbar nav button", { hasText: "Browse" }).click();
await behind.waitFor({ state: "detached" });
await p.locator(".topbar nav button", { hasText: "Library" }).click();
await behind.waitFor({ state: "attached" });
await p.locator(".library-tile").first().click();
await p.locator(".app-page").first().waitFor();
assert.equal(await behind.isVisible(), false, "not behind an app's page");
await reach.press(a, "East");
await behind.waitFor();
await settingsOpen("Library");
await setting.locator("button", { hasText: "Remove" }).click();
await setting.locator("button", { hasText: "Choose a picture…" }).waitFor();
await p.locator(".topbar nav button", { hasText: "Library" }).click();
await p.locator(".library-grid").waitFor();
assert.equal(await behind.count(), 0);
} finally {
await s2.close();
}
// The List layout keeps its own background, with the picture still chosen for the grid.
const s3 = await openApp({ state: { ...installed, settings: { libraryBackground: picture, library: { layout: "sidebar" } } } });
try {
await s3.page.locator(".library-split").waitFor();
assert.equal(await s3.page.locator(".library-background").count(), 0);
} finally {
await s3.close();
}
// A file moved or deleted since: Settings says so, and the library goes on without it.
const s4 = await openApp({ state: { ...installed, settings: { libraryBackground: "/home/player/Pictures/missing.png" } } });
try {
await s4.page.locator(".library-grid").waitFor();
assert.equal(await s4.page.locator(".library-background").count(), 0);
await s4.page.locator(".topbar button[aria-label='Settings']").click();
await s4.page.locator(".settings-nav button", { hasText: "Library" }).first().click();
await s4.page.getByText("Quiver couldn't show that picture.", { exact: false }).waitFor();
} finally {
await s4.close();
}
});
test("Settings' list stays on the screen as the page scrolls, in a window with just room for it", async () => {
// Room for the list's nine sections, and little more: 43 pixels a section.
const s2 = await openApp({ state: installed, height: 477 });
try {
await s2.page.locator(".topbar").waitFor();
await s2.page.locator(".topbar button[aria-label='Settings']").click();
await s2.page.locator(".settings-nav").waitFor();
for (const section of ["general", "updates"]) {
await s2.page.locator(`.settings-nav [data-section="${section}"]`).click();
await pause(100);
const over = await s2.app.execute(() => {
const main = document.querySelector(".shell > main");
const list = document.querySelector(".settings-nav");
main.scrollTop = main.scrollHeight;
return [list.getBoundingClientRect().top - main.getBoundingClientRect().top, main.clientHeight - list.offsetHeight];
});
assert.ok(over[1] >= 0, "the window has room for all of it");
assert.ok(over[0] >= 0, `${section}: ${over[0]}px from the top`);
}
} finally {
await s2.close();
}
});
test("Downloads, and every section of Settings", async () => {
assert.equal(await open('button[aria-label="Downloads"]'), "page: Downloads");
await everything("Downloads");
assert.equal(await back(), "main");
assert.equal(await open('button[aria-label="Settings"]'), "page: Settings");
const sections = await app.execute(() => [...document.querySelectorAll('nav[aria-label="Settings sections"] button')].map((b) => b.innerText.trim()));
for (const name of sections) {
await open('nav[aria-label="Settings sections"] button', { text: name });
await everything(`Settings › ${name}`);
}
});
test("tags open in a window of their own, which a controller gets all around, both tabs, ticks in and leaves", async () => {
assert.equal(await open('button[aria-label="Settings"]'), "page: Settings");
await open('nav[aria-label="Settings sections"] button', { text: "Library" });
assert.equal(await open('section[aria-label="Tags"] button', { text: "Manage tags" }), "dialog: Manage tags");
await everything("Manage tags › Your tags");
await reach.pressOn(app, '[role="tab"]', "South", { text: "From the catalog" });
await s.until(() => app.execute(() => Boolean(document.querySelector('[role="dialog"] .catalog-tag'))));
await everything("Manage tags › From the catalog");
const box = '[role="dialog"] .catalog-tag input';
assert.equal(await app.execute((b) => document.querySelector(b).checked, box), true);
assert.doesNotMatch(await reach.pressOn(app, box, "South"), /^not reached/);
await s.until(() => app.execute((b) => !document.querySelector(b).checked, box));
await reach.press(app, "South");
await s.until(() => app.execute((b) => document.querySelector(b).checked, box));
assert.equal(await back(), "page: Settings");
});
test("a controller rebinds a control with its own buttons", async () => {
const binding = 'button[aria-label="Confirm / Select: controller"]';
assert.equal(await open('button[aria-label="Settings"]'), "page: Settings");
await open('nav[aria-label="Settings sections"] button', { text: "Controllers" });
await open(binding);
assert.equal(await app.execute((b) => document.querySelector(b).innerText, binding), "Press a button…");
await reach.press(app, "West");
assert.equal(await app.execute((b) => document.querySelector(b).innerText, binding), "X");
// X is Confirm now: it rebinds it back to A.
await app.execute((b) => document.querySelector(b).focus(), binding);
await reach.press(app, "West");
await reach.press(app, "South");
assert.equal(await app.execute((b) => document.querySelector(b).innerText, binding), "A");
// Swap A and B, with the controller: A swaps them, and then it's B that confirms, so B swaps them back.
const cells = () => app.execute(() => ["Confirm / Select", "Cancel / Back"].map((a) => document.querySelector(`button[aria-label="${a}: controller"]`).innerText));
await app.execute(() => [...document.querySelectorAll(".controls label.toggle")].find((l) => l.innerText.startsWith("Swap ")).querySelector("input").focus());
await reach.press(app, "South");
await s.until(async () => (await cells()).join() === "B,A");
await reach.press(app, "East");
await s.until(async () => (await cells()).join() === "A,B");
});
test("Settings turns off closing a game with Start + Select, and chooses other buttons for it", async () => {
const s2 = await openApp({ state: installed });
const { page: p } = s2;
const last = () => p.evaluate(() => window.__calls.filter((c) => c.cmd === "close_combo").at(-1)?.args);
try {
// On from the start.
await s2.until(async () => (await last())?.on === true);
await p.locator(".topbar button[aria-label='Settings']").click();
await p.locator(".settings-nav button", { hasText: "Controllers" }).first().click();
const toggle = p.locator(".controls label.toggle", { hasText: "Close a game" }).locator("input");
const buttons = p.locator(".controls .close-combo select");
const saved = () => p.evaluate(() => window.__calls.filter((c) => c.cmd === "write_state" && c.args.name === "settings").at(-1)?.args.value);
assert.equal(await toggle.isChecked(), true);
assert.equal(await buttons.inputValue(), "Start+Select");
// Other buttons: the sticks pressed in.
await buttons.selectOption("LeftThumb+RightThumb");
await s2.until(async () => (await last())?.buttons?.join() === "LeftThumb,RightThumb");
assert.deepEqual((await saved()).closeCombo, ["LeftThumb", "RightThumb"]);
await toggle.uncheck();
await s2.until(async () => (await last())?.on === false);
assert.equal((await saved()).closeComboOff, true);
assert.equal(await buttons.isDisabled(), true);
} finally {
await s2.close();
}
});
test("Advanced Settings takes a GitLab token, keeps it in the keychain, and shows what it allows", async () => {
const s2 = await openApp({ state: installed });
const { page: p } = s2;
try {
await p.locator(".topbar button[aria-label='Settings']").click();
await p.locator('.settings-nav [data-section="advanced"]').click();
const setting = p.locator('section[aria-label="GitLab token"]');
await setting.waitFor();
// Without one, the mock allows fewer requests, and says how many are left.
await setting.getByText(/499 of 500 requests left/).waitFor();
await setting.locator('input[type="password"]').fill("glpat-test");
await setting.getByRole("button", { name: "Save token" }).click();
await setting.getByText("Saved. Requests to GitLab use your token now.").waitFor();
// The token was kept in the keychain, not in settings.json: with every host's, under its own host.
assert.deepEqual(
await p.evaluate(() => window.__calls.find((c) => c.cmd === "secret_set")?.args),
{ key: "repositoryTokens", value: JSON.stringify({ "gitlab.com": "glpat-test" }) },
);
// It went with the request that checked it, and the mock's higher limit shows.
assert.ok(s2.api.gitlabRequests().some((r) => r.path === "/gitlab/user" && r.token === "glpat-test"));
await setting.getByText(/1,999 of 2,000 requests left/).waitFor();
} finally {
await s2.close();
}
});
test("A on a dropdown on a page opens its options, and B closes them without going back a page", async () => {
assert.equal(await open('button[aria-label="Settings"]'), "page: Settings");
await open('nav[aria-label="Settings sections"] button', { text: "General" });
assert.doesNotMatch(await reach.pressOn(app, ".settings-pane select", "South"), /^not reached/);
assert.ok((await page.locator(".select-picker").count()) > 0, "A opens the list");
await reach.press(app, "East");
assert.ok(!(await page.locator(".select-picker").count()), "B closes the list");
assert.equal(await where(), "page: Settings", "and the page stays");
assert.match(await reach.focused(app), /^select /);
});