import { describe, expect, it } from 'vitest';

import detailSource from './SkillDetail.vue?raw';

describe('skill studio contract', () => {
  it('uses one unified file workbench and one publish modal', () => {
    expect(detailSource).not.toContain('activeTab');
    expect(detailSource).not.toContain('instructionsOnly');
    expect(detailSource).not.toContain('skill-detail-page__tabs');
    expect(detailSource.match(/<SkillResourceWorkbench/g)).toHaveLength(1);
    expect(detailSource).toContain('title="发布技能"');
    expect(detailSource).toContain('发布说明');
    expect(detailSource).toContain('maxlength="500"');
    expect(detailSource).toContain(
      'submitSkillPublishApproval(skillId.value, reason)',
    );
    expect(detailSource).not.toContain('能力绑定');
    expect(detailSource).not.toContain('SkillCapabilityPanel');
    expect(detailSource).toContain('command="tools"');
    expect(detailSource).toContain('<SkillToolBindingDialog');
    expect(detailSource).toContain('@saved="handleToolBindingsSaved"');
  });

  it('keeps the detail shell compact and uses the neutral content surface', () => {
    expect(detailSource).toContain('min-height: 48px');
    expect(detailSource).toContain('background: hsl(var(--background))');
    expect(detailSource).not.toContain(
      'background: hsl(var(--surface-canvas))',
    );
  });

  it('saves dirty files and validates the package before opening publish', () => {
    const saveAt = detailSource.indexOf('await saveFiles(false)');
    const validateAt = detailSource.indexOf(
      'resourceWorkbenchRef.value?.validateAll()',
    );
    const dialogAt = detailSource.indexOf('publishDialogOpen.value = true');

    expect(saveAt).toBeGreaterThan(0);
    expect(validateAt).toBeGreaterThan(saveAt);
    expect(dialogAt).toBeGreaterThan(validateAt);
  });
});
