Skip to content

Conversation

@RIT3shSapata
Copy link
Contributor

CBG-5089

Describe your PR here...

  • Added ability for user to pass the user defined xattrs into Sync Function Diagnostic API
  • Added test coverage for the same

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

@RIT3shSapata RIT3shSapata requested a review from bbrks January 14, 2026 10:56
Copilot AI review requested due to automatic review settings January 14, 2026 10:56
Copy link
Contributor

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 PR adds support for user-defined metadata (xattrs) in the Sync Function Diagnostic API, allowing users to test sync functions with custom xattr values. The changes enable passing user xattrs through the API request payload or reading them from existing documents in the database.

Changes:

  • Added Meta field to SyncFnDryRunPayload to accept user-defined xattrs in API requests
  • Updated SyncFnDryrun method signature to accept and process user metadata
  • Changed userXattrKey() from private to public UserXattrKey() method across multiple files
  • Added comprehensive test coverage for user xattr scenarios in diagnostic API

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
rest/diagnostic_doc_api.go Added Meta field to payload struct and validation logic for user xattrs
rest/diagnostic_doc_api_test.go Added test cases for user xattr handling and updated test setup for xattr support
db/crud.go Updated SyncFnDryrun signature to accept userMeta parameter and apply it when provided
db/database_collection.go Changed userXattrKey() to public UserXattrKey() method
db/database.go Updated userXattrKey() call to UserXattrKey()
db/import.go Updated userXattrKey() calls to UserXattrKey()
db/import_listener.go Updated userXattrKey() calls to UserXattrKey()
db/change_cache.go Updated userXattrKey() calls to UserXattrKey()
db/background_mgr_attachment_migration.go Updated userXattrKey() call to UserXattrKey()

Copy link
Member

@bbrks bbrks left a comment

Choose a reason for hiding this comment

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

Probably move the user xattr test cases to a test that is testing that specific sub-feature, so all the other tests can still run in CE mode.

@RIT3shSapata RIT3shSapata requested a review from bbrks January 16, 2026 10:20
Copy link
Member

@bbrks bbrks left a comment

Choose a reason for hiding this comment

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

Need a bit more validation around the meta object being passed into the request really. See inline.

}

// checking user defined metadata
if syncDryRunPayload.Meta != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't ensuring there's nothing else set in the map (e.g. meta.foo)

I think that's mostly why I prefer the struct approach, though it also makes access easier since there's less type assertions too:

	Meta *SyncFnDryRunMeta `json:"meta,omitempty"`
}

type SyncFnDryRunMeta struct {
	Xattrs map[string]any `json:"xattrs,omitempty"`
}

We'd also need to length-check the Xattrs map to ensure only exactly 1 (matching) key is present as well - it's too easy to unintentionally pass extra data into the sync function otherwise that wouldn't be available in the real one.

e.g.

meta.xattrs[my_user_xattr_key]={"my_xattr_data":true}
meta.xattrs[bar]="buzz"

dry run could technically still be able to access meta.xattrs.bar despite not being available in a real sync function.

@bbrks bbrks assigned RIT3shSapata and unassigned bbrks Jan 16, 2026
@RIT3shSapata RIT3shSapata requested a review from bbrks January 16, 2026 12:15
Copy link
Contributor

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

}

type SyncFnDryRunMetaMap struct {
Xatrrs map[string]any `json:"xatrrs"`
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

Typo in field name: 'Xatrrs' should be 'Xattrs'.

Suggested change
Xatrrs map[string]any `json:"xatrrs"`
Xattrs map[string]any `json:"xattrs"`

Copilot uses AI. Check for mistakes.
Doc: db.Body{
"foo": "bar",
},
Meta: SyncFnDryRunMetaMap{Xatrrs: map[string]any{"channelXattr": []string{"channel1", "channel3", "useradmin"}}},
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

Typo in field name: 'Xatrrs' should be 'Xattrs'.

Suggested change
Meta: SyncFnDryRunMetaMap{Xatrrs: map[string]any{"channelXattr": []string{"channel1", "channel3", "useradmin"}}},
Meta: SyncFnDryRunMetaMap{Xattrs: map[string]any{"channelXattr": []string{"channel1", "channel3", "useradmin"}}},

Copilot uses AI. Check for mistakes.
@RIT3shSapata RIT3shSapata requested a review from bbrks January 16, 2026 14:03
@RIT3shSapata RIT3shSapata removed their assignment Jan 16, 2026
@RIT3shSapata RIT3shSapata merged commit 432b8a0 into main Jan 16, 2026
61 of 62 checks passed
@RIT3shSapata RIT3shSapata deleted the CBG-5089 branch January 16, 2026 14:17
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.

3 participants