@@ -49,6 +49,9 @@ func TestCLIHelp(t *testing.T) {
4949 if ! strings .Contains (stdout .String (), "wait --submission 42 --for landed --json --timeout 30m" ) {
5050 t .Fatalf ("expected wait guidance in help, got %q" , stdout .String ())
5151 }
52+ if ! strings .Contains (stdout .String (), "next --json" ) {
53+ t .Fatalf ("expected next guidance in help, got %q" , stdout .String ())
54+ }
5255}
5356
5457func TestMQHelpUsesMQIdentity (t * testing.T ) {
@@ -147,6 +150,122 @@ func TestGlobalJSONCompletionReportsStructuredScript(t *testing.T) {
147150 }
148151}
149152
153+ func TestNextCommitReportsNextIntegratedProtectedAdvance (t * testing.T ) {
154+ repoRoot , _ := createTestRepoWithRemote (t )
155+ initRepoForWorker (t , repoRoot )
156+
157+ featurePath := filepath .Join (t .TempDir (), "feature-next-commit" )
158+ runTestCommand (t , repoRoot , "git" , "worktree" , "add" , "-b" , "feature/next-commit" , featurePath )
159+ writeFileAndCommit (t , featurePath , "next-commit.txt" , "next commit\n " , "next commit feature" )
160+ featureHead := trimNewline (runTestCommand (t , featurePath , "git" , "rev-parse" , "HEAD" ))
161+
162+ resultCh := make (chan nextResult , 1 )
163+ errCh := make (chan error , 1 )
164+ go func () {
165+ var stdout bytes.Buffer
166+ var stderr bytes.Buffer
167+ err := runNext ([]string {"commit" , "--repo" , repoRoot , "--json" , "--timeout" , "10s" , "--poll-interval" , "10ms" }, newStepPrinter (& stdout ), & stderr )
168+ if err != nil {
169+ errCh <- err
170+ return
171+ }
172+ var result nextResult
173+ if unmarshalErr := json .Unmarshal (stdout .Bytes (), & result ); unmarshalErr != nil {
174+ errCh <- unmarshalErr
175+ return
176+ }
177+ resultCh <- result
178+ }()
179+
180+ time .Sleep (100 * time .Millisecond )
181+ submitBranch (t , featurePath )
182+ runOnce (t , repoRoot )
183+
184+ select {
185+ case err := <- errCh :
186+ t .Fatalf ("runNext returned error: %v" , err )
187+ case result := <- resultCh :
188+ if result .Target != nextTargetCommit {
189+ t .Fatalf ("expected commit target, got %+v" , result )
190+ }
191+ if result .ProtectedSHA != featureHead {
192+ t .Fatalf ("expected protected sha %q, got %+v" , featureHead , result )
193+ }
194+ if result .CommitSubject != "next commit feature" {
195+ t .Fatalf ("expected commit subject, got %+v" , result )
196+ }
197+ if result .Branch != "feature/next-commit" {
198+ t .Fatalf ("expected branch in result, got %+v" , result )
199+ }
200+ if result .QueueState == "" {
201+ t .Fatalf ("expected queue state summary, got %+v" , result )
202+ }
203+ case <- time .After (12 * time .Second ):
204+ t .Fatal ("timed out waiting for mq next commit result" )
205+ }
206+ }
207+
208+ func TestNextPushReportsNextPublishedProtectedAdvance (t * testing.T ) {
209+ repoRoot , remoteDir := createTestRepoWithRemote (t )
210+ initRepoForWorker (t , repoRoot )
211+ updatePublishMode (t , repoRoot , "auto" )
212+
213+ featurePath := filepath .Join (t .TempDir (), "feature-next-push" )
214+ runTestCommand (t , repoRoot , "git" , "worktree" , "add" , "-b" , "feature/next-push" , featurePath )
215+ writeFileAndCommit (t , featurePath , "next-push.txt" , "next push\n " , "next push feature" )
216+ featureHead := trimNewline (runTestCommand (t , featurePath , "git" , "rev-parse" , "HEAD" ))
217+
218+ resultCh := make (chan nextResult , 1 )
219+ errCh := make (chan error , 1 )
220+ go func () {
221+ var stdout bytes.Buffer
222+ var stderr bytes.Buffer
223+ err := runNext ([]string {"--repo" , repoRoot , "--json" , "--timeout" , "10s" , "--poll-interval" , "10ms" }, newStepPrinter (& stdout ), & stderr )
224+ if err != nil {
225+ errCh <- err
226+ return
227+ }
228+ var result nextResult
229+ if unmarshalErr := json .Unmarshal (stdout .Bytes (), & result ); unmarshalErr != nil {
230+ errCh <- unmarshalErr
231+ return
232+ }
233+ resultCh <- result
234+ }()
235+
236+ time .Sleep (100 * time .Millisecond )
237+ submitBranch (t , featurePath )
238+ runOnce (t , repoRoot )
239+ runOnce (t , repoRoot )
240+
241+ select {
242+ case err := <- errCh :
243+ t .Fatalf ("runNext returned error: %v" , err )
244+ case result := <- resultCh :
245+ if result .Target != nextTargetPush {
246+ t .Fatalf ("expected push target, got %+v" , result )
247+ }
248+ if result .ProtectedSHA != featureHead {
249+ t .Fatalf ("expected protected sha %q, got %+v" , featureHead , result )
250+ }
251+ if result .CommitSubject != "next push feature" {
252+ t .Fatalf ("expected commit subject, got %+v" , result )
253+ }
254+ if result .PublishRequestID == 0 {
255+ t .Fatalf ("expected publish request id, got %+v" , result )
256+ }
257+ if result .QueueState == "" {
258+ t .Fatalf ("expected queue state summary, got %+v" , result )
259+ }
260+ remoteHead := trimNewline (runTestCommand (t , remoteDir , "git" , "rev-parse" , "refs/heads/main" ))
261+ if remoteHead != featureHead {
262+ t .Fatalf ("expected remote head %q, got %q" , featureHead , remoteHead )
263+ }
264+ case <- time .After (12 * time .Second ):
265+ t .Fatal ("timed out waiting for mq next push result" )
266+ }
267+ }
268+
150269func TestGlobalJSONForwardsToRunOnceAndPublish (t * testing.T ) {
151270 repoRoot , _ := createTestRepoWithRemote (t )
152271 initRepoForWorker (t , repoRoot )
@@ -1254,7 +1373,7 @@ func TestCLIAcceptsSubcommandFlagsForPlannedCommands(t *testing.T) {
12541373 if ! strings .Contains (output , "complete -F _mainline_completions mainline" ) {
12551374 t .Fatalf ("expected completion script output, got %q" , output )
12561375 }
1257- if ! strings .Contains (output , "land submit status confidence run-once wait rebase blocked retry cancel publish" ) {
1376+ if ! strings .Contains (output , "land submit status next confidence run-once wait rebase blocked retry cancel publish" ) {
12581377 t .Fatalf ("expected completion script to include rebase and blocked workflow, got %q" , output )
12591378 }
12601379 if ! strings .Contains (output , "--repo --branch --sha --worktree --requested-by --priority --allow-newer-head --json --check --check-only --queue-only --wait --for --timeout --poll-interval" ) {
0 commit comments