// Pins the changelist's native JSON encoding — the cross-language contract
// with core's `Changelist`/`ChangelistFile` (crates/cambium-core/src/config.rs,
// `#[serde(rename_all = "camelCase")]`, fields `format_version`, `add`, `del`,
// `del_folders`). A Rust struct parses this strictly for version skew (see
// `read_versioned`), so the literal string below — field names, order, and
// the `formatVersion` value — must never drift without a matching Rust
// change.
import { describe, expect, it } from 'vitest';
import { changelistToNativeJson } from './useFileControl';

describe('changelist native JSON contract', () => {
  it('serializes a populated changelist to the exact literal core expects', () => {
    const changelist = {
      add: new Set(['Assets/New.cs']),
      del: new Set(['Assets/Old.cs', 'Assets/Older.cs']),
      delFolders: new Set(['Assets/Trash']),
    };
    expect(changelistToNativeJson(changelist)).toBe(
      '{"formatVersion":1,"add":["Assets/New.cs"],"del":["Assets/Old.cs","Assets/Older.cs"],"delFolders":["Assets/Trash"]}'
    );
  });

  it('serializes an empty changelist with empty arrays, not omitted fields', () => {
    const changelist = { add: new Set(), del: new Set(), delFolders: new Set() };
    expect(changelistToNativeJson(changelist)).toBe(
      '{"formatVersion":1,"add":[],"del":[],"delFolders":[]}'
    );
  });
});
