Skip to content

tests: pinned regression suite for #29 + #30 (CI + pre-commit)#31

Open
kody-w wants to merge 1 commit into
mainfrom
tests/regression-port-and-encoding
Open

tests: pinned regression suite for #29 + #30 (CI + pre-commit)#31
kody-w wants to merge 1 commit into
mainfrom
tests/regression-port-and-encoding

Conversation

@kody-w

@kody-w kody-w commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Summary

Why

#29 and #30 were both invisible until someone hit them: the :7071 hardcode looked fine until you ran a project-local install on a different port, and the encoding bug only crashed Windows users on non-UTF-8 system locales. A grep-able test pinned to a specific PR is the cheapest way to keep them dead.

What gets checked

Test What it asserts Catches reintroduction of
test_index_html_api_is_same_origin The const API = … declaration in index.html does not contain a numeric port literal #29
test_index_html_no_hardcoded_fetch_to_7071 No fetch / XHR / WebSocket / EventSource call site in index.html targets localhost:7071 directly #29 (defense in depth)
test_no_text_open_without_encoding AST-walks every .py in rapp_brainstem/ and flags any text-mode open(), Path.open(), Path.read_text(), or Path.write_text() missing encoding= #30

The AST walker excludes zf.open, urlopen, os.open, subprocess.Popen, webbrowser.open, and binary-mode ("rb"/"wb") opens — these don't have an encoding concept and would otherwise produce false positives.

Manually verified

Reintroduced each regression and confirmed the suite catches them with precise file:line offenders, then reverted and confirmed clean:

$ python3 rapp_brainstem/test_regressions.py
  PASS  index.html declares an `API` constant
  FAIL  index.html `API` constant has no hardcoded port: `API = location.port === '7071' ? '' : ...`
  PASS  index.html has no hardcoded fetch/XHR/WebSocket to :7071
  FAIL  no text-mode open() / read_text / write_text without encoding=utf-8: offenders:
      brainstem.py:771

  2 passed, 2 failed
exit=1

Post-revert: 4 passed, 0 failed.

How to run locally

# direct
python3 rapp_brainstem/test_regressions.py

# via pre-commit (one-time setup: `pip install pre-commit && pre-commit install`)
pre-commit run --all-files

Test plan

  • Suite passes on green main (4/4)
  • Suite catches reintroduced regressions (2/4 fail with correct offenders)
  • YAML for workflow + pre-commit config validates (yaml.safe_load)
  • CI run on this PR is green (will verify after push)

Future regressions

When fixing a new bug that "ought to stay fixed," extend rapp_brainstem/test_regressions.py with a test referencing the PR number — the workflow and pre-commit hook pick it up automatically.

Adds a stdlib-only regression test that catches reintroduction of the
two project-local-install bugs we just fixed:

  - #29 — hardcoded :7071 in the chat UI's `API` constant
  - #30 — text-mode open() without encoding="utf-8" (Windows GBK crash)

Files:

  rapp_brainstem/test_regressions.py
      Three checks: parse the `API` declaration in index.html and reject
      port literals; grep for `fetch('http://localhost:7071/...')` shapes
      elsewhere; ast-walk every .py in the package and flag any text-mode
      open / read_text / write_text without an `encoding=` kwarg.
      Stdlib only, runs directly: `python3 rapp_brainstem/test_regressions.py`.
      Manually verified by reintroducing each regression — both checks
      fail with precise file:line offenders, then pass once reverted.

  .github/workflows/regression-tests.yml
      Runs the suite on PRs touching `rapp_brainstem/` and on every push
      to main. Python 3.11, no extra deps.

  .pre-commit-config.yaml
      Same suite as a `pre-commit` hook (`pip install pre-commit && pre-commit
      install`) so local commits fail fast before CI.

  rapp_brainstem/CLAUDE.md
      Documents the pinned-regressions pattern and points future
      contributors at test_regressions.py for the rationale behind each
      check.
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.

1 participant