Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(scripts): 补齐 Windows 扫描缓冲与 Make 诊断码

zcinta05140cd0449e7d23
diff --git a/apps/desktop/src/main/cindy-make/__tests__/testRunner.test.ts b/apps/desktop/src/main/cindy-make/__tests__/testRunner.test.ts
index 4172632f93..9b29fabec3 100644
--- a/apps/desktop/src/main/cindy-make/__tests__/testRunner.test.ts
+++ b/apps/desktop/src/main/cindy-make/__tests__/testRunner.test.ts
@@ -214,26 +214,29 @@ describe('isolated Make test runner', () => {
expect(h.cleanTemp).toHaveBeenCalledOnce();
});
- it('records a wrapper failure code across chunks without raw output or free-form messages', async () => {
- const h = await processHarness();
- h.emit(
- 'compiler output with private data\r\nDESKTOP_DEV_STEP=launching\r\nDESKTOP_DEV_VERDICT=failed\r\n',
- );
- expect(h.kill).not.toHaveBeenCalled();
- h.emit('co');
- h.emit('de=DEV_PROCESS_EXITED\r\nmessage=private credentials and paths\r\n');
- await expect(h.process.ready).rejects.toMatchObject({ code: 'launchFailed' });
- expect(h.diagnostics).toHaveBeenCalledWith(
- expect.objectContaining({
- event: 'failed',
- reason: 'wrapperFailed',
- step: 'launching',
- wrapperCode: 'DEV_PROCESS_EXITED',
- }),
- );
- expect(JSON.stringify(h.diagnostics.mock.calls)).not.toMatch(/private|credentials|compiler/);
- expect(h.kill).toHaveBeenCalledOnce();
- });
+ it.each(['DEV_PROCESS_EXITED', 'WHOAMI_UNAVAILABLE', 'PROCESS_SCAN_FAILED'])(
+ 'records %s across chunks without raw output or free-form messages',
+ async (code) => {
+ const h = await processHarness();
+ h.emit(
+ 'compiler output with private data\r\nDESKTOP_DEV_STEP=launching\r\nDESKTOP_DEV_VERDICT=failed\r\n',
+ );
+ expect(h.kill).not.toHaveBeenCalled();
+ h.emit('co');
+ h.emit(`de=${code}\r\nmessage=private credentials and paths\r\n`);
+ await expect(h.process.ready).rejects.toMatchObject({ code: 'launchFailed' });
+ expect(h.diagnostics).toHaveBeenCalledWith(
+ expect.objectContaining({
+ event: 'failed',
+ reason: 'wrapperFailed',
+ step: 'launching',
+ wrapperCode: code,
+ }),
+ );
+ expect(JSON.stringify(h.diagnostics.mock.calls)).not.toMatch(/private|credentials|compiler/);
+ expect(h.kill).toHaveBeenCalledOnce();
+ },
+ );
it('bounds incomplete failure verdicts and rejects unknown diagnostic codes', async () => {
vi.useFakeTimers();
const h = await processHarness();
diff --git a/apps/desktop/src/main/cindy-make/testRunner.ts b/apps/desktop/src/main/cindy-make/testRunner.ts
index 7c3748e26f..fc8e879f4c 100644
--- a/apps/desktop/src/main/cindy-make/testRunner.ts
+++ b/apps/desktop/src/main/cindy-make/testRunner.ts
@@ -191,6 +191,8 @@ const WRAPPER_FAILURE_CODES = new Set([
'STARTUP_TIMEOUT',
'STARTUP_FAILED',
'WHOAMI_MISMATCH',
+ 'WHOAMI_UNAVAILABLE',
+ 'PROCESS_SCAN_FAILED',
'MIGRATION_POLICY',
'MIGRATE_FAILED',
'AUTH_INIT_FAILED',
diff --git a/scripts/__tests__/restart-desktop-remote.test.mjs b/scripts/__tests__/restart-desktop-remote.test.mjs
index a6967696bb..f0777c6d23 100644
--- a/scripts/__tests__/restart-desktop-remote.test.mjs
+++ b/scripts/__tests__/restart-desktop-remote.test.mjs
@@ -1410,6 +1410,29 @@ test("process scans ask ps for more than the 1 MiB spawnSync default", () => {
for (const call of calls) assert.ok(call.options.maxBuffer >= 4 * 1024 * 1024);
});
+test("Windows scans read process tables larger than the spawnSync default", () => {
+ // #6537 / review P1: the existing buffer regression only covered ps. Exercise
+ // both production scanners with >1 MiB JSON; a fake spawn boundary reproduces
+ // ENOBUFS without a real subprocess in the default runner tier.
+ const commandLine = `node ${"x".repeat(1024 * 1024)}`;
+ const stdout = JSON.stringify({ ProcessId: 777, ParentProcessId: 501, CommandLine: commandLine });
+ const runCommand = (command, _args, options = {}) => {
+ assert.equal(command, "powershell.exe");
+ if (Buffer.byteLength(stdout) > (options.maxBuffer ?? 1024 * 1024)) {
+ return {
+ status: null, stdout: "",
+ error: Object.assign(new Error("spawnSync powershell.exe ENOBUFS"), { code: "ENOBUFS" }),
+ };
+ }
+ return { status: 0, stdout };
+ };
+ const expected = [{ pid: 777, ppid: 501, command: commandLine }];
+ const whoami = scanProcessTable({ platform: "win32", runCommand });
+ assert.equal(whoami.error, null);
+ assert.deepEqual(whoami.processes, expected);
+ assert.deepEqual(scanRestartProcessTable({ platform: "win32", runCommand }), expected);
+});
+
test("posix process rows parse the pid/ppid/command columns", () => {
assert.deepEqual(
parsePosixProcessTable(" 501 1 /sbin/launchd\n 12 501 node script.mjs\n"),
diff --git a/scripts/desktop-whoami.mjs b/scripts/desktop-whoami.mjs
index 74d8791c6f..a40788b3de 100644
--- a/scripts/desktop-whoami.mjs
+++ b/scripts/desktop-whoami.mjs
@@ -67,7 +67,7 @@ Get-CimInstance Win32_Process |
`;
const result = runCommand('powershell.exe', [
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', script,
- ]);
+ ], { maxBuffer: PROCESS_TABLE_MAX_BYTES });
if (result.error || result.status !== 0) {
return {
processes: [],
diff --git a/scripts/restart-desktop-remote.mjs b/scripts/restart-desktop-remote.mjs
index ce3cd6cc13..e063ffb8fc 100644
--- a/scripts/restart-desktop-remote.mjs
+++ b/scripts/restart-desktop-remote.mjs
@@ -318,7 +318,9 @@ Get-CimInstance Win32_Process |
Select-Object ProcessId,ParentProcessId,CommandLine |
ConvertTo-Json -Compress
`;
- const result = runCommand('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', script]);
+ const result = runCommand('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', script], {
+ maxBuffer: PROCESS_TABLE_MAX_BYTES,
+ });
if (result.error || result.status !== 0) {
throw processScanError(
result.error?.code ?? `powershell.exe exit ${result.status}`,