Skip to content

Commit 7d00670

Browse files
committed
feat: refactor plugin capability handling and improve host config service integration
1 parent 01eb67e commit 7d00670

11 files changed

Lines changed: 93 additions & 55 deletions

File tree

.github/workflows/reusable-make-command-smoke.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ jobs:
7676
backend_port=18080
7777
frontend_port=15666
7878
79-
mkdir -p "$smoke_root/hack/tools" "$smoke_root/apps/lina-core/pkg/plugin/capability" "$smoke_root/apps/lina-core/manifest/config" "$smoke_root/apps/lina-core/manifest/sql" "$smoke_root/apps/lina-core/manifest/i18n/en-US" "$smoke_root/apps/lina-core/internal/packed/manifest" "$smoke_root/apps/lina-vben/node_modules/.bin" "$smoke_root/apps/lina-vben/apps/web-antd"
79+
mkdir -p "$smoke_root/hack/tools" "$smoke_root/apps/lina-core" "$smoke_root/apps/lina-core/manifest/config" "$smoke_root/apps/lina-core/manifest/sql" "$smoke_root/apps/lina-core/manifest/i18n/en-US" "$smoke_root/apps/lina-core/internal/packed/manifest" "$smoke_root/apps/lina-vben/node_modules/.bin" "$smoke_root/apps/lina-vben/apps/web-antd"
8080
cp Makefile "$smoke_root/Makefile"
8181
cp -R hack/makefiles "$smoke_root/hack/makefiles"
8282
cp -R hack/tools/linactl "$smoke_root/hack/tools/linactl"
8383
cp apps/lina-core/go.mod "$smoke_root/apps/lina-core/go.mod"
8484
cp apps/lina-core/go.sum "$smoke_root/apps/lina-core/go.sum"
85-
cp -R apps/lina-core/pkg/plugin/pluginbridge "$smoke_root/apps/lina-core/pkg/plugin/pluginbridge"
86-
cp -R apps/lina-core/pkg/plugin/capability/data "$smoke_root/apps/lina-core/pkg/plugin/capability/data"
85+
cp -R apps/lina-core/pkg "$smoke_root/apps/lina-core/pkg"
8786
cat > "$smoke_root/go.work" <<'WORK'
8887
go 1.25.0
8988
@@ -161,14 +160,13 @@ jobs:
161160
162161
smoke_root="$RUNNER_TEMP/wasm-command-root"
163162
164-
mkdir -p "$smoke_root/hack/tools" "$smoke_root/apps/lina-core/pkg/plugin/capability" "$smoke_root/apps/lina-plugins/demo-dynamic"
163+
mkdir -p "$smoke_root/hack/tools" "$smoke_root/apps/lina-core" "$smoke_root/apps/lina-plugins/demo-dynamic"
165164
cp Makefile "$smoke_root/Makefile"
166165
cp -R hack/makefiles "$smoke_root/hack/makefiles"
167166
cp -R hack/tools/linactl "$smoke_root/hack/tools/linactl"
168167
cp apps/lina-core/go.mod "$smoke_root/apps/lina-core/go.mod"
169168
cp apps/lina-core/go.sum "$smoke_root/apps/lina-core/go.sum"
170-
cp -R apps/lina-core/pkg/plugin/pluginbridge "$smoke_root/apps/lina-core/pkg/plugin/pluginbridge"
171-
cp -R apps/lina-core/pkg/plugin/capability/data "$smoke_root/apps/lina-core/pkg/plugin/capability/data"
169+
cp -R apps/lina-core/pkg "$smoke_root/apps/lina-core/pkg"
172170
cat > "$smoke_root/go.work" <<'WORK'
173171
go 1.25.0
174172

.github/workflows/reusable-plugin-command-smoke.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ jobs:
7171
git -C "$source_dir" add .
7272
git -C "$source_dir" commit -q -m "initial plugin"
7373
74-
mkdir -p "$smoke_root/hack/tools" "$smoke_root/apps/lina-core/pkg/plugin/capability"
74+
mkdir -p "$smoke_root/hack/tools" "$smoke_root/apps/lina-core"
7575
cp Makefile "$smoke_root/Makefile"
7676
cp -R hack/makefiles "$smoke_root/hack/makefiles"
7777
cp -R hack/tools/linactl "$smoke_root/hack/tools/linactl"
7878
cp apps/lina-core/go.mod "$smoke_root/apps/lina-core/go.mod"
7979
cp apps/lina-core/go.sum "$smoke_root/apps/lina-core/go.sum"
80-
cp -R apps/lina-core/pkg/plugin/pluginbridge "$smoke_root/apps/lina-core/pkg/plugin/pluginbridge"
81-
cp -R apps/lina-core/pkg/plugin/capability/data "$smoke_root/apps/lina-core/pkg/plugin/capability/data"
80+
cp -R apps/lina-core/pkg "$smoke_root/apps/lina-core/pkg"
8281
cat > "$smoke_root/go.work" <<'WORK'
8382
go 1.25.0
8483

apps/lina-core/internal/cmd/internal/httpstartup/http_runtime.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,15 @@ func newHTTPRuntime(ctx context.Context, configSvc config.Service) (*httpRuntime
238238
closeHTTPCoordinationAfterInitError(ctx, coordinationSvc)
239239
return nil, err
240240
}
241+
hostConfigReader, ok := configSvc.(pluginservicehostconfig.RawConfigReader)
242+
if !ok {
243+
closeHTTPCoordinationAfterInitError(ctx, coordinationSvc)
244+
return nil, gerror.New("host config service does not support raw reads")
245+
}
241246
var (
242247
jobMgmtSvc = jobmgmtsvc.New(bizCtxSvc, configSvc, i18nSvc, jobRegistry, jobScheduler, scopeSvc)
243248
middlewareSvc = middleware.New(authSvc, bizCtxSvc, configSvc, i18nSvc, pluginSvc, roleSvc, tenantSvc)
244-
hostConfigSvc = pluginservicehostconfig.New(configSvc)
249+
hostConfigSvc = pluginservicehostconfig.New(hostConfigReader)
245250
pluginConfigFactory = pluginserviceconfig.NewConfigFactory("", "")
246251
pluginManifestFactory = pluginservicemanifest.NewFactory("")
247252
)

apps/lina-core/internal/service/plugin/internal/testutil/testutil_services.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func NewServices() *Services {
150150
configProvider,
151151
capabilitySvc,
152152
capabilityconfig.NewConfigFactory("", ""),
153-
capabilityhostconfig.New(configProvider),
153+
capabilityhostconfig.New(mustHostConfigRawReader(configProvider)),
154154
capabilitymanifest.NewFactory(""),
155155
)
156156

@@ -164,6 +164,16 @@ func NewServices() *Services {
164164
}
165165
}
166166

167+
// mustHostConfigRawReader returns the raw host-config reader implemented by
168+
// the shared test config service and panics if fixture wiring regresses.
169+
func mustHostConfigRawReader(configProvider configsvc.Service) capabilityhostconfig.RawConfigReader {
170+
reader, ok := configProvider.(capabilityhostconfig.RawConfigReader)
171+
if !ok {
172+
panic("test config service does not support raw host config reads")
173+
}
174+
return reader
175+
}
176+
167177
// runtimeCacheChangeNotifier is a no-op cache revision publisher for isolated
168178
// plugin runtime tests.
169179
type runtimeCacheChangeNotifier struct{}

apps/lina-core/internal/service/plugin/plugin_host_services_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,23 @@ func newWasmHostServiceTestDeps(t *testing.T) *wasmHostServiceTestDeps {
143143
configSvc: configSvc,
144144
hostServices: newRootTestCapabilities(bizCtxSvc, nil),
145145
configFactory: capabilityconfig.NewConfigFactory("", ""),
146-
hostConfigSvc: capabilityhostconfig.New(configSvc),
146+
hostConfigSvc: capabilityhostconfig.New(mustHostConfigRawReaderForTest(t, configSvc)),
147147
manifestFactory: capabilitymanifest.NewFactory(""),
148148
}
149149
}
150150

151+
// mustHostConfigRawReaderForTest returns the raw host-config reader implemented
152+
// by the test config service or fails the current test during fixture wiring.
153+
func mustHostConfigRawReaderForTest(t *testing.T, configSvc configsvc.Service) capabilityhostconfig.RawConfigReader {
154+
t.Helper()
155+
156+
reader, ok := configSvc.(capabilityhostconfig.RawConfigReader)
157+
if !ok {
158+
t.Fatal("test config service does not support raw host config reads")
159+
}
160+
return reader
161+
}
162+
151163
// configureWasmHostServicesForTest calls the production root configuration
152164
// entry with one explicit dependency set.
153165
func configureWasmHostServicesForTest(deps *wasmHostServiceTestDeps) error {

apps/lina-core/internal/service/plugin/plugin_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,23 @@ func configureRootWasmHostServicesForTest(
124124
configProvider,
125125
capabilities,
126126
capabilityconfig.NewConfigFactory("", ""),
127-
capabilityhostconfig.New(configProvider),
127+
capabilityhostconfig.New(mustHostConfigRawReader(configProvider)),
128128
capabilitymanifest.NewFactory(""),
129129
); err != nil {
130130
panic(err)
131131
}
132132
}
133133

134+
// mustHostConfigRawReader returns the raw host-config reader implemented by
135+
// the root test config service and panics if the fixture wiring regresses.
136+
func mustHostConfigRawReader(configProvider configsvc.Service) capabilityhostconfig.RawConfigReader {
137+
reader, ok := configProvider.(capabilityhostconfig.RawConfigReader)
138+
if !ok {
139+
panic("test config service does not support raw host config reads")
140+
}
141+
return reader
142+
}
143+
134144
// rootTestCapabilities publishes the minimal host service directory required
135145
// by root-package plugin facade tests. It mirrors the production capability
136146
// wiring only for services used by provider construction and leaves unrelated

apps/lina-core/internal/service/user/user_test_dependencies_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ func newUserTestService(tenantRuntimes ...tenantcapsvc.ProviderRuntime) Service
5050
authSvc := auth.New(configSvc, pluginSvc, orgCapSvc, roleSvc, tenantSvc, sessionStore, kvCacheSvc)
5151
notifySvc := notify.New(tenantSvc)
5252
apiDocSvc := apidoc.New(configSvc, bizCtxSvc, i18nSvc, pluginSvc)
53-
hostConfigSvc := capabilityhostconfig.New(configSvc)
53+
hostConfigReader, ok := configSvc.(capabilityhostconfig.RawConfigReader)
54+
if !ok {
55+
panic("test config service does not support raw host config reads")
56+
}
57+
hostConfigSvc := capabilityhostconfig.New(hostConfigReader)
5458
capabilities, err := pluginsvc.NewHostServices(
5559
apiDocSvc,
5660
authSvc,

apps/lina-core/pkg/plugin/capability/hostconfigcap/hostconfig.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@ import (
77
"context"
88

99
"github.com/gogf/gf/v2/container/gvar"
10-
11-
hostconfigsvc "lina-core/internal/service/config"
1210
)
1311

14-
// rawConfigReader is implemented by the host-owned config service. It keeps
15-
// this adapter dependent on the startup-injected config instance instead of
16-
// reaching around the service graph for global configuration.
17-
type rawConfigReader interface {
12+
// RawConfigReader is implemented by the host-owned config service. It keeps
13+
// this adapter dependent on the startup-injected config instance without
14+
// coupling this public capability package to host internal service packages.
15+
type RawConfigReader interface {
16+
// GetRaw returns one raw host configuration value or root snapshot.
1817
GetRaw(ctx context.Context, key string) (*gvar.Var, error)
1918
}
2019

2120
// serviceAdapter reads individual host config keys from the host config service.
2221
type serviceAdapter struct {
23-
configSvc hostconfigsvc.Service
22+
configSvc RawConfigReader
2423
}
2524

2625
// New creates a host config reader backed by the host config service.
27-
func New(configSvc hostconfigsvc.Service) Service {
26+
func New(configSvc RawConfigReader) Service {
2827
return &serviceAdapter{configSvc: configSvc}
2928
}

apps/lina-core/pkg/plugin/capability/hostconfigcap/hostconfig_access.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,5 @@ func (s *serviceAdapter) valueForKey(ctx context.Context, key string) (*gvar.Var
103103
if s == nil || s.configSvc == nil {
104104
return nil, gerror.New("host config service is not configured")
105105
}
106-
reader, ok := s.configSvc.(rawConfigReader)
107-
if !ok {
108-
return nil, gerror.New("host config service does not support raw reads")
109-
}
110-
return reader.GetRaw(ctx, key)
106+
return s.configSvc.GetRaw(ctx, key)
111107
}

apps/lina-core/pkg/plugin/capability/hostconfigcap/hostconfig_access_test.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
"strings"
99
"testing"
1010

11+
"github.com/gogf/gf/v2/container/gvar"
1112
"github.com/gogf/gf/v2/frame/g"
1213
"github.com/gogf/gf/v2/os/gcfg"
13-
14-
hostconfigsvc "lina-core/internal/service/config"
1514
)
1615

1716
// TestHostConfigReadsAnyNonRootHostConfigKey verifies source plugins can read
@@ -26,7 +25,7 @@ plugin:
2625
storagePath: "temp/dynamic"
2726
`)
2827

29-
svc := New(hostconfigsvc.New())
28+
svc := New(testRawHostConfigReader{})
3029
ctx := context.Background()
3130

3231
link, err := svc.String(ctx, "database.default.link", "")
@@ -54,7 +53,7 @@ workspace:
5453
basePath: "/admin"
5554
`)
5655

57-
svc := New(hostconfigsvc.New())
56+
svc := New(testRawHostConfigReader{})
5857
found, err := svc.Exists(context.Background(), "database.default.link")
5958
if err != nil {
6059
t.Fatalf("check missing host config key: %v", err)
@@ -72,7 +71,7 @@ workspace:
7271
basePath: "/admin"
7372
`)
7473

75-
svc := New(hostconfigsvc.New())
74+
svc := New(testRawHostConfigReader{})
7675
value, err := svc.Get(context.Background(), ".")
7776
if err != nil {
7877
t.Fatalf("read host config root: %v", err)
@@ -102,17 +101,6 @@ func TestHostConfigRequiresInjectedRawReader(t *testing.T) {
102101
}
103102
}
104103

105-
// TestHostConfigRejectsServiceWithoutRawReads verifies accidental stand-ins
106-
// cannot bypass the injected host config service contract.
107-
func TestHostConfigRejectsServiceWithoutRawReads(t *testing.T) {
108-
svc := New(hostConfigServiceWithoutRawReads{})
109-
110-
if _, err := svc.Get(context.Background(), "workspace.basePath"); err == nil ||
111-
!strings.Contains(err.Error(), "does not support raw reads") {
112-
t.Fatalf("expected service without raw reads to fail explicitly, got %v", err)
113-
}
114-
}
115-
116104
// setTestHostConfigAdapter swaps the process config adapter for one test case
117105
// and restores the original adapter afterward.
118106
func setTestHostConfigAdapter(t *testing.T, content string) {
@@ -130,13 +118,10 @@ func setTestHostConfigAdapter(t *testing.T, content string) {
130118
})
131119
}
132120

133-
// hostConfigServiceWithoutRawReads satisfies the broad host config service
134-
// contract but intentionally omits GetRaw for dependency-boundary tests.
135-
type hostConfigServiceWithoutRawReads struct {
136-
hostconfigsvc.Service
137-
}
121+
// testRawHostConfigReader reads from the test-scoped GoFrame config adapter.
122+
type testRawHostConfigReader struct{}
138123

139-
// GetWorkspaceBasePath returns a deterministic workspace base path.
140-
func (hostConfigServiceWithoutRawReads) GetWorkspaceBasePath(context.Context) string {
141-
return "/admin"
124+
// GetRaw returns one raw test config value through the active GoFrame adapter.
125+
func (testRawHostConfigReader) GetRaw(ctx context.Context, key string) (*gvar.Var, error) {
126+
return g.Cfg().Get(ctx, key)
142127
}

0 commit comments

Comments
 (0)