fix(coding-agent): accept managed install markers with a UTF-8 BOM

Windows PowerShell 5.1 adds a BOM when it rewrites managed-install.json, which made pi update fail with "Managed install marker is missing or invalid".
This commit is contained in:
Armin Ronacher 2026-10-20 10:29:22 +02:00
parent 530015d93a
commit ea25697e91
3 changed files with 21 additions and 1 deletions

View file

@ -697,6 +697,24 @@ if (process.platform !== "win32") fs.chmodSync(piPath, 0o755);
expect(process.exitCode).toBeUndefined();
});
it("accepts a managed install marker with a UTF-8 BOM", async () => {
const targetVersion = getNewerPatchVersion();
const { managedRoot } = prepareManagedInstall(targetVersion);
writeFileSync(
join(managedRoot, "managed-install.json"),
`\uFEFF${JSON.stringify({ kind: "pi-managed-install", schemaVersion: 1, layout: "releases-v1" })}\r\n`,
);
mockManagedUpdate(targetVersion);
vi.spyOn(console, "log").mockImplementation(() => {});
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
await expect(runPackageCommandDirectly(["update", "--self"])).resolves.toBeUndefined();
expect(readFileSync(join(managedRoot, "current-version"), "utf8")).toBe(`${targetVersion}\n`);
expect(errorSpy).not.toHaveBeenCalled();
expect(process.exitCode).toBeUndefined();
});
it("removes older managed releases after an update", async () => {
// https://github.com/earendil-works/pi/issues/10392
const targetVersion = getNewerPatchVersion();