Tinkerwell with Sage 10 + Bedrock

Hello folks

I have been using Tinkerwell for a while, but it’s stopped working since upgrading Sage. All I get from the console is “ERROR Command “cli” is not defined.”

I’m using a Bedrock/Tinkerwell driver that I found on Github - which had been working fine before.

Inside application.log I get this:

[2023-02-17 14:22:02] development.ERROR: Command "cli" is not defined. {"exception":"[object] (Symfony\\Component\\Console\\Exception\\CommandNotFoundException(code: 0): Command \"cli\" is not defined. at /home/vagrant/web/my-site/site/web/app/themes/my-theme/vendor/symfony/console/Application.php:694)
[stacktrace]
#0 /home/vagrant/web/my-site/site/web/app/themes/my-theme/vendor/symfony/console/Application.php(259): Symfony\\Component\\Console\\Application->find()
#1 /home/vagrant/web/my-site/site/web/app/themes/my-theme/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun()
#2 /home/vagrant/web/my-site/site/web/app/themes/my-theme/vendor/illuminate/console/Application.php(102): Symfony\\Component\\Console\\Application->run()
#3 /home/vagrant/web/my-site/site/web/app/themes/my-theme/vendor/roots/acorn/src/Illuminate/Foundation/Console/Kernel.php(155): Illuminate\\Console\\Application->run()
#4 /home/vagrant/web/my-site/site/web/app/themes/my-theme/vendor/roots/acorn/src/Roots/Acorn/Bootloader.php(150): Illuminate\\Foundation\\Console\\Kernel->handle()
#5 /home/vagrant/web/my-site/site/web/app/themes/my-theme/vendor/roots/acorn/src/Roots/Acorn/Bootloader.php(110): Roots\\Acorn\\Bootloader->bootConsole()
#6 /home/vagrant/web/my-site/site/web/app/themes/my-theme/functions.php(33): Roots\\Acorn\\Bootloader->boot()
#7 /home/vagrant/web/my-site/site/web/wp/wp-settings.php(585): include('...')
#8 /home/vagrant/web/my-site/site/.tinkerwell/BedrockTinkerwellDriver.php(18): require('...')
#9 phar:///tmp/vagrant_tinker.phar/src/Concerns/DriverAware.php(11): BedrockTinkerwellDriver->bootstrap()
#10 phar:///tmp/vagrant_tinker.phar/src/Actions/CliAction.php(27): _PhpScoperc223a629f245\\Tinkerwell\\Actions\\CliAction->detectDriver()
#11 phar:///tmp/vagrant_tinker.phar/src/ActionInvoker.php(37): _PhpScoperc223a629f245\\Tinkerwell\\Actions\\CliAction->__construct()
#12 phar:///tmp/vagrant_tinker.phar/src/ActionInvoker.php(18): _PhpScoperc223a629f245\\Tinkerwell\\ActionInvoker->setUpAction()
#13 phar:///tmp/vagrant_tinker.phar/index.php(25): _PhpScoperc223a629f245\\Tinkerwell\\ActionInvoker->execute()
#14 /tmp/vagrant_tinker.phar(12): require('...')
#15 {main}
"} 

Looking at the Roots Bootloader, it seems that inside boot() we have

if ($app->runningInConsole()) {
    $this->enableHttpsInConsole();
    return class_exists('WP_CLI') ? $this->bootWpCli($app) : $this->bootConsole($app);
}

It seems that Tinkerwell is detected as a console as that conditional passes.

Within that if statement, class_exists('WP_CLI') returns false, so bootConsole() is run. But it’s at that point it looks to me that it might be interfering with Tinkerwell by trying to boot a Symfony Console and accepting arguments.

    protected function bootConsole(ApplicationContract $app)
    {
        $kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);

        $status = $kernel->handle(
            $input = new \Symfony\Component\Console\Input\ArgvInput(),
            new \Symfony\Component\Console\Output\ConsoleOutput()
        );

        $kernel->terminate($input, $status);
        exit($status);
    }

If I block this method from running, Tinkerwell works.

Is there a way to do this programmatically/in a more permanent way?

Thanks in advance!

1 Like

I can confirm there’s an issue with compatibility between Tinkerwell and Bedrock.

Commenting the whole \Roots\Acorn\Bootloader::bootConsole method allows using Tinkerwell again.

Unfortunately, I do not have the time to propose a PR for this bug.

@thebezzo thanks for confirming. I got in touch with Tinkerwell support (before realising it was an Acorn/Sage thing). Even after establishing it wasn’t a Tinkerwell issue, they also followed up to ask more with the intent of perhaps doing something within Tinkerwell to avoid this conflict.

@doug Did you ever end up finding a workaround for this issue?

I’ve opened Bug: ‘Command “cli” is not defined’ in Tinkerwell · Issue #283 · roots/acorn since this seems to me like an actual bug.

For me, this was a problem both with Tinkerwell and also with running PHP unit tests.
A temporary, simple solution in my case was:

if( isset($_SERVER['argv']) && ! in_array('acorn', $_SERVER['argv'])){
	putenv( 'APP_RUNNING_IN_CONSOLE=false' );
}

I do not use bedrock, and acorn is loaded through a mu-plugin.
I’ve added the snippet above just before loading vendor/autoload.php

:warning: I’ve just implemented this a few minutes before posting here and have only done some light testing.

https://github.com/beyondcode/tinkerwell/blob/722ced1f650fb97cc883339c2d9341816bc9e7b9/src/Drivers/RadicleTinkerwellDriver.php

2 Likes