-
Notifications
You must be signed in to change notification settings - Fork 10
fix(valuation): deterministic oldest-first canonical pick (chat#1889 row 10) #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,7 +24,14 @@ export async function findCanonicalArtistBySpotifyId( | |||||||||
| const socials = (await selectSocials({ profileUrlContains: spotifyArtistId })) ?? []; | ||||||||||
| if (socials.length === 0) return null; | ||||||||||
|
|
||||||||||
| for (const social of socials) { | ||||||||||
| // Oldest first: enrichment bumps updated_at mid-flow, so a newest-first | ||||||||||
| // pick can flip between two lookups in the same add (chat#1889 row 10). | ||||||||||
| // The oldest social is the stable, true canonical. | ||||||||||
| const oldestFirst = [...socials].sort( | ||||||||||
| (a, b) => new Date(a.updated_at ?? 0).getTime() - new Date(b.updated_at ?? 0).getTime(), | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Equal Prompt for AI agents
Suggested change
|
||||||||||
| ); | ||||||||||
|
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== file outline =="
ast-grep outline lib/valuation/findCanonicalArtistBySpotifyId.ts --view expanded || true
echo "== file contents =="
cat -n lib/valuation/findCanonicalArtistBySpotifyId.ts
echo "== related test files =="
fd -a '.*canonical.*|.*findCanonical.*|spotify' . | sed 's#^\./##' | head -200
echo "== behavioral Date comparator probe =="
node - <<'JS'
function compare(a,b) {
return new Date(a.updated_at ?? 0).getTime() - new Date(b.updated_at ?? 0).getTime();
}
const cases = [
{updated_at: '2024-01-02T00:00:00Z'},
{updated_at: '2024-01-03T00:00:00Z'},
{updated_at: 'invalid'},
{updated_at: '2024-01-05T00:00:00Z'},
];
for (let i = 1; i <= 10; i++) {
const sorted = [...cases].sort(compare).map(c => c.updated_at);
console.log(JSON.stringify(sorted));
}
console.log(new Date('invalid').getTime());
console.log(new Date('2024-01-03T00:00:00Z').getTime() - new Date('invalid').getTime());
JSRepository: recoupable/api Length of output: 3846 Normalize invalid timestamps before sorting.
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| for (const social of oldestFirst) { | ||||||||||
| const links = await selectAccountSocials({ socialId: social.id }); | ||||||||||
| const linked = links.find(link => link.account_id); | ||||||||||
| if (linked?.account_id) return linked.account_id; | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Clarify the ordering comment.
The previous implementation was not guaranteed to be newest-first; it used the database-returned order. Describe that order as unspecified rather than “newest-first” to keep the rationale accurate.
🤖 Prompt for AI Agents