Repository navigation
Add an offline test target that no AWS account authorizes (GH-1495) - #1532
Conversation
`just test offline` runs the tests under tests/pyathena/ without the `aws` mark. It unsets every AWS setting of the environment, including a loaded .env, sets placeholders for the settings that tests/__init__.py requires and placeholder credentials that no account accepts, and sends the requests of clients that read AWS_ENDPOINT_URL to a closed local port with a single attempt. The Test workflow runs the target for every pull request, including Drafts and external forks, without AWS credentials, and the AWS suites start only after it passes. The testing guide, the contribution guide, AGENTS.md and the development-workflow skill describe when the offline target is enough and when a change also needs its `aws` tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On some hosts, such as WSL2, a connection to a closed loopback port waits for its timeout instead of being refused, so an accidental boto3 request took 60 seconds. https://offline.invalid fails at name resolution, and NO_PROXY keeps a proxy from receiving it. uv run --no-env-file keeps uv from loading a .env file back after the recipe unset AWS_*. The AWS suites also wait for lint, the offline job has a timeout, and the testing guide states that Polars retries for about 30 seconds and that a test reaching AWS should request aws_test_schema. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| export AWS_ACCESS_KEY_ID=offline AWS_SECRET_ACCESS_KEY=offline | ||
| export AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null | ||
| export AWS_EC2_METADATA_DISABLED=true | ||
| export AWS_ENDPOINT_URL=https://offline.invalid AWS_MAX_ATTEMPTS=1 |
There was a problem hiding this comment.
Self-review round 1 (behavior and implementation; base 6acb688be38db78ffe6c6fe094281549e2c2cbf3, reviewed 3cc2a9db974e890c02969e36a6c30b63076fd640, repaired at 389c205bf26cc4e09c3755fc1f7a62ee264460bd). Covered: the _test-offline recipe and help, the offline job and the changes gate, the docs and agent guidance. Inputs: my own pass, /code-review high, /simplify.
FINDINGS (repaired):
- On this WSL2 host a connection to a closed loopback port times out instead of being refused (measured:
127.0.0.1:9and:1wait 10 s at a 10 s timeout;::1:9is refused), so an accidental boto3 request waited 60 s (/code-review). The endpoint is nowhttps://offline.invalid(RFC 6761): boto3 fails in 0.13 s; Polars retries for 28 s and fails ([::1]:9: 40 s). - A
UV_ENV_FILEwould makeuv runload.envback after the unset loop (/code-review). The recipe runsuv run --no-env-file; withUV_ENV_FILE=.env, the pytest process seesAWS_PROFILEunset and the placeholder credentials (without the flag, uv restoresAWS_PROFILE=pyathena). - A proxy in the environment would receive requests for the endpoint (
/code-review).NO_PROXY/no_proxynow includeoffline.invalid. - The unset loop uses
compgenonly (bash 3.2 on macOS has nomapfile), and passes with noAWS_*variable set.
Validation at 389c205b: just test offline 3941 passed in 28 s; under unshare -rn with .env and UV_ENV_FILE=.env, 3938 passed, 3 skipped; just lint, actionlint, shellcheck, rumdl.
| # The AWS suites wait for the offline checks, so a change that fails them | ||
| # does not run the AWS suites. | ||
| changes: | ||
| needs: [lint, offline] |
There was a problem hiding this comment.
Self-review round 1 (behavior and implementation; base 6acb688be38db78ffe6c6fe094281549e2c2cbf3, reviewed 3cc2a9db974e890c02969e36a6c30b63076fd640, repaired at 389c205bf26cc4e09c3755fc1f7a62ee264460bd). Covered: the _test-offline recipe and help, the offline job and the changes gate, the docs and agent guidance. Inputs: my own pass, /code-review high, /simplify.
FINDINGS (repaired): the AWS suites waited for offline but not for lint (/simplify altitude and efficiency); changes now needs both, at no cost, since lint finishes first. The job had no timeout although the AWS suites wait for it (/code-review); timeout-minutes: 20. CI on this Draft at 3cc2a9db: the offline job passed, 3941 tests in 48.7 s on 4 workers, 68 s in all.
Deferred with reasons: running the offline job on every supported Python version, or merging it into lint on 3.12 (#1495 specifies the newest version); the hard-coded 3.15 beside PYTHON_VERSIONS (expressions cannot take the last element of that JSON list; a comment ties them); the duplicated setup-uv/setup-python steps (the same as test-suite.yaml); -m aws in the AWS suite to skip the offline tests there (it would drop offline coverage on the other Python versions of the Release run); the 1-3 minutes the gate adds before the AWS suites (accepted to avoid AWS runs for changes that fail offline).
| PyArrow's S3 client does not read `AWS_ENDPOINT_URL`; its requests reach AWS and are rejected for the placeholder credentials. | ||
|
|
||
| The recipe also runs without the rerun plugin, whose reruns cover only service-side errors of Athena and S3. | ||
| A test that reaches AWS in `just test offline` gets a connection error or a rejected request; make it request `aws_test_schema`, as described above, which also gives it the `aws` mark. |
There was a problem hiding this comment.
Self-review round 1 (behavior and implementation; base 6acb688be38db78ffe6c6fe094281549e2c2cbf3, reviewed 3cc2a9db974e890c02969e36a6c30b63076fd640, repaired at 389c205bf26cc4e09c3755fc1f7a62ee264460bd). Covered: the _test-offline recipe and help, the offline job and the changes gate, the docs and agent guidance. Inputs: my own pass, /code-review high, /simplify.
FINDINGS (repaired): the guide told a contributor to give a test that reaches AWS the aws mark, which would deselect it without the session setup; it now says to request aws_test_schema (/code-review). The guide claimed that AWS_MAX_ATTEMPTS makes Polars fail at once; object_store does not read it, and the guide now states its retries (/code-review). AGENTS.md's "cannot be authorized by an account" was unclear; it links to this section instead (/simplify).
Deferred: shortening the list of what the recipe sets (/simplify); it states the guarantee a reader relies on. Keeping AWS_SHARED_CREDENTIALS_FILE=/dev/null and AWS_EC2_METADATA_DISABLED=true although environment credentials come first: some tests delete the credential variables and would then fall back to those sources.
|
|
||
| - placeholder values for the four settings that `tests/__init__.py` requires; | ||
| - placeholder credentials that no AWS account accepts, empty AWS config and credentials files, and `AWS_EC2_METADATA_DISABLED=true`, so that no request made by accident is authorized; | ||
| - `AWS_ENDPOINT_URL=https://offline.invalid`, a reserved name that does not resolve, excluded from any proxy, and `AWS_MAX_ATTEMPTS=1`, so that a request that boto3 makes by accident fails at once without reaching AWS. |
There was a problem hiding this comment.
Self-review round 2 (claims, callers, operation; base 6acb688be38db78ffe6c6fe094281549e2c2cbf3, head 389c205bf26cc4e09c3755fc1f7a62ee264460bd). Full pass over the guide, docs/contributing.md, AGENTS.md, the skill text, the recipe comment and help, the workflow comments, the PR body, the commit messages, and #1495's validation plan.
Claims checked:
- "unsets every
AWS_*variable ... keeps uv from loading a.envfile": the recipe's process sees placeholders with.envloaded and withUV_ENV_FILE=.env. - "credentials that no AWS account accepts": the access key
offlineis not a valid key ID; no request is authorized. - "a reserved name that does not resolve, excluded from any proxy":
offline.invalidfails resolution in 0.02 s here (RFC 6761); botocore bypasses proxies throughno_proxy(botocore/utils.py:3201,should_bypass_proxies). - "Polars ... retries them for about 30 seconds": 28 s measured with object_store's 8 retries.
- "PyArrow's S3 client does not read
AWS_ENDPOINT_URL": checked without network; it resolves the real S3 host. - GitHub Actions section: the
offlinejob has noif, so it runs for Draft and fork pull requests that change files other than docs and Markdown (the workflow'spaths-ignore);changesneedslintandoffline, also for the schedule and the Release workflow. AGENTS.mdlinks todocs/testing.md#run-the-tests-that-need-no-aws, GitHub's anchor for that heading; the Sphinx labeltesting-offlineis kept.- Add an offline test target that cannot reach AWS #1495's validation plan: selection compared (4933 = 3941 + 992
aws); run underunshare -rnwithout real credentials; endpoint behavior of PyArrow and Polars recorded; run time recorded locally and in CI.
Callers: just test pyathena, sqla and sqla-async, tox, and test-suite.yaml are unchanged; the new gate delays the AWS suites by the offline job's run time (about 70 s, plus the runner start).
CLEAN.
fsspec applies FSSPEC_S3_* variables and its configuration files to every filesystem it constructs, so a developer's fsspec credentials reached PyAthena's S3FileSystem; the legacy boto configuration is a credential source for clients built without credentials; Polars retried an accidental request for about 30 seconds. The recipe unsets FSSPEC_* and the proxy variables, hides the fsspec and boto configuration, and sets POLARS_CLOUD_MAX_RETRIES=0. It syncs the environment before changing it, so uv neither uses the cleared settings to sync nor syncs during the run. isolated_aws_config hides the boto configuration too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| uv sync --inexact | ||
| for name in $(compgen -e AWS_) $(compgen -e FSSPEC_); do unset "$name"; done |
There was a problem hiding this comment.
Independent review (relayed): Codex CLI (codex exec -s read-only, session 01a22665-425e-74b1-91c0-bf1099100a36; a first run was cut off by a session restart and is discarded), static review of 6acb688be38db78ffe6c6fe094281549e2c2cbf3..389c205bf26cc4e09c3755fc1f7a62ee264460bd in a detached snapshot with a neutral prompt; no edits, builds, or tests. Covered: fixture-derived marks, import-time settings, credential providers, filesystem clients, proxies, retries, bash 3.2 behavior, --no-env-file against UV_ENV_FILE, the job's permissions and needs semantics for pull_request, schedule, dispatch and workflow_call, concurrency, and the docs. Result: FINDINGS (8). Repairs at d6c05189a6851c1c342b20c61c25cf2ce92fb464.
- fsspec can supply live credentials and an endpoint (
FSSPEC_S3_*, fsspec config files): repaired. Reproduced first: withFSSPEC_S3_KEYset, the fourtest_get_client_compatible_with_s3fs_profilecases fail, because fsspec applies its configuration in the filesystem metaclass (fsspec/spec.py:93). The recipe unsetsFSSPEC_*and setsFSSPEC_CONFIG_DIR=/dev/null(not a directory, so no files are read); with the variable set,just test offlinepasses. isolated_aws_configexposes the legacy boto configuration (BOTO_CONFIG,~/.boto): repaired in the recipe (BOTO_CONFIG=/dev/null) and the fixture.- An anonymous PyArrow filesystem can read a public object: not changed; the guard is the environment-variable layer agreed on Run tests locally without AWS charges #1461, and an unsigned read bills the bucket owner, not the developer's account. Repaired the guide's PyArrow sentence: the
S3FileSystemconstructor that PyAthena uses does not readAWS_ENDPOINT_URL(the URI factory does). - Polars retries an accidental request: repaired with
POLARS_CLOUD_MAX_RETRIES=0; measured 28.9 s → 0.37 s. - and 7. The
no_proxymerge loses exclusions; uv's automatic sync runs in the cleared environment: repaired together: the recipe runsuv sync --inexactfirst with the developer's settings, then unsets the proxy variables (noNO_PROXYmerge any more) and runsuv run --no-sync --no-env-file. A probe of the pytest process withFSSPEC_S3_KEY,HTTPS_PROXY,UV_ENV_FILE=.envand.envloaded shows only the recipe's settings. - An inherited
PYTEST_ADDOPTScan turn the run into a collection: not changed; it is the developer's own pytest setting, and CI's offline job sets none.
There was a problem hiding this comment.
Repair self-review, round 1 perspective (389c205b..d6c05189). Checked: compgen -e FSSPEC_ with no such variable and set -u; unset of proxy variables that are not set; uv sync --inexact matches what uv run syncs (the default groups include dev) and keeps packages that uv run would keep; uv run --no-sync cannot sync with the cleared settings; FSSPEC_CONFIG_DIR=/dev/null is skipped by fsspec.config.set_conf_files (os.path.isdir); the fixture's BOTO_CONFIG points at a missing file in tmp_path. CI's offline job has no proxy and a cold cache syncs in the first step. CLEAN.
There was a problem hiding this comment.
Repair self-review, round 2 perspective (389c205b..d6c05189). Claims checked: the recipe comment and the guide's list match the recipe line by line; "fails at once" now holds for boto3 (0.13 s) and Polars (0.37 s); the PyArrow sentence is limited to the constructor that PyAthena uses; the fixture docstring names the boto file. The PR body is updated. CLEAN.
There was a problem hiding this comment.
Independent follow-up (relayed): Codex CLI (codex exec -s read-only, session 01a22676-1914-7911-ad13-65c1ce82f799), static review of 389c205b..d6c05189. Findings 1, 2, 3, 5, 6 and 7 of the first review resolved for their scenarios. New FINDINGS (4), all repaired in 3518bf73:
- Without proxy variables, Python's
getproxies()falls back to the macOS system proxy, and a mixed-caseHttps_Proxysurvived the unset: the recipe setsNO_PROXY='*'andno_proxy='*'. - Outside the recipe, fsspec has already loaded
FSSPEC_S3_*at import, soisolated_aws_configdid not isolate the fsspec settings: the fixture replacesfsspec.config.conffor its lifetime (apply_configreads the module global at call time). WithFSSPEC_S3_KEYset and no recipe, the isolated tests pass (21 selected). uv sync --inexactignoredUV_NO_SYNC: the recipe syncs withuv run --no-env-file true, which follows uv's own rules;UV_NO_SYNC=1 just test offlinepasses.- The recipe comment promised one attempt for Polars: it now says "without retries".
There was a problem hiding this comment.
Repair self-review, both perspectives (d6c05189..3518bf73). Behavior: NO_PROXY=* makes urllib.request.getproxies() return only the no entry and proxy_bypass_environment bypass every host; uv run --no-env-file true syncs exactly as the later uv run --no-sync would have; the fixture's monkeypatch.setattr restores fsspec.config.conf after each test. Claims: the recipe comment, the fixture docstring, and the guide's "bypasses every proxy" match the code. Validation at 3518bf73: just lint, shellcheck, rumdl; just test offline 3941 passed with UV_NO_SYNC=1; under unshare -rn with .env, UV_ENV_FILE and UV_OFFLINE=1, 3938 passed, 3 skipped. CLEAN.
There was a problem hiding this comment.
Independent follow-up 2 (relayed): Codex CLI (codex exec -s read-only, session 01a227c7-9f84-79d2-836c-ddcb4ce51230; an earlier run was stopped by the host for low memory and is discarded), static review of d6c05189..3518bf73. All four findings of follow-up 1 resolved (botocore's macOS fallback and mixed-case proxies bypassed for offline.invalid; the fixture's fsspec isolation; uv run ... true honors UV_FROZEN, UV_LOCKED and UV_NO_SYNC). New FINDINGS (3):
- With
UV_ISOLATED=1, the firstuv runinstalls into a temporary environment and the second skips installation: not changed; isolated mode with a project command is unusual, and wrapping the whole recipe in oneuv runwould move the cleanup into a separate script. - "Bypasses every proxy" overstates it (Polars' reqwest matches
*against domain names, not literal IPs): repaired inae20c6c2; the guide and the recipe comment nameNO_PROXY='*'instead. - "Without retries" overstates it (Polars can rebuild the store and repeat a range read): repaired; the comment names
AWS_MAX_ATTEMPTS=1andPOLARS_CLOUD_MAX_RETRIES=0.
There was a problem hiding this comment.
Repair self-review, both perspectives (3518bf73..ae20c6c2, comment and docs wording only): the recipe comment and the guide now name the settings the recipe exports, line for line; no code changed, so the validation at 3518bf73 stands. CLEAN.
There was a problem hiding this comment.
Independent follow-up 3 (relayed): Codex CLI (session 01a227d1-3095-7cb1-884d-a2f8af2c64c2), static review of 3518bf73..ae20c6c2. The retry wording is accurate. FINDINGS (1, wording): "unset every ... proxy setting" overstated it, since a mixed-case name such as Https_Proxy survives the unset (and is bypassed by NO_PROXY='*'). Repaired in 0abd0d03: both texts list HTTP_PROXY, HTTPS_PROXY and ALL_PROXY in upper and lower case and NO_PROXY/no_proxy. Repair self-review (both perspectives): wording only, matches the recipe line for line; CLEAN.
There was a problem hiding this comment.
Independent follow-up 4 (relayed): Codex CLI (session 01a227d2-fb51-70a1-8045-0e90ff388d0a), static review of ae20c6c2..0abd0d03: CLEAN.
|
|
||
| - placeholder values for the four settings that `tests/__init__.py` requires; | ||
| - placeholder credentials that no AWS account accepts, empty AWS, boto, and fsspec configuration, and `AWS_EC2_METADATA_DISABLED=true`, so that no request made by accident is authorized; | ||
| - `AWS_ENDPOINT_URL=https://offline.invalid`, a reserved name that does not resolve, with `AWS_MAX_ATTEMPTS=1` and `POLARS_CLOUD_MAX_RETRIES=0`, so that a request that boto3 or Polars makes by accident fails at once without reaching AWS. |
There was a problem hiding this comment.
Independent review (relayed): Codex CLI (codex exec -s read-only, session 01a22665-425e-74b1-91c0-bf1099100a36; a first run was cut off by a session restart and is discarded), static review of 6acb688be38db78ffe6c6fe094281549e2c2cbf3..389c205bf26cc4e09c3755fc1f7a62ee264460bd in a detached snapshot with a neutral prompt; no edits, builds, or tests. Covered: fixture-derived marks, import-time settings, credential providers, filesystem clients, proxies, retries, bash 3.2 behavior, --no-env-file against UV_ENV_FILE, the job's permissions and needs semantics for pull_request, schedule, dispatch and workflow_call, concurrency, and the docs. Result: FINDINGS (8). Repairs at d6c05189a6851c1c342b20c61c25cf2ce92fb464.
- Documentation-only pull requests never start the offline job: not changed; the Test workflow's
paths-ignorefordocs/**and Markdown is the existing policy, and such changes need no tests. The guide states which pull requests the workflow runs for.
Validation at d6c05189: just lint, shellcheck, rumdl; just test offline 3941 passed; with FSSPEC_S3_KEY, FSSPEC_S3_ENDPOINT_URL, UV_ENV_FILE=.env and .env loaded, 3941 passed; under unshare -rn with UV_OFFLINE=1, 3938 passed, 3 skipped.
Without proxy variables, Python falls back to the system proxy on macOS, and a mixed-case variable survived the unset; NO_PROXY=* bypasses them all. The recipe syncs with `uv run --no-env-file true`, which follows uv's own rules such as UV_NO_SYNC, instead of an unconditional uv sync. isolated_aws_config also hides the fsspec configuration that fsspec loads at import, for runs outside the recipe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…H-1495) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WHAT
just test offlinerunsuv run --no-sync --no-env-file pytest -n auto -p no:rerunfailures -m "not aws" tests/pyathena/. The recipe:uv run --no-env-file truewith the developer's settings, so uv syncs by its own rules (UV_NO_SYNC,UV_FROZEN, ...) before the environment is cleared, and not after;AWS_*andFSSPEC_*variable, including those of a loaded.env, andHTTP_PROXY,HTTPS_PROXYandALL_PROXYin both cases, setsNO_PROXYandno_proxyto*, and keeps uv from loading a.envback (--no-env-file, also againstUV_ENV_FILE);tests/__init__.pyrequires, so no.envis needed;AWS_CONFIG_FILE,AWS_SHARED_CREDENTIALS_FILE,BOTO_CONFIGandFSSPEC_CONFIG_DIRto/dev/null, andAWS_EC2_METADATA_DISABLED=true;AWS_ENDPOINT_URL=https://offline.invalid(RFC 6761, does not resolve),AWS_MAX_ATTEMPTS=1andPOLARS_CLOUD_MAX_RETRIES=0, so a request that boto3 or Polars makes by accident fails at once.isolated_aws_configalso hides the legacy boto configuration (BOTO_CONFIG) and the fsspec configuration loaded at import.just testhelp no longer calls thepyathenatarget "unit tests", and listsoffline..github/workflows/test.yaml: anofflinejob runs the target for every event, including Draft and external-fork pull requests, on Python 3.15, withcontents: read, no AWS credentials, and a 20-minute timeout.changes, which starts the AWS suites, now needs it andlint.docs/testing.mdreplaces the--noconftestsection with the target, states what it sets and when a change also needs itsawstests, and describes the CI job.docs/contributing.md,AGENTS.mdand the development-workflow skill point to it.WHY
Closes #1495. Part of #1461; builds on #1515 (the
awsmark).Local work and AI agent sessions can run the tests that need no AWS without credentials and without a chance of a billed request, and Draft and fork pull requests get a test run in CI.
TEST
Tested commit: 3518bf7 (the offline runs); ae20c6c and 0abd0d0 change only the recipe comment and the guide's wording.
just lint;rumdl checkof the changed Markdown;actionlint .github/workflows/test.yaml;shellcheck -s bashof the recipe body.just test offline: 3941 passed in 24-33 s (-n auto, 24 workers locally). CI on this Draft (at 3cc2a9d): theofflinejob passed, 3941 tests in 48.7 s on 4 workers.uv run --env-file .env just test offlineunderunshare -rn(loopback only), with the real.env(9AWS_*variables) loaded,UV_ENV_FILE=.envandUV_OFFLINE=1: 3938 passed, 3 skipped (a permission test skips as root inside the namespace). A probe of the pytest process with.env,UV_ENV_FILE=.env,FSSPEC_S3_KEYandHTTPS_PROXYset shows only the recipe's settings (plainuv runrestoresAWS_PROFILEfromUV_ENV_FILE). WithFSSPEC_S3_KEYset, the fourtest_get_client_compatible_with_s3fs_profilecases fail outside the recipe and pass through it.aws.AWS_*variable set (env -i bash), and uses only bash 3.2 builtins (compgen).127.0.0.1:9) times out instead of refusing, so boto3 waited 60 s; withhttps://offline.invalid, boto3 fails in 0.13 s, and Polars in 0.37 s withPOLARS_CLOUD_MAX_RETRIES=0(28.9 s with its default 8 retries). TheS3FileSystemconstructor that PyAthena uses for PyArrow does not readAWS_ENDPOINT_URLand resolves the real S3 host (checked without network); the docs state this, and the placeholder credentials cover it.🤖 Generated with Claude Code