|
8 | 8 | remapConditionIdsInSubBlocks, |
9 | 9 | remapWorkflowReferencesInSubBlocks, |
10 | 10 | type SubBlockRecord, |
| 11 | + sanitizeSubBlocksForDuplicate, |
11 | 12 | } from '@/lib/workflows/persistence/remap-internal-ids' |
12 | 13 |
|
13 | 14 | describe('remapWorkflowReferencesInSubBlocks', () => { |
@@ -463,3 +464,78 @@ describe('coerceObjectArray', () => { |
463 | 464 | expect(coerceObjectArray(42)).toEqual({ array: null, wasString: false }) |
464 | 465 | }) |
465 | 466 | }) |
| 467 | + |
| 468 | +describe('sanitizeSubBlocksForDuplicate', () => { |
| 469 | + /** |
| 470 | + * Regression: the strip was keyed on subblock id alone, so duplicating or forking a workflow |
| 471 | + * blanked Discord/Attio/Vercel's REQUIRED user-entered `webhookId` while leaving the |
| 472 | + * `webhookToken` it pairs with — a silently half-configured copy. |
| 473 | + */ |
| 474 | + it('keeps a user-entered webhookId on a block that is not acting as a trigger', () => { |
| 475 | + const discord: SubBlockRecord = { |
| 476 | + operation: { type: 'dropdown', value: 'discord_execute_webhook' }, |
| 477 | + webhookId: { type: 'short-input', value: '1234567890' }, |
| 478 | + webhookToken: { type: 'short-input', value: 'tok_abc' }, |
| 479 | + content: { type: 'long-input', value: 'hello' }, |
| 480 | + } |
| 481 | + |
| 482 | + const out = sanitizeSubBlocksForDuplicate(discord, false) |
| 483 | + |
| 484 | + expect(out.webhookId).toEqual({ type: 'short-input', value: '1234567890' }) |
| 485 | + expect(out.webhookToken).toEqual({ type: 'short-input', value: 'tok_abc' }) |
| 486 | + expect(out.content).toBeDefined() |
| 487 | + expect(out.operation).toBeDefined() |
| 488 | + }) |
| 489 | + |
| 490 | + it('keeps prefixed keys on a block that is not acting as a trigger', () => { |
| 491 | + const out = sanitizeSubBlocksForDuplicate( |
| 492 | + { |
| 493 | + webhookId_custom: { type: 'short-input', value: 'x' }, |
| 494 | + triggerConfig: { type: 'short-input', value: { labelIds: ['a'] } }, |
| 495 | + }, |
| 496 | + false |
| 497 | + ) |
| 498 | + |
| 499 | + expect(out.webhookId_custom).toBeDefined() |
| 500 | + expect(out.triggerConfig).toBeDefined() |
| 501 | + }) |
| 502 | + |
| 503 | + it('still strips webhook runtime identity on a real trigger block', () => { |
| 504 | + const out = sanitizeSubBlocksForDuplicate( |
| 505 | + { |
| 506 | + webhookId: { type: 'short-input', value: 'wh_original' }, |
| 507 | + triggerPath: { type: 'short-input', value: 'deployed-path' }, |
| 508 | + triggerConfig: { type: 'short-input', value: { labelIds: ['a'] } }, |
| 509 | + triggerId: { type: 'short-input', value: 'generic_webhook' }, |
| 510 | + requireAuth: { type: 'switch', value: true }, |
| 511 | + }, |
| 512 | + true |
| 513 | + ) |
| 514 | + |
| 515 | + expect(out.webhookId).toBeUndefined() |
| 516 | + expect(out.triggerPath).toBeUndefined() |
| 517 | + expect(out.triggerConfig).toBeUndefined() |
| 518 | + expect(out.triggerId).toBeUndefined() |
| 519 | + expect(out.requireAuth).toBeDefined() |
| 520 | + }) |
| 521 | + |
| 522 | + it('strips display-only system subblocks regardless of trigger status', () => { |
| 523 | + for (const isTrigger of [true, false]) { |
| 524 | + const out = sanitizeSubBlocksForDuplicate( |
| 525 | + { |
| 526 | + webhookUrlDisplay: { type: 'short-input', value: 'https://x' }, |
| 527 | + samplePayload: { type: 'code', value: '{}' }, |
| 528 | + scheduleInfo: { type: 'schedule-info', value: null }, |
| 529 | + triggerCredentials: { type: 'oauth-input', value: 'cred-1' }, |
| 530 | + }, |
| 531 | + isTrigger |
| 532 | + ) |
| 533 | + |
| 534 | + expect(out.webhookUrlDisplay).toBeUndefined() |
| 535 | + expect(out.samplePayload).toBeUndefined() |
| 536 | + expect(out.scheduleInfo).toBeUndefined() |
| 537 | + // triggerCredentials is deliberately preserved so a copy keeps its OAuth connection. |
| 538 | + expect(out.triggerCredentials).toBeDefined() |
| 539 | + } |
| 540 | + }) |
| 541 | +}) |
0 commit comments