Repository navigation
perf(install): let GitLab and Azure DevOps projects replay a verified no-op #5331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Daniel Meppiel (danielmeppiel)
merged 5 commits into
main
from
danielmeppiel-perf-verdict-gitlab-ado
Nov 24, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1305de3
perf(install): let GitLab and Azure DevOps projects record a verified…
danielmeppiel 1fa51f2
changelog: #5331 fragment
danielmeppiel 9a6bfe6
fix(install): bind the policy cache discovery read to the GitLab/ADO …
danielmeppiel 72a29e0
fix(install): bind policy cache content, tolerate an unreadable cache…
danielmeppiel d32b14c
test(policy): assert the fetch ledger through a named oracle
danielmeppiel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Repeat `apm install` no-ops on GitLab and Azure DevOps projects now replay the verified no-op when their org policy came from a fresh cache. (#5331) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """Org-policy fetch attempts made by this process. | ||
|
|
||
| Each fetch channel notes its attempt when it decides to fetch, before any | ||
| credential lookup or request, so a run whose policy came only from the cache | ||
| can be told apart from one that went to the network (the verified-state record | ||
| replays only the former). Import-light on purpose: nothing here may pull in | ||
| the HTTP stack. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| _ATTEMPTS: list[str] = [] | ||
|
|
||
|
|
||
| def note_fetch_attempt(channel: str) -> None: | ||
| """Record that *channel* (``github``, ``gitlab``, ``ado`` or ``http``) is about to fetch.""" | ||
| _ATTEMPTS.append(channel) | ||
|
|
||
|
|
||
| def fetch_attempts() -> int: | ||
| """How many policy fetch attempts this process has made so far.""" | ||
| return len(_ATTEMPTS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Every org-policy fetch channel notes its attempt before its credential lookup (#5075). | ||
|
|
||
| The verified-state record lets a GitLab or Azure DevOps project replay a no-op | ||
| only when its run made no fetch attempt, so an attempt that fails at the | ||
| credential lookup or the transport must still be counted. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import contextlib | ||
|
|
||
| import pytest | ||
|
|
||
| from apm_cli.core.policy_fetch_ledger import fetch_attempts | ||
| from apm_cli.policy import _gitlab, discovery | ||
| from apm_cli.policy._policy_http import policy_get | ||
|
|
||
| pytestmark = [pytest.mark.component, pytest.mark.promise("P-INV-I2")] | ||
|
|
||
|
|
||
| class _NoCredential(Exception): | ||
| pass | ||
|
|
||
|
|
||
| def _refuse(*_args, **_kwargs): | ||
| raise _NoCredential | ||
|
|
||
|
|
||
| def _github() -> None: | ||
| discovery._fetch_github_contents("acme/.github", "apm-policy.yml") | ||
|
|
||
|
|
||
| def _ado() -> None: | ||
| discovery._fetch_ado_contents("acme", "apm", "apm-policy", "apm-policy.yml") | ||
|
|
||
|
|
||
| def _gitlab_rest() -> None: | ||
| class _Resolver: | ||
| try_with_fallback = staticmethod(_refuse) | ||
|
|
||
| _gitlab._authenticated_gitlab_request( | ||
| _Resolver(), | ||
| api_url="https://gitlab.com/api/v4/projects/acme%2Fapm-policy", | ||
| host="gitlab.com", | ||
| org="acme", | ||
| port=None, | ||
| project_path="acme/apm-policy", | ||
| ) | ||
|
|
||
|
|
||
| def _http() -> None: | ||
| policy_get("not a url") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "channel", [_github, _ado, _gitlab_rest, _http], ids=["github", "ado", "gitlab", "http"] | ||
| ) | ||
| def test_a_failed_fetch_is_still_counted(monkeypatch: pytest.MonkeyPatch, channel) -> None: | ||
| monkeypatch.setattr("apm_cli.core.auth.AuthResolver.try_with_fallback", _refuse) | ||
| before = fetch_attempts() | ||
|
|
||
| with contextlib.suppress(Exception): # the channel's own error handling is not under test | ||
| channel() | ||
|
|
||
| _assert_counted(before) | ||
|
|
||
|
|
||
| def _assert_counted(before: int) -> None: | ||
| """The ledger is the durable state the record writer reads.""" | ||
| assert fetch_attempts() > before |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.