From 827edcb0da6f47dbbef1a66b800dbb86b465f6a5 Mon Sep 17 00:00:00 2001
From: decentral1se <cellarspoon@riseup.net>
Date: Thu, 18 Jul 2024 11:02:46 +0200
Subject: [PATCH] test: full width for CI testing [ci skip]

Also clean up the .env.sample.
---
 .envrc.sample              | 10 +++++-----
 pkg/formatter/formatter.go | 28 ++++++++++++++++++++--------
 scripts/tests/run-ci-int   |  1 +
 3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/.envrc.sample b/.envrc.sample
index 3f8d827c10..e889aecbc2 100644
--- a/.envrc.sample
+++ b/.envrc.sample
@@ -1,7 +1,7 @@
-go env -w GOPRIVATE=coopcloud.tech
-
-# export PASSWORD_STORE_DIR=$(pwd)/../../autonomic/passwords/passwords/
-
+# integration test suite
 # export ABRA_DIR="$HOME/.abra_test"
 # export ABRA_TEST_DOMAIN=test.example.com
-# export ABRA_SKIP_TEARDOWN=1 # for faster feedback when developing tests
+# export ABRA_CI=1
+
+# release automation
+# export GITEA_TOKEN=
diff --git a/pkg/formatter/formatter.go b/pkg/formatter/formatter.go
index 61de2c8886..569695139c 100644
--- a/pkg/formatter/formatter.go
+++ b/pkg/formatter/formatter.go
@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"encoding/json"
 	"fmt"
+	"os"
 	"strings"
 	"time"
 
@@ -42,22 +43,33 @@ func HumanDuration(timestamp int64) string {
 
 // CreateTable prepares a table layout for output.
 func CreateTable() (*table.Table, error) {
+	table := table.New().
+		Border(lipgloss.ThickBorder()).
+		BorderStyle(
+			lipgloss.NewStyle().
+				Foreground(lipgloss.Color("63")),
+		)
+
+	if isAbraCI, ok := os.LookupEnv("ABRA_CI"); ok && isAbraCI == "1" {
+		// NOTE(d1): no width limits for CI testing since we test against outputs
+		log.Debug("detected ABRA_CI=1")
+		return table, nil
+	}
+
 	width, _, err := term.GetSize(0)
 	if err != nil {
 		return nil, err
 	}
 
 	if width-10 < 79 {
-		width = 79
+		// NOTE(d1): maintain standard minimum width
+		table.Width(79)
+	} else {
+		// NOTE(d1): tests show that this produces stable border drawing
+		table.Width(width - 10)
 	}
 
-	return table.New().
-		Width(width - 10).
-		Border(lipgloss.ThickBorder()).
-		BorderStyle(
-			lipgloss.NewStyle().
-				Foreground(lipgloss.Color("63")),
-		), nil
+	return table, nil
 }
 
 // ToJSON converts a lipgloss.Table to JSON representation. It's not a robust
diff --git a/scripts/tests/run-ci-int b/scripts/tests/run-ci-int
index 4964e4391a..d131b6f38f 100755
--- a/scripts/tests/run-ci-int
+++ b/scripts/tests/run-ci-int
@@ -72,6 +72,7 @@ echo "========================================================================"
 export ABRA_DIR="$HOME/.abra_test"
 export TERM=xterm
 export TEST_SERVER=default
+export ABRA_CI=1
 
 rm -rf "$ABRA_DIR"
 bats -Tp tests/integration --filter-tags \!dns --print-output-on-failure