9134e7d216
CC12: renderer views/ (5 screens + Onboarding + settings cards) + lib/ (theme/thumb/datetime/id/qualityOptions/useClipboardLink/queueStats); main core/ (buildArgs/validation/indexerCore/ytdlpPolicy). git mv preserved history; all src+test imports updated. Build emits view chunks from views/, 344 tests + typecheck green, live probe rendered all screens. CC7: wc/onProgress is the leading arg everywhere — downloadAppUpdate(wc,url), indexSource(onProgress,url,signal), indexSourceCancelable(onProgress,url). CC10: closed by-design — jsonStore backs all records; settings stay in electron-store for DPAPI secret encryption (a deliberate two-store split). Also closes the UI24/W4 context-menu cross-reference. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
42 lines
1.8 KiB
TypeScript
42 lines
1.8 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { shouldAutoCheckYtdlp, AUTO_UPDATE_INTERVAL_MS } from '../src/main/core/ytdlpPolicy'
|
|
|
|
const NOW = 1_782_435_469_486 // arbitrary fixed "now"
|
|
|
|
describe('shouldAutoCheckYtdlp', () => {
|
|
it('never checks when auto-update is disabled', () => {
|
|
expect(shouldAutoCheckYtdlp(false, 0, NOW)).toBe(false)
|
|
// …even if a full interval has elapsed.
|
|
expect(shouldAutoCheckYtdlp(false, NOW - AUTO_UPDATE_INTERVAL_MS * 2, NOW)).toBe(false)
|
|
})
|
|
|
|
it('checks on first run (lastCheck is 0 / never)', () => {
|
|
expect(shouldAutoCheckYtdlp(true, 0, NOW)).toBe(true)
|
|
})
|
|
|
|
it('skips while inside the throttle window', () => {
|
|
// Checked one minute ago → far inside the 24h window.
|
|
expect(shouldAutoCheckYtdlp(true, NOW - 60_000, NOW)).toBe(false)
|
|
// Exactly one ms short of the interval still skips.
|
|
expect(shouldAutoCheckYtdlp(true, NOW - (AUTO_UPDATE_INTERVAL_MS - 1), NOW)).toBe(false)
|
|
})
|
|
|
|
it('checks once the interval has elapsed (boundary inclusive)', () => {
|
|
expect(shouldAutoCheckYtdlp(true, NOW - AUTO_UPDATE_INTERVAL_MS, NOW)).toBe(true)
|
|
expect(shouldAutoCheckYtdlp(true, NOW - AUTO_UPDATE_INTERVAL_MS * 3, NOW)).toBe(true)
|
|
})
|
|
|
|
it('honours a custom interval', () => {
|
|
const hour = 60 * 60 * 1000
|
|
expect(shouldAutoCheckYtdlp(true, NOW - 30 * 60_000, NOW, hour)).toBe(false)
|
|
expect(shouldAutoCheckYtdlp(true, NOW - hour, NOW, hour)).toBe(true)
|
|
})
|
|
|
|
it('checks when the clock ran backward (lastCheck is in the future, R9)', () => {
|
|
// A backward clock correction leaves lastCheck > now → (now - lastCheck) is
|
|
// negative; without the guard the check would be skipped forever.
|
|
expect(shouldAutoCheckYtdlp(true, NOW + AUTO_UPDATE_INTERVAL_MS, NOW)).toBe(true)
|
|
expect(shouldAutoCheckYtdlp(true, NOW + 1, NOW)).toBe(true)
|
|
})
|
|
})
|