-
Notifications
You must be signed in to change notification settings - Fork 0
fix(viewer): preserve product-owned design baselines #535
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
57659e9
fix(viewer): preserve product-owned design baselines
monkey1sai 7c1fc90
fix(viewer): verify preserved design baselines
monkey1sai a768464
test(design): guard production rebaseline ordering
monkey1sai 66f302e
Merge branch 'main' into fix/design-reference-provenance-guard
monkey1sai-blip 0789ca9
Merge branch 'main' into fix/design-reference-provenance-guard
monkey1sai-blip d38aa7b
Merge branch 'main' into fix/design-reference-provenance-guard
monkey1sai 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
85 changes: 85 additions & 0 deletions
85
web-viewer-sample/scripts/design-system-rebaseline-authority.mjs
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 @@ | ||
| const AUTHORING_ORIGIN = "authoring_origin"; | ||
| const CANONICAL_PRODUCT_SURFACE = "canonical_product_surface"; | ||
|
|
||
| /** | ||
| * Select only screens whose baseline authority is the approved authoring | ||
| * origin. Legacy screens without a provenance object retain that authority; | ||
| * once provenance is explicit, an unknown or missing authority fails closed. | ||
| */ | ||
| export function planOriginRebaseline(screens) { | ||
| const captureScreens = []; | ||
| const preservedScreens = []; | ||
|
|
||
| for (const screen of screens) { | ||
| if (!Object.hasOwn(screen, "baseline_provenance")) { | ||
| captureScreens.push(screen); | ||
| continue; | ||
| } | ||
|
|
||
| const authority = screen.baseline_provenance?.authority; | ||
| if (authority === AUTHORING_ORIGIN) { | ||
| captureScreens.push(screen); | ||
| continue; | ||
| } | ||
| if (authority === CANONICAL_PRODUCT_SURFACE) { | ||
| preservedScreens.push(screen); | ||
| continue; | ||
| } | ||
|
|
||
| const authorityLabel = | ||
| typeof authority === "string" && authority.length > 0 | ||
| ? authority | ||
| : "missing"; | ||
| throw new Error( | ||
| `Unsupported baseline provenance authority '${authorityLabel}' for ${screen.id}.`, | ||
| ); | ||
| } | ||
|
|
||
| return { captureScreens, preservedScreens }; | ||
| } | ||
|
|
||
| /** | ||
| * Fail closed when a baseline excluded from origin re-capture no longer | ||
| * matches the digest pinned by its owning product surface. | ||
| */ | ||
| export async function verifyPreservedBaselineIntegrity( | ||
| preservedScreens, | ||
| viewportIds, | ||
| readDigest, | ||
| ) { | ||
| for (const screen of preservedScreens) { | ||
| for (const viewportId of viewportIds) { | ||
| const baseline = screen.baselines?.[viewportId]; | ||
| if (!baseline) { | ||
| throw new Error( | ||
| `Missing ${viewportId} preserved baseline slot for ${screen.id}.`, | ||
| ); | ||
| } | ||
| const digest = await readDigest(baseline.path); | ||
| if (digest !== baseline.sha256) { | ||
| throw new Error(`Preserved baseline hash mismatch: ${baseline.path}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Keep the integrity preflight and both write phases on one testable path. | ||
| * A rejected preflight must prevent both screenshot and manifest writes. | ||
| */ | ||
| export async function runGuardedOriginRebaseline({ | ||
| preservedScreens, | ||
| viewportIds, | ||
| readDigest, | ||
| captureBaselines, | ||
| commitManifest, | ||
| }) { | ||
| await verifyPreservedBaselineIntegrity( | ||
| preservedScreens, | ||
| viewportIds, | ||
| readDigest, | ||
| ); | ||
| const captureResult = await captureBaselines(); | ||
| await commitManifest(); | ||
| return captureResult; | ||
| } |
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.