fix(treatments): correct UUID handling scope (only _id field)

REQ-SYNC-072 scope correction: normalizeTreatmentId() should ONLY
handle UUID values in the _id field, not copy syncIdentifier or uuid
fields to identifier.

Changes:
- normalizeTreatmentId(): Only extract UUID from _id to identifier
- normalizeEntryId(): Same fix for entries collection
- upsertQueryFor(): Add syncIdentifier and uuid as dedup fallbacks
  (fields are preserved, not copied to identifier)
- Batch POST: Fetch _id for docs deduped by syncIdentifier/uuid

Test updates:
- TEST-ID-003, TEST-V1-ID-004: Updated to expect identifier NOT copied
  from syncIdentifier (scope fix)

Affected clients:
- Loop overrides (UUID _id → identifier): Still works
- Loop carbs/doses (syncIdentifier): Dedup works, no identifier copy
- xDrip+ (uuid): Dedup works, no identifier copy
- AAPS (identifier): Unchanged

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Ben West
2026-03-17 15:21:25 -07:00
co-authored by Copilot
parent 013e7b6efd
commit 8fc155aa48
3 changed files with 76 additions and 48 deletions
+11 -9
View File
@@ -146,16 +146,17 @@ describe('Identity Field Test Matrix', function() {
const created = res.body[0];
// syncIdentifier preserved
// syncIdentifier preserved (not touched by server)
created.syncIdentifier.should.equal(syncId);
// _id generated as ObjectId
created._id.should.match(/^[0-9a-f]{24}$/);
// identifier should also be set from syncIdentifier
created.identifier.should.equal(syncId);
// identifier should NOT be set from syncIdentifier (scope fix)
// Server only handles UUID _id, not syncIdentifier field
should.not.exist(created.identifier);
console.log(' ✓ syncIdentifier identifier, ObjectId generated');
console.log(' ✓ syncIdentifier preserved, identifier NOT copied (scope fix)');
done();
});
});
@@ -362,7 +363,7 @@ describe('Identity Field Test Matrix', function() {
});
});
it('TEST-V1-ID-004: syncIdentifier copied to identifier', function(done) {
it('TEST-V1-ID-004: syncIdentifier NOT copied to identifier (scope fix)', function(done) {
const syncId = 'sync-id-' + Date.now();
const treatment = {
@@ -383,16 +384,17 @@ describe('Identity Field Test Matrix', function() {
const created = res.body[0];
// syncIdentifier preserved
// syncIdentifier preserved (not touched by server)
created.syncIdentifier.should.equal(syncId);
// identifier should match
created.identifier.should.equal(syncId);
// identifier should NOT be set from syncIdentifier (scope fix)
// Server only handles UUID _id, not syncIdentifier field
should.not.exist(created.identifier);
// _id generated
created._id.should.match(/^[0-9a-f]{24}$/);
console.log(' ✓ syncIdentifier identifier');
console.log(' ✓ syncIdentifier preserved, identifier NOT copied (scope fix)');
done();
});
});