left4me/l4d2web/tests
mwiegand 5f82950d7c
feat(files): delete /files/content endpoint + extract _apply_optional_rename
Step 12/12 of docs/superpowers/plans/2026-05-17-files-overlay-rewrite.md.
End of Phase C — end of the rewrite plan.

Two cleanups in one commit:

1. Delete GET /overlays/<id>/files/content.

The legacy openEditorForFile in files-overlay.js was its only caller,
and Step 9 deleted that code path. grep confirms no remaining live
callers (the matches in .claude/worktrees/* are other in-flight
branches; matches in docs/ are plan/spec text describing the route's
history). Removed:

  * The @bp.get route function (was already a thin wrapper around
    _load_file_for_editing from Step 11)
  * The endpoint's mention in the module docstring
  * test_content_returns_text
  * test_content_returns_415_for_binary
  * test_content_404_for_non_files_overlay
  * The /files/content entry in the batched "non-files-overlay 404s
    everywhere" test

The _load_file_for_editing helper from Step 11 becomes single-caller
(only the edit route uses it now). Kept because the function name
gives the prelude a useful named concept and inlining would add ~17
lines of low-density logic into overlay_file_edit_page.

2. Extract _apply_optional_rename.

overlay_file_save and overlay_file_replace had near-identical rename
branches: safe_resolve_for_move → 422-on-traversal, 409-if-dst-exists,
mkdir-parents, os.rename → echo_path = new_path. Extracted into
_apply_optional_rename(overlay, path, new_path) → (write_target,
echo_path) | Response.

The helper handles both cases:
  * Rename: atomic rename, returns (dst, new_path)
  * No rename: safe_resolve_for_write, mkdir parents, returns
    (write_target, path)

Save's "destination is not a file" 409 (creation branch) stays inline
in overlay_file_save — it's save-specific behavior that doesn't apply
to /replace (which assumes a file exists or creates one).

Subtle behavior change in /save: the prior code called
safe_resolve_for_write(new_path or path) upfront and then potentially
overrode write_target via safe_resolve_for_move. The new code only
calls one validator per branch. Confirmed equivalent: per
overlay_files.py:36-58 (safe_resolve_for_write) vs. lines 76-106
(safe_resolve_for_move), the dst-side checks are identical (root
escape, symlink refuse, parent-is-dir) and safe_resolve_for_move adds
strictly more (src must exist, cycle check for directory moves). pytest
covers the save/replace paths and stays green.

pytest: 580 → 577 passed, 1 skipped, 3 deselected. The -3 is the 3
deleted /files/content tests.

files_routes.py: ended at 735 lines. The plan estimated ~450 — the
delta is the new /files/new route (~43 lines, Step 5), the binary
template branch (Step 7), the _load_file_for_editing helper (Step 11),
and module-header expansions. The structural goal (no dead routes,
shared helpers across paths) is met.

End-of-plan summary:
  * 1091-line files-overlay.js → 4 focused modules totaling 1191 lines
    (core.js 247, editor.js 309, dialogs.js 212, uploads.js 423)
  * Editor flows (text edit, binary replace, create new) all run
    through URL-addressable modals (?modal= deep-linkable)
  * Legacy <dialog id="files-editor-modal"> deleted
  * /files/content deleted (dead endpoint)
  * Shared helpers _load_file_for_editing + _apply_optional_rename
  * pytest stayed green at every step
  * Chromium-verified every step

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 16:29:55 +02:00
..
e2e test(editor-v2): Playwright e2e + Tab→acceptCompletion fix 2026-05-17 02:15:51 +02:00
__init__.py refactor(repo): uv workspace + hatchling + layout restructure 2026-05-15 22:04:29 +02:00
test_admin_users.py secure(l4d2web): block non-admin writes on system overlays; last-admin guard on deactivate 2026-05-14 22:24:19 +02:00
test_alembic_migrations.py feat(l4d2-web): script overlay schema — add overlay.script + last_build_status, drop globals tables 2026-05-08 15:33:04 +02:00
test_auth.py test(datetime): pin tz-aware contract for fixtures (red until UtcDateTime lands) 2026-05-16 11:55:48 +02:00
test_blueprints.py feat(editor-v2): wire data-editor-language attrs into three textareas 2026-05-17 02:06:58 +02:00
test_cli.py tests/cli: cover running+cancelling idempotency, tighten app-context scope 2026-05-11 23:18:54 +02:00
test_config.py config: allow SESSION_COOKIE_SECURE override and disable on test deploy 2026-05-07 00:56:48 +02:00
test_console_routes.py feat(l4d2-web): console panel UI on server detail page 2026-05-14 21:39:21 +02:00
test_health.py security: harden boundary inputs and production defaults 2026-05-07 00:53:33 +02:00
test_host_commands.py fix(l4d2-web): keep SSE log stream from pinning gunicorn threads 2026-05-08 11:18:56 +02:00
test_job_logs.py refactor(repo): uv workspace + hatchling + layout restructure 2026-05-15 22:04:29 +02:00
test_job_worker.py job_worker: don't duplicate streamed stderr on HostCommandError 2026-05-10 22:52:54 +02:00
test_l4d2_facade.py feat(l4d2-web): add hostname edit form to server detail page 2026-05-13 15:42:46 +02:00
test_live_state_poller.py test(datetime): pin tz-aware contract for fixtures (red until UtcDateTime lands) 2026-05-16 11:55:48 +02:00
test_migrations.py feat(live-state): add schema for snapshots, sessions, steam profiles 2026-05-12 21:18:24 +02:00
test_models.py refactor(datetime): introduce UtcDateTime, remove naive-strip workarounds 2026-05-16 11:59:29 +02:00
test_overlay_builders.py overlay_builders: restore symlink overwrite guards + nits 2026-05-11 23:01:38 +02:00
test_overlay_creation.py feat(l4d2-web): overlay path helpers and creation 2026-05-07 16:38:39 +02:00
test_overlay_files.py feat(files-overlay): user-managed file content as a third overlay type 2026-05-09 18:59:32 +02:00
test_overlay_files_routes.py feat(files): delete /files/content endpoint + extract _apply_optional_rename 2026-05-17 16:29:55 +02:00
test_overlays.py auth: reject sessions older than user.password_changed_at 2026-05-11 21:54:13 +02:00
test_pages.py refactor(repo): uv workspace + hatchling + layout restructure 2026-05-15 22:04:29 +02:00
test_profile.py tests/test_profile: hoist sqlalchemy import to module top 2026-05-11 22:01:29 +02:00
test_rate_limit.py rate-limit: extract generic helper, reuse from login 2026-05-11 21:45:51 +02:00
test_rcon.py feat(l4d2-web): add execute_command to rcon service with full test coverage 2026-05-14 21:21:41 +02:00
test_script_overlay_routes.py feat(editor-v2): wire data-editor-language attrs into three textareas 2026-05-17 02:06:58 +02:00
test_security.py fix(csp): allow workshop preview thumbnails from steamusercontent.com 2026-05-16 11:22:30 +02:00
test_seed_script_overlays.py feat(l4d2-web): seed example script overlays from examples/script-overlays/ 2026-05-08 18:41:08 +02:00
test_servers.py test(datetime): pin tz-aware contract for fixtures (red until UtcDateTime lands) 2026-05-16 11:55:48 +02:00
test_status_and_server_logs.py auth: reject sessions older than user.password_changed_at 2026-05-11 21:54:13 +02:00
test_steam_users.py feat(live-state): use Steam avatarfull (184x184), downscale in CSS 2026-05-12 23:17:51 +02:00
test_steam_workshop.py feat(l4d2-web): steam workshop API client and downloader 2026-05-07 16:37:39 +02:00
test_timeago.py feat(app): register timeago Jinja filter 2026-05-16 11:10:59 +02:00
test_url_addressable_modals.py feat(files): delete legacy editor dialog + gut editor.js legacy paths 2026-05-17 16:20:27 +02:00
test_workshop_overlay_models.py feat(l4d2-web): script overlay schema — add overlay.script + last_build_status, drop globals tables 2026-05-08 15:33:04 +02:00
test_workshop_paths.py feat(l4d2-web): overlay path helpers and creation 2026-05-07 16:38:39 +02:00
test_workshop_routes.py workshop_routes: narrow refresh's steam exception handler 2026-05-11 23:08:41 +02:00