Skip to content

Delta Util integration - #6558

Merged
JohnMcPMS merged 13 commits into
microsoft:masterfrom
JohnMcPMS:delta-util
Sep 25, 2026
Merged

JohnMcPMS merged 13 commits into
microsoft:masterfrom
JohnMcPMS:delta-util

Conversation

@JohnMcPMS

@JohnMcPMS JohnMcPMS commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

📖 Description

This change exposes the delta index generation to the util interfaces. It does this exclusively through properties, removing the explicit baseline marking function in favor of setting a property and thus allowing a single pass through the prepare routines. It also adds new properties that will be used in a future change for the client to consume the delta.

It adds extensive consistency checking so that delta generation errors can be detected early. Delta consistency covers:

  1. Consistency of the delta data itself, including confirmation that unnecessary data is not being recorded
  2. When the baseline property is set, the standard consistency check applied to the merged views
  3. When the comparison property is set, a full equivalence check between the merged views and the standard data

An example calling pattern for the delta changes:

using Microsoft.WinGetUtil.Interfaces;
using Microsoft.WinGetUtil.Api;

/// <summary>
/// Produces one source update: a full index, a delta, and — when asked — a new baseline.
/// </summary>
/// <param name="createBaseline">
/// When true, the index produced by this run becomes the new baseline and its delta is
/// empty. When false, the delta is computed against the baseline currently published.
/// </param>
public void PublishSourceUpdate(bool createBaseline)
{
    var factory = new WinGetFactory();
    using var log = factory.LoggingInit(GetLogFilePath());

    // The working index is long lived and is never prepared; preparing is destructive.
    // Everything below runs against a copy, which carries the database lineage that
    // delta generation requires.
    string workingIndexPath = GetWorkingIndexPath();

    using (var working = factory.SQLiteIndexOpen(workingIndexPath))
    {
        // Leave the base time unset so that this run's window starts where the last one ended.
        working.SetProperty(SQLiteIndexProperty.PackageUpdateTrackingBaseTime, string.Empty);

        ProcessManifestChanges(working);
    }

    // A fresh directory, because generation refuses to overwrite an existing delta.
    string stagingPath = CreateStagingDirectory();
    string indexPath = Path.Combine(stagingPath, "index.db");
    string deltaPath = Path.Combine(stagingPath, "delta.db");

    CopyWorkingIndex(workingIndexPath, indexPath);

    // The locator the delta records so that a client can go and acquire the baseline.
    // Creating a baseline describes the package this run is about to publish; otherwise it
    // describes the one already published.
    BaselineLocator baseline = createBaseline
        ? ReserveNextBaselineLocation()
        : GetPublishedBaselineLocation();

    using (var index = factory.SQLiteIndexOpen(indexPath))
    {
        if (createBaseline)
        {
            // This index is its own baseline. Mutually exclusive with naming one.
            index.SetProperty(SQLiteIndexProperty.DeltaMarkAsBaseline, "true");
        }
        else
        {
            index.SetProperty(SQLiteIndexProperty.DeltaBaselineIndexPath, GetPublishedBaselineIndexPath());
        }

        index.SetProperty(SQLiteIndexProperty.DeltaOutputPath, deltaPath);
        index.SetProperty(SQLiteIndexProperty.DeltaBaselineRelativeSourcePath, baseline.RelativeSourcePath);
        index.SetProperty(SQLiteIndexProperty.DeltaBaselinePackageVersion, baseline.PackageVersion);

        // One prepare produces the full index and, beside it, the delta.
        index.PrepareForPackaging();

        // The index is an ordinary one even though it produced a delta, and is checked as such.
        if (!index.IsIndexConsistent())
        {
            throw new InvalidOperationException($"The prepared index is not consistent: {indexPath}");
        }
    }

    // The baseline the delta was computed against, which this run may have just created.
    string baselineIndexPath = createBaseline ? indexPath : GetPublishedBaselineIndexPath();

    using (var delta = factory.SQLiteIndexOpen(deltaPath))
    {
        // Naming the baseline checks the merged result rather than the delta alone; naming
        // the index as well requires the merged result to present exactly the same data.
        delta.SetProperty(SQLiteIndexProperty.DeltaBaselineIndexPath, baselineIndexPath);
        delta.SetProperty(SQLiteIndexProperty.DeltaComparisonIndexPath, indexPath);

        if (!delta.IsIndexConsistent())
        {
            throw new InvalidOperationException($"The delta does not reproduce the index: {deltaPath}");
        }
    }

    PublishSourcePackage(indexPath);
    PublishDeltaPackage(deltaPath);

    if (createBaseline)
    {
        // The same file serves as both the full index and the new baseline.
        PublishBaselinePackage(indexPath, baseline);
    }
}

🔍 Validation

Added new tests.

Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS
JohnMcPMS requested a review from a team as a code owner September 22, 2026 23:21
@github-actions

This comment was marked as outdated.

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.

Copilot review overview

🟡 Changes recommended

Delta consistency can accept malformed data, misclassify damaged deltas, and silently ignore unsupported comparisons.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 3 Medium severity · 1 Low severity

Open (5)
What changed in this PR

Exposes delta-index generation and validation through WinGetUtil properties while integrating baseline metadata and consistency checks.

Changes:

  • Adds public delta-generation and comparison properties.
  • Implements delta metadata, generation, merged-view validation, and equivalence checks.
  • Adds native and interop test coverage.
File Description
src/​WinGetUtilInterop/​Interfaces/​IWinGetSQLiteIndex.cs Defines managed delta properties.
src/​WinGetUtilInterop.UnitTests/​APIUnitTests/​SQLiteIndexUnitTests.cs Tests managed delta workflows.
src/​WinGetUtil/​WinGetUtil.h Extends the native property enum.
src/​WinGetUtil/​Exports.cpp Maps native properties internally.
src/​AppInstallerRepositoryCore/​Microsoft/​SQLiteIndex.h Updates index API and properties.
src/​AppInstallerRepositoryCore/​Microsoft/​SQLiteIndex.cpp Handles delta properties and contextual consistency.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​SQLiteIndexContextData.h Stores new contextual properties.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​ISQLiteIndex.h Adds const operation context.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​ISQLiteIndex.cpp Implements default contextual checking.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​2_1/​Interface.h Declares 2.1 delta metadata and checks.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​2_1/​Interface_2_1.cpp Integrates generation and consistency behavior.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​2_1/​DeltaGeneration.h Defines baseline references.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​2_1/​DeltaGeneration.cpp Persists baseline metadata.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​2_1/​DeltaConsistency.h Declares delta validation APIs.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​2_1/​DeltaConsistency.cpp Implements consistency and equivalence checks.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​2_0/​Interface.h Exposes contextual overloads.
src/​AppInstallerRepositoryCore/​Microsoft/​Schema/​2_0/​Interface_2_0.cpp Rejects unsupported generation properties.
src/​AppInstallerRepositoryCore/​AppInstallerRepositoryCore.vcxproj.filters Registers new files in filters.
src/​AppInstallerRepositoryCore/​AppInstallerRepositoryCore.vcxproj Adds new files to the build.
src/​AppInstallerCLITests/​SQLiteIndexDelta.cpp Expands native delta tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@JohnMcPMS
JohnMcPMS merged commit 99c6a74 into microsoft:master Sep 25, 2026
9 checks passed
@JohnMcPMS
JohnMcPMS deleted the delta-util branch September 25, 2026 17:55
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