Fix C1/C2 + reliability cluster (L140/L141/L148, R6/R7)
Critical: - C1: single source of truth for IPC mock + Settings defaults. DEFAULT_SETTINGS in @shared/ipc; main DEFAULTS, renderer FALLBACK, and preview MOCK_SETTINGS all derive from it. Whole browser mock collapsed into one typed mockApi.ts; main.tsx shrinks to window.api = mockApi. PREVIEW check single-sourced in isPreview.ts. - C2: break the downloads<->sources circular import via a typed event bus (store/coordinator.ts). App eagerly imports sources for side-effects so startup load + scheduled --sync + downloadCompleted subscription still run. Reliability: - L140/L148: cancel/pause release the active slot synchronously; identity-guarded releaseActive; per-spawn cookie jar so a same-id retry/resume is never rejected by a stale entry nor run over the concurrency cap. - L141: renderer history capped at 500 + url de-dup to match main. - R6: writeJsonAtomic reports/logs write failures and keeps data dirty for retry instead of an empty catch. - R7: encryptSecret warns before the plaintext fallback. typecheck + 243 tests + eslint green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+19
-1
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest'
|
||||
import { describe, it, expect, afterEach, vi } from 'vitest'
|
||||
import { mkdtempSync, rmSync, writeFileSync, readdirSync } from 'fs'
|
||||
import { tmpdir } from 'os'
|
||||
import { join } from 'path'
|
||||
@@ -49,6 +49,24 @@ describe('jsonStore atomic write + safe read', () => {
|
||||
expect(readJsonArraySafe(file, isRow)).toEqual([{ id: 'a' }, { id: 'c' }])
|
||||
})
|
||||
|
||||
it('reports success/failure instead of swallowing a bad write (R6)', () => {
|
||||
const d = tmp()
|
||||
const err = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
try {
|
||||
// A normal write lands and reports true, with nothing logged.
|
||||
expect(writeJsonAtomic(join(d, 'data.json'), [{ id: 'a' }])).toBe(true)
|
||||
expect(err).not.toHaveBeenCalled()
|
||||
// A target under a non-existent directory can't be written — it must report
|
||||
// false (so a caller can warn/retry) and log, not throw or silently drop it.
|
||||
expect(writeJsonAtomic(join(d, 'no', 'such', 'dir', 'data.json'), [{ id: 'a' }])).toBe(false)
|
||||
expect(err).toHaveBeenCalledOnce()
|
||||
} finally {
|
||||
err.mockRestore()
|
||||
}
|
||||
// No stray .tmp left behind by the failed write.
|
||||
expect(readdirSync(d)).toEqual(['data.json'])
|
||||
})
|
||||
|
||||
it('backs up a corrupt file instead of silently wiping it (R2)', () => {
|
||||
const d = tmp()
|
||||
const file = join(d, 'data.json')
|
||||
|
||||
Reference in New Issue
Block a user