Repository navigation
fix: custom pages overwrite each other in page sync (all share name "legacy") #85
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
k-r-a-s-s
wants to merge
2
commits into
raisely:master
Choose a base branch
from
k-r-a-s-s:fix/page-sync-filename-collision
base: master
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
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,87 @@ | ||
| import { describe, expect, test } from 'vitest'; | ||
|
|
||
| import { pageFileNames } from '../src/actions/sync.js'; | ||
|
|
||
| describe('pageFileNames', () => { | ||
| test('names template pages by their unique name', () => { | ||
| const pages = [ | ||
| { uuid: 'u1', name: 'home', path: '/' }, | ||
| { uuid: 'u2', name: 'dashboard', path: '/dashboard' }, | ||
| { uuid: 'u3', name: 'profile', path: '/:id' }, | ||
| ]; | ||
| expect(pageFileNames(pages)).toEqual([ | ||
| 'home.json', | ||
| 'dashboard.json', | ||
| 'profile.json', | ||
| ]); | ||
| }); | ||
|
|
||
| test('falls back to path when multiple pages share a name', () => { | ||
| // Custom (page-builder) pages all share the name "legacy" — naming | ||
| // files by name alone collapses them into a single legacy.json. | ||
| const pages = [ | ||
| { uuid: 'u1', name: 'legacy', path: '/cause-areas' }, | ||
| { uuid: 'u2', name: 'legacy', path: '/terms' }, | ||
| { uuid: 'u3', name: 'legacy', path: '/about/team' }, | ||
| { uuid: 'u4', name: 'home', path: '/' }, | ||
| ]; | ||
| expect(pageFileNames(pages)).toEqual([ | ||
| 'cause-areas.json', | ||
| 'terms.json', | ||
| 'about-team.json', | ||
| 'home.json', | ||
| ]); | ||
| }); | ||
|
|
||
| test('keeps name-based file for a name used by only one page', () => { | ||
| const pages = [ | ||
| { uuid: 'u1', name: 'legacy', path: '/only-custom-page' }, | ||
| { uuid: 'u2', name: 'home', path: '/' }, | ||
| ]; | ||
| expect(pageFileNames(pages)).toEqual(['legacy.json', 'home.json']); | ||
| }); | ||
|
|
||
| test('uses path for pages without a name', () => { | ||
| const pages = [ | ||
| { uuid: 'u1', name: null, path: '/register' }, | ||
| { uuid: 'u2', name: null, path: '/signup' }, | ||
| ]; | ||
| expect(pageFileNames(pages)).toEqual(['register.json', 'signup.json']); | ||
| }); | ||
|
|
||
| test('sanitizes special characters in paths', () => { | ||
| const pages = [ | ||
| { uuid: 'u1', name: null, path: '/reset/:passwordResetToken?' }, | ||
| ]; | ||
| expect(pageFileNames(pages)).toEqual([ | ||
| 'reset-_passwordResetToken_.json', | ||
| ]); | ||
| }); | ||
|
|
||
| test('template filenames are reserved regardless of API order', () => { | ||
| // A custom page at the literal path /profile must not take | ||
| // profile.json from the profile template page (path /:id), even | ||
| // when the API returns the custom page first. | ||
| const pages = [ | ||
| { uuid: 'cccccccc-3333', name: 'legacy', path: '/profile' }, | ||
| { uuid: 'dddddddd-4444', name: 'legacy', path: '/terms' }, | ||
| { uuid: 'eeeeeeee-5555', name: 'profile', path: '/:id' }, | ||
| ]; | ||
| expect(pageFileNames(pages)).toEqual([ | ||
| 'profile-cccccccc.json', | ||
| 'terms.json', | ||
| 'profile.json', | ||
| ]); | ||
| }); | ||
|
|
||
| test('disambiguates residual file name collisions with a uuid suffix', () => { | ||
| const pages = [ | ||
| { uuid: 'aaaaaaaa-1111', name: 'legacy', path: '/promo!' }, | ||
| { uuid: 'bbbbbbbb-2222', name: 'legacy', path: '/promo?' }, | ||
| ]; | ||
| expect(pageFileNames(pages)).toEqual([ | ||
| 'promo_.json', | ||
| 'promo_-bbbbbbbb.json', | ||
| ]); | ||
| }); | ||
| }); |
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.
One small follow-up here: could we remove old page files whose UUID we just wrote under a new name, like
legacy.json? Details in the review summary.