Skip to content

Conversation

BrandonOdiwuor
Copy link
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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 10, 2024

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.

@DrahtBot DrahtBot added the Tests label Sep 10, 2024
@fanquake
Copy link
Member

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

Run 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.
libc++abi: terminating

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.
libc++abi: terminating

Target ['/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

@DrahtBot
Copy link
Contributor

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

Hints

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.

@maflcko
Copy link
Member

maflcko commented Oct 1, 2024

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.)

BrandonOdiwuor and others added 3 commits December 18, 2024 08:02
 - 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>
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>
if len(options) == 0:
return ""

generated = ""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is a discussion (#17289 (comment)) 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

@tnndbtc
Copy link

tnndbtc commented Feb 14, 2025

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.

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Feb 22, 2025
 - 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>

Github-Pull: bitcoin#30860
Rebased-From: eb43862
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Feb 22, 2025
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>

Github-Pull: bitcoin#30860
Rebased-From: 7c8b021
@BrandonOdiwuor BrandonOdiwuor marked this pull request as ready for review March 5, 2025 10:23
@DrahtBot
Copy link
Contributor

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

@DrahtBot
Copy link
Contributor

⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

contrib: Autogenerate bash completion
6 participants