Il filtro «Copie» con 200.000 elementi stava al limite dei 250 ms («Copiati» 249 ms): la migrazione 0004 aggiunge solo l'indice ix_media_sha256_entry e la finestra scende a 160 ms. Totali e giorni contano «Copiati» partendo dalle copie e gli altri valori con un solo passaggio sui file dietro gli elenchi degli SHA-256 copiati (1,5 s -> 0,7 s); hanno un limite loro di 3 s, scritto in decisioni.md con le misure. «Copia di nuovo» sceglie un file dell'account che è sul disco: prima prendeva il primo con quello SHA-256 e, nella demo, a certe ore non scriveva nulla. Nuove prove: API delle copie, coerenza della demo, interfaccia nel browser, opzioni del server, avvio del contenitore con /esporta, contenuto dell'immagine e modelli, migrazione 4 e scala. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
273 lines
14 KiB
C#
273 lines
14 KiB
C#
using System.Text.RegularExpressions;
|
|
using Febe.Tests.Desktop.Support;
|
|
|
|
namespace Febe.Tests.Packaging;
|
|
|
|
/// <summary>
|
|
/// What the Docker image installs (spec §11, Alberto's decision of 18 November 2026): only Chromium with the Debian
|
|
/// packages it needs, Xvfb and what the .NET runtime needs, each with its reason next to the list and in docs/docker.md;
|
|
/// Febe itself is process 1, without tini.
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed partial class ImageContentsTests
|
|
{
|
|
/// <summary>Every package the runtime stage may name, and why (the same reasons the Dockerfile gives).</summary>
|
|
private static readonly Dictionary<string, string> Allowed = new(StringComparer.Ordinal)
|
|
{
|
|
["chromium"] = "the browser",
|
|
["chromium-l10n"] = "Chromium's languages: with LANG=it_IT.UTF-8 menus and Accept-Language are Italian",
|
|
["xvfb"] = "the virtual display: Chromium is never headless",
|
|
["libicu76"] = ".NET globalization (InvariantGlobalization is false)",
|
|
["libssl3t64"] = ".NET TLS and AES-GCM",
|
|
["libstdc++6"] = "loaded by libcoreclr, libclrjit and libhostfxr",
|
|
["libgcc-s1"] = ".NET and Chromium",
|
|
["zlib1g"] = "a direct dependency of Chromium",
|
|
["fonts-dejavu-core"] = "the first font fontconfig asks for: without a font Chromium draws no text",
|
|
["fonts-noto-color-emoji"] = "colour emoji: Chromium needs them to show the pages (Alberto, 25 November 2026)",
|
|
["ca-certificates"] = "certificate authorities for .NET TLS",
|
|
["tzdata"] = "time zones for the engine and Chromium",
|
|
["locales"] = "generates it_IT.UTF-8 for the C library Chromium runs with",
|
|
};
|
|
|
|
/// <summary>Without these the image does not work: the browser, its display, and what .NET loads.</summary>
|
|
private static readonly string[] Required = ["chromium", "chromium-l10n", "xvfb", "libicu76", "libssl3t64", "ca-certificates", "tzdata", "locales"];
|
|
|
|
/// <summary>Programs that must not come back: an init of others, privilege tools, downloaders, other runtimes.</summary>
|
|
private static readonly string[] Forbidden =
|
|
["tini", "dumb-init", "gosu", "su-exec", "sudo", "curl", "wget", "nodejs", "npm", "python3", "jq",
|
|
// Videos are read and decoded by Febe's own code since stage C3.
|
|
"ffmpeg",
|
|
// Fonts for looks only (Alberto, 25 November 2026: Liberation leaves, only the emoji stay besides DejaVu).
|
|
"fonts-liberation", "fonts-liberation2", "fonts-noto-core", "fonts-noto"];
|
|
|
|
[TestMethod]
|
|
public void TheImageInstallsOnlyChromiumWhatItNeedsXvfbAndWhatTheDotNetRuntimeNeeds()
|
|
{
|
|
var installed = InstalledPackages(RuntimeStage());
|
|
Assert.HasCount(installed.Distinct(StringComparer.Ordinal).Count(), installed, "every package once");
|
|
foreach (var package in installed)
|
|
{
|
|
Assert.IsTrue(Allowed.ContainsKey(package), $"pacchetto fuori dall'elenco ammesso: {package}");
|
|
}
|
|
|
|
foreach (var package in Required)
|
|
{
|
|
CollectionAssert.Contains(installed, package);
|
|
}
|
|
|
|
foreach (var package in Forbidden)
|
|
{
|
|
CollectionAssert.DoesNotContain(installed, package);
|
|
}
|
|
|
|
// Only the runtime stage installs anything with apt: the build stages use the SDK image as it is.
|
|
var dockerfile = Dockerfile();
|
|
Assert.AreEqual(1, Regex.Matches(Code(dockerfile), @"apt-get install").Count, "a single apt-get install, in the runtime stage");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheTestsOfTheCiDrawWithTheSameFontsAsTheImage()
|
|
{
|
|
var environment = Repository.PathOf(".gitea", "scripts", "ambiente-prove.sh");
|
|
if (!File.Exists(environment))
|
|
{
|
|
Assert.Inconclusive("Questa copia del repository non ha .gitea/ (costruzione dell'immagine Docker).");
|
|
}
|
|
|
|
static string[] Fonts(string text) => [.. Regex.Matches(text, @"\bfonts-[a-z0-9-]+").Select(m => m.Value).Distinct().Order(StringComparer.Ordinal)];
|
|
var image = Fonts(string.Join('\n', InstalledPackages(RuntimeStage())));
|
|
CollectionAssert.AreEqual(new[] { "fonts-dejavu-core", "fonts-noto-color-emoji" }, image, "the font fontconfig asks for and the emoji, no other");
|
|
CollectionAssert.AreEqual(image, Fonts(Code(File.ReadAllText(environment))), "ambiente-prove.sh installs the fonts of the image, no more");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void EveryInstalledPackageHasItsReasonNextToTheList()
|
|
{
|
|
var stage = RuntimeStage();
|
|
var installed = InstalledPackages(stage).ToHashSet(StringComparer.Ordinal);
|
|
var reasons = new HashSet<string>(StringComparer.Ordinal);
|
|
foreach (Match match in ReasonLine().Matches(stage))
|
|
{
|
|
foreach (var name in match.Groups["names"].Value.Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
Assert.IsTrue(reasons.Add(name), $"motivo ripetuto per {name}");
|
|
}
|
|
}
|
|
|
|
foreach (var package in installed)
|
|
{
|
|
Assert.Contains(package, reasons, $"manca il motivo di {package} accanto alla lista");
|
|
}
|
|
|
|
foreach (var name in reasons)
|
|
{
|
|
Assert.Contains(name, installed, $"motivo di un pacchetto che non si installa: {name}");
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheGuideGivesTheSameReasonsForTheSamePackages()
|
|
{
|
|
var path = Repository.PathOf("docs", "docker.md");
|
|
if (!File.Exists(path))
|
|
{
|
|
Assert.Inconclusive("Questa copia del repository non ha docs/ (costruzione dell'immagine Docker).");
|
|
}
|
|
|
|
var guide = File.ReadAllText(path).Replace("\r\n", "\n", StringComparison.Ordinal);
|
|
var start = guide.IndexOf("### Perché c'è ogni pacchetto", StringComparison.Ordinal);
|
|
Assert.IsGreaterThanOrEqualTo(0, start, "docs/docker.md has the table of the packages");
|
|
var end = guide.IndexOf("\n## ", start, StringComparison.Ordinal);
|
|
var section = end < 0 ? guide[start..] : guide[start..end];
|
|
|
|
var listed = new HashSet<string>(StringComparer.Ordinal);
|
|
foreach (Match row in GuideRow().Matches(section))
|
|
{
|
|
foreach (Match name in BacktickedName().Matches(row.Groups["names"].Value))
|
|
{
|
|
Assert.IsTrue(listed.Add(name.Groups["name"].Value), name.Value);
|
|
}
|
|
}
|
|
|
|
var installed = InstalledPackages(RuntimeStage()).ToHashSet(StringComparer.Ordinal);
|
|
Assert.IsTrue(installed.SetEquals(listed), $"Dockerfile: {string.Join(' ', installed.Order())}; guida: {string.Join(' ', listed.Order())}");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void FebeIsProcessOneWithoutTini()
|
|
{
|
|
var dockerfile = Dockerfile();
|
|
var code = Code(dockerfile);
|
|
StringAssert.Contains(code, "ENTRYPOINT [\"/usr/local/bin/febe-avvio\"]");
|
|
StringAssert.Contains(code, "CMD [\"/app/febe\"]");
|
|
StringAssert.Contains(code, "STOPSIGNAL SIGTERM");
|
|
foreach (var program in Forbidden)
|
|
{
|
|
Assert.IsFalse(Regex.IsMatch(code, $@"(?<![\w.-]){Regex.Escape(program)}(?![\w.-])"), $"{program} nel Dockerfile");
|
|
}
|
|
|
|
// Process 1 stays Febe only if the start hands over with exec every time, never as a child.
|
|
var entrypoint = Code(File.ReadAllText(Repository.PathOf("docker", "entrypoint.sh")));
|
|
var handovers = entrypoint.Split('\n').Where(line => line.Contains("\"$@\"", StringComparison.Ordinal)).Select(line => line.Trim()).ToList();
|
|
CollectionAssert.AreEqual(
|
|
new[] { "exec \"$@\"", "exec setpriv --reuid=\"${PUID}\" --regid=\"${PGID}\" --init-groups \"$@\"" },
|
|
handovers);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copie esterne (spec §4.10, §11): /esporta is never made by the image. A VOLUME or a mkdir would give an anonymous
|
|
/// volume or a folder of the image disk that looks like a mounted folder; Compose and Unraid offer it commented out
|
|
/// or empty, with FEBE_ESPORTA.
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void TheImageNeverMakesTheExportFolderAndTheTemplatesOfferItOff()
|
|
{
|
|
var code = Code(Dockerfile());
|
|
var volume = code.Split('\n').Single(line => line.StartsWith("VOLUME ", StringComparison.Ordinal));
|
|
Assert.DoesNotContain("esporta", volume);
|
|
foreach (var line in code.Split('\n').Where(line => line.Contains("mkdir", StringComparison.Ordinal)))
|
|
{
|
|
Assert.DoesNotContain("esporta", line);
|
|
}
|
|
|
|
Assert.DoesNotContain("FEBE_ESPORTA", code, "export is off unless the container declares it");
|
|
StringAssert.Contains(Dockerfile(), "Niente /esporta qui", "the reason stays next to VOLUME");
|
|
|
|
var lines = File.ReadAllText(Repository.PathOf("docker", "compose.yml")).Replace("\r\n", "\n", StringComparison.Ordinal).Split('\n');
|
|
var mount = lines.Single(line => line.Contains(":/esporta", StringComparison.Ordinal) && line.Contains("FEBE_CARTELLA_ESPORTA", StringComparison.Ordinal));
|
|
StringAssert.StartsWith(mount.TrimStart(), "# - ", "the mount of /esporta is commented out in compose.yml");
|
|
var variable = lines.Single(line => line.TrimStart().TrimStart('#').TrimStart().StartsWith("FEBE_ESPORTA:", StringComparison.Ordinal));
|
|
StringAssert.StartsWith(variable.TrimStart(), "# ", "FEBE_ESPORTA is commented out in compose.yml");
|
|
var active = lines.Where(line => !line.TrimStart().StartsWith('#') && line.Contains("esporta", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
Assert.IsEmpty(active, string.Join('\n', active));
|
|
|
|
var template = System.Xml.Linq.XDocument.Load(Repository.PathOf("docker", "unraid", "febe.xml")).Root!;
|
|
var folder = template.Elements("Config").Single(c => (string?)c.Attribute("Target") == "/esporta");
|
|
Assert.AreEqual("Path", (string?)folder.Attribute("Type"));
|
|
Assert.AreEqual("false", (string?)folder.Attribute("Required"));
|
|
Assert.AreEqual(string.Empty, (string?)folder.Attribute("Default"));
|
|
Assert.AreEqual(string.Empty, folder.Value.Trim(), "no folder of the server by default");
|
|
var flag = template.Elements("Config").Single(c => (string?)c.Attribute("Target") == "FEBE_ESPORTA");
|
|
Assert.AreEqual("Variable", (string?)flag.Attribute("Type"));
|
|
Assert.AreEqual(string.Empty, (string?)flag.Attribute("Default"));
|
|
Assert.AreEqual(string.Empty, flag.Value.Trim());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheToolsTheStartUsesComeWithTheBaseImageAndTheBuildChecksThem()
|
|
{
|
|
var code = Code(Dockerfile());
|
|
StringAssert.Contains(code, "for comando in setpriv groupadd useradd getent; do");
|
|
var entrypoint = Code(File.ReadAllText(Repository.PathOf("docker", "entrypoint.sh")));
|
|
foreach (var tool in new[] { "setpriv", "groupadd", "useradd", "getent" })
|
|
{
|
|
StringAssert.Contains(entrypoint, tool + " ");
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheReasonsOfThePackagesStillHold()
|
|
{
|
|
// ICU: the server keeps the culture-aware globalization (dates and sorting in Italian).
|
|
var server = File.ReadAllText(Repository.PathOf("src", "Febe.Server", "Febe.Server.csproj"));
|
|
StringAssert.Contains(server, "<InvariantGlobalization>false</InvariantGlobalization>");
|
|
|
|
// chromium-l10n and locales: the browser takes its language from LANG, never from a command-line switch.
|
|
var code = Code(Dockerfile());
|
|
StringAssert.Contains(code, "LANG=it_IT.UTF-8");
|
|
StringAssert.Contains(code, "it_IT.UTF-8 UTF-8");
|
|
StringAssert.Contains(code, "FEBE_CHROMIUM=/usr/bin/chromium");
|
|
}
|
|
|
|
private static string Dockerfile() =>
|
|
File.ReadAllText(Repository.PathOf("docker", "Dockerfile")).Replace("\r\n", "\n", StringComparison.Ordinal);
|
|
|
|
/// <summary>From the FROM of the runtime stage to the end.</summary>
|
|
private static string RuntimeStage()
|
|
{
|
|
var dockerfile = Dockerfile();
|
|
var start = dockerfile.IndexOf("\nFROM debian:", StringComparison.Ordinal);
|
|
Assert.IsGreaterThanOrEqualTo(0, start, "the runtime stage starts from Debian");
|
|
StringAssert.Contains(dockerfile[start..dockerfile.IndexOf('\n', start + 1)], " AS runtime");
|
|
return dockerfile[start..];
|
|
}
|
|
|
|
/// <summary>The packages of the apt-get install of <paramref name="stage"/>, in order, without options and comments.</summary>
|
|
private static List<string> InstalledPackages(string stage)
|
|
{
|
|
var start = stage.IndexOf("apt-get install", StringComparison.Ordinal);
|
|
Assert.IsGreaterThanOrEqualTo(0, start, "the runtime stage installs with apt-get install");
|
|
var end = stage.IndexOf("&&", start, StringComparison.Ordinal);
|
|
Assert.IsGreaterThan(start, end);
|
|
var packages = new List<string>();
|
|
foreach (var line in Code(stage[start..end]).Split('\n'))
|
|
{
|
|
foreach (var word in line.Replace('\\', ' ').Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
if (word is not ("apt-get" or "install") && !word.StartsWith('-'))
|
|
{
|
|
packages.Add(word);
|
|
}
|
|
}
|
|
}
|
|
|
|
Assert.IsNotEmpty(packages);
|
|
return packages;
|
|
}
|
|
|
|
/// <summary>The text without comment lines (a Dockerfile drops them even inside a continued RUN).</summary>
|
|
private static string Code(string text) =>
|
|
string.Join('\n', text.Split('\n').Where(line => !line.TrimStart().StartsWith('#')));
|
|
|
|
/// <summary>«# name [name] reason»: a line of the list of reasons (continuation lines start further right).</summary>
|
|
[GeneratedRegex(@"^# (?<names>[a-z0-9][a-z0-9.+-]*(?: [a-z0-9][a-z0-9.+-]*)*) {2,}\S", RegexOptions.Multiline)]
|
|
private static partial Regex ReasonLine();
|
|
|
|
/// <summary>A row of the table in docs/docker.md: «| `name`, `name` | reason |».</summary>
|
|
[GeneratedRegex(@"^\| (?<names>`[^|]+) \| [^|]+\|$", RegexOptions.Multiline)]
|
|
private static partial Regex GuideRow();
|
|
|
|
[GeneratedRegex(@"`(?<name>[^`]+)`")]
|
|
private static partial Regex BacktickedName();
|
|
}
|