deer-flow/.github/workflows/backend-windows-live-policy.yml
Louisss 829edac602
fix(tests): pass Windows base system env to the isolated live-policy pytest child (#6439)
* fix(tests): pass Windows base system env to isolated pytest child

The live-test policy regression tests spawn a pytest child with a minimal,
from-scratch env. On Windows that env lacks SystemRoot/TEMP/USERPROFILE, so
the child dies during import asyncio (WinError 10106, winsock provider init)
and tempfile cannot resolve a directory, making the tests fail for
environment reasons instead of testing the opt-in policy.

Extract the env assembly into _child_pytest_env() and pass through a small
allowlist of Windows base system variables (SystemRoot, windir, COMSPEC,
PATHEXT, TEMP, TMP, USERPROFILE) when present. These carry no credentials,
so the isolation contract (no API keys, no real .env) is unchanged, and
POSIX behavior is byte-identical. A new unit test pins the contract: only
the allowlisted base vars may pass through, and SystemRoot must be present
on Windows.

* test(live-policy): seed Windows base env vars in the bootability contract

The contract test asserted TEMP/TMP pass-through without seeding them, so
on Windows hosts that do not export those optional variables (CPython then
falls back to %USERPROFILE%\AppData\Local\Temp) it failed on host
configuration rather than on the helper's contract.

Seed the representative base variables with monkeypatch and assert the
forwarded set exactly, so the isolation contract is deterministic on every
host. Red/green evidence: with TEMP/TMP stripped from the environment the
old assertion fails (extra = {COMSPEC, PATHEXT, SystemRoot, USERPROFILE,
windir}) while the seeded assertion passes.

Addresses the P3 finding in the review of PR #6439.

* ci(tests): cover Windows live-test policy

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-18 09:24:51 +08:00

61 lines
1.9 KiB
YAML

name: Windows Live Test Policy
# These offline policy tests spawn pytest children that collect live tests.
on:
workflow_dispatch:
schedule:
- cron: '17 6 * * 1'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- '.github/workflows/backend-windows-live-policy.yml'
- 'backend/tests/test_client_live_policy.py'
- 'backend/tests/test_client_live.py'
- 'backend/pyproject.toml'
- 'backend/uv.lock'
concurrency:
group: windows-live-policy-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
windows-live-policy:
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
runs-on: windows-latest
timeout-minutes: 15
defaults:
run:
working-directory: backend
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
# Must match backend/Dockerfile's UV_IMAGE tag.
version: '0.11.1'
- name: Install backend dependencies
run: uv sync --locked --group dev
- name: Check isolated child environment and live-test collection policy
# Explicit nodes include all four collection cases and avoid make.
run: >-
uv run python -m pytest
tests/test_client_live_policy.py::test_child_env_stays_isolated_but_bootable_on_windows
tests/test_client_live_policy.py::test_config_alone_does_not_enable_live_collection
tests/test_client_live_policy.py::test_explicit_opt_in_collects_live_tests
tests/test_client_live_policy.py::test_ci_blocks_live_collection_even_with_opt_in
tests/test_client_live_policy.py::test_opt_in_without_config_reports_missing_config
-q