# Contributing [简体中文](../zh-CN/contributing.md) · [Documentation](index.md) Start with the relevant issue and the [architecture](architecture.md). An issue defines the feature's scope and acceptance cases. Keep changes small enough to explain and review as one behavior. Use English for pull requests, issues, comments, and review replies, including their titles. Documentation is English-first, with matching Chinese pages. ## Run the checks Install [uv](https://docs.astral.sh/uv/getting-started/installation/), then run from the repository root: ```sh uv sync --locked --python 3.14 uv run --locked python tools/check.py ``` Python 3.11–3.14 is supported. CI runs the same command on Linux 3.11/3.14 and macOS/Windows 3.14. Use `uv sync --locked --python 3.11` to check the lower endpoint locally. Use a current patch release for development checks. Safe sdist extraction in these checks requires Python 3.11.4 or later; the installed library's supported minor versions remain 3.11–3.14. Use one of the [supported installation platforms](../../README.md#install-a-release). The same dependency constraints apply to development and knowledge-only use. The command checks Ruff lint/two-space formatting, strict mypy, pytest in normal and optimized modes, document pairs/local links, fresh strict HTML/doctest builds, and an isolated wheel install with its declared runtime dependencies. The distribution check runs `python -m build --sdist`, extracts the archive, and runs `python -m build --wheel` inside the extracted tree. Strict HTML/doctest builds also run there and import the extracted package sources. The check then validates the API/catalog pages, generated search index and query code, and doctest results. The installed-package check verifies distribution identity, module origins and `py.typed` outside the checkout, including the adapter's origin after calculation. Imports must not initialize native astronomy. Knowledge queries and supplied-chart comparisons must not initialize astronomy or time data; the knowledge-only mode also rejects `ctypes` modules. It compares complete natal, transit and cross-chart observations, including input, configuration, provenance and bilingual comparison text, with same-revision source results saved in JSON observation files. Chart provenance versions must match installed metadata. Knowledge resource location, loading, name lookup and citation access are exercised without a chart. Normal and optimized modes both run with isolated imports, and the `--missing-metadata` mode checks the calculation failure described below. Temporary HTML, doctest reports, distributions, and consumer environments use `SCRATCH` when set, otherwise the system temporary directory, and are removed on exit. Build metadata and tool caches may remain in ignored checkout directories. Strict documentation builds may fetch the Python intersphinx inventory from `docs.python.org`; allow network access as well as installing the build dependencies. CI installs uv 0.12.5 with a SHA-256 digest for each platform archive from its [upstream release](https://github.com/astral-sh/uv/releases/tag/0.12.5). A fresh tool-cache directory prevents setup-uv from skipping archive verification on a cache hit. When uv, setup-uv or the runner platform changes, repeat the negative check on a temporary branch: replace every matrix `uv-checksum` with a quoted string of 64 zeros and push it. Each setup-uv step must fail with a checksum-mismatch error, and subsequent uv commands must be skipped. An unrelated download/network failure is not sufficient. Do not merge this branch. Tool versions are locked in `uv.lock`. Sphinx 8.2.3 serves Python 3.11; Sphinx 9.1.0 serves newer Python versions. Coverage is reported to locate gaps; it cannot certify the astronomy values, which the reference cases do. Tests exercise birth/time, chart/configuration, result and text contracts as well as development checks. Add domain tests with each feature. For local formatting, run `uv run ruff format .`. A failed command stops the check run; fix its cause and rerun. Dependency changes must update the lock and pass both Python endpoints. Keep suppressions narrow and explain their reason. To keep HTML for inspection, build it into the ignored `build/` directory: ```sh uv run python -m sphinx \ -E -a -n -W -b html -c docs \ -d build/docs-doctrees . build/docs ``` Open `build/docs/index.html` for both language entries. The current combined search index supports both languages. See [search limits](knowledge.md#translation-revisions-and-search). The checks inspect the generated search index, splitter and stemmer interfaces, each page's language and link to its counterpart, complete catalog anchors and whether translations are current. A successful build alone is insufficient. Independent verification can execute the generated JavaScript query/index code; a Python tokenizer unit test does not prove browser behavior. `tools/guide_checks.py` lists the usage topics that need explanations and examples. Each language must contain exactly one marked block per topic, with explanatory prose and one runnable `{doctest}` code block. For example, `` opens the orb block and `` closes it. Titles, translations and page locations may change together with their content. Empty, nested, unmatched, unknown or duplicate blocks fail. The source and extracted sdist both run this check, then compare each document's source example count with its executed Sphinx count. Passing these structural checks does not establish that an explanation is clear or its translation accurate; both still need to be read and checked. `PACKAGE_FILES` in `tools/check.py` lists the source files expected in distributions. The checks independently scan the source tree for unlisted files, require every listed path in the wheel/sdist and compare wheel package bytes with the original checkout, including `catalog.json` and `py.typed`. The installed-package check discovers and imports each actual Python module, deferring the astronomy adapter until calculation; it does not import development checks. Feature PRs keep domain assertions in tests, not the installed-package check; packaging agreement uses source-to-wheel bytes and observation files. Fixed fresh-process inputs live in `tests/consumer_cases/`. Tests pass their text to `python [-O] -c` so the repository root stays on `sys.path` for imports from `tools`. Sphinx discovers only the two root READMEs and sources under `docs/`. Keep virtual environments outside `docs/`: sources anywhere under that directory are documentation inputs, while sibling directories are not. Warnings in these document sources still fail the strict build. Install this development package from the checkout using `uv sync` above. Its distribution name/version is `celestial-astrology` / `0.5.0`; the Python import remains `astrology`. The unrelated PyPI project `astrology` is not this library. Confirm the installed package and version: ```{doctest} >>> from importlib.metadata import version >>> version("celestial-astrology") '0.5.0' ``` The checks execute both READMEs against an isolated wheel install, compare their documented output, inspect the wheel's actual Markdown links, and resolve both language paths against the built site. They also hide `celestial-astrology` metadata in a disposable install. Import and knowledge remain usable; direct calculation raises `PackageNotFoundError` naming that distribution. Both Python modes run before the metadata is restored. For manual Pages delivery, build from a clean committed checkout and set `ASTROLOGY_DOCS_SOURCE_SHA` to its full lowercase commit SHA. The root page then renders that source archive and its install command; an ordinary local build is labeled without a fixed revision. Keep doctrees, caches and other build-control files outside the exported site. Inspect all generated sources/downloads/assets before updating the dedicated `gh-pages` branch with `.nojekyll`. This is a manual site update, not automatic source publishing or a package release. Actual acceptance also checks the deployed root, every README URL and English/Chinese browser search; local HTML success alone is insufficient. Snapshot installation and the Python intersphinx inventory require network access. ## Design Use immutable values for inputs, configuration, rules, and results. A frozen dataclass still permits mutations inside a list or dictionary: store immutable members or copy and isolate mutable input at the boundary. A caller changing its input after construction must not change the chart result. Prefer ordinary functions with explicit arguments and return values. Keep file access, native initialization, network calls, and caches visible at their owning boundary. Importing the package or reading knowledge must not calculate a chart. Use tables for data-shaped rules and functions for computation. Keep definitions in their domain and compose them at the entry point. Add an abstraction when actual callers share a contract; a possible future backend is not a caller. Names and types should express meaning before comments have to explain it. Configuration must affect the computation it describes. Reject unsupported choices and retain requested/effective settings. Avoid implicit global settings, silent substitutions, and factories whose return type depends on hidden state. ## Correctness Return fixtures in `tests/reference/return_reference.json` use independently calculated natal degrees and TT crossings from pyswisseph 2.10.3.2 / Swiss 2.10.03, explicit Moshier plus speed flags 260. Regenerate them without project/native imports or a dependency change: ```sh uv run --no-project --python 3.11 --with pyswisseph==2.10.3.2 python tools/fetch_return_reference.py --output ``` The recipe pins birth/search TT−UTC offsets to 64.184/69.184 seconds for its 2000 natal instants and 2023–2024 intervals. The Sun 5-second and Moon 30-second fixture tolerances cover measured cross-model differences (maxima 1.344672/11.771331 seconds) for these synthetic cases only, not global error bounds. Tests separately recompute native wrapped residuals within 1e-6 degree, compare all event counts and exercise exact endpoint collisions. Cases include near-zero degrees, leap-day birth and two solar returns within calendar 2024. Some overlapping windows repeat events; they are not independent observations. The recipe hash binds the fixture to its generator. This optional reference environment adds no runtime or locked dependency; Swiss code and ephemeris files are not distributed here. Transit fixtures in `tests/reference/transit_reference.json` use explicitly selected Moshier ephemeris calculations through `pyswisseph==2.10.3.2`, not Swiss/JPL data files. The optional generator `tools/fetch_transit_reference.py --output ` runs in a separate reference environment with that package, the project's locked dependencies, and the repository root and `src/` on `PYTHONPATH`. It requires celestial-calendar 1.1.1 for calibration, but its crossing expectations come from Moshier or the existing independent Meeus node formulas. This adds no runtime dependency. The fixture records 1,830 calibration samples over 2021–2022, per-body angular bounds, a rate-scaled time bound and later held-out cases. Compare counts, directions and angular residuals as well as event times; exact native tangencies and endpoint ownership have separate controlled/native tests. Test the domain boundary as well as representative values: non-finite numbers, time ambiguity, coordinate wrap, exact endpoints, missing information, and unsupported combinations. Public validation must still run under `python -O`. Record the source, model/version, time scale, coordinate convention, configuration, units, and tolerance with numerical fixtures. Source/install comparisons test packaging agreement; an independent source tests numerical agreement. Shared formulas or copied datasets can make apparently independent checks agree on the same mistake. Explain why a reference can detect the defect being tested. Use synthetic examples or sources that can be redistributed. Keep astronomical validation separate from the claimed interpretation of a chart. The natal chart cases in `tests/reference/natal_reference.json` compare two instants, one per hemisphere, against JPL Horizons and against definition-level checks. The fixture records the query URLs, the ephemeris kernel Horizons names for each body and for the geocenter (the Sun, the Moon, Mercury and Venus use DE441, the other bodies their own kernels), the retrieval time and the conventions used. To fetch the two Horizons cases again without changing the committed fixture: ```sh uv run --locked python tools/fetch_reference.py --output build/natal_reference.json ``` This requires network access and only the Python standard library. The output path is required; the tool reads no local reference or review files. It writes query URLs, source kernels, conventions, retrieval time and values, then prints the output file's SHA-256. Inspect numerical and provenance changes before deliberately replacing the versioned fixture. Offline tests use controlled responses and are separate from a live fetch. The body tolerances follow the upstream's own model error against Horizons, not the two instants. The Sun and the planets agree to about 0.8 arcseconds in longitude over 24 instants in 2000-2002 and to 1.3 at the 2020 instant; the truncated lunar model agrees within 10 arcseconds in longitude and 2.4 in latitude over 60 instants in 2000-2030. Those samples were taken ad hoc and are not kept in the repository. The tolerances are 3 arcseconds for the Sun and the planets, 15 for the Moon, 1 for latitude, 3 for the Moon's latitude and 1 for the nodes. The axes and the Placidus cusps use 0.001 degrees (3.6 arcseconds): the two instants differ by at most 0.91 arcseconds there, which is the difference between the UT1 the library models and the UT1 Horizons observes. Each reference detects a different defect. Whether a defect is caught depends on the tolerance and on the offset the library already has from the reference (up to 0.91 arcseconds for the axes and 3.4 for the Moon's longitude), so a shift somewhat below the tolerance can still be caught. The cases below were judged with that offset counted: | Reference | Detects | Does not detect | |---|---|---| | Horizons longitudes | A wrong ephemeris or body mapping. UTC used for TT (64-69 seconds) moves the Moon 35-42 arcseconds and Mercury 3-5. | A shift that stays inside the tolerance with that offset counted, including a path that corrupts only the Sun (2.6-2.8 arcseconds). | | Exact leap-second relation | UTC or UT1 passed where TT belongs: the reported JDE(TT) is 0.2-0.3 seconds off. | A rotation path that treats UTC as UT1; the reported JDE(TT) stays exact. | | Horizons sidereal time, axes | The mean sidereal time used for the apparent one (0.002-0.005 degrees). UT1 taken as UTC: 5.0 arcseconds at the northern instant and 3.7 at the southern one, only just past the 3.6 threshold. A mean obliquity for the true one at the northern instant (5.7). | A mean obliquity for the true one at the southern instant (under 1 arcsecond). | | Horizons sidereal time, Placidus cusps 2, 3, 11 and 12 | Cusps away from the Placidus time division by more than about 0.0015 degrees, such as another house system. | A misreading of the Placidus definition shared with the check. This fixture has no external cusp values; cusps 5, 6, 8 and 9 are checked only as exact opposites. | | Meeus chapter 47 nodes | A wrong node definition, direction or missing nutation term. | A mistake in the shared formula, and a TT/UT mix, which moves a node by under 0.4 arcseconds. | The Horizons-based and hand-computed aspect checks have three parts. Cases in `tests/test_aspects.py` need no astronomy. Dividing a one-hour longitude change by the elapsed time checks the sign and unit of the rates used to determine applying or separating motion, with agreement to about 1e-6 degrees per day. The reference tests configure the orbs that Astrodienst publishes for its Hellenistic drawing style and compare the resulting aspect set with one derived from the Horizons longitudes. Where a pair lies near an orb limit, they detect a wrong orb, combination rule or angle; they also detect a node that takes part. They cannot detect a longitude error smaller than the 0.4-degree margin, and the two instants hold no sextile or opposition, so those angles rest on the hand-computed cases. They do not check the status against an external source: Horizons supplies no rates here, and the style page gives parameters, not the aspect list of a chart. The separate Swiss complete-chart reference data includes independently calculated rates and all house cusps. Tests use separately written arithmetic to derive signs, house placements, aspects and motion for four synthetic instants, covering all five aspects. Details follow below. The project-calculated numeric regression samples are not external evidence. Keep their original numbers and extraction provenance when changing pure rules or dependencies. Current provenance and numerical regression are distinct: a version-only change must not prevent numerical comparison. A changed model needs an explicit comparison policy. Demonstrate that a regression test accepts valid input and rejects the defect it targets. A version-label change alone must pass numerical regression; an internally valid numerical change beyond tolerance must fail at the numerical assertion. Record the changed input or implementation, actual exit code and failure location in the PR. A constructor or import failure does not demonstrate a numerical check. ### Complete-chart numerical references `tests/reference/chart_regression.json` retains numbers from two project-calculated synthetic Whole Sign cases: an IANA input with nonuniform aspect orbs from the `0.0.0` development tree and a fixed-offset, two-body case without aspects from the published v0.1.0 wheel. Extraction provenance includes the original sample hashes and the released wheel/manifest digests, source commit and generation procedure. These are regression samples, not independent astronomy references. Tests construct their inputs explicitly; they do not restore saved charts. Numerical regression checks models, frames, configuration, identities and classifications without requiring historical package-version equality. Absolute tolerances are 1e-8 degrees for angles, 1e-9 AU for distances, 1e-9 degrees/TT day for rates and 1e-8 days for Julian dates. A changed model needs a separately justified comparison. These finite cases do not establish global accuracy. `tests/reference/complete_chart_reference.json` contains independently executed Swiss Ephemeris 2.10.03 / pyswisseph 2.10.3.2 numeric states for four synthetic instants, each with three house systems. It records the pyswisseph Python wheel's SHA-256 hash, flags, coordinate/time conventions, source URLs, separate calibration and per-field tolerances. Moshier is requested explicitly; returned `calc` flags are checked. Swiss houses use Swiss UT1 and Delta-T, not Algo5, the fixed Delta-T model used by this adapter. Their tolerance includes that time-model difference. Signs, two-dimensional house membership (using longitude, not object latitude), aspects and motion were derived by separate project-authored arithmetic from the Swiss states; Swiss itself does not supply an aspect table. Mean-node longitude/rate are compared as named models, not assumed identical formulas. Node distance and true nodes are not equivalent comparisons; zero node latitude is a definition-level check. If a reference point is within the combined longitude/cusp tolerances of a cusp, the comparison accepts either adjoining house. It does not claim an exact independent house label for that point. The [Swiss documentation](https://www.astro.com/swisseph/swisseph.htm) describes Moshier's precision class. The recorded thresholds include both implementations' model differences and finite calibration; they are not global accuracy guarantees. The source tool was isolated and is not a runtime/dev dependency. Only generated numbers and project-authored metadata are included, not Swiss code or ephemeris files; see the [GNU output FAQ](https://www.gnu.org/licenses/gpl-faq.html#WhatCaseIsOutputGPL). This does not change the project's MIT license or constitute a general license assurance. ## Knowledge and documentation Each technique needs a named definition, sources and reference cases before implementation. Follow the [knowledge design](knowledge.md). Link explanations to stable concepts, rules and sources. Preserve original quotations and label translations; a checked source is not evidence that a particular chart meets its prerequisites. Update both language pages when behavior changes. Public docstring summaries and contracts are bilingual; identifiers, signatures, units, and defaults have one source. Execute examples and inspect the generated pages. Automated coverage can detect a missing translation file, but cannot establish semantic equivalence. The catalog checks also reject stale text revisions, missing record descriptions, unknown references and duplicate IDs. Both language views have executable examples; source and translation review checks that conditions and limits retain their meaning. ### Add a sourced variant 1. Inspect a retrievable edition and reproduction terms. Record work, author or translator, edition, language, locator, lineage, supported claim and limits. Mark unverified material honestly; two mirrors are not two sources. 2. Add stable records to `src/astrology/knowledge/catalog.json`. Reference an owning enum class/member instead of copying its value or inventing an algorithm. Add a separate explicit variant only when it carries a rule, with its own definition and limits; configuration links alone do not generate variants. Lunar-node definition links are derived from `LunarNode.definition`, and the loader checks all twelve Sign-to-concept identities in the built-in corpus. Source-only variants have no config reference; entries link variant IDs and citations. 3. Keep excerpts, translations and authored statements distinct. `text_defaults` supplies initial revision 1 and project translation credit; each text can override them. Increment a changed text's `revision`; retain its old `zh_revision` until translation review, then update revision and credit together. 4. State prerequisites, exceptions and limits. Select source verification, prerequisite completeness and output eligibility independently. Retrieval must leave chart applicability `not_assessed` even when one condition is computable. Leave unsupported interpretations out of the default corpus. 5. Add boundary/source tests, run the [complete checks](#run-the-checks) and inspect both generated language pages. Checks cover current translations, complete config/catalog/API references and installed resources. Semantic review still verifies translation meaning and source fidelity. ## Review evidence For contributions written with AI, the contributor remains responsible for the result. Include the issue, behavior change, checks actually run, and unresolved questions in the pull request. Distinguish executed evidence from proposed checks. Reviewers check source fidelity, unsupported assumptions, mutation/aliasing, failure behavior, unnecessary abstractions, and translation meaning. Passing lint or achieving high coverage does not answer these questions. When changing a check, demonstrate both an accepted input and a defect it rejects. ## Merge policy Changes to `main` require a pull request and these four checks: - `quality (ubuntu-latest, 3.11)` - `quality (ubuntu-latest, 3.14)` - `quality (macos-latest, 3.14)` - `quality (windows-latest, 3.14)` Required checks use strict mode: the branch must also be up to date with `main`. The configured number of required approving reviews is zero; this does not authorize an automated agent to merge. Merge and publication still require maintainer approval. Branch protection also applies to administrators. No merge-time bypass is configured; force pushes and deletion of `main` are disabled. Changing these settings is a separate administrative operation that requires maintainer authorization. Only squash merges are enabled, using the pull request's title and body. To check enforcement safely, use a temporary, non-draft pull request that is never merged. Compare, in order, a required check passing, a deliberate failure caused only on that probe branch, and the check passing again on the same pull request. Record the tested revisions, exact check names and results, the current `main` revision, effective branch-protection rules and both REST and GraphQL merge states. Exclude other blockers such as conflicts, an outdated branch or blocking reviews. An unchanged configuration alone does not establish execution behavior. `mergeable` describes conflicts, not permission to merge. A computed `BLOCKED` merge state during that intentional failure is distinct from an actual merge request being rejected. Do not attempt to merge a deliberately failing probe or relax protection to obtain an expected result. Retain ambiguous results as incomplete evidence; verification of this repository's merge policy is tracked in [#15](https://github.com/0xf3cd/astrology/issues/15).