wintegrate 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. wintegrate-0.1.0/.github/workflows/ci.yml +171 -0
  2. wintegrate-0.1.0/.github/workflows/publish.yml +57 -0
  3. wintegrate-0.1.0/.gitignore +18 -0
  4. wintegrate-0.1.0/.mailmap +1 -0
  5. wintegrate-0.1.0/LICENSE +21 -0
  6. wintegrate-0.1.0/PKG-INFO +210 -0
  7. wintegrate-0.1.0/README.md +166 -0
  8. wintegrate-0.1.0/pyproject.toml +89 -0
  9. wintegrate-0.1.0/src/wintegrate/__init__.py +114 -0
  10. wintegrate-0.1.0/src/wintegrate/apps.py +100 -0
  11. wintegrate-0.1.0/src/wintegrate/diagnostics.py +409 -0
  12. wintegrate-0.1.0/src/wintegrate/element.py +799 -0
  13. wintegrate-0.1.0/src/wintegrate/env.py +105 -0
  14. wintegrate-0.1.0/src/wintegrate/exceptions.py +43 -0
  15. wintegrate-0.1.0/src/wintegrate/interop.py +877 -0
  16. wintegrate-0.1.0/src/wintegrate/recorder.py +234 -0
  17. wintegrate-0.1.0/src/wintegrate/session.py +465 -0
  18. wintegrate-0.1.0/src/wintegrate/text.py +36 -0
  19. wintegrate-0.1.0/src/wintegrate/window.py +340 -0
  20. wintegrate-0.1.0/tests/conftest.py +19 -0
  21. wintegrate-0.1.0/tests/test_census.py +26 -0
  22. wintegrate-0.1.0/tests/test_desktop_uwp_calculator.py +90 -0
  23. wintegrate-0.1.0/tests/test_e2e_notepad.py +23 -0
  24. wintegrate-0.1.0/tests/test_find_semantics.py +61 -0
  25. wintegrate-0.1.0/tests/test_ime_and_layout.py +117 -0
  26. wintegrate-0.1.0/tests/test_integrated_e2e.py +82 -0
  27. wintegrate-0.1.0/tests/test_key_spec.py +71 -0
  28. wintegrate-0.1.0/tests/test_multi_window.py +137 -0
  29. wintegrate-0.1.0/tests/test_recorder_and_inspect.py +76 -0
  30. wintegrate-0.1.0/tests/test_recorder_backend.py +76 -0
  31. wintegrate-0.1.0/tests/test_replace_pywinauto.py +58 -0
  32. wintegrate-0.1.0/tests/test_text_and_exceptions.py +37 -0
  33. wintegrate-0.1.0/tests/test_win32_dialog.py +196 -0
  34. wintegrate-0.1.0/tests/win32_dialog_app.py +218 -0
  35. wintegrate-0.1.0/uv.lock +452 -0
@@ -0,0 +1,171 @@
1
+ name: CI UI Automation Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ # Every pull request, not just those targeting main: a stacked PR based on
7
+ # another feature branch would otherwise get no CI at all, and could only be
8
+ # verified after its base was merged.
9
+ pull_request:
10
+
11
+ jobs:
12
+ lint:
13
+ runs-on: windows-latest
14
+ steps:
15
+ - uses: actions/checkout@v6
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v7
19
+ with:
20
+ python-version: "3.13"
21
+
22
+ - name: Install dependencies
23
+ run: |
24
+ python -m pip install --upgrade pip
25
+ pip install ruff
26
+
27
+ - name: Run Ruff Lint & Format Check
28
+ run: |
29
+ ruff check src/ tests/
30
+ ruff format --check src/ tests/
31
+
32
+ test-x64:
33
+ needs: lint
34
+ runs-on: windows-latest
35
+ strategy:
36
+ fail-fast: false
37
+ matrix:
38
+ python-version: ["3.11", "3.12", "3.13", "3.14"]
39
+
40
+ steps:
41
+ - uses: actions/checkout@v6
42
+
43
+ - name: Set up Python ${{ matrix.python-version }}
44
+ uses: actions/setup-python@v7
45
+ with:
46
+ python-version: ${{ matrix.python-version }}
47
+
48
+ - name: Install dependencies
49
+ run: |
50
+ python -m pip install --upgrade pip
51
+ pip install -e .[dev]
52
+
53
+ - name: Run unit & live GUI recording tests
54
+ run: |
55
+ pytest tests/ -v -s
56
+
57
+ - name: Upload Recording Artifacts & Diagnostics
58
+ if: always()
59
+ uses: actions/upload-artifact@v6
60
+ with:
61
+ name: ci-artifacts-x64-py${{ matrix.python-version }}
62
+ path: |
63
+ recording-artifacts/
64
+ artifacts/
65
+ if-no-files-found: ignore
66
+
67
+ test-arm64:
68
+ needs: lint
69
+ runs-on: windows-11-arm
70
+ strategy:
71
+ fail-fast: false
72
+ matrix:
73
+ # GitHub Actions setup-python provides official Windows ARM64 builds for Python 3.11+
74
+ python-version: ["3.11", "3.12", "3.13", "3.14"]
75
+
76
+ steps:
77
+ - uses: actions/checkout@v6
78
+
79
+ - name: Install WSL on ARM Runner (Stop 30s probe popups)
80
+ shell: pwsh
81
+ run: |
82
+ # 1. Update WSL stub so the provision daemon stops spawning terminal popups every 30s
83
+ $p = Start-Process -FilePath wsl.exe -ArgumentList '--update', '--confirm' -NoNewWindow -PassThru
84
+ if (-not $p.WaitForExit(60000)) { $p.Kill(); Write-Host 'wsl --update timed out' }
85
+
86
+ # 2. Fallback to arm64 MSI if needed
87
+ function Get-WslStatus {
88
+ $prev = [Console]::OutputEncoding
89
+ try {
90
+ [Console]::OutputEncoding = [System.Text.Encoding]::Unicode
91
+ return ((& wsl.exe --status 2>&1 | Out-String) -replace "\0", '')
92
+ } finally { [Console]::OutputEncoding = $prev }
93
+ }
94
+ $status = Get-WslStatus
95
+ Write-Host "WSL status: $status"
96
+ if ($status -match 'not installed') {
97
+ try {
98
+ $rel = Invoke-RestMethod 'https://api.github.com/repos/microsoft/WSL/releases/latest'
99
+ $asset = $rel.assets | Where-Object { $_.name -match 'arm64\.msi$' } | Select-Object -First 1
100
+ if ($asset) {
101
+ Write-Host "Downloading $($asset.name)..."
102
+ Invoke-WebRequest -Uri $asset.browser_download_url -OutFile wsl-arm64.msi
103
+ Start-Process msiexec -ArgumentList '/i', 'wsl-arm64.msi', '/qn', '/norestart' -Wait
104
+ }
105
+ } catch {
106
+ Write-Host "WSL MSI fallback skipped: $_"
107
+ }
108
+ }
109
+
110
+ # 3. Disable Microsoft Edge First Run Experience via Registry
111
+ New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Force -ErrorAction SilentlyContinue
112
+ Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name "HideFirstRunExperience" -Value 1 -Type DWord -Force -ErrorAction SilentlyContinue
113
+ Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name "PreventFirstRunPage" -Value 1 -Type DWord -Force -ErrorAction SilentlyContinue
114
+ New-Item -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Force -ErrorAction SilentlyContinue
115
+ Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "HideFirstRunExperience" -Value 1 -Type DWord -Force -ErrorAction SilentlyContinue
116
+
117
+ # 4. Sweep existing background popups
118
+ Get-Process -Name "wsl","wslhost","WindowsTerminal","msedge","msedgewebview2" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
119
+ $global:LASTEXITCODE = 0
120
+
121
+ # Python 3.12+ ships pre-installed in the windows-11-arm image's tool cache,
122
+ # but 3.11 does not: setup-python downloads and installs it on every run
123
+ # (~90s). Cache the installed toolchain so later runs restore it instead.
124
+ - name: Cache Python ${{ matrix.python-version }} toolchain
125
+ if: matrix.python-version == '3.11'
126
+ uses: actions/cache@v4
127
+ with:
128
+ path: C:\hostedtoolcache\windows\Python\3.11*
129
+ key: python-toolchain-winarm64-${{ matrix.python-version }}
130
+
131
+ - name: Set up Python ${{ matrix.python-version }}
132
+ uses: actions/setup-python@v7
133
+ with:
134
+ python-version: ${{ matrix.python-version }}
135
+
136
+ - name: Install FFmpeg on Windows ARM64
137
+ continue-on-error: true
138
+ shell: pwsh
139
+ run: |
140
+ # Use official BtbN winarm64 static build for native performance
141
+ try {
142
+ $ProgressPreference = 'SilentlyContinue'
143
+ Invoke-WebRequest -Uri "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-winarm64-gpl.zip" -OutFile ffmpeg-arm64.zip
144
+ Expand-Archive -Path ffmpeg-arm64.zip -DestinationPath ffmpeg-arm64 -Force
145
+ $binDir = Get-ChildItem -Path ffmpeg-arm64 -Filter bin -Recurse -Directory | Select-Object -First 1 -ExpandProperty FullName
146
+ Write-Host "Native ARM64 FFmpeg at: $binDir"
147
+ Add-Content -Path $env:GITHUB_PATH -Value $binDir
148
+ } catch {
149
+ Write-Host "ARM64 FFmpeg download fallback to Chocolatey"
150
+ choco install ffmpeg -y --no-progress
151
+ Add-Content -Path $env:GITHUB_PATH -Value "C:\ProgramData\chocolatey\bin"
152
+ }
153
+
154
+ - name: Install dependencies
155
+ run: |
156
+ python -m pip install --upgrade pip
157
+ pip install -e .[dev]
158
+
159
+ - name: Run unit & live GUI recording tests
160
+ run: |
161
+ pytest tests/ -v -s
162
+
163
+ - name: Upload Recording Artifacts & Diagnostics
164
+ if: always()
165
+ uses: actions/upload-artifact@v6
166
+ with:
167
+ name: ci-artifacts-arm64-py${{ matrix.python-version }}
168
+ path: |
169
+ recording-artifacts/
170
+ artifacts/
171
+ if-no-files-found: ignore
@@ -0,0 +1,57 @@
1
+ name: Publish to PyPI
2
+
3
+ # Publishes on a GitHub Release. workflow_dispatch is kept for a manual re-run of
4
+ # a release that failed after the tag was already cut.
5
+ on:
6
+ release:
7
+ types: [published]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v6
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v7
18
+ with:
19
+ python-version: "3.13"
20
+
21
+ - name: Build sdist and wheel
22
+ run: |
23
+ python -m pip install --upgrade pip build
24
+ python -m build
25
+
26
+ - name: Verify metadata and long description render
27
+ run: |
28
+ python -m pip install twine
29
+ python -m twine check --strict dist/*
30
+
31
+ # A release tag must match the version in pyproject.toml, otherwise the
32
+ # published artifact silently disagrees with the tag people cite.
33
+ - name: Check tag matches package version
34
+ if: github.event_name == 'release'
35
+ run: |
36
+ VERSION=$(python -c 'import tomllib,pathlib;print(tomllib.loads(pathlib.Path("pyproject.toml").read_text())["project"]["version"])')
37
+ TAG="${GITHUB_REF_NAME#v}"
38
+ echo "pyproject version: $VERSION / tag: $TAG"
39
+ test "$VERSION" = "$TAG"
40
+
41
+ - uses: actions/upload-artifact@v6
42
+ with:
43
+ name: dist
44
+ path: dist/
45
+
46
+ publish-pypi:
47
+ needs: build
48
+ runs-on: ubuntu-latest
49
+ environment: pypi
50
+ permissions:
51
+ id-token: write # OIDC token for Trusted Publishing; no API token stored
52
+ steps:
53
+ - uses: actions/download-artifact@v6
54
+ with:
55
+ name: dist
56
+ path: dist/
57
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,18 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.pyd
5
+ .pytest_cache/
6
+ *.egg-info/
7
+ dist/
8
+ build/
9
+ .coverage
10
+ htmlcov/
11
+ artifacts/
12
+ recording-artifacts/
13
+ tmp-*/
14
+ *.log
15
+ *.mp4
16
+ *.webp
17
+ *.png
18
+ scratch_debug_*.py
@@ -0,0 +1 @@
1
+ Mango Yen <mango.yen.tw@gmail.com> mangokingTW <mangokingtw@gmail.com>
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mango Yen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,210 @@
1
+ Metadata-Version: 2.5
2
+ Name: wintegrate
3
+ Version: 0.1.0
4
+ Summary: CI-first Windows UI automation library designed for unattended headless/CI runners.
5
+ Project-URL: Homepage, https://github.com/mangokingTW/wintegrate
6
+ Project-URL: Repository, https://github.com/mangokingTW/wintegrate
7
+ Project-URL: Issues, https://github.com/mangokingTW/wintegrate/issues
8
+ Project-URL: Changelog, https://github.com/mangokingTW/wintegrate/releases
9
+ Author-email: Mango Yen <mango.yen.tw@gmail.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: arm64,ci,gui-testing,testing,ui-automation,uia,windows
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Win32 (MS Windows)
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Software Development :: Quality Assurance
24
+ Classifier: Topic :: Software Development :: Testing
25
+ Requires-Python: >=3.11
26
+ Requires-Dist: comtypes>=1.4.16
27
+ Provides-Extra: all
28
+ Requires-Dist: av>=15.0.0; extra == 'all'
29
+ Requires-Dist: pillow>=12.3.0; extra == 'all'
30
+ Requires-Dist: pyvda>=0.6.0; extra == 'all'
31
+ Provides-Extra: desktop
32
+ Requires-Dist: pyvda>=0.6.0; extra == 'desktop'
33
+ Provides-Extra: dev
34
+ Requires-Dist: av>=15.0.0; extra == 'dev'
35
+ Requires-Dist: pillow>=12.3.0; extra == 'dev'
36
+ Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
37
+ Requires-Dist: pytest>=9.1.1; extra == 'dev'
38
+ Requires-Dist: pyvda>=0.6.0; extra == 'dev'
39
+ Requires-Dist: ruff>=0.16.5; extra == 'dev'
40
+ Provides-Extra: video
41
+ Requires-Dist: av>=15.0.0; extra == 'video'
42
+ Requires-Dist: pillow>=12.3.0; extra == 'video'
43
+ Description-Content-Type: text/markdown
44
+
45
+ # wintegrate
46
+
47
+ A Python library for driving Windows GUIs **from CI**, where no human is watching and the only evidence of what happened is whatever the run left behind.
48
+
49
+ [![CI UI Automation Tests](https://github.com/mangokingTW/wintegrate/actions/workflows/ci.yml/badge.svg)](https://github.com/mangokingTW/wintegrate/actions/workflows/ci.yml)
50
+ [![Python 3.11 | 3.12 | 3.13 | 3.14](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)](https://pypi.org/project/wintegrate/)
51
+ [![Architecture x64 | ARM64](https://img.shields.io/badge/architecture-x64%20%7C%20ARM64-brightgreen)](https://github.com/mangokingTW/wintegrate)
52
+ [![Code Style: Ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
53
+
54
+ ---
55
+
56
+ ## Why wintegrate?
57
+
58
+ Most Windows GUI automation frameworks (e.g. `pywinauto`, `pyautogui`) are built for interactive desktop use on developer workstations. In unattended CI runners (`windows-latest`, `windows-11-arm`), standard interactive assumptions break down:
59
+
60
+ - **Fail-safes panic in CI**: Moving the cursor into a corner panics interactive libraries and halts test runs.
61
+ - **Stale COM wrappers**: Reusing resolved UI element references across seconds causes silent `COMError` failures.
62
+ - **Launcher PID != Window PID**: Modern packaged Windows apps (like Notepad, Terminal) launch a starter shim process that does not own the visible HWND.
63
+ - **Memory & Pipe Deadlocks**: In-memory frame capture exhausts RAM; streaming with unbuffered `stderr` pipes deadlocks subprocesses.
64
+ - **ARM64 Scancode & Input Drops**: DirectX scan-code simulation fails on Windows ARM64 virtualization; keypresses are dropped without verification.
65
+ - **Multi-Window Discovery Collision**: Launching multiple instances of identical apps causes discovery diffs to select the existing instance rather than the new one.
66
+ - **Unverified fire-and-forget**: Typing without post-condition assertions hides silent failures (e.g. counting `\n` while Notepad returns `\r\n` or `\r`).
67
+
68
+ `wintegrate` is engineered specifically for **unattended CI reliability** across both **x64 and ARM64 Windows**.
69
+
70
+ ---
71
+
72
+ ## Core Features & Architecture
73
+
74
+ ### 1. Verified Actions & Post-Conditions
75
+ Every UI interaction confirms its post-condition (line count deltas, buffer content, focus transitions) before returning:
76
+ ```python
77
+ editor.type_verified(
78
+ "Hello from CI\nSecond line\n",
79
+ expected_line_count_delta=2,
80
+ verify_contains="Hello from CI\nSecond line",
81
+ delay_per_char=0.03,
82
+ )
83
+ ```
84
+
85
+ ### 2. Universal x64 & ARM64 Native Unicode Input
86
+ Replaced DirectX scan-code simulation with native Win32 `SendInput` utilizing `KEYEVENTF_UNICODE`. Seamlessly injects special characters, linebreaks, and multibyte Unicode across both Intel/AMD x64 and Windows 11 ARM64 virtualization runners.
87
+
88
+ ### 3. Multi-Window Isolation & Discovery Exclusion
89
+ Supports launching and discovering multiple concurrent instances of the same application without PID/HWND collisions:
90
+ ```python
91
+ with session.app(NOTEPAD) as app_a:
92
+ # exclude_hwnds guarantees discovery finds the new window, not the existing one.
93
+ # fresh=False: the leftover sweep would otherwise kill Window A.
94
+ with session.app(NOTEPAD, fresh=False, exclude_hwnds={app_a.window.hwnd}) as app_b:
95
+ app_a.find_text_input().type_verified("Window A\n", expected_line_count_delta=1)
96
+ app_b.find_text_input().type_verified("Window B\n", expected_line_count_delta=1)
97
+ ```
98
+
99
+ ### 4. Non-Invasive Thread Input Focus (`AttachThreadInput`)
100
+ Switches foreground focus cleanly using `AttachThreadInput` synchronization between the automation thread and the target window thread. Grants activation authority without invasive keystrokes or Z-order corruption.
101
+
102
+ ### 5. Windows 11 Virtual Desktop Clean-Room Isolation (`pyvda`)
103
+ Supports dynamic virtual desktop isolation. When `isolated_virtual_desktop=True`, `wintegrate` creates a clean virtual desktop on the fly, switches to it, executes test operations in isolation away from background noise, and automatically destroys the test desktop on exit.
104
+
105
+ ### 6. Streaming Video & Diagnostic Pipeline
106
+ - **Low-Memory Streaming Recorder**: `ContinuousRecorder` encodes in-process through PyAV (which bundles FFmpeg), falling back to an external FFmpeg subprocess with `stderr` redirected to disk logs. PyAV is preferred because it is the only FFmpeg on PyPI with a `win_arm64` wheel — recording works out of the box on Windows ARM64, where every ffmpeg-shipping package leaves you to install a binary yourself. Frames carry wall-clock timestamps, so a capture loop that falls behind the nominal frame rate still plays back at real speed.
107
+ - **Automatic Failure Artifacts**: Automatically dumps full-screen screenshots and pre/post `window_census.json` diffs on assertion failure.
108
+ - **Event Timeline Logging**: Logs action timestamps and targets to human-readable `.log` and structured `.json`.
109
+
110
+ ### 7. Managed App Lifecycle & Locale-Independent Discovery (`session.app`)
111
+ Modern Windows apps break naive launch-and-poll automation in specific, repeatable ways.
112
+ `session.app()` packages the countermeasures:
113
+
114
+ ```python
115
+ from wintegrate import NOTEPAD, Session, SessionConfig
116
+
117
+ with Session(SessionConfig()) as session:
118
+ with session.app(NOTEPAD) as app: # cleanup guaranteed, even on failure
119
+ editor = app.find_text_input() # locale-independent control ladder
120
+ editor.type_verified("hello\n", expected_line_count_delta=1)
121
+ ```
122
+
123
+ - **No localized strings**: windows are matched by process image name (`Notepad.exe`),
124
+ window class (`Notepad`), and UIA control types — none of which change with the UI
125
+ language. Title regexes are a last-resort fallback and live once, in the `AppSpec`.
126
+ - **Single-instance safety**: Store apps (Notepad) reuse a running instance — a leaked
127
+ instance makes the next launch open a *tab* instead of a new window, and discovery
128
+ times out mysteriously. `fresh="auto"` sweeps leftovers before launching (CI only).
129
+ - **Cold-start headroom**: first launches of Store apps regularly exceed 10s on CI
130
+ runners (ARM64 especially); managed launches default to a 30s discovery timeout.
131
+ - **No leaks**: the context manager closes the window and kills the process on exit,
132
+ and a timed-out discovery kills its own launcher.
133
+
134
+ ---
135
+
136
+ ## Quickstart
137
+
138
+ ```python
139
+ from wintegrate import NOTEPAD, Session, SessionConfig
140
+
141
+ config = SessionConfig(
142
+ artifact_dir="./ci-artifacts",
143
+ record_video=True,
144
+ fps=30,
145
+ )
146
+
147
+ with Session(config) as session:
148
+ # Managed lifecycle: locale-independent discovery, single-instance safety,
149
+ # generous cold-start timeout, and guaranteed cleanup on exit.
150
+ with session.app(NOTEPAD) as app:
151
+ editor = app.find_text_input()
152
+
153
+ # Types hardware keystrokes and verifies line count delta & text content
154
+ editor.type_verified(
155
+ "Hello from CI\nSecond line\n",
156
+ expected_line_count_delta=2,
157
+ verify_contains="Hello from CI\nSecond line",
158
+ )
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Installation
164
+
165
+ ```bash
166
+ pip install wintegrate # core: window/element automation, verified input
167
+ uv add wintegrate
168
+ ```
169
+
170
+ The core install depends on `comtypes` alone. Two optional extras pull in the
171
+ heavier pieces only if you use them:
172
+
173
+ ```bash
174
+ pip install 'wintegrate[video]' # screen recording + failure screenshots (Pillow, PyAV)
175
+ pip install 'wintegrate[desktop]' # virtual desktop clean-room isolation (pyvda)
176
+ pip install 'wintegrate[all]'
177
+ ```
178
+
179
+ Using a feature without its extra raises an error naming the extra to install, so a
180
+ missing dependency never turns into a silently skipped diagnostic.
181
+
182
+ Or install from source with development dependencies:
183
+ ```bash
184
+ git clone https://github.com/mangokingTW/wintegrate.git
185
+ cd wintegrate
186
+ pip install -e .[dev]
187
+ ```
188
+
189
+ Windows only: the package imports on other platforms (so cross-platform tooling and
190
+ `env` checks work), but every Win32/UIA call raises a clear unsupported-platform error.
191
+
192
+ ---
193
+
194
+ ## Running Tests
195
+
196
+ Run full test suite locally:
197
+ ```powershell
198
+ pytest tests/ -v -s
199
+ ```
200
+
201
+ Run static code analysis & formatting check:
202
+ ```powershell
203
+ ruff check src/ tests/
204
+ ```
205
+
206
+ ---
207
+
208
+ ## License
209
+
210
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,166 @@
1
+ # wintegrate
2
+
3
+ A Python library for driving Windows GUIs **from CI**, where no human is watching and the only evidence of what happened is whatever the run left behind.
4
+
5
+ [![CI UI Automation Tests](https://github.com/mangokingTW/wintegrate/actions/workflows/ci.yml/badge.svg)](https://github.com/mangokingTW/wintegrate/actions/workflows/ci.yml)
6
+ [![Python 3.11 | 3.12 | 3.13 | 3.14](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)](https://pypi.org/project/wintegrate/)
7
+ [![Architecture x64 | ARM64](https://img.shields.io/badge/architecture-x64%20%7C%20ARM64-brightgreen)](https://github.com/mangokingTW/wintegrate)
8
+ [![Code Style: Ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
9
+
10
+ ---
11
+
12
+ ## Why wintegrate?
13
+
14
+ Most Windows GUI automation frameworks (e.g. `pywinauto`, `pyautogui`) are built for interactive desktop use on developer workstations. In unattended CI runners (`windows-latest`, `windows-11-arm`), standard interactive assumptions break down:
15
+
16
+ - **Fail-safes panic in CI**: Moving the cursor into a corner panics interactive libraries and halts test runs.
17
+ - **Stale COM wrappers**: Reusing resolved UI element references across seconds causes silent `COMError` failures.
18
+ - **Launcher PID != Window PID**: Modern packaged Windows apps (like Notepad, Terminal) launch a starter shim process that does not own the visible HWND.
19
+ - **Memory & Pipe Deadlocks**: In-memory frame capture exhausts RAM; streaming with unbuffered `stderr` pipes deadlocks subprocesses.
20
+ - **ARM64 Scancode & Input Drops**: DirectX scan-code simulation fails on Windows ARM64 virtualization; keypresses are dropped without verification.
21
+ - **Multi-Window Discovery Collision**: Launching multiple instances of identical apps causes discovery diffs to select the existing instance rather than the new one.
22
+ - **Unverified fire-and-forget**: Typing without post-condition assertions hides silent failures (e.g. counting `\n` while Notepad returns `\r\n` or `\r`).
23
+
24
+ `wintegrate` is engineered specifically for **unattended CI reliability** across both **x64 and ARM64 Windows**.
25
+
26
+ ---
27
+
28
+ ## Core Features & Architecture
29
+
30
+ ### 1. Verified Actions & Post-Conditions
31
+ Every UI interaction confirms its post-condition (line count deltas, buffer content, focus transitions) before returning:
32
+ ```python
33
+ editor.type_verified(
34
+ "Hello from CI\nSecond line\n",
35
+ expected_line_count_delta=2,
36
+ verify_contains="Hello from CI\nSecond line",
37
+ delay_per_char=0.03,
38
+ )
39
+ ```
40
+
41
+ ### 2. Universal x64 & ARM64 Native Unicode Input
42
+ Replaced DirectX scan-code simulation with native Win32 `SendInput` utilizing `KEYEVENTF_UNICODE`. Seamlessly injects special characters, linebreaks, and multibyte Unicode across both Intel/AMD x64 and Windows 11 ARM64 virtualization runners.
43
+
44
+ ### 3. Multi-Window Isolation & Discovery Exclusion
45
+ Supports launching and discovering multiple concurrent instances of the same application without PID/HWND collisions:
46
+ ```python
47
+ with session.app(NOTEPAD) as app_a:
48
+ # exclude_hwnds guarantees discovery finds the new window, not the existing one.
49
+ # fresh=False: the leftover sweep would otherwise kill Window A.
50
+ with session.app(NOTEPAD, fresh=False, exclude_hwnds={app_a.window.hwnd}) as app_b:
51
+ app_a.find_text_input().type_verified("Window A\n", expected_line_count_delta=1)
52
+ app_b.find_text_input().type_verified("Window B\n", expected_line_count_delta=1)
53
+ ```
54
+
55
+ ### 4. Non-Invasive Thread Input Focus (`AttachThreadInput`)
56
+ Switches foreground focus cleanly using `AttachThreadInput` synchronization between the automation thread and the target window thread. Grants activation authority without invasive keystrokes or Z-order corruption.
57
+
58
+ ### 5. Windows 11 Virtual Desktop Clean-Room Isolation (`pyvda`)
59
+ Supports dynamic virtual desktop isolation. When `isolated_virtual_desktop=True`, `wintegrate` creates a clean virtual desktop on the fly, switches to it, executes test operations in isolation away from background noise, and automatically destroys the test desktop on exit.
60
+
61
+ ### 6. Streaming Video & Diagnostic Pipeline
62
+ - **Low-Memory Streaming Recorder**: `ContinuousRecorder` encodes in-process through PyAV (which bundles FFmpeg), falling back to an external FFmpeg subprocess with `stderr` redirected to disk logs. PyAV is preferred because it is the only FFmpeg on PyPI with a `win_arm64` wheel — recording works out of the box on Windows ARM64, where every ffmpeg-shipping package leaves you to install a binary yourself. Frames carry wall-clock timestamps, so a capture loop that falls behind the nominal frame rate still plays back at real speed.
63
+ - **Automatic Failure Artifacts**: Automatically dumps full-screen screenshots and pre/post `window_census.json` diffs on assertion failure.
64
+ - **Event Timeline Logging**: Logs action timestamps and targets to human-readable `.log` and structured `.json`.
65
+
66
+ ### 7. Managed App Lifecycle & Locale-Independent Discovery (`session.app`)
67
+ Modern Windows apps break naive launch-and-poll automation in specific, repeatable ways.
68
+ `session.app()` packages the countermeasures:
69
+
70
+ ```python
71
+ from wintegrate import NOTEPAD, Session, SessionConfig
72
+
73
+ with Session(SessionConfig()) as session:
74
+ with session.app(NOTEPAD) as app: # cleanup guaranteed, even on failure
75
+ editor = app.find_text_input() # locale-independent control ladder
76
+ editor.type_verified("hello\n", expected_line_count_delta=1)
77
+ ```
78
+
79
+ - **No localized strings**: windows are matched by process image name (`Notepad.exe`),
80
+ window class (`Notepad`), and UIA control types — none of which change with the UI
81
+ language. Title regexes are a last-resort fallback and live once, in the `AppSpec`.
82
+ - **Single-instance safety**: Store apps (Notepad) reuse a running instance — a leaked
83
+ instance makes the next launch open a *tab* instead of a new window, and discovery
84
+ times out mysteriously. `fresh="auto"` sweeps leftovers before launching (CI only).
85
+ - **Cold-start headroom**: first launches of Store apps regularly exceed 10s on CI
86
+ runners (ARM64 especially); managed launches default to a 30s discovery timeout.
87
+ - **No leaks**: the context manager closes the window and kills the process on exit,
88
+ and a timed-out discovery kills its own launcher.
89
+
90
+ ---
91
+
92
+ ## Quickstart
93
+
94
+ ```python
95
+ from wintegrate import NOTEPAD, Session, SessionConfig
96
+
97
+ config = SessionConfig(
98
+ artifact_dir="./ci-artifacts",
99
+ record_video=True,
100
+ fps=30,
101
+ )
102
+
103
+ with Session(config) as session:
104
+ # Managed lifecycle: locale-independent discovery, single-instance safety,
105
+ # generous cold-start timeout, and guaranteed cleanup on exit.
106
+ with session.app(NOTEPAD) as app:
107
+ editor = app.find_text_input()
108
+
109
+ # Types hardware keystrokes and verifies line count delta & text content
110
+ editor.type_verified(
111
+ "Hello from CI\nSecond line\n",
112
+ expected_line_count_delta=2,
113
+ verify_contains="Hello from CI\nSecond line",
114
+ )
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Installation
120
+
121
+ ```bash
122
+ pip install wintegrate # core: window/element automation, verified input
123
+ uv add wintegrate
124
+ ```
125
+
126
+ The core install depends on `comtypes` alone. Two optional extras pull in the
127
+ heavier pieces only if you use them:
128
+
129
+ ```bash
130
+ pip install 'wintegrate[video]' # screen recording + failure screenshots (Pillow, PyAV)
131
+ pip install 'wintegrate[desktop]' # virtual desktop clean-room isolation (pyvda)
132
+ pip install 'wintegrate[all]'
133
+ ```
134
+
135
+ Using a feature without its extra raises an error naming the extra to install, so a
136
+ missing dependency never turns into a silently skipped diagnostic.
137
+
138
+ Or install from source with development dependencies:
139
+ ```bash
140
+ git clone https://github.com/mangokingTW/wintegrate.git
141
+ cd wintegrate
142
+ pip install -e .[dev]
143
+ ```
144
+
145
+ Windows only: the package imports on other platforms (so cross-platform tooling and
146
+ `env` checks work), but every Win32/UIA call raises a clear unsupported-platform error.
147
+
148
+ ---
149
+
150
+ ## Running Tests
151
+
152
+ Run full test suite locally:
153
+ ```powershell
154
+ pytest tests/ -v -s
155
+ ```
156
+
157
+ Run static code analysis & formatting check:
158
+ ```powershell
159
+ ruff check src/ tests/
160
+ ```
161
+
162
+ ---
163
+
164
+ ## License
165
+
166
+ MIT License. See [LICENSE](LICENSE) for details.