Skip to content
Open
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
36 changes: 30 additions & 6 deletions .github/workflows/update-integration-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ name: Integration Data Updater
# opens a PR through the Aspire bot GitHub App when the generated data changes.
#
# The bot owns the rolling `chore/update-integration-data` branch and force-pushes
# it on every run, so nobody should commit to it. The PR is labeled
# `:octocat: auto-merge`, which .github/policies/auto-merge.yml turns into an
# approval and a squash auto-merge once the required `ci-gate` check passes.
# Remove the label to hold a PR for manual review.
# it on every run, so nobody should commit to it. When the updater's unit tests
# pass against the new data, the PR is labeled `:octocat: auto-merge`, which
# .github/policies/auto-merge.yml turns into an approval and a squash auto-merge
# once the required `ci-gate` check passes. Remove the label to hold a PR for
# manual review.
#
# All logic lives in src/frontend/scripts/update-integration-data.ps1 so the
# exact same flow can be reproduced locally:
Expand Down Expand Up @@ -92,6 +93,7 @@ jobs:
shell: pwsh
env:
GITHUB_TOKEN: ${{ github.token }}
ASTRO_TELEMETRY_DISABLED: 1
run: ./src/frontend/scripts/update-integration-data.ps1

- name: Commit and refresh automation branch
Expand Down Expand Up @@ -155,13 +157,19 @@ jobs:
BRANCH: ${{ steps.push.outputs.branch }}
PR_TITLE: ${{ steps.update.outputs.pr_title }}
PR_BODY_FILE: ${{ steps.update.outputs.pr_body_file }}
AUTO_MERGE: ${{ steps.update.outputs.auto_merge }}
shell: bash
run: |
set -euo pipefail

label=":octocat: auto-merge"
# Written by update-integration-data.ps1 when unit tests fail.
failure_marker="### :x: Unit tests failed"

# Reuse the existing open PR for the rolling branch if there is one, so
# its review threads and history carry over; otherwise open a fresh PR.
# Adding the label at creation is what triggers the auto-merge policy.
# Adding the label is what triggers the auto-merge policy, so it is only
# applied when the updater's unit tests passed against the new data.
existing=$(gh pr list \
--state open \
--head "$BRANCH" \
Expand All @@ -170,16 +178,31 @@ jobs:

if [ -n "$existing" ]; then
echo "Refreshing existing PR #$existing in place."
previous_body=$(gh pr view "$existing" --json body --jq .body)
has_label=$(gh pr view "$existing" --json labels \
--jq "any(.labels[]; .name == \"$label\")")
gh pr edit "$existing" \
--title "$PR_TITLE" \
--body-file "$PR_BODY_FILE"
if [ "$AUTO_MERGE" != "true" ] && [ "$has_label" = "true" ]; then
gh pr edit "$existing" --remove-label "$label"
elif [ "$AUTO_MERGE" = "true" ] && [ "$has_label" != "true" ] &&
grep -qF -- "$failure_marker" <<< "$previous_body"; then
Comment on lines +189 to +190
# Restore only a label this workflow removed; a maintainer's manual
# hold (label removed without the failure marker) is preserved.
gh pr edit "$existing" --add-label "$label"
fi
else
label_args=()
if [ "$AUTO_MERGE" = "true" ]; then
label_args=(--label "$label")
fi
new_pr=$(gh pr create \
--base main \
--head "$BRANCH" \
--title "$PR_TITLE" \
--body-file "$PR_BODY_FILE" \
--label ":octocat: auto-merge")
"${label_args[@]}")
echo "Created $new_pr"
fi

Expand Down Expand Up @@ -230,6 +253,7 @@ jobs:
echo "- Versions changed: \`${{ steps.update.outputs.versions_changed || 'n/a' }}\`"
echo "- API regen ran: \`${{ steps.update.outputs.regen_ran || 'n/a' }}\`"
echo "- Semantic validation: \`${{ steps.update.outputs.semantic_validation || 'not run' }}\`"
echo "- Unit tests: \`${{ steps.update.outputs.unit_tests || 'not run' }}\`"
if [ -n "${{ steps.update.outputs.icon_warnings }}" ]; then
echo "- Icon warnings: \`${{ steps.update.outputs.icon_warnings }}\`"
fi
Expand Down
80 changes: 70 additions & 10 deletions src/frontend/scripts/update-integration-data.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -757,18 +757,16 @@ Write-Host "All changes are within the allowed data paths." -ForegroundColor Gre
# ── File-count summary (for the PR body) ────────────────────────────────────
function Get-AreaCounts {
param([Parameter(Mandatory)][string]$Prefix)
$names = @(Invoke-Git @('diff', '--name-status', 'HEAD', '--', $Prefix) |
# Generated files are untracked until the workflow stages them, so `git diff`
# alone misses every added file. Version bumps count as an add and a removal.
$names = @(Invoke-Git @('status', '--porcelain', '--untracked-files=all', '--', $Prefix) |
Where-Object { $_ -and $_.Trim().Length -gt 0 })
$added = 0; $modified = 0; $removed = 0
foreach ($n in $names) {
$code = ($n.Trim())[0]
switch ($code) {
'A' { $added++ }
'M' { $modified++ }
'D' { $removed++ }
'R' { $modified++ }
default { }
}
$code = $n.Substring(0, 2)
if ($code -eq '??' -or $code.Contains('A')) { $added++ }
elseif ($code.Contains('D')) { $removed++ }
elseif ($code -match '[MR]') { $modified++ }
}
return [PSCustomObject]@{ Added = $added; Modified = $modified; Removed = $removed }
}
Expand All @@ -779,6 +777,57 @@ $goModulesCounts = Get-AreaCounts -Prefix 'src/frontend/src/data/go-modules/'
$twoslashChanged = @(Invoke-Git @('diff', '--name-only', 'HEAD', '--', 'src/frontend/src/data/twoslash/aspire.d.ts') |
Where-Object { $_ -and $_.Trim().Length -gt 0 }).Count -gt 0

# ── Phase 6: CI unit tests ──────────────────────────────────────────────────
# The semantic gate above only checks generated API data. CI also runs data-
# dependent unit tests (API reference resolution, synced sample content), so run
# them here: a failure still refreshes the PR, but without auto-merge.
Write-Section 'Phase 6 — bun run test:unit'
# Tests run after the scope check, and the workflow stages the allowed paths
# afterwards, so any test that rewrites generated data would leak into the PR.
function Get-DataSnapshot {
$paths = @(Invoke-Git (@('status', '--porcelain', '--untracked-files=all', '--') + $AllowedPaths) |
Where-Object { $_ -and $_.Trim().Length -gt 0 } |
ForEach-Object { (($_.Substring(3)) -split ' -> ')[-1].Trim('"') })
@($paths | Sort-Object | ForEach-Object {
$full = Join-Path $RepoRoot $_
$hash = if (Test-Path -LiteralPath $full -PathType Leaf) { (Get-FileHash -LiteralPath $full).Hash } else { 'missing' }
"$_ $hash"
}) -join "`n"
}
$dataSnapshot = Get-DataSnapshot
Push-Location $FrontendDir
try {
$unitTestLog = & bun run test:unit 2>&1 | Tee-Object -Variable unitTestTeed | Out-String
$unitTestExit = $LASTEXITCODE
}
finally {
Pop-Location
}
if ((Get-DataSnapshot) -ne $dataSnapshot) {
Write-Error "bun run test:unit modified generated data under the allowed paths. Aborting; no PR will be opened."
exit 1
}
$unitTestFailures = @($unitTestLog -split "`r?`n" |
ForEach-Object { $_ -replace '\x1b\[[0-9;]*m', '' } |
Where-Object { $_ -match '^\s*FAIL\s+(?<Test>\S.*?)\s*$' } |
ForEach-Object { $Matches.Test } |
Select-Object -Unique)
$unitTestsPassed = $unitTestExit -eq 0
if (-not $unitTestsPassed) {
if ($unitTestFailures.Count -eq 0) {
$unitTestFailures = @("bun run test:unit exited with code $unitTestExit")
}
$unitTestWarning = "Unit tests failed against the updated data; the PR will not auto-merge."
Write-Warning $unitTestWarning
foreach ($failure in $unitTestFailures) { Write-Warning " $failure" }
if ($IsCI) {
Write-Host "::warning title=Unit tests failed::$unitTestWarning"
}
}
else {
Write-Host "Unit tests passed." -ForegroundColor Green
}

# ── PR title + body ─────────────────────────────────────────────────────────
$dateShort = [DateTime]::UtcNow.ToString('M/d/yy', [System.Globalization.CultureInfo]::InvariantCulture)
$prTitle = "chore: Update integration data and GitHub stats ($dateShort)"
Expand All @@ -788,7 +837,16 @@ $sb = [System.Text.StringBuilder]::new()
[void]$sb.AppendLine("")
[void]$sb.AppendLine("Generated deterministically by ``src/frontend/scripts/update-integration-data.ps1`` (no agent inference).")
[void]$sb.AppendLine("")
[void]$sb.AppendLine("This PR is approved and squash-merged automatically once ``ci-gate`` passes, as configured in ``.github/policies/auto-merge.yml``. Remove the ``:octocat: auto-merge`` label to hold it for manual review.")
if ($unitTestsPassed) {
[void]$sb.AppendLine("This PR is approved and squash-merged automatically once ``ci-gate`` passes, as configured in ``.github/policies/auto-merge.yml``. Remove the ``:octocat: auto-merge`` label to hold it for manual review.")
}
else {
[void]$sb.AppendLine("### :x: Unit tests failed")
[void]$sb.AppendLine("")
[void]$sb.AppendLine("``bun run test:unit`` failed against this data, so this PR is **not** labeled for auto-merge. Fix the failures on ``main``; the next updater run refreshes this PR and restores the ``:octocat: auto-merge`` label once the tests pass.")
[void]$sb.AppendLine("")
foreach ($failure in $unitTestFailures) { [void]$sb.AppendLine("- ``$failure``") }
}
[void]$sb.AppendLine("")
[void]$sb.AppendLine("### What's updated")
[void]$sb.AppendLine("- ``src/frontend/src/data/aspire-integrations.json`` — latest package information")
Expand Down Expand Up @@ -914,6 +972,8 @@ Set-Output 'pr_title' $prTitle
Set-Output 'pr_body_file' $prBodyFile
Set-Output 'icon_warnings' $iconWarnings
Set-Output 'api_failures' ($apiFailureDetails -join "`n")
Set-Output 'unit_tests' $(if ($unitTestsPassed) { 'passed' } else { 'failed' })
Set-Output 'auto_merge' ($unitTestsPassed.ToString().ToLowerInvariant())

Write-Host "PR title : $prTitle"
Write-Host "PR body : $prBodyFile"
Expand Down
12 changes: 0 additions & 12 deletions src/frontend/src/data/api-generation-failures.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
[
{
"name": "Aspire.Hosting.Azure.ApiManagement",
"version": "17.0.0-preview.1.26567.5",
"stage": "TypeScript",
"reason": "Declared export Aspire.Hosting.Azure.AzureApiManagementResource.Identity has no matching generated TypeScript API."
},
{
"name": "Aspire.Hosting.Kubernetes",
"version": "17.0.0",
"stage": "TypeScript",
"reason": "Declared export Aspire.Hosting.Kubernetes.Resources.BaseKubernetesResource.Metadata has no matching generated TypeScript API."
},
{
"name": "CommunityToolkit.Aspire.Hosting.Chroma",
"version": "17.0.0-beta.1052",
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/utils/api-reference-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface ApiReferenceTsCallable {
export interface ApiReferenceTsHandle {
name: string;
fullName?: string;
baseTypeHierarchy?: string[];
capabilities?: ApiReferenceTsCallable[];
}

Expand Down
21 changes: 21 additions & 0 deletions src/frontend/src/utils/api-reference/typescript-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface TsRouteCandidate {
targetTypeId?: string;
expandedTargetTypes: string[];
parentTypeFullName?: string;
parentBaseTypeFullNames: string[];
path: string;
priority: number;
parameters?: ApiReferenceTsCallable['parameters'];
Expand Down Expand Up @@ -103,6 +104,7 @@ function buildTsRouteIndex(modules: readonly ApiReferenceTsDocument[]): TsRouteI
qualifiedName: fn.qualifiedName,
targetTypeId: fn.targetTypeId,
expandedTargetTypes: fn.expandedTargetTypes ?? [],
parentBaseTypeFullNames: [],
path: `${modulePath}/${getTsItemSlug(fn, topLevelItems)}/`,
priority: 0,
parameters: fn.parameters,
Expand Down Expand Up @@ -136,6 +138,7 @@ function buildTsRouteIndex(modules: readonly ApiReferenceTsDocument[]): TsRouteI
targetTypeId: capability.targetTypeId,
expandedTargetTypes: capability.expandedTargetTypes ?? [],
parentTypeFullName: handle.fullName,
parentBaseTypeFullNames: handle.baseTypeHierarchy ?? [],
path,
priority,
parameters: capability.parameters,
Expand Down Expand Up @@ -172,6 +175,15 @@ function candidateMatchesMapping(route: TsRouteCandidate, mapping: ExportMapping
);
}

// ATS projects members of non-exported base types onto each exported derived
// handle, so a base-type member has no capability of its own.
function candidateInheritsMapping(route: TsRouteCandidate, mapping: ExportMapping): boolean {
const normalizedExpectedTypes = mapping.declaringTypeNames.map(normalizeTypeName);
return route.parentBaseTypeFullNames.some((baseType) =>
normalizedExpectedTypes.includes(normalizeTypeName(baseType))
);
}

function deduplicateTsCandidates(candidates: readonly TsRouteCandidate[]): TsRouteCandidate[] {
const unique = new Map<string, TsRouteCandidate>();
for (const candidate of candidates) {
Expand Down Expand Up @@ -228,6 +240,15 @@ function findTsCandidates(
return { matches: preferredTsCandidates(named), suggestions: named };
}

// Only when the declaring type has no capability of its own, so existing
// base-type references don't become ambiguous with derived projections.
const inherited = (tsIndex.byName.get(mapping.methodName.toLowerCase()) ?? []).filter((route) =>
candidateInheritsMapping(route, mapping)
);
if (inherited.length > 0) {
return { matches: preferredTsCandidates(inherited), suggestions: inherited };
}

return { matches: [], suggestions: named };
}

Expand Down
11 changes: 9 additions & 2 deletions src/frontend/tests/unit/api-reference.vitest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,12 @@ describe('API reference authoring validator', () => {
'/reference/api/typescript/aspire.hosting/distributedapplicationexecutioncontext/#ispublishmode'
);

const knownTypeScriptExportGaps = new Set([
// Experimental export.
'Aspire.Hosting.RadiusExtensions.WithContainerImage',
// Declared [AspireExport] upstream, but absent from the generated ATS capabilities.
'Aspire.Hosting.Azure.AzureApiManagementResource.Identity',
]);
const declaredExportFailures: string[] = [];
const checkedExports = new Set<string>();
for (const pkg of packageDocuments) {
Expand All @@ -1378,8 +1384,9 @@ describe('API reference authoring validator', () => {
if (!hasMemberExport) continue;

const fqn = `${typeName}.${member.name}`;
// Experimental export that the TypeScript generator currently omits.
if (fqn === 'Aspire.Hosting.RadiusExtensions.WithContainerImage') continue;
// Exports the TypeScript generator currently omits. Keep these here, not in
// api-generation-failures.json, which the integration data updater rewrites.
if (knownTypeScriptExportGaps.has(fqn)) continue;
const key = `${pkg.package.name}\0${fqn}`;
if (checkedExports.has(key)) continue;
checkedExports.add(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,17 @@ describe('standalone dashboard sample image', () => {
test('preserves the upstream nightly version pin in both README fields', () => {
const sample = samples.find((entry) => entry.name === 'standalone-dashboard');
expect(sample).toBeDefined();
// samples.json is synced from upstream, which bumps the pinned major.minor each release.
const pinnedImage = sample!.readme.match(
/mcr\.microsoft\.com\/aspire\/nightly\/dashboard:\d+\.\d+(?=[\s`])/
)?.[0];
expect(pinnedImage).toBeDefined();
for (const field of ['readme', 'readmeRaw'] as const) {
const source = sample![field];
const images = source.match(/mcr\.microsoft\.com\/[^\s`]+/g);
expect(images).toEqual([versionedNightlyImage, versionedNightlyImage]);
expect(source).toContain(`--name aspire-dashboard ${versionedNightlyImage}`);
expect(source).toContain(`\`${versionedNightlyImage}\` prerelease image.`);
expect(images).toEqual([pinnedImage, pinnedImage]);
expect(source).toContain(`--name aspire-dashboard ${pinnedImage}`);
expect(source).toContain(`\`${pinnedImage}\` prerelease image.`);
}
});
});
31 changes: 31 additions & 0 deletions src/frontend/tests/unit/integration-data-updater.vitest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ function global:bun {
& node $env:FIXTURE_TSX (Join-Path $PSScriptRoot 'src/frontend/scripts/validate-generated-api-data.ts')
$global:LASTEXITCODE = $LASTEXITCODE
}
'test:unit' {
if ($env:FIXTURE_MODE -eq 'unit-test-failure') {
Write-Output "$([char]27)[31m FAIL $([char]27)[39m tests/unit/data.vitest.test.ts > data > matches upstream"
$global:LASTEXITCODE = 1
}
if ($env:FIXTURE_MODE -eq 'unit-test-mutation') {
Set-Content (Join-Path $data 'twoslash/aspire.d.ts') 'rewritten by a test'
}
}
}
}
& "$PSScriptRoot/src/frontend/scripts/update-integration-data.ps1"
Expand All @@ -247,6 +256,7 @@ exit $LASTEXITCODE
'Mocks'
);
const output = path.join(root, 'outputs.txt');
const bodyFile = path.join(root, 'integration-pr-body.md');
const result = spawnSync('pwsh', ['-NoProfile', '-File', wrapper], {
cwd: root,
encoding: 'utf8',
Expand All @@ -263,6 +273,7 @@ exit $LASTEXITCODE
...result,
data,
outputs: fs.existsSync(output) ? fs.readFileSync(output, 'utf8') : '',
body: fs.existsSync(bodyFile) ? fs.readFileSync(bodyFile, 'utf8') : '',
failures: JSON.parse(
fs.readFileSync(path.join(data, 'api-generation-failures.json'), 'utf8')
) as ApiGenerationFailure[],
Expand All @@ -280,6 +291,26 @@ describe('integration data orchestration', () => {
expect(run.failures).toHaveLength(2);
expect(run.failures[0].reason).toContain('NU1102');
expect(run.outputs).toContain('api_failures_checked<<');
// Good moves 1.0.0 -> 2.0.0; the new file is untracked until the workflow stages it.
expect(run.body).toContain('| `src/frontend/src/data/pkgs/**` | 1 | 0 | 1 |');
expect(run.outputs).toMatch(/auto_merge<<(\S+)\ntrue\n/);
});

test('withholds auto-merge and lists failing unit tests', () => {
const run = fixture('unit-test-failure');
expect(run.status, run.stdout + run.stderr).toBe(0);
expect(run.outputs).toMatch(/changed<<(\S+)\ntrue\n/);
expect(run.outputs).toMatch(/auto_merge<<(\S+)\nfalse\n/);
expect(run.body).toContain('### :x: Unit tests failed');
expect(run.body).toContain('- `tests/unit/data.vitest.test.ts > data > matches upstream`');
expect(run.body).not.toContain('approved and squash-merged automatically');
});

test('refuses to publish when unit tests rewrite generated data', () => {
const run = fixture('unit-test-mutation');
expect(run.status, run.stdout + run.stderr).toBe(1);
expect(run.stdout + run.stderr).toContain('modified generated data');
expect(run.outputs).not.toContain('changed<<');
});

test('restores a matching C#/TypeScript pair when only the TS generation fails', () => {
Expand Down
Loading
Loading