Skip to content

[Feature] Add test coverage for SRS logic, filter integrity check, and isMalicious #17

@Aster1630

Description

@Aster1630

What problem does this solve?

v1.2.0 introduced a test suite (43 tests across 3 files) but several of the most complex and security-relevant functions have no coverage:

  • cardKey, recordResult, pickCard in flashcard.js core SRS logic with edge cases around collisions, ease factor clamping, due date calculation, and last-card deduplication.
  • The 30% selector integrity check in updateFilterLists() in background.js a safety feature that prevents compromised filter sources from wiping cached selectors.
  • isMalicious() in maliciousAdBlocker.js the function that decides whether to hide a link or iframe.

Proposed solution

Add test files (or extend existing ones) covering:

  • cardKey: collision test for similar questions, stability test for special characters.
  • recordResult: ease factor increases on correct recall, clamps at 3.0; decreases on failure, clamps at 1.3; interval resets to 1 on failure; nextDue is set correctly.
  • pickCard: avoids repeating the last card; prefers due cards over non-due; falls back to all cards when nothing is due.
  • updateFilterLists integrity check: new total < 70% of cached total → no write, warning status set; new total >= 70% → write proceeds normally.
  • isMalicious: returns true for href matching a pattern; returns true for text matching a keyword; returns false for clean elements; handles empty href/text gracefully.

Which module would this affect?

  • Flashcards
  • Ad Blocker
  • Docs / Translations

Alternatives considered

None, test coverage is the right solution here.

Additional context

The functions are inlined (no module system), so the same pattern used in toneAnalysis.test.js (inline the function in the test file) works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions