-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
140 lines (136 loc) · 6.44 KB
/
Copy pathvite.config.ts
File metadata and controls
140 lines (136 loc) · 6.44 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Root vitest config. Test imports of the published `@rotorsoft/*` packages
* resolve to **source** (not each package's built `dist/`) via
* `resolve.alias` — the vitest-recommended way to wire workspace deps to
* source (vitest-dev/vitest#5517). New in-tree packages become
* test-resolvable as soon as they land in the map — no `pnpm build`
* bootstrap dance.
*
* Why `resolve.alias` and not the native `resolve.tsconfigPaths` option:
* native tsconfig-paths *respects* each package's `exports` map, so subpath
* imports of an `exports`-bearing package (e.g. `@rotorsoft/act-http/hono`)
* resolve to `dist` while the bare package resolves to `src` — two copies
* of the framework load and vitest fails with "failed to find the current
* suite" (a dual-package hazard, vitest-dev/vitest#7465). `resolve.alias`
* takes precedence over `exports`, forcing uniform src resolution.
*
* The alias map is *derived* from the `paths` in `tsconfig.workspace.json` —
* the single source of truth, also consumed by `tsc --noEmit` — so the
* type-checker and the test runner can never drift. Those `paths` are
* themselves generated from each package's `exports` map by
* `scripts/derive-tsconfig-paths.mjs` (`pnpm paths:sync`; CI runs
* `pnpm paths:check`), so a new subpath export propagates here for free. That map also carries
* the private `@act/*` namespace (the in-repo example apps — calculator /
* server / client, not a published scope); no test imports those, but they
* ride along so one map serves both tools. vitest discovers this root config
* for sub-package invocations too (e.g. `pnpm -F @rotorsoft/act-pg exec
* vitest run ...`), so resolution is CWD-independent.
*/
import { createHash } from "node:crypto";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { configDefaults, defineConfig } from "vitest/config";
const root = import.meta.dirname;
// Derive vite aliases from the tsconfig path map. Each key becomes an
// anchored regex (so `@rotorsoft/act` doesn't prefix-match `@rotorsoft/act/x`)
// with `*` → a capture group; exact keys are ordered before wildcard keys so
// the specific mappings win.
const { compilerOptions } = JSON.parse(
readFileSync(resolve(root, "tsconfig.workspace.json"), "utf8")
) as { compilerOptions: { paths?: Record<string, string[]> } };
const paths = compilerOptions.paths ?? {};
const to_alias = ([key, [target]]: [string, string[]]) => ({
find: new RegExp(
`^${key.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "(.*)")}$`
),
replacement: resolve(root, target.replace(/\*/g, "$1")),
});
const alias = [
...Object.entries(paths)
.filter(([k]) => !k.includes("*"))
.map(to_alias),
...Object.entries(paths)
.filter(([k]) => k.includes("*"))
.map(to_alias),
];
export default defineConfig({
resolve: { alias },
test: {
globals: true,
// Agent worktrees under .claude/worktrees hold full checkouts of the
// repo; without this exclude, a bare `vitest run` discovers their
// spec copies too — duplicated suites and contention on shared
// resources (the docker postgres) make runs fail spuriously.
exclude: [...configDefaults.exclude, "**/.claude/**"],
// picocolors enables color emission when `CI` is set in env, which
// wraps act-diagram CLI output in ANSI escapes and breaks
// plain-text `toContain` assertions in format.spec/repl.spec. Force
// picocolors off in tests so output is deterministic across local
// and CI runs; `colors.spec.ts` mocks picocolors directly and is
// unaffected.
env: {
NO_COLOR: "1",
FORCE_COLOR: "0",
// Namespaces every Postgres schema the adapter suites create, to the
// checkout they were run from (#1589).
//
// The `.claude/**` exclude above stops ONE `vitest run` from also
// discovering a worktree's copy of the specs. It cannot help when two
// vitest processes run concurrently in different worktrees, which is
// the normal shape of parallel agent work: both target the docker
// Postgres on 5431, both use the same hardcoded schema names, and both
// `drop()`/`seed()` in `beforeAll` — so they delete each other's tables
// mid-run. Measured on an unmodified tree: 110 failures against a
// sibling, and a full run swinging between 135 and 322 on identical
// code. Results that vary with what else is running are not evidence.
//
// Derived from the config's own directory, so it is stable across runs
// of one checkout (schemas are reused, not accumulated per run) and
// necessarily different between worktrees. No configuration, nothing to
// remember, and CI — one checkout per job — is unaffected.
//
// Six hex characters, not more: the NOTIFY channel is
// `act_commit_<schema>_<table>` and Postgres caps identifiers at 63
// bytes, a budget the notify suites already spend most of. A collision
// between two worktrees is merely the status quo this fixes, so the
// width is chosen against the cap rather than against birthday odds.
ACT_TEST_SCHEMA_SUFFIX: createHash("sha256")
.update(root)
.digest("hex")
.slice(0, 6),
},
// Expose `globalThis.gc` to workers so the retention guarantee in
// `disposers.spec.ts` is enforced rather than skipped (#1441). A claim
// about releasing memory can only be checked by actually collecting;
// without this flag the case silently opts out on every run.
execArgv: ["--expose-gc"],
coverage: {
provider: "v8",
reporter: ["text", "lcov", "html", "json-summary"],
reportsDirectory: "./coverage",
include: ["libs/**/src/**/*.ts"],
exclude: [
"**/node_modules/**",
"packages/**",
"**/*.tsx",
"libs/act-diagram/src/server/**",
"libs/act-diagram/src/client/data/**",
"libs/act-diagram/src/client/components/**",
"libs/act-diagram/src/client/main.tsx",
"libs/act-diagram/src/client/types/protocol.ts",
"libs/act-diagram/src/client/types/file-tab.ts",
"libs/act-diagram/src/client/types/index.ts",
"libs/act-diagram/src/index.ts",
"libs/act-diagram/src/vite-env.d.ts",
],
// 100% on every metric is the merge gate (CLAUDE.md); the enforced
// thresholds must match the stated policy (#1112).
thresholds: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
},
});