Skip to content

test(media): inject the failed registry write instead of chmod-ing the temp dir - #280

Merged
EtienneLescot merged 1 commit into
mainfrom
fix/media-links-registry-test
Aug 5, 2026
Merged

test(media): inject the failed registry write instead of chmod-ing the temp dir#280
EtienneLescot merged 1 commit into
mainfrom
fix/media-links-registry-test

Conversation

@EtienneLescot

@EtienneLescot EtienneLescot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

"logs a refresh it cannot write" arranged its failure with chmod(tempDir, 0o555). That is not a portable way to make a write fail: on Windows the bit
lands on a directory attribute that does not stop a file being created inside,
so the refresh succeeded, nothing warned, and the case failed on every Windows
dev machine. skipIf(process.getuid?.() === 0) could not catch it either —
getuid is undefined there, so the guard read as "not root" and ran anyway.

CI only runs the suite on ubuntu-latest, so this stayed green there while being
permanently red locally — which is the worst shape a test can have: it teaches
you to skim past a red suite on the machine the app is actually developed on.

The write is now failed by injection (vi.spyOn(fs, "writeFile")), which
asserts the same thing on every platform and at any privilege level, and the
spy is asserted to have been called so the case cannot pass with the refresh
path deleted. Verified by ablation: dropping the .catch() in
findMediaLinksByFingerprint still turns it red, with the rejection escaping as
the unhandled one it exists to prevent.

Summary by CodeRabbit

  • Tests
    • Updated refresh failure coverage to work consistently across platforms.
    • Added verification that linked media remains available when a refresh write fails.
    • Confirmed failures are logged as warnings without causing unhandled errors.

…e temp dir

"logs a refresh it cannot write" arranged its failure with `chmod(tempDir,
0o555)`. That is not a portable way to make a write fail: on Windows the bit
lands on a directory attribute that does not stop a file being created inside,
so the refresh succeeded, nothing warned, and the case failed on every Windows
dev machine. `skipIf(process.getuid?.() === 0)` could not catch it either —
`getuid` is undefined there, so the guard read as "not root" and ran anyway.

CI only runs the suite on ubuntu-latest, so this stayed green there while being
permanently red locally — which is the worst shape a test can have: it teaches
you to skim past a red suite on the machine the app is actually developed on.

The write is now failed by injection (`vi.spyOn(fs, "writeFile")`), which
asserts the same thing on every platform and at any privilege level, and the
spy is asserted to have been called so the case cannot pass with the refresh
path deleted. Verified by ablation: dropping the `.catch()` in
findMediaLinksByFingerprint still turns it red, with the rejection escaping as
the unhandled one it exists to prevent.
@EtienneLescot
EtienneLescot merged commit 642f868 into main Aug 5, 2026
14 of 15 checks passed
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 939a2aba-ab5b-4753-8ca6-bf89514f4388

📥 Commits

Reviewing files that changed from the base of the PR and between cf57998 and 7b4dd6f.

📒 Files selected for processing (1)
  • electron/media/mediaLinksRegistry.test.ts

📝 Walkthrough

Walkthrough

The refresh failure test now mocks fs.writeFile to reject with EACCES. It verifies that lookup returns linked media, logs a warning, attempts the write, and produces no unhandled rejection.

Changes

Media refresh failure handling

Layer / File(s) Summary
Mocked refresh write failure coverage
electron/media/mediaLinksRegistry.test.ts
The test replaces permission-based failure setup with an EACCES fs.writeFile rejection. It verifies lookup success, warning logging, write invocation, and unhandled rejection handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: arhxam

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/media-links-registry-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant