@haus-tech/haus-workflow 7.1.0 → 7.2.1
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 +27 -0
- package/dist/cli.js +9712 -9498
- package/package.json +1 -1
- package/packages/agents/qa-fixer.md +66 -0
- package/packages/agents/qa-inventory.md +36 -0
- package/packages/agents/qa-reviewer.md +32 -0
- package/packages/agents/qa-tester.md +85 -0
- package/packages/packages.yaml +8 -0
- package/packages/skills/fixing-weak-tests/SKILL.md +89 -0
- package/packages/skills/fixing-weak-tests/references/audit-brief.md +57 -0
- package/packages/skills/fixing-weak-tests/references/fix-brief.md +55 -0
- package/packages/skills/optimizing-test-suites/SKILL.md +157 -0
- package/packages/skills/optimizing-test-suites/references/affected-tests.md +46 -0
- package/packages/skills/optimizing-test-suites/references/levers.md +79 -0
- package/packages/skills/optimizing-test-suites/scripts/slowest.mjs +78 -0
- package/packages/skills/qa-genomklickning/SKILL.md +179 -0
- package/packages/skills/qa-genomklickning/drivers.md +159 -0
- package/packages/skills/qa-genomklickning/report.md +23 -0
- package/packages/skills/qa-genomklickning/scripts/android-setup.sh +26 -0
- package/packages/skills/qa-genomklickning/scripts/android.sh +62 -0
- package/packages/skills/qa-genomklickning/scripts/chrome-tab-guard.py +55 -0
- package/packages/skills/qa-genomklickning/scripts/env-check.sh +32 -0
- package/packages/skills/qa-genomklickning/scripts/ios-sim.sh +49 -0
- package/packages/skills/request/SKILL.md +3 -2
- package/packages/skills/request/scripts/compare-scores.mjs +23 -11
- package/packages/skills/testsammanfattning/SKILL.md +134 -0
- package/packages/skills/testsammanfattning/references/konfiguration.md +110 -0
- package/packages/skills/testsammanfattning/scripts/test-log.mjs +218 -0
- package/packages/skills/testsammanfattning/scripts/test-summary.mjs +495 -0
- package/packages/templates/agentic-workflow-standard.md +3 -3
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Runs the test suites in test-summary.config.json, writes one log per run and
|
|
3
|
+
// regenerates the test summary. Generated by the testsammanfattning skill.
|
|
4
|
+
//
|
|
5
|
+
// Usage: node scripts/test-log.mjs [--suite unit,e2e] [--no-run] [--config test-summary.config.json]
|
|
6
|
+
//
|
|
7
|
+
// Exit code is 1 if any test or command failed. The log and the summary are
|
|
8
|
+
// written in either case.
|
|
9
|
+
|
|
10
|
+
import { spawnSync, execSync } from 'node:child_process'
|
|
11
|
+
import fs from 'node:fs'
|
|
12
|
+
import os from 'node:os'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
import {
|
|
15
|
+
SEP,
|
|
16
|
+
loadConfig,
|
|
17
|
+
parseJestJson,
|
|
18
|
+
parseJunitXml,
|
|
19
|
+
parsePlaywrightJson,
|
|
20
|
+
relFile,
|
|
21
|
+
stripAnsi,
|
|
22
|
+
writeSummary,
|
|
23
|
+
} from './test-summary.mjs'
|
|
24
|
+
|
|
25
|
+
const MAX_ERROR_LINES = 40
|
|
26
|
+
|
|
27
|
+
function git(cmd, cwd) {
|
|
28
|
+
try {
|
|
29
|
+
return execSync(`git ${cmd}`, { cwd, stdio: ['ignore', 'pipe', 'ignore'] })
|
|
30
|
+
.toString()
|
|
31
|
+
.trim()
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function stamp(d) {
|
|
38
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
39
|
+
return {
|
|
40
|
+
file: `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`,
|
|
41
|
+
human: `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function run(command, cwd, env) {
|
|
46
|
+
console.log(`test-log: ${command}`)
|
|
47
|
+
const res = spawnSync(command, {
|
|
48
|
+
cwd,
|
|
49
|
+
shell: true,
|
|
50
|
+
env: { ...process.env, ...env },
|
|
51
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
52
|
+
maxBuffer: 512 * 1024 * 1024,
|
|
53
|
+
})
|
|
54
|
+
const output = stripAnsi(`${res.stdout ?? ''}${res.stderr ?? ''}`)
|
|
55
|
+
return { code: res.status ?? 1, output }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function runSuite(cfg, suite, noRun) {
|
|
59
|
+
const cwd = path.resolve(cfg.root, suite.cwd ?? '.')
|
|
60
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'test-log-'))
|
|
61
|
+
const out = path.join(tmpDir, 'result.json')
|
|
62
|
+
const extra = (suite.args ?? []).join(' ')
|
|
63
|
+
const fill = (cmd) => cmd.replaceAll('{out}', JSON.stringify(out))
|
|
64
|
+
|
|
65
|
+
if (suite.runner === 'vitest' || suite.runner === 'jest') {
|
|
66
|
+
const cmd = suite.command
|
|
67
|
+
? fill(suite.command)
|
|
68
|
+
: suite.runner === 'vitest'
|
|
69
|
+
? `npx vitest run --reporter=json --outputFile=${JSON.stringify(out)} ${extra}`
|
|
70
|
+
: `npx jest --json --outputFile=${JSON.stringify(out)} ${extra}`
|
|
71
|
+
const { code, output } = run(cmd, cwd, suite.env)
|
|
72
|
+
if (!fs.existsSync(out)) return crashed(suite, code, output)
|
|
73
|
+
const tests = parseJestJson(JSON.parse(fs.readFileSync(out, 'utf8')), cfg.root)
|
|
74
|
+
return { tests, code, output: null }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (suite.runner === 'playwright') {
|
|
78
|
+
const cmd = suite.command ? fill(suite.command) : `npx playwright test --reporter=json ${extra}`
|
|
79
|
+
const { code, output } = run(cmd, cwd, { PLAYWRIGHT_JSON_OUTPUT_NAME: out, ...suite.env })
|
|
80
|
+
if (!fs.existsSync(out)) return crashed(suite, code, output)
|
|
81
|
+
const tests = parsePlaywrightJson(JSON.parse(fs.readFileSync(out, 'utf8')), cfg.root)
|
|
82
|
+
return { tests, code, output: null }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (suite.runner === 'junit') {
|
|
86
|
+
const report = path.resolve(cfg.root, suite.report)
|
|
87
|
+
let code = 0
|
|
88
|
+
let output = ''
|
|
89
|
+
if (!noRun) {
|
|
90
|
+
if (fs.existsSync(report)) fs.unlinkSync(report) // a stale report must not pass as this run's
|
|
91
|
+
;({ code, output } = run(suite.command, cwd, suite.env))
|
|
92
|
+
}
|
|
93
|
+
if (!fs.existsSync(report))
|
|
94
|
+
return crashed(suite, code || 1, output || `Rapporten ${suite.report} finns inte.`)
|
|
95
|
+
const base = path.resolve(cfg.root, suite.fileBase ?? '.')
|
|
96
|
+
const tests = parseJunitXml(fs.readFileSync(report, 'utf8'), cfg.root, base)
|
|
97
|
+
return { tests, code, output: null, reportTime: noRun ? fs.statSync(report).mtime : null }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (suite.runner === 'command') {
|
|
101
|
+
const t0 = Date.now()
|
|
102
|
+
const { code, output } = run(suite.command, cwd, suite.env)
|
|
103
|
+
return {
|
|
104
|
+
tests: [
|
|
105
|
+
{
|
|
106
|
+
file: '-',
|
|
107
|
+
titles: [suite.title ?? suite.command],
|
|
108
|
+
status: code === 0 ? 'passed' : 'failed',
|
|
109
|
+
ms: Date.now() - t0,
|
|
110
|
+
error: code === 0 ? '' : output,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
code,
|
|
114
|
+
output: null,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Okänd runner "${suite.runner}" i sviten ${suite.name}. Tillåtna: vitest, jest, playwright, junit, command.`,
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// The runner died before it wrote its result file: log the suite as one failure.
|
|
124
|
+
function crashed(suite, code, output) {
|
|
125
|
+
return {
|
|
126
|
+
tests: [
|
|
127
|
+
{
|
|
128
|
+
file: '-',
|
|
129
|
+
titles: [`(sviten ${suite.name} kunde inte köras)`],
|
|
130
|
+
status: 'failed',
|
|
131
|
+
ms: null,
|
|
132
|
+
error: output,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
code: code || 1,
|
|
136
|
+
output,
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Keeps the message and the stack frames in the repo's own code, with paths
|
|
141
|
+
// relative to the repo root.
|
|
142
|
+
function errorLines(error, root) {
|
|
143
|
+
if (!error) return []
|
|
144
|
+
const lines = stripAnsi(error)
|
|
145
|
+
.split('\n')
|
|
146
|
+
.filter((l) => l.trim() !== '')
|
|
147
|
+
.filter((l) => !/^\s*at .*(node_modules|node:internal|<anonymous>)/.test(l))
|
|
148
|
+
.map((l) => l.replaceAll(`file://${root}/`, '').replaceAll(`${root}/`, ''))
|
|
149
|
+
const cut = lines.slice(0, MAX_ERROR_LINES).map((l) => ` ${l}`)
|
|
150
|
+
if (lines.length > MAX_ERROR_LINES) cut.push(` … ${lines.length - MAX_ERROR_LINES} rader till`)
|
|
151
|
+
return cut
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function main() {
|
|
155
|
+
const argv = process.argv.slice(2)
|
|
156
|
+
const cfg = loadConfig(argv)
|
|
157
|
+
const si = argv.indexOf('--suite')
|
|
158
|
+
const only = si >= 0 ? argv[si + 1].split(',') : null
|
|
159
|
+
// --no-run: read the JUnit reports already on disk instead of running the
|
|
160
|
+
// suites. Only junit suites can do that; the others are left out.
|
|
161
|
+
const noRun = argv.includes('--no-run')
|
|
162
|
+
const suites = cfg.suites.filter(
|
|
163
|
+
(s) => (!only || only.includes(s.name)) && (!noRun || s.runner === 'junit'),
|
|
164
|
+
)
|
|
165
|
+
if (suites.length === 0) throw new Error(`Inga sviter att köra (--suite ${only}).`)
|
|
166
|
+
|
|
167
|
+
const started = new Date()
|
|
168
|
+
const body = []
|
|
169
|
+
const totals = { passed: 0, failed: 0, skipped: 0 }
|
|
170
|
+
let failedRun = false
|
|
171
|
+
|
|
172
|
+
for (const suite of suites) {
|
|
173
|
+
const { tests, code, reportTime } = runSuite(cfg, suite, noRun)
|
|
174
|
+
const from = reportTime ? `, from existing report ${stamp(reportTime).human}` : ''
|
|
175
|
+
body.push(`## svit ${suite.name} (${suite.runner}), exit ${code}${from}`)
|
|
176
|
+
for (const t of tests) {
|
|
177
|
+
totals[t.status] = (totals[t.status] ?? 0) + 1
|
|
178
|
+
const st = { passed: 'PASS', failed: 'FAIL', skipped: 'SKIP' }[t.status]
|
|
179
|
+
const ms = t.ms == null ? '' : `${Math.round(t.ms)} ms`
|
|
180
|
+
body.push(
|
|
181
|
+
[
|
|
182
|
+
st,
|
|
183
|
+
suite.name,
|
|
184
|
+
relFile(cfg.root, t.file === '-' ? null : t.file),
|
|
185
|
+
t.titles.join(SEP),
|
|
186
|
+
ms,
|
|
187
|
+
].join('\t'),
|
|
188
|
+
)
|
|
189
|
+
if (t.status === 'failed') body.push(...errorLines(t.error, cfg.root))
|
|
190
|
+
}
|
|
191
|
+
if (code !== 0 || tests.some((t) => t.status === 'failed')) failedRun = true
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const sha = git('rev-parse --short HEAD', cfg.root)
|
|
195
|
+
const dirty = git('status --porcelain', cfg.root)
|
|
196
|
+
const commit = sha ? `${sha}${dirty ? ' + uncommitted changes' : ''}` : '-'
|
|
197
|
+
const s = stamp(started)
|
|
198
|
+
const header = [
|
|
199
|
+
`# Testlogg ${s.human}`,
|
|
200
|
+
`# suites: ${suites.map((x) => x.name).join(', ')}${noRun ? ' (existing reports, not run)' : ''}`,
|
|
201
|
+
`# commit: ${commit}`,
|
|
202
|
+
`# result: ${totals.passed} passed, ${totals.failed} failed, ${totals.skipped} skipped`,
|
|
203
|
+
`# format: STATUS<TAB>suite<TAB>file<TAB>title${SEP}title<TAB>duration. Indented lines under FAIL are the error.`,
|
|
204
|
+
'',
|
|
205
|
+
]
|
|
206
|
+
|
|
207
|
+
fs.mkdirSync(cfg.logDir, { recursive: true })
|
|
208
|
+
const logFile = path.join(cfg.logDir, `${s.file}-test-log.txt`)
|
|
209
|
+
fs.writeFileSync(logFile, [...header, ...body, ''].join('\n'))
|
|
210
|
+
console.log(
|
|
211
|
+
`test-log: ${path.relative(process.cwd(), logFile)}: ${totals.passed} godkända, ${totals.failed} underkända, ${totals.skipped} överhoppade`,
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
writeSummary(cfg, { list: !argv.includes('--no-list') })
|
|
215
|
+
process.exit(failedRun ? 1 : 0)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
main()
|