I criteri della specifica §9.11 (frame, blocchi del thread, riga aggiornata entro 100 ms, riconnessione sotto i 2 s, nessun ridisegno della griglia con maniglie e finestra) non li misurava nessuno. Ora il simulatore prende --simulatore-aste N (solo con --simulatore): N aste in elenco, tre su quattro in Attiva, ciclo di 5 s e due autopuntate senza fine per asta, così almeno dieci aste stanno sempre sotto i 4 s; senza l'argomento il simulatore resta quello di sempre. tools/Mimante.Schermate ha la modalità --misura <secondi>, tutta via CDP: uno script nella pagina cronometra frame, compiti dell'interfaccia (timer, frame, eventi del puntatore, ResizeObserver) e messaggi del bot, chiude il canale per la riconnessione, trascina la maniglia e ridimensiona la finestra controllando che i <tr data-id> restino gli stessi nodi, che la griglia non scorra né si virtualizzi e che anche lì nessun compito blocchi il thread; scrive misura.json e misura.txt ed esce con 1 se un criterio vincolante fallisce (anche un solo compito lungo del browser) o la misura non vale (basta un campione con meno di dieci aste in finestra critica; la CPU si riporta soltanto). La password può venire da UI_PASSWORD. prove-a-mano.yml ha il lavoro «prestazioni», dopo carico e schermate per non dividere la CPU, e il commento sul mondo del simulatore è corretto. Le prove dei conti della misura stanno in tests/Mimante.Tests con un riferimento a tools/Mimante.Schermate che esiste solo se la cartella c'è: il contesto dell'immagine non ha tools/ e lì quelle prove restano fuori, così la costruzione dell'immagine non si rompe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
247 lines
12 KiB
C#
247 lines
12 KiB
C#
using System.Text.RegularExpressions;
|
|
using System.Xml.Linq;
|
|
using Xunit;
|
|
|
|
namespace Mimante.Tests.Packaging;
|
|
|
|
/// <summary>
|
|
/// The CI of the repository (.gitea/workflows and .gitea/scripts), read as text: the rules that must survive later
|
|
/// edits. The runner talks to the Docker daemon of Unraid, where the real PostgreSQL of Mimante runs, so nothing may
|
|
/// publish a port and the tried container lives on an internal network; the image is published only from main or a
|
|
/// release tag and :latest only from a release; credentials are never printed; external tools are pinned.
|
|
/// </summary>
|
|
public sealed partial class PipelineTests
|
|
{
|
|
private static readonly string Root = FindRoot();
|
|
|
|
[Fact]
|
|
public void EveryPushOfEveryBranchIsVerifiedAndTagsAreLeftToTheRelease()
|
|
{
|
|
var workflow = Workflow("verifica.yml");
|
|
Assert.Contains("on:\n push:\n branches: [\"**\"]\n workflow_dispatch:", workflow);
|
|
var code = Code(workflow);
|
|
Assert.DoesNotContain("pull_request", code);
|
|
Assert.DoesNotContain("tags:", code);
|
|
Assert.Contains("cancel-in-progress: ${{ gitea.ref != 'refs/heads/main' }}", code);
|
|
Assert.Contains("tags: [\"v*\"]", Workflow("rilascio.yml"));
|
|
}
|
|
|
|
[Fact]
|
|
public void JobsFollowOneAnotherAndEachHasATimeout()
|
|
{
|
|
var verifica = Workflow("verifica.yml");
|
|
Assert.Contains("needs: controlli", Job(verifica, "prove"));
|
|
Assert.Contains("needs: prove", Job(verifica, "immagine"));
|
|
Assert.Contains("needs: [prove, immagine]", Job(Workflow("rilascio.yml"), "release"));
|
|
foreach (var name in new[] { "verifica.yml", "rilascio.yml", "pulizia.yml", "prove-a-mano.yml" })
|
|
{
|
|
var text = Workflow(name);
|
|
foreach (Match job in JobHeader().Matches(text))
|
|
Assert.True(Job(text, job.Groups["name"].Value).Contains("timeout-minutes:"), $"{name}: {job.Groups["name"].Value} has no timeout");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void NothingPublishesAPortOnTheDaemonOfUnraid()
|
|
{
|
|
foreach (var file in Directory.GetFiles(Path.Combine(Root, ".gitea"), "*.*", SearchOption.AllDirectories)
|
|
.Where(f => f.EndsWith(".yml") || f.EndsWith(".sh")))
|
|
{
|
|
var code = Code(File.ReadAllText(file).Replace("\r\n", "\n"));
|
|
Assert.False(Regex.IsMatch(code, @"^\s*ports:", RegexOptions.Multiline), $"{file}: ports");
|
|
Assert.False(Regex.IsMatch(code, @"\s(-p|--publish)(\s|=)\S*\d"), $"{file}: docker run -p");
|
|
Assert.DoesNotContain("--network host", code);
|
|
}
|
|
var trial = Script("prova-immagine.sh");
|
|
Assert.Contains("docker network create --internal", trial);
|
|
Assert.DoesNotContain("--network bridge", trial);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestsRunWithPostgresAndNoneMaySkip()
|
|
{
|
|
foreach (var name in new[] { "verifica.yml", "rilascio.yml" })
|
|
{
|
|
var prove = Job(Workflow(name), "prove");
|
|
Assert.Contains("image: postgres:18", prove);
|
|
Assert.Contains("TEST_DB_HOST: postgres", prove);
|
|
Assert.Contains("dotnet build Mimante.slnx -c Release -nologo -warnaserror", prove);
|
|
Assert.Contains("dotnet test tests/Mimante.Tests -c Release --no-build", prove);
|
|
Assert.Contains("bash .gitea/scripts/riepilogo-prove.sh out/prove 0", prove);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void LatestComesOnlyFromAReleaseAndMainOnlyFromMain()
|
|
{
|
|
var verifica = Code(Workflow("verifica.yml"));
|
|
Assert.DoesNotContain(":latest", verifica.Replace(":latest resta", ""));
|
|
Assert.Contains("[ \"$RIFERIMENTO\" != refs/heads/main ]", verifica);
|
|
Assert.Contains("NOMI+=(\"$IMAGE:main\")", verifica);
|
|
|
|
var rilascio = Code(Workflow("rilascio.yml"));
|
|
Assert.Contains("*-*) echo \"Prova del rilascio: :latest non si sposta.\" ;;", rilascio);
|
|
Assert.Contains("[ -z \"$TOKEN\" ]", rilascio);
|
|
}
|
|
|
|
[Fact]
|
|
public void CredentialsAreNeverPrintedNorPassedOnTheCommandLine()
|
|
{
|
|
foreach (var name in new[] { "verifica.yml", "rilascio.yml", "pulizia.yml", "prove-a-mano.yml" })
|
|
{
|
|
var code = Code(Workflow(name));
|
|
Assert.DoesNotContain("docker login", code);
|
|
Assert.False(Regex.IsMatch(code, @"echo[^\n]*\$\{?(TOKEN|REGISTRY_TOKEN|AUTH)\b"), $"{name} prints a credential");
|
|
Assert.False(Regex.IsMatch(code, @"set -x|bash -x"), $"{name} traces commands");
|
|
// A secret goes into a step only through env:, never inline in a script line.
|
|
foreach (var line in code.Split('\n').Where(l => l.Contains("secrets.")))
|
|
Assert.Matches(@"^\s+[A-Z_]+: \$\{\{ secrets\.[A-Z_]+ \}\}$", line);
|
|
}
|
|
Assert.Contains("-H @<(printf 'Authorization: token %s\\n' \"$REGISTRY_TOKEN\")", Script("pulizia-docker.sh"));
|
|
|
|
foreach (var trial in new[] { Script("prova-immagine.sh"), Script("prova-carico.sh") })
|
|
{
|
|
// Passwords reach the containers by name from the environment, never as a value on the command line.
|
|
Assert.Contains("-e DB_PASSWORD -e UI_PASSWORD", trial);
|
|
Assert.Contains("-e POSTGRES_PASSWORD postgres:18", trial);
|
|
Assert.DoesNotMatch(@"-e (DB|UI|POSTGRES)_PASSWORD=", trial);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TheManualTrialsRunOnlyByHandAndTheLoadTrialKeepsTheMemoryCapOfUnraid()
|
|
{
|
|
var workflow = Workflow("prove-a-mano.yml");
|
|
Assert.Contains("on:\n workflow_dispatch:\n\npermissions:", workflow);
|
|
Assert.Contains("bash .gitea/scripts/prova-carico.sh \"$PROVA\" \"$ESECUZIONE\"", Job(workflow, "carico"));
|
|
Assert.Contains("bash .gitea/scripts/pulizia-docker.sh esecuzione \"$ESECUZIONE\"", Job(workflow, "carico"));
|
|
Assert.DoesNotContain("--push", Code(workflow));
|
|
// The simulator runs inside the job, never inside the image.
|
|
Assert.Contains("--simulatore", Job(workflow, "schermate"));
|
|
Assert.DoesNotContain("--simulatore", Code(Job(workflow, "carico")));
|
|
|
|
// The performance trial (#34) runs alone after the others, with 60 simulated auctions, and gets the password of
|
|
// the interface from UI_PASSWORD, never on its command line.
|
|
var performance = Code(Job(workflow, "prestazioni"));
|
|
Assert.Contains("needs: [carico, schermate]", performance);
|
|
Assert.Contains("--simulatore --simulatore-aste 60", performance);
|
|
Assert.Contains("Mimante.Schermate.dll http://localhost:8080 out/prestazioni --misura 120", performance);
|
|
Assert.DoesNotContain("$UI_PASSWORD", performance);
|
|
Assert.Contains("uses: actions/upload-artifact@v3", performance);
|
|
|
|
var load = Code(Script("prova-carico.sh"));
|
|
Assert.Contains("docker network create --internal", load);
|
|
Assert.Contains("--memory=1g", load);
|
|
Assert.Contains("--label \"mimante.ci.prova=$esecuzione\"", Script("prova-carico.sh"));
|
|
Assert.Contains("nome=\"mimante-prova-$esecuzione\"", load);
|
|
}
|
|
|
|
[Fact]
|
|
public void TheMarkOfTheTrialIsNeverPutInTheImage()
|
|
{
|
|
Assert.DoesNotContain("mimante.ci.prova", Code(Script("costruisci-immagine.sh")));
|
|
Assert.Contains("--label \"mimante.ci.prova=$esecuzione\"", Script("prova-immagine.sh"));
|
|
Assert.Contains("--provenance=false --sbom=false", Script("costruisci-immagine.sh"));
|
|
}
|
|
|
|
[Fact]
|
|
public void TheCleanupNeverPrunesTheWholeDaemon()
|
|
{
|
|
var code = Code(Script("pulizia-docker.sh"));
|
|
foreach (var forbidden in new[] { "system prune", "container prune", "volume prune", "network prune", "image prune", "builder prune" })
|
|
Assert.DoesNotContain(forbidden, code);
|
|
Assert.Contains("^mimante-ci:[0-9]+$", code);
|
|
Assert.Contains("^mimante-ci-[0-9]+$", code);
|
|
Assert.Contains("^sha-[0-9a-f]{7,40}$", code);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExternalToolsArePinnedAndChecked()
|
|
{
|
|
var tool = Script("strumento.sh");
|
|
Assert.Matches(@"versione=""\d+\.\d+\.\d+""", tool);
|
|
Assert.Equal(2, Regex.Matches(tool, @"sha256=""[0-9a-f]{64}""").Count);
|
|
Assert.Contains("sha256sum -c", tool);
|
|
Assert.DoesNotContain("latest", Code(tool));
|
|
foreach (var name in new[] { "verifica.yml", "rilascio.yml" })
|
|
Assert.DoesNotContain("aquasecurity/trivy-action", Workflow(name));
|
|
}
|
|
|
|
[Fact]
|
|
public void ScriptsAreLfAndBashOnly()
|
|
{
|
|
var attributes = File.ReadAllText(Path.Combine(Root, ".gitattributes"));
|
|
Assert.Matches(@"(?m)^\*\.sh\s+text eol=lf", attributes);
|
|
foreach (var file in Directory.GetFiles(Path.Combine(Root, ".gitea", "scripts"), "*.sh"))
|
|
Assert.StartsWith("#!/usr/bin/env bash", File.ReadAllText(file));
|
|
}
|
|
|
|
/// <summary>
|
|
/// The build stage of docker/Dockerfile compiles tests/Mimante.Tests with only src/ and tests/ in the context
|
|
/// (.dockerignore drops tools/): a reference of the test project outside those two folders must depend on the
|
|
/// project being there, and the tests that need it must leave the compilation when it is not (issue #34).
|
|
/// </summary>
|
|
[Fact]
|
|
public void TheImageBuildsTheTestsWithoutTools()
|
|
{
|
|
var ignore = Read(".dockerignore").Split('\n').Select(l => l.Trim()).ToList();
|
|
Assert.Contains("tools", ignore);
|
|
var dockerfile = Read("docker", "Dockerfile");
|
|
Assert.DoesNotContain("COPY tools", dockerfile);
|
|
|
|
var project = XDocument.Parse(Read("tests", "Mimante.Tests", "Mimante.Tests.csproj"));
|
|
var properties = project.Descendants("PropertyGroup").Elements()
|
|
.ToDictionary(e => e.Name.LocalName, e => e.Value, StringComparer.OrdinalIgnoreCase);
|
|
string Expand(string value) =>
|
|
Regex.Replace(value, @"\$\((?<p>[A-Za-z0-9_]+)\)", m => properties.GetValueOrDefault(m.Groups["p"].Value, m.Value));
|
|
|
|
foreach (var reference in project.Descendants("ProjectReference"))
|
|
{
|
|
var path = Expand((string?)reference.Attribute("Include") ?? "").Replace('\\', '/');
|
|
var inContext = !path.StartsWith("../../", StringComparison.Ordinal)
|
|
|| path.StartsWith("../../src/", StringComparison.Ordinal) || path.StartsWith("../../tests/", StringComparison.Ordinal);
|
|
if (inContext) continue;
|
|
var condition = Expand((string?)reference.Parent?.Attribute("Condition") ?? "").Replace('\\', '/');
|
|
Assert.True(condition.Contains($"Exists('{path}')", StringComparison.Ordinal), $"{path}: reference without Exists(...)");
|
|
var removed = project.Descendants("Compile")
|
|
.Where(c => Expand((string?)c.Parent?.Attribute("Condition") ?? "").Replace('\\', '/') == $"!Exists('{path}')")
|
|
.Select(c => (string?)c.Attribute("Remove"))
|
|
.ToList();
|
|
Assert.NotEmpty(removed);
|
|
}
|
|
Assert.Contains("Exists('../../tools/Mimante.Schermate/Mimante.Schermate.csproj')",
|
|
Expand(Read("tests", "Mimante.Tests", "Mimante.Tests.csproj")).Replace('\\', '/'));
|
|
}
|
|
|
|
// ---- helpers ----
|
|
|
|
private static string Workflow(string name) => Read(".gitea", "workflows", name);
|
|
|
|
private static string Script(string name) => Read(".gitea", "scripts", name);
|
|
|
|
private static string Read(params string[] parts) => File.ReadAllText(Path.Combine([Root, .. parts])).Replace("\r\n", "\n");
|
|
|
|
/// <summary>The text without comment lines, so that rules are checked on what runs, not on what is explained.</summary>
|
|
private static string Code(string text) =>
|
|
string.Join('\n', text.Split('\n').Where(l => !l.TrimStart().StartsWith('#')));
|
|
|
|
/// <summary>The block of one job: from « name:» to the next job header.</summary>
|
|
private static string Job(string workflow, string name)
|
|
{
|
|
var start = workflow.IndexOf($"\n {name}:\n", StringComparison.Ordinal);
|
|
Assert.True(start >= 0, $"job {name} not found");
|
|
var next = JobHeader().Match(workflow, start + name.Length + 4);
|
|
return next.Success ? workflow[start..next.Index] : workflow[start..];
|
|
}
|
|
|
|
[GeneratedRegex(@"\n (?<name>[a-z][a-z0-9_-]*):\n (runs-on|needs):")]
|
|
private static partial Regex JobHeader();
|
|
|
|
private static string FindRoot()
|
|
{
|
|
for (var d = new DirectoryInfo(AppContext.BaseDirectory); d != null; d = d.Parent)
|
|
if (File.Exists(Path.Combine(d.FullName, "Mimante.slnx"))) return d.FullName;
|
|
throw new InvalidOperationException("Mimante.slnx not found above " + AppContext.BaseDirectory);
|
|
}
|
|
}
|