Skip to content

Commit 76cb251

Browse files
mweinbachclaude
andauthored
fix(providers): fall back to windows-x86_64 ACP binaries on Windows on ARM (pingdotgg#18521)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 364f508 commit 76cb251

2 files changed

Lines changed: 176 additions & 17 deletions

File tree

‎packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts‎

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import * as FileSystem from "effect/FileSystem";
1414
import * as Path from "effect/Path";
1515
import * as Fiber from "effect/Fiber";
1616
import * as Layer from "effect/Layer";
17+
import * as Sink from "effect/Sink";
18+
import * as Stream from "effect/Stream";
1719
import * as Schema from "effect/Schema";
1820
import * as HttpClient from "effect/http/HttpClient";
1921
import * as HttpClientResponse from "effect/http/HttpClientResponse";
@@ -209,6 +211,47 @@ describe("AcpRegistrySupport", () => {
209211
platformTarget: "darwin-aarch64",
210212
}),
211213
).toBeUndefined();
214+
expect(
215+
AcpRegistrySupport.resolveAcpRegistryDistribution({
216+
agent: makeAgent({
217+
binary: {
218+
"windows-x86_64": {
219+
archive: archiveUrl,
220+
cmd: "./bin/example-agent-x64.exe",
221+
args: ["acp"],
222+
},
223+
},
224+
}),
225+
preference: "auto",
226+
platformTarget: "windows-aarch64",
227+
}),
228+
).toMatchObject({
229+
kind: "binary",
230+
binaryTarget: { cmd: "./bin/example-agent-x64.exe" },
231+
});
232+
expect(
233+
AcpRegistrySupport.resolveAcpRegistryDistribution({
234+
agent: makeAgent({
235+
binary: {
236+
"windows-aarch64": {
237+
archive: archiveUrl,
238+
cmd: "./bin/example-agent-arm64.exe",
239+
args: ["acp"],
240+
},
241+
"windows-x86_64": {
242+
archive: archiveUrl,
243+
cmd: "./bin/example-agent-x64.exe",
244+
args: ["acp"],
245+
},
246+
},
247+
}),
248+
preference: "auto",
249+
platformTarget: "windows-aarch64",
250+
}),
251+
).toMatchObject({
252+
kind: "binary",
253+
binaryTarget: { cmd: "./bin/example-agent-arm64.exe" },
254+
});
212255
});
213256

214257
it.effect("resolves a local command on the selected environment without the registry", () => {
@@ -782,6 +825,90 @@ describe("AcpRegistrySupport", () => {
782825
);
783826
});
784827

828+
it.effect("prepares an x64 ZIP fallback on Windows ARM when PATH tar cannot read ZIP", () => {
829+
const downloadUrl = "https://registry.test/agent-windows-x64.zip";
830+
const agent = makeAgent({
831+
binary: { "windows-x86_64": { archive: downloadUrl, cmd: "./agent.exe" } },
832+
npx: { package: "@example/[email protected]" },
833+
});
834+
return Effect.gen(function* () {
835+
const fileSystem = yield* FileSystem.FileSystem;
836+
const path = yield* Path.Path;
837+
const cacheDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-acp-arm-zip-" });
838+
const commands: Array<string> = [];
839+
const spawner = ChildProcessSpawner.make((command) =>
840+
Effect.gen(function* () {
841+
if (command._tag !== "StandardCommand") return yield* Effect.die("Unexpected pipeline");
842+
commands.push(command.command);
843+
// Simulate Git's GNU tar rejecting ZIP and System32 bsdtar listing/extracting it.
844+
const supportsZip = command.command === "C:\\Windows\\System32\\tar.exe";
845+
if (supportsZip && command.args[0] === "-xf") {
846+
const outputDirectory = command.args[3];
847+
if (!outputDirectory) return yield* Effect.die("Missing extraction directory");
848+
yield* fileSystem.writeFileString(path.join(outputDirectory, "agent.exe"), "fixture");
849+
}
850+
return ChildProcessSpawner.makeHandle({
851+
pid: ChildProcessSpawner.ProcessId(1),
852+
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(supportsZip ? 0 : 1)),
853+
isRunning: Effect.succeed(false),
854+
kill: () => Effect.void,
855+
unref: Effect.succeed(Effect.void),
856+
stdin: Sink.drain,
857+
stdout: Stream.make(new TextEncoder().encode(supportsZip ? "agent.exe\r\n" : "")),
858+
stderr: Stream.make(
859+
new TextEncoder().encode(supportsZip ? "" : "GNU tar cannot read ZIP"),
860+
),
861+
all: Stream.empty,
862+
getInputFd: () => Sink.drain,
863+
getOutputFd: () => Stream.empty,
864+
});
865+
}).pipe(Effect.orDie),
866+
);
867+
const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
868+
cacheDir,
869+
toolsDir: path.join(cacheDir, "tools"),
870+
registryUrl,
871+
}).pipe(
872+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
873+
Effect.provideService(HostProcess.Platform, "win32"),
874+
Effect.provideService(HostProcess.Architecture, "arm64"),
875+
Effect.provideService(HostProcess.Environment, {
876+
SystemRoot: "C:\\Windows",
877+
PATH: "C:\\Program Files\\Git\\usr\\bin;C:\\Windows\\System32",
878+
}),
879+
Effect.provideService(SpawnExecutableResolution, (command) =>
880+
command === "tar" ? "C:\\Program Files\\Git\\usr\\bin\\tar.exe" : command,
881+
),
882+
);
883+
yield* resolver.prepare({ agentId: agent.id });
884+
const resolved = yield* resolver.resolve(settings(), "/workspace", {});
885+
expect(resolved.spawn.command).toBe(
886+
yield* fileSystem.realPath(
887+
path.join(cacheDir, "tools", agent.id, agent.version, "windows-x86_64", "agent.exe"),
888+
),
889+
);
890+
expect(yield* fileSystem.readFileString(resolved.spawn.command)).toBe("fixture");
891+
expect(commands).toEqual([
892+
"C:\\Windows\\System32\\tar.exe",
893+
"C:\\Windows\\System32\\tar.exe",
894+
]);
895+
}).pipe(
896+
Effect.scoped,
897+
Effect.provide(
898+
layerResolver((request) =>
899+
Effect.succeed(
900+
HttpClientResponse.fromWeb(
901+
request,
902+
request.url === registryUrl
903+
? new Response(makeRegistry(agent))
904+
: new Response("ZIP fixture"),
905+
),
906+
),
907+
),
908+
),
909+
);
910+
});
911+
785912
it.effect("searches compatible agents with deterministic ranking and bounded metadata", () => {
786913
const exact = {
787914
...makeAgent({ npx: { package: "@example/[email protected]" } }),

‎packages/provider-acp-registry/src/server/AcpRegistrySupport.ts‎

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "@t3tools/contracts";
1313
import type { AcpRegistryDistributionPreference } from "../settings.ts";
1414
import type { AcpRegistrySettings } from "../settings.ts";
15+
import { cliArchiveTarCommand } from "@t3tools/shared/cliRelease";
1516
import * as HostProcess from "@t3tools/shared/HostProcess";
1617
import {
1718
mergePathEntries,
@@ -238,6 +239,18 @@ export function resolveAcpRegistryPlatformTarget(
238239
return os && arch ? (`${os}-${arch}` as AcpRegistryPlatformTarget) : undefined;
239240
}
240241

242+
function resolveAcpRegistryPlatformTargetCandidates(
243+
platformTarget: AcpRegistryPlatformTarget | undefined,
244+
): ReadonlyArray<AcpRegistryPlatformTarget> {
245+
if (platformTarget === undefined) return [];
246+
// Windows 11 on ARM executes windows-x86_64 binaries under Prism emulation
247+
// when an agent does not publish a native windows-aarch64 binary.
248+
if (platformTarget === "windows-aarch64") {
249+
return ["windows-aarch64", "windows-x86_64"];
250+
}
251+
return [platformTarget];
252+
}
253+
241254
interface ExactPackageSpec {
242255
readonly name: string;
243256
readonly version: string;
@@ -375,18 +388,22 @@ export const acpRegistryManagedBinaryDirectories = Effect.fn("acpRegistryManaged
375388
(left, right) => right.localeCompare(left, undefined, { numeric: true }),
376389
);
377390
for (const version of versions) {
378-
const installRoot = path.join(installsDirectory, agent, version, target);
379-
if (yield* fileSystem.exists(installRoot).pipe(Effect.orElseSucceed(() => false))) {
380-
const binaryTarget = cachedAgentByInstall.get(`${agent}\0${version}`)?.distribution
381-
.binary?.[target];
382-
const commandSegments =
383-
binaryTarget === undefined ? undefined : normalizeRegistryCommandPath(binaryTarget.cmd);
384-
const directory =
385-
commandSegments === undefined
386-
? installRoot
387-
: path.join(installRoot, ...commandSegments.slice(0, -1));
388-
if (yield* fileSystem.exists(directory).pipe(Effect.orElseSucceed(() => false))) {
389-
directories.push(directory);
391+
for (const candidateTarget of resolveAcpRegistryPlatformTargetCandidates(target)) {
392+
const installRoot = path.join(installsDirectory, agent, version, candidateTarget);
393+
if (yield* fileSystem.exists(installRoot).pipe(Effect.orElseSucceed(() => false))) {
394+
const binaryTarget = cachedAgentByInstall.get(`${agent}\0${version}`)?.distribution
395+
.binary?.[candidateTarget];
396+
const commandSegments =
397+
binaryTarget === undefined
398+
? undefined
399+
: normalizeRegistryCommandPath(binaryTarget.cmd);
400+
const directory =
401+
commandSegments === undefined
402+
? installRoot
403+
: path.join(installRoot, ...commandSegments.slice(0, -1));
404+
if (yield* fileSystem.exists(directory).pipe(Effect.orElseSucceed(() => false))) {
405+
directories.push(directory);
406+
}
390407
}
391408
}
392409
}
@@ -409,7 +426,9 @@ export function resolveAcpRegistryDistribution(input: {
409426
readonly platformTarget: AcpRegistryPlatformTarget | undefined;
410427
}): ResolvedAcpRegistryDistribution | undefined {
411428
const { agent, platformTarget } = input;
412-
const binary = platformTarget ? agent.distribution.binary?.[platformTarget] : undefined;
429+
const binary = resolveAcpRegistryPlatformTargetCandidates(platformTarget)
430+
.map((candidate) => agent.distribution.binary?.[candidate])
431+
.find((entry) => entry !== undefined);
413432
const candidates: ReadonlyArray<AcpRegistryDistributionKind> =
414433
input.preference === "auto" ? ["binary", "npx", "uvx"] : [input.preference];
415434

@@ -1336,11 +1355,16 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
13361355

13371356
const binaryPaths = (agent: AcpRegistryAgent, target: typeof AcpRegistryBinaryTarget.Type) => {
13381357
const commandSegments = normalizeRegistryCommandPath(target.cmd);
1339-
if (platformTarget === undefined || commandSegments === undefined) return undefined;
1340-
const installRoot = path.join(agentInstallRoot(agent), platformTarget);
1358+
const matchedPlatformTarget =
1359+
resolveAcpRegistryPlatformTargetCandidates(platformTarget).find(
1360+
(candidate) => agent.distribution.binary?.[candidate] === target,
1361+
) ?? platformTarget;
1362+
if (matchedPlatformTarget === undefined || commandSegments === undefined) return undefined;
1363+
const installRoot = path.join(agentInstallRoot(agent), matchedPlatformTarget);
13411364
return {
13421365
commandSegments,
13431366
installRoot,
1367+
platformTarget: matchedPlatformTarget,
13441368
executablePath: path.join(installRoot, ...commandSegments),
13451369
};
13461370
};
@@ -1487,6 +1511,14 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
14871511
yield* fileSystem.makeDirectory(path.dirname(targetPath), { recursive: true });
14881512
yield* fileSystem.rename(archivePath, targetPath);
14891513
} else {
1514+
// The new Windows ARM fallback must extract x64 ZIPs even when Git's GNU tar wins PATH.
1515+
// Keep archive selection for existing native distributions unchanged in this PR.
1516+
const tarCommand =
1517+
platformTarget === "windows-aarch64" &&
1518+
paths.platformTarget === "windows-x86_64" &&
1519+
kind === "zip"
1520+
? cliArchiveTarCommand(platform, hostEnvironment)
1521+
: "tar";
14901522
const listArgs =
14911523
kind === "tar_gz"
14921524
? ["-tzf", archivePath]
@@ -1498,7 +1530,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
14981530
const entries =
14991531
listArgs === undefined
15001532
? yield* runCommand("unzip", ["-Z1", archivePath])
1501-
: yield* runCommand("tar", listArgs);
1533+
: yield* runCommand(tarCommand, listArgs);
15021534
if (!validateArchiveEntries(entries)) {
15031535
return yield* new AcpRegistryError({
15041536
reason: "archive_invalid",
@@ -1509,7 +1541,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
15091541
yield* runCommand("unzip", ["-q", archivePath, "-d", extractionRoot]);
15101542
} else {
15111543
const extractFlag = kind === "tar_gz" ? "-xzf" : kind === "tar_bz2" ? "-xjf" : "-xf";
1512-
yield* runCommand("tar", [extractFlag, archivePath, "-C", extractionRoot]);
1544+
yield* runCommand(tarCommand, [extractFlag, archivePath, "-C", extractionRoot]);
15131545
}
15141546
}
15151547

0 commit comments

Comments
 (0)