Le 14 osservazioni della revisione di funzione/senza-terzi, ciascuna con la prova che l'avrebbe trovata. Installatore: un aggiornamento senza /D= va nella cartella già installata (InstallLocation) invece che in quella predefinita, che lasciava la vecchia copia. Una cartella senza permessi non sembra più «Febe aperto». La dimensione in «App installate» conta solo i due file dell'installatore. I file in sola lettura si sostituiscono e si tolgono. «Febe» in Esegui all'avvio si toglie solo se avvia quella copia, non un Febe portatile. Febe parte alla fine solo con «Fine» e la casella spuntata. /PROVA= rifiuta la radice di un disco. CI: jq non c'era ed era un componente esterno. JSON letto e scritto con .gitea/scripts/json.sh (json-campi.awk e json-stringa.awk sul lettore json.awk) per gitleaks, Trivy e la release. Le credenziali del registro stanno solo in un DOCKER_CONFIG temporaneo della pubblicazione, con plugin, contesti e contesto corrente del runner, tolto alla fine. Le prove del rilascio girano in debian:trixie con Chromium, come la verifica, senza prove saltate. Ogni flusso usa shell: bash. Caratteri: tolti fonts-liberation e fonts-noto-color-emoji dall'immagine e dalle prove della CI, perché Chromium non li chiede. Resta fonts-dejavu-core. Icone: la prova della griglia legge davvero i percorsi SVG (tutti i comandi, archi e curve) e i punti. La lettura dei nomi delle icone vede ogni forma con cui l'interfaccia li chiede. Schermate: tools/schermate (Node) diventa tools/Febe.Schermate, in C# con ClientWebSocket e System.Text.Json, nessun pacchetto, solo verso indirizzi di questo computer. Provato contro una dimostrazione con Edge su Windows. Documenti: CLAUDE.md, processo, guida, LEGGIMI e docker.md aggiornati. Righe nuove in decisioni.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
145 lines
7.4 KiB
C#
145 lines
7.4 KiB
C#
using System.Text.Json;
|
|
using System.Text.RegularExpressions;
|
|
using Febe.Schermate;
|
|
using Febe.Tests.Desktop.Support;
|
|
|
|
namespace Febe.Tests.Web;
|
|
|
|
/// <summary>
|
|
/// The screenshot tool of spec §10.7 (tools/Febe.Schermate), written in C# like the rest (Alberto's decision of
|
|
/// 18 November 2026: no Node, no third-party programs): only Febe's own interface on this computer, every screenshot of
|
|
/// docs/schermate and nothing else.
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed partial class ScreenshotToolTests
|
|
{
|
|
[TestMethod]
|
|
public void OnlyFebeOnThisComputerIsPhotographed()
|
|
{
|
|
foreach (var address in new[] { "http://127.0.0.1:8490/libreria", "http://localhost:8480/", "http://[::1]:8480/account", "https://127.0.0.1:8443/" })
|
|
{
|
|
Assert.IsTrue(Shots.IsOnThisComputer(new Uri(address)), address);
|
|
}
|
|
|
|
foreach (var address in new[]
|
|
{
|
|
"https://www.instagram.com/", "http://127.0.0.2:8480/", "http://localhost.example.com/", "file:///etc/passwd",
|
|
"http://user:pw@127.0.0.1:8480/", "http://192.168.1.10:8480/", "ws://127.0.0.1:8480/",
|
|
})
|
|
{
|
|
Assert.IsFalse(Shots.IsOnThisComputer(new Uri(address)), address);
|
|
}
|
|
|
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => Request.Parse(["una", "https://www.instagram.com/", "x.png"], Path.GetTempPath()));
|
|
StringAssert.Contains(ex.Message, "questo computer");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheListTakesEveryScreenshotOfTheFolderOnceWithItsStep()
|
|
{
|
|
var folder = Repository.PathOf("docs", "schermate");
|
|
var steps = Repository.PathOf("tools", "Febe.Schermate", "passi");
|
|
var files = Shots.All.Select(s => s.File).ToList();
|
|
CollectionAssert.AllItemsAreUnique(files);
|
|
CollectionAssert.AreEquivalent(Directory.GetFiles(folder, "*.png").Select(Path.GetFileName).ToList(), files, "every screenshot of docs/schermate, no other");
|
|
foreach (var shot in Shots.All)
|
|
{
|
|
Assert.IsTrue(shot.Page.StartsWith('/'), shot.File);
|
|
Assert.IsTrue(shot.Width is >= 390 and <= 1440 && shot.Height is >= 844 and <= 1470, shot.File);
|
|
if (shot.Step is not null)
|
|
{
|
|
Assert.IsTrue(File.Exists(Path.Combine(steps, shot.Step)), $"manca il passo {shot.Step}");
|
|
}
|
|
}
|
|
|
|
// The steps go next to the program, where it looks for them.
|
|
var project = File.ReadAllText(Repository.PathOf("tools", "Febe.Schermate", "Febe.Schermate.csproj"));
|
|
StringAssert.Contains(project, "<None Include=\"passi\\*.js\" CopyToOutputDirectory=\"PreserveNewest\" />");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheCommandLineGivesTheDemoTheFolderAndASingleShot()
|
|
{
|
|
var root = Repository.PathOf();
|
|
var all = Request.Parse([], Path.Combine(root, "src"));
|
|
Assert.AreEqual(new Uri("http://127.0.0.1:8480/"), all.Base);
|
|
Assert.AreEqual(Path.Combine(root, "docs", "schermate"), all.Folder);
|
|
Assert.HasCount(Shots.All.Count, all.Shots);
|
|
Assert.AreEqual(new Uri("http://127.0.0.1:8480/libreria?tema=chiaro"), all.AddressOf(all.Shots[0]));
|
|
|
|
var other = Request.Parse(["8490", "uscita"], root);
|
|
Assert.AreEqual(8490, other.Base.Port);
|
|
Assert.AreEqual(Path.Combine(root, "uscita"), other.Folder);
|
|
|
|
var one = Request.Parse(["una", "http://localhost:8490/attivita?scena=fermo", "prova.png", "390", "844", "500", "passo.js"], root);
|
|
var shot = one.Shots.Single();
|
|
Assert.AreEqual(new Uri("http://localhost:8490/attivita?scena=fermo"), one.AddressOf(shot));
|
|
Assert.AreEqual(root, one.Folder);
|
|
Assert.AreEqual(new Shot(string.Empty, "prova.png", 390, 844, 500, Path.Combine(root, "passo.js")), shot);
|
|
Assert.AreEqual(Path.Combine(root, "passo.js"), one.StepPath(shot.Step!));
|
|
|
|
foreach (var wrong in new[] { new[] { "porta" }, ["0"], ["70000"], ["8480", "a", "b"], ["una", "http://127.0.0.1/"], ["una", "http://127.0.0.1/", "x.jpg"],
|
|
["una", "http://127.0.0.1/", "x.png", "10"], ["una", "http://127.0.0.1/", "x.png", "800", "600", "-1"] })
|
|
{
|
|
Assert.ThrowsExactly<ArgumentException>(() => Request.Parse(wrong, root), string.Join(' ', wrong));
|
|
}
|
|
|
|
Assert.IsNull(Request.RepositoryRoot(Path.GetPathRoot(Path.GetTempPath())!));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheBrowserHasNoWindowAPrivateProfileAndTheDebugPortOnlyHere()
|
|
{
|
|
var arguments = Screenshotter.Arguments("profilo", 390, 844, noSandbox: false);
|
|
CollectionAssert.Contains(arguments, "--headless");
|
|
CollectionAssert.Contains(arguments, "--user-data-dir=profilo");
|
|
CollectionAssert.Contains(arguments, "--remote-debugging-port=0");
|
|
CollectionAssert.Contains(arguments, "--remote-debugging-address=127.0.0.1");
|
|
CollectionAssert.Contains(arguments, "--no-proxy-server");
|
|
CollectionAssert.Contains(arguments, "--window-size=390,844");
|
|
CollectionAssert.DoesNotContain(arguments, "--no-sandbox");
|
|
Assert.AreEqual("about:blank", arguments[^1]);
|
|
CollectionAssert.Contains(Screenshotter.Arguments("profilo", 1440, 900, noSandbox: true), "--no-sandbox");
|
|
|
|
// Only a page target on 127.0.0.1 is driven.
|
|
Assert.AreEqual(
|
|
"ws://127.0.0.1:9333/devtools/page/A",
|
|
Screenshotter.PageDebugger("""[{"type":"service_worker","webSocketDebuggerUrl":"ws://127.0.0.1:9333/devtools/page/W"},{"type":"page","webSocketDebuggerUrl":"ws://127.0.0.1:9333/devtools/page/A"}]"""));
|
|
Assert.IsNull(Screenshotter.PageDebugger("""[{"type":"page","webSocketDebuggerUrl":"ws://10.0.0.5:9333/devtools/page/A"}]"""));
|
|
Assert.IsNull(Screenshotter.PageDebugger("[]"));
|
|
|
|
using var hover = JsonDocument.Parse("""{"hover":[640,212.5],"label":"x"}""");
|
|
Assert.AreEqual((640d, 212.5d), Screenshotter.HoverPoint(hover.RootElement));
|
|
using var none = JsonDocument.Parse("""{"hover":[1]}""");
|
|
Assert.IsNull(Screenshotter.HoverPoint(none.RootElement));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void NoToolNeedsNode()
|
|
{
|
|
var tools = Repository.PathOf("tools");
|
|
foreach (var file in Directory.EnumerateFiles(tools, "*", SearchOption.AllDirectories))
|
|
{
|
|
var relative = Path.GetRelativePath(tools, file);
|
|
if (relative.Split(Path.DirectorySeparatorChar).Any(part => part is "bin" or "obj"))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
Assert.IsFalse(Path.GetExtension(file) is ".mjs" or ".cjs" or ".ts", $"script Node: {relative}");
|
|
Assert.AreNotEqual("package.json", Path.GetFileName(file), relative);
|
|
if (Path.GetExtension(file) is ".sh" or ".ps1" or ".cmd" or ".bat" or ".cs" or ".csproj")
|
|
{
|
|
Assert.IsFalse(NodeCommand().IsMatch(File.ReadAllText(file)), $"comando node in {relative}");
|
|
}
|
|
}
|
|
|
|
Assert.IsFalse(Directory.Exists(Path.Combine(tools, "schermate")), "tools/schermate became tools/Febe.Schermate");
|
|
StringAssert.Contains(File.ReadAllText(Repository.PathOf("Febe.slnx")), "<Project Path=\"tools/Febe.Schermate/Febe.Schermate.csproj\" />");
|
|
}
|
|
|
|
/// <summary>«node» or «npx» run as a command (at the start of a line or after a separator), not inside a word.</summary>
|
|
[GeneratedRegex(@"(?m)(?:^|[;&|(`]\s*|\bexec\s+|\btimeout\s+\d+\s+)(?:node|npx|npm)\s")]
|
|
private static partial Regex NodeCommand();
|
|
}
|