Skip to content

Clarify npm and pip package name validation errors#31822

Merged
pelikhan merged 4 commits into
mainfrom
copilot/extend-npm-pip-package-error-messages
May 13, 2026
Merged

Clarify npm and pip package name validation errors#31822
pelikhan merged 4 commits into
mainfrom
copilot/extend-npm-pip-package-error-messages

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

✨ Enhancement

Invalid npm/pip package names currently fail with value-only errors, which force workflow authors to look up naming rules elsewhere. This updates those validation errors to explain the constraint inline and show a canonical valid example.

  • What does this improve?

    • npm and pip package-name validation errors now include the rule summary and a concrete example, not just the rejected value.
    • Existing validator tests now assert the user-facing guidance, so future changes preserve the improved error quality.
  • Why is this valuable?

    • Shortens time-to-fix for common workflow authoring mistakes.
    • Brings these validation errors closer to the more actionable patterns already used elsewhere in the codebase.
  • Implementation approach:

    • Updated pkg/workflow/name_validation.go to expand the npm and PyPI error strings with format rules and examples.
    • Updated the existing package-name validation tests in pkg/workflow/argument_injection_test.go to verify:
      • the invalid input is still surfaced, and
      • the new rule/example guidance is present.
return fmt.Errorf(
	"invalid npm package name: %q — npm names must be lowercase alphanumeric and may include hyphens, dots, and underscores (e.g. \"my-package\" or \"@scope/name\")",
	pkg,
)

Copilot AI and others added 2 commits May 13, 2026 00:04
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Extend npm/pip package name validation error messages Clarify npm and pip package name validation errors May 13, 2026
Copilot AI requested a review from pelikhan May 13, 2026 00:11
@pelikhan pelikhan marked this pull request as ready for review May 13, 2026 00:11
Copilot AI review requested due to automatic review settings May 13, 2026 00:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances npm and pip package-name validation errors to include inline rule guidance and canonical examples, and updates tests to assert the improved user-facing error text.

Changes:

  • Expanded validateNpmPackageName and validatePipPackageName error messages with rule summaries and examples.
  • Updated existing validator tests to assert both the rejected value and the new guidance text.
  • Updated the generated .github/workflows/agentic_commands.yml header metadata (compiler_version).
Show a summary per file
File Description
pkg/workflow/name_validation.go Improves npm/PyPI validation error strings with rule + example guidance.
pkg/workflow/argument_injection_test.go Strengthens assertions to ensure errors include both the invalid value and guidance text.
.github/workflows/agentic_commands.yml Regenerated workflow header (compiler_version).

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

pkg/workflow/argument_injection_test.go:360

  • The same long expected PyPI guidance string is duplicated across multiple test cases. Consider factoring it into a single const/var used by all invalid-case entries to keep the table concise and reduce maintenance overhead if the wording changes.
		{
			name:        "name starting with hyphen is rejected",
			pkg:         "--index-url=https://attacker.example",
			expectError: true,
			errContains: "PyPI names must start and end with a letter or digit, with hyphens, underscores, or dots allowed inside (e.g. \"requests\" or \"my-package\")",
		},
  • Files reviewed: 3/3 changed files
  • Comments generated: 3

if !npmPackageNameRE.MatchString(pkg) {
nameValidationLog.Printf("Invalid npm package name: %s", pkg)
return fmt.Errorf("invalid npm package name: %q", pkg)
return fmt.Errorf("invalid npm package name: %q — npm names must be lowercase alphanumeric and may include hyphens, dots, and underscores (e.g. \"my-package\" or \"@scope/name\")", pkg)
Comment on lines 265 to 270
{
name: "name starting with hyphen is rejected",
pkg: "--registry=https://attacker.example",
expectError: true,
errContains: "invalid npm package name",
errContains: "npm names must be lowercase alphanumeric and may include hyphens, dots, and underscores (e.g. \"my-package\" or \"@scope/name\")",
},
@@ -1,4 +1,4 @@
# gh-aw-commands: {"payload_version":"v1","schema_version":"v1","compiler_version":"26ba207","commands":["ace","approach-validator","archie","brave","cloclo","craft","grumpy","mergefest","nit","plan","poem-bot","review","security-review","summarize","tidy","unbloat"],"workflows":["ace-editor","approach-validator","archie","brave","cloclo","craft","grumpy-reviewer","mergefest","pdf-summary","plan","poem-bot","pr-code-quality-reviewer","pr-nitpick-reviewer","security-review","tidy","unbloat-docs"]}
# gh-aw-commands: {"payload_version":"v1","schema_version":"v1","compiler_version":"26cb048","commands":["ace","approach-validator","archie","brave","cloclo","craft","grumpy","mergefest","nit","plan","poem-bot","review","security-review","summarize","tidy","unbloat"],"workflows":["ace-editor","approach-validator","archie","brave","cloclo","craft","grumpy-reviewer","mergefest","pdf-summary","plan","poem-bot","pr-code-quality-reviewer","pr-nitpick-reviewer","security-review","tidy","unbloat-docs"]}
@pelikhan pelikhan merged commit ad04922 into main May 13, 2026
22 of 23 checks passed
@pelikhan pelikhan deleted the copilot/extend-npm-pip-package-error-messages branch May 13, 2026 00:18
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.

UX: Extend npm/pip package name validation error messages with naming rules

3 participants