refactor: ChangeLog::recordPartial and column-size truncation

recordPartial() replaces the partial-log FollowUp blocks in content-create,
content-update and post-replace-with-copy; record() truncates ability,
object_type and object_id to their column sizes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-26 01:15:13 +02:00
co-authored by Claude Opus 5.5
parent 46a445fe9d
commit 0c4da28855
8 changed files with 94 additions and 47 deletions
+47
View File
@@ -67,6 +67,53 @@ final class ChangeLogTest extends TestCase
unlink($log);
}
public function testRecordTruncatesObjectIdAndAbilityToTheColumnSizes(): void
{
Functions\when('current_time')->justReturn('2026-09-25 08:00:00');
Functions\when('get_current_user_id')->justReturn(3);
$db = Mockery::mock(\wpdb::class)->makePartial();
$db->expects('insert')
->with('wp_lit_mcp_log', Mockery::on(static function (array $row): bool {
return $row['object_id'] === str_repeat('ä', 191) && $row['ability'] === str_repeat('ö', 100);
}), Mockery::type('array'))
->andReturn(1);
(new ChangeLog($db))->record(str_repeat('ö', 150), 'option', str_repeat('ä', 300), 'x');
}
public function testRecordPartialStoresResultPartial(): void
{
Functions\when('current_time')->justReturn('2026-09-25 08:00:00');
Functions\when('get_current_user_id')->justReturn(3);
$db = Mockery::mock(\wpdb::class)->makePartial();
$db->expects('insert')
->with('wp_lit_mcp_log', Mockery::on(static function (array $row): bool {
return $row['result'] === 'partial' && $row['revision_id'] === 7 && $row['object_id'] === '12';
}), Mockery::type('array'))
->andReturn(1);
(new ChangeLog($db))->recordPartial('lit/content-update', 'page', '12', 'teilweise', 7);
}
public function testRecordPartialNeverThrows(): void
{
Functions\when('current_time')->justReturn('2026-09-25 08:00:00');
Functions\when('get_current_user_id')->justReturn(3);
$db = Mockery::mock(\wpdb::class)->makePartial();
$db->allows('insert')->andThrow(new \RuntimeException('db gone'));
$log = (string) tempnam(sys_get_temp_dir(), 'lit-mcp-log');
$previous = ini_set('error_log', $log);
try {
(new ChangeLog($db))->recordPartial('lit/menu-set-items', 'nav_menu', '4', 'teilweise');
} finally {
ini_set('error_log', (string) $previous);
}
self::assertStringContainsString('db gone', (string) file_get_contents($log));
unlink($log);
}
public function testPurgeDeletesRowsOlderThanTheRetention(): void
{
$db = Mockery::mock(\wpdb::class)->makePartial();