Repository navigation
chore: absorb circuit-breaker into packages/circuit-breaker - #13869
Conversation
Bring the full base circuit-breaker library in under the Utopia namespace and house it to match the shape of other utopia-php packages (cache, pools, telemetry). Namespaces - ChiragAgg5k\CircuitBreaker -> Utopia\CircuitBreaker - ChiragAgg5k\Tests -> Utopia\Tests - Sources moved under src/CircuitBreaker/ (matches "src/<Foo>/<Foo>.php" PSR-4 layout used by the rest of utopia-php) composer.json - Name, description, authors, keywords, PSR-4 roots, suggest keys - Utopia script names (lint / format / check / test, test:unit, test:e2e, test:e2e:docker, telemetry:up/scenario/down) Docs & branding - README rewritten with utopia banner, badges, marketing paragraph, section ordering, and API reference - LICENSE copyright changed to "Utopia" Tooling - phpunit.xml.dist -> phpunit.xml, phpstan.neon.dist -> phpstan.neon - docker-composer.yml / docker-composer.telemetry.yml renamed to the standard docker-compose.* spelling - CI split into .github/workflows/linter.yml (pint + phpstan) and .github/workflows/tests.yml (unit tests on PHP 8.2/8.3/8.4 plus a Docker-based e2e job) The public API, adapter surface, telemetry wiring, cache semantics, and test coverage all behave exactly as before; this change is purely structural + cosmetic. Unit tests, phpstan level 5, and pint all pass locally.
- tests.yml: drop opentelemetry/protobuf host extensions from the E2E job. The E2E step only shells out to `composer test:e2e:docker`; all PHP execution happens inside the Dockerfile container where those extensions are installed already. - phpstan.neon: add `tests` to analysed paths so test helpers, anonymous-class cache adapters, and the custom telemetry subclass are covered. Paired with a narrow ignoreErrors block for two patterns the upstream type system can't express: the $values property on anonymous Counter/Gauge subclasses emitted by Utopia\Telemetry\Adapter\Test, and the defensive method_exists(Redis, 'getLastError') guard.
Useful for tests that need to exercise breaker-open behaviour without driving N failures through call(), and for operational manual breaks (e.g. an admin endpoint disabling a backend). Idempotent: calling on an already-open breaker refreshes openedAt without recording a transition.
feat: add trip() to force breaker into open state
Rename cacheKey option to key
Defer rare telemetry instrument creation
Absorb utopia-php/circuit-breaker
Reuse mirror redirect workflow
docs: enforce documentation style with Vale
fix(telemetry): register instruments on first write
refactor(pools,circuit-breaker,storage): drop the deprecated Instrument::lazy() helpers
circuit-breaker: judge health by failure rate, not a consecutive count
perf(telemetry, circuit-breaker): record less per call on the cache path
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
| static fn (array $write): bool => $write[0] === 'set', | ||
| )); | ||
|
|
||
| $this->assertSame(['set', 'users-api:state', CircuitState::OPEN->value], $setWrites[array_key_last($setWrites)]); |
There was a problem hiding this comment.
Tests mirror implementation details
This assertion hard-codes the exact cache key and write order. Other tests in this file also require zero adapter writes and inspect the telemetry callback registry. These checks test internal storage and registration details rather than observable circuit-breaker behavior, so harmless refactors can break the suite without changing the public contract. The repository requires tests to assert observable behavior instead of mirroring source code or configuration, and that requirement must be satisfied before merging.
Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/circuit-breaker/tests/CircuitBreakerTest.php
Line: 167
Comment:
**Tests mirror implementation details**
This assertion hard-codes the exact cache key and write order. Other tests in this file also require zero adapter writes and inspect the telemetry callback registry. These checks test internal storage and registration details rather than observable circuit-breaker behavior, so harmless refactors can break the suite without changing the public contract. The repository requires tests to assert observable behavior instead of mirroring source code or configuration, and that requirement must be satisfied before merging.
**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
|
Split run pushed |
|
Retired from the monorepo in utopia-php/monorepo#343. Its Split run no longer includes |
Summary
This moves
utopia-php/circuit-breakerintopackages/circuit-breaker, so Appwrite loads it directly. It follows the playbook inrfc/monorepo.mdand comes in three commits:Add 'packages/circuit-breaker/' from commit '51c9b9b0…': subtree import from the mirror with full history. The mirror head is the0.4.1tag Appwrite already locks, and its tree matchespackages/circuit-breakerinutopia-php/monorepo(34f0cca), so the dependency graph doesn't change.chore(circuit-breaker): mirror plumbing:mirror.ymlnow points here, the README banner is refreshed, andabsorbremoves theDockerfile, sincedocker-compose.ymldoesn't build from it.refactor: load circuit-breaker from packages/:replaceentries and removes the package from the lock. Appwrite never required it directly; it came in throughutopia-php/cache(^0.4), andreplacenow satisfies that.docker-compose.telemetry.yml, the Grafana/Prometheus/OTel stack underdocker/,examples/telemetry, the dashboard screenshot, thetelemetry:*composer scripts and their README section, 1,797 lines in all. The demo built from the Dockerfile the monorepo tooling strips, so it would have broken anyway. Telemetry support in the library itself is unchanged and still documented.src/CircuitBreaker/*moves up tosrc/.tests/unit/*moves up totests/, andtests/e2ebecomestests/E2E, matching the rootpackagessuite exclusion.Utopia\Tests\{unit,e2e}namespace toUtopia\CircuitBreaker\Tests(andTests\E2E), with a matchingautoload-deventry.phpstan.neonused to include the monorepo root config, andvalidaterejects that, so it's now standalone at level max. Its two documentedignoreErrorsare kept. Aphpstan-baseline.neonholds 29 findings, since the monorepo analysed this package at level 5. They are casts frommixedin the Redis and Swoole Table adapters, plus loosely typed fixtures in the tests. The RFC's phase 8 burn-down list now includes them.composer test:e2e:dockerscript that doesn't exist. They now saydocker compose up -d --wait && composer test:e2e.braces_position,fn (spacing).There's nothing to hoist, since the package requires only PHP.
utopia-php/telemetrystays in itsrequire-devfor the unit tier.Net: +216 / −1,974 across the three commits.
Validation
bin/monorepo validate: all packages validbin/monorepo check circuit-breaker: Pint and PHPStan level max (with baseline) passbin/monorepo test circuit-breaker: unit 36 tests / 117 assertions; e2e 6 tests / 30 assertions against Redis fromdocker-compose.yml, plus Swoole Tablevendor/bin/phpunit --testsuite packages --filter 'Utopia\\CircuitBreaker\\Tests': 36 tests pass under the root autoloader, with E2E excludedUtopia\CircuitBreaker\CircuitBreakerresolves topackages/circuit-breaker/srcfrom the root autoloader (used byutopia-php/cache'sCircuitBreakeradapter)bin/monorepo split circuit-breaker --dry-run:f40e0130, which fast-forwards from the mirror head51c9b9b0git diff --checkMerge and follow-up
Merge with a merge commit.
The
utopia-php/circuit-breakermirror already has the canonicalmainruleset (id18540974), with the split app as an always-bypass actor, so the absorb ran with--skip-ruleset.After merge: confirm
Splitpushes toutopia-php/circuit-breaker. Then removepackages/circuit-breakerfromutopia-php/monorepo.cachethere still requiresutopia-php/circuit-breaker: ^0.4from Packagist, and the mirror keeps serving that. The mirror has no open PRs, and neither does the monorepo for circuit-breaker.🤖 Generated with Claude Code