ipal-doctor: never write first-seen dates when CI is set

The CLI ignored CI (writeSeen was only !sites && !json); docs and comments
already said "not in CI". shouldWriteSeen() + test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-24 00:01:18 +01:00
co-authored by Claude Opus 5.5
parent 36f8f69f82
commit 5cd0224ebd
2 changed files with 19 additions and 2 deletions
+9 -1
View File
@@ -26,6 +26,14 @@ export const DOCTOR_USAGE = `Usage: ipal-doctor [dir] [options]
Exit: 0 ok · 1 findings at or above --fail-on · 2 could not run · 3 a rule crashed
Silence a rule with a reason in ipal-doctor.json — docs/doctor.md`
/**
* Whether this run stores first-seen dates in ipal-doctor.json: not with --sites or --json, and
* never when CI is set (a CI run must not change a tracked file).
*/
export function shouldWriteSeen(args: { json?: boolean; sites?: unknown }, env: Record<string, string | undefined> = process.env): boolean {
return !args.sites && !args.json && !env.CI
}
const RANK: Record<DoctorSeverity, number> = { error: 3, info: 1, warning: 2 }
type Args = {
@@ -132,7 +140,7 @@ export async function runDoctorCli(argv: string[], { cwd = process.cwd(), log =
skip: args.skip,
staging: args.staging,
url: args.sites ? undefined : args.url,
writeSeen: !args.sites && !args.json,
writeSeen: shouldWriteSeen(args),
}),
)
}
+10 -1
View File
@@ -6,7 +6,7 @@ import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vite
import type { DoctorConfig, DoctorReport } from '../src/modules/doctor/types.js'
import { expandSites, parseDoctorArgs, runDoctorCli } from '../src/modules/doctor/cli.js'
import { expandSites, parseDoctorArgs, runDoctorCli, shouldWriteSeen } from '../src/modules/doctor/cli.js'
import { formatDriftTable, formatReport } from '../src/modules/doctor/format.js'
import { bareHost, parseEnvFile, readAuditSkips } from '../src/modules/doctor/project.js'
import { planSkills } from '../src/modules/doctor/rules/agents.js'
@@ -452,3 +452,12 @@ describe('the reference site', () => {
for (const setting of Object.values(config.rules ?? {})) {expect(setting.reason?.trim()).toBeTruthy()}
})
})
describe('ipal-doctor: first-seen dates', () => {
test('are written only outside CI, and never with --json or --sites', () => {
expect(shouldWriteSeen({}, {})).toBe(true)
expect(shouldWriteSeen({}, { CI: 'true' })).toBe(false)
expect(shouldWriteSeen({ json: true }, {})).toBe(false)
expect(shouldWriteSeen({ sites: 'clients/*' }, {})).toBe(false)
})
})