Text attributes data truncation#893
Conversation
|
Warning Review limit reached
More reviews will be available in 27 minutes and 2 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThree new ChangesByte-safe TEXT validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
tests/unit/Validator/StructureTest.php (2)
412-413: 💤 Low valueMinor: Multibyte test lacks error message assertion.
For consistency with the ASCII overflow test on line 409, consider asserting the error message for the multibyte test as well.
🔍 Add assertion for consistency
// Multi-byte content over the limit is rejected the same way. $multibyte = \str_repeat('📝', 20000); $this->assertEquals(false, $validator->isValid(new Document($base + ['blocks_json' => $multibyte]))); + $this->assertEquals('Invalid document structure: Attribute "blocks_json" has invalid type. Value must be a valid string and no longer than 16383 chars', $validator->getDescription());🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/Validator/StructureTest.php` around lines 412 - 413, The multibyte overflow test starting at the line with str_repeat and '📝' is missing an assertion for the error message, unlike the ASCII overflow test on line 409. After the assertEquals call that validates isValid returns false for the multibyte Document, add an additional assertion to check the error message returned by the validator, following the same pattern as the ASCII overflow test for consistency.
995-1047: 💤 Low valueConsider adding test case for byte-safe limit edge.
While
testTextByteSafeValidationcomprehensively tests the 16,383-character byte-safe limit for legacy attributes,testTextValidationcould benefit from a similar edge-case test. Currently it tests 16,383 chars (pass) and 65,536 chars (fail due to declared size), but doesn't verify that 16,384 chars would fail due to the byte-safe limit.🧪 Optional test case to add
Add this test case between the existing assertions to verify byte-safe enforcement:
$this->assertEquals(false, $validator->isValid(new Document([ '$collection' => ID::custom('posts'), 'title' => 'Demo Title', 'description' => 'Demo description', 'rating' => 5, 'price' => 1.99, 'published' => true, 'tags' => ['dog', 'cat', 'mouse'], 'feedback' => 'team@appwrite.io', 'text_field' => \str_repeat('a', 16384), '$createdAt' => '2000-04-01T12:00:00.000+00:00', '$updatedAt' => '2000-04-01T12:00:00.000+00:00' ]))); $this->assertEquals('Invalid document structure: Attribute "text_field" has invalid type. Value must be a valid string and no longer than 16383 chars', $validator->getDescription());🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/Validator/StructureTest.php` around lines 995 - 1047, The testTextValidation method should include an additional test case to verify the byte-safe character limit edge case. Add a new assertion between the existing test cases that validates a Document with text_field set to \str_repeat('a', 16384) should fail (assertEquals false), and verify the corresponding error message from getDescription indicates the byte-safe limit of 16383 characters, similar to the pattern already established in the method with the 65536 character test case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Database/Database.php`:
- Around line 118-121: The MAX_LONGTEXT_BYTES constant in the Database class is
set to a value that exceeds the 32-bit signed integer maximum, causing it to be
converted to a float in 32-bit PHP environments. This breaks the intdiv call in
downstream code that expects integer arguments. Fix this by explicitly casting
MAX_LONGTEXT_BYTES to int using the (int) type cast operator to ensure it
remains an integer on all PHP platforms, including 32-bit environments.
---
Nitpick comments:
In `@tests/unit/Validator/StructureTest.php`:
- Around line 412-413: The multibyte overflow test starting at the line with
str_repeat and '📝' is missing an assertion for the error message, unlike the
ASCII overflow test on line 409. After the assertEquals call that validates
isValid returns false for the multibyte Document, add an additional assertion to
check the error message returned by the validator, following the same pattern as
the ASCII overflow test for consistency.
- Around line 995-1047: The testTextValidation method should include an
additional test case to verify the byte-safe character limit edge case. Add a
new assertion between the existing test cases that validates a Document with
text_field set to \str_repeat('a', 16384) should fail (assertEquals false), and
verify the corresponding error message from getDescription indicates the
byte-safe limit of 16383 characters, similar to the pattern already established
in the method with the 65536 character test case.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 338e4613-aa3d-423d-af38-75776ac9f9df
📒 Files selected for processing (4)
src/Database/Database.phpsrc/Database/Validator/Structure.phptests/e2e/Adapter/Scopes/DocumentTests.phptests/unit/Validator/StructureTest.php
Greptile Summary
Confidence Score: 5/5The change is narrowly scoped to text attribute capacity validation and includes targeted coverage for creation, validation, and update paths. No review comments were identified, and the implementation is backed by tests covering multibyte byte-length boundaries and adapter limit references.
What T-Rex did
Reviews (8): Last reviewed commit: "messages" | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
tests/unit/Validator/StructureTest.php (1)
441-445: ⚡ Quick winAssert the exact failure reason in the multibyte overflow test.
This test currently validates only
false; asserting the description too will lock the byte-limit contract and catch regressions in failure source.Suggested test hardening
$multibyte = \str_repeat('📝', 20000); $this->assertEquals(false, $validator->isValid(new Document($base + ['text' => $multibyte]))); +$this->assertEquals( + 'Invalid document structure: Attribute "text" has invalid type. Value must be a valid string no longer than 65535 bytes', + $validator->getDescription() +);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/Validator/StructureTest.php` around lines 441 - 445, The multibyte overflow test in the test method currently only asserts that the validator returns false but does not verify the specific failure reason. Strengthen this test by adding an additional assertion that checks the failure description or error message from the validator after the isValid call with the multibyte document. This will ensure that the specific byte-limit contract is properly validated and catch any regressions where the failure source changes. Reference the validator's method to retrieve the error description (commonly methods like getError, getFailureDescription, or similar) to assert the expected error message alongside the false result.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@phpunit.xml`:
- Line 10: The stopOnFailure attribute in the phpunit.xml configuration is set
to "true", which causes the test suite to halt immediately upon encountering the
first failure. This masks subsequent failures and reduces diagnostic value in CI
environments. Change stopOnFailure from "true" to "false" to allow the full test
suite to execute and report all failures in a single run, providing better
visibility into the overall test health.
In `@src/Database/Validator/ByteLength.php`:
- Line 53: The file is missing a trailing newline at the end of the file, which
violates PSR-12 standards that require a single blank line at the end of every
file. Add a single newline character after the closing brace at the end of the
ByteLength.php file to satisfy the Pint code style checker and resolve the
single_blank_line_at_eof CI failure.
In `@tests/e2e/Adapter/Base.php`:
- Around line 26-27: Uncomment the two trait usage statements in the Base class
by removing the leading // from the lines containing CollectionTests and
CustomDocumentTypeTests. These commented-out trait usages need to be re-enabled
so that their test methods are included in the test discovery and execution,
restoring the full E2E coverage that these traits provide to the adapter tests.
---
Nitpick comments:
In `@tests/unit/Validator/StructureTest.php`:
- Around line 441-445: The multibyte overflow test in the test method currently
only asserts that the validator returns false but does not verify the specific
failure reason. Strengthen this test by adding an additional assertion that
checks the failure description or error message from the validator after the
isValid call with the multibyte document. This will ensure that the specific
byte-limit contract is properly validated and catch any regressions where the
failure source changes. Reference the validator's method to retrieve the error
description (commonly methods like getError, getFailureDescription, or similar)
to assert the expected error message alongside the false result.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7d8392e1-0183-4343-9aef-8defb270cf4f
📒 Files selected for processing (6)
phpunit.xmlsrc/Database/Validator/ByteLength.phpsrc/Database/Validator/Structure.phptests/e2e/Adapter/Base.phptests/e2e/Adapter/Scopes/DocumentTests.phptests/unit/Validator/StructureTest.php
| private const MARIADB_TEXT_BYTES = '' . Database::MAX_TEXT_BYTES; | ||
| private const MARIADB_MEDIUMTEXT_BYTES = '' . Database::MAX_MEDIUMTEXT_BYTES; | ||
| private const MARIADB_LONGTEXT_BYTES = '' . Database::MAX_LONGTEXT_BYTES; |
| case Database::VAR_LONGTEXT: | ||
| $validators[] = new Text($size, min: 0); | ||
| $validators[] = new ByteLength(Database::MAX_LONGTEXT_BYTES); | ||
| break; |
Summary by CodeRabbit
Release Notes
New Features
Tests