-
Notifications
You must be signed in to change notification settings - Fork 0
Generate unique check IDs and detail routes #16
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
7 commits
Select commit
Hold shift + click to select a range
c126fdf
Generate unique check IDs
maquchizi 44d8f99
Update unit tests
maquchizi a61c379
Update E2E tests
maquchizi 299c7b8
Document the new check ID pattern
maquchizi 1b59ca5
Upgrade to ES2024
maquchizi e029b5a
Move to a 64 bit hash for check IDs
maquchizi eced36a
Clean up the details page metadata
maquchizi 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,72 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import type { SiteHistory } from "@/lib/types"; | ||
| import { generateMetadata } from "./page"; | ||
|
|
||
| const { mockConfig, getSiteHistory } = vi.hoisted(() => ({ | ||
| mockConfig: { siteName: "Acme" }, | ||
| getSiteHistory: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/config", () => ({ config: mockConfig })); | ||
| vi.mock("@/lib/synthetics", () => ({ getSiteHistory })); | ||
|
|
||
| function siteWith(job: string, target: string): SiteHistory { | ||
| return { | ||
| check: { id: "the-id", name: job, target, job, instance: target }, | ||
| } as SiteHistory; | ||
| } | ||
|
|
||
| const meta = (id: string) => | ||
| generateMetadata({ params: Promise.resolve({ id }) }); | ||
|
|
||
| beforeEach(() => { | ||
| getSiteHistory.mockReset(); | ||
| }); | ||
|
|
||
| describe("site detail generateMetadata", () => { | ||
| it("combines job and target without the check id", async () => { | ||
| getSiteHistory.mockResolvedValue( | ||
| siteWith("PesaCheck", "https://pesacheck.org"), | ||
| ); | ||
|
|
||
| expect(await meta("pesacheck-abc123")).toEqual({ | ||
| title: "PesaCheck · pesacheck.org · Acme Status", | ||
| }); | ||
| }); | ||
|
|
||
| it("dedupes when job and target are identical", async () => { | ||
| getSiteHistory.mockResolvedValue( | ||
| siteWith("academy.africa", "https://academy.africa"), | ||
| ); | ||
|
|
||
| expect(await meta("academy-africa-abc123")).toEqual({ | ||
| title: "academy.africa · Acme Status", | ||
| }); | ||
| }); | ||
|
|
||
| it("dedupes when job and target only differ by a trailing slash", async () => { | ||
| getSiteHistory.mockResolvedValue( | ||
| siteWith("academy.africa", "https://academy.africa/"), | ||
| ); | ||
|
|
||
| expect(await meta("academy-africa-abc123")).toEqual({ | ||
| title: "academy.africa · Acme Status", | ||
| }); | ||
| }); | ||
|
|
||
| it("falls back to the id when the check is not found", async () => { | ||
| getSiteHistory.mockResolvedValue(null); | ||
|
|
||
| expect(await meta("unknown-id")).toEqual({ | ||
| title: "unknown-id · Acme Status", | ||
| }); | ||
| }); | ||
|
|
||
| it("falls back to the id when the lookup throws", async () => { | ||
| getSiteHistory.mockRejectedValue(new Error("boom")); | ||
|
|
||
| expect(await meta("some-id")).toEqual({ | ||
| title: "some-id · Acme Status", | ||
| }); | ||
| }); | ||
| }); |
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
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
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.
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.
When an installation has many checks sharing the same job slug (for example one job name monitoring many targets) or a crafted pair of targets, this 32-bit FNV suffix can collide, producing duplicate
/site/<id>links and React keys;getSiteHistory()then resolves the first matching check, leaving the other target without an addressable detail page. Use a longer/collision-resistant digest or include an encoded target component so the public ID is actually unique for the(job, target)pair.Useful? React with 👍 / 👎.
Uh oh!
There was an error while loading. Please reload this page.
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.
While the chance of a collision at 32-bit is "highly unlikely", moving to 64 bit makes it "practically impossible" at the cost of a longer (uglier?) hash. I think that's a fair trade off so I've made the change.