Skip to content

Commit ef51244

Browse files
author
David Buzinski
committed
fix formatting, update tests
1 parent db3f8db commit ef51244

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/install.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ export async function install(
109109
try {
110110
await mpm.install(mpmPath, releaseInfo, products, destination);
111111
} catch (e) {
112-
if (releaseInfo.isPrerelease && e instanceof Error && e.message === "Specified release is unavailable") {
112+
if (
113+
releaseInfo.isPrerelease &&
114+
e instanceof Error &&
115+
e.message === "Specified release is unavailable"
116+
) {
113117
core.info("Installation failed. Retrying...");
114118
const grRelease: matlab.Release = {
115119
...releaseInfo,

src/install.unit.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ describe("install procedure", () => {
336336
matlabGetReleaseInfoMock.mockResolvedValue(prereleaseInfo);
337337
});
338338

339-
it("retries with general release when prerelease install fails", async () => {
339+
it("retries with general release when prerelease install fails with unavailable release", async () => {
340340
mpmInstallMock
341-
.mockRejectedValueOnce(Error("Script exited with non-zero code 1"))
341+
.mockRejectedValueOnce(Error("Specified release is unavailable"))
342342
.mockResolvedValueOnce(undefined);
343343
matlabGetToolcacheDirMock
344344
.mockResolvedValueOnce([
@@ -360,7 +360,7 @@ describe("install procedure", () => {
360360
});
361361

362362
it("rejects when both prerelease and general release install fail", async () => {
363-
mpmInstallMock.mockRejectedValue(Error("Script exited with non-zero code 1"));
363+
mpmInstallMock.mockRejectedValue(Error("Specified release is unavailable"));
364364
matlabGetToolcacheDirMock
365365
.mockResolvedValueOnce([
366366
"/opt/hostedtoolcache/MATLAB/2026.1.999-prerelease/x64",
@@ -375,7 +375,18 @@ describe("install procedure", () => {
375375

376376
it("does not retry for non-prerelease install failures", async () => {
377377
matlabGetReleaseInfoMock.mockResolvedValue(releaseInfo);
378+
mpmInstallMock.mockRejectedValue(Error("Specified release is unavailable"));
379+
await expect(doInstall()).rejects.toBeDefined();
380+
expect(mpmInstallMock).toHaveBeenCalledTimes(1);
381+
});
382+
383+
it("does not retry prerelease install for other errors", async () => {
378384
mpmInstallMock.mockRejectedValue(Error("Script exited with non-zero code 1"));
385+
matlabGetToolcacheDirMock.mockResolvedValueOnce([
386+
"/opt/hostedtoolcache/MATLAB/2026.1.999-prerelease/x64",
387+
false,
388+
]);
389+
379390
await expect(doInstall()).rejects.toBeDefined();
380391
expect(mpmInstallMock).toHaveBeenCalledTimes(1);
381392
});

src/mpm.unit.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,23 @@ describe("mpm install", () => {
213213
expect(rmRFMock).toHaveBeenCalledWith(destination);
214214
});
215215

216+
it("rejects with specific message when output includes specified release is unavailable", async () => {
217+
const destination = "/opt/matlab";
218+
const products = ["MATLAB", "Compiler"];
219+
220+
execMock.mockImplementation((cmd: string, args?: string[], options?: ExecOptions) => {
221+
if (options && options.listeners && typeof options.listeners.stderr === "function") {
222+
options.listeners.stderr(Buffer.from("Error: Specified release is unavailable."));
223+
}
224+
return Promise.resolve(1);
225+
});
226+
227+
await expect(mpm.install(mpmPath, releaseInfo, products, destination)).rejects.toThrow(
228+
"Specified release is unavailable",
229+
);
230+
expect(rmRFMock).toHaveBeenCalledWith(destination);
231+
});
232+
216233
it("does not reject when mpm exits non-zero but reports already installed", async () => {
217234
const destination = "/opt/matlab";
218235
const products = ["MATLAB", "Compiler"];

0 commit comments

Comments
 (0)