promote
napt.promote
Deployment promotion for NAPT.
Implements ring-based promotion of published apps: napt promote plan
computes which releases should enter or advance through the configured
deployment rings and writes one reviewable plan file per app;
napt promote apply executes each app's plan against Intune
independently.
The core invariant: each ring holds at most one release of an app's Update
entry: the newest release that has reached it. Promotion advances the
published release into the next ring once it has held its current ring for
the ring's promote_after_days.
Assignment drift (differences between what deployment state says should
be assigned and what Intune actually has) is detected on every apply and
on plan --check-drift, and is always reported, never corrected.
Publications whose deployment state writeback was lost (e.g. a failed CI
push after a successful upload) are recovered from tenant evidence on
every apply and on plan --reconcile.
Modules:
| Name | Description |
|---|---|
planner |
Plan computation and plan file writing. |
applier |
Plan execution against Intune. |
preflight |
Group resolution validation before assignment. |
drift |
Assignment drift detection. |
reconcile |
Lost publication writeback recovery. |
napt.promote.planner
Promotion planning for NAPT deployment rings.
Computes promotion actions as a pure function of (deployment state, configuration, clock): no Graph calls, no side effects beyond the plan file. Re-running plan against unchanged inputs produces byte-identical output, so committed plan files diff cleanly and CI can use the plan file's change status to decide whether to open a review.
Two action types are planned per app, one per Intune entry:
assign: Point new installs at the published release: assign its install entry to the configureddeployment.installgroups, displacing the previous release's install assignment.promote: Move the published release one ring forward: assign its update entry to the target ring's groups.from_ring: nullmarks a first rollout (the release enters the first ring); otherwise the release has heldfrom_ringfor at least that ring'spromote_after_days.
Every action carries a plain-English summary sentence plus the
reviewer context behind it (the entry it touches, the version it
displaces, and bake timestamps), so a committed plan file reads on
its own in review.
A ring without promote_after_days never advances automatically:
releases hold it until the configuration changes (the natural terminal
ring, or a deliberate manual gate).
Plans are written per app (default state/plans/<app_id>.json), and
an app's plan file exists exactly when that app has eligible actions; a
stale plan file is removed when a plan run finds none for its app. Exit
codes follow NAPT's uniform contract (0 success, 1 error, 2 usage error);
CI detects
pending work from the plan files' git status, not from exit codes.
plans_dir_for
Returns the plans directory for a state directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dir
|
Path
|
The configured state directory ( |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the plans directory ( |
Source code in napt/promote/planner.py
plan_path_for
Returns an app's plan file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dir
|
Path
|
The configured state directory ( |
required |
app_id
|
str
|
Recipe identifier the plan belongs to. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the app's plan file ( |
Source code in napt/promote/planner.py
load_recipe_configs
Loads effective configurations for a recipe file or directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipes
|
Path
|
A recipe YAML file, or a directory scanned recursively. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Effective configurations keyed by recipe id, in path order. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the path does not exist, contains no recipes, a recipe is invalid, or two recipe files resolve to the same id. |
Source code in napt/promote/planner.py
plan_promotions
plan_promotions(
configs: dict[str, dict[str, Any]],
states: dict[str, dict[str, Any]],
now: datetime | None = None,
) -> list[dict[str, Any]]
Computes promotion actions for the apps in a run.
Evaluates each app's ring eligibility against its deployment state and the clock. Read-only: neither Intune nor the states are modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configs
|
dict[str, dict[str, Any]]
|
Effective configurations keyed by recipe id, from load_recipe_configs. |
required |
states
|
dict[str, dict[str, Any]]
|
Each app's deployment state keyed by recipe id, from load_deployment_states. |
required |
now
|
datetime | None
|
Evaluation clock. Defaults to the current UTC time; tests pass a fixed value for determinism. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Action dicts sorted by app id and action type. |
Raises:
| Type | Description |
|---|---|
StateError
|
On an invalid ring timestamp. |
Source code in napt/promote/planner.py
write_plan_files
write_plan_files(
actions: list[dict[str, Any]], state_dir: Path, app_ids: Iterable[str]
) -> list[Path]
Writes one plan file per app, removing stale files for apps without work.
An app's plan file exists exactly when that app has planned actions,
so each file's git status is the per-app signal that a promotion
review is needed. Only apps covered by this run (app_ids) are
written or cleaned up; plan files for apps outside the run are left
untouched, so planning a single recipe never clobbers the rest of
the fleet's plans.
The app's id and display name are written once at the file's top
level rather than repeated per action; promote apply re-injects them
when it loads the file. Output is deterministic: a fixed key order
(reading order, summary first, not alphabetical), fixed
indentation, no clock-derived values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
list[dict[str, Any]]
|
Planned actions from plan_promotions. |
required |
state_dir
|
Path
|
The configured state directory; plan files live in
its |
required |
app_ids
|
Iterable[str]
|
Recipe ids covered by this plan run. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
Paths of the plan files written, sorted by app id. |
Source code in napt/promote/planner.py
napt.promote.applier
Promotion apply for NAPT deployment rings.
Executes promotion plans against Intune: assigns install entries, promotes releases through rings, displaces the older releases they replace, and retires them per the retention policy.
Plans are applied per app: each state/plans/<app_id>.json file is
an independent unit of work, preflighted, executed, and consumed on
its own. Only the plan files of the recipes given to the run are
loaded, so applying one recipe leaves every other app's reviewed plan
in place. A failure inside one app's plan (an unresolvable group, a
Graph error, a state file that cannot be written) records the
failure, keeps that plan file for retry, and moves on to the next;
one app's problem never strands the rest of the fleet's promotions.
Every action is validated against current deployment state before
executing (validate-then-act): stale actions, where the published
release changed since the plan was written or the action already
applied, are skipped with a warning instead of failing, so re-running
apply after a partial failure is safe. Deployment state is saved after
each applied action, and ring entered_at timestamps are written
here and only here.
Displaced releases are found through their provenance stamps (the
tenant is listed once per run), not through deployment state, which
only records the current release's app IDs. A displaced release that
no longer holds any ring moves to the retained list; releases beyond
deployment.retain_versions have their Intune apps deleted and
leave the run's tenant listing, so the drift check that follows does
not report them.
Assignments NAPT does not manage are preserved: assignment sets are read, modified, and written back, so admin-made assignments and non-group targets survive every apply.
ApplyResult
dataclass
Result from applying promotion plans against Intune.
Attributes:
| Name | Type | Description |
|---|---|---|
applied |
list[dict[str, Any]]
|
The actions that were executed, as planned. |
skipped |
list[dict[str, Any]]
|
Entries of |
failed |
list[dict[str, Any]]
|
Entries of |
drift |
list[dict[str, Any]]
|
Assignment drift findings, reported and never corrected. |
recovered |
list[dict[str, Any]]
|
Publications whose lost state writeback was recovered before applying. |
Source code in napt/promote/applier.py
load_plan_file
Loads planned actions from a per-app plan file.
The file records its app id and display name once at the top level;
both are re-injected into every returned action, so in-memory
actions look the same as the planner's output. The filename is the
app's identity, as for deployment state: <app_id>.json must
declare that same app id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan_path
|
Path
|
Path to the plan file. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
The planned action dicts. |
Raises:
| Type | Description |
|---|---|
StateError
|
If the plan file cannot be read, contains invalid JSON, lacks an actions list or app id, declares an app id other than its filename, its schemaVersion is missing or unsupported, an action is not shaped like the planner writes it, or an action references a different app than the one the file declares. |
Source code in napt/promote/applier.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
apply_plan
apply_plan(
configs: dict[str, dict[str, Any]],
state_dir: Path,
plan_file: Path | None = None,
now: datetime | None = None,
report_unknown_apps: bool = True,
) -> ApplyResult
Executes promotion plans against Intune.
Consumes the given recipes' plan files from <state_dir>/plans/,
removing each after its app applies fully. A plan file written by
napt promote plan is the only thing apply executes: a recipe
without one has nothing to apply, and plan files for apps outside
the run are left untouched, so applying one recipe never consumes
another app's reviewed plan. Each app's plan is an independent
unit: its groups are preflighted before any of its actions execute,
so an unresolvable group fails that app with zero mutations, and a
failure while loading, preflighting, or applying one app records
the failure, keeps its plan file for retry, and continues with the
remaining apps. A dead group referenced only by stale or
already-applied actions never blocks an app. Deployment state is
saved after each applied action, so a failed run resumes safely:
already-applied actions validate as no-ops.
Assignment drift is checked on every run, including runs with nothing to apply (which therefore still authenticate), and reported in the summary, never corrected. Publications whose state writeback was lost are recovered first (see reconcile_publications); a recovered release is picked up by the next plan run, since the plan files being applied were computed before the recovery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configs
|
dict[str, dict[str, Any]]
|
Effective configurations keyed by recipe id, from load_recipe_configs. |
required |
state_dir
|
Path
|
State directory holding |
required |
plan_file
|
Path | None
|
Explicit path to a single plan file to apply; its app must be one of the recipes. When omitted, the recipes' plan files in the default plans directory are applied. |
None
|
now
|
datetime | None
|
Evaluation clock for ring timestamps. Defaults to the current UTC time. |
None
|
report_unknown_apps
|
bool
|
Whether the drift check reports a stamped app
whose recipe id is not in |
True
|
Returns:
| Type | Description |
|---|---|
ApplyResult
|
The applied and skipped actions, the per-app failures, the drift findings, and the recovered publications. |
Raises:
| Type | Description |
|---|---|
AuthError
|
If authentication fails, or Graph rejects the token during a run. |
ConfigError
|
On a plan file for an app the run has no recipe for. |
NetworkError
|
On Graph API failures outside a per-app unit (listing the tenant, reconciliation, the drift check). |
StateError
|
On corrupted deployment state, or an explicit
|
Source code in napt/promote/applier.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
napt.promote.preflight
Group validation for promotion plans.
A planned action names its assignment groups, so an unresolvable group (a typo in ring configuration, a deleted Entra ID group) is knowable before anything mutates the tenant. Checking up front turns what would be a mid-run abort (leaving a half-applied plan) into either a failed plan that never reaches review, or an apply that refuses to start that app's plan.
Used by the authenticated napt promote plan modes (a plan with an
unresolvable group fails instead of becoming a reviewable promotion PR)
and by napt promote apply as a per-app preflight before executing
any of that app's actions. Offline plans skip validation; the apply
preflight is the backstop for anything they produce.
unresolvable_groups
unresolvable_groups(
access_token: str,
actions: list[dict[str, Any]],
group_id_cache: dict[str, str] | None = None,
) -> list[str]
Resolves every group named in the actions, collecting failures.
Each distinct group is resolved once. Successful resolutions land in the shared cache, so a subsequent apply pass re-resolves nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Bearer token for Graph API. |
required |
actions
|
list[dict[str, Any]]
|
Planned action dicts (each may carry a "groups" list). |
required |
group_id_cache
|
dict[str, str] | None
|
Shared cache for group name resolution. A new cache is used when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
One failure description per unresolvable group, sorted for deterministic output. Empty when every group resolves. |
Raises:
| Type | Description |
|---|---|
AuthError
|
On 401 or 403. |
NetworkError
|
On Graph API failures. |
Source code in napt/promote/preflight.py
napt.promote.drift
Assignment drift detection for NAPT deployment promotion.
Compares what deployment state says should be assigned in Intune against what actually is, and reports every discrepancy as a finding. Strictly observational: drift is warned about and never corrected; manual admin changes are deliberately left alone.
Finding kinds:
missing_app: State references a release whose stamped Intune entry no longer exists.missing_assignment: An assignment NAPT applied (ring group or install group) is no longer present.intent_mismatch: An expected assignment exists with a different intent.unrecorded_assignment: A NAPT-stamped app carries an assignment that matches a currently configured target, but NAPT has no record of making it: either an apply writeback was lost (a later apply converges it) or it was made outside NAPT. Left alone.unexpected_assignment: A NAPT-stamped app carries an assignment NAPT has no record of making and that matches no configured target (typically admin-made; left alone).orphaned_release: A stamped app exists for a release that no state file references (e.g., a crashed run replaced by newest-wins).unknown_app: A stamped app references a recipe id with no recipe.
Authorship is always inferred, never known: Graph assignments carry no provenance field, so deployment state records are the only memory of what NAPT assigned, and a lost writeback loses that memory.
target_key
Returns a comparable identity for an assignment target.
detect_drift
detect_drift(
access_token: str,
configs: dict[str, dict[str, Any]],
states: dict[str, dict[str, Any]],
existing_apps: list[dict[str, Any]],
group_id_cache: dict[str, str] | None = None,
report_unknown_apps: bool = True,
) -> list[dict[str, Any]]
Detects assignment drift between deployment state and Intune.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Bearer token for Graph API. |
required |
configs
|
dict[str, dict[str, Any]]
|
Effective configurations keyed by recipe id. |
required |
states
|
dict[str, dict[str, Any]]
|
Each app's deployment state keyed by recipe id, from load_deployment_states. |
required |
existing_apps
|
list[dict[str, Any]]
|
Mobile app dicts from list_mobile_apps. |
required |
group_id_cache
|
dict[str, str] | None
|
Shared cache for group name resolution, so a caller that already resolved groups (apply, plan validation) re-resolves nothing. A new cache is used when omitted. |
None
|
report_unknown_apps
|
bool
|
Whether a stamped app whose recipe id is not
in |
True
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Finding dicts, each with "app_id", "kind", and "detail" keys, sorted for deterministic output. Empty when Intune matches state. |
Raises:
| Type | Description |
|---|---|
AuthError
|
On 401 or 403. |
ConfigError
|
If a configured group cannot be resolved. |
NetworkError
|
On Graph API failures. |
Source code in napt/promote/drift.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
napt.promote.reconcile
Publication recovery for lost deployment state writebacks.
A publish run records the pending-to-published transition in deployment state after uploading, but that record can be lost, most commonly when a CI runner uploads successfully and then fails to push the state commit (branch protection, network). The tenant then holds a fully published release that state still lists as pending, which blocks promotion planning and, if a newer discovery replaces the pending slot, orphans the published release permanently.
Reconciliation closes that gap by re-deriving the record from tenant
evidence: when every entry the app's build_types requires exists in
Intune, stamped for the pending release's installer hash and with
committed content, the publication demonstrably succeeded and
published is recorded exactly as the publish run would have. This
trusts provenance stamps and committed content the same way idempotent
upload adoption already does, so no new trust is introduced.
Unlike drift detection, which never corrects, reconciliation writes deployment state: it completes NAPT's own half-persisted transaction rather than overriding an admin's tenant change.
Finding kinds:
recovered: The publication was fully committed in the tenant and has been recorded as published.incomplete: Some required entries are missing or their content was never committed; nothing is recorded; re-run publish to finish.
reconcile_publications
reconcile_publications(
access_token: str,
configs: dict[str, dict[str, Any]],
states: dict[str, dict[str, Any]],
deployment_dir: Path,
existing_apps: list[dict[str, Any]],
) -> list[dict[str, Any]]
Records publications whose deployment state writeback was lost.
For each app with a pending release, checks the tenant for stamped
entries matching the pending installer hash. When every entry
required by the app's build_types exists with committed content,
records the release as published (clearing the pending slot) exactly
as the original publish run would have. Partial evidence (some
entries missing or uncommitted) is warned about but never recorded,
because only a publish re-run can finish the upload.
Apps whose pending release has no stamped entries at all are the normal awaiting-publication case and produce no finding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Bearer token for Graph API. |
required |
configs
|
dict[str, dict[str, Any]]
|
Effective configurations keyed by recipe id. |
required |
states
|
dict[str, dict[str, Any]]
|
Each app's deployment state keyed by recipe id, from load_deployment_states. A recovered publication is recorded into the dict as well as the file, so the steps that follow see it. |
required |
deployment_dir
|
Path
|
Directory holding per-app deployment state files. |
required |
existing_apps
|
list[dict[str, Any]]
|
Mobile app dicts from list_mobile_apps. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Finding dicts, each with "app_id", "kind" ("recovered" or "incomplete"), and "detail" keys, sorted for deterministic output. Empty when no pending release has tenant evidence. |
Raises:
| Type | Description |
|---|---|
AuthError
|
On 401 or 403. |
NetworkError
|
On Graph API failures. |
Source code in napt/promote/reconcile.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |