Skip to content

fixed/enforced stricker JSON metadata files during generation.#77

Open
tonyboylehub wants to merge 2 commits intomainfrom
fix/metadata-generation
Open

fixed/enforced stricker JSON metadata files during generation.#77
tonyboylehub wants to merge 2 commits intomainfrom
fix/metadata-generation

Conversation

@tonyboylehub
Copy link
Contributor

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a9bcd045-833a-4a28-8645-6833f4816204

📥 Commits

Reviewing files that changed from the base of the PR and between 83c33a3 and e5877d2.

📒 Files selected for processing (1)
  • src/commands/core/asset/create.ts

Summary by CodeRabbit

  • Refactor

    • Centralized JSON metadata preparation into a shared utility to standardize how image references and file lists are embedded during asset creation.
  • Tests

    • Added tests covering image assignment and file-array handling for metadata preparation.
    • Simplified test setup by removing the prior pre-test hook and using a fixed short delay instead.

Walkthrough

Extracts inline JSON metadata mutation into a new helper prepareJsonMetadata, used by asset creation flows to set image and normalize properties.files. Adds unit tests for the helper and a small test change removing a before-hook in a toolbox test.

Changes

Cohort / File(s) Summary
Metadata Preparation Utility
src/lib/core/create/prepareJsonMetadata.ts
New module exporting prepareJsonMetadata(jsonFile, imageEntry) and types JsonMetadata, ImageFileEntry; embeds image URI and ensures properties.files contains the image entry.
Asset Creation Workflow Updates
src/commands/core/asset/create.ts, src/lib/core/create/createAssetFromFiles.ts
Replaced direct JSON mutations with calls to prepareJsonMetadata; added import and a type cast for jsonFile.name where used.
Unit Tests for Utility
test/commands/core/core.prepareJsonMetadata.test.ts
New tests covering cases: missing properties, missing properties.files, existing files (overwriting index 0), and preserving subsequent file entries.
Test Adjustment
test/commands/toolbox/token.create.test.ts
Removed a before-hook that performed a toolbox sol airdrop and introduced a 10s delay; no other test logic changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • blockiosaurus
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fixed/enforced stricker JSON metadata files during generation' directly relates to the changeset, which introduces validation and stricter handling of JSON metadata structure by adding the prepareJsonMetadata helper function.
Description check ✅ Passed The description accurately describes the PR's purpose: fixing a crash caused by missing 'properties' fields in JSON metadata and automatically generating this field if omitted, which aligns with the changes introducing prepareJsonMetadata validation logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/metadata-generation
📝 Coding Plan
  • Generate coding plan for human review comments

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
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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6179dff and 83c33a3.

📒 Files selected for processing (5)
  • src/commands/core/asset/create.ts
  • src/lib/core/create/createAssetFromFiles.ts
  • src/lib/core/create/prepareJsonMetadata.ts
  • test/commands/core/core.prepareJsonMetadata.test.ts
  • test/commands/toolbox/token.create.test.ts
💤 Files with no reviewable changes (1)
  • test/commands/toolbox/token.create.test.ts

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.

2 participants