import { describe, expect, it } from '@jest/globals';
import fs from 'node:fs';
import path from 'node:path';

describe('runtime queue configuration', () => {
  it.each([
    path.resolve(__dirname, '../../../docker-compose.yml'),
    path.resolve(__dirname, '../../../../podman-compose.yml'),
  ])('%s preserves durable Bull keys with noeviction', (composePath) => {
    const compose = fs.readFileSync(composePath, 'utf8');

    expect(compose).toContain('--maxmemory-policy noeviction');
    expect(compose).not.toContain('--maxmemory-policy allkeys-lru');
    expect(compose).toContain('stop_grace_period: 30s');
  });

  it('preserves provider cost precision below one ten-thousandth of a dollar', () => {
    const schema = fs.readFileSync(path.resolve(__dirname, '../../../prisma/schema.prisma'), 'utf8');
    const migration = fs.readFileSync(
      path.resolve(__dirname, '../../../prisma/migrations/20260730000000_expand_provider_cost_precision/migration.sql'),
      'utf8'
    );

    expect(schema).toMatch(/cost\s+Decimal\s+@default\(0\) @db\.Decimal\(18, 9\)/);
    expect(migration).toContain('ALTER COLUMN "cost" TYPE DECIMAL(18,9)');
  });

  it('keeps the published Redis port separate from the internal service port', () => {
    const compose = fs.readFileSync(path.resolve(__dirname, '../../../docker-compose.yml'), 'utf8');

    expect(compose).toContain('"${REDIS_PUBLISHED_PORT:-6379}:6379"');
    expect(compose).toContain('REDIS_PORT: 6379');
    expect(compose).not.toContain('REDIS_PORT: ${REDIS_PORT:-6379}');
  });
});
