fix(e2e): ignore inline kitchen sink json diagnostics · openclaw/openclaw@6ad7f66
vincentkoc
·
2026-06-20
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -624,7 +624,7 @@ async function resolveOpenClawCommand(runner, args, env, options = {}) {
|
624 | 624 | }; |
625 | 625 | } |
626 | 626 | |
627 | | -function parseJsonOutput(stdout) { |
| 627 | +export function parseJsonOutput(stdout) { |
628 | 628 | const trimmed = stdout.trim(); |
629 | 629 | if (!trimmed) { |
630 | 630 | throw new Error("command produced no JSON output"); |
@@ -757,6 +757,9 @@ function extractBalancedJsonObjects(text) {
|
757 | 757 | if (text[index] !== "{") { |
758 | 758 | continue; |
759 | 759 | } |
| 760 | +if (!isJsonObjectRecordStart(text, index)) { |
| 761 | +continue; |
| 762 | +} |
760 | 763 | const end = findBalancedJsonObjectEnd(text, index); |
761 | 764 | if (end > index) { |
762 | 765 | candidates.push(text.slice(index, end + 1)); |
@@ -766,6 +769,17 @@ function extractBalancedJsonObjects(text) {
|
766 | 769 | return candidates; |
767 | 770 | } |
768 | 771 | |
| 772 | +function isJsonObjectRecordStart(text, index) { |
| 773 | +if (index === 0) { |
| 774 | +return true; |
| 775 | +} |
| 776 | +let cursor = index - 1; |
| 777 | +while (cursor >= 0 && (text[cursor] === " " || text[cursor] === "\t")) { |
| 778 | +cursor -= 1; |
| 779 | +} |
| 780 | +return cursor < 0 || text[cursor] === "\n" || text[cursor] === "\r"; |
| 781 | +} |
| 782 | + |
769 | 783 | function findBalancedJsonObjectEnd(text, startIndex) { |
770 | 784 | let depth = 0; |
771 | 785 | let inString = false; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -43,6 +43,7 @@ import {
|
43 | 43 | listKitchenSinkAuthorizationRpcProbeNames, |
44 | 44 | listKitchenSinkReadOnlyRpcProbeNames, |
45 | 45 | makeEnv, |
| 46 | +parseJsonOutput, |
46 | 47 | parseGatewayCliRequestFailure, |
47 | 48 | readPositiveInt, |
48 | 49 | readBoundedResponseText, |
@@ -913,6 +914,18 @@ await runCommand(process.execPath, [${JSON.stringify(scriptPath)}], {
|
913 | 914 | }); |
914 | 915 | |
915 | 916 | describe("kitchen-sink RPC payload unwrapping", () => { |
| 917 | +it("parses the final JSON record without accepting inline diagnostic objects", () => { |
| 918 | +const parsed = parseJsonOutput( |
| 919 | +[ |
| 920 | +'debug: ignored inline diagnostic {"ok":false,"result":{"stale":true}}', |
| 921 | +JSON.stringify({ ok: true, result: { current: true } }, null, 2), |
| 922 | +'warning: ignored trailing diagnostic {"ok":false,"result":{"stale":true}}', |
| 923 | +].join("\n"), |
| 924 | +); |
| 925 | + |
| 926 | +expect(parsed).toEqual({ ok: true, result: { current: true } }); |
| 927 | +}); |
| 928 | + |
916 | 929 | it("preserves explicit nullish JSON-RPC result fields", () => { |
917 | 930 | expect(unwrapRpcPayload({ jsonrpc: "2.0", result: null })).toBeNull(); |
918 | 931 | expect(unwrapRpcPayload({ jsonrpc: "2.0", result: undefined })).toBeUndefined(); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。