main
sh 51 lines 1.65 KB
Raw
1 #!/bin/bash
2 # Copyright 2026 Google LLC
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # set -e # Don't exit on error so we can capture the failure
17
18 # Integration Test: Variable Persistence
19 # Verifies if variables defined in one 'colab exec' call persist in the next.
20
21 SESSION_NAME="repro-persist-$(date +%s)"
22
23 # Cleanup on exit
24 cleanup() {
25 echo "[*] Cleaning up..."
26 colab stop -s "$SESSION_NAME" || true
27 }
28 trap cleanup EXIT
29
30 echo "[*] Starting session..."
31 colab new -s "$SESSION_NAME"
32
33 echo "[*] Phase 1: Defining variable 'eric'..."
34 echo 'eric = "present"' | colab exec -s "$SESSION_NAME"
35
36 echo "[*] Phase 2: Attempting to access 'eric'..."
37 # If this fails, it will return exit code 0 but print a Traceback to stderr
38 OUTPUT=$(echo 'print(f"Value of eric: {eric}")' | colab exec -s "$SESSION_NAME" 2>&1)
39
40 echo "[*] Result:"
41 echo "$OUTPUT"
42
43 if echo "$OUTPUT" | grep -q "NameError: name 'eric' is not defined"; then
44 echo "[FAILURE] Variable persistence failed (NameError detected)."
45 exit 1
46 elif echo "$OUTPUT" | grep -q "Value of eric: present"; then
47 echo "[SUCCESS] Variable persistence verified."
48 else
49 echo "[UNKNOWN] Unexpected output format."
50 exit 1
51 fi