[PR #2278] dev: accept argv, guard stdout.reconfigure, and reject whitespace --out #2281

Open
opened 2026-11-26 21:20:40 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2278
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/dev-cli-safety


📝 Commits (1)

  • 0da9526 dev: accept argv, guard stdout.reconfigure, and reject whitespace --out

📊 Changes

2 files changed (+34 additions, -4 deletions)

View changed files

📝 scripts/dev.py (+7 -4)
📝 tests/test_dev_discovery.py (+27 -0)

📄 Description

Claimed in the coordination issue as: DEV-CLI-STDOUT-RECONFIGURE-AND-ARGV-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191757339)

What and why

scripts/dev.py previously:

  • Defined main() with no argv parameter, preventing programmatic or in-process testing.
  • Called sys.stdout.reconfigure(encoding="utf-8") unguarded in discover, raising AttributeError when sys.stdout is replaced with io.StringIO or another non-reconfigurable stream.
  • Treated whitespace-only --out " " as a valid --out PATH in guest-scene.

This adds argv: list[str] | None = None to main(), wraps sys.stdout.reconfigure(encoding="utf-8") in try/except (AttributeError, ValueError, OSError), rejects whitespace-only --out in guest_scene(), and adds unit tests in tests/test_dev_discovery.py.

Tested

  • python -I tests/test_dev_discovery.py -v (5 passed)
  • python -I tests/test_dev_guest_scene.py -v (4 passed)
  • Detached upstream/main baseline negative control: failed with tests/test_dev_discovery.py before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2278 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/dev-cli-safety` --- ### 📝 Commits (1) - [`0da9526`](https://github.com/ubiquitarianism/leonida/commit/0da952685f9466423a319d5201b9ffe17d646d6b) dev: accept argv, guard stdout.reconfigure, and reject whitespace --out ### 📊 Changes **2 files changed** (+34 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `scripts/dev.py` (+7 -4) 📝 `tests/test_dev_discovery.py` (+27 -0) </details> ### 📄 Description Claimed in the coordination issue as: DEV-CLI-STDOUT-RECONFIGURE-AND-ARGV-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191757339) ### What and why `scripts/dev.py` previously: - Defined `main()` with no `argv` parameter, preventing programmatic or in-process testing. - Called `sys.stdout.reconfigure(encoding="utf-8")` unguarded in `discover`, raising `AttributeError` when `sys.stdout` is replaced with `io.StringIO` or another non-reconfigurable stream. - Treated whitespace-only `--out " "` as a valid `--out PATH` in `guest-scene`. This adds `argv: list[str] | None = None` to `main()`, wraps `sys.stdout.reconfigure(encoding="utf-8")` in `try/except (AttributeError, ValueError, OSError)`, rejects whitespace-only `--out` in `guest_scene()`, and adds unit tests in `tests/test_dev_discovery.py`. ### Tested - `python -I tests/test_dev_discovery.py -v` (5 passed) - `python -I tests/test_dev_guest_scene.py -v` (4 passed) - Detached `upstream/main` baseline negative control: failed with `tests/test_dev_discovery.py` before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2281
No description provided.