diff --git a/src/services/github-service.ts b/src/services/github-service.ts index dbce51d..aca736f 100644 --- a/src/services/github-service.ts +++ b/src/services/github-service.ts @@ -148,7 +148,7 @@ export class GitHubService extends BaseGitService implements GitServiceInterface const errorMessage = e instanceof Error ? e.message : String(e); const looksStale = /does not exist in tree|does not match|expectedHeadOid/i.test(errorMessage); if (!looksStale || attempt === maxAttempts) throw e; - await new Promise(resolve => setTimeout(resolve, 500 * attempt)); + await new Promise(resolve => window.setTimeout(resolve, 500 * attempt)); } } // Unreachable: the loop always returns or throws. @@ -178,7 +178,7 @@ export class GitHubService extends BaseGitService implements GitServiceInterface const shaByPath = new Map(freshTree.map(e => [e.path, e.sha])); const results = items.map((item, i) => ({ path: item.path, sha: shaByPath.get(fullPaths[i] as string) })); if (results.every(r => r.sha) || attempt === 3) return results; - await new Promise(resolve => setTimeout(resolve, 500 * attempt)); + await new Promise(resolve => window.setTimeout(resolve, 500 * attempt)); } // Unreachable: the loop always returns on its last iteration. throw new Error('pushBatch: exhausted retries reading back blob shas'); diff --git a/src/settings.ts b/src/settings.ts index 1d4370a..de704d4 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -105,7 +105,7 @@ const CONNECTION_TEST_DEBOUNCE_MS = 800; export class GitLabSyncSettingTab extends PluginSettingTab { plugin: GitLabFilesPush; private statusBadgeEl: HTMLElement | null = null; - private connectionTestTimer: ReturnType | null = null; + private connectionTestTimer: number | null = null; private unsubscribeConnectionStatus: (() => void) | null = null; constructor(app: App, plugin: GitLabFilesPush) { @@ -120,7 +120,7 @@ export class GitLabSyncSettingTab extends PluginSettingTab { this.unsubscribeConnectionStatus?.(); this.unsubscribeConnectionStatus = null; if (this.connectionTestTimer) { - clearTimeout(this.connectionTestTimer); + window.clearTimeout(this.connectionTestTimer); this.connectionTestTimer = null; } } @@ -153,11 +153,6 @@ export class GitLabSyncSettingTab extends PluginSettingTab { } } - // Rebuilding the whole settings tab (renderSettings) to refresh the badge - // would empty and recreate every field, stealing focus mid-typing. The - // badge element is instead created once per renderSettings pass and - // updated in place by setStatusBadge(), driven by the plugin's shared - // connection status (see main.ts) so it stays in sync with the status bar. // Persistent (until dismissed) banner surfacing the current version's notable // highlights right at the top of the settings tab, so users who dismissed or // never saw the WhatsNewModal (see main.ts) can still find them. Separate @@ -193,6 +188,11 @@ export class GitLabSyncSettingTab extends PluginSettingTab { }); } + // Rebuilding the whole settings tab (renderSettings) to refresh the badge + // would empty and recreate every field, stealing focus mid-typing. The + // badge element is instead created once per renderSettings pass and + // updated in place by setStatusBadge(), driven by the plugin's shared + // connection status (see main.ts) so it stays in sync with the status bar. private renderConnectionStatus(containerEl: HTMLElement): void { this.statusBadgeEl = containerEl.createDiv({ cls: 'gfs-connection-status' }); this.unsubscribeConnectionStatus?.(); @@ -219,9 +219,9 @@ export class GitLabSyncSettingTab extends PluginSettingTab { // don't hit the remote API on every character typed. private scheduleConnectionTest(): void { if (this.connectionTestTimer) { - clearTimeout(this.connectionTestTimer); + window.clearTimeout(this.connectionTestTimer); } - this.connectionTestTimer = setTimeout(() => { + this.connectionTestTimer = window.setTimeout(() => { this.connectionTestTimer = null; void this.plugin.testConnection(); }, CONNECTION_TEST_DEBOUNCE_MS); diff --git a/src/utils/git-blob-sha.ts b/src/utils/git-blob-sha.ts index 6934d9d..0a1dc72 100644 --- a/src/utils/git-blob-sha.ts +++ b/src/utils/git-blob-sha.ts @@ -15,7 +15,7 @@ export async function gitBlobSha(content: string | ArrayBuffer): Promise // SHA-1 isn't for security here — it's required because it's git's own // object-hashing algorithm, so this must match `git hash-object` exactly. - // eslint-disable-next-line sonarjs/hashing + // eslint-disable-next-line sonarjs/hashing -- SHA-1 is required here to match git's own object-hashing algorithm, not used for security const digest = await crypto.subtle.digest('SHA-1', combined); return Array.from(new Uint8Array(digest)).map(b => b.toString(16).padStart(2, '0')).join(''); } diff --git a/tests/setup.ts b/tests/setup.ts index b264080..fc0c872 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -21,6 +21,11 @@ if (typeof window === 'undefined') { (globalThis as unknown as { window: unknown }).window = { setInterval: vi.fn(), clearInterval: vi.fn(), + // Delegate to the global timers (not bound methods captured once) so + // vi.useFakeTimers()/vi.useRealTimers() — which patch globalThis — keep + // controlling window.setTimeout/clearTimeout too. + setTimeout: (handler: (...args: unknown[]) => void, timeout?: number) => globalThis.setTimeout(handler, timeout), + clearTimeout: (handle?: ReturnType) => globalThis.clearTimeout(handle), }; }