• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / INS-WebPortal / 23947356214

03 Apr 2026 01:11PM UTC coverage: 9.056% (+6.6%) from 2.453%
23947356214

Pull #529

github

web-flow
Merge 7f84494b9 into 246148ece
Pull Request #529: 3.3.0 Release

244 of 1858 branches covered (13.13%)

Branch coverage included in aggregate %.

125 of 217 new or added lines in 28 files covered. (57.6%)

6 existing lines in 6 files now uncovered.

227 of 3343 relevant lines covered (6.79%)

29.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/src/utils/datasetUtils.js
1
import DATASET_ID_MAP from '../config/datasetIdMigrationConfig';
2

3
/**
4
 * Defines the maximum number of hops allowed to follow migration chains.
5
 * If a specific ID changes more than this number of times, the migration
6
 * will be aborted.
7
 *
8
 * @type {number}
9
 */
10
const DEFAULT_MAX_HOPS = 5;
2✔
11

12
/**
13
 * Builds a migration map from an array of migration edges.
14
 * @param {Array<[string, string]>} migrationEdges An array of tuples representing migration edges.
15
 * @returns {Map<string, string>} A map of migration edges.
16
 */
17
const buildMigrationMap = (migrationEdges) => {
2✔
18
  /** @type {Map<string, string>} */
19
  const map = new Map();
16✔
20

21
  migrationEdges.forEach((edge) => {
16✔
22
    if (!Array.isArray(edge) || edge.length !== 2) {
616✔
23
      throw new Error('datasetIdMigrationConfig entries must be [fromId, toId] tuples.');
2✔
24
    }
25

26
    const [from, to] = edge;
614✔
27
    if (!from || !to) {
614✔
28
      throw new Error('datasetIdMigrationConfig entries must contain non-empty from/to values.');
2✔
29
    }
30

31
    if (map.has(from)) {
612✔
32
      throw new Error(`Duplicate migration source detected for "${from}".`);
2✔
33
    }
34

35
    map.set(from, to);
610✔
36
  });
37

38
  return map;
10✔
39
};
40

41
/**
42
 * A utility function to migrate old dataset IDs to the latest dataset UUID.
43
 * It handles multi-hop migrations and detects cycles or excessive hops to prevent infinite loops.
44
 *
45
 * @param {string} incomingId The dataset ID to migrate, if applicable.
46
 * @returns {{ originalId: string, migratedId: string }} An object containing the mapping result.
47
 */
48
const migrateDatasetId = (incomingId) => {
2✔
49
  try {
20✔
50
    if (!incomingId || typeof incomingId !== 'string') {
20✔
51
      throw new Error('Invalid dataset ID provided for migration.');
4✔
52
    }
53

54
    const migrationMap = buildMigrationMap(DATASET_ID_MAP);
16✔
55
    const visited = new Set([incomingId]);
10✔
56
    let current = incomingId;
10✔
57
    let hops = 0;
10✔
58

59
    while (migrationMap.has(current)) {
10✔
60
      if (hops >= DEFAULT_MAX_HOPS) {
24✔
61
        throw new Error(`Migration chain exceeded ${DEFAULT_MAX_HOPS} hops from "${incomingId}".`);
2✔
62
      }
63

64
      const next = migrationMap.get(current);
22✔
65
      if (typeof next !== 'string') {
22!
NEW
66
        break;
×
67
      }
68

69
      if (visited.has(next)) {
22✔
70
        throw new Error(`Cycle detected in dataset ID migrations at "${next}".`);
2✔
71
      }
72

73
      visited.add(next);
20✔
74
      current = next;
20✔
75
      hops += 1;
20✔
76
    }
77

78
    return { originalId: incomingId, migratedId: current };
6✔
79
  } catch (error) {
80
    console.error('Failed to migrate dataset ID:', error);
14✔
81
    return { originalId: incomingId, migratedId: incomingId };
14✔
82
  }
83
};
84

85
export default migrateDatasetId;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc