-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathSettingsPanels.logic.test.ts
More file actions
134 lines (121 loc) · 4.55 KB
/
Copy pathSettingsPanels.logic.test.ts
File metadata and controls
134 lines (121 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import {
DEFAULT_SERVER_SETTINGS,
ProviderDriverKind,
ProviderInstanceId,
type ProviderInstanceConfig,
} from "@t3tools/contracts";
import { normalizeSearchQuery } from "@t3tools/shared/searchRanking";
import { describe, expect, it } from "vite-plus/test";
import {
archivedThreadSearchScore,
buildProviderInstanceUpdatePatch,
formatDiagnosticsDescription,
} from "./SettingsPanels.logic";
function scoreArchivedTitle(title: string, query: string): number | null {
const normalizedQuery = normalizeSearchQuery(query);
return archivedThreadSearchScore({
normalizedTitle: normalizeSearchQuery(title),
normalizedQuery,
tokens: normalizedQuery.split(/\s+/u).filter((token) => token.length > 0),
});
}
describe("archivedThreadSearchScore", () => {
it("ranks phrase matches ahead of all-token and partial-token matches", () => {
const phraseMatch = scoreArchivedTitle("Alpha Beta cleanup", "alpha beta");
const allTokenMatch = scoreArchivedTitle("Alpha cleanup Beta", "alpha beta");
const partialTokenMatch = scoreArchivedTitle("Alpha cleanup", "alpha beta");
expect(phraseMatch).not.toBeNull();
expect(allTokenMatch).not.toBeNull();
expect(partialTokenMatch).not.toBeNull();
expect(phraseMatch!).toBeLessThan(allTokenMatch!);
expect(allTokenMatch!).toBeLessThan(partialTokenMatch!);
});
it("matches titles case-insensitively and rejects unrelated titles", () => {
expect(scoreArchivedTitle("Release Candidate Notes", "candidate")).not.toBeNull();
expect(scoreArchivedTitle("Release Candidate Notes", "missing")).toBeNull();
});
});
describe("formatDiagnosticsDescription", () => {
it("collapses trace and metric URLs that share the same OTEL base path", () => {
expect(
formatDiagnosticsDescription({
localTracingEnabled: true,
otlpTracesEnabled: true,
otlpTracesUrl: "http://localhost:4318/v1/traces",
otlpMetricsEnabled: true,
otlpMetricsUrl: "http://localhost:4318/v1/metrics",
}),
).toBe("Local trace file. Exporting OTEL to http://localhost:4318/v1/{traces,metrics}.");
});
it("keeps separate trace and metric URLs when their base paths differ", () => {
expect(
formatDiagnosticsDescription({
localTracingEnabled: true,
otlpTracesEnabled: true,
otlpTracesUrl: "http://localhost:4318/v1/traces",
otlpMetricsEnabled: true,
otlpMetricsUrl: "http://localhost:9000/v1/metrics",
}),
).toBe(
"Local trace file. Exporting OTEL traces to http://localhost:4318/v1/traces and metrics to http://localhost:9000/v1/metrics.",
);
});
it("omits OTEL text when no exporter is enabled", () => {
expect(
formatDiagnosticsDescription({
localTracingEnabled: true,
otlpTracesEnabled: false,
otlpMetricsEnabled: false,
}),
).toBe("Local trace file.");
});
});
describe("buildProviderInstanceUpdatePatch", () => {
it("promotes an edited default provider into providerInstances and resets the legacy provider", () => {
const instanceId = ProviderInstanceId.make("codex");
const nextInstance = {
driver: ProviderDriverKind.make("codex"),
enabled: true,
config: {
binaryPath: "/opt/t3/codex",
},
} satisfies ProviderInstanceConfig;
const patch = buildProviderInstanceUpdatePatch({
settings: {
...DEFAULT_SERVER_SETTINGS,
providers: {
...DEFAULT_SERVER_SETTINGS.providers,
codex: {
...DEFAULT_SERVER_SETTINGS.providers.codex,
binaryPath: "/legacy/codex",
},
},
},
instanceId,
instance: nextInstance,
driver: ProviderDriverKind.make("codex"),
isDefault: true,
});
expect(patch.providerInstances?.[instanceId]).toEqual(nextInstance);
expect(patch.providers?.codex).toEqual(DEFAULT_SERVER_SETTINGS.providers.codex);
});
it("updates custom instances without touching legacy provider settings", () => {
const instanceId = ProviderInstanceId.make("codex_personal");
const nextInstance = {
driver: ProviderDriverKind.make("codex"),
enabled: true,
config: {
homePath: "/Users/example/.codex-personal",
},
} satisfies ProviderInstanceConfig;
const patch = buildProviderInstanceUpdatePatch({
settings: DEFAULT_SERVER_SETTINGS,
instanceId,
instance: nextInstance,
driver: ProviderDriverKind.make("codex"),
isDefault: false,
});
expect(patch.providerInstances?.[instanceId]).toEqual(nextInstance);
expect(patch.providers).toBeUndefined();
});
});