dexcord/lib/mix/tasks/dexcord.coverage.ex
Luna 0a84650025 feat(coverage): mix dexcord.coverage gate with pinned OpenAPI spec + CI workflow
Adds `Dexcord.Api.Coverage`, a testable core that diffs the compiled
endpoint route table against a pinned snapshot of Discord's official
OpenAPI spec (`priv/discord_openapi.json`). The spec is a coverage
CHECKLIST, not codegen input: it is refreshed only by the deliberate
`mix dexcord.coverage.refresh`, so upstream churn never breaks CI
spontaneously.

- `mix dexcord.coverage` compiles then exits non-zero on any in-scope
  endpoint missing from the declared surface (AC1.8/AC1.9).
- `mix dexcord.coverage.refresh` pins the spec via :httpc + castore,
  adding inets/ssl to the code path since Mix prunes them.
- `priv/coverage_allowlist.exs` records out-of-scope spec routes with a
  comment per family; reconciled against the real pin (Social SDK
  lobbies/partner-sdk, OIDC, application-by-id, scheduled-event
  exceptions, join requests, thread search, monetization).
- `.gitea/workflows/ci.yml` runs the suite + gate (Actions must be
  enabled on the Gitea remote).
- ratelimit_test.exs gains AC1.10 spot-checks proving the new Phase 5
  route shapes collapse to bounded, id-collapsed keys.
2026-07-05 06:46:09 -03:00

22 lines
722 B
Elixir

defmodule Mix.Tasks.Dexcord.Coverage do
@shortdoc "Verifies declared REST routes cover the pinned Discord OpenAPI spec"
@moduledoc "See Dexcord.Api.Coverage. Exits non-zero when in-scope endpoints are missing."
use Mix.Task
@impl Mix.Task
def run(_argv) do
Mix.Task.run("compile")
case Dexcord.Api.Coverage.check() do
{:ok, stats} ->
Mix.shell().info(
"coverage OK — #{stats.declared} declared, #{stats.spec} in spec, #{stats.allowlisted} allowlisted"
)
{:missing, missing} ->
Mix.shell().error("MISSING #{length(missing)} in-scope endpoint(s):")
Enum.each(missing, &Mix.shell().error(" " <> &1))
exit({:shutdown, 1})
end
end
end