@@ -80,31 +80,17 @@ def test_agent_tasks_extraction_with_remote_and_branch
8080 vcs_repo . checkout_branch ( 'extract-test' )
8181 agent_tasks = AgentTasks . new ( repo )
8282
83- # Save original token and set test token
84- original_token = ENV . fetch ( 'GITHUB_TOKEN' , nil )
85-
86- begin
87- ENV [ 'GITHUB_TOKEN' ] = 'test_token_123'
88- # Test autopush message generation
89- message = agent_tasks . agent_prompt ( autopush : true )
90-
91- assert_includes message , 'extraction test task'
92- assert_includes message , 'git remote add target_remote "https://x-access-token:[email protected] /testuser/test-repo.git"' 93- assert_includes message , 'git push target_remote HEAD:extract-test'
94- ensure
95- # Restore original token
96- if original_token
97- ENV [ 'GITHUB_TOKEN' ] = original_token
98- else
99- ENV . delete ( 'GITHUB_TOKEN' )
100- end
101- end
83+ # Autopush message generation should not embed credentials
84+ message = agent_tasks . agent_prompt ( autopush : true )
85+ assert_includes message , 'extraction test task'
86+ assert_includes message , 'git remote add target_remote "https://github.com/testuser/test-repo.git"'
87+ assert_includes message , 'git push target_remote HEAD:extract-test'
10288 ensure
10389 FileUtils . remove_entry ( repo ) if repo && File . exist? ( repo )
10490 FileUtils . remove_entry ( remote ) if remote && File . exist? ( remote )
10591 end
10692
107- def test_agent_tasks_autopush_requires_github_token
93+ def test_agent_tasks_autopush_without_token
10894 repo , remote = setup_repo ( :git )
10995
11096 # Set up HTTPS remote
@@ -119,34 +105,12 @@ def test_agent_tasks_autopush_requires_github_token
119105 vcs_repo . checkout_branch ( 'token-test' )
120106 agent_tasks = AgentTasks . new ( repo )
121107
122- # Save original token
123- original_token = ENV . fetch ( 'GITHUB_TOKEN' , nil )
124-
125- begin
126- # Test with missing token
127- ENV . delete ( 'GITHUB_TOKEN' )
128- error = assert_raises ( StandardError ) do
129- agent_tasks . agent_prompt ( autopush : true )
130- end
131- assert_includes error . message ,
132- 'The Codex environment must be configured with a GITHUB_TOKEN, ' \
133- 'specified as a secret'
134-
135- # Test with token present
136- ENV [ 'GITHUB_TOKEN' ] = 'test_token_123'
137- message = agent_tasks . agent_prompt ( autopush : true )
138- assert_includes message , 'git remote add target_remote "https://x-access-token:[email protected] /testuser/test-repo.git"' 139- assert_includes message , 'git push target_remote HEAD:token-test'
140- ensure
141- # Restore original token
142- if original_token
143- ENV [ 'GITHUB_TOKEN' ] = original_token
144- else
145- ENV . delete ( 'GITHUB_TOKEN' )
146- end
147- FileUtils . remove_entry ( repo ) if repo && File . exist? ( repo )
148- FileUtils . remove_entry ( remote ) if remote && File . exist? ( remote )
149- end
108+ message = agent_tasks . agent_prompt ( autopush : true )
109+ assert_includes message , 'git remote add target_remote "https://github.com/testuser/test-repo.git"'
110+ assert_includes message , 'git push target_remote HEAD:token-test'
111+ ensure
112+ FileUtils . remove_entry ( repo ) if repo && File . exist? ( repo )
113+ FileUtils . remove_entry ( remote ) if remote && File . exist? ( remote )
150114 end
151115
152116 def test_agent_tasks_autopush_errors_on_missing_commit_data
@@ -163,25 +127,12 @@ def test_agent_tasks_autopush_errors_on_missing_commit_data
163127
164128 agent_tasks = AgentTasks . new ( repo )
165129
166- # Save original token and set test token
167- original_token = ENV . fetch ( 'GITHUB_TOKEN' , nil )
168- ENV [ 'GITHUB_TOKEN' ] = 'test_token_123'
169-
170- begin
171- # Should raise error because commit doesn't have Target-Remote
172- error = assert_raises ( StandardError ) do
173- agent_tasks . agent_prompt ( autopush : true )
174- end
175- assert_includes error . message , 'You are not currently on a agent task branch'
176- ensure
177- # Restore original token
178- if original_token
179- ENV [ 'GITHUB_TOKEN' ] = original_token
180- else
181- ENV . delete ( 'GITHUB_TOKEN' )
182- end
183- FileUtils . remove_entry ( repo ) if repo && File . exist? ( repo )
184- FileUtils . remove_entry ( remote ) if remote && File . exist? ( remote )
130+ error = assert_raises ( StandardError ) do
131+ agent_tasks . agent_prompt ( autopush : true )
185132 end
133+ assert_includes error . message , 'You are not currently on a agent task branch'
134+ ensure
135+ FileUtils . remove_entry ( repo ) if repo && File . exist? ( repo )
136+ FileUtils . remove_entry ( remote ) if remote && File . exist? ( remote )
186137 end
187138end
0 commit comments