26f897c1ec
release / release-please (push) Failing after 1m49s
docs / build (push) Failing after 6m34s
release / build-and-upload (arm64, linux) (push) Has been cancelled
release / build-and-upload (arm64, windows) (push) Has been cancelled
release / build-darwin (amd64, darwin) (push) Has been cancelled
release / checksums (push) Has been cancelled
release / finalize (push) Has been cancelled
release / build-darwin (arm64, darwin) (push) Has been cancelled
release / build-and-upload (amd64, linux) (push) Has been cancelled
release / build-and-upload (amd64, windows) (push) Has been cancelled
docs / deploy (push) Has been cancelled
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// fixtureDir returns the agent's fixture directory if FAKEAGENT_FIXTURE
|
|
// is set, e.g.
|
|
// FAKEAGENT_FIXTURE=internal/e2e/fixtures + agent=claude →
|
|
// internal/e2e/fixtures/claude. Returns "" if no fixture is configured.
|
|
func fixtureDir(agent string) string {
|
|
root := os.Getenv("FAKEAGENT_FIXTURE")
|
|
if root == "" {
|
|
return ""
|
|
}
|
|
return filepath.Join(root, agent)
|
|
}
|
|
|
|
// readFixtureFile reads a file from the fixture directory. The flavour
|
|
// arg picks between recorded variants ("structured" vs "plain"). Returns
|
|
// (nil, nil) only when fixture mode is not configured.
|
|
func readFixtureFile(dir, flavour, name string) ([]byte, error) {
|
|
if dir == "" {
|
|
return nil, nil
|
|
}
|
|
// Try <dir>/<flavour>/<name> first (opencode layout), then
|
|
// <dir>/<flavour>.<ext> (claude/codex layout where flavour is
|
|
// the file basename and name carries the extension).
|
|
candidates := []string{
|
|
filepath.Join(dir, flavour, name),
|
|
filepath.Join(dir, flavour+filepath.Ext(name)),
|
|
}
|
|
for _, p := range candidates {
|
|
data, err := os.ReadFile(p)
|
|
if err == nil {
|
|
return data, nil
|
|
}
|
|
if !os.IsNotExist(err) {
|
|
return nil, fmt.Errorf("read fixture %s: %w", p, err)
|
|
}
|
|
}
|
|
return nil, fmt.Errorf("missing fixture for %s/%s (%s)", filepath.Base(dir), flavour, strings.Join(candidates, ", "))
|
|
}
|