The GitHub Actions job "Backport Approval Check" on 
texera.git/gh-readonly-queue/main/pr-9578-728d5cd7039257acfb54dfeef73f87db053e21f6
 has succeeded.
Run started by GitHub user mengw15 (triggered by mengw15).

Head commit for run:
3ed01463a0ae537234d00e703e5fe13817a385c3 / Ryan Zhang 
<[email protected]>
feat(notebook-migration): reject uploads whose language does not match the 
selected tab (#9578)

### What changes were proposed in this PR?

The import modal decides which prompts a conversion uses from where the
user uploads: the Python Notebook / R Notebook switch on the Jupyter
Notebook tab, or the Python File, Python Folder, R File and R Folder
tabs. Until now only one mismatch was checked, and its message could
point users to the wrong place. An R notebook uploaded as a Python
Notebook went through to the Python prompts and came back as a workflow
of broken Python UDFs.

**Mismatch checks.** The dashboard now checks every upload against the
selected language before any model call:

* Notebooks: the language comes from `metadata.kernelspec.language`,
falling back to `metadata.language_info.name`, ignoring case and
surrounding spaces. A notebook that declares neither is accepted as
before.
* Files: the extension decides. An extension no language claims keeps
today's upload hint.
* Folders: a folder with no files in the selected language but some in
another is pointed at the right tab. Any other folder, including a mixed
one, goes on to `parseFolder` and its existing checks.

| Upload | Message |
| --- | --- |
| R notebook as a Python Notebook | This notebook uses an R kernel, not
Python. Switch the notebook type to R Notebook. |
| Python notebook as an R Notebook | This notebook uses a Python kernel,
not R. Switch the notebook type to Python Notebook. |
| Any other kernel, either type | This notebook uses a julia kernel.
Only Python and R notebooks can be converted. |
| R file on a Python tab | This is an R file. Upload it under the R File
tab. |
| Python file on an R tab | This is a Python file. Upload it under the
Python File tab. |
| Python folder on R Folder | This folder holds Python files, not R.
Upload it under the Python Folder tab. |
| R folder on Python Folder | This folder holds R files, not Python.
Upload it under the R Folder tab. |

When the right place is an R option and R is not enabled on the
deployment, the message says so instead of pointing at a disabled
control, for example "This notebook uses an R kernel, and R is not
enabled on this deployment." The checks are driven by the per language
table the dispatch already used, now extended with each language's
kernel name, notebook type and tab names, so a later language gets them
without new branches.

**Script read errors.** `parseScriptFile` takes the language, so an
empty or unreadable R file is reported as "The R file is empty." or
"Failed to read the R file." rather than naming Python.

**Error duration.** Migration errors now stay on screen for 8 seconds
instead of ng-zorro's default 3, since most of them are two sentences of
instructions. Errors elsewhere in the app keep the default.

#### Demo video

https://drive.google.com/file/d/1BkMJHuZqcvIPArxia73Dtqp3th-_y2kn/view?usp=sharing

### Any related issues, documentation, discussions?

Closes #8929
Parent-issue #4301

### How was this PR tested?

* `user-workflow.component.spec.ts`, a new "language mismatches" block
of 14 tests covering every row above: R and Python notebooks on the
wrong type with R on and off, case and spacing in the declared language,
the `language_info` fallback, an unsupported kernel on both types with
the right article, R and Python files on the wrong tab with R on and
off, an unknown extension, folders in either direction with R on and
off, and a mixed folder and a folder with no source both reaching
`parseFolder`. Existing assertions were updated to the new wording and
to expect the 8 second duration, and the R folder test from #9427 now
sends R files.
* `notebook-migration.service.spec.ts`: the exact Python and R messages
from `parseScriptFile`.

The full frontend suite passes, and every new line and branch is
covered.

Checked against a local stack by driving the modal's own upload and
submit with files carrying the mock inputs' kernels, extensions and
folder paths. With R off, the four R uploads on Python options each
showed the R is not enabled message. With R on, all seven mismatches
showed the messages above, and a matching R notebook passed the checks
and went on to the model call. No mismatch made a model request. An
error toast stayed visible for about 9 seconds, the 8 second duration
plus its fade out.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

---------

Co-authored-by: Meng Wang <[email protected]>

Report URL: https://github.com/apache/texera/actions/runs/45292987336

With regards,
GitHub Actions via GitBox

Reply via email to