test(compare): enforce invader resume watchdog
This commit is contained in:
@@ -886,6 +886,15 @@ function comparisonUnificationInvaderResumeTrace(array $request, array $environm
|
|||||||
'autoresetAnchor' => $gameStorage->autoreset_united_wall_anchor,
|
'autoresetAnchor' => $gameStorage->autoreset_united_wall_anchor,
|
||||||
'autoresetAnchorRefreshed' => $gameStorage->autoreset_united_wall_anchor !== $pausedAnchor,
|
'autoresetAnchorRefreshed' => $gameStorage->autoreset_united_wall_anchor !== $pausedAnchor,
|
||||||
];
|
];
|
||||||
|
if (
|
||||||
|
$decisionResult !== RaiseInvaderMessage::ACCEPTED
|
||||||
|
|| $afterSummon['isunited'] !== 1
|
||||||
|
|| $afterSummon['plock'] !== 0
|
||||||
|
|| $afterSummon['invaderNationCount'] !== 7
|
||||||
|
|| $afterSummon['autoresetAnchorRefreshed'] !== true
|
||||||
|
) {
|
||||||
|
throw new \RuntimeException('invader choice did not start an unlocked, watchdog-active event game');
|
||||||
|
}
|
||||||
|
|
||||||
$resumeBoundary = addTurn(
|
$resumeBoundary = addTurn(
|
||||||
cutTurn(Util::toInt($gameStorage->turntime), Util::toInt($gameStorage->turnterm)),
|
cutTurn(Util::toInt($gameStorage->turntime), Util::toInt($gameStorage->turnterm)),
|
||||||
@@ -938,6 +947,19 @@ function comparisonUnificationInvaderResumeTrace(array $request, array $environm
|
|||||||
'autoresetAnchor' => $gameStorage->autoreset_united_wall_anchor,
|
'autoresetAnchor' => $gameStorage->autoreset_united_wall_anchor,
|
||||||
'autoresetAnchorRefreshed' => $gameStorage->autoreset_united_wall_anchor !== $stalledAnchor,
|
'autoresetAnchorRefreshed' => $gameStorage->autoreset_united_wall_anchor !== $stalledAnchor,
|
||||||
];
|
];
|
||||||
|
$expectedYear = $month === 12 ? $year + 1 : $year;
|
||||||
|
$expectedMonth = $month === 12 ? 1 : $month + 1;
|
||||||
|
if (
|
||||||
|
$afterResume['turntime'] < $resumeBoundary
|
||||||
|
|| $afterResume['year'] !== $expectedYear
|
||||||
|
|| $afterResume['month'] !== $expectedMonth
|
||||||
|
|| $afterResume['isunited'] !== 1
|
||||||
|
|| $afterResume['lockedCalls'] !== 0
|
||||||
|
|| $afterResume['plock'] !== 0
|
||||||
|
|| $afterResume['autoresetAnchorRefreshed'] !== true
|
||||||
|
) {
|
||||||
|
throw new \RuntimeException('invader event game did not advance through the next monthly boundary');
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'schemaVersion' => 1,
|
'schemaVersion' => 1,
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class AutoResetProgressTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRecordStoresInjectedWallTimeWithMicroseconds(): void
|
||||||
|
{
|
||||||
|
$storage = $this->createMock(KVStorage::class);
|
||||||
|
$storage->expects(self::once())
|
||||||
|
->method('setValue')
|
||||||
|
->with(
|
||||||
|
AutoResetProgress::STORAGE_KEY,
|
||||||
|
'2026-08-12 15:40:12.345678',
|
||||||
|
)
|
||||||
|
->willReturnSelf();
|
||||||
|
|
||||||
|
AutoResetProgress::record(
|
||||||
|
$storage,
|
||||||
|
new \DateTimeImmutable('2026-08-12 15:40:12.345678 UTC'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRecordIfAdvancedIgnoresEqualOrRegressiveTicks(): void
|
||||||
|
{
|
||||||
|
$storage = $this->createMock(KVStorage::class);
|
||||||
|
$storage->expects(self::never())->method('setValue');
|
||||||
|
|
||||||
|
self::assertFalse(AutoResetProgress::recordIfAdvanced($storage, 100, 100));
|
||||||
|
self::assertFalse(AutoResetProgress::recordIfAdvanced($storage, 100, 99));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRecordIfAdvancedRefreshesTheWatchdogAnchor(): void
|
||||||
|
{
|
||||||
|
$storage = $this->createMock(KVStorage::class);
|
||||||
|
$storage->expects(self::once())
|
||||||
|
->method('setValue')
|
||||||
|
->with(
|
||||||
|
AutoResetProgress::STORAGE_KEY,
|
||||||
|
'2026-08-12 15:41:00.000001',
|
||||||
|
)
|
||||||
|
->willReturnSelf();
|
||||||
|
|
||||||
|
self::assertTrue(AutoResetProgress::recordIfAdvanced(
|
||||||
|
$storage,
|
||||||
|
100,
|
||||||
|
101,
|
||||||
|
new \DateTimeImmutable('2026-08-12 15:41:00.000001 UTC'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user