Skip to content

refactor(export): add lightning route policy plan#554

Merged
meiiie merged 2 commits into
mainfrom
refactor/export-route-policy
May 22, 2026
Merged

refactor(export): add lightning route policy plan#554
meiiie merged 2 commits into
mainfrom
refactor/export-route-policy

Conversation

@meiiie
Copy link
Copy Markdown
Collaborator

@meiiie meiiie commented May 22, 2026

Summary

  • Add a structured Lightning export route plan in backendPolicy.
  • Model native static layout, Breeze streaming, and WebCodecs as explicit route decisions with selected/fallback/rejected states.
  • Add tests for Windows auto selecting native static layout first, plus Breeze fallback when native static layout is rejected.

Why

This is a small architecture slice from the broader #504 work. It establishes the route policy as pure TypeScript before wiring it into ModernVideoExporter, so the next PR can change execution flow against a tested policy contract instead of mixing policy, runtime behavior, and native helper changes in one broad diff.

Validation

  • npm test -- src/lib/exporter/backendPolicy.test.ts (5 passed)
  • npx tsc --noEmit
  • npx biome check --formatter-enabled=false src/lib/exporter/backendPolicy.ts src/lib/exporter/backendPolicy.test.ts
  • git diff --check

Note: full formatter-enabled Biome on Windows wants to normalize existing CRLF line endings in these files, so I used formatter-disabled scoped Biome to avoid unrelated line-ending churn.

Summary by CodeRabbit

  • New Features

    • Added an intelligent export-route planner that orders and selects export backends based on platform and user preference, and records per-route selection, fallback or rejection with documented reasons.
  • Tests

    • Expanded unit tests covering platform-specific preference ordering (Windows vs mac), auto and explicit selections, fallback behavior, and propagation of rejection/fallback reason codes.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

Adds platform-aware export-route planning types and functions and extensive tests verifying route selection, fallback ordering, and propagation of rejection/fallback reason codes for native-static, breeze-stream, and webcodecs.

Changes

Backend Route Planning

Layer / File(s) Summary
Route Planning Types and Implementation
src/lib/exporter/backendPolicy.ts
Adds LightningExportRoute, LightningExportRouteDecision, and LightningExportRoutePlan. Implements shouldPreferNativeStaticLayoutBeforeBreeze and planLightningExportRoutes, and updates imports to include ExportBackendPreference.
Route Planning Tests
src/lib/exporter/backendPolicy.test.ts
Expands tests to import the new helpers and validate: Windows vs macOS preference behavior; auto selection when native static is available; auto fallback when native static is rejected with skip reasons and propagation of those reasons; explicit breeze selection cases (native-static attempted/rejected then breeze-stream selected) including unavailable vs skip-reason scenarios; and full decision ordering including webcodecs fallback reasons.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant planLightningExportRoutes
  participant shouldPreferNativeStaticLayoutBeforeBreeze
  Caller->>planLightningExportRoutes: options { backendPreference, platform, nativeStaticLayoutAvailable, nativeStaticLayoutSkipReasons? }
  planLightningExportRoutes->>shouldPreferNativeStaticLayoutBeforeBreeze: (platform, backendPreference)
  shouldPreferNativeStaticLayoutBeforeBreeze-->>planLightningExportRoutes: boolean
  planLightningExportRoutes->>planLightningExportRoutes: build ordered decisions (native-static-layout → breeze-stream → webcodecs)
  planLightningExportRoutes-->>Caller: LightningExportRoutePlan { selectedRoute, decisions[] }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop, a plan, three routes to try,
Native first on Windows—give it a try,
Breeze next if native declines the race,
WebCodecs waits as the fallback place,
Reasons logged, decisions in their space.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor(export): add lightning route policy plan' accurately describes the main change: adding a new structured route policy plan for Lightning exports.
Description check ✅ Passed The PR description covers the main objectives and validation, but does not follow the repository's template structure with all required sections (Type of Change checkbox, formal Testing Guide section).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/export-route-policy

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/lib/exporter/backendPolicy.ts (1)

109-121: ⚡ Quick win

Consider documenting native static layout decision for consistency.

The preferStaticFirst path (lines 87-107) documents all three routes in the decisions array, but this path only documents breeze-stream and webcodecs. This creates an inconsistent decision structure—consumers of the plan might expect a consistent three-route breakdown across all scenarios.

If native static layout is never considered for darwin auto mode, consider adding a rejected decision with a reason like "platform-does-not-use-native-static-layout" to maintain structural consistency.

📋 Proposed addition for consistent decision documentation
 if (options.backendPreference === "auto" && shouldPreferNativeAutoBackend(options.platform)) {
+	decisions.push({
+		route: "native-static-layout",
+		status: "rejected",
+		reasons: ["platform-does-not-use-native-static-layout"],
+	});
 	decisions.push({
 		route: "breeze-stream",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/exporter/backendPolicy.ts` around lines 109 - 121, The decisions
array for the auto/darwin path (inside the block that checks
options.backendPreference === "auto" &&
shouldPreferNativeAutoBackend(options.platform)) only pushes breeze-stream and
webcodecs entries, creating an inconsistent decision structure vs. the
preferStaticFirst path; add a third decision for the native static route (use
the same route identifier used elsewhere, e.g., "native-static" or
"static-layout") with status "rejected" and reason
"platform-does-not-use-native-static-layout" so the decisions array always
contains a three-route breakdown while leaving selectedRoute as "breeze-stream".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/exporter/backendPolicy.ts`:
- Around line 83-107: Add unit tests in src/lib/exporter/backendPolicy.test.ts
covering the branch where options.backendPreference === "breeze" for
planLightningExportRoutes: create tests for (1) nativeStaticLayoutAvailable:
true (expect selectedRoute "native-static-layout", breeze-stream status
"fallback" with reason "user-selected-breeze"), (2) nativeStaticLayoutAvailable:
false (expect selectedRoute "breeze-stream" selected and webcodecs fallback),
and (3) a case with nativeStaticLayoutSkipReasons non-empty to ensure
addNativeStaticLayoutDecision records a rejection and decisions include the
appropriate skip reason; use the same helper/setup used by existing "auto" tests
and assert decisions array and selectedRoute match the semantics in
backendPolicy.ts.

---

Nitpick comments:
In `@src/lib/exporter/backendPolicy.ts`:
- Around line 109-121: The decisions array for the auto/darwin path (inside the
block that checks options.backendPreference === "auto" &&
shouldPreferNativeAutoBackend(options.platform)) only pushes breeze-stream and
webcodecs entries, creating an inconsistent decision structure vs. the
preferStaticFirst path; add a third decision for the native static route (use
the same route identifier used elsewhere, e.g., "native-static" or
"static-layout") with status "rejected" and reason
"platform-does-not-use-native-static-layout" so the decisions array always
contains a three-route breakdown while leaving selectedRoute as "breeze-stream".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4b9c841a-ca7d-4c0d-916c-8807947dab1c

📥 Commits

Reviewing files that changed from the base of the PR and between 9f896ec and c87acf4.

📒 Files selected for processing (2)
  • src/lib/exporter/backendPolicy.test.ts
  • src/lib/exporter/backendPolicy.ts

Comment thread src/lib/exporter/backendPolicy.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/exporter/backendPolicy.ts (1)

83-107: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Clarify the semantics of backendPreference: "breeze" selecting native-static-layout.

When a user sets backendPreference: "breeze", the current implementation tries native-static-layout first (line 88) and only falls back to breeze-stream if native-static is unavailable. This means explicitly selecting "breeze" can result in selectedRoute: "native-static-layout", with breeze-stream marked as "fallback" carrying reason "user-selected-breeze".

This behavior is counterintuitive—users selecting "breeze" likely expect breeze-stream to be used. While the tests confirm this is intentional, the code lacks documentation explaining why "breeze" preference prioritizes native-static-layout over breeze-stream.

Consider adding a comment explaining the design intent (e.g., if "breeze" means "native-like pipeline" encompassing both routes), or reconsider whether the preference should be renamed to better reflect its behavior.

📝 Suggested documentation addition
 const preferStaticFirst =
+  // Note: "breeze" preference prioritizes native-static-layout over breeze-stream
+  // when visually compatible, as both are part of the native/Breeze pipeline.
   options.backendPreference === "breeze" ||
   shouldPreferNativeStaticLayoutBeforeBreeze(options.platform, options.backendPreference);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/exporter/backendPolicy.ts` around lines 83 - 107, The code treats
backendPreference === "breeze" as preferring native-static-first which can yield
selectedRoute "native-static-layout" and mark "breeze-stream" as fallback; add a
clear explanatory comment immediately above the preferStaticFirst block (near
the preferStaticFirst variable, addNativeStaticLayoutDecision call, and the
selectedRoute/decisions logic) describing the design intent: that "breeze" is
interpreted as a native-like pipeline which prefers native-static-layout when
available and only falls back to breeze-stream (and why the fallback reason uses
"user-selected-breeze"), so future readers/tests understand this intentional
behavior rather than assuming a bug.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/lib/exporter/backendPolicy.ts`:
- Around line 83-107: The code treats backendPreference === "breeze" as
preferring native-static-first which can yield selectedRoute
"native-static-layout" and mark "breeze-stream" as fallback; add a clear
explanatory comment immediately above the preferStaticFirst block (near the
preferStaticFirst variable, addNativeStaticLayoutDecision call, and the
selectedRoute/decisions logic) describing the design intent: that "breeze" is
interpreted as a native-like pipeline which prefers native-static-layout when
available and only falls back to breeze-stream (and why the fallback reason uses
"user-selected-breeze"), so future readers/tests understand this intentional
behavior rather than assuming a bug.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b5da11c7-2501-40ff-9f45-76b76fa44abb

📥 Commits

Reviewing files that changed from the base of the PR and between c87acf4 and cee6a12.

📒 Files selected for processing (2)
  • src/lib/exporter/backendPolicy.test.ts
  • src/lib/exporter/backendPolicy.ts

@meiiie meiiie merged commit b5132de into main May 22, 2026
3 checks passed
@meiiie meiiie deleted the refactor/export-route-policy branch May 22, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant