Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.9 KB
Raw Blame
import { TaskRunDetailDTOApi } from '../generated/api.schemas'
import { spaceFeedStatus } from './spaceFeedStatus'

const run = (
    status: string,
    environment: string,
    output: TaskRunDetailDTOApi['output'] = null,
    mode = 'background'
): TaskRunDetailDTOApi => ({ status, environment, output, state: { mode } }) as unknown as TaskRunDetailDTOApi

describe('spaceFeedStatus', () => {
    it.each([
        ['no run', null, 'Draft'],
        ['a cloud run in progress', run('in_progress', 'cloud'), 'In progress'],
        ['an interactive cloud run between turns', run('in_progress', 'cloud', null, 'interactive'), 'Ready'],
        ['a local run in progress', run('in_progress', 'local'), null],
        ['a local run that completed', run('completed', 'local'), 'Ready'],
        [
            'a run with a pull request',
            run('in_progress', 'local', { pr_url: 'https://example.com/pull/1' }),
            'PR ready',
        ],
        [
            'a run with a listed pull request',
            run('completed', 'cloud', { pr_urls: ['https://example.com/pull/2'] }),
            'PR ready',
        ],
        [
            'a failed run with a pull request',
            run('failed', 'cloud', { pr_url: 'https://example.com/pull/3' }),
            'Failed',
        ],
    ])('labels %s', (_, latestRun, label) => {
        expect(spaceFeedStatus(latestRun)?.label ?? null).toEqual(label)
    })

    it.each([
        ['merged', 'Merged', 'completed'],
        ['closed', 'Closed', 'destructive'],
        ['draft', 'Draft PR', 'default'],
        ['unknown', 'PR ready', 'info'],
    ] as const)('labels a run whose pull request is %s', (prState, label, variant) => {
        const latestRun = run('completed', 'cloud', { pr_url: 'https://github.com/org/app/pull/1' })
        expect(spaceFeedStatus(latestRun, prState)).toMatchObject({ label, variant })
    })
})