Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

4.2 KB
Raw Blame
import { describe, expect, it } from 'vitest';
import { managedTelemetryNotice } from './managed-telemetry-notice';

describe('managedTelemetryNotice', () => {
  it('says nothing while the stack is down', () => {
    expect(
      managedTelemetryNotice({
        running: false,
        deployed: { known: true, enabled: true, endpointCurrent: true },
        consent: false,
        sharedWithOthers: false,
      })
    ).toEqual({ kind: 'in-step' });
  });

  it('says nothing when nothing has been observed', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: null,
        consent: true,
        sharedWithOthers: false,
      })
    ).toEqual({
      kind: 'in-step',
    });
  });

  it('says nothing when the server agrees with the user', () => {
    for (const consent of [true, false]) {
      expect(
        managedTelemetryNotice({
          running: true,
          deployed: { known: true, enabled: consent, endpointCurrent: true },
          consent,
          sharedWithOthers: false,
        })
      ).toEqual({ kind: 'in-step' });
    }
  });

  it('reports a server that has not picked up an opt-in', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: true, enabled: false, endpointCurrent: true },
        consent: true,
        sharedWithOthers: false,
      })
    ).toEqual({ kind: 'stale', consent: true });
  });

  // The direction that matters most: a server still reporting after the user
  // said no must not be reported as merely "out of date".
  it('reports a server still sharing after the user opted out', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: true, enabled: true, endpointCurrent: true },
        consent: false,
        sharedWithOthers: false,
      })
    ).toEqual({ kind: 'stale', consent: false });
  });

  it('reports an unreadable server as unknown rather than as agreeing', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: false, reason: 'ssh timed out' },
        consent: true,
        sharedWithOthers: false,
      })
    ).toEqual({ kind: 'unknown', reason: 'ssh timed out' });
  });

  it('does not offer to turn sharing on over others using the server', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: true, enabled: false, endpointCurrent: true },
        consent: true,
        sharedWithOthers: true,
      })
    ).toEqual({ kind: 'in-step' });
  });

  it('still offers to apply a no on a server others use', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: true, enabled: true, endpointCurrent: true },
        consent: false,
        sharedWithOthers: true,
      })
    ).toEqual({ kind: 'stale', consent: false });
  });

  it('reports a server sharing to an address this build no longer names', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: true, enabled: true, endpointCurrent: false },
        consent: true,
        sharedWithOthers: false,
      })
    ).toEqual({ kind: 'stale-endpoint' });
  });

  it('applies the relay on a shared server too, since a restart keeps a sharing server sharing', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: true, enabled: true, endpointCurrent: false },
        consent: true,
        sharedWithOthers: true,
      })
    ).toEqual({ kind: 'stale-endpoint' });
  });

  it('does not chase the address of a server that is not sharing', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: true, enabled: false, endpointCurrent: false },
        consent: false,
        sharedWithOthers: false,
      })
    ).toEqual({ kind: 'in-step' });
  });

  it('puts an opt-out first when a server is still sharing to an old address', () => {
    expect(
      managedTelemetryNotice({
        running: true,
        deployed: { known: true, enabled: true, endpointCurrent: false },
        consent: false,
        sharedWithOthers: false,
      })
    ).toEqual({ kind: 'stale', consent: false });
  });
});