fixed/enforced stricker JSON metadata files during generation.#77
fixed/enforced stricker JSON metadata files during generation.#77tonyboylehub wants to merge 2 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughExtracts inline JSON metadata mutation into a new helper Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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: 4
🤖 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/commands/core/asset/create.ts`:
- Around line 127-130: The command currently reads the JSON with fs.readFileSync
when preparing metadata; replace that direct file read with the shared file
utilities from src/lib/file.ts (use the module's JSON read helper, e.g.,
readJsonFile/readJson) instead of fs.readFileSync, then pass the returned object
into prepareJsonMetadata (keeping { uri: imageUri.uri, type: imageUri.mimeType
}); update imports to pull the helper into this file and remove direct fs usage
so jsonPath and jsonFile are validated/handled consistently via the shared
utilities.
- Around line 146-149: The code passes jsonFile.name directly into
createAssetFromArgs which can be missing or invalid; before calling
createAssetFromArgs (in the createAsset command), validate jsonFile.name is a
non-empty string (e.g., typeof name === 'string' && name.trim().length > 0) and
if not, throw or return a clear error message (or process.exit with a
user-facing error) so createAssetFromArgs, umi, assetSigner, and jsonUri are
never invoked with an invalid name; update the block that sets name:
jsonFile.name to perform this check and fail fast with a descriptive error.
In `@src/lib/core/create/prepareJsonMetadata.ts`:
- Around line 15-24: prepareJsonMetadata mutates nested fields without
validating their types, causing crashes when jsonFile.properties is not an
object or properties.files is not an array; update prepareJsonMetadata to first
check typeof jsonFile.properties === "object" && jsonFile.properties !== null
(otherwise overwrite with a new object) and check
Array.isArray(jsonFile.properties.files) (otherwise set files to a new array),
then assign jsonFile.properties.files[0] = imageEntry and jsonFile.image =
imageEntry.uri; reference symbols: prepareJsonMetadata, jsonFile.properties,
jsonFile.properties.files, imageEntry.
In `@test/commands/core/core.prepareJsonMetadata.test.ts`:
- Around line 6-53: Add regression tests for malformed shapes by updating
core.prepareJsonMetadata.test.ts to cover cases where metadata.properties is not
an object (e.g., properties: "x") and where properties.files is not an
array/object (e.g., properties: { files: "x" }); for each case call
prepareJsonMetadata(json, imageEntry) and assert it does not throw, sets
result.image === imageEntry.uri, and that result.properties.files[0] deep-equals
imageEntry (and preserves any valid subsequent entries if present); place these
alongside the existing tests referencing prepareJsonMetadata and imageEntry so
the crash-fix is locked in.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 9eab94d2-3c91-4492-b005-f61144dc7959
📒 Files selected for processing (5)
src/commands/core/asset/create.tssrc/lib/core/create/createAssetFromFiles.tssrc/lib/core/create/prepareJsonMetadata.tstest/commands/core/core.prepareJsonMetadata.test.tstest/commands/toolbox/token.create.test.ts
💤 Files with no reviewable changes (1)
- test/commands/toolbox/token.create.test.ts
Metadata files if not passed in or generated correctly (missing properties field in particular) was causing a silent crash. This resolves the issue and also generates the properies field if missed by the user/ai agent.