# Contributing to OAuthMC

OAuthMC is a standalone Rust crate with a zero-dependency TypeScript SDK (`sdk/js`) and a `node-minecraft-protocol` client test matrix (`tests/clients`).

## Toolchain and prerequisites

- Rust toolchain pinned in [rust-toolchain.toml](https://github.com/YellowUmbrellaDev/sculk.network/blob/96e9a1b/crates/oauthmc/rust-toolchain.toml) (`1.100.0`, with `rustfmt` and `clippy`)
- Node.js 22.18 or later (for the client matrix and TypeScript SDK tests)
- `musl-tools` and the `x86_64-unknown-linux-musl` Rust target (only for static release builds outside Docker)
- Docker (only for testing the container build)

## Build from source

Run all commands from `crates/oauthmc`:

```sh
cargo build --locked
```

For an optimized release binary:

```sh
cargo build --release --locked
```

For a static Linux musl binary (matching CI and the Dockerfile):

```sh
rustup target add x86_64-unknown-linux-musl
CC_x86_64_unknown_linux_musl=musl-gcc cargo build --release --locked --target x86_64-unknown-linux-musl
```

## Checks and tests

### Format, lint, and Rust tests

Run the same Rust checks CI executes:

```sh
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test --locked
```

`cargo test --locked` runs the unit tests (`src/`) and integration tests (`tests/integration.rs`):

```text
test result: ok. 19 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
...
test result: ok. 20 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
```

### Minecraft client matrix

The client matrix in `tests/clients/run-matrix.mjs` starts a mock Mojang session server (`tests/clients/mock-session.mjs`) and an OAuthMC binary, then connects real `node-minecraft-protocol` clients in online mode across:

- **Code mode**: `1.8.9`, `1.12.2`, `1.16.5`, `1.19`, `1.19.2`, `1.20.1`, `1.21.1`, `26.1`
- **Link mode**: `1.21.6`, `1.21.8`, `1.21.11`, `26.1`

Install the client dependencies once and run the matrix against your built binary:

```sh
npm --prefix tests/clients ci --no-audit --no-fund
OAUTHMC_BIN="$PWD/target/release/oauthmc" node tests/clients/run-matrix.mjs
```

Each version prints one `OK` line with the generated code, verified UUID, and username (using the mock session server's fixture player):

```text
[<version>] OK code=<XXXX-XXXX> uuid=<uuid> name=<player>
...
[<version> link] OK code=<XXXX-XXXX> uuid=<uuid> name=<player> verified=true
```

### TypeScript SDK tests

From the repository root:

```sh
pnpm --filter oauthmc typecheck
pnpm --filter oauthmc test
```

## Container smoke test

Build the Docker image and run the built-in health check:

```sh
docker build -t oauthmc .
docker run -d --name oauthmc-smoke \
  -e OAUTHMC_API_KEYS="smoke-test-key-0123456789abcdef0123" \
  oauthmc
docker exec oauthmc-smoke /oauthmc healthcheck
docker rm -f oauthmc-smoke
```

## Releases

OAuthMC is released from this monorepo with its own version and tags (`oauthmc-v0.3.0`), by the same `release` workflow as sculk.network. [The release guide](https://docs.sculk.network/nightly/sculk/releases.md) has the model and the steps. In short:

- Every night, if anything under `src/`, `Cargo.toml`, `Cargo.lock`, `rust-toolchain.toml` or `Dockerfile` changed and `ci-ok` passed on `main`, the workflow publishes `oauthmc-vX.Y.0-nightly.<date>.<run>` and the image tags `:X.Y.0-nightly.<date>.<run>` and `:nightly`.
- A maintainer promotes the latest nightly to a stable release with `gh workflow run release --ref main -f channel=stable -f product=oauthmc`. It publishes `:X.Y.0`, `:X.Y` and `:latest`.
- The version lives in the tag and the image's `org.opencontainers.image.version` label. Leave `Cargo.toml` at `0.1.0`, and do not keep a changelog: the GitHub Release notes list the commits that touched OAuthMC.

## Documentation

Keep the Markdown under `docs/` and the root `README.md` in sync with the source code:

- Environment variables and default message templates live in `src/config.rs` and are documented in [docs/configuration.md](https://docs.sculk.network/nightly/oauthmc/configuration.md).
- HTTP endpoints, status codes, and error codes live in `src/api.rs` and are documented in [docs/api.md](https://docs.sculk.network/nightly/oauthmc/api.md) and [docs/openapi.yaml](https://docs.sculk.network/nightly/oauthmc/openapi.md).
- Protocol version constants live in `src/mc.rs` and are documented in [docs/protocol.md](https://docs.sculk.network/nightly/oauthmc/protocol.md).
- The default server list icon is `src/favicon.png` (64x64, embedded in the binary). The mark ([docs/assets/mark.svg](https://docs.sculk.network/nightly/assets/crates/oauthmc/docs/assets/mark.svg)), the README banner and the GitHub social preview (`docs/assets/social.png`, 1280x640) live in `docs/assets/`.
- Use relative links only so every page renders on both GitHub and static-site generators.
