taf-git 0.0.0-stage → 3.0.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/CHANGELOG.md +413 -0
- package/LICENSE +21 -0
- package/README.md +266 -2
- package/RECEIPT-FORMAT.md +100 -0
- package/dist/badge.d.ts +23 -0
- package/dist/badge.js +150 -0
- package/dist/badge.js.map +1 -0
- package/dist/cli.d.ts +42 -0
- package/dist/cli.js +323 -0
- package/dist/cli.js.map +1 -0
- package/dist/git-env.d.ts +20 -0
- package/dist/git-env.js +45 -0
- package/dist/git-env.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/parsers/bun.d.ts +58 -0
- package/dist/parsers/bun.js +126 -0
- package/dist/parsers/bun.js.map +1 -0
- package/dist/parsers/index.d.ts +21 -0
- package/dist/parsers/index.js +63 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/jest.d.ts +41 -0
- package/dist/parsers/jest.js +87 -0
- package/dist/parsers/jest.js.map +1 -0
- package/dist/parsers/junit.d.ts +24 -0
- package/dist/parsers/junit.js +144 -0
- package/dist/parsers/junit.js.map +1 -0
- package/dist/parsers/vitest.d.ts +16 -0
- package/dist/parsers/vitest.js +61 -0
- package/dist/parsers/vitest.js.map +1 -0
- package/dist/parsers/wjttc.d.ts +37 -0
- package/dist/parsers/wjttc.js +152 -0
- package/dist/parsers/wjttc.js.map +1 -0
- package/dist/receipt-push.d.ts +38 -0
- package/dist/receipt-push.js +63 -0
- package/dist/receipt-push.js.map +1 -0
- package/dist/skipped-names.d.ts +60 -0
- package/dist/skipped-names.js +159 -0
- package/dist/skipped-names.js.map +1 -0
- package/dist/taf-core.d.ts +32 -0
- package/dist/taf-core.js +303 -0
- package/dist/taf-core.js.map +1 -0
- package/package.json +64 -4
- package/project.faf +57 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* taf-git - The Git-Native Receipt Printer
|
|
5
|
+
*
|
|
6
|
+
* v2.x CLI: reads test output from file (pre-capture pattern)
|
|
7
|
+
* Platform-agnostic - works in ANY CI/CD environment or locally
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.runTafGit = runTafGit;
|
|
44
|
+
exports.optionValue = optionValue;
|
|
45
|
+
exports.cliVersion = cliVersion;
|
|
46
|
+
const child_process_1 = require("child_process");
|
|
47
|
+
const git_env_1 = require("./git-env");
|
|
48
|
+
const fs = __importStar(require("fs"));
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
const parsers_1 = require("./parsers");
|
|
51
|
+
const taf_core_1 = require("./taf-core");
|
|
52
|
+
const skipped_names_1 = require("./skipped-names");
|
|
53
|
+
const badge_1 = require("./badge");
|
|
54
|
+
/**
|
|
55
|
+
* Main CLI function - reads test output from file
|
|
56
|
+
*/
|
|
57
|
+
async function runTafGit(options = {}) {
|
|
58
|
+
const { file, autoCommit = false, commitMessage = 'chore: update .taf with test results', cwd = process.cwd(), verbose = false, logger = console.log, } = options;
|
|
59
|
+
try {
|
|
60
|
+
if (!file) {
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
tafUpdated: false,
|
|
64
|
+
error: 'No test output file specified. Use --file <path>.\nExample: npm test 2>&1 | tee test-output.txt && npx taf-git --file test-output.txt',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Resolve file path
|
|
68
|
+
const filePath = path.isAbsolute(file) ? file : path.join(cwd, file);
|
|
69
|
+
if (!fs.existsSync(filePath)) {
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
tafUpdated: false,
|
|
73
|
+
error: `Test output file not found: ${filePath}`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const output = fs.readFileSync(filePath, 'utf-8');
|
|
77
|
+
if (verbose)
|
|
78
|
+
logger(`Read ${output.length} bytes from ${filePath}`);
|
|
79
|
+
// Parse test output
|
|
80
|
+
const testResults = (0, parsers_1.parseTestOutput)(output);
|
|
81
|
+
if (!testResults) {
|
|
82
|
+
if (verbose) {
|
|
83
|
+
logger(`Parser returned null`);
|
|
84
|
+
logger(`Output sample (first 500 chars): ${output.slice(0, 500)}`);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
tafUpdated: false,
|
|
89
|
+
error: (0, parsers_1.noResultsReason)(output),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (verbose) {
|
|
93
|
+
logger(`Parsed results: ${testResults.passed}/${testResults.total} tests passing`);
|
|
94
|
+
}
|
|
95
|
+
// Check if .taf file exists
|
|
96
|
+
const tafPath = path.join(cwd, '.taf');
|
|
97
|
+
if (!fs.existsSync(tafPath)) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
testResults: {
|
|
101
|
+
total: testResults.total,
|
|
102
|
+
passed: testResults.passed,
|
|
103
|
+
failed: testResults.failed,
|
|
104
|
+
result: testResults.result,
|
|
105
|
+
},
|
|
106
|
+
tafUpdated: false,
|
|
107
|
+
error: taf_core_1.NO_TAF_FILE,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// Update .taf file
|
|
111
|
+
const updated = await (0, taf_core_1.updateTafFile)(tafPath, testResults, { skippedNamesCap: options.skippedNamesCap });
|
|
112
|
+
if (updated) {
|
|
113
|
+
if (verbose)
|
|
114
|
+
logger('.taf file updated successfully');
|
|
115
|
+
if (taf_core_1.lastUpdate.skippedTests?.newly_skipped?.length)
|
|
116
|
+
logger(`Newly skipped: ${taf_core_1.lastUpdate.skippedTests.newly_skipped.join(' | ')}`);
|
|
117
|
+
if (taf_core_1.lastUpdate.skippedNamesNote)
|
|
118
|
+
logger(`Skipped names not written: ${taf_core_1.lastUpdate.skippedNamesNote}`);
|
|
119
|
+
// Commit changes if enabled
|
|
120
|
+
if (autoCommit) {
|
|
121
|
+
commitTafUpdate(cwd, commitMessage, verbose, logger);
|
|
122
|
+
if (verbose)
|
|
123
|
+
logger('Changes committed to git');
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
success: true,
|
|
127
|
+
testResults: {
|
|
128
|
+
total: testResults.total,
|
|
129
|
+
passed: testResults.passed,
|
|
130
|
+
failed: testResults.failed,
|
|
131
|
+
result: testResults.result,
|
|
132
|
+
},
|
|
133
|
+
tafUpdated: true,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return {
|
|
138
|
+
success: false,
|
|
139
|
+
testResults: {
|
|
140
|
+
total: testResults.total,
|
|
141
|
+
passed: testResults.passed,
|
|
142
|
+
failed: testResults.failed,
|
|
143
|
+
result: testResults.result,
|
|
144
|
+
},
|
|
145
|
+
tafUpdated: false,
|
|
146
|
+
error: '.taf file was not updated',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return {
|
|
152
|
+
success: false,
|
|
153
|
+
tafUpdated: false,
|
|
154
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Commit .taf file changes to git
|
|
160
|
+
*/
|
|
161
|
+
function commitTafUpdate(cwd, message, verbose, logger = console.log) {
|
|
162
|
+
try {
|
|
163
|
+
// env passed explicitly (the same as the default): it is the process.env
|
|
164
|
+
// the caller sees, so a test that clears GIT_DIR clears it for git too.
|
|
165
|
+
const opts = { cwd, stdio: 'pipe', env: process.env };
|
|
166
|
+
// Arguments, never a shell string: the message is the user's text.
|
|
167
|
+
// Every step names .taf, so nothing else that is staged is committed.
|
|
168
|
+
(0, child_process_1.execFileSync)('git', ['add', '--', '.taf'], opts);
|
|
169
|
+
const diff = (0, child_process_1.execFileSync)('git', ['diff', '--cached', '--name-only', '--', '.taf'], opts).toString().trim();
|
|
170
|
+
if (diff.length === 0) {
|
|
171
|
+
if (verbose)
|
|
172
|
+
logger('No changes to commit');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
(0, child_process_1.execFileSync)('git', ['commit', '-m', message, '--', '.taf'], opts);
|
|
176
|
+
// Push only where there is somewhere to push. A branch with no upstream
|
|
177
|
+
// keeps the receipt in a local commit and says so; a push that fails
|
|
178
|
+
// (the remote moved on) is an error, never a quiet exit 0.
|
|
179
|
+
try {
|
|
180
|
+
(0, child_process_1.execFileSync)('git', ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'], opts);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
logger('Receipt committed. This branch has no upstream, so it was not pushed.');
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
(0, child_process_1.execFileSync)('git', ['push'], opts);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
const stderr = String(error.stderr ?? '');
|
|
191
|
+
const next = (0, git_env_1.pushWasBehind)(stderr) ? 'Send it with: git pull --rebase && git push' : 'Check your push access and branch protection, then: git push';
|
|
192
|
+
throw new Error(`The receipt is committed but not pushed: ${(0, git_env_1.pushFailureReason)(stderr)}. ${next}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (verbose)
|
|
197
|
+
logger(`Error committing changes: ${error}`);
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The value of an option, written `--name value` or `--name=value`; undefined
|
|
203
|
+
* when it isn't there or has no value.
|
|
204
|
+
*/
|
|
205
|
+
function optionValue(args, name) {
|
|
206
|
+
for (let i = 0; i < args.length; i++) {
|
|
207
|
+
if (args[i] === name) {
|
|
208
|
+
return args[i + 1];
|
|
209
|
+
}
|
|
210
|
+
if (args[i].startsWith(`${name}=`)) {
|
|
211
|
+
return args[i].slice(name.length + 1);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Handle the 'badge' subcommand
|
|
218
|
+
*/
|
|
219
|
+
function handleBadgeCommand(args) {
|
|
220
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
221
|
+
console.log(`\ntaf-git badge - Generate SVG badge from .taf history\n\nUSAGE:\n npx taf-git badge [OPTIONS]\n\nOPTIONS:\n --output <path> Write SVG to file (default: stdout)\n --label <text> Badge label (default: TAF)\n --taf <path> Path to .taf file (default: .taf)\n --help, -h Show this help\n`);
|
|
222
|
+
process.exit(0);
|
|
223
|
+
}
|
|
224
|
+
const outputPath = optionValue(args, '--output') || undefined;
|
|
225
|
+
const label = optionValue(args, '--label') || undefined;
|
|
226
|
+
const tafPath = optionValue(args, '--taf') || undefined;
|
|
227
|
+
const result = (0, badge_1.generateBadge)({ tafPath, label });
|
|
228
|
+
if (!result.success || !result.svg) {
|
|
229
|
+
console.error(`Error: ${result.error || 'Failed to generate badge'}`);
|
|
230
|
+
process.exit(1);
|
|
231
|
+
}
|
|
232
|
+
if (outputPath) {
|
|
233
|
+
fs.writeFileSync(outputPath, result.svg, 'utf-8');
|
|
234
|
+
console.log(`Badge written to ${outputPath}`);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
process.stdout.write(result.svg);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The installed package's version. package.json sits one level above both
|
|
242
|
+
* src/ (tests) and dist/ (the published bin).
|
|
243
|
+
*/
|
|
244
|
+
function cliVersion() {
|
|
245
|
+
return JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8')).version;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* CLI entry point
|
|
249
|
+
*/
|
|
250
|
+
async function main() {
|
|
251
|
+
const args = process.argv.slice(2);
|
|
252
|
+
// --version / -V (-v is --verbose)
|
|
253
|
+
if (args.includes('--version') || args.includes('-V')) {
|
|
254
|
+
console.log(cliVersion());
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
// Subcommand: badge
|
|
258
|
+
if (args[0] === 'badge') {
|
|
259
|
+
handleBadgeCommand(args.slice(1));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// Show help
|
|
263
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
264
|
+
console.log(`\ntaf-git - The Git-Native Receipt Printer\n\nUSAGE:\n npm test 2>&1 | tee test-output.txt\n npx taf-git --file test-output.txt [OPTIONS]\n\n # WJTTC / pc-ai bar\n node tests/wjttc/run-wjttc.mjs 2>&1 | tee wjttc-out.txt\n npx taf-git --file wjttc-out.txt\n\nCOMMANDS:\n badge Generate a shields.io-style SVG badge from .taf\n\nOPTIONS:\n --file <path> Path to test output file (required)\n --commit Auto-commit .taf changes to git\n --message <msg> Custom commit message\n --cwd <dir> Working directory (default: current)\n --skipped-names <n> Skipped test names per receipt (default 25, 0 = off)\n --verbose, -v Verbose output\n --version, -V Print the version\n --help, -h Show this help\n\nPARSERS:\n JUnit XML (pytest, cargo, Go, Java, .NET ...), Bun, WJTTC (pc-ai bar), Jest, Vitest\n\nEXAMPLES:\n npm test 2>&1 | tee test-output.txt\n npx taf-git --file test-output.txt\n\n npx taf-git --file test-output.txt --commit\n\n npx taf-git badge --output badge.svg\n\nPLATFORM SUPPORT:\n Works in ANY CI/CD that runs Node.js:\n GitHub Actions, GitLab CI, Jenkins, CircleCI,\n Bitbucket Pipelines, Azure Pipelines, local dev\n\nLEARN MORE:\n https://github.com/Wolfe-Jam/taf-git\n`);
|
|
265
|
+
process.exit(0);
|
|
266
|
+
}
|
|
267
|
+
const options = {
|
|
268
|
+
verbose: args.includes('--verbose') || args.includes('-v'),
|
|
269
|
+
};
|
|
270
|
+
// Options take `--name value` or `--name=value`.
|
|
271
|
+
const file = optionValue(args, '--file');
|
|
272
|
+
if (file) {
|
|
273
|
+
options.file = file;
|
|
274
|
+
}
|
|
275
|
+
// Parse auto-commit flag
|
|
276
|
+
if (args.includes('--commit')) {
|
|
277
|
+
options.autoCommit = true;
|
|
278
|
+
}
|
|
279
|
+
const message = optionValue(args, '--message');
|
|
280
|
+
if (message) {
|
|
281
|
+
options.commitMessage = message;
|
|
282
|
+
}
|
|
283
|
+
const cwd = optionValue(args, '--cwd');
|
|
284
|
+
if (cwd) {
|
|
285
|
+
options.cwd = cwd;
|
|
286
|
+
}
|
|
287
|
+
if (args.some((a) => a === '--skipped-names' || a.startsWith('--skipped-names='))) {
|
|
288
|
+
try {
|
|
289
|
+
options.skippedNamesCap = (0, skipped_names_1.parseSkippedNamesCap)(optionValue(args, '--skipped-names'));
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
console.error(error.message);
|
|
293
|
+
process.exit(1);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Run the tool
|
|
297
|
+
const result = await runTafGit(options);
|
|
298
|
+
if (result.success) {
|
|
299
|
+
if (result.testResults) {
|
|
300
|
+
console.log(`Tests: ${result.testResults.passed}/${result.testResults.total} passing`);
|
|
301
|
+
console.log(`Result: ${result.testResults.result}`);
|
|
302
|
+
}
|
|
303
|
+
if (result.tafUpdated) {
|
|
304
|
+
console.log('.taf file updated');
|
|
305
|
+
}
|
|
306
|
+
process.exit(0);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
console.error(`Error: ${result.error}`);
|
|
310
|
+
if (result.testResults) {
|
|
311
|
+
console.log(`Tests: ${result.testResults.passed}/${result.testResults.total} passing`);
|
|
312
|
+
}
|
|
313
|
+
process.exit(1);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// Run CLI if called directly
|
|
317
|
+
if (require.main === module) {
|
|
318
|
+
main().catch((error) => {
|
|
319
|
+
console.error('Fatal error:', error);
|
|
320
|
+
process.exit(1);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AACA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCH,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AClB,CAAC;AACH,CAAC;AAED,6BAA6B;AAC7B,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bot's git identity, given to each git command through the environment.
|
|
3
|
+
* Never written to git config: `git config --global` on a developer's machine
|
|
4
|
+
* would replace their own name and email for every repo.
|
|
5
|
+
*/
|
|
6
|
+
export declare function botGitEnv(base?: NodeJS.ProcessEnv): {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Why a `git push` failed, from its stderr: the `[remote rejected]` /
|
|
11
|
+
* `[rejected]` line (else `error:` / `fatal:`), plus the server's own
|
|
12
|
+
* `remote:` message when it sent one. Never the hint git prints after them.
|
|
13
|
+
*/
|
|
14
|
+
export declare function pushFailureReason(stderr: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* True when the push was refused because the remote moved on (pulling first
|
|
17
|
+
* fixes it): behind before the push, or the ref moved during it (`cannot lock
|
|
18
|
+
* ref` / `failed to update ref`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function pushWasBehind(stderr: string): boolean;
|
package/dist/git-env.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.botGitEnv = botGitEnv;
|
|
4
|
+
exports.pushFailureReason = pushFailureReason;
|
|
5
|
+
exports.pushWasBehind = pushWasBehind;
|
|
6
|
+
/**
|
|
7
|
+
* The bot's git identity, given to each git command through the environment.
|
|
8
|
+
* Never written to git config: `git config --global` on a developer's machine
|
|
9
|
+
* would replace their own name and email for every repo.
|
|
10
|
+
*/
|
|
11
|
+
function botGitEnv(base = process.env) {
|
|
12
|
+
const env = {};
|
|
13
|
+
for (const [k, v] of Object.entries(base)) {
|
|
14
|
+
if (v !== undefined) {
|
|
15
|
+
env[k] = v;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
env.GIT_AUTHOR_NAME = 'taf-git[bot]';
|
|
19
|
+
env.GIT_AUTHOR_EMAIL = 'taf-git[bot]@users.noreply.github.com';
|
|
20
|
+
env.GIT_COMMITTER_NAME = 'taf-git[bot]';
|
|
21
|
+
env.GIT_COMMITTER_EMAIL = 'taf-git[bot]@users.noreply.github.com';
|
|
22
|
+
return env;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Why a `git push` failed, from its stderr: the `[remote rejected]` /
|
|
26
|
+
* `[rejected]` line (else `error:` / `fatal:`), plus the server's own
|
|
27
|
+
* `remote:` message when it sent one. Never the hint git prints after them.
|
|
28
|
+
*/
|
|
29
|
+
function pushFailureReason(stderr) {
|
|
30
|
+
const lines = stderr.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
31
|
+
const pick = (re) => lines.find((l) => re.test(l));
|
|
32
|
+
const why = pick(/\[remote rejected\]/) ?? pick(/\[rejected\]/) ?? pick(/^(error|fatal):/) ?? lines[lines.length - 1] ?? 'push failed';
|
|
33
|
+
const remote = lines.find((l) => /^remote:\s*\S/.test(l) && !/^remote:\s*(Resolving|Counting|Compressing|Total|Enumerating)/.test(l));
|
|
34
|
+
return [why, remote].filter(Boolean).join(' — ').replace(/\.+$/, '');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* True when the push was refused because the remote moved on (pulling first
|
|
38
|
+
* fixes it): behind before the push, or the ref moved during it (`cannot lock
|
|
39
|
+
* ref` / `failed to update ref`).
|
|
40
|
+
*/
|
|
41
|
+
function pushWasBehind(stderr) {
|
|
42
|
+
return /\[rejected\].*\((fetch first|non-fast-forward)\)/.test(stderr)
|
|
43
|
+
|| /\[remote rejected\].*\((cannot lock ref|failed to update ref)/.test(stderr);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=git-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-env.js","sourceRoot":"","sources":["../src/git-env.ts"],"names":[],"mappings":";;AAKA,8BAQC;AAOD,8CAMC;AAOD,sCAGC;AApCD;;;;GAIG;AACH,SAAgB,SAAS,CAAC,OAA0B,OAAO,CAAC,GAAG;IAC7D,MAAM,GAAG,GAA8B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAAA,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YAAA,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAAA,CAAC;IAAA,CAAC;IAC/E,GAAG,CAAC,eAAe,GAAG,cAAc,CAAC;IACrC,GAAG,CAAC,gBAAgB,GAAG,uCAAuC,CAAC;IAC/D,GAAG,CAAC,kBAAkB,GAAG,cAAc,CAAC;IACxC,GAAG,CAAC,mBAAmB,GAAG,uCAAuC,CAAC;IAClE,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtE,MAAM,IAAI,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC,iBAAiB,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,aAAa,CAAC;IACvI,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,+DAA+D,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACtI,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,MAAc;IAC1C,OAAO,kDAAkD,CAAC,IAAI,CAAC,MAAM,CAAC;WACjE,+DAA+D,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACpF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun test output parser
|
|
3
|
+
*
|
|
4
|
+
* Extracts test counts from `bun test` CLI output.
|
|
5
|
+
*/
|
|
6
|
+
import { TestResults } from './jest';
|
|
7
|
+
/**
|
|
8
|
+
* Parse Bun test output to extract test results.
|
|
9
|
+
*
|
|
10
|
+
* Bun output format (summary block at the end of a run):
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* 232 pass
|
|
14
|
+
* 1 skip
|
|
15
|
+
* 1 todo
|
|
16
|
+
* 0 fail
|
|
17
|
+
* 848 expect() calls
|
|
18
|
+
* Ran 234 tests across 9 files. [21.53s]
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Notes:
|
|
22
|
+
* - Anchored on `Ran <N> tests across <M> files.` — the canonical truthful
|
|
23
|
+
* total (includes skip + todo + pass + fail). Without this line, the parser
|
|
24
|
+
* returns null and the dispatcher falls through to jest/vitest.
|
|
25
|
+
* - Per-category counts (`pass`, `fail`, `skip`, `todo`) come from their own
|
|
26
|
+
* lines elsewhere in the same output. Singular forms — bun does not use
|
|
27
|
+
* `passed`/`failed`/`skipped` (intentional differentiator from jest/vitest).
|
|
28
|
+
* - `skipped` aggregates `skip` + `todo` (matches the convention vitest.ts
|
|
29
|
+
* already uses for parity in the shared TestResults shape).
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseBunOutput(output: string): TestResults | null;
|
|
32
|
+
/**
|
|
33
|
+
* Example Bun outputs for testing:
|
|
34
|
+
*
|
|
35
|
+
* All passing:
|
|
36
|
+
* ```
|
|
37
|
+
* 173 pass
|
|
38
|
+
* 0 fail
|
|
39
|
+
* Ran 173 tests across 8 files. [4.2s]
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* Mixed (the grok-faf-mcp 1.4.9 shape):
|
|
43
|
+
* ```
|
|
44
|
+
* 232 pass
|
|
45
|
+
* 1 skip
|
|
46
|
+
* 1 todo
|
|
47
|
+
* 0 fail
|
|
48
|
+
* 848 expect() calls
|
|
49
|
+
* Ran 234 tests across 9 files. [21.53s]
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* Failing:
|
|
53
|
+
* ```
|
|
54
|
+
* 170 pass
|
|
55
|
+
* 3 fail
|
|
56
|
+
* Ran 173 tests across 8 files. [5.1s]
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bun test output parser
|
|
4
|
+
*
|
|
5
|
+
* Extracts test counts from `bun test` CLI output.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.parseBunOutput = parseBunOutput;
|
|
9
|
+
/**
|
|
10
|
+
* Parse Bun test output to extract test results.
|
|
11
|
+
*
|
|
12
|
+
* Bun output format (summary block at the end of a run):
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* 232 pass
|
|
16
|
+
* 1 skip
|
|
17
|
+
* 1 todo
|
|
18
|
+
* 0 fail
|
|
19
|
+
* 848 expect() calls
|
|
20
|
+
* Ran 234 tests across 9 files. [21.53s]
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Notes:
|
|
24
|
+
* - Anchored on `Ran <N> tests across <M> files.` — the canonical truthful
|
|
25
|
+
* total (includes skip + todo + pass + fail). Without this line, the parser
|
|
26
|
+
* returns null and the dispatcher falls through to jest/vitest.
|
|
27
|
+
* - Per-category counts (`pass`, `fail`, `skip`, `todo`) come from their own
|
|
28
|
+
* lines elsewhere in the same output. Singular forms — bun does not use
|
|
29
|
+
* `passed`/`failed`/`skipped` (intentional differentiator from jest/vitest).
|
|
30
|
+
* - `skipped` aggregates `skip` + `todo` (matches the convention vitest.ts
|
|
31
|
+
* already uses for parity in the shared TestResults shape).
|
|
32
|
+
*/
|
|
33
|
+
function parseBunOutput(output) {
|
|
34
|
+
// Strip ANSI color codes + normalize line endings (parity with siblings).
|
|
35
|
+
// eslint-disable-next-line no-control-regex
|
|
36
|
+
let cleanOutput = output.replace(/\x1b\[[0-9;]*m/g, '');
|
|
37
|
+
cleanOutput = cleanOutput.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
38
|
+
// Canonical anchor: bun-unique "Ran N tests across M files." summary line.
|
|
39
|
+
// Without this, this isn't bun output — let the dispatcher try the others.
|
|
40
|
+
const ranMatch = cleanOutput.match(/^Ran\s+(\d+)\s+tests?\s+across\s+\d+\s+files?/m);
|
|
41
|
+
if (!ranMatch)
|
|
42
|
+
return null;
|
|
43
|
+
const total = parseInt(ranMatch[1], 10);
|
|
44
|
+
if (total === 0)
|
|
45
|
+
return null;
|
|
46
|
+
let passed = 0;
|
|
47
|
+
let failed = 0;
|
|
48
|
+
let skipped = 0;
|
|
49
|
+
// Per-line counts. Each line is `<leading-ws><N> <singular-word>` on its own.
|
|
50
|
+
// Anchored with ^...$ + multiline to avoid catching the "expect() calls" line
|
|
51
|
+
// or any noise inside test descriptions.
|
|
52
|
+
const passedMatch = cleanOutput.match(/^\s*(\d+)\s+pass\s*$/m);
|
|
53
|
+
if (passedMatch)
|
|
54
|
+
passed = parseInt(passedMatch[1], 10);
|
|
55
|
+
const failedMatch = cleanOutput.match(/^\s*(\d+)\s+fail\s*$/m);
|
|
56
|
+
if (failedMatch)
|
|
57
|
+
failed = parseInt(failedMatch[1], 10);
|
|
58
|
+
const skipMatch = cleanOutput.match(/^\s*(\d+)\s+skip\s*$/m);
|
|
59
|
+
if (skipMatch)
|
|
60
|
+
skipped += parseInt(skipMatch[1], 10);
|
|
61
|
+
const todoMatch = cleanOutput.match(/^\s*(\d+)\s+todo\s*$/m);
|
|
62
|
+
if (todoMatch)
|
|
63
|
+
skipped += parseInt(todoMatch[1], 10);
|
|
64
|
+
const result = failed > 0 ? 'FAILED' : 'PASSED';
|
|
65
|
+
return {
|
|
66
|
+
total,
|
|
67
|
+
passed,
|
|
68
|
+
failed,
|
|
69
|
+
skipped: skipped > 0 ? skipped : undefined,
|
|
70
|
+
skippedNames: skipped > 0 ? bunSkippedNames(cleanOutput) : undefined,
|
|
71
|
+
result,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Names of skipped and todo tests: `(skip) outer > name` and `(todo) name`
|
|
76
|
+
* lines, each prefixed with its file header (`a.test.ts:` in a terminal,
|
|
77
|
+
* `::group::a.test.ts:` in GitHub Actions). Undefined when bun printed no
|
|
78
|
+
* per-test lines (it omits them when it detects an AI agent running it).
|
|
79
|
+
*/
|
|
80
|
+
function bunSkippedNames(cleanOutput) {
|
|
81
|
+
const names = [];
|
|
82
|
+
let file = '';
|
|
83
|
+
let sawTestLine = false;
|
|
84
|
+
for (const line of cleanOutput.split('\n')) {
|
|
85
|
+
const header = line.match(/^(?:::group::)?(\S.*?):\s*$/);
|
|
86
|
+
if (header && !/^\(/.test(line)) {
|
|
87
|
+
file = header[1];
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const test = line.match(/^\((skip|todo|pass|fail)\)\s+(.*)$/);
|
|
91
|
+
if (!test)
|
|
92
|
+
continue;
|
|
93
|
+
sawTestLine = true;
|
|
94
|
+
if (test[1] === 'skip' || test[1] === 'todo')
|
|
95
|
+
names.push(file ? `${file} > ${test[2]}` : test[2]);
|
|
96
|
+
}
|
|
97
|
+
return sawTestLine ? names : undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Example Bun outputs for testing:
|
|
101
|
+
*
|
|
102
|
+
* All passing:
|
|
103
|
+
* ```
|
|
104
|
+
* 173 pass
|
|
105
|
+
* 0 fail
|
|
106
|
+
* Ran 173 tests across 8 files. [4.2s]
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* Mixed (the grok-faf-mcp 1.4.9 shape):
|
|
110
|
+
* ```
|
|
111
|
+
* 232 pass
|
|
112
|
+
* 1 skip
|
|
113
|
+
* 1 todo
|
|
114
|
+
* 0 fail
|
|
115
|
+
* 848 expect() calls
|
|
116
|
+
* Ran 234 tests across 9 files. [21.53s]
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* Failing:
|
|
120
|
+
* ```
|
|
121
|
+
* 170 pass
|
|
122
|
+
* 3 fail
|
|
123
|
+
* Ran 173 tests across 8 files. [5.1s]
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
//# sourceMappingURL=bun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.js","sourceRoot":"","sources":["../../src/parsers/bun.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA4BH,wCA2CC;AAnED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,cAAc,CAAC,MAAc;IAC3C,0EAA0E;IAC1E,4CAA4C;IAC5C,IAAI,WAAW,GAAG,MAAM,CAAC,OAAO,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,CAAC;IACpG,CAAC;IACD,OAAO,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACzC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified test output parser
|
|
3
|
+
*
|
|
4
|
+
* Tries each framework parser in order until one succeeds.
|
|
5
|
+
*/
|
|
6
|
+
import { TestResults } from './jest';
|
|
7
|
+
export { TestResults } from './jest';
|
|
8
|
+
export { parseJunitOutput } from './junit';
|
|
9
|
+
export { parseWjttcOutput } from './wjttc';
|
|
10
|
+
export declare const SUPPORTED_PARSERS: readonly string[];
|
|
11
|
+
/** What the CLI and the Action report when no parser matches. */
|
|
12
|
+
export declare const UNPARSEABLE_OUTPUT: string;
|
|
13
|
+
/** A JUnit report that lists no tests (node --test with no test files): nothing ran, so no receipt. */
|
|
14
|
+
export declare const NO_TESTS = "No tests ran: the JUnit report lists 0 tests, so there is no receipt to print.";
|
|
15
|
+
/** Why the output gave no results: no tests at all, or a format taf-git doesn't read. */
|
|
16
|
+
export declare function noResultsReason(output: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Parse test output from any supported framework: the first parser in
|
|
19
|
+
* PARSERS that recognises the output wins.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseTestOutput(output: string): TestResults | null;
|