fix(registry): don't fallback embeddedMetaJSON to default empty JSON#275
Conversation
When meta_data.json is not compiled in, embeddedMetaJSON was being set
to meta_data_default.json ({"version":"0.0.0","services":[]}), which is
34 bytes. This caused hasEmbeddedData() to return true even though there
were no real services, making TestColdStart_UsesEmbedded fail instead of
skip, and TestCacheHit_WithinTTL fail on the embedded calendar check.
Fix: leave embeddedMetaJSON as nil when no real meta_data.json is present,
so hasEmbeddedData() correctly returns false and dependent tests skip.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
yanghongping seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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.
🧹 Nitpick comments (1)
internal/registry/loader_embedded.go (1)
11-12: Remove the unusedembeddedMetaDataDefaultJSONvariable and its embed directive.The variable is no longer referenced after removing the fallback branch. Deleting the
//go:embed meta_data_default.jsondirective and variable declaration at lines 11-12 will reduce binary size and improve code clarity.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/registry/loader_embedded.go` around lines 11 - 12, Remove the unused embed directive and variable by deleting the `//go:embed meta_data_default.json` line and the `var embeddedMetaDataDefaultJSON []byte` declaration (symbol: embeddedMetaDataDefaultJSON and its embed comment) from the file so the unused embedded asset is not compiled into the binary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/registry/loader_embedded.go`:
- Around line 11-12: Remove the unused embed directive and variable by deleting
the `//go:embed meta_data_default.json` line and the `var
embeddedMetaDataDefaultJSON []byte` declaration (symbol:
embeddedMetaDataDefaultJSON and its embed comment) from the file so the unused
embedded asset is not compiled into the binary.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 49e540bd-03bd-4d9e-8e85-2d07a1728ebe
📒 Files selected for processing (1)
internal/registry/loader_embedded.go
Greptile SummaryRemoves the As a minor follow-up, Confidence Score: 5/5Safe to merge; correctly prevents false-positive hasEmbeddedData() results with no functional regressions. Single-line removal with a clear, well-described intent. The one remaining finding is P2 (unused dead variable / double-embed) and does not block merge. No files require special attention; the unused embeddedMetaDataDefaultJSON declaration in loader_embedded.go is worth cleaning up as a follow-up. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[init called] --> B{metaFS.ReadFile meta_data.json\nsucceeds AND len > 0?}
B -- Yes --> C[embeddedMetaJSON = data]
B -- No --> D[embeddedMetaJSON remains nil]
C --> E[hasEmbeddedData returns true]
D --> F[hasEmbeddedData returns false]
F --> G[Tests needing embedded data: SKIP]
E --> H[Tests needing embedded data: RUN]
|
Summary
loader_embedded.gowas settingembeddedMetaJSONto the default empty JSON ({"version":"0.0.0","services":[]}) whenmeta_data.jsonis not compiled inhasEmbeddedData()to returntrue(34 bytes > 0), even though there were no real servicesTestColdStart_UsesEmbedded: failed with "expected embedded projects, got none"TestCacheHit_WithinTTL: failed with "expected calendar from embedded data"Fix
Remove the
elsefallback soembeddedMetaJSONremainsnilwhen no realmeta_data.jsonis present.hasEmbeddedData()then correctly returnsfalseand dependent tests skip as intended.Test plan
go build ./...— passesgo vet ./...— no warningsTestColdStart_UsesEmbedded— now correctly SKIP (was FAIL)TestCacheHit_WithinTTL— now PASS (was FAIL)🤖 Generated with Claude Code
Summary by CodeRabbit