simplify3x-connect 0.31.1 → 0.31.3
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.
- package/dist/adapters/simplifyqa/adapter.d.ts +157 -46
- package/dist/adapters/simplifyqa/adapter.d.ts.map +1 -1
- package/dist/adapters/simplifyqa/adapter.js +795 -214
- package/dist/adapters/simplifyqa/adapter.js.map +1 -1
- package/dist/adapters/simplifyqa/mapper.d.ts.map +1 -1
- package/dist/adapters/simplifyqa/mapper.js +2 -0
- package/dist/adapters/simplifyqa/mapper.js.map +1 -1
- package/dist/adapters/simplifyqa/stackSetup.d.ts +60 -0
- package/dist/adapters/simplifyqa/stackSetup.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/stackSetup.js +135 -0
- package/dist/adapters/simplifyqa/stackSetup.js.map +1 -0
- package/dist/adapters/types.d.ts +8 -4
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/domain/types.d.ts +11 -0
- package/dist/domain/types.d.ts.map +1 -1
- package/dist/domain/types.js.map +1 -1
- package/dist/initAgents.d.ts.map +1 -1
- package/dist/initAgents.js +5 -4
- package/dist/initAgents.js.map +1 -1
- package/dist/server.js +2 -2
- package/dist/server.js.map +1 -1
- package/dist/tools/attachment.tools.d.ts +14 -0
- package/dist/tools/attachment.tools.d.ts.map +1 -1
- package/dist/tools/attachment.tools.js +46 -38
- package/dist/tools/attachment.tools.js.map +1 -1
- package/dist/tools/autoDefectLog.d.ts +17 -0
- package/dist/tools/autoDefectLog.d.ts.map +1 -0
- package/dist/tools/autoDefectLog.js +52 -0
- package/dist/tools/autoDefectLog.js.map +1 -0
- package/dist/tools/backlog.tools.d.ts.map +1 -1
- package/dist/tools/backlog.tools.js +7 -5
- package/dist/tools/backlog.tools.js.map +1 -1
- package/dist/tools/defectUpdate.tools.d.ts +3 -2
- package/dist/tools/defectUpdate.tools.d.ts.map +1 -1
- package/dist/tools/defectUpdate.tools.js +106 -20
- package/dist/tools/defectUpdate.tools.js.map +1 -1
- package/dist/tools/discovery.tools.d.ts.map +1 -1
- package/dist/tools/discovery.tools.js +51 -20
- package/dist/tools/discovery.tools.js.map +1 -1
- package/dist/tools/executionPlan.tools.d.ts.map +1 -1
- package/dist/tools/executionPlan.tools.js +48 -21
- package/dist/tools/executionPlan.tools.js.map +1 -1
- package/dist/tools/releaseSprint.tools.d.ts +1 -1
- package/dist/tools/releaseSprint.tools.d.ts.map +1 -1
- package/dist/tools/releaseSprint.tools.js +67 -1
- package/dist/tools/releaseSprint.tools.js.map +1 -1
- package/dist/tools/run.tools.d.ts.map +1 -1
- package/dist/tools/run.tools.js +29 -13
- package/dist/tools/run.tools.js.map +1 -1
- package/dist/tools/stackSetupTool.d.ts +21 -0
- package/dist/tools/stackSetupTool.d.ts.map +1 -0
- package/dist/tools/stackSetupTool.js +28 -0
- package/dist/tools/stackSetupTool.js.map +1 -0
- package/dist/tools/suiteManage.tools.d.ts.map +1 -1
- package/dist/tools/suiteManage.tools.js +26 -14
- package/dist/tools/suiteManage.tools.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ import { mergeApiPatch } from '../../drafts/apiPatch.js';
|
|
|
15
15
|
import { matchStepNumbers } from '../../drafts/bulk.js';
|
|
16
16
|
import { resolveCollection } from './searchRegistry.js';
|
|
17
17
|
import { mapLimit } from './mapLimit.js';
|
|
18
|
+
import { distributeCases, firstEmptyStack, pickBrowser, resolveStacks } from './stackSetup.js';
|
|
18
19
|
import { ExecutionFailureAnalysis, fetchFailureImage } from './executionFailures.js';
|
|
19
20
|
import { log } from '../../log.js';
|
|
20
21
|
import { applyHealPlan as applyHealPlanCore } from './heal/apply.js';
|
|
@@ -402,6 +403,7 @@ const BACKLOG_ATTACHMENT_SPECS = {
|
|
|
402
403
|
epic: { path: '/pm/epic', objKey: 'epicObj', parentType: 'EP', keys: EPIC_FORM_KEYS },
|
|
403
404
|
feature: { path: '/pm/feature', objKey: 'featureObj', parentType: 'FT', keys: FEATURE_FORM_KEYS },
|
|
404
405
|
userstory: { path: '/pm/userstory', objKey: 'userstoryObj', parentType: 'US', keys: STORY_FORM_KEYS },
|
|
406
|
+
defect: { path: '/pm/defect', objKey: 'defectObj', parentType: 'DE', keys: [] },
|
|
405
407
|
};
|
|
406
408
|
const STEP_ALLOWED_KEYS = ['projectId', 'sharedFnProjectId', 'moduleId', 'apiData', 'lastActiveTab', 'userstoryId',
|
|
407
409
|
'updateVersion', 'type', 'parentId', 'objectId', 'stepType', 'functionId', 'actionId',
|
|
@@ -565,6 +567,28 @@ function testcaseVersion(raw, optional = false) {
|
|
|
565
567
|
throw new Error(`${str(raw, 'code') ?? `TC-${raw?.id}`} has no version to add.`);
|
|
566
568
|
return { versionId: versionId ?? '', versionName: versionName ?? 'v1.0' };
|
|
567
569
|
}
|
|
570
|
+
/** Version for a plan/suite entry: the requested one (id or name), else the test case's current one.
|
|
571
|
+
* A requested version that does not exist FAILS — silently falling back to v1.0 turned a request for
|
|
572
|
+
* v2.0 into a duplicate v1.0 row. */
|
|
573
|
+
export function pickTestcaseVersion(raw, wantId, wantName) {
|
|
574
|
+
const id = (wantId ?? '').trim();
|
|
575
|
+
const name = (wantName ?? '').trim();
|
|
576
|
+
if (!id && !name)
|
|
577
|
+
return testcaseVersion(raw);
|
|
578
|
+
const versions = Array.isArray(raw?.versions) ? raw.versions : [];
|
|
579
|
+
const hit = versions.find((v) => {
|
|
580
|
+
const vid = str(v, 'id', '_id', 'versionId') ?? '';
|
|
581
|
+
const vname = str(v, 'name', 'versionName') ?? '';
|
|
582
|
+
return (id && vid === id) || (name && vname.trim().toLowerCase() === name.toLowerCase());
|
|
583
|
+
});
|
|
584
|
+
if (!hit) {
|
|
585
|
+
const code = str(raw, 'code') ?? `TC-${raw?.id}`;
|
|
586
|
+
const available = versions.map((v) => `${str(v, 'name') ?? '?'} (${str(v, 'id', '_id', 'versionId') ?? '?'})`).join(', ');
|
|
587
|
+
throw new Error(`${code} has no version ${id ? `"${id}"` : `"${name}"`}. Available versions: ${available || '(none)'}. ` +
|
|
588
|
+
`Read them with sqa_query({ op:"get", collection:"testcases", id:"${code}" }).`);
|
|
589
|
+
}
|
|
590
|
+
return { versionId: str(hit, 'id', '_id', 'versionId') ?? '', versionName: str(hit, 'name', 'versionName') ?? '' };
|
|
591
|
+
}
|
|
568
592
|
/** Refused suite delete: something still uses it (the caller lists `blockers`). */
|
|
569
593
|
export class SuiteBlockedError extends Error {
|
|
570
594
|
constructor(suite, blockers) {
|
|
@@ -574,6 +598,15 @@ export class SuiteBlockedError extends Error {
|
|
|
574
598
|
this.name = 'SuiteBlockedError';
|
|
575
599
|
}
|
|
576
600
|
}
|
|
601
|
+
export class PmBlockedError extends Error {
|
|
602
|
+
constructor(kind, record, blockers) {
|
|
603
|
+
super(`${record.code ?? record.id} is still in use and was not deleted.`);
|
|
604
|
+
this.kind = kind;
|
|
605
|
+
this.record = record;
|
|
606
|
+
this.blockers = blockers;
|
|
607
|
+
this.name = 'PmBlockedError';
|
|
608
|
+
}
|
|
609
|
+
}
|
|
577
610
|
const toRef = (r) => {
|
|
578
611
|
const code = str(r, 'code');
|
|
579
612
|
const name = str(r, 'name');
|
|
@@ -628,9 +661,10 @@ function sqaRecurrence(type, start, end, timeZone, extra = {}) {
|
|
|
628
661
|
const given = Object.keys(extra);
|
|
629
662
|
if (given.length) {
|
|
630
663
|
if (once)
|
|
631
|
-
throw new Error(`A Once schedule has no recurrence settings (${given.join(', ')}) — pick hourly / daily / weekly / monthly.`);
|
|
632
|
-
if (type === 'every_5_minutes') {
|
|
633
|
-
|
|
664
|
+
throw new Error(`A Once schedule has no recurrence settings (${given.join(', ')}) — pick every_n_minutes / hourly / daily / weekly / monthly.`);
|
|
665
|
+
if (type === 'every_5_minutes' && extra.interval !== undefined) {
|
|
666
|
+
// "Every N minutes" — the Scheduler stores it as EVERY_5_MINUTES + interval N; interval 1 = 5 minutes.
|
|
667
|
+
// (Kept permissive: the product's picker is fixed at 5, but the record accepts N.)
|
|
634
668
|
}
|
|
635
669
|
}
|
|
636
670
|
let interval = 1;
|
|
@@ -695,16 +729,30 @@ function sqaBrowser(browser) {
|
|
|
695
729
|
if (!browser)
|
|
696
730
|
return 'CHROME';
|
|
697
731
|
const id = SQA_BROWSERS[browser.trim().toLowerCase()];
|
|
698
|
-
if (
|
|
699
|
-
|
|
700
|
-
|
|
732
|
+
if (id)
|
|
733
|
+
return id;
|
|
734
|
+
// a UI picker key as the Scheduler stores it (CHROME_HEADLESS, FIREFOX_PRIVATE …)
|
|
735
|
+
try {
|
|
736
|
+
return pickBrowser(browser, 'LOCAL').key;
|
|
737
|
+
}
|
|
738
|
+
catch { /* fall through to the plain message */ }
|
|
739
|
+
throw new Error(`Unknown browser "${browser}" — use chrome, edge, firefox or safari.`);
|
|
740
|
+
}
|
|
741
|
+
/** A CLOUD run / schedule is headless: the UI's cloud picker offers only Chrome, Firefox and Edge Headless. "chrome" there means Chrome
|
|
742
|
+
* Headless; a browser the picker does not offer (Safari …) is refused with the three that exist. */
|
|
743
|
+
export const CLOUD_BROWSER_NAMES = ['Chrome Headless', 'Firefox Headless', 'Edge Headless'];
|
|
744
|
+
function cloudBrowserEntry(browser) {
|
|
745
|
+
const b = pickBrowser(browser, 'CLOUD');
|
|
746
|
+
return { name: b.key, id: b.key, technologyType: 'WEB', type: 'NONE' }; // the UI binds key → id AND name
|
|
701
747
|
}
|
|
702
748
|
/** The platform a test case runs on, as the scheduler form derives it from `tcType`: its browser for
|
|
703
749
|
* WEB, its own technology for API / MAINFRAME / SAP / DESKTOP / DATABASE. Mobile needs a device the
|
|
704
750
|
* MCP can't pick, so it is refused. */
|
|
705
|
-
function tcPlatform(tc, browser) {
|
|
751
|
+
function tcPlatform(tc, browser, cloud = false) {
|
|
706
752
|
const tech = String(tc?.tcType ?? 'WEB').toUpperCase();
|
|
707
753
|
if (tech === 'WEB') {
|
|
754
|
+
if (cloud)
|
|
755
|
+
return [cloudBrowserEntry(browser)];
|
|
708
756
|
const b = sqaBrowser(browser);
|
|
709
757
|
return [{ id: b, name: b, type: 'NONE', technologyType: 'WEB' }];
|
|
710
758
|
}
|
|
@@ -716,7 +764,7 @@ function tcPlatform(tc, browser) {
|
|
|
716
764
|
* technology among the suite's live test cases (the scheduler keys it by technologyType at run time) —
|
|
717
765
|
* the browser for WEB, the technology itself for API / MAINFRAME / SAP / DESKTOP / DATABASE. A suite
|
|
718
766
|
* doc has no platform of its own. Mobile needs a device the MCP can't pick, so it is refused. */
|
|
719
|
-
function suitePlatform(suite, browser, verb) {
|
|
767
|
+
function suitePlatform(suite, browser, verb, cloud = false) {
|
|
720
768
|
const code = suite?.code ?? `SU-${suite?.id}`;
|
|
721
769
|
const rows = (Array.isArray(suite?.testCases) ? suite.testCases : []).filter((r) => r && r.deleted !== true);
|
|
722
770
|
if (!rows.length)
|
|
@@ -728,6 +776,8 @@ function suitePlatform(suite, browser, verb) {
|
|
|
728
776
|
return techs.map((t) => {
|
|
729
777
|
if (t !== 'WEB')
|
|
730
778
|
return { id: t, name: t, type: 'NONE', technologyType: t };
|
|
779
|
+
if (cloud)
|
|
780
|
+
return cloudBrowserEntry(browser);
|
|
731
781
|
const b = sqaBrowser(browser);
|
|
732
782
|
return { id: b, name: b, type: 'NONE', technologyType: 'WEB' };
|
|
733
783
|
});
|
|
@@ -1558,8 +1608,8 @@ export class SimplifyQaAdapter {
|
|
|
1558
1608
|
: [];
|
|
1559
1609
|
}
|
|
1560
1610
|
/** `GET /pm/auth/me` → `{ userDetails: { id, username, email, … }, userPreference, … }`.
|
|
1561
|
-
|
|
1562
|
-
|
|
1611
|
+
* Only `userDetails.id` is read: the payload also carries an agent token and the full
|
|
1612
|
+
* preference/privilege set, which must never be logged or persisted. */
|
|
1563
1613
|
async fetchUserIdFromMe() {
|
|
1564
1614
|
try {
|
|
1565
1615
|
const raw = await this.http.getJson('/pm/auth/me');
|
|
@@ -2410,6 +2460,98 @@ export class SimplifyQaAdapter {
|
|
|
2410
2460
|
...(versionNote ? { versionNote } : {}),
|
|
2411
2461
|
};
|
|
2412
2462
|
}
|
|
2463
|
+
/** A value of the defect form's Environment / Type (Execution Type) dropdown. The project's own list wins when it defines one; the form
|
|
2464
|
+
* otherwise offers a fixed list (Development / QA / UAT, Manual / Automation). A value outside it is refused with the valid ones. */
|
|
2465
|
+
async defectChoice(key, want) {
|
|
2466
|
+
const canon = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
2467
|
+
const fixed = { environment: ['Development', 'QA', 'UAT'], executionType: ['Manual', 'Automation'] };
|
|
2468
|
+
const project = await this.defaultFieldValues(9, key);
|
|
2469
|
+
const values = project.length ? project : fixed[key].map((v) => ({ key: v, value: v }));
|
|
2470
|
+
const hit = values.find((v) => canon(v.key) === canon(want) || canon(v.value) === canon(want));
|
|
2471
|
+
if (!hit) {
|
|
2472
|
+
throw new Error(`"${want}" is not a defect ${key === 'executionType' ? 'type (execution type)' : key} in this project. Valid: ${values.map((v) => v.key).join(', ')}.`);
|
|
2473
|
+
}
|
|
2474
|
+
return hit.key;
|
|
2475
|
+
}
|
|
2476
|
+
/** A planned date of the defect form as the backend takes it (a date); only YYYY-MM-DD is accepted so a typo is not guessed at. */
|
|
2477
|
+
defectDate(label, v) {
|
|
2478
|
+
const day = String(v).trim().slice(0, 10);
|
|
2479
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(day) || Number.isNaN(new Date(`${day}T00:00:00Z`).getTime())) {
|
|
2480
|
+
throw new Error(`${label} must be a date like 2026-11-20 (got "${v}").`);
|
|
2481
|
+
}
|
|
2482
|
+
return `${day}T00:00:00.000Z`;
|
|
2483
|
+
}
|
|
2484
|
+
/** The form's Feature field: a feature of THIS project, by id, business key (FT-248) or exact name. */
|
|
2485
|
+
async resolveDefectFeature(ref) {
|
|
2486
|
+
const projectId = this.requireProjectId();
|
|
2487
|
+
const raw = String(ref).trim();
|
|
2488
|
+
const attempts = [];
|
|
2489
|
+
if (/^\d+$/.test(raw))
|
|
2490
|
+
attempts.push({ column: 'id', value: Number.parseInt(raw, 10) });
|
|
2491
|
+
for (const c of SimplifyQaAdapter.codeVariants(raw))
|
|
2492
|
+
attempts.push({ column: 'code', value: c });
|
|
2493
|
+
attempts.push({ column: 'name', value: raw });
|
|
2494
|
+
for (const a of attempts) {
|
|
2495
|
+
const res = await this.http.postJson('/pm/feature/search', this.searchBody([{ column: 'projectIds', value: projectId }, { column: a.column, value: a.value }], { startIndex: 0, limit: 5, selectFields: ['id', 'code', 'name'] }));
|
|
2496
|
+
const hit = pickArray(res, 'data', 'content', 'features').find((r) => a.column === 'id' ? String(str(r, 'id', '_id')) === String(a.value) : String(str(r, a.column) ?? '').toLowerCase() === String(a.value).toLowerCase());
|
|
2497
|
+
const id = hit ? Number.parseInt(str(hit, 'id', '_id') ?? '', 10) : NaN;
|
|
2498
|
+
if (Number.isFinite(id))
|
|
2499
|
+
return { id, label: [str(hit, 'code'), str(hit, 'name')].filter(Boolean).join(' ') || String(id) };
|
|
2500
|
+
}
|
|
2501
|
+
throw new Error(`No feature "${ref}" in this project. Pass its id, business key (e.g. FT-248) or exact name.`);
|
|
2502
|
+
}
|
|
2503
|
+
/** The extra form fields of a create / update, checked and turned into the wire fields — before anything is written, so one bad value
|
|
2504
|
+
* refuses the whole call. `clearable` (update): 'none' empties a field. `before` carries the dates already on the defect so that a
|
|
2505
|
+
* new end date is compared with the stored start date and the other way round. */
|
|
2506
|
+
async defectFormFields(input, clearable, before = {}) {
|
|
2507
|
+
const wire = {};
|
|
2508
|
+
const labels = {};
|
|
2509
|
+
const isNone = (v) => clearable && v.trim().toLowerCase() === 'none';
|
|
2510
|
+
for (const key of ['environment', 'executionType']) {
|
|
2511
|
+
const want = input[key];
|
|
2512
|
+
if (want === undefined)
|
|
2513
|
+
continue;
|
|
2514
|
+
if (isNone(want)) {
|
|
2515
|
+
wire[key] = '';
|
|
2516
|
+
labels[key] = 'none';
|
|
2517
|
+
continue;
|
|
2518
|
+
}
|
|
2519
|
+
const v = await this.defectChoice(key, want);
|
|
2520
|
+
wire[key] = v;
|
|
2521
|
+
labels[key] = v;
|
|
2522
|
+
}
|
|
2523
|
+
if (input.featureId !== undefined) {
|
|
2524
|
+
if (isNone(input.featureId)) {
|
|
2525
|
+
wire['featureId'] = null;
|
|
2526
|
+
labels['featureId'] = 'none';
|
|
2527
|
+
}
|
|
2528
|
+
else {
|
|
2529
|
+
const f = await this.resolveDefectFeature(input.featureId);
|
|
2530
|
+
wire['featureId'] = f.id;
|
|
2531
|
+
labels['featureId'] = f.label;
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
for (const [key, label] of [['plannedStartDate', 'Planned start date'], ['plannedEndDate', 'Planned end date']]) {
|
|
2535
|
+
const want = input[key];
|
|
2536
|
+
if (want === undefined)
|
|
2537
|
+
continue;
|
|
2538
|
+
if (isNone(want)) {
|
|
2539
|
+
wire[key] = null;
|
|
2540
|
+
labels[key] = 'none';
|
|
2541
|
+
continue;
|
|
2542
|
+
}
|
|
2543
|
+
wire[key] = this.defectDate(label, want);
|
|
2544
|
+
labels[key] = String(wire[key]).slice(0, 10);
|
|
2545
|
+
}
|
|
2546
|
+
const day = (k) => {
|
|
2547
|
+
const v = k in wire ? wire[k] : before[k];
|
|
2548
|
+
return v ? String(v).slice(0, 10) : undefined;
|
|
2549
|
+
};
|
|
2550
|
+
const [start, end] = [day('plannedStartDate'), day('plannedEndDate')];
|
|
2551
|
+
if (start && end && end < start)
|
|
2552
|
+
throw new Error(`Planned end date (${end}) must be on or after the planned start date (${start}).`);
|
|
2553
|
+
return { wire, labels };
|
|
2554
|
+
}
|
|
2413
2555
|
/** Change a defect the way the SimplifyQA defect form does (a partial `PUT /pm/defect/:id` carrying the project and the version it
|
|
2414
2556
|
* read), then read it back. USER STORY is `userstoryId`; TEST CASE is `selectedTestCase` — entries with the test case's id, code,
|
|
2415
2557
|
* name and chosen version — which the backend also writes onto the test case's own linked-defects list; that last step swallows its
|
|
@@ -2444,6 +2586,16 @@ export class SimplifyQaAdapter {
|
|
|
2444
2586
|
if (v !== doc[key])
|
|
2445
2587
|
change(key, key, v, String(doc[key] ?? '(none)'), v);
|
|
2446
2588
|
}
|
|
2589
|
+
// Environment, Type (execution type), Feature, planned dates
|
|
2590
|
+
const extra = await this.defectFormFields(patch, true, doc);
|
|
2591
|
+
const FORM_LABELS = { environment: 'environment', executionType: 'type', featureId: 'feature', plannedStartDate: 'planned start date', plannedEndDate: 'planned end date' };
|
|
2592
|
+
for (const [key, to] of Object.entries(extra.wire)) {
|
|
2593
|
+
const dateKey = key === 'plannedStartDate' || key === 'plannedEndDate';
|
|
2594
|
+
const was = dateKey ? String(doc[key] ?? '').slice(0, 10) : String(doc[key] ?? '');
|
|
2595
|
+
const now = dateKey ? String(to ?? '').slice(0, 10) : String(to ?? '');
|
|
2596
|
+
if (was !== now)
|
|
2597
|
+
change(FORM_LABELS[key] ?? key, key, to, was || '(none)', extra.labels[key] ?? now);
|
|
2598
|
+
}
|
|
2447
2599
|
if (patch.name !== undefined && patch.name.trim() !== name) {
|
|
2448
2600
|
if (patch.name.trim().length < 3)
|
|
2449
2601
|
throw new Error('A defect name needs at least 3 characters.');
|
|
@@ -2547,41 +2699,48 @@ export class SimplifyQaAdapter {
|
|
|
2547
2699
|
warnings.push('SimplifyQA does not remove the defect from the removed test case\'s own linked-defects list when it is unlinked here.');
|
|
2548
2700
|
}
|
|
2549
2701
|
}
|
|
2550
|
-
|
|
2702
|
+
const wantLinks = patch.linkages ?? [];
|
|
2703
|
+
if (!shown.length && !wantLinks.length)
|
|
2551
2704
|
return { id: String(defectId), code, name, changes: [], written: false, warnings };
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2705
|
+
let nameNow = name;
|
|
2706
|
+
if (shown.length) {
|
|
2707
|
+
// save (a stale version is retried once with the fresh one)
|
|
2708
|
+
const send = (d) => this.http.putJson(`/pm/defect/${defectId}`, { projectId, updateVersion: typeof d['updateVersion'] === 'number' ? d['updateVersion'] : 0, ...changes });
|
|
2555
2709
|
try {
|
|
2556
|
-
|
|
2710
|
+
try {
|
|
2711
|
+
await send(doc);
|
|
2712
|
+
}
|
|
2713
|
+
catch (e) {
|
|
2714
|
+
if (!/CONCURRENCY/i.test(e instanceof Error ? e.message : String(e)))
|
|
2715
|
+
throw e;
|
|
2716
|
+
await send((await this.readDefectDoc(defectId)) ?? doc);
|
|
2717
|
+
}
|
|
2557
2718
|
}
|
|
2558
2719
|
catch (e) {
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
catch (e) {
|
|
2565
|
-
const m = e instanceof Error ? e.message : String(e);
|
|
2566
|
-
if (/INVALIDTOKEN|Don't Have Privileges|privilege/i.test(m)) {
|
|
2567
|
-
throw new Error(`Updating a defect needs the "add_defect" privilege in this project, and the connected user does not have it (${m}).`);
|
|
2720
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
2721
|
+
if (/INVALIDTOKEN|Don't Have Privileges|privilege/i.test(m)) {
|
|
2722
|
+
throw new Error(`Updating a defect needs the "add_defect" privilege in this project, and the connected user does not have it (${m}).`);
|
|
2723
|
+
}
|
|
2724
|
+
throw e;
|
|
2568
2725
|
}
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2726
|
+
// read the defect back and compare
|
|
2727
|
+
const after = await this.readDefectDoc(defectId);
|
|
2728
|
+
if (!after)
|
|
2729
|
+
throw new Error(`${code} was updated but could not be read back.`);
|
|
2730
|
+
for (const k of Object.keys(changes)) {
|
|
2731
|
+
const want = changes[k];
|
|
2732
|
+
const got = after[k];
|
|
2733
|
+
const same = k === 'ownerId'
|
|
2734
|
+
? JSON.stringify([...(Array.isArray(got) ? got : [])].map(Number).sort()) === JSON.stringify([...want].sort())
|
|
2735
|
+
: k === 'plannedStartDate' || k === 'plannedEndDate'
|
|
2736
|
+
? String(got ?? '').slice(0, 10) === String(want ?? '').slice(0, 10)
|
|
2737
|
+
: k === 'selectedTestCase'
|
|
2738
|
+
? sig(Array.isArray(got) ? got : []) === sig(want)
|
|
2739
|
+
: String(got ?? '') === String(want ?? '');
|
|
2740
|
+
if (!same)
|
|
2741
|
+
throw new Error(`${code}: "${k}" was sent as ${JSON.stringify(want).slice(0, 200)} but reads back as ${JSON.stringify(got).slice(0, 200)}.`);
|
|
2742
|
+
}
|
|
2743
|
+
nameNow = String(after['name'] ?? name);
|
|
2585
2744
|
}
|
|
2586
2745
|
// the test case's own linked-defects list is written by the backend with its failures swallowed — check it, repair it, re-check
|
|
2587
2746
|
for (const t of added) {
|
|
@@ -2598,7 +2757,19 @@ export class SimplifyQaAdapter {
|
|
|
2598
2757
|
if (!state.ok)
|
|
2599
2758
|
warnings.push(`${t.label}: the defect is saved with the test case, but the test case's own linked-defects list does not show ${code}.`);
|
|
2600
2759
|
}
|
|
2601
|
-
|
|
2760
|
+
// Linkages, saved from the DEFECT's side (each is read back from /pm/linkages inside linkBacklogItem)
|
|
2761
|
+
let linksAdded = 0;
|
|
2762
|
+
for (const l of wantLinks) {
|
|
2763
|
+
const r = await this.linkBacklogItem({ sourceType: 'defect', sourceId: String(defectId), destType: l.destType, destId: l.destId, linkType: l.linkType });
|
|
2764
|
+
const to = `${r.destinationCode ?? l.destId} (${l.linkType})`;
|
|
2765
|
+
if (r.alreadyLinked)
|
|
2766
|
+
warnings.push(`${code} was already linked to ${to} — left as it is.`);
|
|
2767
|
+
else {
|
|
2768
|
+
shown.push({ field: 'linkage', from: '(none)', to });
|
|
2769
|
+
linksAdded++;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
return { id: String(defectId), code, name: nameNow, changes: shown, written: shown.length > linksAdded || linksAdded > 0, warnings };
|
|
2602
2773
|
}
|
|
2603
2774
|
// ---------------------------------------------------------------------- Defect create
|
|
2604
2775
|
/** Log a defect the way Defect Management → Create Defect does (`POST /pm/defect`), then read it back. The backend requires a name,
|
|
@@ -2684,8 +2855,11 @@ export class SimplifyQaAdapter {
|
|
|
2684
2855
|
moduleId = await this.resolveModuleId('Default module').catch(() => undefined);
|
|
2685
2856
|
if (moduleId !== undefined && !Number.isFinite(moduleId))
|
|
2686
2857
|
moduleId = undefined;
|
|
2858
|
+
// Environment, Type (execution type), Feature, planned dates — checked now, before anything is created
|
|
2859
|
+
const extra = await this.defectFormFields(input, false);
|
|
2687
2860
|
const body = {
|
|
2688
2861
|
projectId, name, state, priority, description: input.description ?? '',
|
|
2862
|
+
...extra.wire,
|
|
2689
2863
|
...(severity ? { severity } : {}), ...(category ? { category } : {}),
|
|
2690
2864
|
...(ownerId ? { ownerId } : {}),
|
|
2691
2865
|
...(plan.releaseId != null ? { releaseId: plan.releaseId } : {}), ...(plan.iterationId != null ? { iterationId: plan.iterationId } : {}),
|
|
@@ -2724,10 +2898,34 @@ export class SimplifyQaAdapter {
|
|
|
2724
2898
|
warnings.push(`${t.label}: the defect is saved with the test case, but the test case's own linked-defects list does not show ${defectCode}.`);
|
|
2725
2899
|
}
|
|
2726
2900
|
}
|
|
2901
|
+
// the extra form fields as stored (a mismatch is reported, never hidden — the defect exists by now)
|
|
2902
|
+
const fields = [];
|
|
2903
|
+
const FIELD_NAMES = { environment: 'environment', executionType: 'type', featureId: 'feature', plannedStartDate: 'planned start', plannedEndDate: 'planned end' };
|
|
2904
|
+
for (const [key, sent] of Object.entries(extra.wire)) {
|
|
2905
|
+
const dateKey = key === 'plannedStartDate' || key === 'plannedEndDate';
|
|
2906
|
+
const got = dateKey ? String(doc[key] ?? '').slice(0, 10) : String(doc[key] ?? '');
|
|
2907
|
+
const want = dateKey ? String(sent ?? '').slice(0, 10) : String(sent ?? '');
|
|
2908
|
+
if (got === want)
|
|
2909
|
+
fields.push(`${FIELD_NAMES[key] ?? key} ${extra.labels[key] ?? got}`);
|
|
2910
|
+
else
|
|
2911
|
+
warnings.push(`${defectCode}: ${FIELD_NAMES[key] ?? key} was sent as ${want || 'empty'} but reads back as ${got || 'empty'}.`);
|
|
2912
|
+
}
|
|
2913
|
+
// Linkages, saved from the new defect's side; a failed one is reported with its reason while the defect stays logged
|
|
2914
|
+
const linked = [];
|
|
2915
|
+
for (const l of input.linkages ?? []) {
|
|
2916
|
+
try {
|
|
2917
|
+
const r = await this.linkBacklogItem({ sourceType: 'defect', sourceId: String(defectId), destType: l.destType, destId: l.destId, linkType: l.linkType });
|
|
2918
|
+
linked.push(`${r.destinationCode ?? l.destId} (${l.linkType})`);
|
|
2919
|
+
}
|
|
2920
|
+
catch (e) {
|
|
2921
|
+
warnings.push(`${defectCode} was logged, but linking it to ${l.destType} ${l.destId} failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2727
2924
|
return {
|
|
2728
2925
|
defectId: String(defectId), defectCode, name, state: String(doc['state'] ?? state ?? ''), priority: String(doc['priority'] ?? priority ?? ''),
|
|
2729
2926
|
...(severity ? { severity: String(doc['severity'] ?? severity) } : {}), testCases: tcEntries.map((t) => t.label),
|
|
2730
|
-
...(userstoryId !== undefined ? { storyId: userstoryId } : {}),
|
|
2927
|
+
...(userstoryId !== undefined ? { storyId: userstoryId } : {}),
|
|
2928
|
+
...(fields.length ? { fields } : {}), ...(linked.length ? { linked } : {}), defaults, warnings,
|
|
2731
2929
|
};
|
|
2732
2930
|
}
|
|
2733
2931
|
// ---------------------------------------------------------------------- Defects from a failed step
|
|
@@ -3123,6 +3321,8 @@ export class SimplifyQaAdapter {
|
|
|
3123
3321
|
* `userstoryObj` + `filename1`), so this re-saves the item with its existing fields + attachments
|
|
3124
3322
|
* and the new file. Reads the attachments back and returns them. */
|
|
3125
3323
|
async addAttachment(input) {
|
|
3324
|
+
if (input.entityType === 'defect')
|
|
3325
|
+
return this.addDefectAttachment(input);
|
|
3126
3326
|
const spec = BACKLOG_ATTACHMENT_SPECS[input.entityType];
|
|
3127
3327
|
const numeric = input.entityType === 'epic' ? await this.resolveEpicNumericId(input.itemId)
|
|
3128
3328
|
: input.entityType === 'feature' ? await this.resolveFeatureNumericId(input.itemId)
|
|
@@ -3156,7 +3356,66 @@ export class SimplifyQaAdapter {
|
|
|
3156
3356
|
}
|
|
3157
3357
|
return { ...(doc['id'] !== undefined ? { id: String(doc['id']) } : {}), name: input.fileName, attachments };
|
|
3158
3358
|
}
|
|
3159
|
-
/**
|
|
3359
|
+
/** Attach a file to a DEFECT: the defect's own update with the file as the multipart `filename1` part and ONLY the project and version
|
|
3360
|
+
* as fields — a defect update takes just what changes, and its existing attachments are left alone. Read back from `/pm/attachment/:id/DE`. */
|
|
3361
|
+
async addDefectAttachment(input) {
|
|
3362
|
+
if (!this.http.putMultipartWithFiles)
|
|
3363
|
+
throw new Error('This connection cannot upload attachments.');
|
|
3364
|
+
const projectId = this.requireProjectId();
|
|
3365
|
+
let doc = await this.findDefectDoc(input.itemId);
|
|
3366
|
+
const id = String(doc['id']);
|
|
3367
|
+
const send = (d) => this.http.putMultipartWithFiles(`/pm/defect/${id}`, 'defectObj', { projectId, updateVersion: typeof d['updateVersion'] === 'number' ? d['updateVersion'] : 0 }, [{ partName: 'filename1', fileName: input.fileName, ...(input.contentType ? { contentType: input.contentType } : {}), data: input.data }]);
|
|
3368
|
+
try {
|
|
3369
|
+
try {
|
|
3370
|
+
await send(doc);
|
|
3371
|
+
}
|
|
3372
|
+
catch (e) {
|
|
3373
|
+
if (!/CONCURRENCY/i.test(e instanceof Error ? e.message : String(e)))
|
|
3374
|
+
throw e;
|
|
3375
|
+
doc = (await this.readDefectDoc(Number(id))) ?? doc;
|
|
3376
|
+
await send(doc);
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
catch (e) {
|
|
3380
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
3381
|
+
if (/INVALIDTOKEN|Don't Have Privileges|privilege/i.test(m)) {
|
|
3382
|
+
throw new Error(`Attaching a file to a defect needs the "add_defect" privilege in this project, and the connected user does not have it (${m}).`);
|
|
3383
|
+
}
|
|
3384
|
+
throw e;
|
|
3385
|
+
}
|
|
3386
|
+
const attachments = await this.entityAttachments('defect', id);
|
|
3387
|
+
if (!attachments.some((a) => String(a['original_name'] ?? a['name'] ?? '') === input.fileName)) {
|
|
3388
|
+
throw new Error(`Uploaded "${input.fileName}" to defect ${input.itemId}, but reading the attachments back did not find it. ` +
|
|
3389
|
+
`Attachments now: ${attachments.map((a) => String(a['original_name'] ?? a['name'] ?? '')).join(', ') || '(none)'}`);
|
|
3390
|
+
}
|
|
3391
|
+
return { id, name: input.fileName, attachments };
|
|
3392
|
+
}
|
|
3393
|
+
/** Remove one attachment from a DEFECT: the update's `attachments` names the rows to delete — the row with `deleted:true` and the project
|
|
3394
|
+
* (the backend scopes the delete by it). Read back to confirm it is gone. */
|
|
3395
|
+
async removeDefectAttachment(input) {
|
|
3396
|
+
if (!this.http.putMultipart)
|
|
3397
|
+
throw new Error('This connection cannot update attachments.');
|
|
3398
|
+
const projectId = this.requireProjectId();
|
|
3399
|
+
const doc = await this.findDefectDoc(input.itemId);
|
|
3400
|
+
const id = String(doc['id']);
|
|
3401
|
+
const rows = await this.entityAttachments('defect', id);
|
|
3402
|
+
const wanted = input.attachment.trim();
|
|
3403
|
+
const match = rows.find((a) => String(a['id']) === wanted || String(a['original_name'] ?? a['name'] ?? '') === wanted);
|
|
3404
|
+
if (!match) {
|
|
3405
|
+
throw new Error(`No attachment "${input.attachment}" on defect ${input.itemId}. Attachments: ${rows.map((a) => String(a['original_name'] ?? a['name'] ?? a['id'])).join(', ') || '(none)'}`);
|
|
3406
|
+
}
|
|
3407
|
+
const row = { ...match, deleted: true, projectId };
|
|
3408
|
+
delete row['file'];
|
|
3409
|
+
await this.http.putMultipart(`/pm/defect/${id}`, 'defectObj', {
|
|
3410
|
+
projectId, updateVersion: typeof doc['updateVersion'] === 'number' ? doc['updateVersion'] : 0, attachments: [row],
|
|
3411
|
+
});
|
|
3412
|
+
const attachments = await this.entityAttachments('defect', id);
|
|
3413
|
+
if (attachments.some((a) => String(a['id']) === String(match['id']))) {
|
|
3414
|
+
throw new Error(`Tried to delete "${input.attachment}" but it is still listed after the save.`);
|
|
3415
|
+
}
|
|
3416
|
+
return { removed: true, attachments };
|
|
3417
|
+
}
|
|
3418
|
+
/** Attachments of an epic / feature / user story / defect (`/pm/attachment/:id/:parentType`). */
|
|
3160
3419
|
async entityAttachments(entityType, id) {
|
|
3161
3420
|
const spec = BACKLOG_ATTACHMENT_SPECS[entityType];
|
|
3162
3421
|
const projectId = this.requireProjectId();
|
|
@@ -3173,7 +3432,7 @@ export class SimplifyQaAdapter {
|
|
|
3173
3432
|
if (!this.http.getBinary)
|
|
3174
3433
|
throw new Error('This connection cannot download files.');
|
|
3175
3434
|
const base = (this.cfg.baseUrl ?? '').replace(/\/+$/, '');
|
|
3176
|
-
const rows = await this.entityAttachments(input.entityType, input.itemId);
|
|
3435
|
+
const rows = await this.entityAttachments(input.entityType, input.entityType === 'defect' ? String((await this.findDefectDoc(input.itemId))['id']) : input.itemId);
|
|
3177
3436
|
const nameOf = (a) => String(a['original_name'] ?? a['name'] ?? '').trim();
|
|
3178
3437
|
const sizeOf = (a) => {
|
|
3179
3438
|
const n = typeof a['size'] === 'number' ? a['size'] : Number(a['size'] ?? a['fileSize']);
|
|
@@ -3251,6 +3510,8 @@ export class SimplifyQaAdapter {
|
|
|
3251
3510
|
/** Remove one attachment (by id or stored/original name) from an epic / feature / user story.
|
|
3252
3511
|
* Mirrors the UI: mark the row `deleted:true` and re-save the item (multipart, no file part). */
|
|
3253
3512
|
async removeAttachment(input) {
|
|
3513
|
+
if (input.entityType === 'defect')
|
|
3514
|
+
return this.removeDefectAttachment(input);
|
|
3254
3515
|
const spec = BACKLOG_ATTACHMENT_SPECS[input.entityType];
|
|
3255
3516
|
const numeric = input.entityType === 'epic' ? await this.resolveEpicNumericId(input.itemId)
|
|
3256
3517
|
: input.entityType === 'feature' ? await this.resolveFeatureNumericId(input.itemId)
|
|
@@ -3964,6 +4225,62 @@ export class SimplifyQaAdapter {
|
|
|
3964
4225
|
}
|
|
3965
4226
|
return { id, code, name: String(after.name ?? row.name ?? ''), stateBefore, stateAfter: String(after.state ?? ''), changed: changes, warnings, written: true };
|
|
3966
4227
|
}
|
|
4228
|
+
/** Everything that still uses a release / sprint, found by the MCP itself (nothing is written). A lookup that FAILS
|
|
4229
|
+
* stops the whole preview — "could not check" must never read as "nothing uses it". */
|
|
4230
|
+
async releaseOrSprintDeletePreview(kind, ref) {
|
|
4231
|
+
const row = await this.findPm(kind, ref);
|
|
4232
|
+
const n = Number(row.id);
|
|
4233
|
+
const column = kind === 'release' ? 'releaseId' : 'iterationId';
|
|
4234
|
+
const where = async (label, path) => {
|
|
4235
|
+
try {
|
|
4236
|
+
const raw = await this.http.postJson(path, this.searchBody([{ column, value: n }], { selectFields: ['id', 'code', 'name'], limit: 100 }));
|
|
4237
|
+
return pickArray(raw, 'data', 'content').map(toRef);
|
|
4238
|
+
}
|
|
4239
|
+
catch (e) {
|
|
4240
|
+
throw new Error(`Could not check the ${label} that use ${row.code ?? `#${n}`} (${e instanceof Error ? e.message : String(e)}). Nothing was deleted.`);
|
|
4241
|
+
}
|
|
4242
|
+
};
|
|
4243
|
+
const [stories, defects, tasks, executionPlans, pipelines, schedules] = await Promise.all([
|
|
4244
|
+
where('stories', '/pm/userstory/search'), where('defects', '/pm/defect/search'), where('tasks', '/pm/task/search'),
|
|
4245
|
+
where('execution plans', '/tm/executionplan/search'), where('pipelines', '/pl/pipelines/search'), where('schedules', '/sh/scheduler/search'),
|
|
4246
|
+
]);
|
|
4247
|
+
const sprints = kind === 'release'
|
|
4248
|
+
? (await this.pmRows('sprint')).filter((s) => String(s?.releaseId) === String(n)).map(toRef)
|
|
4249
|
+
: [];
|
|
4250
|
+
// A release can belong to several projects, and deleting it removes it from all of them.
|
|
4251
|
+
const projectId = this.requireProjectId();
|
|
4252
|
+
const otherIds = kind === 'release' && Array.isArray(row.projectIds)
|
|
4253
|
+
? row.projectIds.map(Number).filter((p) => Number.isFinite(p) && String(p) !== String(projectId))
|
|
4254
|
+
: [];
|
|
4255
|
+
const otherProjects = otherIds.length ? await this.refsByIds('/pm/project/search', otherIds) : [];
|
|
4256
|
+
return {
|
|
4257
|
+
kind,
|
|
4258
|
+
record: { ...toRef(row), ...(row.state ? { state: String(row.state) } : {}) },
|
|
4259
|
+
blockers: { sprints, stories, defects, tasks, executionPlans, pipelines, schedules, otherProjects },
|
|
4260
|
+
callerIsAdmin: await this.isCallerAdmin(),
|
|
4261
|
+
};
|
|
4262
|
+
}
|
|
4263
|
+
/** Delete a release / sprint (`PATCH /pm/release|sprint { id:[n] }` — admin only) — only when nothing uses it, and proven by
|
|
4264
|
+
* re-reading: SimplifyQA answers 201 whether or not the row was found. */
|
|
4265
|
+
async deleteReleaseOrSprint(kind, ref) {
|
|
4266
|
+
const { record, blockers } = await this.releaseOrSprintDeletePreview(kind, ref);
|
|
4267
|
+
if (Object.values(blockers).some((b) => b.length))
|
|
4268
|
+
throw new PmBlockedError(kind, record, blockers);
|
|
4269
|
+
try {
|
|
4270
|
+
await this.http.patchJson(`/pm/${kind}`, { id: [Number(record.id)] });
|
|
4271
|
+
}
|
|
4272
|
+
catch (e) {
|
|
4273
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
4274
|
+
if (/INVALIDUSERTYPE|admin privileges|not.*authori[sz]ed|forbidden|\b40[13]\b/i.test(m)) {
|
|
4275
|
+
throw new Error(`Deleting a ${kind} needs an admin user in SimplifyQA, and the connected user is not one (${m}). Nothing was deleted.`);
|
|
4276
|
+
}
|
|
4277
|
+
throw e;
|
|
4278
|
+
}
|
|
4279
|
+
const still = (await this.pmRows(kind)).some((r) => String(r.id) === record.id);
|
|
4280
|
+
if (still)
|
|
4281
|
+
throw new Error(`SimplifyQA answered OK but ${record.code ?? record.id} is still listed — nothing was deleted.`);
|
|
4282
|
+
return record;
|
|
4283
|
+
}
|
|
3967
4284
|
/** Create a release or a sprint the way Releases → Create does (`POST /pm/release` / `/pm/sprint`), then read it back.
|
|
3968
4285
|
* The backend requires a state and at least one owner, so the state defaults to the project's first one (New) and the owner to
|
|
3969
4286
|
* the connected user. A sprint needs an existing release of this project. */
|
|
@@ -4302,19 +4619,54 @@ export class SimplifyQaAdapter {
|
|
|
4302
4619
|
jiraIssueKey: '',
|
|
4303
4620
|
jiraLinkId: '',
|
|
4304
4621
|
};
|
|
4305
|
-
const
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4622
|
+
const readLinks = async () => {
|
|
4623
|
+
const rawLinks = await this.http.getJson(`/pm/linkages/${source.id}/${specs[input.sourceType].parentType}?projectId=${projectId}`);
|
|
4624
|
+
return (Array.isArray(rawLinks) ? rawLinks : pickArray(rawLinks, 'data', 'content', 'linkages'));
|
|
4625
|
+
};
|
|
4626
|
+
if (input.sourceType === 'defect') {
|
|
4627
|
+
// A defect's save ADDS the rows that carry no id and leaves the others alone, and its document does not echo its links — so only the
|
|
4628
|
+
// new row is sent, and only when this exact link (same item, same type) is not already there.
|
|
4629
|
+
const present = await readLinks();
|
|
4630
|
+
if (present.some((l) => Number(l['destinationId']) === dest.id && String(l['linkTypeKey']) === chosen.key)) {
|
|
4631
|
+
return { linkTypeKey: chosen.key, ...(dest.code ? { destinationCode: dest.code } : {}), linkedIssues: present, alreadyLinked: true };
|
|
4632
|
+
}
|
|
4633
|
+
const sendLink = async () => {
|
|
4634
|
+
const d = await this.readDefectDoc(source.id);
|
|
4635
|
+
return this.http.putJson(`/pm/defect/${source.id}`, { projectId, updateVersion: typeof d?.['updateVersion'] === 'number' ? d['updateVersion'] : 0, linkedIssues: [entry] });
|
|
4636
|
+
};
|
|
4637
|
+
try {
|
|
4638
|
+
try {
|
|
4639
|
+
await sendLink();
|
|
4640
|
+
}
|
|
4641
|
+
catch (e) {
|
|
4642
|
+
if (!/CONCURRENCY/i.test(e instanceof Error ? e.message : String(e)))
|
|
4643
|
+
throw e;
|
|
4644
|
+
await sendLink();
|
|
4645
|
+
}
|
|
4646
|
+
}
|
|
4647
|
+
catch (e) {
|
|
4648
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
4649
|
+
if (/INVALIDTOKEN|Don't Have Privileges|privilege/i.test(m)) {
|
|
4650
|
+
throw new Error(`Linking from a defect needs the "add_defect" privilege in this project, and the connected user does not have it (${m}).`);
|
|
4651
|
+
}
|
|
4652
|
+
throw e;
|
|
4653
|
+
}
|
|
4654
|
+
}
|
|
4655
|
+
else {
|
|
4656
|
+
const sourceRaw = asDoc(await this.http.getJson(`${specs[input.sourceType].path}/${source.id}`));
|
|
4657
|
+
const existing = Array.isArray(sourceRaw['linkedIssues']) ? sourceRaw['linkedIssues'] : [];
|
|
4658
|
+
const merged = [
|
|
4659
|
+
...existing.filter((e) => !(Number(e['destinationId']) === dest.id && String(e['linkTypeKey']) === chosen.key)),
|
|
4660
|
+
entry,
|
|
4661
|
+
];
|
|
4662
|
+
const version = typeof sourceRaw['updateVersion'] === 'number' ? sourceRaw['updateVersion'] : 0;
|
|
4663
|
+
if (input.sourceType === 'epic')
|
|
4664
|
+
await this.updateEpic(String(source.id), { linkedIssues: merged, updateVersion: version });
|
|
4665
|
+
else if (input.sourceType === 'feature')
|
|
4666
|
+
await this.updateFeature(String(source.id), { linkedIssues: merged, updateVersion: version });
|
|
4667
|
+
else
|
|
4668
|
+
await this.updateStory(String(source.id), { linkedIssues: merged });
|
|
4669
|
+
}
|
|
4318
4670
|
// Confirm from the linkages sub-resource (the item document does not echo the array).
|
|
4319
4671
|
const rawLinks = await this.http.getJson(`/pm/linkages/${source.id}/${specs[input.sourceType].parentType}?projectId=${projectId}`);
|
|
4320
4672
|
const links = (Array.isArray(rawLinks) ? rawLinks : pickArray(rawLinks, 'data', 'content', 'linkages'));
|
|
@@ -4450,6 +4802,39 @@ export class SimplifyQaAdapter {
|
|
|
4450
4802
|
const doc = Array.isArray(raw) ? (raw[0] ?? {}) : raw;
|
|
4451
4803
|
return (doc?.data && typeof doc.data === 'object' && !Array.isArray(doc.data) ? doc.data : doc) ?? {};
|
|
4452
4804
|
}
|
|
4805
|
+
/** The ADMIN-level Auto Defect Logging switch of the connected project (Project settings → Defect
|
|
4806
|
+
* management → `generalSettings.defectManagement.autoDefectFlag`). The backend logs a defect for a
|
|
4807
|
+
* failed step only when this is on AND the suite / execution plan has autoDefectLog set — the UI
|
|
4808
|
+
* refuses the suite/plan toggle while it is off. `undefined` = could not be read (no access): callers
|
|
4809
|
+
* must then not block. */
|
|
4810
|
+
/** What a CLOUD run's browser question offers: the UI's cloud picker (headless only). */
|
|
4811
|
+
cloudBrowserOptions() {
|
|
4812
|
+
return [...CLOUD_BROWSER_NAMES];
|
|
4813
|
+
}
|
|
4814
|
+
async autoDefectLogStatus() {
|
|
4815
|
+
try {
|
|
4816
|
+
const project = await this.getProjectById(String(this.requireProjectId()));
|
|
4817
|
+
const dm = project?.['generalSettings']?.['defectManagement'];
|
|
4818
|
+
// the backend builds the defect from this config (owner, priority, state); without them the defect is not created
|
|
4819
|
+
const cfg = dm?.['configAutologgedDefect'] ?? {};
|
|
4820
|
+
const missing = [['assignee', cfg['assigneeId']], ['priority', cfg['priority']], ['state', cfg['state'] ?? cfg['status']]]
|
|
4821
|
+
.filter(([, v]) => v === undefined || v === null || v === '').map(([k]) => String(k));
|
|
4822
|
+
return { adminEnabled: dm?.['autoDefectFlag'] === true, configMissing: missing };
|
|
4823
|
+
}
|
|
4824
|
+
catch {
|
|
4825
|
+
return undefined;
|
|
4826
|
+
}
|
|
4827
|
+
}
|
|
4828
|
+
/** The suite's / execution plan's own Auto Defect Logging flag (what its Settings panel shows), or undefined when it cannot be read. */
|
|
4829
|
+
async autoDefectLogOf(kind, id) {
|
|
4830
|
+
try {
|
|
4831
|
+
const raw = kind === 'suite' ? await this.readOwnSuite(id) : await this.readOwnPlan(id);
|
|
4832
|
+
return raw['autoDefectLog'] === true;
|
|
4833
|
+
}
|
|
4834
|
+
catch {
|
|
4835
|
+
return undefined;
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4453
4838
|
/** Soft-delete a project — the admin Project screen's delete (`PATCH /pm/project { ids }`). */
|
|
4454
4839
|
async deleteProject(id) {
|
|
4455
4840
|
const numeric = Number.parseInt(numericId(id), 10);
|
|
@@ -6624,6 +7009,10 @@ export class SimplifyQaAdapter {
|
|
|
6624
7009
|
// The catalog can miss a project's newer custom actions, so look the id / name / display name up
|
|
6625
7010
|
// directly with a targeted search (never GET /tm/action/:id — that route reads the id as a project id).
|
|
6626
7011
|
let fallbackDiag = '';
|
|
7012
|
+
// An EXISTING step whose action still cannot be found (a custom method from another catalogue, a
|
|
7013
|
+
// row the search is not allowed to read) must round-trip untouched instead of failing the whole
|
|
7014
|
+
// edit: keep the action id it was saved with. Only a NEW step is refused when it cannot resolve.
|
|
7015
|
+
let preserveAction = false;
|
|
6627
7016
|
if (!meta) {
|
|
6628
7017
|
try {
|
|
6629
7018
|
meta = await this.findActionLive(name);
|
|
@@ -6638,12 +7027,16 @@ export class SimplifyQaAdapter {
|
|
|
6638
7027
|
if (meta.displayName)
|
|
6639
7028
|
catalog.set(`dis::${meta.displayName.toLowerCase()}`, meta);
|
|
6640
7029
|
}
|
|
7030
|
+
else if (isNumericId && s.sourceId) {
|
|
7031
|
+
meta = { id: Number.parseInt(name, 10), objectRequired: false };
|
|
7032
|
+
preserveAction = true;
|
|
7033
|
+
}
|
|
6641
7034
|
}
|
|
6642
7035
|
if (!meta) {
|
|
6643
7036
|
throw new Error(`Automation step ${i + 1}: the action "${name}" was not found in the action list for technology ${tech} (project ${projectId}). Check the action id, method name or display name.${fallbackDiag} [catalog: ${this.actionCatalogFetchDiag}]`);
|
|
6644
7037
|
}
|
|
6645
|
-
let objectId = null;
|
|
6646
|
-
if (meta.objectRequired) {
|
|
7038
|
+
let objectId = preserveAction ? undefined : null;
|
|
7039
|
+
if (!preserveAction && meta.objectRequired) {
|
|
6647
7040
|
// Resolution ladder (first match wins):
|
|
6648
7041
|
// 1. objectRef.id set → use directly (round-trip OR LLM referencing a known object)
|
|
6649
7042
|
// 2. sourceId set but no objectRef.id → preserve DB value (existing step, backend may
|
|
@@ -6929,9 +7322,19 @@ export class SimplifyQaAdapter {
|
|
|
6929
7322
|
const tcNum = numericId(String(op.tcId));
|
|
6930
7323
|
switch (op.op) {
|
|
6931
7324
|
case 'add': {
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
7325
|
+
// The same test case may legitimately appear once PER VERSION — dedupe on (tc, version),
|
|
7326
|
+
// never on the tc alone, or asking for v2.0 after v1.0 silently keeps v1.0.
|
|
7327
|
+
const wantsVersion = !!(op.versionId || op.version);
|
|
7328
|
+
if (!wantsVersion && members.some((m) => String(m['testcaseId']) === tcNum))
|
|
7329
|
+
break;
|
|
7330
|
+
const entry = await this.buildSuiteEntryFromTestcase(tcNum, {
|
|
7331
|
+
...(op.versionId ? { versionId: op.versionId } : {}),
|
|
7332
|
+
...(op.version ? { version: op.version } : {}),
|
|
7333
|
+
});
|
|
7334
|
+
const dup = members.some((m) => String(m['testcaseId']) === tcNum
|
|
7335
|
+
&& String(m['versionId'] ?? '') === String(entry['versionId'] ?? ''));
|
|
7336
|
+
if (!dup)
|
|
7337
|
+
members.push(entry);
|
|
6935
7338
|
break;
|
|
6936
7339
|
}
|
|
6937
7340
|
case 'remove': {
|
|
@@ -7036,7 +7439,8 @@ export class SimplifyQaAdapter {
|
|
|
7036
7439
|
const raw = await this.readOwnSuite(id);
|
|
7037
7440
|
const payload = {
|
|
7038
7441
|
id: raw['id'], suiteType: raw['suiteType'], projectId: raw['projectId'],
|
|
7039
|
-
|
|
7442
|
+
// the settings validator requires both; a suite saved without them would otherwise fail on any settings change
|
|
7443
|
+
autoReExecTriggerOn: raw['autoReExecTriggerOn'] ?? 'AFTER_SUITE', autoReExecCount: raw['autoReExecCount'] ?? 0,
|
|
7040
7444
|
};
|
|
7041
7445
|
for (const k of SUITE_SETTING_KEYS)
|
|
7042
7446
|
if (settings[k] !== undefined)
|
|
@@ -7170,7 +7574,12 @@ export class SimplifyQaAdapter {
|
|
|
7170
7574
|
const candidates = [];
|
|
7171
7575
|
for (const tcId of input.tcIds ?? []) {
|
|
7172
7576
|
const raw = await this.readOwnTestcase(tcId);
|
|
7173
|
-
const v =
|
|
7577
|
+
const v = pickTestcaseVersion(raw, input.versionId, input.version);
|
|
7578
|
+
candidates.push({ raw, ...v, platform: entryPlatform(raw.executionPlatform), source: { sourceType: 'testcase', sourceId: 0 } });
|
|
7579
|
+
}
|
|
7580
|
+
for (const spec of input.testCases ?? []) {
|
|
7581
|
+
const raw = await this.readOwnTestcase(spec.tcId);
|
|
7582
|
+
const v = pickTestcaseVersion(raw, spec.versionId, spec.version);
|
|
7174
7583
|
candidates.push({ raw, ...v, platform: entryPlatform(raw.executionPlatform), source: { sourceType: 'testcase', sourceId: 0 } });
|
|
7175
7584
|
}
|
|
7176
7585
|
for (const suiteId of input.suiteIds ?? []) {
|
|
@@ -7191,18 +7600,30 @@ export class SimplifyQaAdapter {
|
|
|
7191
7600
|
}
|
|
7192
7601
|
const existing = await this.listPlanEntries(Number(plan['id']));
|
|
7193
7602
|
let seq = existing.reduce((m, e) => Math.max(m, Number(e?.seq) || 0), 0);
|
|
7194
|
-
|
|
7603
|
+
// Dedupe on (test case, VERSION, assignee): a plan may legitimately hold v1.0 and v2.0 of one TC.
|
|
7604
|
+
// An older entry that stores no version at all is treated as "this test case is already in" (we
|
|
7605
|
+
// cannot prove which version, so adding another would risk an invisible duplicate).
|
|
7606
|
+
const seenExact = new Set(existing
|
|
7607
|
+
.filter((e) => e?.tcVersionId)
|
|
7608
|
+
.map((e) => `${Number(e?.testcaseId)}|${String(e.tcVersionId)}|${e?.expAssignedTo ?? null}`));
|
|
7609
|
+
const seenAnyVersion = new Set(existing
|
|
7610
|
+
.filter((e) => !e?.tcVersionId)
|
|
7611
|
+
.map((e) => `${Number(e?.testcaseId)}|${e?.expAssignedTo ?? null}`));
|
|
7195
7612
|
const added = [];
|
|
7196
7613
|
const skipped = [];
|
|
7197
7614
|
const rows = [];
|
|
7198
7615
|
for (const c of candidates) {
|
|
7199
7616
|
const code = str(c.raw, 'code') ?? `TC-${c.raw.id}`;
|
|
7200
|
-
const key = `${Number(c.raw.id)}|${assignee}`;
|
|
7201
|
-
if (
|
|
7617
|
+
const key = `${Number(c.raw.id)}|${String(c.versionId ?? '')}|${assignee}`;
|
|
7618
|
+
if (seenAnyVersion.has(`${Number(c.raw.id)}|${assignee}`)) {
|
|
7202
7619
|
skipped.push({ code, reason: 'already in the plan' });
|
|
7203
7620
|
continue;
|
|
7204
7621
|
}
|
|
7205
|
-
|
|
7622
|
+
if (seenExact.has(key)) {
|
|
7623
|
+
skipped.push({ code, reason: `already in the plan (${c.versionName || c.versionId})` });
|
|
7624
|
+
continue;
|
|
7625
|
+
}
|
|
7626
|
+
seenExact.add(key);
|
|
7206
7627
|
const tcDesc = str(c.raw, 'description');
|
|
7207
7628
|
rows.push({
|
|
7208
7629
|
testcaseId: Number(c.raw.id), code, projectId, moduleId: Number(c.raw.moduleId),
|
|
@@ -7265,77 +7686,154 @@ export class SimplifyQaAdapter {
|
|
|
7265
7686
|
const doc = raw?.data ?? raw;
|
|
7266
7687
|
return doc && typeof doc === 'object' && doc.id !== undefined ? doc : null;
|
|
7267
7688
|
}
|
|
7268
|
-
/** Configure the plan's STACK canvas
|
|
7269
|
-
* them — the same document the UI's Stack Setup saves
|
|
7270
|
-
* 'STACK'). Round-robin
|
|
7689
|
+
/** Configure the plan's STACK canvas — N stacks (or one described per stack: local / remote / cloud, its browser, its machine,
|
|
7690
|
+
* its test cases) with the plan's automation test cases spread over them — the same document the UI's Stack Setup saves
|
|
7691
|
+
* (`POST/PUT /tm/executionFlow`, flowType 'STACK'). Round-robin unless test cases are named; `append` adds stacks to the
|
|
7692
|
+
* saved setup. The backend divides the saved stacks at run time. */
|
|
7271
7693
|
async configurePlanStacks(planId, opts) {
|
|
7272
|
-
const count = Math.trunc(opts.count);
|
|
7273
|
-
if (!Number.isFinite(count) || count < 1)
|
|
7274
|
-
throw new Error('stacks must be at least 1.');
|
|
7275
7694
|
const plan = await this.readOwnPlan(planId, { writable: true });
|
|
7276
7695
|
const projectId = this.requireProjectId();
|
|
7277
|
-
const
|
|
7696
|
+
const label = String(plan['code'] ?? planId);
|
|
7278
7697
|
const entries = (await this.listPlanEntries(Number(plan['id'])))
|
|
7279
7698
|
.filter((e) => String(e.executionType ?? '').toUpperCase() === 'AUTOMATION' && String(e.status ?? '').toUpperCase() !== 'BLOCKED');
|
|
7280
7699
|
if (!entries.length)
|
|
7281
|
-
throw new Error(`${
|
|
7282
|
-
const
|
|
7283
|
-
const browser = { name: browserKey.charAt(0).toUpperCase() + browserKey.slice(1), key: browserKey, type: 'NONE' };
|
|
7284
|
-
const existing = await this.getPlanStacks(planId);
|
|
7285
|
-
const stackDefs = Array.from({ length: count }, (_, i) => ({
|
|
7286
|
-
id: randomUUID(), name: `Stack ${i + 1}`, position: null,
|
|
7287
|
-
mode, agentId: null,
|
|
7288
|
-
executionPlatform: { LOCAL: {}, REMOTE: {}, CLOUD: mode === 'CLOUD' ? { browser } : {} },
|
|
7289
|
-
items: [],
|
|
7290
|
-
}));
|
|
7291
|
-
entries.forEach((e, i) => {
|
|
7292
|
-
const stack = stackDefs[i % count];
|
|
7700
|
+
throw new Error(`${label} has no AUTOMATION test cases to distribute.`);
|
|
7701
|
+
const cases = entries.map((e) => {
|
|
7293
7702
|
const tech = String(e.tcType ?? 'WEB').toUpperCase();
|
|
7294
7703
|
const p = e.executionPlatform ?? {};
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
:
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7704
|
+
return {
|
|
7705
|
+
ref: { code: e.code ?? `TC-${e.testcaseId}`, id: String(e.testcaseId) },
|
|
7706
|
+
key: `${e.testcaseId}|${e.stepId ?? ''}`, tech,
|
|
7707
|
+
nativePlatform: { name: p.name, id: p.id, technologyType: p.technologyType ?? tech, type: p.type ?? 'NONE',
|
|
7708
|
+
...(p.cloudDeviceType ? { cloudDeviceType: p.cloudDeviceType } : {}), ...(p.osVersion ? { osVersion: p.osVersion } : {}) },
|
|
7709
|
+
item: (platform) => ({
|
|
7710
|
+
id: e.testcaseId, versionId: e.tcVersionId, stepId: e.stepId, type: e.type ?? 'TC',
|
|
7711
|
+
technologyType: tech, name: e.tcName ?? '', description: '', versionName: e.versionName ?? '',
|
|
7712
|
+
seq: e.seq ?? 0, stepCount: -1, code: e.code ?? '', prerequisite: '',
|
|
7713
|
+
projectId, projectName: '', moduleId: e.moduleId ?? null, moduleName: '',
|
|
7714
|
+
userstoryId: e.userstoryId ?? null, userstoryName: '',
|
|
7715
|
+
sourceType: e.sourceType ?? null, sourceId: e.sourceId ?? null,
|
|
7716
|
+
assignTo: e.expAssignedTo ?? null, assignDate: e.expAssignedDate ?? null, assigneeName: '',
|
|
7717
|
+
createdByName: '', createdBy: null,
|
|
7718
|
+
executionType: 'AUTOMATION', status: 'NOTEXECUTED', executionId: null, executionOS: null,
|
|
7719
|
+
iterationsSelected: [], platform,
|
|
7720
|
+
}),
|
|
7721
|
+
};
|
|
7722
|
+
});
|
|
7723
|
+
return this.saveStackFlow('EP', Number(plan['id']), label, projectId, cases, opts, await this.getPlanStacks(planId));
|
|
7724
|
+
}
|
|
7725
|
+
/** Save a STACK canvas (plan or suite) the way the UI's Save does and read it back. Per stack: its platform (LOCAL stamps this
|
|
7726
|
+
* machine's agent, REMOTE the chosen machine, CLOUD none) and the browser its WEB test cases run in; test cases spread
|
|
7727
|
+
* round-robin, or as named. `append` keeps the saved stacks and adds new ones. Refuses what the UI refuses (an empty stack). */
|
|
7728
|
+
async saveStackFlow(parentType, parentId, label, projectId, cases, opts, existing) {
|
|
7729
|
+
const append = opts.append === true;
|
|
7730
|
+
const savedStacks = Array.isArray(existing?.['stacks']) ? existing['stacks'] : [];
|
|
7731
|
+
if (append && !savedStacks.length)
|
|
7732
|
+
throw new Error(`${label} has no saved stack setup to add to — run stack_setup without append first.`);
|
|
7733
|
+
const fresh = resolveStacks({ count: opts.count, mode: opts.mode, browser: opts.browser, stackConfigs: opts.stackConfigs });
|
|
7734
|
+
// REMOTE stacks name a machine — resolve it to the registry row id the UI stores, refusing one that does not exist.
|
|
7735
|
+
const needsRemote = fresh.some((s) => s.mode === 'REMOTE');
|
|
7736
|
+
const machines = needsRemote ? await this.listLocalAgents() : [];
|
|
7737
|
+
for (const s of fresh) {
|
|
7738
|
+
if (s.mode !== 'REMOTE')
|
|
7739
|
+
continue;
|
|
7740
|
+
const want = String(s.agentId).trim().toLowerCase();
|
|
7741
|
+
const hit = machines.find((m) => m.id.toLowerCase() === want) ?? machines.find((m) => (m.name ?? '').toLowerCase() === want);
|
|
7742
|
+
if (!hit) {
|
|
7743
|
+
throw new Error(`No machine "${s.agentId}" to run a REMOTE stack on. Registered: ${machines.map((m) => `${m.name ?? m.id} (${m.id})`).join(', ') || '(none)'}.`);
|
|
7744
|
+
}
|
|
7745
|
+
s.agentId = hit.id;
|
|
7746
|
+
}
|
|
7747
|
+
// LOCAL stacks carry the saving user's own agent (the UI stamps `_us.agentId`); without a registered agent it stays empty.
|
|
7748
|
+
let localAgent = null;
|
|
7749
|
+
if (fresh.some((s) => s.mode === 'LOCAL'))
|
|
7750
|
+
localAgent = await this.resolveLocalAgentId().catch(() => null);
|
|
7751
|
+
const keyOf = (it) => `${it?.id ?? it?.testcaseId}|${it?.stepId ?? ''}`;
|
|
7752
|
+
const current = append
|
|
7753
|
+
? savedStacks.map((s) => (Array.isArray(s?.items) ? s.items : [])
|
|
7754
|
+
.map((it) => cases.findIndex((c) => c.key === keyOf(it))).filter((i) => i >= 0))
|
|
7755
|
+
: [];
|
|
7756
|
+
const { buckets, unassigned } = distributeCases(cases.map((c) => c.ref), fresh, current);
|
|
7757
|
+
const empty = firstEmptyStack(buckets);
|
|
7758
|
+
if (empty !== undefined) {
|
|
7759
|
+
throw new Error(`${label} has ${cases.length} test case(s) — it cannot fill ${buckets.length} stacks (stack ${empty} would have none, and every stack needs at least one). Use fewer stacks or name test cases for it.`);
|
|
7760
|
+
}
|
|
7761
|
+
const cfgs = savedStacks.map((s, i) => ({
|
|
7762
|
+
id: String(s.id), name: String(s.name ?? `Stack ${i + 1}`), position: s.position ?? null,
|
|
7763
|
+
mode: String(s.mode ?? 'LOCAL').toUpperCase(), agentId: s.agentId ?? null,
|
|
7764
|
+
executionPlatform: { LOCAL: {}, REMOTE: {}, CLOUD: {}, ...(s.executionPlatform ?? {}) },
|
|
7765
|
+
...(s.createdBy !== undefined ? { createdBy: s.createdBy } : {}),
|
|
7766
|
+
}));
|
|
7767
|
+
if (!append)
|
|
7768
|
+
cfgs.length = 0;
|
|
7769
|
+
const taken = new Set(cfgs.map((c) => c.name.toLowerCase()));
|
|
7770
|
+
fresh.forEach((s) => {
|
|
7771
|
+
let n = cfgs.length + 1;
|
|
7772
|
+
while (taken.has(`stack ${n}`))
|
|
7773
|
+
n++;
|
|
7774
|
+
const name = `Stack ${n}`;
|
|
7775
|
+
taken.add(name.toLowerCase());
|
|
7776
|
+
cfgs.push({
|
|
7777
|
+
id: randomUUID(), name, position: null, mode: s.mode,
|
|
7778
|
+
agentId: s.mode === 'REMOTE' ? s.agentId : s.mode === 'LOCAL' ? localAgent : null,
|
|
7779
|
+
executionPlatform: { LOCAL: {}, REMOTE: {}, CLOUD: {}, [s.mode]: { browser: { id: s.browser.key, key: s.browser.key, name: s.browser.key, technologyType: 'WEB', type: 'NONE' } } },
|
|
7780
|
+
});
|
|
7781
|
+
});
|
|
7782
|
+
const stackDefs = cfgs.map((c, n) => {
|
|
7783
|
+
const mine = (buckets[n] ?? []).map((i) => cases[i]);
|
|
7784
|
+
const bucket = c.executionPlatform[c.mode] ?? {};
|
|
7785
|
+
const savedKey = bucket.browser?.key ?? bucket.browser?.id;
|
|
7786
|
+
const browser = savedKey ? { key: String(savedKey), name: String(savedKey), technologyType: 'WEB', type: 'NONE' } : pickBrowser(undefined, c.mode);
|
|
7787
|
+
// like the UI, a browser pick only stays where the stack has a WEB test case
|
|
7788
|
+
const hasWeb = mine.some((k) => k.tech === 'WEB');
|
|
7789
|
+
for (const m of ['LOCAL', 'REMOTE', 'CLOUD'])
|
|
7790
|
+
if (!hasWeb && c.executionPlatform[m]?.browser)
|
|
7791
|
+
delete c.executionPlatform[m].browser;
|
|
7792
|
+
if (hasWeb && !c.executionPlatform[c.mode].browser)
|
|
7793
|
+
c.executionPlatform[c.mode] = { ...c.executionPlatform[c.mode], browser: { id: browser.key, key: browser.key, name: browser.key, technologyType: 'WEB', type: 'NONE' } };
|
|
7794
|
+
return {
|
|
7795
|
+
...c,
|
|
7796
|
+
items: mine.map((k) => k.item(PLAN_SPECIAL_TECH.includes(k.tech)
|
|
7797
|
+
? [{ name: k.tech, id: k.tech, technologyType: k.tech, type: 'NONE' }]
|
|
7798
|
+
: k.tech === 'WEB' ? [{ name: browser.key, id: browser.key, technologyType: 'WEB', type: 'NONE' }] : [k.nativePlatform])),
|
|
7312
7799
|
};
|
|
7313
|
-
stack.items.push(item);
|
|
7314
7800
|
});
|
|
7801
|
+
const viewMode = existing?.['viewMode'] === 'canvas' ? 'canvas' : 'grid'; // the validator takes only 'grid' | 'canvas'
|
|
7315
7802
|
const payload = {
|
|
7316
7803
|
...(existing?.['id'] ? { id: existing['id'] } : {}),
|
|
7317
|
-
parentId
|
|
7318
|
-
|
|
7319
|
-
|
|
7804
|
+
parentId, parentType, flowType: 'STACK', projectId, viewMode, stacks: stackDefs,
|
|
7805
|
+
connections: append && Array.isArray(existing?.['connections']) ? existing['connections'] : [],
|
|
7806
|
+
canvasConfig: existing?.['canvasConfig'] ?? { startNodePosition: { x: 300, y: 50 } },
|
|
7320
7807
|
};
|
|
7321
7808
|
if (existing?.['id'])
|
|
7322
7809
|
await this.http.putJson('/tm/executionFlow', payload);
|
|
7323
7810
|
else
|
|
7324
7811
|
await this.http.postJson('/tm/executionFlow', payload);
|
|
7325
7812
|
// Read it back — the canvas shows the saved document, and a run divides by it.
|
|
7326
|
-
const after = await this.getPlanStacks(
|
|
7327
|
-
const
|
|
7328
|
-
if (
|
|
7329
|
-
throw new Error(`Saved ${
|
|
7813
|
+
const after = parentType === 'EP' ? await this.getPlanStacks(String(parentId)) : await this.getSuiteStacks(String(parentId));
|
|
7814
|
+
const saved = Array.isArray(after?.['stacks']) ? after['stacks'] : [];
|
|
7815
|
+
if (saved.length !== stackDefs.length)
|
|
7816
|
+
throw new Error(`Saved ${stackDefs.length} stack(s) but ${label}'s STACK drawing reads back ${saved.length}.`);
|
|
7817
|
+
const wrong = saved.findIndex((s, n) => (Array.isArray(s?.items) ? s.items.length : 0) !== (buckets[n]?.length ?? 0));
|
|
7818
|
+
if (wrong >= 0)
|
|
7819
|
+
throw new Error(`${label}'s stack ${wrong + 1} reads back with a different number of test cases than was saved.`);
|
|
7820
|
+
const usesCloud = saved.some((s) => String(s?.mode).toUpperCase() === 'CLOUD');
|
|
7821
|
+
const cloudAvailable = usesCloud ? (await this.listCloudRunners().catch(() => [])).some((r) => r.online) : undefined;
|
|
7822
|
+
const notes = [];
|
|
7823
|
+
if (fresh.some((s) => s.mode === 'LOCAL') && !localAgent) {
|
|
7824
|
+
notes.push('No local agent is registered on this machine, so the LOCAL stack(s) carry no agent yet — open the Stack Setup and save it from the machine that will run them.');
|
|
7330
7825
|
}
|
|
7331
|
-
const cloudAvailable = mode === 'CLOUD' ? (await this.listCloudRunners().catch(() => [])).some((r) => r.online) : undefined;
|
|
7332
7826
|
return {
|
|
7333
7827
|
created: !existing,
|
|
7334
7828
|
...(cloudAvailable !== undefined ? { cloudAvailable } : {}),
|
|
7335
|
-
stacks:
|
|
7336
|
-
id: String(s.id ?? ''), name: String(s.name ?? `Stack ${
|
|
7829
|
+
stacks: saved.map((s, n) => ({
|
|
7830
|
+
id: String(s.id ?? ''), name: String(s.name ?? `Stack ${n + 1}`), mode: String(s.mode ?? ''),
|
|
7831
|
+
...(s.agentId ? { agentId: String(s.agentId) } : {}),
|
|
7832
|
+
...(s.executionPlatform?.[String(s.mode ?? '')]?.browser?.name ? { browser: String(s.executionPlatform[String(s.mode)].browser.name) } : {}),
|
|
7337
7833
|
codes: (Array.isArray(s.items) ? s.items : []).map((it) => String(it.code ?? `TC-${it.id}`)),
|
|
7338
7834
|
})),
|
|
7835
|
+
...(unassigned.length ? { unassigned: unassigned.map((i) => cases[i].ref.code) } : {}),
|
|
7836
|
+
...(notes.length ? { notes } : {}),
|
|
7339
7837
|
};
|
|
7340
7838
|
}
|
|
7341
7839
|
async startExecutionPlanRun(planId, opts) {
|
|
@@ -7368,6 +7866,7 @@ export class SimplifyQaAdapter {
|
|
|
7368
7866
|
// (NONE when cloud isn't set up) — it is NOT gated on a cloud machine unless a stack really is CLOUD.
|
|
7369
7867
|
let agentId;
|
|
7370
7868
|
let cloudType = 'NONE';
|
|
7869
|
+
let stackCount = 0;
|
|
7371
7870
|
const requireLocalAgent = async () => {
|
|
7372
7871
|
const probe = await this.probeLocalAgentDetailed();
|
|
7373
7872
|
if (!probe.up) {
|
|
@@ -7398,6 +7897,7 @@ export class SimplifyQaAdapter {
|
|
|
7398
7897
|
const stacks = Array.isArray(flow?.['stacks']) ? flow['stacks'] : [];
|
|
7399
7898
|
if (!stacks.length)
|
|
7400
7899
|
throw new Error(`${code} has no saved stack setup — configure it first (action:"stack_setup").`);
|
|
7900
|
+
stackCount = stacks.length;
|
|
7401
7901
|
// The backend runs only the stacks holding a test case assigned to the user who starts the run, and silently does
|
|
7402
7902
|
// nothing for anyone else — refuse that here instead of reporting a run that executes nothing.
|
|
7403
7903
|
const me = await this.ensureUserId();
|
|
@@ -7406,6 +7906,10 @@ export class SimplifyQaAdapter {
|
|
|
7406
7906
|
throw new Error(`None of ${code}'s stack test cases are assigned to you, so a stack run started by you would execute nothing. ` +
|
|
7407
7907
|
'Run it as the assignee, or assign the test cases to yourself.');
|
|
7408
7908
|
}
|
|
7909
|
+
const noMachine = mine.filter((s) => String(s?.mode).toUpperCase() === 'REMOTE' && !s?.agentId);
|
|
7910
|
+
if (noMachine.length) {
|
|
7911
|
+
throw new Error(`${code} has REMOTE stack(s) with no machine chosen (${noMachine.map((s) => s?.name ?? s?.id).join(', ')}) — pick one with stack_setup (stackConfigs: [{ mode:"remote", agentId }]).`);
|
|
7912
|
+
}
|
|
7409
7913
|
const cloudStacks = mine.filter((s) => String(s?.mode).toUpperCase() === 'CLOUD');
|
|
7410
7914
|
if (cloudStacks.length) {
|
|
7411
7915
|
const online = await onlineCloud();
|
|
@@ -7431,6 +7935,7 @@ export class SimplifyQaAdapter {
|
|
|
7431
7935
|
const shellItems = Array.isArray(shell.executionItems) ? shell.executionItems : [];
|
|
7432
7936
|
const items = [];
|
|
7433
7937
|
const started = [];
|
|
7938
|
+
const cloudNeedsBrowser = [];
|
|
7434
7939
|
const skipped = [];
|
|
7435
7940
|
for (const e of runnable) {
|
|
7436
7941
|
const item = shellItems.find((it) => it.id == e.testcaseId && it.assignTo == e.expAssignedTo
|
|
@@ -7442,16 +7947,33 @@ export class SimplifyQaAdapter {
|
|
|
7442
7947
|
}
|
|
7443
7948
|
const tech = String(item.technologyType ?? e.tcType ?? '');
|
|
7444
7949
|
const p = e.executionPlatform ?? {};
|
|
7445
|
-
|
|
7950
|
+
let cloudWeb;
|
|
7951
|
+
if (runMode === 'cloud' && tech.toUpperCase() === 'WEB') {
|
|
7952
|
+
// the cloud picker is Chrome / Firefox / Edge Headless: a browser the caller names applies to every web test case
|
|
7953
|
+
if (opts.browser)
|
|
7954
|
+
cloudWeb = [cloudBrowserEntry(opts.browser)];
|
|
7955
|
+
else if (/_HEADLESS$/i.test(String(p.id ?? '')))
|
|
7956
|
+
cloudWeb = [{ name: p.name, id: p.id, technologyType: 'WEB', type: p.type ?? 'NONE' }];
|
|
7957
|
+
else {
|
|
7958
|
+
cloudNeedsBrowser.push(c);
|
|
7959
|
+
continue;
|
|
7960
|
+
}
|
|
7961
|
+
}
|
|
7962
|
+
const platform = cloudWeb ?? (PLAN_SPECIAL_TECH.includes(tech)
|
|
7446
7963
|
? [{ name: tech, id: tech, technologyType: tech, type: 'NONE' }]
|
|
7447
7964
|
: [{ name: p.name, id: p.id, technologyType: p.technologyType, type: p.type,
|
|
7448
|
-
...(p.cloudDeviceType ? { cloudDeviceType: p.cloudDeviceType } : {}), ...(p.osVersion ? { osVersion: p.osVersion } : {}) }];
|
|
7965
|
+
...(p.cloudDeviceType ? { cloudDeviceType: p.cloudDeviceType } : {}), ...(p.osVersion ? { osVersion: p.osVersion } : {}) }]);
|
|
7449
7966
|
items.push({ ...item, name: e.tcName, isSelected: true, platform, configuration: {}, startTime: new Date().toISOString() });
|
|
7450
7967
|
started.push(c);
|
|
7451
7968
|
}
|
|
7969
|
+
if (cloudNeedsBrowser.length) {
|
|
7970
|
+
throw new Error(`ASK the user which browser to run ${code} in on the cloud — ${CLOUD_BROWSER_NAMES.join(', ')} (cloud runs are headless) — then call again with \`browser\` set. ` +
|
|
7971
|
+
`It has no saved cloud browser for: ${cloudNeedsBrowser.join(', ')}.`);
|
|
7972
|
+
}
|
|
7452
7973
|
if (!items.length)
|
|
7453
7974
|
throw new Error(`${code} can't run: none of its test cases are part of the plan's last execution.`);
|
|
7454
7975
|
const shellCode = String(shell.code ?? `#${shell.id}`);
|
|
7976
|
+
const priorStatus = String(shell.status ?? 'NOTEXECUTED');
|
|
7455
7977
|
await this.http.putJson('/exec/execution/status', { id: Number(shell.id), projectId, status: 'INPROGRESS' });
|
|
7456
7978
|
const body = { ...shell };
|
|
7457
7979
|
for (const k of PLAN_RUN_DROP_KEYS)
|
|
@@ -7466,6 +7988,9 @@ export class SimplifyQaAdapter {
|
|
|
7466
7988
|
globalConfiguration: {
|
|
7467
7989
|
TERMINATE_ON_FAIL: plan['terminateOnFailure'] ?? false, NEW_BROWSER_SESSION: plan['newBrowserSession'] ?? false,
|
|
7468
7990
|
RE_EXECUTION_COUNT: plan['autoReExecCount'] ?? 0, RE_EXECUTION_TYPE: plan['autoReExecTriggerOn'] ?? 'AFTER_TESTCASE',
|
|
7991
|
+
// The Execute dialog's "containers" setting: one per stack for a stack run, else the plan's own limit.
|
|
7992
|
+
MINIMUM_CONTAINER_COUNT: plan['minimumContainerCount'] ?? 0,
|
|
7993
|
+
MAXIMUM_CONTAINER_COUNT: plan['maximumContainerCount'] ?? (runMode === 'stack' ? Math.max(1, stackCount) : 5),
|
|
7469
7994
|
},
|
|
7470
7995
|
executionItems: runMode === 'stack' ? [] : items,
|
|
7471
7996
|
});
|
|
@@ -7474,12 +7999,26 @@ export class SimplifyQaAdapter {
|
|
|
7474
7999
|
created = await this.http.postJson('/exec/execution', body);
|
|
7475
8000
|
}
|
|
7476
8001
|
catch (e) {
|
|
7477
|
-
|
|
7478
|
-
|
|
8002
|
+
// The shell was flipped to INPROGRESS above; a refused start must put it back or the plan looks
|
|
8003
|
+
// permanently in progress and every later run reports "no execution id".
|
|
8004
|
+
try {
|
|
8005
|
+
await this.http.putJson('/exec/execution/status', { id: Number(shell.id), projectId, status: priorStatus });
|
|
8006
|
+
}
|
|
8007
|
+
catch { /* best effort — the original error is the one to report */ }
|
|
8008
|
+
throw new Error(`Starting ${code} did not run: ${e instanceof Error ? e.message : String(e)} ` +
|
|
8009
|
+
`(${shellCode} was restored to ${priorStatus}).`);
|
|
7479
8010
|
}
|
|
7480
8011
|
const runId = str(created?.data ?? created, 'id');
|
|
7481
|
-
if (!runId)
|
|
7482
|
-
|
|
8012
|
+
if (!runId) {
|
|
8013
|
+
// Same rollback as a refused POST: never leave the plan's shell stuck INPROGRESS.
|
|
8014
|
+
try {
|
|
8015
|
+
await this.http.putJson('/exec/execution/status', { id: Number(shell.id), projectId, status: priorStatus });
|
|
8016
|
+
}
|
|
8017
|
+
catch { /* best effort */ }
|
|
8018
|
+
const msg = str(created, 'message') ?? str(created?.error, 'message');
|
|
8019
|
+
throw new Error(`Starting ${code} did not run: SimplifyQA returned no execution id` +
|
|
8020
|
+
`${msg ? ` — ${msg}` : ''} (${shellCode} was restored to ${priorStatus}).`);
|
|
8021
|
+
}
|
|
7483
8022
|
return { runId, started, skipped: [...skipped] };
|
|
7484
8023
|
}
|
|
7485
8024
|
/** Every live entry of a plan (the search has no privilege check; scoped to the active project). */
|
|
@@ -7533,33 +8072,21 @@ export class SimplifyQaAdapter {
|
|
|
7533
8072
|
const doc = raw?.data ?? raw;
|
|
7534
8073
|
return doc && typeof doc === 'object' && doc.id !== undefined ? doc : null;
|
|
7535
8074
|
}
|
|
7536
|
-
/** Configure the suite's STACK canvas
|
|
7537
|
-
* document the suite's Stack canvas saves (`POST/PUT /tm/executionFlow`, parentType 'SU', flowType
|
|
7538
|
-
* '
|
|
8075
|
+
/** Configure the suite's STACK canvas — N stacks (or one described per stack) with its test cases spread over them — the same
|
|
8076
|
+
* document the suite's Stack canvas saves (`POST/PUT /tm/executionFlow`, parentType 'SU', flowType 'STACK'). Same options as
|
|
8077
|
+
* a plan's: per-stack platform / browser / machine, named test cases, `append`. */
|
|
7539
8078
|
async configureSuiteStacks(suiteId, opts) {
|
|
7540
|
-
const count = Math.trunc(opts.count);
|
|
7541
|
-
if (!Number.isFinite(count) || count < 1)
|
|
7542
|
-
throw new Error('stacks must be at least 1.');
|
|
7543
8079
|
const suite = await this.readOwnSuite(suiteId);
|
|
7544
8080
|
const label = String(suite['code'] ?? `SU-${suite['id']}`);
|
|
7545
8081
|
if (String(suite['suiteType'] ?? 'AUTOMATION').toUpperCase() === 'MANUAL') {
|
|
7546
8082
|
throw new Error(`${label} is a manual suite — Stack execution is for automation suites.`);
|
|
7547
8083
|
}
|
|
7548
8084
|
const projectId = this.requireProjectId();
|
|
7549
|
-
const mode = (opts.mode ?? 'CLOUD').toUpperCase();
|
|
7550
8085
|
const rows = (Array.isArray(suite['testCases']) ? suite['testCases'] : []).filter((r) => r?.deleted !== true && r?.stepId);
|
|
7551
8086
|
if (!rows.length)
|
|
7552
8087
|
throw new Error(`${label} has no saved test cases to distribute.`);
|
|
7553
|
-
const
|
|
7554
|
-
|
|
7555
|
-
const existing = await this.getSuiteStacks(suiteId);
|
|
7556
|
-
const stackDefs = Array.from({ length: count }, (_, i) => ({
|
|
7557
|
-
id: randomUUID(), name: `Stack ${i + 1}`, position: null,
|
|
7558
|
-
mode, agentId: null,
|
|
7559
|
-
executionPlatform: { LOCAL: {}, REMOTE: {}, CLOUD: mode === 'CLOUD' ? { browser } : {} },
|
|
7560
|
-
items: [],
|
|
7561
|
-
}));
|
|
7562
|
-
let i = 0;
|
|
8088
|
+
const cases = [];
|
|
8089
|
+
let seq = 0;
|
|
7563
8090
|
for (const row of rows) {
|
|
7564
8091
|
const rawTc = await this.fetchRawTestcase(String(row.testcaseId)).catch(() => undefined);
|
|
7565
8092
|
if (!rawTc || !Object.keys(rawTc).length)
|
|
@@ -7567,53 +8094,29 @@ export class SimplifyQaAdapter {
|
|
|
7567
8094
|
const tech = String(str(rawTc, 'tcType') ?? 'WEB').toUpperCase();
|
|
7568
8095
|
const versions = Array.isArray(rawTc?.versions) ? rawTc.versions : [];
|
|
7569
8096
|
const ver = versions.find((v) => str(v, 'id', '_id') === String(row.versionId));
|
|
7570
|
-
const p = row?.executionPlatform?.
|
|
7571
|
-
const
|
|
7572
|
-
|
|
7573
|
-
:
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
8097
|
+
const p = row?.executionPlatform?.LOCAL ?? row?.executionPlatform?.CLOUD ?? row?.executionPlatform ?? {};
|
|
8098
|
+
const n = ++seq;
|
|
8099
|
+
cases.push({
|
|
8100
|
+
ref: { code: str(rawTc, 'code') ?? `TC-${rawTc.id ?? row.testcaseId}`, id: String(rawTc.id ?? row.testcaseId) },
|
|
8101
|
+
key: `${rawTc.id ?? row.testcaseId}|${row.stepId ?? ''}`, tech,
|
|
8102
|
+
nativePlatform: { name: p.name, id: p.id, technologyType: p.technologyType ?? tech, type: p.type ?? 'NONE',
|
|
8103
|
+
...(p.cloudDeviceType ? { cloudDeviceType: p.cloudDeviceType } : {}), ...(p.osVersion ? { osVersion: p.osVersion } : {}) },
|
|
8104
|
+
item: (platform) => ({
|
|
8105
|
+
id: Number(rawTc.id ?? row.testcaseId), versionId: row.versionId, stepId: row.stepId, type: 'TC',
|
|
8106
|
+
technologyType: tech, name: str(rawTc, 'name', 'title') ?? '', description: '', versionName: str(ver, 'name') ?? '',
|
|
8107
|
+
seq: row.seq ?? n, stepCount: -1, code: str(rawTc, 'code') ?? '', prerequisite: '',
|
|
8108
|
+
projectId, projectName: '', moduleId: rawTc.moduleId ?? null, moduleName: '',
|
|
8109
|
+
userstoryId: rawTc.userstoryId ?? null, userstoryName: '',
|
|
8110
|
+
sourceType: null, sourceId: null, assignTo: null, assignDate: null, assigneeName: '',
|
|
8111
|
+
createdByName: '', createdBy: null,
|
|
8112
|
+
executionType: 'AUTOMATION', status: 'NOTEXECUTED', executionId: null, executionOS: null,
|
|
8113
|
+
iterationsSelected: [], platform,
|
|
8114
|
+
}),
|
|
7587
8115
|
});
|
|
7588
|
-
i++;
|
|
7589
8116
|
}
|
|
7590
|
-
if (!
|
|
8117
|
+
if (!cases.length)
|
|
7591
8118
|
throw new Error(`None of ${label}'s test cases could be read, so there is nothing to distribute.`);
|
|
7592
|
-
|
|
7593
|
-
throw new Error(`${label} has ${i} test case(s) — it cannot fill ${count} stacks (every stack needs at least one).`);
|
|
7594
|
-
const payload = {
|
|
7595
|
-
...(existing?.['id'] ? { id: existing['id'] } : {}),
|
|
7596
|
-
parentId: Number(suite['id']), parentType: 'SU', flowType: 'STACK', projectId,
|
|
7597
|
-
viewMode: false, stacks: stackDefs,
|
|
7598
|
-
connections: [], canvasConfig: { startNodePosition: { x: 0, y: 0 } },
|
|
7599
|
-
};
|
|
7600
|
-
if (existing?.['id'])
|
|
7601
|
-
await this.http.putJson('/tm/executionFlow', payload);
|
|
7602
|
-
else
|
|
7603
|
-
await this.http.postJson('/tm/executionFlow', payload);
|
|
7604
|
-
const after = await this.getSuiteStacks(suiteId);
|
|
7605
|
-
const saved = Array.isArray(after?.['stacks']) ? after['stacks'] : [];
|
|
7606
|
-
if (saved.length !== count)
|
|
7607
|
-
throw new Error(`Saved ${count} stack(s) but ${label}'s STACK drawing reads back ${saved.length}.`);
|
|
7608
|
-
const cloudAvailable = mode === 'CLOUD' ? (await this.listCloudRunners().catch(() => [])).some((r) => r.online) : undefined;
|
|
7609
|
-
return {
|
|
7610
|
-
created: !existing,
|
|
7611
|
-
...(cloudAvailable !== undefined ? { cloudAvailable } : {}),
|
|
7612
|
-
stacks: saved.map((s, n) => ({
|
|
7613
|
-
id: String(s.id ?? ''), name: String(s.name ?? `Stack ${n + 1}`), mode: String(s.mode ?? mode),
|
|
7614
|
-
codes: (Array.isArray(s.items) ? s.items : []).map((it) => String(it.code ?? `TC-${it.id}`)),
|
|
7615
|
-
})),
|
|
7616
|
-
};
|
|
8119
|
+
return this.saveStackFlow('SU', Number(suite['id']), label, projectId, cases, opts, await this.getSuiteStacks(suiteId));
|
|
7617
8120
|
}
|
|
7618
8121
|
/** What a suite STACK run needs, checked before anything is created: a saved canvas with no empty stack,
|
|
7619
8122
|
* a cloud machine only when a stack is CLOUD, and this machine's agent only when a stack is LOCAL. */
|
|
@@ -7639,6 +8142,10 @@ export class SimplifyQaAdapter {
|
|
|
7639
8142
|
}
|
|
7640
8143
|
cloudType = online[0]?.cloudType ?? 'VM';
|
|
7641
8144
|
}
|
|
8145
|
+
const noMachine = stacks.filter((s) => String(s?.mode).toUpperCase() === 'REMOTE' && !s?.agentId);
|
|
8146
|
+
if (noMachine.length) {
|
|
8147
|
+
throw new Error(`${label} has REMOTE stack(s) with no machine chosen (${noMachine.map((s) => s?.name ?? s?.id).join(', ')}) — pick one with stack_setup (stackConfigs: [{ mode:"remote", agentId }]).`);
|
|
8148
|
+
}
|
|
7642
8149
|
let agentId = null;
|
|
7643
8150
|
if (stacks.some((s) => (String(s?.mode ?? 'LOCAL')).toUpperCase() === 'LOCAL')) {
|
|
7644
8151
|
const probe = await this.probeLocalAgentDetailed();
|
|
@@ -7731,7 +8238,7 @@ export class SimplifyQaAdapter {
|
|
|
7731
8238
|
if (target.suiteId) {
|
|
7732
8239
|
schedulerType = 'SU';
|
|
7733
8240
|
parent = await this.readOwnSuite(target.suiteId);
|
|
7734
|
-
platForm = suitePlatform(parent, opts.browser, 'schedule it');
|
|
8241
|
+
platForm = suitePlatform(parent, opts.browser, 'schedule it', opts.mode === 'cloud');
|
|
7735
8242
|
}
|
|
7736
8243
|
else if (target.tcId) {
|
|
7737
8244
|
schedulerType = 'TC';
|
|
@@ -7741,7 +8248,7 @@ export class SimplifyQaAdapter {
|
|
|
7741
8248
|
if (Number(parent['projectId']) !== projectId)
|
|
7742
8249
|
throw new Error(`${parent['code'] ?? `TC-${parent['id']}`} is not in project ${projectId}.`);
|
|
7743
8250
|
parentVersionId = testcaseVersion(parent, true).versionId || undefined;
|
|
7744
|
-
platForm = tcPlatform(parent, opts.browser);
|
|
8251
|
+
platForm = tcPlatform(parent, opts.browser, opts.mode === 'cloud');
|
|
7745
8252
|
}
|
|
7746
8253
|
else {
|
|
7747
8254
|
throw new Error('Nothing to schedule: give a test case or a suite.');
|
|
@@ -7882,6 +8389,8 @@ export class SimplifyQaAdapter {
|
|
|
7882
8389
|
// WHAT it runs: a test case or a suite — the same schedule, re-pointed (the Scheduler form's type + target), with the platform and
|
|
7883
8390
|
// version that kind of schedule carries, as createSchedule builds them.
|
|
7884
8391
|
const notes = [];
|
|
8392
|
+
// a cloud schedule's browsers are the cloud ones (headless); the mode being changed in the same call counts
|
|
8393
|
+
const scheduleIsCloud = String(changes.mode ?? doc['executionMode'] ?? '').toLowerCase() === 'cloud';
|
|
7885
8394
|
let target;
|
|
7886
8395
|
if (changes.tcId !== undefined || changes.suiteId !== undefined) {
|
|
7887
8396
|
if (changes.tcId !== undefined && changes.suiteId !== undefined)
|
|
@@ -7890,7 +8399,7 @@ export class SimplifyQaAdapter {
|
|
|
7890
8399
|
const wasType = String(doc['schedulerType'] ?? '');
|
|
7891
8400
|
if (changes.suiteId !== undefined) {
|
|
7892
8401
|
const suite = await this.readOwnSuite(changes.suiteId);
|
|
7893
|
-
const platForm = suitePlatform(suite, changes.browser, 'schedule it');
|
|
8402
|
+
const platForm = suitePlatform(suite, changes.browser, 'schedule it', scheduleIsCloud);
|
|
7894
8403
|
Object.assign(patch, { schedulerType: 'SU', parentId: Number(suite['id']), platForm, parentVersionId: undefined });
|
|
7895
8404
|
target = { type: 'SU', id: Number(suite['id']), code: String(suite['code'] ?? `SU-${suite['id']}`) };
|
|
7896
8405
|
}
|
|
@@ -7904,7 +8413,7 @@ export class SimplifyQaAdapter {
|
|
|
7904
8413
|
const webEntry = (Array.isArray(doc['platForm']) ? doc['platForm'] : []).find((p) => String(p?.technologyType ?? '').toUpperCase() === 'WEB');
|
|
7905
8414
|
const keepBrowser = changes.browser ?? (webEntry?.id ? String(webEntry.id) : undefined);
|
|
7906
8415
|
Object.assign(patch, {
|
|
7907
|
-
schedulerType: 'TC', parentId: Number(tc['id']), platForm: tcPlatform(tc, keepBrowser),
|
|
8416
|
+
schedulerType: 'TC', parentId: Number(tc['id']), platForm: tcPlatform(tc, keepBrowser, scheduleIsCloud),
|
|
7908
8417
|
parentVersionId: testcaseVersion(tc, true).versionId || undefined,
|
|
7909
8418
|
});
|
|
7910
8419
|
target = { type: 'TC', id: Number(tc['id']), code: String(tc['code'] ?? `TC-${tc['id']}`) };
|
|
@@ -7935,8 +8444,9 @@ export class SimplifyQaAdapter {
|
|
|
7935
8444
|
throw new Error('A suite schedule needs a release (the Scheduler marks Release as required for a suite) — pass releaseId (id, code or name).');
|
|
7936
8445
|
}
|
|
7937
8446
|
if (changes.browser && doc['schedulerType'] === 'TC' && finalType === 'TC' && !('platForm' in patch)) {
|
|
7938
|
-
|
|
7939
|
-
|
|
8447
|
+
patch['platForm'] = scheduleIsCloud
|
|
8448
|
+
? [cloudBrowserEntry(changes.browser)]
|
|
8449
|
+
: (() => { const b = sqaBrowser(changes.browser); return [{ id: b, name: b, type: 'NONE', technologyType: 'WEB' }]; })();
|
|
7940
8450
|
}
|
|
7941
8451
|
if (changes.environmentId)
|
|
7942
8452
|
patch['environment'] = await this.environmentKey(changes.environmentId);
|
|
@@ -8289,16 +8799,36 @@ export class SimplifyQaAdapter {
|
|
|
8289
8799
|
}
|
|
8290
8800
|
/** Assemble the strict allow-listed suite entry for an ADD op. Required fields per the SQA
|
|
8291
8801
|
* validator: testcaseId, code, seq (set by the caller), version, versionId, tcType. */
|
|
8292
|
-
async buildSuiteEntryFromTestcase(tcNum) {
|
|
8802
|
+
async buildSuiteEntryFromTestcase(tcNum, requested) {
|
|
8293
8803
|
const raw = await this.fetchRawTestcase(tcNum);
|
|
8294
8804
|
if (Object.keys(raw).length === 0)
|
|
8295
8805
|
throw new Error(`test case ${tcNum} not found (cannot add to suite)`);
|
|
8296
8806
|
const code = str(raw, 'code', 'tcCode') ?? `TC_${tcNum}`;
|
|
8297
8807
|
const tcType = str(raw, 'tcType') ?? 'WEB';
|
|
8808
|
+
const versions = Array.isArray(raw?.versions) ? raw.versions : [];
|
|
8298
8809
|
let versionName = str(raw, 'versionName', 'selectedVersionName');
|
|
8299
8810
|
let versionId = str(raw, 'versionId', 'selectedVersionId');
|
|
8300
|
-
|
|
8301
|
-
|
|
8811
|
+
// A caller may pin a version (the same TC can sit in a suite once per version). The backend only
|
|
8812
|
+
// stores what we send, so an unknown version must FAIL here — otherwise v1.0 was silently added
|
|
8813
|
+
// again and the caller saw "success" for a row that is not the requested one.
|
|
8814
|
+
const wantId = (requested?.versionId ?? '').trim();
|
|
8815
|
+
const wantName = (requested?.version ?? '').trim();
|
|
8816
|
+
if (wantId || wantName) {
|
|
8817
|
+
const hit = versions.find((v) => {
|
|
8818
|
+
const id = str(v, 'id', '_id', 'versionId') ?? '';
|
|
8819
|
+
const name = str(v, 'name', 'versionName') ?? '';
|
|
8820
|
+
return (wantId && id === wantId) || (wantName && name.trim().toLowerCase() === wantName.toLowerCase());
|
|
8821
|
+
});
|
|
8822
|
+
if (!hit) {
|
|
8823
|
+
const available = versions.map((v) => `${str(v, 'name') ?? '?'} (${str(v, 'id', '_id', 'versionId') ?? '?'})`).join(', ');
|
|
8824
|
+
throw new Error(`${code} has no version ${wantId ? `"${wantId}"` : `"${wantName}"`}. ` +
|
|
8825
|
+
`Available versions: ${available || '(none)'}. Read them with sqa_query({ op:"get", collection:"testcases", id:"${code}" }).`);
|
|
8826
|
+
}
|
|
8827
|
+
versionName = str(hit, 'name', 'versionName') ?? versionName;
|
|
8828
|
+
versionId = str(hit, 'id', '_id', 'versionId') ?? versionId;
|
|
8829
|
+
}
|
|
8830
|
+
else if ((!versionName || !versionId) && versions.length > 0) {
|
|
8831
|
+
const v = versions.find((x) => x?.isChecked === true || x?.selected === true) ?? versions[0];
|
|
8302
8832
|
versionName ?? (versionName = str(v, 'name'));
|
|
8303
8833
|
versionId ?? (versionId = str(v, 'id', '_id'));
|
|
8304
8834
|
}
|
|
@@ -10139,12 +10669,17 @@ export class SimplifyQaAdapter {
|
|
|
10139
10669
|
const agentId = mode === 'LOCAL' ? await this.resolveLocalAgentId(opts.agentId)
|
|
10140
10670
|
: mode === 'REMOTE' ? await this.resolveRemoteAgentId(opts.agentId)
|
|
10141
10671
|
: null;
|
|
10142
|
-
// Multi-device parallel: when opts.devices has >1 entry, build
|
|
10143
|
-
//
|
|
10672
|
+
// Multi-device parallel: when opts.devices has >1 entry, build ONE executionItem whose
|
|
10673
|
+
// platform[] array contains ALL devices. The agent's ServerToAgentAdapter checks
|
|
10674
|
+
// executionItems[0].platforms.size() — only when >1 does it create MultiTestCaseMetaData
|
|
10675
|
+
// and MultiTestCaseExecutor.executeInParallel(). One-item-per-device would leave each
|
|
10676
|
+
// item with platforms.size()==1, falling through to single-device serial mode.
|
|
10144
10677
|
const isMultiDevice = opts.devices && opts.devices.length > 1;
|
|
10145
10678
|
let executionItems;
|
|
10146
10679
|
if (isMultiDevice) {
|
|
10147
|
-
|
|
10680
|
+
// Collect all device platforms into a single array for the ONE executionItem
|
|
10681
|
+
const allPlatforms = [];
|
|
10682
|
+
for (const dev of opts.devices) {
|
|
10148
10683
|
const devPlatform = this.buildRunPlatform(tcType, mode, {
|
|
10149
10684
|
deviceId: dev.deviceId,
|
|
10150
10685
|
...(dev.deviceName ? { deviceName: dev.deviceName } : {}),
|
|
@@ -10152,19 +10687,21 @@ export class SimplifyQaAdapter {
|
|
|
10152
10687
|
...(dev.osVersion ? { osVersion: dev.osVersion } : {}),
|
|
10153
10688
|
...(dev.cloudDeviceType ? { cloudDeviceType: dev.cloudDeviceType } : {}),
|
|
10154
10689
|
});
|
|
10155
|
-
|
|
10156
|
-
|
|
10690
|
+
allPlatforms.push(...devPlatform);
|
|
10691
|
+
}
|
|
10692
|
+
const stepId = Math.random().toString(36).slice(2, 8).padEnd(6, '0');
|
|
10693
|
+
executionItems = [{
|
|
10157
10694
|
id: tcNum,
|
|
10158
10695
|
name,
|
|
10159
10696
|
description,
|
|
10160
10697
|
versionId,
|
|
10161
10698
|
versionName,
|
|
10162
|
-
seq:
|
|
10163
|
-
stepId
|
|
10699
|
+
seq: 1,
|
|
10700
|
+
stepId,
|
|
10164
10701
|
stepCount: 0,
|
|
10165
10702
|
technologyType: tcType,
|
|
10166
10703
|
type: 'TC',
|
|
10167
|
-
platform:
|
|
10704
|
+
platform: allPlatforms,
|
|
10168
10705
|
projectId,
|
|
10169
10706
|
projectName,
|
|
10170
10707
|
configuration: {},
|
|
@@ -10176,8 +10713,7 @@ export class SimplifyQaAdapter {
|
|
|
10176
10713
|
prerequisite,
|
|
10177
10714
|
moduleName,
|
|
10178
10715
|
userstoryName: '',
|
|
10179
|
-
};
|
|
10180
|
-
});
|
|
10716
|
+
}];
|
|
10181
10717
|
}
|
|
10182
10718
|
else {
|
|
10183
10719
|
const platform = this.buildRunPlatform(tcType, mode, {
|
|
@@ -10349,6 +10885,7 @@ export class SimplifyQaAdapter {
|
|
|
10349
10885
|
const stackRun = mode === 'STACK' ? await this.suiteStackRunPlan(rawSuite, opts) : undefined;
|
|
10350
10886
|
const members = !stackRun && Array.isArray(rawSuite.testCases) ? rawSuite.testCases : [];
|
|
10351
10887
|
const executionItems = [];
|
|
10888
|
+
const cloudNeedsBrowser = [];
|
|
10352
10889
|
let seqCounter = 0;
|
|
10353
10890
|
for (const row of members) {
|
|
10354
10891
|
seqCounter++;
|
|
@@ -10377,7 +10914,17 @@ export class SimplifyQaAdapter {
|
|
|
10377
10914
|
// mode, send `[]` and let the backend reject/accept per its own rules.
|
|
10378
10915
|
const savedPlatform = row?.executionPlatform?.[mode];
|
|
10379
10916
|
let platform = [];
|
|
10380
|
-
if (
|
|
10917
|
+
if (mode === 'CLOUD' && tcType === 'WEB') {
|
|
10918
|
+
// the cloud picker is Chrome / Firefox / Edge Headless: a browser the caller names applies to every web test case (as the Run dialog's does)
|
|
10919
|
+
const saved = savedPlatform && typeof savedPlatform === 'object' ? String(savedPlatform.id ?? savedPlatform.name ?? '') : '';
|
|
10920
|
+
if (opts.browser)
|
|
10921
|
+
platform = [cloudBrowserEntry(opts.browser)];
|
|
10922
|
+
else if (/_HEADLESS$/i.test(saved))
|
|
10923
|
+
platform = [{ name: savedPlatform.name, id: savedPlatform.id ?? savedPlatform.name, technologyType: 'WEB', type: savedPlatform.type ?? 'NONE' }];
|
|
10924
|
+
else
|
|
10925
|
+
cloudNeedsBrowser.push(str(rawTc, 'code') ?? `TC-${memberTcId}`);
|
|
10926
|
+
}
|
|
10927
|
+
else if (savedPlatform && typeof savedPlatform === 'object') {
|
|
10381
10928
|
const p = {
|
|
10382
10929
|
name: savedPlatform.name,
|
|
10383
10930
|
id: savedPlatform.id ?? savedPlatform.name,
|
|
@@ -10429,6 +10976,10 @@ export class SimplifyQaAdapter {
|
|
|
10429
10976
|
userstoryName: '',
|
|
10430
10977
|
});
|
|
10431
10978
|
}
|
|
10979
|
+
if (cloudNeedsBrowser.length) {
|
|
10980
|
+
throw new Error(`ASK the user which browser to run ${rawSuite.code ?? suiteId} in on the cloud — ${CLOUD_BROWSER_NAMES.join(', ')} (cloud runs are headless) — then call again with \`browser\` set. ` +
|
|
10981
|
+
`It has no saved cloud browser for: ${cloudNeedsBrowser.join(', ')}.`);
|
|
10982
|
+
}
|
|
10432
10983
|
if (!stackRun && executionItems.length === 0) {
|
|
10433
10984
|
throw new Error(`startRun: suite ${suiteId} has no runnable test cases (all members were deleted, ` +
|
|
10434
10985
|
`unreadable, or filtered out).`);
|
|
@@ -10885,10 +11436,8 @@ export class SimplifyQaAdapter {
|
|
|
10885
11436
|
buildRunPlatform(tcType, mode, opts) {
|
|
10886
11437
|
const t = tcType.toUpperCase();
|
|
10887
11438
|
if (t === 'WEB') {
|
|
10888
|
-
if (mode === 'CLOUD')
|
|
10889
|
-
|
|
10890
|
-
return [{ name: key, id: key, technologyType: 'WEB', type: 'NONE' }];
|
|
10891
|
-
}
|
|
11439
|
+
if (mode === 'CLOUD')
|
|
11440
|
+
return [cloudBrowserEntry(opts.browser)];
|
|
10892
11441
|
const b = (opts.browser ?? 'CHROME').toUpperCase();
|
|
10893
11442
|
return [{ name: b, id: b, technologyType: 'WEB', type: 'NONE' }];
|
|
10894
11443
|
}
|
|
@@ -11063,7 +11612,22 @@ export class SimplifyQaAdapter {
|
|
|
11063
11612
|
const m = e instanceof Error ? e.message : String(e);
|
|
11064
11613
|
return /Could not reach the product MCP|fetch failed|ECONNREFUSED/i.test(m);
|
|
11065
11614
|
}
|
|
11066
|
-
|
|
11615
|
+
/** A version of the test case by id or name ("v2.0"). Only versions of THIS test case are accepted —
|
|
11616
|
+
* an unknown one is refused with the list, never silently replaced by the current version. */
|
|
11617
|
+
async resolveTcVersion(tcId, ref) {
|
|
11618
|
+
const raw = await this.fetchRawTestcase(tcId);
|
|
11619
|
+
const versions = toVersionEntries(Array.isArray(raw?.versions) ? raw.versions : []);
|
|
11620
|
+
const want = ref.trim().toLowerCase();
|
|
11621
|
+
const hit = versions.find((v) => v.id === ref.trim()) ?? versions.find((v) => (v.name ?? '').trim().toLowerCase() === want);
|
|
11622
|
+
if (!hit) {
|
|
11623
|
+
throw new Error(`${tcId} has no version "${ref}". Its versions: ${versions.map((v) => `${v.name ?? '?'} (${v.id})`).join(', ') || '(none)'}.`);
|
|
11624
|
+
}
|
|
11625
|
+
return { id: hit.id, name: hit.name ?? hit.id };
|
|
11626
|
+
}
|
|
11627
|
+
async readJournal(tcId, versionId) {
|
|
11628
|
+
// A non-current version has no journal on the agent (it only knows the recorded/current one): read its saved steps.
|
|
11629
|
+
if (versionId)
|
|
11630
|
+
return this.stepsView(tcId, versionId);
|
|
11067
11631
|
const h = this.hop();
|
|
11068
11632
|
if (h) {
|
|
11069
11633
|
try {
|
|
@@ -11076,7 +11640,17 @@ export class SimplifyQaAdapter {
|
|
|
11076
11640
|
}
|
|
11077
11641
|
return this.stepsView(tcId);
|
|
11078
11642
|
}
|
|
11079
|
-
async editJournal(tcId, ops) {
|
|
11643
|
+
async editJournal(tcId, ops, versionId) {
|
|
11644
|
+
if (versionId) {
|
|
11645
|
+
// The agent's journal belongs to the current version only, so a pinned version is edited on its saved steps.
|
|
11646
|
+
const pinned = new Set(['set_meta', 'add_step', 'update_step', 'update_steps', 'add_assertions', 'remove_step', 'remove_steps', 'move_step', 'insert_nested', 'duplicate_step']);
|
|
11647
|
+
const needsAgent = ops.filter((o) => !pinned.has(o.op)).map((o) => o.op);
|
|
11648
|
+
if (needsAgent.length) {
|
|
11649
|
+
throw new Error(`${needsAgent.join(', ')} cannot be applied to a chosen version (versionId "${versionId}") — it needs the agent, which only edits the current version. ` +
|
|
11650
|
+
'Select that version as current in SimplifyQA first, or use the other ops.');
|
|
11651
|
+
}
|
|
11652
|
+
return this.editStepsDirect(tcId, ops, versionId);
|
|
11653
|
+
}
|
|
11080
11654
|
// Every step-editing op is applied straight to the saved test case. Sent through the agent, an edit
|
|
11081
11655
|
// either opened the recorder window (SCRPY) and never landed, or — as with a plain `update_step` on
|
|
11082
11656
|
// a saved TC — hit the agent's JOURNAL editor, which only knows recording journals and rejected a
|
|
@@ -11105,14 +11679,21 @@ export class SimplifyQaAdapter {
|
|
|
11105
11679
|
}
|
|
11106
11680
|
return this.editStepsDirect(tcId, ops);
|
|
11107
11681
|
}
|
|
11108
|
-
async stepsView(tcId) {
|
|
11109
|
-
const
|
|
11110
|
-
|
|
11682
|
+
async stepsView(tcId, versionRef) {
|
|
11683
|
+
const pinned = versionRef ? await this.resolveTcVersion(tcId, versionRef) : undefined;
|
|
11684
|
+
const tc = await this.getTestCase(tcId, pinned?.id);
|
|
11685
|
+
const cur = tc.versions?.find((v) => v.id === tc.currentVersionId);
|
|
11686
|
+
return {
|
|
11687
|
+
tcId, source: 'steps', steps: tc.steps ?? [],
|
|
11688
|
+
...(cur ? { version: { id: cur.id, name: cur.name ?? cur.id } } : {}),
|
|
11689
|
+
...(tc.versions ? { versionCount: tc.versions.length } : {}),
|
|
11690
|
+
};
|
|
11111
11691
|
}
|
|
11112
11692
|
/** Agent-free step edit: read the test case, apply remove / update / move by step number, renumber, and
|
|
11113
11693
|
* save through updateTestCase (which sends removed steps back with `deleted:true`, as the UI does). */
|
|
11114
|
-
async editStepsDirect(tcId, ops) {
|
|
11115
|
-
|
|
11694
|
+
async editStepsDirect(tcId, ops, versionRef) {
|
|
11695
|
+
const pinned = versionRef ? await this.resolveTcVersion(tcId, versionRef) : undefined;
|
|
11696
|
+
let tc = await this.getTestCase(tcId, pinned?.id);
|
|
11116
11697
|
log(`[mcp][editStepsDirect] tcId=${tcId} technologyType=${tc.technologyType ?? '(none)'} executionPlatform=${tc.executionPlatform ? JSON.stringify(tc.executionPlatform) : '(none)'} steps=${tc.steps?.length ?? 0} ops=${ops.map(o => o.op).join(',')}`);
|
|
11117
11698
|
let steps = [...(tc.steps ?? [])];
|
|
11118
11699
|
for (const op of ops) {
|
|
@@ -11242,7 +11823,7 @@ export class SimplifyQaAdapter {
|
|
|
11242
11823
|
steps = steps.map((x, k) => ({ ...x, n: k + 1 }));
|
|
11243
11824
|
}
|
|
11244
11825
|
await this.updateTestCase(tcId, { ...tc, steps });
|
|
11245
|
-
return this.stepsView(tcId);
|
|
11826
|
+
return this.stepsView(tcId, pinned?.id);
|
|
11246
11827
|
}
|
|
11247
11828
|
// ---------------------------------------------------------------------- Self-healing
|
|
11248
11829
|
/** `heal_propose` on the product server: replay + DOM evidence + proposals. Read-only — it never
|