fix: stabilize ci checks
This commit is contained in:
@@ -13,8 +13,16 @@ const mockTheme: SearchableSelectListTheme = {
|
||||
};
|
||||
|
||||
const testItems = [
|
||||
{ value: "anthropic/claude-3-opus", label: "anthropic/claude-3-opus", description: "Claude 3 Opus" },
|
||||
{ value: "anthropic/claude-3-sonnet", label: "anthropic/claude-3-sonnet", description: "Claude 3 Sonnet" },
|
||||
{
|
||||
value: "anthropic/claude-3-opus",
|
||||
label: "anthropic/claude-3-opus",
|
||||
description: "Claude 3 Opus",
|
||||
},
|
||||
{
|
||||
value: "anthropic/claude-3-sonnet",
|
||||
label: "anthropic/claude-3-sonnet",
|
||||
description: "Claude 3 Sonnet",
|
||||
},
|
||||
{ value: "openai/gpt-4", label: "openai/gpt-4", description: "GPT-4" },
|
||||
{ value: "openai/gpt-4-turbo", label: "openai/gpt-4-turbo", description: "GPT-4 Turbo" },
|
||||
{ value: "google/gemini-pro", label: "google/gemini-pro", description: "Gemini Pro" },
|
||||
@@ -50,7 +58,11 @@ describe("SearchableSelectList", () => {
|
||||
const items = [
|
||||
{ value: "openrouter/auto", label: "openrouter/auto", description: "Routes to best" },
|
||||
{ value: "opus-direct", label: "opus-direct", description: "Direct opus model" },
|
||||
{ value: "anthropic/claude-3-opus", label: "anthropic/claude-3-opus", description: "Claude 3 Opus" },
|
||||
{
|
||||
value: "anthropic/claude-3-opus",
|
||||
label: "anthropic/claude-3-opus",
|
||||
description: "Claude 3 Opus",
|
||||
},
|
||||
];
|
||||
const list = new SearchableSelectList(items, 5, mockTheme);
|
||||
|
||||
@@ -66,7 +78,11 @@ describe("SearchableSelectList", () => {
|
||||
|
||||
it("exact label match beats description match", () => {
|
||||
const items = [
|
||||
{ value: "provider/other", label: "provider/other", description: "This mentions opus in description" },
|
||||
{
|
||||
value: "provider/other",
|
||||
label: "provider/other",
|
||||
description: "This mentions opus in description",
|
||||
},
|
||||
{ value: "provider/opus-model", label: "provider/opus-model", description: "Something else" },
|
||||
];
|
||||
const list = new SearchableSelectList(items, 5, mockTheme);
|
||||
|
||||
@@ -98,7 +98,11 @@ export class SearchableSelectList implements Component {
|
||||
exactLabel.sort(this.compareByScore);
|
||||
wordBoundary.sort(this.compareByScore);
|
||||
descriptionMatches.sort(this.compareByScore);
|
||||
const fuzzyMatches = fuzzyFilter(fuzzyCandidates, query, (i) => `${i.label} ${i.description ?? ""}`);
|
||||
const fuzzyMatches = fuzzyFilter(
|
||||
fuzzyCandidates,
|
||||
query,
|
||||
(i) => `${i.label} ${i.description ?? ""}`,
|
||||
);
|
||||
return [
|
||||
...exactLabel.map((s) => s.item),
|
||||
...wordBoundary.map((s) => s.item),
|
||||
@@ -133,7 +137,10 @@ export class SearchableSelectList implements Component {
|
||||
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
private compareByScore = (a: { item: SelectItem; score: number }, b: { item: SelectItem; score: number }) => {
|
||||
private compareByScore = (
|
||||
a: { item: SelectItem; score: number },
|
||||
b: { item: SelectItem; score: number },
|
||||
) => {
|
||||
if (a.score !== b.score) return a.score - b.score;
|
||||
return this.getItemLabel(a.item).localeCompare(this.getItemLabel(b.item));
|
||||
};
|
||||
@@ -190,7 +197,10 @@ export class SearchableSelectList implements Component {
|
||||
// Calculate visible range with scrolling
|
||||
const startIndex = Math.max(
|
||||
0,
|
||||
Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),
|
||||
Math.min(
|
||||
this.selectedIndex - Math.floor(this.maxVisible / 2),
|
||||
this.filteredItems.length - this.maxVisible,
|
||||
),
|
||||
);
|
||||
const endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);
|
||||
|
||||
@@ -211,7 +221,12 @@ export class SearchableSelectList implements Component {
|
||||
return lines;
|
||||
}
|
||||
|
||||
private renderItemLine(item: SelectItem, isSelected: boolean, width: number, query: string): string {
|
||||
private renderItemLine(
|
||||
item: SelectItem,
|
||||
isSelected: boolean,
|
||||
width: number,
|
||||
query: string,
|
||||
): string {
|
||||
const prefix = isSelected ? "→ " : " ";
|
||||
const prefixWidth = prefix.length;
|
||||
const displayValue = this.getItemLabel(item);
|
||||
|
||||
Reference in New Issue
Block a user