plugin-workflow-ci 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-v2.js +1 -0
- package/client.js +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +21 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +105 -0
- package/dist/locale/vi-VN.json +105 -0
- package/dist/locale/zh-CN.json +105 -0
- package/dist/server/actions/ci-manager.js +307 -0
- package/dist/server/collections/ci-gate-runs.js +85 -0
- package/dist/server/collections/ci-git-feedback-outbox.js +51 -0
- package/dist/server/collections/ci-pipelines.js +88 -0
- package/dist/server/index.js +62 -0
- package/dist/server/instructions/CiInstructions.js +180 -0
- package/dist/server/migrations/20261206000001-harden-workflow-ci-v020.js +91 -0
- package/dist/server/plugin.js +255 -0
- package/dist/server/services/AiTriageService.js +215 -0
- package/dist/server/services/CiGateWorkflowService.js +1776 -0
- package/dist/server/services/EphemeralContainerService.js +891 -0
- package/dist/server/services/GitFeedbackService.js +995 -0
- package/dist/server/services/constants-internal.js +65 -0
- package/dist/shared/collection-schemas.js +125 -0
- package/dist/shared/constants.js +120 -0
- package/dist/shared/runtime-context.js +67 -0
- package/dist/shared/types.js +24 -0
- package/dist/shared/ui/CiPipelinesSettingsView.js +700 -0
- package/package.json +58 -4
- package/server.js +1 -0
- package/src/client/index.tsx +10 -0
- package/src/client/locale.ts +31 -0
- package/src/client/plugin.tsx +62 -0
- package/src/client/workflow.tsx +119 -0
- package/src/client-v2/index.tsx +10 -0
- package/src/client-v2/locale.ts +32 -0
- package/src/client-v2/plugin.tsx +77 -0
- package/src/client-v2/workflow.tsx +124 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +105 -0
- package/src/locale/vi-VN.json +105 -0
- package/src/locale/zh-CN.json +105 -0
- package/src/server/actions/ci-manager.ts +377 -0
- package/src/server/collections/ci-gate-runs.ts +65 -0
- package/src/server/collections/ci-git-feedback-outbox.ts +31 -0
- package/src/server/collections/ci-pipelines.ts +68 -0
- package/src/server/index.ts +17 -0
- package/src/server/instructions/CiInstructions.ts +180 -0
- package/src/server/migrations/20261206000001-harden-workflow-ci-v020.ts +78 -0
- package/src/server/plugin.ts +274 -0
- package/src/server/services/AiTriageService.ts +254 -0
- package/src/server/services/CiGateWorkflowService.ts +2310 -0
- package/src/server/services/EphemeralContainerService.ts +1170 -0
- package/src/server/services/GitFeedbackService.ts +1224 -0
- package/src/server/services/constants-internal.ts +27 -0
- package/src/shared/collection-schemas.ts +98 -0
- package/src/shared/constants.ts +50 -0
- package/src/shared/runtime-context.tsx +55 -0
- package/src/shared/types.ts +203 -0
- package/src/shared/ui/CiPipelinesSettingsView.tsx +1035 -0
- package/README.md +0 -3
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Model } from '@nocobase/database';
|
|
11
|
+
import type Application from '@nocobase/server';
|
|
12
|
+
import {
|
|
13
|
+
AGENT_LOOP_PATTERNS_COLLECTION,
|
|
14
|
+
AGENT_LOOP_RUNS_COLLECTION,
|
|
15
|
+
TEST_CASE_RESULTS_COLLECTION,
|
|
16
|
+
} from '../../shared/constants';
|
|
17
|
+
import type { CiGateRunRecord, CiPipelineRecord, CiTriageSummary } from '../../shared/types';
|
|
18
|
+
|
|
19
|
+
function isPlainRecord(val: unknown): val is Record<string, unknown> {
|
|
20
|
+
return Boolean(val) && typeof val === 'object' && !Array.isArray(val);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function extractSuspectedFilesFromTraces(traces: string[]): string[] {
|
|
24
|
+
const files = new Set<string>();
|
|
25
|
+
const pathRegex = /(?:^|[\s(])((?:packages|src|apps|tests?)\/[A-Za-z0-9_./-]+\.[A-Za-z0-9]+)(?::\d+)?/gm;
|
|
26
|
+
for (const trace of traces) {
|
|
27
|
+
let match = pathRegex.exec(trace);
|
|
28
|
+
while (match) {
|
|
29
|
+
if (match[1] && !match[1].includes('node_modules')) {
|
|
30
|
+
files.add(match[1]);
|
|
31
|
+
}
|
|
32
|
+
if (files.size >= 8) break;
|
|
33
|
+
match = pathRegex.exec(trace);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return [...files];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const INFRA_FLAKY_REGEX =
|
|
40
|
+
/ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOTFOUND|socket hang up|Timeout \d+ms exceeded|Target page, context or browser has been closed|HTTP 50[234]|Container exited with non-zero/i;
|
|
41
|
+
|
|
42
|
+
export class AiTriageService {
|
|
43
|
+
constructor(private readonly app: Application) {}
|
|
44
|
+
|
|
45
|
+
private hasCollection(name: string): boolean {
|
|
46
|
+
try {
|
|
47
|
+
return Boolean(this.app.db.getCollection(name));
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async analyzeFailedRun(params: {
|
|
54
|
+
pipeline: CiPipelineRecord;
|
|
55
|
+
gateRun: CiGateRunRecord;
|
|
56
|
+
testRun: Record<string, unknown>;
|
|
57
|
+
}): Promise<CiTriageSummary | null> {
|
|
58
|
+
const verdict = String(params.testRun.verdict || '');
|
|
59
|
+
if (verdict !== 'failed' && verdict !== 'diff_mismatch' && verdict !== 'error') {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const testRunId = Number(params.testRun.id || params.gateRun.testRunId || 0);
|
|
64
|
+
const tmPlugin = (this.app.pm.get('plugin-test-manager') || this.app.pm.get('test-manager')) as
|
|
65
|
+
| {
|
|
66
|
+
workflowService?: {
|
|
67
|
+
listCaseResultsForRun?: (
|
|
68
|
+
runId: number,
|
|
69
|
+
extraFilter?: Record<string, unknown>,
|
|
70
|
+
) => Promise<Array<Record<string, unknown>>>;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
| undefined;
|
|
74
|
+
|
|
75
|
+
let problems: Array<Record<string, unknown>> = [];
|
|
76
|
+
if (testRunId > 0 && typeof tmPlugin?.workflowService?.listCaseResultsForRun === 'function') {
|
|
77
|
+
const allMatched = await tmPlugin.workflowService.listCaseResultsForRun(testRunId, {
|
|
78
|
+
status: { $in: ['failed', 'diff_mismatch'] },
|
|
79
|
+
});
|
|
80
|
+
problems = allMatched.slice(0, 30);
|
|
81
|
+
} else if (testRunId > 0 && this.hasCollection(TEST_CASE_RESULTS_COLLECTION)) {
|
|
82
|
+
const problemModels = (await this.app.db.getRepository(TEST_CASE_RESULTS_COLLECTION).find({
|
|
83
|
+
filter: {
|
|
84
|
+
runId: testRunId,
|
|
85
|
+
status: { $in: ['failed', 'diff_mismatch'] },
|
|
86
|
+
},
|
|
87
|
+
limit: 30,
|
|
88
|
+
})) as Model[];
|
|
89
|
+
problems = problemModels.map((m) => m.toJSON() as Record<string, unknown>);
|
|
90
|
+
}
|
|
91
|
+
const failedItems = problems.filter((p) => p.status === 'failed');
|
|
92
|
+
const diffItems = problems.filter((p) => p.status === 'diff_mismatch');
|
|
93
|
+
|
|
94
|
+
const errorTexts = problems
|
|
95
|
+
.flatMap((p) => [String(p.errorMessage || ''), String(p.stackTrace || '')])
|
|
96
|
+
.filter((s) => s.trim().length > 0);
|
|
97
|
+
if (typeof params.testRun.errorMessage === 'string' && params.testRun.errorMessage.trim()) {
|
|
98
|
+
errorTexts.push(params.testRun.errorMessage.trim());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const suspectedFiles = extractSuspectedFilesFromTraces(errorTexts);
|
|
102
|
+
|
|
103
|
+
let classification: CiTriageSummary['classification'] = 'unknown';
|
|
104
|
+
let confidence = 0.72;
|
|
105
|
+
let rootCause = 'Test run reported failures.';
|
|
106
|
+
let suggestedAction = 'Inspect failed test case stack traces and recent commit changes.';
|
|
107
|
+
|
|
108
|
+
if (failedItems.length === 0 && diffItems.length > 0 && verdict === 'diff_mismatch') {
|
|
109
|
+
classification = 'baseline_change';
|
|
110
|
+
confidence = 0.9;
|
|
111
|
+
const sampleCase = String(diffItems[0]?.caseCode || 'case');
|
|
112
|
+
const diffReport = isPlainRecord(diffItems[0]?.diffReport) ? diffItems[0].diffReport : {};
|
|
113
|
+
const layers = Array.isArray(diffReport.checkedLayers) ? diffReport.checkedLayers.join(', ') : 'output/database';
|
|
114
|
+
rootCause = `${diffItems.length} case(s) (including "${sampleCase}") completed without runtime errors, but actual ${layers} state diverged from the stored dataset baseline.`;
|
|
115
|
+
suggestedAction =
|
|
116
|
+
'Review the Expected vs Actual Diff in Test Manager; approve the new baseline if this API/DB change is intentional, or revert the unintended payload/schema mutation.';
|
|
117
|
+
} else if (errorTexts.some((txt) => INFRA_FLAKY_REGEX.test(txt))) {
|
|
118
|
+
classification = 'flaky_or_infra';
|
|
119
|
+
confidence = 0.84;
|
|
120
|
+
const firstErr = (errorTexts[0] || 'Transient network/browser timeout').split('\n')[0].slice(0, 180);
|
|
121
|
+
rootCause = `Detected infrastructure or transient connectivity/timeout signature: "${firstErr}".`;
|
|
122
|
+
suggestedAction =
|
|
123
|
+
'Verify preview/target service health and network reachability, then trigger Re-run Failed Cases (or enable Flaky Auto-Retry on the tenant).';
|
|
124
|
+
} else if (failedItems.length > 0) {
|
|
125
|
+
classification = 'code_regression';
|
|
126
|
+
confidence = suspectedFiles.length > 0 ? 0.88 : 0.78;
|
|
127
|
+
const firstCase = String(failedItems[0]?.caseCode || 'test case');
|
|
128
|
+
const firstMsg = String(failedItems[0]?.errorMessage || 'Assertion failed')
|
|
129
|
+
.split('\n')[0]
|
|
130
|
+
.slice(0, 180);
|
|
131
|
+
rootCause = `${failedItems.length} assertion/execution failure(s) led by "${firstCase}": ${firstMsg}`;
|
|
132
|
+
suggestedAction =
|
|
133
|
+
suspectedFiles.length > 0
|
|
134
|
+
? `Inspect commit ${params.gateRun.commitSha.slice(0, 8)} changes around ${suspectedFiles
|
|
135
|
+
.slice(0, 3)
|
|
136
|
+
.join(', ')} and fix the failing assertion/handler.`
|
|
137
|
+
: `Inspect commit ${params.gateRun.commitSha.slice(0, 8)} diff and stack traces for "${firstCase}".`;
|
|
138
|
+
} else if (verdict === 'error') {
|
|
139
|
+
classification = 'flaky_or_infra';
|
|
140
|
+
confidence = 0.8;
|
|
141
|
+
rootCause = String(params.testRun.errorMessage || 'Runner workflow or container terminated abnormally.');
|
|
142
|
+
suggestedAction = 'Check CI runner container logs, image availability, and callback token configuration.';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const dispatchOutcome = await this.enqueueAgentOrchestratorTriage({
|
|
146
|
+
pipeline: params.pipeline,
|
|
147
|
+
gateRun: params.gateRun,
|
|
148
|
+
testRunId,
|
|
149
|
+
classification,
|
|
150
|
+
rootCause,
|
|
151
|
+
suspectedFiles,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
classification,
|
|
156
|
+
confidence,
|
|
157
|
+
rootCause,
|
|
158
|
+
suggestedAction,
|
|
159
|
+
...(suspectedFiles.length > 0 ? { suspectedFiles } : {}),
|
|
160
|
+
agentDispatched: dispatchOutcome.agentDispatched,
|
|
161
|
+
...(dispatchOutcome.agentLoopRunId ? { agentLoopRunId: dispatchOutcome.agentLoopRunId } : {}),
|
|
162
|
+
...(dispatchOutcome.triageError ? { triageError: dispatchOutcome.triageError } : {}),
|
|
163
|
+
analyzedAt: new Date().toISOString(),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private async enqueueAgentOrchestratorTriage(params: {
|
|
168
|
+
pipeline: CiPipelineRecord;
|
|
169
|
+
gateRun: CiGateRunRecord;
|
|
170
|
+
testRunId: number;
|
|
171
|
+
classification: string;
|
|
172
|
+
rootCause: string;
|
|
173
|
+
suspectedFiles: string[];
|
|
174
|
+
}): Promise<{ agentDispatched: boolean; agentLoopRunId?: number | null; triageError?: string | null }> {
|
|
175
|
+
const patternKey = String(params.pipeline.agentLoopPatternKey || '').trim();
|
|
176
|
+
if (!patternKey) {
|
|
177
|
+
return { agentDispatched: false };
|
|
178
|
+
}
|
|
179
|
+
if (!this.hasCollection(AGENT_LOOP_PATTERNS_COLLECTION) || !this.hasCollection(AGENT_LOOP_RUNS_COLLECTION)) {
|
|
180
|
+
return {
|
|
181
|
+
agentDispatched: false,
|
|
182
|
+
triageError: `Agent Orchestrator collections are not installed for pattern "${patternKey}"`,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const patternModel = (await this.app.db.getRepository(AGENT_LOOP_PATTERNS_COLLECTION).findOne({
|
|
187
|
+
filter: { key: patternKey, enabled: true },
|
|
188
|
+
})) as Model | null;
|
|
189
|
+
if (!patternModel) {
|
|
190
|
+
return {
|
|
191
|
+
agentDispatched: false,
|
|
192
|
+
triageError: `Enabled Agent Loop pattern "${patternKey}" was not found`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const patternId = Number(patternModel.get('id'));
|
|
197
|
+
const goal = [
|
|
198
|
+
`Triage CI Test Run #${params.testRunId} on branch "${params.gateRun.branch}" commit ${params.gateRun.commitSha}.`,
|
|
199
|
+
`Initial classification: ${params.classification}.`,
|
|
200
|
+
`Summary: ${params.rootCause}`,
|
|
201
|
+
params.suspectedFiles.length > 0 ? `Suspected files: ${params.suspectedFiles.join(', ')}` : '',
|
|
202
|
+
]
|
|
203
|
+
.filter(Boolean)
|
|
204
|
+
.join(' ');
|
|
205
|
+
|
|
206
|
+
const workflowPlugin = (this.app.pm.get('workflow') || this.app.pm.get('@nocobase/plugin-workflow')) as
|
|
207
|
+
| { instructions?: { get?: (name: string) => unknown } }
|
|
208
|
+
| undefined;
|
|
209
|
+
const loopEnqueueInstruction = workflowPlugin?.instructions?.get?.('agent-loop-enqueue') as
|
|
210
|
+
| {
|
|
211
|
+
owner?: {
|
|
212
|
+
triggers?: { enqueue?: (input: Record<string, unknown>) => Promise<{ run?: Record<string, unknown> }> };
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
| undefined;
|
|
216
|
+
|
|
217
|
+
if (typeof loopEnqueueInstruction?.owner?.triggers?.enqueue !== 'function') {
|
|
218
|
+
return {
|
|
219
|
+
agentDispatched: false,
|
|
220
|
+
triageError: 'plugin-agent-orchestrator trigger service is not active on this node',
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
const res = await loopEnqueueInstruction.owner.triggers.enqueue({
|
|
226
|
+
patternId,
|
|
227
|
+
triggerType: 'event',
|
|
228
|
+
triggerKey: `workflow-ci:triage:${params.gateRun.id}:${params.testRunId}`,
|
|
229
|
+
triggerPayload: {
|
|
230
|
+
source: 'plugin-workflow-ci',
|
|
231
|
+
ciGateRunId: params.gateRun.id,
|
|
232
|
+
testRunId: params.testRunId,
|
|
233
|
+
commitSha: params.gateRun.commitSha,
|
|
234
|
+
branch: params.gateRun.branch,
|
|
235
|
+
mrIid: params.gateRun.mrIid ?? null,
|
|
236
|
+
},
|
|
237
|
+
goal,
|
|
238
|
+
});
|
|
239
|
+
const id = Number(res?.run?.id || 0);
|
|
240
|
+
if (Number.isFinite(id) && id > 0) {
|
|
241
|
+
return { agentDispatched: true, agentLoopRunId: id };
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
agentDispatched: false,
|
|
245
|
+
triageError: 'Agent Orchestrator enqueue did not return a valid run ID',
|
|
246
|
+
};
|
|
247
|
+
} catch (error) {
|
|
248
|
+
return {
|
|
249
|
+
agentDispatched: false,
|
|
250
|
+
triageError: error instanceof Error ? error.message : String(error),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|