// Integration test: install_module against a `planned` seed
// entry must fail with a clear, human-readable error class —
// not a panic, not a silent success.
//
// Why this matters: planned modules are listed in the Store
// but have no wasm_url. The old behaviour was a server-side
// panic on resolve_install_source(); the new contract emits a
// FAILED_PRECONDITION with "no installable version" so
// Studio's friendly-error mapper can show a usable message.

import 'package:flutter_test/flutter_test.dart';

import 'hub_fixture.dart';

void main() {
  test('install_module on a planned entry surfaces a clear error',
      () async {
    final fixture = await HubFixture.start();
    if (fixture == null) return;
    try {
      // web.scrape is `planned` in the seed and has no
      // wasm_url. The hub resolves the name through the store
      // index, finds the entry, then fails at the
      // "no installable version" check.
      try {
        await fixture.client.installModule(source: 'web.scrape');
        fail('install_module should not succeed for a planned entry');
      } catch (e) {
        final msg = e.toString();
        expect(
          msg.contains('no installable version') ||
              msg.contains('not yet published'),
          isTrue,
          reason:
              'Expected a clear planned-status error, got: $msg',
        );
      }
    } finally {
      await fixture.dispose();
    }
  });
}
