Skip to content

refactor(webapistore): resolve base service names from BaseModel meta#189

Merged
buke merged 3 commits into
mainfrom
refactor/webapistore-base-service-names
Jul 25, 2026
Merged

refactor(webapistore): resolve base service names from BaseModel meta#189
buke merged 3 commits into
mainfrom
refactor/webapistore-base-service-names

Conversation

@buke

@buke buke commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

User description

Summary

  • Replace the hardcoded baseServiceNames map in webapistore.go with resolveBaseServiceNames, which loads conventional service names from the abstract BaseModel IrModel by BaseModelModuleSpec path.
  • Fail store generation when BaseModel meta is missing or has no conventional services (no silent empty filter set).
  • Keep the FE base surface on the hand-written WebModelStore service section; add a contract comment so new BaseModel RPCs are declared there (not in a Go name list).

Test plan

  • go test ./internal/module/artifact/generate/ -count=1
  • New coverage: filter base services from interface; missing BaseModel errors; empty/non-conventional services error
  • Optional: reinstall a business module and confirm generated XxxStore interface omits Search/NameSearch/Copy while still binding them at runtime

Made with Cursor


PR Type

Enhancement, Tests, Documentation


Description

  • Go core: dynamically resolve base service names from abstract BaseModel metadata instead of hardcoded map.

  • Go core: fail store generation when BaseModel metadata is missing or contains no conventional services.

  • Go core: add Go unit tests covering base service interface filtering and error cases.

  • TS modules: add contract comment in modules/web/web/stores/modelStore.ts for declaring new base RPCs.


File Walkthrough

Relevant files
Tests
generator_test.go
add abstract BaseModel test helper for generator tests     

internal/module/artifact/generate/generator_test.go

  • Add seedAbstractBaseModel helper function to seed abstract BaseModel
    and its services in test DB.
  • Update full pipeline generator test to seed BaseModel.
+48/-0   
webapistore_test.go
add unit tests for BaseModel service name resolution and filtering

internal/module/artifact/generate/webapistore_test.go

  • Seed BaseModel across existing web API store generator tests.
  • Add test asserting base services are omitted from generated
    PartnerStore interface.
  • Add error path tests for missing BaseModel and non-conventional/empty
    service lists.
+98/-0   
Enhancement
webapistore.go
resolve base service names dynamically from BaseModel meta

internal/module/artifact/generate/webapistore.go

  • Replace hardcoded baseServiceNames map with resolveBaseServiceNames.
  • Query BaseModel by module path spec and collect conventional model
    services.
  • Return explicit errors if BaseModel is missing or has no conventional
    services.
+52/-30 
Documentation
modelStore.ts
document WebModelStore RPC contract for BaseModel services

modules/web/web/stores/modelStore.ts

  • Add code comment explaining that Go store generator filters methods
    based on BaseModel meta.
  • Instruct developers to declare new FE base surface RPCs in
    WebModelStore.
+4/-1     

Summary by CodeRabbit

  • Bug Fixes
    • Updated web API store generation to resolve conventional BaseModel service names dynamically at runtime (instead of a fixed list).
    • Improved generation robustness, including handling for nil generator context.
    • Added clearer errors when the required abstract BaseModel is missing, not abstract, or has no conventional services.
  • Tests
    • Expanded test coverage for BaseModel/service resolution, filtering behavior, and partner interface generation rules.
  • Documentation
    • Updated guidance comments to match the new BaseModel service resolution approach.

- Resolve IsBaseService names from abstract BaseModel by path instead of a hardcoded map.

- Fail generation when BaseModel meta is missing or has no conventional services.

- Document that the FE base surface remains the hand-written WebModelStore service section.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f9d71ec-aa1c-4716-8deb-a137ce80d6b6

📥 Commits

Reviewing files that changed from the base of the PR and between 0a98bbf and c1b33ba.

📒 Files selected for processing (2)
  • internal/module/artifact/generate/webapistore.go
  • internal/module/artifact/generate/webapistore_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/module/artifact/generate/webapistore.go

📝 Walkthrough

Walkthrough

WebApiStore generation now resolves conventional BaseModel services from persisted metadata instead of a hardcoded list. Tests seed BaseModel metadata and cover filtering, missing records, empty conventional services, invalid model state, and non-conventional-only services.

Changes

BaseModel service resolution

Layer / File(s) Summary
Seed BaseModel metadata
internal/module/artifact/generate/generator_test.go, internal/module/artifact/generate/webapistore_test.go
Test helpers create abstract BaseModel metadata and deterministic conventional services for generator scenarios.
Resolve services during generation
internal/module/artifact/generate/webapistore.go, modules/web/web/stores/modelStore.ts
Generation loads BaseModel services from runtime metadata, filters conventional services, and uses the resolved names when rendering WebModelStore output.
Validate filtering and failures
internal/module/artifact/generate/webapistore_test.go
Tests cover custom-service retention, base-service exclusion, missing or non-abstract BaseModel records, empty conventional services, and resolver input/load errors.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Generator
  participant Resolver
  participant Metadata
  participant WebModelStore
  Generator->>Resolver: Resolve BaseModel service names
  Resolver->>Metadata: Load abstract BaseModel and Services
  Metadata-->>Resolver: Return service metadata
  Resolver-->>Generator: Return conventional service map
  Generator->>WebModelStore: Apply base-service filtering
Loading

Possibly related PRs

  • choysum-dev/choysum#188: Adds and wires the BaseModel.NameSearch service, overlapping with this PR’s metadata-driven conventional-service resolution.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change and tests, but it omits the repository's required CLA agreement template section. Add the exact CLA agreement statement required by the template, or confirm it appears at the top of the PR description.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: resolving webapistore base service names from BaseModel meta.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/webapistore-base-service-names

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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 `@internal/module/artifact/generate/webapistore.go`:
- Around line 385-387: Move the resolveBaseServiceNames call in the web API
generation flow before the zero-model early-return guard, so BaseModel metadata
is validated even for empty applications. Preserve successful behavior for valid
empty apps and propagate metadata resolution errors; add a regression test
covering an empty application with invalid BaseModel metadata.
- Around line 344-351: Update the IrModel lookup query in the model-loading flow
to add an abstract = true predicate alongside the existing path conditions,
ensuring Take(&model) selects the abstract base model before preloading
Services. Preserve the existing path matching and ordering behavior.
🪄 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: ba0380e7-9fe8-4a5f-a953-05b9c50b1766

📥 Commits

Reviewing files that changed from the base of the PR and between 9b8a4b8 and d153735.

📒 Files selected for processing (4)
  • internal/module/artifact/generate/generator_test.go
  • internal/module/artifact/generate/webapistore.go
  • internal/module/artifact/generate/webapistore_test.go
  • modules/web/web/stores/modelStore.ts

Comment thread internal/module/artifact/generate/webapistore.go
Comment thread internal/module/artifact/generate/webapistore.go
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

…ames

- Constrain the BaseModel path lookup with abstract=true so a concrete model at the same path cannot supply IsBaseService names.

- Add a regression test covering a non-abstract model at the BaseModel path.

Co-authored-by: Cursor <cursoragent@cursor.com>
@buke

buke commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

/improve

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to 0a98bbf

CategorySuggestion                                                                                                                                    Impact
General
Handle error from BaseModelModuleSpec

Handle the error returned by meta.BaseModelModuleSpec instead of ignoring it with a
blank identifier. This ensures that any configuration or resolution issues are
properly propagated rather than failing silently with an empty path.

internal/module/artifact/generate/webapistore.go [339-340]

-	path, _ := meta.BaseModelModuleSpec(runtimeScope)
+	path, err := meta.BaseModelModuleSpec(runtimeScope)
+	if err != nil {
+		return nil, xfmt.Errorf("resolve base model module spec: %w", err)
+	}
 	path = strings.TrimSpace(path)
Suggestion importance[1-10]: 6

__

Why: Ignoring the error returned by meta.BaseModelModuleSpec is a bad practice. Properly handling and propagating this error improves robustness and helps diagnose configuration issues.

Low

Previous suggestions

Suggestions up to commit d153735
CategorySuggestion                                                                                                                                    Impact
General
Handle error from BaseModelModuleSpec

Handle the error returned by meta.BaseModelModuleSpec instead of ignoring it with _.
Surfacing the actual error makes debugging configuration or resolution issues much
easier than masking them as an empty path error.

internal/module/artifact/generate/webapistore.go [335-339]

-	path, _ := meta.BaseModelModuleSpec(runtimeScope)
+	path, err := meta.BaseModelModuleSpec(runtimeScope)
+	if err != nil {
+		return nil, xfmt.Errorf("resolve base model module spec: %w", err)
+	}
 	path = strings.TrimSpace(path)
 	if path == "" {
 		return nil, xfmt.Errorf("base model module path is empty")
 	}
Suggestion importance[1-10]: 6

__

Why: Handling the error returned by meta.BaseModelModuleSpec instead of ignoring it with _ improves error reporting and makes debugging configuration issues easier.

Low

- Extract path/services helpers so empty path, nil services, and non-NotFound load errors are unit-testable.

- Add nil-context generate coverage for the resolve wiring path.

Co-authored-by: Cursor <cursoragent@cursor.com>
@buke
buke merged commit 8080efe into main Jul 25, 2026
43 checks passed
@buke
buke deleted the refactor/webapistore-base-service-names branch July 25, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant