fix(ci): keep npm debug diagnostics best-effort

This commit is contained in:
Vincent Koc
2026-07-05 22:08:52 +02:00
parent 79f7d90cb9
commit 1408deede7
2 changed files with 39 additions and 17 deletions

View File

@@ -3011,25 +3011,29 @@ export function appendLatestNpmDebugLogTail(
env = process.env,
platform = process.platform,
) {
const candidates = resolveNpmDebugLogDirs(homeDir, env, platform)
.flatMap(findNpmDebugLogs)
.toSorted((left, right) => left.mtimeMs - right.mtimeMs);
const latest = candidates.at(-1);
if (!latest) {
try {
const candidates = resolveNpmDebugLogDirs(homeDir, env, platform)
.flatMap(findNpmDebugLogs)
.toSorted((left, right) => left.mtimeMs - right.mtimeMs);
const latest = candidates.at(-1);
if (!latest) {
return "";
}
const tail = readLogTextWindow(latest.path, { maxBytes: CROSS_OS_NPM_DEBUG_LOG_TAIL_BYTES });
if (!tail.trim()) {
return "";
}
appendFileSync(
logPath,
`\n${new Date().toISOString()} npm-debug-log path=${latest.path}\n${tail}\n`,
"utf8",
);
return tail;
} catch {
return "";
}
const tail = readLogTextWindow(latest.path, { maxBytes: CROSS_OS_NPM_DEBUG_LOG_TAIL_BYTES });
if (!tail.trim()) {
return "";
}
appendFileSync(
logPath,
`\n${new Date().toISOString()} npm-debug-log path=${latest.path}\n${tail}\n`,
"utf8",
);
return tail;
}
export function resolveNpmDebugLogDirs(homeDir, env = process.env, platform = process.platform) {

View File

@@ -1417,6 +1417,24 @@ describe("scripts/openclaw-cross-os-release-checks", () => {
}
});
it("keeps npm debug log collection best-effort", () => {
const dir = mkdtempSync(join(tmpdir(), "openclaw-cross-os-npm-debug-best-effort-"));
try {
const homeDir = join(dir, "home");
const logPath = join(dir, "install.log");
const logsDir = join(dir, "not-a-directory");
writeFileSync(logPath, "install failed\n");
writeFileSync(logsDir, "not a directory\n");
expect(appendLatestNpmDebugLogTail(homeDir, logPath, { npm_config_logs_dir: logsDir })).toBe(
"",
);
expect(readFileSync(logPath, "utf8")).toBe("install failed\n");
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
it("resolves relative npm log config from the install working directory", () => {
const dir = mkdtempSync(join(tmpdir(), "openclaw-cross-os-npm-relative-logs-"));
try {