mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-09 04:03:59 +00:00
fix(ci): keep npm debug diagnostics best-effort
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user