"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const strict_1 = __importDefault(require("node:assert/strict"));
const accepted_1 = require("../commands/accepted");
(0, node_test_1.describe)('buildAcceptedMergeComment', () => {
    (0, node_test_1.it)('includes comment prefix and branch name', () => {
        const config = { commentPrefix: '[aidev]' };
        const text = (0, accepted_1.buildAcceptedMergeComment)(config, 'abc123/fix-bug');
        strict_1.default.equal(text, '[aidev] Merging the accepted pull request for branch `abc123/fix-bug`.');
    });
    (0, node_test_1.it)('respects custom comment prefix', () => {
        const config = { commentPrefix: '[bot]' };
        const text = (0, accepted_1.buildAcceptedMergeComment)(config, 'x/y');
        strict_1.default.ok(text.startsWith('[bot] '));
        strict_1.default.ok(text.includes('`x/y`'));
    });
});
(0, node_test_1.describe)('buildAcceptedConflictComment', () => {
    (0, node_test_1.it)('embeds the conflict marker so duplicates can be detected', () => {
        const config = { commentPrefix: '[aidev]' };
        const text = (0, accepted_1.buildAcceptedConflictComment)(config, 'abc/fix', 'main');
        strict_1.default.ok(text.startsWith('[aidev] '));
        strict_1.default.ok(text.includes('`abc/fix`'));
        strict_1.default.ok(text.includes('`main`'));
        strict_1.default.ok(text.includes(accepted_1.ACCEPTED_CONFLICT_MARKER));
    });
});
(0, node_test_1.describe)('buildAcceptedMergeFailureComment', () => {
    const config = { commentPrefix: '[aidev]' };
    (0, node_test_1.it)('includes the prefix, branch name, and the raw gh reason', () => {
        const text = (0, accepted_1.buildAcceptedMergeFailureComment)(config, 'abc/fix-bug', 'Pull request is not mergeable: required status checks failed.');
        strict_1.default.ok(text.startsWith('[aidev] '));
        strict_1.default.ok(text.includes('`abc/fix-bug`'));
        strict_1.default.ok(text.includes('Pull request is not mergeable: required status checks failed.'));
    });
    (0, node_test_1.it)('falls back to a placeholder when the reason is empty', () => {
        const text = (0, accepted_1.buildAcceptedMergeFailureComment)(config, 'b/x', '   ');
        strict_1.default.ok(text.includes('no error message reported by gh'));
    });
    (0, node_test_1.it)('preserves multi-line reasons inside a fenced code block', () => {
        const reason = 'line one\nline two';
        const text = (0, accepted_1.buildAcceptedMergeFailureComment)(config, 'b/x', reason);
        strict_1.default.ok(text.includes('```\nline one\nline two\n```'));
    });
});
function makeComment(text) {
    return { id: 'c', text, author: 'a', authorId: 'a', date: 0 };
}
(0, node_test_1.describe)('hasAlreadyNotifiedConflict', () => {
    const prefix = '[aidev]';
    (0, node_test_1.it)('returns true when a prior aidev-prefixed conflict notice exists', () => {
        const config = { commentPrefix: prefix };
        const notice = (0, accepted_1.buildAcceptedConflictComment)(config, 'b/x', 'main');
        strict_1.default.equal((0, accepted_1.hasAlreadyNotifiedConflict)([makeComment(notice)], prefix), true);
    });
    (0, node_test_1.it)('returns false when no prior notice exists', () => {
        const comments = [
            makeComment(`${prefix} Merging the accepted pull request for branch \`b/x\`.`),
            makeComment('looks good'),
        ];
        strict_1.default.equal((0, accepted_1.hasAlreadyNotifiedConflict)(comments, prefix), false);
    });
    (0, node_test_1.it)('ignores notices that lack the comment prefix (so user-written text containing the marker does not block aidev)', () => {
        const text = `random user note: ${accepted_1.ACCEPTED_CONFLICT_MARKER}`;
        strict_1.default.equal((0, accepted_1.hasAlreadyNotifiedConflict)([makeComment(text)], prefix), false);
    });
    (0, node_test_1.it)('returns false on empty comments', () => {
        strict_1.default.equal((0, accepted_1.hasAlreadyNotifiedConflict)([], prefix), false);
    });
});
function stubProvider(overrides = {}) {
    const noop = async () => { throw new Error('not implemented'); };
    return {
        fetchTasks: noop,
        fetchTasksByStatus: noop,
        postComment: noop,
        getComments: noop,
        updateStatus: noop,
        createTask: noop,
        ...overrides,
    };
}
(0, node_test_1.describe)('resolveDoneStatus', () => {
    (0, node_test_1.it)('returns the configured doneStatus when set', async () => {
        const config = { doneStatus: 'Released' };
        const provider = stubProvider({
            fetchAvailableStatuses: async () => ['done', 'open'],
        });
        const result = await (0, accepted_1.resolveDoneStatus)(config, provider);
        strict_1.default.equal(result, 'Released');
    });
    (0, node_test_1.it)('detects "done" from available board statuses', async () => {
        const config = { doneStatus: '' };
        const provider = stubProvider({
            fetchAvailableStatuses: async () => ['Open', 'In Review', 'Done'],
        });
        const result = await (0, accepted_1.resolveDoneStatus)(config, provider);
        strict_1.default.equal(result, 'Done');
    });
    (0, node_test_1.it)('matches case-insensitively and preserves the board casing', async () => {
        const config = { doneStatus: '' };
        const provider = stubProvider({
            fetchAvailableStatuses: async () => ['Open', 'CLOSED'],
        });
        const result = await (0, accepted_1.resolveDoneStatus)(config, provider);
        strict_1.default.equal(result, 'CLOSED');
    });
    (0, node_test_1.it)('prefers "done" over later candidates when multiple match', async () => {
        const config = { doneStatus: '' };
        const provider = stubProvider({
            fetchAvailableStatuses: async () => ['prod', 'finish', 'done', 'closed'],
        });
        const result = await (0, accepted_1.resolveDoneStatus)(config, provider);
        strict_1.default.equal(result, 'done');
    });
    (0, node_test_1.it)('falls back through the candidate order (closed, finish, success, prod)', async () => {
        const config = { doneStatus: '' };
        const provider = stubProvider({
            fetchAvailableStatuses: async () => ['Backlog', 'Success', 'Prod'],
        });
        const result = await (0, accepted_1.resolveDoneStatus)(config, provider);
        strict_1.default.equal(result, 'Success');
    });
    (0, node_test_1.it)('returns null when no candidate matches', async () => {
        const config = { doneStatus: '' };
        const provider = stubProvider({
            fetchAvailableStatuses: async () => ['Open', 'In Review', 'Backlog'],
        });
        const result = await (0, accepted_1.resolveDoneStatus)(config, provider);
        strict_1.default.equal(result, null);
    });
    (0, node_test_1.it)('returns null when the provider does not implement fetchAvailableStatuses', async () => {
        const config = { doneStatus: '' };
        const provider = stubProvider();
        const result = await (0, accepted_1.resolveDoneStatus)(config, provider);
        strict_1.default.equal(result, null);
    });
    (0, node_test_1.it)('returns null when fetchAvailableStatuses throws', async () => {
        const config = { doneStatus: '' };
        const provider = stubProvider({
            fetchAvailableStatuses: async () => { throw new Error('boom'); },
        });
        const result = await (0, accepted_1.resolveDoneStatus)(config, provider);
        strict_1.default.equal(result, null);
    });
});
//# sourceMappingURL=accepted.test.js.map