/**
 * A5 regression guard: sensitive tools are hidden unless explicitly opted in.
 *
 * These tests lock in the core security property at the resolver level.
 * If resolveWorkspaceTools ever starts leaking Bash/BrowseWeb/SshExec/SshUpload
 * under the default policy, this file will catch it immediately.
 */
import { describe, it, expect } from 'vitest';
import { resolveWorkspaceTools } from './workspace-tool-policy.js';

describe('sensitive tools hidden unless opted in', () => {
  it('default policy {} hides Bash, BrowseWeb, SshExec, SshUpload', async () => {
    const { allowedTools } = await resolveWorkspaceTools({});
    for (const t of ['Bash', 'BrowseWeb', 'SshExec', 'SshUpload']) {
      expect(allowedTools).not.toContain(t);
    }
  });

  it('enabling Bash individually surfaces it without unlocking other sensitives', async () => {
    const { allowedTools } = await resolveWorkspaceTools({ enabledSensitive: ['Bash'] });
    expect(allowedTools).toContain('Bash');
    // browser and ssh categories remain locked
    expect(allowedTools).not.toContain('BrowseWeb');
    expect(allowedTools).not.toContain('SshExec');
    expect(allowedTools).not.toContain('SshUpload');
  });

  it('enabling browser category surfaces BrowseWeb but not Bash or SSH', async () => {
    const { allowedTools } = await resolveWorkspaceTools({ enabledSensitive: ['browser'] });
    expect(allowedTools).toContain('BrowseWeb');
    expect(allowedTools).not.toContain('Bash');
    expect(allowedTools).not.toContain('SshExec');
    expect(allowedTools).not.toContain('SshUpload');
  });

  it('enabling ssh category surfaces SshExec and SshUpload but not Bash or BrowseWeb', async () => {
    const { allowedTools } = await resolveWorkspaceTools({ enabledSensitive: ['ssh'] });
    expect(allowedTools).toContain('SshExec');
    expect(allowedTools).toContain('SshUpload');
    expect(allowedTools).not.toContain('Bash');
    expect(allowedTools).not.toContain('BrowseWeb');
  });

  it('META tools (ReadToolDoc, ReadSkill) are always included under default policy', async () => {
    const { allowedTools } = await resolveWorkspaceTools({});
    expect(allowedTools).toContain('ReadToolDoc');
    expect(allowedTools).toContain('ReadSkill');
  });
});
