|
2 | 2 | * @vitest-environment node |
3 | 3 | */ |
4 | 4 | import { describe, expect, it } from 'vitest' |
| 5 | +import { IncidentioBlock } from '@/blocks/blocks/incidentio' |
5 | 6 | import { customFieldsCreateTool } from '@/tools/incidentio/custom_fields_create' |
6 | 7 | import { escalationsCreateTool } from '@/tools/incidentio/escalations_create' |
7 | 8 | import { escalationsListTool } from '@/tools/incidentio/escalations_list' |
@@ -143,7 +144,7 @@ describe('incident_updates new_incident_status output', () => { |
143 | 144 | 'incident_updates', |
144 | 145 | 'updater', |
145 | 146 | ]) |
146 | | - expect(updaterFields).toEqual(['user']) |
| 147 | + expect(updaterFields.sort()).toEqual(['alert', 'api_key', 'user', 'workflow']) |
147 | 148 | expect( |
148 | 149 | declaredPropertyNames(incidentUpdatesListTool.outputs, [ |
149 | 150 | 'incident_updates', |
@@ -184,11 +185,13 @@ const SPEC_ESCALATION = { |
184 | 185 |
|
185 | 186 | describe('escalation title output', () => { |
186 | 187 | it('declares title and status instead of name', () => { |
187 | | - expect(declaredPropertyNames(escalationsListTool.outputs, ['escalations'])).toEqual([ |
| 188 | + expect(declaredPropertyNames(escalationsListTool.outputs, ['escalations']).sort()).toEqual([ |
| 189 | + 'created_at', |
| 190 | + 'description', |
188 | 191 | 'id', |
189 | | - 'title', |
| 192 | + 'priority', |
190 | 193 | 'status', |
191 | | - 'created_at', |
| 194 | + 'title', |
192 | 195 | 'updated_at', |
193 | 196 | ]) |
194 | 197 | for (const tool of [escalationsShowTool, escalationsCreateTool]) { |
@@ -251,3 +254,58 @@ describe('custom_fields_create field_type description', () => { |
251 | 254 | } |
252 | 255 | }) |
253 | 256 | }) |
| 257 | + |
| 258 | +/** |
| 259 | + * `WorkflowsCreate/UpdateWorkflowPayloadV2.runs_on_incidents` accepts exactly |
| 260 | + * `newly_created` and `newly_created_and_active`. The block previously offered |
| 261 | + * `active` and `all` as well, so a user could pick a value the API rejects with |
| 262 | + * a 422 — the tool-side description alone does not close that path. |
| 263 | + */ |
| 264 | +describe('the block only offers runs_on_incidents values the API accepts', () => { |
| 265 | + const SPEC_ENUM = ['newly_created', 'newly_created_and_active'] |
| 266 | + |
| 267 | + it('offers exactly the spec enum', () => { |
| 268 | + const sub = IncidentioBlock.subBlocks.find((s) => s.id === 'runs_on_incidents') |
| 269 | + expect(sub).toBeDefined() |
| 270 | + const ids = (sub!.options as Array<{ id: string }>).map((o) => o.id) |
| 271 | + expect(ids).toEqual(SPEC_ENUM) |
| 272 | + }) |
| 273 | + |
| 274 | + it('defaults to a value the API accepts', () => { |
| 275 | + const sub = IncidentioBlock.subBlocks.find((s) => s.id === 'runs_on_incidents') |
| 276 | + expect(SPEC_ENUM).toContain((sub as { value: () => string }).value()) |
| 277 | + }) |
| 278 | +}) |
| 279 | + |
| 280 | +/** |
| 281 | + * `updater` is an `ActorV2`, a four-branch union. Declaring only `user` meant an |
| 282 | + * update made by an API key, workflow or alert had no reachable actor fields. |
| 283 | + */ |
| 284 | +describe('updater declares every ActorV2 branch', () => { |
| 285 | + it('covers user, api_key, workflow and alert', () => { |
| 286 | + const updater = ( |
| 287 | + incidentUpdatesListTool.outputs?.incident_updates as { |
| 288 | + items?: { properties?: Record<string, { properties?: Record<string, unknown> }> } |
| 289 | + } |
| 290 | + )?.items?.properties?.updater |
| 291 | + expect(Object.keys(updater?.properties ?? {}).sort()).toEqual([ |
| 292 | + 'alert', |
| 293 | + 'api_key', |
| 294 | + 'user', |
| 295 | + 'workflow', |
| 296 | + ]) |
| 297 | + }) |
| 298 | +}) |
| 299 | + |
| 300 | +/** `description` and `priority` are both in EscalationV2's required set. */ |
| 301 | +describe('escalations declare the fields the spec marks required', () => { |
| 302 | + it.each([ |
| 303 | + ['escalations_create', escalationsCreateTool], |
| 304 | + ['escalations_show', escalationsShowTool], |
| 305 | + ['escalations_list', escalationsListTool], |
| 306 | + ])('%s', (_name, tool) => { |
| 307 | + const declared = JSON.stringify(tool.outputs) |
| 308 | + expect(declared).toContain('description') |
| 309 | + expect(declared).toContain('priority') |
| 310 | + }) |
| 311 | +}) |
0 commit comments