-
Notifications
You must be signed in to change notification settings - Fork 2
fix(app): surface uninstall failures instead of reporting false success #1973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
martin-helmich
wants to merge
1
commit into
master
Choose a base branch
from
fix/1970-uninstall-false-success
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−6
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { describe, expect, it } from "@jest/globals"; | ||
| import { AxiosError, AxiosHeaders } from "axios"; | ||
| import { mapUninstallError } from "./uninstall.js"; | ||
|
|
||
| function axiosErrorWithStatus(status: number): AxiosError { | ||
| const headers = new AxiosHeaders(); | ||
| const config = { headers }; | ||
| return new AxiosError( | ||
| `Request failed with status code ${status}`, | ||
| "ERR_BAD_RESPONSE", | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| config as any, | ||
| {}, | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| { status, data: {}, statusText: "", headers, config } as any, | ||
| ); | ||
| } | ||
|
|
||
| describe("mapUninstallError", () => { | ||
| it("maps an HTTP 412 to a linked-primary-database hint", () => { | ||
| const original = axiosErrorWithStatus(412); | ||
| const mapped = mapUninstallError(original); | ||
|
|
||
| expect(mapped).toBeInstanceOf(Error); | ||
| expect((mapped as Error).message).toContain("cannot uninstall"); | ||
| expect((mapped as Error).message).toContain("primary database"); | ||
| // The original error is preserved as the cause and not swallowed. | ||
| expect((mapped as Error).cause).toBe(original); | ||
| }); | ||
|
|
||
| it("passes through other Axios errors unchanged", () => { | ||
| const original = axiosErrorWithStatus(409); | ||
| const mapped = mapUninstallError(original); | ||
|
|
||
| expect(mapped).toBe(original); | ||
| }); | ||
|
|
||
| it("passes through non-Axios errors unchanged", () => { | ||
| const original = new Error("something else"); | ||
| const mapped = mapUninstallError(original); | ||
|
|
||
| expect(mapped).toBe(original); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { beforeEach, describe, expect, it, jest } from "@jest/globals"; | ||
|
|
||
| /* | ||
| * Regression test for the bug where a failing deletion (e.g. an app uninstall | ||
| * rejected with HTTP 412) still printed "Process completed successfully" and | ||
| * exited with code 0. The command must instead surface the error via | ||
| * process.error() and exit with a non-zero code. | ||
| */ | ||
|
|
||
| const fakeStep = { | ||
| complete: jest.fn(), | ||
| error: jest.fn(), | ||
| }; | ||
|
|
||
| const fakeProcess = { | ||
| start: jest.fn(), | ||
| addStep: jest.fn(() => fakeStep), | ||
| addConfirmation: jest.fn(async () => true), | ||
| addInfo: jest.fn(), | ||
| complete: jest.fn(async (_summary: unknown) => {}), | ||
| error: jest.fn(async (_err: unknown) => {}), | ||
| }; | ||
|
|
||
| const makeProcessRenderer = jest.fn(() => fakeProcess); | ||
|
|
||
| jest.unstable_mockModule("../../rendering/process/process_flags.js", () => ({ | ||
| __esModule: true, | ||
| makeProcessRenderer, | ||
| processFlags: {}, | ||
| })); | ||
|
|
||
| const { DeleteBaseCommand } = await import("./DeleteBaseCommand.js"); | ||
|
|
||
| class TestDelete extends DeleteBaseCommand<typeof TestDelete> { | ||
| static resourceName = "test resource"; | ||
| public shouldThrow: unknown = undefined; | ||
|
|
||
| protected async deleteResource(): Promise<void> { | ||
| if (this.shouldThrow !== undefined) { | ||
| throw this.shouldThrow; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function makeInstance(): TestDelete { | ||
| const instance = Object.create(TestDelete.prototype) as TestDelete; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| (instance as any).flags = { force: true }; | ||
| return instance; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| async function runExec(instance: TestDelete): Promise<any> { | ||
| try { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| await (instance as any).exec(); | ||
| return undefined; | ||
| } catch (err) { | ||
| return err; | ||
| } | ||
| } | ||
|
|
||
| describe("DeleteBaseCommand", () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("reports success and does not exit non-zero when deletion succeeds", async () => { | ||
| const instance = makeInstance(); | ||
|
|
||
| const thrown = await runExec(instance); | ||
|
|
||
| expect(fakeStep.complete).toHaveBeenCalled(); | ||
| expect(fakeProcess.complete).toHaveBeenCalledTimes(1); | ||
| expect(fakeProcess.error).not.toHaveBeenCalled(); | ||
| // no ux.exit() -> no thrown ExitError | ||
| expect(thrown).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("surfaces the error and exits non-zero when deletion fails", async () => { | ||
| const instance = makeInstance(); | ||
| const failure = new Error("boom"); | ||
| instance.shouldThrow = failure; | ||
|
|
||
| const thrown = await runExec(instance); | ||
|
|
||
| // Must NOT falsely report success ... | ||
| expect(fakeProcess.complete).not.toHaveBeenCalled(); | ||
| // ... must surface the actual error ... | ||
| expect(fakeStep.error).toHaveBeenCalledWith(failure); | ||
| expect(fakeProcess.error).toHaveBeenCalledWith(failure); | ||
| // ... and must exit with a non-zero code (ux.exit(1) throws an ExitError). | ||
| expect(thrown).toBeDefined(); | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| expect((thrown as any).oclif?.exit).toBe(1); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure if this can't be done more elegantly. Also don't know if there are other conditions in which a 412 status code might arise. Should investigate if there's a more specific error code in the response body that we could filter for.