@@ -46,6 +46,21 @@ func TestNewCmdCreate(t *testing.T) {
4646 ProblemStatementFile : "" ,
4747 },
4848 },
49+ {
50+ name : "empty arg" ,
51+ args : "''" ,
52+ wantErr : "task description cannot be empty" ,
53+ },
54+ {
55+ name : "whitespace arg" ,
56+ args : "' '" ,
57+ wantErr : "task description cannot be empty" ,
58+ },
59+ {
60+ name : "whitespace and newline arg" ,
61+ args : "'\n '" ,
62+ wantErr : "task description cannot be empty" ,
63+ },
4964 {
5065 name : "mutually exclusive arg and file" ,
5166 args : "'some task inline' -F foo.md" ,
@@ -96,7 +111,7 @@ func TestNewCmdCreate(t *testing.T) {
96111
97112 _ , err = cmd .ExecuteC ()
98113 if tt .wantErr != "" {
99- require .Error (t , err , tt .wantErr )
114+ require .EqualError (t , err , tt .wantErr )
100115 } else {
101116 require .NoError (t , err )
102117 }
@@ -158,72 +173,85 @@ func Test_createRun(t *testing.T) {
158173 wantErrIs error
159174 }{
160175 {
161- name : "interactive with file prompts to edit with file contents" ,
176+ name : "interactive, problem statement from arg" ,
177+ isTTY : true ,
178+ opts : & CreateOptions {
179+ BaseRepo : func () (ghrepo.Interface , error ) { return ghrepo .New ("OWNER" , "REPO" ), nil },
180+ ProblemStatement : "task description from arg" ,
181+ },
182+ capiStubs : func (t * testing.T , m * capi.CapiClientMock ) {
183+ m .CreateJobFunc = func (ctx context.Context , owner , repo , problemStatement , baseBranch string ) (* capi.Job , error ) {
184+ require .Equal (t , "OWNER" , owner )
185+ require .Equal (t , "REPO" , repo )
186+ require .Equal (t , "task description from arg" , problemStatement )
187+ return & createdJobSuccessWithPR , nil
188+ }
189+ },
190+ wantStdout : "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n " ,
191+ },
192+ {
193+ name : "non-interactive, problem statement from arg" ,
194+ opts : & CreateOptions {
195+ BaseRepo : func () (ghrepo.Interface , error ) { return ghrepo .New ("OWNER" , "REPO" ), nil },
196+ ProblemStatement : "task description from arg" ,
197+ },
198+ capiStubs : func (t * testing.T , m * capi.CapiClientMock ) {
199+ m .CreateJobFunc = func (ctx context.Context , owner , repo , problemStatement , baseBranch string ) (* capi.Job , error ) {
200+ require .Equal (t , "OWNER" , owner )
201+ require .Equal (t , "REPO" , repo )
202+ require .Equal (t , "task description from arg" , problemStatement )
203+ return & createdJobSuccessWithPR , nil
204+ }
205+ },
206+ wantStdout : "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n " ,
207+ },
208+ {
209+ name : "interactive, problem statement from file" ,
210+ isTTY : true ,
162211 opts : & CreateOptions {
163212 BaseRepo : func () (ghrepo.Interface , error ) { return ghrepo .New ("OWNER" , "REPO" ), nil },
164213 ProblemStatement : "" ,
165214 ProblemStatementFile : taskDescFile ,
166- Prompter : & prompter.PrompterMock {
167- MarkdownEditorFunc : func (prompt , defaultValue string , blankAllowed bool ) (string , error ) {
168- require .Equal (t , "Enter the task description" , prompt )
169- require .Equal (t , "task description from file" , defaultValue )
170- return "edited task description" , nil
171- },
172- ConfirmFunc : func (message string , defaultValue bool ) (bool , error ) {
173- require .Equal (t , "Submit agent task" , message )
174- return true , nil
175- },
176- },
177215 },
178- isTTY : true ,
179216 capiStubs : func (t * testing.T , m * capi.CapiClientMock ) {
180217 m .CreateJobFunc = func (ctx context.Context , owner , repo , problemStatement , baseBranch string ) (* capi.Job , error ) {
181218 require .Equal (t , "OWNER" , owner )
182219 require .Equal (t , "REPO" , repo )
183- require .Equal (t , "edited task description" , problemStatement )
220+ require .Equal (t , "task description from file " , problemStatement )
184221 return & createdJobSuccessWithPR , nil
185222 }
186223 },
187224 wantStdout : "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n " ,
188225 },
189226 {
190- name : "interactively rejecting confirmation prompt aborts task creation " ,
227+ name : "non-interactive, problem statement loaded from file " ,
191228 opts : & CreateOptions {
192- BaseRepo : func () (ghrepo.Interface , error ) { return ghrepo .New ("OWNER" , "REPO" ), nil },
193- ProblemStatement : "" ,
194- Prompter : & prompter.PrompterMock {
195- MarkdownEditorFunc : func (prompt , defaultValue string , blankAllowed bool ) (string , error ) {
196- require .Equal (t , "Enter the task description" , prompt )
197- return "From editor" , nil
198- },
199- ConfirmFunc : func (message string , defaultValue bool ) (bool , error ) {
200- require .Equal (t , "Submit agent task" , message )
201- return false , nil
202- },
203- },
229+ BaseRepo : func () (ghrepo.Interface , error ) { return ghrepo .New ("OWNER" , "REPO" ), nil },
230+ ProblemStatement : "" ,
231+ ProblemStatementFile : taskDescFile ,
232+ },
233+ capiStubs : func (t * testing.T , m * capi.CapiClientMock ) {
234+ m .CreateJobFunc = func (ctx context.Context , owner , repo , problemStatement , baseBranch string ) (* capi.Job , error ) {
235+ require .Equal (t , "OWNER" , owner )
236+ require .Equal (t , "REPO" , repo )
237+ require .Equal (t , "task description from file" , problemStatement )
238+ return & createdJobSuccessWithPR , nil
239+ }
204240 },
205- isTTY : true ,
206- wantErr : "SilentError" ,
207- wantErrIs : cmdutil .SilentError ,
208- wantStdErr : "" ,
241+ wantStdout : "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n " ,
209242 },
210243 {
211- name : "interactively entering task description with editor, no file " ,
244+ name : "interactive, problem statement from prompt/ editor" ,
212245 isTTY : true ,
213246 opts : & CreateOptions {
214247 BaseRepo : func () (ghrepo.Interface , error ) {
215248 return ghrepo .New ("OWNER" , "REPO" ), nil
216249 },
217- ProblemStatement : "" ,
218250 Prompter : & prompter.PrompterMock {
219251 MarkdownEditorFunc : func (prompt , defaultValue string , blankAllowed bool ) (string , error ) {
220252 require .Equal (t , "Enter the task description" , prompt )
221253 return "From editor" , nil
222254 },
223- ConfirmFunc : func (message string , defaultValue bool ) (bool , error ) {
224- require .Equal (t , "Submit agent task" , message )
225- return true , nil
226- },
227255 },
228256 },
229257 capiStubs : func (t * testing.T , m * capi.CapiClientMock ) {
@@ -235,7 +263,7 @@ func Test_createRun(t *testing.T) {
235263 wantStdout : "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n " ,
236264 },
237265 {
238- name : "empty task description from interactive prompt returns error" ,
266+ name : "interactive, empty task description from editor returns error" ,
239267 isTTY : true ,
240268 opts : & CreateOptions {
241269 BaseRepo : func () (ghrepo.Interface , error ) {
@@ -247,26 +275,7 @@ func Test_createRun(t *testing.T) {
247275 },
248276 },
249277 },
250- wantErr : "SilentError" ,
251- wantErrIs : cmdutil .SilentError ,
252- wantStdErr : "a task description is required.\n " ,
253- },
254- {
255- name : "problem statement loaded from file non-interactively doesn't prompt or return error" ,
256- opts : & CreateOptions {
257- BaseRepo : func () (ghrepo.Interface , error ) { return ghrepo .New ("OWNER" , "REPO" ), nil },
258- ProblemStatement : "" ,
259- ProblemStatementFile : taskDescFile ,
260- },
261- capiStubs : func (t * testing.T , m * capi.CapiClientMock ) {
262- m .CreateJobFunc = func (ctx context.Context , owner , repo , problemStatement , baseBranch string ) (* capi.Job , error ) {
263- require .Equal (t , "OWNER" , owner )
264- require .Equal (t , "REPO" , repo )
265- require .Equal (t , "task description from file" , problemStatement )
266- return & createdJobSuccessWithPR , nil
267- }
268- },
269- wantStdout : "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n " ,
278+ wantErr : "a task description is required" ,
270279 },
271280 {
272281 name : "missing repo returns error" ,
@@ -276,18 +285,6 @@ func Test_createRun(t *testing.T) {
276285 }},
277286 wantErr : "a repository is required; re-run in a repository or supply one with --repo owner/name" ,
278287 },
279- {
280- name : "non-interactive empty description returns error" ,
281- opts : & CreateOptions {
282- BaseRepo : func () (ghrepo.Interface , error ) {
283- return ghrepo .New ("OWNER" , "REPO" ), nil
284- },
285- ProblemStatement : "" ,
286- },
287- wantErr : "SilentError" ,
288- wantErrIs : cmdutil .SilentError ,
289- wantStdErr : "a task description is required.\n " ,
290- },
291288 {
292289 name : "problem statement loaded from arg non-interactively doesn't prompt or return error" ,
293290 opts : & CreateOptions {
@@ -491,8 +488,6 @@ func Test_createRun(t *testing.T) {
491488 }
492489 },
493490 wantStdout : heredoc .Doc (`
494- https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1
495-
496491 (rendered:) <raw-logs-one>
497492 (rendered:) <raw-logs-two>
498493 ` ),
0 commit comments