Skip to content

refactor(export): add native static route plan#556

Merged
meiiie merged 1 commit into
mainfrom
refactor/native-static-route-plan
May 22, 2026
Merged

refactor(export): add native static route plan#556
meiiie merged 1 commit into
mainfrom
refactor/native-static-route-plan

Conversation

@meiiie
Copy link
Copy Markdown
Collaborator

@meiiie meiiie commented May 22, 2026

Summary

  • Add a pure native static-layout route planner for the Electron export path.
  • Model the CUDA -> Windows D3D11 -> FFmpeg fallback order with structured decisions and reasons.
  • Add focused tests for CUDA selected, CUDA skipped to D3D11, both GPU routes skipped to FFmpeg, and source proxy metadata preservation.

Verification

  • npm test -- electron/ipc/export/nativeStaticLayoutRoutePlan.test.ts
  • npx tsc --noEmit
  • npx biome check --formatter-enabled=false electron/ipc/export/nativeStaticLayoutRoutePlan.ts electron/ipc/export/nativeStaticLayoutRoutePlan.test.ts
  • git diff --check

Notes

Summary by CodeRabbit

  • Tests

    • Added comprehensive test suite for export route planning, covering GPU compositor and software fallback scenarios.
  • New Features

    • Added export route planning infrastructure to intelligently select between hardware acceleration options and fallback paths with decision tracking.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

This PR introduces a static layout export route planner that selects between CUDA, D3D11, and FFmpeg based on capability probe data. The implementation includes type contracts for routes and decisions, along with comprehensive tests verifying all routing scenarios.

Changes

Static Layout Export Route Planning

Layer / File(s) Summary
Route planning contracts and implementation
electron/ipc/export/nativeStaticLayoutRoutePlan.ts
NativeStaticLayoutRoute type and probe interfaces (NvidiaCudaExportCapabilityProbe, WindowsD3D11ExportCapabilityProbe) define available routes and GPU capabilities. NativeStaticLayoutRouteDecision and NativeStaticLayoutRoutePlan track ordered route choices and selected fallbacks. planNativeStaticLayoutRoutes builds a decision array and selects routes by checking cuda.skipReason and d3d11.skipReason: CUDA selected if available, D3D11 if CUDA skipped, FFmpeg if both unavailable.
Route selection test suite
electron/ipc/export/nativeStaticLayoutRoutePlan.test.ts
Test fixtures establish source, CUDA, and D3D11 probes. Four scenario tests verify: CUDA selection with D3D11/FFmpeg fallbacks; D3D11 selection when CUDA unavailable; FFmpeg selection when both native routes unavailable; and source metadata preservation across returned plan.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A planner hops through routes with care,
Picks CUDA first—a GPU pair!
When CUDA rests, D3D11's near,
FFmpeg waits, a safe frontier,
Four tests ensure the path is bright! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a native static route plan for the export functionality.
Description check ✅ Passed The PR description provides a clear summary, detailed verification steps, and relevant notes, though it deviates from the provided template structure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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/native-static-route-plan

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.

🧹 Nitpick comments (1)
electron/ipc/export/nativeStaticLayoutRoutePlan.test.ts (1)

152-165: ⚡ Quick win

Make the proxy-metadata assertion mutation-safe.

This assertion reuses the same object passed into the planner, so an in-place mutation could still pass. Snapshot expected metadata before the call and assert against that snapshot.

Suggested test hardening
 it("preserves proxy source metadata for route diagnostics", () => {
 	const proxiedSource = {
 		inputCodec: "vp9",
 		proxyCodec: "h264",
 		proxyCreated: true,
 	};
+	const expectedSource = { ...proxiedSource };

-	expect(
-		planNativeStaticLayoutRoutes({
-			cuda: cudaProbe,
-			d3d11: d3d11Probe,
-			source: proxiedSource,
-		}).source,
-	).toEqual(proxiedSource);
+	const plan = planNativeStaticLayoutRoutes({
+		cuda: cudaProbe,
+		d3d11: d3d11Probe,
+		source: proxiedSource,
+	});
+
+	expect(plan.source).toEqual(expectedSource);
+	expect(proxiedSource).toEqual(expectedSource);
 });
🤖 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 `@electron/ipc/export/nativeStaticLayoutRoutePlan.test.ts` around lines 152 -
165, The test currently passes the proxiedSource object directly to
planNativeStaticLayoutRoutes and then asserts the returned .source equals the
same object, which won't catch in-place mutations; to harden it, clone or
snapshot the expected metadata before calling planNativeStaticLayoutRoutes
(e.g., const expectedSource = { ...proxiedSource } or deep clone) and then call
planNativeStaticLayoutRoutes({ cuda: cudaProbe, d3d11: d3d11Probe, source:
proxiedSource }) and assert that result.source strictly equals the saved
expectedSource (not the original proxiedSource), ensuring
planNativeStaticLayoutRoutes did not mutate the input; reference the
proxiedSource variable and planNativeStaticLayoutRoutes function in the test.
🤖 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.

Nitpick comments:
In `@electron/ipc/export/nativeStaticLayoutRoutePlan.test.ts`:
- Around line 152-165: The test currently passes the proxiedSource object
directly to planNativeStaticLayoutRoutes and then asserts the returned .source
equals the same object, which won't catch in-place mutations; to harden it,
clone or snapshot the expected metadata before calling
planNativeStaticLayoutRoutes (e.g., const expectedSource = { ...proxiedSource }
or deep clone) and then call planNativeStaticLayoutRoutes({ cuda: cudaProbe,
d3d11: d3d11Probe, source: proxiedSource }) and assert that result.source
strictly equals the saved expectedSource (not the original proxiedSource),
ensuring planNativeStaticLayoutRoutes did not mutate the input; reference the
proxiedSource variable and planNativeStaticLayoutRoutes function in the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c5ad696-a47a-49c3-ae44-553ca15b149c

📥 Commits

Reviewing files that changed from the base of the PR and between 9d8b3c6 and 31eb0ec.

📒 Files selected for processing (2)
  • electron/ipc/export/nativeStaticLayoutRoutePlan.test.ts
  • electron/ipc/export/nativeStaticLayoutRoutePlan.ts

@meiiie meiiie merged commit 8cfc522 into main May 22, 2026
3 checks passed
@meiiie meiiie deleted the refactor/native-static-route-plan branch May 22, 2026 11:58
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