From cfe65f903530cedaef5c79b861034a032d9bca83 Mon Sep 17 00:00:00 2001 From: Delta Student Date: Sun, 31 May 2026 12:17:45 +0530 Subject: [PATCH 1/7] fix: cleanup test warnings and update cache logic --- components/dashboard/StatsCard.test.tsx | 5 +++-- lib/cache.ts | 26 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/components/dashboard/StatsCard.test.tsx b/components/dashboard/StatsCard.test.tsx index c248f69ea..0eb9ab2b6 100644 --- a/components/dashboard/StatsCard.test.tsx +++ b/components/dashboard/StatsCard.test.tsx @@ -4,10 +4,11 @@ import { render, screen } from '@testing-library/react'; import StatsCard from './StatsCard'; // Mock framer-motion + vi.mock('framer-motion', () => ({ motion: { - div: ({ children, ...props }: any) => ( -
+ div: ({ children, ...rest }: any) => ( +
{children}
), diff --git a/lib/cache.ts b/lib/cache.ts index b514d11ed..1e77911c8 100644 --- a/lib/cache.ts +++ b/lib/cache.ts @@ -5,7 +5,6 @@ type CacheItem = { value: T; expiresAt: number; }; - /** * A Simple in-memory TTL(Time To Live) cache. * @@ -16,8 +15,22 @@ type CacheItem = { */ export class TTLCache { private store = new Map>(); + private cleanupInterval: ReturnType | null = null; private readonly maxSize?: number; + private assertValidKey(key: unknown): asserts key is string { + if (key === null || key === undefined) { + throw new TypeError('Cache key cannot be null or undefined'); + } + + if (typeof key !== 'string') { + throw new TypeError('Cache key cannot be null or undefined'); + } + + if (key.trim().length === 0) { + throw new TypeError('Cache key cannot be empty'); + } + } /** * Creates a new TTL cache instance. @@ -62,6 +75,9 @@ export class TTLCache { * const user = cache.get("user:1"); */ get(key: string): T | null { + if (typeof key !== 'string' || key.trim().length === 0) { + return null; + } const hit = this.store.get(key); if (!hit) return null; @@ -87,6 +103,9 @@ export class TTLCache { * } */ has(key: string): boolean { + if (typeof key !== 'string' || key.trim().length === 0) { + return false; + } const hit = this.store.get(key); if (!hit) return false; @@ -109,6 +128,7 @@ export class TTLCache { * cache.delete("user:1"); */ delete(key: string): boolean { + this.assertValidKey(key); return this.store.delete(key); } @@ -134,6 +154,7 @@ export class TTLCache { * @returns `true` if the entry existed and was updated, `false` if missing or expired. */ update(key: string, value: T): boolean { + this.assertValidKey(key); const hit = this.store.get(key); if (!hit || Date.now() > hit.expiresAt) return false; hit.value = value; @@ -141,7 +162,8 @@ export class TTLCache { } set(key: string, value: T, ttlMs: number): void { - if (key === '') throw new Error('Cache key cannot be empty'); + this.assertValidKey(key); + if (ttlMs <= 0) throw new RangeError(`ttlMs must be positive, got ${ttlMs}`); const maxSize = this.maxSize; From 9ce8ce468f7d348d53a0f0ae2fce6b1169e6e4d0 Mon Sep 17 00:00:00 2001 From: Delta Student Date: Mon, 1 Jun 2026 12:05:09 +0530 Subject: [PATCH 2/7] chore: trigger status refresh From f6f0d83b65aafcaeeb307787d889235e4c9a4fce Mon Sep 17 00:00:00 2001 From: Delta Student Date: Wed, 3 Jun 2026 15:33:35 +0530 Subject: [PATCH 3/7] trigger recheck From 298858868fad4275b0d71c1187e35f0e4f45f2a7 Mon Sep 17 00:00:00 2001 From: Delta Student Date: Mon, 8 Jun 2026 13:44:38 +0530 Subject: [PATCH 4/7] Fix TTLCache validation, pass tests, lint, and build --- app/page.tsx | 2 +- components/dashboard/StatsCard.test.tsx | 2 +- lib/cache.ts | 21 ++++++--------------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 123b8f164..e6f0d52ae 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,6 +1,6 @@ 'use client'; import { trackUser } from '@/utils/tracking'; -import InteractiveViewer from '@/components/InteractiveViewer'; + import Link from 'next/link'; import { useRef, useState, useEffect } from 'react'; import { AnimatePresence, motion } from 'framer-motion'; diff --git a/components/dashboard/StatsCard.test.tsx b/components/dashboard/StatsCard.test.tsx index eb802d7d7..e6436d886 100644 --- a/components/dashboard/StatsCard.test.tsx +++ b/components/dashboard/StatsCard.test.tsx @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unused-vars */ + import { describe, it, expect, vi, beforeEach } from 'vitest'; import { render, screen } from '@testing-library/react'; import StatsCard from './StatsCard'; diff --git a/lib/cache.ts b/lib/cache.ts index 69d42a9c1..58aa9b7e1 100644 --- a/lib/cache.ts +++ b/lib/cache.ts @@ -18,26 +18,15 @@ export class TTLCache { private cleanupInterval: ReturnType | null = null; private readonly maxSize?: number; - private assertValidKey(key: unknown): asserts key is string { - if (key === null || key === undefined) { - throw new TypeError('Cache key cannot be null or undefined'); - } - + private static assertValidKey(key: unknown): asserts key is string { if (typeof key !== 'string') { - throw new TypeError('Cache key cannot be null or undefined'); + throw new TypeError('Cache key must be a string'); } if (key.trim().length === 0) { throw new TypeError('Cache key cannot be empty'); } } - - private static assertValidKey(key: unknown): asserts key is string { - if (typeof key !== 'string') { - throw new TypeError('Cache key must be a string'); - } - } - /** * Creates a new TTL cache instance. * @@ -108,7 +97,9 @@ export class TTLCache { * } */ has(key: string): boolean { - TTLCache.assertValidKey(key); + if (typeof key !== 'string' || key.trim().length === 0) { + return false; + } const hit = this.store.get(key); if (!hit) return false; @@ -169,7 +160,7 @@ export class TTLCache { set(key: string, value: T, ttlMs: number): void { TTLCache.assertValidKey(key); - if (key === '') throw new Error('Cache key cannot be empty'); + if (ttlMs <= 0) throw new RangeError(`ttlMs must be positive, got ${ttlMs}`); const maxSize = this.maxSize; From bdcc1acc28fb7a4dcdbb3db0cecb47b4f75722aa Mon Sep 17 00:00:00 2001 From: Delta Student Date: Mon, 8 Jun 2026 14:35:13 +0530 Subject: [PATCH 5/7] chore: trigger PR refresh From 005ce943c5f0955c927c112531d7a97bfed8c691 Mon Sep 17 00:00:00 2001 From: Delta Student Date: Sat, 13 Jun 2026 22:08:20 +0530 Subject: [PATCH 6/7] fix: update cache null validation and test adjustments --- .../confirm/route.theme-contrast.test.ts | 8 +++++ lib/cache.ts | 29 ++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/api/student/resume/confirm/route.theme-contrast.test.ts b/app/api/student/resume/confirm/route.theme-contrast.test.ts index 6279396f2..9c6325a22 100644 --- a/app/api/student/resume/confirm/route.theme-contrast.test.ts +++ b/app/api/student/resume/confirm/route.theme-contrast.test.ts @@ -1,6 +1,14 @@ import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll } from 'vitest'; import { POST } from './route'; +vi.mock('@/lib/github-owner-verification', () => ({ + verifyGitHubOwner: vi.fn().mockResolvedValue({ + verified: true, + status: 200, + message: 'OK', + }), +})); + vi.mock('@/lib/mongodb', () => ({ default: vi.fn(), })); diff --git a/lib/cache.ts b/lib/cache.ts index b9e3a7065..edbcedbb9 100644 --- a/lib/cache.ts +++ b/lib/cache.ts @@ -17,12 +17,10 @@ type CacheItem = { * @typeParam T - Type of values stored in the cache. */ export class TTLCache { -fix/ttlcache-null-validation - private store = new Map>(); - + //private store = new Map>(); private store = new Map>(); - + private cleanupInterval: ReturnType | null = null; private readonly maxSize?: number; private static assertValidKey(key: unknown): asserts key is string { @@ -115,7 +113,14 @@ fix/ttlcache-null-validation * const user = cache.get("user:1"); */ get(key: string): T | null { - TTLCache.assertValidKey(key); + //TTLCache.assertValidKey(key); + if (key === null || key === undefined) { + throw new TypeError('Cache key must be a string'); + } + + if (typeof key !== 'string') { + throw new TypeError('Cache key must be a string'); + } const hit = this.store.get(key); if (!hit) return null; @@ -142,8 +147,13 @@ fix/ttlcache-null-validation * } */ has(key: string): boolean { - if (typeof key !== 'string' || key.trim().length === 0) { - return false; + //TTLCache.assertValidKey(key); + if (key === null || key === undefined) { + throw new TypeError('Cache key must be a string'); + } + + if (typeof key !== 'string') { + throw new TypeError('Cache key must be a string'); } const hit = this.store.get(key); @@ -211,7 +221,10 @@ fix/ttlcache-null-validation } set(key: string, value: T, ttlMs: number): void { - TTLCache.assertValidKey(key); + //TTLCache.assertValidKey(key); + if (typeof key !== 'string' || key.trim().length === 0) { + throw new TypeError('Cache key cannot be empty'); + } if (ttlMs <= 0) throw new RangeError(`ttlMs must be positive, got ${ttlMs}`); if (Number.isNaN(ttlMs)) ttlMs = 60_000; From a175941f84ddbd26981c00e254e0331ba29abcb9 Mon Sep 17 00:00:00 2001 From: Delta Student Date: Sat, 13 Jun 2026 22:42:57 +0530 Subject: [PATCH 7/7] chore: trigger CI refresh