From 36f224ba2b1920bffe2b3d9996bb7fb7a7ce21e8 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 5 Oct 2026 10:27:05 -0400 Subject: [PATCH 1/3] test(cache): clarify and strengthen home cache size coverage The existing tests checked `files` folder size calculations, but did not verify that the root also reports the recalculated `files`-folder size. One test's comment also referred to unknown sizes that were not present in its fixture. - Assert the recalculated `files` size and the root's reported size. - Insert a root-level file to show that it does not affect the root's reported size. - Remove unused fixture data and redundant cleanup. Assisted-by: Copilot:gpt-6-luna Signed-off-by: Josh --- tests/lib/Files/Cache/HomeCacheTest.php | 45 +++++++++++++------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/lib/Files/Cache/HomeCacheTest.php b/tests/lib/Files/Cache/HomeCacheTest.php index 23d8ae278948a..828505e4f0727 100644 --- a/tests/lib/Files/Cache/HomeCacheTest.php +++ b/tests/lib/Files/Cache/HomeCacheTest.php @@ -37,6 +37,9 @@ public function getUID(): string { } } +/** + * Tests home-storage-specific cache behavior, with a current focus on size reporting. + */ #[Group('DB')] class HomeCacheTest extends TestCase { private Home $storage; @@ -53,11 +56,10 @@ protected function setUp(): void { } /** - * Tests that the root and files folder size calculation ignores the subdirs - * that have an unknown size. This makes sure that quota calculation still - * works as it's based on the "files" folder size. + * The files folder size must ignore children with unknown sizes, and the root + * must report the files folder size. */ - public function testRootFolderSizeIgnoresUnknownUpdate(): void { + public function testFilesFolderSizeIgnoresUnknownChildSizes(): void { $dir1 = 'files/knownsize'; $dir2 = 'files/unknownsize'; $fileData = []; @@ -75,43 +77,44 @@ public function testRootFolderSizeIgnoresUnknownUpdate(): void { $this->assertTrue($this->cache->inCache($dir1)); $this->assertTrue($this->cache->inCache($dir2)); - // check that files and root size ignored the unknown sizes - $this->assertEquals(1000, $this->cache->calculateFolderSize('files')); + $this->assertSame(1000, $this->cache->calculateFolderSize('files')); + $this->assertSame(1000, $this->cache->get('files')['size']); + $this->assertSame(1000, $this->cache->get('')['size']); - // clean up + // Removing the root also removes its descendants. $this->cache->remove(''); - $this->cache->remove('files'); - $this->cache->remove($dir1); - $this->cache->remove($dir2); + $this->assertFalse($this->cache->inCache('')); $this->assertFalse($this->cache->inCache('files')); $this->assertFalse($this->cache->inCache($dir1)); $this->assertFalse($this->cache->inCache($dir2)); } - public function testRootFolderSizeIsFilesSize(): void { + /** + * The root reports the files folder size, not the stored root size or the + * size of other entries directly under the root. + */ + public function testRootFolderSizeMatchesFilesFolderSize(): void { $dir1 = 'files'; - $afile = 'test.txt'; $fileData = []; $fileData[''] = ['size' => 1500, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']; $fileData[$dir1] = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']; - $fileData[$afile] = ['size' => 500, 'mtime' => 20]; + $fileData['test.txt'] = ['size' => 500, 'mtime' => 20, 'mimetype' => 'text/plain']; $this->cache->put('', $fileData['']); $this->cache->put($dir1, $fileData[$dir1]); + $this->cache->put('test.txt', $fileData['test.txt']); - $this->assertTrue($this->cache->inCache($dir1)); + $this->assertTrue($this->cache->inCache('test.txt')); - // check that root size ignored the unknown sizes - $data = $this->cache->get('files'); - $this->assertEquals(1000, $data['size']); - $data = $this->cache->get(''); - $this->assertEquals(1000, $data['size']); + $this->assertSame(1000, $this->cache->get('files')['size']); + $this->assertSame(1000, $this->cache->get('')['size']); - // clean up + // Removing the root also removes its descendants. $this->cache->remove(''); - $this->cache->remove($dir1); + $this->assertFalse($this->cache->inCache('')); $this->assertFalse($this->cache->inCache($dir1)); + $this->assertFalse($this->cache->inCache('test.txt')); } } From 7850da8b58c9cead749eb7c76042aac24c9bdbf1 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 5 Oct 2026 10:30:54 -0400 Subject: [PATCH 2/3] test(cache): cover home special-folder size handling The HomeCache size-calculation behavior for `files_trashbin` and `files_versions` was not covered. Add data-driven tests verifying that known-size children contribute to each folder's calculated size while children with unknown sizes are ignored. Assisted-by: Copilot:gpt-6-luna Signed-off-by: Josh --- tests/lib/Files/Cache/HomeCacheTest.php | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/lib/Files/Cache/HomeCacheTest.php b/tests/lib/Files/Cache/HomeCacheTest.php index 828505e4f0727..5968418c47bbc 100644 --- a/tests/lib/Files/Cache/HomeCacheTest.php +++ b/tests/lib/Files/Cache/HomeCacheTest.php @@ -117,4 +117,31 @@ public function testRootFolderSizeMatchesFilesFolderSize(): void { $this->assertFalse($this->cache->inCache($dir1)); $this->assertFalse($this->cache->inCache('test.txt')); } + + public static function specialFolderPathsDataProvider(): array { + return [ + ['files_trashbin'], + ['files_versions'], + ]; + } + + #[\PHPUnit\Framework\Attributes\DataProvider('specialFolderPathsDataProvider')] + public function testSpecialFolderSizeIgnoresUnknownChildSizes(string $path): void { + $knownSizePath = $path . '/knownsize'; + $unknownSizePath = $path . '/unknownsize'; + + $this->cache->put('', ['size' => 0, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']); + $this->cache->put($path, ['size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']); + $this->cache->put($knownSizePath, ['size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']); + $this->cache->put($unknownSizePath, ['size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory']); + + $this->assertSame(1000, $this->cache->calculateFolderSize($path)); + $this->assertSame(1000, $this->cache->get($path)['size']); + + $this->cache->remove(''); + + $this->assertFalse($this->cache->inCache($path)); + $this->assertFalse($this->cache->inCache($knownSizePath)); + $this->assertFalse($this->cache->inCache($unknownSizePath)); + } } From f06a22c58c36f5b3426e74b742f7d9f358004927 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 5 Oct 2026 10:35:41 -0400 Subject: [PATCH 3/3] test(cache): cover slash root alias behavior The slash root alias had a separate HomeCache code path from the empty root path, but its no-op size calculation and reported size were not directly tested. Verify that calculating `/` returns zero and reading `/` reports the size of the `files` folder. Assisted-by: Copilot:gpt-6-luna Signed-off-by: Josh --- tests/lib/Files/Cache/HomeCacheTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/lib/Files/Cache/HomeCacheTest.php b/tests/lib/Files/Cache/HomeCacheTest.php index 5968418c47bbc..855a9ab136c0b 100644 --- a/tests/lib/Files/Cache/HomeCacheTest.php +++ b/tests/lib/Files/Cache/HomeCacheTest.php @@ -144,4 +144,17 @@ public function testSpecialFolderSizeIgnoresUnknownChildSizes(string $path): voi $this->assertFalse($this->cache->inCache($knownSizePath)); $this->assertFalse($this->cache->inCache($unknownSizePath)); } + + public function testSlashRootAliasUsesFilesFolderSize(): void { + $this->cache->put('', ['size' => 1500, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']); + $this->cache->put('files', ['size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']); + + $this->assertSame(0, $this->cache->calculateFolderSize('/')); + $this->assertSame(1000, $this->cache->get('/')['size']); + + $this->cache->remove(''); + + $this->assertFalse($this->cache->inCache('')); + $this->assertFalse($this->cache->inCache('files')); + } }