Skip to content

Record Git template provenance in generated aspire.config.json - #21833

Draft
Mitch Denny (mitchdenny) wants to merge 2 commits into
mainfrom
mitchdenny-generated-template-provenance
Draft

Mitch Denny (mitchdenny) wants to merge 2 commits into
mainfrom
mitchdenny-generated-template-provenance

Conversation

@mitchdenny

@mitchdenny Mitch Denny (mitchdenny) commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Description

Generated projects currently lose the Git origin of their selected template. This adds provenance.template.repository, provenance.template.sha, and provenance.template.path to the output-root aspire.config.json after successful Git-backed template generation.

This is a separate draft follow-up to the feedback around #21831, based on main, with no dependency on that PR or picker-heading changes.

The recorded SHA is the already-resolved commit used for the verified checkout, including cached checkouts and callbacks selected before a branch moves. The path identifies the selected template's directory containing .template.config, not the broader search directory. Generation does not perform another Git lookup. The write uses the existing workspace lock and atomic JSON writer, preserving template-owned settings and unrelated provenance fields. A write error is reported before the template success message. Persisted filesystem paths use / separators, including absolute local Windows repository paths.

Fixes # (issue)

User-facing usage

Existing Git-template invocations now produce origin metadata automatically:

aspire new --template-repository https://github.com/example/templates.git --template-path templates/my-template --name MyApp --output ./MyApp

The generated configuration includes:

{
  "provenance": {
    "template": {
      "repository": "https://github.com/example/templates.git",
      "sha": "0123456789abcdef0123456789abcdef01234567",
      "path": "templates/my-template"
    }
  }
}

This is generation metadata, not templateSources registration or a configSource binding. Directory and built-in templates intentionally remain unchanged because they have no verified Git acquisition metadata. Failed, rejected, or cancelled generation writes no provenance. Typed configuration persistence, CLI configuration schema, the generated extension schema's provenance section, and the directly related documentation are updated. Existing extension input routing already covers extension/**; no test-selection routing change is needed.

Validation

Passed on macOS: 1,025 tests passed, 6 skipped, 0 failed, including real local Git checkout/ref/cache scenarios, resolved SHA/path assertions, relative/absolute local-path normalization, configuration preservation, invalid configuration, cancellation, engine/computed-generation failures, credentials, built-in/directory behavior, schema, and configuration-source materialization.

dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class '*.NewCommandLocalTemplateTests' --filter-class '*.TemplateEngineFactoryGitTests' --filter-class '*.TemplateEngineFactoryGitCheckoutTests' --filter-class '*.SettingsSchemaBuilderTests' --filter-class '*.AspireConfigFileTests' --filter-class '*.NewCommandTemplateConfigPersistenceTests' --filter-class '*.ConfigSourceServiceTests' --filter-class '*.ConfigurationHelperTests' --filter-class '*.ConfigurationServiceTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

Passed in a Linux ARM64 Docker test runner: all 4 CustomTemplateTests scenarios, using the current branch's self-contained CLI archive and a no-.NET-SDK polyglot test image. Both interactive and unattended repository generation assert the exact fixture repository, actual Git commit, and selected template path before snapshot scrubbing. The fixture makes only its generated config readable for host-side verification; production config permissions remain unchanged.

dotnet artifacts/bin/Aspire.Cli.EndToEnd.Tests/Debug/net10.0/Aspire.Cli.EndToEnd.Tests.dll --filter-class '*.CustomTemplateTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

dotnet build tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj --no-restore — passed with no warnings. node extension/scripts/generate-schema.js — passed; retained only the generated provenance delta to avoid unrelated pre-existing schema drift. Live aspire config info --json was checked against the extension schema for the exact repository, sha, path shape. git diff --check — passed. Generated snapshots were reviewed and the final runs passed.

The standard localhive.sh packaging attempt was blocked by missing pwsh, so the Linux CLI was published directly for the local E2E run. Repository E2E cases cannot reach the host loopback Git server from Docker Desktop on macOS; running the test runner itself on Linux with shared Docker networking avoids that local limitation without changing product or test networking. Windows execution and the full product suite were not run locally.

CI passed for final commit 10501fb4fe1d5fe931cf6eba4b98e8b7606b878f: https://github.com/microsoft/aspire/actions/runs/42169003734. The final current-head check snapshot is 205 successful checks, 15 skipped, none failed or pending. Both previously failing groups passed: Windows CLI unit tests and Linux CustomTemplateTests. Native hosting validation and the other current-head workflows also passed. The first attempt hit an unrelated 45-minute timeout in the shared E2E Docker image build during apt package installation; rerunning that job and its dependents succeeded without infrastructure changes. No cloud resources were provisioned. No visual UI change is included.

Security considerations

Repository URLs are persisted without passwords, HTTPS userinfo, query strings, or fragments; SSH usernames remain valid location metadata. Local Git repository paths are made absolute and normalized to / separators. The configuration write rejects symbolic links and uses the existing lock/atomic writer. Origin metadata does not authenticate a template, grant trust, add inherited settings, or authorize execution. No additional network operations or template post-actions are introduced. A formal security review has not been performed.

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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 5, 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 -- 21833

Or

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

@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

Provenance generation can bypass legacy template settings and prevent migration, while Windows snapshot scrubbing leaves machine-specific repository paths that fail comparison.

2 open issues
What changed in this PR

Records Git template origins in generated projects so users can identify the repository, resolved commit, and selected template directory. This is separate from picker-heading changes and does not register template sources or enable configuration inheritance.

Changes:

  • Carries verified checkout metadata through generation and merges provenance before reporting success.
  • Adds typed configuration support, schema entries, and documentation.
  • Extends tests and snapshots for commit pinning, configuration preservation, credential removal, and failure handling.
File Description
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_UsesCachedCheckoutAndKeepsTemplatesAlive.verified.txt Records cached-checkout provenance.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ResolvesRefsAndReusesPinnedCheckoutsAcrossInvocations.verified.txt Records resolved commits across refs.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ProvenanceRecordsSelectedTemplateAndResolvedCommit_searchPath=templates-web_reference=refs-tags-v17.0.verified.json Captures tag provenance and retained settings.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ProvenanceRecordsSelectedTemplateAndResolvedCommit_searchPath=templates-web_reference=0123456789abcdef0123456789abcdef01234567.verified.json Captures explicit-commit provenance.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ProvenanceRecordsSelectedTemplateAndResolvedCommit_searchPath=templates_reference=release-17.0.verified.json Captures selected-template path from broader search.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ProvenanceRecordsSelectedTemplateAndResolvedCommit_searchPath=._reference=HEAD.verified.json Captures provenance from repository-root search.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ConfiguresOnlyGeneratedNuGetConfig_templateOwnsConfig=True.verified.txt Adds provenance alongside template-owned configuration.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ConfiguresOnlyGeneratedNuGetConfig_templateOwnsConfig=False.verified.txt Adds provenance alongside generated NuGet configuration.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ClonesGitRepositoryAndRenders_specifyTemplatePath=True.verified.txt Records subdirectory template origin.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.RepositoryTemplate_ClonesGitRepositoryAndRenders_specifyTemplatePath=False.verified.txt Records root template origin.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.ConfiguredGitSources_ReusesCachedCommitsAndKeepsSelectedSnapshotPinned.verified.txt Captures pinned cached-source metadata.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.ConfiguredGitSources_RealGitCheckoutRendersSelectedTemplate.verified.txt Captures real-checkout provenance.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.ConfiguredGitSources_MixedSearchSelectsGitTemplateAndShowsAcquisitionStages.verified.txt Records Git origin after mixed-source selection.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.ConfiguredGitSourceObjects_RealGitRefsRenderOnlySelectedSubdirectory.verified.txt Captures commits and paths across configured refs.
tests/​Aspire.Cli.Tests/​Snapshots/​NewCommandLocalTemplateTests.ConfiguredGitSourceObjects_MixedSearchScopesPathsAndSharesCheckout.verified.txt Records the selected scoped template path.
tests/​Aspire.Cli.Tests/​Snapshots/​ConfigSourceServiceTests.Materialize_PreservesProjectSettingsAndCopiesAllowedSections.verified.json Shows local provenance surviving materialization.
tests/​Aspire.Cli.Tests/​Configuration/​ConfigSourceServiceTests.cs Checks inherited configuration does not replace provenance.
tests/​Aspire.Cli.Tests/​Commands/​SettingsSchemaBuilderTests.cs Checks provenance shape and local-only scope.
tests/​Aspire.Cli.Tests/​Commands/​NewCommandTemplateConfigPersistenceTests.cs Checks built-in templates omit provenance.
tests/​Aspire.Cli.Tests/​Commands/​NewCommandLocalTemplateTests.Provenance.cs Adds focused provenance and failure-path tests.
tests/​Aspire.Cli.Tests/​Commands/​NewCommandLocalTemplateTests.cs Adds real-Git and cached-checkout assertions.
tests/​Aspire.Cli.Tests/​Commands/​NewCommandLocalTemplateTests.ConfiguredGitSources.cs Checks pinned commits without extra resolution.
tests/​Aspire.Cli.Tests/​Commands/​NewCommandLocalTemplateTests.ConfiguredGitSourceObjects.cs Checks configured refs and selected paths.
src/​Aspire.Cli/​Templating/​TemplateEngineFactory.NuGetValues.cs Defers success reporting to the generation wrapper.
src/​Aspire.Cli/​Templating/​TemplateEngineFactory.cs Captures Git metadata and writes provenance atomically.
src/​Aspire.Cli/​Configuration/​AspireConfigProvenance.cs Defines provenance models preserving unknown fields.
src/​Aspire.Cli/​Configuration/​AspireConfigFile.cs Adds local provenance configuration.
extension/​schemas/​aspire-config.schema.json Describes provenance for editor validation.
docs/​specs/​git-templating.md Documents origin metadata and its boundaries.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 5, 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 6, 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 6, 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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Tests selector

2 / 101 PR test projects · 5 PR jobs, from 31 changed files.

Selected PR test projects (2 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests

Selected PR jobs (5)

cli-starter-validation, extension-e2e, extension-unit, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

📦 affected project Aspire.Cli
→ 1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/CustomTemplateTests.cs (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/Snapshots/CustomTemplateTests.RepositoryTemplatePromptsWithoutDotNetSdk.verified.txt (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.EndToEnd.Tests/Snapshots/CustomTemplateTests.RepositoryTemplateUsesDefaultsNonInteractivelyWithoutDotNetSdk.verified.txt (changed test)
→ 1 directly: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.Tests/Commands/NewCommandLocalTemplateTests.ConfiguredGitSourceObjects.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/NewCommandLocalTemplateTests.ConfiguredGitSources.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/NewCommandLocalTemplateTests.Provenance.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/NewCommandLocalTemplateTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/NewCommandTemplateConfigPersistenceTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/SettingsSchemaBuilderTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Configuration/ConfigSourceServiceTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/ConfigSourceServiceTests.Materialize_PreservesProjectSettingsAndCopiesAllowedSections.verified.json (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.ConfiguredGitSourceObjects_MixedSearchScopesPathsAndSharesCheckout.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.ConfiguredGitSourceObjects_RealGitRefsRenderOnlySelectedSubdirectory.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.ConfiguredGitSources_MixedSearchSelectsGitTemplateAndShowsAcquisitionStages.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.ConfiguredGitSources_RealGitCheckoutRendersSelectedTemplate.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.ConfiguredGitSources_ReusesCachedCommitsAndKeepsSelectedSnapshotPinned.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ClonesGitRepositoryAndRenders_specifyTemplatePath=False.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ClonesGitRepositoryAndRenders_specifyTemplatePath=True.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ConfiguresOnlyGeneratedNuGetConfig_templateOwnsConfig=False.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ConfiguresOnlyGeneratedNuGetConfig_templateOwnsConfig=True.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ProvenanceRecordsSelectedTemplateAndResolvedCommit_searchPath=._reference=HEAD.verified.json (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ProvenanceRecordsSelectedTemplateAndResolvedCommit_searchPath=templates-web_reference=0123456789abcdef0123456789abcdef01234567.verified.json (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ProvenanceRecordsSelectedTemplateAndResolvedCommit_searchPath=templates-web_reference=refs-tags-v17.0.verified.json (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ProvenanceRecordsSelectedTemplateAndResolvedCommit_searchPath=templates_reference=release-17.0.verified.json (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_ResolvesRefsAndReusesPinnedCheckoutsAcrossInvocations.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/NewCommandLocalTemplateTests.RepositoryTemplate_UsesCachedCheckoutAndKeepsTemplatesAlive.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Cli
extension-e2e • extension/schemas/aspire-config.schema.json, src/Aspire.Cli/Configuration/AspireConfigFile.cs, src/Aspire.Cli/Configuration/AspireConfigProvenance.cs, src/Aspire.Cli/Templating/TemplateEngineFactory.NuGetValues.cs, src/Aspire.Cli/Templating/TemplateEngineFactory.cs
• affected project Aspire.Cli
extension-unit extension/schemas/aspire-config.schema.json
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli

Selection computed for commit 10501fb.

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.

🔵 Needs a closer look

Repository URL sanitization drops required SSH usernames from git+ssh and ssh+git URLs, potentially making recorded repository locations unusable.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve SSH usernames when normalizing repository URLs

src/​Aspire.Cli/​Templating/​TemplateEngineFactory.cs:419

For a direct --template-repository git+ssh://git@example.test/templates.git (or ssh+git://...), this removes the SSH username and records a different repository location. GitCommandRunner.UsesSsh already recognizes both schemes as SSH, and dropping git@ can make the recorded URL unusable on servers that require that account. Preserve the username for those two SSH schemes as well, while continuing to remove passwords.

2 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants