-
Notifications
You must be signed in to change notification settings - Fork 4
SP-1383: gate early-access commands behind feature flag, replace beta #393
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
Open
A. Jashari (admirjashari)
wants to merge
1
commit into
main
Choose a base branch
from
SP-1383-early-access-feature-flag
base: main
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.
Open
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
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
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,38 @@ | ||
| /** | ||
| * Recognizes the backend's "feature not enabled" response so the CLI can surface a | ||
| * clear message instead of a raw error. Enforcement stays entirely in the backend | ||
| * (pacman); the CLI only translates the response — it never decides entitlement. | ||
| * | ||
| * The backend rejects a flag-gated request with 403 and a machine-readable body: | ||
| * {"errorCode":"feature-disabled", ...} (pacman's standard ErrorTransport). Keying | ||
| * off the stable code (rather than a free-text message) keeps this robust. | ||
| */ | ||
| export const FEATURE_DISABLED_CODE = "feature-disabled"; | ||
|
|
||
| /** | ||
| * True when the given error represents a backend "feature disabled" rejection. | ||
| * HttpClient rejects with the stringified response body (often wrapped as | ||
| * "FatalError: {json}"), so we extract and parse the embedded JSON payload. | ||
| */ | ||
| export function isFeatureDisabledError(error: unknown): boolean { | ||
| return extractErrorCode(error) === FEATURE_DISABLED_CODE; | ||
| } | ||
|
|
||
| function extractErrorCode(error: unknown): string | undefined { | ||
| let text = ""; | ||
| if (error instanceof Error) { | ||
| text = error.message; | ||
| } else if (typeof error === "string") { | ||
| text = error; | ||
| } | ||
| const jsonStart = text.indexOf("{"); | ||
| if (jsonStart === -1) { | ||
| return undefined; | ||
| } | ||
| try { | ||
| const payload = JSON.parse(text.slice(jsonStart)); | ||
| return typeof payload.errorCode === "string" ? payload.errorCode : undefined; | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| } | ||
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,34 @@ | ||
| import Module = require("../../../src/commands/deployment/module"); | ||
| import { testContext } from "../../utls/test-context"; | ||
| import { createMockConfigurator } from "../../utls/configurator-mock"; | ||
|
|
||
| describe("Deployment Module", () => { | ||
| describe("register", () => { | ||
| it("registers the deployment command groups without throwing", () => { | ||
| const mockConfigurator = createMockConfigurator(); | ||
|
|
||
| expect(() => new Module().register(testContext, mockConfigurator)).not.toThrow(); | ||
|
|
||
| expect(mockConfigurator.command).toHaveBeenCalledWith("deployment"); | ||
| expect(mockConfigurator.command).toHaveBeenCalledWith("create"); | ||
| expect(mockConfigurator.command).toHaveBeenCalledWith("list"); | ||
| expect(mockConfigurator.command).toHaveBeenCalledWith("history"); | ||
| expect(mockConfigurator.command).toHaveBeenCalledWith("active"); | ||
| expect(mockConfigurator.command).toHaveBeenCalledWith("deployables"); | ||
| expect(mockConfigurator.command).toHaveBeenCalledWith("targets"); | ||
| }); | ||
|
|
||
| it("wires an action handler for every leaf subcommand", () => { | ||
| const mockConfigurator = createMockConfigurator(); | ||
|
|
||
| new Module().register(testContext, mockConfigurator); | ||
|
|
||
| // create, history, active, deployables, targets | ||
| const expectedLeafCommands = 5; | ||
| expect(mockConfigurator.action).toHaveBeenCalledTimes(expectedLeafCommands); | ||
| for (const call of mockConfigurator.action.mock.calls) { | ||
| expect(typeof call[0]).toBe("function"); | ||
| } | ||
| }); | ||
| }); | ||
| }); |
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,37 @@ | ||
| import { isFeatureDisabledError } from "../../../src/core/feature-flag/feature-disabled-error"; | ||
| import { FatalError } from "../../../src/core/utils/logger"; | ||
|
|
||
| describe("isFeatureDisabledError", () => { | ||
| it("returns true for a backend feature-disabled body", () => { | ||
| expect(isFeatureDisabledError(new Error('{"errorCode":"feature-disabled","feature":"pacman.branching"}'))).toBe(true); | ||
| }); | ||
|
|
||
| it("returns true when the body is wrapped by FatalError (prefixed)", () => { | ||
| expect(isFeatureDisabledError(new FatalError('FatalError: {"errorCode":"feature-disabled"}'))).toBe(true); | ||
| }); | ||
|
|
||
| it("returns true for a raw string payload", () => { | ||
| expect(isFeatureDisabledError('{"errorCode":"feature-disabled"}')).toBe(true); | ||
| }); | ||
|
|
||
| it("returns false for a different backend error code", () => { | ||
| expect(isFeatureDisabledError(new Error('{"errorCode":"optimistic-lock"}'))).toBe(false); | ||
| }); | ||
|
|
||
| it("returns false for a non-JSON error", () => { | ||
| expect(isFeatureDisabledError(new Error("Backend responded with status code 403"))).toBe(false); | ||
| }); | ||
|
|
||
| it("returns false when a brace is present but the payload is not valid JSON", () => { | ||
| expect(isFeatureDisabledError(new Error("something { not valid json"))).toBe(false); | ||
| }); | ||
|
|
||
| it("returns false when errorCode is not a string", () => { | ||
| expect(isFeatureDisabledError(new Error('{"errorCode":123}'))).toBe(false); | ||
| }); | ||
|
|
||
| it("returns false for undefined / non-error input", () => { | ||
| expect(isFeatureDisabledError(undefined)).toBe(false); | ||
| expect(isFeatureDisabledError(42)).toBe(false); | ||
| }); | ||
| }); |
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.
this seems unnecessary. either we return json or we don't?