@thegetty/quire-cli 1.0.0-rc.37 → 1.0.0-rc.39

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.
Files changed (104) hide show
  1. package/package.json +5 -2
  2. package/src/commands/build.js +13 -6
  3. package/src/commands/clean.js +10 -2
  4. package/src/commands/clean.spec.js +10 -0
  5. package/src/commands/clean.test.js +122 -0
  6. package/src/commands/config.js +3 -1
  7. package/src/commands/config.test.js +42 -1
  8. package/src/commands/doctor.js +251 -0
  9. package/src/commands/doctor.spec.js +115 -0
  10. package/src/commands/doctor.test.js +1409 -0
  11. package/src/commands/epub.js +9 -2
  12. package/src/commands/help.js +60 -0
  13. package/src/commands/help.test.js +132 -0
  14. package/src/commands/info.js +79 -71
  15. package/src/commands/info.spec.js +8 -0
  16. package/src/commands/info.test.js +173 -76
  17. package/src/commands/pdf.js +10 -3
  18. package/src/commands/validate.js +39 -7
  19. package/src/commands/validate.spec.js +8 -0
  20. package/src/commands/validate.test.js +144 -0
  21. package/src/errors/help/help-topic-not-found-error.js +22 -0
  22. package/src/errors/help/index.js +8 -0
  23. package/src/errors/index.js +6 -0
  24. package/src/errors/input/index.js +8 -0
  25. package/src/errors/input/invalid-input-error.js +21 -0
  26. package/src/helpers/pager.js +59 -0
  27. package/src/helpers/pager.test.js +85 -0
  28. package/src/lib/README.md +77 -22
  29. package/src/lib/conf/README.md +6 -0
  30. package/src/lib/conf/build-status.js +103 -0
  31. package/src/lib/conf/build-status.test.js +247 -0
  32. package/src/lib/conf/defaults.js +14 -0
  33. package/src/lib/conf/format.js +1 -1
  34. package/src/lib/conf/schema.js +46 -1
  35. package/src/lib/constants.js +28 -0
  36. package/src/lib/doctor/README.md +667 -0
  37. package/src/lib/doctor/checks/environment/cli-version.js +62 -0
  38. package/src/lib/doctor/checks/environment/cli-version.test.js +132 -0
  39. package/src/lib/doctor/checks/environment/git-available.js +77 -0
  40. package/src/lib/doctor/checks/environment/git-available.test.js +52 -0
  41. package/src/lib/doctor/checks/environment/index.js +13 -0
  42. package/src/lib/doctor/checks/environment/node-version.js +66 -0
  43. package/src/lib/doctor/checks/environment/node-version.test.js +17 -0
  44. package/src/lib/doctor/checks/environment/npm-available.js +66 -0
  45. package/src/lib/doctor/checks/environment/npm-available.test.js +52 -0
  46. package/src/lib/doctor/checks/environment/os-info.js +48 -0
  47. package/src/lib/doctor/checks/environment/os-info.test.js +81 -0
  48. package/src/lib/doctor/checks/environment/runtime-info.js +51 -0
  49. package/src/lib/doctor/checks/environment/runtime-info.test.js +132 -0
  50. package/src/lib/doctor/checks/outputs/epub-output.js +119 -0
  51. package/src/lib/doctor/checks/outputs/epub-output.test.js +277 -0
  52. package/src/lib/doctor/checks/outputs/index.js +10 -0
  53. package/src/lib/doctor/checks/outputs/pdf-output.js +144 -0
  54. package/src/lib/doctor/checks/outputs/pdf-output.test.js +377 -0
  55. package/src/lib/doctor/checks/outputs/stale-build.js +122 -0
  56. package/src/lib/doctor/checks/outputs/stale-build.test.js +282 -0
  57. package/src/lib/doctor/checks/project/data-files.js +56 -0
  58. package/src/lib/doctor/checks/project/data-files.test.js +125 -0
  59. package/src/lib/doctor/checks/project/dependencies.js +53 -0
  60. package/src/lib/doctor/checks/project/dependencies.test.js +71 -0
  61. package/src/lib/doctor/checks/project/index.js +11 -0
  62. package/src/lib/doctor/checks/project/quire-11ty.js +98 -0
  63. package/src/lib/doctor/checks/project/quire-11ty.test.js +170 -0
  64. package/src/lib/doctor/checks/project/quire-project.js +38 -0
  65. package/src/lib/doctor/checks/project/quire-project.test.js +47 -0
  66. package/src/lib/doctor/checks/tools/index.js +10 -0
  67. package/src/lib/doctor/checks/tools/pandoc-available.js +82 -0
  68. package/src/lib/doctor/checks/tools/pandoc-available.test.js +73 -0
  69. package/src/lib/doctor/checks/tools/prince-available.js +81 -0
  70. package/src/lib/doctor/checks/tools/prince-available.test.js +73 -0
  71. package/src/lib/doctor/constants.js +39 -0
  72. package/src/lib/doctor/formatDuration.js +108 -0
  73. package/src/lib/doctor/formatDuration.test.js +76 -0
  74. package/src/lib/doctor/formatters/human.js +257 -0
  75. package/src/lib/doctor/formatters/human.test.js +463 -0
  76. package/src/lib/doctor/formatters/index.js +8 -0
  77. package/src/lib/doctor/formatters/json.js +78 -0
  78. package/src/lib/doctor/formatters/json.test.js +174 -0
  79. package/src/lib/doctor/formatters/shared.js +129 -0
  80. package/src/lib/doctor/formatters/shared.test.js +194 -0
  81. package/src/lib/doctor/index.js +271 -0
  82. package/src/lib/doctor/index.test.js +797 -0
  83. package/src/lib/help/frontmatter.js +77 -0
  84. package/src/lib/help/frontmatter.test.js +139 -0
  85. package/src/lib/help/index.js +135 -0
  86. package/src/lib/help/index.test.js +160 -0
  87. package/src/lib/help/topics/configuration.md +77 -0
  88. package/src/lib/help/topics/debugging.md +69 -0
  89. package/src/lib/help/topics/epub.md +74 -0
  90. package/src/lib/help/topics/pdf.md +74 -0
  91. package/src/lib/help/topics/publishing.md +80 -0
  92. package/src/lib/help/topics/workflows.md +50 -0
  93. package/src/lib/platform.js +95 -0
  94. package/src/lib/project/build.js +44 -25
  95. package/src/lib/project/build.test.js +30 -8
  96. package/src/lib/project/detect.js +16 -2
  97. package/src/lib/project/index.js +18 -2
  98. package/src/lib/project/output-paths.js +87 -0
  99. package/src/lib/project/output-paths.test.js +66 -0
  100. package/src/lib/project/paths.js +48 -0
  101. package/src/main.js +38 -3
  102. package/src/packageConfig.js +17 -0
  103. package/src/validators/validate-data-files.js +154 -0
  104. package/src/validators/validate-data-files.test.js +217 -0
@@ -0,0 +1,797 @@
1
+ import test from 'ava'
2
+ import sinon from 'sinon'
3
+ import esmock from 'esmock'
4
+
5
+ /**
6
+ * Index module tests
7
+ *
8
+ * Tests the barrel export, checkSections structure, and runner functions.
9
+ * Individual check function tests are in the domain test files:
10
+ * - checks/environment/*.test.js
11
+ * - checks/tools/*.test.js
12
+ * - checks/project/*.test.js
13
+ * - checks/outputs/*.test.js
14
+ */
15
+
16
+ test.beforeEach((t) => {
17
+ t.context.sandbox = sinon.createSandbox()
18
+ })
19
+
20
+ test.afterEach.always((t) => {
21
+ t.context.sandbox.restore()
22
+ })
23
+
24
+ // ─────────────────────────────────────────────────────────────────────────────
25
+ // Barrel export tests
26
+ // ─────────────────────────────────────────────────────────────────────────────
27
+
28
+ test('checks array exports all check definitions', async (t) => {
29
+ const { checks } = await import('./index.js')
30
+
31
+ t.true(Array.isArray(checks))
32
+ t.is(checks.length, 15)
33
+
34
+ const checkNames = checks.map((c) => c.name)
35
+ t.true(checkNames.includes('Operating system'))
36
+ t.true(checkNames.includes('Quire CLI version'))
37
+ t.true(checkNames.includes('Node.js version'))
38
+ t.true(checkNames.includes('Node.js runtime'))
39
+ t.true(checkNames.includes('npm'))
40
+ t.true(checkNames.includes('Git'))
41
+ t.true(checkNames.includes('PrinceXML'))
42
+ t.true(checkNames.includes('Pandoc'))
43
+ t.true(checkNames.includes('Quire project'))
44
+ t.true(checkNames.includes('Dependencies'))
45
+ t.true(checkNames.includes('quire-11ty version'))
46
+ t.true(checkNames.includes('Data files'))
47
+ t.true(checkNames.includes('Build status'))
48
+ t.true(checkNames.includes('PDF output'))
49
+ t.true(checkNames.includes('EPUB output'))
50
+
51
+ // Verify each check has a function
52
+ for (const { check } of checks) {
53
+ t.is(typeof check, 'function')
54
+ }
55
+ })
56
+
57
+ test('checkSections exports checks organized by 4 sections', async (t) => {
58
+ const { checkSections } = await import('./index.js')
59
+
60
+ t.true(Array.isArray(checkSections))
61
+ t.is(checkSections.length, 4)
62
+
63
+ const sectionNames = checkSections.map((s) => s.name)
64
+ t.true(sectionNames.includes('Environment'))
65
+ t.true(sectionNames.includes('Tools'))
66
+ t.true(sectionNames.includes('Project'))
67
+ t.true(sectionNames.includes('Outputs'))
68
+
69
+ // Environment section should have 6 checks
70
+ const envSection = checkSections.find((s) => s.name === 'Environment')
71
+ t.is(envSection.checks.length, 6)
72
+ const envCheckNames = envSection.checks.map((c) => c.name)
73
+ t.true(envCheckNames.includes('Operating system'))
74
+ t.true(envCheckNames.includes('Quire CLI version'))
75
+ t.true(envCheckNames.includes('Node.js version'))
76
+ t.true(envCheckNames.includes('Node.js runtime'))
77
+ t.true(envCheckNames.includes('npm'))
78
+ t.true(envCheckNames.includes('Git'))
79
+
80
+ // Tools section should have 2 checks
81
+ const toolsSection = checkSections.find((s) => s.name === 'Tools')
82
+ t.is(toolsSection.checks.length, 2)
83
+ const toolCheckNames = toolsSection.checks.map((c) => c.name)
84
+ t.true(toolCheckNames.includes('PrinceXML'))
85
+ t.true(toolCheckNames.includes('Pandoc'))
86
+
87
+ // Project section should have 4 checks
88
+ const projectSection = checkSections.find((s) => s.name === 'Project')
89
+ t.is(projectSection.checks.length, 4)
90
+ const projectCheckNames = projectSection.checks.map((c) => c.name)
91
+ t.true(projectCheckNames.includes('Quire project'))
92
+ t.true(projectCheckNames.includes('Dependencies'))
93
+ t.true(projectCheckNames.includes('quire-11ty version'))
94
+ t.true(projectCheckNames.includes('Data files'))
95
+
96
+ // Outputs section should have 3 checks
97
+ const outputsSection = checkSections.find((s) => s.name === 'Outputs')
98
+ t.is(outputsSection.checks.length, 3)
99
+ const outputCheckNames = outputsSection.checks.map((c) => c.name)
100
+ t.true(outputCheckNames.includes('Build status'))
101
+ t.true(outputCheckNames.includes('PDF output'))
102
+ t.true(outputCheckNames.includes('EPUB output'))
103
+ })
104
+
105
+ test('default export includes all expected functions', async (t) => {
106
+ const doctor = await import('./index.js')
107
+
108
+ // Runner functions
109
+ t.is(typeof doctor.default.runAllChecks, 'function')
110
+ t.is(typeof doctor.default.runAllChecksWithSections, 'function')
111
+
112
+ // Check functions
113
+ t.is(typeof doctor.default.checkOsInfo, 'function')
114
+ t.is(typeof doctor.default.checkCliVersion, 'function')
115
+ t.is(typeof doctor.default.checkNodeVersion, 'function')
116
+ t.is(typeof doctor.default.checkRuntimeInfo, 'function')
117
+ t.is(typeof doctor.default.checkNpmAvailable, 'function')
118
+ t.is(typeof doctor.default.checkGitAvailable, 'function')
119
+ t.is(typeof doctor.default.checkPrinceAvailable, 'function')
120
+ t.is(typeof doctor.default.checkPandocAvailable, 'function')
121
+ t.is(typeof doctor.default.checkQuireProject, 'function')
122
+ t.is(typeof doctor.default.checkDependencies, 'function')
123
+ t.is(typeof doctor.default.checkOutdatedQuire11ty, 'function')
124
+ t.is(typeof doctor.default.checkDataFiles, 'function')
125
+ t.is(typeof doctor.default.checkStaleBuild, 'function')
126
+ t.is(typeof doctor.default.checkPdfOutput, 'function')
127
+ t.is(typeof doctor.default.checkEpubOutput, 'function')
128
+
129
+ // Collections
130
+ t.truthy(doctor.default.checks)
131
+ t.truthy(doctor.default.checkSections)
132
+ })
133
+
134
+ test('named exports match default export', async (t) => {
135
+ const doctor = await import('./index.js')
136
+
137
+ t.is(doctor.checkOsInfo, doctor.default.checkOsInfo)
138
+ t.is(doctor.checkCliVersion, doctor.default.checkCliVersion)
139
+ t.is(doctor.checkNodeVersion, doctor.default.checkNodeVersion)
140
+ t.is(doctor.checkRuntimeInfo, doctor.default.checkRuntimeInfo)
141
+ t.is(doctor.checkNpmAvailable, doctor.default.checkNpmAvailable)
142
+ t.is(doctor.checkGitAvailable, doctor.default.checkGitAvailable)
143
+ t.is(doctor.checkPrinceAvailable, doctor.default.checkPrinceAvailable)
144
+ t.is(doctor.checkPandocAvailable, doctor.default.checkPandocAvailable)
145
+ t.is(doctor.checkQuireProject, doctor.default.checkQuireProject)
146
+ t.is(doctor.checkDependencies, doctor.default.checkDependencies)
147
+ t.is(doctor.checkOutdatedQuire11ty, doctor.default.checkOutdatedQuire11ty)
148
+ t.is(doctor.checkDataFiles, doctor.default.checkDataFiles)
149
+ t.is(doctor.checkStaleBuild, doctor.default.checkStaleBuild)
150
+ t.is(doctor.checkPdfOutput, doctor.default.checkPdfOutput)
151
+ t.is(doctor.checkEpubOutput, doctor.default.checkEpubOutput)
152
+ t.is(doctor.runAllChecks, doctor.default.runAllChecks)
153
+ t.is(doctor.runAllChecksWithSections, doctor.default.runAllChecksWithSections)
154
+ })
155
+
156
+ test('constants are exported', async (t) => {
157
+ const doctor = await import('./index.js')
158
+
159
+ t.is(doctor.DOCS_BASE_URL, 'https://quire.getty.edu/docs-v1')
160
+ t.is(doctor.REQUIRED_NODE_VERSION, 22)
161
+ t.is(doctor.QUIRE_11TY_PACKAGE, '@thegetty/quire-11ty')
162
+ t.deepEqual(doctor.SECTION_NAMES, ['environment', 'tools', 'project', 'outputs'])
163
+ t.deepEqual(doctor.CHECK_IDS, [
164
+ 'os', 'cli', 'node', 'runtime', 'npm', 'git',
165
+ 'prince', 'pandoc',
166
+ 'project', 'deps', '11ty', 'data',
167
+ 'build', 'pdf', 'epub',
168
+ ])
169
+ })
170
+
171
+ // ─────────────────────────────────────────────────────────────────────────────
172
+ // Runner function tests
173
+ // ─────────────────────────────────────────────────────────────────────────────
174
+
175
+ test('runAllChecks runs all checks and returns results array', async (t) => {
176
+ const { sandbox } = t.context
177
+
178
+ // Create mock check functions
179
+ const mockCheckOs = sandbox.stub().returns({ ok: true, message: 'macOS 14 (arm64)' })
180
+ const mockCheckCli = sandbox.stub().returns({ ok: true, message: 'v1.0.0-rc.33' })
181
+ const mockCheckNode = sandbox.stub().returns({ ok: true, message: 'v22' })
182
+ const mockCheckRuntime = sandbox.stub().returns({ ok: true, message: 'Heap limit: 4096 MB' })
183
+ const mockCheckNpm = sandbox.stub().resolves({ ok: true, message: '10.2.4' })
184
+ const mockCheckGit = sandbox.stub().resolves({ ok: true, message: '2.43.0' })
185
+ const mockCheckPrince = sandbox.stub().returns({ ok: true, message: 'installed' })
186
+ const mockCheckPandoc = sandbox.stub().returns({ ok: true, message: 'installed' })
187
+ const mockCheckProject = sandbox.stub().returns({ ok: true, message: '.quire' })
188
+ const mockCheckDeps = sandbox.stub().returns({ ok: true, message: 'installed' })
189
+ const mockCheckQuire11ty = sandbox.stub().resolves({ ok: true, message: 'v1.0.0' })
190
+ const mockCheckData = sandbox.stub().returns({ ok: true, message: '3 files' })
191
+ const mockCheckStale = sandbox.stub().returns({ ok: true, message: 'up to date' })
192
+ const mockCheckPdf = sandbox.stub().returns({ ok: true, message: 'no PDF' })
193
+ const mockCheckEpub = sandbox.stub().returns({ ok: true, message: 'no EPUB' })
194
+
195
+ const { runAllChecks } = await esmock('./index.js', {
196
+ './checks/environment/index.js': {
197
+ checkOsInfo: mockCheckOs,
198
+ checkCliVersion: mockCheckCli,
199
+ checkNodeVersion: mockCheckNode,
200
+ checkRuntimeInfo: mockCheckRuntime,
201
+ checkNpmAvailable: mockCheckNpm,
202
+ checkGitAvailable: mockCheckGit,
203
+ },
204
+ './checks/tools/index.js': {
205
+ checkPrinceAvailable: mockCheckPrince,
206
+ checkPandocAvailable: mockCheckPandoc,
207
+ },
208
+ './checks/project/index.js': {
209
+ checkQuireProject: mockCheckProject,
210
+ checkDependencies: mockCheckDeps,
211
+ checkOutdatedQuire11ty: mockCheckQuire11ty,
212
+ checkDataFiles: mockCheckData,
213
+ },
214
+ './checks/outputs/index.js': {
215
+ checkStaleBuild: mockCheckStale,
216
+ checkPdfOutput: mockCheckPdf,
217
+ checkEpubOutput: mockCheckEpub,
218
+ },
219
+ })
220
+
221
+ const results = await runAllChecks()
222
+
223
+ t.true(Array.isArray(results))
224
+ t.is(results.length, 15)
225
+
226
+ // Verify each result has expected shape
227
+ for (const result of results) {
228
+ t.is(typeof result.name, 'string')
229
+ t.is(typeof result.ok, 'boolean')
230
+ }
231
+
232
+ // Verify all checks were called
233
+ t.true(mockCheckOs.calledOnce)
234
+ t.true(mockCheckCli.calledOnce)
235
+ t.true(mockCheckNode.calledOnce)
236
+ t.true(mockCheckRuntime.calledOnce)
237
+ t.true(mockCheckNpm.calledOnce)
238
+ t.true(mockCheckGit.calledOnce)
239
+ t.true(mockCheckPrince.calledOnce)
240
+ t.true(mockCheckPandoc.calledOnce)
241
+ t.true(mockCheckProject.calledOnce)
242
+ t.true(mockCheckDeps.calledOnce)
243
+ t.true(mockCheckQuire11ty.calledOnce)
244
+ t.true(mockCheckData.calledOnce)
245
+ t.true(mockCheckStale.calledOnce)
246
+ t.true(mockCheckPdf.calledOnce)
247
+ t.true(mockCheckEpub.calledOnce)
248
+ })
249
+
250
+ test('runAllChecksWithSections returns results organized by 4 sections', async (t) => {
251
+ const { sandbox } = t.context
252
+
253
+ // Create mock check functions
254
+ const mockCheckOs = sandbox.stub().returns({ ok: true, message: 'macOS 14 (arm64)' })
255
+ const mockCheckCli = sandbox.stub().returns({ ok: true, message: 'v1.0.0-rc.33' })
256
+ const mockCheckNode = sandbox.stub().returns({ ok: true, message: 'v22' })
257
+ const mockCheckRuntime = sandbox.stub().returns({ ok: true, message: 'Heap limit: 4096 MB' })
258
+ const mockCheckNpm = sandbox.stub().resolves({ ok: true, message: '10.2.4' })
259
+ const mockCheckGit = sandbox.stub().resolves({ ok: true, message: '2.43.0' })
260
+ const mockCheckPrince = sandbox.stub().returns({ ok: true, message: 'installed' })
261
+ const mockCheckPandoc = sandbox.stub().returns({ ok: true, message: 'installed' })
262
+ const mockCheckProject = sandbox.stub().returns({ ok: true, message: '.quire' })
263
+ const mockCheckDeps = sandbox.stub().returns({ ok: true, message: 'installed' })
264
+ const mockCheckQuire11ty = sandbox.stub().resolves({ ok: true, message: 'v1.0.0' })
265
+ const mockCheckData = sandbox.stub().returns({ ok: true, message: '3 files' })
266
+ const mockCheckStale = sandbox.stub().returns({ ok: true, message: 'up to date' })
267
+ const mockCheckPdf = sandbox.stub().returns({ ok: true, message: 'no PDF' })
268
+ const mockCheckEpub = sandbox.stub().returns({ ok: true, message: 'no EPUB' })
269
+
270
+ const { runAllChecksWithSections } = await esmock('./index.js', {
271
+ './checks/environment/index.js': {
272
+ checkOsInfo: mockCheckOs,
273
+ checkCliVersion: mockCheckCli,
274
+ checkNodeVersion: mockCheckNode,
275
+ checkRuntimeInfo: mockCheckRuntime,
276
+ checkNpmAvailable: mockCheckNpm,
277
+ checkGitAvailable: mockCheckGit,
278
+ },
279
+ './checks/tools/index.js': {
280
+ checkPrinceAvailable: mockCheckPrince,
281
+ checkPandocAvailable: mockCheckPandoc,
282
+ },
283
+ './checks/project/index.js': {
284
+ checkQuireProject: mockCheckProject,
285
+ checkDependencies: mockCheckDeps,
286
+ checkOutdatedQuire11ty: mockCheckQuire11ty,
287
+ checkDataFiles: mockCheckData,
288
+ },
289
+ './checks/outputs/index.js': {
290
+ checkStaleBuild: mockCheckStale,
291
+ checkPdfOutput: mockCheckPdf,
292
+ checkEpubOutput: mockCheckEpub,
293
+ },
294
+ })
295
+
296
+ const sections = await runAllChecksWithSections()
297
+
298
+ t.true(Array.isArray(sections))
299
+ t.is(sections.length, 4)
300
+
301
+ // Verify section structure
302
+ const sectionNames = sections.map((s) => s.section)
303
+ t.deepEqual(sectionNames, ['Environment', 'Tools', 'Project', 'Outputs'])
304
+
305
+ // Verify each section has results
306
+ for (const { section, results } of sections) {
307
+ t.is(typeof section, 'string')
308
+ t.true(Array.isArray(results))
309
+ for (const result of results) {
310
+ t.is(typeof result.name, 'string')
311
+ t.is(typeof result.ok, 'boolean')
312
+ }
313
+ }
314
+
315
+ // Verify section sizes
316
+ const envSection = sections.find((s) => s.section === 'Environment')
317
+ t.is(envSection.results.length, 6)
318
+
319
+ const toolsSection = sections.find((s) => s.section === 'Tools')
320
+ t.is(toolsSection.results.length, 2)
321
+
322
+ const projectSection = sections.find((s) => s.section === 'Project')
323
+ t.is(projectSection.results.length, 4)
324
+
325
+ const outputsSection = sections.find((s) => s.section === 'Outputs')
326
+ t.is(outputsSection.results.length, 3)
327
+ })
328
+
329
+ test('runAllChecksWithSections filters by section name', async (t) => {
330
+ const { sandbox } = t.context
331
+
332
+ // Create mock check functions
333
+ const mockCheckOs = sandbox.stub().returns({ ok: true, message: 'macOS 14 (arm64)' })
334
+ const mockCheckCli = sandbox.stub().returns({ ok: true, message: 'v1.0.0-rc.33' })
335
+ const mockCheckNode = sandbox.stub().returns({ ok: true, message: 'v22' })
336
+ const mockCheckRuntime = sandbox.stub().returns({ ok: true, message: 'Heap limit: 4096 MB' })
337
+ const mockCheckNpm = sandbox.stub().resolves({ ok: true, message: '10.2.4' })
338
+ const mockCheckGit = sandbox.stub().resolves({ ok: true, message: '2.43.0' })
339
+ const mockCheckPrince = sandbox.stub().returns({ ok: true, message: 'installed' })
340
+ const mockCheckPandoc = sandbox.stub().returns({ ok: true, message: 'installed' })
341
+ const mockCheckProject = sandbox.stub().returns({ ok: true, message: '.quire' })
342
+ const mockCheckDeps = sandbox.stub().returns({ ok: true, message: 'installed' })
343
+ const mockCheckQuire11ty = sandbox.stub().resolves({ ok: true, message: 'v1.0.0' })
344
+ const mockCheckData = sandbox.stub().returns({ ok: true, message: '3 files' })
345
+ const mockCheckStale = sandbox.stub().returns({ ok: true, message: 'up to date' })
346
+ const mockCheckPdf = sandbox.stub().returns({ ok: true, message: 'no PDF' })
347
+ const mockCheckEpub = sandbox.stub().returns({ ok: true, message: 'no EPUB' })
348
+
349
+ const { runAllChecksWithSections } = await esmock('./index.js', {
350
+ './checks/environment/index.js': {
351
+ checkOsInfo: mockCheckOs,
352
+ checkCliVersion: mockCheckCli,
353
+ checkNodeVersion: mockCheckNode,
354
+ checkRuntimeInfo: mockCheckRuntime,
355
+ checkNpmAvailable: mockCheckNpm,
356
+ checkGitAvailable: mockCheckGit,
357
+ },
358
+ './checks/tools/index.js': {
359
+ checkPrinceAvailable: mockCheckPrince,
360
+ checkPandocAvailable: mockCheckPandoc,
361
+ },
362
+ './checks/project/index.js': {
363
+ checkQuireProject: mockCheckProject,
364
+ checkDependencies: mockCheckDeps,
365
+ checkOutdatedQuire11ty: mockCheckQuire11ty,
366
+ checkDataFiles: mockCheckData,
367
+ },
368
+ './checks/outputs/index.js': {
369
+ checkStaleBuild: mockCheckStale,
370
+ checkPdfOutput: mockCheckPdf,
371
+ checkEpubOutput: mockCheckEpub,
372
+ },
373
+ })
374
+
375
+ // Filter to environment section only (legacy array syntax)
376
+ const sections = await runAllChecksWithSections(['environment'])
377
+
378
+ t.is(sections.length, 1)
379
+ t.is(sections[0].section, 'Environment')
380
+ t.is(sections[0].results.length, 6)
381
+
382
+ // Verify only environment checks were called
383
+ t.true(mockCheckOs.calledOnce)
384
+ t.true(mockCheckCli.calledOnce)
385
+ t.true(mockCheckNode.calledOnce)
386
+ t.true(mockCheckRuntime.calledOnce)
387
+ t.true(mockCheckNpm.calledOnce)
388
+ t.true(mockCheckGit.calledOnce)
389
+
390
+ // Verify tools, project, and output checks were NOT called
391
+ t.false(mockCheckPrince.called)
392
+ t.false(mockCheckPandoc.called)
393
+ t.false(mockCheckProject.called)
394
+ t.false(mockCheckDeps.called)
395
+ t.false(mockCheckQuire11ty.called)
396
+ t.false(mockCheckData.called)
397
+ t.false(mockCheckStale.called)
398
+ t.false(mockCheckPdf.called)
399
+ t.false(mockCheckEpub.called)
400
+ })
401
+
402
+ test('runAllChecksWithSections filters by check ID', async (t) => {
403
+ const { sandbox } = t.context
404
+
405
+ // Create mock check functions
406
+ const mockCheckOs = sandbox.stub().returns({ ok: true, message: 'macOS 14 (arm64)' })
407
+ const mockCheckCli = sandbox.stub().returns({ ok: true, message: 'v1.0.0-rc.33' })
408
+ const mockCheckNode = sandbox.stub().returns({ ok: true, message: 'v22' })
409
+ const mockCheckRuntime = sandbox.stub().returns({ ok: true, message: 'Heap limit: 4096 MB' })
410
+ const mockCheckNpm = sandbox.stub().resolves({ ok: true, message: '10.2.4' })
411
+ const mockCheckGit = sandbox.stub().resolves({ ok: true, message: '2.43.0' })
412
+ const mockCheckPrince = sandbox.stub().returns({ ok: true, message: 'installed' })
413
+ const mockCheckPandoc = sandbox.stub().returns({ ok: true, message: 'installed' })
414
+ const mockCheckProject = sandbox.stub().returns({ ok: true, message: '.quire' })
415
+ const mockCheckDeps = sandbox.stub().returns({ ok: true, message: 'installed' })
416
+ const mockCheckQuire11ty = sandbox.stub().resolves({ ok: true, message: 'v1.0.0' })
417
+ const mockCheckData = sandbox.stub().returns({ ok: true, message: '3 files' })
418
+ const mockCheckStale = sandbox.stub().returns({ ok: true, message: 'up to date' })
419
+ const mockCheckPdf = sandbox.stub().returns({ ok: true, message: 'no PDF' })
420
+ const mockCheckEpub = sandbox.stub().returns({ ok: true, message: 'no EPUB' })
421
+
422
+ const { runAllChecksWithSections } = await esmock('./index.js', {
423
+ './checks/environment/index.js': {
424
+ checkOsInfo: mockCheckOs,
425
+ checkCliVersion: mockCheckCli,
426
+ checkNodeVersion: mockCheckNode,
427
+ checkRuntimeInfo: mockCheckRuntime,
428
+ checkNpmAvailable: mockCheckNpm,
429
+ checkGitAvailable: mockCheckGit,
430
+ },
431
+ './checks/tools/index.js': {
432
+ checkPrinceAvailable: mockCheckPrince,
433
+ checkPandocAvailable: mockCheckPandoc,
434
+ },
435
+ './checks/project/index.js': {
436
+ checkQuireProject: mockCheckProject,
437
+ checkDependencies: mockCheckDeps,
438
+ checkOutdatedQuire11ty: mockCheckQuire11ty,
439
+ checkDataFiles: mockCheckData,
440
+ },
441
+ './checks/outputs/index.js': {
442
+ checkStaleBuild: mockCheckStale,
443
+ checkPdfOutput: mockCheckPdf,
444
+ checkEpubOutput: mockCheckEpub,
445
+ },
446
+ })
447
+
448
+ // Filter to specific checks by ID (node and git from Environment)
449
+ const sections = await runAllChecksWithSections({ checks: ['node', 'git'] })
450
+
451
+ t.is(sections.length, 1)
452
+ t.is(sections[0].section, 'Environment')
453
+ t.is(sections[0].results.length, 2)
454
+
455
+ // Verify result names match the requested checks
456
+ const resultNames = sections[0].results.map((r) => r.name)
457
+ t.true(resultNames.includes('Node.js version'))
458
+ t.true(resultNames.includes('Git'))
459
+
460
+ // Verify only requested checks were called
461
+ t.true(mockCheckNode.calledOnce)
462
+ t.true(mockCheckGit.calledOnce)
463
+
464
+ // Verify other checks were NOT called
465
+ t.false(mockCheckOs.called)
466
+ t.false(mockCheckCli.called)
467
+ t.false(mockCheckRuntime.called)
468
+ t.false(mockCheckNpm.called)
469
+ t.false(mockCheckPrince.called)
470
+ t.false(mockCheckPandoc.called)
471
+ t.false(mockCheckProject.called)
472
+ t.false(mockCheckDeps.called)
473
+ t.false(mockCheckQuire11ty.called)
474
+ t.false(mockCheckData.called)
475
+ t.false(mockCheckStale.called)
476
+ t.false(mockCheckPdf.called)
477
+ t.false(mockCheckEpub.called)
478
+ })
479
+
480
+ test('runAllChecksWithSections filters checks across multiple sections', async (t) => {
481
+ const { sandbox } = t.context
482
+
483
+ // Create mock check functions
484
+ const mockCheckOs = sandbox.stub().returns({ ok: true, message: 'macOS 14 (arm64)' })
485
+ const mockCheckCli = sandbox.stub().returns({ ok: true, message: 'v1.0.0-rc.33' })
486
+ const mockCheckNode = sandbox.stub().returns({ ok: true, message: 'v22' })
487
+ const mockCheckRuntime = sandbox.stub().returns({ ok: true, message: 'Heap limit: 4096 MB' })
488
+ const mockCheckNpm = sandbox.stub().resolves({ ok: true, message: '10.2.4' })
489
+ const mockCheckGit = sandbox.stub().resolves({ ok: true, message: '2.43.0' })
490
+ const mockCheckPrince = sandbox.stub().returns({ ok: true, message: 'installed' })
491
+ const mockCheckPandoc = sandbox.stub().returns({ ok: true, message: 'installed' })
492
+ const mockCheckProject = sandbox.stub().returns({ ok: true, message: '.quire' })
493
+ const mockCheckDeps = sandbox.stub().returns({ ok: true, message: 'installed' })
494
+ const mockCheckQuire11ty = sandbox.stub().resolves({ ok: true, message: 'v1.0.0' })
495
+ const mockCheckData = sandbox.stub().returns({ ok: true, message: '3 files' })
496
+ const mockCheckStale = sandbox.stub().returns({ ok: true, message: 'up to date' })
497
+ const mockCheckPdf = sandbox.stub().returns({ ok: true, message: 'no PDF' })
498
+ const mockCheckEpub = sandbox.stub().returns({ ok: true, message: 'no EPUB' })
499
+
500
+ const { runAllChecksWithSections } = await esmock('./index.js', {
501
+ './checks/environment/index.js': {
502
+ checkOsInfo: mockCheckOs,
503
+ checkCliVersion: mockCheckCli,
504
+ checkNodeVersion: mockCheckNode,
505
+ checkRuntimeInfo: mockCheckRuntime,
506
+ checkNpmAvailable: mockCheckNpm,
507
+ checkGitAvailable: mockCheckGit,
508
+ },
509
+ './checks/tools/index.js': {
510
+ checkPrinceAvailable: mockCheckPrince,
511
+ checkPandocAvailable: mockCheckPandoc,
512
+ },
513
+ './checks/project/index.js': {
514
+ checkQuireProject: mockCheckProject,
515
+ checkDependencies: mockCheckDeps,
516
+ checkOutdatedQuire11ty: mockCheckQuire11ty,
517
+ checkDataFiles: mockCheckData,
518
+ },
519
+ './checks/outputs/index.js': {
520
+ checkStaleBuild: mockCheckStale,
521
+ checkPdfOutput: mockCheckPdf,
522
+ checkEpubOutput: mockCheckEpub,
523
+ },
524
+ })
525
+
526
+ // Filter to checks from different sections (node from Environment, pdf from Outputs)
527
+ const sections = await runAllChecksWithSections({ checks: ['node', 'pdf'] })
528
+
529
+ t.is(sections.length, 2)
530
+
531
+ // Verify Environment section has only node check
532
+ const envSection = sections.find((s) => s.section === 'Environment')
533
+ t.truthy(envSection)
534
+ t.is(envSection.results.length, 1)
535
+ t.is(envSection.results[0].name, 'Node.js version')
536
+
537
+ // Verify Outputs section has only pdf check
538
+ const outputsSection = sections.find((s) => s.section === 'Outputs')
539
+ t.truthy(outputsSection)
540
+ t.is(outputsSection.results.length, 1)
541
+ t.is(outputsSection.results[0].name, 'PDF output')
542
+
543
+ // Verify only requested checks were called
544
+ t.true(mockCheckNode.calledOnce)
545
+ t.true(mockCheckPdf.calledOnce)
546
+
547
+ // Project and Tools sections should not appear (no checks from them)
548
+ const projectSection = sections.find((s) => s.section === 'Project')
549
+ t.falsy(projectSection)
550
+ const toolsSection = sections.find((s) => s.section === 'Tools')
551
+ t.falsy(toolsSection)
552
+ })
553
+
554
+ test('runAllChecks handles async checks correctly', async (t) => {
555
+ const { sandbox } = t.context
556
+
557
+ // Mix of sync and async checks
558
+ const mockSyncCheck = sandbox.stub().returns({ ok: true, message: 'sync' })
559
+ const mockAsyncCheck = sandbox.stub().resolves({ ok: false, level: 'warn', message: 'async' })
560
+
561
+ const { runAllChecks } = await esmock('./index.js', {
562
+ './checks/environment/index.js': {
563
+ checkOsInfo: mockSyncCheck,
564
+ checkCliVersion: mockSyncCheck,
565
+ checkNodeVersion: mockSyncCheck,
566
+ checkRuntimeInfo: mockSyncCheck,
567
+ checkNpmAvailable: mockAsyncCheck,
568
+ checkGitAvailable: mockAsyncCheck,
569
+ },
570
+ './checks/tools/index.js': {
571
+ checkPrinceAvailable: mockSyncCheck,
572
+ checkPandocAvailable: mockSyncCheck,
573
+ },
574
+ './checks/project/index.js': {
575
+ checkQuireProject: mockSyncCheck,
576
+ checkDependencies: mockSyncCheck,
577
+ checkOutdatedQuire11ty: mockAsyncCheck,
578
+ checkDataFiles: mockSyncCheck,
579
+ },
580
+ './checks/outputs/index.js': {
581
+ checkStaleBuild: mockSyncCheck,
582
+ checkPdfOutput: mockSyncCheck,
583
+ checkEpubOutput: mockSyncCheck,
584
+ },
585
+ })
586
+
587
+ const results = await runAllChecks()
588
+
589
+ t.is(results.length, 15)
590
+
591
+ // Verify async results are properly awaited
592
+ const asyncResults = results.filter((r) => r.message === 'async')
593
+ t.is(asyncResults.length, 3)
594
+ for (const result of asyncResults) {
595
+ t.false(result.ok)
596
+ t.is(result.level, 'warn')
597
+ }
598
+ })
599
+
600
+ test('runAllChecks preserves all check result properties', async (t) => {
601
+ const { sandbox } = t.context
602
+
603
+ const fullResult = {
604
+ ok: false,
605
+ level: 'warn',
606
+ message: 'Test message',
607
+ remediation: 'Fix steps',
608
+ docsUrl: 'https://example.com',
609
+ }
610
+
611
+ const { runAllChecks } = await esmock('./index.js', {
612
+ './checks/environment/index.js': {
613
+ checkOsInfo: sandbox.stub().returns({ ok: true, message: 'macOS 14' }),
614
+ checkCliVersion: sandbox.stub().returns(fullResult),
615
+ checkNodeVersion: sandbox.stub().returns({ ok: true, message: null }),
616
+ checkRuntimeInfo: sandbox.stub().returns({ ok: true, message: 'Heap limit: 4096 MB' }),
617
+ checkNpmAvailable: sandbox.stub().resolves({ ok: true, message: '10.2.4' }),
618
+ checkGitAvailable: sandbox.stub().resolves({ ok: true, message: '2.43.0' }),
619
+ },
620
+ './checks/tools/index.js': {
621
+ checkPrinceAvailable: sandbox.stub().returns({ ok: true, message: 'installed' }),
622
+ checkPandocAvailable: sandbox.stub().returns({ ok: true, message: 'installed' }),
623
+ },
624
+ './checks/project/index.js': {
625
+ checkQuireProject: sandbox.stub().returns({ ok: true, message: null }),
626
+ checkDependencies: sandbox.stub().returns({ ok: true, message: 'installed' }),
627
+ checkOutdatedQuire11ty: sandbox.stub().resolves({ ok: true, message: null }),
628
+ checkDataFiles: sandbox.stub().returns({ ok: true, message: null }),
629
+ },
630
+ './checks/outputs/index.js': {
631
+ checkStaleBuild: sandbox.stub().returns({ ok: true, message: null }),
632
+ checkPdfOutput: sandbox.stub().returns({ ok: true, message: null }),
633
+ checkEpubOutput: sandbox.stub().returns({ ok: true, message: null }),
634
+ },
635
+ })
636
+
637
+ const results = await runAllChecks()
638
+ const cliResult = results.find((r) => r.name === 'Quire CLI version')
639
+
640
+ t.false(cliResult.ok)
641
+ t.is(cliResult.level, 'warn')
642
+ t.is(cliResult.message, 'Test message')
643
+ t.is(cliResult.remediation, 'Fix steps')
644
+ t.is(cliResult.docsUrl, 'https://example.com')
645
+ })
646
+
647
+ // ─────────────────────────────────────────────────────────────────────────────
648
+ // Timeout tests
649
+ // ─────────────────────────────────────────────────────────────────────────────
650
+
651
+ test('DEFAULT_CHECK_TIMEOUT is exported and has reasonable value', async (t) => {
652
+ const { DEFAULT_CHECK_TIMEOUT } = await import('./index.js')
653
+
654
+ t.is(typeof DEFAULT_CHECK_TIMEOUT, 'number')
655
+ t.is(DEFAULT_CHECK_TIMEOUT, 10000, 'default timeout should be 10 seconds')
656
+ })
657
+
658
+ test('runAllChecksWithSections handles slow checks with timeout', async (t) => {
659
+ const { sandbox } = t.context
660
+
661
+ // Create a check that takes longer than the timeout
662
+ const slowCheck = sandbox.stub().callsFake(() =>
663
+ new Promise((resolve) => setTimeout(() => resolve({ ok: true, message: 'slow' }), 200))
664
+ )
665
+ const fastCheck = sandbox.stub().returns({ ok: true, message: 'fast' })
666
+
667
+ const { runAllChecksWithSections } = await esmock('./index.js', {
668
+ './checks/environment/index.js': {
669
+ checkOsInfo: fastCheck,
670
+ checkCliVersion: fastCheck,
671
+ checkNodeVersion: slowCheck,
672
+ checkRuntimeInfo: fastCheck,
673
+ checkNpmAvailable: fastCheck,
674
+ checkGitAvailable: fastCheck,
675
+ },
676
+ './checks/tools/index.js': {
677
+ checkPrinceAvailable: fastCheck,
678
+ checkPandocAvailable: fastCheck,
679
+ },
680
+ './checks/project/index.js': {
681
+ checkQuireProject: fastCheck,
682
+ checkDependencies: fastCheck,
683
+ checkOutdatedQuire11ty: fastCheck,
684
+ checkDataFiles: fastCheck,
685
+ },
686
+ './checks/outputs/index.js': {
687
+ checkStaleBuild: fastCheck,
688
+ checkPdfOutput: fastCheck,
689
+ checkEpubOutput: fastCheck,
690
+ },
691
+ })
692
+
693
+ // Use a very short timeout (50ms) to trigger the timeout
694
+ const sections = await runAllChecksWithSections({ checks: ['node'], timeout: 50 })
695
+
696
+ t.is(sections.length, 1)
697
+ const nodeResult = sections[0].results[0]
698
+
699
+ // Should have timed out
700
+ t.false(nodeResult.ok)
701
+ t.is(nodeResult.level, 'timeout')
702
+ t.regex(nodeResult.message, /skipped.*timed out/)
703
+ t.truthy(nodeResult.remediation)
704
+ })
705
+
706
+ test('runAllChecksWithSections completes checks within timeout', async (t) => {
707
+ const { sandbox } = t.context
708
+
709
+ // Create a check that completes quickly
710
+ const fastCheck = sandbox.stub().returns({ ok: true, message: 'fast' })
711
+
712
+ const { runAllChecksWithSections } = await esmock('./index.js', {
713
+ './checks/environment/index.js': {
714
+ checkOsInfo: fastCheck,
715
+ checkCliVersion: fastCheck,
716
+ checkNodeVersion: fastCheck,
717
+ checkRuntimeInfo: fastCheck,
718
+ checkNpmAvailable: fastCheck,
719
+ checkGitAvailable: fastCheck,
720
+ },
721
+ './checks/tools/index.js': {
722
+ checkPrinceAvailable: fastCheck,
723
+ checkPandocAvailable: fastCheck,
724
+ },
725
+ './checks/project/index.js': {
726
+ checkQuireProject: fastCheck,
727
+ checkDependencies: fastCheck,
728
+ checkOutdatedQuire11ty: fastCheck,
729
+ checkDataFiles: fastCheck,
730
+ },
731
+ './checks/outputs/index.js': {
732
+ checkStaleBuild: fastCheck,
733
+ checkPdfOutput: fastCheck,
734
+ checkEpubOutput: fastCheck,
735
+ },
736
+ })
737
+
738
+ // Use a long timeout - check should complete well before
739
+ const sections = await runAllChecksWithSections({ checks: ['node'], timeout: 5000 })
740
+
741
+ t.is(sections.length, 1)
742
+ const nodeResult = sections[0].results[0]
743
+
744
+ // Should have completed successfully
745
+ t.true(nodeResult.ok)
746
+ t.is(nodeResult.message, 'fast')
747
+ })
748
+
749
+ test('runAllChecksWithSections includes check id in results', async (t) => {
750
+ const { sandbox } = t.context
751
+
752
+ const fastCheck = sandbox.stub().returns({ ok: true, message: 'fast' })
753
+
754
+ const { runAllChecksWithSections } = await esmock('./index.js', {
755
+ './checks/environment/index.js': {
756
+ checkOsInfo: fastCheck,
757
+ checkCliVersion: fastCheck,
758
+ checkNodeVersion: fastCheck,
759
+ checkRuntimeInfo: fastCheck,
760
+ checkNpmAvailable: fastCheck,
761
+ checkGitAvailable: fastCheck,
762
+ },
763
+ './checks/tools/index.js': {
764
+ checkPrinceAvailable: fastCheck,
765
+ checkPandocAvailable: fastCheck,
766
+ },
767
+ './checks/project/index.js': {
768
+ checkQuireProject: fastCheck,
769
+ checkDependencies: fastCheck,
770
+ checkOutdatedQuire11ty: fastCheck,
771
+ checkDataFiles: fastCheck,
772
+ },
773
+ './checks/outputs/index.js': {
774
+ checkStaleBuild: fastCheck,
775
+ checkPdfOutput: fastCheck,
776
+ checkEpubOutput: fastCheck,
777
+ },
778
+ })
779
+
780
+ const sections = await runAllChecksWithSections({ checks: ['node', 'npm'] })
781
+
782
+ // Each result should have an id property
783
+ for (const { results } of sections) {
784
+ for (const result of results) {
785
+ t.truthy(result.id, 'result should have id property')
786
+ t.is(typeof result.id, 'string')
787
+ }
788
+ }
789
+
790
+ // Verify specific IDs
791
+ const envSection = sections.find((s) => s.section === 'Environment')
792
+ const nodeResult = envSection.results.find((r) => r.name === 'Node.js version')
793
+ const npmResult = envSection.results.find((r) => r.name === 'npm')
794
+
795
+ t.is(nodeResult.id, 'node')
796
+ t.is(npmResult.id, 'npm')
797
+ })