gitarsenal-cli 1.5.3 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Test Modal Authentication
4
-
5
- This script tests different approaches to authenticate with Modal.
6
- """
7
-
8
- import os
9
- import sys
10
- import json
11
- from pathlib import Path
12
- import time
13
-
14
- # Try to get tokens from the proxy server
15
- try:
16
- # First, try to import the fetch_modal_tokens module
17
- from fetch_modal_tokens import get_tokens
18
- TOKEN_ID, TOKEN_SECRET = get_tokens()
19
- print(f"✅ Using tokens from proxy server or defaults")
20
- except ImportError:
21
- # If the module is not available, use hardcoded tokens
22
- print(f"⚠️ Using hardcoded tokens")
23
-
24
- # Set tokens directly in environment
25
- os.environ["MODAL_TOKEN_ID"] = TOKEN_ID
26
- os.environ["MODAL_TOKEN_SECRET"] = TOKEN_SECRET
27
-
28
- # Print environment variables
29
- print(f"Environment variables:")
30
- print(f"MODAL_TOKEN_ID = {os.environ.get('MODAL_TOKEN_ID')}")
31
- print(f"MODAL_TOKEN_SECRET = {os.environ.get('MODAL_TOKEN_SECRET')}")
32
-
33
- # Create token file
34
- modal_dir = Path.home() / ".modal"
35
- modal_dir.mkdir(exist_ok=True)
36
- token_file = modal_dir / "token.json"
37
- with open(token_file, 'w') as f:
38
- # Use the correct format with token_id and token_secret
39
- token_data = {
40
- "token_id": TOKEN_ID,
41
- "token_secret": TOKEN_SECRET
42
- }
43
- json.dump(token_data, f)
44
- print(f"Created token file at {token_file}")
45
- print(f"Token file contents: {json.dumps(token_data)}")
46
-
47
- # Create .modalconfig file
48
- modalconfig_file = Path.home() / ".modalconfig"
49
- with open(modalconfig_file, 'w') as f:
50
- f.write(f"token_id = {TOKEN_ID}\n")
51
- f.write(f"token_secret = {TOKEN_SECRET}\n")
52
- print(f"Created .modalconfig file at {modalconfig_file}")
53
-
54
- # Try to import Modal
55
- print("\nTrying to import Modal...")
56
- try:
57
- import modal
58
- print("✅ Successfully imported Modal")
59
- except Exception as e:
60
- print(f"❌ Error importing Modal: {e}")
61
-
62
- # Try to create a simple Modal app
63
- print("\nTrying to create a Modal app...")
64
- try:
65
- app = modal.App("test-auth")
66
- print("✅ Successfully created Modal app")
67
- except Exception as e:
68
- print(f"❌ Error creating Modal app: {e}")
69
-
70
- # Try to create a simple Modal function
71
- print("\nTrying to create a Modal function...")
72
- try:
73
- @app.function()
74
- def hello():
75
- return "Hello, world!"
76
-
77
- print("✅ Successfully created Modal function")
78
- except Exception as e:
79
- print(f"❌ Error creating Modal function: {e}")
80
-
81
- # Try to run the function
82
- print("\nTrying to run the Modal function...")
83
- try:
84
- with app.run():
85
- result = hello.remote()
86
- print(f"✅ Successfully ran Modal function: {result}")
87
- except Exception as e:
88
- print(f"❌ Error running Modal function: {e}")
89
-
90
- print("\nDone testing Modal authentication.")
@@ -1,256 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Test Modal Token Cleanup
4
-
5
- This script tests the Modal token cleanup functionality by:
6
- 1. Setting up a Modal token
7
- 2. Verifying the token exists in environment and files
8
- 3. Cleaning up the token
9
- 4. Verifying the token has been removed
10
- """
11
-
12
- import os
13
- import sys
14
- import json
15
- from pathlib import Path
16
- import time
17
-
18
- # Add the parent directory to the path so we can import our modules
19
- parent_dir = Path(__file__).parent.absolute()
20
- sys.path.append(str(parent_dir))
21
-
22
- # Import our cleanup function
23
- from test_modalSandboxScript import cleanup_modal_token
24
-
25
- def setup_test_token():
26
- """Set up a test Modal token in environment and files"""
27
- print("🔧 Setting up test Modal token...")
28
-
29
- # Set test token in environment variables
30
- test_token = "ak-testtoken12345"
31
- os.environ["MODAL_TOKEN_ID"] = test_token
32
- os.environ["MODAL_TOKEN"] = test_token
33
- os.environ["MODAL_TOKEN_SECRET"] = "as-testsecret12345"
34
-
35
- # Create token files
36
- modal_dir = Path.home() / ".modal"
37
- modal_dir.mkdir(exist_ok=True)
38
-
39
- # Create token.json
40
- token_file = modal_dir / "token.json"
41
- with open(token_file, 'w') as f:
42
- token_data = {
43
- "token_id": test_token,
44
- "token_secret": "as-testsecret12345"
45
- }
46
- json.dump(token_data, f)
47
-
48
- # Create token_alt.json
49
- token_alt_file = modal_dir / "token_alt.json"
50
- with open(token_alt_file, 'w') as f:
51
- token_data_alt = {
52
- "id": test_token,
53
- "secret": "as-testsecret12345"
54
- }
55
- json.dump(token_data_alt, f)
56
-
57
- # Create .modalconfig file
58
- modalconfig_file = Path.home() / ".modalconfig"
59
- with open(modalconfig_file, 'w') as f:
60
- f.write(f"token_id = {test_token}\n")
61
- f.write(f"token_secret = as-testsecret12345\n")
62
-
63
- print("✅ Test Modal token set up successfully")
64
- return test_token
65
-
66
- def verify_token_exists(test_token):
67
- """Verify that the test token exists in environment and files"""
68
- print("🔍 Verifying test token exists...")
69
-
70
- # Check environment variables
71
- env_token_id = os.environ.get("MODAL_TOKEN_ID")
72
- env_token = os.environ.get("MODAL_TOKEN")
73
- env_token_secret = os.environ.get("MODAL_TOKEN_SECRET")
74
-
75
- if env_token_id != test_token:
76
- print(f"❌ MODAL_TOKEN_ID mismatch: expected '{test_token}', got '{env_token_id}'")
77
- return False
78
-
79
- if env_token != test_token:
80
- print(f"❌ MODAL_TOKEN mismatch: expected '{test_token}', got '{env_token}'")
81
- return False
82
-
83
- if not env_token_secret:
84
- print("❌ MODAL_TOKEN_SECRET not set")
85
- return False
86
-
87
- # Check token files
88
- modal_dir = Path.home() / ".modal"
89
- token_file = modal_dir / "token.json"
90
- if not token_file.exists():
91
- print(f"❌ Token file not found at {token_file}")
92
- return False
93
-
94
- token_alt_file = modal_dir / "token_alt.json"
95
- if not token_alt_file.exists():
96
- print(f"❌ Alternative token file not found at {token_alt_file}")
97
- return False
98
-
99
- modalconfig_file = Path.home() / ".modalconfig"
100
- if not modalconfig_file.exists():
101
- print(f"❌ .modalconfig file not found at {modalconfig_file}")
102
- return False
103
-
104
- print("✅ Test token exists in environment and files")
105
- return True
106
-
107
- def verify_token_cleaned_up():
108
- """Verify that the test token has been cleaned up"""
109
- print("🔍 Verifying token cleanup...")
110
-
111
- # Check that the original token is not in environment variables
112
- env_token_id = os.environ.get("MODAL_TOKEN_ID")
113
- env_token = os.environ.get("MODAL_TOKEN")
114
- env_token_secret = os.environ.get("MODAL_TOKEN_SECRET")
115
-
116
- # Check that original tokens are removed or replaced with invalid tokens
117
- if env_token_id and not ("invalid" in env_token_id or "placeholder" in env_token_id):
118
- print(f"❌ Original MODAL_TOKEN_ID still exists: '{env_token_id}'")
119
- return False
120
-
121
- if env_token and not ("invalid" in env_token or "placeholder" in env_token):
122
- print(f"❌ Original MODAL_TOKEN still exists: '{env_token}'")
123
- return False
124
-
125
- if env_token_secret and not ("invalid" in env_token_secret or "placeholder" in env_token_secret):
126
- print(f"❌ Original MODAL_TOKEN_SECRET still exists: '{env_token_secret}'")
127
- return False
128
-
129
- # Check token files
130
- modal_dir = Path.home() / ".modal"
131
- token_file = modal_dir / "token.json"
132
-
133
- # Check if token.json contains invalid values
134
- if token_file.exists():
135
- try:
136
- import json
137
- with open(token_file, 'r') as f:
138
- token_data = json.load(f)
139
-
140
- if "token_id" in token_data:
141
- if not ("invalid" in token_data["token_id"] or "placeholder" in token_data["token_id"]):
142
- print(f"❌ Token file contains original token_id: {token_data['token_id']}")
143
- return False
144
- print(f"✅ Token file contains invalid token_id: {token_data['token_id']}")
145
- else:
146
- print("❌ Token file does not contain token_id")
147
- return False
148
-
149
- if "token_secret" in token_data:
150
- if not ("invalid" in token_data["token_secret"] or "placeholder" in token_data["token_secret"]):
151
- print(f"❌ Token file contains original token_secret")
152
- return False
153
- print(f"✅ Token file contains invalid token_secret")
154
- else:
155
- print("❌ Token file does not contain token_secret")
156
- return False
157
- except Exception as e:
158
- print(f"❌ Error reading token file: {e}")
159
- return False
160
- else:
161
- print("❌ Token file does not exist")
162
- return False
163
-
164
- # Check .modalconfig file
165
- modalconfig_file = Path.home() / ".modalconfig"
166
- if modalconfig_file.exists():
167
- try:
168
- with open(modalconfig_file, 'r') as f:
169
- config_content = f.read()
170
-
171
- if not ("invalid" in config_content or "placeholder" in config_content):
172
- print("❌ .modalconfig file does not contain invalid tokens")
173
- return False
174
-
175
- print("✅ .modalconfig file contains invalid tokens")
176
- except Exception as e:
177
- print(f"❌ Error reading .modalconfig file: {e}")
178
- return False
179
- else:
180
- print("❌ .modalconfig file does not exist")
181
- return False
182
-
183
- # Check if Modal sessions directory exists
184
- session_dir = modal_dir / "sessions"
185
- if session_dir.exists():
186
- print(f"❌ Modal sessions directory still exists at {session_dir}")
187
- return False
188
-
189
- # Check for any session or auth files
190
- if modal_dir.exists():
191
- for file in os.listdir(modal_dir):
192
- if "session" in file.lower() or "auth" in file.lower():
193
- print(f"❌ Modal session/auth file still exists: {modal_dir / file}")
194
- return False
195
-
196
- # Check if Modal CLI works with invalid tokens
197
- try:
198
- import subprocess
199
- result = subprocess.run(
200
- ["modal", "--help"],
201
- capture_output=True,
202
- text=True
203
- )
204
- if result.returncode == 0:
205
- print("✅ Modal CLI works with invalid tokens")
206
- else:
207
- print("❌ Modal CLI does not work with invalid tokens")
208
- print(f"Output: {result.stdout}")
209
- print(f"Error: {result.stderr}")
210
- return False
211
-
212
- # Check that operations requiring authentication fail
213
- result = subprocess.run(
214
- ["modal", "app", "list"],
215
- capture_output=True,
216
- text=True
217
- )
218
- if result.returncode != 0 or "unauthorized" in result.stderr.lower() or "error" in result.stderr.lower():
219
- print("✅ Modal operations requiring authentication fail as expected")
220
- else:
221
- print("❌ Modal operations requiring authentication still work")
222
- print(f"Output: {result.stdout}")
223
- return False
224
- except Exception as e:
225
- print(f"⚠️ Error checking Modal CLI status: {e}")
226
-
227
- print("✅ Token has been cleaned up successfully")
228
- return True
229
-
230
- def run_test():
231
- """Run the token cleanup test"""
232
- print("🧪 Running Modal token cleanup test...")
233
-
234
- # Set up test token
235
- test_token = setup_test_token()
236
-
237
- # Verify token exists
238
- if not verify_token_exists(test_token):
239
- print("❌ Test failed: Token setup verification failed")
240
- return False
241
-
242
- # Clean up token
243
- print("🧹 Cleaning up token...")
244
- cleanup_modal_token()
245
-
246
- # Verify token has been cleaned up
247
- if not verify_token_cleaned_up():
248
- print("❌ Test failed: Token cleanup verification failed")
249
- return False
250
-
251
- print("✅ Test passed: Token cleanup works correctly")
252
- return True
253
-
254
- if __name__ == "__main__":
255
- success = run_test()
256
- sys.exit(0 if success else 1)
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Verify that environment variables are set correctly after running fetch_modal_tokens.py
4
- """
5
-
6
- import os
7
- import subprocess
8
- import sys
9
-
10
- def check_env_var(var_name):
11
- """Check if an environment variable is set and print its status"""
12
- value = os.environ.get(var_name)
13
- if value:
14
- print(f"✅ {var_name} is set (length: {len(value)})")
15
- return True
16
- else:
17
- print(f"❌ {var_name} is not set")
18
- return False
19
-
20
- def main():
21
- """Main function to verify environment variables"""
22
- print("🔍 Checking environment variables before running fetch_modal_tokens.py...")
23
- modal_id_before = check_env_var("MODAL_TOKEN_ID")
24
- modal_secret_before = check_env_var("MODAL_TOKEN_SECRET")
25
- openai_key_before = check_env_var("OPENAI_API_KEY")
26
-
27
- print("\n🔄 Running fetch_modal_tokens.py...")
28
- # Set a test API key for the script to use
29
- os.environ["GITARSENAL_API_KEY"] = "test_key"
30
-
31
- try:
32
- # Import the module to run it
33
- from fetch_modal_tokens import get_tokens
34
- token_id, token_secret = get_tokens()
35
- print(f"\n✅ get_tokens() returned values successfully")
36
- print(f" token_id length: {len(token_id) if token_id else 0}")
37
- print(f" token_secret length: {len(token_secret) if token_secret else 0}")
38
- except Exception as e:
39
- print(f"\n❌ Error running get_tokens(): {e}")
40
- sys.exit(1)
41
-
42
- print("\n🔍 Checking environment variables after running fetch_modal_tokens.py...")
43
- modal_id_after = check_env_var("MODAL_TOKEN_ID")
44
- modal_secret_after = check_env_var("MODAL_TOKEN_SECRET")
45
- openai_key_after = check_env_var("OPENAI_API_KEY")
46
-
47
- # Verify that the variables were set
48
- if modal_id_after and modal_secret_after:
49
- print("\n✅ MODAL_TOKEN_ID and MODAL_TOKEN_SECRET were successfully set")
50
- else:
51
- print("\n❌ Failed to set all required environment variables")
52
-
53
- if openai_key_after:
54
- print("✅ OPENAI_API_KEY was also set")
55
-
56
- # Check if the values match what was returned by get_tokens()
57
- if modal_id_after and os.environ.get("MODAL_TOKEN_ID") == token_id:
58
- print("✅ MODAL_TOKEN_ID matches the value returned by get_tokens()")
59
-
60
- if modal_secret_after and os.environ.get("MODAL_TOKEN_SECRET") == token_secret:
61
- print("✅ MODAL_TOKEN_SECRET matches the value returned by get_tokens()")
62
-
63
- if __name__ == "__main__":
64
- main()