From 01fe71d7db128fdf61c043fcee683420e04b051b Mon Sep 17 00:00:00 2001 From: HanShaoshuai-k Date: Thu, 28 May 2026 18:56:36 +0800 Subject: [PATCH] fix(config): allow lark-channel bind source override (#1154) Change-Id: I406ea13e372e6bdd5f3d9d6210b04ebdf0354182 --- cmd/config/binder.go | 8 +++++--- cmd/config/binder_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/cmd/config/binder.go b/cmd/config/binder.go index 8a942667..c0608d6d 100644 --- a/cmd/config/binder.go +++ b/cmd/config/binder.go @@ -389,10 +389,12 @@ func resolveHermesEnvPath() string { } // resolveLarkChannelConfigPath returns the path to lark-channel-bridge's -// config.json. Mirrors the bridge's src/config/paths.ts which hardcodes -// ~/.lark-channel/config.json with no env override — multi-instance is not -// a supported scenario today. +// source config. LARK_CHANNEL_CONFIG lets a host point bind at a projected +// single-account config without changing lark-cli's target config directory. func resolveLarkChannelConfigPath() string { + if p := os.Getenv("LARK_CHANNEL_CONFIG"); strings.TrimSpace(p) != "" { + return expandHome(p) + } home, err := vfs.UserHomeDir() if err != nil || home == "" { fmt.Fprintf(os.Stderr, "warning: unable to determine home directory: %v\n", err) diff --git a/cmd/config/binder_test.go b/cmd/config/binder_test.go index febc994d..c86dc35b 100644 --- a/cmd/config/binder_test.go +++ b/cmd/config/binder_test.go @@ -4,6 +4,7 @@ package config import ( + "path/filepath" "reflect" "testing" @@ -173,3 +174,27 @@ func TestSelectCandidate_AppIDFlag_WinsOverTUI(t *testing.T) { } assertCandidate(t, got, Candidate{AppID: "cli_b"}) } + +func TestResolveLarkChannelConfigPath_Default(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("LARK_CHANNEL_CONFIG", "") + + got := resolveLarkChannelConfigPath() + want := filepath.Join(home, ".lark-channel", "config.json") + if got != want { + t.Fatalf("resolveLarkChannelConfigPath() = %q, want %q", got, want) + } +} + +func TestResolveLarkChannelConfigPath_EnvOverride(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("LARK_CHANNEL_CONFIG", "~/bridge/projection.json") + + got := resolveLarkChannelConfigPath() + want := filepath.Join(home, "bridge", "projection.json") + if got != want { + t.Fatalf("resolveLarkChannelConfigPath() = %q, want %q", got, want) + } +}