1+ import { default as assert } from 'assert' ;
2+ import { RemoteAgentJobPayload } from '../../github/copilotApi' ;
3+
4+ describe ( 'CopilotApi Tests' , function ( ) {
5+ describe ( 'RemoteAgentJobPayload' , ( ) => {
6+ it ( 'should have optional head_ref property' , ( ) => {
7+ // Test payload without head_ref (when not pushing)
8+ const payloadWithoutHeadRef : RemoteAgentJobPayload = {
9+ problem_statement : 'Test problem' ,
10+ pull_request : {
11+ title : 'Test title' ,
12+ body_placeholder : 'Test body' ,
13+ base_ref : 'main'
14+ }
15+ } ;
16+
17+ assert . strictEqual ( payloadWithoutHeadRef . pull_request ?. head_ref , undefined ) ;
18+ assert . strictEqual ( payloadWithoutHeadRef . pull_request ?. base_ref , 'main' ) ;
19+ } ) ;
20+
21+ it ( 'should include head_ref when pushing async branch' , ( ) => {
22+ // Test payload with head_ref (when pushing to async branch)
23+ const payloadWithHeadRef : RemoteAgentJobPayload = {
24+ problem_statement : 'Test problem' ,
25+ pull_request : {
26+ title : 'Test title' ,
27+ body_placeholder : 'Test body' ,
28+ base_ref : 'main' ,
29+ head_ref : 'continue-from-1234567890'
30+ }
31+ } ;
32+
33+ assert . strictEqual ( payloadWithHeadRef . pull_request ?. head_ref , 'continue-from-1234567890' ) ;
34+ assert . strictEqual ( payloadWithHeadRef . pull_request ?. base_ref , 'main' ) ;
35+ } ) ;
36+
37+ it ( 'should support conditional head_ref property using spread operator' , ( ) => {
38+ const hasChanges = true ;
39+ const autoPushAndCommit = true ;
40+ const baseRef = 'main' ;
41+ const ref = 'continue-from-1234567890' ;
42+
43+ // Simulate the logic from copilotRemoteAgent.ts
44+ const payload : RemoteAgentJobPayload = {
45+ problem_statement : 'Test problem' ,
46+ pull_request : {
47+ title : 'Test title' ,
48+ body_placeholder : 'Test body' ,
49+ base_ref : hasChanges && autoPushAndCommit ? baseRef : ref ,
50+ ...( hasChanges && autoPushAndCommit && { head_ref : ref } )
51+ }
52+ } ;
53+
54+ assert . strictEqual ( payload . pull_request ?. base_ref , 'main' ) ;
55+ assert . strictEqual ( payload . pull_request ?. head_ref , 'continue-from-1234567890' ) ;
56+ } ) ;
57+
58+ it ( 'should not include head_ref when not pushing' , ( ) => {
59+ const hasChanges = false ;
60+ const autoPushAndCommit = true ;
61+ const baseRef = 'main' ;
62+ const ref = 'main' ;
63+
64+ // Simulate the logic from copilotRemoteAgent.ts
65+ const payload : RemoteAgentJobPayload = {
66+ problem_statement : 'Test problem' ,
67+ pull_request : {
68+ title : 'Test title' ,
69+ body_placeholder : 'Test body' ,
70+ base_ref : hasChanges && autoPushAndCommit ? baseRef : ref ,
71+ ...( hasChanges && autoPushAndCommit && { head_ref : ref } )
72+ }
73+ } ;
74+
75+ assert . strictEqual ( payload . pull_request ?. base_ref , 'main' ) ;
76+ assert . strictEqual ( payload . pull_request ?. head_ref , undefined ) ;
77+ } ) ;
78+ } ) ;
79+ } ) ;
0 commit comments