Commit Graph

5 Commits

Author SHA1 Message Date
Jedrzej Kosinski
fe7efc6283 deploy_environment: add CRLF / lone-CR newline tests
Per @guill review on PR #13425: add tests covering Windows-style line
endings, since editors often save files with CRLF and we want to confirm
the CR never leaks into the returned value.

- `_write_env_file` now opens with `newline=""` so the on-disk bytes
  match the literal string passed in (deterministic across host OSes,
  no `\n` -> `\r\n` translation on Windows).

New tests:
- `test_crlf_line_ending`: `"...\r\n"` -> value (no trailing CR).
- `test_crlf_multiline_only_first_line_used`: `readline(128)` stops at
  the translated newline boundary for CRLF lines.
- `test_crlf_with_surrounding_whitespace`: leading/trailing spaces +
  CRLF still yield the bare value.
- `test_lone_cr_line_ending`: classic-Mac / legacy editor `"...\r"`
  is also handled by universal-newlines decoding.

15/15 unit tests pass.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019df5a8-36be-7107-a4af-c7e4f51687df
2026-05-04 19:40:05 -07:00
Jedrzej Kosinski
38e5aac7bd Read .comfy_environment from ComfyUI install dir, not --base-directory
folder_paths.base_path is overridden by --base-directory to a user-supplied
location. Launchers/installers write the .comfy_environment marker next to the
ComfyUI install itself, so reading from base_path would silently fall back to
'local-git' whenever --base-directory is in use, defeating the purpose of the
env header.

Amp-Thread-ID: https://ampcode.com/threads/T-019df554-0cf8-755a-9f84-674e974aa5d1
Co-authored-by: Amp <amp@ampcode.com>
2026-05-04 16:52:15 -07:00
Jedrzej Kosinski
2001646f78 Switch deploy-environment value convention from underscores to dashes
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run
Default value is now 'local-git' (was 'local_git'). Dashes are easier to type and more conventional in HTTP-header-adjacent identifiers. Tests updated accordingly.

Amp-Thread-ID: https://ampcode.com/threads/T-019df26e-96f4-7518-94da-0e4263680e3c
Co-authored-by: Amp <amp@ampcode.com>
2026-05-04 07:20:22 -07:00
Jedrzej Kosinski
22186b3dae Use functools.cache instead of manual global cache
Replaces the hand-rolled '_cached_value' module global with @functools.cache, which is the standard Python idiom for memoization. Tests now use the built-in get_deploy_environment.cache_clear() to reset between cases.

Amp-Thread-ID: https://ampcode.com/threads/T-019df26e-96f4-7518-94da-0e4263680e3c
Co-authored-by: Amp <amp@ampcode.com>
2026-05-04 06:55:54 -07:00
Jedrzej Kosinski
06e416bd0d Bound .comfy_environment read at 128 bytes; add unit tests
Defense-in-depth: cap readline() so a malformed or maliciously-large single-line file cannot blow up memory before the value is sanitized.

Adds tests-unit/deploy_environment_test.py covering: missing file fallback, basic read, whitespace strip, multi-line (only first line used), empty + whitespace-only files, control-char stripping (header-injection protection), non-ASCII stripping, 128-byte read cap, cache stickiness, and OSError fallback.

Amp-Thread-ID: https://ampcode.com/threads/T-019df26e-96f4-7518-94da-0e4263680e3c
Co-authored-by: Amp <amp@ampcode.com>
2026-05-04 06:53:40 -07:00