Repository navigation
Replace repeated agent prose with CI checks #1204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+210
−620
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fade3b1
Check toolchain and service pins in CI instead of agent prose.
jatmn 3d2fe41
Reduce the agent prompt to the repository identity and the local gate.
jatmn b22a79a
Lock the log-channel copy skip in CI instead of agent prose.
jatmn 7c67b18
Make the new contracts check match what the fixtures and images actua…
jatmn d0c4cbe
Count braces when reading db_open_options.
jatmn 8b8bb5c
Stop scanning Rust to decide which process migrates.
jatmn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,3 @@ | ||
| # Copilot code review instructions for jModGuard | ||
| # Copilot review notes | ||
|
|
||
| Copilot is a backup reviewer here, requested manually only when Sourcery can't review. It is advisory: PR Reviewer and Pullfrog form the merge gate. See `AGENTS.md` for the full contracts. | ||
|
|
||
| ## Layout | ||
| - `src/`: the shared `jmodguard` data and config crate. `src/db.rs` is the local/remote libSQL pool and data-layer facade, and it runs its own database runtimes. `src/db/` holds bootstrap/migrations, configuration, settings, moderation and tests. `src/db_compat.rs` has remote deadlines and rollback, and `src/tenant.rs` holds tenant stores. | ||
| - `crates/bot`: the Discord gateway bot (Serenity). It handles automod, commands, action and nickname workers, and is the only role that migrates. | ||
| - `crates/api`: the axum WebUI/API. It never migrates and dispatches through the queue, not the bot token. | ||
| - `crates/updater`: the in-app updater. `src/launcher_child.rs` is the launcher child side. | ||
| - `crates/runtime`: process primitives (health, cgroup). It must not import root data, Serenity, or bot/API state. | ||
| - `crates/integration-tests`: cross-service tests. `migrations/`, `frontend/` and `docs/` round it out. | ||
|
|
||
| ## Hard rules (flag any break as P1) | ||
| - The bot must always be able to moderate. No change may block or disable bans, kicks, timeouts, deletes or automod enforcement. | ||
| - The in-app updater never runs schema migrations. Schema changes use the durable bot/API paired protocol, and recovery after the migration fence is forward-only. | ||
| - Never display or estimate host-wide memory; reading MemTotal solely to detect an unbounded cgroup limit is allowed. Use the process's or container's own limits only. | ||
| - Keep the service boundaries. Bot and API dependency graphs stay independent, the API never migrates, and API work never takes unscoped queue or moderation access. | ||
| - Never run core migrations or defaults on a guild store. Credentials stay in process config, never in catalog rows. | ||
|
|
||
| ## Rust conventions | ||
| - Code must pass Clippy with `-D warnings`. No `unwrap()`/`expect()` in runtime paths (tests are fine). | ||
| - Every behavior change needs a test at the smallest reliable boundary that proves it. | ||
|
|
||
| ## How to review | ||
| - Stay within the PR's stated scope. Don't ask for unrelated refactors. | ||
| - Report only real bugs, contract breaks, security issues, data loss, and missing tests for changed behavior. Skip style nits and formatting. | ||
| - Start each finding with a priority: **P1** for a bug, data loss, security issue, or hard-rule break; **P2** for a likely bug or a missing test; **P3** for a minor but real issue. | ||
| - Never comment on Release Please PRs (`chore(main): release …`) or on `CHANGELOG.md` / `.release-please-manifest.json` changes. | ||
| Report behavioral bugs, data loss, and security issues in the diff. Formatting and service boundaries are enforced in CI. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| #!/usr/bin/env bash | ||
| # Executable stand-in for agent-doc claims that are facts about this tree: | ||
| # the Rust pin, the runtime image, and production dependency edges. | ||
| # Which process migrates is asserted by process_options_fix_migration_role_and_keep_shared_settings. | ||
| # Operator manuals are not the source of these facts. | ||
| set -euo pipefail | ||
|
|
||
| root="$(cd "$(dirname "$0")/.." && pwd)" | ||
|
|
||
| fail() { | ||
| echo "check-pinned-facts: $*" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| section_body() { | ||
| local file="$1" | ||
| local section="$2" | ||
| awk -v section="$section" ' | ||
| $0 == section { grab = 1; next } | ||
| grab && /^\[/ { exit } | ||
| grab { print } | ||
| ' "$file" | ||
| } | ||
|
|
||
| # grep -q in a pipefail pipeline returns success before awk finishes, so a | ||
| # large section makes awk die with SIGPIPE and the match is reported missing. | ||
| section_matches() { | ||
| local file="$1" | ||
| local section="$2" | ||
| local pattern="$3" | ||
| local body | ||
| body="$(section_body "$file" "$section")" || return 1 | ||
| printf '%s\n' "$body" | grep -E -- "$pattern" >/dev/null | ||
| } | ||
|
|
||
| require_section() { | ||
| local file="$1" | ||
| local section="$2" | ||
| local pattern="$3" | ||
| local message="$4" | ||
| section_matches "$file" "$section" "$pattern" || fail "$message" | ||
| } | ||
|
|
||
| forbid_section() { | ||
| local file="$1" | ||
| local section="$2" | ||
| local pattern="$3" | ||
| local message="$4" | ||
| if section_matches "$file" "$section" "$pattern"; then | ||
| fail "$message" | ||
| fi | ||
| } | ||
|
|
||
| final_stage() { | ||
| awk ' | ||
| /^FROM / { stage = ""; has = 1 } | ||
| has { stage = stage $0 ORS } | ||
| END { printf "%s", stage } | ||
| ' "$1" | ||
| } | ||
|
|
||
| # The last assignment in the runtime stage is the one the container keeps. | ||
| final_stage_sets_remote_db() { | ||
| local stage last | ||
| stage="$(final_stage "$1")" | ||
| last="$(printf '%s\n' "$stage" | awk ' | ||
| $0 ~ /^ENV JMODGUARD_REQUIRE_REMOTE_DB=/ { value = $0 } | ||
| END { print value } | ||
| ')" | ||
| [[ "$last" == "ENV JMODGUARD_REQUIRE_REMOTE_DB=1" ]] | ||
| } | ||
|
|
||
| self_test() { | ||
| local tmp impl_file | ||
| tmp="$(mktemp)" | ||
| cat >"$tmp" <<'EOF' | ||
| [dependencies] | ||
| anyhow = "1" | ||
| [dev-dependencies] | ||
| serenity = "1" | ||
| jmodguard-runtime = { path = "runtime" } | ||
| EOF | ||
| if section_matches "$tmp" "[dependencies]" '^serenity[[:space:]]*='; then | ||
| fail "self-test: dev-dependencies leaked into [dependencies]" | ||
| fi | ||
| section_matches "$tmp" "[dev-dependencies]" '^serenity[[:space:]]*=' \ | ||
| || fail "self-test: missed serenity in [dev-dependencies]" | ||
| if section_matches "$tmp" "[dev-dependencies]" '^jmodguard[[:space:]]*='; then | ||
| fail "self-test: jmodguard-runtime matched as jmodguard" | ||
| fi | ||
| { | ||
| echo '[dependencies]' | ||
| echo 'serenity = "1"' | ||
| i=0 | ||
| while [ "$i" -lt 20000 ]; do | ||
| echo "crate${i} = \"1\"" | ||
| i=$((i + 1)) | ||
| done | ||
| echo '[dev-dependencies]' | ||
| } >"$tmp" | ||
| section_matches "$tmp" "[dependencies]" '^serenity[[:space:]]*=' \ | ||
| || fail "self-test: a large section hid a real dependency match" | ||
|
|
||
| impl_file="$(mktemp)" | ||
| cat >"$impl_file" <<'EOF' | ||
| FROM rust:1.100.0-trixie@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa AS builder | ||
| ENV JMODGUARD_REQUIRE_REMOTE_DB=1 | ||
| FROM debian:trixie-slim | ||
| ENV OTHER=1 | ||
| EOF | ||
| if final_stage_sets_remote_db "$impl_file"; then | ||
| fail "self-test: builder-only remote DB setting counted for the runtime stage" | ||
| fi | ||
| cat >"$impl_file" <<'EOF' | ||
| FROM rust:1.100.0-trixie AS builder | ||
| ENV JMODGUARD_REQUIRE_REMOTE_DB=1 | ||
| FROM debian:trixie-slim | ||
| ENV JMODGUARD_REQUIRE_REMOTE_DB=0 | ||
| ENV JMODGUARD_REQUIRE_REMOTE_DB=1 | ||
| EOF | ||
| final_stage_sets_remote_db "$impl_file" \ | ||
| || fail "self-test: the last runtime assignment must win" | ||
| rm -f "$tmp" "$impl_file" | ||
| } | ||
|
|
||
| check_tree() { | ||
| local channel channel_re msrv versions version dockerfile tag | ||
| channel="$(awk -F'"' '/^channel = / { print $2; exit }' "$root/rust-toolchain.toml")" | ||
| [[ "$channel" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || fail "rust-toolchain channel must be X.Y.Z, found: ${channel:-empty}" | ||
| msrv="${channel%.*}" | ||
|
|
||
| versions="$(grep -E '^rust-version = "' "$root/Cargo.toml" || true)" | ||
| [[ -n "$versions" ]] || fail "Cargo.toml has no rust-version pin" | ||
| while IFS= read -r line; do | ||
| version="$(printf '%s\n' "$line" | sed -E 's/.*"([^"]+)".*/\1/')" | ||
| [[ "$version" == "$msrv" ]] || fail "Cargo.toml rust-version ${version} must be ${msrv} (from channel ${channel})" | ||
| done <<<"$versions" | ||
|
|
||
| local bot_from api_from | ||
| bot_from="$(awk '/^FROM rust:/ { print; exit }' "$root/Dockerfile.bot")" | ||
| api_from="$(awk '/^FROM rust:/ { print; exit }' "$root/Dockerfile.api")" | ||
| [[ "$bot_from" == "FROM rust:${channel}-"*@sha256:* ]] \ | ||
| || fail "Dockerfile.bot builder must pin rust:${channel} by digest, found: ${bot_from:-missing}" | ||
| channel_re="${channel//./\\.}" | ||
| [[ "$bot_from" =~ ^FROM\ rust:${channel_re}-[^@[:space:]]+@sha256:[0-9a-f]{64}([[:space:]]+AS[[:space:]].+)?$ ]] \ | ||
| || fail "Dockerfile.bot builder digest is not a full sha256 pin: $bot_from" | ||
| [[ "$api_from" == "$bot_from" ]] \ | ||
| || fail "Dockerfile.api builder must use the same pinned image as Dockerfile.bot" | ||
| for dockerfile in Dockerfile.bot Dockerfile.api; do | ||
| final_stage_sets_remote_db "$root/$dockerfile" \ | ||
| || fail "$dockerfile runtime stage must set JMODGUARD_REQUIRE_REMOTE_DB=1" | ||
| done | ||
|
|
||
| forbid_section "$root/Cargo.toml" "[dependencies]" '^serenity[[:space:]]*=' \ | ||
| "root production dependencies must not include serenity" | ||
| forbid_section "$root/Cargo.toml" "[dependencies]" '^jmodguard-bot[[:space:]]*=' \ | ||
| "root production dependencies must not include jmodguard-bot" | ||
| forbid_section "$root/Cargo.toml" "[dependencies]" '^jmodguard-api[[:space:]]*=' \ | ||
| "root production dependencies must not include jmodguard-api" | ||
|
|
||
| require_section "$root/crates/bot/Cargo.toml" "[dependencies]" '^serenity[[:space:]]*=' \ | ||
| "bot production dependencies must include serenity" | ||
| forbid_section "$root/crates/bot/Cargo.toml" "[dependencies]" '^jmodguard-api[[:space:]]*=' \ | ||
| "bot production dependencies must not include jmodguard-api" | ||
|
|
||
| forbid_section "$root/crates/api/Cargo.toml" "[dependencies]" '^serenity[[:space:]]*=' \ | ||
| "API production dependencies must not include serenity" | ||
| forbid_section "$root/crates/api/Cargo.toml" "[dependencies]" '^jmodguard-bot[[:space:]]*=' \ | ||
| "API production dependencies must not include jmodguard-bot" | ||
| require_section "$root/crates/api/Cargo.toml" "[dependencies]" 'memory-store' \ | ||
| "API sessions must keep the tower-sessions memory-store feature" | ||
|
|
||
| forbid_section "$root/crates/runtime/Cargo.toml" "[dependencies]" '^jmodguard[[:space:]]*=' \ | ||
| "runtime must not depend on the data crate" | ||
| forbid_section "$root/crates/runtime/Cargo.toml" "[dependencies]" '^jmodguard-bot[[:space:]]*=' \ | ||
| "runtime must not depend on the bot" | ||
| forbid_section "$root/crates/runtime/Cargo.toml" "[dependencies]" '^jmodguard-api[[:space:]]*=' \ | ||
| "runtime must not depend on the API" | ||
| forbid_section "$root/crates/runtime/Cargo.toml" "[dependencies]" '^serenity[[:space:]]*=' \ | ||
| "runtime must not depend on serenity" | ||
|
|
||
| tag="$(awk -F'"' '/^tag = / { print $2; exit }' "$root/dylint.toml")" | ||
| [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] \ | ||
| || fail "dylint.toml must pin a vX.Y.Z library tag, found: ${tag:-empty}" | ||
| } | ||
|
|
||
| self_test | ||
| check_tree | ||
| echo "check-pinned-facts: ok" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.