[codex] Allow task container injection during platform init#57
[codex] Allow task container injection during platform init#57ChiragAgg5k wants to merge 1 commit intomainfrom
Conversation
Greptile SummaryThis PR adds a minimal, well-scoped feature to
Confidence Score: 5/5Safe to merge; all findings are non-blocking test quality issues. The production change is correct and minimal. The only issues are in the test helper code (output buffer leak, potentially undefined variable), which are P2 and do not affect correctness of the feature itself. tests/e2e/CLITest.php — the ob_start/ob_get_clean imbalance and undefined $result on exception paths should be cleaned up. Important Files Changed
Reviews (1): Last reviewed commit: "feat: allow task container injection" | Re-trigger Greptile |
| try { | ||
| $_SERVER['argv'] = ['test.php', 'inject']; | ||
| ob_start(); | ||
|
|
||
| $container = new Container(); | ||
| $container->set('test', fn () => 'test-value'); | ||
|
|
||
| $platform = new TestPlatform(); | ||
| $platform->init(Service::TYPE_TASK, [ | ||
| 'adapter' => new Generic(), | ||
| 'container' => $container, | ||
| ]); | ||
|
|
||
| $cli = $platform->getCli(); | ||
| $cli->run(); | ||
|
|
||
| $result = ob_get_clean(); | ||
| } finally { | ||
| $_SERVER['argv'] = $argv; | ||
| } |
There was a problem hiding this comment.
Output buffer not closed on exception path
ob_start() is called inside the try block, but ob_get_clean() only runs on the happy path. If $cli->run() throws, the buffer is never flushed or discarded, which can corrupt output for every subsequent test in the suite. Additionally, $result is referenced after the try/finally block but is only assigned inside the try — if an exception escapes, $result would be undefined at the assertEquals call.
Moving the buffer teardown into finally fixes both issues:
$argv = $_SERVER['argv'] ?? [];
$result = '';
try {
$_SERVER['argv'] = ['test.php', 'inject'];
ob_start();
$container = new Container();
$container->set('test', fn () => 'test-value');
$platform = new TestPlatform();
$platform->init(Service::TYPE_TASK, [
'adapter' => new Generic(),
'container' => $container,
]);
$cli = $platform->getCli();
$cli->run();
} finally {
$result = ob_get_clean();
$_SERVER['argv'] = $argv;
}
$this->assertEquals('test-value', $result);|
Superseded by utopia-php/cli#51. Closing this in favor of the CLI-owned container approach. |
Summary
Platform::init()task bootstrapping to accept a providedcontainerparamWhy
Appwrite needs to register task resources directly on a shared DI container in
app/cli.php, bututopia-php/platformcurrently creates the CLI without exposing a way to supply the task container duringinit(Service::TYPE_TASK).This keeps the change minimal and compatible with the existing
utopia-php/cliAPI by reusingCLI::setContainer().Validation
composer testcomposer lintcomposer format src/Platform/Platform.php tests/Platform/TestServiceCLI.php tests/Platform/TestActionCLIInjection.php tests/e2e/CLITest.phpImpact
Users can now do:
and register CLI task resources directly on that container.