test(agent): avoid os.Chdir in builtin skill cache test

This commit is contained in:
pikaxinge 2026-02-28 04:20:38 +00:00
parent ae7d36d965
commit 2ab92fa6c6
2 changed files with 8 additions and 14 deletions

View file

@ -46,8 +46,11 @@ func getGlobalConfigDir() string {
func NewContextBuilder(workspace string) *ContextBuilder { func NewContextBuilder(workspace string) *ContextBuilder {
// builtin skills: skills directory in current project // builtin skills: skills directory in current project
// Use the skills/ directory under the current working directory // Use the skills/ directory under the current working directory
wd, _ := os.Getwd() builtinSkillsDir := strings.TrimSpace(os.Getenv("PICOCLAW_BUILTIN_SKILLS"))
builtinSkillsDir := filepath.Join(wd, "skills") if builtinSkillsDir == "" {
wd, _ := os.Getwd()
builtinSkillsDir = filepath.Join(wd, "skills")
}
globalSkillsDir := filepath.Join(getGlobalConfigDir(), "skills") globalSkillsDir := filepath.Join(getGlobalConfigDir(), "skills")
return &ContextBuilder{ return &ContextBuilder{

View file

@ -439,7 +439,7 @@ description: global-v2
} }
// TestBuiltinSkillFileContentChange verifies that modifying a builtin skill // TestBuiltinSkillFileContentChange verifies that modifying a builtin skill
// ({cwd}/skills) invalidates the cached system prompt. // invalidates the cached system prompt.
func TestBuiltinSkillFileContentChange(t *testing.T) { func TestBuiltinSkillFileContentChange(t *testing.T) {
tmpHome := t.TempDir() tmpHome := t.TempDir()
t.Setenv("HOME", tmpHome) t.Setenv("HOME", tmpHome)
@ -448,18 +448,9 @@ func TestBuiltinSkillFileContentChange(t *testing.T) {
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
builtinRoot := t.TempDir() builtinRoot := t.TempDir()
oldWD, err := os.Getwd() t.Setenv("PICOCLAW_BUILTIN_SKILLS", builtinRoot)
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(builtinRoot); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
_ = os.Chdir(oldWD)
})
builtinSkillPath := filepath.Join(builtinRoot, "skills", "builtin-skill", "SKILL.md") builtinSkillPath := filepath.Join(builtinRoot, "builtin-skill", "SKILL.md")
if err := os.MkdirAll(filepath.Dir(builtinSkillPath), 0o755); err != nil { if err := os.MkdirAll(filepath.Dir(builtinSkillPath), 0o755); err != nil {
t.Fatal(err) t.Fatal(err)
} }