Skip to content

feat: allow cli container injection#51

Merged
ChiragAgg5k merged 4 commits intomasterfrom
codex/task-container-injection
Apr 5, 2026
Merged

feat: allow cli container injection#51
ChiragAgg5k merged 4 commits intomasterfrom
codex/task-container-injection

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

  • allow injecting a container when constructing CLI
  • expose the current container with getContainer()
  • add coverage for using a provided container for task injections

Testing

  • composer test
  • composer lint
  • composer check

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 5, 2026

Greptile Summary

This PR allows callers to inject a pre-built Container into the CLI constructor (or via setContainer()), and exposes the current container through a new getContainer() accessor. The injected container becomes the parent of an internally-managed child container, so resources defined on it are inherited, but the CLI's own runtime resources remain isolated and are cleared on reset().

  • CLI::__construct() gains an optional ?Container $container parameter; when provided it is stored as $parentContainer and used to seed new Container($container)
  • getContainer(): Container is added as a new public accessor returning the internal child container
  • setContainer() gains a proper Container type hint (previously untyped) and now wraps the given container in a child container, consistent with the constructor behaviour
  • reset() is updated to reconstruct $this->container from $this->parentContainer, so parent-injected resources survive resets while runtime additions do not
  • Two new tests cover container isolation (assertNotSame) and post-reset resource availability

Confidence Score: 5/5

PR is safe to merge — changes are additive, well-tested, and backward compatible

All new parameters are optional with null defaults so existing callers are unaffected. The child-container pattern is applied consistently across the constructor, setContainer, and reset. Two targeted tests verify the new behaviour. No P0 or P1 issues found.

No files require special attention

Important Files Changed

Filename Overview
src/CLI/CLI.php Adds optional Container injection to constructor, getContainer() accessor, proper type hint on setContainer(), and updates reset() to preserve the parent container
tests/CLI/CLITest.php Adds two targeted tests covering child-container isolation and post-reset resource preservation

Reviews (2): Last reviewed commit: "Reapply "fix: preserve injected containe..." | Re-trigger Greptile

@ChiragAgg5k ChiragAgg5k merged commit 8d1955b into master Apr 5, 2026
7 checks passed
@ChiragAgg5k ChiragAgg5k deleted the codex/task-container-injection branch April 5, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants