Skip to content

fix: validate simulator notification rules#123

Draft
goanpeca wants to merge 1 commit into
mainfrom
fix/issue-17-notification-rule-validation
Draft

fix: validate simulator notification rules#123
goanpeca wants to merge 1 commit into
mainfrom
fix/issue-17-notification-rule-validation

Conversation

@goanpeca

@goanpeca goanpeca commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary:

  • Add simulator validation for bucket notification rule names, event types, webhook targets, HTTPS URLs, and unsupported fields.
  • Reject invalid rules before storing them in b2_set_bucket_notification_rules.
  • Update notification rule regression coverage and stale targetType docs.

Linked issue:

Tests run:

  • pnpm vitest run src/simulator/validation.test.ts src/simulator/fidelity.test.ts
  • pnpm run typecheck
  • pnpm run lint
  • pnpm run lint:docs

Follow-up notes:

  • None.

Copilot AI review requested due to automatic review settings July 8, 2026 13:08
@goanpeca goanpeca added this to the v0.3.0 milestone Jul 8, 2026
@goanpeca goanpeca added bug Something isn't working area: simulator Area: simulator priority: medium Medium severity labels Jul 8, 2026
@goanpeca goanpeca self-assigned this Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the simulator’s fidelity to the real B2 API by validating b2_set_bucket_notification_rules inputs (per Issue #17) so invalid notification rules are rejected before being stored/used, and updates related regression coverage and docs.

Changes:

  • Added validateNotificationRules() in the simulator validation layer (names, event types, webhook target type, https URL, and unknown-field rejection).
  • Wired the new validator into B2Simulator.setBucketNotificationRules so invalid rules return 400 instead of being stored.
  • Added/updated unit + fidelity tests and corrected targetType documentation to reflect 'webhook'.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/types/notifications.ts Updates notification rule docs/examples to use targetType: 'webhook'.
src/simulator/validation.ts Adds validateNotificationRules() and supporting helpers/constants.
src/simulator/validation.test.ts Adds unit tests for notification rule validation.
src/simulator/index.ts Enforces notification rule validation in setBucketNotificationRules.
src/simulator/fidelity.test.ts Adds simulator fidelity regression tests for invalid notification rules and updates existing expectations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +371 to +386
const eventTypes = ruleValue['eventTypes']
if (!Array.isArray(eventTypes) || eventTypes.length === 0) {
return {
code: 'bad_request',
message: `${rulePath}.eventTypes must be a non-empty array`,
}
}
for (const eventType of eventTypes) {
if (typeof eventType !== 'string' || !KNOWN_NOTIFICATION_EVENT_TYPES.has(eventType)) {
return {
code: 'bad_request',
message: `${rulePath}.eventTypes contains an unknown event type`,
}
}
}

Comment on lines 65 to 68
readonly targetConfiguration: {
/** Target type (e.g., `'url'` for webhook delivery). */
/** Target type (`'webhook'` for webhook delivery). */
readonly targetType: string
/** Webhook URL that receives the event notifications. */
Copilot AI review requested due to automatic review settings July 8, 2026 16:08
@goanpeca goanpeca force-pushed the fix/issue-17-notification-rule-validation branch from 842293f to 8dd03b5 Compare July 8, 2026 16:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: simulator Area: simulator bug Something isn't working priority: medium Medium severity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

simulator: set_bucket_notification_rules performs no validation

2 participants