Skip to content

Normalize Python import formatting - #1573

Closed
0xjohnnydev wants to merge 2 commits into
mainfrom
chore/python-import-format-baseline
Closed

Normalize Python import formatting#1573
0xjohnnydev wants to merge 2 commits into
mainfrom
chore/python-import-format-baseline

Conversation

@0xjohnnydev

@0xjohnnydev 0xjohnnydev commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • run the repo lint formatter over Python tests/helpers that currently fail repo-wide isort/black checks
  • keep formatting-only churn out of the security split PRs

This branch is intended as the formatting baseline for the split security PRs so their diffs stay reviewable.

Testing

  • uv run isort --check-only .
  • uv run black --check .
  • uv run ruff check .

Summary by CodeRabbit

  • Tests

    • Refactored integration test suite with consistent multi-line formatting for driver tool calls and assertions.
    • Added conditional test-skipping for missing environment variables.
  • Chores

    • Reorganized module imports across the codebase for consistency.
    • Standardized code formatting, whitespace, and string literal quoting throughout test files.

Review Change Stack

@vercel

vercel Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview May 18, 2026 7:00pm

Request Review

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 820421b7-4942-4024-8b0b-b77187311509

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR applies comprehensive formatting and style standardization across the test suite and documentation scripts. Changes normalize import ordering, string literal quoting conventions, multi-line argument layouts, regex patterns, and whitespace placement consistently throughout the codebase without altering any functional logic or test behavior.

Changes

Code formatting and style standardization

Layer / File(s) Summary
Modal app S3 sync logging message formatting
docs/scripts/modal_app.py
Final log messages in sync_to_s3 converted from f-strings to plain string literals.
CUA driver-rs integration test formatting
libs/cua-driver-rs/tests/integration/*, libs/cua-driver-rs/tests/integration/v2/*, libs/cua-driver-rs/tests/integration/v2/harness/*
Import reordering, multi-line call argument formatting, regex string quoting normalization, whitespace adjustments, and assertion formatting updates across integration and v2 harness test files.
CUA driver integration test formatting
libs/cua-driver/Tests/integration/*, libs/cua-driver/Tests/integration/harness/*
Consistent formatting applied across CUA driver integration tests: import ordering, multi-line argument styles, regex quoting changes, and assertion layout normalization.
Sandbox/transport library test formatting
libs/python/cua-sandbox/cua_sandbox/transport/*, libs/python/cua-sandbox/tests/test_transport_http_retry.py
Multi-line logging call formatting and import cleanup in transport retry test.
Top-level test file import reordering
tests/test_image_builder.py, tests/test_image_builder_cloud.py, tests/test_interfaces.py, examples/sandboxes/test_linux_cloud_vm.py
Import reordering and addition of required module-level imports to support test functionality.

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

  • trycua/cua#1430: Both PRs touch docs/scripts/modal_app.py's sync_to_s3—the retrieved PR adds the S3 sync implementation, and the main PR only changes sync_to_s3's final completion log message formatting (f-strings → plain strings).
  • trycua/cua#1524: The main PR's formatting change inside libs/cua-driver-rs/tests/integration/test_focus_steal_parity.py (reflowing the test_launch_with_url_preserves_frontmost _launch(...) call) is directly related to the retrieved PR's focus-steal parity work that added/implemented the same test module/method.

Suggested reviewers

  • ddupont808

Poem

🐰 Code formatting anew,
String quotes and spacing bloom,
Test suites look fresh and bright,
Imports aligned just right!

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/python-import-format-baseline

@sentry

sentry Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libs/cua-driver-rs/tests/integration/test_cli.py`:
- Line 139: Replace insecure tempfile.mktemp usages by creating a
TemporaryDirectory for the test run and building socket/file paths inside it: in
the test setup assign a TemporaryDirectory object to a class attribute (e.g.,
cls._tmpdir = tempfile.TemporaryDirectory()) and set cls._sock_file =
os.path.join(cls._tmpdir.name, "<desired-name>.sock") instead of
tempfile.mktemp; update the other mktemp occurrences the same way (use
os.path.join(cls._tmpdir.name, ...)); ensure teardown/cleanup calls
cls._tmpdir.cleanup() so the directory is removed after tests. This targets the
cls._sock_file assignments and other mktemp usages in the test module.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e1761b7-9564-4ecf-92f6-1dfdf8de44ca

📥 Commits

Reviewing files that changed from the base of the PR and between 0f834c6 and 5ae1c1f.

📒 Files selected for processing (57)
  • docs/scripts/modal_app.py
  • examples/sandboxes/test_linux_cloud_vm.py
  • libs/cua-driver-rs/tests/integration/driver_client.py
  • libs/cua-driver-rs/tests/integration/test_api_parity.py
  • libs/cua-driver-rs/tests/integration/test_background_focus.py
  • libs/cua-driver-rs/tests/integration/test_cli.py
  • libs/cua-driver-rs/tests/integration/test_concurrent_drivers.py
  • libs/cua-driver-rs/tests/integration/test_cursor_visibility.py
  • libs/cua-driver-rs/tests/integration/test_double_click_delivery.py
  • libs/cua-driver-rs/tests/integration/test_focus_steal_parity.py
  • libs/cua-driver-rs/tests/integration/test_list_windows.py
  • libs/cua-driver-rs/tests/integration/test_overlay_z_order.py
  • libs/cua-driver-rs/tests/integration/test_pixel_click_delivery.py
  • libs/cua-driver-rs/tests/integration/v2/conftest.py
  • libs/cua-driver-rs/tests/integration/v2/harness/cv.py
  • libs/cua-driver-rs/tests/integration/v2/harness/driver.py
  • libs/cua-driver-rs/tests/integration/v2/harness/monitor.py
  • libs/cua-driver-rs/tests/integration/v2/harness/tree.py
  • libs/cua-driver-rs/tests/integration/v2/test_blender.py
  • libs/cua-driver-rs/tests/integration/v2/test_chrome.py
  • libs/cua-driver-rs/tests/integration/v2/test_electron.py
  • libs/cua-driver-rs/tests/integration/v2/test_safari.py
  • libs/cua-driver-rs/tests/integration/v2/test_tauri.py
  • libs/cua-driver/Tests/integration/conftest.py
  • libs/cua-driver/Tests/integration/driver_client.py
  • libs/cua-driver/Tests/integration/harness/cv.py
  • libs/cua-driver/Tests/integration/harness/driver.py
  • libs/cua-driver/Tests/integration/harness/monitor.py
  • libs/cua-driver/Tests/integration/harness/tree.py
  • libs/cua-driver/Tests/integration/test_background_focus.py
  • libs/cua-driver/Tests/integration/test_background_menu_shortcut.py
  • libs/cua-driver/Tests/integration/test_blender.py
  • libs/cua-driver/Tests/integration/test_browser_js.py
  • libs/cua-driver/Tests/integration/test_check_permissions_cli.py
  • libs/cua-driver/Tests/integration/test_chrome.py
  • libs/cua-driver/Tests/integration/test_chrome_minimized_nav.py
  • libs/cua-driver/Tests/integration/test_click_opens_new_window.py
  • libs/cua-driver/Tests/integration/test_click_pixel_ax.py
  • libs/cua-driver/Tests/integration/test_drag_slider_delivery.py
  • libs/cua-driver/Tests/integration/test_electron.py
  • libs/cua-driver/Tests/integration/test_hermes_chrome_form_fill.py
  • libs/cua-driver/Tests/integration/test_hermes_form_fill.py
  • libs/cua-driver/Tests/integration/test_hermes_form_fill_qwen.py
  • libs/cua-driver/Tests/integration/test_hermes_launch_safari_bg.py
  • libs/cua-driver/Tests/integration/test_hidden_app_capture.py
  • libs/cua-driver/Tests/integration/test_launch_app_visible.py
  • libs/cua-driver/Tests/integration/test_list_windows.py
  • libs/cua-driver/Tests/integration/test_overlay_z_order.py
  • libs/cua-driver/Tests/integration/test_safari.py
  • libs/cua-driver/Tests/integration/test_tauri.py
  • libs/cua-driver/Tests/integration/test_webkit_js.py
  • libs/python/cua-sandbox/cua_sandbox/transport/cloud.py
  • libs/python/cua-sandbox/cua_sandbox/transport/http.py
  • libs/python/cua-sandbox/tests/test_transport_http_retry.py
  • tests/test_image_builder.py
  • tests/test_image_builder_cloud.py
  • tests/test_interfaces.py
💤 Files with no reviewable changes (3)
  • tests/test_image_builder_cloud.py
  • tests/test_image_builder.py
  • tests/test_interfaces.py

import os
import tempfile

cls._sock_file = tempfile.mktemp(suffix=".sock", prefix="cua-driver-test-")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify deprecated mktemp usage in Python tests/helpers.
rg -nP --type=py '\btempfile\.mktemp\s*\('

Repository: trycua/cua

Length of output: 679


🏁 Script executed:

cd libs/cua-driver-rs/tests/integration && wc -l test_cli.py

Repository: trycua/cua

Length of output: 70


🏁 Script executed:

cd libs/cua-driver-rs/tests/integration && sed -n '130,180p' test_cli.py

Repository: trycua/cua

Length of output: 1858


🏁 Script executed:

cd libs/cua-driver-rs/tests/integration && head -20 test_cli.py

Repository: trycua/cua

Length of output: 631


🌐 Web query:

Python tempfile.mktemp deprecated insecure CWE-377

💡 Result:

The Python function tempfile.mktemp is deprecated and considered insecure because it creates a race condition vulnerability, classified under CWE-377 (Insecure Temporary File) [1][2][3]. The insecurity arises because mktemp only generates a unique filename; it does not create the file itself [3][4]. This creates a time-of-check to time-of-use (TOCTOU) window between the moment the filename is returned and the moment the application subsequently opens or creates the file [5][3][6]. During this interval, a malicious process can predict the filename and create a file (or a symbolic link) at that location, potentially allowing the attacker to hijack the file, access sensitive data, or perform denial-of-service attacks [7][5][3][4]. Key points regarding its status: - Deprecation: The function has been deprecated since Python 2.3 [7][6][8]. - Security Risk: It is widely flagged by security linters (such as Bandit and Ruff) and static analysis tools (like CodeQL) as a security vulnerability [3][4]. - Recommended Alternatives: Developers should use secure alternatives that handle file creation atomically, such as tempfile.mkstemp or the context manager tempfile.NamedTemporaryFile [3][4][6]. If a file must persist after the context manager closes, NamedTemporaryFile(delete=False) can be used [7][6][8].

Citations:


🏁 Script executed:

cd libs/cua-driver-rs/tests/integration && sed -n '160,175p' test_cli.py

Repository: trycua/cua

Length of output: 699


🏁 Script executed:

cd libs/cua-driver-rs/tests/integration && head -30 test_cli.py | grep -E '^import|^from'

Repository: trycua/cua

Length of output: 202


Replace deprecated tempfile.mktemp usages with tempfile.TemporaryDirectory.

Lines 139, 161, and 169 use tempfile.mktemp(), which is deprecated since Python 2.3 and creates a race condition vulnerability (CWE-377). Between generating the filename and creating the file, an attacker can exploit this time-of-check-time-of-use window. Replace with TemporaryDirectory for atomic, secure temp file handling.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/cua-driver-rs/tests/integration/test_cli.py` at line 139, Replace
insecure tempfile.mktemp usages by creating a TemporaryDirectory for the test
run and building socket/file paths inside it: in the test setup assign a
TemporaryDirectory object to a class attribute (e.g., cls._tmpdir =
tempfile.TemporaryDirectory()) and set cls._sock_file =
os.path.join(cls._tmpdir.name, "<desired-name>.sock") instead of
tempfile.mktemp; update the other mktemp occurrences the same way (use
os.path.join(cls._tmpdir.name, ...)); ensure teardown/cleanup calls
cls._tmpdir.cleanup() so the directory is removed after tests. This targets the
cls._sock_file assignments and other mktemp usages in the test module.

@injaneity

Copy link
Copy Markdown
Collaborator

closing as outdated, since current main already has ci-lint-python.yml enforcing isort, black, and ruff for libs/python and tests.

@injaneity injaneity closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants