fix: Snapshot-Option je Bereich auf 8 MB begrenzen, älteste Einträge fallen heraus

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-16 18:03:49 +02:00
co-authored by Claude Opus 5.5
parent fe8a01f878
commit 60c31f9697
2 changed files with 50 additions and 3 deletions
@@ -64,6 +64,32 @@ final class SnapshotStoreTest extends TestCase
self::assertNull($store->get('presets', $ids[1]));
}
/** Final review I-4: the option as a whole stays below TOTAL_BYTES; the oldest entries fall out first. */
public function testKeepsTheOptionBelowTheTotalSize(): void
{
$store = new SnapshotStore();
$big = ['x' => str_repeat('a', 1900000)];
$ids = [];
for ($i = 0; $i < 5; ++$i) {
$ids[] = $store->save('presets', $big + ['n' => $i], 'lit/divi-presets-set');
}
$list = $store->list('presets');
self::assertSame([$ids[4], $ids[3], $ids[2], $ids[1]], array_column($list, 'id'));
self::assertLessThanOrEqual(SnapshotStore::TOTAL_BYTES, array_sum(array_column($list, 'size')));
}
public function testOldEntriesOverTheTotalSizeFallOutButTheNewestStays(): void
{
$store = new SnapshotStore();
$store->save('presets', ['x' => str_repeat('a', 1900000)], 'lit/divi-presets-set');
$this->options['lit_mcp_snapshots_presets'][0]['size'] = SnapshotStore::TOTAL_BYTES + 1;
$newest = $store->save('presets', ['n' => 1], 'lit/divi-presets-set');
self::assertSame([$newest], array_column($store->list('presets'), 'id'));
}
public function testRefusesSnapshotsAboveTheLimit(): void
{
$this->expectException(SnapshotTooLarge::class);