Skip to content

fix: filter test case seeding check to current algorithm instead of global db emptiness#491

Open
Xenon010101 wants to merge 1 commit into
algoscope-hq:mainfrom
Xenon010101:fix/bug-478-test-case-seeding
Open

fix: filter test case seeding check to current algorithm instead of global db emptiness#491
Xenon010101 wants to merge 1 commit into
algoscope-hq:mainfrom
Xenon010101:fix/bug-478-test-case-seeding

Conversation

@Xenon010101
Copy link
Copy Markdown
Contributor

@Xenon010101 Xenon010101 commented May 30, 2026

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

  • Bug Fixes
    • Improved test case initialization logic to correctly identify and load sample test cases when filtering is applied, ensuring the appropriate cases are available for your current selection.

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 30, 2026

Deploy Preview for astounding-nougat-da0f6a ready!

Name Link
🔨 Latest commit 580607d
🔍 Latest deploy log https://app.netlify.com/projects/astounding-nougat-da0f6a/deploys/6a1a9568a1d7a600081b5c55
😎 Deploy Preview https://deploy-preview-491--astounding-nougat-da0f6a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

📝 Walkthrough

Walkthrough

TestCaseManager'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.

Changes

Algorithm-Aware Seeding Logic

Layer / File(s) Summary
Algorithm-filtered seeding condition
src/components/testCaseManager/TestCaseManager.jsx
The load callback now derives currentAlgoCases by filtering fetched data for the selected algorithm, and checks currentAlgoCases.length === 0 instead of data.length === 0 before seeding sample cases. This ensures each algorithm's sample cases seed independently regardless of cases stored for other algorithms.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • algoscope-hq/AlgoScope#305: Makes similar algorithm-aware modifications to TestCaseManager seeding logic for consistent per-algorithm test case persistence.
  • algoscope-hq/AlgoScope#309: Builds on TestCaseManager seeding functionality with related algorithm-specific persistence workflow changes.

Suggested labels

gssoc:approved

🚥 Pre-merge checks | ✅ 5 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Algorithm Complexity ⚠️ Warning Check for algorithm complexity is inapplicable—PR modifies a React UI component (TestCaseManager), not an algorithm implementation. No algorithm code with documented complexity exists in the changes. This check should apply only to PRs modifying algorithm implementations. Clarify if component operations require specific complexity validation.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main fix: filtering the seeding check from global database emptiness to algorithm-specific emptiness.
Description check ✅ Passed The description clearly explains the bug, the fix, and references the related issue, but lacks some template sections like Type of Change, Release Notes, Testing, and CI/CD impact.
Linked Issues check ✅ Passed The changes directly implement the proposed solution from #478: filtering fetched cases to algorithm-specific subset and using that for the seeding condition check.
Out of Scope Changes check ✅ Passed The changes are narrowly focused on fixing the test case seeding logic for the current algorithm, with no extraneous modifications detected.
Conventional Commits ✅ Passed Commit message "fix: filter test case seeding check to current algorithm instead of global db emptiness" follows conventional commits standard with proper 'fix' type prefix and clear description.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9f6f2f6 and 580607d.

📒 Files selected for processing (1)
  • src/components/testCaseManager/TestCaseManager.jsx

Comment on lines +42 to 50
const currentAlgoCases = algorithm
? data.filter((tc) => tc.algorithm === algorithm)
: data

if (
!search &&
data.length === 0 &&
currentAlgoCases.length === 0 &&
sampleCases.length > 0 &&
!hasSeededSamples.current
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Seeding of Sample Test Cases Fails for Subsequent Algorithms

1 participant