Skip to content

Conversation

@h3n4l
Copy link
Member

@h3n4l h3n4l commented Jan 23, 2026

Summary

  • Add comprehensive Unicode support tests for field names and values
  • Add JavaScript function parsing tests for $function and $accumulator operators

Test Coverage

Unicode Support (TestUnicodeSupport)

  • Field values: emoji, Hindi, Chinese, Korean, Japanese, Arabic RTL, European special characters, math/currency symbols
  • Field names: emoji, Hindi, Chinese, Korean field names
  • Queries: filter by Unicode values, regex with Unicode
  • Aggregation: $match, $group, $project with Unicode data

JavaScript Function Parsing (TestAggregateJavaScriptFunctionParsing)

  • $function operator: simple functions, multiple arguments, conditional logic, array operations, use in $match via $expr
  • $accumulator operator: basic accumulator, with finalize, with initArgs, multiple accumulateArgs
  • Special characters in JS body: escaped quotes, single quotes, regex

Test plan

  • All 39 new test cases pass
  • Existing tests unaffected
  • Linter passes

🤖 Generated with Claude Code

Add comprehensive test coverage for:
- Unicode support in field names and values (emoji, Hindi, Chinese,
  Korean, Japanese, Arabic, European special characters)
- Unicode in queries and aggregation pipelines
- $function operator parsing with various JS function patterns
- $accumulator operator parsing with init, accumulate, merge, finalize

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Copilot AI review requested due to automatic review settings January 23, 2026 08:06
@h3n4l h3n4l closed this Jan 23, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds comprehensive test coverage for Unicode support and JavaScript function parsing in MongoDB shell command execution. The tests verify that the parser correctly handles Unicode characters in field names and values, as well as JavaScript code in aggregation operators.

Changes:

  • Add 31 Unicode support test cases covering emoji, Hindi, Chinese, Korean, Japanese, Arabic, and special characters in field values, field names, queries, and aggregation operations
  • Add 8 JavaScript function parsing test cases for $function and $accumulator operators with various JavaScript code patterns including conditionals, array operations, and special characters

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

require.Contains(t, result.Rows[0], `"acknowledged": true`)

// Verify the data was stored correctly by querying it back
findStmt := `db.unicode.findOne({` + tt.checkKey + `: "` + tt.checkVal + `"})`
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

String concatenation is used to build the query, which could be fragile if the Unicode values contain special characters like quotes or backslashes that need escaping. Consider using a more robust approach to build the findOne query, such as using a template or ensuring proper escaping of the Unicode values before concatenation.

Copilot uses AI. Check for mistakes.
require.Contains(t, result.Rows[0], `"acknowledged": true`)

// Query using unicode field name
findStmt := `db.unicode_fields.findOne({"` + tt.fieldName + `": "` + tt.fieldVal + `"})`
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

String concatenation is used to build the query with Unicode field names, which could be fragile if the Unicode values contain special characters like quotes or backslashes that need escaping. Consider using a more robust approach to build the findOne query or ensuring proper escaping of the Unicode values before concatenation.

Copilot uses AI. Check for mistakes.
Comment on lines +2631 to +2637
if err != nil {
// MongoDB returns "JavaScript execution is disabled" or similar
// when JS is disabled, which is fine - it means parsing succeeded.
errStr := err.Error()
require.NotContains(t, errStr, "parse", "statement should parse without errors")
require.NotContains(t, errStr, "syntax", "statement should have valid syntax")
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

The error checking logic only verifies that parse-related error strings are absent when an error occurs, but doesn't verify the actual success case. This approach is fragile because it assumes any non-parse error means parsing succeeded. Consider using more explicit error type checking (like checking for gomongo.ParseError) or documenting this behavior more clearly if this is intentional for testing parsing when JavaScript execution may be disabled.

Copilot uses AI. Check for mistakes.
Comment on lines +2723 to +2727
if err != nil {
errStr := err.Error()
require.NotContains(t, errStr, "parse", "statement should parse without errors")
require.NotContains(t, errStr, "syntax", "statement should have valid syntax")
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

The error checking logic only verifies that parse-related error strings are absent when an error occurs, but doesn't verify the actual success case. This approach is fragile because it assumes any non-parse error means parsing succeeded. Consider using more explicit error type checking (like checking for gomongo.ParseError) or documenting this behavior more clearly if this is intentional for testing parsing when JavaScript execution may be disabled.

Copilot uses AI. Check for mistakes.
Comment on lines +2798 to +2802
if err != nil {
errStr := err.Error()
require.NotContains(t, errStr, "parse", "statement should parse without errors")
require.NotContains(t, errStr, "syntax", "statement should have valid syntax")
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

The error checking logic only verifies that parse-related error strings are absent when an error occurs, but doesn't verify the actual success case. This approach is fragile because it assumes any non-parse error means parsing succeeded. Consider using more explicit error type checking (like checking for gomongo.ParseError) or documenting this behavior more clearly if this is intentional for testing parsing when JavaScript execution may be disabled.

Copilot uses AI. Check for mistakes.
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