|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { TriggerDevBlock } from '@/blocks/blocks/trigger_dev' |
| 6 | +import { triggerDevGetEnvVarTool } from '@/tools/trigger_dev/get_env_var' |
| 7 | +import { triggerDevListEnvVarsTool } from '@/tools/trigger_dev/list_env_vars' |
| 8 | + |
| 9 | +/** Builds a JSON Response the way the executor hands one to transformResponse. */ |
| 10 | +function jsonResponse(body: unknown): Response { |
| 11 | + return { ok: true, status: 200, json: async () => body } as Response |
| 12 | +} |
| 13 | + |
| 14 | +describe('trigger.dev env var secret disambiguation', () => { |
| 15 | + it('surfaces isSecret from the retrieve endpoint, which returns it top-level', async () => { |
| 16 | + const result = await triggerDevGetEnvVarTool.transformResponse!( |
| 17 | + jsonResponse({ name: 'SLACK_API_KEY', value: 'tr_redacted', isSecret: true }), |
| 18 | + {} as never |
| 19 | + ) |
| 20 | + |
| 21 | + expect(result.output).toEqual({ |
| 22 | + name: 'SLACK_API_KEY', |
| 23 | + value: 'tr_redacted', |
| 24 | + isSecret: true, |
| 25 | + }) |
| 26 | + }) |
| 27 | + |
| 28 | + it('surfaces isSecret false for a non-secret variable', async () => { |
| 29 | + const result = await triggerDevGetEnvVarTool.transformResponse!( |
| 30 | + jsonResponse({ name: 'LOG_LEVEL', value: 'debug', isSecret: false }), |
| 31 | + {} as never |
| 32 | + ) |
| 33 | + |
| 34 | + expect(result.output.isSecret).toBe(false) |
| 35 | + }) |
| 36 | + |
| 37 | + it('surfaces isSecret per item from the list endpoint, which returns an array', async () => { |
| 38 | + const result = await triggerDevListEnvVarsTool.transformResponse!( |
| 39 | + jsonResponse([ |
| 40 | + { name: 'SLACK_API_KEY', value: 'redacted', isSecret: true }, |
| 41 | + { name: 'LOG_LEVEL', value: 'debug', isSecret: false }, |
| 42 | + ]), |
| 43 | + {} as never |
| 44 | + ) |
| 45 | + |
| 46 | + expect(result.output.variables).toEqual([ |
| 47 | + { name: 'SLACK_API_KEY', value: 'redacted', isSecret: true }, |
| 48 | + { name: 'LOG_LEVEL', value: 'debug', isSecret: false }, |
| 49 | + ]) |
| 50 | + }) |
| 51 | + |
| 52 | + it('declares isSecret on both tools so it is selectable downstream', () => { |
| 53 | + expect(triggerDevGetEnvVarTool.outputs).toHaveProperty('isSecret') |
| 54 | + |
| 55 | + const variables = triggerDevListEnvVarsTool.outputs!.variables as { |
| 56 | + items: { properties: Record<string, unknown> } |
| 57 | + } |
| 58 | + expect(variables.items.properties).toHaveProperty('isSecret') |
| 59 | + }) |
| 60 | + |
| 61 | + it('treats a missing isSecret as secret, never as a real plaintext value', async () => { |
| 62 | + const result = await triggerDevGetEnvVarTool.transformResponse!( |
| 63 | + jsonResponse({ name: 'MYSTERY', value: 'something' }), |
| 64 | + {} as never |
| 65 | + ) |
| 66 | + |
| 67 | + expect(result.output.isSecret).toBe(true) |
| 68 | + }) |
| 69 | +}) |
| 70 | + |
| 71 | +describe('trigger.dev block env var outputs', () => { |
| 72 | + it('declares isSecret alongside its sibling value output', () => { |
| 73 | + expect(TriggerDevBlock.outputs).toHaveProperty('value') |
| 74 | + expect(TriggerDevBlock.outputs).toHaveProperty('isSecret') |
| 75 | + }) |
| 76 | +}) |
0 commit comments