Files
ik-codex/test/tests/Games/ProjectZomboid/Log/ProjectZomboidPerkLogTest.php
indifferentketchup 0c90e40a28
Some checks failed
Tests / Run tests on PHP v8.4 (push) Failing after 1s
Tests / Run tests on PHP v8.5 (push) Failing after 0s
Add SkillProgressionAnomalyAnalyser
Compares consecutive perks-snapshot rows per Steam ID and emits a
SkillProgressionAnomalyProblem for any single skill whose level gained
more than THRESHOLD_DELTA between two snapshots. Login/Logout/LevelUp
event rows are skipped via a perk-pair regex check on the bracketed
event field.

Threshold of 3 reflects PZ's slow leveling pace: typical session bridges
should not produce four-or-more level jumps in a single skill. The
constant is documented inline so operators can tune for modded XP
servers without touching analysis logic.

Synthetic fixture extended with a PlayerSuspect Steam ID carrying two
snapshots: Strength jumps 2 -> 10 (delta +8, triggers), Fitness jumps
2 -> 8 (+6, triggers), Maintenance jumps 0 -> 3 (+3, exactly at
threshold, does NOT trigger). The existing single-snapshot players
remain noise-free.
2026-04-30 22:43:44 +00:00

60 lines
2.2 KiB
PHP

<?php
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Log;
use IndifferentKetchup\Codex\Detective\Detective;
use IndifferentKetchup\Codex\Log\File\PathLogFile;
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidPerkLog;
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\PerkPattern;
use PHPUnit\Framework\TestCase;
class ProjectZomboidPerkLogTest extends TestCase
{
private function fixturePath(): string
{
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/perk-minimal.txt';
}
public function testParsesEachLineAsAnEntry(): void
{
$log = (new ProjectZomboidPerkLog())->setLogFile(new PathLogFile($this->fixturePath()));
$log->parse();
$this->assertCount(10, $log->getEntries());
}
public function testFieldsRegexHandlesEventRow(): void
{
$line = '[16-04-26 18:29:08.171] [76561198000000001][Player1][1000,2000,1][Login][Hours Survived: 100].';
$this->assertSame(1, preg_match(PerkPattern::FIELDS, $line, $m));
$this->assertSame('Player1', $m['player']);
$this->assertSame('Login', $m['event']);
$this->assertSame('100', $m['hours']);
}
public function testFieldsRegexHandlesPerksRow(): void
{
$line = '[16-04-26 18:30:02.500] [76561198000000003][AdminUser][1020,2020,0][Logout][Hours Survived: 75].';
$this->assertSame(1, preg_match(PerkPattern::FIELDS, $line, $m));
$this->assertSame('Logout', $m['event']);
}
public function testPerkPairRegexExtractsSkillsFromBracketedList(): void
{
$bracket = 'Cooking=5, Fitness=6, Strength=7';
$count = preg_match_all(PerkPattern::PERK_PAIR, $bracket, $matches, PREG_SET_ORDER);
$this->assertSame(3, $count);
$this->assertSame('Cooking', $matches[0]['skill']);
$this->assertSame('5', $matches[0]['level']);
}
public function testDetectiveDispatchesByContent(): void
{
$detective = (new Detective())
->setLogFile(new PathLogFile($this->fixturePath()))
->addPossibleLogClass(ProjectZomboidPerkLog::class);
$this->assertInstanceOf(ProjectZomboidPerkLog::class, $detective->detect());
}
}