Skip to content

test(cli): add Jest test suite for PromptKit CLI#148

Closed
abeltrano wants to merge 1 commit intomainfrom
test/cli-jest-suite
Closed

test(cli): add Jest test suite for PromptKit CLI#148
abeltrano wants to merge 1 commit intomainfrom
test/cli-jest-suite

Conversation

@abeltrano
Copy link
Copy Markdown
Collaborator

Fixes #147

Adds comprehensive automated test coverage for the PromptKit CLI module.

What's included

53 tests across 4 suites — all passing:

Suite Tests Coverage
manifest.test.js 19 loadManifest, getTemplates, all getters, resolveTemplateDeps
assemble.test.js 18 stripFrontmatter, loadComponent, full assembly, param substitution
launch.test.js 9 detectCli priority (mocked child_process), copyContentToTemp
cli.test.js 7 list, assemble, --version, error handling (integration via subprocess)

Infrastructure

  • Jest added as dev dependency
  • Test scripts: npm test and npm run test:coverage
  • Test fixtures in cli/__tests__/fixtures/ — minimal mock persona, protocols, format, taxonomy, templates, and manifest
  • CI workflow (.github/workflows/cli-tests.yml) — runs on push/PR when cli/ changes
  • coverage/ added to .gitignore

How to run

cd cli && npm ci && npm test

Add comprehensive test coverage for the CLI module:

- manifest.js: loadManifest, getTemplates, persona/protocol/format/
  taxonomy lookups, resolveTemplateDeps (16 tests)
- assemble.js: stripFrontmatter, loadComponent, full assembly with
  section ordering, param substitution, verbatim inclusion (15 tests)
- launch.js: detectCli priority order with mocked child_process,
  copyContentToTemp file/directory operations (9 tests)
- cli.js: integration tests for list, assemble, --version, error
  handling via subprocess execution (7 tests)

Tests validate against real repo content (personas/, protocols/,
formats/, templates/, manifest.yaml) rather than synthetic fixtures,
so they catch structural regressions without maintenance burden.

Infrastructure:
- Jest dev dependency with test and test:coverage scripts
- CI workflow (.github/workflows/cli-tests.yml) triggers on cli/ changes
- coverage/ added to .gitignore

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@abeltrano abeltrano force-pushed the test/cli-jest-suite branch from fe3aea9 to f218c21 Compare March 30, 2026 21:15
@abeltrano abeltrano closed this Mar 30, 2026
@abeltrano
Copy link
Copy Markdown
Collaborator Author

Abandoning in favor of generating test cases from newly added validation.md in #145

@abeltrano
Copy link
Copy Markdown
Collaborator Author

Suggestion: Use data-driven tests instead of hardcoded component names

The tests currently hardcode specific component names (systems-engineer, anti-hallucination, investigate-bug, etc.) throughout all four test files. This means tests will break whenever components are added, renamed, or removed from the manifest — creating an ongoing maintenance burden.

Recommended approach

Iterate over the manifest dynamically so tests automatically cover every component with zero updates needed when the library evolves:

Before (brittle):

test("finds persona by name", () => {
  const persona = getPersona(manifest, "systems-engineer");
  expect(persona).toBeDefined();
  expect(persona.path).toBe("personas/systems-engineer.md");
});

After (data-driven):

for (const p of manifest.personas) {
  test("persona '\' resolves to an existing file", () => {
    const found = getPersona(manifest, p.name);
    expect(found).toBeDefined();
    expect(fs.existsSync(path.join(repoRoot, found.path))).toBe(true);
  });
}

This pattern applies across all test files:

  • manifest.test.js — iterate manifest.personas, all protocol categories, manifest.formats, manifest.taxonomies for lookup tests; iterate getTemplates(manifest) for resolveTemplateDeps
  • assemble.test.jsloadComponent should verify all manifest-referenced paths load and strip headers; assemble() should verify structural correctness for every template (or at least one per category)
  • launch.test.jscopyContentToTemp should load the manifest from the temp dir and verify all referenced paths exist, rather than checking hardcoded filenames
  • cli.test.js — use list --json output to pick a template name dynamically instead of hardcoding investigate-bug

Additional gap

resolveTemplateDeps is tested for missing protocols but not for missing persona, format, or taxonomy — those edge cases should be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No automated tests for PromptKit CLI (npx module)

1 participant