feat: add coordinates redaction pass

Adds three COORDS_*_REGEX constants (at-clause, bracketed, parenthesised)
plus COORDS_REPLACEMENT, wires them into redact(), and covers all three
contexts with 8 new tests including a critical negative test asserting
DebugLog-server.txt server-metadata triples are not redacted.
Also updates two Task 3 player-name tests whose expected strings now
include the coords redaction that the wired pass applies.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-01 14:49:52 +00:00
parent 44b6b99047
commit 2d1cbccc5d
3 changed files with 148 additions and 7 deletions

View File

@@ -42,27 +42,30 @@ class ProjectZomboidRedactorPlayerNameTest extends TestCase
// The second name (after "hit") is NOT yet redacted — deferred to v2.
// The weapon name ("Tire Iron (Worn)") must also survive unchanged.
$input = '[16-04-26 17:14:35.128][INFO] Combat: "Player1" (1005,2005,0) hit "Player2" (1006,2005,0) weapon="Tire Iron (Worn)" damage=0.112317.';
$expected = '[16-04-26 17:14:35.128][INFO] Combat: "<player>" (1005,2005,0) hit "Player2" (1006,2005,0) weapon="Tire Iron (Worn)" damage=0.112317.';
// Attacker coords (before "hit") are also replaced by the coordinates pass.
// Victim coords (before "weapon=") lack the trailing keyword and are NOT replaced — deferred to v2.
$expected = '[16-04-26 17:14:35.128][INFO] Combat: "<player>" (0,0,0) hit "Player2" (1006,2005,0) weapon="Tire Iron (Worn)" damage=0.112317.';
$output = (new ProjectZomboidRedactor())
->redactSteamIds(false)
->redact($input);
// Player1 (after "Combat: ") is replaced; Player2 (after "hit") is NOT
// replaced in v1 — that anchor is deferred.
$this->assertSame($expected, $output, 'First Combat: player name must be replaced; second name and weapon must survive.');
// Player1 (after "Combat: ") is replaced; attacker coords (before "hit") are also replaced.
// Player2 (after "hit") and victim coords (before "weapon=") are NOT replaced in v1 — deferred.
$this->assertSame($expected, $output, 'First Combat: player name and attacker coords must be replaced; second name, victim coords, and weapon must survive.');
}
public function testRedactsSafetyNameInPvpLog(): void
{
$input = '[16-04-26 16:17:49.731][LOG] Safety: "Player1" (1000,2000,0) restore true.';
$expected = '[16-04-26 16:17:49.731][LOG] Safety: "<player>" (1000,2000,0) restore true.';
// Coords (before ") restore") are also replaced by the coordinates pass.
$expected = '[16-04-26 16:17:49.731][LOG] Safety: "<player>" (0,0,0) restore true.';
$output = (new ProjectZomboidRedactor())
->redactSteamIds(false)
->redact($input);
$this->assertSame($expected, $output, 'Player name following the Safety: token must be replaced.');
$this->assertSame($expected, $output, 'Player name and coords following the Safety: token must both be replaced.');
}
public function testBareQuotedStringWithoutAnchorIsNotTouched(): void