Skip to content

test: fix intermittent CI failures in PHPUnit and Cypress suites#60802

Draft
miaulalala wants to merge 5 commits into
masterfrom
worktree-fix+noid+flaky-test-fixes
Draft

test: fix intermittent CI failures in PHPUnit and Cypress suites#60802
miaulalala wants to merge 5 commits into
masterfrom
worktree-fix+noid+flaky-test-fixes

Conversation

@miaulalala
Copy link
Copy Markdown
Contributor

Summary

Fixes five identified flaky test patterns found by cross-referencing ~50 recent CI failure runs:

  • CacheTest::testExtendedgetFolderContentsById has no ORDER BY, so insertion order is not guaranteed. MariaDB 11.8 returns rows in a different physical order than earlier versions, causing consistent assertion failures on that matrix. Fix: sort by name before asserting.

  • ViewTest::testCopyBetweenStorageCrossNonLocal — Three testCopyBetweenStorage* variants all mount at the fixed paths / and /substorage. These mounts persist in the Filesystem singleton between tests; stale cache entries from a prior test's storage can cause copyFromCache() to fail its put() consistency check on MySQL 8.0/8.4. Fix: use getUniqueID('/') (the same pattern already used in testCacheAPI) to scope each invocation to its own mount namespace.

  • files-renaming.cy.ts / FilesUtils::renameFile (5× CI failures) — After triggerActionForFile('rename'), Vue replaces the file row element. All 9 test cases in files-renaming.cy.ts and the renameFile() utility chained .findByRole()/.find() off getRowForFile(), which holds the now-detached element. Fix: use a fresh top-level cy.findByRole() / cy.get() after the action; Cypress retries from the document root and survives the re-render. Also fixes live_photos.cy.ts failures that call renameFile().

  • filesVersionsUtils::toggleVersionMenu (4× CI failures in version_deletion.cy.ts) — Chained .eq(index).find('button') is the canonical stale DOM pattern: if the versions list re-renders between finding the nth entry and finding its button, the intermediate element is detached. Fix: query all version buttons in one combined selector and pick by index, so Cypress retries the full query as a unit. Also stabilises openVersionsPanel by: (a) removing the @sidebar alias that could go stale, and (b) waiting for at least one version entry to render before returning.

Test plan

  • PHP unit: NOCOVERAGE=1 ./autotest.sh sqlite tests/lib/Files/Cache/CacheTest.phptestExtended passes
  • PHP unit: NOCOVERAGE=1 ./autotest.sh sqlite tests/lib/Files/ViewTest.php — all testCopyBetweenStorage* pass
  • Cypress: files-renaming.cy.ts and files_versions/version_deletion.cy.ts — no stale DOM errors on repeated runs
  • CI: observe reduced flakiness in Cypress files-renaming, version_deletion, live_photos specs and PHPUnit MySQL/MariaDB matrix

🤖 Generated with Claude Code

…ore asserting order

getFolderContentsById issues no ORDER BY, so insertion order is not guaranteed.
MariaDB 11.8 returns rows in a different physical order than earlier versions,
causing consistent assertion failures on that matrix combination.

Signed-off-by: Anna Larch <anna@nextcloud.com>
AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The three testCopyBetweenStorage* variants all mount at the fixed paths /
and /substorage. These paths persist in the Filesystem mount singleton
between tests; if a prior test's cache entries linger under the same
storage numeric ID, copyFromCache() sees an existing entry and can fail
its consistency check on MySQL 8.0/8.4.

Using getUniqueID('/') (the same pattern as testCacheAPI) scopes each test
invocation to its own mount namespace, preventing cross-test contamination.

Signed-off-by: Anna Larch <anna@nextcloud.com>
AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…and files-renaming

After triggerActionForFile('rename') Vue re-renders the file row, detaching
the DOM element previously returned by getRowForFile(). Chaining .find() or
.findByRole() off that stale element causes Cypress to throw "subject is no
longer attached to the DOM".

Fix: use a fresh top-level cy.get()/cy.findByRole() after the rename action
instead of chaining off the row element. A fresh query causes Cypress to
retry from the document root, surviving the re-render.

This affects all 9 test cases in files-renaming.cy.ts and the renameFile()
utility in FilesUtils.ts (which is also used by live_photos.cy.ts).

Signed-off-by: Anna Larch <anna@nextcloud.com>
AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…toggleVersionMenu

Two stale DOM issues in the versions panel utilities:

1. openVersionsPanel used cy.get('@Sidebar').find(...) to locate the versions
   tab button. If the sidebar re-renders after opening, the stored alias is
   stale. Fix: use a fresh combined selector cy.get('[data-cy-sidebar] [...]').
   Also add a wait for at least one version entry to be rendered before
   returning, ensuring callers don't race against the list population.

2. toggleVersionMenu chained .find('button') off .eq(index), which is a
   common stale DOM pattern: if the versions list re-renders between finding
   the nth entry and finding its button, the intermediate element is detached.
   Fix: query all version buttons in one selector and pick by index, so
   Cypress retries the full query as a unit.

Signed-off-by: Anna Larch <anna@nextcloud.com>
AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@miaulalala miaulalala requested review from a team as code owners May 28, 2026 12:39
@miaulalala miaulalala requested review from ArtificialOwl, leftybournes, nfebe, sorbaugh and susnux and removed request for a team May 28, 2026 12:39
@miaulalala miaulalala self-assigned this May 28, 2026
@miaulalala miaulalala added 3. to review Waiting for reviews tests Related to tests CI AI assisted labels May 28, 2026
@miaulalala miaulalala marked this pull request as draft May 28, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews AI assisted CI tests Related to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant