Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export default (options: Record<string, string>): Context => {
isSnapshotCaptured: false,
sessionCapabilitiesMap: new Map<string, any[]>(),
sessionTestIdMap: new Map<string, string>(),
testIdTestNameMap: new Map<string, string>(),
buildToSnapshotCountMap: new Map<string, number>(),
sessionIdToSnapshotNameMap: new Map<string, string[]>(),
fetchResultsForBuild: new Array<string>,
Expand Down
20 changes: 20 additions & 0 deletions src/lib/processSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ export async function prepareSnapshot(snapshot: Snapshot, ctx: Context): Promise
processedOptions.testId = sessionCapabilities.id;
}
}
if (options.testName) {
processedOptions.testName = options.testName;
} else if (processedOptions.testId && ctx.testIdTestNameMap?.has(processedOptions.testId)) {
processedOptions.testName = ctx.testIdTestNameMap.get(processedOptions.testId);
} else if (ctx.sessionCapabilitiesMap && ctx.sessionCapabilitiesMap.has(sessionId)) {
const sessionCapabilities = ctx.sessionCapabilitiesMap.get(sessionId);
if (sessionCapabilities && sessionCapabilities.name) {
processedOptions.testName = sessionCapabilities.name;
}
}
}

if (options.web && Object.keys(options.web).length) {
Expand Down Expand Up @@ -578,6 +588,16 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
processedOptions.testId = sessionCapabilities.id;
}
}
if (options.testName) {
processedOptions.testName = options.testName;
} else if (processedOptions.testId && ctx.testIdTestNameMap?.has(processedOptions.testId)) {
processedOptions.testName = ctx.testIdTestNameMap.get(processedOptions.testId);
} else if (ctx.sessionCapabilitiesMap && ctx.sessionCapabilitiesMap.has(sessionId)) {
const sessionCapabilities = ctx.sessionCapabilitiesMap.get(sessionId);
if (sessionCapabilities && sessionCapabilities.name) {
processedOptions.testName = sessionCapabilities.name;
}
}
}

if (options.web && Object.keys(options.web).length) {
Expand Down
23 changes: 22 additions & 1 deletion src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,36 @@ export default async (ctx: Context): Promise<FastifyInstance<Server, IncomingMes
if (sessionId) {
if (ctx.sessionTestIdMap?.has(sessionId)) {
// Already have testId from LTMS fallback, skip getSmartUICapabilities
snapshot.options.testId = ctx.sessionTestIdMap.get(sessionId);
const cachedTestId = ctx.sessionTestIdMap.get(sessionId);
snapshot.options.testId = cachedTestId;
ctx.log.debug(`Using cached testId for sessionId ${sessionId}: ${snapshot.options.testId}`);
if (cachedTestId && ctx.testIdTestNameMap?.has(cachedTestId)) {
snapshot.options.testName = ctx.testIdTestNameMap.get(cachedTestId);
ctx.log.debug(`Using cached testName for testId ${cachedTestId}: ${snapshot.options.testName}`);
}
} else if (ctx.sessionCapabilitiesMap?.has(sessionId)) {
// Use cached capabilities if available
const cachedCapabilities = ctx.sessionCapabilitiesMap.get(sessionId);
capsBuildId = cachedCapabilities?.buildId || ''
if (cachedCapabilities?.name) {
snapshot.options.testName = cachedCapabilities.name;
if (cachedCapabilities?.id) {
ctx.testIdTestNameMap?.set(cachedCapabilities.id, cachedCapabilities.name);
}
}
} else {
// If not cached, fetch from API and cache it
try {
let fetchedCapabilitiesResp = await ctx.client.getSmartUICapabilities(sessionId, ctx.config, ctx.git, ctx.log, ctx.isStartExec, ctx.options.baselineBuild, ctx.env);
capsBuildId = fetchedCapabilitiesResp?.buildId || ''
ctx.log.debug(`fetch caps for sessionId: ${sessionId} are ${JSON.stringify(fetchedCapabilitiesResp)}`)
if (fetchedCapabilitiesResp?.name) {
snapshot.options.testName = fetchedCapabilitiesResp.name;
const testIdForCache = fetchedCapabilitiesResp?.id || fetchedCapabilitiesResp?.testId;
if (testIdForCache) {
ctx.testIdTestNameMap?.set(testIdForCache, fetchedCapabilitiesResp.name);
}
}
if (capsBuildId) {
ctx.sessionCapabilitiesMap.set(sessionId, fetchedCapabilitiesResp);
} else if (fetchedCapabilitiesResp && fetchedCapabilitiesResp?.sessionId) {
Expand All @@ -116,6 +134,9 @@ export default async (ctx: Context): Promise<FastifyInstance<Server, IncomingMes
// LTMS fallback: only testId returned, no buildId
ctx.sessionTestIdMap?.set(sessionId, fetchedCapabilitiesResp.testId);
snapshot.options.testId = fetchedCapabilitiesResp.testId;
if (fetchedCapabilitiesResp?.name) {
ctx.testIdTestNameMap?.set(fetchedCapabilitiesResp.testId, fetchedCapabilitiesResp.name);
}
ctx.log.debug(`Cached LTMS fallback testId for sessionId ${sessionId}: ${fetchedCapabilitiesResp.testId}`);
}
} catch (error: any) {
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface Context {
isSnapshotCaptured ?: boolean;
sessionCapabilitiesMap?: Map<string, any[]>;
sessionTestIdMap?: Map<string, string>;
testIdTestNameMap?: Map<string, string>;
buildToSnapshotCountMap?: Map<string, number>;
fetchResultsForBuild?: Array<string>;
sessionIdToSnapshotNameMap?: Map<string, string[]>;
Expand Down Expand Up @@ -189,6 +190,7 @@ export interface Snapshot {
ignoreType?: string[],
sessionId?: string
testId?: string
testName?: string
sync?: boolean;
contextId?: string;
useExtendedViewport?: boolean;
Expand Down