Skip to content

Conversation

@KoblerS
Copy link
Collaborator

@KoblerS KoblerS commented Jan 22, 2026

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:
    • Replaced path module with cds.utils.path for path operations
    • Replaced fs/promises module with cds.utils.fs for file system operations
    • Updated readFile to readFileSync for synchronous file reading
    • Updated path.join to join from CDS utilities

Benefits

✅ Better alignment with SAP CAP best practices
✅ Consistent API usage across the codebase
✅ Reduced direct dependency on Node.js built-in modules

  • 🔄 Regenerate and Update Summary

@KoblerS KoblerS self-assigned this Jan 22, 2026
@KoblerS KoblerS requested a review from a team as a code owner January 22, 2026 12:19
Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a 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
Copy link
Contributor

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.

Suggested change
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

Comment on lines +21 to 23
const fileContent = readFileSync(
join(__dirname, "..", "integration", 'content/sample.pdf')
)
Copy link
Contributor

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:

  1. readFileSync is synchronous but not awaited, creating inconsistent async patterns
  2. Without an encoding parameter, readFileSync returns 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.

Suggested change
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

@KoblerS KoblerS merged commit b0c0367 into main Jan 22, 2026
16 of 17 checks passed
@KoblerS KoblerS deleted the fix-typo branch January 22, 2026 12:28
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.

2 participants