Skip to content

Commit 7ea6747

Browse files
committed
fix visits marking
1 parent 6117140 commit 7ea6747

4 files changed

Lines changed: 53 additions & 154 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/browser-session/url-suggestions.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,43 @@ describe('mergeSuggestionSources with an imported directory', () => {
206206
expect(merged[0]).toMatchObject({
207207
tier: SUGGESTION_TIER.ACCOUNT,
208208
lastSeenAt: Date.parse('2026-01-15T00:00:00.000Z'),
209+
visits: 900,
209210
})
210211
})
211212

213+
it('keeps the visit counts of hosts promoted above the imported tier', () => {
214+
const merged = mergeSuggestionSources(
215+
[session('gitlab.com')],
216+
[credential('https://github.com')],
217+
[site('github.com', { visits: 900 }), site('gitlab.com', { visits: 40 })]
218+
)
219+
220+
// Both were promoted out of the imported tier by other evidence. Dropping
221+
// their counts here is what left byConfidence with nothing but hostnames.
222+
expect(merged.map((result) => [result.hostname, result.visits])).toEqual([
223+
['github.com', 900],
224+
['gitlab.com', 40],
225+
])
226+
})
227+
228+
it('orders a password import by usage rather than falling back to the alphabet', () => {
229+
// One import stamps every credential with the same instant, so tier and
230+
// recency both tie and visits is the only thing left to sort on. These
231+
// hosts are deliberately in the opposite order by name and by usage.
232+
const hosts: Array<[string, number]> = [
233+
['adobe.com', 10],
234+
['github.com', 500],
235+
['zoom.us', 8495],
236+
]
237+
const merged = mergeSuggestionSources(
238+
[],
239+
hosts.map(([hostname]) => credential(`https://${hostname}`)),
240+
hosts.map(([hostname, visits]) => site(hostname, { visits }))
241+
)
242+
243+
expect(hostnames(rankSuggestions(merged, ''))).toEqual(['zoom.us', 'github.com', 'adobe.com'])
244+
})
245+
212246
it('reaches an imported host by the name the source browser gave it', () => {
213247
const merged = mergeSuggestionSources([], [], [site('mail.google.com', { name: 'Gmail' })])
214248

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/browser-session/url-suggestions.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ export interface UrlSuggestion {
3838
/** @see SUGGESTION_TIER */
3939
tier: SuggestionTier
4040
/**
41-
* Source-browser visit count, for hosts that came from an import. Orders the
42-
* imported tier by how much the user actually uses each site, which is the
43-
* only usage signal that exists for a host this browser has never seen.
41+
* Source-browser visit count, carried over for every host the import knows —
42+
* not only the ones admitted at {@link SUGGESTION_TIER.IMPORTED}. A host with
43+
* a saved password is usually in the import too, and its visit count is the
44+
* only signal that separates it from the rest of its tier once
45+
* {@link byConfidence} runs out of timestamps to compare.
4446
*/
4547
visits?: number
4648
}
@@ -106,6 +108,7 @@ export function mergeSuggestionSources(
106108
icon: icon ?? site?.icon,
107109
lastSeenAt: seenAt,
108110
tier,
111+
visits: site?.visits,
109112
})
110113
}
111114

@@ -188,8 +191,19 @@ export function rankSuggestions(
188191
* Tier has to lead. Every host from one import shares that import's timestamp,
189192
* which is by definition the newest thing in the corpus, so ordering on recency
190193
* alone would put a site the user has never signed into above the one they use
191-
* daily. Within the imported tier those timestamps are all equal and the source
192-
* browser's own usage is what remains to tell them apart.
194+
* daily.
195+
*
196+
* Visits then has to outrank recency, because one import flattens the
197+
* timestamps of every tier it touches, not just the imported one: a password
198+
* import stamps all of its credentials with the same instant, so the whole
199+
* account tier ties on recency and would fall through to the alphabetical
200+
* tiebreak below. That is why {@link mergeSuggestionSources} carries `visits`
201+
* onto credentialed hosts as well — without it this comparator has nothing
202+
* left, and the omnibox opens on whichever eight hosts sort first by name.
203+
*
204+
* A credentialed host the import has never heard of counts as zero visits and
205+
* so sits below one it has. That is deliberate: keeping every step of the chain
206+
* a total order is what stops `sort` from seeing an inconsistent comparator.
193207
*/
194208
function byConfidence(first: UrlSuggestion, second: UrlSuggestion): number {
195209
return (

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/browser-session/zz-verify-visits.test.ts

Lines changed: 0 additions & 120 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/browser-session/zz-verify2.test.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)