fix(34): WR-01 keep summer build working for frameworks before party.Describe

summer build always emitted party.Describe and []party.Info, so an
application whose framework requirement predates v0.6.0 stopped compiling
once the CLI was updated. The build now checks the party package go list
resolves in the application (a static look for Describe and Info, not a
version compare, since a local checkout reports the previous tag until
it is tagged) and, when they are missing, writes main.go and
plugins.gen.go exactly as before, with a warning to move the framework
to v0.6.0. An unresolvable party package keeps the current sources.
This commit is contained in:
Jakub Zych
2026-10-29 22:03:57 +01:00
parent 9b72439533
commit 07673e4f30
4 changed files with 180 additions and 4 deletions

View File

@@ -301,3 +301,68 @@ func TestEffectiveFramework(t *testing.T) {
}
})
}
// TestLegacyFramework pins WR-01: an application whose framework has no
// party.Describe (before v0.6.0) gets the sources summer build wrote
// before, without the plugin metadata, so it still compiles.
func TestLegacyFramework(t *testing.T) {
ctx := t.Context()
app := func(t *testing.T, partySrc string) string {
t.Helper()
root := t.TempDir()
fw := filepath.Join(root, "framework")
writeAll(t, filepath.Join(fw, "go.mod"), "module "+frameworkModule+"\n\ngo 1.27.0\n")
writeAll(t, filepath.Join(fw, "modules", "party", "party.go"), partySrc)
writeAll(t, filepath.Join(fw, "modules", "party", "party_test.go"), "package party\n\nfunc Describe() {}\n\ntype Info struct{}\n")
dir := filepath.Join(root, "app")
writeAll(t, filepath.Join(dir, "go.mod"), "module example.test/app\n\ngo 1.27.0\n\nrequire "+frameworkModule+" v0.5.3\n\nreplace "+frameworkModule+" => ../framework\n")
return dir
}
m := Manifest{Module: "example.test/app", Binary: "app", Plugins: []Plugin{{ID: "acme.blog", Module: "example.test/blog"}}}
t.Run("before party.Describe", func(t *testing.T) {
meta, warnings := resolveBuildMeta(ctx, app(t, "package party\n\nfunc Activate() {}\n"), Manifest{Module: "example.test/app", Binary: "app"})
if !meta.Legacy || len(warnings) != 1 || !strings.Contains(warnings[0], "has no party.Describe") || !strings.Contains(warnings[0], "v0.6.0") {
t.Fatalf("meta %+v, warnings %q", meta, warnings)
}
mainSrc, err := generateMainFor(m, !meta.Legacy)
if err != nil {
t.Fatal(err)
}
gen, err := generatePluginsGen(m, meta)
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(mainSrc), "party.Describe") || !strings.Contains(string(mainSrc), "party.Activate(app, PluginIDs)") {
t.Errorf("main.go:\n%s", mainSrc)
}
want := "// Code generated by summer build. DO NOT EDIT.\n\npackage main\n\nimport (\n\t_ \"example.test/blog\"\n)\n\n" +
"// PluginIDs is the ordered plugin list from summer.yaml.\nvar PluginIDs = []string{\n\t\"acme.blog\",\n}\n"
if string(gen) != want {
t.Errorf("plugins.gen.go:\n%s\nwant:\n%s", gen, want)
}
})
t.Run("with party.Describe", func(t *testing.T) {
src := "package party\n\ntype Info struct{ ID string }\n\nfunc Describe(any, []Info, string) error { return nil }\n"
meta, warnings := resolveBuildMeta(ctx, app(t, src), Manifest{Module: "example.test/app", Binary: "app"})
if meta.Legacy {
t.Fatalf("meta %+v, warnings %q", meta, warnings)
}
mainSrc, err := generateMainFor(m, !meta.Legacy)
if err != nil || !strings.Contains(string(mainSrc), "party.Describe(app, PluginInfo, FrameworkVersion)") {
t.Errorf("main.go: %v\n%s", err, mainSrc)
}
})
t.Run("unresolvable party package keeps the current sources", func(t *testing.T) {
orig := listPackages
listPackages = func(context.Context, string, []string) ([]listedPackage, error) {
return nil, os.ErrPermission
}
t.Cleanup(func() { listPackages = orig })
if !frameworkDescribes(ctx, t.TempDir()) {
t.Error("a failing go list switched to the legacy sources")
}
})
}