import { describe, expect, it } from 'vitest';
import {
  buildGoaExecutionPayload,
  classifyWorkspaceType,
  parseGoaPayloadJson,
} from './goa-architect';

describe('GOA architect', () => {
  it('classifies fixes in existing projects as brownfield', () => {
    expect(classifyWorkspaceType('Fix the login middleware bug', true)).toBe('BROWNFIELD');
  });

  it('builds a greenfield template and stabilization plan', () => {
    const payload = buildGoaExecutionPayload({
      userPrompt: 'Create a new landing page for Acme',
      workspaceRoot: '/tmp/acme',
      isExistingProject: false,
      templateMatch: { id: 'hello-world-minimal', category: 'landing', confidence: 0.9 },
    });
    expect(payload.workspace_type).toBe('GREENFIELD');
    expect(payload.instructions.map((item) => item.engine)).toEqual([
      'CLI_TEMPLATE',
      'STABILIZATION',
    ]);
  });

  it('rejects prose and malformed planner responses', () => {
    expect(parseGoaPayloadJson('not json')).toBeNull();
    expect(parseGoaPayloadJson('{"workspace_type":"GREENFIELD"}')).toBeNull();
  });
});
