summaryrefslogtreecommitdiff
path: root/internal/askcli/formatter_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-10 22:41:47 +0300
committerPaul Buetow <paul@buetow.org>2026-04-10 22:41:47 +0300
commitbd749f8e9a0eeaa5578a368996f7b93955580a39 (patch)
tree5d2e45a7a155cdecbbc7ee864a35e4818277714e /internal/askcli/formatter_test.go
parentdc71be943e25087905b2b9a4fec2fcf6b6f9925f (diff)
task 20: hide do info UUID unless HEXAI_DEBUG is set
Diffstat (limited to 'internal/askcli/formatter_test.go')
-rw-r--r--internal/askcli/formatter_test.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/internal/askcli/formatter_test.go b/internal/askcli/formatter_test.go
index 61ede0a..e473ed4 100644
--- a/internal/askcli/formatter_test.go
+++ b/internal/askcli/formatter_test.go
@@ -2,10 +2,24 @@ package askcli
import (
"fmt"
+ "os"
"strings"
"testing"
)
+func unsetTestEnv(t *testing.T, key string) {
+ t.Helper()
+ oldValue, hadValue := os.LookupEnv(key)
+ _ = os.Unsetenv(key)
+ t.Cleanup(func() {
+ if !hadValue {
+ _ = os.Unsetenv(key)
+ return
+ }
+ _ = os.Setenv(key, oldValue)
+ })
+}
+
func TestFormatTaskList(t *testing.T) {
tasks := []TaskExport{
{UUID: "uuid-1", Description: "Short task", Status: "pending", Priority: "H", Tags: []string{"cli"}, Urgency: 15.0},
@@ -145,6 +159,7 @@ func TestFormatTaskListForWidth_TruncatesDescriptionWhenTerminalIsNarrow(t *test
}
func TestFormatTaskInfo(t *testing.T) {
+ unsetTestEnv(t, "HEXAI_DEBUG")
task := TaskExport{
UUID: "test-uuid",
Description: "Test description",
@@ -165,8 +180,8 @@ func TestFormatTaskInfo(t *testing.T) {
if !strings.Contains(output, "ID: 0") {
t.Fatalf("FormatTaskInfo missing alias ID: %s", output)
}
- if !strings.Contains(output, "test-uuid") {
- t.Fatalf("FormatTaskInfo missing UUID: %s", output)
+ if strings.Contains(output, "UUID:") || strings.Contains(output, "test-uuid") {
+ t.Fatalf("FormatTaskInfo leaked UUID in default mode: %s", output)
}
if !strings.Contains(output, "H") {
t.Fatalf("FormatTaskInfo missing priority H: %s", output)
@@ -188,6 +203,16 @@ func TestFormatTaskInfo(t *testing.T) {
}
}
+func TestFormatTaskInfo_DebugShowsUUID(t *testing.T) {
+ t.Setenv("HEXAI_DEBUG", "1")
+ task := TaskExport{UUID: "test-uuid", Description: "Test description", Status: "pending", Priority: "H", Urgency: 1}
+
+ output := FormatTaskInfo(task, "0", nil)
+ if !strings.Contains(output, "UUID: test-uuid") {
+ t.Fatalf("FormatTaskInfo missing UUID in debug mode: %s", output)
+ }
+}
+
func TestFormatSuccess(t *testing.T) {
output := FormatSuccess("0")
if !strings.Contains(output, "ok") || !strings.Contains(output, "0") {
@@ -266,6 +291,7 @@ func TestRejectNumericID(t *testing.T) {
}
func TestFormatTaskInfo_NoOptionalFields(t *testing.T) {
+ unsetTestEnv(t, "HEXAI_DEBUG")
task := TaskExport{
UUID: "simple-uuid",
Description: "Simple task",
@@ -275,8 +301,8 @@ func TestFormatTaskInfo_NoOptionalFields(t *testing.T) {
Urgency: 0,
}
output := FormatTaskInfo(task, "0", nil)
- if !strings.Contains(output, "simple-uuid") {
- t.Fatalf("FormatTaskInfo missing UUID: %s", output)
+ if strings.Contains(output, "UUID:") || strings.Contains(output, "simple-uuid") {
+ t.Fatalf("FormatTaskInfo leaked UUID in default mode: %s", output)
}
if !strings.Contains(output, "Started: no") {
t.Fatalf("FormatTaskInfo should show Started: no when not started: %s", output)