Skip to content

Add regression tests for record renewal in credentials-core - #89

Merged
ualtinok merged 2 commits into
cortexkit:masterfrom
iceteaSA:test/renewal-regression-tests
Dec 5, 2026
Merged

ualtinok merged 2 commits into
cortexkit:masterfrom
iceteaSA:test/renewal-regression-tests

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Refs #88

This pull request changes tests only. If it fits, please label it trivial, as CONTRIBUTING.md allows when there is no design to agree.

What changes

  1. test(credentials-core): cover record renewal adds 15 tests for the renewal coordinator and its store writes: refresh intents, report cooldowns, parked records, forced reads, and the lock registry. They are in engine_tests.rs, store_tests.rs, and the #[cfg(test)] mod lock_registry_tests in engine.rs. No production code changes.
  2. test(credentials-core): let RefreshLogs see cached callsites is a separate commit with the subscriber change you asked for: RefreshLogs returns Interest::always() from register_callsite and filters by target in event(), as connectors_tests.rs does. This is a suspected cause of the auth_events_refresh_outage_logs_onset_and_recovery_across_restarts flake, not a proven one: in our runs that test still failed once with this change applied. You can drop this commit and keep the first one.

How it was checked

The 32 code changes in the issue table are the ones these tests catch. Each new test fails on its change and passes on unchanged code. After review, three assertions became stricter (an exact error variant, a success read before a refusal, and no deferral row on a forced read), and a planted change proved each one again.

On the head of this branch (master 1a40f031 plus these two commits), on Linux: cargo fmt --all -- --check and cargo clippy --workspace --all-targets -- -D warnings pass. cargo test -p credentials-core --all-features passed in two of three runs (1278 tests each). The third run failed only auth_events_refresh_outage_logs_onset_and_recovery_across_restarts at engine_tests.rs:1188. That is the flake that the second commit is for, so the second commit does not remove it completely.

AI helped write this draft.


Summary by cubic

Adds regression tests covering the record renewal coordinator and its store writes, tied to the failing cases from issue #88. Tests only, no production code changes.

  • Adds 15 tests across engine_tests.rs, store_tests.rs, and engine.rs for refresh intents, report cooldowns, parked records, forced reads, and the lock registry.
  • Updates RefreshLogs in engine_tests.rs to register callsites with Interest::always() and filter by target in event(), matching how connectors_tests.rs works. This is a suspected cause of the auth_events_refresh_outage_logs_onset_and_recovery_across_restarts flake, not a proven one—the test still failed once with the change applied. Drop this commit if you prefer to keep the PR strictly tests-only.

Written for commit c8adb8d. Summary will update on new commits.

View guided diff

Add regression tests for the renewal coordinator and its store writes:
refresh intents, cooldowns, parked records, forced reads and the lock
registry. Tests only; no production change. Refs cortexkit#88.
RefreshLogs installs a thread-local subscriber without register_callsite,
so tracing can cache Interest::never for the refresh events when another
thread reaches them first. Return Interest::always and filter by target
in event(), as connectors_tests does. This is a suspected cause of the
outage-log test flake, not a proven one: the test still failed once in
our runs with this change applied.
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Design gate skipped: the trivial label is applied.

@ualtinok ualtinok added the trivial Typo-class change; exempt from the design-approved gate label Dec 5, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/credentials-core/src/store_tests.rs">

<violation number="1" location="crates/credentials-core/src/store_tests.rs:3646">
P2: This assertion expects `NeedsReauth`, but the intent version is 2 while the stored record remains version 1, so reconciliation returns `NotFound` on the version guard. Expect `NotFound` or create a parked record at version 2.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

let stale_version = store.read_intent(id).unwrap().unwrap();
assert!(matches!(
store.get_for_reconciliation(&stale_version),
Err(StoreOpError::NeedsReauth)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This assertion expects NeedsReauth, but the intent version is 2 while the stored record remains version 1, so reconciliation returns NotFound on the version guard. Expect NotFound or create a parked record at version 2.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At crates/credentials-core/src/store_tests.rs, line 3646:

<comment>This assertion expects `NeedsReauth`, but the intent version is 2 while the stored record remains version 1, so reconciliation returns `NotFound` on the version guard. Expect `NotFound` or create a parked record at version 2.</comment>

<file context>
@@ -3449,6 +3449,216 @@ fn refresh_commit_cannot_restore_non_active_records() {
+    let stale_version = store.read_intent(id).unwrap().unwrap();
+    assert!(matches!(
+        store.get_for_reconciliation(&stale_version),
+        Err(StoreOpError::NeedsReauth)
+    ));
+    store.open_intent(id, 1, "old-hash").unwrap();
</file context>
Suggested change
Err(StoreOpError::NeedsReauth)
Err(StoreOpError::NotFound)

@ualtinok
ualtinok merged commit 7a1be58 into cortexkit:master Dec 5, 2026
11 of 13 checks passed
@ckcred-alfonso

ckcred-alfonso Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Thank you for these. Merged as 7a1be58. Before merging we checked two of them against planted changes: dropping the start-time check from the intent confirmation fails confirming_a_refresh_intent_requires_the_same_marker_and_record, and letting the report cooldown hold back a forced read fails a_forced_read_ignores_the_report_cooldown.

You were right that auth_events_refresh_outage_logs_onset_and_recovery_across_restarts is flaky, and the defect is ours. The cause is in how tracing caches a log site. While only one dispatcher exists, tracing-core decides whether a new log site is wanted by asking the dispatcher of the thread that reaches it first. When another test thread logs the refresh-outage start first, that thread has no capture, so the site is cached as never wanted. The test's own thread-local capture is then never asked, which is why returning Interest::always() from RefreshLogs didn't help: on that thread RefreshLogs isn't the dispatcher being asked.

The fix keeps a second, disabled dispatcher registered while the test runs, so the interest is worked out across every dispatcher. The test now also makes another thread reach the log site first every time, so it fails reliably without the fix. It replaces the RefreshLogs change from your second commit: e69c9b8, now on master.

I also merged #90: with the enrolled fence arm removed, its test fails at the final not_found assertion while the control read still passes, as you described. Thank you for both.

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

Labels

trivial Typo-class change; exempt from the design-approved gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants