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
65 changes: 58 additions & 7 deletions packages/provider-core/src/server/maintenanceResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,34 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
);

it.effect.each([
{ directory: "Caskroom", name: "package-tool", kind: "cask" },
{ directory: "Cellar", name: "package-tool", kind: "formula" },
{ directory: "Cellar", name: "package-tool@latest", kind: "formula" },
{
directory: "Caskroom",
name: "package-tool",
kind: "cask",
version: "0.148.0,42",
latestVersion: "0.148.0",
},
{
directory: "Cellar",
name: "package-tool",
kind: "formula",
version: "0.148.0",
latestVersion: "0.148.0",
},
{
directory: "Cellar",
name: "package-tool@latest",
kind: "formula",
version: "0.148.0",
latestVersion: "0.148.0",
},
{
directory: "Caskroom",
name: "versionless-package-tool",
kind: "cask",
version: "latest",
latestVersion: null,
},
] as const)(
"upgrades the owning Homebrew $kind $name through an executable alias",
(fixture) =>
Expand All @@ -635,7 +660,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
tempDir,
fixture.directory,
fixture.name,
"0.148.0",
fixture.latestVersion ?? "latest",
"package-tool-0.148.0",
);
writeExecutable(ownedBinary);
Expand All @@ -660,8 +685,8 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
? `${tempDir}\n`
: JSON.stringify(
fixture.kind === "cask"
? { casks: [{ version: "0.148.0,42" }] }
: { formulae: [{ versions: { stable: "0.148.0" } }] },
? { casks: [{ version: fixture.version }] }
: { formulae: [{ versions: { stable: fixture.version } }] },
);
}),
),
Expand All @@ -674,7 +699,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
expect(capabilities).toEqual({
provider: driver("packageTool"),
packageName: "@example/package-tool",
latestVersion: "0.148.0",
latestVersion: fixture.latestVersion,
update: {
command:
fixture.kind === "cask"
Expand All @@ -688,6 +713,26 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
lockKey: "homebrew",
},
});

const provider = yield* enrichProviderSnapshotWithVersionAdvisory(
{ ...installedPackageToolProvider, version: "0.148.0" },
capabilities,
).pipe(
Effect.provide(ProviderLatestVersions.layer),
Effect.provideService(
HttpClient.HttpClient,
HttpClient.make(() =>
Effect.die("Homebrew version checks should not fall back to npm"),
),
),
);

expect(provider.versionAdvisory).toMatchObject({
status: fixture.latestVersion === null ? "unknown" : "current",
latestVersion: fixture.latestVersion,
canUpdate: true,
message: null,
});
}),
{ skip: !symlinksSupported },
);
Expand Down Expand Up @@ -735,6 +780,12 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
expect(parseHomebrewLatestVersion("not json", formula)).toBeNull();
});

it("treats Homebrew's latest cask version as unknown", () => {
const info = JSON.stringify({ casks: [{ version: "latest" }] });
const cask = { kind: "cask", name: "package-tool", prefix: "/opt/homebrew" } as const;
expect(parseHomebrewLatestVersion(info, cask)).toBeNull();
});

it.effect.skipIf(windowsHost)(
"disables one-click updates for explicit custom binary paths it cannot safely map",
() =>
Expand Down
3 changes: 2 additions & 1 deletion packages/provider-core/src/server/maintenanceResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ export function parseHomebrewLatestVersion(
ownership.kind === "formula"
? decoded.value.formulae?.[0]?.versions?.stable
: decoded.value.casks?.[0]?.version?.split(",", 1)[0];
return nonEmptyString(raw);
const version = nonEmptyString(raw);
return version === "latest" ? null : version;
}

const runHomebrew = Effect.fn("runHomebrew")(function* (
Expand Down
Loading