-
Notifications
You must be signed in to change notification settings - Fork 0
test: cover recoverable session-load errors and run-id branding #275
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { describe, it, expect } from '@jest/globals'; | ||
| import { RUN_ID_PATTERN, RUN_ID_PREFIX, assertRunId, isRunId } from '../../src/runbook/run-id.js'; | ||
|
|
||
| describe('isRunId', () => { | ||
| it('accepts canonical rd_ + 32 lowercase hex chars', () => { | ||
| expect(isRunId('rd_4b7f0c2d9e1a4b7f0c2d9e1a4b7f0c2d')).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts all-zero hex segment', () => { | ||
| expect(isRunId('rd_00000000000000000000000000000000')).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts all-f hex segment', () => { | ||
| expect(isRunId('rd_ffffffffffffffffffffffffffffffff')).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects uppercase hex characters', () => { | ||
| expect(isRunId('rd_ABCDEF00000000000000000000000000')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects uppercase RD_ prefix', () => { | ||
| expect(isRunId('RD_00000000000000000000000000000000')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects missing prefix', () => { | ||
| expect(isRunId('00000000000000000000000000000000')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects 31-char hex segment', () => { | ||
| expect(isRunId('rd_0000000000000000000000000000000')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects 33-char hex segment', () => { | ||
| expect(isRunId('rd_000000000000000000000000000000000')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects non-hex character in segment', () => { | ||
| expect(isRunId('rd_g0000000000000000000000000000000')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects hyphenated UUID-style body', () => { | ||
| expect(isRunId('rd_550e8400-e29b-41d4-a716-446655440000')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects empty string', () => { | ||
| expect(isRunId('')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects bare prefix with no body', () => { | ||
| expect(isRunId('rd_')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects legacy wf-YYYY-MM-DD-... format', () => { | ||
| expect(isRunId('wf-2024-01-07-abc123')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects non-string values', () => { | ||
| expect(isRunId(undefined)).toBe(false); | ||
| expect(isRunId(null)).toBe(false); | ||
| expect(isRunId(123)).toBe(false); | ||
| expect(isRunId({})).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('assertRunId', () => { | ||
| it('returns the input when valid', () => { | ||
| const raw = 'rd_4b7f0c2d9e1a4b7f0c2d9e1a4b7f0c2d'; | ||
| expect(assertRunId(raw)).toBe(raw); | ||
| }); | ||
|
|
||
| it('throws on invalid id with a message naming the expected format', () => { | ||
| expect(() => assertRunId('not-a-run-id')).toThrow(/rd_/); | ||
| }); | ||
|
|
||
| it('throws on uppercase hex', () => { | ||
| expect(() => assertRunId('rd_ABCDEF00000000000000000000000000')).toThrow(); | ||
| }); | ||
|
|
||
| it('throws on empty string', () => { | ||
| expect(() => assertRunId('')).toThrow(); | ||
| }); | ||
|
|
||
| it('throws on bare prefix', () => { | ||
| expect(() => assertRunId('rd_')).toThrow(); | ||
| }); | ||
|
|
||
| it('is idempotent for valid ids', () => { | ||
| const raw = 'rd_22222222222222222222222222222222'; | ||
| expect(assertRunId(assertRunId(raw))).toBe(raw); | ||
| }); | ||
| }); | ||
|
|
||
| describe('RUN_ID_PATTERN / RUN_ID_PREFIX', () => { | ||
| it('exports the rd_ prefix constant', () => { | ||
| expect(RUN_ID_PREFIX).toBe('rd_'); | ||
| }); | ||
|
|
||
| it('exposes a pattern that anchors both ends', () => { | ||
| expect(RUN_ID_PATTERN.source.startsWith('^')).toBe(true); | ||
| expect(RUN_ID_PATTERN.source.endsWith('$')).toBe(true); | ||
| }); | ||
|
|
||
| it('matches values accepted by isRunId', () => { | ||
| const id = 'rd_11111111111111111111111111111111'; | ||
| expect(RUN_ID_PATTERN.test(id)).toBe(true); | ||
| expect(isRunId(id)).toBe(true); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['missing rd_ prefix', '00000000000000000000000000000000'], | ||
| ['uppercase hex', 'rd_ABCDEF00000000000000000000000000'], | ||
| ['31-char body (too short)', 'rd_0000000000000000000000000000000'], | ||
| ['33-char body (too long)', 'rd_000000000000000000000000000000000'], | ||
| ['non-hex character in body', 'rd_g0000000000000000000000000000000'], | ||
| ['hyphenated UUID body', 'rd_550e8400-e29b-41d4-a716-446655440000'], | ||
| ])('rejects %s in both RUN_ID_PATTERN and isRunId', (_label, value) => { | ||
| expect(RUN_ID_PATTERN.test(value)).toBe(false); | ||
| expect(isRunId(value)).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.
Uh oh!
There was an error while loading. Please reload this page.