Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion config/k3s/activate-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ fi

mkdir -p "$HOME/.kube"

SCP_ERR=$(mktemp)
trap 'rm -f "$SCP_ERR"' EXIT

if scp -o ConnectTimeout=5 -o BatchMode=yes \
"${REMOTE_HOST}:${REMOTE_KUBECONFIG_PATH}" "$LOCAL_KUBECONFIG" 2>/dev/null; then
"${REMOTE_HOST}:${REMOTE_KUBECONFIG_PATH}" "$LOCAL_KUBECONFIG" 2>"$SCP_ERR"; then
chmod 600 "$LOCAL_KUBECONFIG"
echo "k3s-client: kubeconfig synced from ${REMOTE_HOST}"
else
echo "k3s-client: failed to fetch kubeconfig from ${REMOTE_HOST}" >&2
sed 's/^/k3s-client: /' "$SCP_ERR" >&2
fi
12 changes: 12 additions & 0 deletions spec/activate_k3s_client_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ When run bash -c "grep 'chmod 600' '$SCRIPT'"
The output should include 'chmod 600'
End
End

Describe 'failure visibility'
It 'does not silently discard scp stderr'
When run bash -c "grep 'scp ' '$SCRIPT'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test 'does not silently discard scp stderr' is currently ineffective. Because grep 'scp ' only returns the first line of the multi-line scp command, it does not see the redirection (which was on the following line due to the backslash). Consequently, this test would pass even if 2>/dev/null were still present in the script. Using grep -A 1 ensures the redirection line is included in the check.

Suggested change
When run bash -c "grep 'scp ' '$SCRIPT'"
When run bash -c "grep -A 1 'scp ' '$SCRIPT'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This regression test only greps the first line of the multi-line scp invocation, so it can miss a reintroduced 2>/dev/null on the continuation line. Include the following line (or scan the whole script) before asserting stderr is not discarded.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At spec/activate_k3s_client_spec.sh, line 50:

<comment>This regression test only greps the first line of the multi-line `scp` invocation, so it can miss a reintroduced `2>/dev/null` on the continuation line. Include the following line (or scan the whole script) before asserting stderr is not discarded.</comment>

<file context>
@@ -44,4 +44,16 @@ When run bash -c "grep 'chmod 600' '$SCRIPT'"
+
+Describe 'failure visibility'
+It 'does not silently discard scp stderr'
+When run bash -c "grep 'scp ' '$SCRIPT'"
+The output should not include '2>/dev/null'
+End
</file context>
Suggested change
When run bash -c "grep 'scp ' '$SCRIPT'"
When run bash -c "grep -A 1 'scp ' '$SCRIPT'"

The output should not include '2>/dev/null'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression test is too narrow to catch a recurrence: this assertion only looks at lines containing scp (the if scp ... line), but the original 2>/dev/null was on the continuation line "${REMOTE_HOST}:..." "$LOCAL_KUBECONFIG" 2>/dev/null; then — which has no scp token. Reintroducing the bug in the same shape would leave this grep output unchanged and the test would still pass.

Consider checking the whole script instead, e.g.:

It 'does not silently discard scp stderr'
When run bash -c "! grep -n '2>/dev/null' '$SCRIPT'"
The status should be success
End

or a multi-line grep that spans the scp invocation (grep -Pzo 'scp[^;]*2>/dev/null').

End

It 'logs scp failures to stderr'
When run bash -c "grep 'failed to fetch kubeconfig' '$SCRIPT'"
The output should include 'failed to fetch kubeconfig'
End
End
End
Loading