Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove FORCE_TTY and FORCE_WATCH #450

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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 .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

defaults:
run:
# GitHub Actions run without a TTY device. This is a workaround to get one,
# based on https://github.com/actions/runner/issues/241#issuecomment-2019042651
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'

on:
push:
branches: [ main ]
Expand Down
2 changes: 1 addition & 1 deletion pkg/boot/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func upLLIR(ctx context.Context, backend be.Backend, ir llir.LLIR, opts UpOption
isRunning := make(chan struct{})
cancellable, cancel := context.WithCancel(ctx)

if opts.Watch && !util.StdoutIsTty() && os.Getenv("LUNCHPAIL_FORCE_WATCH") == "" {
if opts.Watch && !util.StdoutIsTty() {
// if stdout is not a tty, then we can't support
// watch, no matter what the user asked for
fmt.Fprintf(os.Stderr, "Warning: disabling watch mode because stdout is not a tty\n")
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func StdinIsTty() bool {
}

func StdoutIsTty() bool {
return term.IsTerminal(int(os.Stdout.Fd())) || os.Getenv("LUNCHPAIL_FORCE_TTY") != ""
return term.IsTerminal(int(os.Stdout.Fd()))
}
51 changes: 32 additions & 19 deletions tests/bin/pipelines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,23 @@ function actual {
echo "$dir"/"$bb".output.$ext
}

function tester {
cmdline="$1"
function start {
echo
echo "🧪 $(tput setaf 5)Starting Pipeline Test: $(tput bold)$1$(tput sgr0)"
echo -n "$(tput dim)"
}

function validate {
echo -n "$(tput sgr0)"
actual_ec=$1
expected="$2"
actual="$3"
expected_ec=${4:-0}

echo ""
echo "------------------------------------------------------------------------------------"
echo " $(tput bold)Test:$(tput sgr0) $1"
echo " $(tput bold)Expected:$(tput sgr0) $expected"
echo " $(tput bold)Actual:$(tput sgr0) $actual"
echo " $(tput bold)Expected exit code$(tput sgr0): $expected_ec"
echo "------------------------------------------------------------------------------------"
echo "🧪 $(tput setaf 5)Expected: $expected$(tput sgr0)"
echo "🧪 $(tput setaf 5)Actual: $actual$(tput sgr0)"
echo "🧪 $(tput setaf 5)Expected exit code: $expected_ec$(tput sgr0)"

set +e
eval "$1 $input"
actual_ec=$?
set -e
if [[ $actual_ec = $expected_ec ]]
then echo "✅ PASS the exit code matches actual_ec=$actual_ec expected_ec=$expected_ec test=$1"
else echo "❌ FAIL mismatched exit code actual_ec=$actual_ec expected_ec=$expected_ec test=$1" && return 1
Expand All @@ -75,14 +74,28 @@ function tester {
}

lpcat="$lp cat $VERBOSE"
lpcatfinal="LUNCHPAIL_FORCE_TTY=1 $lp cat $VERBOSE"

tester "$lpcatfinal $IN1" "$IN1" $(actual "$IN1") # input should equal output
tester "$lpcatfinal nopenopenopenopenope" n/a n/a 1 # expect failure trying to cat a non-existent file
start "cat"
$lpcat $IN1
validate $? "$IN1" $(actual "$IN1") # input should equal output

start "cat expecting error"
set +e
$lpcat nopenopenopenopenope
validate $? n/a n/a 1
set -e

start "cat | cat"
$lpcat $IN1 | $lpcat
validate $? "$IN1" $(actual "$IN1" .)

tester "$lpcat $IN1 | $lpcatfinal" "$IN1" $(actual "$IN1" .) # cat | cat: input should still equal output
tester "$lpcat $IN1 | $lpcat | $lpcatfinal" "$IN1" $(actual "$IN1" .) # cat | cat | cat: input should still equal output
tester "$lpcat $IN1 | $lpcat | $lpcat | $lpcatfinal" "$IN1" $(actual "$IN1" .) # cat | cat | cat | cat: input should still equal output
start "cat | cat | cat"
$lpcat $IN1 | $lpcat | $lpcat # cat | cat | cat
validate $? "$IN1" $(actual "$IN1" .)

start "cat | cat | cat | cat"
$lpcat $IN1 | $lpcat | $lpcat | $lpcat # cat | cat | cat | cat
validate $? "$IN1" $(actual "$IN1" .)

echo
echo "✅ PASS all pipeline tests have passed!"
6 changes: 0 additions & 6 deletions tests/bin/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ if [[ -n "$taskqueue" ]]
then QUEUE="--queue $taskqueue"
fi

# due to the use of eval, `up` will think it is not attached to a tty
export LUNCHPAIL_FORCE_WATCH=1

# same re: eval... the pipeline/redirect needs to know it is attached to a tty
export LUNCHPAIL_FORCE_TTY=1

echo "Calling up using target=${LUNCHPAIL_TARGET:-kubernetes}"
eval $testapp up \
-v \
Expand Down