Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/commands/installSwiftlyToolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,19 @@ export async function installSwiftlySnapshotToolchain(ctx: WorkspaceContext): Pr
return;
}

const availableToolchains = await Swiftly.listAvailable(ctx.logger);
// Prompt user to enter the branch for snapshot toolchains
const branch = await vscode.window.showInputBox({
title: "Enter Swift Snapshot Branch",
prompt: "Enter the branch name to list snapshot toolchains (e.g., 'main-snapshot', '6.1-snapshot')",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wish there was a way to show the user which snapshot branches are available, but I suppose that's something that would need to be added to Swiftly first.

placeHolder: "main-snapshot",
value: "main-snapshot",
});

if (!branch) {
return; // User cancelled input
}

const availableToolchains = await Swiftly.listAvailable(ctx.logger, branch);

if (availableToolchains.length === 0) {
ctx.logger?.debug("No toolchains available for installation via Swiftly.");
Expand Down
4 changes: 2 additions & 2 deletions src/toolchain/swiftly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const StableVersion = z.object({
export type StableVersion = z.infer<typeof StableVersion>;

const SnapshotVersion = z.object({
major: z.number(),
minor: z.number(),
major: z.union([z.number(), z.undefined()]),
minor: z.union([z.number(), z.undefined()]),
branch: z.string(),
date: z.string(),
name: z.string(),
Expand Down
69 changes: 69 additions & 0 deletions test/unit-tests/toolchain/swiftly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,75 @@ suite("Swiftly Unit Tests", () => {
const result = await Swiftly.listAvailable();
expect(result).to.deep.equal([]);
});

test("should handle snapshot toolchains without major/minor fields", async () => {
mockedPlatform.setValue("darwin");

mockUtilities.execFile.withArgs("swiftly", ["--version"]).resolves({
stdout: "1.1.0\n",
stderr: "",
});

const snapshotResponse = {
toolchains: [
{
inUse: false,
installed: false,
isDefault: false,
version: {
type: "snapshot",
branch: "main",
date: "2025-08-26",
name: "main-snapshot-2025-08-26",
},
},
{
inUse: false,
installed: true,
isDefault: false,
version: {
type: "snapshot",
branch: "main",
date: "2025-08-25",
name: "main-snapshot-2025-08-25",
},
},
],
};

mockUtilities.execFile
.withArgs("swiftly", ["list-available", "--format=json", "main-snapshot"])
.resolves({
stdout: JSON.stringify(snapshotResponse),
stderr: "",
});

const result = await Swiftly.listAvailable(undefined, "main-snapshot");
expect(result).to.deep.equal([
{
inUse: false,
installed: false,
isDefault: false,
version: {
type: "snapshot",
branch: "main",
date: "2025-08-26",
name: "main-snapshot-2025-08-26",
},
},
{
inUse: false,
installed: true,
isDefault: false,
version: {
type: "snapshot",
branch: "main",
date: "2025-08-25",
name: "main-snapshot-2025-08-25",
},
},
]);
});
});

suite("Post-Install", () => {
Expand Down