Validate Discord app distribution config - #611
Conversation
Greptile SummaryThis PR adds runtime input validation to the Discord chat target:
Confidence Score: 4/5Safe to merge — the new validations are additive guards with no changes to the happy-path logic, and all existing tests should continue to pass. The validation logic is straightforward and correct. The only live concerns are that error messages drop the rejected value (harder to debug in production) and the test suite misses the build path for an invalid distribution. Neither affects current runtime correctness of the validated paths. Both files are worth a second look: index.ts for the double-validation in manifestFor/inviteUrl and the error message detail, index.test.ts for the missing build-path distribution test. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[build / ship called] --> B[manifestFor]
B --> C[normalizeCommands]
C --> D{requireDistribution}
D -- invalid --> E[throw: distribution must be one of]
D -- valid --> F[requireApplicationId]
F -- missing/empty --> G[throw: requires applicationId]
F -- non-numeric --> H[throw: must be numeric snowflake]
F -- valid --> I[scopesFor]
I -- invalid scope found --> J[throw: scope must be one of]
I -- valid / defaults used --> K[inviteUrl]
K --> L[requireApplicationId again]
K --> M[scopesFor again]
L --> N[build manifest object]
M --> N
N --> O{ctx.dryRun?}
O -- yes --> P[return dry-run meta]
O -- no --> Q[lookup secret token]
Q --> R[callDiscord PATCH / PUT]
Reviews (1): Last reviewed commit: "Validate Discord app distribution config" | Re-trigger Greptile |
| const invalid = scopes.find((scope) => !SCOPES.includes(scope as typeof SCOPES[number])); | ||
| if (invalid) throw new Error(`chat-discord scope must be one of: ${SCOPES.join(', ')}`); |
There was a problem hiding this comment.
The error omits the invalid value, making it harder to debug when a bad scope is passed programmatically. Including the rejected value in the message gives the caller something actionable to act on immediately.
| const invalid = scopes.find((scope) => !SCOPES.includes(scope as typeof SCOPES[number])); | |
| if (invalid) throw new Error(`chat-discord scope must be one of: ${SCOPES.join(', ')}`); | |
| const invalid = scopes.find((scope) => !SCOPES.includes(scope as typeof SCOPES[number])); | |
| if (invalid) throw new Error(`chat-discord scope "${invalid}" is not supported; must be one of: ${SCOPES.join(', ')}`); |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| if (!DISTRIBUTIONS.includes(distribution as Config['distribution'])) { | ||
| throw new Error(`chat-discord distribution must be one of: ${DISTRIBUTIONS.join(', ')}`); | ||
| } |
There was a problem hiding this comment.
Same pattern: the error message for an invalid
distribution doesn't include the rejected value. When config is assembled dynamically (e.g. from a deserialized config file) the error gives no hint of what value was actually received.
| if (!DISTRIBUTIONS.includes(distribution as Config['distribution'])) { | |
| throw new Error(`chat-discord distribution must be one of: ${DISTRIBUTIONS.join(', ')}`); | |
| } | |
| if (!DISTRIBUTIONS.includes(distribution as Config['distribution'])) { | |
| throw new Error(`chat-discord distribution "${distribution}" is not supported; must be one of: ${DISTRIBUTIONS.join(', ')}`); | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| it('rejects unsupported distributions in dry-run shipping', async () => { | ||
| await expect(adapter.ship(fakeShipContext({ | ||
| version: '1.2.3', | ||
| dryRun: true, | ||
| }) as any, { | ||
| applicationId: '123456', | ||
| distribution: 'server-listing', | ||
| } as any)).rejects.toThrow('distribution must be one of'); | ||
| }); |
There was a problem hiding this comment.
Missing
build-path coverage for invalid distribution
The new distribution test only exercises adapter.ship. Both build and ship reach manifestFor → requireDistribution, so the validation fires on both paths. Adding a parallel test for adapter.build with an invalid distribution would close the gap and guard against a future refactor that separates the two paths.
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
8 similar comments
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
Fixes #610.
Changes:
Validation: