import test from 'node:test';
import assert from 'node:assert/strict';
import { resolveLayeredConflicts } from '../src/user-style/conflict-resolver.js';
function cand(partial) {
    return { score: 1, source: 'lexical', matchReason: '', ...partial };
}
test('project convention overrides team convention', () => {
    const project = cand({ knowledgeId: 'p1', title: 'Use spaces for indentation.', source: 'lexical' });
    const team = cand({ knowledgeId: 't1', title: 'Never use spaces for indentation.', source: 'lexical', metadata: { conventionScope: 'team' } });
    const r = resolveLayeredConflicts([project, team]);
    assert.deepEqual(r.suppressedCandidateIds, ['t1']);
    assert.match(r.instructionLines[0], /Project convention/);
});
test('team convention overrides personal coding_preference', () => {
    const team = cand({ knowledgeId: 't1', title: 'Use named exports.', source: 'lexical', metadata: { conventionScope: 'team' } });
    const personal = cand({ knowledgeId: 'u1', title: 'Never use named exports.', source: 'userStyle', metadata: { userStyleAtomId: 'a1', userStylePriority: 'coding_preference' } });
    const r = resolveLayeredConflicts([team, personal]);
    assert.deepEqual(r.suppressedCandidateIds, ['u1']);
});
test('personal_workflow is inviolable and beats a project convention', () => {
    const project = cand({ knowledgeId: 'p1', title: 'Always add a co-author trailer.', source: 'lexical' });
    const personal = cand({ knowledgeId: 'u1', title: 'Never add a co-author trailer.', source: 'userStyle', metadata: { userStyleAtomId: 'a1', userStylePriority: 'personal_workflow' } });
    const r = resolveLayeredConflicts([project, personal]);
    assert.deepEqual(r.suppressedCandidateIds, ['p1']);
    assert.match(r.instructionLines[0], /personal workflow/i);
});
test('non-conflicting candidates pass through untouched', () => {
    const a = cand({ knowledgeId: 'p1', title: 'Use Postgres for storage.', source: 'lexical' });
    const b = cand({ knowledgeId: 't1', title: 'Prefer pnpm over npm.', source: 'lexical', metadata: { conventionScope: 'team' } });
    const r = resolveLayeredConflicts([a, b]);
    assert.deepEqual(r.suppressedCandidateIds, []);
});
test('two conflicting personal_workflow atoms both survive (neither suppressed)', () => {
    const a = cand({ knowledgeId: 'u1', title: 'Always squash commits.', source: 'userStyle', metadata: { userStyleAtomId: 'a1', userStylePriority: 'personal_workflow' } });
    const b = cand({ knowledgeId: 'u2', title: 'Never squash commits.', source: 'userStyle', metadata: { userStyleAtomId: 'a2', userStylePriority: 'personal_workflow' } });
    const r = resolveLayeredConflicts([a, b]);
    assert.deepEqual(r.suppressedCandidateIds, []);
});
