import { describe, expect, it } from 'vitest';
import { hasAnyCoderPlan, hasHyperTierPlan } from './plan-gate';
import { buildCdCommand, resolvePaneCwd } from './shell-utils';
import type { VigthoriaAuthStatus } from '@/types/workbench';

const auth = (plan: string): VigthoriaAuthStatus => ({
  cliInstalled: true,
  hasToken: true,
  authenticated: true,
  isAdmin: false,
  isMasterAdmin: false,
  apiUrl: 'https://coder.vigthoria.io',
  modelsApiUrl: 'https://api.vigthoria.io',
  message: 'ok',
  plan,
});

describe('plan and shell policy', () => {
  it('distinguishes basic Coder and Hyper-Loop plans', () => {
    expect(hasAnyCoderPlan(auth('developer'))).toBe(true);
    expect(hasHyperTierPlan(auth('developer'))).toBe(false);
    expect(hasHyperTierPlan(auth('enterprise'))).toBe(true);
  });

  it('quotes POSIX paths', () => {
    expect(buildCdCommand('/tmp/a b', '/bin/bash', 'linux')).toBe('cd "/tmp/a b"');
  });

  it('uses workspace root for missing pane cwd', () => {
    expect(resolvePaneCwd('', '/tmp/project')).toBe('/tmp/project');
  });
});
