|
1 | | -import { execFileSync } from "node:child_process"; |
| 1 | +import { execFileSync, spawnSync } from "node:child_process"; |
2 | 2 | import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
3 | 3 | import { tmpdir } from "node:os"; |
4 | 4 | import path from "node:path"; |
5 | 5 | // Release prepare tests cover shadow planning, cutover commands, and candidate manifests. |
6 | 6 | import { expectDefined } from "@openclaw/normalization-core"; |
7 | | -import { describe, expect, it, vi } from "vitest"; |
| 7 | +import { describe, expect, it } from "vitest"; |
8 | 8 | import { |
9 | 9 | buildReleasePreparationManifest, |
10 | 10 | createReleasePrepareSteps, |
11 | 11 | parseReleasePrepareArgs, |
12 | 12 | readWorktreeState, |
13 | | - runReleasePrepareStep, |
14 | 13 | runReleasePrepareSteps, |
15 | 14 | } from "../../scripts/release-prepare.ts"; |
16 | 15 |
|
@@ -125,41 +124,41 @@ describe("release preparation plan", () => { |
125 | 124 | expect(results.map((result) => result.status)).toEqual(["failed", "skipped"]); |
126 | 125 | }); |
127 | 126 |
|
128 | | - it("keeps JSON mode child output off stdout", () => { |
129 | | - const stdout: string[] = []; |
130 | | - const stderr: string[] = []; |
131 | | - const stdoutSpy = vi.spyOn(process.stdout, "write").mockImplementation((chunk) => { |
132 | | - stdout.push(String(chunk)); |
133 | | - return true; |
134 | | - }); |
135 | | - const stderrSpy = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => { |
136 | | - stderr.push(String(chunk)); |
137 | | - return true; |
138 | | - }); |
139 | | - try { |
| 127 | + it("streams large JSON-mode child output to stderr without buffering", () => { |
| 128 | + const childScript = [ |
| 129 | + 'const { writeSync } = require("node:fs");', |
| 130 | + 'writeSync(1, "child stdout begin\\n" + "x".repeat(2 * 1024 * 1024) + "\\nchild stdout end\\n");', |
| 131 | + 'writeSync(2, "child stderr sentinel\\n");', |
| 132 | + "process.exit(23);", |
| 133 | + ].join(""); |
| 134 | + const harness = ` |
| 135 | + import { runReleasePrepareStep } from ${JSON.stringify(new URL("../../scripts/release-prepare.ts", import.meta.url).href)}; |
140 | 136 | const status = runReleasePrepareStep( |
141 | | - { |
142 | | - args: [ |
143 | | - "-e", |
144 | | - 'process.stdout.write("child stdout\\n"); process.stderr.write("child stderr\\n");', |
145 | | - ], |
146 | | - command: process.execPath, |
147 | | - id: "release-version", |
148 | | - name: "JSON child", |
149 | | - }, |
| 137 | + { args: ["-e", ${JSON.stringify(childScript)}], command: process.execPath, id: "release-version", name: "JSON child" }, |
150 | 138 | process.cwd(), |
151 | 139 | { json: true }, |
152 | 140 | ); |
| 141 | + process.exitCode = status; |
| 142 | + `; |
| 143 | + const result = spawnSync( |
| 144 | + process.execPath, |
| 145 | + ["--import", "tsx", "--input-type=module", "-e", harness], |
| 146 | + { |
| 147 | + cwd: process.cwd(), |
| 148 | + encoding: "utf8", |
| 149 | + maxBuffer: 4 * 1024 * 1024, |
| 150 | + stdio: ["ignore", "pipe", "pipe"], |
| 151 | + }, |
| 152 | + ); |
153 | 153 |
|
154 | | - expect(status).toBe(0); |
155 | | - expect(stdout.join("")).toBe(""); |
156 | | - expect(stderr.join("")).toContain("[release-prepare] JSON child"); |
157 | | - expect(stderr.join("")).toContain("child stdout"); |
158 | | - expect(stderr.join("")).toContain("child stderr"); |
159 | | - } finally { |
160 | | - stdoutSpy.mockRestore(); |
161 | | - stderrSpy.mockRestore(); |
162 | | - } |
| 154 | + expect(result.error).toBeUndefined(); |
| 155 | + expect(result.status).toBe(23); |
| 156 | + expect(result.stdout).toBe(""); |
| 157 | + expect(result.stderr).toContain("[release-prepare] JSON child"); |
| 158 | + expect(result.stderr).toContain("child stdout begin"); |
| 159 | + expect(result.stderr).toContain("child stdout end"); |
| 160 | + expect(result.stderr).toContain("child stderr sentinel"); |
| 161 | + expect(Buffer.byteLength(result.stderr)).toBeGreaterThan(2 * 1024 * 1024); |
163 | 162 | }); |
164 | 163 | }); |
165 | 164 |
|
|
0 commit comments