Skip to content

Commit 78f2a16

Browse files
Copilotpelikhan
andauthored
include effective token message in agent failure issue/comment footer (#24196)
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/ce790b60-0ef3-4dcc-b31a-13a21079fc23 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent da624a1 commit 78f2a16

2 files changed

Lines changed: 135 additions & 27 deletions

File tree

actions/setup/js/messages.test.cjs

Lines changed: 127 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("messages.cjs", () => {
3333
delete process.env.GH_AW_TRACKER_ID;
3434
delete process.env.GITHUB_RUN_ID;
3535
delete process.env.GH_AW_WORKFLOW_ID;
36+
delete process.env.GH_AW_EFFECTIVE_TOKENS;
3637
// Clear cache by reimporting
3738
vi.resetModules();
3839
});
@@ -676,54 +677,153 @@ describe("messages.cjs", () => {
676677
});
677678
});
678679

679-
describe("getCloseOlderDiscussionMessage", () => {
680-
it("should return default close older discussion message", async () => {
681-
const { getCloseOlderDiscussionMessage } = await import("./messages.cjs");
680+
describe("getFooterAgentFailureIssueMessage", () => {
681+
it("should return default footer without effective tokens when env var is not set", async () => {
682+
const { getFooterAgentFailureIssueMessage } = await import("./messages.cjs");
682683

683-
const result = getCloseOlderDiscussionMessage({
684-
newDiscussionUrl: "https://github.com/test/repo/discussions/10",
685-
newDiscussionNumber: 10,
684+
const result = getFooterAgentFailureIssueMessage({
686685
workflowName: "Test Workflow",
687686
runUrl: "https://github.com/test/repo/actions/runs/123",
688687
});
689688

690-
expect(result).toContain("This discussion has been marked as **outdated**");
691-
expect(result).toContain("[Test Workflow](https://github.com/test/repo/actions/runs/123)");
692-
expect(result).toContain("[Discussion #10](https://github.com/test/repo/discussions/10)");
689+
expect(result).toBe("> Generated from [Test Workflow](https://github.com/test/repo/actions/runs/123/agentic_workflow)");
690+
expect(result).not.toContain("●");
693691
});
694692

695-
it("should use custom close older discussion template", async () => {
693+
it("should include effective tokens in default footer when env var is set", async () => {
694+
process.env.GH_AW_EFFECTIVE_TOKENS = "12500";
695+
696+
const { getFooterAgentFailureIssueMessage } = await import("./messages.cjs");
697+
698+
const result = getFooterAgentFailureIssueMessage({
699+
workflowName: "Test Workflow",
700+
runUrl: "https://github.com/test/repo/actions/runs/123",
701+
});
702+
703+
expect(result).toBe("> Generated from [Test Workflow](https://github.com/test/repo/actions/runs/123/agentic_workflow) · ● 12.5K");
704+
});
705+
706+
it("should include effective tokens before history link in default footer", async () => {
707+
process.env.GH_AW_EFFECTIVE_TOKENS = "5000";
708+
const historyUrl = "https://github.com/search?q=repo:test/repo+is:issue&type=issues";
709+
710+
const { getFooterAgentFailureIssueMessage } = await import("./messages.cjs");
711+
712+
const result = getFooterAgentFailureIssueMessage({
713+
workflowName: "Test Workflow",
714+
runUrl: "https://github.com/test/repo/actions/runs/123",
715+
historyUrl,
716+
});
717+
718+
expect(result).toBe(`> Generated from [Test Workflow](https://github.com/test/repo/actions/runs/123/agentic_workflow) · ● 5K · [◷](${historyUrl})`);
719+
});
720+
721+
it("should not include effective tokens in custom footer unless placeholder is used", async () => {
722+
process.env.GH_AW_EFFECTIVE_TOKENS = "5000";
696723
process.env.GH_AW_SAFE_OUTPUT_MESSAGES = JSON.stringify({
697-
closeOlderDiscussion: "This is outdated. See [{new_discussion_number}]({new_discussion_url}).",
724+
agentFailureIssue: "> Custom: [{workflow_name}]({run_url})",
698725
});
699726

700-
const { getCloseOlderDiscussionMessage } = await import("./messages.cjs");
727+
const { getFooterAgentFailureIssueMessage } = await import("./messages.cjs");
701728

702-
const result = getCloseOlderDiscussionMessage({
703-
newDiscussionUrl: "https://github.com/test/repo/discussions/15",
704-
newDiscussionNumber: 15,
705-
workflowName: "Custom Bot",
706-
runUrl: "https://example.com/run/456",
729+
const result = getFooterAgentFailureIssueMessage({
730+
workflowName: "Test Workflow",
731+
runUrl: "https://github.com/test/repo/actions/runs/123",
732+
});
733+
734+
expect(result).toBe("> Custom: [Test Workflow](https://github.com/test/repo/actions/runs/123)");
735+
expect(result).not.toContain("●");
736+
});
737+
738+
it("should allow custom footer template to include effective tokens via placeholder", async () => {
739+
process.env.GH_AW_EFFECTIVE_TOKENS = "5000";
740+
process.env.GH_AW_SAFE_OUTPUT_MESSAGES = JSON.stringify({
741+
agentFailureIssue: "> Custom: [{workflow_name}]({run_url}){effective_tokens_suffix}",
742+
});
743+
744+
const { getFooterAgentFailureIssueMessage } = await import("./messages.cjs");
745+
746+
const result = getFooterAgentFailureIssueMessage({
747+
workflowName: "Test Workflow",
748+
runUrl: "https://github.com/test/repo/actions/runs/123",
749+
});
750+
751+
expect(result).toBe("> Custom: [Test Workflow](https://github.com/test/repo/actions/runs/123) · ● 5K");
752+
});
753+
});
754+
755+
describe("getFooterAgentFailureCommentMessage", () => {
756+
it("should return default footer without effective tokens when env var is not set", async () => {
757+
const { getFooterAgentFailureCommentMessage } = await import("./messages.cjs");
758+
759+
const result = getFooterAgentFailureCommentMessage({
760+
workflowName: "Test Workflow",
761+
runUrl: "https://github.com/test/repo/actions/runs/123",
762+
});
763+
764+
expect(result).toBe("> Generated from [Test Workflow](https://github.com/test/repo/actions/runs/123/agentic_workflow)");
765+
expect(result).not.toContain("●");
766+
});
767+
768+
it("should include effective tokens in default footer when env var is set", async () => {
769+
process.env.GH_AW_EFFECTIVE_TOKENS = "12500";
770+
771+
const { getFooterAgentFailureCommentMessage } = await import("./messages.cjs");
772+
773+
const result = getFooterAgentFailureCommentMessage({
774+
workflowName: "Test Workflow",
775+
runUrl: "https://github.com/test/repo/actions/runs/123",
707776
});
708777

709-
expect(result).toBe("This is outdated. See [15](https://github.com/test/repo/discussions/15).");
778+
expect(result).toBe("> Generated from [Test Workflow](https://github.com/test/repo/actions/runs/123/agentic_workflow) · ● 12.5K");
710779
});
711780

712-
it("should support snake_case placeholders", async () => {
781+
it("should include effective tokens before history link in default footer", async () => {
782+
process.env.GH_AW_EFFECTIVE_TOKENS = "5000";
783+
const historyUrl = "https://github.com/search?q=repo:test/repo+is:issue&type=issues";
784+
785+
const { getFooterAgentFailureCommentMessage } = await import("./messages.cjs");
786+
787+
const result = getFooterAgentFailureCommentMessage({
788+
workflowName: "Test Workflow",
789+
runUrl: "https://github.com/test/repo/actions/runs/123",
790+
historyUrl,
791+
});
792+
793+
expect(result).toBe(`> Generated from [Test Workflow](https://github.com/test/repo/actions/runs/123/agentic_workflow) · ● 5K · [◷](${historyUrl})`);
794+
});
795+
796+
it("should not include effective tokens in custom footer unless placeholder is used", async () => {
797+
process.env.GH_AW_EFFECTIVE_TOKENS = "5000";
713798
process.env.GH_AW_SAFE_OUTPUT_MESSAGES = JSON.stringify({
714-
closeOlderDiscussion: "Outdated by {workflow_name}. New: #{new_discussion_number}",
799+
agentFailureComment: "> Custom: [{workflow_name}]({run_url})",
715800
});
716801

717-
const { getCloseOlderDiscussionMessage } = await import("./messages.cjs");
802+
const { getFooterAgentFailureCommentMessage } = await import("./messages.cjs");
803+
804+
const result = getFooterAgentFailureCommentMessage({
805+
workflowName: "Test Workflow",
806+
runUrl: "https://github.com/test/repo/actions/runs/123",
807+
});
718808

719-
const result = getCloseOlderDiscussionMessage({
720-
newDiscussionUrl: "https://github.com/test/repo/discussions/20",
721-
newDiscussionNumber: 20,
722-
workflowName: "Weekly Report",
723-
runUrl: "https://example.com/run/789",
809+
expect(result).toBe("> Custom: [Test Workflow](https://github.com/test/repo/actions/runs/123)");
810+
expect(result).not.toContain("●");
811+
});
812+
813+
it("should allow custom footer template to include effective tokens via placeholder", async () => {
814+
process.env.GH_AW_EFFECTIVE_TOKENS = "5000";
815+
process.env.GH_AW_SAFE_OUTPUT_MESSAGES = JSON.stringify({
816+
agentFailureComment: "> Custom: [{workflow_name}]({run_url}){effective_tokens_suffix}",
817+
});
818+
819+
const { getFooterAgentFailureCommentMessage } = await import("./messages.cjs");
820+
821+
const result = getFooterAgentFailureCommentMessage({
822+
workflowName: "Test Workflow",
823+
runUrl: "https://github.com/test/repo/actions/runs/123",
724824
});
725825

726-
expect(result).toBe("Outdated by Weekly Report. New: #20");
826+
expect(result).toBe("> Custom: [Test Workflow](https://github.com/test/repo/actions/runs/123) · ● 5K");
727827
});
728828
});
729829
});

actions/setup/js/messages_footer.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ function getFooterAgentFailureIssueMessage(ctx) {
205205

206206
// Default footer template with link to workflow run
207207
let defaultFooter = "> Generated from [{workflow_name}]({agentic_workflow_url})";
208+
// Append effective tokens with ● symbol when available (compact format, no "ET" label)
209+
if (effectiveTokens) {
210+
defaultFooter += `{effective_tokens_suffix}`;
211+
}
208212
// Append history link when available
209213
if (ctx.historyUrl) {
210214
defaultFooter += " · [◷]({history_url})";
@@ -239,6 +243,10 @@ function getFooterAgentFailureCommentMessage(ctx) {
239243

240244
// Default footer template with link to workflow run
241245
let defaultFooter = "> Generated from [{workflow_name}]({agentic_workflow_url})";
246+
// Append effective tokens with ● symbol when available (compact format, no "ET" label)
247+
if (effectiveTokens) {
248+
defaultFooter += `{effective_tokens_suffix}`;
249+
}
242250
// Append history link when available
243251
if (ctx.historyUrl) {
244252
defaultFooter += " · [◷]({history_url})";

0 commit comments

Comments
 (0)