# Playbook: test a change

**The question, in the user's words:** "I am changing how `JpaUserCredentialStore.createCredentialEntity` sets a new credential's priority. Which existing tests exercise it, and what is left untested?"

**What you get at the end:** the tests that already reach the change, how far up each one sits, the production paths with no test on them, and the places to add one.

## The steps

### 1. Every caller three levels up, as places, with tests marked

```
niro ask get_reverse_call_chain method_fqn=org.keycloak.models.jpa.JpaUserCredentialStore.createCredentialEntity depth=3 answer=locations

JpaUserCredentialStore.createCredentialEntity has 2 direct callers and 12 more further up (14 in all).
confidence: complete | has_more: false — this is the COMPLETE caller chain. Use it directly.
model/jpa/.../JpaUserCredentialStore.java:80  ...JpaUserCredentialStore.createCredential_Nzv6uN (depth 1)
model/storage/.../UserCredentialManager.java:122  ...UserCredentialManager.createStoredCredential_Nj44zN (depth 2)
model/infinispan/.../SubjectCredentialManagerCacheAdapter.java:53  ...createStoredCredential_N778tN (depth 3)
services/.../PasswordCredentialProvider.java:133  ...PasswordCredentialProvider.createCredential_N0xesN (depth 3)
tests/base/.../CredentialModelTest.java:56  ...CredentialModelTest.testCredentialCRUD_NkjyaN [test] (depth 3)
tests/base/.../CredentialModelTest.java:176  ...testCredentialUpdateWithDuplicateLabel_NlanoN [test] (depth 3)
testsuite/.../LDAPUserMultipleCredentialTest.java:100  ...afterImportTestRealm_NjqfxN [test] (depth 3)
testsuite/.../UserStorageTest.java:938  ...UserStorageTest.testCredentialCRUD_Ni2geN [test] (depth 3)
testsuite/.../UserStorageTest.java:1042  ...testCRUDCredentialsOfDifferentUser_Ns8n5N [test] (depth 3)
testsuite/.../RecoveryAuthnCodesAuthenticatorTest.java:329  ...createRecoveryAuthnCodesForUser_Nyz8kN [test] (depth 3)
model/jpa/.../JpaUserProvider.java:1065  ...JpaUserProvider.createCredential_N0sf7N (depth 1)
[shown all 14 callers; ask without answer= for signatures and code]

```

`[test]` marks a caller in test code. Six tests can reach the change in the code as written, all three levels up, through a user's credential manager.

**Check the branches that choose a class at run time.** Two of the six, both in `UserStorageTest`, use a user stored outside Keycloak's own database (a federated user, here "thor"). `UserCredentialManager.getStoreForUser` sends such a user's credentials to a different store, so at run time those two tests never reach `createCredentialEntity`. Four tests really run it. Niro lists every caller the code makes possible; which one a running program takes can depend on data, and only reading that branch tells you.

**Do not combine this with `purpose=VERIFY`.** VERIFY gives names only and leaves the `[test]` marks out.

### 2. What production paths have no test?

The same list shows four credential providers (`OTPCredentialProvider`, `PasswordCredentialProvider`, `RecoveryAuthnCodesCredentialProvider`, `WebAuthnCredentialProvider`) at depth 3 with no test on the list beside them. Ask one level further for each, or ask the provider's own callers, to see whether a test reaches it from higher up:

```
niro ask get_reverse_call_chain method_fqn=org.keycloak.credential.PasswordCredentialProvider.createCredential depth=2 answer=locations

```

### 3. Write the test next to an existing one

`CredentialModelTest` is the closest model test: it calls `user.credentialManager().createStoredCredential(...)` inside a session. Open it with `get_source_code` at the line the list gave.

## Why the answer is complete, and where it is not

- **The chain crosses interfaces.** The tests call `credentialManager()`, which returns an interface; the graph follows it to `SubjectCredentialManagerCacheAdapter` and on down. A text search from the test has no class name to follow.

- **It is checked against a grep:** the test methods that call `createStoredCredential` directly are exactly these six (10 call lines in 4 files). A grep has the same blind spot as the graph here: it cannot tell which store a running test will use.

- **Tests further up are not listed** until you raise `depth` (8 at most). A test that reaches the code through a REST call over HTTP to a running server is outside the graph.

## What grep would do instead

To get here by search, an agent needs to know that `createCredentialEntity` is reached through `createCredential`, then `createStoredCredential`, then the credential manager interface, before it can search the tests for `createStoredCredential(`. That is three searches and three reads before the useful one, and the middle step names an interface, not a class.

## Cost

What these steps cost depends on your code and your question. How Niro counts the size of its answers, and how to measure the cost on your own tasks, is in [Tokens, speed and accuracy](https://help.niroai.dev/cli/tokens-speed-and-accuracy/).

## Related

[Choose what to test](https://help.niroai.dev/cli/lifecycle-test/), [Playbook: change code safely](https://help.niroai.dev/cli/playbook-change-safely/), [Playbook: review a change](https://help.niroai.dev/cli/playbook-review-a-change/).