import { describe, it } from 'node:test';
import { strict as assert } from 'node:assert';
import path from 'node:path';
import { configExplainCommand } from '../../src/commands/config.js';

describe('mx config command', () => {
  it('classifies package declarations as shared direct and managed inputs', async () => {
    const result = await configExplainCommand('packages/chat/matrix.json', {
      cwd: '/repo',
    });

    assert.equal(result.kind, 'package-declaration');
    assert.equal(result.directRunReads, true);
    assert.equal(result.managedHostReads, true);
    assert.equal(result.generated, false);
    assert.equal(result.relativePath, 'packages/chat/matrix.json');
  });

  it('classifies Runtime Host generated state as managed-only generated state', async () => {
    const result = await configExplainCommand('/repo/.matrix/home/runtimes/RUNTIME-1/status.json', {
      cwd: '/repo',
    });

    assert.equal(result.kind, 'runtime-host-generated-state');
    assert.equal(result.directRunReads, false);
    assert.equal(result.managedHostReads, true);
    assert.equal(result.generated, true);
  });

  it('classifies stored API keys as credential state read through resolvers', async () => {
    const result = await configExplainCommand(path.join('/repo', '.matrix/home/credentials/matrix-api-key.json'), {
      cwd: '/repo',
    });

    assert.equal(result.kind, 'credential-link-state');
    assert.equal(result.directRunReads, true);
    assert.equal(result.managedHostReads, true);
    assert.match(result.recommendedAction, /never commit/);
  });

  it('classifies historical deployment paths as deletion candidates', async () => {
    const result = await configExplainCommand('packages/dev-platform-deployment/package.json', {
      cwd: '/repo',
    });

    assert.equal(result.kind, 'deletion-candidate');
    assert.equal(result.directRunReads, false);
    assert.equal(result.managedHostReads, false);
    assert.match(result.recommendedAction, /grep\/test proof/);
  });
});
