From f8eae9d0ccd6e2db9ae91f327f99f8fe76902ba3 Mon Sep 17 00:00:00 2001 From: garrytan Date: Sat, 31 Oct 2026 12:59:21 +0000 Subject: [PATCH] fix(health): Health Stack rows stay markdown like /verify reads them; an empty section names why (fix-check) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- lib/checks.ts | 4 ++-- test/health-detect-no-loss.test.ts | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/checks.ts b/lib/checks.ts index 1937d58690..242bf75112 100644 --- a/lib/checks.ts +++ b/lib/checks.ts @@ -71,7 +71,7 @@ export function healthStack(claudeMd: string, keepTests = false): Check[] { while (taken.has(name)) name = `${key}-${++n + 1}`; seen.set(key, n); taken.add(name); - checks.push({ name, command: m[2].replace(/^`([^`]+)`$/, '$1'), source: 'CLAUDE.md Health Stack' }); + checks.push({ name, command: m[2].replace(/`/g, ''), source: 'CLAUDE.md Health Stack' }); } return checks; } @@ -141,7 +141,7 @@ export function healthDimensions(root: string, env: NodeJS.ProcessEnv = process. const stack = healthStack(claude, true); if (/^##\s+Health Stack\s*$/m.test(claude)) { const keys = new Set(stack.map(c => c.name.replace(/-\d+$/, '').replace(/^tests$/, 'test'))); - return { checks: stack.map(c => ({ dimension: c.name, command: c.command, source: c.source })), missing: HEALTH_DIMENSIONS.filter(d => !keys.has(d)).map(dimension => ({ dimension, reason: 'not in the CLAUDE.md Health Stack section' })) }; + return { checks: stack.map(c => ({ dimension: c.name, command: c.command, source: c.source })), missing: HEALTH_DIMENSIONS.filter(d => !keys.has(d)).map(dimension => ({ dimension, reason: stack.length ? 'not in the CLAUDE.md Health Stack section' : 'the CLAUDE.md Health Stack section has no "- key: command" rows' })) }; } const has = (file: string) => fs.existsSync(path.join(root, file)); const which = (bin: string) => Bun.which(bin, { PATH: env.PATH ?? '' }) !== null; diff --git a/test/health-detect-no-loss.test.ts b/test/health-detect-no-loss.test.ts index bc15ebb986..6526e9d279 100644 --- a/test/health-detect-no-loss.test.ts +++ b/test/health-detect-no-loss.test.ts @@ -142,17 +142,18 @@ describe('/health detection: no check lost (GST-116 PR 2)', () => { } }); - // Value: protects=a Health Stack keeps shell syntax, an empty section still turns auto-detection off, and detection runs - // where /health runs (a monorepo package); fails_when=backticks inside a command are stripped (a failing checker becomes - // a lookup), a section with no rows falls through to auto-detection, or the bin detects from the git top-level; - // why_new=review pass 1 outside voice; seam=the bin from a subdirectory - test('Health Stack bytes, an empty section, and the working directory', () => { + // Value: protects=Health Stack rows read as markdown like gstack:verify: (code-span backticks dropped), an empty section + // still turns auto-detection off and says so, and detection runs where /health runs (a monorepo package); + // fails_when=a section with no rows falls through to auto-detection, or the bin detects from the git top-level; + // why_new=review pass 1 voices; seam=the bin from a subdirectory + test('Health Stack spans, an empty section, and the working directory', () => { const tick = String.fromCharCode(96); - const subst = healthDimensions(repo('hs-subst', { 'CLAUDE.md': `## Health Stack\n\n- test: test "$(${tick}command -v false${tick})" = x\n- lint: ${tick}eslint .${tick}\n` }), { PATH: '', HOME: bareHome }); - expect(subst.checks.map(c => c.command)).toEqual([`test "$(${tick}command -v false${tick})" = x`, 'eslint .']); + const spans = healthDimensions(repo('hs-spans', { 'CLAUDE.md': `## Health Stack\n\n- lint: ${tick}eslint .${tick} && ${tick}prettier --check .${tick}\n` }), { PATH: '', HOME: bareHome }); + expect(spans.checks.map(c => c.command)).toEqual(['eslint . && prettier --check .']); const empty = healthDimensions(repo('hs-empty', { 'tsconfig.json': '{}', 'CLAUDE.md': '## Health Stack\n\nNo health tools are configured.\n' }), { PATH: stubs, HOME: gbrainHome }); expect(empty.checks).toEqual([]); expect(empty.missing.map(m => m.dimension)).toEqual([...HEALTH_DIMENSIONS]); + expect(empty.missing[0].reason).toBe('the CLAUDE.md Health Stack section has no "- key: command" rows'); const mono = repo('monorepo', { 'tsconfig.json': '{}', 'packages/app/package.json': JSON.stringify({ scripts: { test: 'vitest run' } }) }); expect(spawnSync('git', ['init', '-q'], { cwd: mono, timeout: 30_000 }).status).toBe(0); const env = { ...process.env, PATH: process.env.PATH, HOME: bareHome };