Skip to content

Conversation

abnegate
Copy link
Member

@abnegate abnegate commented Sep 29, 2025

Summary by CodeRabbit

  • New Features

    • Added MongoDB transactions, sessions, and causal consistency support.
    • New bulk and aggregation operations (e.g., multi-insert, aggregation).
    • Upgraded authentication to SCRAM-SHA-256 for stronger security.
    • Enhanced error handling with richer classifications and clearer messages.
  • Tests

    • Introduced comprehensive transaction/session test suite and updated existing tests.
  • Chores

    • Simplified CI workflows and switched quality checks.
    • Broadened dependency version ranges.
    • Updated Docker setup, including MongoDB 8 image.
  • Style

    • Minor Dockerfile formatting improvements.

Copy link
Contributor

coderabbitai bot commented Sep 29, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Updates CI workflows and Docker config, revises composer scripts and dependency ranges, upgrades Mongo auth to SCRAM-SHA-256, introduces a new exception hierarchy, and significantly extends Client with sessions, transactions, concerns, and causal consistency. Adds extensive transaction tests and minor test adjustments.

Changes

Cohort / File(s) Summary
CI workflows
.github/workflows/codeql-analysis.yml, .github/workflows/tests.yml
CodeQL step now runs composer check instead of analyse. Tests workflow removes PHP matrix and related variable usage, running a single PHP context.
Composer config
composer.json
Renames script to check; PHPStan now max level with memory limit and scoped to src. Broadens require and require-dev versions to wildcard ranges.
Docker environment
docker-compose.yml, php83.Dockerfile
tests service now references php${PHP_VERSION:-83}.Dockerfile; Mongo image updated to mongo:8. Dockerfile stage alias casing normalized to AS.
Auth (SCRAM)
src/Auth.php
Switches SCRAM-SHA-1 to SCRAM-SHA-256 across hashing/HMAC and mechanism name; alters challenge flow to always generate response; encodeCredentials now returns raw password and is exposed as public static.
Client sessions/transactions
src/Client.php
Adds sessions, transactions, read/write/readConcern handling, causal consistency, command option plumbing, response parsing, retry helpers, connection lifecycle, and many new public methods (e.g., startSession, withTransaction, insertMany, aggregate, commit/abort, close).
Error handling
src/Exception.php
Introduces base Mongo exception with labels, write errors, categorization APIs; adds specialized subclasses (Connection, Authentication, Transaction, BulkWrite with result accessor).
Tests
tests/MongoTest.php, tests/TransactionTest.php
Minor constructor/options tweaks in MongoTest. New TransactionTest covering sessions, transactions, concerns, causal consistency, CRUD in transactions, and cleanup; skips when no replica set.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Test as Test/Caller
    participant Client as Client
    participant Server as MongoDB

    Test->>Client: startSession(options)
    Client->>Server: send { startSession }
    Server-->>Client: { id, clusterTime }
    Client->>Client: track session, cluster/operation time

    Test->>Client: withTransaction(session, callback, opts)
    Client->>Server: send { startTransaction } (session, writeConcern, readConcern?)
    alt callback succeeds
        Client->>Server: send CRUD ops (session, txnNumber)
        Client->>Server: send { commitTransaction }
        Server-->>Client: { ok } or UnknownCommitResult
        alt UnknownCommitResult
            Client->>Server: retry commit
        end
    else transient error
        Client->>Client: detect TransientTransactionError
        Client->>Server: abort or retry whole withTransaction
    end
    Client-->>Test: result

    note over Client: Updates causal consistency (operationTime, clusterTime) from replies
Loading
sequenceDiagram
    autonumber
    participant Client as Client
    participant Server as MongoDB

    Client->>Server: auth SASLStart (SCRAM-SHA-256)
    Server-->>Client: challenge
    Client->>Server: SASLContinue (generateResponse with sha256/hmac-sha256)
    Server-->>Client: success
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60–90 minutes

Possibly related PRs

  • Feat mongo transactions #20 — Also adds session/transaction support in Client, overlapping with new methods and flow.
  • Upsert #19 — Overlapping Client changes around insert logic and BSON handling.

Poem

A rabbit taps the cluster’s door,
With SCRAMs of 256—not 1—no more.
It starts a dance of tidy commits,
Retries, concerns, and causal bits.
Sessions bloom, exceptions sing,
“All tests in step!”—thump goes the spring. 🐇✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-client-updates

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1363598 and 85a806b.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • .github/workflows/codeql-analysis.yml (1 hunks)
  • .github/workflows/tests.yml (0 hunks)
  • composer.json (1 hunks)
  • docker-compose.yml (2 hunks)
  • php83.Dockerfile (2 hunks)
  • src/Auth.php (10 hunks)
  • src/Client.php (19 hunks)
  • src/Exception.php (1 hunks)
  • tests/MongoTest.php (3 hunks)
  • tests/TransactionTest.php (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

@abnegate abnegate marked this pull request as ready for review September 30, 2025 09:35
@abnegate abnegate merged commit b9c9c2e into main Sep 30, 2025
2 of 4 checks passed
@abnegate abnegate deleted the feat-client-updates branch September 30, 2025 09:36
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.

1 participant