mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
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:
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user