Standalone plugins now build against git.dev.alexdunmow.com/block/pluginsdk. Check 2c requires a pluginsdk module require (rule missing-pluginsdk-require) and enforces its version against the CMS anchor (rule pluginsdk-version-mismatch) once the CMS migrates; a coexisting block/core require stays allowed (calcomblock keeps core for captcha). - check_sdkboundaries.go: degrade the 2c OK message gracefully when the pluginsdk version anchor is empty (transition period) — omit the version clause instead of printing "SDK version ". - check_rbac.go: document pluginsdk in the definitions-only module comment. - plugin_sdk_versions_test.go: retarget fixtures to pluginsdk; add cases for missing-pluginsdk-require, pluginsdk-version-mismatch, a forbidden core replace directive, and an allowed coexisting core require. - lint_test.go: synthesized plugin repos now require pluginsdk (replace- directive case replaces pluginsdk). - registry_test.go: add checks 30 and 31 to the canonical order (were added to the registry without updating this test). - golden: regenerate — check count 32 -> 34 (checks 30/31 SKIP in fixtures). - README.md: describe 2c as the pluginsdk boundary. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
90 lines
3.6 KiB
Go
90 lines
3.6 KiB
Go
package main
|
|
|
|
func init() {
|
|
register(Check{
|
|
Seq: 22,
|
|
ID: "2c",
|
|
Title: "Standalone plugin SDK import boundaries",
|
|
Run: func(ctx *ScanContext, rep *Reporter) {
|
|
var cmsGoModViolations []pluginGoModViolation
|
|
var pluginImportViolations []pluginImportViolation
|
|
var pluginGoModViolations []pluginGoModViolation
|
|
var standalonePluginLabels []string
|
|
checkedStandalonePluginRoots := make(map[string]bool)
|
|
// Version anchor = the CMS backend's pluginsdk pin; empty (skip
|
|
// version enforcement) until the CMS itself migrates to pluginsdk.
|
|
requiredSDKVersion, requiredSDKVersionErr := currentCMSPluginSDKVersion()
|
|
if requiredSDKVersionErr != nil {
|
|
rep.Fatal("failed to resolve CMS SDK version: %v", requiredSDKVersionErr)
|
|
}
|
|
checkStandalonePluginRoot := func(root string, label string) {
|
|
if checkedStandalonePluginRoots[root] || !shouldCheckStandalonePluginImports(root) {
|
|
return
|
|
}
|
|
checkedStandalonePluginRoots[root] = true
|
|
standalonePluginLabels = append(standalonePluginLabels, label)
|
|
for _, v := range checkStandalonePluginImports(root) {
|
|
v.file = prefixDisplayPath(label, v.file)
|
|
pluginImportViolations = append(pluginImportViolations, v)
|
|
}
|
|
for _, v := range checkStandalonePluginGoMod(root, requiredSDKVersion) {
|
|
v.file = prefixDisplayPath(label, v.file)
|
|
pluginGoModViolations = append(pluginGoModViolations, v)
|
|
}
|
|
}
|
|
for _, target := range ctx.backendTargets {
|
|
// A codeless plugin repo (plugin.mod, no Go) has no go.mod by
|
|
// design — nothing for the replace-directive check to parse.
|
|
if samePath(target.root, ctx.backendDir) && !isCodelessPluginRepo(target.root) {
|
|
for _, v := range checkCMSCoreSDKGoMod(target.root) {
|
|
v.file = prefixDisplayPath(target.displayOrRoot(), v.file)
|
|
cmsGoModViolations = append(cmsGoModViolations, v)
|
|
}
|
|
}
|
|
checkStandalonePluginRoot(target.root, target.displayOrRoot())
|
|
}
|
|
for _, target := range ctx.pluginTargets {
|
|
checkStandalonePluginRoot(target.root, target.display)
|
|
}
|
|
if len(cmsGoModViolations) > 0 || len(pluginImportViolations) > 0 || len(pluginGoModViolations) > 0 {
|
|
if len(cmsGoModViolations) > 0 {
|
|
rep.Fail("%d CMS backend go.mod violation(s)", len(cmsGoModViolations))
|
|
for _, v := range cmsGoModViolations {
|
|
if v.line > 0 {
|
|
rep.Findingf("%s:%d [%s] %s", v.file, v.line, v.rule, v.detail)
|
|
continue
|
|
}
|
|
rep.Findingf("%s [%s] %s", v.file, v.rule, v.detail)
|
|
}
|
|
}
|
|
if len(pluginImportViolations) > 0 {
|
|
rep.Fail("%d standalone plugin import violation(s)", len(pluginImportViolations))
|
|
for _, v := range pluginImportViolations {
|
|
rep.Findingf("%s:%d imports BlockNinja CMS package %q", v.file, v.line, v.importPath)
|
|
}
|
|
}
|
|
if len(pluginGoModViolations) > 0 {
|
|
rep.Fail("%d standalone plugin go.mod violation(s)", len(pluginGoModViolations))
|
|
for _, v := range pluginGoModViolations {
|
|
if v.line > 0 {
|
|
rep.Findingf("%s:%d [%s] %s", v.file, v.line, v.rule, v.detail)
|
|
continue
|
|
}
|
|
rep.Findingf("%s [%s] %s", v.file, v.rule, v.detail)
|
|
}
|
|
}
|
|
} else if len(standalonePluginLabels) > 0 {
|
|
if requiredSDKVersion != "" {
|
|
rep.OK("Standalone plugin imports and go.mod stay on SDK version %s", requiredSDKVersion)
|
|
} else {
|
|
rep.OK("Standalone plugin imports and go.mod build against the plugin SDK")
|
|
}
|
|
} else if ctx.includeCoreTargets {
|
|
rep.OK("%s/go.mod does not locally replace %s", ctx.backendTargets[0].displayOrRoot(), blockCoreImportPrefix)
|
|
} else {
|
|
rep.Skip("no standalone plugin roots scanned")
|
|
}
|
|
},
|
|
})
|
|
}
|