@su-sws/synthetic-web-team 0.1.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/AGENTS.md +149 -0
- package/README.md +321 -0
- package/package.json +58 -0
- package/packages/cli/bin/sws.mjs +722 -0
- package/packages/cli/src/axe.mjs +164 -0
- package/packages/cli/src/browser.mjs +192 -0
- package/packages/cli/src/checks.mjs +1254 -0
- package/packages/cli/src/github.mjs +131 -0
- package/packages/cli/src/history.mjs +137 -0
- package/packages/cli/src/perf.mjs +245 -0
- package/packages/cli/src/preflight.mjs +185 -0
- package/packages/cli/src/report.mjs +315 -0
- package/packages/cli/src/states.mjs +556 -0
- package/packages/wizard/bin/wizard.mjs +767 -0
- package/packages/wizard/src/detect.mjs +135 -0
- package/packages/wizard/src/emit.mjs +553 -0
- package/skills/role-accessibility-lead/SKILL.md +183 -0
- package/skills/role-api-architect/SKILL.md +65 -0
- package/skills/role-backend-developer/SKILL.md +66 -0
- package/skills/role-compliance-officer/SKILL.md +73 -0
- package/skills/role-content-designer/SKILL.md +145 -0
- package/skills/role-devops/SKILL.md +200 -0
- package/skills/role-discoverability/SKILL.md +164 -0
- package/skills/role-frontend-developer/SKILL.md +167 -0
- package/skills/role-fullstack-developer/SKILL.md +56 -0
- package/skills/role-identity-engineer/SKILL.md +77 -0
- package/skills/role-information-architect/SKILL.md +136 -0
- package/skills/role-infrastructure-architect/SKILL.md +60 -0
- package/skills/role-qa-engineer/SKILL.md +81 -0
- package/skills/role-security-operations/SKILL.md +56 -0
- package/skills/role-software-architect/SKILL.md +75 -0
- package/skills/role-staff-technical-architect/SKILL.md +73 -0
- package/skills/role-strategist/SKILL.md +122 -0
- package/skills/role-user-researcher/SKILL.md +66 -0
- package/skills/role-ux-designer/SKILL.md +159 -0
- package/skills/sws-compliance-check/SKILL.md +153 -0
- package/skills/sws-decanter/SKILL.md +191 -0
- package/skills/sws-deploy/SKILL.md +162 -0
- package/skills/sws-diverge/SKILL.md +131 -0
- package/skills/sws-github/SKILL.md +171 -0
- package/skills/sws-install/SKILL.md +97 -0
- package/skills/sws-netlify/SKILL.md +110 -0
- package/skills/sws-onboard/SKILL.md +85 -0
- package/skills/sws-preflight/SKILL.md +87 -0
- package/skills/sws-prior-art/SKILL.md +137 -0
- package/skills/sws-vercel/SKILL.md +117 -0
- package/standards/fragments/global-footer.yml +137 -0
- package/standards/fragments/identity-bar.yml +180 -0
- package/standards/hosting/capabilities.yml +215 -0
- package/standards/hosting/github-pages.yml +306 -0
- package/standards/hosting/netlify.yml +234 -0
- package/standards/hosting/vercel.yml +284 -0
- package/standards/patterns/components.md +162 -0
- package/standards/patterns/content.md +130 -0
- package/standards/patterns/decanter.md +352 -0
- package/standards/patterns/discoverability.md +121 -0
- package/standards/patterns/forms.md +116 -0
- package/standards/patterns/ia.md +126 -0
- package/standards/patterns/motion.md +267 -0
- package/standards/patterns/sws-conventions.md +225 -0
- package/standards/policy/accessibility.md +241 -0
- package/standards/policy/brand.md +213 -0
- package/standards/policy/escalation.md +53 -0
- package/standards/policy/identity.md +96 -0
- package/standards/policy/minsec.md +119 -0
- package/standards/policy/minweb.md +87 -0
- package/standards/policy/privacy.md +114 -0
- package/standards/policy/procurement.md +79 -0
- package/standards/prior-art/README.md +205 -0
- package/standards/prior-art/catalog.yml +409 -0
- package/standards/prior-art/patterns/INDEX.md +53 -0
- package/standards/prior-art/repos.yml +734 -0
- package/standards/recipes/astro-ssr/RECIPE.md +274 -0
- package/standards/recipes/astro-ssr/acceptance.yml +168 -0
- package/standards/recipes/astro-static/RECIPE.md +468 -0
- package/standards/recipes/astro-static/acceptance.yml +800 -0
- package/standards/recipes/next-ssr/RECIPE.md +407 -0
- package/standards/recipes/next-ssr/acceptance.yml +187 -0
- package/standards/scope.md +111 -0
- package/standards/stack/performance-budget.yml +95 -0
- package/standards/stack/reference-versions.yml +168 -0
- package/standards/stack/requirements.yml +154 -0
|
@@ -0,0 +1,1254 @@
|
|
|
1
|
+
// All checks live here. Each returns an array of findings:
|
|
2
|
+
// { id, state, detail, fix? }
|
|
3
|
+
// state is one of: pass | fail | unknown | not_applicable
|
|
4
|
+
//
|
|
5
|
+
// THE RULE THAT MATTERS: a check that cannot run returns `unknown`, never
|
|
6
|
+
// `pass`. This is not theoretical. A harness in this project once printed
|
|
7
|
+
// "TOTAL VIOLATIONS: 0" while axe had silently failed to load. A report that
|
|
8
|
+
// says clean when it means did not run is worse than no report.
|
|
9
|
+
//
|
|
10
|
+
// Second rule: report per item. "The footer is wrong" is not actionable.
|
|
11
|
+
// "Trademarks points at the wrong URL" is.
|
|
12
|
+
|
|
13
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
14
|
+
import { join, relative, dirname } from 'node:path';
|
|
15
|
+
import { execFileSync } from 'node:child_process';
|
|
16
|
+
import { parse } from 'node-html-parser';
|
|
17
|
+
import YAML from 'yaml';
|
|
18
|
+
import { RESULTS_PATH as AXE_RESULTS_PATH, SCHEMA as AXE_SCHEMA } from './axe.mjs';
|
|
19
|
+
import { RESULTS_PATH as PERF_RESULTS_PATH, SCHEMA as PERF_SCHEMA } from './perf.mjs';
|
|
20
|
+
import { RESULTS_PATH as STATE_RESULTS_PATH, SCHEMA as STATE_SCHEMA } from './states.mjs';
|
|
21
|
+
import { newestMtime } from './browser.mjs';
|
|
22
|
+
|
|
23
|
+
const read = (p) => readFileSync(p, 'utf8');
|
|
24
|
+
const readYaml = (p) => YAML.parse(read(p));
|
|
25
|
+
const ok = (id, detail) => ({ id, state: 'pass', detail });
|
|
26
|
+
const bad = (id, detail, fix) => ({ id, state: 'fail', detail, fix });
|
|
27
|
+
const dunno = (id, detail) => ({ id, state: 'unknown', detail });
|
|
28
|
+
const na = (id, detail) => ({ id, state: 'not_applicable', detail });
|
|
29
|
+
|
|
30
|
+
// --------------------------------------------------------------------------
|
|
31
|
+
// helpers
|
|
32
|
+
// --------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
export function findHtml(dir) {
|
|
35
|
+
if (!existsSync(dir)) return [];
|
|
36
|
+
const out = [];
|
|
37
|
+
(function walk(d) {
|
|
38
|
+
for (const name of readdirSync(d)) {
|
|
39
|
+
const p = join(d, name);
|
|
40
|
+
if (statSync(p).isDirectory()) walk(p);
|
|
41
|
+
else if (name.endsWith('.html')) out.push(p);
|
|
42
|
+
}
|
|
43
|
+
})(dir);
|
|
44
|
+
return out.sort();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function pkg(root) {
|
|
48
|
+
const p = join(root, 'package.json');
|
|
49
|
+
return existsSync(p) ? JSON.parse(read(p)) : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function deps(root) {
|
|
53
|
+
const j = pkg(root);
|
|
54
|
+
if (!j) return {};
|
|
55
|
+
return { ...(j.dependencies || {}), ...(j.devDependencies || {}) };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function installed(root, name) {
|
|
59
|
+
const p = join(root, 'node_modules', name, 'package.json');
|
|
60
|
+
return existsSync(p) ? JSON.parse(read(p)) : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// --------------------------------------------------------------------------
|
|
64
|
+
// footer: reads the contract, never hardcodes the link set
|
|
65
|
+
// --------------------------------------------------------------------------
|
|
66
|
+
|
|
67
|
+
export function footer({ root, html, standards }) {
|
|
68
|
+
const contractPath = join(standards, 'fragments', 'global-footer.yml');
|
|
69
|
+
if (!existsSync(contractPath)) {
|
|
70
|
+
return [dunno('footer.global.present', `contract not found at ${contractPath}`)];
|
|
71
|
+
}
|
|
72
|
+
if (!html.length) {
|
|
73
|
+
return [dunno('footer.global.present', 'no built HTML found; run the build first')];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const c = readYaml(contractPath);
|
|
77
|
+
const expected = [...c.resource_links, ...c.policy_links];
|
|
78
|
+
const out = [];
|
|
79
|
+
|
|
80
|
+
const missingFooter = [];
|
|
81
|
+
for (const f of html) {
|
|
82
|
+
const doc = parse(read(f));
|
|
83
|
+
if (!doc.querySelector('footer')) missingFooter.push(relative(root, f));
|
|
84
|
+
}
|
|
85
|
+
out.push(
|
|
86
|
+
missingFooter.length
|
|
87
|
+
? bad('footer.global.present', `no <footer> on ${missingFooter.length} page(s): ${missingFooter.slice(0, 3).join(', ')}`,
|
|
88
|
+
'Add the Global Footer to the shared layout.')
|
|
89
|
+
: ok('footer.global.present', `present on all ${html.length} page(s)`)
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Link set, checked on the first page. The footer is in a shared layout, so
|
|
93
|
+
// per-page divergence is a different (rarer) problem than a wrong contract.
|
|
94
|
+
const doc = parse(read(html[0]));
|
|
95
|
+
const footEl = doc.querySelector('footer');
|
|
96
|
+
if (!footEl) {
|
|
97
|
+
out.push(dunno('footer.global.exact', 'no footer to inspect'));
|
|
98
|
+
out.push(dunno('footer.no-additions', 'no footer to inspect'));
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const anchors = footEl.querySelectorAll('a').map((a) => ({
|
|
103
|
+
label: a.text.replace(/\s+/g, ' ').trim(),
|
|
104
|
+
href: (a.getAttribute('href') || '').trim(),
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
const problems = [];
|
|
108
|
+
for (const want of expected) {
|
|
109
|
+
const hit = anchors.find((a) => a.label === want.label);
|
|
110
|
+
if (!hit) problems.push(`missing link "${want.label}"`);
|
|
111
|
+
else if (hit.href !== want.href) {
|
|
112
|
+
problems.push(`"${want.label}" points at ${hit.href}, contract says ${want.href}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const order = expected.map((e) => e.label).filter((l) => anchors.some((a) => a.label === l));
|
|
116
|
+
const actualOrder = anchors.map((a) => a.label).filter((l) => order.includes(l));
|
|
117
|
+
if (order.join('|') !== actualOrder.join('|')) problems.push('link order differs from the contract');
|
|
118
|
+
|
|
119
|
+
out.push(
|
|
120
|
+
problems.length
|
|
121
|
+
? bad('footer.global.exact', problems.join('; '),
|
|
122
|
+
'The Global Footer is immutable. The contract is standards/fragments/global-footer.yml.')
|
|
123
|
+
: ok('footer.global.exact', `all ${expected.length} links match label, href, and order`)
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const extra = anchors.filter((a) => !expected.some((e) => e.label === a.label));
|
|
127
|
+
out.push(
|
|
128
|
+
extra.length
|
|
129
|
+
? bad('footer.no-additions',
|
|
130
|
+
`${extra.length} link(s) not in the contract: ${extra.map((e) => `"${e.label}"`).join(', ')}`,
|
|
131
|
+
'Unit links belong in a LOCAL footer above the Global Footer, not inside it.')
|
|
132
|
+
: ok('footer.no-additions', 'no additional links inside the Global Footer')
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const text = footEl.text.replace(/\s+/g, ' ');
|
|
136
|
+
const missingCopy = (c.copyright?.lines || []).filter((l) => !text.includes(l.replace('©', '©')));
|
|
137
|
+
out.push(
|
|
138
|
+
missingCopy.length
|
|
139
|
+
? bad('footer.copyright', `missing: ${missingCopy.join(' / ')}`, 'Both copyright lines are part of the fragment.')
|
|
140
|
+
: ok('footer.copyright', 'copyright lines present')
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const a11yLink = anchors.find((a) => a.label === 'Accessibility');
|
|
144
|
+
out.push(
|
|
145
|
+
a11yLink ? ok('a11y.link-present', `Accessibility link -> ${a11yLink.href}`)
|
|
146
|
+
: bad('a11y.link-present', 'no Accessibility link in the footer',
|
|
147
|
+
'MinWeb requires a barrier-reporting link. Normally https://www.stanford.edu/site/accessibility')
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// --------------------------------------------------------------------------
|
|
154
|
+
// identity bar: DOM POSITION, not string order
|
|
155
|
+
// --------------------------------------------------------------------------
|
|
156
|
+
|
|
157
|
+
export function identity({ root, html, standards, dist }) {
|
|
158
|
+
if (!html.length) return [dunno('brand.identity-bar.present', 'no built HTML found')];
|
|
159
|
+
|
|
160
|
+
const SELECTORS = ['#su-identity', '.su-identity', '[data-su-identity]', '#stanford-identity'];
|
|
161
|
+
const out = [];
|
|
162
|
+
const missing = [];
|
|
163
|
+
const badOrder = [];
|
|
164
|
+
|
|
165
|
+
for (const f of html) {
|
|
166
|
+
const doc = parse(read(f));
|
|
167
|
+
const body = doc.querySelector('body');
|
|
168
|
+
if (!body) { missing.push(relative(root, f)); continue; }
|
|
169
|
+
|
|
170
|
+
const kids = body.childNodes.filter((n) => n.nodeType === 1);
|
|
171
|
+
const idx = kids.findIndex((el) => SELECTORS.some((s) => {
|
|
172
|
+
try { return el.matches?.(s); } catch { return false; }
|
|
173
|
+
}));
|
|
174
|
+
|
|
175
|
+
if (idx === -1) { missing.push(relative(root, f)); continue; }
|
|
176
|
+
|
|
177
|
+
// Permitted: index 0, or index 1 preceded only by a skip link.
|
|
178
|
+
const first = kids[0];
|
|
179
|
+
const firstIsSkip =
|
|
180
|
+
first?.rawTagName === 'a' &&
|
|
181
|
+
(/skip/i.test(first.getAttribute('class') || '') || /skip/i.test(first.text || ''));
|
|
182
|
+
if (!(idx === 0 || (idx === 1 && firstIsSkip))) {
|
|
183
|
+
badOrder.push(`${relative(root, f)}: identity bar is child ${idx}, preceded by <${kids.slice(0, idx).map((k) => k.rawTagName).join(', ')}>`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
out.push(
|
|
188
|
+
missing.length
|
|
189
|
+
? bad('brand.identity-bar.present', `not found on ${missing.length} page(s): ${missing.slice(0, 3).join(', ')}`,
|
|
190
|
+
'Add the Stanford Identity Bar to the shared layout.')
|
|
191
|
+
: ok('brand.identity-bar.present', `present on all ${html.length} page(s)`)
|
|
192
|
+
);
|
|
193
|
+
out.push(
|
|
194
|
+
badOrder.length
|
|
195
|
+
? bad('brand.identity-bar.nothing-above', badOrder.slice(0, 3).join(' | '),
|
|
196
|
+
'Only a skip navigation link may precede the Identity Bar.')
|
|
197
|
+
: ok('brand.identity-bar.nothing-above', 'nothing precedes it except the skip link')
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// ---- exact markup, which is what fixes the height ----------------------
|
|
201
|
+
//
|
|
202
|
+
// CLASSES, NOT PIXELS. A measured height would be the obvious check and it
|
|
203
|
+
// would be flaky: the bar measures 28.8px at 1280px and 30.1px at 1600px,
|
|
204
|
+
// because the line box depends on the metrics of whichever font actually
|
|
205
|
+
// resolves for --font-stanford. A brand check that drifts by a pixel gets
|
|
206
|
+
// switched off. The classes are exact, deterministic, and on Decanter's scale
|
|
207
|
+
// they can only produce the Stanford height.
|
|
208
|
+
//
|
|
209
|
+
// This exists because this project shipped a bar at roughly 44px -- `py-12` in
|
|
210
|
+
// a centred wrapper with `font-serif text-24 md:text-27` -- which was visibly
|
|
211
|
+
// taller than every other Stanford site.
|
|
212
|
+
const fragPath = standards && join(standards, 'fragments', 'identity-bar.yml');
|
|
213
|
+
if (!fragPath || !existsSync(fragPath)) {
|
|
214
|
+
out.push(dunno('brand.identity-bar.exact', `contract not found at ${fragPath ?? 'standards/fragments/identity-bar.yml'}`));
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let frag;
|
|
219
|
+
try { frag = readYaml(fragPath); }
|
|
220
|
+
catch (err) { out.push(dunno('brand.identity-bar.exact', `contract is not valid YAML: ${err.message}`)); return out; }
|
|
221
|
+
|
|
222
|
+
const problems = [];
|
|
223
|
+
const classesOf = (el) => (el?.getAttribute('class') || '').split(/\s+/).filter(Boolean);
|
|
224
|
+
const offend = (list, patterns) => (patterns ?? [])
|
|
225
|
+
.flatMap((rx) => list.filter((c) => new RegExp(rx).test(c)).map((c) => ({ c, rx })));
|
|
226
|
+
|
|
227
|
+
// The bar is in a shared layout, so the first page is representative; a
|
|
228
|
+
// per-page divergence is a different and rarer problem.
|
|
229
|
+
const doc = parse(read(html[0]));
|
|
230
|
+
const bar = SELECTORS.map((sel) => { try { return doc.querySelector(sel); } catch { return null; } }).find(Boolean);
|
|
231
|
+
|
|
232
|
+
if (!bar) {
|
|
233
|
+
out.push(dunno('brand.identity-bar.exact', 'no Identity Bar element to inspect'));
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const barClasses = classesOf(bar);
|
|
238
|
+
for (const want of frag.container?.classes ?? []) {
|
|
239
|
+
if (!barClasses.includes(want)) problems.push(`bar is missing \`${want}\``);
|
|
240
|
+
}
|
|
241
|
+
for (const { c, rx } of offend(barClasses, frag.container?.disallowed_class_patterns)) {
|
|
242
|
+
problems.push(`bar has \`${c}\`, which changes its height (matches ${rx})`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const link = bar.querySelector('a');
|
|
246
|
+
if (!link) {
|
|
247
|
+
problems.push('bar contains no link');
|
|
248
|
+
} else {
|
|
249
|
+
const linkClasses = classesOf(link);
|
|
250
|
+
for (const want of frag.link?.classes ?? []) {
|
|
251
|
+
if (!linkClasses.includes(want)) problems.push(`logo link is missing \`${want}\``);
|
|
252
|
+
}
|
|
253
|
+
for (const { c, rx } of offend(linkClasses, frag.link?.disallowed_class_patterns)) {
|
|
254
|
+
problems.push(`logo link has \`${c}\`, which changes its size (matches ${rx})`);
|
|
255
|
+
}
|
|
256
|
+
const href = (link.getAttribute('href') || '').trim();
|
|
257
|
+
if (frag.link?.href && href !== frag.link.href) {
|
|
258
|
+
problems.push(`logo link points at ${href || '(nothing)'}, contract says ${frag.link.href}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ---- the Stanford ligature font -----------------------------------------
|
|
263
|
+
//
|
|
264
|
+
// If the bar is on the page, this font is required. Decanter's
|
|
265
|
+
// --font-stanford falls back to Source Serif 4, so omitting it does not error
|
|
266
|
+
// -- the wordmark just renders in the wrong typeface, and the bar comes out
|
|
267
|
+
// 28.8px instead of 30.8px. It looks like a rendering quirk rather than a
|
|
268
|
+
// brand defect, which is exactly why it needs a check.
|
|
269
|
+
//
|
|
270
|
+
// Decanter 8 publishes no font assets, so "we installed Decanter" is not
|
|
271
|
+
// enough: the @font-face has to be declared by the project.
|
|
272
|
+
if (frag.font?.required) {
|
|
273
|
+
const css = [];
|
|
274
|
+
(function walk(d) {
|
|
275
|
+
if (!existsSync(d)) return;
|
|
276
|
+
for (const name of readdirSync(d)) {
|
|
277
|
+
const fp = join(d, name);
|
|
278
|
+
if (statSync(fp).isDirectory()) walk(fp);
|
|
279
|
+
else if (fp.endsWith('.css')) css.push(read(fp));
|
|
280
|
+
}
|
|
281
|
+
})(dist ?? '');
|
|
282
|
+
// Inline <style> counts too, and so does a linked stylesheet we cannot see
|
|
283
|
+
// (a CDN URL in the markup), so search the HTML as well.
|
|
284
|
+
const haystack = [...css, ...html.map(read)].join('\n');
|
|
285
|
+
|
|
286
|
+
const family = frag.font.family ?? 'Stanford';
|
|
287
|
+
const declared = new RegExp(`@font-face[^}]*font-family\\s*:\\s*['"]?${family}['"]?`, 'i').test(haystack)
|
|
288
|
+
|| new RegExp(`font-family\\s*:\\s*['"]?${family}['"]?[^}]*src\\s*:`, 'i').test(haystack);
|
|
289
|
+
const referenced = (frag.font.sources ?? [])
|
|
290
|
+
.some((src) => src.url && haystack.includes(src.url.split('/').pop()));
|
|
291
|
+
|
|
292
|
+
out.push(declared || referenced
|
|
293
|
+
? ok('brand.identity-bar.font-loaded', `${family} font face declared`)
|
|
294
|
+
: bad('brand.identity-bar.font-loaded',
|
|
295
|
+
`the Identity Bar is present but no @font-face for "${family}" was found in the build`,
|
|
296
|
+
`Without it, --font-stanford falls back to Source Serif 4: the wordmark renders in the wrong typeface and the bar measures ${frag.measured?.bar_height_px ? '28.8px instead of ' + frag.measured.bar_height_px + 'px' : 'the wrong height'}. Decanter 8 ships no font assets, so declare it yourself — the CSS is in standards/fragments/identity-bar.yml under font.css, served from the University Communications media CDN.`));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
out.push(problems.length
|
|
300
|
+
? bad('brand.identity-bar.exact', problems.slice(0, 4).join('; '),
|
|
301
|
+
`The Identity Bar is brand furniture with a fixed height. Use the markup in standards/fragments/identity-bar.yml verbatim: ${(frag.container?.classes ?? []).join(' ')} on the container, and \`logo inline-block text-20 leading-none\` on the link. Not font-serif -- \`logo\` is a Decanter component class carrying the Stanford font and its ligatures.`)
|
|
302
|
+
: ok('brand.identity-bar.exact', `matches the contract (extracted ${frag.extracted ?? 'unknown'}), ~${frag.measured?.bar_height_px ?? '?'}px tall`));
|
|
303
|
+
|
|
304
|
+
return out;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// --------------------------------------------------------------------------
|
|
308
|
+
// decanter: check the whole dependency tree, not just the top level
|
|
309
|
+
// --------------------------------------------------------------------------
|
|
310
|
+
|
|
311
|
+
export function decanter({ root }) {
|
|
312
|
+
const out = [];
|
|
313
|
+
const d = installed(root, 'decanter');
|
|
314
|
+
const declared = deps(root).decanter;
|
|
315
|
+
|
|
316
|
+
if (!d) {
|
|
317
|
+
out.push(declared
|
|
318
|
+
? dunno('decanter.installed', `declared as "${declared}" but not installed; run install first`)
|
|
319
|
+
: na('decanter.installed', 'decanter is not a dependency of this project'));
|
|
320
|
+
} else {
|
|
321
|
+
const major = String(d.version).split('.')[0];
|
|
322
|
+
out.push(major === '8'
|
|
323
|
+
? ok('decanter.installed', `decanter ${d.version}`)
|
|
324
|
+
: bad('decanter.installed', `decanter resolved to ${d.version}, expected 8.x`,
|
|
325
|
+
'v7 is a Tailwind 3 JS preset and v8 is CSS-first. Install decanter@^8, or note that the git v8 branch form is also valid.'));
|
|
326
|
+
|
|
327
|
+
out.push(d.main === 'src/css/index.css'
|
|
328
|
+
? ok('decanter.css-first', `main is ${d.main}`)
|
|
329
|
+
: bad('decanter.css-first', `main is "${d.main}", expected src/css/index.css`,
|
|
330
|
+
'A tailwind.config.js main field means v7 is installed.'));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Nested tailwind is the silent v7 tell.
|
|
334
|
+
const nested = join(root, 'node_modules', 'decanter', 'node_modules', 'tailwindcss');
|
|
335
|
+
out.push(existsSync(nested)
|
|
336
|
+
? bad('decanter.no-nested-tailwind', 'node_modules/decanter/node_modules/tailwindcss exists',
|
|
337
|
+
'v7 crept in beneath a v4 top level. Delete node_modules and the lockfile, then reinstall.')
|
|
338
|
+
: ok('decanter.no-nested-tailwind', 'no nested tailwind under decanter'));
|
|
339
|
+
|
|
340
|
+
const tw = installed(root, 'tailwindcss');
|
|
341
|
+
out.push(!tw
|
|
342
|
+
? dunno('decanter.tailwind-major', 'tailwindcss not installed')
|
|
343
|
+
: String(tw.version).startsWith('4')
|
|
344
|
+
? ok('decanter.tailwind-major', `tailwindcss ${tw.version}`)
|
|
345
|
+
: bad('decanter.tailwind-major', `tailwindcss ${tw.version}, expected 4.x`,
|
|
346
|
+
'Decanter 8 requires Tailwind 4.'));
|
|
347
|
+
|
|
348
|
+
const cfg = ['tailwind.config.js', 'tailwind.config.mjs', 'tailwind.config.ts']
|
|
349
|
+
.filter((f) => existsSync(join(root, f)));
|
|
350
|
+
out.push(cfg.length
|
|
351
|
+
? bad('decanter.no-js-config', `found ${cfg.join(', ')}`,
|
|
352
|
+
'Decanter 8 has no JS config. Its presence signals a v7 mental model.')
|
|
353
|
+
: ok('decanter.no-js-config', 'no tailwind JS config'));
|
|
354
|
+
|
|
355
|
+
out.push(deps(root)['@astrojs/tailwind']
|
|
356
|
+
? bad('decanter.no-dead-integration', '@astrojs/tailwind is a dependency',
|
|
357
|
+
'Dead package: supports neither current Astro nor Tailwind 4. Use @tailwindcss/vite.')
|
|
358
|
+
: ok('decanter.no-dead-integration', '@astrojs/tailwind absent'));
|
|
359
|
+
|
|
360
|
+
// Entry CSS: redundant tailwind import, and the @source myth.
|
|
361
|
+
const cssFiles = [];
|
|
362
|
+
(function walk(d) {
|
|
363
|
+
if (!existsSync(d)) return;
|
|
364
|
+
for (const n of readdirSync(d)) {
|
|
365
|
+
const p = join(d, n);
|
|
366
|
+
if (statSync(p).isDirectory()) { if (n !== 'node_modules') walk(p); }
|
|
367
|
+
else if (n.endsWith('.css')) cssFiles.push(p);
|
|
368
|
+
}
|
|
369
|
+
})(join(root, 'src'));
|
|
370
|
+
|
|
371
|
+
const entry = cssFiles.find((f) => /@import\s+['"]decanter['"]/.test(read(f)));
|
|
372
|
+
if (!entry) {
|
|
373
|
+
out.push(d ? bad('decanter.entry-css', 'no CSS file imports decanter',
|
|
374
|
+
"Add @import 'decanter'; to your entry CSS. That is the whole integration.")
|
|
375
|
+
: na('decanter.entry-css', 'decanter not in use'));
|
|
376
|
+
} else {
|
|
377
|
+
const body = read(entry);
|
|
378
|
+
out.push(ok('decanter.entry-css', `${relative(root, entry)} imports decanter`));
|
|
379
|
+
if (/@import\s+['"]tailwindcss['"]/.test(body)) {
|
|
380
|
+
out.push(bad('decanter.no-redundant-tailwind-import',
|
|
381
|
+
`${relative(root, entry)} imports both tailwindcss and decanter`,
|
|
382
|
+
'Decanter imports Tailwind itself. Harmless but redundant, ~340 bytes.'));
|
|
383
|
+
} else {
|
|
384
|
+
out.push(ok('decanter.no-redundant-tailwind-import', 'no redundant tailwindcss import'));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// --------------------------------------------------------------------------
|
|
391
|
+
// seo
|
|
392
|
+
// --------------------------------------------------------------------------
|
|
393
|
+
|
|
394
|
+
export function seo({ root, html, dist }) {
|
|
395
|
+
if (!html.length) return [dunno('seo.title-unique', 'no built HTML found')];
|
|
396
|
+
const out = [];
|
|
397
|
+
const titles = [];
|
|
398
|
+
const noDesc = [];
|
|
399
|
+
const noCanon = [];
|
|
400
|
+
|
|
401
|
+
for (const f of html) {
|
|
402
|
+
const doc = parse(read(f));
|
|
403
|
+
const t = doc.querySelector('title')?.text?.trim();
|
|
404
|
+
titles.push({ f: relative(root, f), t });
|
|
405
|
+
const desc = doc.querySelector('meta[name="description"]')?.getAttribute('content')?.trim();
|
|
406
|
+
if (!desc) noDesc.push(relative(root, f));
|
|
407
|
+
if (!doc.querySelector('link[rel="canonical"]')) noCanon.push(relative(root, f));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const empty = titles.filter((x) => !x.t);
|
|
411
|
+
const seen = new Map();
|
|
412
|
+
for (const x of titles) if (x.t) seen.set(x.t, (seen.get(x.t) || 0) + 1);
|
|
413
|
+
const dupes = [...seen].filter(([, n]) => n > 1).map(([t]) => t);
|
|
414
|
+
|
|
415
|
+
out.push(empty.length || dupes.length
|
|
416
|
+
? bad('seo.title-unique',
|
|
417
|
+
[empty.length && `${empty.length} page(s) with no title`,
|
|
418
|
+
dupes.length && `duplicate title(s): ${dupes.slice(0, 2).map((d) => `"${d}"`).join(', ')}`]
|
|
419
|
+
.filter(Boolean).join('; '),
|
|
420
|
+
'Every page needs a unique, non-empty title.')
|
|
421
|
+
: ok('seo.title-unique', `${titles.length} unique titles`));
|
|
422
|
+
|
|
423
|
+
out.push(noDesc.length
|
|
424
|
+
? bad('seo.meta-description', `${noDesc.length} page(s) without one: ${noDesc.slice(0, 3).join(', ')}`)
|
|
425
|
+
: ok('seo.meta-description', 'all pages have a meta description'));
|
|
426
|
+
|
|
427
|
+
out.push(noCanon.length
|
|
428
|
+
? bad('seo.canonical', `${noCanon.length} page(s) without a canonical link`,
|
|
429
|
+
'Requires `site` set in the framework config. Missing `site` also silently breaks the sitemap.')
|
|
430
|
+
: ok('seo.canonical', 'canonical links present'));
|
|
431
|
+
|
|
432
|
+
const sitemap = ['sitemap-index.xml', 'sitemap.xml'].find((f) => existsSync(join(dist, f)));
|
|
433
|
+
out.push(sitemap
|
|
434
|
+
? ok('seo.sitemap', `${sitemap} emitted`)
|
|
435
|
+
: bad('seo.sitemap', 'no sitemap in the build output',
|
|
436
|
+
'Add @astrojs/sitemap and set `site` in the config.'));
|
|
437
|
+
|
|
438
|
+
const robotsPath = join(dist, 'robots.txt');
|
|
439
|
+
if (!existsSync(robotsPath)) {
|
|
440
|
+
out.push(bad('seo.robots', 'no robots.txt', 'Add public/robots.txt with a Sitemap: reference.'));
|
|
441
|
+
out.push(bad('seo.robots-ai-sections', 'no robots.txt'));
|
|
442
|
+
} else {
|
|
443
|
+
const r = read(robotsPath);
|
|
444
|
+
out.push(/sitemap:/i.test(r)
|
|
445
|
+
? ok('seo.robots', 'robots.txt references the sitemap')
|
|
446
|
+
: bad('seo.robots', 'robots.txt does not reference the sitemap'));
|
|
447
|
+
const AI = ['GPTBot', 'OAI-SearchBot', 'ClaudeBot', 'Claude-SearchBot', 'PerplexityBot', 'Google-Extended'];
|
|
448
|
+
const named = AI.filter((a) => r.includes(a));
|
|
449
|
+
out.push(named.length
|
|
450
|
+
? ok('seo.robots-ai-sections', `addresses ${named.length} AI user agent(s)`)
|
|
451
|
+
: { id: 'seo.robots-ai-sections', state: 'fail',
|
|
452
|
+
detail: 'no AI crawler rules; silence is a default rather than a decision',
|
|
453
|
+
fix: 'Allow retrieval bots (OAI-SearchBot, Claude-SearchBot, PerplexityBot). Whether to allow TRAINING crawlers is a unit policy call, not ours to impose.' });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const llms = existsSync(join(dist, 'llms.txt'));
|
|
457
|
+
out.push(llms
|
|
458
|
+
? { id: 'seo.no-llms-txt-on-marketing', state: 'fail',
|
|
459
|
+
detail: 'llms.txt present',
|
|
460
|
+
fix: '97% of published llms.txt files get zero requests and AI search crawlers read HTML directly. It is fetched by IDE coding agents, so it belongs on documentation sites only.' }
|
|
461
|
+
: ok('seo.no-llms-txt-on-marketing', 'no llms.txt, correct for a unit site'));
|
|
462
|
+
|
|
463
|
+
const ld = html.some((f) => read(f).includes('application/ld+json'));
|
|
464
|
+
out.push(ld
|
|
465
|
+
? ok('seo.structured-data', 'JSON-LD present (for rich results, NOT an AI-citation lever)')
|
|
466
|
+
: bad('seo.structured-data', 'no JSON-LD found',
|
|
467
|
+
'Add EducationalOrganization or Organization plus BreadcrumbList. For rich results only.'));
|
|
468
|
+
|
|
469
|
+
return out;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// --------------------------------------------------------------------------
|
|
473
|
+
// a11y: needs a real browser, so this reports unknown by design
|
|
474
|
+
// --------------------------------------------------------------------------
|
|
475
|
+
// axe: this module does not run axe, it reads what `sws a11y` recorded. Keeping
|
|
476
|
+
// the browser out of `sws check` means check stays fast and installable
|
|
477
|
+
// everywhere; the tradeoff is that a missing results file is a normal state and
|
|
478
|
+
// must read as `unknown` rather than as a failure.
|
|
479
|
+
//
|
|
480
|
+
// Four things become `unknown`, and the third is the one people get wrong:
|
|
481
|
+
// 1. no results file axe was never run
|
|
482
|
+
// 2. status is not `ok` deps missing, no browser, or a partial run
|
|
483
|
+
// 3. results predate the build a stale pass is not a pass
|
|
484
|
+
// 4. schema mismatch do not guess at an old shape
|
|
485
|
+
// --------------------------------------------------------------------------
|
|
486
|
+
|
|
487
|
+
export function axeFinding({ root, dist, html }) {
|
|
488
|
+
// The finding id is repeated literally at every call site rather than held in
|
|
489
|
+
// a variable. Deliberate: scripts/validate-criteria.mjs proves every emitted
|
|
490
|
+
// id has a criterion by grepping this file statically, and a variable is
|
|
491
|
+
// invisible to it. The gate caught exactly that when this module was written.
|
|
492
|
+
const p = join(root, AXE_RESULTS_PATH);
|
|
493
|
+
|
|
494
|
+
if (!existsSync(p)) {
|
|
495
|
+
return dunno('a11y.axe.routes', !html.length
|
|
496
|
+
? 'no built HTML found; run the build, then `sws a11y`'
|
|
497
|
+
: 'axe has not been run. Run `sws a11y` (needs @playwright/test and @axe-core/playwright in this project)');
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
let r;
|
|
501
|
+
try { r = JSON.parse(read(p)); }
|
|
502
|
+
catch (err) { return dunno('a11y.axe.routes', `${AXE_RESULTS_PATH} is not valid JSON (${err.message}); re-run \`sws a11y\``); }
|
|
503
|
+
|
|
504
|
+
if (r.schema !== AXE_SCHEMA) {
|
|
505
|
+
return dunno('a11y.axe.routes', `${AXE_RESULTS_PATH} is schema ${r.schema ?? '?'}, this CLI expects ${AXE_SCHEMA}; re-run \`sws a11y\``);
|
|
506
|
+
}
|
|
507
|
+
if (r.status !== 'ok') {
|
|
508
|
+
return dunno('a11y.axe.routes', `axe did not complete (${r.status}): ${r.detail ?? 'no detail recorded'}`);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// Staleness. If anything in dist is newer than the recorded build state, the
|
|
512
|
+
// results describe a build that no longer exists.
|
|
513
|
+
if (dist && existsSync(dist)) {
|
|
514
|
+
const now = newestMtime(dist);
|
|
515
|
+
if (typeof r.distMtime === 'number' && now > r.distMtime + 1000) {
|
|
516
|
+
return dunno('a11y.axe.routes', `axe results predate the current build (build is ${Math.round((now - r.distMtime) / 1000)}s newer); re-run \`sws a11y\``);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const routes = Array.isArray(r.routes) ? r.routes : [];
|
|
521
|
+
if (!routes.length) return dunno('a11y.axe.routes', 'axe results record no routes; re-run `sws a11y`');
|
|
522
|
+
|
|
523
|
+
// Every built page should have been audited. A results file covering three of
|
|
524
|
+
// twelve routes is not evidence about the other nine.
|
|
525
|
+
if (html.length && routes.length < html.length) {
|
|
526
|
+
return dunno('a11y.axe.routes', `axe covered ${routes.length} of ${html.length} built page(s); re-run \`sws a11y\``);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const offenders = routes.filter((x) => (x.counts?.violations ?? 0) > 0);
|
|
530
|
+
const total = offenders.reduce((a, x) => a + x.counts.violations, 0);
|
|
531
|
+
const engine = r.versions?.axe ? `axe ${r.versions.axe}` : 'axe';
|
|
532
|
+
|
|
533
|
+
if (!offenders.length) {
|
|
534
|
+
return ok('a11y.axe.routes', `${engine}: 0 violations across ${routes.length} route(s) at ${r.tags?.join(', ') ?? 'WCAG 2.1 AA'}`);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// Per item, not in aggregate. "The page has violations" is not actionable.
|
|
538
|
+
const detail = offenders.slice(0, 4).map((x) => {
|
|
539
|
+
const worst = x.violations.slice(0, 3)
|
|
540
|
+
.map((v) => `${v.id}${v.nodeCount > 1 ? ` x${v.nodeCount}` : ''}`).join(', ');
|
|
541
|
+
return `${x.route}: ${worst}`;
|
|
542
|
+
}).join(' | ');
|
|
543
|
+
|
|
544
|
+
return bad('a11y.axe.routes',
|
|
545
|
+
`${engine}: ${total} violation(s) on ${offenders.length} of ${routes.length} route(s). ${detail}`,
|
|
546
|
+
`Full detail with selectors and help URLs is in ${AXE_RESULTS_PATH}. Each violation lists a helpUrl explaining the fix.`);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// --------------------------------------------------------------------------
|
|
550
|
+
// interactive states: hover and focus feedback that colour vision is not
|
|
551
|
+
// required to perceive. Reads what `sws a11y` recorded, same contract as axe.
|
|
552
|
+
// --------------------------------------------------------------------------
|
|
553
|
+
// axe cannot see this at all -- it audits a static snapshot, and a hover state
|
|
554
|
+
// only exists while a pointer is over the element -- so a control whose entire
|
|
555
|
+
// hover state is `hover:text-poppy-light` reads as a clean page. The runner in
|
|
556
|
+
// states.mjs drives a real mouse and a real Tab key and diffs computed style,
|
|
557
|
+
// classifying each changed property as a colour or as a non-colour cue.
|
|
558
|
+
//
|
|
559
|
+
// Three findings, because they are three different obligations and one number
|
|
560
|
+
// would not tell anyone what to do:
|
|
561
|
+
// focus-visible something must change on keyboard focus at all (SC 2.4.7)
|
|
562
|
+
// focus-non-color that change must not be colour alone (SC 1.4.1, G183)
|
|
563
|
+
// hover-non-color the same for hover, where a hover state exists
|
|
564
|
+
// --------------------------------------------------------------------------
|
|
565
|
+
|
|
566
|
+
export function statesFinding({ root, dist, html }) {
|
|
567
|
+
const p = join(root, STATE_RESULTS_PATH);
|
|
568
|
+
const spread = (why) => [
|
|
569
|
+
dunno('a11y.state.focus-visible', why),
|
|
570
|
+
dunno('a11y.state.focus-non-color', why),
|
|
571
|
+
dunno('a11y.state.hover-non-color', why),
|
|
572
|
+
];
|
|
573
|
+
|
|
574
|
+
if (!existsSync(p)) {
|
|
575
|
+
return spread(!html.length
|
|
576
|
+
? 'no built HTML found; run the build, then `sws a11y`'
|
|
577
|
+
: 'hover and focus states have not been measured. Run `sws a11y` (needs @playwright/test in this project)');
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
let r;
|
|
581
|
+
try { r = JSON.parse(read(p)); }
|
|
582
|
+
catch (err) { return spread(`${STATE_RESULTS_PATH} is not valid JSON (${err.message}); re-run \`sws a11y\``); }
|
|
583
|
+
|
|
584
|
+
if (r.schema !== STATE_SCHEMA) {
|
|
585
|
+
return spread(`${STATE_RESULTS_PATH} is schema ${r.schema ?? '?'}, this CLI expects ${STATE_SCHEMA}; re-run \`sws a11y\``);
|
|
586
|
+
}
|
|
587
|
+
if (r.status !== 'ok') {
|
|
588
|
+
return spread(`the state audit did not complete (${r.status}): ${r.detail ?? 'no detail recorded'}`);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// Same staleness rule as axe: results describing a build that no longer
|
|
592
|
+
// exists are not evidence about this one.
|
|
593
|
+
if (dist && existsSync(dist)) {
|
|
594
|
+
const now = newestMtime(dist);
|
|
595
|
+
if (typeof r.distMtime === 'number' && now > r.distMtime + 1000) {
|
|
596
|
+
return spread(`state results predate the current build (build is ${Math.round((now - r.distMtime) / 1000)}s newer); re-run \`sws a11y\``);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const routes = Array.isArray(r.routes) ? r.routes : [];
|
|
601
|
+
if (!routes.length) return spread('state results record no routes; re-run `sws a11y`');
|
|
602
|
+
if (html.length && routes.length < html.length) {
|
|
603
|
+
return spread(`the state audit covered ${routes.length} of ${html.length} built page(s); re-run \`sws a11y\``);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const all = routes.flatMap((x) => (x.findings ?? []).map((f) => ({ ...f, route: x.route })));
|
|
607
|
+
const pick = (state, verdict) => all.filter((f) => f.state === state && f.verdict === verdict);
|
|
608
|
+
|
|
609
|
+
// Per item, and named the way a person can find it in a template: the
|
|
610
|
+
// element path, its label, and the state classes it already carries.
|
|
611
|
+
const detail = (list) => list.slice(0, 4).map((f) => {
|
|
612
|
+
const where = f.label ? `"${f.label.slice(0, 32)}"` : f.target;
|
|
613
|
+
const inst = f.occurrences > 1 ? ` x${f.occurrences}` : '';
|
|
614
|
+
const cls = f.classes?.length ? ` [${f.classes.slice(0, 2).join(' ')}]` : '';
|
|
615
|
+
return `${f.route} ${where}${inst}${cls}`;
|
|
616
|
+
}).join(' | ') + (list.length > 4 ? ` | +${list.length - 4} more, see ${STATE_RESULTS_PATH}` : '');
|
|
617
|
+
|
|
618
|
+
const scale = `${r.totals.controls} distinct control shape(s) across ${routes.length} route(s)`;
|
|
619
|
+
const out = [];
|
|
620
|
+
|
|
621
|
+
const noChange = pick('focus', 'no-change');
|
|
622
|
+
out.push(noChange.length
|
|
623
|
+
? bad('a11y.state.focus-visible',
|
|
624
|
+
`${noChange.length} control shape(s) change nothing on keyboard focus. ${detail(noChange)}`,
|
|
625
|
+
'Every focusable control needs a visible focus state. Decanter and the browser both give you one for free; the usual cause is a removed outline. Restore it, or add `focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2`.')
|
|
626
|
+
: ok('a11y.state.focus-visible', `every control reached by Tab changes visibly on focus (${scale})`));
|
|
627
|
+
|
|
628
|
+
const focusColour = pick('focus', 'colour-only');
|
|
629
|
+
out.push(focusColour.length
|
|
630
|
+
? bad('a11y.state.focus-non-color',
|
|
631
|
+
`${focusColour.length} control shape(s) signal focus with colour alone. ${detail(focusColour)}`,
|
|
632
|
+
'Add a non-colour cue to the focus state. For text links and buttons the best fix is an underline: `focus-visible:underline`, or `focus-visible:no-underline` where the link is underlined at rest. For icon and image controls use an outline or a border instead.')
|
|
633
|
+
: ok('a11y.state.focus-non-color', `focus states carry a non-colour cue (${scale})`));
|
|
634
|
+
|
|
635
|
+
const hoverColour = pick('hover', 'colour-only');
|
|
636
|
+
out.push(hoverColour.length
|
|
637
|
+
? bad('a11y.state.hover-non-color',
|
|
638
|
+
`${hoverColour.length} control shape(s) change colour and nothing else on hover. ${detail(hoverColour)}`,
|
|
639
|
+
'Add a non-colour cue: `hover:underline`, or `hover:no-underline` where the link is underlined at rest. `hocus:underline` covers hover and focus together. For icon and image controls use an outline, a border, or a shape change.')
|
|
640
|
+
: ok('a11y.state.hover-non-color', `hover states carry a non-colour cue (${scale})`));
|
|
641
|
+
|
|
642
|
+
return out;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// --------------------------------------------------------------------------
|
|
646
|
+
|
|
647
|
+
export function a11y({ root, dist, html }) {
|
|
648
|
+
const out = [];
|
|
649
|
+
|
|
650
|
+
out.push(axeFinding({ root, dist, html }));
|
|
651
|
+
out.push(...statesFinding({ root, dist, html }));
|
|
652
|
+
|
|
653
|
+
// Static structural checks that genuinely can run here.
|
|
654
|
+
if (html.length) {
|
|
655
|
+
const noLang = [], noSkip = [], badHeads = [], noAlt = [];
|
|
656
|
+
for (const f of html) {
|
|
657
|
+
const doc = parse(read(f));
|
|
658
|
+
const htmlEl = doc.querySelector('html');
|
|
659
|
+
if (!htmlEl?.getAttribute('lang')) noLang.push(relative(root, f));
|
|
660
|
+
|
|
661
|
+
const firstA = doc.querySelector('body a');
|
|
662
|
+
if (!firstA || !/skip/i.test((firstA.getAttribute('class') || '') + firstA.text)) {
|
|
663
|
+
noSkip.push(relative(root, f));
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const heads = doc.querySelectorAll('h1,h2,h3,h4,h5,h6')
|
|
667
|
+
.map((h) => Number(h.rawTagName[1]));
|
|
668
|
+
const h1s = heads.filter((n) => n === 1).length;
|
|
669
|
+
if (h1s !== 1) badHeads.push(`${relative(root, f)}: ${h1s} h1`);
|
|
670
|
+
else for (let i = 1; i < heads.length; i++) {
|
|
671
|
+
if (heads[i] - heads[i - 1] > 1) { badHeads.push(`${relative(root, f)}: h${heads[i - 1]} -> h${heads[i]}`); break; }
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const imgs = doc.querySelectorAll('img').filter((im) => im.getAttribute('alt') === undefined);
|
|
675
|
+
if (imgs.length) noAlt.push(`${relative(root, f)}: ${imgs.length}`);
|
|
676
|
+
}
|
|
677
|
+
out.push(noLang.length ? bad('a11y.lang', `missing lang on ${noLang.length} page(s)`) : ok('a11y.lang', 'html lang set'));
|
|
678
|
+
out.push(noSkip.length ? bad('a11y.skiplink', `no skip link first on ${noSkip.length} page(s)`,
|
|
679
|
+
'A skip navigation link must be the first focusable element.') : ok('a11y.skiplink', 'skip link is first'));
|
|
680
|
+
out.push(badHeads.length ? bad('a11y.heading-order', badHeads.slice(0, 3).join(' | '),
|
|
681
|
+
'Exactly one h1 per page, no skipped levels. Heading level is structure, not size.') : ok('a11y.heading-order', 'heading structure valid'));
|
|
682
|
+
out.push(noAlt.length ? bad('a11y.image-alt', `images without alt: ${noAlt.slice(0, 3).join(', ')}`,
|
|
683
|
+
'Decorative images use alt="". Every img needs the attribute.') : ok('a11y.image-alt', 'all images have alt'));
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
out.push(dunno('a11y.manual-checklist',
|
|
687
|
+
'automation covers roughly 30% of issues per ODA guidance; the manual WCAG 2.1 AA checklist is not automatable'));
|
|
688
|
+
return out;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// --------------------------------------------------------------------------
|
|
692
|
+
// perf: reads what `sws perf` recorded, same contract as axe. Budgets
|
|
693
|
+
// first-party uncompressed bytes and request counts, not Lighthouse scores;
|
|
694
|
+
// the reasoning is in standards/stack/performance-budget.yml.
|
|
695
|
+
// --------------------------------------------------------------------------
|
|
696
|
+
|
|
697
|
+
export function perf({ root, dist, html }) {
|
|
698
|
+
const p = join(root, PERF_RESULTS_PATH);
|
|
699
|
+
|
|
700
|
+
if (!existsSync(p)) {
|
|
701
|
+
return [dunno('perf.budget', !html.length
|
|
702
|
+
? 'no built HTML found; run the build, then `sws perf`'
|
|
703
|
+
: 'performance budget has not been measured. Run `sws perf` (needs @playwright/test in this project)')];
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
let r;
|
|
707
|
+
try { r = JSON.parse(read(p)); }
|
|
708
|
+
catch (err) { return [dunno('perf.budget', `${PERF_RESULTS_PATH} is not valid JSON (${err.message}); re-run \`sws perf\``)]; }
|
|
709
|
+
|
|
710
|
+
if (r.schema !== PERF_SCHEMA) {
|
|
711
|
+
return [dunno('perf.budget', `${PERF_RESULTS_PATH} is schema ${r.schema ?? '?'}, this CLI expects ${PERF_SCHEMA}; re-run \`sws perf\``)];
|
|
712
|
+
}
|
|
713
|
+
if (r.status !== 'ok') {
|
|
714
|
+
return [dunno('perf.budget', `measurement did not complete (${r.status}): ${r.detail ?? 'no detail recorded'}`)];
|
|
715
|
+
}
|
|
716
|
+
if (dist && existsSync(dist) && typeof r.distMtime === 'number') {
|
|
717
|
+
const now = newestMtime(dist);
|
|
718
|
+
if (now > r.distMtime + 1000) {
|
|
719
|
+
return [dunno('perf.budget', `budget results predate the current build (build is ${Math.round((now - r.distMtime) / 1000)}s newer); re-run \`sws perf\``)];
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const routes = Array.isArray(r.routes) ? r.routes : [];
|
|
723
|
+
if (!routes.length) return [dunno('perf.budget', 'budget results record no routes; re-run `sws perf`')];
|
|
724
|
+
if (html.length && routes.length < html.length) {
|
|
725
|
+
return [dunno('perf.budget', `budget covered ${routes.length} of ${html.length} built page(s); re-run \`sws perf\``)];
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
const worst = r.totals.worst_total_kb;
|
|
729
|
+
const limit = r.budget.limits.total_kb;
|
|
730
|
+
const overridden = Object.keys(r.budget.overrides ?? {});
|
|
731
|
+
const suffix = overridden.length ? `. Project override on ${overridden.join(', ')}` : '';
|
|
732
|
+
|
|
733
|
+
if (!r.breaches.length) {
|
|
734
|
+
return [ok('perf.budget',
|
|
735
|
+
`worst route ${worst} KB of ${limit} KB budget, first-party uncompressed, across ${routes.length} route(s)${suffix}`)];
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// Per item. "Over budget" is not actionable; "js is 210 KB against 150" is.
|
|
739
|
+
const detail = r.breaches.slice(0, 4)
|
|
740
|
+
.map((b) => `${b.route} ${b.key.replace(/_kb$/, '')} ${b.actual}${b.key.endsWith('_kb') ? ' KB' : ''} > ${b.limit}`)
|
|
741
|
+
.join(' | ');
|
|
742
|
+
|
|
743
|
+
return [bad('perf.budget', `${r.breaches.length} budget breach(es). ${detail}`,
|
|
744
|
+
`Full measurement in ${PERF_RESULTS_PATH}. The usual wins on a Stanford site are fewer and correctly sized images, fewer islands, and no client-side framework for static content. If the budget is genuinely wrong for this site, override it in .sws/manifest.yml under performance_budget with a reason.`)];
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// --------------------------------------------------------------------------
|
|
748
|
+
// secrets: the only blocking check
|
|
749
|
+
// --------------------------------------------------------------------------
|
|
750
|
+
|
|
751
|
+
const SECRET_PATTERNS = [
|
|
752
|
+
[/AKIA[0-9A-Z]{16}/, 'AWS access key id'],
|
|
753
|
+
[/gh[pousr]_[A-Za-z0-9]{36,}/, 'GitHub token'],
|
|
754
|
+
[/sk_live_[A-Za-z0-9]{20,}/, 'Stripe live secret key'],
|
|
755
|
+
[/-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/, 'private key'],
|
|
756
|
+
[/eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\./, 'JWT'],
|
|
757
|
+
[/(?:api[_-]?key|secret|password|token)\s*[:=]\s*['"][A-Za-z0-9!@#$%^&*_\-]{16,}['"]/i, 'hardcoded credential'],
|
|
758
|
+
];
|
|
759
|
+
|
|
760
|
+
export function secrets({ root }) {
|
|
761
|
+
let files;
|
|
762
|
+
try {
|
|
763
|
+
files = execFileSync('git', ['ls-files'], { cwd: root, encoding: 'utf8' })
|
|
764
|
+
.split('\n').filter(Boolean);
|
|
765
|
+
} catch {
|
|
766
|
+
return [dunno('minweb.no-secrets', 'not a git repository, or git unavailable; cannot enumerate tracked files')];
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
const SKIP = /\.(png|jpe?g|gif|webp|avif|ico|woff2?|ttf|otf|eot|pdf|zip|mp4|webm)$/i;
|
|
770
|
+
const hits = [];
|
|
771
|
+
for (const f of files) {
|
|
772
|
+
if (SKIP.test(f) || f.includes('node_modules')) continue;
|
|
773
|
+
const p = join(root, f);
|
|
774
|
+
if (!existsSync(p) || statSync(p).size > 512 * 1024) continue;
|
|
775
|
+
const body = read(p);
|
|
776
|
+
for (const [re, label] of SECRET_PATTERNS) {
|
|
777
|
+
const m = body.match(re);
|
|
778
|
+
if (m) {
|
|
779
|
+
const line = body.slice(0, m.index).split('\n').length;
|
|
780
|
+
hits.push(`${f}:${line} looks like a ${label}`);
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
if (!hits.length) return [ok('minweb.no-secrets', `${files.length} tracked files scanned, nothing found`)];
|
|
787
|
+
|
|
788
|
+
return [{
|
|
789
|
+
id: 'minweb.no-secrets',
|
|
790
|
+
state: 'fail',
|
|
791
|
+
blocking: true,
|
|
792
|
+
detail: hits.slice(0, 5).join('; '),
|
|
793
|
+
fix: [
|
|
794
|
+
'ROTATE THE CREDENTIAL NOW. It is already in git history and blocking a deploy does not un-leak it.',
|
|
795
|
+
'Then remove it from history (git filter-repo or BFG), then force-push.',
|
|
796
|
+
'Then move the value into Vault or your host\'s environment settings.',
|
|
797
|
+
].join(' '),
|
|
798
|
+
}];
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// --------------------------------------------------------------------------
|
|
802
|
+
// hygiene, build, workflow, manifest, ownership
|
|
803
|
+
// --------------------------------------------------------------------------
|
|
804
|
+
|
|
805
|
+
export function hygiene({ root, html, manifest }) {
|
|
806
|
+
const out = [];
|
|
807
|
+
if (!html.length) {
|
|
808
|
+
out.push(dunno('minweb.https-only', 'no built HTML found'));
|
|
809
|
+
} else {
|
|
810
|
+
const bads = [];
|
|
811
|
+
for (const f of html) {
|
|
812
|
+
const m = read(f).match(/http:\/\/(?!localhost|127\.0\.0\.1)[a-z0-9.-]*stanford\.edu/gi);
|
|
813
|
+
if (m) bads.push(`${relative(root, f)}: ${[...new Set(m)].slice(0, 2).join(', ')}`);
|
|
814
|
+
}
|
|
815
|
+
out.push(bads.length
|
|
816
|
+
? bad('minweb.https-only', bads.slice(0, 3).join(' | '), 'Use https:// for Stanford URLs.')
|
|
817
|
+
: ok('minweb.https-only', 'no insecure Stanford URLs'));
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const major = Number(process.versions.node.split('.')[0]);
|
|
821
|
+
out.push(major >= 22
|
|
822
|
+
? ok('build.node-major', `node ${process.versions.node}`)
|
|
823
|
+
: bad('build.node-major', `node ${process.versions.node}; 22.12+ needed, 24 LTS preferred`));
|
|
824
|
+
|
|
825
|
+
const fa = Object.keys(deps(root)).filter((d) => /^@fortawesome\/pro-/.test(d));
|
|
826
|
+
out.push(fa.length
|
|
827
|
+
? bad('security.no-fontawesome-pro', `${fa.join(', ')}`,
|
|
828
|
+
'Licence-gated with a preinstall token check. A unit site inheriting this gets an install failure and a licence nobody mentioned. Use Heroicons.')
|
|
829
|
+
: ok('security.no-fontawesome-pro', 'no FontAwesome Pro packages'));
|
|
830
|
+
|
|
831
|
+
// Consent UI, and the framing matters more than the detection.
|
|
832
|
+
//
|
|
833
|
+
// A cookie banner is NOT forbidden at Stanford. It is simply not required:
|
|
834
|
+
// the Global Footer's Privacy link satisfies the disclosure obligation, so a
|
|
835
|
+
// banner is a deliberate addition rather than a default. Any unit is free to
|
|
836
|
+
// add one.
|
|
837
|
+
//
|
|
838
|
+
// So this reports an UNDECLARED one, exactly like the third-party tooling
|
|
839
|
+
// check below it, and passes once the project records the choice in
|
|
840
|
+
// .sws/manifest.yml under `privacy.consent_tooling`. An earlier version
|
|
841
|
+
// reported the mere presence of consent UI as a failure, which asserted a
|
|
842
|
+
// prohibition Stanford does not have -- and this project has no business
|
|
843
|
+
// inventing policy.
|
|
844
|
+
//
|
|
845
|
+
// This was two substrings anywhere in the document -- /cookie/ AND
|
|
846
|
+
// /(accept|consent)/ -- and it produced a false failure on this project's own
|
|
847
|
+
// site, which is the worst possible place for it to fire. "cookie" came from
|
|
848
|
+
// the MANDATED Global Footer link (`title="Privacy and cookie policy"`, part
|
|
849
|
+
// of the byte-exact contract every compliant Stanford site must carry), and
|
|
850
|
+
// "accept" came from prose about accepted risks. So the check fired on the one
|
|
851
|
+
// element the project requires, on a page with no banner anywhere.
|
|
852
|
+
//
|
|
853
|
+
// A check that fails a correct site gets the whole tool switched off. Now it
|
|
854
|
+
// looks for the two things a real banner actually has: a container named like
|
|
855
|
+
// one, or a control whose OWN text asks you to accept cookies.
|
|
856
|
+
//
|
|
857
|
+
// An earlier version of this fix ALSO skipped the whole <footer>, on the
|
|
858
|
+
// theory that its content is mandated. That was unnecessary -- the mandated
|
|
859
|
+
// link's text is "Privacy", which matches neither pattern -- and it opened a
|
|
860
|
+
// real evasion gap: a banner placed inside the footer went undetected. Scan
|
|
861
|
+
// everything.
|
|
862
|
+
const CONSENT_CONTAINER = /(?:id|class)="[^"]*(?:cookie[-_ ]?(?:consent|banner|notice|bar|law)|consent[-_ ]?(?:banner|bar|manager|modal)|gdpr[-_ ]?(?:banner|notice))[^"]*"/i;
|
|
863
|
+
const CONSENT_CONTROL = /\b(?:accept|allow|agree\s+to|opt\s+in\s+to)\b[^<>]{0,30}\bcookies?\b|\bcookies?\b[^<>]{0,30}\b(?:accept(?:ed)?|allow(?:ed)?)\b/i;
|
|
864
|
+
|
|
865
|
+
const bannerHits = [];
|
|
866
|
+
for (const f of html) {
|
|
867
|
+
const doc = parse(read(f));
|
|
868
|
+
const markup = read(f);
|
|
869
|
+
if (CONSENT_CONTAINER.test(markup)) { bannerHits.push(`${relative(root, f)}: element named like a consent banner`); continue; }
|
|
870
|
+
for (const el of doc.querySelectorAll('button, a, [role="button"]')) {
|
|
871
|
+
const label = (el.text || '').replace(/\s+/g, ' ').trim();
|
|
872
|
+
if (label && CONSENT_CONTROL.test(label)) {
|
|
873
|
+
bannerHits.push(`${relative(root, f)}: control labelled "${label.slice(0, 40)}"`);
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
const declared = String(manifest?.privacy?.consent_tooling ?? '').trim();
|
|
879
|
+
if (!bannerHits.length) {
|
|
880
|
+
out.push(ok('privacy.consent-ui-declared', 'no consent UI in the built output'));
|
|
881
|
+
} else if (declared) {
|
|
882
|
+
out.push(ok('privacy.consent-ui-declared',
|
|
883
|
+
`consent UI present and declared in .sws/manifest.yml: ${declared.split('\n')[0].slice(0, 80)}`));
|
|
884
|
+
} else {
|
|
885
|
+
out.push(bad('privacy.consent-ui-declared',
|
|
886
|
+
`consent UI present but not declared: ${bannerHits.slice(0, 3).join('; ')}`,
|
|
887
|
+
'This is allowed — no cookie banner is required at Stanford, but none is forbidden either. Record it in .sws/manifest.yml under privacy.consent_tooling with the reason, consult the University Privacy Office, and remember the banner is now yours to keep accessible.'));
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
return out;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
export function build({ root, dist, manifest }) {
|
|
894
|
+
const out = [];
|
|
895
|
+
out.push(existsSync(dist)
|
|
896
|
+
? ok('build.succeeds', `build output present at ${relative(root, dist) || dist}`)
|
|
897
|
+
: dunno('build.succeeds', `no build output at ${dist}; run the build first`));
|
|
898
|
+
|
|
899
|
+
const cfg = ['astro.config.mjs', 'astro.config.js', 'astro.config.ts']
|
|
900
|
+
.map((f) => join(root, f)).find(existsSync);
|
|
901
|
+
if (!cfg) {
|
|
902
|
+
out.push(na('build.static-output', 'no Astro config; not an Astro project'));
|
|
903
|
+
out.push(na('build.base-path', 'no Astro config'));
|
|
904
|
+
out.push(na('astro.no-hybrid-output', 'no Astro config'));
|
|
905
|
+
out.push(na('astro.adapter-configured', 'no Astro config'));
|
|
906
|
+
return out;
|
|
907
|
+
}
|
|
908
|
+
const c = read(cfg);
|
|
909
|
+
out.push(/output:\s*['"]static['"]/.test(c) || !/output:/.test(c)
|
|
910
|
+
? ok('build.static-output', "output is 'static' (or default)")
|
|
911
|
+
: bad('build.static-output', 'output is not static', "GitHub Pages needs output: 'static'. 'hybrid' no longer exists."));
|
|
912
|
+
|
|
913
|
+
out.push(/\bsite:\s*['"]https?:\/\//.test(c)
|
|
914
|
+
? ok('build.site-set', '`site` is set')
|
|
915
|
+
: bad('build.site-set', '`site` is not set in the Astro config',
|
|
916
|
+
'Without it the sitemap emits nothing and canonical URLs are wrong. Most common configuration miss.'));
|
|
917
|
+
|
|
918
|
+
out.push(/\bbase:\s*['"]/.test(c)
|
|
919
|
+
? ok('build.base-path', '`base` is set for a subpath deploy')
|
|
920
|
+
: na('build.base-path', 'no `base` set; correct unless deploying to a subpath'));
|
|
921
|
+
|
|
922
|
+
// 'hybrid' was removed from Astro. Its presence signals a config copied from
|
|
923
|
+
// an older project, and it fails at build time rather than silently -- but
|
|
924
|
+
// catching it here is cheap and gives an earlier, clearer message.
|
|
925
|
+
out.push(/output:\s*['"]hybrid['"]/.test(c)
|
|
926
|
+
? bad('astro.no-hybrid-output', "output: 'hybrid' is set",
|
|
927
|
+
"'hybrid' was removed from Astro. Use 'server' plus per-page `export const prerender = true`, or 'static'.")
|
|
928
|
+
: ok('astro.no-hybrid-output', "no 'hybrid' output"));
|
|
929
|
+
|
|
930
|
+
// A mismatch here is a real and quiet failure: @astrojs/vercel configured on
|
|
931
|
+
// a project deploying to Netlify builds successfully and serves wrongly.
|
|
932
|
+
const isServer = /output:\s*['"]server['"]/.test(c);
|
|
933
|
+
const adapterMatch = c.match(/@astrojs\/(netlify|vercel)/);
|
|
934
|
+
if (!isServer) {
|
|
935
|
+
out.push(na('astro.adapter-configured', "output is not 'server'; no host adapter required"));
|
|
936
|
+
} else if (!adapterMatch) {
|
|
937
|
+
out.push(bad('astro.adapter-configured', "output: 'server' is set but no @astrojs/netlify or @astrojs/vercel adapter import was found",
|
|
938
|
+
'Add and configure the host adapter matching the recorded hosting.provider in .sws/manifest.yml.'));
|
|
939
|
+
} else {
|
|
940
|
+
const adapterHost = adapterMatch[1];
|
|
941
|
+
const recordedHost = manifest?.hosting?.provider;
|
|
942
|
+
if (!recordedHost) {
|
|
943
|
+
out.push(dunno('astro.adapter-configured', `@astrojs/${adapterHost} adapter found, but .sws/manifest.yml records no hosting.provider to compare it against`));
|
|
944
|
+
} else if (recordedHost === adapterHost) {
|
|
945
|
+
out.push(ok('astro.adapter-configured', `@astrojs/${adapterHost} adapter matches hosting.provider: ${recordedHost}`));
|
|
946
|
+
} else {
|
|
947
|
+
out.push(bad('astro.adapter-configured', `@astrojs/${adapterHost} adapter configured, but .sws/manifest.yml records hosting.provider: ${recordedHost}`,
|
|
948
|
+
'A mismatched adapter builds successfully and serves wrongly. Fix the adapter import or the manifest.'));
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
return out;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
export function workflow({ root }) {
|
|
955
|
+
// .github/workflows is a REPOSITORY-level concern, so walk up to find it. A
|
|
956
|
+
// site can legitimately live in a subdirectory (this project's own docs site
|
|
957
|
+
// does) with CI defined at the repo root. Looking only in the project
|
|
958
|
+
// directory reported a false failure on a correctly configured repo.
|
|
959
|
+
let dir = null;
|
|
960
|
+
let d = root;
|
|
961
|
+
for (let i = 0; i < 6; i++) {
|
|
962
|
+
const c = join(d, '.github', 'workflows');
|
|
963
|
+
if (existsSync(c)) { dir = c; break; }
|
|
964
|
+
const up = dirname(d);
|
|
965
|
+
if (up === d) break;
|
|
966
|
+
d = up;
|
|
967
|
+
}
|
|
968
|
+
if (!dir) {
|
|
969
|
+
return [
|
|
970
|
+
bad('workflow.push-to-main-deploys', 'no .github/workflows directory',
|
|
971
|
+
'Push to main should deploy. Pull requests are first-class but never required.'),
|
|
972
|
+
dunno('workflow.report-reaches-a-reader', 'no workflows to inspect'),
|
|
973
|
+
];
|
|
974
|
+
}
|
|
975
|
+
const files = readdirSync(dir).filter((f) => /\.ya?ml$/.test(f)).map((f) => join(dir, f));
|
|
976
|
+
const all = files.map(read).join('\n---\n');
|
|
977
|
+
const out = [];
|
|
978
|
+
|
|
979
|
+
out.push(/on:[\s\S]{0,200}push:[\s\S]{0,120}branches:\s*\[?\s*['"]?main/.test(all)
|
|
980
|
+
? ok('workflow.push-to-main-deploys', 'triggers on push to main')
|
|
981
|
+
: bad('workflow.push-to-main-deploys', 'no push-to-main trigger found',
|
|
982
|
+
'Many campus editors work through the GitHub web UI, which is push-to-main by construction.'));
|
|
983
|
+
|
|
984
|
+
const perms = [];
|
|
985
|
+
if (!/issues:\s*write/.test(all)) perms.push('issues: write');
|
|
986
|
+
if (!/pull-requests:\s*write/.test(all)) perms.push('pull-requests: write');
|
|
987
|
+
out.push(perms.length
|
|
988
|
+
? bad('workflow.report-reaches-a-reader', `missing permissions: ${perms.join(', ')}`,
|
|
989
|
+
'Without these the advisory report is produced and nobody sees it, which is worse than not running it.')
|
|
990
|
+
: ok('workflow.report-reaches-a-reader', 'report permissions present'));
|
|
991
|
+
|
|
992
|
+
return out;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// Consent tooling, by package name and by the script hosts these products load
|
|
996
|
+
// from. Stanford requires NO cookie banner: the Global Footer's Privacy link
|
|
997
|
+
// carries the disclosure, and guidance actively tells units not to build one.
|
|
998
|
+
// So finding one of these is not a failure in itself, it is an undeclared
|
|
999
|
+
// deliberate choice, which is the thing this project cares about.
|
|
1000
|
+
const CONSENT_TOOLING = [
|
|
1001
|
+
'onetrust', 'cookiebot', 'cookieyes', 'osano', 'termly', 'iubenda',
|
|
1002
|
+
'klaro', 'tarteaucitron', 'cookieconsent', 'usercentrics', 'trustarc',
|
|
1003
|
+
'quantcast', 'civic-cookie-control', 'cookiehub', 'cookiefirst',
|
|
1004
|
+
];
|
|
1005
|
+
|
|
1006
|
+
export function manifest({ root, html, standards }) {
|
|
1007
|
+
const p = join(root, '.sws', 'manifest.yml');
|
|
1008
|
+
if (!existsSync(p)) {
|
|
1009
|
+
return [
|
|
1010
|
+
bad('manifest.present', 'no .sws/manifest.yml',
|
|
1011
|
+
'Records standards version, resolved versions, tier, owners, prior art, and divergences.'),
|
|
1012
|
+
dunno('minweb.siteimprove', 'no manifest to read'),
|
|
1013
|
+
dunno('minweb.ownership', 'no manifest to read'),
|
|
1014
|
+
dunno('manifest.divergences-explained', 'no manifest to read'),
|
|
1015
|
+
dunno('privacy.consent-tooling-declared', 'no manifest to read'),
|
|
1016
|
+
dunno('hosting.recorded', 'no manifest to read'),
|
|
1017
|
+
];
|
|
1018
|
+
}
|
|
1019
|
+
const m = readYaml(p) || {};
|
|
1020
|
+
const out = [ok('manifest.present', `.sws/manifest.yml, standards v${m.standards_version ?? '?'}`)];
|
|
1021
|
+
|
|
1022
|
+
out.push(m.siteimprove
|
|
1023
|
+
? ok('minweb.siteimprove', 'Siteimprove registration recorded')
|
|
1024
|
+
: bad('minweb.siteimprove', 'Siteimprove registration not recorded',
|
|
1025
|
+
'Required for public-facing Stanford sites. Google Analytics is not required.'));
|
|
1026
|
+
|
|
1027
|
+
const b = m.owners?.business, t = m.owners?.technical;
|
|
1028
|
+
const isStanford = (s) => typeof s === 'string' && /@stanford\.edu/.test(s);
|
|
1029
|
+
out.push(isStanford(b?.email) && isStanford(t?.email)
|
|
1030
|
+
? ok('minweb.ownership', `business: ${b.email}, technical: ${t.email}`)
|
|
1031
|
+
: bad('minweb.ownership', 'business owner and/or technical administrator missing a stanford.edu email',
|
|
1032
|
+
'MinWeb requires both be identifiable with valid Stanford affiliation.'));
|
|
1033
|
+
|
|
1034
|
+
// Divergence is supported and expected. Only SILENT divergence is a problem,
|
|
1035
|
+
// so what gets checked is the presence of a reason, never the choice itself.
|
|
1036
|
+
const divs = Array.isArray(m.divergences) ? m.divergences : [];
|
|
1037
|
+
const named = (d) => d?.changed || d?.from || '(unnamed)';
|
|
1038
|
+
if (!divs.length) {
|
|
1039
|
+
out.push(na('manifest.divergences-explained', 'no divergences recorded'));
|
|
1040
|
+
} else {
|
|
1041
|
+
const silent = divs.filter((d) => !String(d?.reason ?? '').trim());
|
|
1042
|
+
out.push(silent.length
|
|
1043
|
+
? bad('manifest.divergences-explained',
|
|
1044
|
+
`${silent.length} of ${divs.length} divergence(s) record no reason: ${silent.map(named).join('; ')}`,
|
|
1045
|
+
'Add a one-line `reason:` and the `cost_accepted:`. Deviating is supported; not saying why is not.')
|
|
1046
|
+
: ok('manifest.divergences-explained', `${divs.length} divergence(s), each with a reason`));
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// Consent tooling: declared, or flagged. Not banned, because a unit may have
|
|
1050
|
+
// a real reason, but it is never the default and it needs the Privacy Office.
|
|
1051
|
+
const found = new Set();
|
|
1052
|
+
for (const name of Object.keys(deps(root))) {
|
|
1053
|
+
const hit = CONSENT_TOOLING.find((c) => name.toLowerCase().includes(c));
|
|
1054
|
+
if (hit) found.add(hit);
|
|
1055
|
+
}
|
|
1056
|
+
for (const f of html) {
|
|
1057
|
+
const markup = read(f).toLowerCase();
|
|
1058
|
+
for (const c of CONSENT_TOOLING) if (markup.includes(c)) found.add(c);
|
|
1059
|
+
}
|
|
1060
|
+
const declared = m.privacy?.consent_tooling;
|
|
1061
|
+
if (!found.size) {
|
|
1062
|
+
out.push(ok('privacy.consent-tooling-declared', 'no consent tooling present, which is the Stanford default'));
|
|
1063
|
+
} else if (String(declared ?? '').trim()) {
|
|
1064
|
+
out.push(ok('privacy.consent-tooling-declared',
|
|
1065
|
+
`${[...found].join(', ')} present and declared in .sws/manifest.yml`));
|
|
1066
|
+
} else {
|
|
1067
|
+
out.push(bad('privacy.consent-tooling-declared',
|
|
1068
|
+
`${[...found].join(', ')} present but not declared in .sws/manifest.yml`,
|
|
1069
|
+
'No cookie banner is required at Stanford; the Global Footer Privacy link carries the disclosure. If you are keeping this, record it under privacy.consent_tooling with the reason, and consult the University Privacy Office.'));
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// This is the criterion that makes the hosting axis legible: neither Netlify
|
|
1073
|
+
// nor Vercel is a divergence (SWS runs both), so this only asks that the
|
|
1074
|
+
// choice be WRITTEN DOWN rather than guessed from a lockfile.
|
|
1075
|
+
const hostingProvider = m.hosting?.provider;
|
|
1076
|
+
if (!hostingProvider) {
|
|
1077
|
+
out.push(bad('hosting.recorded', 'no hosting.provider recorded in .sws/manifest.yml',
|
|
1078
|
+
'Record hosting: { provider: github-pages|netlify|vercel, production_url: ... }. See standards/hosting/.'));
|
|
1079
|
+
} else {
|
|
1080
|
+
const profile = standards ? join(standards, 'hosting', `${hostingProvider}.yml`) : null;
|
|
1081
|
+
out.push(profile && existsSync(profile)
|
|
1082
|
+
? ok('hosting.recorded', `hosting.provider: ${hostingProvider}, matches standards/hosting/${hostingProvider}.yml`)
|
|
1083
|
+
: bad('hosting.recorded', `hosting.provider: ${hostingProvider} has no matching profile under standards/hosting/`,
|
|
1084
|
+
'Check for a typo in hosting.provider, or pass --standards if this run cannot resolve the standards directory.'));
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
return out;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// --------------------------------------------------------------------------
|
|
1091
|
+
// security: response headers. Only meaningful on a server-rendered target, so
|
|
1092
|
+
// everything here is not_applicable on a static build rather than failing.
|
|
1093
|
+
// --------------------------------------------------------------------------
|
|
1094
|
+
|
|
1095
|
+
function nextConfig(root) {
|
|
1096
|
+
const f = ['next.config.ts', 'next.config.mjs', 'next.config.js']
|
|
1097
|
+
.map((n) => join(root, n)).find(existsSync);
|
|
1098
|
+
return f ? { path: f, body: read(f) } : null;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// Astro (and a static build on any host) sends response headers from HOST
|
|
1102
|
+
// CONFIG, not application code -- see astro-ssr/RECIPE.md step 3b. Middleware
|
|
1103
|
+
// is the wrong place: it does not run for prerendered routes, so headers set
|
|
1104
|
+
// there apply to some pages and not others, and the pages that miss out are
|
|
1105
|
+
// the prerendered ones, which is most of a content site.
|
|
1106
|
+
function hostConfig(root) {
|
|
1107
|
+
const netlifyPath = join(root, 'netlify.toml');
|
|
1108
|
+
if (existsSync(netlifyPath)) return { kind: 'netlify', file: 'netlify.toml', body: read(netlifyPath) };
|
|
1109
|
+
const vercelPath = join(root, 'vercel.json');
|
|
1110
|
+
if (existsSync(vercelPath)) return { kind: 'vercel', file: 'vercel.json', body: read(vercelPath) };
|
|
1111
|
+
return null;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
const DEFAULT_HEADER_SET = [
|
|
1115
|
+
['Strict-Transport-Security', 'HSTS'],
|
|
1116
|
+
['X-Content-Type-Options', 'nosniff'],
|
|
1117
|
+
['Referrer-Policy', 'referrer policy'],
|
|
1118
|
+
['Permissions-Policy', 'permissions policy'],
|
|
1119
|
+
['X-Frame-Options', 'frame options'],
|
|
1120
|
+
];
|
|
1121
|
+
|
|
1122
|
+
export function security({ root }) {
|
|
1123
|
+
const cfg = nextConfig(root);
|
|
1124
|
+
const host = hostConfig(root);
|
|
1125
|
+
const out = [];
|
|
1126
|
+
|
|
1127
|
+
// Astro-specific: headers in host config. Meaningful regardless of whether
|
|
1128
|
+
// a Next config is also present, so it runs independently of the block below.
|
|
1129
|
+
out.push(host
|
|
1130
|
+
? (() => {
|
|
1131
|
+
const missing = DEFAULT_HEADER_SET.filter(([h]) => !new RegExp(h, 'i').test(host.body)).map(([, l]) => l);
|
|
1132
|
+
return missing.length
|
|
1133
|
+
? bad('astro.headers-in-host-config', `${host.file} is missing: ${missing.join(', ')}`,
|
|
1134
|
+
`Add the default header set (see standards/hosting/capabilities.yml) under ${
|
|
1135
|
+
host.kind === 'netlify' ? '[[headers]] in netlify.toml' : '"headers" in vercel.json'}.`)
|
|
1136
|
+
: ok('astro.headers-in-host-config', `default security header set found in ${host.file}`);
|
|
1137
|
+
})()
|
|
1138
|
+
: na('astro.headers-in-host-config', 'no netlify.toml or vercel.json found'));
|
|
1139
|
+
|
|
1140
|
+
if (!cfg) {
|
|
1141
|
+
out.push(na('security.csp-present', host
|
|
1142
|
+
? 'no Next config; this project configures response headers in host config instead (see astro.headers-in-host-config)'
|
|
1143
|
+
: 'no Next config; response headers are not applicable to a static build'));
|
|
1144
|
+
// NOTE: headers-set is `na` rather than `fail` here for the same reason.
|
|
1145
|
+
// A static build genuinely cannot send headers; that is a stated cost of
|
|
1146
|
+
// astro-static, not a defect in the project.
|
|
1147
|
+
out.push(na('security.headers-set', host ? 'no Next config; see astro.headers-in-host-config' : 'no Next config'));
|
|
1148
|
+
return out;
|
|
1149
|
+
}
|
|
1150
|
+
const b = cfg.body;
|
|
1151
|
+
|
|
1152
|
+
// A dynamically built CSP is normal (the homesite composes it from an array),
|
|
1153
|
+
// so look for the header name rather than trying to parse a policy.
|
|
1154
|
+
const hasHeaders = /async\s+headers\s*\(/.test(b) || /headers\s*:\s*async/.test(b);
|
|
1155
|
+
// CSP IS OPTIONAL AND ABSENCE IS A PASS. Corrected 2026-09-03: this used to
|
|
1156
|
+
// report a missing CSP as a failure, which nudged people towards the one
|
|
1157
|
+
// header that breaks pages at CONTENT-EDIT time rather than at deploy time.
|
|
1158
|
+
// MinWeb requires no response headers at all. The default header set below
|
|
1159
|
+
// is what we actually ask for, because none of it can break a page.
|
|
1160
|
+
if (!hasHeaders) {
|
|
1161
|
+
out.push(ok('security.csp-present', 'no CSP, which is compliant: CSP is optional'));
|
|
1162
|
+
out.push(bad('security.headers-set', 'no headers() function in the Next config',
|
|
1163
|
+
'Add headers() returning the default set: HSTS, nosniff, Referrer-Policy, ' +
|
|
1164
|
+
'Permissions-Policy, and X-Frame-Options: SAMEORIGIN. See standards/hosting/capabilities.yml.'));
|
|
1165
|
+
} else {
|
|
1166
|
+
out.push(/Content-Security-Policy/i.test(b)
|
|
1167
|
+
? ok('security.csp-present', 'CSP configured in headers(); record it in .sws/manifest.yml')
|
|
1168
|
+
: ok('security.csp-present', 'no CSP, which is compliant: CSP is optional'));
|
|
1169
|
+
|
|
1170
|
+
const want = [
|
|
1171
|
+
['Strict-Transport-Security', 'HSTS'],
|
|
1172
|
+
['X-Content-Type-Options', 'nosniff'],
|
|
1173
|
+
['Referrer-Policy', 'referrer policy'],
|
|
1174
|
+
['Permissions-Policy', 'permissions policy'],
|
|
1175
|
+
['X-Frame-Options', 'frame options'],
|
|
1176
|
+
];
|
|
1177
|
+
const missing = want.filter(([h]) => !new RegExp(h, 'i').test(b)).map(([, l]) => l);
|
|
1178
|
+
out.push(missing.length
|
|
1179
|
+
? bad('security.headers-set', `missing: ${missing.join(', ')}`,
|
|
1180
|
+
'Report per header. Every one of these is cheap and none of them can break a page, ' +
|
|
1181
|
+
'which is exactly why they are the default and a CSP is not.')
|
|
1182
|
+
: ok('security.headers-set', 'the default security header set is configured'));
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
// The Storyblok Visual Editor CSP check lived here until 2026-09-03. REMOVED
|
|
1186
|
+
// with the CMS scope, not because it was wrong: this package is scoped to
|
|
1187
|
+
// static content authored in the repo, so there is no Visual Editor to iframe
|
|
1188
|
+
// and no second policy to verify. See standards/scope.md.
|
|
1189
|
+
//
|
|
1190
|
+
// Deleting it rather than leaving it dormant is deliberate. A check that can
|
|
1191
|
+
// only ever report not_applicable is noise in every report, and its criterion
|
|
1192
|
+
// was dead weight in the acceptance contract. It comes back with the CMS, and
|
|
1193
|
+
// the logic worth keeping is recorded in git history: a runtime-composed CSP
|
|
1194
|
+
// cannot be read by regex, so the honest result there was `unknown` rather
|
|
1195
|
+
// than a guess in either direction.
|
|
1196
|
+
return out;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// --------------------------------------------------------------------------
|
|
1200
|
+
// next: framework-specific wiring
|
|
1201
|
+
// --------------------------------------------------------------------------
|
|
1202
|
+
|
|
1203
|
+
export function next({ root, html }) {
|
|
1204
|
+
const cfg = nextConfig(root);
|
|
1205
|
+
const isNext = !!cfg || !!deps(root).next;
|
|
1206
|
+
if (!isNext) {
|
|
1207
|
+
return ['next.postcss-configured', 'next.no-vite-tailwind', 'next.no-tailwind-config', 'next.metadata-base']
|
|
1208
|
+
.map((id) => na(id, 'not a Next project'));
|
|
1209
|
+
}
|
|
1210
|
+
const out = [];
|
|
1211
|
+
|
|
1212
|
+
const post = ['postcss.config.mjs', 'postcss.config.js', 'postcss.config.json']
|
|
1213
|
+
.map((n) => join(root, n)).find(existsSync);
|
|
1214
|
+
out.push(post && /@tailwindcss\/postcss/.test(read(post))
|
|
1215
|
+
? ok('next.postcss-configured', `${relative(root, post)} registers @tailwindcss/postcss`)
|
|
1216
|
+
: bad('next.postcss-configured', post ? 'postcss config does not register @tailwindcss/postcss' : 'no postcss config',
|
|
1217
|
+
'Next compiles Tailwind through PostCSS. Without this, Decanter is imported and never compiled.'));
|
|
1218
|
+
|
|
1219
|
+
out.push(deps(root)['@tailwindcss/vite']
|
|
1220
|
+
? bad('next.no-vite-tailwind', '@tailwindcss/vite is a dependency',
|
|
1221
|
+
'That is the Astro integration. Next uses @tailwindcss/postcss. Signals a copied Astro config.')
|
|
1222
|
+
: ok('next.no-vite-tailwind', '@tailwindcss/vite absent, correct for Next'));
|
|
1223
|
+
|
|
1224
|
+
const twCfg = ['tailwind.config.js', 'tailwind.config.mjs', 'tailwind.config.ts']
|
|
1225
|
+
.filter((f) => existsSync(join(root, f)));
|
|
1226
|
+
out.push(twCfg.length
|
|
1227
|
+
? bad('next.no-tailwind-config', `found ${twCfg.join(', ')}`,
|
|
1228
|
+
'Scaffold with --no-tailwind. Decanter 8 has no JS config.')
|
|
1229
|
+
: ok('next.no-tailwind-config', 'no tailwind JS config'));
|
|
1230
|
+
|
|
1231
|
+
// metadataBase is the Next equivalent of Astro's `site`, and the same miss.
|
|
1232
|
+
const layouts = [];
|
|
1233
|
+
(function walk(d) {
|
|
1234
|
+
if (!existsSync(d)) return;
|
|
1235
|
+
for (const n of readdirSync(d)) {
|
|
1236
|
+
const p = join(d, n);
|
|
1237
|
+
if (statSync(p).isDirectory()) { if (n !== 'node_modules') walk(p); }
|
|
1238
|
+
else if (/^layout\.(t|j)sx?$/.test(n)) layouts.push(p);
|
|
1239
|
+
}
|
|
1240
|
+
})(join(root, 'app'));
|
|
1241
|
+
|
|
1242
|
+
if (!layouts.length) {
|
|
1243
|
+
out.push(dunno('next.metadata-base', 'no app/layout file found; App Router expected'));
|
|
1244
|
+
} else {
|
|
1245
|
+
const hit = layouts.find((f) => /metadataBase/.test(read(f)));
|
|
1246
|
+
out.push(hit
|
|
1247
|
+
? ok('next.metadata-base', `metadataBase set in ${relative(root, hit)}`)
|
|
1248
|
+
: bad('next.metadata-base', 'metadataBase not set in any app layout',
|
|
1249
|
+
'Without it canonical and Open Graph URLs do not resolve absolutely. The Next equivalent of Astro\'s `site`.'));
|
|
1250
|
+
}
|
|
1251
|
+
return out;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
export const ALL = { footer, identity, decanter, seo, a11y, perf, secrets, hygiene, build, workflow, manifest, security, next };
|