@elisra-devops/docgen-data-provider 1.94.0 → 1.96.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -194,6 +194,15 @@ export default class ResultDataProvider {
194
194
  * Maps raw test point data to a simplified object.
195
195
  */
196
196
  private mapTestPointForCrossPlans;
197
+ /**
198
+ * Resolves a point timestamp that can be used as WIT `asOf` anchor.
199
+ * Returns an ISO string when a valid date exists, otherwise an empty string.
200
+ */
201
+ private resolvePointAsOfTimestamp;
202
+ /**
203
+ * Builds a normalized test point shape used by downstream result fetch flows.
204
+ */
205
+ private buildMappedTestPoint;
197
206
  getTestPointsForTestCases(projectName: string, testCaseId: string[]): Promise<any>;
198
207
  /**
199
208
  * Fetches test cases by suite ID.
@@ -201,11 +210,29 @@ export default class ResultDataProvider {
201
210
  private fetchTestCasesBySuiteId;
202
211
  private attachSuiteTestCaseContextToPoints;
203
212
  private extractWorkItemFieldsMap;
213
+ /**
214
+ * Reads a field value by reference name with case-insensitive key matching.
215
+ */
204
216
  private getFieldValueByName;
205
217
  private resolveSuiteTestCaseRevision;
206
218
  private buildWorkItemSnapshotFromSuiteTestCase;
207
219
  private fetchWorkItemByRevision;
220
+ private fetchWorkItemByAsOf;
208
221
  private fetchWorkItemLatest;
222
+ /**
223
+ * Executes a work-item GET by URL and applies consistent warning/error handling.
224
+ */
225
+ private fetchWorkItemByUrl;
226
+ /**
227
+ * Returns true when the snapshot includes a non-empty test steps XML payload.
228
+ */
229
+ private hasStepsInWorkItemSnapshot;
230
+ private logRunlessSnapshotDecision;
231
+ /**
232
+ * Resolves runless test case data using ordered fallbacks:
233
+ * 1) point-based `asOf` snapshot, 2) explicit revision, 3) suite payload snapshot, 4) latest WI.
234
+ */
235
+ private resolveRunlessTestCaseData;
209
236
  /**
210
237
  * Fetches result data based on the Work Item Test Reporter.
211
238
  *
@@ -274,7 +274,7 @@ class ResultDataProvider {
274
274
  const planName = await this.fetchTestPlanName(testPlanId, projectName);
275
275
  const suites = await this.fetchTestSuites(testPlanId, projectName, selectedSuiteIds, true);
276
276
  const testData = await this.fetchTestData(suites, projectName, testPlanId, false);
277
- const runResults = await this.fetchAllResultDataTestReporter(testData, projectName, selectedFields, false, includeAllHistory);
277
+ const runResults = await this.fetchAllResultDataTestReporter(testData, projectName, selectedFields, false, includeAllHistory, true);
278
278
  const rows = this.alignStepsWithIterationsFlatReport(testData, runResults, true, testPlanId, planName);
279
279
  return { planId: testPlanId, planName, rows: rows || [] };
280
280
  }
@@ -2548,32 +2548,32 @@ class ResultDataProvider {
2548
2548
  */
2549
2549
  mapTestPoint(testPoint, projectName) {
2550
2550
  var _a, _b, _c, _d, _e;
2551
- return {
2551
+ const pointAsOfTimestamp = this.resolvePointAsOfTimestamp(testPoint);
2552
+ return this.buildMappedTestPoint({
2552
2553
  testPointId: testPoint.id,
2553
2554
  testCaseId: testPoint.testCaseReference.id,
2554
2555
  testCaseName: testPoint.testCaseReference.name,
2555
- testCaseUrl: `${this.orgUrl}${projectName}/_workitems/edit/${testPoint.testCaseReference.id}`,
2556
2556
  configurationName: (_a = testPoint.configuration) === null || _a === void 0 ? void 0 : _a.name,
2557
- outcome: ((_b = testPoint.results) === null || _b === void 0 ? void 0 : _b.outcome) || 'Not Run',
2557
+ outcome: (_b = testPoint.results) === null || _b === void 0 ? void 0 : _b.outcome,
2558
2558
  testSuite: testPoint.testSuite,
2559
2559
  lastRunId: (_c = testPoint.results) === null || _c === void 0 ? void 0 : _c.lastTestRunId,
2560
2560
  lastResultId: (_d = testPoint.results) === null || _d === void 0 ? void 0 : _d.lastResultId,
2561
2561
  lastResultDetails: (_e = testPoint.results) === null || _e === void 0 ? void 0 : _e.lastResultDetails,
2562
- };
2562
+ }, projectName, pointAsOfTimestamp);
2563
2563
  }
2564
2564
  /**
2565
2565
  * Maps raw test point data to a simplified object.
2566
2566
  */
2567
2567
  mapTestPointForCrossPlans(testPoint, projectName) {
2568
2568
  var _a, _b, _c;
2569
- return {
2569
+ const pointAsOfTimestamp = this.resolvePointAsOfTimestamp(testPoint);
2570
+ return this.buildMappedTestPoint({
2570
2571
  testPointId: testPoint.id,
2571
2572
  testCaseId: testPoint.testCase.id,
2572
2573
  testCaseName: testPoint.testCase.name,
2573
- testCaseUrl: `${this.orgUrl}${projectName}/_workitems/edit/${testPoint.testCase.id}`,
2574
- testSuite: testPoint.testSuite,
2575
2574
  configurationName: (_a = testPoint.configuration) === null || _a === void 0 ? void 0 : _a.name,
2576
- outcome: testPoint.outcome || 'Not Run',
2575
+ outcome: testPoint.outcome,
2576
+ testSuite: testPoint.testSuite,
2577
2577
  lastRunId: (_b = testPoint.lastTestRun) === null || _b === void 0 ? void 0 : _b.id,
2578
2578
  lastResultId: (_c = testPoint.lastResult) === null || _c === void 0 ? void 0 : _c.id,
2579
2579
  lastResultDetails: testPoint.lastResultDetails || {
@@ -2581,7 +2581,50 @@ class ResultDataProvider {
2581
2581
  dateCompleted: '0000-00-00T00:00:00.000Z',
2582
2582
  runBy: { displayName: 'No tester', id: '00000000-0000-0000-0000-000000000000' },
2583
2583
  },
2584
+ }, projectName, pointAsOfTimestamp);
2585
+ }
2586
+ /**
2587
+ * Resolves a point timestamp that can be used as WIT `asOf` anchor.
2588
+ * Returns an ISO string when a valid date exists, otherwise an empty string.
2589
+ */
2590
+ resolvePointAsOfTimestamp(testPoint) {
2591
+ const candidates = [
2592
+ testPoint === null || testPoint === void 0 ? void 0 : testPoint.lastUpdatedDate,
2593
+ testPoint === null || testPoint === void 0 ? void 0 : testPoint.lastUpdatedOn,
2594
+ testPoint === null || testPoint === void 0 ? void 0 : testPoint.updatedDate,
2595
+ testPoint === null || testPoint === void 0 ? void 0 : testPoint.updatedOn,
2596
+ ];
2597
+ for (const candidate of candidates) {
2598
+ const raw = String(candidate || '').trim();
2599
+ if (!raw)
2600
+ continue;
2601
+ const parsed = new Date(raw);
2602
+ if (!Number.isNaN(parsed.getTime())) {
2603
+ return parsed.toISOString();
2604
+ }
2605
+ }
2606
+ return '';
2607
+ }
2608
+ /**
2609
+ * Builds a normalized test point shape used by downstream result fetch flows.
2610
+ */
2611
+ buildMappedTestPoint(pointData, projectName, pointAsOfTimestamp) {
2612
+ const mappedPoint = {
2613
+ testPointId: pointData.testPointId,
2614
+ testCaseId: pointData.testCaseId,
2615
+ testCaseName: pointData.testCaseName,
2616
+ testCaseUrl: `${this.orgUrl}${projectName}/_workitems/edit/${pointData.testCaseId}`,
2617
+ configurationName: pointData.configurationName,
2618
+ outcome: pointData.outcome || 'Not Run',
2619
+ testSuite: pointData.testSuite,
2620
+ lastRunId: pointData.lastRunId,
2621
+ lastResultId: pointData.lastResultId,
2622
+ lastResultDetails: pointData.lastResultDetails,
2584
2623
  };
2624
+ if (pointAsOfTimestamp) {
2625
+ mappedPoint.pointAsOfTimestamp = pointAsOfTimestamp;
2626
+ }
2627
+ return mappedPoint;
2585
2628
  }
2586
2629
  // Helper method to get all test points for a test case
2587
2630
  async getTestPointsForTestCases(projectName, testCaseId) {
@@ -2639,6 +2682,9 @@ class ResultDataProvider {
2639
2682
  }
2640
2683
  return fields;
2641
2684
  }
2685
+ /**
2686
+ * Reads a field value by reference name with case-insensitive key matching.
2687
+ */
2642
2688
  getFieldValueByName(fields, fieldName) {
2643
2689
  if (!fields || typeof fields !== 'object')
2644
2690
  return undefined;
@@ -2711,13 +2757,20 @@ class ResultDataProvider {
2711
2757
  return null;
2712
2758
  const expandParam = expandAll ? '?$expand=all' : '';
2713
2759
  const url = `${this.orgUrl}${projectName}/_apis/wit/workItems/${id}/revisions/${rev}${expandParam}`;
2714
- try {
2715
- return await tfs_1.TFSServices.getItemContent(url, this.token);
2716
- }
2717
- catch (error) {
2718
- logger_1.default.warn(`Failed to fetch work item ${id} by revision ${rev}: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
2760
+ return this.fetchWorkItemByUrl(url, `work item ${id} by revision ${rev}`);
2761
+ }
2762
+ async fetchWorkItemByAsOf(projectName, workItemId, asOfTimestamp, expandAll = false) {
2763
+ const id = Number(workItemId || 0);
2764
+ const parsedAsOf = new Date(String(asOfTimestamp || '').trim());
2765
+ if (!Number.isFinite(id) || id <= 0 || Number.isNaN(parsedAsOf.getTime()))
2719
2766
  return null;
2767
+ logger_1.default.debug(`[RunlessResolver] Fetching work item ${id} by asOf (raw="${String(asOfTimestamp || '')}", normalized="${parsedAsOf.toISOString()}", expandAll=${String(expandAll)})`);
2768
+ const query = [`asOf=${encodeURIComponent(parsedAsOf.toISOString())}`];
2769
+ if (expandAll) {
2770
+ query.push(`$expand=all`);
2720
2771
  }
2772
+ const url = `${this.orgUrl}${projectName}/_apis/wit/workItems/${id}?${query.join('&')}`;
2773
+ return this.fetchWorkItemByUrl(url, `work item ${id} by asOf ${parsedAsOf.toISOString()}`);
2721
2774
  }
2722
2775
  async fetchWorkItemLatest(projectName, workItemId, expandAll = false) {
2723
2776
  const id = Number(workItemId || 0);
@@ -2725,14 +2778,77 @@ class ResultDataProvider {
2725
2778
  return null;
2726
2779
  const expandParam = expandAll ? '?$expand=all' : '';
2727
2780
  const url = `${this.orgUrl}${projectName}/_apis/wit/workItems/${id}${expandParam}`;
2781
+ return this.fetchWorkItemByUrl(url, `latest work item ${id}`);
2782
+ }
2783
+ /**
2784
+ * Executes a work-item GET by URL and applies consistent warning/error handling.
2785
+ */
2786
+ async fetchWorkItemByUrl(url, failureContext) {
2728
2787
  try {
2729
2788
  return await tfs_1.TFSServices.getItemContent(url, this.token);
2730
2789
  }
2731
2790
  catch (error) {
2732
- logger_1.default.warn(`Failed to fetch latest work item ${id}: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
2791
+ logger_1.default.warn(`Failed to fetch ${failureContext}: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
2733
2792
  return null;
2734
2793
  }
2735
2794
  }
2795
+ /**
2796
+ * Returns true when the snapshot includes a non-empty test steps XML payload.
2797
+ */
2798
+ hasStepsInWorkItemSnapshot(workItemData) {
2799
+ const stepsXml = this.extractStepsXmlFromFieldsMap((workItemData === null || workItemData === void 0 ? void 0 : workItemData.fields) || {});
2800
+ return String(stepsXml || '').trim() !== '';
2801
+ }
2802
+ logRunlessSnapshotDecision(testCaseId, source, snapshot) {
2803
+ var _a;
2804
+ if (!snapshot) {
2805
+ logger_1.default.debug(`[RunlessResolver] TC ${testCaseId}: source=${source}, snapshot=none`);
2806
+ return;
2807
+ }
2808
+ const stepsXml = this.extractStepsXmlFromFieldsMap((snapshot === null || snapshot === void 0 ? void 0 : snapshot.fields) || {});
2809
+ const stepsLength = String(stepsXml || '').trim().length;
2810
+ logger_1.default.debug(`[RunlessResolver] TC ${testCaseId}: source=${source}, rev=${String((_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.rev) !== null && _a !== void 0 ? _a : '')}, hasSteps=${String(stepsLength > 0)}, stepsLength=${String(stepsLength)}`);
2811
+ }
2812
+ /**
2813
+ * Resolves runless test case data using ordered fallbacks:
2814
+ * 1) point-based `asOf` snapshot, 2) explicit revision, 3) suite payload snapshot, 4) latest WI.
2815
+ */
2816
+ async resolveRunlessTestCaseData(projectName, testCaseId, suiteTestCaseRevision, pointAsOfTimestamp, fallbackSnapshot, expandAll) {
2817
+ let bestSnapshotWithoutSteps = null;
2818
+ if (pointAsOfTimestamp) {
2819
+ const asOfSnapshot = await this.fetchWorkItemByAsOf(projectName, testCaseId, pointAsOfTimestamp, expandAll);
2820
+ this.logRunlessSnapshotDecision(testCaseId, 'asOf', asOfSnapshot);
2821
+ if (asOfSnapshot) {
2822
+ if (this.hasStepsInWorkItemSnapshot(asOfSnapshot))
2823
+ return asOfSnapshot;
2824
+ bestSnapshotWithoutSteps = asOfSnapshot;
2825
+ }
2826
+ }
2827
+ else {
2828
+ logger_1.default.debug(`[RunlessResolver] TC ${testCaseId}: asOf timestamp is empty, skipping asOf fetch`);
2829
+ }
2830
+ const revisionSnapshot = await this.fetchWorkItemByRevision(projectName, testCaseId, suiteTestCaseRevision, expandAll);
2831
+ this.logRunlessSnapshotDecision(testCaseId, `revision:${String(suiteTestCaseRevision)}`, revisionSnapshot);
2832
+ if (revisionSnapshot) {
2833
+ if (this.hasStepsInWorkItemSnapshot(revisionSnapshot))
2834
+ return revisionSnapshot;
2835
+ bestSnapshotWithoutSteps = bestSnapshotWithoutSteps || revisionSnapshot;
2836
+ }
2837
+ this.logRunlessSnapshotDecision(testCaseId, 'suiteSnapshot', fallbackSnapshot);
2838
+ if (fallbackSnapshot) {
2839
+ if (this.hasStepsInWorkItemSnapshot(fallbackSnapshot))
2840
+ return fallbackSnapshot;
2841
+ bestSnapshotWithoutSteps = bestSnapshotWithoutSteps || fallbackSnapshot;
2842
+ }
2843
+ const latestSnapshot = await this.fetchWorkItemLatest(projectName, testCaseId, expandAll);
2844
+ this.logRunlessSnapshotDecision(testCaseId, 'latest', latestSnapshot);
2845
+ if (latestSnapshot) {
2846
+ if (this.hasStepsInWorkItemSnapshot(latestSnapshot))
2847
+ return latestSnapshot;
2848
+ bestSnapshotWithoutSteps = bestSnapshotWithoutSteps || latestSnapshot;
2849
+ }
2850
+ return bestSnapshotWithoutSteps;
2851
+ }
2736
2852
  /**
2737
2853
  * Fetches result data based on the Work Item Test Reporter.
2738
2854
  *
@@ -2747,7 +2863,7 @@ class ResultDataProvider {
2747
2863
  * @param isQueryMode - (Optional) A flag indicating whether the result data is being fetched in query mode.
2748
2864
  * @returns A promise that resolves to the fetched result data.
2749
2865
  */
2750
- async fetchResultDataBasedOnWiBase(projectName, runId, resultId, isTestReporter = false, selectedFields, isQueryMode, point, includeAllHistory = false) {
2866
+ async fetchResultDataBasedOnWiBase(projectName, runId, resultId, isTestReporter = false, selectedFields, isQueryMode, point, includeAllHistory = false, useRunlessAsOf = false) {
2751
2867
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2752
2868
  try {
2753
2869
  let filteredFields = {};
@@ -2762,14 +2878,12 @@ class ResultDataProvider {
2762
2878
  const suiteTestCaseItem = point === null || point === void 0 ? void 0 : point.suiteTestCase;
2763
2879
  const testCaseId = Number((point === null || point === void 0 ? void 0 : point.testCaseId) || ((_a = suiteTestCaseItem === null || suiteTestCaseItem === void 0 ? void 0 : suiteTestCaseItem.workItem) === null || _a === void 0 ? void 0 : _a.id) || (suiteTestCaseItem === null || suiteTestCaseItem === void 0 ? void 0 : suiteTestCaseItem.testCaseId) || 0);
2764
2880
  const suiteTestCaseRevision = this.resolveSuiteTestCaseRevision(suiteTestCaseItem);
2881
+ const pointAsOfTimestamp = useRunlessAsOf
2882
+ ? String((point === null || point === void 0 ? void 0 : point.pointAsOfTimestamp) || '').trim()
2883
+ : '';
2884
+ logger_1.default.debug(`[RunlessResolver] Start TC ${String(testCaseId)}: useRunlessAsOf=${String(useRunlessAsOf)}, pointAsOfTimestamp="${pointAsOfTimestamp}", suiteRevision=${String(suiteTestCaseRevision)}, pointOutcome="${String((point === null || point === void 0 ? void 0 : point.outcome) || '')}"`);
2765
2885
  const fallbackSnapshot = this.buildWorkItemSnapshotFromSuiteTestCase(suiteTestCaseItem, testCaseId, String((point === null || point === void 0 ? void 0 : point.testCaseName) || ''));
2766
- let testCaseData = await this.fetchWorkItemByRevision(projectName, testCaseId, suiteTestCaseRevision, isTestReporter);
2767
- if (!testCaseData) {
2768
- testCaseData = fallbackSnapshot;
2769
- }
2770
- if (!testCaseData) {
2771
- testCaseData = await this.fetchWorkItemLatest(projectName, testCaseId, isTestReporter);
2772
- }
2886
+ const testCaseData = await this.resolveRunlessTestCaseData(projectName, testCaseId, suiteTestCaseRevision, pointAsOfTimestamp, fallbackSnapshot, isTestReporter);
2773
2887
  if (!testCaseData) {
2774
2888
  logger_1.default.warn(`Could not resolve test case ${point.testCaseId} for runless point fallback.`);
2775
2889
  return null;
@@ -4045,8 +4159,8 @@ class ResultDataProvider {
4045
4159
  * @param selectedFields - (Optional) An array of field names to include in the result data.
4046
4160
  * @returns A promise that resolves to the fetched result data.
4047
4161
  */
4048
- async fetchResultDataBasedOnWiTestReporter(projectName, runId, resultId, selectedFields, isQueryMode, point, includeAllHistory = false) {
4049
- return this.fetchResultDataBasedOnWiBase(projectName, runId, resultId, true, selectedFields, isQueryMode, point, includeAllHistory);
4162
+ async fetchResultDataBasedOnWiTestReporter(projectName, runId, resultId, selectedFields, isQueryMode, point, includeAllHistory = false, useRunlessAsOf = false) {
4163
+ return this.fetchResultDataBasedOnWiBase(projectName, runId, resultId, true, selectedFields, isQueryMode, point, includeAllHistory, useRunlessAsOf);
4050
4164
  }
4051
4165
  /**
4052
4166
  * Fetches all result data for the test reporter by processing the provided test data.
@@ -4060,8 +4174,8 @@ class ResultDataProvider {
4060
4174
  * @param selectedFields - An optional array of field names to include in the result data.
4061
4175
  * @returns A promise that resolves to an array of processed result data.
4062
4176
  */
4063
- async fetchAllResultDataTestReporter(testData, projectName, selectedFields, isQueryMode, includeAllHistory = false) {
4064
- return this.fetchAllResultDataBase(testData, projectName, true, (projectName, testSuiteId, point, selectedFields, isQueryMode, includeAllHistory) => this.fetchResultDataForTestReporter(projectName, testSuiteId, point, selectedFields, isQueryMode, includeAllHistory), [selectedFields, isQueryMode, includeAllHistory]);
4177
+ async fetchAllResultDataTestReporter(testData, projectName, selectedFields, isQueryMode, includeAllHistory = false, useRunlessAsOf = false) {
4178
+ return this.fetchAllResultDataBase(testData, projectName, true, (projectName, testSuiteId, point, selectedFields, isQueryMode, includeAllHistory, useRunlessAsOf) => this.fetchResultDataForTestReporter(projectName, testSuiteId, point, selectedFields, isQueryMode, includeAllHistory, useRunlessAsOf), [selectedFields, isQueryMode, includeAllHistory, useRunlessAsOf]);
4065
4179
  }
4066
4180
  /**
4067
4181
  * Aligns test steps with iterations for the test reporter by processing test data and iterations
@@ -4169,8 +4283,8 @@ class ResultDataProvider {
4169
4283
  * @returns A promise that resolves to the formatted result data object containing details about the test case,
4170
4284
  * test suite, last run, iteration, and other selected fields.
4171
4285
  */
4172
- async fetchResultDataForTestReporter(projectName, testSuiteId, point, selectedFields, isQueryMode, includeAllHistory = false) {
4173
- return this.fetchResultDataBase(projectName, testSuiteId, point, (project, runId, resultId, fields, isQueryMode, point, includeAllHistory) => this.fetchResultDataBasedOnWiTestReporter(project, runId, resultId, fields, isQueryMode, point, includeAllHistory), (resultData, testSuiteId, point, selectedFields) => {
4286
+ async fetchResultDataForTestReporter(projectName, testSuiteId, point, selectedFields, isQueryMode, includeAllHistory = false, useRunlessAsOf = false) {
4287
+ return this.fetchResultDataBase(projectName, testSuiteId, point, (project, runId, resultId, fields, isQueryMode, point, includeAllHistory, useRunlessAsOf) => this.fetchResultDataBasedOnWiTestReporter(project, runId, resultId, fields, isQueryMode, point, includeAllHistory, useRunlessAsOf), (resultData, testSuiteId, point, selectedFields) => {
4174
4288
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
4175
4289
  const { lastRunId, lastResultId, configurationName, lastResultDetails } = point;
4176
4290
  try {
@@ -4263,7 +4377,7 @@ class ResultDataProvider {
4263
4377
  logger_1.default.error(`Error stack: ${err.stack}`);
4264
4378
  return null;
4265
4379
  }
4266
- }, [selectedFields, isQueryMode, point, includeAllHistory]);
4380
+ }, [selectedFields, isQueryMode, point, includeAllHistory, useRunlessAsOf]);
4267
4381
  }
4268
4382
  getTestOutcome(resultData) {
4269
4383
  // Default outcome if nothing else is available