Prove dell'interfaccia: un indirizzo rilasciato si può trattenere di nuovo

In UiBrowser.Requests la regola creata da __hold restava anche dopo
__release e valeva per prima: un secondo __hold dello stesso indirizzo
non tratteneva nulla, perché il fetch e __release trovavano sempre la
regola già rilasciata, e ogni richiesta successiva a quell'indirizzo
continuava a contare in __started e __done. Una prova che trattenesse due
volte la stessa risposta avrebbe lasciato la pagina a risposta già
arrivata, passando senza provare nulla (rilievo R2 della revisione;
nessuna prova di oggi lo fa).

Ora il rilascio toglie la regola: le richieste già trattenute tengono la
propria e contano come finite sotto il suo indirizzo, le successive
passano subito e non contano, e lo stesso indirizzo si può trattenere di
nuovo. Trattenerlo due volte insieme, o rilasciarlo due volte, è un
errore della prova e lo dice. Con una prova diagnostica solo locale:
prima «seconda trattenuta: passata», ora trattenuta, e started=2 done=2
invece di 3 e 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-21 12:36:44 +02:00
1 parent fe4ef9f048
commit 4b35178880
2 files changed
+11 -7

No files matched your search

+10 -6
View File
@@ -23,9 +23,11 @@ internal sealed class UiBrowser : IAsyncDisposable
/// <item><c>window.__busy()</c>: the requests not over yet. A fetch is over once the page's own continuation of
/// its answer has run, and the body it reads there (as api.js does) has arrived; a WebSocket once it is open or
/// closed. See <see cref="WaitForQuietAsync"/>.</item>
/// <item><c>window.__hold(match)</c> holds back every fetch whose address contains match until
/// <c>window.__release(match)</c>, also one the page aborts meanwhile; <c>window.__started[match]</c> counts the
/// held-back requests that started, <c>window.__done[match]</c> those that are over.</item>
/// <item><c>window.__hold(match)</c> holds back every fetch whose address contains match, from then until
/// <c>window.__release(match)</c>, also one the page aborts meanwhile. The release lets them go and ends the hold:
/// later requests pass at once, and the address can be held again (twice at the same time is an error).
/// <c>window.__started[match]</c> counts the held-back requests that started and <c>window.__done[match]</c>
/// those that are over, adding up all the holds of that address.</item>
/// </list>
/// An answer is late because the test holds it, never because of a delay the page might outlast on a slow machine:
/// the test waits until the page has asked (<c>__started</c>), does what has to come first, releases it, and
@@ -46,14 +48,16 @@ internal sealed class UiBrowser : IAsyncDisposable
window.__done = {};
window.__busy = () => busy;
window.__hold = (match) => {
if (holds.some((h) => h.match === match)) throw new Error(`richieste già trattenute per ${match}`);
let release;
holds.push({ match, gate: new Promise((resolve) => { release = resolve; }), release: () => release() });
return true;
};
// The requests held so far keep their hold and count as over under its match; the next ones pass.
window.__release = (match) => {
const hold = holds.find((h) => h.match === match);
if (!hold) throw new Error(`nessuna richiesta trattenuta per ${match}`);
hold.release();
const index = holds.findIndex((h) => h.match === match);
if (index < 0) throw new Error(`nessuna richiesta trattenuta per ${match}`);
holds.splice(index, 1)[0].release();
return true;
};
window.fetch = async (input, init) => {