#!/usr/bin/env bash

set -euo pipefail

cleanup() {
    qs ipc call overview close >/dev/null 2>&1 || true
}
trap cleanup EXIT

qs ipc show | rg -A8 '^target overview$' | rg -q 'function search\(query: string\): void'
qs ipc call overview search ChatGPT >/dev/null

for _ in $(seq 1 20); do
    if hyprctl layers | rg -q 'namespace: qs-overview'; then
        printf 'overview-search contract: PASS\n'
        exit 0
    fi
    sleep 0.1
done

printf 'overview-search contract: overview did not map\n' >&2
exit 1
