Keep the slash command list in one module, and test that `/help` and the registered commands match

Aperta
#154 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
78/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript
Ambito
testing, tooling

Direzione di ricerca

Start by copying scripts/register-commands.mjs and printing JSON.stringify(commands, null, 2) with and without LINK_PREVIEW=1 to snapshot current output. Then extract lines 23-107 into slashCommands(vars, { preview }) in a new scripts/commands.ts, reading vars the way test/config.test.ts (line 9) reads wrangler.jsonc, and compare against helpReply in src/messages.ts (line 377) and runCommand in src/commands.ts (line 28). Write test/commands.test.ts covering parity, descriptions, dispatch and Discord limits, modelled on test/help.test.ts. Done when the diff against the snapshot is empty, deleting a helpReply line fails a test, and npm run typecheck plus npm test pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

help wanted testing

The slash commands are written down in three places that have to agree:

  • scripts/register-commands.mjs (lines 23 to 107) builds what Discord shows: names, descriptions, options and choices
  • helpReply in src/messages.ts (line 377) types the names and descriptions out again
  • runCommand in src/commands.ts (line 28) handles them, and the comment at the top of that file says "keep the two in sync"

They match today, but nothing checks it. The register script builds the list and sends it to Discord in the same file, at the top level, so a test can't get at the list without making the request. A new command or a reworded description can drift apart, and nobody notices until someone reads /help in the server.

What to do

  • Move the list into a function a test can import, for example slashCommands(vars, { preview }) in scripts/commands.ts, built from the same wrangler.jsonc vars. register-commands.mjs then only reads the config, calls it and sends the result. It already imports ./jsonc.ts, so a .ts import works there.
  • Add tests, for example in a new test/commands.test.ts, that check:
    • with LINKING on and off, the registered names and the /help names are the same and in the same order
    • each /help description is the registered description with a period at the end (they all are today)
    • runCommand answers every registered name with something other than "I don't know that command."
    • Discord's limits: names match ^[-_a-z0-9]{1,32}$, command and option descriptions are 1 to 100 characters, and required options come before optional ones

Where to look

  • scripts/register-commands.mjs and scripts/jsonc.ts
  • test/config.test.ts (line 9) reads wrangler.jsonc the same way the script does
  • test/help.test.ts for how /help is checked now

Acceptance criteria

  • npm run register sends the same JSON as before for our wrangler.jsonc
  • The tests above, which fail if a command is missing from /help or a description changes in only one place
  • npm run typecheck and npm test pass

How to test

Before changing anything, make a local copy of the script that prints JSON.stringify(commands, null, 2) instead of sending it (with and without LINK_PREVIEW=1), and save the output. Do the same after the change and diff the two. You don't need a Discord token for this. Then break things on purpose: drop a line from helpReply, or change one description in the new module only, and check that a test fails each time.


Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off develop, and open your PR against develop with Closes #154 in the description.

Lingua principale
TypeScript
Stelle
0
Fork
1
Merge medio
2h 38m
PR unite (30g)
73

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di codercops/discord-bot

Tutte le issue di codercops/discord-bot

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.