File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,6 +92,8 @@ def _missing_(cls, value):
9292 return None
9393
9494
95+ TERMINAL_STATUSES = [Status .COMPLETE , Status .FAILED , Status .EXCEPTION ]
96+
9597AGENT_BROWSER_EXT_PATH = ""
9698AGENT_BROWSER_LOCK = Lock ()
9799ANALYZER_FOLDER = ""
@@ -494,6 +496,11 @@ def put_status():
494496 except ValueError :
495497 return json_error (400 , "No valid status has been provided" )
496498
499+ # If the new status is terminal, unset the async subprocess so /status reports
500+ # the final analysis state rather than the child process state.
501+ if status in TERMINAL_STATUSES :
502+ state ["async_subprocess" ] = None
503+
497504 state ["status" ] = status
498505 state ["description" ] = request .form .get ("description" )
499506 return json_success ("Analysis status updated" )
Original file line number Diff line number Diff line change @@ -639,6 +639,34 @@ def test_async_failure(self):
639639 js = self .confirm_status (str (agent .Status .FAILED ))
640640 assert "process_id" not in js
641641
642+ def test_async_manual_status_override (self ):
643+ """Test that a manual status update overrides an in-progress async process."""
644+ # Upload a Python file that sleeps for a short period, to ensure the
645+ # async subprocess is running while we override the status.
646+ file_contents = (
647+ "import time" ,
648+ "time.sleep(10)" ,
649+ )
650+
651+ filepath = self .store_file (file_contents )
652+ form = {"filepath" : filepath , "async" : 1 }
653+
654+ execpy_resp = self .post_form ("execpy" , form )
655+ assert execpy_resp .get ("message" ) == "Successfully spawned command"
656+
657+ # While the subprocess is running, the status should initially be RUNNING.
658+ self .confirm_status (str (agent .Status .RUNNING ))
659+
660+ # Manually override the status to COMPLETE via POST /status.
661+ override_form = {
662+ "status" : str (agent .Status .COMPLETE ),
663+ "description" : "beep boop"
664+ }
665+ status_resp = self .post_form ("status" , override_form )
666+ assert status_resp .get ("message" ) == "Analysis status updated"
667+
668+ self .confirm_status (str (agent .Status .COMPLETE ))
669+
642670 def test_execute (self ):
643671 """Test executing the 'date' command."""
644672 if sys .platform == "win32" :
You can’t perform that action at this time.
0 commit comments