From 27c93a6e7f41514c61ae56bece3ca5a1455000c8 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 19:00:01 +0200 Subject: [PATCH 1/2] =?UTF-8?q?test:=20reproduce=20#260=20=E2=80=94=20a=20?= =?UTF-8?q?percentage=20written=20with=20a=20decimal=20comma=20is=20read?= =?UTF-8?q?=20as=20its=20last=20digit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/installer-process.test.ts | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/drivers/installer-process.test.ts b/src/drivers/installer-process.test.ts index 8a0b3928f..0f8def9d6 100644 --- a/src/drivers/installer-process.test.ts +++ b/src/drivers/installer-process.test.ts @@ -58,6 +58,36 @@ describe("runInstallerProcess", () => { expect(progress.map((report) => report.percent)).toEqual([10, 20, 30]); }); + it("reads a percentage written with a decimal comma, as xcodebuild prints it in a region that uses one", async () => { + // Byte for byte as `xcodebuild -downloadPlatform iOS -buildVersion 18.4` wrote it under + // language English, region Poland: one `\n`, then `\r`-separated redraws, a line with only + // the title, a "Preparing" line, comma decimals in the percentage and the sizes, and a + // redraw padded with trailing spaces. + const title = "Downloading iOS 18.4 Universal Simulator (22E238):"; + const runner = new ScriptedProcessRunner([ + { + match: { args: ["install"], command }, + stderrLines: [ + [ + "Finding content...\n", + `${title} `, + `${title} Preparing to download...`, + `${title} 0,0% (73 kB of 8,86 GB)`, + `${title} 0,4% (39,4 MB of 8,86 GB)`, + `${title} 2,7% (235 MB of 8,86 GB) `, + `${title} 9,7% (857,8 MB of 8,86 GB)`, + ].join("\r"), + ], + }, + ]); + const clock = new FakeClock(); + + const { outcome, progress } = run(runner, clock); + await outcome; + + expect(progress.map((report) => report.percent)).toEqual([0, 0.4, 2.7, 9.7]); + }); + it("reports each percentage while the installer is still running, before it exits", async () => { const runner = new ScriptedProcessRunner([ { From 06480b32d2adccc2e6bcf7cbf1d4e0079f6564c0 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 19:05:03 +0200 Subject: [PATCH 2/2] fix(drivers): read an installer's percentage written with a decimal comma xcodebuild formats its progress in the user's locale, so a region with a decimal comma prints 9,7%, which the parser read as 7%. Accept a dot or a comma before the decimals. --- docs/internal/KNOWN-PITFALLS.md | 6 +++++- src/drivers/installer-process.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/internal/KNOWN-PITFALLS.md b/docs/internal/KNOWN-PITFALLS.md index 83e3bd9f2..bf1f29b9f 100644 --- a/docs/internal/KNOWN-PITFALLS.md +++ b/docs/internal/KNOWN-PITFALLS.md @@ -333,7 +333,11 @@ single line, read when the install is already over, whose last percentage is 100. `runInstallerProcess` therefore spawns with `lineEnd: "carriage-return-too"`, which ends a line at a bare `\r` as well. Anything else that reads an installer's progress must do the same, or it -reports nothing until the end. +reports nothing until the end. `xcodebuild` also formats its numbers in the +user's locale, so in a region with a decimal comma it prints `9,7%`; the +parser accepts a dot or a comma before the decimals (#260). A locale whose +digits are not ASCII (Arabic `٩٫٧٪`) still matches nothing, so that download +reports no progress at all rather than wrong progress. ## An iOS runtime download outlives the runtime, and only Xcode can reclaim it (#79) diff --git a/src/drivers/installer-process.ts b/src/drivers/installer-process.ts index 50f2d6c76..7de6295f2 100644 --- a/src/drivers/installer-process.ts +++ b/src/drivers/installer-process.ts @@ -69,12 +69,16 @@ export async function runInstallerProcess( } } -/** The last percentage printed on a line, e.g. `12.5` from `Downloading iOS 18.0: 12.5%`. */ +/** + * The last percentage printed on a line, e.g. `12.5` from `Downloading iOS 18.0: 12.5%`. + * `xcodebuild` formats it in the user's locale, so the decimal separator may be a comma + * (`12,5%`); a percentage never reaches a thousand, so no grouping separator comes before `%`. + */ function parseProgressPercent(line: string): number | undefined { - const matches = [...line.matchAll(/(\d{1,3}(?:\.\d+)?)\s*%/g)]; + const matches = [...line.matchAll(/(\d{1,3}(?:[.,]\d+)?)\s*%/g)]; const last = matches.at(-1)?.[1]; if (last === undefined) return undefined; - const percent = Number.parseFloat(last); + const percent = Number.parseFloat(last.replace(",", ".")); return percent >= 0 && percent <= 100 ? percent : undefined; }