Skip to content

Fix/issue 1824 6 k quarterly fallback #1842

Fix/issue 1824 6 k quarterly fallback

Fix/issue 1824 6 k quarterly fallback #1842

# Regression Tests Workflow
# Runs regression tests on-demand or on schedule to catch breaking changes
name: Regression Tests
on:
# Manual trigger
workflow_dispatch:
# Nightly, an hour after python-hatch-workflow.yml's full run. This is the
# run that measures the lane's coverage for Codecov; pushes to main skip it
# (see "Run regression tests" below).
schedule:
- cron: '0 8 * * *'
# PRE-MERGE GATE. The required context is the `Regression gate` job at the end
# of this file, never the `regression` job itself.
#
# The network-marked regression tests used to gate nothing: they ran only
# after merge, so a break was invisible on the pull request that caused it.
# Three of four consecutive post-merge runs failed the week of 2026-08-08,
# one of them genuine content loss in `Filing.text()` that sat on main for
# three commits, and auto-merge later merged a pull request whose advisory
# run was red.
#
# There is deliberately NO paths filter on this trigger. A required check that
# never reports blocks the pull request forever (the deadlock documented at
# the top of python-hatch-workflow.yml), so every pull request must produce
# the `Regression gate` context. The `changes` job decides instead whether the
# suite is relevant, using the same path list as the push trigger below; when
# it is not, the suite is skipped and the gate passes. Keep the two lists in
# step. The lane takes 12-19 minutes on a pull request (no coverage), running
# alongside test-fast, which takes 13-23.
pull_request:
branches: [ "main", "5.*.x" ]
# Also run on main branch pushes that touch the library.
#
# This used to name three packages — edgar/xbrl, edgar/entity and the
# regression tree itself — which left every other package uncovered. A change
# under edgar/documents that added no regression file ran the suite in no job
# at all, and that is where the section-extraction defect cluster lives
# (bead edgartools-07lk.21). `edgar/**` closes the hole as a class instead of
# one package at a time; docs- and script-only merges still skip it.
#
# The four test-harness files are here because they decide what this lane
# RUNS, not just what it runs against. tests/conftest.py assigns every
# regression test its fast/network marker and fails collection on an
# unclassified file; _offline_filings.py backs the tests that resolve an
# accession without the quarterly index; _offline_harness.py is the offline
# measurement; _vcr_safety.py installs the safe YAML loader the cassette gate
# exists to protect. A pull request can break this suite by touching only
# those and never trigger the lane — PR #1013 was exactly that shape.
# pyproject.toml carries the marker registry and pytest options
# (xfail_strict among them), which change outcomes suite-wide.
push:
branches: [ "main", "5.*.x" ]
paths:
- 'tests/issues/regression/**'
- 'edgar/**'
- '.github/workflows/regression-tests.yml'
- 'tests/conftest.py'
- 'tests/_offline_filings.py'
- 'tests/_offline_harness.py'
- 'tests/_vcr_safety.py'
- 'pyproject.toml'
# Read-only by default. Jobs that write (the red-main `report` job) grant
# their own job-level permissions; nothing else inherits the token's write scope.
permissions:
contents: read
pull-requests: read
issues: read
# Only pull-request runs are ever cancelled, by a newer commit on the same PR.
# Every other run (a push to main, the nightly, a manual dispatch) gets a group
# of its own, keyed by commit, so nothing can supersede it. Same rule as
# python-hatch-workflow.yml, which explains the pending-run trap in full.
#
# Two ways a push run on main was lost here. With cancel-in-progress true for
# pushes, the next merge cancelled a RUNNING run: the run for 4f710f58, the
# merge that added the Regression gate, was cancelled 15 seconds in. With it
# false, GitHub still cancels a PENDING run when a newer one queues in the same
# group: 6 of the 100 push runs from 2026-11-11 to 2026-11-23 were cancelled
# before any job started. PRs merge without being up to date with main, so the
# post-merge run is the only check that the combination works.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# Decides whether this change can affect the regression suite. Only pull
# requests are filtered here; push runs are already filtered by the trigger's
# `paths`, and scheduled and manual runs always run the suite.
#
# The patterns below mirror the push trigger's `paths` list. In a `case`
# pattern `*` also matches `/`, so `edgar/*` covers the whole package. The
# pull-request files API lists at most 3,000 files; a larger change is treated
# as relevant. If the API call fails, this job fails and so does the gate:
# failing closed costs a re-run, failing open would let a break through.
changes:
name: Regression scope
runs-on: ubuntu-latest
outputs:
relevant: ${{ steps.scope.outputs.relevant }}
steps:
- name: Decide whether the regression suite applies
id: scope
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}
EVENT: ${{ github.event_name }}
run: |
if [ "$EVENT" != "pull_request" ]; then
echo "relevant=true" >> "$GITHUB_OUTPUT"
exit 0
fi
files=$(gh api --paginate "repos/$REPO/pulls/$PR/files" --jq '.[].filename')
count=$(printf '%s\n' "$files" | grep -c . || true)
relevant=false
if [ "$count" -ge 3000 ]; then
relevant=true
fi
while IFS= read -r f; do
case "$f" in
edgar/*|tests/issues/regression/*|.github/workflows/regression-tests.yml|\
tests/conftest.py|tests/_offline_filings.py|tests/_offline_harness.py|\
tests/_vcr_safety.py|pyproject.toml)
relevant=true
echo "relevant because of: $f"
break
;;
esac
done <<< "$files"
echo "relevant=$relevant" >> "$GITHUB_OUTPUT"
echo "$count changed files; regression suite relevant: $relevant"
# See python-hatch-workflow.yml: cassettes are loaded with PyYAML's unsafe
# loader, so this has to pass before anything runs pytest.
#
# The name carries the "(regression)" suffix on purpose. `main` requires the
# context "Cassette safety gate", produced by the identically-named job in
# python-hatch-workflow.yml. Once this workflow runs on pull requests too, an
# unsuffixed name here would put two check runs with that one required name on
# every pull request touching edgar/**, and branch protection matches contexts
# by name. Either this advisory job's red blocks a merge, or its green
# satisfies the requirement the real gate was supposed to answer — and which
# of the two you get depends on reporting order. Keep the names distinct.
cassette-gate:
name: Cassette safety gate (regression)
needs: changes
if: needs.changes.outputs.relevant == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python 3.13
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.13'
- name: Install PyYAML
run: python -m pip install --upgrade pip PyYAML
- name: Scan cassettes for unsafe YAML tags
run: python scripts/check_cassettes.py
regression:
needs: cassette-gate
runs-on: ubuntu-latest
env:
EDGAR_LOCAL_DATA_DIR: ${{ github.workspace }}/.edgar-data
strategy:
fail-fast: false
matrix:
# Single version: regression tests verify data correctness against real
# filings, not Python compatibility (the fast job covers 3.11 + 3.13).
python-version: ["3.12"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
# Persist the SEC HTTP cache — regression tests fetch real filings, and
# /Archives/edgar/data is cached forever (see CACHE_RULES), so a warm cache
# serves them from disk instead of re-downloading.
#
# Restore and save are split so pull requests can READ the cache without
# WRITING one. This entry is 857 MB, and the repository was already at
# 10.7 GB against a 10 GB ceiling when the pull-request trigger was added,
# so it is evicting LRU today. A save on every pull-request run would push
# main's warm entry out and leave the lane re-downloading a filing set it
# already had — slower, and rude to the SEC. Pull-request runs restore from
# whatever main last saved and throw their own copy away.
- name: Restore SEC HTTP cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.edgar-data/_tcache
key: edgar-tcache-regression-${{ github.run_id }}
restore-keys: |
edgar-tcache-regression-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[ai]"
python -m pip install pytest pytest-cov pytest-env pytest-xdist pytest-asyncio pytest-retry pytest-mock pytest-vcr "vcrpy>=8.3.0,<9" freezegun==1.5.1 filelock tqdm responses
# `not fast`: the fast regression tests (45,660 of 46,447 on 2026-10-24)
# already gate every pull request and push in test-fast, in parallel, in
# python-hatch-workflow.yml. Re-running them here, serially, took 26 of
# this job's 43 test minutes and checked nothing new (edgartools-07lk.26).
# What is left is what only this lane runs: the network-marked regression
# tests and the few marked neither fast nor network.
- name: Run regression tests
run: |
# Coverage only on the nightly and manual runs. It roughly doubles the
# lane: push runs on main took 25-37 min with it (November 2026) against
# 12-19 min for the same tests on a pull request without it, and a push
# run's job is to say quickly whether main is red. Codecov carries the
# `regression` flag forward between nightly uploads (codecov.yml), so
# commits in between keep this lane's lines in their total.
if [ "${{ github.event_name }}" = "schedule" ] || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
pytest -rs --cov --cov-report=xml -m 'regression and not fast' --enable-cache
else
pytest -rs -m 'regression and not fast' --enable-cache
fi
# `always()`: a run that failed still warmed the cache, and the next one
# should not pay for those downloads again.
- name: Save SEC HTTP cache
if: always() && github.event_name != 'pull_request'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.edgar-data/_tcache
key: edgar-tcache-regression-${{ github.run_id }}
# Only from the runs that measured coverage: the nightly and manual ones.
# Never on pull requests: Codecov posts its own commit statuses, and a
# partial `regression`-flag upload would put a red check on a pull request
# that only the `Regression gate` job may decide.
- name: Upload coverage reports
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
if: matrix.python-version == '3.12' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
with:
files: coverage.xml
fail_ci_if_error: false
flags: regression
token: ${{ secrets.CODECOV_TOKEN }}
# A red `main` has to arrive somewhere a person looks.
#
# This lane runs post-merge, so nothing blocks on it and its result lands in
# the Actions tab and nowhere else. On 2026-08-08 it went red at 13:00 and
# three more pull requests merged through it before anyone noticed — the
# failures were visible the whole time and no one was looking (edgartools-hwdp).
#
# One issue, reopened and commented rather than duplicated, so a week of
# nightly failures is one thread and not seven. It closes itself when the lane
# goes green again, which makes the issue list the answer to "is main ok?".
# `needs` covers both jobs on purpose. A failed cassette gate skips the
# regression job rather than failing it, so keying only on that job's result
# would stay silent for the one failure that stops the suite running at all.
# Neither a cancelled run (concurrency supersedes one on every push) nor a
# skipped one is treated as red.
#
# The `github.event_name != 'pull_request'` guard became load-bearing when the
# advisory pre-merge trigger was added: "main is red" is a claim about main,
# and a pull request that breaks a regression test must not file it. Its
# `issues: write` would not survive a fork pull request anyway.
report:
name: Report red main
needs: [cassette-gate, regression]
# main only: a green push to a 5.*.x maintenance branch must not close
# main's red-main issue (see python-hatch-workflow.yml's report job).
if: always() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
issues: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SHA: ${{ github.sha }}
LABEL: red-main
TITLE: "Regression Tests are failing on main"
steps:
- name: Ensure the tracking label exists
run: |
gh label create "$LABEL" --repo "$REPO" --color b60205 \
--description "Post-merge regression lane is red" 2>/dev/null || true
- name: Open or update the tracking issue
if: needs.regression.result == 'failure' || needs['cassette-gate'].result == 'failure'
run: |
number=$(gh issue list --repo "$REPO" --label "$LABEL" --state all \
--limit 1 --json number --jq '.[0].number // empty')
body=$(printf '%s\n\n- commit: %s\n- run: %s\n' \
"The post-merge regression lane failed on \`main\`." "$SHA" "$RUN_URL")
if [ -z "$number" ]; then
gh issue create --repo "$REPO" --label "$LABEL" \
--title "$TITLE" --body "$body"
else
gh issue reopen --repo "$REPO" "$number" 2>/dev/null || true
gh issue comment --repo "$REPO" "$number" --body "$body"
fi
- name: Close the tracking issue when main is green again
if: needs.regression.result == 'success' && needs['cassette-gate'].result == 'success'
run: |
number=$(gh issue list --repo "$REPO" --label "$LABEL" --state open \
--limit 1 --json number --jq '.[0].number // empty')
if [ -n "$number" ]; then
gh issue close --repo "$REPO" "$number" \
--comment "Green again at $SHA — $RUN_URL"
fi
# THE REQUIRED CONTEXT. Branch protection on `main` requires "Regression gate",
# the name of this job. Renaming it retires the context and blocks every pull
# request; update the protection contexts in the same commit (see the top of
# python-hatch-workflow.yml).
#
# It runs on every event (`always()`), so the context always reports. It passes
# when the suite was not relevant, or when the cassette gate and the suite both
# passed. Anything else fails it, including a failed or cancelled `changes` job
# and a cancelled suite, because a check that passes when nothing ran is not a
# gate.
gate:
name: Regression gate
needs: [changes, cassette-gate, regression]
if: always()
runs-on: ubuntu-latest
steps:
- name: Pass only when the suite passed or did not apply
env:
SCOPE: ${{ needs.changes.result }}
RELEVANT: ${{ needs.changes.outputs.relevant }}
CASSETTES: ${{ needs['cassette-gate'].result }}
REGRESSION: ${{ needs.regression.result }}
run: |
echo "scope=$SCOPE relevant=$RELEVANT cassette-gate=$CASSETTES regression=$REGRESSION"
if [ "$SCOPE" != "success" ]; then
echo "::error::Could not decide whether the regression suite applies."
exit 1
fi
if [ "$RELEVANT" != "true" ]; then
echo "No library or regression-harness change: the suite does not apply."
exit 0
fi
if [ "$CASSETTES" = "success" ] && [ "$REGRESSION" = "success" ]; then
exit 0
fi
echo "::error::The regression suite did not pass (cassette gate: $CASSETTES, regression: $REGRESSION)."
exit 1