From 3719adc2d9d6365acda0d9dcfa21f0e013fc3668 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Tue, 20 Oct 2026 20:33:33 +0200 Subject: [PATCH] Libreria: lo stato vuoto segue il collegamento anche quando il motore risponde dopo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La Libreria vuota sceglieva una volta sola, alla risposta di /api/library/days, fra il benvenuto del primo avvio (§10.3: Febe non collegato, i due pulsanti) e «La libreria è ancora vuota», guardando lo stato del motore in quel momento. Se /api/engine (o il primo evento del flusso) arrivava dopo, lo stato era ancora sconosciuto: il primo avvio mostrava la libreria vuota e ci restava, anche dopo che il motore aveva detto «non collegato». Provato con Chrome trattenendo la risposta del motore. È un difetto a sé, trovato mentre si cercava la causa dell'issue #5, e non è fra le cause di quel fallimento: nella prova del pulsante Indietro lo stato del motore è già noto quando la Libreria si ridisegna, e quella prova passa anche senza questa correzione. Ora lo stato vuoto senza filtri segue il motore finché è sullo schermo: diventa il benvenuto quando si sa che Febe non è collegato e torna «La libreria è ancora vuota» quando si collega. Si ridisegna solo quando cambia tipo, così il fuoco su un pulsante del benvenuto non si perde a ogni evento. Il benvenuto è lo stesso di prima: confrontato con docs/schermate/primo-avvio.png. Nuova prova TheEmptyLibraryFollowsTheConnectionAlsoWhenTheEngineAnswersLate: trattiene /api/engine fino a un segnale e toglie EventSource; sul codice di prima fallisce. Co-Authored-By: Claude Opus 5.5 --- docs/decisioni.md | 1 + src/Febe.Web/wwwroot/js/pages/library.js | 30 ++++++++++++---- tests/Febe.Tests/Web/InterfaceTests.cs | 45 +++++++++++++++++++++++- 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/docs/decisioni.md b/docs/decisioni.md index 1b2a08a..ae37d5c 100644 --- a/docs/decisioni.md +++ b/docs/decisioni.md @@ -277,3 +277,4 @@ Ogni scelta tecnica presa strada facendo, con data e motivo (specifica §15). | 2026-10-20 | I file di `.vscode/` sono JSON rigido, senza commenti: le spiegazioni stanno nella guida (pagina «Sviluppo», «Da VS Code»), nei campi `detail` delle attività e in queste righe | Il controllo «File JSON» della CI legge ogni `*.json` tracciato con `JSON.parse`, e con i commenti `//` il lavoro «controlli» falliva a ogni push dopo l'unione. VS Code legge anche il JSON rigido, così il ramo non dipende da come la CI tratta i commenti | | 2026-10-20 | `src/Febe.Desktop/Properties/launchSettings.json` con un solo profilo, «Sito di prova»: `--dati` e `--libreria` in `%USERPROFILE%\FebeSviluppo\comune`, `--sito-di-prova http://127.0.0.1:8481 --accesso-di-prova --prima-sessione 30 --sviluppo` | `dotnet run --project src/Febe.Desktop` e i comandi del C# Dev Kit (▷ «Debug project associated with this file», «Start New Instance», «C#: …») avviavano Febe senza opzioni: Instagram vero e dati veri, senza la conferma della configurazione ⚠. `dotnet run` e il Dev Kit leggono quel profilo ed espandono `%USERPROFILE%` (provato); se un altro strumento non lo facesse, Febe rifiuta il percorso non completo e non parte. Una cartella comune perché il file non conosce il checkout. Instagram vero dal terminale: `dotnet run --project src/Febe.Desktop --no-launch-profile` | | 2026-10-20 | Le prove dell'interfaccia aspettano lo stato finale di una pagina, mai uno di passaggio come il mosaico vuoto che la Libreria mette sullo schermo prima della risposta di `/api/library/days` | Issue #5: `TheBackButtonAsksBeforeLosingUnsavedChanges` aspettava `.vuoto-pagina` o `.mosaico`, ma una libreria vuota con Febe non collegato finisce sul benvenuto; la prova passava solo se il primo controllo cadeva nei circa 10 ms in cui c'è il mosaico vuoto (provato con Chrome: con il primo controllo ritardato di 5 ms o più falliva sempre) | +| 2026-10-20 | Lo stato vuoto della Libreria senza filtri segue il collegamento finché è sullo schermo: se il motore risponde dopo la libreria, «La libreria è ancora vuota» diventa il benvenuto del primo avvio; quando Febe si collega, il benvenuto lascia il posto alla libreria vuota. Si ridisegna solo quando cambia tipo. La prova trattiene `/api/engine` fino a un suo segnale e toglie `EventSource` (l'interfaccia ripiega su `/api/engine`) | Prima la scelta si faceva una volta sola, alla risposta della libreria: con il motore in ritardo il primo avvio mostrava la libreria vuota invece dei due pulsanti di §10.3, e ci restava (provato con Chrome trattenendo `/api/engine`). Un segnale invece di un ritardo: l'ordine delle risposte non dipende dalla velocità della macchina | diff --git a/src/Febe.Web/wwwroot/js/pages/library.js b/src/Febe.Web/wwwroot/js/pages/library.js index 066ab8e..a46137d 100644 --- a/src/Febe.Web/wwwroot/js/pages/library.js +++ b/src/Febe.Web/wwwroot/js/pages/library.js @@ -323,6 +323,29 @@ export default { } } + // The empty state: no results of a filter, the first start (spec §10.3: not connected, the two ways to begin) or an + // empty library. Whether Febe is connected comes with the engine, which may answer after the library: the empty + // state follows it while it is on screen, and is drawn again only when it changes kind. + let empty = null; + function drawEmpty() { + const kind = filtersActive() ? 'filtro' : notConnected() ? 'benvenuto' : 'vuota'; + if (empty && empty.kind === kind && empty.node.isConnected) return; + let node; + if (kind === 'filtro') { + node = h('div.vuoto-pagina', icon('list-filter'), h('h2', t('libreria.nessuno')), h('p', t('libreria.nessunoTesto')), + h('button.btn', { type: 'button', onclick: () => { Object.assign(state, readState(new URLSearchParams())); search.value = ''; apply(); } }, t('libreria.togliFiltri'))); + } else if (kind === 'benvenuto') { + node = welcome(); + } else { + node = h('div.vuoto-pagina', icon('image'), h('h2', t('libreria.vuota')), h('p', t('libreria.vuotaTesto'))); + } + fill(host, node); + empty = { kind, node }; + } + page.onEngine(() => { + if (empty && empty.node.isConnected) drawEmpty(); + }); + // The mosaic. async function apply() { setQuery({ @@ -347,12 +370,7 @@ export default { onOpen: (tile) => openViewer({ tile, source: mosaic, origin: t('libreria.titolo'), onDeleted: (ids) => mosaic.removeTiles(ids) }), onSelection: drawSelection, onTotals: ({ entries, accounts: n }) => page.count(t('libreria.quanti', { elementi: t('comune.elementi', { n: entries }), account: t('comune.account', { n }) })), - onEmpty: () => fill(host, filtersActive() - ? h('div.vuoto-pagina', icon('list-filter'), h('h2', t('libreria.nessuno')), h('p', t('libreria.nessunoTesto')), - h('button.btn', { type: 'button', onclick: () => { Object.assign(state, readState(new URLSearchParams())); search.value = ''; apply(); } }, t('libreria.togliFiltri'))) - : notConnected() - ? welcome() - : h('div.vuoto-pagina', icon('image'), h('h2', t('libreria.vuota')), h('p', t('libreria.vuotaTesto')))), + onEmpty: drawEmpty, }); try { await mosaic.start(); diff --git a/tests/Febe.Tests/Web/InterfaceTests.cs b/tests/Febe.Tests/Web/InterfaceTests.cs index 58e1ae4..0024cf5 100644 --- a/tests/Febe.Tests/Web/InterfaceTests.cs +++ b/tests/Febe.Tests/Web/InterfaceTests.cs @@ -20,7 +20,8 @@ namespace Febe.Tests.Web; /// The interface itself in a real (headless) Chromium against a test server: what only shows when the scripts run. /// The «driving» lease of the Browser and Collegamento pages (spec §4.1, §10.3: the engine is still only while Alberto /// uses the browser), the remote view's keyboard and mouse, the mosaic and the account card when filters change, -/// the unsaved-changes guard on the browser's Back button, the window bar of Limiti, the sidebar status box. +/// the empty library that follows the connection, the unsaved-changes guard on the browser's Back button, the window +/// bar of Limiti, the sidebar status box. /// [TestClass] [DoNotParallelize] @@ -30,6 +31,25 @@ public sealed class InterfaceTests private static readonly ConnectionStatus Verification = new(ConnectionState.VerificationRequired, "tuo.profilo", "Il tuo profilo", false, "https://www.instagram.com/challenge/"); + /// + /// Installed before the page scripts: the answer of /api/engine waits until window.__releaseEngine(), + /// and without the event stream (the interface then asks /api/engine) nothing brings the engine sooner. + /// + private const string HoldEngine = """ + (() => { + const original = window.fetch.bind(window); + let release; + const gate = new Promise((resolve) => { release = resolve; }); + window.__releaseEngine = () => { release(); return true; }; + window.fetch = async (input, init) => { + const url = typeof input === 'string' ? input : input.url; + if (url.includes('/api/engine')) await gate; + return original(input, init); + }; + delete window.EventSource; + })(); + """; + // ------------------------------------------------------------------------------------------ the driving lease [TestMethod] @@ -362,6 +382,29 @@ public sealed class InterfaceTests await ui.WaitAsync("document.querySelector('main .mosaico .tess') !== null", "tessere disegnate"); } + [TestMethod] + public async Task TheEmptyLibraryFollowsTheConnectionAlsoWhenTheEngineAnswersLate() + { + await using var server = await WebTestServer.StartAsync(); + await using var ui = await UiBrowser.StartAsync(); + await ui.AddInitScriptAsync(HoldEngine); + await ui.OpenAsync(new Uri(server.Address, "/libreria")); + + // The library answered first: nothing says yet whether Febe is connected. + await ui.WaitAsync("document.querySelector('main .vuoto-pagina') !== null", "libreria vuota prima del motore"); + Assert.IsTrue((await ui.EvalAsync("import('/js/core/engine.js').then((m) => m.engineState() === null)")).GetBoolean(), "the engine has not answered yet"); + + // Not connected (no own account): the first start with its two ways to begin (spec §10.3). + await ui.EvalAsync("window.__releaseEngine()"); + await ui.WaitAsync("document.querySelector('main .benvenuto') !== null && document.querySelector('main .vuoto-pagina') === null", "primo avvio dopo la risposta del motore"); + + // Connected now (the own account is known): the welcome gives way to the empty library. + await server.Db.Accounts.AddAsync(Make.Account("tuo.profilo", mine: true)); + await ui.EvalAsync("import('/js/core/engine.js').then((m) => m.refreshEngine()).then(() => true)"); + await ui.WaitAsync("document.querySelector('main .benvenuto') === null && document.querySelector('main .vuoto-pagina h2') !== null", "libreria vuota da collegato"); + Assert.AreEqual("La libreria è ancora vuota", (await ui.EvalAsync("document.querySelector('main .vuoto-pagina h2').textContent")).GetString()); + } + [TestMethod] public async Task TheAccountHeaderFollowsEveryMenuAction() {