-
Notifications
You must be signed in to change notification settings - Fork 414
Make add_comment wildcard target misses non-fatal in safe outputs
#37041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32d9baf
79129bc
59681e4
8ba5273
07064c4
eb3ac1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,7 +222,7 @@ describe("add_comment", () => { | |
| expect(result.itemNumber).toBe(28912); | ||
| }); | ||
|
|
||
| it("should fail when target is '*' but no item_number provided", async () => { | ||
| it("should skip (not fail) when target is '*' but no item_number provided", async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] Missing regression test for the "strict behavior preserved" invariant — when The updated test only locks in the skip path. Without a complementary test for the hard-fail path, the 💡 Suggested additional testAdd a test adjacent to the current one: it("should hard-fail (not skip) when target is * but explicit field resolves nothing meaningful", async () => {
// Tests that having a recognized field still triggers hard-fail
// when resolveTarget returns shouldFail (strict behavior preserved)
const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8");
const handler = await eval(`(async () => { ${addCommentScript}; return await main({ target: * }); })()`);
const message = {
type: "add_comment",
pull_request_number: 42, // explicit field present — should still hard-fail
body: "Test comment",
};
const result = await handler(message, {});
expect(result.success).toBe(false);
expect(result.skipped).toBeUndefined(); // NOT a skip — explicit field was provided
});This makes the skip-vs-fail boundary explicit and protects against accidental widening of the skip condition. |
||
| const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8"); | ||
|
|
||
| const handler = await eval(`(async () => { ${addCommentScript}; return await main({ target: '*' }); })()`); | ||
|
|
@@ -235,9 +235,28 @@ describe("add_comment", () => { | |
| const result = await handler(message, {}); | ||
|
|
||
| expect(result.success).toBe(false); | ||
| expect(result.skipped).toBe(true); | ||
| expect(result.error).toMatch(/no.*item_number/i); | ||
| }); | ||
|
|
||
| it("should hard-fail (not skip) when target is '*' and explicit pull_request_number is invalid", async () => { | ||
| const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8"); | ||
|
|
||
| const handler = await eval(`(async () => { ${addCommentScript}; return await main({ target: '*' }); })()`); | ||
|
|
||
| const message = { | ||
| type: "add_comment", | ||
| pull_request_number: "invalid", | ||
| body: "Test comment with invalid explicit pull_request_number", | ||
| }; | ||
|
|
||
| const result = await handler(message, {}); | ||
|
|
||
| expect(result.success).toBe(false); | ||
| expect(result.skipped).toBeUndefined(); | ||
| expect(result.error).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("should use explicit item_number even with triggering target", async () => { | ||
| const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8"); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnose]
item_numberandissue_numberinWILDCARD_TARGET_FIELDSare pre-handled byresolveSafeOutputIssueTargetat line 471 (using the same aliases). By the timeresolveTargetfails, those two fields are already absent or null in the message — making their presence in this list technically dead weight.The fields that can actually reach this code path unaided are
pull_request_number,pr_number,pr, andpull_number. A short JSDoc comment would make this intent explicit and prevent future drift.📋 Reasoning
resolveSafeOutputIssueTarget(line 471) uses aliases["item_number", "issue_number", "pr-number"]resolveTarget— we never enter theshouldFailbranchnumber: null, those fields are absent/null in the messagemessage.item_number != nullandmessage.issue_number != nullare always falseConsider narrowing and documenting:
Or keep the full list and add a comment explaining it serves as a belt-and-suspenders guard.