feat: add projectType metadata field (standard | shorts)#804
Conversation
|
@kseungyong is attempting to deploy a commit to the OpenCut OSS Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughDefines ChangesProject Type System
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/web/src/core/managers/project-manager.ts (1)
98-98: ⚡ Quick winUse a shared default project type constant instead of a hardcoded string.
Line 98 hardcodes
"standard", which duplicates domain data already centralized in project types. Pulling the default from a shared exported constant avoids future drift.♻️ Proposed fix
--- a/apps/web/src/project/types.ts +++ b/apps/web/src/project/types.ts @@ export const PROJECT_TYPES = ["standard", "shorts"] as const; export type TProjectType = (typeof PROJECT_TYPES)[number]; +export const DEFAULT_PROJECT_TYPE: TProjectType = "standard";--- a/apps/web/src/core/managers/project-manager.ts +++ b/apps/web/src/core/managers/project-manager.ts @@ import type { + DEFAULT_PROJECT_TYPE, TProject, TProjectMetadata, TProjectSortKey, @@ - projectType: projectType ?? "standard", + projectType: projectType ?? DEFAULT_PROJECT_TYPE,🤖 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 `@apps/web/src/core/managers/project-manager.ts` at line 98, Replace the hardcoded "standard" default used in the object assignment (projectType: projectType ?? "standard") with the shared exported default constant from the project types module (e.g. DEFAULT_PROJECT_TYPE); add the appropriate import for that constant and use projectType: projectType ?? DEFAULT_PROJECT_TYPE so the default value is centralized and cannot drift from the domain constants.
🤖 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 `@apps/web/src/project/__tests__/project-type.test.ts`:
- Around line 10-13: Replace the weak length-only assertion in the "TProjectType
only accepts known values" test with a strict equality and a compile-time
type-equality guard: assert that the runtime array equals ["standard", "shorts"]
exactly, and add a TypeScript-only check that TProjectType is exactly equal to
the union type derived from that const array (e.g. derive Expected = typeof
expected[number] from const expected = ["standard","shorts"] as const and use a
conditional type to ensure Expected extends TProjectType and TProjectType
extends Expected). This ensures both runtime values and the type alias
TProjectType cannot widen.
---
Nitpick comments:
In `@apps/web/src/core/managers/project-manager.ts`:
- Line 98: Replace the hardcoded "standard" default used in the object
assignment (projectType: projectType ?? "standard") with the shared exported
default constant from the project types module (e.g. DEFAULT_PROJECT_TYPE); add
the appropriate import for that constant and use projectType: projectType ??
DEFAULT_PROJECT_TYPE so the default value is centralized and cannot drift from
the domain constants.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: fdd23259-5095-41b1-b6ae-426d75122a2f
📒 Files selected for processing (3)
apps/web/src/core/managers/project-manager.tsapps/web/src/project/__tests__/project-type.test.tsapps/web/src/project/types.ts
| test("TProjectType only accepts known values", () => { | ||
| const valid: TProjectType[] = ["standard", "shorts"]; | ||
| expect(valid.length).toBe(2); | ||
| }); |
There was a problem hiding this comment.
Strengthen the invariant test so it fails when TProjectType widens.
The current check only verifies array length, so it can still pass if TProjectType becomes too broad (for example, string).
✅ Proposed stronger test
test("TProjectType only accepts known values", () => {
- const valid: TProjectType[] = ["standard", "shorts"];
- expect(valid.length).toBe(2);
+ const assertKnownProjectType = (value: TProjectType): void => {
+ switch (value) {
+ case "standard":
+ case "shorts":
+ return;
+ default: {
+ const exhaustiveCheck: never = value;
+ return exhaustiveCheck;
+ }
+ }
+ };
+
+ assertKnownProjectType("standard");
+ assertKnownProjectType("shorts");
+ expect(PROJECT_TYPES).toHaveLength(2);
});🤖 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 `@apps/web/src/project/__tests__/project-type.test.ts` around lines 10 - 13,
Replace the weak length-only assertion in the "TProjectType only accepts known
values" test with a strict equality and a compile-time type-equality guard:
assert that the runtime array equals ["standard", "shorts"] exactly, and add a
TypeScript-only check that TProjectType is exactly equal to the union type
derived from that const array (e.g. derive Expected = typeof expected[number]
from const expected = ["standard","shorts"] as const and use a conditional type
to ensure Expected extends TProjectType and TProjectType extends Expected). This
ensures both runtime values and the type alias TProjectType cannot widen.
Adds optional projectType discriminator on TProjectMetadata so downstream features (preset pickers, export defaults, UI affordances) can branch on intent without inferring from canvas dimensions. - New const PROJECT_TYPES and type TProjectType - TProjectMetadata.projectType (optional for back-compat with stored projects) - ProjectManager.createNewProject accepts optional projectType, defaults to 'standard' - Unit tests for PROJECT_TYPES invariants
a1620a9 to
7131f88
Compare
|
Closing — continuing on a private fork. The branch |
Summary
Adds an optional discriminator field `projectType` to `TProjectMetadata`. This is foundational for upcoming Shorts-flavored features (9:16 preset, YouTube Shorts export preset, vertical-safe text positioning) that need to branch on user intent rather than infer it from canvas dimensions.
Changes
Field is optional → existing stored projects in IndexedDB load unchanged.
Why Optional
No storage migration needed. Code paths that branch on type use `?? "standard"`.
Test Plan
Summary by CodeRabbit
New Features
Tests