import test from 'node:test';
import assert from 'node:assert/strict';

import { resolveRecommendedAssignee } from './ai-assignee-recommendation';
import type { VersionMember } from './derive';

const members: VersionMember[] = [
  { name: 'Alice', role: 'frontend' },
  { name: 'Bob', role: 'testing' },
];

test('resolves an AI recommended assignee only when the name is a current version member', () => {
  const recommendation = resolveRecommendedAssignee(
    {
      recommendedAssigneeName: 'Alice',
      recommendedAssigneeReason: 'Frontend implementation matches this member role.',
    },
    members,
  );

  assert.deepEqual(recommendation, {
    name: 'Alice',
    role: 'frontend',
    reason: 'Frontend implementation matches this member role.',
  });
});

test('ignores hallucinated recommended assignee names', () => {
  const recommendation = resolveRecommendedAssignee(
    {
      recommendedAssigneeName: 'Carol',
      recommendedAssigneeReason: 'Model invented a person.',
    },
    members,
  );

  assert.equal(recommendation, undefined);
});

test('does not resolve case-mismatched member names', () => {
  const recommendation = resolveRecommendedAssignee(
    {
      recommendedAssigneeName: 'alice',
      recommendedAssigneeReason: 'Lowercase is not an exact member name.',
    },
    members,
  );

  assert.equal(recommendation, undefined);
});
