IAPL rename, review fixes I-1 to I-11

I-1  ipalEnvRules() keeps the IPAL_ rule names (IAPL_ as aliases); iaplEnvRules() the other way round; the IAPL_ value
     is the one checked when both are set
I-2  COOKIE_SCAN_URL_ENV / COOKIE_SCAN_TOKEN_ENV (and the internal SITE_NOINDEX_ENV) keep their old values;
     IAPL_COOKIE_SCAN_URL_ENV / IAPL_COOKIE_SCAN_TOKEN_ENV added
I-3  bin/ipal-*.mjs: five files that run the new ones (1.16's audit skill and CI call them by path); legacy:site checks it
I-4  storage-names sees <SiteProviders … stats> when a JSX prop comes first (the reference layout's shape)
I-5  AGENT.md: a text naming an ipal-<name> skill means iapl-<name> (the vendored ext-* skills)
I-6  leftover text in the skills-current message
I-7  iapl-skills removes the old pointer block when both are in AGENTS.md
I-8, I-11  changelog: the doctor's summary line, IAPL_DOCTOR_STATUS, --strict in CI until the skills are refreshed
I-9  env.md: an empty IAPL_ variable does not switch the IPAL_ one off
I-10 verifyLimit.keyPrefix undefined or empty is 'not given'

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 18:45:36 +01:00
co-authored by Claude Fable 5.2
parent 03452376f9
commit 38b903fcfa
25 changed files with 202 additions and 33 deletions
+2
View File
@@ -32,6 +32,7 @@
"ipal",
"ipal-",
"ipal-a",
"ipal-audit",
"ipal-audit-skip",
"ipal-b",
"ipal-badge*",
@@ -63,6 +64,7 @@
"ipal-panel-smtp",
"ipal-polish-",
"ipal-primary",
"ipal-reference",
"ipal-release",
"ipal-row",
"ipal-safe-back",
+77 -3
View File
@@ -29,7 +29,7 @@ import { LEGACY_COMMANDS, LEGACY_EXPORTS, LEGACY_SKILL_NAMES, PLUGIN_ENV_NAMES }
import { runDoctor } from '../src/modules/doctor/run.js'
import { assertEnv } from '../src/modules/env/assertEnv.js'
import { buildVerifyLimit, clearVerifyLimits, verifyLimitKey } from '../src/modules/security/totp/verifyLimit.js'
import { isSiteNoindex } from '../src/modules/seo/siteNoindex.js'
import { isSiteNoindex, SITE_NOINDEX_ENV } from '../src/modules/seo/siteNoindex.js'
import { legacyEnvName, readEnv } from '../src/modules/shared/envName.js'
import { IAPL_VISITOR_COOKIE, VISITOR_COOKIE, visitorCookieFor } from '../src/modules/stats/visitorCookie.js'
@@ -63,11 +63,13 @@ describe('exported names', () => {
// types have no runtime value: only the names that exist at runtime are compared here
const runtime = Object.entries(LEGACY_EXPORTS).filter(([, name]) => name in values)
expect(runtime.map(([old]) => old).sort()).toEqual(['IPAL_BREAKPOINTS', 'IPAL_TOKENS', 'ipalEnvRules', 'ipalKit', 'ipalT', 'ipalVar'])
for (const [old, name] of runtime) {expect(values[old], `${old} → ${name}`).toBe(values[name])}
// ipalEnvRules is the one exception: the same rules under the names a project wrote before (next test block)
for (const [old, name] of runtime.filter(([o]) => o !== 'ipalEnvRules')) {expect(values[old], `${old} → ${name}`).toBe(values[name])}
})
test('the env and tokens entries carry both spellings too', () => {
expect(envEntry.ipalEnvRules).toBe(envEntry.iaplEnvRules)
expect(envEntry.ipalEnvRules).toBe(root.ipalEnvRules)
expect(envEntry.iaplEnvRules).toBe(root.iaplEnvRules)
expect(tokensEntry.IPAL_TOKENS).toBe(tokensEntry.IAPL_TOKENS)
expect(tokensEntry.IPAL_BREAKPOINTS).toBe(tokensEntry.IAPL_BREAKPOINTS)
expect(tokensEntry.ipalVar).toBe(tokensEntry.iaplVar)
@@ -117,6 +119,48 @@ describe('env variables', () => {
expect(() => assertEnv(required, { env: { ...old, IPAL_COOKIE_SCAN_TOKEN: 'short' } })).toThrow(/IAPL_COOKIE_SCAN_TOKEN must be at least 16/)
})
test('ipalEnvRules() keeps the old rule names, so code that adapts the rules by name still starts', () => {
const features = { cookieCrawl: true, ipHeader: true }
const names = (rules: { name: string }[]) => rules.map((r) => r.name)
const old = envEntry.ipalEnvRules(features)
const fresh = envEntry.iaplEnvRules(features)
expect(names(old)).toEqual(names(fresh).map((n) => n.replace(/^IAPL_/, 'IPAL_')))
expect(old.find((r) => r.name === 'IPAL_IP_HEADER')?.aliases).toEqual(['IAPL_IP_HEADER'])
expect(fresh.find((r) => r.name === 'IAPL_IP_HEADER')?.aliases).toEqual(['IPAL_IP_HEADER'])
// the two measured cases of the review: production, only the old env names, the project's code unchanged
const env = { DATABASE_URI: 'mongodb://127.0.0.1/x_prod', IPAL_IP_HEADER: 'cf-connecting-ip', NEXT_PUBLIC_SERVER_URL: 'https://example.pl', NODE_ENV: 'production', PAYLOAD_SECRET: 's'.repeat(40) }
const before = process.env.NODE_ENV
;(process.env as Record<string, string | undefined>).NODE_ENV = 'production'
try {
const rules = envEntry.ipalEnvRules(features)
expect(() => assertEnv(rules, { env })).toThrow(/IPAL_COOKIE_SCAN_URL is required/)
expect(() => assertEnv(rules.map((r) => (/^IPAL_COOKIE_SCAN/.test(r.name) ? { ...r, required: false } : r)), { env })).not.toThrow()
expect(() => assertEnv(rules.filter((r) => !r.name.startsWith('IPAL_COOKIE_SCAN')), { env })).not.toThrow()
// untouched rules: the old env alone, the new env alone, and a too-short token under the old rule's own name
const scan = { COOKIE_SCAN_TOKEN: '0123456789abcdef', COOKIE_SCAN_URL: 'https://crawler.example.com' }
const withPrefix = (prefix: string) => Object.fromEntries(Object.entries(scan).map(([k, v]) => [`${prefix}_${k}`, v]))
expect(() => assertEnv(rules, { env: { ...env, ...withPrefix('IPAL') } })).not.toThrow()
expect(() => assertEnv(rules, { env: { ...env, IAPL_IP_HEADER: 'cf-connecting-ip', IPAL_IP_HEADER: undefined, ...withPrefix('IAPL') } })).not.toThrow()
expect(() => assertEnv(envEntry.iaplEnvRules(features), { env: { ...env, ...withPrefix('IPAL') } })).not.toThrow()
expect(() => assertEnv(rules, { env: { ...env, ...withPrefix('IPAL'), IPAL_COOKIE_SCAN_TOKEN: 'short' } })).toThrow(/IPAL_COOKIE_SCAN_TOKEN must be at least 16/)
// both spellings set: the IAPL_ value is the one checked, whichever the rule is named after
expect(() => assertEnv(rules, { env: { ...env, ...withPrefix('IPAL'), IAPL_COOKIE_SCAN_TOKEN: 'short' } })).toThrow(/must be at least 16/)
} finally {
;(process.env as Record<string, string | undefined>).NODE_ENV = before
}
})
test('the exported name constants kept their values; the new names have constants of their own', () => {
expect([root.COOKIE_SCAN_URL_ENV, root.COOKIE_SCAN_TOKEN_ENV]).toEqual(['IPAL_COOKIE_SCAN_URL', 'IPAL_COOKIE_SCAN_TOKEN'])
expect([root.IAPL_COOKIE_SCAN_URL_ENV, root.IAPL_COOKIE_SCAN_TOKEN_ENV]).toEqual(['IAPL_COOKIE_SCAN_URL', 'IAPL_COOKIE_SCAN_TOKEN'])
expect(SITE_NOINDEX_ENV).toBe('IPAL_NOINDEX')
// an empty new variable does not switch the old one off (docs/env.md)
process.env.IAPL_NOINDEX = ''
process.env.IPAL_NOINDEX = '1'
expect(isSiteNoindex()).toBe(true)
})
test('every runtime variable the doctor knows has an IPAL_ twin', () => {
for (const name of PLUGIN_ENV_NAMES) {expect(legacyEnvName(name)).toBe(name.replace('IAPL_', 'IPAL_'))}
})
@@ -226,6 +270,15 @@ describe('the doctor on a project that was not touched', () => {
expect(await check("storageNames: 'iapl'", 'visitorCookie={IAPL_VISITOR_COOKIE}')).toEqual([])
expect(await check("storageNames: 'iapl'", 'locale="pl"')).toEqual(['the page sets the visitor cookie ipal_vid, the cookie scanner declares iapl_vid'])
expect(await check('', 'visitorCookie="iapl_vid"')).toEqual(['the page sets the visitor cookie iapl_vid, the cookie scanner declares ipal_vid'])
// the reference layout's shape: <SiteProviders> with a JSX prop before `stats` (the first `>` is inside it)
const providers = (stats: string) => `import { SiteProviders } from '@intecion/ipal-kit/rsc'\nexport default function L() {\n return (\n <SiteProviders\n banner={<CookieBanner controls="switch" equalChoice settings="detailed" />}\n lightbox\n ${stats}\n shell={shell}\n >\n <main />\n </SiteProviders>\n )\n}\n`
const withProviders = async (names: string, stats: string) =>
(await run(project({ 'package.json': { name: 'x' }, 'src/app/(frontend)/[locale]/layout.tsx': providers(stats), 'src/payload.config.ts': config(names) }), ['storage-names'])).findings.filter((f) => f.rule === 'storage-names').length
expect(await withProviders("storageNames: 'iapl'", 'stats={{ locale }}')).toBe(1)
expect(await withProviders("storageNames: 'iapl'", 'stats')).toBe(1)
expect(await withProviders("storageNames: 'iapl'", 'stats={{ locale, visitorCookie: IAPL_VISITOR_COOKIE }}')).toBe(0)
expect(await withProviders('', 'stats={{ locale }}')).toBe(0)
expect(await withProviders("storageNames: 'iapl'", 'theme')).toBe(0) // no statistics mounted: nothing to compare
// a name the doctor cannot read (a variable) is not judged
expect(await check('', 'visitorCookie={name}')).toEqual([])
})
@@ -238,6 +291,15 @@ describe('commands and skills', () => {
expect(existsSync(path.join(packageRoot, pkg.bin[name])), pkg.bin[name]).toBe(true)
}
expect(Object.keys(pkg.bin)).toHaveLength(10)
// …and the old FILES are still there: 1.16's own audit skill and CI scripts call them by path
for (const [old, name] of Object.entries(LEGACY_COMMANDS)) {
const file = path.join(packageRoot, 'bin', `${old}.mjs`)
expect(existsSync(file), `bin/${old}.mjs`).toBe(true)
expect(readFileSync(file, 'utf8')).toContain(`import './${pkg.bin[name].replace('bin/', '')}'`)
}
const byPath = spawnSync(process.execPath, [path.join(packageRoot, 'bin/ipal-skills.mjs'), '--help'], { encoding: 'utf8' })
expect(byPath.status).toBe(0)
expect(byPath.stdout).toContain('Usage: iapl-skills')
// `pnpm dlx @intecion/ipal-kit create` runs the bin named after the package
expect(pkg.bin['ipal-kit']).toBe('bin/iapl.mjs')
})
@@ -288,6 +350,11 @@ describe('commands and skills', () => {
expect(second.stdout).not.toMatch(/^(?:add|remove|create)\b/m)
expect(second.stdout).toContain('ok AGENTS.md')
expect(readFileSync(path.join(dir, 'AGENTS.md'), 'utf8')).toBe(agents)
// a rollback to 1.16 whose installer appended its block again, then the upgrade: one block, the new one
writeFileSync(path.join(dir, 'AGENTS.md'), `${agents}\n<!-- ipal-kit:start -->\n## ipal-kit 1.16.7 — agent guide\n\nold text\n<!-- ipal-kit:end -->\n`)
expect(run('iapl-skills.mjs').status).toBe(0)
expect(readFileSync(path.join(dir, 'AGENTS.md'), 'utf8')).toBe(agents)
})
})
@@ -325,5 +392,12 @@ describe('stored names', () => {
expect((await limit(req()))?.status).toBe(429)
expect([...data.keys()]).toEqual(['iapl:2fa-verify:users:1'])
expect(data.get('iapl:2fa-verify:users:1')).toMatchObject({ count: 3 })
// an empty or undefined prefix is "not given", never a third key
for (const keyPrefix of [undefined, '', ' ']) {
data.clear()
clearVerifyLimits()
await buildVerifyLimit('users', { keyPrefix })(req())
expect([...data.keys()]).toEqual(['ipal:2fa-verify:users:1'])
}
})
})