Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions actions/setup/js/safe_output_type_validator.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const SAMPLE_VALIDATION_CONFIG = {
fields: {
body: { type: "string", sanitize: true, maxLength: 65000 },
event: { type: "string", enum: ["APPROVE", "REQUEST_CHANGES", "COMMENT"] },
pull_request_number: { optionalPositiveInteger: true },
pull_request_number: { issueOrPRNumber: true },
repo: { type: "string", maxLength: 256 },
},
},
Expand Down Expand Up @@ -388,7 +388,7 @@ describe("safe_output_type_validator", () => {
const result = validateItem({ type: "submit_pull_request_review", event: "APPROVE", pull_request_number: "42", repo: "owner/repo" }, "submit_pull_request_review", 1);

expect(result.isValid).toBe(true);
expect(result.normalizedItem.pull_request_number).toBe(42);
expect(result.normalizedItem.pull_request_number).toBe("42"); // IssueOrPRNumber does not normalize strings to integers
expect(result.normalizedItem.repo).toBe("owner/repo");
});

Expand Down Expand Up @@ -423,7 +423,8 @@ describe("safe_output_type_validator", () => {
it("should reject invalid submit_pull_request_review pull_request_number", async () => {
const { validateItem } = await import("./safe_output_type_validator.cjs");

const invalidValues = [0, -1, "abc", 3.14];
// IssueOrPRNumber accepts any string or number - only reject invalid types

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] Narrowing the invalid-value set silently removes rejection of 0 and -1. With IssueOrPRNumber, these pass validation and reach pr_helpers.cjs where parseInt(String(0)) = 0 — which is not NaN, so the handler accepts it and fires a GitHub API call for PR #0 or #-1. The previous OptionalPositiveInteger caught these at validation time.

💡 Suggested addition to the test
// Values that pass IssueOrPRNumber validation but are still semantically
// invalid PR numbers — the handler (or validator) should reject them
const edgeCaseValues = [0, -1, 3.14];
for (const value of edgeCaseValues) {
  const result = validateItem(
    { type: 'submit_pull_request_review', event: 'APPROVE', pull_request_number: value },
    'submit_pull_request_review', 1
  );
  // Document whether these should be valid or invalid, and why
}

If zero/negative numbers are intentionally allowed (relying on the GitHub API to reject them), a comment explaining that decision would help future readers.

const invalidValues = [{ foo: "bar" }, ["array"], true];
for (const value of invalidValues) {
const result = validateItem({ type: "submit_pull_request_review", event: "APPROVE", pull_request_number: value }, "submit_pull_request_review", 1);
expect(result.isValid).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion pkg/workflow/safe_outputs_validation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ var ValidationConfig = map[string]TypeValidationConfig{
Fields: map[string]FieldValidation{
"body": {Type: "string", Sanitize: true, MaxLength: MaxBodyLength},
"event": {Type: "string", Enum: []string{"APPROVE", "REQUEST_CHANGES", "COMMENT"}},
"pull_request_number": {OptionalPositiveInteger: true},
"pull_request_number": {IssueOrPRNumber: true},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/diagnose] This fix aligns submit_pull_request_review with the convention, but three other handlers still use OptionalPositiveInteger for their pull_request_number fields: create_pull_request_review_comment (line 224), reply_to_pull_request_review_comment (line 244), and close_pull_request (line 284). Consider a follow-up to fully resolve the inconsistency, or note in the PR body why those are intentionally different.

💡 Remaining instances
// create_pull_request_review_comment
"pull_request_number": {OptionalPositiveInteger: true}, // line 224

// reply_to_pull_request_review_comment
"pull_request_number": {OptionalPositiveInteger: true}, // line 244

// close_pull_request
"pull_request_number": {OptionalPositiveInteger: true}, // line 284

If these also need temp-ID support, they should switch to IssueOrPRNumber too.

"repo": {Type: "string", MaxLength: 256}, // Optional: target repository in format "owner/repo"
},
},
Expand Down
Loading