Skip to content

Wrap token usage step summary in a details section#24375

Merged
pelikhan merged 2 commits intomainfrom
copilot/wrap-token-usage-summary
Apr 3, 2026
Merged

Wrap token usage step summary in a details section#24375
pelikhan merged 2 commits intomainfrom
copilot/wrap-token-usage-summary

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Summary

Wraps the Token Usage step summary in a collapsible details section, consistent with how other step summaries are rendered (e.g. "MCP Gateway Activity", "DIFC Filtered Events", "Agentic Conversation").

Changes

  • actions/setup/js/parse_mcp_gateway_log.cjs: Refactored generateTokenUsageSummary to return only the table markdown content (no raw HTML wrapper). writeStepSummaryWithTokenUsage now uses coreObj.summary.addDetails("Token Usage", ...) to wrap the content, using the core.summary.* helper API. The emoji has been removed from the section label.
  • actions/setup/js/parse_mcp_gateway_log.test.cjs: Updated test assertions to reflect the new return value of generateTokenUsageSummary (table content only, no <details> wrapper), and added addDetails to the mock summary object.


const lines = [];
lines.push("### 📊 Token Usage\n");
lines.push("<details>");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot remove emoji, use core.summary.* helpers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 3ce5f64. Removed the emoji from the label and refactored writeStepSummaryWithTokenUsage to use coreObj.summary.addDetails("Token Usage", ...) instead of building raw HTML in generateTokenUsageSummary. The generator now returns just the table markdown content.

Copilot AI requested a review from pelikhan April 3, 2026 21:06
@pelikhan pelikhan marked this pull request as ready for review April 3, 2026 21:34
Copilot AI review requested due to automatic review settings April 3, 2026 21:34
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

Wraps the “Token Usage” step summary output in a collapsible section to match the UX of other step summaries.

Changes:

  • Refactors generateTokenUsageSummary to return only the token-usage table markdown (removes the “### 📊 Token Usage” heading).
  • Updates writeStepSummaryWithTokenUsage to wrap the token usage markdown via core.summary.addDetails("Token Usage", ...).
  • Adjusts unit tests to match the new generateTokenUsageSummary output and mocks addDetails on the summary object.
Show a summary per file
File Description
actions/setup/js/parse_mcp_gateway_log.cjs Removes the token-usage heading from generated markdown and renders token usage inside a step-summary details block via addDetails.
actions/setup/js/parse_mcp_gateway_log.test.cjs Updates assertions to reflect the new token-usage markdown shape and extends the mocked summary API with addDetails.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines 183 to 188
coreObj.info(`Found token-usage.jsonl (${content.length} bytes)`);
const parsedSummary = parseTokenUsageJsonl(content);
const markdown = generateTokenUsageSummary(parsedSummary);
if (markdown.length > 0) {
coreObj.summary.addRaw(markdown);
coreObj.summary.addDetails("Token Usage", "\n\n" + markdown);
}
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The new coreObj.summary.addDetails("Token Usage", ...) behavior isn’t covered by tests. Consider adding a unit test that mocks fs.existsSync/fs.readFileSync for TOKEN_USAGE_PATH and asserts summary.addDetails is called with the expected label and markdown content (and that summary.write() still runs).

Copilot uses AI. Check for mistakes.
Comment on lines 1005 to 1009
test("renders header and table columns", () => {
const summary = parseTokenUsageJsonl(JSON.stringify({ model: "claude-sonnet-4-6", provider: "anthropic", input_tokens: 100, output_tokens: 200, cache_read_tokens: 5000, cache_write_tokens: 3000, duration_ms: 2500 }));
const md = generateTokenUsageSummary(summary);
expect(md).toContain("### 📊 Token Usage");
expect(md).toContain("| Model | Input | Output | Cache Read | Cache Write | ET | Requests | Duration |");
expect(md).toContain("claude-sonnet-4-6");
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

This test name is now misleading: generateTokenUsageSummary no longer renders a header (the assertion for the header was removed). Rename the test to reflect what it actually verifies (e.g., table columns/content).

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 2f74213 into main Apr 3, 2026
67 checks passed
@pelikhan pelikhan deleted the copilot/wrap-token-usage-summary branch April 3, 2026 21:39
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.

3 participants