Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

2.2 KB
Raw Blame
import { describe, it, expect } from 'vitest';
import { zipSync } from 'fflate';
import {
  hasLegacySoraHeader,
  isLegacySoraExtension,
  isLegacySoraV2Bytes,
  parseLegacySoraV1Json,
  unwrapLegacySoraBytes,
} from '../legacySoraMigrator';

describe('Read-Only Legacy .sora Migrator Helpers', () => {
  it('parses legacy .sora v1.2 JSON (including UTF-8 BOM) and strips prototype keys', () => {
    const v1Json = JSON.stringify({
      app: 'Sora Paint',
      version: '1.2',
      name: 'Legacy Project',
      dimensions: { width: 1440, height: 900, dpi: 300 },
      colorMode: 'color',
      layers: [
        {
          id: 'layer-bg',
          name: 'Background',
          type: 'raster',
          visible: true,
          opacity: 1,
          blendMode: 'normal',
          locked: false,
          parentId: null,
        },
      ],
      canvases: {},
      masks: {},
    });

    const parsed = parseLegacySoraV1Json('\ufeff' + v1Json);
    expect(parsed.format).toBe('sora-v1');
    expect(parsed.version).toBe('1.2');
    expect(parsed.name).toBe('Legacy Project');
    expect(parsed.layers).toHaveLength(1);

    const polluted = parseLegacySoraV1Json(
      '{"layers":[{"id":"l1","name":"L1","type":"raster","visible":true,"opacity":1,"blendMode":"normal","locked":false,"parentId":null,"__proto__":{"polluted":true}}]}'
    );
    expect((polluted.layers[0] as unknown as Record<string, unknown>).polluted).toBeUndefined();
  });

  it('detects and unwraps 8-byte SORA\\x00\\x02 wrapper prefix on legacy v2 archives', () => {
    const zipBytes = zipSync({
      'manifest.json': new TextEncoder().encode(JSON.stringify({ name: 'Legacy V2 Doc' })),
    });

    const wrapped = new Uint8Array(8 + zipBytes.byteLength);
    wrapped.set([0x53, 0x4f, 0x52, 0x41, 0x00, 0x02, 0x00, 0x00], 0);
    wrapped.set(zipBytes, 8);

    expect(hasLegacySoraHeader(wrapped)).toBe(true);
    expect(isLegacySoraV2Bytes(wrapped)).toBe(true);
    expect(Array.from(unwrapLegacySoraBytes(wrapped))).toEqual(Array.from(zipBytes));

    expect(hasLegacySoraHeader(zipBytes)).toBe(false);
    expect(isLegacySoraV2Bytes(zipBytes)).toBe(true);
    expect(isLegacySoraExtension('old-chapter.sora')).toBe(true);
    expect(isLegacySoraExtension('new-chapter.ink')).toBe(false);
  });
});