test: autogenerate bash completion #30860

pull BrandonOdiwuor wants to merge 3 commits into bitcoin:master from BrandonOdiwuor:bash-completion changing 11 files +498 −57
  1. BrandonOdiwuor commented at 8:26 am on September 10, 2024: contributor

    Fixes #17289, and follows up on #18606

    Adds a functional test that parses available RPC commands, generates the associated bitcoin-cli autocomplete file and checks that the current autocomplete file matches.

    An outdated autocomplete file can be updated via the –overwrite test parameter.

  2. DrahtBot commented at 8:26 am on September 10, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/30860.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32145 (test: Add functional test for bitcoin-chainstate by TheCharlatan)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label Tests on Sep 10, 2024
  4. fanquake commented at 3:44 pm on September 10, 2024: member

    https://github.com/bitcoin/bitcoin/actions/runs/10788681404/job/29919981336?pr=30860#step:7:3564:

    0Run rpc with args ['/Users/runner/work/bitcoin/bitcoin/ci/scratch/build-x86_64-apple-darwin/src/test/fuzz/fuzz', PosixPath('/Users/runner/work/bitcoin/bitcoin/ci/scratch/qa-assets/fuzz_corpora/rpc')]Error: RPC command "format" not found in RPC_COMMANDS_SAFE_FOR_FUZZING or RPC_COMMANDS_NOT_SAFE_FOR_FUZZING. Please update src/test/fuzz/rpc.cpp.
    1libc++abi: terminating
    2
    3Error: RPC command "format" not found in RPC_COMMANDS_SAFE_FOR_FUZZING or RPC_COMMANDS_NOT_SAFE_FOR_FUZZING. Please update src/test/fuzz/rpc.cpp.
    4libc++abi: terminating
    5
    6Target ['/Users/runner/work/bitcoin/bitcoin/ci/scratch/build-x86_64-apple-darwin/src/test/fuzz/fuzz', PosixPath('/Users/runner/work/bitcoin/bitcoin/ci/scratch/qa-assets/fuzz_corpora/rpc')] failed with exit code -6
    
  5. DrahtBot commented at 7:14 pm on September 10, 2024: contributor

    🚧 At least one of the CI tasks failed. Debug: https://github.com/bitcoin/bitcoin/runs/29919986329

    Make sure to run all tests locally, according to the documentation.

    The failure may happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  6. DrahtBot added the label CI failed on Sep 10, 2024
  7. maflcko commented at 12:35 pm on October 1, 2024: member
    Are you still working on this? (It looks like this has been opened as draft, with failing CI, which is fine. However, without any progress, it seems better to close this for now.)
  8. BrandonOdiwuor force-pushed on Oct 4, 2024
  9. BrandonOdiwuor force-pushed on Oct 4, 2024
  10. BrandonOdiwuor force-pushed on Oct 4, 2024
  11. DrahtBot added the label Needs rebase on Oct 10, 2024
  12. BrandonOdiwuor force-pushed on Oct 23, 2024
  13. BrandonOdiwuor force-pushed on Oct 23, 2024
  14. DrahtBot removed the label Needs rebase on Oct 23, 2024
  15. DrahtBot removed the label CI failed on Oct 23, 2024
  16. in test/functional/tool_cli_bash_completion.py:261 in 7c8b021fee outdated
    256+            self.options.header = path.join(test_data_dir, 'bitcoin-cli.header.bash-completion')
    257+
    258+        if self.options.footer is None or len(self.options.footer) == 0:
    259+            self.options.footer = path.join(test_data_dir, 'bitcoin-cli.footer.bash-completion')
    260+
    261+        if self.options.completion is None or len(self.option.completion) == 0:
    


    luke-jr commented at 3:44 pm on November 15, 2024:
    0        if self.options.completion is None or len(self.options.completion) == 0:
    

    BrandonOdiwuor commented at 7:28 am on December 18, 2024:
    fixed
  17. luke-jr changes_requested
  18. DrahtBot added the label CI failed on Dec 2, 2024
  19. rpc: add format command with support for args_cli
     - add format command to get infos about commands via a particular format
     - add output format args_cli to get arguments type info of shown commands
     - refactor RPCArg::ToTypeString to be used accross multiple output formats
     - overload CRPCTable::execute to call != methods than in their request
    
    Co-authored-by: pierrenn <git@pnn.sh>
    1fa440b4c5
  20. contrib: sync bitcoin-cli bash autocompletion 03921191a6
  21. test: keeps bitcoin-cli autocomplete in sync
    Adds a functional test which parses available RPC commands, generates
    the associated bitcoin-cli autcomplete file and checks that the current
    autocomplete matches the file
    An outdated autcomplete file can be updated using the --overwrite parameter
    
    Co-authored-by: pierrenn <git@pnn.sh>
    abf6ad42bd
  22. BrandonOdiwuor force-pushed on Dec 18, 2024
  23. BrandonOdiwuor requested review from luke-jr on Dec 18, 2024
  24. DrahtBot removed the label CI failed on Dec 18, 2024
  25. in test/functional/tool_cli_bash_completion.py:191 in abf6ad42bd
    186+        self.log.info(f"Generating part of the completion file for options {commands}")
    187+
    188+        if len(options) == 0:
    189+            return ""
    190+
    191+        generated = ""
    


    tnndbtc commented at 7:58 pm on February 14, 2025:

    Since there is a discussion (https://github.com/bitcoin/bitcoin/issues/17289#issuecomment-618736031) on whether it will slow down when user hit TAB key to send request to bitcoind for auto completion, what about we add those cword==1 commands in contrib/completions/bash/bitcoin-cli.bash so that it will not rely on the startup of bitcoind?

    The suggested code is pasted below and tested:

        # create cword==1 block to avoid the calling of bitcoind to get auto complete
        commands = []
        for command in options:
            commands.append(command.command)
        commands_str = " ".join(commands)
        cword_1_block = f"""    if ((cword == 1)); then
        options=\"{commands_str}\"
        COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
        return 0\n    fi\n\n"""
    
        generated = cword_1_block
  26. tnndbtc commented at 8:21 pm on February 14, 2025: none

    I tested the code in mac(Apple M1 chip) and it worked fine. Steps are: # run test and generate contrib/completions/bash/bitcoin-cli.bash: % build/test/functional/test_runner.py test/functional/tool_cli_bash_completion.py –tmpdir /tmp –nocleanup –overwrite

    # validate bash-completion on mac, first install bash-completion: % brew install bash-completion

    # switch to bash shell % bash

    # source the bash_completion script % . /opt/homebrew/etc/profile.d/bash_completion.sh

    # source bitcoin-cli bash % source contrib/completions/bash/bitcoin-cli.bash

    # then, without starting bitcoind % bitcoin-cli con[TAB]

    #this will auto complete to converttopsbt % bitcoin-cli converttopsbt

    #this will auto complete to converttopsbt % bitcoin-cli converttopsbt somestring [TAB] false true

    % bitcoin-cli converttopsbt some t[TAB]

    # it will auto complete true % bitcoin-cli converttopsbt some true

    % bitcoin-cli converttopsbt some true t[TAB]

    # it will auto complete false % bitcoin-cli converttopsbt some true f[TAB]

    % bitcoin-cli converttopsbt some true false

    Also, traced the code, especially in test/functional/tool_cli_bash_completion.py: get_command_options generate_completion_block and they look good to me. Left an enhancement comment in the PR so that the author can review.

  27. luke-jr referenced this in commit be15feb951 on Feb 22, 2025
  28. luke-jr referenced this in commit 7dd6f5b7fc on Feb 22, 2025
  29. BrandonOdiwuor marked this as ready for review on Mar 5, 2025
  30. DrahtBot commented at 4:29 pm on March 27, 2025: contributor

    🐙 This pull request conflicts with the target branch and needs rebase.

  31. DrahtBot added the label Needs rebase on Mar 27, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-04-17 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me