Skip to content

Detect drift in generated pipeline output - #21681

Merged
Eric Erhardt (eerhardt) merged 5 commits into
microsoft:mainfrom
MattKotsenas:feature/pipeline-output-diffing-standalone
Nov 3, 2026
Merged

Eric Erhardt (eerhardt) merged 5 commits into
microsoft:mainfrom
MattKotsenas:feature/pipeline-output-diffing-standalone

Conversation

@MattKotsenas

@MattKotsenas Matt Kotsenas (MattKotsenas) commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes #18833

Users sometimes add their generated assets to source control. Those assets can drift from the code that generates them, leading to stale deployments or deployed files that do not match the versioned artifacts.

To support these workflows, this PR adds an opt-in check that regenerates pipeline output from the current source and fails when selected artifacts are added, changed or removed.

builder.Pipeline.WithOutputDiffing();

Diffing hooks the publish step by default. Run aspire do publish-and-diff to generate and compare. Ordinary aspire do publish remains generation-only. Diffing can be configured to target any step.

The differ captures existing output before selected step actions, including prerequisite and build writers. It compares that capture with output after the comparison step's dependencies and action finish. The default differ checks the global directory returned by IPipelineOutputService.

When a usable Git worktree is available, the default differ uses Git membership and content semantics, including attributes and clean filters. Otherwise it uses filesystem membership and streaming XxHash3. Pipeline:OutputDiff configures ordered glob rules and whether Git is automatic, required or disabled. Custom IPipelineOutputDiffer and IPipelineOutputFileHasher implementations use ordinary host DI.

See docs/specs/pipeline-output.md for capture boundaries, postprocessing timing, link handling and extension contracts.

Security considerations

I checked 'Yes' for security assumptions, because enabling git trusts the Git executable and configuration.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21681

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21681"

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@IEvangelist

Copy link
Copy Markdown
Member

PR Testing Report (local, Windows, dogfood CLI)

Scenarios (aspire-empty + AddDockerComposeEnvironment + nginx container + builder.Pipeline.WithOutputDiffing())

# Scenario Result
1 aspire do publish-and-diff on a git repo with no committed output Pass - fails, Added: docker-compose.yaml
2 Commit output, rerun publish-and-diff Pass - 10/10 steps, exit 0
3 Tamper with docker-compose.yaml, plain aspire do publish Pass - generation-only, exit 0, output regenerated
4 Tamper again, publish-and-diff Pass - fails, Changed: docker-compose.yaml, exit 6
5 Non-git directory (filesystem fallback): clean run, then tamper Pass - exit 0, then Changed: docker-compose.yaml
6 Pipeline:OutputDiff:UseGit=true with no worktree Pass - clear failure: "Git is required to capture pipeline output..."

Notes

  • The Removed path and Pipeline:OutputDiff glob rules were not exercised end-to-end (unit tests cover them).
  • The scenario 6 message ends with a trailing : and an empty directory path in the observed output (possibly console wrapping); minor.
  • WithOutputDiffing requires using Aspire.Hosting.Pipelines; (not covered by implicit usings).

Overall: PR VERIFIED for tested scenarios.

@IEvangelist David Pine (IEvangelist) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Three non-blocking considerations: sharing process termination mechanics, environment-dependent output fingerprinting, and documenting Git protocol constants.

@MattKotsenas
Matt Kotsenas (MattKotsenas) force-pushed the feature/pipeline-output-diffing-standalone branch from 5be9395 to b9328e7 Compare November 2, 2026 15:08
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Register output diffing services and configuration only through the application builder. Use explicit capture modes, mark the diffing contracts experimental, and keep the file hasher internal.
Pair asynchronous snapshotters and comparers through a shared snapshot type. Add constrained builder overloads for custom providers while preserving the default opt-in and capture lifecycle.
Resolve snapshotters independently for before and after captures and select
the default strategy per capture. Keep only the baseline snapshot in a
StrongBox so default-valued struct snapshots remain valid.

Rename the built-in providers to Default, narrow interface documentation,
and update lifetime, retry, clone, and strategy-change coverage.
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@eerhardt Eric Erhardt (eerhardt) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@eerhardt
Eric Erhardt (eerhardt) merged commit c64ba9f into microsoft:main Nov 3, 2026
693 of 697 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Nov 3, 2026
@MattKotsenas
Matt Kotsenas (MattKotsenas) deleted the feature/pipeline-output-diffing-standalone branch November 3, 2026 18:23
Eric Erhardt (eerhardt) added a commit to microsoft/aspire.dev that referenced this pull request Nov 6, 2026
Add a new "Detect drift in generated pipeline output" page covering the
opt-in WithOutputDiffing API (microsoft/aspire#21681), the
`aspire do publish-and-diff` step, targeting other steps, the
Pipeline:OutputDiff configuration (rules and Git mode), how Git and
filesystem comparison work, a GitHub Actions example, and custom
snapshotter and comparer extensibility.

Also add the ASPIREPIPELINES005 diagnostic page, overview row, and sidebar
entries, and cross-link from the pipelines, CI/CD, Docker Compose, and
aspire do/publish reference pages.

Co-authored-by: Copilot App <[email protected]>
Eric Erhardt (eerhardt) added a commit to microsoft/aspire.dev that referenced this pull request Nov 10, 2026
## Summary

Documents the 17.0 feature "Detect drift in generated pipeline output"
from microsoft/aspire#21681 (fixes microsoft/aspire#18833).

- Adds
[`deployment/output-diffing.mdx`](src/frontend/src/content/docs/deployment/output-diffing.mdx):
why and when to use it, enabling `WithOutputDiffing`, running `aspire do
publish-and-diff`, reading `Added`/`Changed`/`Removed` results and
fixing drift, a GitHub Actions example, comparing other steps,
`Pipeline:OutputDiff` configuration (ordered include/exclude rules and
`Auto`/`Git`/`FileSystem` mode), how Git and filesystem comparison work,
capture timing, and C#-only custom
`IPipelineOutputSnapshotter<TSnapshot>` /
`IPipelineOutputComparer<TSnapshot>` extensibility. Includes a sidebar
entry with all locale translations.
- Adds the `ASPIREPIPELINES005` diagnostic page, overview table row, and
sidebar entry.
- Cross-links from the pipelines overview, CI/CD overview (new section
and card), Docker Compose output artifacts, and the `aspire do` and
`aspire publish` CLI reference pages.
- AppHost samples use synced TypeScript-then-C# tabs.
`withOutputDiffing` is exported to the TypeScript AppHost SDK; the
factory and generic overloads, options-pattern configuration, and custom
snapshotter/comparer are C#-only, with a note beside each operation.

The 17.0 what's-new page is intentionally not touched.

### Assumptions and notes

- The PR description shows `builder.Pipeline.WithOutputDiffing()` and
mentions `IPipelineOutputDiffer` / `IPipelineOutputFileHasher`. The
merged code on `release/17.0` and `main` exposes
`builder.WithOutputDiffing()` (an extension on
`IDistributedApplicationBuilder`), and the public extension points are
the snapshotter and comparer interfaces. The hasher is internal. The
docs follow the merged code and docs/specs/pipeline-output.md.
- `ASPIREPIPELINES005` is documented as an error because a C# AppHost
build reports `error ASPIREPIPELINES005` until suppressed (verified).
The product repo's docs/list-of-diagnostics.md lists it as a warning.
- The checked-in API reference data stops at 13.6, so the new APIs are
inline code rather than `ApiReference` links, and the TypeScript blocks
have no `twoslash` meta (the generated type bundle doesn't contain
`withOutputDiffing`). The TypeScript samples were type-checked against a
generated SDK instead (see Validation).
- No open docs PR covers this feature. #1852 and #1856 (diagnostic
graduations) and #2035 (pipelines page) edit nearby files but different
content; this PR doesn't duplicate or contradict them.

## Third-party links and affiliations

None.

## Validation

Documentation behavior was verified against a dev Aspire CLI
(`17.1.0-preview.1.26556.5`, a `main` build that contains #21681; the
output diffing source is identical on `release/17.0`) using C#
file-based and TypeScript AppHosts with a Docker Compose environment:

- `aspire do publish-and-diff` with no committed output: failed with
`Added: docker-compose.yaml`, exit code 6.
- Same command after committing output: succeeded (10/10 steps).
- After tampering with the committed file or changing the AppHost:
failed with `Changed: docker-compose.yaml`; the regenerated file was
left on disk and `git diff` showed it.
- `aspire do publish` after tampering: generation only, no comparison.
- A custom step deleting a tracked file reported `Removed:`; a custom
`targetStep`/`diffStepName` worked; two comparison targets coexisted;
`--output-path` moved the compared directory.
- Git-ignored output in `Auto` mode was not compared (passed silently);
`Mode=FileSystem` detected it. `Mode=Git` outside a worktree failed with
"Git is required to capture pipeline output...". A stale untracked file
that generation doesn't touch was not reported.
- `Pipeline:OutputDiff` rules and mode worked from `appsettings.json`
(C# and TypeScript AppHosts) and from `Pipeline__OutputDiff__*`
environment variables; invalid actions failed with "Output diff rule
actions must be Include or Exclude."
- All C# samples from the new page compiled together with `dotnet build
apphost.cs`; the TypeScript samples passed `npx tsc -p
tsconfig.apphost.json --noEmit` against the generated SDK.

Repository checks (from `src/frontend`):

- `pnpm install --frozen-lockfile --prefer-offline`: passed.
- `pnpm exec astro sync`: passed.
- `pnpm exec vitest run --config vitest.config.ts
tests/unit/seo-lengths.vitest.test.ts
tests/unit/apphost-examples.vitest.test.ts
tests/unit/typescript-first-apphost-tabs.vitest.test.ts
tests/unit/aspire-version-placeholders.vitest.test.ts
tests/unit/page-metadata.vitest.test.ts
tests/unit/redirects.vitest.test.ts
tests/unit/twoslash-blocks.vitest.test.ts
tests/unit/filetree-format.vitest.test.ts`: 8 files, 93 tests passed.
- `pnpm test:unit:twoslash-blocks`: passed.
- `pnpm exec eslint config/sidebar/deployment.topics.ts
config/sidebar/reference.topics.ts` and `pnpm exec prettier --check` on
the same files: passed.
- Rendered the new pages with `pnpm exec astro dev` and checked them
with `playwright-cli` (HTTP 200, tabs, tables, steps, and the new
sidebar entry).
- Not run: `pnpm build` (CI only, per repository policy).

---------

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Matt Kotsenas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add aspire publish --verify to detect drift between checked-in generated artifacts and the AppHost

3 participants