Unit-test byInterestingness: a four-level repo sort comparator with no tests
Opened by @Kartik8Dwivedi Β· Assignees: None
Claim Status & GitHub Signal
Unassigned, with 1 comment. Unassigned does not guarantee unclaimedβread comments and linked PRs first.
The task involves writing unit tests for an existing comparator function, which is a beginner-friendly task. It requires understanding of the sorting logic and how to structure tests, but does not require deep knowledge of complex algorithms or extensive experience with testing frameworks.
What It's About
The issue is about adding unit tests for a four-level sorting comparator function in a TypeScript project to ensure its correctness and stability.
Why It Matters
Testing the sorting logic is crucial to maintain the integrity of the UI's data presentation, ensuring that repositories are ranked correctly based on their interestingness, which directly impacts user experience.
Expected Outcome
The expected outcome is a comprehensive test suite that verifies the sorting logic, including edge cases and ensures that the function behaves as intended without mutating its input.
Log in to compare this issue's requirements against your profile skills. Required concepts: Unit Testing, Sorting Algorithms, TypeScript, Test-Driven Development, Function Stability.
Progressive AI Hints
Hint #1 is always free and calibrated to your experience level. Extra hints unlock with coins without spoiling the full solution.
Skill-Gap Learning
Issue Description
Good first issue, frontend tests. A four-level sort comparator with no tests, including a tie-break that exists purely to stop the UI flickering.
frontend/lib/repo-ranking.ts orders the "Indexed Repositories" cards. Its promise is that the order is entirely data-driven, with no hand-picked hero list: a newly analysed repo with real findings rises on its own, and a clean library sinks on its own. byInterestingness implements that in four stages plus a guard, and none of it is tested.
Reading lib/repo-ranking.ts:31-48, the contract is:
- A repo whose
statsisnullsinks below every repo with stats. The comment is explicit about why: "we cannot claim it is interesting when we do not know anything about it." - Then
provenDivergences, descending. - Then
stats.semanticDuplicateClusters, descending, treating a missing value as 0. - Then
stats.functions, descending, treating a missing value as 0. - Then
owner/namealphabetically, described in the code as a "stable, alphabetical tie-break so the order never flickers between renders."
Task
Add frontend/tests/repo-ranking.test.ts covering:
- Each of the five levels in isolation, so a failure tells you which rule broke rather than just "the order is wrong".
- Level precedence, which is the part a naive test misses: a repo with fewer clusters but more proven divergences must still sort above one with many clusters and none proven. Proven beats cluster count, always. Same again for clusters beating function count.
- The
nullstats guard winning over everything, including over a null-stats repo that would otherwise sort first by name. - The alphabetical tie-break actually producing a deterministic order for two repos identical on every metric, and
rankReposbeing stable across repeated calls on the same input. rankReposnot mutating its argument. It is written as[...entries].sort(...)precisely so it does not, and that is worth pinning since changing it toentries.sort(...)would pass every other test here while introducing a real bug.toRanked(detail)derivingprovenDivergencesfrom the clusters rather than fromstats.behavioralConflicts. The type comment atlib/repo-ranking.ts:15-19calls this out specifically, and it is the same honesty distinction as #166's sibling file.
Please do not
- Change
lib/repo-ranking.ts. Test-only. If a test of yours exposes a genuine ordering bug, stop and say so on this issue rather than fixing it quietly in the same PR, since that deserves its own discussion. - Test by rendering the cards. The comparator is a pure function over plain objects.
Done when
cd frontend && npm test && npm run lint
both pass. As a sanity check on your own tests, temporarily swap the order of the provenDivergences and clusters blocks in the comparator and confirm something fails. If nothing does, the precedence cases above are not really covered yet.
Claiming
Comment here before you start and I will assign it to you.
Linked Pull Requests (0)
No linked or cross-referenced pull requests detected via GitHub timeline. Check comments below for informal claims before starting.
GitHub Comments (1)
Hi, I'd like to work on this. Please assign it to me β I'll add frontend/tests/repo-ranking.test.ts covering the five levels, precedence, the null-stats guard, the tie-break, and rankRepos stability/non-mutation as described.
Issue Troubleshooting Threads (0)
No troubleshooting threads opened for this issue yet. If you hit a test, build, or navigation blocker, post what you've tried so fellow contributors can help.
PR Verification & Rewards
Sign in and link GitHub to verify your PR against this issue and earn XP + coins.
Contribution Workflow
Track your local progress before opening a pull request on GitHub.
Repository Context
Top Repository Paths
CONTRIBUTING.md Excerpt
Contributing to Ditto
Thanks for being here. Ditto is early and built to grow, and the most useful contributions are often not code β they're telling us where the tool is wrong.
The single most valuable thing you can do
Report a false positive. Ditto's whole promise is precision: when it says two functions do the same thing, it should be right. If it flags a cluster that isn't a real duplicate, that's the most useful bug report we can get. Use the Report a false positive issue template β include the repo and the cluster, and it directly improves the heuristics.
Runner-up: run it on your own codebase and tell us what it found β or what it should have found and didn't. Both are gold.
Ways to contribute
- Report a false positive (above) β most valuable.
- File a bug with the bug template.
- Propose a feature with the feature template.
- Write code β see Good first issues and the areas below.
- Improve docs β a clearer explanation, a better example repo, a fixed typo.
Where the project wants help most
These map to the roadmap in the README:
- A new language adapter. The AST layer is the only language-specific part β
everything downstream (fingerprint β embed β cluster β adjudicate β probe) is
language-agnostic. Swapping
ts-morphfortree-sitteropens up Python, Go, Java. This is the highest-leverage contribution. - Ditto Guard / MCP β surface the index to a coding agent so it can ask "does this already exist?" before writing the duplicate.
- Incremental re-indexing β fingerprints are already cached by body hash; the missing piece is a CI job that re-indexes only what a commit touched.
- Precision work β anything that reduces false positives.
Development setup
Full instructions are in the README's Run it yourself section. The short version:
# backend
cd backend && npm install
npm run typecheck # must pass
npm test # must pass (331 tests)
# frontend
cd frontend && npm install
npm test # must pass
npm run build
You can develop most of the UI with **zero backend and zero API
... (truncated)
Advisory PR Assistant
Helps structure your PR description or unpack reviewer feedback. Does not perform GitHub actions.