import { SkillSecretService } from '../src/modules/netaclaw/service/skill_secret.js';

describe('SkillSecretService storage format', () => {
  const originalSkillSecretKey = process.env.SKILL_SECRET_KEY;
  const originalAppSecret = process.env.APP_SECRET;

  afterEach(() => {
    if (originalSkillSecretKey === undefined) delete process.env.SKILL_SECRET_KEY;
    else process.env.SKILL_SECRET_KEY = originalSkillSecretKey;

    if (originalAppSecret === undefined) delete process.env.APP_SECRET;
    else process.env.APP_SECRET = originalAppSecret;
  });

  it('stores and reads skill secrets without requiring SKILL_SECRET_KEY or APP_SECRET', () => {
    delete process.env.SKILL_SECRET_KEY;
    delete process.env.APP_SECRET;

    const service = new SkillSecretService();
    const stored = service.encrypt({
      ARK_API_KEY: 'ark-key',
      DAMAGE_DETECT_MODEL: 'doubao-seed-2-0-pro-260215',
    });

    expect(stored).toBe(JSON.stringify({
      ARK_API_KEY: 'ark-key',
      DAMAGE_DETECT_MODEL: 'doubao-seed-2-0-pro-260215',
    }));
    expect(service.decrypt(stored)).toEqual({
      ARK_API_KEY: 'ark-key',
      DAMAGE_DETECT_MODEL: 'doubao-seed-2-0-pro-260215',
    });
  });
});
