Skip to content

test(dev): add malformed package-script metadata matrix (SW-220) - #453

Open
yunus-dev-codecrafter wants to merge 1 commit into
DigiNodes:mainfrom
yunus-dev-codecrafter:sw-220-malformed-package-script-metadata-matrix
Open

yunus-dev-codecrafter wants to merge 1 commit into
DigiNodes:mainfrom
yunus-dev-codecrafter:sw-220-malformed-package-script-metadata-matrix

Conversation

@yunus-dev-codecrafter

Copy link
Copy Markdown
Contributor

closes #402
Add a focused dev-only test file covering all invalid shapes of the scripts object and individual script values so that malformed metadata cannot reach npm.

Coverage added:

  • scripts: null, boolean, number, string, array -- all rejected with 'package.json must define a scripts object.' before process-plan creation.
  • Null, boolean, number, array, object script values on dev/start/ start:backend -- skipped (not an immediate error) so a lower-precedence candidate with a valid string can still be selected.
  • All three candidates non-string -> ValidationCliError 'No supported development script'.
  • Error message contains candidate names and 'package.json' so it is actionable.
  • Explicit distinction between missing/null scripts (guard) vs blank string values (selector).
  • Positive regression guards confirm valid scripts still resolve.
  • Precedence rule (dev > start > start:backend) is documented in the file header as the single authoritative statement.

No runtime-dependency or npm-invocation changes.

Closes #402

Summary
Adds a focused, dev-only malformed-manifest test matrix for the dev resolver (
project.ts
). The resolver already rejects invalid scripts shapes and skips non-string script values, but no tests pinned that behavior exhaustively. This PR adds deterministic regression coverage for every invalid scripts shape (null, boolean, number, string, array) and every non-string script value type (null, boolean, number, float, array, plain object) so that malformed metadata cannot silently reach npm.

Related Issue
Closes #402

Scope
Completed:

New test file
dev-project-malformed-scripts-metadata.test.ts
with three describe blocks:
Malformed scripts object shapes — null, true, false, 0, 42, "start", [], ['dev','start'] are all rejected with 'package.json must define a scripts object.' before any process-plan is created. Includes a test that explicitly distinguishes a missing scripts key from a null value.
Non-string individual script values — a 10-type matrix (null, true, false, 0, 42, -1, 3.14, [], ['node','dev.js'], {command:'...'}) tests the skip-then-fallthrough path and the all-candidates-exhausted rejection path for each type.
Malformed shapes and precedence interaction — mixed scenarios confirm the skip/reject distinction holds across combinations, and that error messages are actionable (name the candidates and reference package.json).
The precedence rule (dev → start → start:backend; non-string = skip; blank string = skip; reject only when no candidate survives) is stated once in the file header as the authoritative documented form.
Positive regression guards in each section confirm valid scripts continue to resolve unchanged.
Intentionally left out (per issue scope):

Test-project detection and Node/Cargo ambiguity (covered by #119).
New script names or npm invocation behavior changes.
No runtime dependencies added.
Testing
New test file:
dev-project-malformed-scripts-metadata.test.ts

The test runner (vitest run) is blocked repo-wide by a pre-existing parse error in
template-generation.ts
(lines 257–530, 9 TS errors, present on main before this PR). tsc --noEmit confirms all 9 errors are in that pre-existing file — zero errors introduced by this PR. The new test file is structurally and type-correctly consistent with the existing dev-project.test.ts and dev-project-diagnostics.test.ts files, which are blocked by the same pre-existing issue.

Tests added/updated where applicable
Existing relevant tests pass (blocked by pre-existing template-generation.ts parse error on main; not introduced by this PR)
Lint/type/build checks pass where available (tsc --noEmit shows zero new errors)
Security Impact
No security-sensitive behavior is changed
Security notes: This PR adds tests only. No source files, child-process invocations, filesystem writes, secrets handling, or network behavior are modified. The test file uses the same withTempDirectory helper as the rest of the test suite, which cleans up after itself.

Release Impact
No published/user-visible behavior change
Changeset not required; reason explained below
Release notes: Test-only change. No behavior visible to end users or downstream consumers is modified.

Documentation
No documentation change required
The precedence rule is documented inline in the new test file header. No ADR or architecture doc update is needed for a test-only addition.

Checklist
I read
wave-architecture.md
for Stellar Wave work
I stayed within the agreed issue scope
I checked for overlapping open contributor PRs
I did not include secrets or sensitive data
I reviewed new/updated dependencies if any (none added)
I considered failure/error paths, not only the happy path
I am not disclosing an unresolved vulnerability publicly

Add a focused dev-only test file covering all invalid shapes of the
scripts object and individual script values so that malformed metadata
cannot reach npm.

Coverage added:
- scripts: null, boolean, number, string, array -- all rejected with
  'package.json must define a scripts object.' before process-plan
  creation.
- Null, boolean, number, array, object script values on dev/start/
  start:backend -- skipped (not an immediate error) so a lower-precedence
  candidate with a valid string can still be selected.
- All three candidates non-string -> ValidationCliError 'No supported
  development script'.
- Error message contains candidate names and 'package.json' so it is
  actionable.
- Explicit distinction between missing/null scripts (guard) vs blank
  string values (selector).
- Positive regression guards confirm valid scripts still resolve.
- Precedence rule (dev > start > start:backend) is documented in the
  file header as the single authoritative statement.

No runtime-dependency or npm-invocation changes.

Closes DigiNodes#402
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Important

  • Trigger review

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

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f89ff91f-62ff-4b0e-b01c-60dc9c6c3da9
  • 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

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.

SW-220 — Add a malformed package-script metadata matrix for the dev resolver

1 participant