feat: save-fixture fetches component master node trees (#16)#19
feat: save-fixture fetches component master node trees (#16)#19
Conversation
When saving a fixture with node-id scoping, INSTANCE nodes reference component masters that live outside the scope. Now save-fixture: 1. Collects all componentId references from the scoped tree 2. Fetches master node trees via getFileNodes (batched at 50) 3. Does a 2nd pass to resolve nested component references 4. Stores masters in new optional `componentDefinitions` field This enables design-tree, analysis rules, and converters to access the full component structure for better analysis and code generation. - New: componentDefinitions field in AnalysisFile schema (optional, backward-compatible) - New: component-resolver.ts with collectComponentIds + resolveComponentDefinitions - New: transformComponentMasterNodes in figma-transformer.ts - Updated: figma-file-loader preserves componentDefinitions from saved fixtures - 9 new tests, 270 total passing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a multi-pass component master resolution flow: collect component IDs from INSTANCE nodes, fetch their master COMPONENT node trees from Figma in batched passes, transform those nodes into AnalysisNode form, and attach them to fixtures as Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant CLI as CLI (save-fixture)
participant Resolver as Component Resolver
participant Client as Figma Client
participant Transformer as Figma Transformer
participant Storage as Fixture Storage
CLI->>Resolver: collectComponentIds(document)
Resolver-->>CLI: Set(component IDs)
loop multi-pass (batch by 50)
CLI->>Client: getFileNodes(fileKey, batchIDs)
Client-->>CLI: GetFileNodesResponse
CLI->>Transformer: transformComponentMasterNodes(response, batchIDs)
Transformer-->>CLI: Record<ID, AnalysisNode>
CLI->>Resolver: extract component IDs from new masters
Resolver-->>CLI: pending IDs for next pass
end
CLI->>Storage: write fixture (with componentDefinitions)
Storage-->>CLI: save complete
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/core/adapters/component-resolver.ts`:
- Around line 74-82: The loop that repopulates pendingIds currently iterates
over allDefinitions each pass; change it to only iterate over the definitions
fetched in the current pass (the variable representing the current pass's nodes)
instead of allDefinitions to avoid re-scanning already-known definitions; update
the code that builds pendingIds (currently referencing pendingIds,
allDefinitions, resolvedIds and calling collectComponentIds) to use the
current-pass collection of nodes (the variable that holds nodes returned this
iteration) so you only add ids not in resolvedIds from that subset.
- Around line 64-66: The catch block in component-resolver.ts that currently
swallows errors should log the failure at debug level: inside the catch in the
resolveComponents (or the batch-processing function) replace the empty body with
a debug log that includes the caught error and identifying batch/component
metadata (e.g., batch index or component names/ids) using the module's existing
logger instance so you can trace which batch failed without changing behavior
for production (keep it debug-level).
In `@src/core/adapters/figma-file-loader.ts`:
- Around line 39-50: Summary: validation failures in parsing
data.componentDefinitions are currently silent—add logging for failed
validations. Modify the loop that iterates data.componentDefinitions (the block
using AnalysisNodeSchema.safeParse and assigning file.componentDefinitions) so
that when result.success is false you log the id, the raw entry (or a short
summary) and the validation errors; use the repository's existing logger (e.g.,
processLogger or module logger) or console.debug if none exists, and keep the
current behavior of skipping invalid entries.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0586185b-7c86-475a-8052-120aa2802330
📒 Files selected for processing (7)
src/cli/index.tssrc/core/adapters/component-resolver.test.tssrc/core/adapters/component-resolver.tssrc/core/adapters/figma-file-loader.tssrc/core/adapters/figma-transformer.tssrc/core/adapters/index.tssrc/core/contracts/figma-node.ts
Previously componentDefinitions was only populated during save-fixture. Now loadFromApi also resolves component masters so that `canicode analyze` with a Figma URL gets full component structure for accurate scoring. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add debug logging for failed batch fetches in component-resolver - Add debug logging for validation failures in figma-file-loader - Optimize next-pass ID collection to scan only current-pass results Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Addresses docstring coverage check (62.5% → 80%+ threshold). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
componentDefinitions필드 추가 (optional, 기존 fixture 호환)변경 사항
AnalysisFileSchema에componentDefinitions: Record<string, AnalysisNode>추가 (optional)component-resolver.ts신규:collectComponentIds+resolveComponentDefinitionsfigma-transformer.ts:transformComponentMasterNodes추가figma-file-loader.ts: 저장된 fixture에서componentDefinitions보존cli/index.ts: save-fixture 플로우에 마스터 resolve 연결동작 방식
외부 라이브러리 컴포넌트(다른 파일)는 자동 skip.
이후 활용
Test plan
pnpm test:run— 270 tests passed (9 new)pnpm lint— cleanCloses #16
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests
Bug Fixes