Skip to content

Commit cd899a1

Browse files
authored
fix(report): set explicit assetPrefix to avoid runtime publicPath error (#2345)
* fix(report): set explicit assetPrefix to avoid runtime publicPath error Without an explicit output.assetPrefix, rsbuild defaults to 'auto', which relies on document.currentScript.src at runtime. Combined with inlineScripts: true the src is empty, and some browsers throw 'Automatic publicPath is not supported in this browser' when the bundle tries to resolve asset paths. This surfaced in 1.7.x when reports moved to the html-and-external-assets layout (with externalized screenshots). Setting assetPrefix: './' makes rspack emit relative paths and skip the runtime auto-detection path entirely. * feat(core): warn when ReportMergingTool meets a version-mismatched source report Users who install @midscene/android and @midscene/core at different versions (commonly 'latest' on core while pinning android to a prepatch) end up with ReportMergingTool loaded from the older @midscene/core at the package root while the agent generates reports from the newer core nested under @midscene/android. Before #2153's per-execution append model, mergeReports read only the last <script type="midscene_web_dump"> tag per source file, which silently drops every intermediate action and leaves the merged report with nothing but the test's final step. Peek at the source report's sdkVersion on append and log a clear warning when it differs from the merger's own getVersion(), so the mismatch surfaces before the user spends time debugging an empty-looking report.
1 parent 5d98966 commit cd899a1

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

apps/report/rsbuild.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export default defineConfig({
154154
},
155155
},
156156
output: {
157+
assetPrefix: './',
157158
inlineScripts: true,
158159
injectStyles: true,
159160
},

packages/core/src/report.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
ReportActionDump,
3030
} from './types';
3131
import type { ReportFileWithAttributes } from './types';
32-
import { getReportTpl, reportHTMLContent } from './utils';
32+
import { getReportTpl, getVersion, reportHTMLContent } from './utils';
3333

3434
/**
3535
* Check if a report is in directory mode (html-and-external-assets).
@@ -58,6 +58,24 @@ export function dedupeExecutionsKeepLatest<T extends Pick<ExecutionDump, 'id'>>(
5858
}
5959
return Array.from(deduped.values());
6060
}
61+
/**
62+
* Peek at the first `sdkVersion` field embedded in a midscene_web_dump
63+
* script tag inside the given report file. Returns undefined if no
64+
* recognizable tag or sdkVersion is present.
65+
*/
66+
function peekReportSdkVersion(reportFilePath: string): string | undefined {
67+
try {
68+
const dump = extractLastDumpScriptSync(reportFilePath);
69+
if (!dump) return undefined;
70+
const match = dump.match(/"sdkVersion"\s*:\s*"([^"]+)"/);
71+
return match?.[1];
72+
} catch {
73+
return undefined;
74+
}
75+
}
76+
77+
const warnedMismatchedVersions = new Set<string>();
78+
6179
export class ReportMergingTool {
6280
private reportInfos: ReportFileWithAttributes[] = [];
6381

@@ -72,6 +90,21 @@ export class ReportMergingTool {
7290
}
7391

7492
public append(reportInfo: ReportFileWithAttributes) {
93+
if (reportInfo.reportFilePath) {
94+
const sourceVersion = peekReportSdkVersion(reportInfo.reportFilePath);
95+
const currentVersion = getVersion();
96+
if (
97+
sourceVersion &&
98+
currentVersion &&
99+
sourceVersion !== currentVersion &&
100+
!warnedMismatchedVersions.has(sourceVersion)
101+
) {
102+
warnedMismatchedVersions.add(sourceVersion);
103+
logMsg(
104+
`[@midscene/core] ReportMergingTool version mismatch: source report was written by @midscene/core@${sourceVersion} but the merger is @midscene/core@${currentVersion}. This commonly means @midscene/core and the device package (e.g. @midscene/android) resolve to different versions in node_modules. Merged output may silently drop intermediate steps. Align the versions and reinstall (rm -rf node_modules package-lock.json && npm install).`,
105+
);
106+
}
107+
}
75108
this.reportInfos.push(reportInfo);
76109
}
77110
public clear() {

0 commit comments

Comments
 (0)