Correzioni della revisione di C6: installatore, CI senza jq, caratteri e schermate senza Node

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>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 16:04:39 +01:00
1 parent 525d7dfdaa
commit be662f2d28
46 files changed
+2091 -283

No files matched your search

+495 -11
View File
@@ -92,34 +92,491 @@ public sealed partial class InHouseAssetsTests
Assert.IsFalse(shape.HasElements, $"{path}: forme annidate");
foreach (var attribute in shape.Attributes())
{
Assert.IsTrue(Geometry.Contains(attribute.Name.LocalName), $"{path}: attributo «{attribute.Name.LocalName}» (spessore, colore e riempimento vengono dal foglio di stile)");
if (attribute.Name.LocalName is not ("d" or "points" or "stroke-dasharray" or "stroke-dashoffset"))
var name = attribute.Name.LocalName;
Assert.IsTrue(Geometry.Contains(name), $"{path}: attributo «{name}» (spessore, colore e riempimento vengono dal foglio di stile)");
var where = $"{path}: <{shape.Name.LocalName} {name}=\"{attribute.Value}\">";
switch (name)
{
var value = double.Parse(attribute.Value, System.Globalization.CultureInfo.InvariantCulture);
Assert.IsTrue(value is >= 0 and <= 24, $"{path}: {attribute.Name.LocalName}={attribute.Value} fuori dalla griglia");
case "d":
foreach (var (x, y) in PathPoints(attribute.Value, where)!)
{
AssertOnGrid(x, where);
AssertOnGrid(y, where);
}
break;
case "points":
var numbers = Numbers(attribute.Value, where);
Assert.IsTrue(numbers.Count >= 4 && numbers.Count % 2 == 0, $"{where}: coppie di coordinate, almeno due punti");
numbers.ForEach(value => AssertOnGrid(value, where));
break;
case "stroke-dasharray" or "stroke-dashoffset":
Numbers(attribute.Value, where).ForEach(value => Assert.IsTrue(value is >= 0 and <= 100, where));
break;
default:
AssertOnGrid(Number(attribute.Value, where), where);
break;
}
}
}
}
}
[TestMethod]
public void TheGridCheckReadsPathsAndPointsAndFindsWhatIsOffTheGrid()
{
// Absolute and relative commands, repeated arguments, arcs with packed flags, curves, closing.
var points = PathPoints("M4.5 12a7.5 7.5 0 0 1 13-5.1l2 2.1M3 3h18v18H3zM6 9c0-2 1-3 3-3s3 1 3 3q2 2 4 0t4 0", "prova");
Assert.IsNotNull(points);
Assert.IsTrue(points.Any(p => Math.Abs(p.X - 19.5) < 1e-9 && Math.Abs(p.Y - 9) < 1e-9), "a relative line after a relative arc");
Assert.IsTrue(points.Any(p => p == (21.0, 21.0)), "h and v, then H");
Assert.IsTrue(points.Any(p => p == (20.0, 9.0)), "c, s, q and t");
Assert.IsTrue(points.All(p => p.X is >= 0 and <= 24 && p.Y is >= 0 and <= 24));
Assert.IsTrue(PathPoints("M2 12a10 10 0 1012 0", "prova")!.Any(p => p.Y > 12 + 5), "the arc is followed, not only its ends");
// What the test must refuse: off the grid by an end, by a curve or by an arc that bulges, broken numbers.
foreach (var bad in new[] { "M30 30L-5 40", "M2 2l30 0", "M2 12C2 -10 22 -10 22 12", "M2 2a20 20 0 0 1 20 0", "M2 2L3", "M2,x 3", "L2 2", "M2 2a1 1 0 2 1 3 3" })
{
var off = PathPoints(bad, bad, failQuietly: true);
Assert.IsTrue(off is null || off.Any(p => p.X is < 0 or > 24 || p.Y is < 0 or > 24), $"«{bad}» passerebbe");
}
Assert.ThrowsExactly<FormatException>(() => Numbers("0,0 99,x", "prova", failQuietly: true));
CollectionAssert.AreEqual(new[] { 0.5, 0.5, -3.0, 1e-1 }, Numbers("0.5.5-3,1e-1", "prova"));
}
private static void AssertOnGrid(double value, string where) =>
Assert.IsTrue(value is >= -1e-6 and <= 24 + 1e-6, $"{where}: {value.ToString(System.Globalization.CultureInfo.InvariantCulture)} fuori dalla griglia 0–24");
private static double Number(string text, string where)
{
Assert.IsTrue(double.TryParse(text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var value), $"{where}: «{text}» non è un numero");
return value;
}
private static List<double> Numbers(string text, string where, bool failQuietly = false)
{
var numbers = new List<double>();
var at = 0;
while (SkipSeparators(text, ref at) < text.Length)
{
if (ReadNumber(text, ref at) is not { } value)
{
if (failQuietly)
{
throw new FormatException(where);
}
Assert.Fail($"{where}: «{text[at..]}» non è un numero");
}
else
{
numbers.Add(value);
}
}
return numbers;
}
/// <summary>
/// Every point the outline of an SVG path goes through (SVG 1.1 §8.3): the ends of each segment, the control points
/// of the curves and points along each curve and arc, all made absolute. A path that does not start with a move,
/// a command with too few numbers or a number that does not parse fails the test (or gives null with
/// <paramref name="failQuietly"/>).
/// </summary>
private static List<(double X, double Y)>? PathPoints(string d, string where, bool failQuietly = false)
{
var points = new List<(double X, double Y)>();
double x = 0, y = 0, startX = 0, startY = 0;
var at = 0;
var command = '\0';
void Refuse(string why)
{
if (!failQuietly)
{
Assert.Fail($"{where}: {why}");
}
}
while (SkipSeparators(d, ref at) < d.Length)
{
if (char.IsAsciiLetter(d[at]))
{
command = d[at++];
if (points.Count == 0 && command is not ('M' or 'm'))
{
Refuse("il percorso deve cominciare con M");
return null;
}
if (command is 'Z' or 'z')
{
(x, y) = (startX, startY);
points.Add((x, y));
continue;
}
}
else if (command is '\0' or 'Z' or 'z')
{
Refuse($"numero senza comando: «{d[at..]}»");
return null;
}
var relative = char.IsAsciiLetterLower(command);
var arguments = char.ToUpperInvariant(command) switch
{
'M' or 'L' or 'T' => 2,
'H' or 'V' => 1,
'C' => 6,
'S' or 'Q' => 4,
'A' => 7,
_ => -1,
};
if (arguments < 0)
{
Refuse($"comando «{command}» sconosciuto");
return null;
}
var values = new double[arguments];
for (var i = 0; i < arguments; i++)
{
SkipSeparators(d, ref at);
double? value = char.ToUpperInvariant(command) == 'A' && i is 3 or 4 ? ReadFlag(d, ref at) : ReadNumber(d, ref at);
if (value is null)
{
Refuse($"comando «{command}» con argomenti mancanti o non validi: «{d[at..]}»");
return null;
}
values[i] = value.Value;
}
(double X, double Y) Absolute(int index) => relative ? (x + values[index], y + values[index + 1]) : (values[index], values[index + 1]);
var from = (X: x, Y: y);
switch (char.ToUpperInvariant(command))
{
case 'M':
(x, y) = Absolute(0);
(startX, startY) = (x, y);
points.Add((x, y));
command = relative ? 'l' : 'L';
break;
case 'L' or 'T':
(x, y) = Absolute(0);
points.Add((x, y));
break;
case 'H':
x = relative ? x + values[0] : values[0];
points.Add((x, y));
break;
case 'V':
y = relative ? y + values[0] : values[0];
points.Add((x, y));
break;
case 'C':
{
var (c1, c2, end) = (Absolute(0), Absolute(2), Absolute(4));
points.AddRange([c1, c2, end]);
for (var t = 0.0625; t < 1; t += 0.0625)
{
var u = 1 - t;
points.Add(((u * u * u * from.X) + (3 * u * u * t * c1.X) + (3 * u * t * t * c2.X) + (t * t * t * end.X),
(u * u * u * from.Y) + (3 * u * u * t * c1.Y) + (3 * u * t * t * c2.Y) + (t * t * t * end.Y)));
}
(x, y) = end;
break;
}
case 'S' or 'Q':
{
var (control, end) = (Absolute(0), Absolute(2));
points.AddRange([control, end]);
(x, y) = end;
break;
}
case 'A':
{
var end = Absolute(5);
points.Add(end);
points.AddRange(ArcPoints(from, values[0], values[1], values[2], values[3] != 0, values[4] != 0, end));
(x, y) = end;
break;
}
}
}
if (points.Count == 0)
{
Refuse("percorso vuoto");
return null;
}
return points;
}
/// <summary>Points along an elliptical arc, from its end points to its centre as in SVG 1.1 appendix F.6.5.</summary>
private static IEnumerable<(double X, double Y)> ArcPoints((double X, double Y) from, double rx, double ry, double rotation, bool large, bool sweep, (double X, double Y) to)
{
rx = Math.Abs(rx);
ry = Math.Abs(ry);
if (rx == 0 || ry == 0 || from == to)
{
yield break;
}
var phi = rotation * Math.PI / 180;
var (cos, sin) = (Math.Cos(phi), Math.Sin(phi));
var dx = (from.X - to.X) / 2;
var dy = (from.Y - to.Y) / 2;
var x1 = (cos * dx) + (sin * dy);
var y1 = (-sin * dx) + (cos * dy);
var lambda = (x1 * x1 / (rx * rx)) + (y1 * y1 / (ry * ry));
if (lambda > 1)
{
rx *= Math.Sqrt(lambda);
ry *= Math.Sqrt(lambda);
}
var numerator = (rx * rx * ry * ry) - (rx * rx * y1 * y1) - (ry * ry * x1 * x1);
var factor = Math.Sqrt(Math.Max(0, numerator / ((rx * rx * y1 * y1) + (ry * ry * x1 * x1)))) * (large == sweep ? -1 : 1);
var cx1 = factor * rx * y1 / ry;
var cy1 = -factor * ry * x1 / rx;
var cx = (cos * cx1) - (sin * cy1) + ((from.X + to.X) / 2);
var cy = (sin * cx1) + (cos * cy1) + ((from.Y + to.Y) / 2);
static double Angle(double ux, double uy, double vx, double vy) => Math.Atan2((ux * vy) - (uy * vx), (ux * vx) + (uy * vy));
var start = Angle(1, 0, (x1 - cx1) / rx, (y1 - cy1) / ry);
var delta = Angle((x1 - cx1) / rx, (y1 - cy1) / ry, (-x1 - cx1) / rx, (-y1 - cy1) / ry);
if (!sweep && delta > 0)
{
delta -= 2 * Math.PI;
}
else if (sweep && delta < 0)
{
delta += 2 * Math.PI;
}
for (var step = 1; step < 32; step++)
{
var angle = start + (delta * step / 32);
var (ex, ey) = (rx * Math.Cos(angle), ry * Math.Sin(angle));
yield return ((cos * ex) - (sin * ey) + cx, (sin * ex) + (cos * ey) + cy);
}
}
private static int SkipSeparators(string text, ref int at)
{
while (at < text.Length && (char.IsWhiteSpace(text[at]) || text[at] == ','))
{
at++;
}
return at;
}
private static double? ReadNumber(string text, ref int at)
{
var match = SvgNumber().Match(text, at);
if (!match.Success || match.Index != at)
{
return null;
}
at += match.Length;
return double.Parse(match.Value, System.Globalization.CultureInfo.InvariantCulture);
}
/// <summary>An arc flag: one digit, 0 or 1, which may touch the next number («0 01 3 3»).</summary>
private static double? ReadFlag(string text, ref int at)
{
if (at < text.Length && text[at] is '0' or '1')
{
return text[at++] - '0';
}
return null;
}
[TestMethod]
public void EveryIconThePagesAskForIsDrawn()
{
var files = new EmbeddedWwwroot();
var drawn = files.Files.Where(f => f.StartsWith("icone/", StringComparison.Ordinal))
.Select(f => f["icone/".Length..^".svg".Length]).ToHashSet(StringComparer.Ordinal);
var asked = 0;
var asked = new Dictionary<string, string>(StringComparer.Ordinal);
foreach (var path in files.Files.Where(f => f.EndsWith(".js", StringComparison.Ordinal)))
{
foreach (Match match in IconCall().Matches(files.ReadText(path)!))
foreach (var name in IconNamesAskedIn(files.ReadText(path)!))
{
asked++;
Assert.Contains(match.Groups[1].Value, drawn, $"{path} chiede l'icona «{match.Groups[1].Value}»");
asked.TryAdd(name, path);
}
}
Assert.IsGreaterThan(20, asked, "le pagine usano le icone");
foreach (var (name, path) in asked)
{
Assert.Contains(name, drawn, $"{path} chiede l'icona «{name}»");
}
// Every form the pages use is read, not only icon('…'): names held in data (icon: '…', a map of icons, the
// third argument of label), chosen with a condition, or taken from a list a function returns. One name for each
// form, as the pages have them today.
foreach (var (name, form) in new[]
{
("layout-grid", "icon: '…' (shell.js)"), ("sun", "icon: '…' (settings-general.js)"), ("gauge", "PLAN_ICONS e icon: '…'"),
("trash-2", "icon: '…' (accounts.js)"), ("circle-check", "icon(on ? '…' : '…')"), ("at-sign", "icon(cond ? '…' : '…')"),
("octagon-alert", "[colore, '…'] in outcome"), ("shield-alert", "return ['…', …] di placeholderFor"),
("user-check", "label(testo, '', '…')"), ("hourglass", "icon(a ? '…' : b ? '…' : '…')"),
})
{
Assert.IsTrue(asked.ContainsKey(name), $"la prova non legge più la forma {form}: manca «{name}»");
}
Assert.IsGreaterThan(50, asked.Count, "le pagine usano le icone");
}
[TestMethod]
public void TheReadingOfTheIconNamesSeesEveryFormAndNotTheConditions()
{
const string script = """
const MENU = [{ path: '/', icon: 'uno' }, { icon: x ? 'due' : 'tre', label: 'non-icona' }];
const STATE_ICONS = { a: 'quattro', b: 'cinque' };
h('b', icon(s.kind === 'video' ? 'sei' : 'sette', 's'), icon('otto'), label(t('x'), 'ambra', 'nove'));
const outcome = { ok: ['verde', 'dieci'], ko: ['rosso', 'undici'] }[k] || ['', 'dodici'];
h('td', icon(outcome[1]));
function placeholderFor(m) {
if (m === 'Off') return ['tredici', t('a'), null];
return ['quattordici', t('b'), 'about:blank'];
}
const [name, text] = placeholderFor(mode);
fill(icon(name, 'l'));
""";
CollectionAssert.AreEquivalent(
new[] { "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove", "dieci", "undici", "dodici", "tredici", "quattordici" },
IconNamesAskedIn(script).Distinct().ToArray(),
"not «video» (a condition), not «non-icona», «verde» or «about:blank»");
}
/// <summary>
/// The icon names a script asks for: the literals that reach <c>icon(…)</c> directly or through data.
/// <list type="bullet">
/// <item>the first argument of <c>icon(…)</c>, the value of <c>icon: …</c> and the third argument of <c>label(…)</c>,
/// with the literals of a condition left out (those before a <c>?</c> or after <c>===</c>);</item>
/// <item>the values of an object assigned to a name with ICON in it (<c>PLAN_ICONS</c>);</item>
/// <item><c>icon(v[n])</c>: element n of the lists in <c>const v = …</c>;</item>
/// <item><c>icon(v)</c> with <c>const [.., v, ..] = f(…)</c>: that element of the lists <c>f</c> returns.</item>
/// </list>
/// </summary>
private static IEnumerable<string> IconNamesAskedIn(string script)
{
foreach (Match call in IconArgument().Matches(script))
{
foreach (var name in NamesIn(FirstArgument(script, call.Index + call.Length)))
{
yield return name;
}
}
foreach (Match property in IconProperty().Matches(script))
{
foreach (var name in NamesIn(FirstArgument(script, property.Index + property.Length)))
{
yield return name;
}
}
foreach (Match label in LabelIcon().Matches(script))
{
yield return label.Groups[1].Value;
}
foreach (Match map in IconMap().Matches(script))
{
foreach (Match value in QuotedValue().Matches(map.Groups["body"].Value))
{
yield return value.Groups[1].Value;
}
}
foreach (Match indexed in IndexedIcon().Matches(script))
{
var definition = Regex.Match(script, $@"const {Regex.Escape(indexed.Groups["list"].Value)} = (?<value>[^;\n]+)");
var index = int.Parse(indexed.Groups["index"].Value, System.Globalization.CultureInfo.InvariantCulture);
foreach (Match list in ListLiteral().Matches(definition.Groups["value"].Value))
{
var items = list.Groups["items"].Value.Split(',', StringSplitOptions.TrimEntries);
if (index < items.Length && Quoted().Match(items[index]) is { Success: true } item)
{
yield return item.Groups[1].Value;
}
}
}
foreach (Match variable in VariableIcon().Matches(script))
{
var name = variable.Groups["name"].Value;
foreach (Match destructured in Regex.Matches(script, @"const \[(?<names>[^\]]+)\] = (?<function>\w+)\("))
{
var names = destructured.Groups["names"].Value.Split(',', StringSplitOptions.TrimEntries);
var position = Array.IndexOf(names, name);
if (position < 0)
{
continue;
}
var body = Regex.Match(script, $@"function {Regex.Escape(destructured.Groups["function"].Value)}\([^)]*\) \{{(?<body>.*?)\n\s*\}}", RegexOptions.Singleline);
foreach (Match returned in Regex.Matches(body.Groups["body"].Value, @"return \[(?<items>[^\]]*)\]"))
{
var items = returned.Groups["items"].Value.Split(',', StringSplitOptions.TrimEntries);
if (position < items.Length && Quoted().Match(items[position]) is { Success: true } item)
{
yield return item.Groups[1].Value;
}
}
}
}
}
/// <summary>The text of an argument or a value from <paramref name="start"/> to the comma, parenthesis or brace that ends it.</summary>
private static string FirstArgument(string script, int start)
{
var depth = 0;
for (var i = start; i < script.Length; i++)
{
var c = script[i];
if (c is '(' or '[' or '{')
{
depth++;
}
else if (c is ')' or ']' or '}' || (c is ',' or ';' or '\n' && depth == 0))
{
if (depth == 0)
{
return script[start..i];
}
depth--;
}
}
return script[start..];
}
/// <summary>The quoted names of an expression, without the operands of a condition.</summary>
private static IEnumerable<string> NamesIn(string expression)
{
foreach (Match literal in Quoted().Matches(expression))
{
var after = expression[(literal.Index + literal.Length)..].TrimStart();
var before = expression[..literal.Index].TrimEnd();
if (after.StartsWith('?') || before.EndsWith("===", StringComparison.Ordinal) || before.EndsWith("!==", StringComparison.Ordinal))
{
continue;
}
yield return literal.Groups[1].Value;
}
}
[TestMethod]
@@ -167,8 +624,35 @@ public sealed partial class InHouseAssetsTests
[GeneratedRegex(@"--carattere:([^;]+);")]
private static partial Regex CharacterToken();
[GeneratedRegex(@"\bicon\('([a-z0-9-]+)'")]
private static partial Regex IconCall();
[GeneratedRegex(@"[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?")]
private static partial Regex SvgNumber();
[GeneratedRegex(@"(?<![\w.])icon\((?!name, size)")]
private static partial Regex IconArgument();
[GeneratedRegex(@"\bicon:\s*")]
private static partial Regex IconProperty();
[GeneratedRegex(@"\blabel\([^;\n]*?,\s*'[^']*',\s*'([a-z0-9-]+)'\)")]
private static partial Regex LabelIcon();
[GeneratedRegex(@"const \w*ICON\w* = \{(?<body>[^}]*)\}", RegexOptions.IgnoreCase)]
private static partial Regex IconMap();
[GeneratedRegex(@":\s*'([a-z0-9-]+)'")]
private static partial Regex QuotedValue();
[GeneratedRegex(@"\bicon\((?<list>\w+)\[(?<index>\d)\]\)")]
private static partial Regex IndexedIcon();
[GeneratedRegex(@"\bicon\((?<name>[A-Za-z_]\w*)[,)]")]
private static partial Regex VariableIcon();
[GeneratedRegex(@"\[(?<items>[^\[\]]*)\]")]
private static partial Regex ListLiteral();
[GeneratedRegex(@"'([a-z0-9]+(?:-[a-z0-9]+)*)'")]
private static partial Regex Quoted();
// The font and the icon set Febe carried until 18 November 2026.
[GeneratedRegex(@"\b(archivo|lucide)\b", RegexOptions.IgnoreCase)]
+144
View File
@@ -0,0 +1,144 @@
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();
}
+1 -1
View File
@@ -9,7 +9,7 @@ using Febe.Tests.Browser.TestSupport;
namespace Febe.Tests.Web.Support;
/// <summary>
/// A headless Chromium that drives Febe's own interface, like <c>tools/schermate</c>: only addresses on 127.0.0.1, never
/// A headless Chromium that drives Febe's own interface, like <c>tools/Febe.Schermate</c>: only addresses on 127.0.0.1, never
/// Instagram (spec §2). It speaks the DevTools protocol directly, without the command policy of Febe's own client,
/// because here the tests click, type and run scripts in Febe's pages. Inconclusive when Chromium is missing.
/// </summary>