Skip to content

Commit bca862d

Browse files
Feat: Enhance session handling by adding notes for OS and browser version discrepancies
1 parent e3f110f commit bca862d

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

src/tools/live-utils/start-session.ts

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ export async function startBrowserSession(
3535
const entry = await filterDesktop(args);
3636
const url = buildDesktopUrl(args, entry);
3737
openBrowser(url);
38+
if (entry.notes) {
39+
return `${url}, ${entry.notes}`;
40+
}
3841
return url;
3942
} else {
4043
const entry = await filterMobile(args);
4144
const url = buildMobileUrl(args, entry);
4245
openBrowser(url);
46+
if (entry.notes) {
47+
return `${url}, ${entry.notes}`;
48+
}
4349
return url;
4450
}
4551
}
@@ -51,6 +57,7 @@ interface DesktopEntry {
5157
os_version: string;
5258
browser: string;
5359
browser_version: string;
60+
notes?: string;
5461
}
5562

5663
async function filterDesktop(args: DesktopArgs): Promise<DesktopEntry> {
@@ -106,6 +113,24 @@ async function filterDesktop(args: DesktopArgs): Promise<DesktopEntry> {
106113
if (!final)
107114
throw new Error(`No entry for browser version "${args.browserVersion}".`);
108115

116+
if (
117+
args.osVersion !== chosenOS &&
118+
args.osVersion !== "latest" &&
119+
args.osVersion !== "oldest"
120+
) {
121+
final.notes = `Note: Os version ${args.osVersion} was not found. Using "${chosenOS}" instead.`;
122+
}
123+
if (
124+
args.browserVersion !== chosenBrow &&
125+
args.browserVersion !== "latest" &&
126+
args.browserVersion !== "oldest"
127+
) {
128+
if (!final.notes) {
129+
final.notes = `Note: `;
130+
}
131+
final.notes += `Browser version ${args.browserVersion} was not found. Using "${chosenBrow}" instead.`;
132+
}
133+
109134
return final;
110135
}
111136

@@ -131,6 +156,7 @@ interface MobileEntry {
131156
os: string;
132157
os_version: string;
133158
display_name: string;
159+
notes?: string;
134160
}
135161

136162
async function filterMobile(args: MobileArgs): Promise<MobileEntry> {
@@ -140,18 +166,14 @@ async function filterMobile(args: MobileArgs): Promise<MobileEntry> {
140166
os: grp.os,
141167
os_version: d.os_version,
142168
display_name: d.display_name,
169+
notes: "",
143170
})),
144171
);
145172

146173
let candidates = all.filter((d) => d.os === args.os);
147174
if (!candidates.length)
148175
throw new Error(`No mobile OS entries for "${args.os}".`);
149176

150-
// resolve OS version
151-
const vers = candidates.map((d) => d.os_version);
152-
const chosen = resolveVersion(args.osVersion, vers);
153-
candidates = candidates.filter((d) => d.os_version === chosen);
154-
155177
// fuzzy‐match device name
156178
const matches = customFuzzySearch(
157179
candidates,
@@ -160,18 +182,43 @@ async function filterMobile(args: MobileArgs): Promise<MobileEntry> {
160182
5,
161183
);
162184
if (!matches.length)
163-
throw new Error(
164-
`No devices matching "${args.device}" on ${args.os} ${chosen}.`,
165-
);
185+
throw new Error(`No devices matching "${args.device}" on ${args.os}.`);
166186

167187
const exact = matches.find(
168188
(m) => m.display_name.toLowerCase() === args.device.toLowerCase(),
169189
);
170190
if (!exact) {
171191
const names = matches.map((m) => m.display_name).join(", ");
172-
throw new Error(`Did you mean: ${names}?`);
192+
throw new Error(
193+
`Alternative Device/Device's found : ${names}. Please Select one.`,
194+
);
173195
}
174-
return exact;
196+
candidates = candidates.filter((d) => d.display_name === exact.display_name);
197+
if (!candidates.length)
198+
throw new Error(`No device "${exact.display_name}" on ${args.os}.`);
199+
// resolve browser versio
200+
201+
// resolve OS version
202+
const vers = candidates.map((d) => d.os_version);
203+
const chosen = resolveVersion(args.osVersion, vers);
204+
candidates = candidates.filter((d) => d.os_version === chosen);
205+
206+
if (!candidates.length)
207+
throw new Error(`No entry for OS version "${args.osVersion}".`);
208+
209+
let notes = "";
210+
if (
211+
chosen !== args.osVersion &&
212+
args.osVersion !== "latest" &&
213+
args.osVersion !== "oldest"
214+
) {
215+
notes = `Note: Os version ${args.osVersion} was not found. Using ${chosen} instead.`;
216+
}
217+
218+
const final = candidates[0];
219+
if (!final) throw new Error(`No entry for OS version "${args.osVersion}".`);
220+
final.notes = notes;
221+
return final;
175222
}
176223

177224
function buildMobileUrl(args: MobileArgs, d: MobileEntry): string {

0 commit comments

Comments
 (0)