Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ func ParseTaskfile(rootPath string) (*ast.Taskfile, error) {
}

func NewTaskExecutor(dir string, verbose bool) *task.Executor {
// On Windows, task runs core utils like mktemp in-process via u-root,
// which falls back to a hardcoded /tmp when TMPDIR is unset.
if os.Getenv("TMPDIR") == "" {
os.Setenv("TMPDIR", os.TempDir())
}

var o io.Writer = os.Stdout
var e io.Writer = os.Stderr
return &task.Executor{
Expand Down
46 changes: 46 additions & 0 deletions pkg/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,49 @@ func TestInstantiateDotEnv_PriorsAsSubstitutionsSkipPrompt(t *testing.T) {
t.Errorf("expected prompted value for OTHER, got %q", got["OTHER"])
}
}

// Regression test for https://github.com/livekit/livekit-cli/issues/911:
// on Windows, task runs mktemp through u-root, which falls back to a
// hardcoded /tmp when TMPDIR is unset.
func TestTaskMktempWithoutTMPDIR(t *testing.T) {
t.Setenv("TMPDIR", "")
os.Unsetenv("TMPDIR")

dir := t.TempDir()
// Mirrors set_agent_name_if_present in livekit-examples/agent-starter-python.
taskfile := `version: '3'
tasks:
mk:
cmds:
- |
tmp="$(mktemp)"
printf 'ok\n' >> "$tmp"
echo "$tmp" > out.txt
`
if err := os.WriteFile(filepath.Join(dir, TaskFile), []byte(taskfile), 0o644); err != nil {
t.Fatal(err)
}

run, err := NewTask(context.Background(), nil, dir, "mk", false)
if err != nil {
t.Fatal(err)
}
if err := run(); err != nil {
t.Fatalf("mktemp task failed: %v", err)
}

out, err := os.ReadFile(filepath.Join(dir, "out.txt"))
if err != nil {
t.Fatal(err)
}
tmp := strings.TrimSpace(string(out))
t.Cleanup(func() { os.Remove(tmp) })
// "/tmp\NNN" can still resolve on Windows if \tmp exists on the current
// drive, so require an absolute path rather than just a usable one.
if !filepath.IsAbs(tmp) {
t.Fatalf("mktemp output %q is not an absolute path", tmp)
}
if got, err := os.ReadFile(tmp); err != nil || string(got) != "ok\n" {
t.Fatalf("temp file %q: got %q, err %v", tmp, got, err)
}
}
Loading