Comparer les révisions
1
Révisions
main
...
test/autotests
| Auteur | SHA1 | Date | ||
|---|---|---|---|---|
| ||||
|
|
57c90577ff | |||
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
# Autotests (16/10/2026) : compile et lance les tests dans un conteneur JDK 21 jetable (rien installé sur l'hôte).
|
||||
# Usage (sur la machine de build) : sh autotests-conteneur.sh <dossier>
|
||||
# Entrée : <dossier>/src.tgz (copie du worktree test/autotests, sans .git ni build).
|
||||
# Ne touche à aucun serveur Minecraft ni à son conteneur.
|
||||
set -e
|
||||
D="$1"
|
||||
[ -n "$D" ] && [ -f "$D/src.tgz" ] || { echo "usage : $0 <dossier contenant src.tgz>"; exit 2; }
|
||||
cd "$D"
|
||||
rm -rf src-build
|
||||
mkdir src-build
|
||||
tar xzf src.tgz -C src-build
|
||||
cd src-build
|
||||
sed -i 's/\r$//' gradlew
|
||||
mkdir -p "$HOME/.cache/gastinelclaims-gradle"
|
||||
set +e
|
||||
nice -n 10 docker run --rm --memory 4g --cpus 4 \
|
||||
-u "$(id -u):$(id -g)" \
|
||||
-e GRADLE_USER_HOME=/gradle-home \
|
||||
-v "$HOME/.cache/gastinelclaims-gradle:/gradle-home" \
|
||||
-v "$(pwd):/src" -w /src \
|
||||
eclipse-temurin:21-jdk \
|
||||
sh ./gradlew --no-daemon clean test > "$D/build.log" 2>&1
|
||||
CODE=$?
|
||||
set -e
|
||||
echo "code de sortie gradle : $CODE"
|
||||
grep -E "FAILED|BUILD|error:|tests completed" "$D/build.log" | head -40
|
||||
echo "--- totaux (XML JUnit) ---"
|
||||
T=0; F=0; E=0; S=0
|
||||
for x in build/test-results/test/*.xml; do
|
||||
[ -f "$x" ] || continue
|
||||
l=$(grep -o '<testsuite [^>]*>' "$x" | head -1)
|
||||
t=$(echo "$l" | sed -n 's/.* tests="\([0-9]*\)".*/\1/p'); f=$(echo "$l" | sed -n 's/.* failures="\([0-9]*\)".*/\1/p')
|
||||
e=$(echo "$l" | sed -n 's/.* errors="\([0-9]*\)".*/\1/p'); s=$(echo "$l" | sed -n 's/.* skipped="\([0-9]*\)".*/\1/p')
|
||||
T=$((T+t)); F=$((F+f)); E=$((E+e)); S=$((S+s))
|
||||
echo "$(basename "$x") tests=$t echecs=$f erreurs=$e ignores=$s"
|
||||
done
|
||||
echo "TOTAL tests=$T echecs=$F erreurs=$E ignores=$S"
|
||||
echo "--- echecs detailles ---"
|
||||
for x in build/test-results/test/*.xml; do grep -A8 '<failure' "$x" 2>/dev/null | head -30; done | head -120
|
||||
@@ -0,0 +1,230 @@
|
||||
package com.gastineltpa;
|
||||
|
||||
import com.gastineltpa.core.TpaRegistry;
|
||||
import com.gastineltpa.core.TpaRegistry.Request;
|
||||
import com.gastineltpa.core.TpaRegistry.Type;
|
||||
import com.gastineltpa.core.Warmups;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Autotests adverses de GastinelTpa (16/10/2026).
|
||||
*
|
||||
* Convention (comme GastinelGarde, branche test/cas-limites) : un test FAILLE_… ou FAUX_POSITIF_…
|
||||
* PASSE TANT QUE LE DÉFAUT EXISTE ; il échouera le jour du correctif et il faudra inverser son assertion.
|
||||
*
|
||||
* Preuves : logique pure (TpaRegistry, Warmups : code de production, horloge injectée) ou lecture du
|
||||
* source de production (pour ce qui demande un vrai ServerPlayer). Rien ici n'est testé en jeu.
|
||||
*/
|
||||
class AutotestTpaTest {
|
||||
|
||||
private long now;
|
||||
private TpaRegistry reg;
|
||||
private final UUID victime = UUID.randomUUID();
|
||||
private final UUID attaquant = UUID.randomUUID();
|
||||
private final UUID ami = UUID.randomUUID();
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
now = 1_000_000L;
|
||||
reg = new TpaRegistry(() -> now);
|
||||
}
|
||||
|
||||
/** Dossier du projet : le test tourne parfois dans build/minecraft-junit (moddev unitTest). */
|
||||
private static Path racine() {
|
||||
Path p = Path.of("").toAbsolutePath();
|
||||
while (p != null && !Files.isDirectory(p.resolve("src/main/java"))) p = p.getParent();
|
||||
assertNotNull(p, "dossier du projet introuvable depuis " + Path.of("").toAbsolutePath());
|
||||
return p;
|
||||
}
|
||||
|
||||
private static String source(String fichier) throws IOException {
|
||||
return Files.readString(racine().resolve("src/main/java/com/gastineltpa/" + fichier), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/** Corps (approximatif) d'une méthode : du nom jusqu'à la méthode suivante. */
|
||||
private static String methode(String src, String signature) {
|
||||
int i = src.indexOf(signature);
|
||||
assertTrue(i >= 0, "signature introuvable : " + signature);
|
||||
int j = src.indexOf("\n private static ", i + signature.length());
|
||||
int k = src.indexOf("\n static ", i + signature.length());
|
||||
int fin = src.length();
|
||||
if (j > 0) fin = Math.min(fin, j);
|
||||
if (k > 0) fin = Math.min(fin, k);
|
||||
return src.substring(i, fin);
|
||||
}
|
||||
|
||||
// --- T1 : appât /tpa remplacé par /tpahere ---
|
||||
|
||||
@Test
|
||||
void FAILLE_T1_tpaRemplaceeParTpahereLeBoutonAccepterDejaAfficheTirelaVictime() {
|
||||
// L'attaquant envoie /tpa (« je viens chez toi »), la victime lit le message, l'attaquant envoie
|
||||
// aussitôt /tpahere vers la même victime : add() REMPLACE la demande (même couple) par le nouveau
|
||||
// type. Le bouton [Accepter] du premier message lance « /tpaccept <attaquant> » : il accepte le TPAHERE
|
||||
// et c'est la victime qui est téléportée chez l'attaquant (piège, lave, base fermée, combat).
|
||||
reg.add(attaquant, victime, Type.TPA);
|
||||
now += 5_000;
|
||||
reg.add(attaquant, victime, Type.TPAHERE);
|
||||
Request acceptee = reg.find(victime, attaquant).orElseThrow(); // ce que fait /tpaccept <attaquant>
|
||||
assertEquals(Type.TPAHERE, acceptee.type(), "le bouton du message TPA accepte un TPAHERE");
|
||||
assertEquals(1, reg.size());
|
||||
}
|
||||
|
||||
// --- T2 : /tpaccept sans argument ---
|
||||
|
||||
@Test
|
||||
void FAILLE_T2_tpacceptSansArgumentAccepteLaDemandeLaPlusRecenteMemeDUnInconnu() {
|
||||
reg.add(ami, victime, Type.TPAHERE);
|
||||
now += 2_000;
|
||||
// La victime s'apprête à taper /tpaccept pour son ami ; l'attaquant glisse une demande juste avant.
|
||||
reg.add(attaquant, victime, Type.TPAHERE);
|
||||
assertEquals(attaquant, reg.latest(victime).orElseThrow().from());
|
||||
}
|
||||
|
||||
@Test
|
||||
void FAILLE_T2b_renvoyerUneDemandeLaRemetEnTete() {
|
||||
reg.add(attaquant, victime, Type.TPA);
|
||||
now += 1_000;
|
||||
reg.add(ami, victime, Type.TPA);
|
||||
now += 1_000;
|
||||
reg.add(attaquant, victime, Type.TPA); // spam du même couple : repasse en dernier
|
||||
assertEquals(attaquant, reg.latest(victime).orElseThrow().from());
|
||||
}
|
||||
|
||||
// --- T3 : spam ---
|
||||
|
||||
@Test
|
||||
void FAILLE_T3_aucuneLimiteNiRechargeSurLesDemandes() {
|
||||
for (int i = 0; i < 1_000; i++) {
|
||||
reg.add(attaquant, victime, Type.TPA); // chaque appel envoie un message cliquable à la victime
|
||||
}
|
||||
assertEquals(1, reg.size(), "même couple : remplacée, mais jamais refusée");
|
||||
for (int i = 0; i < 500; i++) reg.add(attaquant, UUID.randomUUID(), Type.TPA);
|
||||
assertEquals(501, reg.size(), "aucune limite de demandes simultanées par joueur");
|
||||
}
|
||||
|
||||
@Test
|
||||
void FAILLE_T3b_demanderNeConsulteAucuneRecharge() throws IOException {
|
||||
String d = methode(source("TpaCommands.java"), "private static int demander(");
|
||||
assertFalse(d.contains("RECHARGES") || d.contains("Cooldowns") || d.contains("disponible("),
|
||||
"/tpa consulte une recharge : faille corrigée ?");
|
||||
}
|
||||
|
||||
// --- T4 / T5 : téléportation, combat, sécurité de l'arrivée ---
|
||||
|
||||
@Test
|
||||
void FAILLE_T4_fuiteDeCombat_leDepartTpaNEstAnnuleNiParLesDegatsNiParLeMouvement() throws IOException {
|
||||
String s = source("TpaCommands.java");
|
||||
assertFalse(s.contains("Damage") || s.contains("hurt"), "TpaCommands écoute les dégâts : corrigé ?");
|
||||
assertFalse(s.contains("Warmups"), "le départ TPA utilise Warmups : corrigé ?");
|
||||
// Témoin : /spawn, /rtp, /home annulent bien sur dégât.
|
||||
assertTrue(source("SpawnRtpCommands.java").contains("Téléportation annulée : tu as été blessé."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void FAILLE_T5_arriveeTpaSansControleDeSecuriteNiDeClaim() throws IOException {
|
||||
// /home vérifie l'arrivée (verifierSur : bloc plein, lave, feu) ; TPA/TPAHERE téléporte à la position
|
||||
// exacte de la destination AU MOMENT DU DÉPART, quelle qu'elle soit (en l'air en élytres, au-dessus
|
||||
// du vide, dans un claim fermé…). En TPAHERE la destination est le demandeur : il choisit l'endroit.
|
||||
String t = methode(source("TpaCommands.java"), "private static void teleporter(");
|
||||
assertFalse(t.contains("verifierSur") || t.contains("ClaimsBridge") || t.contains("onGround"),
|
||||
"teleporter TPA contrôle l'arrivée : corrigé ?");
|
||||
}
|
||||
|
||||
// --- T6 : chute après /tpaccept (#90) ---
|
||||
|
||||
@Test
|
||||
void FAILLE_T6_issue90_laChuteCommenceeAvantLaTpEstGardeeALArrivee() throws IOException {
|
||||
// Sur la branche testée (commit 184dbbf), teleporter TPA ne remet pas fallDistance à 0, alors que
|
||||
// /home et /rtp le font. NB : le correctif (3 lignes) existe NON COMMITÉ dans la copie de travail
|
||||
// principale (version 1.2.2) ; ce test échouera dès qu'il sera commité, c'est voulu.
|
||||
String t = methode(source("TpaCommands.java"), "private static void teleporter(");
|
||||
assertFalse(t.contains("fallDistance"), "teleporter TPA remet la chute à zéro : #90 corrigé");
|
||||
assertTrue(methode(source("SpawnRtpCommands.java"), "private static void teleporter(")
|
||||
.contains("p.fallDistance = 0;"), "témoin /rtp");
|
||||
assertTrue(source("HomesCommands.java").contains("p.fallDistance = 0;"), "témoin /home");
|
||||
}
|
||||
|
||||
// --- T7 : /home dans un chunk claimé après coup ---
|
||||
|
||||
@Test
|
||||
void FAILLE_T7_homeNeReverifiePasLeClaimALArrivee() throws IOException {
|
||||
String h = source("HomesCommands.java");
|
||||
assertTrue(methode(h, "private static int definir(").contains("ClaimsBridge.autorise")
|
||||
|| h.contains("ClaimsBridge.autorise(niveau, p.getUUID()"),
|
||||
"témoin : /sethome vérifie le claim");
|
||||
String partir = methode(h, "private static void partir(");
|
||||
assertFalse(partir.contains("ClaimsBridge"), "/home revérifie le claim : corrigé ?");
|
||||
}
|
||||
|
||||
// --- T8 : délai /home /spawn : dérive lente ---
|
||||
|
||||
@Test
|
||||
void FAUX_POSITIF_ou_FAILLE_T8_warmupToleranceMesureeDepuisLeDepart() {
|
||||
// Mesure : la tolérance (0,6 bloc) est comptée depuis la position de départ, pas par tick.
|
||||
// Être poussé par l'eau ou un piston annule (faux positif possible) ; à l'inverse rester immobile
|
||||
// pendant qu'un allié frappe n'est pas « blessé » si les dégâts sont annulés (bouclier) [À VÉRIFIER].
|
||||
Warmups w = new Warmups();
|
||||
UUID j = UUID.randomUUID();
|
||||
w.start(j, "home", 0, 64, 0, 60);
|
||||
double[] pos = {0, 64, 0};
|
||||
int ticks = 0;
|
||||
Warmups.Fin fin = null;
|
||||
while (fin == null && ticks < 60) {
|
||||
pos[0] += 0.05; // courant d'eau lent : 1 bloc/s
|
||||
ticks++;
|
||||
for (Warmups.Resultat r : w.tick(id -> pos)) fin = r.fin();
|
||||
}
|
||||
assertEquals(Warmups.Fin.BOUGE, fin);
|
||||
assertTrue(ticks <= 13, "annulé après " + ticks + " ticks de dérive");
|
||||
}
|
||||
|
||||
// --- Réfutés (comportement correct) ---
|
||||
|
||||
@Test
|
||||
void honnete_deconnexionRetireToutesLesDemandesDuJoueur() {
|
||||
reg.add(attaquant, victime, Type.TPA);
|
||||
reg.add(victime, ami, Type.TPAHERE);
|
||||
reg.add(ami, attaquant, Type.TPA);
|
||||
assertEquals(2, reg.removeInvolving(victime).size());
|
||||
assertTrue(reg.find(victime, attaquant).isEmpty());
|
||||
assertEquals(1, reg.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void honnete_deconnexionPendantLeDelaiAnnuleLeDepart() throws IOException {
|
||||
String s = source("TpaCommands.java");
|
||||
assertTrue(s.contains("EN_COURS.removeIf(d -> d.voyageur().equals(parti.getUUID()) || d.destination().equals(parti.getUUID()));"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void honnete_uneDemandeAccepteeNePeutPasEtreAccepteeDeuxFois() {
|
||||
Request r = reg.add(attaquant, victime, Type.TPA);
|
||||
assertTrue(reg.remove(r)); // /tpaccept retire la demande avant de programmer le départ
|
||||
assertFalse(reg.remove(r));
|
||||
assertTrue(reg.find(victime, attaquant).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void honnete_demandeExpireeApres60sInacceptable() {
|
||||
reg.add(attaquant, victime, Type.TPAHERE);
|
||||
now += TpaRegistry.EXPIRATION_MS;
|
||||
assertTrue(reg.find(victime, attaquant).isEmpty());
|
||||
assertTrue(reg.latest(victime).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void honnete_annulerNeTouchePasLesDemandesDesAutres() {
|
||||
reg.add(ami, victime, Type.TPA);
|
||||
assertTrue(reg.cancel(attaquant, victime).isEmpty());
|
||||
assertTrue(reg.find(victime, ami).isPresent());
|
||||
}
|
||||
}
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur