playwright-smart-test 1.0.7 → 1.0.8
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/cli/index.js
CHANGED
|
@@ -15,7 +15,7 @@ const program = new Command();
|
|
|
15
15
|
program
|
|
16
16
|
.name('playwright-smart-test')
|
|
17
17
|
.description('AI-Powered Smart Regression Test Selection Agent for Playwright')
|
|
18
|
-
.version('1.0.
|
|
18
|
+
.version('1.0.8');
|
|
19
19
|
async function executeAnalysis(options) {
|
|
20
20
|
const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();
|
|
21
21
|
const config = loadConfig(cwd, options.config);
|
|
@@ -8,6 +8,8 @@ export declare class GitDiffAnalyzer {
|
|
|
8
8
|
private cwd;
|
|
9
9
|
constructor(cwd?: string);
|
|
10
10
|
private runGit;
|
|
11
|
+
private sanitizeGitRef;
|
|
12
|
+
private parseRemoteRef;
|
|
11
13
|
getChangedFiles(options?: DiffOptions): Promise<DiffFile[]>;
|
|
12
14
|
/**
|
|
13
15
|
* Parse git diff --numstat output:
|
|
@@ -19,14 +19,69 @@ export class GitDiffAnalyzer {
|
|
|
19
19
|
throw new Error(`Git command failed [git ${args.join(' ')}]: ${message}`);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
sanitizeGitRef(ref) {
|
|
23
|
+
if (!ref) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const safeRef = ref.trim();
|
|
27
|
+
if (!safeRef || safeRef.includes('\0') || safeRef.includes('\n') || safeRef.includes('\r')) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (safeRef.startsWith('-') || safeRef.includes(' ') || safeRef.includes('..')) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (safeRef.startsWith('/') || safeRef.endsWith('/')) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const validPattern = /^(?:HEAD|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*|refs\/(?:heads|remotes|tags)\/[A-Za-z0-9._/-]+)$/;
|
|
37
|
+
if (!validPattern.test(safeRef)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return safeRef;
|
|
41
|
+
}
|
|
42
|
+
parseRemoteRef(ref) {
|
|
43
|
+
const safeRef = this.sanitizeGitRef(ref);
|
|
44
|
+
if (!safeRef) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const match = safeRef.match(/^([A-Za-z0-9._-]+)\/([A-Za-z0-9._/-]+)$/);
|
|
48
|
+
if (!match) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const remote = match[1];
|
|
52
|
+
const branch = match[2];
|
|
53
|
+
if (!remote || !branch || branch.includes('..') || branch.startsWith('/') || branch.endsWith('/')) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return { remote, branch };
|
|
57
|
+
}
|
|
22
58
|
async getChangedFiles(options = {}) {
|
|
23
59
|
await this.runGit(['rev-parse', '--is-inside-work-tree']);
|
|
60
|
+
const safeBase = this.sanitizeGitRef(options.base);
|
|
61
|
+
const safeHead = this.sanitizeGitRef(options.head) ?? 'HEAD';
|
|
62
|
+
if (safeBase) {
|
|
63
|
+
try {
|
|
64
|
+
await this.runGit(['rev-parse', '--verify', safeBase]);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
const remoteRef = this.parseRemoteRef(safeBase);
|
|
68
|
+
if (remoteRef) {
|
|
69
|
+
const { remote, branch } = remoteRef;
|
|
70
|
+
try {
|
|
71
|
+
await this.runGit(['fetch', '--depth=100', remote, `${branch}:refs/remotes/${remote}/${branch}`]);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Ignore fetch failure and proceed with available refs.
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
24
79
|
let diffRangeArgs;
|
|
25
|
-
if (
|
|
26
|
-
diffRangeArgs = [`${
|
|
80
|
+
if (safeBase && safeHead) {
|
|
81
|
+
diffRangeArgs = [`${safeBase}...${safeHead}`];
|
|
27
82
|
}
|
|
28
|
-
else if (
|
|
29
|
-
diffRangeArgs = [
|
|
83
|
+
else if (safeBase) {
|
|
84
|
+
diffRangeArgs = [safeBase];
|
|
30
85
|
}
|
|
31
86
|
else if (options.staged) {
|
|
32
87
|
diffRangeArgs = ['--cached'];
|
|
@@ -34,9 +89,28 @@ export class GitDiffAnalyzer {
|
|
|
34
89
|
else {
|
|
35
90
|
diffRangeArgs = ['HEAD'];
|
|
36
91
|
}
|
|
37
|
-
|
|
92
|
+
let numstatOutput;
|
|
93
|
+
try {
|
|
94
|
+
numstatOutput = await this.runGit(['diff', '--numstat', ...diffRangeArgs]);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
const fallbackArgs = safeBase ? [safeBase] : ['HEAD'];
|
|
98
|
+
try {
|
|
99
|
+
numstatOutput = await this.runGit(['diff', '--numstat', ...fallbackArgs]);
|
|
100
|
+
diffRangeArgs = fallbackArgs;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
numstatOutput = '';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
38
106
|
const numstatMap = this.parseNumstat(numstatOutput);
|
|
39
|
-
|
|
107
|
+
let rawDiff;
|
|
108
|
+
try {
|
|
109
|
+
rawDiff = await this.runGit(['diff', ...diffRangeArgs]);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
rawDiff = '';
|
|
113
|
+
}
|
|
40
114
|
const patchesByFile = this.splitPatches(rawDiff);
|
|
41
115
|
const allPaths = Array.from(new Set([...numstatMap.keys(), ...patchesByFile.keys()]));
|
|
42
116
|
const files = allPaths.map((filePath) => {
|
|
@@ -96,21 +170,18 @@ export class GitDiffAnalyzer {
|
|
|
96
170
|
const trimmed = section.trim();
|
|
97
171
|
if (!trimmed)
|
|
98
172
|
continue;
|
|
99
|
-
// Extract the header line without regex backtracking
|
|
100
173
|
const newlineIndex = trimmed.indexOf('\n');
|
|
101
174
|
const headerLine = (newlineIndex === -1 ? trimmed : trimmed.slice(0, newlineIndex)).trim();
|
|
102
175
|
if (!headerLine.startsWith('diff --git '))
|
|
103
176
|
continue;
|
|
104
|
-
const line = headerLine.slice(11);
|
|
177
|
+
const line = headerLine.slice(11);
|
|
105
178
|
const sepIndex = line.lastIndexOf(' b/');
|
|
106
179
|
if (sepIndex !== -1) {
|
|
107
180
|
let filePath = line.slice(sepIndex + 3).trim();
|
|
108
|
-
// Fallback for deleted files where b/ is /dev/null
|
|
109
181
|
if (filePath === '/dev/null' || filePath === 'dev/null') {
|
|
110
182
|
const aPath = line.slice(0, sepIndex).trim();
|
|
111
183
|
filePath = aPath.startsWith('a/') ? aPath.slice(2) : aPath;
|
|
112
184
|
}
|
|
113
|
-
// Clean quotes if path was enclosed in quotes by git
|
|
114
185
|
if (filePath.startsWith('"') && filePath.endsWith('"')) {
|
|
115
186
|
filePath = filePath.slice(1, -1);
|
|
116
187
|
}
|
|
@@ -12,8 +12,36 @@ export class TestSelector {
|
|
|
12
12
|
async selectTests(changedFiles, catalog) {
|
|
13
13
|
const allKnownSpecs = catalog.map((c) => c.filePath.replace(/\\/g, '/'));
|
|
14
14
|
const deletedPaths = new Set(changedFiles.filter((f) => f.status === 'deleted').map((f) => f.path.replace(/\\/g, '/')));
|
|
15
|
-
// Guardrail
|
|
15
|
+
// Guardrail 1a: Zero Modified Files
|
|
16
|
+
if (changedFiles.length === 0) {
|
|
17
|
+
return {
|
|
18
|
+
isFullRegression: false,
|
|
19
|
+
fullRegressionReason: undefined,
|
|
20
|
+
changedFiles,
|
|
21
|
+
changedComponents: [],
|
|
22
|
+
impactedComponents: [],
|
|
23
|
+
aiAnalysis: {
|
|
24
|
+
changedComponents: [],
|
|
25
|
+
impactedComponents: [],
|
|
26
|
+
directReason: 'Zero modified files detected against the base branch.',
|
|
27
|
+
rippleEffectReason: 'Working tree is clean and identical to the target branch. No regression test execution required.',
|
|
28
|
+
riskScore: 'LOW',
|
|
29
|
+
requiresFullRegression: false,
|
|
30
|
+
confidenceScore: 'HIGH',
|
|
31
|
+
recommendedTests: [],
|
|
32
|
+
},
|
|
33
|
+
selectedSpecs: [],
|
|
34
|
+
directlyModifiedSpecs: [],
|
|
35
|
+
componentRuleSpecs: [],
|
|
36
|
+
aiRecommendedSpecs: [],
|
|
37
|
+
playwrightCommand: 'npx playwright test',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Guardrail 1b: Docs & Asset Fast-Path
|
|
16
41
|
if (this.isDocsAndAssetsOnly(changedFiles)) {
|
|
42
|
+
const fileNames = changedFiles.map((f) => path.basename(f.path));
|
|
43
|
+
const preview = fileNames.slice(0, 4).join(', ') +
|
|
44
|
+
(fileNames.length > 4 ? ` (+${fileNames.length - 4} more)` : '');
|
|
17
45
|
return {
|
|
18
46
|
isFullRegression: false,
|
|
19
47
|
fullRegressionReason: undefined,
|
|
@@ -23,8 +51,8 @@ export class TestSelector {
|
|
|
23
51
|
aiAnalysis: {
|
|
24
52
|
changedComponents: [],
|
|
25
53
|
impactedComponents: [],
|
|
26
|
-
directReason:
|
|
27
|
-
rippleEffectReason: '
|
|
54
|
+
directReason: `Verified documentation/non-code changes only (${preview}). Static code analysis confirmed zero application source code, components, or domain logic were altered.`,
|
|
55
|
+
rippleEffectReason: 'Documentation, asset, or metadata changes do not alter runtime UI or application workflows. Safe to skip regression suite.',
|
|
28
56
|
riskScore: 'LOW',
|
|
29
57
|
requiresFullRegression: false,
|
|
30
58
|
confidenceScore: 'HIGH',
|
|
@@ -134,7 +162,7 @@ export class TestSelector {
|
|
|
134
162
|
}
|
|
135
163
|
isDocsAndAssetsOnly(changedFiles) {
|
|
136
164
|
if (changedFiles.length === 0)
|
|
137
|
-
return
|
|
165
|
+
return false;
|
|
138
166
|
const docsPatterns = this.config.safetyRules?.docsOnlyPatterns || [
|
|
139
167
|
'**/*.md',
|
|
140
168
|
'docs/**',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright-smart-test",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI-Powered Smart Regression Test Selection Agent for Playwright",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -69,4 +69,4 @@
|
|
|
69
69
|
"overrides": {
|
|
70
70
|
"minimatch": "^11.0.3"
|
|
71
71
|
}
|
|
72
|
-
}
|
|
72
|
+
}
|