fix: filter test case seeding check to current algorithm instead of global db emptiness#491
Conversation
…lobal db emptiness
✅ Deploy Preview for astounding-nougat-da0f6a ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@Xenon010101 is attempting to deploy a commit to the adityapaul2603-gmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughTestCaseManager's sample case seeding now filters the fetched test cases by the selected algorithm before checking if the list is empty. This allows each algorithm to seed its own sample cases independently, fixing the bug where subsequent algorithms failed to seed because a shared IndexedDB store appeared non-empty once any algorithm had stored cases. ChangesAlgorithm-Aware Seeding Logic
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/testCaseManager/TestCaseManager.jsx`:
- Around line 42-50: The guard that prevents reseeding uses a single boolean
hasSeededSamples.current so after one algorithm seeds other algorithms won’t
seed when only the algorithm prop changes; update the logic to track seeding
per-algorithm (e.g., change hasSeededSamples.current from a boolean to a
map/object keyed by algorithm) and use algorithm (or a derived algorithm key) to
check and set the per-algorithm flag before seeding sampleCases for
currentAlgoCases; update all places that read/write hasSeededSamples.current to
use hasSeededSamples.current[algorithmKey] (or delete/initialize entries when
needed) so each algorithm can seed independently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4d87c3f1-d507-4cf7-95bd-efc37d66f860
📒 Files selected for processing (1)
src/components/testCaseManager/TestCaseManager.jsx
| const currentAlgoCases = algorithm | ||
| ? data.filter((tc) => tc.algorithm === algorithm) | ||
| : data | ||
|
|
||
| if ( | ||
| !search && | ||
| data.length === 0 && | ||
| currentAlgoCases.length === 0 && | ||
| sampleCases.length > 0 && | ||
| !hasSeededSamples.current |
There was a problem hiding this comment.
Per-algorithm seeding can still be skipped after an algorithm switch in the same mount
Line 50 uses a single boolean (hasSeededSamples.current) as a global guard, so once one algorithm seeds, later algorithms won’t seed if this component stays mounted and only algorithm prop changes.
Suggested fix (track seeding per algorithm key)
- const hasSeededSamples = useRef(false)
+ const seededAlgorithmsRef = useRef(new Set())
const load = useCallback(async () => {
const data = await fetchCases()
const currentAlgoCases = algorithm
? data.filter((tc) => tc.algorithm === algorithm)
: data
+ const seedKey = algorithm ?? '__global__'
+ const alreadySeeded = seededAlgorithmsRef.current.has(seedKey)
if (
!search &&
currentAlgoCases.length === 0 &&
sampleCases.length > 0 &&
- !hasSeededSamples.current
+ !alreadySeeded
) {
- hasSeededSamples.current = true
+ seededAlgorithmsRef.current.add(seedKey)
await Promise.all(
sampleCases.map((sampleCase) => saveTestCase(sampleCase))
)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/testCaseManager/TestCaseManager.jsx` around lines 42 - 50, The
guard that prevents reseeding uses a single boolean hasSeededSamples.current so
after one algorithm seeds other algorithms won’t seed when only the algorithm
prop changes; update the logic to track seeding per-algorithm (e.g., change
hasSeededSamples.current from a boolean to a map/object keyed by algorithm) and
use algorithm (or a derived algorithm key) to check and set the per-algorithm
flag before seeding sampleCases for currentAlgoCases; update all places that
read/write hasSeededSamples.current to use
hasSeededSamples.current[algorithmKey] (or delete/initialize entries when
needed) so each algorithm can seed independently.
Description
The TestCaseManager's auto-seeding logic checked data.length === 0 on the globally returned test case array. Once any algorithm seeded its cases, the IndexedDB was no longer empty, preventing all subsequent algorithms from ever seeding their own sample cases.
Fix
Changed the check from data.length === 0 to currentAlgoCases.length === 0, filtering the fetched cases to only those belonging to the current algorithm before deciding whether to seed. If no �lgorithm is provided, it falls back to the global check.
Related Issue
Fixes #478
Summary by CodeRabbit