playwright-smart-test 1.0.9 → 1.0.10
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/README.md +15 -5
- package/dist/cli/index.js +12 -1
- package/dist/diff/git-diff-analyzer.js +37 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -158,13 +158,13 @@ Generate a starter configuration with `npx playwright-smart-test init` or create
|
|
|
158
158
|
},
|
|
159
159
|
"ai": {
|
|
160
160
|
"provider": "gemini",
|
|
161
|
-
"model": "gemini-3.
|
|
161
|
+
"model": "gemini-3.5-flash-lite",
|
|
162
162
|
"temperature": 0.2
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
-
> **Model Flexibility**: You can configure any Gemini model (e.g. `gemini-3.
|
|
167
|
+
> **Model Flexibility**: You can configure any Gemini model (e.g. `gemini-3.5-flash-lite`, `gemini-2.5-flash`, `gemini-1.5-flash`, `gemini-1.5-pro`) or override it dynamically via the `GEMINI_MODEL` environment variable.
|
|
168
168
|
|
|
169
169
|
---
|
|
170
170
|
|
|
@@ -178,8 +178,11 @@ Generate a starter configuration with `npx playwright-smart-test init` or create
|
|
|
178
178
|
| `playwright-smart-test init` | Generates a starter `playwright-smart-test.config.json` configuration file. |
|
|
179
179
|
|
|
180
180
|
### CLI Options
|
|
181
|
-
* `-b, --base <ref>`: Target Git branch or
|
|
182
|
-
* `-h, --head <ref>`: Head Git commit/branch (default: working directory
|
|
181
|
+
* `-b, --base <ref>`: Target Git branch, commit, or tag to diff against. Supports remote references (`origin/main`), local branches (`main`), commit SHAs, and ancestor specifiers (`HEAD~1`, `origin/main~2`, `HEAD^`).
|
|
182
|
+
* `-h, --head <ref>`: Head Git commit/branch (default: `HEAD` or uncommitted working directory).
|
|
183
|
+
* `--fail-on-empty`: Exit with status code 1 if 0 modified files are detected against the base ref (safeguard against empty diffs or un-fetched base refs in CI).
|
|
184
|
+
* `--comment`: Automatically post or update an interactive PR comment on GitHub and append the report to `$GITHUB_STEP_SUMMARY`.
|
|
185
|
+
* `--cwd <dir>`: Target working directory (defaults to `process.cwd()`).
|
|
183
186
|
* `--staged`: Analyze only staged git changes.
|
|
184
187
|
* `-c, --config <path>`: Path to custom configuration file.
|
|
185
188
|
* `-o, --output <path>`: Save report to `.md` or `.json` (e.g. `--output report.md`).
|
|
@@ -237,11 +240,18 @@ jobs:
|
|
|
237
240
|
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
|
|
238
241
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
239
242
|
run: |
|
|
240
|
-
npx playwright-smart-test run --comment --base "${{ github.event_name == 'pull_request' && format('origin/{0}', github.base_ref) || 'HEAD~1' }}"
|
|
243
|
+
npx playwright-smart-test run --comment --fail-on-empty --base "${{ github.event_name == 'pull_request' && format('origin/{0}', github.base_ref) || 'HEAD~1' }}"
|
|
241
244
|
```
|
|
242
245
|
|
|
243
246
|
---
|
|
244
247
|
|
|
248
|
+
> [!TIP]
|
|
249
|
+
> Always execute with `npx playwright-smart-test` (or `npm exec -- playwright-smart-test`) rather than bare `npm exec`. In `npm 10`, flags passed after binary subcommands without the `--` separator may be intercepted by `npm exec` rather than reaching the CLI agent.
|
|
250
|
+
>
|
|
251
|
+
> Also ensure `actions/checkout` specifies `fetch-depth: 0` so full git history is available to calculate diffs against the base branch.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
245
255
|
## 📊 Sample PR Impact Report
|
|
246
256
|
|
|
247
257
|
When running `playwright-smart-test run --comment` or `playwright-smart-test comment`, the agent automatically posts an interactive analysis report directly to the GitHub Pull Request and GitHub Actions Step Summary:
|
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.10');
|
|
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);
|
|
@@ -27,6 +27,14 @@ async function executeAnalysis(options) {
|
|
|
27
27
|
staged: options.staged,
|
|
28
28
|
});
|
|
29
29
|
console.log(`Detected ${pc.yellow(changedFiles.length.toString())} modified files.`);
|
|
30
|
+
if (changedFiles.length === 0) {
|
|
31
|
+
if (options.base) {
|
|
32
|
+
console.warn(pc.yellow(`⚠️ [playwright-smart-test] Warning: 0 modified files detected against base '${options.base}'. Verify that '${options.base}' exists and has distinct commits relative to HEAD.`));
|
|
33
|
+
}
|
|
34
|
+
if (options.failOnEmpty) {
|
|
35
|
+
throw new Error(`0 modified files detected against base '${options.base || 'HEAD'}'. Aborting because --fail-on-empty was specified.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
30
38
|
const catalogIndexer = new TestCatalogIndexer(cwd);
|
|
31
39
|
const catalog = await catalogIndexer.scanTestFiles(config.testDir, config.testMatch);
|
|
32
40
|
console.log(`Indexed ${pc.yellow(catalog.length.toString())} Playwright spec files in '${config.testDir}'.`);
|
|
@@ -43,6 +51,7 @@ program
|
|
|
43
51
|
.option('-c, --config <path>', 'Path to custom config file')
|
|
44
52
|
.option('-o, --output <path>', 'Save analysis result to file (.json or .md)')
|
|
45
53
|
.option('--cwd <dir>', 'Working directory', process.cwd())
|
|
54
|
+
.option('--fail-on-empty', 'Exit with error code 1 if 0 modified files are detected')
|
|
46
55
|
.action(async (options) => {
|
|
47
56
|
try {
|
|
48
57
|
const { result } = await executeAnalysis(options);
|
|
@@ -75,6 +84,7 @@ program
|
|
|
75
84
|
.option('--cwd <dir>', 'Working directory', process.cwd())
|
|
76
85
|
.option('--dry-run', 'Print the command without executing')
|
|
77
86
|
.option('--comment', 'Automatically post or update PR comment and step summary on GitHub')
|
|
87
|
+
.option('--fail-on-empty', 'Exit with error code 1 if 0 modified files are detected')
|
|
78
88
|
.action(async (options) => {
|
|
79
89
|
try {
|
|
80
90
|
const { result, cwd } = await executeAnalysis(options);
|
|
@@ -111,6 +121,7 @@ program
|
|
|
111
121
|
.option('--repo <owner/repo>', 'Explicit GitHub repository')
|
|
112
122
|
.option('--token <token>', 'Explicit GitHub Token')
|
|
113
123
|
.option('--stdout', 'Only output markdown to stdout without attempting GitHub API post')
|
|
124
|
+
.option('--fail-on-empty', 'Exit with error code 1 if 0 modified files are detected')
|
|
114
125
|
.action(async (options) => {
|
|
115
126
|
try {
|
|
116
127
|
const { result } = await executeAnalysis(options);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
+
import pc from 'picocolors';
|
|
3
4
|
const execFileAsync = promisify(execFile);
|
|
4
5
|
export class GitDiffAnalyzer {
|
|
5
6
|
cwd;
|
|
@@ -33,7 +34,7 @@ export class GitDiffAnalyzer {
|
|
|
33
34
|
if (safeRef.startsWith('/') || safeRef.endsWith('/')) {
|
|
34
35
|
return null;
|
|
35
36
|
}
|
|
36
|
-
const validPattern = /^(?:HEAD|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*|refs\/(?:heads|remotes|tags)\/[A-Za-z0-9._/-]+)
|
|
37
|
+
const validPattern = /^(?:HEAD|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*|refs\/(?:heads|remotes|tags)\/[A-Za-z0-9._/-]+)(?:~[0-9]+|\^[0-9]*)*$/;
|
|
37
38
|
if (!validPattern.test(safeRef)) {
|
|
38
39
|
return null;
|
|
39
40
|
}
|
|
@@ -57,6 +58,12 @@ export class GitDiffAnalyzer {
|
|
|
57
58
|
}
|
|
58
59
|
async getChangedFiles(options = {}) {
|
|
59
60
|
await this.runGit(['rev-parse', '--is-inside-work-tree']);
|
|
61
|
+
if (options.base && !this.sanitizeGitRef(options.base)) {
|
|
62
|
+
throw new Error(`Invalid base git reference '${options.base}'. Reference contains disallowed characters or formatting.`);
|
|
63
|
+
}
|
|
64
|
+
if (options.head && !this.sanitizeGitRef(options.head)) {
|
|
65
|
+
throw new Error(`Invalid head git reference '${options.head}'. Reference contains disallowed characters or formatting.`);
|
|
66
|
+
}
|
|
60
67
|
const safeBase = this.sanitizeGitRef(options.base);
|
|
61
68
|
const safeHead = this.sanitizeGitRef(options.head) ?? 'HEAD';
|
|
62
69
|
if (safeBase) {
|
|
@@ -66,12 +73,13 @@ export class GitDiffAnalyzer {
|
|
|
66
73
|
catch {
|
|
67
74
|
const remoteRef = this.parseRemoteRef(safeBase) ?? { remote: 'origin', branch: safeBase };
|
|
68
75
|
const { remote, branch } = remoteRef;
|
|
76
|
+
const fetchBranch = branch.replace(/[~^].*$/, '');
|
|
69
77
|
try {
|
|
70
|
-
await this.runGit(['fetch', '--depth=100', remote, `+refs/heads/${
|
|
78
|
+
await this.runGit(['fetch', '--depth=100', remote, `+refs/heads/${fetchBranch}:refs/remotes/${remote}/${fetchBranch}`]);
|
|
71
79
|
}
|
|
72
80
|
catch {
|
|
73
81
|
try {
|
|
74
|
-
await this.runGit(['fetch', '--depth=100', remote, `+${
|
|
82
|
+
await this.runGit(['fetch', '--depth=100', remote, `+${fetchBranch}:refs/remotes/${remote}/${fetchBranch}`]);
|
|
75
83
|
}
|
|
76
84
|
catch {
|
|
77
85
|
// Ignore fetch failure and proceed with available refs.
|
|
@@ -92,6 +100,7 @@ export class GitDiffAnalyzer {
|
|
|
92
100
|
else {
|
|
93
101
|
diffRangeArgs = ['HEAD'];
|
|
94
102
|
}
|
|
103
|
+
console.log(pc.dim(`[playwright-smart-test] Comparing git diff using: git diff --numstat ${diffRangeArgs.join(' ')}`));
|
|
95
104
|
let numstatOutput;
|
|
96
105
|
try {
|
|
97
106
|
numstatOutput = await this.runGit(['diff', '--numstat', ...diffRangeArgs]);
|
|
@@ -104,6 +113,9 @@ export class GitDiffAnalyzer {
|
|
|
104
113
|
}
|
|
105
114
|
catch (fallbackErr) {
|
|
106
115
|
const diffMessage = diffErr instanceof Error ? diffErr.message : String(diffErr);
|
|
116
|
+
if (safeBase) {
|
|
117
|
+
throw new Error(`Git diff failed for base '${safeBase}': ${diffMessage}`);
|
|
118
|
+
}
|
|
107
119
|
console.warn(`[playwright-smart-test] Warning: git diff failed for [${diffRangeArgs.join(' ')}] and fallback [${fallbackArgs.join(' ')}]: ${diffMessage}`);
|
|
108
120
|
numstatOutput = '';
|
|
109
121
|
}
|
|
@@ -139,6 +151,28 @@ export class GitDiffAnalyzer {
|
|
|
139
151
|
patch,
|
|
140
152
|
};
|
|
141
153
|
});
|
|
154
|
+
// Also include untracked files when diffing locally against working tree without base
|
|
155
|
+
if (!safeBase && !options.staged) {
|
|
156
|
+
try {
|
|
157
|
+
const untrackedOutput = await this.runGit(['ls-files', '--others', '--exclude-standard']);
|
|
158
|
+
const untrackedFiles = untrackedOutput.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
159
|
+
for (const filePath of untrackedFiles) {
|
|
160
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
161
|
+
if (!allPaths.includes(normalized)) {
|
|
162
|
+
files.push({
|
|
163
|
+
path: normalized,
|
|
164
|
+
status: 'added',
|
|
165
|
+
additions: 1,
|
|
166
|
+
deletions: 0,
|
|
167
|
+
patch: '',
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// ls-files optional fallback
|
|
174
|
+
}
|
|
175
|
+
}
|
|
142
176
|
return files;
|
|
143
177
|
}
|
|
144
178
|
/**
|