-
Notifications
You must be signed in to change notification settings - Fork 123
BE-565: Disallow zero ontology type versions #9891
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5769701
Disallow zero ontology type versions
montekki 5fc0624
Test ontology version bounds and update overflow
montekki c2d12a1
Handle invalid ontology versions in type routes
montekki 476a21e
Add typed ontology major version arithmetic
montekki 6e8c2d9
Add PostgreSQL conversions for ontology major versions
montekki c3bfe13
Update libs/@local/graph/api/src/rest/legacy/utoipa_typedef/subgraph/β¦
montekki 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,5 @@ | ||
| --- | ||
| "@blockprotocol/type-system": patch | ||
| --- | ||
|
|
||
| Reject zero major versions in versioned URLs. Require ontology version constructors to receive integers between 1 and 4294967295. |
63 changes: 63 additions & 0 deletions
63
...sh-frontend/src/pages/@/[shortname]/types/data-type/[...slug-maybe-version].page.test.tsx
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,63 @@ | ||
| import { renderToStaticMarkup } from "react-dom/server"; | ||
| import { describe, expect, test, vi } from "vitest"; | ||
|
|
||
| import Page from "./[...slug-maybe-version].page"; | ||
|
|
||
| const router = vi.hoisted(() => ({ | ||
| query: {} as Record<string, string[]>, | ||
| asPath: "", | ||
| })); | ||
|
|
||
| vi.mock("next/router", () => ({ useRouter: () => router })); | ||
| vi.mock("../../../../../shared/layout", () => ({ | ||
| getLayoutWithSidebar: () => null, | ||
| })); | ||
| vi.mock("../../../../shared/not-found", () => ({ | ||
| NotFound: () => "not found", | ||
| })); | ||
| vi.mock("../../../../shared/data-type", () => ({ | ||
| DataType: ({ requestedVersion }: { requestedVersion: string | null }) => | ||
| requestedVersion ?? "latest", | ||
| })); | ||
| vi.mock("../../../../../shared/generate-link-parameters", () => ({ | ||
| generateLinkParameters: () => ({ href: "/" }), | ||
| })); | ||
| vi.mock("../../shared/use-route-namespace", () => ({ | ||
| useRouteNamespace: () => ({ | ||
| loading: false, | ||
| routeNamespace: { webId: "alice" }, | ||
| }), | ||
| })); | ||
| vi.mock("../shared/get-type-base-url", () => ({ | ||
| getTypeBaseUrl: () => "http://example.com/types/data-type/test/", | ||
| })); | ||
|
|
||
| const renderVersion = (version?: string) => { | ||
| router.asPath = `/@alice/types/data-type/test${version === undefined ? "" : `/v/${version}`}`; | ||
| return renderToStaticMarkup(<Page />); | ||
| }; | ||
|
|
||
| describe("data type route versions", () => { | ||
| test.each(["0", "4294967296", "-1", "1.5", "invalid", "1invalid"])( | ||
| "renders not found for version %s", | ||
| (version) => { | ||
| expect(renderVersion(version)).toBe("not found"); | ||
| }, | ||
| ); | ||
|
|
||
| test.each(["1", "4294967295"])("renders version %s", (version) => { | ||
| expect(renderVersion(version)).toContain(version); | ||
| }); | ||
|
|
||
| test.each(["1?tab=definition", "1#definition"])( | ||
| "renders a valid version with a query or fragment: %s", | ||
| (version) => { | ||
| expect(renderVersion(version)).toContain("1"); | ||
| expect(renderVersion(version)).not.toContain("not found"); | ||
| }, | ||
| ); | ||
|
|
||
| test("renders the latest version when no version is requested", () => { | ||
| expect(renderVersion()).toContain("latest"); | ||
| }); | ||
| }); |
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
117 changes: 117 additions & 0 deletions
117
apps/hash-frontend/src/pages/shared/entity-type-page/edit-bar-type-editor.test.tsx
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,117 @@ | ||
| import { renderToStaticMarkup } from "react-dom/server"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { makeOntologyTypeVersion } from "@blockprotocol/type-system"; | ||
|
|
||
| import { EditBarTypeEditor } from "./edit-bar-type-editor"; | ||
|
|
||
| import type { ReactNode } from "react"; | ||
|
|
||
| const formState = vi.hoisted(() => ({ | ||
| dirtyFields: {} as Record<string, boolean>, | ||
| isSubmitting: false, | ||
| })); | ||
|
|
||
| const confirmButton = vi.hoisted(() => ({ disabled: false })); | ||
|
|
||
| vi.mock("@hashintel/type-editor", () => ({ | ||
| useEntityTypeFormState: () => formState, | ||
| })); | ||
|
|
||
| vi.mock("@hashintel/design-system", () => ({ | ||
| FontAwesomeIcon: () => null, | ||
| })); | ||
|
|
||
| vi.mock("../../../shared/icons/svg", () => ({ | ||
| PencilSimpleLine: () => null, | ||
| })); | ||
|
|
||
| vi.mock("../shared/edit-bar-contents", () => ({ | ||
| EditBarCollapse: ({ | ||
| children, | ||
| in: visible, | ||
| }: { | ||
| children: ReactNode; | ||
| in: boolean; | ||
| }) => (visible ? children : null), | ||
| EditBarContainer: ({ children }: { children: ReactNode }) => children, | ||
| EditBarContents: ({ | ||
| label, | ||
| confirmButtonProps, | ||
| discardButtonProps, | ||
| }: { | ||
| label: string; | ||
| confirmButtonProps: { children: ReactNode; disabled: boolean }; | ||
| discardButtonProps: { children: ReactNode }; | ||
| }) => { | ||
| confirmButton.disabled = confirmButtonProps.disabled; | ||
| return ( | ||
| <> | ||
| {label} {confirmButtonProps.children} {discardButtonProps.children} | ||
| </> | ||
| ); | ||
| }, | ||
| useFreezeScrollWhileTransitioning: () => null, | ||
| })); | ||
|
|
||
| const renderEditor = (isDraft: boolean, major = 1) => | ||
| renderToStaticMarkup( | ||
| <EditBarTypeEditor | ||
| currentVersion={makeOntologyTypeVersion({ major })} | ||
| isDraft={isDraft} | ||
| gentleErrorStyling={false} | ||
| discardButtonProps={{}} | ||
| />, | ||
| ); | ||
|
|
||
| describe("EditBarTypeEditor", () => { | ||
| beforeEach(() => { | ||
| formState.dirtyFields = {}; | ||
| confirmButton.disabled = false; | ||
| }); | ||
|
|
||
| it("shows creation actions for a pristine draft at version one", () => { | ||
| const markup = renderEditor(true); | ||
|
|
||
| expect(markup).toContain("this type has not yet been created"); | ||
| expect(markup).toContain("Create"); | ||
| expect(markup).toContain("Discard this type"); | ||
| }); | ||
|
|
||
| it("shows update actions for an edited existing type at version one", () => { | ||
| formState.dirtyFields = { title: true }; | ||
|
|
||
| const markup = renderEditor(false); | ||
|
|
||
| expect(markup).toContain("Version 1 -> 2"); | ||
| expect(markup).toContain("Publish update"); | ||
| expect(markup).toContain("Discard changes"); | ||
| expect(markup).not.toContain("this type has not yet been created"); | ||
| }); | ||
|
|
||
| it("hides the edit bar for a pristine existing type", () => { | ||
| expect(renderEditor(false)).toBe(""); | ||
| }); | ||
|
|
||
| it("renders a pristine existing type at the maximum version", () => { | ||
| expect(renderEditor(false, 4_294_967_295)).toBe(""); | ||
| }); | ||
|
|
||
| it("disables publishing an update at the maximum version", () => { | ||
| formState.dirtyFields = { title: true }; | ||
|
|
||
| expect(renderEditor(false, 4_294_967_295)).toContain( | ||
| "this type has reached the maximum version and cannot be updated", | ||
| ); | ||
| expect(confirmButton.disabled).toBe(true); | ||
| }); | ||
|
|
||
| it("allows publishing the last available version", () => { | ||
| formState.dirtyFields = { title: true }; | ||
|
|
||
| expect(renderEditor(false, 4_294_967_294)).toContain( | ||
| "Version 4294967294 -> 4294967295", | ||
| ); | ||
| expect(confirmButton.disabled).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.