diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..13a1272 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + test: + name: Core test suite & docs strict build + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Set up Python 3.12 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: "3.12" + + - name: Install package and dev dependencies into .venv + run: | + python -m venv .venv + .venv/bin/python -m pip install -e ".[dev]" + + - name: Run non-e2e test suite + run: > + .venv/bin/python -m pytest -q -rs -n auto --maxprocesses=12 -p no:cacheprovider + --ignore=tests/test_e2e_real.py + --ignore=tests/test_app_e2e.py + --ignore=tests/test_control_e2e.py + --ignore=tests/test_gateway_e2e.py + + - name: Build documentation site (strict, out-of-tree) + run: .venv/bin/python -m mkdocs build --strict -d "${RUNNER_TEMP:?RUNNER_TEMP must be set}/site" diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 3d73cb5..801c868 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -25,15 +25,18 @@ permissions: contents: read concurrency: - group: pages - cancel-in-progress: false + group: ${{ github.event_name == 'pull_request' && format('pages-pr-{0}', github.event.pull_request.number) || 'pages' }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: build: runs-on: ubuntu-latest + timeout-minutes: 15 steps: - - uses: actions/checkout@v7 - - uses: actions/setup-python@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: "3.12" - name: Install @@ -42,7 +45,7 @@ jobs: run: python -m pytest tests/test_site.py -q -rs -p no:cacheprovider - name: Build run: python -m mkdocs build --strict - - uses: actions/upload-pages-artifact@v5 + - uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 if: github.event_name != 'pull_request' with: path: site @@ -51,6 +54,7 @@ jobs: if: github.event_name != 'pull_request' needs: build runs-on: ubuntu-latest + timeout-minutes: 10 permissions: pages: write id-token: write @@ -59,4 +63,4 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} steps: - id: deployment - uses: actions/deploy-pages@v5 + uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..69edbed --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,31 @@ +# Servedeck — Agent & Contributor Card + +Self-contained working guide for automated coding and review agents operating on this public repository. Full ground rules, test discipline, and the two-pass review gate live in [CONTRIBUTING.md](CONTRIBUTING.md). + +## Key Commands + +*(Create a repo-local `.venv` via `python3 -m venv .venv && .venv/bin/python -m pip install -e ".[dev]"` so `tests/test_cli_control.py` executes all 16 console-script tests instead of skipping.)* + +- **Everyday non-e2e test suite (35 modules including `tests/test_cli_control.py`, `tests/test_hygiene.py`, and `tests/test_site.py`; caps parallel workers at `12`):** + ```bash + .venv/bin/python -m pytest -q -rs -n auto --maxprocesses=12 -p no:cacheprovider \ + --ignore=tests/test_e2e_real.py \ + --ignore=tests/test_app_e2e.py \ + --ignore=tests/test_control_e2e.py \ + --ignore=tests/test_gateway_e2e.py + ``` +- **Documentation site strict build (write output outside the repo tree so rendered HTML under `site/` does not trip `tests/test_hygiene.py` on subsequent local runs):** + ```bash + .venv/bin/python -m mkdocs build --strict -d + ``` +- **CI workflows:** `.github/workflows/ci.yml` runs on every `push` to `main` and every `pull_request` (`.venv` editable install, all 35 non-e2e modules with `-rs`, and out-of-tree `mkdocs build --strict`); `.github/workflows/pages.yml` builds and publishes the site with SHA-pinned GitHub Actions. + +## Non-Negotiable Invariants + +- **Never run `sudo`.** Operator lifecycle for the persistent `servedeck.service` unit uses `systemctl --user`. Control-plane code in `servedeck/units.py` uses `systemctl --user`, `systemd-run --user`, and `journalctl --user` **exclusively** for transient `model-*` / `sd-test-*` user units (explicitly refusing `servedeck` and all other names via `_NAME_RE`). Read-only kernel Xid polling uses `journalctl -k -b all --no-pager` (`servedeck/gpu.py`, `servedeck/xid_watch.py`). Where host-level privilege is needed, emit a copyable command for the operator. +- **Never use `pgrep` or `pkill`.** Enforced by AST scan in `tests/test_hygiene.py`, which bans any `pgrep` or `pkill` invocation in executable (non-docstring) string literals (not only `-f`). +- **Keep transient e2e units under the `sd-test-` namespace** (`test_app_e2e.py`, `test_control_e2e.py`, `test_e2e_real.py`; the sole deliberate exception is the read-only `sd-netns-probe-` helper in `tests/conftest.py`, kept outside `sd-test-*` so e2e teardown globs do not race or stop it). Never start, stop, or mutate any live `model-*` unit or non-test production user unit (`servedeck`, `lfm2-350m`, `qwen-vllm`, `*-reasoning-proxy`) from automated tests. +- **No host-specific paths, machine names, or hardcoded GPU sizes** in code or docs (`models.toml`, `servedeck/settings.py`, and `servedeck/limits.py` own machine config). Keep documentation free of user-specific home paths and scratch temp paths. +- **Measured vs. estimated numbers:** Label any derived value explicitly as estimated; every measured figure must cite a real log or live probe. +- **Review & proof discipline:** Every behavioral fix ships a regression test seen to fail before the fix (`fail-before` / mutant proof). Follow the author-blind two-pass review gate and `### Negative-Rule Ledger` in [CONTRIBUTING.md](CONTRIBUTING.md). +- **Commit identity (maintainer / automated-agent commits):** Maintainer and maintainer-operated automated-agent commits use sole repository owner identity with explicit staged paths and zero `Co-Authored-By:` or AI attribution trailers; external contributors (and agents acting on their behalf) retain the contributor's own authorship identity. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 27690e1..8742942 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -92,3 +92,26 @@ as part of a normal check. How to contribute: [CONTRIBUTING.md](CONTRIBUTING.md) | Use it | [Operations](https://servedeck.rlalphalabs.com/operations/) · [Clients](https://servedeck.rlalphalabs.com/clients/) · [Configuration](https://servedeck.rlalphalabs.com/configuration/) | | How it is built | [Architecture](https://servedeck.rlalphalabs.com/architecture/) · [Builds](https://servedeck.rlalphalabs.com/builds/) · [Host](https://servedeck.rlalphalabs.com/host/) · [Decisions](https://servedeck.rlalphalabs.com/decisions/) | | Each model, measured | [Flash-Next](https://servedeck.rlalphalabs.com/models/flashnext/) · [Qwen3.8-27B](https://servedeck.rlalphalabs.com/models/qwen27b/) · [GLM-5.3](https://servedeck.rlalphalabs.com/models/glm53/) · [LFM2.5-350M](https://servedeck.rlalphalabs.com/models/lfm2/) | + +## Review & Verification Gate + +Every pull request clears three sequential stages before being marked ready for review: + +1. **Deterministic gate:** + - CI workflow `.github/workflows/ci.yml` passes: editable install inside repo-local `.venv` (ensuring `tests/test_cli_control.py` executes all 16 console-script tests instead of skipping), `.venv/bin/python -m pytest -q -rs -n auto --maxprocesses=12 -p no:cacheprovider` excluding the 4 GPU/systemd e2e modules (covering all 35 non-e2e test modules including `tests/test_cli_control.py`, `tests/test_hygiene.py`, and `tests/test_site.py`), plus out-of-tree `.venv/bin/python -m mkdocs build --strict -d ` (preventing generated HTML under `site/` from tripping `tests/test_hygiene.py`). + - Behavioral changes include an executable `fail-before` proof (test fails against the base tree or reverted code) or `mutant-kill` proof (a one-line defect in a throwaway copy causes assertion exit `1`). + - GitHub Actions workflows stay pinned to exact 40-character commit SHAs with minimal `permissions` and `persist-credentials: false` strictly on `actions/checkout`. +2. **Pass-1 author-blind diff audit:** + - Start a fresh reviewer with zero authoring history and **without** reading PR rationalization prose first. + - Read the diff and referenced callers directly, emit a **2-sentence paraphrase** of what the diff changes (catching unspoken assumptions early), audit correctness, systemd/process control safety, concurrency, packaging/hygiene invariants, and docs, and record every unrun check (e.g., GPU e2e gate or missing local `mkdocs`) under `COULD NOT VERIFY`. + - Severity labels: **`Blocker:`** (correctness, safety, security, test-gate weakening, or ledger counter-shape — must fix), **`Warning:`** (high-risk defect or missing edge-case coverage — must fix or clear via Pass-2 proof), **`Nit:`** (non-blocking polish). +3. **Pass-2 proof-backed verification:** + - No candidate `Blocker:` or `Warning:` finding may be dismissed with prose alone. Every disputed finding maps strictly to `VERIFIED` (must fix or escalate) or `DISPUTED_WITH_PROOF` backed by one of: (a) an executable counter-probe against the exact trigger input, (b) a caller-complete invariant proof quoting exact `file:line` guards across the repo, (c) a matching row in the `` branch's `### Negative-Rule Ledger` below (never from self-edited PR lines), or (d) an exact verbatim documentation clause for non-executable `.md` prose. + +### Negative-Rule Ledger + +| Allowed Exact Shape (symbol/invariant) | Still-A-Bug Counter-Shape (never dismiss) | +| :--- | :--- | +| `systemctl --user` (for manual operator lifecycle of persistent `servedeck.service`), `servedeck/units.py` using `systemctl --user` / `systemd-run --user` / `journalctl --user` **exclusively** for transient `model-*` / `sd-test-*` user units (explicitly refusing `servedeck` and all other names via `_NAME_RE`), and read-only kernel Xid polling via `journalctl -k -b all --no-pager` (`servedeck/gpu.py`, `servedeck/xid_watch.py`). | Any invocation of `sudo`, `su`, or system-wide `systemctl` / `systemd-run` (without `--user`), widening `servedeck/units.py` `_NAME_RE` beyond `model-*` / `sd-test-*` (e.g., permitting `servedeck` or other persistent units), or wildcard unit stop globs such as `systemctl --user stop 'sd-test-*'` (`Blocker:`). | +| `sd-test-` transient unit prefix in isolated systemd e2e tests (`test_app_e2e.py`, `test_control_e2e.py`, `test_e2e_real.py`), plus the read-only `sd-netns-probe-` helper in `tests/conftest.py` (kept outside `sd-test-*` so e2e teardown sweeps do not race or stop it). | Starting, stopping, or mutating any live `model-*` unit or non-test production user unit (`servedeck`, `lfm2-350m`, `qwen-vllm`, `*-reasoning-proxy`) from automated tests (`Blocker:`). | +| Excluding the 4 fixed-port/GPU e2e modules (`test_e2e_real.py`, `test_app_e2e.py`, `test_control_e2e.py`, `test_gateway_e2e.py`) from the everyday `ci.yml` runner, and host-hardware/cache-gated individual test skips surfaced transparently by `-rs` (GPU/HF cache/multi-filesystem checks). | Weakening, causing module-/dependency-level skips (e.g., omitting `.venv` so `tests/test_cli_control.py` silently skips, or omitting `mkdocs` so `TestTheBuiltSite` in `tests/test_site.py` skips), or excluding any of the 35 non-e2e unit/hygiene/site test modules (`Blocker:`). |