unsloth/tests/python
Daniel Han 9c69529705
Windows: stop compiling C# for colour on hosts that already render it (#8767)
* Windows: stop compiling C# for colour on hosts that already render it

Enable-StudioVirtualTerminal is called unconditionally by install.ps1 and
studio/setup.ps1, and it reaches Add-Type, which runs the C# compiler and drops
a source file in %TEMP% on every install. An ANY.RUN submission of the shipped
0.1.701-beta Windows build captured that as two csc.exe processes and a
"Suspicious source code drop".

Under Windows Terminal there is nothing to enable: it always renders VT. Ask
for that case first and skip the compile.

All three conjuncts are load-bearing. WT_SESSION is inherited, so the desktop
app's console-less spawn carries it into a pipe, and without the redirect check
the Studio log panel would fill with escape sequences.
$Host.UI.SupportsVirtualTerminal reports what the host CAN render, not whether
this output buffer has ENABLE_VIRTUAL_TERMINAL_PROCESSING set, so it cannot
carry the decision alone either.

Nothing else moves. Outside this one function both scripts are identical to
main line for line, and $script:StudioVtOk is the only value the function
feeds, so the same verdict means the same bytes.

The other compile stays. UnslothStudioFinalPathV2 feeds
Get-StudioRuntimePathHash, which Python derives the same mutex name from byte
for byte, so a managed fast path differing on case or an 8.3 name would let two
installers each believe they hold the install lock.

Guards: test_installer_av_shapes.py fails if the compile moves back ahead of
the host check or loses a conjunct, and test_windows_setup_output_encoding.py
runs this function beside the one it replaces on a real Windows host, with
WT_SESSION forced set and forced empty, asserting the same verdict and the
same banner bytes.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Decide the redirected case without the compiler, not the Windows Terminal one

Review caught that the WT_SESSION test was unsound. WT_SESSION is inherited, so
a run launched from Windows Terminal into a NEW legacy console, which is what
an elevated install gets, carries it with stdout not redirected and a buffer
that has no ENABLE_VIRTUAL_TERMINAL_PROCESSING. SupportsVirtualTerminal reports
host capability rather than the state of that buffer, so the branch would have
claimed VT and printed literal escape sequences.

There is no sound way to learn the current buffer's mode without GetConsoleMode,
which is the compile. So decide the other direction instead: a redirected stdout
is not a console, GetConsoleMode fails on a non-console handle, and the compiled
path could then only return $false. Return it directly.

This is provably identical rather than probably identical, and it covers the case
that was actually measured: install.rs spawns install.ps1 with a pipe, so the
desktop install is exactly where the compile was happening.

Also drops the env plumbing from _run_console_less. It is lru_cached, so a dict
argument would have raised TypeError before PowerShell was ever spawned, and the
Windows parity job would have failed rather than proving anything. The parity
case no longer needs it: the console-less probe IS the redirected case, so the
early return is the branch under test rather than a bystander.

* Reconstruct the exact merge-base function in the VT parity test

The regex stripped only the guard and left the four comments above it behind, so
the reconstructed predecessor was merge-base code plus comments rather than the
merge-base function. Comments do not execute, so the comparison was still
measuring the right thing, but a test that says it compares against the real
predecessor should do that. Verified both files now reconstruct byte for byte.

Also drops a stale WT_SESSION reference from an assertion message, left over
from the design this PR replaced.

* Tighten the comments this PR adds

---------

Co-authored-by: danielhanchen <danielhanchen@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-08-14 04:44:37 -07:00
..
__init__.py Consolidate dual venvs and separate install from update (#4530) 2026-03-25 05:24:21 -07:00
conftest.py Formatting: ruff line-length 100, kwarg-spacing passes, drop blank after short local imports (#6079) 2026-06-08 04:24:13 -07:00
test_bitsandbytes_kernel_readiness.py Anchor the bnb bind assertion on the symbol, not the module alias (#7590) 2026-07-28 21:35:04 -07:00
test_change_system_message.py Escape the system message spliced into predefined chat templates (#7746) 2026-08-02 07:18:09 -07:00
test_conftest_bitsandbytes_preimport.py Tests: import bitsandbytes before the GPU-free harness spoofs CUDA (#7582) 2026-07-28 18:52:25 -07:00
test_construct_chat_template_validation.py Render a static prefix when default_system_message is None (#8117) 2026-08-08 14:57:17 +02:00
test_cpo_processor_text_tokenizer.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_cross_platform_parity.py Reduce antivirus false positives in the desktop installers (#8586) 2026-08-13 07:02:18 -07:00
test_dpo_vision_processor_passthrough.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_e2e_no_torch_sandbox.py Studio: apply base.txt on the install.sh and install.ps1 paths (#8195) 2026-08-11 00:06:23 -07:00
test_fast_language_model_text_only.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_fast_model_config_passthrough.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_fast_sentence_transformer_embedding_parity.py Fix FastSentenceTransformer Qwen embedding preprocessing (#6939) 2026-07-09 01:46:22 -07:00
test_fast_sentence_transformer_redirect_lifecycle.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_flash_attn_install_python_stack.py Studio: verify the flash-attn import after installing it (#8465) 2026-08-12 05:43:51 -07:00
test_get_chat_template_escaping.py Escape the system message spliced into predefined chat templates (#7746) 2026-08-02 07:18:09 -07:00
test_get_lora_parameters_bias_fp8_block_size.py Propagate fp8 block_size before the early return in get_lora_parameters_bias (#7189) 2026-07-17 16:30:45 -07:00
test_get_lora_parameters_fp8_block_size.py Propagate fp8 block_size before the early return in get_lora_parameters_bias (#7189) 2026-07-17 16:30:45 -07:00
test_gpu_init_ldconfig_guard.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_grpo_ddp_model_config.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_import_without_bitsandbytes.py Keep import unsloth working when bitsandbytes is absent (#7502) 2026-07-28 08:03:54 -07:00
test_install_python_stack.py Studio: keep the extras install working under a hardened uv.toml / pip.conf (#8579) 2026-08-12 09:46:34 -07:00
test_install_uv_override_space.py Installer: make UV_OVERRIDE space-safe on Apple Silicon (#6503) (#6639) 2026-06-24 17:34:18 -07:00
test_mlx_public_trainer_api.py Bound dataset_num_proc by memory, and stop treating 1 as "no multiprocessing" (#7831) 2026-08-05 05:31:27 -07:00
test_module_entry_point.py Windows: stop depending on the generated unsloth.exe console script (#8592) 2026-08-13 07:54:51 -07:00
test_no_torch_filtering.py Studio: apply base.txt on the install.sh and install.ps1 paths (#8195) 2026-08-11 00:06:23 -07:00
test_orpo_processor_text_tokenizer.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_pad_token_fix.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_patch_trl_rl_trainers_defensive.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_remove_special_tokens_no_bos.py fix: guard remove_special_tokens against tokenizers without a BOS token (#7048) 2026-07-10 14:55:11 -03:00
test_revision_forwarding.py Forward revision to the config, weight and tokenizer loads (#4222) 2026-08-02 22:35:19 -07:00
test_rl_config_pickling.py Keep checkpoint saves working, and portable, once a TRL config is patched (#8344) 2026-08-10 20:49:40 -07:00
test_studio_import_no_torch.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_studio_runtime_gate.py Repair seven tests left behind by their own subjects (#8132) 2026-08-07 19:43:27 -07:00
test_to_sharegpt_optional_none.py Fix to_sharegpt optional block rendering "None" for missing extra columns (#6827) 2026-07-08 17:57:41 -03:00
test_tokenizers_and_torch_constraint.py Studio: drop the mlx-lm 0.31.3 exclusion so current mlx-vlm resolves (#7061) 2026-08-07 02:41:04 -03:00
test_torchcodec_torch_compat.py Gate the torchcodec audio extras to platforms that have a wheel (#7587) 2026-07-28 20:56:11 -07:00
test_unsloth_run_tool_policy_resolver.py Studio: honor a request's enable_tools: false instead of overriding it (#8547) 2026-08-12 06:26:58 -07:00
test_v100_fullft_precision.py Export ACCELERATE_MIXED_PRECISION when bf16/fp16 is set explicitly (fixes #4891) (#7534) 2026-07-29 06:39:18 -07:00
test_virustotal_scan.py Reduce antivirus false positives in the desktop installers (#8586) 2026-08-13 07:02:18 -07:00
test_vision_lora_targeting.py tests: read checked-in files as UTF-8 instead of the platform default (#7438) 2026-07-26 23:31:56 -07:00
test_windows_arm64_python_choice.py Windows: unblock the consumer install on clean and no-winget machines (#7549) 2026-07-28 22:24:40 -07:00
test_windows_git_gate.py Windows: do not abort setup on an unreadable llama.cpp install (#7735) 2026-08-02 07:25:39 -07:00
test_windows_installer_concurrency_guard.py Windows: stop depending on the generated unsloth.exe console script (#8592) 2026-08-13 07:54:51 -07:00
test_windows_no_torch_setup.py Fix Windows no-torch setup (#7511) 2026-07-28 05:54:25 -07:00
test_windows_python_313_8_screen.py Ask uv for a Python that can import torch, and skip the one that cannot (#7830) 2026-08-05 03:03:39 -07:00
test_windows_python_venv_hardening.py Make install.ps1 work with the user's PowerShell profile loaded (#8161) 2026-08-09 04:27:28 -07:00
test_windows_setup_output_encoding.py Windows: stop compiling C# for colour on hosts that already render it (#8767) 2026-08-14 04:44:37 -07:00
test_windows_studio_update_launcher.py Windows: stop depending on the generated unsloth.exe console script (#8592) 2026-08-13 07:54:51 -07:00
test_windows_vcredist_download_tls.py Windows: verify the publisher of the installers we download and run (#8418) 2026-08-11 05:18:46 -07:00
test_windows_xformers_installer.py Install a CUDA-matched xFormers on Windows instead of whatever PyPI serves (#8156) 2026-08-09 00:20:55 -07:00
test_windows_xformers_wheel_match.py Install a CUDA-matched xFormers on Windows instead of whatever PyPI serves (#8156) 2026-08-09 00:20:55 -07:00