-
Notifications
You must be signed in to change notification settings - Fork 11
Fix typo #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request introduces critical bugs by replacing async file operations with synchronous ones in an async test context. The change from fs.readFile to readFileSync breaks the async/await pattern and may cause the test to fail or behave unexpectedly. Additionally, the imports are incorrectly changed to use the synchronous version when the async version should be used instead.
PR Bot Information
Version: 1.17.30 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback
- LLM:
anthropic--claude-4.5-sonnet - Event Trigger:
pull_request.opened - Correlation ID:
a7362130-f78c-11f0-913b-2702c5543764
| const cds = require('@sap/cds'); | ||
| const path = require("path") | ||
| const app = path.join(__dirname, "../incidents-app") | ||
| const { readFileSync } = cds.utils.fs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: readFileSync import should be readFile for async usage
Since this is an async test function (line 13 uses async), the synchronous readFileSync is inappropriate. Import the async readFile instead to maintain proper async/await patterns.
| const { readFileSync } = cds.utils.fs | |
| const { readFile } = cds.utils.fs |
Double-check suggestion before committing. Edit this comment for amendments.
Please provide feedback on the review comment by checking the appropriate box:
- 🌟 Awesome comment, a human might have missed that.
- ✅ Helpful comment
- 🤷 Neutral
- ❌ This comment is not helpful
| const fileContent = readFileSync( | ||
| join(__dirname, "..", "integration", 'content/sample.pdf') | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: readFileSync used in async context without encoding causes test failure
The change from fs.readFile (async) to readFileSync (sync) introduces two problems:
readFileSyncis synchronous but not awaited, creating inconsistent async patterns- Without an encoding parameter,
readFileSyncreturns a Buffer, which may not match the expected type for axios.put
The original async pattern with fs.readFile was correct for a test using async/await.
| const fileContent = readFileSync( | |
| join(__dirname, "..", "integration", 'content/sample.pdf') | |
| ) | |
| const fileContent = await cds.utils.fs.readFile( | |
| join(__dirname, "..", "integration", 'content/sample.pdf') | |
| ) |
Double-check suggestion before committing. Edit this comment for amendments.
Please provide feedback on the review comment by checking the appropriate box:
- 🌟 Awesome comment, a human might have missed that.
- ✅ Helpful comment
- 🤷 Neutral
- ❌ This comment is not helpful
Refactor: Replace Node.js Built-in Modules with CDS Utils
♻️ Refactor: Migrated from Node.js built-in modules (
path,fs/promises) to CDS utility functions for improved consistency with the SAP CAP framework.Changes
tests/unit/validateAttachmentSize.test.js:pathmodule withcds.utils.pathfor path operationsfs/promisesmodule withcds.utils.fsfor file system operationsreadFiletoreadFileSyncfor synchronous file readingpath.jointojoinfrom CDS utilitiesBenefits
✅ Better alignment with SAP CAP best practices
✅ Consistent API usage across the codebase
✅ Reduced direct dependency on Node.js built-in modules