fix(qa): match Windows RPC sampling ports exactly · openclaw/openclaw@7bf821a
vincentkoc
·
2026-06-17
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1874,8 +1874,7 @@ export async function sampleWindowsProcessByPort(port, options = {}) {
|
1874 | 1874 | const pid = stdout |
1875 | 1875 | .split(/\r?\n/u) |
1876 | 1876 | .map((line) => line.trim()) |
1877 | | -.filter((line) => line.includes(`:${safePort}`) && /\bLISTENING\b/iu.test(line)) |
1878 | | -.map((line) => Number.parseInt(line.split(/\s+/u).at(-1) ?? "", 10)) |
| 1877 | +.map((line) => parseWindowsNetstatListeningPid(line, safePort)) |
1879 | 1878 | .find((candidate) => Number.isInteger(candidate) && candidate > 0); |
1880 | 1879 | if (!pid) { |
1881 | 1880 | return null; |
@@ -1886,6 +1885,19 @@ export async function sampleWindowsProcessByPort(port, options = {}) {
|
1886 | 1885 | } |
1887 | 1886 | } |
1888 | 1887 | |
| 1888 | +function parseWindowsNetstatListeningPid(line, port) { |
| 1889 | +if (!/\bLISTENING\b/iu.test(line)) { |
| 1890 | +return null; |
| 1891 | +} |
| 1892 | +const fields = line.trim().split(/\s+/u); |
| 1893 | +const localPortMatch = fields[1]?.match(/:(\d+)$/u); |
| 1894 | +if (!localPortMatch || Number(localPortMatch[1]) !== port) { |
| 1895 | +return null; |
| 1896 | +} |
| 1897 | +const processId = Number(fields.at(-1) ?? ""); |
| 1898 | +return Number.isSafeInteger(processId) && processId > 0 ? processId : null; |
| 1899 | +} |
| 1900 | + |
1889 | 1901 | function powershellSingleQuoted(value) { |
1890 | 1902 | return `'${String(value).replace(/'/gu, "''")}'`; |
1891 | 1903 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1358,6 +1358,8 @@ describe("kitchen-sink RPC process sampling", () => {
|
1358 | 1358 | return { |
1359 | 1359 | stdout: [ |
1360 | 1360 | " Proto Local Address Foreign Address State PID", |
| 1361 | +" TCP 127.0.0.1:196750 0.0.0.0:0 LISTENING 1111", |
| 1362 | +" TCP 127.0.0.1:1967 0.0.0.0:0 LISTENING 2222", |
1361 | 1363 | " TCP 127.0.0.1:19675 0.0.0.0:0 LISTENING 6789", |
1362 | 1364 | ].join("\r\n"), |
1363 | 1365 | stderr: "", |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。