@sssb/tools 0.0.0 → 0.2.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/LICENSE +21 -0
- package/bin/sssb.js +102 -0
- package/package.json +89 -5
- package/src/app-port.js +77 -0
- package/src/app.js +142 -0
- package/src/assembly-checks.d.ts +57 -0
- package/src/assembly-checks.js +259 -0
- package/src/commands/check-demo-size.js +80 -0
- package/src/commands/check-doc-paths.js +48 -0
- package/src/commands/check-e2e.js +611 -0
- package/src/commands/check-fences.js +51 -0
- package/src/commands/check-real-env.js +165 -0
- package/src/commands/check-tmpdir-leak.js +78 -0
- package/src/commands/ci.js +350 -0
- package/src/commands/dev-tick.js +25 -0
- package/src/commands/doctor-checks.js +1276 -0
- package/src/commands/doctor-vitest.js +262 -0
- package/src/commands/doctor.js +954 -0
- package/src/commands/e2e-profile.js +94 -0
- package/src/commands/guide.js +108 -0
- package/src/commands/launch-json.js +55 -0
- package/src/commands/port.js +22 -0
- package/src/commands/serve-standalone.js +78 -0
- package/src/commands/tick.js +27 -0
- package/src/doc-paths.d.ts +106 -0
- package/src/doc-paths.js +328 -0
- package/src/framework-guard.js +35 -0
- package/src/kit.d.ts +43 -0
- package/src/kit.js +205 -0
- package/src/next.d.ts +16 -0
- package/src/next.js +55 -0
- package/src/ports.d.ts +72 -0
- package/src/ports.js +306 -0
- package/src/prune-mantine-css.js +171 -0
- package/src/testing/tmp-dir-marker.js +9 -0
- package/src/testing/tmp-dir-setup.d.ts +2 -0
- package/src/testing/tmp-dir-setup.js +9 -0
- package/src/testing/tmp-dir.d.ts +20 -0
- package/src/testing/tmp-dir.js +174 -0
- package/src/tick/dev-tick.js +128 -0
- package/src/tick/tick.js +315 -0
- package/src/tick/ticker-marker.d.ts +17 -0
- package/src/tick/ticker-marker.js +83 -0
- package/src/tick/ticker.d.ts +36 -0
- package/src/tick/ticker.js +142 -0
- package/src/vite.d.ts +38 -0
- package/src/vite.js +64 -0
- package/src/vitest.d.ts +21 -0
- package/src/vitest.js +55 -0
- package/tsconfig.base.json +33 -0
- package/README.md +0 -3
|
@@ -0,0 +1,954 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// `sssb doctor [--app <dir>]`: the checks that a workspace's installed SSSB is the one it was built and tested as
|
|
3
|
+
// (ADR-0014 part 5), and that SSSB's conformance suite would actually run (part 3). ONE RUN CHECKS THE WHOLE
|
|
4
|
+
// WORKSPACE: it walks pnpm-workspace.yaml for every importer of @sssb/kit and every APP (in-repo, the apps the
|
|
5
|
+
// workspace's commands fan out over, `sssb.apps` or apps/*; otherwise every importer with a seam of its own,
|
|
6
|
+
// `src/app-config`), and gives each app the per-app checks, the one it runs for (`--app`, or the working directory)
|
|
7
|
+
// among them. WHERE IT STARTS: `--app <dir>`, or the working directory when it resolves @sssb/kit (an app, or an
|
|
8
|
+
// in-repo root), or, at the root of a workspace whose root takes no @sssb/kit (a generated workspace's), the
|
|
9
|
+
// workspace's first app; the walk then also has to reach every app the workspace names, so starting from the first
|
|
10
|
+
// finds what starting from any other would. It fails, naming every problem, on:
|
|
11
|
+
//
|
|
12
|
+
// - FIRST, and alone: a layout pnpm installed with a `nodeLinker` other than `isolated` (`pnp`, `hoisted`), or a
|
|
13
|
+
// `.pnp.cjs` at the root or in doctor's own NODE_OPTIONS, which the checks below are not built for, and under which
|
|
14
|
+
// (Plug'n'Play) Vitest's listing never finishes;
|
|
15
|
+
// - a workspace walk that cannot read pnpm-workspace.yaml, or that does not reach the app doctor runs for (or, when it
|
|
16
|
+
// chose its own start, any app the workspace names);
|
|
17
|
+
// - two copies of a singleton: a peer of @sssb/kit found from the kit's directory and from an app's must be ONE
|
|
18
|
+
// real directory (the `readlink -f` check build-notes tells a dependency PR to run by hand);
|
|
19
|
+
// - an importer of @sssb/kit, anywhere in the workspace, without its own seam: it must declare its
|
|
20
|
+
// `@sssb/app-config` link, and the instance it resolves must have that very seam linked (in-repo mode, where the
|
|
21
|
+
// seam goes through aliases instead, every tsconfig `paths` entry and every Vitest alias that would resolve the
|
|
22
|
+
// seam for an app must send it into that app's own);
|
|
23
|
+
// - an @sssb/* package an app resolves at another version than its @sssb/kit;
|
|
24
|
+
// - an app's port declaration (`"sssb": { "port": … }`) that is not valid, two apps that declare one port slot, or two
|
|
25
|
+
// custom slots with one default port: their dev servers and e2e runs would bind one port (portSlotProblems);
|
|
26
|
+
// - a check of the conformance suite that would not run, unless the app opted out of it by name in its own suite
|
|
27
|
+
// file: the MAIN unit run (the config a bare `vitest` would load for the app: the root's when it runs the app's
|
|
28
|
+
// `src/` tests, else the one Vitest finds walking up from the app, else Vitest's defaults there) must list every
|
|
29
|
+
// unit check from the app's own `src/sssb.conformance.test.ts`; some config that runs its `tests/contract/` files
|
|
30
|
+
// must list every contract check from them;
|
|
31
|
+
// - an app guide copy that is stale against the guide the kit ships (`sssb guide --check`), once the kit ships one;
|
|
32
|
+
// in-repo, only once the repository holds a copy (SSSB's own repo, where the kit's guide is the source).
|
|
33
|
+
//
|
|
34
|
+
// It REPORTS, without failing: every other Vitest config (`vitest*.config.*` at the root or in an app) that runs some of
|
|
35
|
+
// an app's `src/` tests but not its suite, or its `tests/contract/` files without listing every contract check, or that
|
|
36
|
+
// doctor cannot list (any of them CI might run instead); a bare `vitest` from the app's directory, when the root's is
|
|
37
|
+
// the main run, that would not run the app's suite (even one that runs none of its tests); each opt-out with its reason; the flags and file filters the root's and the apps'
|
|
38
|
+
// package.json scripts pass to vitest (doctor proves what each configuration would run, never what a CI step's own
|
|
39
|
+
// command line adds); which script runs each app's contract config (doctor lists the contract checks, it never runs
|
|
40
|
+
// them); `dedupePeerDependents: false` missing from pnpm-workspace.yaml (advice); framework cutover rows the
|
|
41
|
+
// workspace's checklist never mentions; and the commits the workspace pins SSSB's reusable workflow and the plugin's
|
|
42
|
+
// marketplace at (`.github/workflows/*.yml`, `.claude/settings.json`), against the release commit the installed
|
|
43
|
+
// @sssb/kit stamps into its package (`dist/release.json`), naming both commits where they differ.
|
|
44
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs'
|
|
45
|
+
import { createRequire } from 'node:module'
|
|
46
|
+
import path from 'node:path'
|
|
47
|
+
import { readJson, takeAppDir, UsageError, workspaceApps, workspaceRootOf } from '../app.js'
|
|
48
|
+
import { kitDirOf, kitVersionOf, resolveAppsKit } from '../kit.js'
|
|
49
|
+
import {
|
|
50
|
+
aliasProblems,
|
|
51
|
+
areaOf,
|
|
52
|
+
cutoverReport,
|
|
53
|
+
discoverWorkspace,
|
|
54
|
+
githubRepositoryOf,
|
|
55
|
+
importerSeamProblems,
|
|
56
|
+
kitPeers,
|
|
57
|
+
missingTests,
|
|
58
|
+
nodeLinkerProblem,
|
|
59
|
+
ownTests,
|
|
60
|
+
packageDirFrom,
|
|
61
|
+
parseWorkspaceYaml,
|
|
62
|
+
pinReport,
|
|
63
|
+
portSlotProblems,
|
|
64
|
+
PROBE,
|
|
65
|
+
realish,
|
|
66
|
+
singletonProblems,
|
|
67
|
+
sssbPackagesOf,
|
|
68
|
+
versionProblems,
|
|
69
|
+
vitestInvocations,
|
|
70
|
+
} from './doctor-checks.js'
|
|
71
|
+
import {
|
|
72
|
+
projectsRunning,
|
|
73
|
+
runKey,
|
|
74
|
+
seamAliases,
|
|
75
|
+
vitestDefaultConfig,
|
|
76
|
+
vitestList,
|
|
77
|
+
vitestRunsFor,
|
|
78
|
+
} from './doctor-vitest.js'
|
|
79
|
+
|
|
80
|
+
const SEAM = '@sssb/app-config'
|
|
81
|
+
const RUNNERS = /** @type {const} */ (['unit', 'contract'])
|
|
82
|
+
|
|
83
|
+
/** @typedef {{ status: 'ok' | 'FAIL' | 'report' | 'advice', title: string, lines?: string[] }} Result */
|
|
84
|
+
/** @typedef {ReturnType<typeof discoverWorkspace>} Workspace */
|
|
85
|
+
/** @typedef {import('./doctor-vitest.js').VitestRun} VitestRun */
|
|
86
|
+
/** @typedef {import('./doctor-checks.js').SeamRoute} SeamRoute */
|
|
87
|
+
/** @typedef {Map<string, ReturnType<typeof vitestList>>} VitestCache each `vitest list`, by cwd, config and selection */
|
|
88
|
+
/** @typedef {{ run: VitestRun, projects: string[] }} Selected a Vitest run, and the projects in it to list (none: all) */
|
|
89
|
+
/**
|
|
90
|
+
* @typedef {object} Plan which runs hold an app to which checks (planFor)
|
|
91
|
+
* @property {Selected | null} main the MAIN unit run: the first run a bare `vitest` would make for the app that runs
|
|
92
|
+
* any of its `src/` test files
|
|
93
|
+
* @property {VitestRun[]} tried the bare runs tried for it, in order
|
|
94
|
+
* @property {string[]} mainErrors a bare run doctor could not list before it found the main one
|
|
95
|
+
* @property {{ run: VitestRun, files: number, bare: boolean }[]} partial other configs that run some of the app's
|
|
96
|
+
* `src/` test files and not its `src/sssb.conformance.test.ts`, and the bare runs past the main one (`bare`) that do
|
|
97
|
+
* not run it, even running none of those files
|
|
98
|
+
* @property {Selected[]} contract every config that runs any of the app's `tests/contract/` files
|
|
99
|
+
* @property {{ run: VitestRun, error: string }[]} unlisted other configs doctor could not list
|
|
100
|
+
* @property {string[]} nested the workspace packages inside the app, whose files are not the app's
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The app doctor runs for, and whether it was chosen for the person. Doctor checks the whole workspace from any of its
|
|
105
|
+
* apps, so the short form has to work where people type it, the root: with no `--app`, a working directory that
|
|
106
|
+
* resolves `@sssb/kit` is the app (as before), and a workspace root that does not (a generated workspace's root takes
|
|
107
|
+
* no framework) starts from the workspace's first app.
|
|
108
|
+
* @param {string[]} args
|
|
109
|
+
* @param {string} [cwd]
|
|
110
|
+
* @returns {{ dir: string, defaulted: boolean, named: string[] }} `named`: when doctor chose the app, every app the
|
|
111
|
+
* workspace names (absolute), which the walk must all reach: the person did not name one to hold it to
|
|
112
|
+
*/
|
|
113
|
+
export function doctorApp(args, cwd = process.cwd()) {
|
|
114
|
+
if (args.includes('--app')) return { dir: takeAppDir(args, cwd), defaulted: false, named: [] }
|
|
115
|
+
const here = path.resolve(cwd)
|
|
116
|
+
if (existsSync(path.join(here, 'package.json')) && packageDirFrom(here, '@sssb/kit') !== null) {
|
|
117
|
+
return { dir: here, defaulted: false, named: [] }
|
|
118
|
+
}
|
|
119
|
+
if (existsSync(path.join(here, 'pnpm-workspace.yaml')) && existsSync(path.join(here, 'package.json'))) {
|
|
120
|
+
const apps = workspaceApps(here)
|
|
121
|
+
if (apps.length === 0) {
|
|
122
|
+
throw new UsageError(
|
|
123
|
+
`sssb doctor: ${here} is a workspace root that takes no @sssb/kit and has no apps (\`sssb.apps\` in its ` +
|
|
124
|
+
'package.json, or apps/<name>): pass --app <dir>',
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
return { dir: path.resolve(here, apps[0]), defaulted: true, named: apps.map((a) => path.resolve(here, a)) }
|
|
128
|
+
}
|
|
129
|
+
// Neither: the usual refusal, which says to run from an app or pass --app.
|
|
130
|
+
return { dir: takeAppDir(args, cwd), defaulted: false, named: [] }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** @param {string[]} args */
|
|
134
|
+
export async function run(args) {
|
|
135
|
+
const chosen = doctorApp(args)
|
|
136
|
+
const appDir = realpathSync(chosen.dir)
|
|
137
|
+
if (args.length > 0) throw new UsageError(`sssb doctor: unknown argument ${args[0]} (usage: doctor [--app <dir>])`)
|
|
138
|
+
const root = realpathSync(workspaceRootOf(appDir))
|
|
139
|
+
const rel = relativeTo(root)
|
|
140
|
+
// Said before anything can fail on the app it chose, so a failure there is read with the reason it was picked.
|
|
141
|
+
if (chosen.defaulted) {
|
|
142
|
+
console.log(
|
|
143
|
+
`sssb doctor: no --app, and the working directory (${root}) takes no @sssb/kit: starting from ${rel(appDir)}. One run checks every app of the workspace.`,
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
// First: under another layout nothing below holds, and under Plug'n'Play (`.pnp.cjs` in NODE_OPTIONS) Vitest's
|
|
147
|
+
// listing never finishes until the limit stops it.
|
|
148
|
+
const layout = nodeLinkerProblem(root)
|
|
149
|
+
if (layout !== null) {
|
|
150
|
+
console.log(`sssb doctor: ${rel(appDir)}`)
|
|
151
|
+
return print([{ status: 'FAIL', title: `installed layout: ${layout}. Nothing else is checked until it is` }])
|
|
152
|
+
}
|
|
153
|
+
const kitDir = kitDirOf(appDir)
|
|
154
|
+
const version = kitVersionOf(appDir)
|
|
155
|
+
const heading = `sssb doctor: ${rel(appDir)}, @sssb/kit ${version} at ${rel(kitDir)}`
|
|
156
|
+
|
|
157
|
+
/** @type {Workspace} */
|
|
158
|
+
let workspace
|
|
159
|
+
try {
|
|
160
|
+
workspace = discoverWorkspace(root, kitDir)
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (!(error instanceof UsageError)) throw error
|
|
163
|
+
console.log(heading)
|
|
164
|
+
return print([
|
|
165
|
+
{
|
|
166
|
+
status: 'FAIL',
|
|
167
|
+
title: `workspace walk: ${error.message.replace(/^sssb: /, '')}. Nothing else is checked until doctor can walk the workspace`,
|
|
168
|
+
},
|
|
169
|
+
])
|
|
170
|
+
}
|
|
171
|
+
const { inRepo, apps } = workspace
|
|
172
|
+
console.log(
|
|
173
|
+
heading +
|
|
174
|
+
(inRepo
|
|
175
|
+
? ' (in-repo mode: the kit is a package of this workspace, so the seam goes through aliases, not a link)'
|
|
176
|
+
: ''),
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
/** @type {VitestCache} */
|
|
180
|
+
const cache = new Map()
|
|
181
|
+
/** @type {Map<string, Plan>} */
|
|
182
|
+
const plans = new Map()
|
|
183
|
+
for (const app of apps) plans.set(app, planFor(root, app, nestedIn(workspace.packages, app), cache))
|
|
184
|
+
const targets = [...new Set([appDir, ...apps])]
|
|
185
|
+
|
|
186
|
+
/** @type {Result[]} */
|
|
187
|
+
const results = [
|
|
188
|
+
walk(
|
|
189
|
+
root,
|
|
190
|
+
appDir,
|
|
191
|
+
workspace,
|
|
192
|
+
chosen.named.map((dir) => realpathSync(dir)),
|
|
193
|
+
),
|
|
194
|
+
...targets.map((target) => singletons(root, target)),
|
|
195
|
+
inRepo ? await inRepoAliases(root, workspace, plans) : importers(root, workspace),
|
|
196
|
+
...targets.map((target) => versions(root, target)),
|
|
197
|
+
portSlots(root, apps),
|
|
198
|
+
...apps.flatMap((app) => RUNNERS.flatMap((runner) => conformance(root, app, runner, plans, cache))),
|
|
199
|
+
...commandLines(root, appDir, apps, plans),
|
|
200
|
+
...(await guides(root, apps, inRepo)),
|
|
201
|
+
pins(root, kitDir, version, inRepo),
|
|
202
|
+
dedupeAdvice(root, inRepo),
|
|
203
|
+
cutover(root, appDir),
|
|
204
|
+
]
|
|
205
|
+
return print(results)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** @param {string} root */
|
|
209
|
+
const relativeTo = (root) => (/** @type {string} */ dir) => path.relative(root, dir) || '(the workspace root)'
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @param {Result[]} results
|
|
213
|
+
* @returns {number} the exit code
|
|
214
|
+
*/
|
|
215
|
+
function print(results) {
|
|
216
|
+
let problems = 0
|
|
217
|
+
for (const { status, title, lines = [] } of results) {
|
|
218
|
+
console.log(`${status.padEnd(7)} ${title}`)
|
|
219
|
+
for (const line of lines) console.log(` ${status === 'FAIL' ? '- ' : ''}${line}`)
|
|
220
|
+
if (status === 'FAIL') problems += Math.max(lines.length, 1)
|
|
221
|
+
}
|
|
222
|
+
console.log(problems === 0 ? 'sssb doctor: ok' : `sssb doctor: ${problems} problem(s)`)
|
|
223
|
+
return problems === 0 ? 0 : 1
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @param {string} title
|
|
228
|
+
* @param {string[]} problems
|
|
229
|
+
* @param {string[]} [notes]
|
|
230
|
+
* @returns {Result}
|
|
231
|
+
*/
|
|
232
|
+
const verdict = (title, problems, notes = []) =>
|
|
233
|
+
problems.length > 0 ? { status: 'FAIL', title, lines: problems } : { status: 'ok', title, lines: notes }
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The workspace packages strictly inside `app` (a root-level app's apps/*), real paths. The app's own seam,
|
|
237
|
+
* `src/app-config`, is a workspace package too (so pnpm keeps it linked), but its files, tests included, are the app's.
|
|
238
|
+
* @param {readonly string[]} packages
|
|
239
|
+
* @param {string} app
|
|
240
|
+
*/
|
|
241
|
+
const nestedIn = (packages, app) =>
|
|
242
|
+
packages
|
|
243
|
+
.map((dir) => realpathSync(dir))
|
|
244
|
+
.filter((dir) => dir !== app && dir.startsWith(app + path.sep) && dir !== path.join(app, 'src', 'app-config'))
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* PORT SLOTS: each app of the workspace binds a port of its own (see portSlotProblems).
|
|
248
|
+
* @param {string} root
|
|
249
|
+
* @param {readonly string[]} apps
|
|
250
|
+
* @returns {Result}
|
|
251
|
+
*/
|
|
252
|
+
function portSlots(root, apps) {
|
|
253
|
+
const { problems, slots } = portSlotProblems(root, apps)
|
|
254
|
+
return verdict('port slots: no two apps bind one port', problems, slots)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* THE WALK REACHES THE APP: what every workspace-wide check below covers is what the walk found, so an app it missed
|
|
259
|
+
* (a pnpm-workspace.yaml glob that does not cover it, a manifest that does not declare @sssb/kit) would pass every
|
|
260
|
+
* one of them unexamined. Doctor's own app must be among the importers, and, when it has a seam, among the apps.
|
|
261
|
+
* @param {string} root
|
|
262
|
+
* @param {string} appDir
|
|
263
|
+
* @param {Workspace} workspace
|
|
264
|
+
* @param {string[]} [named] the apps the workspace names, when doctor chose its own start: each must be reached too,
|
|
265
|
+
* or the bare form would pass a workspace whose walk drops an app that `--app <it>` would fail
|
|
266
|
+
* @returns {Result}
|
|
267
|
+
*/
|
|
268
|
+
function walk(root, appDir, workspace, named = []) {
|
|
269
|
+
const rel = relativeTo(root)
|
|
270
|
+
const importerDirs = workspace.importers.map(({ dir }) => dir)
|
|
271
|
+
const importers = importerDirs.map(rel).join(', ') || 'none'
|
|
272
|
+
const apps = workspace.apps.map(rel).join(', ') || 'none'
|
|
273
|
+
/** @type {string[]} */
|
|
274
|
+
const problems = []
|
|
275
|
+
if (!importerDirs.includes(appDir))
|
|
276
|
+
problems.push(
|
|
277
|
+
`${rel(appDir)} is not among the importers of @sssb/kit the walk found (${importers}): check pnpm-workspace.yaml's ` +
|
|
278
|
+
`packages globs, and that ${rel(appDir)}'s package.json declares @sssb/kit`,
|
|
279
|
+
)
|
|
280
|
+
if (existsSync(path.join(appDir, 'src', 'app-config')) && !workspace.apps.includes(appDir))
|
|
281
|
+
problems.push(
|
|
282
|
+
`${rel(appDir)} has a seam (src/app-config) but is not among the apps the walk found (${apps})` +
|
|
283
|
+
(workspace.inRepo ? ": in-repo, the apps are the root package.json's sssb.apps, or apps/*" : ''),
|
|
284
|
+
)
|
|
285
|
+
/** @type {string[]} */
|
|
286
|
+
const unreached = []
|
|
287
|
+
for (const dir of named) {
|
|
288
|
+
if (dir === appDir) continue
|
|
289
|
+
if (!importerDirs.includes(dir) || !workspace.apps.includes(dir)) {
|
|
290
|
+
unreached.push(
|
|
291
|
+
`${rel(dir)} is named by the workspace (\`sssb.apps\`, or apps/*) but the walk does not reach it as an app that ` +
|
|
292
|
+
`takes @sssb/kit (importers: ${importers}; apps: ${apps}): check pnpm-workspace.yaml's packages globs, and that ` +
|
|
293
|
+
`${rel(dir)}'s package.json declares @sssb/kit`,
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (problems.length === 0 && unreached.length > 0) {
|
|
298
|
+
return {
|
|
299
|
+
status: 'FAIL',
|
|
300
|
+
title: 'workspace walk: it does not reach every app the workspace names, so the checks below do not cover them',
|
|
301
|
+
lines: unreached,
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return problems.length > 0
|
|
305
|
+
? {
|
|
306
|
+
status: 'FAIL',
|
|
307
|
+
title: `workspace walk: it does not reach ${rel(appDir)}, the app doctor runs for, so the checks below do not cover it`,
|
|
308
|
+
lines: [...problems, ...unreached],
|
|
309
|
+
}
|
|
310
|
+
: {
|
|
311
|
+
status: 'ok',
|
|
312
|
+
title: `workspace walk: ${workspace.packages.length} package(s) from pnpm-workspace.yaml; importers of @sssb/kit: ${importers}; apps: ${apps}`,
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @param {string} root
|
|
318
|
+
* @param {string} target
|
|
319
|
+
* @returns {Result}
|
|
320
|
+
*/
|
|
321
|
+
function singletons(root, target) {
|
|
322
|
+
const name = relativeTo(root)(target)
|
|
323
|
+
let kitDir
|
|
324
|
+
try {
|
|
325
|
+
kitDir = kitDirOf(target)
|
|
326
|
+
} catch (error) {
|
|
327
|
+
return { status: 'FAIL', title: `${name}: one copy of each singleton`, lines: [messageOf(error)] }
|
|
328
|
+
}
|
|
329
|
+
const { peers, optional } = kitPeers(kitDir)
|
|
330
|
+
const { problems, notes, same } = singletonProblems({
|
|
331
|
+
peers,
|
|
332
|
+
optional,
|
|
333
|
+
fromKit: (peer) => packageDirFrom(/** @type {string} */ (kitDir), peer),
|
|
334
|
+
fromApp: (peer) => packageDirFrom(target, peer),
|
|
335
|
+
})
|
|
336
|
+
return verdict(
|
|
337
|
+
problems.length > 0
|
|
338
|
+
? `${name}: one copy of each singleton: it and its @sssb/kit do not share every peer`
|
|
339
|
+
: `${name}: one copy of each singleton: ${same.join(', ') || 'no peer'}`,
|
|
340
|
+
problems,
|
|
341
|
+
notes,
|
|
342
|
+
)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** @param {unknown} error */
|
|
346
|
+
const messageOf = (error) => (error instanceof Error ? error.message : String(error))
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* @param {string} root
|
|
350
|
+
* @param {Workspace} workspace
|
|
351
|
+
* @returns {Result}
|
|
352
|
+
*/
|
|
353
|
+
function importers(root, workspace) {
|
|
354
|
+
const { problems, importers: found } = importerSeamProblems(root, kitDirOf, workspace.importers, workspace.packages)
|
|
355
|
+
return verdict(
|
|
356
|
+
problems.length > 0
|
|
357
|
+
? 'one SSSB per importer, with its own seam: an importer of @sssb/kit runs on a seam not its own'
|
|
358
|
+
: `one SSSB per importer, with its own seam: ${found.join(', ') || 'no importer'}`,
|
|
359
|
+
problems,
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* In-repo mode's check, over every app of the workspace: every tsconfig `paths` entry, and every alias of every Vitest
|
|
365
|
+
* project that holds the app to checks (its main unit run's, and every contract config's), that would resolve the seam
|
|
366
|
+
* sends it into the app's own.
|
|
367
|
+
* @param {string} root
|
|
368
|
+
* @param {Workspace} workspace
|
|
369
|
+
* @param {Map<string, Plan>} plans
|
|
370
|
+
* @returns {Promise<Result>}
|
|
371
|
+
*/
|
|
372
|
+
async function inRepoAliases(root, workspace, plans) {
|
|
373
|
+
/** Paths shown relative to the workspace root (so equal real paths stay equal); a bare specifier as it is. */
|
|
374
|
+
const shown = (/** @type {string} */ file) => (path.isAbsolute(file) ? path.relative(root, file) || '.' : file)
|
|
375
|
+
const show = (/** @type {SeamRoute} */ route) => ({
|
|
376
|
+
find: route.find,
|
|
377
|
+
to: shown(route.to),
|
|
378
|
+
resolved: route.resolved.map(shown),
|
|
379
|
+
})
|
|
380
|
+
/** @type {Parameters<typeof aliasProblems>[0]} */
|
|
381
|
+
const apps = []
|
|
382
|
+
for (const appDir of workspace.apps) {
|
|
383
|
+
const plan = /** @type {Plan} */ (plans.get(appDir))
|
|
384
|
+
const own = realish(path.join(appDir, 'src', 'app-config'))
|
|
385
|
+
/** @type {Parameters<typeof aliasProblems>[0][number]['projects']} */
|
|
386
|
+
const projects = []
|
|
387
|
+
const seen = new Set()
|
|
388
|
+
for (const { run, projects: names } of [...(plan.main ? [plan.main] : []), ...plan.contract]) {
|
|
389
|
+
const key = `${run.cwd}\0${run.config ?? ''}\0${names.join('\0')}`
|
|
390
|
+
if (seen.has(key)) continue
|
|
391
|
+
seen.add(key)
|
|
392
|
+
const config = configName(root, run)
|
|
393
|
+
for (const [project, routes] of await seamAliases(run, names, own))
|
|
394
|
+
projects.push({ config, project, routes: routes.map(show) })
|
|
395
|
+
}
|
|
396
|
+
apps.push({
|
|
397
|
+
app: relativeTo(root)(appDir),
|
|
398
|
+
own: shown(own),
|
|
399
|
+
tsconfig: tsconfigRoutes(appDir).map(show),
|
|
400
|
+
projects,
|
|
401
|
+
})
|
|
402
|
+
}
|
|
403
|
+
const problems = aliasProblems(apps)
|
|
404
|
+
// The other importers have no seam of their own to alias: in-repo, each is compiled within a program that names one
|
|
405
|
+
// (the root's is the framework's own, on its test fixture; the showcase's seed is compiled within the showcase).
|
|
406
|
+
const others = workspace.importers
|
|
407
|
+
.map(({ dir }) => dir)
|
|
408
|
+
.filter((dir) => !workspace.apps.includes(dir))
|
|
409
|
+
.map(relativeTo(root))
|
|
410
|
+
return verdict(
|
|
411
|
+
problems.length > 0
|
|
412
|
+
? "in-repo mode: an app's aliases send @sssb/app-config somewhere other than its own src/app-config"
|
|
413
|
+
: `in-repo mode: each app's tsconfig and Vitest projects alias @sssb/app-config to its own src/app-config: ${apps
|
|
414
|
+
.map((a) => `${a.app} (${a.projects.map((p) => `${p.config}:${p.project}`).join(', ')})`)
|
|
415
|
+
.join('; ')}`,
|
|
416
|
+
problems,
|
|
417
|
+
others.length
|
|
418
|
+
? [
|
|
419
|
+
`not apps, so not alias-checked: ${others.join(', ')} (no seam of their own; each compiles within a program that names one)`,
|
|
420
|
+
]
|
|
421
|
+
: [],
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Every place the app's tsconfig sends the seam, as TypeScript itself reads the file (its `extends` and `baseUrl`
|
|
427
|
+
* honoured), through the compiler the app installs: each target of each `paths` key that is or starts with
|
|
428
|
+
* `@sssb/app-config`, with where a subpath lands through it (a `*` filled in with a probe name). Empty when it maps no
|
|
429
|
+
* such path.
|
|
430
|
+
* @param {string} appDir
|
|
431
|
+
* @returns {SeamRoute[]}
|
|
432
|
+
*/
|
|
433
|
+
function tsconfigRoutes(appDir) {
|
|
434
|
+
const file = path.join(appDir, 'tsconfig.json')
|
|
435
|
+
if (!existsSync(file)) return []
|
|
436
|
+
/** @type {typeof import('typescript')} */
|
|
437
|
+
let ts
|
|
438
|
+
try {
|
|
439
|
+
ts = createRequire(path.join(appDir, 'package.json'))('typescript')
|
|
440
|
+
} catch (error) {
|
|
441
|
+
throw new UsageError(`sssb doctor: ${appDir} does not resolve \`typescript\`, which reads its tsconfig`, {
|
|
442
|
+
cause: error,
|
|
443
|
+
})
|
|
444
|
+
}
|
|
445
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(
|
|
446
|
+
file,
|
|
447
|
+
{},
|
|
448
|
+
{
|
|
449
|
+
...ts.sys,
|
|
450
|
+
onUnRecoverableConfigFileDiagnostic: () => {},
|
|
451
|
+
},
|
|
452
|
+
)
|
|
453
|
+
if (!parsed) return []
|
|
454
|
+
const options = /** @type {{ baseUrl?: string, pathsBasePath?: string }} */ (parsed.options)
|
|
455
|
+
const base = options.baseUrl ?? options.pathsBasePath ?? appDir
|
|
456
|
+
/** @type {SeamRoute[]} */
|
|
457
|
+
const routes = []
|
|
458
|
+
for (const [key, targets] of Object.entries(parsed.options.paths ?? {})) {
|
|
459
|
+
if (!key.startsWith(SEAM)) continue
|
|
460
|
+
for (const target of targets) {
|
|
461
|
+
const to = path.resolve(base, target)
|
|
462
|
+
// The FIRST `*` in the target takes the matched text and any later one stays literal, exactly as
|
|
463
|
+
// TypeScript's resolver substitutes it (`replaceFirstStar`). TypeScript rejects a second `*` only when it
|
|
464
|
+
// builds a program (TS5062), so the parsed config doctor reads still carries such a target, and doctor must
|
|
465
|
+
// follow it where TypeScript would.
|
|
466
|
+
const star = to.indexOf('*')
|
|
467
|
+
const probed = key.includes('*') && star >= 0 ? `${to.slice(0, star)}${PROBE}${to.slice(star + 1)}` : to
|
|
468
|
+
routes.push({ find: key, to, resolved: [realish(probed)] })
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return routes
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* @param {string} root
|
|
476
|
+
* @param {string} target
|
|
477
|
+
* @returns {Result}
|
|
478
|
+
*/
|
|
479
|
+
function versions(root, target) {
|
|
480
|
+
const name = relativeTo(root)(target)
|
|
481
|
+
const packages = sssbPackagesOf(target)
|
|
482
|
+
const problems = versionProblems(packages)
|
|
483
|
+
return verdict(
|
|
484
|
+
problems.length > 0
|
|
485
|
+
? `${name}: versions in step: an @sssb package is not the version of @sssb/kit`
|
|
486
|
+
: `${name}: versions in step: ${[...packages].map(([pkg, v]) => `${pkg} ${v}`).join(', ')}`,
|
|
487
|
+
problems,
|
|
488
|
+
)
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* How a run is named in doctor's output.
|
|
493
|
+
* @param {string} root
|
|
494
|
+
* @param {VitestRun} run
|
|
495
|
+
*/
|
|
496
|
+
const configName = (root, run) =>
|
|
497
|
+
run.config
|
|
498
|
+
? path.relative(root, run.config) +
|
|
499
|
+
(path.dirname(run.config) === run.cwd ? '' : ` from ${relativeTo(root)(run.cwd)}`)
|
|
500
|
+
: `Vitest's defaults from ${relativeTo(root)(run.cwd)}`
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* How a `vitest list` is named in doctor's output: where it runs, the config, the projects selected.
|
|
504
|
+
* @param {string} root
|
|
505
|
+
* @param {Selected} selected
|
|
506
|
+
*/
|
|
507
|
+
const listName = (root, { run, projects }) =>
|
|
508
|
+
`vitest list from ${run.cwd === root ? 'the workspace root' : path.relative(root, run.cwd)}` +
|
|
509
|
+
(run.config ? ` --config ${path.relative(run.cwd, run.config)}` : ", Vitest's defaults") +
|
|
510
|
+
(projects.length ? `, project ${projects.join(', ')}` : '')
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* A `vitest list`, once per run and selection.
|
|
514
|
+
* @param {VitestRun} run
|
|
515
|
+
* @param {{ filesOnly?: boolean, projects?: readonly string[] }} options
|
|
516
|
+
* @param {VitestCache} cache
|
|
517
|
+
*/
|
|
518
|
+
function listOnce(run, options, cache) {
|
|
519
|
+
const key = [run.cwd, run.config ?? '', options.filesOnly ? 'files' : 'tests', ...(options.projects ?? [])].join(
|
|
520
|
+
'\0',
|
|
521
|
+
)
|
|
522
|
+
// After one listing ran out of time, the rest are not waited on: each would likely hang the same way, and the
|
|
523
|
+
// limit is per listing, so one app's configs could each spend it.
|
|
524
|
+
const listed = cache.get(key) ?? cache.get(STOPPED) ?? vitestList(run, options)
|
|
525
|
+
cache.set(key, listed)
|
|
526
|
+
if (!listed.ok && listed.timedOut && !cache.has(STOPPED)) {
|
|
527
|
+
cache.set(STOPPED, {
|
|
528
|
+
ok: false,
|
|
529
|
+
timedOut: true,
|
|
530
|
+
error: `not listed, since an earlier listing ran out of time (${listed.error})`,
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
return listed
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** The cache key of the error every listing after one that ran out of time returns. */
|
|
537
|
+
const STOPPED = '\0stopped'
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* WHICH RUNS HOLD AN APP TO WHICH CHECKS, found with `vitest list --filesOnly` alone (it loads each config and globs
|
|
541
|
+
* its files; it runs no globalSetup and collects no test file):
|
|
542
|
+
*
|
|
543
|
+
* - the MAIN unit run: the first of the runs a bare `vitest` would make for the app (vitestRunsFor's `bare`) that
|
|
544
|
+
* runs any of its `src/` test files, with the projects that run them selected. It must list every unit check. A
|
|
545
|
+
* bare run doctor cannot list stops the search (doctor cannot tell whether that one is the main run);
|
|
546
|
+
* - every OTHER config (root's and app's) that runs some of its `src/` test files but not its
|
|
547
|
+
* `src/sssb.conformance.test.ts`, and every bare run past the main one (the app directory's, when the root's is
|
|
548
|
+
* main) that does not run that file, even one that runs none of them: reported, since CI might run it instead of
|
|
549
|
+
* the main one;
|
|
550
|
+
* - every config (the main run's too) that runs any of its `tests/contract/` files: one of them must list every
|
|
551
|
+
* contract check (Vitest's defaults are no contract config);
|
|
552
|
+
* - every other config doctor cannot list: reported.
|
|
553
|
+
*
|
|
554
|
+
* Only the main run and the contract configs are then listed in full (conformance), which loads their globalSetup.
|
|
555
|
+
* @param {string} root
|
|
556
|
+
* @param {string} app
|
|
557
|
+
* @param {string[]} nested the workspace packages inside the app, whose files are not the app's
|
|
558
|
+
* @param {VitestCache} cache
|
|
559
|
+
* @returns {Plan}
|
|
560
|
+
*/
|
|
561
|
+
function planFor(root, app, nested, cache) {
|
|
562
|
+
/** @type {Plan} */
|
|
563
|
+
const plan = { main: null, tried: [], mainErrors: [], partial: [], contract: [], unlisted: [], nested }
|
|
564
|
+
const { bare, configs } = vitestRunsFor(root, app)
|
|
565
|
+
const filesOf = (/** @type {VitestRun} */ run) => listOnce(run, { filesOnly: true }, cache)
|
|
566
|
+
/** @param {import('./doctor-vitest.js').ListedFile[]} listed @param {'unit' | 'contract'} area */
|
|
567
|
+
const inArea = (listed, area) => listed.filter((entry) => areaOf(entry.file, app, nested) === area)
|
|
568
|
+
/** @param {import('./doctor-vitest.js').ListedFile[]} listed */
|
|
569
|
+
const select = (listed) => {
|
|
570
|
+
const projects = projectsRunning(listed, app)
|
|
571
|
+
return projects.includes('') ? [] : projects
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
for (const run of bare) {
|
|
575
|
+
plan.tried.push(run)
|
|
576
|
+
const files = filesOf(run)
|
|
577
|
+
if (!files.ok) {
|
|
578
|
+
plan.mainErrors.push(`${configName(root, run)}: ${files.error}`)
|
|
579
|
+
break
|
|
580
|
+
}
|
|
581
|
+
const unit = inArea(files.listed, 'unit')
|
|
582
|
+
if (unit.length > 0) {
|
|
583
|
+
plan.main = { run, projects: select(unit) }
|
|
584
|
+
break
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const main = plan.main?.run
|
|
589
|
+
const tried = new Set(plan.tried.map(runKey))
|
|
590
|
+
// The bare runs past the main one (the root's was main: a bare `vitest` from the app's directory, as the app's own
|
|
591
|
+
// scripts and a `pnpm -r` run it). Each is held to the unit area like any other config, and reported even when it
|
|
592
|
+
// runs NONE of the app's src/ files: a config whose globs reach the app only from the root finds nothing there,
|
|
593
|
+
// and passes when it sets `passWithNoTests`. One that is not also a config file run from its own directory (the
|
|
594
|
+
// root's config, run from the app) is only reported: it never joins the contract configs, which are listed in full.
|
|
595
|
+
const untried = new Set(bare.filter((run) => !tried.has(runKey(run))).map(runKey))
|
|
596
|
+
const isConfig = (/** @type {VitestRun} */ run) => configs.some((r) => runKey(r) === runKey(run))
|
|
597
|
+
const suite = path.join(app, 'src', 'sssb.conformance.test.ts')
|
|
598
|
+
const runs = [
|
|
599
|
+
...configs,
|
|
600
|
+
...(main?.config && !isConfig(main) ? [main] : []),
|
|
601
|
+
...bare.filter((run) => untried.has(runKey(run)) && !isConfig(run)),
|
|
602
|
+
]
|
|
603
|
+
for (const run of runs) {
|
|
604
|
+
const isMain = main !== undefined && runKey(run) === runKey(main)
|
|
605
|
+
const isBare = untried.has(runKey(run))
|
|
606
|
+
const reportOnly = isBare && !isConfig(run)
|
|
607
|
+
const files = filesOf(run)
|
|
608
|
+
if (!files.ok) {
|
|
609
|
+
// A bare run tried for the main one already failed the unit check; any other is reported.
|
|
610
|
+
if (!tried.has(runKey(run))) plan.unlisted.push({ run, error: files.error })
|
|
611
|
+
continue
|
|
612
|
+
}
|
|
613
|
+
const unit = inArea(files.listed, 'unit')
|
|
614
|
+
if (!isMain && (unit.length > 0 || isBare) && !unit.some((entry) => path.resolve(entry.file) === suite))
|
|
615
|
+
plan.partial.push({ run, files: new Set(unit.map((entry) => path.resolve(entry.file))).size, bare: isBare })
|
|
616
|
+
const contract = reportOnly ? [] : inArea(files.listed, 'contract')
|
|
617
|
+
if (contract.length > 0) plan.contract.push({ run, projects: select(contract) })
|
|
618
|
+
}
|
|
619
|
+
return plan
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* THE CONFORMANCE SUITE WOULD RUN (the unit runner): the main unit run (planFor) must list every test of every unit
|
|
624
|
+
* check, from the app's own `src/sssb.conformance.test.ts` (ownTests), less the checks the app opted out of by name
|
|
625
|
+
* there; no main run, or one doctor cannot list, fails. Every other config that runs some of the app's `src/` tests but
|
|
626
|
+
* not the suite, and every other config doctor cannot list, is reported: doctor cannot see which config CI runs.
|
|
627
|
+
*
|
|
628
|
+
* THE CONTRACT RUNNER'S CHECKS WOULD RUN: some config that runs the app's `tests/contract/` files must list every
|
|
629
|
+
* contract check; when one does, each other that runs them and does not is reported, and when none does, each fails.
|
|
630
|
+
* Each opt-out is reported with its reason.
|
|
631
|
+
* @param {string} root
|
|
632
|
+
* @param {string} app
|
|
633
|
+
* @param {'unit' | 'contract'} runner
|
|
634
|
+
* @param {Map<string, Plan>} plans
|
|
635
|
+
* @param {VitestCache} cache
|
|
636
|
+
* @returns {Result[]}
|
|
637
|
+
*/
|
|
638
|
+
function conformance(root, app, runner, plans, cache) {
|
|
639
|
+
const rel = relativeTo(root)
|
|
640
|
+
const label = `${rel(app)}: ${runner === 'unit' ? 'the conformance suite would run' : "the contract runner's checks would run"}`
|
|
641
|
+
const plan = /** @type {Plan} */ (plans.get(app))
|
|
642
|
+
let registry
|
|
643
|
+
try {
|
|
644
|
+
registry = readJson(resolveAppsKit(app, 'testing/checks.json'))
|
|
645
|
+
} catch (error) {
|
|
646
|
+
return [{ status: 'FAIL', title: label, lines: [messageOf(error)] }]
|
|
647
|
+
}
|
|
648
|
+
/** @type {Result[]} */
|
|
649
|
+
const results = []
|
|
650
|
+
/** @type {Map<string, string>} */
|
|
651
|
+
const opted = new Map()
|
|
652
|
+
/** @param {Selected} selected */
|
|
653
|
+
const check = (selected) => {
|
|
654
|
+
const result = listOnce(selected.run, { projects: selected.projects }, cache)
|
|
655
|
+
const listed = result.ok ? ownTests(result.listed, app, runner, plan.nested) : []
|
|
656
|
+
const outcome = missingTests(listed, registry, runner)
|
|
657
|
+
if (result.ok) for (const { id, reason } of outcome.optedOut) opted.set(id, reason)
|
|
658
|
+
return {
|
|
659
|
+
...outcome,
|
|
660
|
+
selected,
|
|
661
|
+
where: listName(root, selected),
|
|
662
|
+
error: result.ok ? null : result.error,
|
|
663
|
+
passes: result.ok && outcome.missing.length === 0,
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
/** @param {ReturnType<typeof check>} c @returns {Result} */
|
|
667
|
+
const failed = (c) => ({
|
|
668
|
+
status: 'FAIL',
|
|
669
|
+
title: `${label}: ${c.missing.length} of its ${c.expected} tests would not run (${c.where})`,
|
|
670
|
+
lines: [...(c.error === null ? [] : [`${c.where}: ${c.error}`]), ...c.missing.map((n) => `not listed: ${n}`)],
|
|
671
|
+
})
|
|
672
|
+
/** @param {ReturnType<typeof check>} c */
|
|
673
|
+
const passed = (c) =>
|
|
674
|
+
/** @type {Result} */ ({ status: 'ok', title: `${label}: all ${c.expected} tests listed (${c.where})` })
|
|
675
|
+
|
|
676
|
+
if (runner === 'unit') {
|
|
677
|
+
const mainName = plan.main ? configName(root, plan.main.run) : 'the config a bare `vitest` loads'
|
|
678
|
+
if (plan.mainErrors.length > 0)
|
|
679
|
+
results.push({
|
|
680
|
+
status: 'FAIL',
|
|
681
|
+
title: `${label}: doctor cannot list the config a bare \`vitest\` would load for ${rel(app)}, so it cannot tell whether that config runs its tests`,
|
|
682
|
+
lines: plan.mainErrors,
|
|
683
|
+
})
|
|
684
|
+
else if (plan.main === null)
|
|
685
|
+
results.push({
|
|
686
|
+
status: 'FAIL',
|
|
687
|
+
title:
|
|
688
|
+
`${label}: no config a bare \`vitest\` would load for ${rel(app)} runs a test file of its src/ ` +
|
|
689
|
+
`(tried ${plan.tried.map((run) => configName(root, run)).join(', ')}), so nothing holds it to the unit checks`,
|
|
690
|
+
})
|
|
691
|
+
else {
|
|
692
|
+
const c = check(plan.main)
|
|
693
|
+
results.push(c.passes ? passed(c) : failed(c))
|
|
694
|
+
}
|
|
695
|
+
for (const { run, files, bare } of plan.partial) {
|
|
696
|
+
const runs =
|
|
697
|
+
files === 0
|
|
698
|
+
? 'runs none of its src/ test files, so not src/sssb.conformance.test.ts'
|
|
699
|
+
: `runs ${files} of its src/ test files but not src/sssb.conformance.test.ts`
|
|
700
|
+
results.push({
|
|
701
|
+
status: 'report',
|
|
702
|
+
title: bare
|
|
703
|
+
? `${rel(app)}: a bare \`vitest\` from ${rel(run.cwd)} loads ` +
|
|
704
|
+
`${run.config ? path.relative(root, run.config) : "no config (Vitest's defaults)"} and ${runs}: ` +
|
|
705
|
+
`if CI runs it there (the app's own scripts, \`pnpm -r\`) instead of ${mainName} from the root, ` +
|
|
706
|
+
'the conformance checks do not run'
|
|
707
|
+
: `${rel(app)}: ${configName(root, run)} ${runs}: if CI runs it instead of ${mainName}, the ` +
|
|
708
|
+
'conformance checks do not run',
|
|
709
|
+
})
|
|
710
|
+
}
|
|
711
|
+
for (const { run, error } of plan.unlisted)
|
|
712
|
+
results.push({
|
|
713
|
+
status: 'report',
|
|
714
|
+
title:
|
|
715
|
+
`${rel(app)}: doctor cannot list ${configName(root, run)}, so it cannot tell what that config runs; ` +
|
|
716
|
+
`it is not the config a bare \`vitest\` loads, so this is no failure, but if CI runs it, doctor has not checked it`,
|
|
717
|
+
lines: [error],
|
|
718
|
+
})
|
|
719
|
+
} else if (plan.contract.length === 0) {
|
|
720
|
+
results.push({
|
|
721
|
+
status: 'FAIL',
|
|
722
|
+
title:
|
|
723
|
+
`${label}: no Vitest config at the workspace root or in ${rel(app)} runs a test file of its ` +
|
|
724
|
+
'tests/contract/, so nothing runs its contract checks',
|
|
725
|
+
})
|
|
726
|
+
} else {
|
|
727
|
+
const checked = plan.contract.map(check)
|
|
728
|
+
const passing = checked.filter((c) => c.passes)
|
|
729
|
+
if (passing.length === 0) results.push(...checked.map(failed))
|
|
730
|
+
else {
|
|
731
|
+
const names = passing.map((c) => configName(root, c.selected.run)).join(', ')
|
|
732
|
+
for (const c of checked)
|
|
733
|
+
results.push(
|
|
734
|
+
c.passes
|
|
735
|
+
? passed(c)
|
|
736
|
+
: {
|
|
737
|
+
status: 'report',
|
|
738
|
+
title:
|
|
739
|
+
`${rel(app)}: ${configName(root, c.selected.run)} runs its tests/contract/ files but ` +
|
|
740
|
+
(c.error === null
|
|
741
|
+
? `${c.missing.length} of its ${c.expected} contract tests would not run: ` +
|
|
742
|
+
`if CI runs it instead of ${names}, those checks do not run`
|
|
743
|
+
: `doctor cannot list its tests (${c.error}): if CI runs it instead of ` +
|
|
744
|
+
`${names}, doctor has not checked that the contract checks run`),
|
|
745
|
+
},
|
|
746
|
+
)
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
for (const [id, reason] of opted)
|
|
750
|
+
results.push({ status: 'report', title: `${rel(app)}: opted out of ${id}: ${reason || '(no reason given)'}` })
|
|
751
|
+
return results
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* WHAT DOCTOR CANNOT SEE: the command line a CI step runs Vitest with. Doctor proves what each configuration would
|
|
756
|
+
* run; a flag or a file filter on the command (`-t`, `--project`, `--shard`, a path...) can run fewer. It reads the
|
|
757
|
+
* root's and the apps' package.json scripts and reports every such flag they pass, and, since it lists the contract
|
|
758
|
+
* checks and never runs them, which script runs each app's contract config, or that none does.
|
|
759
|
+
* @param {string} root
|
|
760
|
+
* @param {string} appDir
|
|
761
|
+
* @param {string[]} apps
|
|
762
|
+
* @param {Map<string, Plan>} plans
|
|
763
|
+
* @returns {Result[]}
|
|
764
|
+
*/
|
|
765
|
+
function commandLines(root, appDir, apps, plans) {
|
|
766
|
+
const rel = relativeTo(root)
|
|
767
|
+
const dirs = [...new Set([root, appDir, ...apps])]
|
|
768
|
+
const owner = (/** @type {string} */ dir) => (dir === root ? 'root' : rel(dir))
|
|
769
|
+
const invocations = dirs.flatMap((dir) =>
|
|
770
|
+
vitestInvocations(readJson(path.join(dir, 'package.json')).scripts ?? {}).map((call) => ({ ...call, dir })),
|
|
771
|
+
)
|
|
772
|
+
const narrowed = invocations.filter((call) => call.narrowing.length > 0)
|
|
773
|
+
/** @type {Result[]} */
|
|
774
|
+
const results = [
|
|
775
|
+
{
|
|
776
|
+
status: 'report',
|
|
777
|
+
title:
|
|
778
|
+
"CI's command line: doctor proves what each Vitest configuration would run, not what a CI step's own " +
|
|
779
|
+
'flags make of it; the flags and file filters the package.json scripts pass to vitest:',
|
|
780
|
+
lines:
|
|
781
|
+
narrowed.length > 0
|
|
782
|
+
? narrowed.map((call) => `${owner(call.dir)} script ${call.script}: ${call.narrowing.join(', ')}`)
|
|
783
|
+
: [
|
|
784
|
+
`none (scripts of ${dirs.map(owner).join(', ')}; a flag a CI step adds itself is not here to see)`,
|
|
785
|
+
],
|
|
786
|
+
},
|
|
787
|
+
]
|
|
788
|
+
/** @type {string[]} */
|
|
789
|
+
const lines = []
|
|
790
|
+
for (const app of apps) {
|
|
791
|
+
const plan = /** @type {Plan} */ (plans.get(app))
|
|
792
|
+
const configs = [...new Set(plan.contract.map(({ run }) => run.config).filter((c) => c !== null))]
|
|
793
|
+
for (const config of configs) {
|
|
794
|
+
const callers = invocations.filter(
|
|
795
|
+
(call) =>
|
|
796
|
+
(call.config ? path.resolve(call.dir, call.config) : vitestDefaultConfig(call.dir)) === config,
|
|
797
|
+
)
|
|
798
|
+
const name = path.relative(root, config)
|
|
799
|
+
lines.push(
|
|
800
|
+
callers.length > 0
|
|
801
|
+
? `${rel(app)}: ${callers.map((call) => `${owner(call.dir)} script ${call.script}`).join(', ')} runs ${name}`
|
|
802
|
+
: `${rel(app)}: no script of the root's or ${rel(app)}'s package.json runs ${name}; CI must run it itself`,
|
|
803
|
+
)
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
if (lines.length > 0)
|
|
807
|
+
results.push({
|
|
808
|
+
status: 'report',
|
|
809
|
+
title: "contract checks: doctor lists them and never runs them, so CI must run each app's contract config:",
|
|
810
|
+
lines,
|
|
811
|
+
})
|
|
812
|
+
return results
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* The app guide (`sssb guide --check`) of every app, once the framework ships one.
|
|
817
|
+
*
|
|
818
|
+
* IN-REPO, a missing copy is not a failure. There the kit is a package of the workspace and its guide
|
|
819
|
+
* (`packages/kit/src/guide.md`) is the source, checked by the doc gate; a copy is the adopter's mechanism, and SSSB's
|
|
820
|
+
* own `CLAUDE.md` imports the source itself (`@packages/kit/src/guide.md`, ADR-0014 P13), which nothing can make stale:
|
|
821
|
+
* that import is ok, and its absence is reported. Once a copy exists it is checked as an adopter's is. An adopter's
|
|
822
|
+
* workspace is never in-repo, so a missing copy fails there.
|
|
823
|
+
*
|
|
824
|
+
* @param {string} root
|
|
825
|
+
* @param {string[]} apps
|
|
826
|
+
* @param {boolean} inRepo
|
|
827
|
+
* @returns {Promise<Result[]>}
|
|
828
|
+
*/
|
|
829
|
+
async function guides(root, apps, inRepo) {
|
|
830
|
+
/** @type {Result[]} */
|
|
831
|
+
const results = []
|
|
832
|
+
/** @param {string} title */
|
|
833
|
+
const reportOnce = (title) => {
|
|
834
|
+
if (!results.some((r) => r.title === title)) results.push({ status: 'report', title })
|
|
835
|
+
}
|
|
836
|
+
for (const app of apps) {
|
|
837
|
+
let source
|
|
838
|
+
try {
|
|
839
|
+
source = resolveAppsKit(app, 'guide.md')
|
|
840
|
+
} catch {
|
|
841
|
+
reportOnce('app guide: not checked: this @sssb/kit ships no guide (it arrives at P7)')
|
|
842
|
+
continue
|
|
843
|
+
}
|
|
844
|
+
if (inRepo && !existsSync(path.join(workspaceRootOf(app), '.claude', 'sssb-guide.md'))) {
|
|
845
|
+
const importLine = `@${path.relative(root, realpathSync(source)).split(path.sep).join('/')}`
|
|
846
|
+
const claudeMd = path.join(root, 'CLAUDE.md')
|
|
847
|
+
const imports =
|
|
848
|
+
existsSync(claudeMd) &&
|
|
849
|
+
readFileSync(claudeMd, 'utf8')
|
|
850
|
+
.split('\n')
|
|
851
|
+
.some((line) => line.trim().split(/\s+/).includes(importLine))
|
|
852
|
+
if (imports && !results.some((r) => r.status === 'ok' && r.title.startsWith('app guide:')))
|
|
853
|
+
results.push({
|
|
854
|
+
status: 'ok',
|
|
855
|
+
title: `app guide: in-repo, CLAUDE.md imports the kit's guide from its source (${importLine}), so no copy can go stale`,
|
|
856
|
+
})
|
|
857
|
+
else if (!imports)
|
|
858
|
+
reportOnce(
|
|
859
|
+
"app guide: not checked: in-repo, the kit's guide is this workspace's own source, and the repository " +
|
|
860
|
+
`neither imports it from CLAUDE.md (${importLine}) nor holds a copy of it (\`.claude/sssb-guide.md\`)`,
|
|
861
|
+
)
|
|
862
|
+
continue
|
|
863
|
+
}
|
|
864
|
+
const name = relativeTo(root)(app)
|
|
865
|
+
const status = await (await import('./guide.js')).run(['--app', app, '--check'])
|
|
866
|
+
results.push(
|
|
867
|
+
status === 0
|
|
868
|
+
? { status: 'ok', title: `${name}: app guide: the repository's copy matches the kit's` }
|
|
869
|
+
: { status: 'FAIL', title: `${name}: app guide: the repository's copy is not the kit's (see above)` },
|
|
870
|
+
)
|
|
871
|
+
}
|
|
872
|
+
return results
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* The workflow and plugin pins against the kit's release stamp (pinReport): read here, judged there. The workflows are
|
|
877
|
+
* the workspace root's `.github/workflows/*.{yml,yaml}`, the settings its `.claude/settings.json` (the shared one; a
|
|
878
|
+
* machine's `settings.local.json` is no pin of the repository's), the stamp the APP's kit's `dist/release.json`.
|
|
879
|
+
* @param {string} root
|
|
880
|
+
* @param {string} kitDir
|
|
881
|
+
* @param {string} version
|
|
882
|
+
* @param {boolean} inRepo
|
|
883
|
+
* @returns {Result}
|
|
884
|
+
*/
|
|
885
|
+
function pins(root, kitDir, version, inRepo) {
|
|
886
|
+
const read = (/** @type {string} */ file) => (existsSync(file) ? readFileSync(file, 'utf8') : null)
|
|
887
|
+
const workflowsDir = path.join(root, '.github', 'workflows')
|
|
888
|
+
const workflows = existsSync(workflowsDir)
|
|
889
|
+
? readdirSync(workflowsDir)
|
|
890
|
+
.filter((name) => /\.ya?ml$/.test(name))
|
|
891
|
+
.sort()
|
|
892
|
+
.map((name) => ({
|
|
893
|
+
file: `.github/workflows/${name}`,
|
|
894
|
+
text: /** @type {string} */ (read(path.join(workflowsDir, name))),
|
|
895
|
+
}))
|
|
896
|
+
: []
|
|
897
|
+
const settingsText = read(path.join(root, '.claude', 'settings.json'))
|
|
898
|
+
return pinReport({
|
|
899
|
+
inRepo,
|
|
900
|
+
version,
|
|
901
|
+
stamp: read(path.join(kitDir, 'dist', 'release.json')),
|
|
902
|
+
repository: githubRepositoryOf(readJson(path.join(kitDir, 'package.json')).repository),
|
|
903
|
+
workflows,
|
|
904
|
+
settings: settingsText === null ? null : { file: '.claude/settings.json', text: settingsText },
|
|
905
|
+
})
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* @param {string} root
|
|
910
|
+
* @param {boolean} inRepo
|
|
911
|
+
* @returns {Result}
|
|
912
|
+
*/
|
|
913
|
+
function dedupeAdvice(root, inRepo) {
|
|
914
|
+
const { dedupePeerDependents } = parseWorkspaceYaml(readFileSync(path.join(root, 'pnpm-workspace.yaml'), 'utf8'))
|
|
915
|
+
if (dedupePeerDependents === false)
|
|
916
|
+
return { status: 'ok', title: 'pnpm-workspace.yaml sets dedupePeerDependents: false' }
|
|
917
|
+
return {
|
|
918
|
+
status: 'advice',
|
|
919
|
+
title:
|
|
920
|
+
'pnpm-workspace.yaml does not set `dedupePeerDependents: false`: without it, a package that takes @sssb/kit ' +
|
|
921
|
+
"and links no seam silently shares another app's instance and seam (ADR-0014 part 5). Set it, then reinstall " +
|
|
922
|
+
'from a fresh lockfile, since a lockfile resolved before it keeps the merged layout' +
|
|
923
|
+
(inRepo ? ' (in-repo mode: the seam goes through aliases here, so this is advice for an adopter)' : ''),
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* @param {string} root
|
|
929
|
+
* @param {string} appDir
|
|
930
|
+
* @returns {Result}
|
|
931
|
+
*/
|
|
932
|
+
function cutover(root, appDir) {
|
|
933
|
+
let rows
|
|
934
|
+
try {
|
|
935
|
+
rows = readJson(resolveAppsKit(appDir, 'cutover/rows.json'))
|
|
936
|
+
} catch {
|
|
937
|
+
return { status: 'report', title: 'cutover rows: not checked: this @sssb/kit publishes no cutover/rows.json' }
|
|
938
|
+
}
|
|
939
|
+
const file = path.join(root, 'docs', 'cutover-checklist.md')
|
|
940
|
+
const checklist = existsSync(file) ? readFileSync(file, 'utf8') : null
|
|
941
|
+
const { unmentioned, sssbOnly } = cutoverReport(rows, checklist)
|
|
942
|
+
const skipped = sssbOnly.length ? ` (${sssbOnly.join(', ')}: SSSB's own repository only, not looked for)` : ''
|
|
943
|
+
if (unmentioned.length === 0)
|
|
944
|
+
return { status: 'ok', title: `cutover rows: docs/cutover-checklist.md records every framework row${skipped}` }
|
|
945
|
+
return {
|
|
946
|
+
status: 'report',
|
|
947
|
+
title:
|
|
948
|
+
(checklist === null
|
|
949
|
+
? `cutover rows: the workspace has no docs/cutover-checklist.md, so none of the framework's rows is recorded`
|
|
950
|
+
: `cutover rows: docs/cutover-checklist.md never mentions ${unmentioned.length} framework row(s)`) +
|
|
951
|
+
skipped,
|
|
952
|
+
lines: [unmentioned.join(', ')],
|
|
953
|
+
}
|
|
954
|
+
}
|