fix: use immediate parent dir for main.go extension names

deriveExtensionName was using the full directory path (e.g.
examples/extensions/kit-telegram) to derive the display name for
main.go extensions, producing verbose names like 'Examples Extensions
Kit Telegram Extension'. Now uses filepath.Base(dir) so only the
immediate parent directory is used, giving 'Kit Telegram Extension'.

Also fix TestLoadExtensions_SkipsBadFiles which was flaky when
globally-installed git packages existed — isolate the test from the
host environment by overriding XDG_CONFIG_HOME, XDG_DATA_HOME, and
the working directory.
This commit is contained in:
Ed Zynda
2026-03-18 17:36:06 +03:00
parent caa6d1c178
commit 8b7be8b735
2 changed files with 11 additions and 2 deletions
+9
View File
@@ -304,6 +304,15 @@ func Init(api ext.API) {
func TestLoadExtensions_SkipsBadFiles(t *testing.T) {
dir := t.TempDir()
// Isolate from host environment so globally-installed extensions
// are not discovered alongside the test fixtures.
isolated := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", filepath.Join(isolated, "config"))
t.Setenv("XDG_DATA_HOME", filepath.Join(isolated, "data"))
origWd, _ := os.Getwd()
_ = os.Chdir(isolated)
t.Cleanup(func() { _ = os.Chdir(origWd) })
// Good extension
good := `package main
import "kit/ext"
+2 -2
View File
@@ -383,8 +383,8 @@ func deriveExtensionName(relPath string, isMain bool) string {
base := filepath.Base(relPath)
if isMain && dir != "." {
// Use directory name for main.go files
name := strings.ReplaceAll(dir, "/", " ")
// Use immediate parent directory name for main.go files
name := filepath.Base(dir)
name = strings.ReplaceAll(name, "_", " ")
name = strings.ReplaceAll(name, "-", " ")
return cases.Title(language.English).String(name) + " Extension"