fix(web): send symbolic comparator values for service alert rules - #883
Conversation
The "Add Alert Rule" dialog on the service monitoring page sent
comparator values gt/gte/lt/lte, but POST
/external-services/{id}/metrics/alert-rules only ever accepted the
symbolic operators >, <, >=, <= (matching the OpenAPI spec, the DB
CHECK constraint, and the default seed rules). Every submission from
that form was rejected with 400 Bad Request.
The text-form values match a different, newer alerts API (OTel
detectors) that this page doesn't call — likely copied from there.
Extract the comparator options into a small shared module so the
values can't drift from the endpoint's contract again, and add a
regression test asserting the options stay within the backend's
accepted set.
Signed-off-by: David Viejo <dviejo@kfs.es>
📓 Changelog previewThis is what your commits will add to the generated ## [Unreleased]
### Fixed
- **web:** Send symbolic comparator values for service alert rules
### Testing
- **web:** Assert exact comparator option set, not a subset |
Greptile SummaryThe PR updates service alert-rule submissions to use the symbolic comparator values required by the external-services API.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| web/src/lib/service-alert-comparator.ts | Defines the four symbolic comparator values and their UI labels in a shared typed constant. |
| web/src/lib/service-alert-comparator.test.ts | Verifies exact comparator membership and rejects duplicate option values. |
| web/src/pages/ServiceMonitoring.tsx | Uses the shared symbolic comparator contract when rendering and submitting alert rules. |
Reviews (2): Last reviewed commit: "test(web): assert exact comparator optio..." | Re-trigger Greptile
| // SPDX-FileCopyrightText: 2024-2026 Temps Contributors | ||
| // SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
|
||
| import { describe, expect, test } from 'bun:test' | ||
| import { SERVICE_ALERT_COMPARATOR_OPTIONS } from './service-alert-comparator' |
There was a problem hiding this comment.
This standalone test file separates the comparator contract tests from service-alert-comparator.ts, contrary to the repository requirement that tests remain in the same file as the code they exercise.
Context Used: CLAUDE.md (source)
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!
There was a problem hiding this comment.
Keeping this as a separate file rather than merging — every other module in web/src/lib/ (password-policy.ts, drop-archive.ts, etc.) follows the same convention: implementation + a colocated but separate *.test.ts. The CLAUDE.md "same file" rule reads as the Rust convention (#[cfg(test)] mod tests inline); there's no precedent anywhere in web/ for TS tests living inside the implementation file itself, so I don't think this is a real deviation.
There was a problem hiding this comment.
You're right — this is a false positive. The repository-wide “same file” guidance reflects the Rust #[cfg(test)] convention, while the established TypeScript convention in web/src/lib/ is a separate colocated *.test.ts file. Keeping service-alert-comparator.test.ts separate is consistent with the surrounding modules, so no change is needed.
Greptile review on #883: the previous assertion only checked that every declared option was in the backend's accepted set, so silently dropping one of the four supported comparators (e.g. "<=") would still pass. Assert set equality instead. Signed-off-by: David Viejo <dviejo@kfs.es>
…valid Info severity main independently fixed the same comparator/severity contract bug (#883, #884) this branch fixes for the service-monitoring alert-rule dialog. Resolve by taking main's shared `service-alert-comparator` module and also dropping the "Info" severity option in ServiceMonitoring.tsx's dialog (mirroring MonitoringCard.tsx) since validate_severity only accepts warning/critical, while keeping this branch's accessible-name additions (id/aria-label on every alert-rule modal control). Signed-off-by: David Viejo <dviejo@kfs.es>
Summary
ServiceMonitoring.tsx) sentcomparatorvaluesgt/gte/lt/lte, butPOST /external-services/{id}/metrics/alert-rulesonly ever accepts the symbolic operators>,<,>=,<=— matching the OpenAPI spec, themonitoring_alert_rulesDB CHECK constraint, and the default seed rules. Every submission from that form was rejected with400 Bad Request: comparator must be one of: >, <, >=, <=.web/src/lib/service-alert-comparator.ts(symbolic values matching the actual endpoint), updatedServiceMonitoring.tsxto use it, and added a regression test (service-alert-comparator.test.ts) asserting the options never drift from the backend's accepted set again.Test plan
bun test src— all 460 existing frontend tests + 2 new ones pass.bunx tsc --noEmit— clean.comparator: "gt"→400.comparator: ">"→201.> greater than,≥ greater or equal,< less than,≤ less or equal), submitted, and got a201response plus an "Alert rule created" success toast, with the new rule appearing in the alert rules table.