Captcha is now the host-stamped X-Bn-Verified-Captcha trusted header (pluginsdk v0.2.2), so no plugin has a legitimate core import left: isForbiddenPluginImport flags ALL first-party prefixes unconditionally, and a block/core require in a plugin go.mod fails as no-block-core-require (always vestigial — imports are already forbidden). Fleet-verified: no plugin imports or requires core. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
197 lines
6.4 KiB
Go
197 lines
6.4 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestCheckCMSCoreSDKGoModFlagsLocalBlockCoreReplace(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "go.mod"), `module git.dev.alexdunmow.com/block/cms
|
|
|
|
go 1.26.2
|
|
|
|
require git.dev.alexdunmow.com/block/core v0.5.0
|
|
|
|
replace git.dev.alexdunmow.com/block/core => ../core
|
|
`, 0644)
|
|
|
|
violations := checkCMSCoreSDKGoMod(root)
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkCMSCoreSDKGoMod() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].rule != "no-local-block-core-replace" {
|
|
t.Fatalf("rule = %q, want no-local-block-core-replace", violations[0].rule)
|
|
}
|
|
if violations[0].line != 7 {
|
|
t.Fatalf("line = %d, want 7", violations[0].line)
|
|
}
|
|
}
|
|
|
|
func TestCheckCMSCoreSDKGoModAllowsPublishedBlockCoreRequire(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "go.mod"), `module git.dev.alexdunmow.com/block/cms
|
|
|
|
go 1.26.2
|
|
|
|
require git.dev.alexdunmow.com/block/core v0.5.0
|
|
`, 0644)
|
|
|
|
violations := checkCMSCoreSDKGoMod(root)
|
|
if len(violations) != 0 {
|
|
t.Fatalf("checkCMSCoreSDKGoMod() returned %d violations, want 0: %#v", len(violations), violations)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginGoModFlagsReplaceDirectives(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "go.mod"), `module example.com/plugin
|
|
|
|
go 1.26.2
|
|
|
|
require git.dev.alexdunmow.com/block/pluginsdk v0.2.1
|
|
|
|
replace git.dev.alexdunmow.com/block/pluginsdk => ../block-pluginsdk
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginGoMod(root, "v0.2.1")
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginGoMod() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].rule != "no-replace-directives" {
|
|
t.Fatalf("rule = %q, want no-replace-directives", violations[0].rule)
|
|
}
|
|
if violations[0].line != 7 {
|
|
t.Fatalf("line = %d, want 7", violations[0].line)
|
|
}
|
|
}
|
|
|
|
// A replace directive for the coexisting block/core module still fails —
|
|
// replace directives of any module are forbidden in standalone plugin repos.
|
|
func TestCheckStandalonePluginGoModFlagsCoreReplaceDirective(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "go.mod"), `module example.com/plugin
|
|
|
|
go 1.26.2
|
|
|
|
require git.dev.alexdunmow.com/block/pluginsdk v0.2.1
|
|
|
|
replace git.dev.alexdunmow.com/block/core => ../block-core
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginGoMod(root, "v0.2.1")
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginGoMod() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].rule != "no-replace-directives" {
|
|
t.Fatalf("rule = %q, want no-replace-directives", violations[0].rule)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginGoModFlagsOutdatedSDKVersion(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "go.mod"), `module example.com/plugin
|
|
|
|
go 1.26.2
|
|
|
|
require git.dev.alexdunmow.com/block/pluginsdk v0.2.0
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginGoMod(root, "v0.2.1")
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginGoMod() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].rule != "pluginsdk-version-mismatch" {
|
|
t.Fatalf("rule = %q, want pluginsdk-version-mismatch", violations[0].rule)
|
|
}
|
|
if !strings.Contains(violations[0].detail, "want v0.2.1") {
|
|
t.Fatalf("detail = %q, want target version", violations[0].detail)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginGoModFlagsMissingPluginSDKRequire(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "go.mod"), `module example.com/plugin
|
|
|
|
go 1.26.2
|
|
|
|
require github.com/google/uuid v1.6.0
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginGoMod(root, "v0.2.1")
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginGoMod() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].rule != "missing-pluginsdk-require" {
|
|
t.Fatalf("rule = %q, want missing-pluginsdk-require", violations[0].rule)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginGoModAllowsMatchingSDKVersionWithoutReplace(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "go.mod"), `module example.com/plugin
|
|
|
|
go 1.26.2
|
|
|
|
require git.dev.alexdunmow.com/block/pluginsdk v0.2.1
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginGoMod(root, "v0.2.1")
|
|
if len(violations) != 0 {
|
|
t.Fatalf("checkStandalonePluginGoMod() returned %d violations, want 0: %#v", len(violations), violations)
|
|
}
|
|
}
|
|
|
|
// The former captcha/backup coexistence is over (captcha = host-stamped
|
|
// trusted header since pluginsdk v0.2.2): a block/core require in a
|
|
// standalone plugin go.mod is always vestigial and now fails the gate.
|
|
func TestCheckStandalonePluginGoModFlagsCoreRequire(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "go.mod"), `module example.com/plugin
|
|
|
|
go 1.26.2
|
|
|
|
require (
|
|
git.dev.alexdunmow.com/block/core v0.5.0
|
|
git.dev.alexdunmow.com/block/pluginsdk v0.2.1
|
|
)
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginGoMod(root, "v0.2.1")
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginGoMod() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].rule != "no-block-core-require" {
|
|
t.Fatalf("rule = %q, want no-block-core-require", violations[0].rule)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginGoModSkipsCodelessRepo(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "plugin.mod"), "[plugin]\nname = \"fixture\"\nversion = \"0.1.0\"\n", 0644)
|
|
writeTestFile(t, filepath.Join(root, "blocks", "blocks.yaml"), "blocks: []\n", 0644)
|
|
|
|
if !isCodelessPluginRepo(root) {
|
|
t.Fatal("isCodelessPluginRepo() = false, want true for plugin.mod with no root Go source")
|
|
}
|
|
violations := checkStandalonePluginGoMod(root, "v0.2.1")
|
|
if len(violations) != 0 {
|
|
t.Fatalf("checkStandalonePluginGoMod() returned %d violations, want 0 for codeless repo: %#v", len(violations), violations)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginGoModStillRequiresGoModWithRootGoSource(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "plugin.mod"), "[plugin]\nname = \"fixture\"\nversion = \"0.1.0\"\n", 0644)
|
|
writeTestFile(t, filepath.Join(root, "main.go"), "package main\nfunc main() {}\n", 0644)
|
|
|
|
if isCodelessPluginRepo(root) {
|
|
t.Fatal("isCodelessPluginRepo() = true, want false with root Go source")
|
|
}
|
|
violations := checkStandalonePluginGoMod(root, "v0.2.1")
|
|
if len(violations) != 1 || violations[0].rule != "missing-go-mod" {
|
|
t.Fatalf("checkStandalonePluginGoMod() = %#v, want single missing-go-mod violation", violations)
|
|
}
|
|
}
|