Skip to content

V- Modal AI: Visual Video / Image Search - Flutter Video SDK

5.0 KB
Raw Blame
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';

final scripts = <String>[
  'install.sh',
  'build.sh',
  'run.sh',
  'test.sh',
  'env.sh',
  'security_check.sh',
  if (File('cli.sh').existsSync()) 'cli.sh',
];

void main() {
  test(
    'all shell scripts have valid syntax and executable dispatchers',
    () async {
      for (final path in scripts) {
        expect(File(path).existsSync(), isTrue, reason: path);
        final syntax = await Process.run('bash', <String>['-n', path]);
        expect(syntax.exitCode, 0, reason: '$path: ${syntax.stderr}');
        final help = await Process.run('bash', <String>[path, 'help']);
        expect(help.exitCode, 0, reason: '$path: ${help.stderr}');
        expect(help.stdout, contains('Usage'));
        final bad = await Process.run('bash', <String>[path, 'not-a-command']);
        expect(bad.exitCode, isNot(0));
      }
    },
  );

  test(
    'env.sh is source-only, idempotent, and preserves explicit values',
    () async {
      const sentinel = 'sdk-secret-sentinel';
      final result = await Process.run('bash', <String>[
        '-c',
        'VMODAL_API_KEY=$sentinel; source env.sh; sdk_env_live; '
            'test "\$VMODAL_API_KEY" = "$sentinel"; sdk_env_live',
      ]);
      expect(result.exitCode, 0, reason: '${result.stderr}');
      expect('${result.stdout}${result.stderr}', isNot(contains(sentinel)));
    },
  );

  test('local helpers cannot publish', () {
    for (final path in scripts.where(
      (String path) => path != 'security_check.sh',
    )) {
      final text = File(path).readAsStringSync();
      expect(text, isNot(contains('pub publish --force')), reason: path);
      expect(text, isNot(contains('--skip-validation')), reason: path);
      expect(text, isNot(contains('git merge')), reason: path);
    }
  });

  test(
    'development setup invokes install and clean supports public clones',
    () {
      final readme = File('README.md').readAsStringSync();
      expect(readme, contains('bash install.sh install'));
      expect(readme.split('\n'), isNot(contains('bash install.sh')));

      final build = File('build.sh').readAsStringSync();
      expect(build, contains('name: vmodal_sdk_flutter'));
      expect(build, contains('example/01_full_app/pubspec.yaml'));
      expect(build, contains('example/02_users/pubspec.yaml'));
      expect(build, isNot(contains('*/uinterface/sdk_flutter')));
    },
  );

  test('backend auth reference participates in the offline Dart gates', () {
    final build = File('build.sh').readAsStringSync();
    for (final command in <String>['pub_get', 'analyze', 'test']) {
      final body = RegExp(
        'sdk_$command\\(\\) \\{([\\s\\S]*?)\\n\\}',
      ).firstMatch(build)!.group(1)!;
      final operation = command == 'pub_get' ? 'pub get' : command;
      expect(
        body,
        contains(
          '(cd example/06_userlogin_backend_auth && sdk_flutter $operation)',
        ),
        reason: 'Missing backend reference gate: $command',
      );
    }
    expect(build, contains('example/06_userlogin_backend_auth/lib'));
    expect(build, contains('example/06_userlogin_backend_auth/test'));
    expect(build, isNot(contains('node --test')));
  });

  test('security commands and fixed all ordering are registered', () {
    final text = File('security_check.sh').readAsStringSync();
    for (final command in <String>[
      'workflow',
      'toolchain',
      'version',
      'license',
      'routes',
      'package',
      'secrets',
      'all',
    ]) {
      expect(text, contains('$command)'));
    }
    final body = RegExp(
      r'sdk_security_all\(\) \{([\s\S]*?)\n\}',
    ).firstMatch(text)!.group(1)!;
    var offset = -1;
    for (final call in <String>[
      'sdk_security_workflow',
      'sdk_security_toolchain',
      'sdk_security_version',
      'sdk_security_license',
      'sdk_security_routes',
      'sdk_security_package',
      'sdk_security_secrets',
    ]) {
      final next = body.indexOf(call);
      expect(next, greaterThan(offset), reason: call);
      offset = next;
    }
  });

  test('live gate searches with the advertised LanceDB version', () {
    final shell = File('test.sh').readAsStringSync();
    final live = File('tool/live_test.dart').readAsStringSync();
    expect(shell, contains('sdk_live_lancedb_version'));
    expect(shell, contains('run tool/live_test.dart'));
    expect(live, contains('.findGroup(group, mode: \'vid_file\')'));
    expect(live, contains('?.latestLancedbVersion'));
    expect(live, contains('versionLancedb: version'));
  });

  test('pre-commit regenerates the SDK reference for Flutter changes', () {
    final configFile = File('../../.pre-commit-config.yaml');
    if (!configFile.existsSync()) return;
    final config = configFile.readAsStringSync();
    final cli = File('cli.sh').readAsStringSync();
    expect(config, contains('files: ^uinterface/sdk_flutter/'));
    expect(config, contains('cli.sh docs_precommit'));
    expect(cli, contains('docs.py" generate'));
    expect(cli, contains('docs.py" check'));
    expect(cli, contains('diff --cached --name-only'));
  });
}