verify-package-readme-summaries.spec.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { describe, expect, it } from 'vitest'
  2. import {
  3. MAX_PACKAGE_README_SUMMARY_WORDS,
  4. packageReadmeSummaryErrors,
  5. } from './verify-package-readme-summaries.ts'
  6. function readme(summary: string, kind = 'package-reference'): string {
  7. return `---\nkind: "${kind}"\n---\n# Example\n\n## Summary\n\n${summary}\n\n## Table of Contents\n`
  8. }
  9. describe('package README Summary limit', () => {
  10. it('accepts exactly 100 whitespace-delimited words', () => {
  11. const summary = Array.from({ length: MAX_PACKAGE_README_SUMMARY_WORDS }, () => 'word').join(' ')
  12. expect(packageReadmeSummaryErrors('packages/example/example/README.md', readme(summary))).toEqual([])
  13. })
  14. it.each([
  15. 'package-group',
  16. 'package-reference',
  17. 'package-library',
  18. 'package-bundle',
  19. ])('rejects 101 words and directs the author to the skill and %s template', (kind) => {
  20. const summary = Array.from({ length: MAX_PACKAGE_README_SUMMARY_WORDS + 1 }, () => 'word').join(' ')
  21. expect(packageReadmeSummaryErrors('packages/example/example/README.md', readme(summary, kind))).toEqual([
  22. `packages/example/example/README.md: Summary has 101 words; the limit is 100. Read .agents/skills/dsh-doc/SKILL.md and .agents/skills/dsh-doc/templates/${kind}.md before rewriting it.`,
  23. ])
  24. })
  25. it('counts only the Summary body', () => {
  26. const laterSection = Array.from({ length: 101 }, () => 'detail').join(' ')
  27. expect(packageReadmeSummaryErrors(
  28. 'packages/example/example/README.md',
  29. `${readme('Short summary.')}\n${laterSection}`,
  30. )).toEqual([])
  31. })
  32. it('rejects a missing Summary instead of silently narrowing the corpus', () => {
  33. expect(packageReadmeSummaryErrors(
  34. 'packages/example/example/README.md',
  35. '---\nkind: "package-reference"\n---\n# Example\n',
  36. )).toEqual(['packages/example/example/README.md: missing `## Summary`'])
  37. })
  38. })