Skip to content

chore: absorb user-agent into packages/user-agent - #13862

Merged
loks0n merged 7 commits into
mainfrom
feat/absorb-user-agent
Sep 23, 2026
Merged

loks0n merged 7 commits into
mainfrom
feat/absorb-user-agent

Conversation

@loks0n

@loks0n loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member

Summary

This moves utopia-php/user-agent into packages/user-agent, so Appwrite loads it directly. It follows the playbook in rfc/monorepo.md and comes in three commits:

  1. Add 'packages/user-agent/' from commit '0396bd61…': subtree import from the mirror with full history. The mirror head is the 0.1.2 tag that Appwrite already locks, so the dependency graph doesn't change.
  2. chore(user-agent): mirror plumbing: mirror.yml now points here, and the README banner is refreshed.
  3. refactor: load user-agent from packages/:
    • Adds the root autoload and replace entries, drops the utopia-php/user-agent require line, and removes the package from the lock.
    • Applies step A of the standard shape: src/UserAgent/* moves up to src/.
    • Adds a standalone phpstan.neon (level max, src + tests). The package passes it without a baseline.
    • Applies Pint formatting (braces_position) to 5 files. Rector is clean.
    • MatomoCompatibilityTest needs matomo/device-detector, which is only in the package's require-dev. It now has #[RequiresMethod(MatomoDeviceDetector::class, 'parse')], so the root packages suite skips it and bin/monorepo test user-agent still runs it. The alternative was adding Matomo to Appwrite's root require-dev just for this test.

There's nothing to hoist, since the package only requires PHP. Appwrite uses it in src/Appwrite/Detector/Detector.php and src/Appwrite/Platform/Workers/StatsUsage.php, and root PHPStan passes on both.

Validation

  • bin/monorepo validate: all packages valid
  • bin/monorepo check user-agent: Rector, Pint, and PHPStan level max all pass
  • bin/monorepo test user-agent: 98 tests / 402 assertions, including the Matomo compatibility tests
  • vendor/bin/phpunit --testsuite packages --filter 'Utopia\\UserAgent\\Tests': 90 tests pass, 2 Matomo tests skipped under the root autoloader
  • vendor/bin/phpunit tests/unit/Detector: pass
  • bin/monorepo split user-agent --dry-run: 6dcb9ede8141e6a5eda4f56b024beb4f21eddb63
  • git diff --check

Merge 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-agent mirror already has the canonical main ruleset (id 19101116), with the split app as an always-bypass actor, so the absorb ran with --skip-ruleset.

After merge: confirm Appwrite's Split pushes to utopia-php/user-agent. Then remove packages/user-agent from utopia-php/monorepo in a follow-up PR. The mirror has no open PRs.

🤖 Generated with Claude Code

loks0n and others added 6 commits July 17, 2026 14:12
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
…2f3428fe8c5'

git-subtree-dir: packages/user-agent
git-subtree-mainline: 7316872
git-subtree-split: 0396bd6
@loks0n loks0n added the absorb History-preserving package absorption; merge commit required label Sep 23, 2026
@loks0n loks0n self-assigned this Sep 23, 2026
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The PR is not ready to merge because the existing repository-rule violation prohibiting newly added regular-expression parsing remains unresolved.

Fix All in Claude CodeFindings

  1. P2 Prohibited regex-based parsing ▶
  2. P2 Tests mirror Matomo internals ▶
Fix with agent prompt
### Issue 1
packages/user-agent/src/Detection/ClientDetector.php:undefined-57
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.

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!

### Issue 2
packages/user-agent/tests/MatomoCompatibilityTest.php:58-79
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.

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!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR absorbs utopia-php/user-agent into packages/user-agent, wires its namespaces into the root Composer autoloader, and replaces the external package dependency with the local package.

  • Imports the user-agent parser, detector classes, tests, package metadata, and mirror workflow.
  • Removes utopia-php/user-agent from the root dependency lock and declares the local package as its replacement.
  • Adds package-level PHPStan, PHPUnit, Rector, and benchmark configuration.
  • No PR-authored code changed after the previous review; the head only merged the updated base branch.

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

];

foreach ($blink as $pattern => [$code, $name]) {
if (preg_match($pattern, $userAgent, $matches) === 1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Fix in Claude Code Fix in Codex

Comment on lines +58 to +79
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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)

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!

Fix in Claude Code Fix in Codex

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/absorb-user-agent (after).

Metric Before After Change
🚀 Requests/sec 191.71 193.7 ⚪ +1%
⏱️ Latency P50 88.18 ms 88.47 ms ⚪ +0.3%
⏱️ Latency P95 220.98 ms 207.38 ms 🟢 -6.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 88.47 207.38 12,369 193.7 -13.61
Account 166.18 340.1 651 10.8 -8.24
TablesDB 86.14 169.18 6,727 107.77 -6.38
Storage 80.15 171.66 3,255 53.54 -5.47
Functions 126.02 256.67 1,736 29.17 -11.16

Top API waits (after)

API request Max wait (ms)
functions.variables.update 532.27
account.name.update 512.82
account.prefs.update 428.64
tablesdb.rows.delete 422.26
tablesdb.rows.increment 420.87

@loks0n
loks0n merged commit d974af3 into main Sep 23, 2026
66 of 117 checks passed
@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Squash-merged, so the subtree annotation was dropped and Split was rejected by the mirror (non-fast-forward). Fix: #13864 restores the annotation; split verified locally to fast-forward onto 0396bd6. Blocked on that until the mirror push is confirmed.

loks0n added a commit that referenced this pull request Sep 23, 2026
#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]>
@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Resolved by #13864 (admin-merged). Split run pushed utopia-php/user-agent main to fb88bd8, a fast-forward on 0396bd6. Remaining: remove packages/user-agent from utopia-php/monorepo.

@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Retired from the monorepo in utopia-php/monorepo#340. Its Split run no longer includes user-agent, and the mirror stays at fb88bd8. The migration is complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

absorb History-preserving package absorption; merge commit required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants