v2.0.4 — re-auth on 401, robust bucket-switch test

- auth: when a background poll or save returns 401 (session expired
  while the UI is still open), the api() helpers now prompt for the
  password instead of letting the save fail silently. Concurrent 401s
  collapse onto a single dialog via a shared reauthPromise, and each
  caller retries its original request once after login. /api/auth/* is
  excluded from the retry path. Extracts promptLogin() in app.js and
  exposes it as window._reauth so both the core util.js api() and the
  plugin-SDK hyprcrd.js api() can share the flow.
- tests: the "open-switches-bucket" detail test assumed buckets[0] was
  a plain top-level bucket, but the bar renders super-bucket parents
  with data-bucket-super and hides child buckets entirely, so the
  .bucket-tab.active[data-bucket] selector found nothing on setups
  with nested layouts. Test now picks two plain top-level buckets or
  skips.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
thandClaude Opus 4.7 committed 2026-04-18 12:50:44 +02:00
1 parent 48b5907f4c
commit f986a41ccc
6 files changed
+76 -28

No files matched your search

+11 -2
View File
@@ -86,7 +86,17 @@ describe('Detail: open-switches-bucket', () => {
it('switches to the card bucket when the setting is on', async () => {
const buckets = await fetch('api/buckets').then(r => r.json());
if (!Array.isArray(buckets) || !buckets.length) return;
const b = buckets[0];
// The bucket bar renders top-level non-super buckets with
// `data-bucket=<id>`, super-bucket parents with `data-bucket-super`,
// and hides child buckets behind the parent's dropdown. To keep
// this test robust across different user bucket layouts, pick two
// plain top-level buckets (no children, no parent). Skip when the
// fixture doesn't give us two.
const childParentIds = new Set(buckets.filter(x => x.parent_id).map(x => x.parent_id));
const plainTop = buckets.filter(x => !x.parent_id && !childParentIds.has(x.id));
if (plainTop.length < 2) return;
const b = plainTop[0];
const other = plainTop[1];
const token = csrf();
const h = { 'Content-Type': 'application/json', 'X-CSRF-Token': token };
let card;
@@ -99,7 +109,6 @@ describe('Detail: open-switches-bucket', () => {
await sleep(100);
// Start on a DIFFERENT bucket so the switch is visible.
const other = buckets.length > 1 ? buckets[1] : buckets[0];
window.state.activeBucket = String(other.id);
// Enable the setting.