fix(telemetry): silent-fs-error test exercises the actual code path

Earlier test used '/proc/0/...' as the unwritable dir. On Windows this
resolved to 'C:\proc\0\...' and mkdir({recursive: true}) silently created
it — the silent code path was never exercised, plus filesystem side-effect
leaked outside the test tmpdir.

Replace with a path that points to an existing file (mkdir on a file path
fails on every platform). Also add a companion test that confirms silent
is opt-in: without {silent: true}, the same fs failure DOES throw.

7 tests pass (was 6).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
altair823
2026-05-01 16:52:11 +09:00
parent 93e278b241
commit 50b6d05bcb

View File

@@ -58,17 +58,32 @@ describe('TelemetryService.emit', () => {
});
it('emit is silent (does not throw) when fs write fails — invariant: telemetry never breaks app', async () => {
// Pass a non-writable path; emit should swallow the error.
// Make the "dir" actually a file so mkdir({recursive:true}) reliably fails on every platform.
// (Earlier draft used /proc/0/... which on Windows resolves to C:\proc\0\... and
// mkdir({recursive:true}) silently *creates* it, leaking filesystem side-effects + the
// silent code path was never exercised.)
const blockingFile = join(dir, 'this-is-a-file-not-a-dir');
writeFileSync(blockingFile, '');
const svc = new TelemetryService(
'/proc/0/no-such-thing-readonly',
blockingFile,
() => new Date('2026-05-01T12:00:00Z'),
14,
{ silent: true }
);
// Should resolve, not throw
await expect(svc.emit({
kind: 'capture',
payload: { noteId: 'n1', rawTextLength: 1, hasMedia: false }
})).resolves.toBeUndefined();
});
it('emit DOES throw when fs write fails AND silent is not set (default)', async () => {
// Companion case — confirms silent is opt-in. Without silent, fs failure surfaces.
const blockingFile = join(dir, 'block-default');
writeFileSync(blockingFile, '');
const svc = new TelemetryService(blockingFile, () => new Date('2026-05-01T12:00:00Z'));
await expect(svc.emit({
kind: 'capture',
payload: { noteId: 'n1', rawTextLength: 1, hasMedia: false }
})).rejects.toThrow();
});
});