# Path: src/funfuzz/js/inspect_shell.py
# def queryBuildConfiguration(s, parameter):  # pylint: disable=invalid-name,missing-param-doc,missing-return-doc
#     # pylint: disable=missing-return-type-doc,missing-type-doc
#     """Test if a binary is compiled with specified parameters, in getBuildConfiguration()."""
#     return json.loads(testBinary(s,
#                                  ["-e", f'print(getBuildConfiguration()["{parameter}"])'],
#                                  False, stderr=subprocess.DEVNULL)[0].rstrip().lower())


import io
import logging
import platform
import tarfile
import fuzzfetch
import requests
from pathlib import Path
from ..js.inspect_shell import queryBuildConfiguration
    RUN_COV_LOG.info("Obtaining coverage build zip file from TaskCluster, into %s", str(dirpath))

    extract_folder = dirpath / "cov-build"
    dirpath.mkdir(parents=True, exist_ok=True)  # Ensure this dir has been created

    # Use fuzzfetch to obtain build instead of wget
    fetcher, fetch_opts = fuzzfetch.Fetcher.from_args(
        [
            "--fuzzing",
            "--coverage",
            "--build", rev,
            "--name", "cov-build",
            "--out", str(dirpath),
            "--target", "js",
        ],
        skip_dir_check=True,
    )
    extract_folder = Path(fetch_opts["out"])
    fetcher.extract_build(fetch_opts["targets"], extract_folder)

    RUN_COV_LOG.info("Coverage build zip file extracted to this folder: %s", extract_folder.resolve())

    js_cov_bin_name = f'js{".exe" if platform.system() == "Windows" else ""}'
    js_cov_bin = extract_folder / "dist" / "bin" / js_cov_bin_name

    Path.chmod(js_cov_bin, Path.stat(js_cov_bin).st_mode | 0o111)  # Ensure the js binary is executable
    assert js_cov_bin.is_file()

    # Check that the binary is non-debug.
    assert not queryBuildConfiguration(js_cov_bin, "debug")

# Path: src/funfuzz/js/inspect_shell.py
# def queryBuildConfiguration(s, parameter):  # pylint: disable=invalid-name,missing-param-doc,missing-return-doc
#     # pylint: disable=missing-return-type-doc,missing-type-doc
#     """Test if a binary is compiled with specified parameters, in getBuildConfiguration()."""
#     return json.loads(testBinary(s,
#                                  ["-e", f'print(getBuildConfiguration()["{parameter}"])'],
#                                  False, stderr=subprocess.DEVNULL)[0].rstrip().lower())


# Path: src/funfuzz/ccoverage/get_build.py
import io
import logging
import platform
import tarfile
import fuzzfetch
import requests
from pathlib import Path
from ..js.inspect_shell import queryBuildConfiguration

    RUN_COV_LOG.info("Obtaining coverage build zip file from TaskCluster, into %s", str(dirpath))

    extract_folder = dirpath / "cov-build"
    dirpath.mkdir(parents=True, exist_ok=True)  # Ensure this dir has been created

    # Use fuzzfetch to obtain build instead of wget
    fetcher, fetch_opts = fuzzfetch.Fetcher.from_args(
        [
            "--fuzzing",
            "--coverage",
            "--build", rev,
            "--name", "cov-build",
            "--out", str(dirpath),
            "--target", "js",
        ],
        skip_dir_check=True,
    )
    extract_folder = Path(fetch_opts["out"])
    fetcher.extract_build(fetch_opts["targets"], extract_folder)

    RUN_COV_LOG.info("Coverage build zip file extracted to this folder: %s", extract_folder.resolve())

    js_cov_bin_name = f'js{".exe" if platform.system() == "Windows" else ""}'
    js_cov_bin = extract_folder / "dist" / "bin" / js_cov_bin_name

    Path.chmod(js_cov_bin, Path.stat(js_cov_bin).st_mode | 0o111)  # Ensure the js binary is executable
    assert js_cov_bin.is_file()

    # Check that the binary is non-debug.
    assert not queryBuildConfiguration(js_cov_bin, "debug")

    assert queryBuildConfiguration(js_cov_bin, "coverage")