/**
 * publishSentinelRunKill drives metrics (N3)
 */

import { describe, it, expect, beforeEach, jest } from '@jest/globals';
import { publishSentinelRunKill } from '../adapters/redis-sentinel-publisher.js';
import { resetMetrics, sentinelKillsTotal } from '../metrics/index.js';

const mockPublish = jest.fn<() => Promise<number>>().mockResolvedValue(1);

jest.mock('../db/redis.js', () => ({
  getRedisClient: jest.fn(() => Promise.resolve({ publish: mockPublish })),
}));

describe('publishSentinelRunKill', () => {
  beforeEach(() => {
    resetMetrics();
    mockPublish.mockClear();
  });

  it('increments sentinelKillsTotal and publishes kill + audit channels', async () => {
    await publishSentinelRunKill('run-9', 'manual_cancellation');

    expect(mockPublish).toHaveBeenCalledTimes(2);

    const metrics = await sentinelKillsTotal.get();
    const manual = metrics.values.find((v) => v.labels.trigger === 'manual');
    expect(manual?.value).toBe(1);
  });
});
