Skip to content

Commit 437f443

Browse files
steipetecxbAsDev
andauthored
refactor(logging): clarify support export config limit
Co-authored-by: 陈宪彪0668000387 <[email protected]>
1 parent 998f4c8 commit 437f443

2 files changed

Lines changed: 16 additions & 55 deletions

File tree

src/logging/diagnostic-support-export.test.ts

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -913,55 +913,10 @@ describe("diagnostic support export", () => {
913913
expect(combined).toContain("Attach this zip to the bug report");
914914
});
915915

916-
it("reads a normal-size config file and reports parseOk: true", async () => {
917-
const configPath = path.join(tempDir, "openclaw.json");
918-
const outputPath = path.join(tempDir, "support-normal-config.zip");
919-
fs.writeFileSync(
920-
configPath,
921-
JSON.stringify({
922-
gateway: { mode: "local", port: 18789 },
923-
logging: { redactSensitive: "off" },
924-
}),
925-
"utf8",
926-
);
927-
928-
await writeDiagnosticSupportExport({
929-
env: {
930-
...process.env,
931-
HOME: tempDir,
932-
OPENCLAW_CONFIG_PATH: configPath,
933-
OPENCLAW_STATE_DIR: tempDir,
934-
},
935-
stateDir: tempDir,
936-
outputPath,
937-
now: new Date("2026-07-18T12:00:00.000Z"),
938-
readLogTail: async () => ({
939-
file: path.join(tempDir, "logs", "openclaw.log"),
940-
cursor: 0,
941-
size: 0,
942-
truncated: false,
943-
reset: false,
944-
lines: [],
945-
}),
946-
});
947-
948-
const entries = await readZipTextEntries(outputPath);
949-
const configShape = JSON.parse(entries["config/shape.json"] ?? "{}") as {
950-
parseOk?: boolean;
951-
gateway?: { mode?: string; port?: number };
952-
};
953-
expect(configShape.parseOk).toBe(true);
954-
expect(configShape.gateway?.mode).toBe("local");
955-
expect(configShape.gateway?.port).toBe(18789);
956-
});
957-
958-
it("handles an oversized config file exceeding the 8 MB read cap gracefully", async () => {
916+
it("finishes the support export when the config exceeds its read limit", async () => {
959917
const configPath = path.join(tempDir, "openclaw.json");
960918
const outputPath = path.join(tempDir, "support-oversized-config.zip");
961-
962-
// Write a config file slightly over the 8 MB DIAGNOSTIC_CONFIG_MAX_BYTES cap
963-
const oversizedContent = Buffer.alloc(8 * 1024 * 1024 + 1, "{");
964-
fs.writeFileSync(configPath, oversizedContent);
919+
fs.writeFileSync(configPath, Buffer.alloc(8 * 1024 * 1024 + 1, "{"));
965920

966921
await writeDiagnosticSupportExport({
967922
env: {
@@ -989,12 +944,16 @@ describe("diagnostic support export", () => {
989944
error?: string;
990945
};
991946
expect(configShape.parseOk).toBe(false);
992-
// Error message should reference the size cap
993-
expect(JSON.stringify(configShape)).toMatch(/exceed|too large|maxBytes|size/i);
994-
995-
// Other bundle contents are still present despite oversized config
996-
expect(Object.keys(entries).toSorted()).toContain("diagnostics.json");
997-
expect(Object.keys(entries).toSorted()).toContain("manifest.json");
947+
expect(configShape.error).toContain("File exceeds 8388608 bytes");
948+
expect(entries["config/sanitized.json"]).toBe("null\n");
949+
expect(Object.keys(entries).toSorted()).toEqual([
950+
"config/sanitized.json",
951+
"config/shape.json",
952+
"diagnostics.json",
953+
"logs/openclaw-sanitized.jsonl",
954+
"manifest.json",
955+
"summary.md",
956+
]);
998957

999958
const combined = Object.values(entries).join("\n");
1000959
expect(combined).toContain("Attach this zip to the bug report");

src/logging/diagnostic-support-export.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ const DIAGNOSTIC_SUPPORT_EXPORT_VERSION = 1;
3939

4040
const DEFAULT_LOG_LIMIT = 5000;
4141
const DEFAULT_LOG_MAX_BYTES = 1_000_000;
42-
const DIAGNOSTIC_CONFIG_MAX_BYTES = 8 * 1024 * 1024;
42+
// Support export must remain usable when the config is corrupt or unexpectedly
43+
// large. This defensive ceiling is not the product's general config-file limit.
44+
const SUPPORT_EXPORT_CONFIG_MAX_BYTES = 8 * 1024 * 1024;
4345
const SUPPORT_EXPORT_PREFIX = "openclaw-diagnostics-";
4446
const SUPPORT_EXPORT_SUFFIX = ".zip";
4547
type Awaitable<T> = T | Promise<T>;
@@ -347,7 +349,7 @@ function readConfigExport(options: {
347349
stat = fs.statSync(options.configPath);
348350
const { buffer } = readRegularFileSync({
349351
filePath: options.configPath,
350-
maxBytes: DIAGNOSTIC_CONFIG_MAX_BYTES,
352+
maxBytes: SUPPORT_EXPORT_CONFIG_MAX_BYTES,
351353
});
352354
const parsed = parseConfigJson5(buffer.toString("utf8"));
353355
if (!parsed.ok) {

0 commit comments

Comments
 (0)