diff --git a/submit_ce/domain/event/file.py b/submit_ce/domain/event/file.py index 34702b9f..c2411cd4 100644 --- a/submit_ce/domain/event/file.py +++ b/submit_ce/domain/event/file.py @@ -17,8 +17,22 @@ logger = logging.getLogger(__name__) def _common_file_change_project(submission: Submission) -> None: - """Common changes during `project` to submission when any file change happens.""" + """Common state changes during `project` when any file change happens. + + A file change invalidates the previous processing outcome: the compiled + preview no longer reflects the current source (its file and the compile log + are removed in `_common_file_change_execute`). So we mark the submission + unprocessed -- `is_source_processed=False`, which round-trips to the legacy + `must_process=1` column -- and drop the now-stale `submission.preview`, + mirroring `UnConfirmSourceProcessed`. Without this the Process stage stays + "complete" after an edit (letting the submitter skip recompilation) and + `submission.preview` dangles at a deleted file. Applies to both TeX and + PDF-only submissions, since all file-change events route through here. + [SUBMISSION-207] + """ submission.submitter_confirmed_preview = False + submission.is_source_processed = False + submission.preview = None def _common_file_change_execute(api: SubmitApi, submission: Submission) -> None: diff --git a/submit_ce/domain/event/tests/test_file_events.py b/submit_ce/domain/event/tests/test_file_events.py index 741854a7..7c728a23 100644 --- a/submit_ce/domain/event/tests/test_file_events.py +++ b/submit_ce/domain/event/tests/test_file_events.py @@ -2,6 +2,7 @@ from pytz import UTC from submit_ce.domain import submission as submod, agent +from submit_ce.domain.preview import Preview from submit_ce.domain.event.file import ( UploadFiles, RemoveFiles, RemoveAllFiles, _common_file_change_execute, ) @@ -63,6 +64,42 @@ def test_remove_all_files_clears_package(): assert s.submitter_confirmed_preview is False +def _processed_submission(): + """A submission that has already been processed, with a preview recorded.""" + s = _blank_submission() + s.is_source_processed = True + s.submitter_confirmed_preview = True + s.preview = Preview(source_id=1, source_checksum="a", + preview_checksum="b", size_bytes=10, added=_now()) + return s + + +def test_upload_resets_processing_state(): + """Uploading files after a submission is processed marks it unprocessed and + drops the stale preview, so Process re-runs on the new source. [SUBMISSION-207]""" + s = _processed_submission() + e = UploadFiles(creator=s.creator, files=[]) + e.validate_pre_lock(s) + s = e.project(s) + + assert s.is_source_processed is False + assert s.preview is None + assert s.submitter_confirmed_preview is False + + +def test_remove_all_resets_processing_state(): + """RemoveAllFiles (e.g. swapping a processed PDF-only submission's file) also + resets the processing state and clears the preview. [SUBMISSION-207]""" + s = _processed_submission() + e = RemoveAllFiles(creator=s.creator) + e.validate_pre_lock(s) + s = e.project(s) + + assert s.is_source_processed is False + assert s.preview is None + assert s.submitter_confirmed_preview is False + + def test_file_change_deletes_compile_log(mocker): """Any source file change invalidates the compile log alongside the other derived artifacts, so a stale log can't linger on the Process page after the