Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

1.1 KB
Raw Blame
import { createHash } from 'node:crypto'
import { validateMigrationFiles } from './migrations'

function migration(file: string, sql: string) {
  return { file, sql, sha256: createHash('sha256').update(sql).digest('hex') }
}

test('orders migration files by name without changing the submitted deployment', () => {
  const first = migration('0001_schema.sql', 'CREATE TABLE projects (id int)')
  const second = migration('0002_index.sql', 'CREATE INDEX idx ON projects (id)')
  const submitted = [second, first]
  expect(validateMigrationFiles(submitted)).toEqual([first, second])
  expect(submitted).toEqual([second, first])
})

test('returns every name, duplicate and content error for the manifest editor', () => {
  const invalid = migration('wrong.sql', 'SELECT 1')
  expect(() => validateMigrationFiles([invalid, { ...invalid, sql: 'SELECT 2' }])).toThrow(
    expect.objectContaining({
      code: 'invalid_manifest',
      details: {
        errors: ['migration_name', 'migration_name', 'migration_duplicate', 'migration_sha256'].map((rule) =>
          expect.objectContaining({ file: invalid.file, rule }),
        ),
      },
    }),
  )
})