Sessione salvata: copia alla chiusura della finestra e alla fine della guida, «Serve «Ho finito»», scelta per la copia incompleta e stato in Collegamento (#36, S4b)
Risposte 1, 5, 6, 9 e 10 di Alberto a S4. I valori __spin_r, __spin_b e __spin_t si copiano dalla pagina come gli altri (su Instagram da SiteData, ipotesi H23, operazioni ancora non configurate; nel sito di prova dal modulo GiroProva). La sessione si copia anche quando si chiude la finestra del browser su Windows e quando il permesso di guida finisce, sempre prima che la pagina torni al motore e con le garanzie di «Ho finito». Con «richieste» «Collegato» vuole una sessione salvata leggibile, altrimenti lo stato è «Serve «Ho finito»» e il motore aspetta. Nuova impostazione sessione.copia-incompleta (sostituisci, predefinita, o tieni-completa) e riquadro della sessione salvata nella pagina Collegamento, con soli conteggi e nomi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9958745e53
commit
883ea4683c
41 files changed
+1349
-101
No files matched your search
@@ -289,6 +289,101 @@ public sealed class SessionCaptureTests
|
||||
AssertNoSecret(string.Join("\n", log));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task KeepTheCompleteCopyKeepsTheSavedOneOnlyWhenItIsCompleteAndTheNewOneLacksWhatTheRequestsNeed()
|
||||
{
|
||||
// Answer 9 of 18 November 2026: «tieni la completa» is a choice; «sostituisci» stays the default.
|
||||
var log = new List<string>();
|
||||
var store = new InMemorySiteSession(null);
|
||||
var choice = IncompleteCopyChoice.KeepComplete;
|
||||
BrowserSessionCopier Copier(JsonObject page) =>
|
||||
new(Page($"http://{SiteHost}/", page: page), Plan, store, new VirtualClock(), log.Add) { IncompleteCopy = _ => Task.FromResult(choice) };
|
||||
var lacking = PageValues();
|
||||
((JsonObject)lacking["values"]!).Remove("lsd");
|
||||
|
||||
// Nothing saved yet: the incomplete copy is saved all the same (there is no complete one to keep).
|
||||
Assert.AreEqual(SessionCopyStatus.Saved, (await Copier(lacking).CopyAsync(() => true, CancellationToken.None)).Status);
|
||||
var incomplete = store.Read()!;
|
||||
|
||||
// An incomplete saved copy is not one to keep: the next incomplete copy replaces it.
|
||||
Assert.AreEqual(SessionCopyStatus.Saved, (await Copier(lacking).CopyAsync(() => true, CancellationToken.None)).Status);
|
||||
Assert.AreNotEqual(incomplete.Capture, store.Read()!.Capture);
|
||||
|
||||
// A complete copy, then an incomplete one: the complete one stays, and the outcome says so.
|
||||
Assert.AreEqual(SessionCopyStatus.Saved, (await Copier(PageValues()).CopyAsync(() => true, CancellationToken.None)).Status);
|
||||
var complete = store.Read();
|
||||
var kept = await Copier(lacking).CopyAsync(() => true, CancellationToken.None);
|
||||
Assert.AreEqual(SessionCopyStatus.KeptComplete, kept.Status);
|
||||
Assert.IsFalse(kept.Saved);
|
||||
Assert.AreEqual(1, kept.MissingValues);
|
||||
Assert.AreSame(complete, store.Read(), "the saved session stays as it was");
|
||||
StringAssert.Contains(log[^1], "resta la copia completa salvata prima");
|
||||
StringAssert.Contains(log[^1], "mancano lsd");
|
||||
|
||||
// A complete new copy always replaces it.
|
||||
Assert.AreEqual(SessionCopyStatus.Saved, (await Copier(PageValues()).CopyAsync(() => true, CancellationToken.None)).Status);
|
||||
Assert.AreNotSame(complete, store.Read());
|
||||
complete = store.Read();
|
||||
|
||||
// With «sostituisci» the incomplete copy replaces the complete one, as in S4.
|
||||
choice = IncompleteCopyChoice.Replace;
|
||||
Assert.AreEqual(SessionCopyStatus.Saved, (await Copier(lacking).CopyAsync(() => true, CancellationToken.None)).Status);
|
||||
Assert.AreNotSame(complete, store.Read());
|
||||
Assert.IsFalse(store.Read()!.Fields.ContainsKey("lsd"), "missing, never guessed");
|
||||
AssertNoSecret(string.Join("\n", log));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheReportCountsAndNamesWhatTheSavedSessionHoldsAndNeverAValue()
|
||||
{
|
||||
var store = new InMemorySiteSession(null);
|
||||
var clock = new VirtualClock();
|
||||
var page = PageValues();
|
||||
((JsonObject)page["values"]!).Remove("hsi");
|
||||
((JsonObject)page["docIds"]!).Remove("ProvaProfiloQuery");
|
||||
var copier = new BrowserSessionCopier(Page($"http://{SiteHost}/", page: page), Plan, store, clock, _ => { });
|
||||
|
||||
var none = copier.Report();
|
||||
Assert.AreEqual(SavedSessionState.None, none.State);
|
||||
Assert.AreEqual(SavedSessionState.None, copier.SavedState);
|
||||
Assert.IsFalse(none.Complete);
|
||||
Assert.IsNull(none.CopiedAt);
|
||||
Assert.AreEqual(Plan.Values.Count, none.ValuesExpected);
|
||||
Assert.AreEqual(0, none.ValuesPresent);
|
||||
|
||||
await copier.CopyAsync(() => true, CancellationToken.None);
|
||||
var report = copier.Report();
|
||||
Assert.AreEqual(SavedSessionState.Present, report.State);
|
||||
Assert.AreEqual(SavedSessionState.Present, copier.SavedState);
|
||||
Assert.AreEqual(clock.Now, report.CopiedAt);
|
||||
Assert.AreEqual(3, report.Cookies);
|
||||
Assert.AreEqual(Plan.Values.Count - 1, report.ValuesPresent);
|
||||
Assert.AreEqual(14, report.ValuesExpected, "the page values of the test catalog, spin_r, spin_b and spin_t among them");
|
||||
CollectionAssert.AreEqual(new[] { "hsi" }, report.MissingValues.ToArray());
|
||||
Assert.AreEqual(0, report.DocIdsPresent);
|
||||
CollectionAssert.AreEqual(new[] { "ProvaProfiloQuery" }, report.MissingDocIds.ToArray());
|
||||
Assert.AreEqual(2, report.NeededMissing, "the configured GraphQL query sends both");
|
||||
Assert.IsFalse(report.Complete);
|
||||
AssertNoSecret(report.ToString());
|
||||
AssertNoSecret(string.Join(",", report.MissingValues.Concat(report.MissingDocIds)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheSpinValuesAreCopiedFromTheirModuleLikeTheOtherValuesOfThePage()
|
||||
{
|
||||
// Decision of 18 November 2026: __spin_r, __spin_b, __spin_t are a snapshot of the page at «Ho finito».
|
||||
var store = new InMemorySiteSession(null);
|
||||
await new BrowserSessionCopier(Page($"http://{SiteHost}/"), Plan, store, new VirtualClock(), _ => { }).CopyAsync(() => true, CancellationToken.None);
|
||||
var saved = store.Read()!;
|
||||
Assert.AreEqual("1001", saved.Fields["spin_r"]);
|
||||
Assert.AreEqual("ramo", saved.Fields["spin_b"]);
|
||||
Assert.AreEqual("1700000000", saved.Fields["spin_t"]);
|
||||
var script = SessionCaptureScript.Build(Plan);
|
||||
StringAssert.Contains(script, "read(\"GiroProva\", \"revisione\")");
|
||||
StringAssert.Contains(script, "read(\"GiroProva\", \"tempo\")");
|
||||
Assert.DoesNotContain("SiteData", script, "the test site's own module names, never Instagram's");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(20_000, CooperativeCancellation = true)]
|
||||
public async Task ABrowserThatDoesNotAnswerIsABrowserErrorAfterTheTimeout()
|
||||
@@ -382,6 +477,9 @@ public sealed class SessionCaptureTests
|
||||
["comet_req"] = "7",
|
||||
["ccg"] = "BUONA",
|
||||
["entry_nonce"] = "nonce-segreto",
|
||||
["spin_r"] = "1001",
|
||||
["spin_b"] = "ramo",
|
||||
["spin_t"] = "1700000000",
|
||||
["estraneo"] = "non chiesto",
|
||||
},
|
||||
["docIds"] = new JsonObject { ["ProvaProfiloQuery"] = "9000000000000009", ["AltraQuery"] = "1" },
|
||||
|
||||
Reference in new issue
Block a user