import assert from 'node:assert/strict' import { describe, it } from 'node:test' import { resolvePrompt } from './prompts.ts' import { automationIds, launcherOf } from './shared.ts' describe('resolvePrompt', () => { for (const id of automationIds.filter((a) => launcherOf(a) === 'cursor')) { it(`${id} is repo-agnostic and includes shared footer`, () => { const prompt = resolvePrompt({ automation: id, repo: 'acme/widgets', branch: 'main', }) assert.match(prompt, /\*\*acme\/widgets\*\*/) assert.match(prompt, /Rules \(all automations\)/) assert.match(prompt, /npx @kodycodes\/cli/) assert.match(prompt, /ship-pr/) assert.match(prompt, /Format before each commit/) assert.match(prompt, /Ask the owner before changing production data/) assert.match(prompt, /Merge once CI is green/) assert.doesNotMatch(prompt, /ManagePullRequest/) assert.doesNotMatch(prompt, /Cursor\/GitHub account/) assert.doesNotMatch(prompt, /## Repo-local skills/) assert.doesNotMatch(prompt, /\{\{notify\}\}/) assert.match(prompt, /no notify target is configured/) }) } it('uses the configured notify target in the footer and templates', () => { const prompt = resolvePrompt({ automation: 'legacy-reaper', repo: 'acme/widgets', branch: 'main', notify: 'kody:@acme/chat/ping-me', }) assert.match(prompt, /6\. Report: message the owner \(`kody:@acme\/chat\/ping-me`\)/) assert.match(prompt, /High risk: leave the PR open and message the owner \(`kody:@acme\/chat\/ping-me`\)/) assert.match(prompt, /Ask the owner before changing production data \(`kody:@acme\/chat\/ping-me`\)/) assert.doesNotMatch(prompt, /no notify target/) }) it('legacy-reaper keeps audit→tracks→conductor→report +/-', () => { const prompt = resolvePrompt({ automation: 'legacy-reaper', repo: 'acme/widgets', branch: 'main', }) assert.match(prompt, /Audit/) assert.match(prompt, /conflict-partitioned/) assert.match(prompt, /conductor/i) assert.match(prompt, /\+\/- lines/) assert.match(prompt, /GitHub issue/) assert.match(prompt, /strong investigation model/) }) it('docs-freshness keeps temporal nuance without early-exit paragraph', () => { const prompt = resolvePrompt({ automation: 'docs-freshness', repo: 'acme/widgets', branch: 'main', }) assert.match(prompt, /how things are now/i) assert.match(prompt, /now that you're verified/i) assert.doesNotMatch(prompt, /Early exit/) }) it('keep-tests-tight stays minimal but keeps the bar', () => { const prompt = resolvePrompt({ automation: 'keep-tests-tight', repo: 'acme/widgets', branch: 'main', }) assert.match(prompt, /testing-principles\.md/) assert.match(prompt, /independent oracle/) assert.match(prompt, /tautological/) }) it('docs-freshness scoped starts from listed files, fixes inaccurate comments, and only lists present reasons', async () => { const { scopedTemplates } = await import('./prompts/templates.ts') const { reasonsBlock } = await import('./scope-core.ts') const reasons = reasonsBlock('docs-freshness', ['inaccurate', 'duplication', 'inaccurate', 'fine']) const prompt = resolvePrompt({ automation: 'docs-freshness', repo: 'acme/widgets', branch: 'main', branchName: 'cleanup/docs-freshness-2026-11-05', templateOverride: scopedTemplates['docs-freshness'], files: '- `README.md` [doc] inaccurate (confidence 0.80)\n- `src/a.ts` [documented-export] duplication (confidence 0.70)', range: 'abc123...def456', reasons, notify: 'kody:@kentcdodds/discord/send-me-a-message', }) assert.match(prompt, /Start from these files and the docs that describe them/) assert.match(prompt, /fix inaccurate comments in that file/) assert.match(prompt, /\*\*inaccurate:\*\*/) assert.match(prompt, /\*\*duplication:\*\*/) assert.doesNotMatch(prompt, /temporal-language/) assert.doesNotMatch(prompt, /Do not audit/) assert.doesNotMatch(prompt, /leave the code alone/) assert.match(prompt, /cleanup\/docs-freshness-2026-11-05/) assert.match(prompt, /npx @kodycodes\/cli/) assert.match(prompt, /When a file needs nothing, note it in the PR/) assert.match(prompt, /When nothing needs changing, open no PR/) assert.doesNotMatch(prompt, /ManagePullRequest/) assert.doesNotMatch(prompt, /\u2014/) }) it('keep-tests-tight scoped only lists present reasons', async () => { const { scopedTemplates } = await import('./prompts/templates.ts') const { reasonsBlock } = await import('./scope-core.ts') const prompt = resolvePrompt({ automation: 'keep-tests-tight', repo: 'acme/widgets', branch: 'main', branchName: 'cleanup/keep-tests-tight-2026-11-05', templateOverride: scopedTemplates['keep-tests-tight'], files: '- `src/a.test.ts` [test] tautological (confidence 0.90)', range: 'abc123...def456', reasons: reasonsBlock('keep-tests-tight', ['tautological']), }) assert.match(prompt, /Start from these files and the tests that cover them/) assert.match(prompt, /\*\*tautological:\*\*/) assert.doesNotMatch(prompt, /missing-oracle/) assert.doesNotMatch(prompt, /Do not audit/) }) it('prod-ci-failure is minimal and inserts CI extra', () => { const prompt = resolvePrompt({ automation: 'prod-ci-failure', repo: 'acme/widgets', branch: 'main', extra: '## Failure context\n- Head SHA: `deadbeef`', }) assert.match(prompt, /deadbeef/) assert.match(prompt, /Fix the CI failure/) assert.doesNotMatch(prompt, /## Approach/) }) describe('general-audit (Devin)', () => { const resolve = (notify?: string | null) => resolvePrompt({ automation: 'general-audit', repo: 'acme/widgets', branch: 'main', notify }) it('covers the audit areas', () => { const prompt = resolve() for (const area of [ /Authentication and authorization/, /Multi-tenant isolation/, /Secrets handling and leakage/, /Injection/, /SSRF/, /Unsafe deserialization/, /signature verification/, /CORS, cookies/, /Dependencies/, ]) { assert.match(prompt, area) } }) it('never routes findings to public places, even without a notify target', () => { const prompt = resolve(null) assert.match(prompt, /Keep findings in the private report/) assert.match(prompt, /Describe vulnerability fixes in the private report/) assert.match(prompt, /keep the report in this Devin session only/) assert.match(prompt, /leave out user or org handles, emails, internal ids, and credential details/) assert.doesNotMatch(prompt, /PR description/) assert.doesNotMatch(prompt, /ManagePullRequest/) assert.doesNotMatch(prompt, /squash-merge/) assert.doesNotMatch(prompt, /\{\{\w+\}\}/) }) it('sends the private report through the notify target', () => { const prompt = resolve('kody:@acme/chat/ping-me') assert.match(prompt, /calling the Kody export `kody:@acme\/chat\/ping-me` through your Kody MCP connection/) assert.match(prompt, /import send from 'kody:@acme\/chat\/ping-me'/) assert.match(prompt, /Keep exploit steps and payloads out of the message/) }) it('allows only non-disclosing hygiene PRs', () => { const prompt = resolve() assert.match(prompt, /routine dependency bump/) assert.match(prompt, /no CVE or advisory ids/) assert.match(prompt, /Leave it open and mention it in the private report/) }) it('contains no em dashes', () => { assert.doesNotMatch(resolve('kody:@acme/chat/ping-me'), /\u2014/) }) it('walks the four lanes in order: security, performance, accessibility, code health', () => { const prompt = resolve('kody:@acme/chat/ping-me') const headings = ['## Lane 1: Security', '## Lane 2: Performance', '## Lane 3: Accessibility', '## Lane 4: Code health'] const positions = headings.map((h) => prompt.indexOf(h)) for (const [i, pos] of positions.entries()) assert.ok(pos >= 0, `missing ${headings[i]}`) assert.deepEqual([...positions].sort((a, b) => a - b), positions) assert.match(prompt, /in order\*\*, finishing each lane before you start the next: 1\. Security, 2\. Performance, 3\. Accessibility, 4\. Code health/) for (const area of [/N\+1 queries/, /Keyboard and focus/, /color contrast/, /Dead code/, /Dependency drift/, /Test gaps/]) { assert.match(prompt, area) } }) it('keeps the whole audit in one session', () => { const prompt = resolve() assert.match(prompt, /in this one session/) assert.match(prompt, /Finish every lane yourself in this single session/) }) it('asks for a report with one section per lane in order, including empty lanes', () => { const prompt = resolve('kody:@acme/chat/ping-me') const report = prompt.slice(prompt.indexOf('## Private audit report')) const sections = ['**Security** (', '**Performance** (', '**Accessibility** (', '**Code health** ('] const positions = sections.map((s) => report.indexOf(s)) for (const pos of positions) assert.ok(pos >= 0) assert.deepEqual([...positions].sort((a, b) => a - b), positions) assert.match(report, /A lane with zero findings still gets its section, with the line "None found\."/) assert.match(report, /affected file paths, and the suggested fix/) }) it('forbids issues and PRs about findings in every lane', () => { const prompt = resolve() assert.match(prompt, /Put performance, accessibility, and code health suggested fixes in the private report/) assert.match(prompt, /Keep findings in the private report/) }) }) })