Repository navigation
chore: absorb user-agent into packages/user-agent - #13862
Conversation
feat(user-agent): add fast user-agent detector
…pansion-6rbfh4 feat(user-agent): expand OS, browser, device, and bot detection
…cation fix(user-agent): identify native Flutter iOS apps
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
| ]; | ||
|
|
||
| foreach ($blink as $pattern => [$code, $name]) { | ||
| if (preg_match($pattern, $userAgent, $matches) === 1) { |
There was a problem hiding this comment.
Prohibited regex-based parsing
The imported detectors add extensive preg_match()-based parsing even though the repository explicitly prohibits new regular expressions in favor of string operations or existing validators unless the PR explains why no alternative works. The same pattern appears throughout DeviceDetector, OperatingSystemDetector, and BotDetector. This repository requirement must be satisfied before merging by replacing these expressions or documenting and justifying the necessary exceptions.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/user-agent/src/Detection/ClientDetector.php
Line: 57
Comment:
**Prohibited regex-based parsing**
The imported detectors add extensive `preg_match()`-based parsing even though the repository explicitly prohibits new regular expressions in favor of string operations or existing validators unless the PR explains why no alternative works. The same pattern appears throughout `DeviceDetector`, `OperatingSystemDetector`, and `BotDetector`. This repository requirement must be satisfied before merging by replacing these expressions or documenting and justifying the necessary exceptions.
**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))
---
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!
| public function testCoreFieldsMatchMatomo64(string $userAgent): void | ||
| { | ||
| $matomo = new MatomoDeviceDetector($userAgent); | ||
| $matomo->skipBotDetection(); | ||
| $matomo->parse(); | ||
|
|
||
| $os = $matomo->getOs(); | ||
| $client = $matomo->getClient(); | ||
| $agent = UserAgent::parse($userAgent); | ||
|
|
||
| $this->assertSame($this->nullable($os['short_name'] ?? null), $agent->operatingSystem()->code); | ||
| $this->assertSame($this->nullable($os['name'] ?? null), $agent->operatingSystem()->name); | ||
| $this->assertSame($this->nullable($os['version'] ?? null), $agent->operatingSystem()->version); | ||
| $this->assertSame($this->nullable($client['type'] ?? null), $agent->client()->type); | ||
| $this->assertSame($this->nullable($client['short_name'] ?? null), $agent->client()->code); | ||
| $this->assertSame($this->nullable($client['name'] ?? null), $agent->client()->name); | ||
| $this->assertSame($this->nullable($client['version'] ?? null), $agent->client()->version); | ||
| $this->assertSame($this->nullable($client['engine'] ?? null), $agent->client()->engine); | ||
| $this->assertSame($this->nullable($client['engine_version'] ?? null), $agent->client()->engineVersion); | ||
| $this->assertSame($this->nullable($matomo->getDeviceName()), $agent->device()->type); | ||
| $this->assertSame($this->nullable($matomo->getBrandName()), $agent->device()->brand); | ||
| $this->assertSame($this->nullable($matomo->getModel()), $agent->device()->model); |
There was a problem hiding this comment.
These tests make the pinned Matomo 6.4 implementation the assertion oracle, requiring every parser field and bot decision to match it instead of defining Appwrite’s observable behavior independently. This directly violates the repository directive against mirroring source, configuration, or version pins in assertions. It also turns intentional parser differences or dependency upgrades into misleading failures. Replace these differential assertions with explicit behavior-focused cases 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/user-agent/tests/MatomoCompatibilityTest.php
Line: 58-79
Comment:
**Tests mirror Matomo internals**
These tests make the pinned Matomo 6.4 implementation the assertion oracle, requiring every parser field and bot decision to match it instead of defining Appwrite’s observable behavior independently. This directly violates the repository directive against mirroring source, configuration, or version pins in assertions. It also turns intentional parser differences or dependency upgrades into misleading failures. Replace these differential assertions with explicit behavior-focused cases 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)
|
|
Squash-merged, so the subtree annotation was dropped and |
#13862 was squash-merged, which dropped the annotation from the `git subtree add` merge commit and left the split unable to continue the mirror's history (non-fast-forward on utopia-php/user-agent). Restore it: the mainline is the squash's parent, the split is the mirror head it was imported from. git-subtree-dir: packages/user-agent git-subtree-mainline: 96c3ca6 git-subtree-split: 0396bd6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Retired from the monorepo in utopia-php/monorepo#340. Its Split run no longer includes |
Summary
This moves
utopia-php/user-agentintopackages/user-agent, so Appwrite loads it directly. It follows the playbook inrfc/monorepo.mdand comes in three commits:Add 'packages/user-agent/' from commit '0396bd61…': subtree import from the mirror with full history. The mirror head is the0.1.2tag that Appwrite already locks, so the dependency graph doesn't change.chore(user-agent): mirror plumbing:mirror.ymlnow points here, and the README banner is refreshed.refactor: load user-agent from packages/:replaceentries, drops theutopia-php/user-agentrequire line, and removes the package from the lock.src/UserAgent/*moves up tosrc/.phpstan.neon(level max,src+tests). The package passes it without a baseline.braces_position) to 5 files. Rector is clean.MatomoCompatibilityTestneedsmatomo/device-detector, which is only in the package'srequire-dev. It now has#[RequiresMethod(MatomoDeviceDetector::class, 'parse')], so the rootpackagessuite skips it andbin/monorepo test user-agentstill runs it. The alternative was adding Matomo to Appwrite's rootrequire-devjust for this test.There's nothing to hoist, since the package only requires PHP. Appwrite uses it in
src/Appwrite/Detector/Detector.phpandsrc/Appwrite/Platform/Workers/StatsUsage.php, and root PHPStan passes on both.Validation
bin/monorepo validate: all packages validbin/monorepo check user-agent: Rector, Pint, and PHPStan level max all passbin/monorepo test user-agent: 98 tests / 402 assertions, including the Matomo compatibility testsvendor/bin/phpunit --testsuite packages --filter 'Utopia\\UserAgent\\Tests': 90 tests pass, 2 Matomo tests skipped under the root autoloadervendor/bin/phpunit tests/unit/Detector: passbin/monorepo split user-agent --dry-run:6dcb9ede8141e6a5eda4f56b024beb4f21eddb63git diff --checkMerge and follow-up
Merge with a merge commit, not a squash. A squash drops the subtree annotation the split continues from.
The
utopia-php/user-agentmirror already has the canonicalmainruleset (id19101116), with the split app as an always-bypass actor, so the absorb ran with--skip-ruleset.After merge: confirm Appwrite's
Splitpushes toutopia-php/user-agent. Then removepackages/user-agentfromutopia-php/monorepoin a follow-up PR. The mirror has no open PRs.🤖 Generated with Claude Code