Skip to content

Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.

TypeScript
1.9 KB
Raw Blame
/**
 * Pure gate in front of resolveSender. A spoofed From used to become the
 * workspace member with that address. Internal attribution now requires the
 * gate's aligned verdict and an envelope sender that is the same mailbox.
 */
import assert from 'node:assert/strict'
import { test } from 'node:test'

process.env.CUMORA_RUNTIME_CLIENT = 'http'
process.env.OPENAI_API_KEY ??= 'test-key'

const { inboundSenderAuthenticated } = await import('../api/inbound-email.js')

test('a missing or non-aligned verdict never maps onto an internal author', () => {
  assert.equal(inboundSenderAuthenticated({
    authVerdict: undefined,
    envelopeFrom: '[email protected]',
    headerFrom: 'CEO <[email protected]>',
  }), false)
  assert.equal(inboundSenderAuthenticated({
    authVerdict: 'unaligned',
    envelopeFrom: '[email protected]',
    headerFrom: '[email protected]',
  }), false)
  assert.equal(inboundSenderAuthenticated({
    authVerdict: 'aligned ',
    envelopeFrom: '[email protected]',
    headerFrom: '[email protected]',
  }), false)
  assert.equal(inboundSenderAuthenticated({
    authVerdict: 'aligned',
    envelopeFrom: undefined,
    headerFrom: '[email protected]',
  }), false)
})

test('an aligned verdict maps only when the envelope mailbox is the header From', () => {
  assert.equal(inboundSenderAuthenticated({
    authVerdict: 'aligned',
    envelopeFrom: '[email protected]',
    headerFrom: 'CEO <[email protected]>',
  }), true)
  assert.equal(inboundSenderAuthenticated({
    authVerdict: 'aligned',
    envelopeFrom: 'CEO <[email protected]>',
    headerFrom: '[email protected]',
  }), true)
  assert.equal(inboundSenderAuthenticated({
    authVerdict: 'aligned',
    envelopeFrom: '[email protected]',
    headerFrom: 'CEO <[email protected]>',
  }), false)
  assert.equal(inboundSenderAuthenticated({
    authVerdict: 'aligned',
    envelopeFrom: 'not-an-address',
    headerFrom: '[email protected]',
  }), false)
})