-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.shared.ts
More file actions
79 lines (76 loc) · 3 KB
/
Copy pathvitest.shared.ts
File metadata and controls
79 lines (76 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import type { ViteUserConfig } from 'vitest/config'
/**
* Shared vitest configuration for AgentsKit packages.
*
* The `lines` threshold is the gate metric (simplest, most stable signal).
* Per-package thresholds are set at "current minus small buffer" to prevent
* silent regressions while not blocking PRs on aspirational targets.
*
* Aspirational target for the next 2 sprints: every package ≥ 80% lines.
* Sacred target (Manifesto principle 1): @agentskit/core ≥ 90% lines.
*
* To raise a threshold: write the tests, raise the number in the package's
* vitest.config.ts, ship the PR. CI will hold the new line.
*
* `criticalFiles` allows individual files (security-sensitive paths) to
* carry a tighter gate than the package-level default. Each entry is a
* vitest threshold-glob — see
* https://vitest.dev/config/#coverage-thresholds for the syntax.
*/
export interface PackageTestConfig {
/** Lines coverage threshold (percentage 0-100). Default: 60. */
linesThreshold?: number
/** Optional package-level thresholds for the other V8 metrics. */
statementsThreshold?: number
branchesThreshold?: number
functionsThreshold?: number
/** Test environment. Default: 'node'. React packages should use 'happy-dom'. */
environment?: 'node' | 'jsdom' | 'happy-dom'
/** Setup files to run before tests (relative to package root). */
setupFiles?: string[]
/** Per-test timeout for packages with process/UI integration tests. */
testTimeout?: number
/** Hook timeout for packages whose fixtures build or spawn consumers. */
hookTimeout?: number
/**
* Files that must be held to a higher coverage bar than the package
* default. Map of glob → required lines%. Use for security-critical
* surfaces (shell, filesystem, fetch-url, vault, sandbox, mcp client).
*/
criticalFiles?: Record<string, number>
}
export function createTestConfig(opts: PackageTestConfig = {}): ViteUserConfig {
const baseThresholds: Record<string, unknown> = {
lines: opts.linesThreshold ?? 90,
}
if (opts.statementsThreshold !== undefined) baseThresholds.statements = opts.statementsThreshold
if (opts.branchesThreshold !== undefined) baseThresholds.branches = opts.branchesThreshold
if (opts.functionsThreshold !== undefined) baseThresholds.functions = opts.functionsThreshold
if (opts.criticalFiles) {
for (const [pattern, lines] of Object.entries(opts.criticalFiles)) {
baseThresholds[pattern] = { lines }
}
}
return {
test: {
environment: opts.environment ?? 'node',
globals: true,
passWithNoTests: true,
setupFiles: opts.setupFiles,
testTimeout: opts.testTimeout,
hookTimeout: opts.hookTimeout,
coverage: {
provider: 'v8',
reporter: ['text', 'html', 'lcov', 'json-summary'],
include: ['src/**/*.{ts,tsx}'],
exclude: [
'src/**/*.{test,spec}.{ts,tsx}',
'src/**/*.d.ts',
'src/**/index.ts',
'src/**/__tests__/**',
],
thresholds: baseThresholds,
},
},
}
}