Core source-media policy module: availability, tri-state, duration, failure tiers (source-media issue 06) - #17
Merged
Conversation
…ailure tiers (source-media issue 06) Pure core module owning every source-media decision a formula could get wrong; scene/ui hand it plain facts (the document + a SourceMediaFacts projection of the ephemeral media record) and obey. Decides video-export availability (Animation OR decodable video; an undecodable bound video blocks with a codec reason even alongside an Animation), the decodable / preview-only / rejected import tri-state, export duration (Animation duration, else video duration clamped to the 30 s cap), and the failure-tier mapping for the toast UX. Behavior-level tests red-to-green; existing export math untouched.
Review follow-up: the 30 s cap and the Animation duration clamp are the same ceiling and must not drift apart, so the constant now references the limit instead of repeating the literal.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What & why
Implements source-media issue 06 (
.scratch/source-media/issues/06-core-source-media-policy.md): a purecore/policy module (src/core/source-media.ts) owning every source-media decision a formula could get wrong, so the scene/ui layers hand it plain facts and obey. The mediabunny /canDecode()plumbing stays in scene/ui; this module only consumes their results as plain data.It decides:
resolveVideoExportAvailability(document, facts): available when the document has an Animation OR the bound Source Media is a decodable video (supersedes "requires an Animation"). Unavailability carries a reason (nothing-to-exportvsundecodable-video) so issue 08 can render the disabled state vs the persistent codec notice. Deliberate ambiguity resolution (recorded in the PRD + ticket): a bound playable-but-undecodable video blocks video export even alongside an Animation — the deterministic export loop cannot decode its frames.classifySourceVideoImport: decodable / preview-only / rejected from the probe's playable/decodable facts.resolveVideoExportDuration: Animation duration when one exists (video truncates); else the video duration clamped toVIDEO_EXPORT_DURATION_CAP(derived fromANIMATION_DURATION_LIMIT.max), guarding non-finite durations to the cap and non-positive to 0.resolveSourceMediaFailureTier: reject-at-import / preview-only-notice / abort-export.Unblocks issues 07 (deterministic video export) and 08 (availability + no-Animation export).
Checklist
pnpm typecheck && pnpm lint && pnpm test && pnpm buildgreen locallycore/behavior covered by behavior-level Vitest tests (24 tests, red→green: availability truth table, tri-state, 30 s clamp + frame-count consequences, failure tiers)scene//ui/changes verified in the browser (screenshot below) — n/a, core-only sliceCONTEXT.mdvocabulary in names and typescore/stays free of react/three imports (ESLint boundary)Evidence
Core-only, no visual change.
src/core/source-media.test.ts: 24 passing behavior-level tests; full suite 467 green.Note
Low Risk
Core-only pure functions and tests; no runtime or UI integration yet, so production behavior is unchanged until follow-up issues wire it in.
Overview
Adds a pure
core/source-mediapolicy layer so scene/UI can pass probe/facts and follow fixed rules for video export and import UX.Video export availability (
resolveVideoExportAvailability) now allows export when there is an Animation or a decodable bound video (replacing the old “requires an Animation” rule). Undecodable-but-playable video blocks export even with an Animation, with reasonundecodable-videovsnothing-to-exportfor the export panel.Import gets tri-state
classifySourceVideoImport(decodable / preview-only / rejected) from playable+decodable probes; export length usesresolveVideoExportDuration(animation duration wins; otherwise video duration clamped toVIDEO_EXPORT_DURATION_CAP, tied toANIMATION_DURATION_LIMIT.max).resolveSourceMediaFailureTiermaps import/export failures to toast tiers (reject, preview-only notice, abort export).New types and helpers are re-exported from
core/index. Behavior is covered bysource-media.test.ts(availability table, classification, duration edge cases, failure tiers).Reviewed by Cursor Bugbot for commit 9cd3642. Bugbot is set up for automated code reviews on this repo. Configure here.