<?php

use App\AI\Agents\Agent;

function makeAgent(): Agent
{
    // Agent is abstract, so reach the default persona through a bare subclass.
    return new class extends Agent {};
}

// Keep the suite independent of whether the project has a real Larry.md.
beforeEach(function () {
    if (file_exists(base_path('Larry.md'))) {
        rename(base_path('Larry.md'), base_path('Larry.md.bak'));
    }
});

afterEach(function () {
    if (file_exists(base_path('Larry.md'))) {
        unlink(base_path('Larry.md'));
    }

    if (file_exists(base_path('Larry.md.bak'))) {
        rename(base_path('Larry.md.bak'), base_path('Larry.md'));
    }
});

it('prepares the agent instructions', function () {
    expect(makeAgent()->instructions())->toBe('You are a helpful AI assistant.');
});

it('optionally loads Larry.md guidelines', function () {
    $guidelines = <<<'MD'
        # Coding Requirements

        - Favor Pest over PHPUnit.
        - Never use PHPDoc blocks.
        MD;

    file_put_contents(base_path('Larry.md'), $guidelines);

    expect(makeAgent()->instructions())
        ->toContain('You are a helpful AI assistant.')
        ->toContain('# Project Guidelines')
        ->toContain('Favor Pest over PHPUnit.');
});
