ipal-doctor: old-style block maps, 2FA behind a switch, folder name as database base; first sweep table
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a4e8cfeae8
commit
e97cf6d7d9
@@ -344,3 +344,40 @@ A throwaway prototype of the static rules and the live header/admin rules, run *
|
||||
6. Docs: `docs/doctor.md`, AGENT.md §11 and §14, the `ipal-doctor` skill, `ipal-setup` / `ipal-upgrade` final
|
||||
step, generated `docs/agent/doctor-rules.md`, CHANGELOG.
|
||||
7. Hand the rule list to the starter; it runs the doctor in its own tests (a generated site = 0 findings).
|
||||
|
||||
## 9. First real run (2026-10-29, built doctor, `--sites --offline`, read-only)
|
||||
|
||||
The client sites were not changed (git status before and after compared). `--offline`: no `plugin-latest` / `deps-audit`.
|
||||
Existing client sites are a report only (D7).
|
||||
|
||||
| Rule | architektimprezpl-web | coastalclimatesupplycomau-web | ecogenicacouk-web | intecioncom-web | saydiamondspl-web | thecleanteampl-web | vanstevpl-web |
|
||||
|---|---|---|---|---|---|---|---|
|
||||
| **errors / warnings / info** | 5 / 12 / 4 | 23 / 51 / 3 | 3 / 6 / 3 | 6 / 24 / 5 | 11 / 15 / 3 | 6 / 20 / 2 | 32 / 64 / 4 |
|
||||
| `2fa` | ✅ | ⚠️ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| `admin-meta` | ⚠️ | ⚠️ | ⚠️ | ⚠️ | ⚠️ | ⚠️ | ⚠️ |
|
||||
| `agents-md` | ✅ | ✅ | ✅ | ❌ 2 | ❌ 3 | ❌ 3 | ❌ 3 |
|
||||
| `audit` | ⚠️ 3 | ❌ 36 | ✅ | ⚠️ 11 | ⚠️ | ⚠️ | ❌ 58 |
|
||||
| `blocks-duplicate` | ⚠️ 3 | ⚠️ 4 | ⚠️ 3 | ⚠️ 3 | ⚠️ 6 | ⚠️ 5 | ⚠️ 3 |
|
||||
| `blocks-helper-copy` | ✅ | ⚠️ 3 | ⚠️ | ✅ | ✅ | ✅ | ⚠️ |
|
||||
| `blocks-tokens` | ⚠️ | ⚠️ | ✅ | ⚠️ | ✅ | ⚠️ | ❌ 5 |
|
||||
| `blocks-ui-required` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
|
||||
| `cookie-scanner` | ℹ️ | ❌ | ❌ | ℹ️ | ❌ | ❌ | ❌ |
|
||||
| `csp` | ℹ️ | ℹ️ | ℹ️ | ℹ️ | ⚠️ 2 | ⚠️ | ⚠️ 2 |
|
||||
| `db-name` | ❌ 2 | ❌ | ❌ | ❌ 2 | ❌ 2 | ⚠️ | ❌ 2 |
|
||||
| `env-example` | ❌ | ❌ 2 | ❌ | ⚠️ | ✅ | ⚠️ | ❌ 2 |
|
||||
| `env-rules` | ℹ️ | ℹ️ | ℹ️ | ℹ️ | ℹ️ | ℹ️ | ⚠️ 2 |
|
||||
| `i18n-literals` | ⚠️ | ⚠️ 21 | ✅ | ✅ | ✅ | ✅ | ❌ 5 |
|
||||
| `importmap` | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
|
||||
| `layout-extra` | ℹ️ | ℹ️ | ℹ️ | ℹ️ | ℹ️ | ✅ | ℹ️ |
|
||||
| `layout-required` | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `next-min` | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| `node-22` | ⚠️ 2 | ⚠️ 2 | ⚠️ | ⚠️ 2 | ⚠️ 2 | ⚠️ 2 | ⚠️ 2 |
|
||||
| `plugin-installed` | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ |
|
||||
| `pnpm-pinned` | ✅ | ✅ | ✅ | ℹ️ | ✅ | ℹ️ | ℹ️ |
|
||||
| `powered-by` | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| `seed-named` | ✅ | ✅ | ✅ | ❌ 4 | ❌ 5 | ⚠️ 5 | ❌ 5 |
|
||||
| `sharp-min` | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||
| `skills-current` | ⚠️ | ✅ | ✅ | ⚠️ | ✅ | ✅ | ⚠️ |
|
||||
|
||||
|
||||
The reference site: `node bin/ipal-doctor.mjs reference --strict --offline` → 0 errors, 0 warnings, 0 info (2 silenced with reasons).
|
||||
|
||||
@@ -140,7 +140,8 @@ export function createDoctorContext(options: ProjectOptions): DoctorContext {
|
||||
// Domain: ipal-doctor.json → a non-local NEXT_PUBLIC_SERVER_URL → the folder name minus -web (docs: D6).
|
||||
const urls = [env.local?.NEXT_PUBLIC_SERVER_URL, env.example?.NEXT_PUBLIC_SERVER_URL].filter(Boolean).map((u) => bareHost(u!))
|
||||
const fromDir = basename(root).replace(/-web$/, '')
|
||||
const domain = config.domain ? bareHost(config.domain) : (urls.find((h) => !isLocalHost(h)) ?? (fromDir.includes('.') ? fromDir : null))
|
||||
// The folder name (`intecioncom-web`) is already the domain without dots — enough for the database names.
|
||||
const domain = config.domain ? bareHost(config.domain) : (urls.find((h) => !isLocalHost(h)) ?? (/-web$/.test(basename(root)) && fromDir ? fromDir : null))
|
||||
|
||||
const agents = read('AGENTS.md')
|
||||
const launchedInAgents = /^[-* ][^\n]*?launch(?:ed)?[^\n]*?\d{4}-\d{2}-\d{2}/im.test(agents.split(/^## Project decisions\s*$/m)[1] ?? '')
|
||||
|
||||
@@ -48,8 +48,9 @@ export const blockRules: DoctorRule[] = [
|
||||
const file = `${ctx.src}blocks/registry.ts`
|
||||
if (!ctx.exists(file)) {return []} // layout-required reports the missing file
|
||||
const code = registry(ctx)
|
||||
if (/createBlockRegistry\s*\(/.test(code) || /RenderBlocks/.test(code)) {return []}
|
||||
return [{ file, fix: 'export const blockRegistry = createBlockRegistry(content, { … }) from @intecion/ipal-kit/blocks/rsc', message: 'blocks/registry.ts uses neither createBlockRegistry nor RenderBlocks', severity: 'error' }]
|
||||
// createBlockRegistry, or a blockType → component map for RenderBlocks / createPageRoute (sites before the library).
|
||||
if (/createBlockRegistry\s*\(|RenderBlocks|BlockComponentMap/.test(code) || /export\s+const\s+\w+\s*(?::\s*(?:[\w,<>][\w<>, ]*| ))?=\s*\{/.test(code)) {return []}
|
||||
return [{ file, fix: 'export const blockRegistry = createBlockRegistry(content, { … }) from @intecion/ipal-kit/blocks/rsc', message: 'blocks/registry.ts exports neither createBlockRegistry nor a blockType → component map', severity: 'error' }]
|
||||
},
|
||||
docs: 'docs/blocks.md',
|
||||
group: 'blocks',
|
||||
|
||||
@@ -101,7 +101,10 @@ export const securityRules: DoctorRule[] = [
|
||||
id: '2fa',
|
||||
check: (ctx) => {
|
||||
const out: RuleFinding[] = []
|
||||
if (!/twoFactor\s*:\s*\{[\s\S]*?plugin\s*:\s*payloadTotp/.test(cfg(ctx))) {out.push({ file: configFile(ctx) ?? 'payload.config.ts', fix: "ipalKit({ twoFactor: { issuer: '<site>', plugin: payloadTotp } })", message: '2FA is not on (twoFactor with plugin: payloadTotp)', severity: 'error' })}
|
||||
const code = cfg(ctx)
|
||||
const twoFactor = code.match(/twoFactor\s*:([^\n]*)/)?.[1] ?? ''
|
||||
if (/\?\s*false\b|:\s*false\b|&&/.test(twoFactor) && /payloadTotp/.test(twoFactor)) {out.push({ file: configFile(ctx) ?? undefined, fix: 'twoFactor: { issuer, plugin: payloadTotp } without a switch', message: '2FA can be turned off at runtime (a condition on twoFactor)', severity: 'warning' })}
|
||||
if (!/twoFactor\s*:[^\n]*payloadTotp|twoFactor\s*:\s*\{[\s\S]*?plugin\s*:\s*payloadTotp/.test(code)) {out.push({ file: configFile(ctx) ?? 'payload.config.ts', fix: "ipalKit({ twoFactor: { issuer: '<site>', plugin: payloadTotp } })", message: '2FA is not on (twoFactor with plugin: payloadTotp)', severity: 'error' })}
|
||||
else if (!ctx.installed('@clocklimited/payload-2fa')) {out.push({ fix: 'pnpm add @clocklimited/payload-2fa', message: '@clocklimited/payload-2fa is not installed', severity: 'error' })}
|
||||
if (ctx.deep?.usersWithout2fa) {out.push({ fix: 'each of them signs in and sets up TOTP (forceSetup)', message: `${ctx.deep.usersWithout2fa} panel user(s) without TOTP`, severity: 'error' })}
|
||||
return out
|
||||
|
||||
@@ -149,6 +149,19 @@ describe('layout, blocks, seeds, agents', () => {
|
||||
const report = await doctor(lib, ['blocks-ui-required', 'blocks-ui-override', 'blocks-registry'])
|
||||
expect(report.findings.map((f) => f.message)).toEqual(["components/ui/ overrides Button but the registry does not pass them — library blocks keep the plugin's look"])
|
||||
})
|
||||
test('an old-style blockType → component map passes blocks-registry; 2FA behind a switch is a warning', async () => {
|
||||
const map = project({ ...base(), 'src/blocks/registry.ts': "export const blockRegistry: BlockComponentMap = { hero: Hero }" })
|
||||
expect((await doctor(map, ['blocks-registry'])).findings).toEqual([])
|
||||
const sw = project({ ...base(), ...installed('@clocklimited/payload-2fa', '3.0.0'), 'src/payload.config.ts': "twoFactor: process.env.X === 'true' ? false : { issuer: 'A', plugin: payloadTotp }," })
|
||||
expect(rules(await doctor(sw, ['2fa']))).toEqual(['2fa:warning'])
|
||||
})
|
||||
test('the folder name gives the database base when there is no domain', async () => {
|
||||
const parent = project({})
|
||||
const root = path.join(parent, 'acmepl-web')
|
||||
mkdirSync(root)
|
||||
writeFileSync(path.join(root, '.env'), 'DATABASE_URI=mongodb://db/acme\n')
|
||||
expect((await doctor(root, ['db-name'])).findings.map((f) => f.message)).toEqual(['.env: database "acme", expected acmepl_dev'])
|
||||
})
|
||||
test('a project block duplicating a library block (also by a renamed slug) and helper copies', async () => {
|
||||
const root = project({
|
||||
...base(),
|
||||
|
||||
Reference in New Issue
Block a user