Skip to content

Commit 96aba2d

Browse files
committed
feat: automatically migrate v2 to v3 reports
We've recently made breaking changes with 41ada54, and we want to ensure existing reports for users continue to work. This commit lazily migrates v2 to v3 reports when loaded. We can keep this logic for a while; while we also migrate our own Firebase database for permanent storage (maybe we need to expose this script for users as well eventually).
1 parent fb2e79c commit 96aba2d

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

report-app/report-server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
FetchedLocalReports,
1212
fetchReportsFromDisk,
1313
} from '../runner/reporting/report-local-disk';
14+
import { RunInfo } from '../runner/shared-interfaces';
15+
import { convertV2ReportToV3Report } from '../runner/reporting/migrations/v2_to_v3';
1416

1517
const app = express();
1618
const reportsLoader = await getReportLoader();
@@ -39,14 +41,17 @@ app.get('/api/reports', async (_, res) => {
3941
app.get('/api/reports/:id', async (req, res) => {
4042
const id = req.params.id;
4143
const localData = await resolveLocalData(options.reportsRoot);
42-
let result: { group: string }[] | null = null;
44+
let result: RunInfo[] | null = null;
4345

4446
if (localData.has(id)) {
4547
result = [localData.get(id)!.run];
4648
} else {
4749
result = await reportsLoader.getGroupedReports(id);
4850
}
4951

52+
// Convert potential older v2 reports.
53+
result = result.map((r) => convertV2ReportToV3Report(r));
54+
5055
res.json(result);
5156
});
5257

@@ -79,7 +84,7 @@ if (isMainModule(import.meta.url)) {
7984
export const reqHandler = createNodeRequestHandler(app);
8085

8186
interface ReportLoader {
82-
getGroupedReports: (groupId: string) => Promise<{ group: string }[]>;
87+
getGroupedReports: (groupId: string) => Promise<RunInfo[]>;
8388
getGroupsList: () => Promise<{ id: string }[]>;
8489
configureEndpoints?: (expressApp: typeof app) => Promise<void>;
8590
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Migrates a v2 report to a v3 report.
3+
* See: https://github.com/angular/web-codegen-scorer/commit/41ada541481a10c99de055ab6bb1c19b06a25b88.
4+
*/
5+
export function convertV2ReportToV3Report(doc: any) {
6+
if (doc.version === 3) {
7+
return doc;
8+
}
9+
10+
const migrateFromBuildResultToSplit = (origBuildResult: any) => {
11+
const buildResult = {
12+
status: origBuildResult.status,
13+
message: origBuildResult.message,
14+
errorType: origBuildResult.errorType,
15+
safetyWebReportJson: origBuildResult.safetyWebReportJson,
16+
missingDependency: origBuildResult.missingDependency,
17+
};
18+
const serveTestingResult = {
19+
errorMessage: undefined,
20+
screenshotPngUrl: origBuildResult.screenshotPngUrl,
21+
runtimeErrors: origBuildResult.runtimeErrors,
22+
userJourneyAgentOutput: origBuildResult.userJourneyAgentOutput,
23+
cspViolations: origBuildResult.cspViolations,
24+
axeViolations: origBuildResult.axeViolations,
25+
};
26+
27+
return { buildResult, serveTestingResult };
28+
};
29+
30+
for (const result of doc.results) {
31+
const finalAttemptSplit = migrateFromBuildResultToSplit(result.build);
32+
result.finalAttempt = {
33+
buildResult: finalAttemptSplit.buildResult,
34+
serveTestingResult: finalAttemptSplit.serveTestingResult,
35+
};
36+
delete result.build;
37+
38+
for (const attempt of result.attemptDetails) {
39+
const attemptSplit = migrateFromBuildResultToSplit(attempt.buildResult);
40+
attempt.buildResult = attemptSplit.buildResult;
41+
attempt.serveTestingResult = attemptSplit.serveTestingResult;
42+
}
43+
}
44+
45+
doc.version = 3;
46+
47+
return doc;
48+
}

0 commit comments

Comments
 (0)