Skip to content

test(helpers): add assertPackageMetadata conformance helper (SW-039) - #283

Merged
dDevAhmed merged 1 commit into
DigiNodes:mainfrom
kobbzy:feat/sw-039-metadata-conformance-helper
Oct 20, 2026
Merged

dDevAhmed merged 1 commit into
DigiNodes:mainfrom
kobbzy:feat/sw-039-metadata-conformance-helper

Conversation

@kobbzy

@kobbzy kobbzy commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Add a reusable assertPackageMetadata test helper that centralises all generated-project package.json conformance assertions, eliminating the per-test readFileSync/JSON.parse boilerplate that was duplicated across template tests.

Changes

New file — tests/helpers/package-metadata.ts

  • readPackageJson(path) — reads and parses a package.json, throwing a descriptive error on missing file or invalid JSON.
  • assertPackageMetadata(path, options) — single call that asserts all seven conformance constraints:
    1. name matches the expected project name.
    2. scripts values match exactly (no missing or extra keys).
    3. engines.node matches the frozen minimum version.
    4. dependencies is absent (opt-out via allowDependencies).
    5. devDependencies is absent (opt-out via allowDevDependencies).
    6. Raw content contains no SECRET, SEED, or PRIVATE_KEY literals.
    7. Raw content contains no Stellar secret key strkey pattern.
  • ExpectedScripts and PackageMetadataOptions types exported for template tests.

tests/helpers/index.ts

  • Exports assertPackageMetadata, readPackageJson, ExpectedScripts, and PackageMetadataOptions.

tests/basic-app-package-metadata.test.ts

  • All existing tests migrated to assertPackageMetadata — duplicate read/parse boilerplate removed.
  • New consolidated test: 'conforms to all frozen package.json metadata constraints' exercises every check in a single call.
  • No production generator behaviour changed.

src/diagnostics/bounds.ts

  • Previously untracked file already imported by src/diagnostics/run.ts. Included to keep the build coherent; no SW-039 logic.

.changeset/sw-039-metadata-conformance-helper.md

  • Patch-level changeset entry for the helper addition.

Acceptance Criteria

  • Helper validates expected names/scripts/metadata deterministically.
  • No production generator behaviour changes.
  • At least one template test (basic-app-package-metadata.test.ts) adopts the helper.
  • All 9 tests in the conformance suite pass (npx vitest run tests/basic-app-package-metadata.test.ts).

Closes #141
Closes #130
Closes #142

- Add tests/helpers/package-metadata.ts with readPackageJson and
  assertPackageMetadata, centralising all generated package.json
  assertions: name, scripts (exact keys + values), engines.node,
  absence of dependencies/devDependencies, and no embedded secrets.
- Export both helpers and their types from tests/helpers/index.ts.
- Adopt the helper across all tests in basic-app-package-metadata.test.ts,
  removing the per-test readFileSync/JSON.parse boilerplate.
- Add a consolidated 'conforms to all frozen package.json metadata
  constraints' test that exercises every check in a single call.
- Include src/diagnostics/bounds.ts (previously untracked but already
  imported by src/diagnostics/run.ts) to keep the build coherent.
- Add changeset entry for the patch-level helper addition.

No production generator behaviour is changed.
@kobbzy
kobbzy requested a review from dDevAhmed as a code owner October 20, 2026 08:49
@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4b5add9d-40a4-4a86-95f7-1693aeaa5ff1
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dDevAhmed
dDevAhmed merged commit 87c1ed9 into DigiNodes:main Oct 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants