simplify3x-connect 0.31.2 → 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 +149 -46
- package/dist/adapters/simplifyqa/adapter.d.ts.map +1 -1
- package/dist/adapters/simplifyqa/adapter.js +766 -206
- 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 +5 -0
- package/dist/tools/autoDefectLog.d.ts.map +1 -1
- package/dist/tools/autoDefectLog.js +29 -0
- package/dist/tools/autoDefectLog.js.map +1 -1
- 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 +38 -20
- 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 +14 -13
- 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'));
|
|
@@ -4455,11 +4807,29 @@ export class SimplifyQaAdapter {
|
|
|
4455
4807
|
* failed step only when this is on AND the suite / execution plan has autoDefectLog set — the UI
|
|
4456
4808
|
* refuses the suite/plan toggle while it is off. `undefined` = could not be read (no access): callers
|
|
4457
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
|
+
}
|
|
4458
4814
|
async autoDefectLogStatus() {
|
|
4459
4815
|
try {
|
|
4460
4816
|
const project = await this.getProjectById(String(this.requireProjectId()));
|
|
4461
|
-
const
|
|
4462
|
-
|
|
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;
|
|
4463
4833
|
}
|
|
4464
4834
|
catch {
|
|
4465
4835
|
return undefined;
|
|
@@ -6639,6 +7009,10 @@ export class SimplifyQaAdapter {
|
|
|
6639
7009
|
// The catalog can miss a project's newer custom actions, so look the id / name / display name up
|
|
6640
7010
|
// directly with a targeted search (never GET /tm/action/:id — that route reads the id as a project id).
|
|
6641
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;
|
|
6642
7016
|
if (!meta) {
|
|
6643
7017
|
try {
|
|
6644
7018
|
meta = await this.findActionLive(name);
|
|
@@ -6653,12 +7027,16 @@ export class SimplifyQaAdapter {
|
|
|
6653
7027
|
if (meta.displayName)
|
|
6654
7028
|
catalog.set(`dis::${meta.displayName.toLowerCase()}`, meta);
|
|
6655
7029
|
}
|
|
7030
|
+
else if (isNumericId && s.sourceId) {
|
|
7031
|
+
meta = { id: Number.parseInt(name, 10), objectRequired: false };
|
|
7032
|
+
preserveAction = true;
|
|
7033
|
+
}
|
|
6656
7034
|
}
|
|
6657
7035
|
if (!meta) {
|
|
6658
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}]`);
|
|
6659
7037
|
}
|
|
6660
|
-
let objectId = null;
|
|
6661
|
-
if (meta.objectRequired) {
|
|
7038
|
+
let objectId = preserveAction ? undefined : null;
|
|
7039
|
+
if (!preserveAction && meta.objectRequired) {
|
|
6662
7040
|
// Resolution ladder (first match wins):
|
|
6663
7041
|
// 1. objectRef.id set → use directly (round-trip OR LLM referencing a known object)
|
|
6664
7042
|
// 2. sourceId set but no objectRef.id → preserve DB value (existing step, backend may
|
|
@@ -6944,9 +7322,19 @@ export class SimplifyQaAdapter {
|
|
|
6944
7322
|
const tcNum = numericId(String(op.tcId));
|
|
6945
7323
|
switch (op.op) {
|
|
6946
7324
|
case 'add': {
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
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);
|
|
6950
7338
|
break;
|
|
6951
7339
|
}
|
|
6952
7340
|
case 'remove': {
|
|
@@ -7051,7 +7439,8 @@ export class SimplifyQaAdapter {
|
|
|
7051
7439
|
const raw = await this.readOwnSuite(id);
|
|
7052
7440
|
const payload = {
|
|
7053
7441
|
id: raw['id'], suiteType: raw['suiteType'], projectId: raw['projectId'],
|
|
7054
|
-
|
|
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,
|
|
7055
7444
|
};
|
|
7056
7445
|
for (const k of SUITE_SETTING_KEYS)
|
|
7057
7446
|
if (settings[k] !== undefined)
|
|
@@ -7185,7 +7574,12 @@ export class SimplifyQaAdapter {
|
|
|
7185
7574
|
const candidates = [];
|
|
7186
7575
|
for (const tcId of input.tcIds ?? []) {
|
|
7187
7576
|
const raw = await this.readOwnTestcase(tcId);
|
|
7188
|
-
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);
|
|
7189
7583
|
candidates.push({ raw, ...v, platform: entryPlatform(raw.executionPlatform), source: { sourceType: 'testcase', sourceId: 0 } });
|
|
7190
7584
|
}
|
|
7191
7585
|
for (const suiteId of input.suiteIds ?? []) {
|
|
@@ -7206,18 +7600,30 @@ export class SimplifyQaAdapter {
|
|
|
7206
7600
|
}
|
|
7207
7601
|
const existing = await this.listPlanEntries(Number(plan['id']));
|
|
7208
7602
|
let seq = existing.reduce((m, e) => Math.max(m, Number(e?.seq) || 0), 0);
|
|
7209
|
-
|
|
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}`));
|
|
7210
7612
|
const added = [];
|
|
7211
7613
|
const skipped = [];
|
|
7212
7614
|
const rows = [];
|
|
7213
7615
|
for (const c of candidates) {
|
|
7214
7616
|
const code = str(c.raw, 'code') ?? `TC-${c.raw.id}`;
|
|
7215
|
-
const key = `${Number(c.raw.id)}|${assignee}`;
|
|
7216
|
-
if (
|
|
7617
|
+
const key = `${Number(c.raw.id)}|${String(c.versionId ?? '')}|${assignee}`;
|
|
7618
|
+
if (seenAnyVersion.has(`${Number(c.raw.id)}|${assignee}`)) {
|
|
7217
7619
|
skipped.push({ code, reason: 'already in the plan' });
|
|
7218
7620
|
continue;
|
|
7219
7621
|
}
|
|
7220
|
-
|
|
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);
|
|
7221
7627
|
const tcDesc = str(c.raw, 'description');
|
|
7222
7628
|
rows.push({
|
|
7223
7629
|
testcaseId: Number(c.raw.id), code, projectId, moduleId: Number(c.raw.moduleId),
|
|
@@ -7280,77 +7686,154 @@ export class SimplifyQaAdapter {
|
|
|
7280
7686
|
const doc = raw?.data ?? raw;
|
|
7281
7687
|
return doc && typeof doc === 'object' && doc.id !== undefined ? doc : null;
|
|
7282
7688
|
}
|
|
7283
|
-
/** Configure the plan's STACK canvas
|
|
7284
|
-
* them — the same document the UI's Stack Setup saves
|
|
7285
|
-
* '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. */
|
|
7286
7693
|
async configurePlanStacks(planId, opts) {
|
|
7287
|
-
const count = Math.trunc(opts.count);
|
|
7288
|
-
if (!Number.isFinite(count) || count < 1)
|
|
7289
|
-
throw new Error('stacks must be at least 1.');
|
|
7290
7694
|
const plan = await this.readOwnPlan(planId, { writable: true });
|
|
7291
7695
|
const projectId = this.requireProjectId();
|
|
7292
|
-
const
|
|
7696
|
+
const label = String(plan['code'] ?? planId);
|
|
7293
7697
|
const entries = (await this.listPlanEntries(Number(plan['id'])))
|
|
7294
7698
|
.filter((e) => String(e.executionType ?? '').toUpperCase() === 'AUTOMATION' && String(e.status ?? '').toUpperCase() !== 'BLOCKED');
|
|
7295
7699
|
if (!entries.length)
|
|
7296
|
-
throw new Error(`${
|
|
7297
|
-
const
|
|
7298
|
-
const browser = { name: browserKey.charAt(0).toUpperCase() + browserKey.slice(1), key: browserKey, type: 'NONE' };
|
|
7299
|
-
const existing = await this.getPlanStacks(planId);
|
|
7300
|
-
const stackDefs = Array.from({ length: count }, (_, i) => ({
|
|
7301
|
-
id: randomUUID(), name: `Stack ${i + 1}`, position: null,
|
|
7302
|
-
mode, agentId: null,
|
|
7303
|
-
executionPlatform: { LOCAL: {}, REMOTE: {}, CLOUD: mode === 'CLOUD' ? { browser } : {} },
|
|
7304
|
-
items: [],
|
|
7305
|
-
}));
|
|
7306
|
-
entries.forEach((e, i) => {
|
|
7307
|
-
const stack = stackDefs[i % count];
|
|
7700
|
+
throw new Error(`${label} has no AUTOMATION test cases to distribute.`);
|
|
7701
|
+
const cases = entries.map((e) => {
|
|
7308
7702
|
const tech = String(e.tcType ?? 'WEB').toUpperCase();
|
|
7309
7703
|
const p = e.executionPlatform ?? {};
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
:
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
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])),
|
|
7327
7799
|
};
|
|
7328
|
-
stack.items.push(item);
|
|
7329
7800
|
});
|
|
7801
|
+
const viewMode = existing?.['viewMode'] === 'canvas' ? 'canvas' : 'grid'; // the validator takes only 'grid' | 'canvas'
|
|
7330
7802
|
const payload = {
|
|
7331
7803
|
...(existing?.['id'] ? { id: existing['id'] } : {}),
|
|
7332
|
-
parentId
|
|
7333
|
-
|
|
7334
|
-
|
|
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 } },
|
|
7335
7807
|
};
|
|
7336
7808
|
if (existing?.['id'])
|
|
7337
7809
|
await this.http.putJson('/tm/executionFlow', payload);
|
|
7338
7810
|
else
|
|
7339
7811
|
await this.http.postJson('/tm/executionFlow', payload);
|
|
7340
7812
|
// Read it back — the canvas shows the saved document, and a run divides by it.
|
|
7341
|
-
const after = await this.getPlanStacks(
|
|
7342
|
-
const
|
|
7343
|
-
if (
|
|
7344
|
-
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.');
|
|
7345
7825
|
}
|
|
7346
|
-
const cloudAvailable = mode === 'CLOUD' ? (await this.listCloudRunners().catch(() => [])).some((r) => r.online) : undefined;
|
|
7347
7826
|
return {
|
|
7348
7827
|
created: !existing,
|
|
7349
7828
|
...(cloudAvailable !== undefined ? { cloudAvailable } : {}),
|
|
7350
|
-
stacks:
|
|
7351
|
-
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) } : {}),
|
|
7352
7833
|
codes: (Array.isArray(s.items) ? s.items : []).map((it) => String(it.code ?? `TC-${it.id}`)),
|
|
7353
7834
|
})),
|
|
7835
|
+
...(unassigned.length ? { unassigned: unassigned.map((i) => cases[i].ref.code) } : {}),
|
|
7836
|
+
...(notes.length ? { notes } : {}),
|
|
7354
7837
|
};
|
|
7355
7838
|
}
|
|
7356
7839
|
async startExecutionPlanRun(planId, opts) {
|
|
@@ -7383,6 +7866,7 @@ export class SimplifyQaAdapter {
|
|
|
7383
7866
|
// (NONE when cloud isn't set up) — it is NOT gated on a cloud machine unless a stack really is CLOUD.
|
|
7384
7867
|
let agentId;
|
|
7385
7868
|
let cloudType = 'NONE';
|
|
7869
|
+
let stackCount = 0;
|
|
7386
7870
|
const requireLocalAgent = async () => {
|
|
7387
7871
|
const probe = await this.probeLocalAgentDetailed();
|
|
7388
7872
|
if (!probe.up) {
|
|
@@ -7413,6 +7897,7 @@ export class SimplifyQaAdapter {
|
|
|
7413
7897
|
const stacks = Array.isArray(flow?.['stacks']) ? flow['stacks'] : [];
|
|
7414
7898
|
if (!stacks.length)
|
|
7415
7899
|
throw new Error(`${code} has no saved stack setup — configure it first (action:"stack_setup").`);
|
|
7900
|
+
stackCount = stacks.length;
|
|
7416
7901
|
// The backend runs only the stacks holding a test case assigned to the user who starts the run, and silently does
|
|
7417
7902
|
// nothing for anyone else — refuse that here instead of reporting a run that executes nothing.
|
|
7418
7903
|
const me = await this.ensureUserId();
|
|
@@ -7421,6 +7906,10 @@ export class SimplifyQaAdapter {
|
|
|
7421
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. ` +
|
|
7422
7907
|
'Run it as the assignee, or assign the test cases to yourself.');
|
|
7423
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
|
+
}
|
|
7424
7913
|
const cloudStacks = mine.filter((s) => String(s?.mode).toUpperCase() === 'CLOUD');
|
|
7425
7914
|
if (cloudStacks.length) {
|
|
7426
7915
|
const online = await onlineCloud();
|
|
@@ -7446,6 +7935,7 @@ export class SimplifyQaAdapter {
|
|
|
7446
7935
|
const shellItems = Array.isArray(shell.executionItems) ? shell.executionItems : [];
|
|
7447
7936
|
const items = [];
|
|
7448
7937
|
const started = [];
|
|
7938
|
+
const cloudNeedsBrowser = [];
|
|
7449
7939
|
const skipped = [];
|
|
7450
7940
|
for (const e of runnable) {
|
|
7451
7941
|
const item = shellItems.find((it) => it.id == e.testcaseId && it.assignTo == e.expAssignedTo
|
|
@@ -7457,16 +7947,33 @@ export class SimplifyQaAdapter {
|
|
|
7457
7947
|
}
|
|
7458
7948
|
const tech = String(item.technologyType ?? e.tcType ?? '');
|
|
7459
7949
|
const p = e.executionPlatform ?? {};
|
|
7460
|
-
|
|
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)
|
|
7461
7963
|
? [{ name: tech, id: tech, technologyType: tech, type: 'NONE' }]
|
|
7462
7964
|
: [{ name: p.name, id: p.id, technologyType: p.technologyType, type: p.type,
|
|
7463
|
-
...(p.cloudDeviceType ? { cloudDeviceType: p.cloudDeviceType } : {}), ...(p.osVersion ? { osVersion: p.osVersion } : {}) }];
|
|
7965
|
+
...(p.cloudDeviceType ? { cloudDeviceType: p.cloudDeviceType } : {}), ...(p.osVersion ? { osVersion: p.osVersion } : {}) }]);
|
|
7464
7966
|
items.push({ ...item, name: e.tcName, isSelected: true, platform, configuration: {}, startTime: new Date().toISOString() });
|
|
7465
7967
|
started.push(c);
|
|
7466
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
|
+
}
|
|
7467
7973
|
if (!items.length)
|
|
7468
7974
|
throw new Error(`${code} can't run: none of its test cases are part of the plan's last execution.`);
|
|
7469
7975
|
const shellCode = String(shell.code ?? `#${shell.id}`);
|
|
7976
|
+
const priorStatus = String(shell.status ?? 'NOTEXECUTED');
|
|
7470
7977
|
await this.http.putJson('/exec/execution/status', { id: Number(shell.id), projectId, status: 'INPROGRESS' });
|
|
7471
7978
|
const body = { ...shell };
|
|
7472
7979
|
for (const k of PLAN_RUN_DROP_KEYS)
|
|
@@ -7481,6 +7988,9 @@ export class SimplifyQaAdapter {
|
|
|
7481
7988
|
globalConfiguration: {
|
|
7482
7989
|
TERMINATE_ON_FAIL: plan['terminateOnFailure'] ?? false, NEW_BROWSER_SESSION: plan['newBrowserSession'] ?? false,
|
|
7483
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),
|
|
7484
7994
|
},
|
|
7485
7995
|
executionItems: runMode === 'stack' ? [] : items,
|
|
7486
7996
|
});
|
|
@@ -7489,12 +7999,26 @@ export class SimplifyQaAdapter {
|
|
|
7489
7999
|
created = await this.http.postJson('/exec/execution', body);
|
|
7490
8000
|
}
|
|
7491
8001
|
catch (e) {
|
|
7492
|
-
|
|
7493
|
-
|
|
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}).`);
|
|
7494
8010
|
}
|
|
7495
8011
|
const runId = str(created?.data ?? created, 'id');
|
|
7496
|
-
if (!runId)
|
|
7497
|
-
|
|
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
|
+
}
|
|
7498
8022
|
return { runId, started, skipped: [...skipped] };
|
|
7499
8023
|
}
|
|
7500
8024
|
/** Every live entry of a plan (the search has no privilege check; scoped to the active project). */
|
|
@@ -7548,33 +8072,21 @@ export class SimplifyQaAdapter {
|
|
|
7548
8072
|
const doc = raw?.data ?? raw;
|
|
7549
8073
|
return doc && typeof doc === 'object' && doc.id !== undefined ? doc : null;
|
|
7550
8074
|
}
|
|
7551
|
-
/** Configure the suite's STACK canvas
|
|
7552
|
-
* document the suite's Stack canvas saves (`POST/PUT /tm/executionFlow`, parentType 'SU', flowType
|
|
7553
|
-
* '
|
|
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`. */
|
|
7554
8078
|
async configureSuiteStacks(suiteId, opts) {
|
|
7555
|
-
const count = Math.trunc(opts.count);
|
|
7556
|
-
if (!Number.isFinite(count) || count < 1)
|
|
7557
|
-
throw new Error('stacks must be at least 1.');
|
|
7558
8079
|
const suite = await this.readOwnSuite(suiteId);
|
|
7559
8080
|
const label = String(suite['code'] ?? `SU-${suite['id']}`);
|
|
7560
8081
|
if (String(suite['suiteType'] ?? 'AUTOMATION').toUpperCase() === 'MANUAL') {
|
|
7561
8082
|
throw new Error(`${label} is a manual suite — Stack execution is for automation suites.`);
|
|
7562
8083
|
}
|
|
7563
8084
|
const projectId = this.requireProjectId();
|
|
7564
|
-
const mode = (opts.mode ?? 'CLOUD').toUpperCase();
|
|
7565
8085
|
const rows = (Array.isArray(suite['testCases']) ? suite['testCases'] : []).filter((r) => r?.deleted !== true && r?.stepId);
|
|
7566
8086
|
if (!rows.length)
|
|
7567
8087
|
throw new Error(`${label} has no saved test cases to distribute.`);
|
|
7568
|
-
const
|
|
7569
|
-
|
|
7570
|
-
const existing = await this.getSuiteStacks(suiteId);
|
|
7571
|
-
const stackDefs = Array.from({ length: count }, (_, i) => ({
|
|
7572
|
-
id: randomUUID(), name: `Stack ${i + 1}`, position: null,
|
|
7573
|
-
mode, agentId: null,
|
|
7574
|
-
executionPlatform: { LOCAL: {}, REMOTE: {}, CLOUD: mode === 'CLOUD' ? { browser } : {} },
|
|
7575
|
-
items: [],
|
|
7576
|
-
}));
|
|
7577
|
-
let i = 0;
|
|
8088
|
+
const cases = [];
|
|
8089
|
+
let seq = 0;
|
|
7578
8090
|
for (const row of rows) {
|
|
7579
8091
|
const rawTc = await this.fetchRawTestcase(String(row.testcaseId)).catch(() => undefined);
|
|
7580
8092
|
if (!rawTc || !Object.keys(rawTc).length)
|
|
@@ -7582,53 +8094,29 @@ export class SimplifyQaAdapter {
|
|
|
7582
8094
|
const tech = String(str(rawTc, 'tcType') ?? 'WEB').toUpperCase();
|
|
7583
8095
|
const versions = Array.isArray(rawTc?.versions) ? rawTc.versions : [];
|
|
7584
8096
|
const ver = versions.find((v) => str(v, 'id', '_id') === String(row.versionId));
|
|
7585
|
-
const p = row?.executionPlatform?.
|
|
7586
|
-
const
|
|
7587
|
-
|
|
7588
|
-
:
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7601
|
-
|
|
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
|
+
}),
|
|
7602
8115
|
});
|
|
7603
|
-
i++;
|
|
7604
8116
|
}
|
|
7605
|
-
if (!
|
|
8117
|
+
if (!cases.length)
|
|
7606
8118
|
throw new Error(`None of ${label}'s test cases could be read, so there is nothing to distribute.`);
|
|
7607
|
-
|
|
7608
|
-
throw new Error(`${label} has ${i} test case(s) — it cannot fill ${count} stacks (every stack needs at least one).`);
|
|
7609
|
-
const payload = {
|
|
7610
|
-
...(existing?.['id'] ? { id: existing['id'] } : {}),
|
|
7611
|
-
parentId: Number(suite['id']), parentType: 'SU', flowType: 'STACK', projectId,
|
|
7612
|
-
viewMode: false, stacks: stackDefs,
|
|
7613
|
-
connections: [], canvasConfig: { startNodePosition: { x: 0, y: 0 } },
|
|
7614
|
-
};
|
|
7615
|
-
if (existing?.['id'])
|
|
7616
|
-
await this.http.putJson('/tm/executionFlow', payload);
|
|
7617
|
-
else
|
|
7618
|
-
await this.http.postJson('/tm/executionFlow', payload);
|
|
7619
|
-
const after = await this.getSuiteStacks(suiteId);
|
|
7620
|
-
const saved = Array.isArray(after?.['stacks']) ? after['stacks'] : [];
|
|
7621
|
-
if (saved.length !== count)
|
|
7622
|
-
throw new Error(`Saved ${count} stack(s) but ${label}'s STACK drawing reads back ${saved.length}.`);
|
|
7623
|
-
const cloudAvailable = mode === 'CLOUD' ? (await this.listCloudRunners().catch(() => [])).some((r) => r.online) : undefined;
|
|
7624
|
-
return {
|
|
7625
|
-
created: !existing,
|
|
7626
|
-
...(cloudAvailable !== undefined ? { cloudAvailable } : {}),
|
|
7627
|
-
stacks: saved.map((s, n) => ({
|
|
7628
|
-
id: String(s.id ?? ''), name: String(s.name ?? `Stack ${n + 1}`), mode: String(s.mode ?? mode),
|
|
7629
|
-
codes: (Array.isArray(s.items) ? s.items : []).map((it) => String(it.code ?? `TC-${it.id}`)),
|
|
7630
|
-
})),
|
|
7631
|
-
};
|
|
8119
|
+
return this.saveStackFlow('SU', Number(suite['id']), label, projectId, cases, opts, await this.getSuiteStacks(suiteId));
|
|
7632
8120
|
}
|
|
7633
8121
|
/** What a suite STACK run needs, checked before anything is created: a saved canvas with no empty stack,
|
|
7634
8122
|
* a cloud machine only when a stack is CLOUD, and this machine's agent only when a stack is LOCAL. */
|
|
@@ -7654,6 +8142,10 @@ export class SimplifyQaAdapter {
|
|
|
7654
8142
|
}
|
|
7655
8143
|
cloudType = online[0]?.cloudType ?? 'VM';
|
|
7656
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
|
+
}
|
|
7657
8149
|
let agentId = null;
|
|
7658
8150
|
if (stacks.some((s) => (String(s?.mode ?? 'LOCAL')).toUpperCase() === 'LOCAL')) {
|
|
7659
8151
|
const probe = await this.probeLocalAgentDetailed();
|
|
@@ -7746,7 +8238,7 @@ export class SimplifyQaAdapter {
|
|
|
7746
8238
|
if (target.suiteId) {
|
|
7747
8239
|
schedulerType = 'SU';
|
|
7748
8240
|
parent = await this.readOwnSuite(target.suiteId);
|
|
7749
|
-
platForm = suitePlatform(parent, opts.browser, 'schedule it');
|
|
8241
|
+
platForm = suitePlatform(parent, opts.browser, 'schedule it', opts.mode === 'cloud');
|
|
7750
8242
|
}
|
|
7751
8243
|
else if (target.tcId) {
|
|
7752
8244
|
schedulerType = 'TC';
|
|
@@ -7756,7 +8248,7 @@ export class SimplifyQaAdapter {
|
|
|
7756
8248
|
if (Number(parent['projectId']) !== projectId)
|
|
7757
8249
|
throw new Error(`${parent['code'] ?? `TC-${parent['id']}`} is not in project ${projectId}.`);
|
|
7758
8250
|
parentVersionId = testcaseVersion(parent, true).versionId || undefined;
|
|
7759
|
-
platForm = tcPlatform(parent, opts.browser);
|
|
8251
|
+
platForm = tcPlatform(parent, opts.browser, opts.mode === 'cloud');
|
|
7760
8252
|
}
|
|
7761
8253
|
else {
|
|
7762
8254
|
throw new Error('Nothing to schedule: give a test case or a suite.');
|
|
@@ -7897,6 +8389,8 @@ export class SimplifyQaAdapter {
|
|
|
7897
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
|
|
7898
8390
|
// version that kind of schedule carries, as createSchedule builds them.
|
|
7899
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';
|
|
7900
8394
|
let target;
|
|
7901
8395
|
if (changes.tcId !== undefined || changes.suiteId !== undefined) {
|
|
7902
8396
|
if (changes.tcId !== undefined && changes.suiteId !== undefined)
|
|
@@ -7905,7 +8399,7 @@ export class SimplifyQaAdapter {
|
|
|
7905
8399
|
const wasType = String(doc['schedulerType'] ?? '');
|
|
7906
8400
|
if (changes.suiteId !== undefined) {
|
|
7907
8401
|
const suite = await this.readOwnSuite(changes.suiteId);
|
|
7908
|
-
const platForm = suitePlatform(suite, changes.browser, 'schedule it');
|
|
8402
|
+
const platForm = suitePlatform(suite, changes.browser, 'schedule it', scheduleIsCloud);
|
|
7909
8403
|
Object.assign(patch, { schedulerType: 'SU', parentId: Number(suite['id']), platForm, parentVersionId: undefined });
|
|
7910
8404
|
target = { type: 'SU', id: Number(suite['id']), code: String(suite['code'] ?? `SU-${suite['id']}`) };
|
|
7911
8405
|
}
|
|
@@ -7919,7 +8413,7 @@ export class SimplifyQaAdapter {
|
|
|
7919
8413
|
const webEntry = (Array.isArray(doc['platForm']) ? doc['platForm'] : []).find((p) => String(p?.technologyType ?? '').toUpperCase() === 'WEB');
|
|
7920
8414
|
const keepBrowser = changes.browser ?? (webEntry?.id ? String(webEntry.id) : undefined);
|
|
7921
8415
|
Object.assign(patch, {
|
|
7922
|
-
schedulerType: 'TC', parentId: Number(tc['id']), platForm: tcPlatform(tc, keepBrowser),
|
|
8416
|
+
schedulerType: 'TC', parentId: Number(tc['id']), platForm: tcPlatform(tc, keepBrowser, scheduleIsCloud),
|
|
7923
8417
|
parentVersionId: testcaseVersion(tc, true).versionId || undefined,
|
|
7924
8418
|
});
|
|
7925
8419
|
target = { type: 'TC', id: Number(tc['id']), code: String(tc['code'] ?? `TC-${tc['id']}`) };
|
|
@@ -7950,8 +8444,9 @@ export class SimplifyQaAdapter {
|
|
|
7950
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).');
|
|
7951
8445
|
}
|
|
7952
8446
|
if (changes.browser && doc['schedulerType'] === 'TC' && finalType === 'TC' && !('platForm' in patch)) {
|
|
7953
|
-
|
|
7954
|
-
|
|
8447
|
+
patch['platForm'] = scheduleIsCloud
|
|
8448
|
+
? [cloudBrowserEntry(changes.browser)]
|
|
8449
|
+
: (() => { const b = sqaBrowser(changes.browser); return [{ id: b, name: b, type: 'NONE', technologyType: 'WEB' }]; })();
|
|
7955
8450
|
}
|
|
7956
8451
|
if (changes.environmentId)
|
|
7957
8452
|
patch['environment'] = await this.environmentKey(changes.environmentId);
|
|
@@ -8304,16 +8799,36 @@ export class SimplifyQaAdapter {
|
|
|
8304
8799
|
}
|
|
8305
8800
|
/** Assemble the strict allow-listed suite entry for an ADD op. Required fields per the SQA
|
|
8306
8801
|
* validator: testcaseId, code, seq (set by the caller), version, versionId, tcType. */
|
|
8307
|
-
async buildSuiteEntryFromTestcase(tcNum) {
|
|
8802
|
+
async buildSuiteEntryFromTestcase(tcNum, requested) {
|
|
8308
8803
|
const raw = await this.fetchRawTestcase(tcNum);
|
|
8309
8804
|
if (Object.keys(raw).length === 0)
|
|
8310
8805
|
throw new Error(`test case ${tcNum} not found (cannot add to suite)`);
|
|
8311
8806
|
const code = str(raw, 'code', 'tcCode') ?? `TC_${tcNum}`;
|
|
8312
8807
|
const tcType = str(raw, 'tcType') ?? 'WEB';
|
|
8808
|
+
const versions = Array.isArray(raw?.versions) ? raw.versions : [];
|
|
8313
8809
|
let versionName = str(raw, 'versionName', 'selectedVersionName');
|
|
8314
8810
|
let versionId = str(raw, 'versionId', 'selectedVersionId');
|
|
8315
|
-
|
|
8316
|
-
|
|
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];
|
|
8317
8832
|
versionName ?? (versionName = str(v, 'name'));
|
|
8318
8833
|
versionId ?? (versionId = str(v, 'id', '_id'));
|
|
8319
8834
|
}
|
|
@@ -10370,6 +10885,7 @@ export class SimplifyQaAdapter {
|
|
|
10370
10885
|
const stackRun = mode === 'STACK' ? await this.suiteStackRunPlan(rawSuite, opts) : undefined;
|
|
10371
10886
|
const members = !stackRun && Array.isArray(rawSuite.testCases) ? rawSuite.testCases : [];
|
|
10372
10887
|
const executionItems = [];
|
|
10888
|
+
const cloudNeedsBrowser = [];
|
|
10373
10889
|
let seqCounter = 0;
|
|
10374
10890
|
for (const row of members) {
|
|
10375
10891
|
seqCounter++;
|
|
@@ -10398,7 +10914,17 @@ export class SimplifyQaAdapter {
|
|
|
10398
10914
|
// mode, send `[]` and let the backend reject/accept per its own rules.
|
|
10399
10915
|
const savedPlatform = row?.executionPlatform?.[mode];
|
|
10400
10916
|
let platform = [];
|
|
10401
|
-
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') {
|
|
10402
10928
|
const p = {
|
|
10403
10929
|
name: savedPlatform.name,
|
|
10404
10930
|
id: savedPlatform.id ?? savedPlatform.name,
|
|
@@ -10450,6 +10976,10 @@ export class SimplifyQaAdapter {
|
|
|
10450
10976
|
userstoryName: '',
|
|
10451
10977
|
});
|
|
10452
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
|
+
}
|
|
10453
10983
|
if (!stackRun && executionItems.length === 0) {
|
|
10454
10984
|
throw new Error(`startRun: suite ${suiteId} has no runnable test cases (all members were deleted, ` +
|
|
10455
10985
|
`unreadable, or filtered out).`);
|
|
@@ -10906,10 +11436,8 @@ export class SimplifyQaAdapter {
|
|
|
10906
11436
|
buildRunPlatform(tcType, mode, opts) {
|
|
10907
11437
|
const t = tcType.toUpperCase();
|
|
10908
11438
|
if (t === 'WEB') {
|
|
10909
|
-
if (mode === 'CLOUD')
|
|
10910
|
-
|
|
10911
|
-
return [{ name: key, id: key, technologyType: 'WEB', type: 'NONE' }];
|
|
10912
|
-
}
|
|
11439
|
+
if (mode === 'CLOUD')
|
|
11440
|
+
return [cloudBrowserEntry(opts.browser)];
|
|
10913
11441
|
const b = (opts.browser ?? 'CHROME').toUpperCase();
|
|
10914
11442
|
return [{ name: b, id: b, technologyType: 'WEB', type: 'NONE' }];
|
|
10915
11443
|
}
|
|
@@ -11084,7 +11612,22 @@ export class SimplifyQaAdapter {
|
|
|
11084
11612
|
const m = e instanceof Error ? e.message : String(e);
|
|
11085
11613
|
return /Could not reach the product MCP|fetch failed|ECONNREFUSED/i.test(m);
|
|
11086
11614
|
}
|
|
11087
|
-
|
|
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);
|
|
11088
11631
|
const h = this.hop();
|
|
11089
11632
|
if (h) {
|
|
11090
11633
|
try {
|
|
@@ -11097,7 +11640,17 @@ export class SimplifyQaAdapter {
|
|
|
11097
11640
|
}
|
|
11098
11641
|
return this.stepsView(tcId);
|
|
11099
11642
|
}
|
|
11100
|
-
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
|
+
}
|
|
11101
11654
|
// Every step-editing op is applied straight to the saved test case. Sent through the agent, an edit
|
|
11102
11655
|
// either opened the recorder window (SCRPY) and never landed, or — as with a plain `update_step` on
|
|
11103
11656
|
// a saved TC — hit the agent's JOURNAL editor, which only knows recording journals and rejected a
|
|
@@ -11126,14 +11679,21 @@ export class SimplifyQaAdapter {
|
|
|
11126
11679
|
}
|
|
11127
11680
|
return this.editStepsDirect(tcId, ops);
|
|
11128
11681
|
}
|
|
11129
|
-
async stepsView(tcId) {
|
|
11130
|
-
const
|
|
11131
|
-
|
|
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
|
+
};
|
|
11132
11691
|
}
|
|
11133
11692
|
/** Agent-free step edit: read the test case, apply remove / update / move by step number, renumber, and
|
|
11134
11693
|
* save through updateTestCase (which sends removed steps back with `deleted:true`, as the UI does). */
|
|
11135
|
-
async editStepsDirect(tcId, ops) {
|
|
11136
|
-
|
|
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);
|
|
11137
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(',')}`);
|
|
11138
11698
|
let steps = [...(tc.steps ?? [])];
|
|
11139
11699
|
for (const op of ops) {
|
|
@@ -11263,7 +11823,7 @@ export class SimplifyQaAdapter {
|
|
|
11263
11823
|
steps = steps.map((x, k) => ({ ...x, n: k + 1 }));
|
|
11264
11824
|
}
|
|
11265
11825
|
await this.updateTestCase(tcId, { ...tc, steps });
|
|
11266
|
-
return this.stepsView(tcId);
|
|
11826
|
+
return this.stepsView(tcId, pinned?.id);
|
|
11267
11827
|
}
|
|
11268
11828
|
// ---------------------------------------------------------------------- Self-healing
|
|
11269
11829
|
/** `heal_propose` on the product server: replay + DOM evidence + proposals. Read-only — it never
|