Skip to content

Commit 79188e8

Browse files
authored
Add support for selecting Swift snapshot branch for toolchain installation (#1807)
1 parent fc656b4 commit 79188e8

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed

src/commands/installSwiftlyToolchain.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,19 @@ export async function installSwiftlySnapshotToolchain(ctx: WorkspaceContext): Pr
162162
return;
163163
}
164164

165-
const availableToolchains = await Swiftly.listAvailable(ctx.logger);
165+
// Prompt user to enter the branch for snapshot toolchains
166+
const branch = await vscode.window.showInputBox({
167+
title: "Enter Swift Snapshot Branch",
168+
prompt: "Enter the branch name to list snapshot toolchains (e.g., 'main-snapshot', '6.1-snapshot')",
169+
placeHolder: "main-snapshot",
170+
value: "main-snapshot",
171+
});
172+
173+
if (!branch) {
174+
return; // User cancelled input
175+
}
176+
177+
const availableToolchains = await Swiftly.listAvailable(ctx.logger, branch);
166178

167179
if (availableToolchains.length === 0) {
168180
ctx.logger?.debug("No toolchains available for installation via Swiftly.");

src/toolchain/swiftly.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const StableVersion = z.object({
6767
export type StableVersion = z.infer<typeof StableVersion>;
6868

6969
const SnapshotVersion = z.object({
70-
major: z.number(),
71-
minor: z.number(),
70+
major: z.union([z.number(), z.undefined()]),
71+
minor: z.union([z.number(), z.undefined()]),
7272
branch: z.string(),
7373
date: z.string(),
7474
name: z.string(),

test/unit-tests/toolchain/swiftly.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,75 @@ suite("Swiftly Unit Tests", () => {
353353
const result = await Swiftly.listAvailable();
354354
expect(result).to.deep.equal([]);
355355
});
356+
357+
test("should handle snapshot toolchains without major/minor fields", async () => {
358+
mockedPlatform.setValue("darwin");
359+
360+
mockUtilities.execFile.withArgs("swiftly", ["--version"]).resolves({
361+
stdout: "1.1.0\n",
362+
stderr: "",
363+
});
364+
365+
const snapshotResponse = {
366+
toolchains: [
367+
{
368+
inUse: false,
369+
installed: false,
370+
isDefault: false,
371+
version: {
372+
type: "snapshot",
373+
branch: "main",
374+
date: "2025-08-26",
375+
name: "main-snapshot-2025-08-26",
376+
},
377+
},
378+
{
379+
inUse: false,
380+
installed: true,
381+
isDefault: false,
382+
version: {
383+
type: "snapshot",
384+
branch: "main",
385+
date: "2025-08-25",
386+
name: "main-snapshot-2025-08-25",
387+
},
388+
},
389+
],
390+
};
391+
392+
mockUtilities.execFile
393+
.withArgs("swiftly", ["list-available", "--format=json", "main-snapshot"])
394+
.resolves({
395+
stdout: JSON.stringify(snapshotResponse),
396+
stderr: "",
397+
});
398+
399+
const result = await Swiftly.listAvailable(undefined, "main-snapshot");
400+
expect(result).to.deep.equal([
401+
{
402+
inUse: false,
403+
installed: false,
404+
isDefault: false,
405+
version: {
406+
type: "snapshot",
407+
branch: "main",
408+
date: "2025-08-26",
409+
name: "main-snapshot-2025-08-26",
410+
},
411+
},
412+
{
413+
inUse: false,
414+
installed: true,
415+
isDefault: false,
416+
version: {
417+
type: "snapshot",
418+
branch: "main",
419+
date: "2025-08-25",
420+
name: "main-snapshot-2025-08-25",
421+
},
422+
},
423+
]);
424+
});
356425
});
357426

358427
suite("Post-Install", () => {

0 commit comments

Comments
 (0)