mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-21 15:01:03 +00:00
test: normalize perf manifest paths
This commit is contained in:
@@ -25,14 +25,25 @@ const readJson = (filePath, fallback) => {
|
||||
};
|
||||
|
||||
const normalizeRepoPath = (value) => value.split(path.sep).join("/");
|
||||
const repoRoot = path.resolve(process.cwd());
|
||||
const normalizeTrackedRepoPath = (value) => {
|
||||
const normalizedValue = typeof value === "string" ? value : String(value ?? "");
|
||||
const repoRelative = path.isAbsolute(normalizedValue)
|
||||
? path.relative(repoRoot, path.resolve(normalizedValue))
|
||||
: normalizedValue;
|
||||
if (path.isAbsolute(repoRelative) || repoRelative.startsWith("..") || repoRelative === "") {
|
||||
return normalizeRepoPath(normalizedValue);
|
||||
}
|
||||
return normalizeRepoPath(repoRelative);
|
||||
};
|
||||
|
||||
const normalizeManifestEntries = (entries) =>
|
||||
entries
|
||||
.map((entry) =>
|
||||
typeof entry === "string"
|
||||
? { file: normalizeRepoPath(entry), reason: "" }
|
||||
? { file: normalizeTrackedRepoPath(entry), reason: "" }
|
||||
: {
|
||||
file: normalizeRepoPath(String(entry?.file ?? "")),
|
||||
file: normalizeTrackedRepoPath(String(entry?.file ?? "")),
|
||||
reason: typeof entry?.reason === "string" ? entry.reason : "",
|
||||
},
|
||||
)
|
||||
@@ -60,7 +71,7 @@ export function loadUnitTimingManifest() {
|
||||
const files = Object.fromEntries(
|
||||
Object.entries(raw.files ?? {})
|
||||
.map(([file, value]) => {
|
||||
const normalizedFile = normalizeRepoPath(file);
|
||||
const normalizedFile = normalizeTrackedRepoPath(file);
|
||||
const durationMs =
|
||||
Number.isFinite(value?.durationMs) && value.durationMs >= 0 ? value.durationMs : null;
|
||||
const testCount =
|
||||
@@ -97,7 +108,7 @@ export function loadUnitMemoryHotspotManifest() {
|
||||
const files = Object.fromEntries(
|
||||
Object.entries(raw.files ?? {})
|
||||
.map(([file, value]) => {
|
||||
const normalizedFile = normalizeRepoPath(file);
|
||||
const normalizedFile = normalizeTrackedRepoPath(file);
|
||||
const deltaKb =
|
||||
Number.isFinite(value?.deltaKb) && value.deltaKb > 0 ? Math.round(value.deltaKb) : null;
|
||||
const sources = Array.isArray(value?.sources)
|
||||
|
||||
@@ -57,10 +57,24 @@ function parseArgs(argv) {
|
||||
return args;
|
||||
}
|
||||
|
||||
const normalizeRepoPath = (value) => value.split(path.sep).join("/");
|
||||
const repoRoot = path.resolve(process.cwd());
|
||||
const normalizeTrackedRepoPath = (value) => {
|
||||
const normalizedValue = typeof value === "string" ? value : String(value ?? "");
|
||||
const repoRelative = path.isAbsolute(normalizedValue)
|
||||
? path.relative(repoRoot, path.resolve(normalizedValue))
|
||||
: normalizedValue;
|
||||
if (path.isAbsolute(repoRelative) || repoRelative.startsWith("..") || repoRelative === "") {
|
||||
return normalizeRepoPath(normalizedValue);
|
||||
}
|
||||
return normalizeRepoPath(repoRelative);
|
||||
};
|
||||
|
||||
function mergeHotspotEntry(aggregated, file, value) {
|
||||
if (!(Number.isFinite(value?.deltaKb) && value.deltaKb > 0)) {
|
||||
return;
|
||||
}
|
||||
const normalizedFile = normalizeTrackedRepoPath(file);
|
||||
const normalizeSourceLabel = (source) => {
|
||||
const separator = source.lastIndexOf(":");
|
||||
if (separator === -1) {
|
||||
@@ -75,9 +89,9 @@ function mergeHotspotEntry(aggregated, file, value) {
|
||||
.filter((source) => typeof source === "string" && source.length > 0)
|
||||
.map(normalizeSourceLabel)
|
||||
: [];
|
||||
const previous = aggregated.get(file);
|
||||
const previous = aggregated.get(normalizedFile);
|
||||
if (!previous) {
|
||||
aggregated.set(file, {
|
||||
aggregated.set(normalizedFile, {
|
||||
deltaKb: Math.round(value.deltaKb),
|
||||
sources: [...new Set(nextSources)],
|
||||
});
|
||||
|
||||
@@ -50,6 +50,17 @@ function parseArgs(argv) {
|
||||
}
|
||||
|
||||
const normalizeRepoPath = (value) => value.split(path.sep).join("/");
|
||||
const repoRoot = path.resolve(process.cwd());
|
||||
const normalizeTrackedRepoPath = (value) => {
|
||||
const normalizedValue = typeof value === "string" ? value : String(value ?? "");
|
||||
const repoRelative = path.isAbsolute(normalizedValue)
|
||||
? path.relative(repoRoot, path.resolve(normalizedValue))
|
||||
: normalizedValue;
|
||||
if (path.isAbsolute(repoRelative) || repoRelative.startsWith("..") || repoRelative === "") {
|
||||
return normalizeRepoPath(normalizedValue);
|
||||
}
|
||||
return normalizeRepoPath(repoRelative);
|
||||
};
|
||||
|
||||
const opts = parseArgs(process.argv.slice(2));
|
||||
const reportPath =
|
||||
@@ -74,7 +85,7 @@ const report = JSON.parse(fs.readFileSync(reportPath, "utf8"));
|
||||
const files = Object.fromEntries(
|
||||
(report.testResults ?? [])
|
||||
.map((result) => {
|
||||
const file = typeof result.name === "string" ? normalizeRepoPath(result.name) : "";
|
||||
const file = typeof result.name === "string" ? normalizeTrackedRepoPath(result.name) : "";
|
||||
const start = typeof result.startTime === "number" ? result.startTime : 0;
|
||||
const end = typeof result.endTime === "number" ? result.endTime : 0;
|
||||
const testCount = Array.isArray(result.assertionResults) ? result.assertionResults.length : 0;
|
||||
|
||||
Reference in New Issue
Block a user