-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(webapp): accept all valid run and batch IDs in dashboard filters #4152
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
4 commits
Select commit
Hold shift + click to select a range
b17ef59
fix(webapp): accept all valid run and batch IDs in dashboard filters
d-cs 31f453e
Merge branch 'main' into fix/ksuid-id-filter-validation
d-cs 9a00d4f
refactor(webapp): consolidate id filter validators into a tested helper
d-cs 3bfc9dd
docs(webapp): note why error id filter skips the shared validator
d-cs 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,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: fix | ||
| --- | ||
|
|
||
| The Run ID and Batch ID filters on the runs, batches, and logs pages now accept every valid ID format, fixing a case where valid IDs were rejected and the Apply button stayed disabled. |
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
|
d-cs marked this conversation as resolved.
|
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,85 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| BatchId, | ||
| generateFriendlyId, | ||
| generateKsuidId, | ||
| RunId, | ||
| } from "@trigger.dev/core/v3/isomorphic"; | ||
| import { isValidFriendlyId, makeFriendlyIdValidator } from "./friendlyId"; | ||
|
|
||
| describe("isValidFriendlyId", () => { | ||
| it("accepts every id generation the real generators produce", () => { | ||
| // nanoid (legacy V1), cuid (run-engine), ksuid (run-ops split) | ||
| expect(isValidFriendlyId(generateFriendlyId("run"), "run")).toBe(true); | ||
| expect(isValidFriendlyId(RunId.generate().friendlyId, "run")).toBe(true); | ||
| expect(isValidFriendlyId(RunId.toFriendlyId(generateKsuidId()), "run")).toBe(true); | ||
|
|
||
| expect(isValidFriendlyId(generateFriendlyId("batch"), "batch")).toBe(true); | ||
| expect(isValidFriendlyId(BatchId.generate().friendlyId, "batch")).toBe(true); | ||
| expect(isValidFriendlyId(BatchId.toFriendlyId(generateKsuidId()), "batch")).toBe(true); | ||
| }); | ||
|
|
||
| it("accepts each valid body length (21 nanoid, 25 cuid, 27 ksuid)", () => { | ||
| expect(isValidFriendlyId("run_" + "a".repeat(21), "run")).toBe(true); | ||
| expect(isValidFriendlyId("run_" + "a".repeat(25), "run")).toBe(true); | ||
| expect(isValidFriendlyId("run_" + "a".repeat(27), "run")).toBe(true); | ||
| }); | ||
|
|
||
| it("accepts mixed-case (uppercase) ksuid bodies", () => { | ||
| expect(isValidFriendlyId("run_2ABCdefGHI0123456789jklMN", "run")).toBe(true); | ||
| }); | ||
|
|
||
| it("rejects the wrong prefix", () => { | ||
| expect(isValidFriendlyId(RunId.generate().friendlyId, "batch")).toBe(false); | ||
| expect(isValidFriendlyId("batch_" + "a".repeat(25), "run")).toBe(false); | ||
| }); | ||
|
|
||
| it("rejects a bare (unprefixed) id", () => { | ||
| expect(isValidFriendlyId("a".repeat(25), "run")).toBe(false); | ||
| }); | ||
|
|
||
| it("rejects body lengths that match no generator", () => { | ||
| for (const len of [0, 20, 22, 24, 26, 28]) { | ||
| expect(isValidFriendlyId("run_" + "a".repeat(len), "run")).toBe(false); | ||
| } | ||
| }); | ||
|
|
||
| it("rejects non-base62 characters in the body", () => { | ||
| expect(isValidFriendlyId("run_" + "-".repeat(25), "run")).toBe(false); | ||
| expect(isValidFriendlyId("run_" + "!".repeat(25), "run")).toBe(false); | ||
| // an underscore in the body is not base62 | ||
| expect(isValidFriendlyId("run_" + "a".repeat(24) + "_", "run")).toBe(false); | ||
| }); | ||
|
|
||
| it("does not treat the prefix separator as optional", () => { | ||
| // "runX..." shares the "run" prefix but not the "run_" marker | ||
| expect(isValidFriendlyId("run" + "a".repeat(25), "run")).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("makeFriendlyIdValidator", () => { | ||
| const validateRunId = makeFriendlyIdValidator("run", "Run"); | ||
| const validateBatchId = makeFriendlyIdValidator("batch", "Batch"); | ||
|
|
||
| it("returns undefined for a valid id of any generation", () => { | ||
| expect(validateRunId(generateFriendlyId("run"))).toBeUndefined(); | ||
| expect(validateRunId(RunId.generate().friendlyId)).toBeUndefined(); | ||
| expect(validateRunId(RunId.toFriendlyId(generateKsuidId()))).toBeUndefined(); | ||
| expect(validateBatchId(BatchId.toFriendlyId(generateKsuidId()))).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("reports a wrong prefix distinctly from a wrong shape", () => { | ||
| expect(validateRunId("batch_" + "a".repeat(25))).toBe("Run IDs start with 'run_'"); | ||
| expect(validateRunId("run_" + "a".repeat(20))).toBe("That doesn't look like a valid run ID"); | ||
| }); | ||
|
|
||
| it("derives the marker and label per entity", () => { | ||
| const validateWaitpointId = makeFriendlyIdValidator("waitpoint", "Waitpoint"); | ||
| expect(validateWaitpointId("run_" + "a".repeat(25))).toBe( | ||
| "Waitpoint IDs start with 'waitpoint_'" | ||
| ); | ||
| expect(validateWaitpointId("waitpoint_" + "a".repeat(20))).toBe( | ||
| "That doesn't look like a valid waitpoint ID" | ||
| ); | ||
| }); | ||
| }); |
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,31 @@ | ||
| import { CUID_LENGTH, KSUID_LENGTH } from "@trigger.dev/core/v3/isomorphic"; | ||
|
|
||
| // The body after `<prefix>_` is a base62 id; three generator lengths remain | ||
| // valid in existing data and must all be accepted: 21 (nanoid), 25 (cuid), | ||
| // 27 (ksuid). cuid/ksuid come from core so this tracks any future change. | ||
| const NANOID_BODY_LENGTH = 21; | ||
| const VALID_BODY_LENGTHS: ReadonlySet<number> = new Set([ | ||
| NANOID_BODY_LENGTH, | ||
| CUID_LENGTH, | ||
| KSUID_LENGTH, | ||
| ]); | ||
|
|
||
| const BASE62 = /^[0-9A-Za-z]+$/; | ||
|
|
||
| export function isValidFriendlyId(value: string, prefix: string): boolean { | ||
| const marker = `${prefix}_`; | ||
| if (!value.startsWith(marker)) return false; | ||
| const body = value.slice(marker.length); | ||
| return VALID_BODY_LENGTHS.has(body.length) && BASE62.test(body); | ||
| } | ||
|
|
||
| export function makeFriendlyIdValidator(prefix: string, label: string) { | ||
| const marker = `${prefix}_`; | ||
| return (value: string): string | undefined => { | ||
| if (!value.startsWith(marker)) return `${label} IDs start with '${marker}'`; | ||
| if (!isValidFriendlyId(value, prefix)) { | ||
| return `That doesn't look like a valid ${label.toLowerCase()} ID`; | ||
| } | ||
| 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
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.