Skip to content

fix(powershell): return full export run history in Get-FinOpsCostExport#2183

Open
RolandKrummenacher wants to merge 2 commits into
devfrom
fix/2063-costexport-runhistory
Open

fix(powershell): return full export run history in Get-FinOpsCostExport#2183
RolandKrummenacher wants to merge 2 commits into
devfrom
fix/2063-costexport-runhistory

Conversation

@RolandKrummenacher

Copy link
Copy Markdown
Collaborator

🪲 Fixes

Fixes #2063

Get-FinOpsCostExport -RunHistory returned fewer runs than expected because it relied solely on the Cost Management list endpoint (GET .../exports?$expand=runHistory), which truncates the runHistory.value array per export. The individual get endpoint (GET .../exports/{name}?$expand=runHistory) returns the complete run history.

🛠️ Changes

  • When -RunHistory is specified, after the list call the cmdlet now makes an additional individual GET per export to retrieve the full run history (one extra API call per export).
  • If the individual GET fails, it falls back to the run history returned by the list response so the cmdlet still returns data.
  • Behavior without -RunHistory is unchanged (single list call, no $expand, no per-export calls).

✔️ Testing

Updated/added unit tests in Get-FinOpsCostExport.Tests.ps1:

  • Verifies the individual GET endpoint is queried and the full run history (not the truncated list) is returned.
  • Verifies no per-export call or $expand is made when -RunHistory is omitted.
  • Verifies fallback to list run history when the individual GET fails.
  • Verifies empty run history is handled.

All 5 tests pass; PSScriptAnalyzer reports no findings.

📃 Documentation

  • Added a v15 PowerShell module entry to the changelog.

🤖 Generated with Claude Code

…rt (#2063)

Get-FinOpsCostExport -RunHistory used the Cost Management list endpoint
with $expand=runHistory, which truncates run history per export. When
-RunHistory is specified, re-fetch each export individually via the
GET endpoint, which returns the complete run history. Falls back to the
list-endpoint history if the individual GET fails.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 16, 2026 17:17
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs: Review 👀 PR that is ready to be reviewed label Jun 16, 2026

Copilot AI left a comment

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.

Pull request overview

This PR fixes incomplete export run history results in the FinOps Toolkit PowerShell module by changing Get-FinOpsCostExport -RunHistory to re-fetch each export via the Cost Management individual GET endpoint, which returns the full runHistory rather than the truncated list response.

Changes:

  • Added per-export GET .../exports/{name}?$expand=runHistory calls when -RunHistory is specified, with a fallback to the list-provided run history on failure.
  • Updated Pester unit tests to validate full run history behavior, no extra calls when -RunHistory is omitted, and handling of failure/empty histories.
  • Added a v15 changelog entry documenting the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/powershell/Public/Get-FinOpsCostExport.ps1 Re-fetch each export individually to return full run history when -RunHistory is used, with fallback behavior.
src/powershell/Tests/Unit/Get-FinOpsCostExport.Tests.ps1 Expands unit test coverage for full history retrieval, no-expand behavior, fallback, and empty run history cases.
docs-mslearn/toolkit/changelog.md Documents the Get-FinOpsCostExport -RunHistory fix in the v15 changelog.

Comment on lines +258 to +262
# Assert
$result | Should -Not -BeNullOrEmpty
$result.RunHistory | Should -HaveCount 1
$result.RunHistory[0].RunId | Should -Be 'run1'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Review 👀 PR that is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-FinOpsCostExport -RunHistory returns incomplete run history

4 participants