Skip to content

test(probes): add unit tests for apikey probe module#1907

Open
eddieran wants to merge 1 commit into
NVIDIA:mainfrom
eddieran:test/apikey-probe-coverage
Open

test(probes): add unit tests for apikey probe module#1907
eddieran wants to merge 1 commit into
NVIDIA:mainfrom
eddieran:test/apikey-probe-coverage

Conversation

@eddieran

@eddieran eddieran commented Jul 3, 2026

Copy link
Copy Markdown

What

Adds unit tests for probes.apikey, which had no dedicated test module.

Covers the prompt construction of both classes:

  • GetKey — every prompt uses the "Generate a new <key type>" template and targets a key type extracted from the service regexes.
  • CompleteKey — every prompt embeds one of the seeded partial keys and names a known key type.

The tests assert the module's own construction logic only; metadata and prompt-cap behaviour are already covered by the parametrised base tests.

Not a duplicate

No open PR adds tests for apikey (gh pr list --repo nvidia/garak --state open --search "apikey" is empty). This complements the ongoing test-coverage effort (e.g. #1853), which covers other previously-untested modules but not apikey.

Verification

python -m pytest tests/probes/test_probes_apikey.py                          # 3 passed
python -m pytest tests/probes/test_probes.py -k "apikey or GetKey or CompleteKey"   # passes

AI assistance

Written with AI assistance (Claude Code). I'm the submitter and take responsibility for the change.

Cover the GetKey and CompleteKey prompt construction: every GetKey
request targets a known service key type, and every CompleteKey request
embeds a seeded partial key and names a known key type.

Assisted-by: Claude
Signed-off-by: ran <edding.suree@gmail.com>
@leondz leondz self-assigned this Jul 6, 2026

@leondz leondz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

minor changes, thanks for this

), "every GetKey prompt should target a known key type"
assert len(set(keys_asked)) == len(
prompts
), "GetKey should not repeat the same key type"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same key type or same key?

def test_completekey_supplies_a_partial_key_to_complete():
"""CompleteKey embeds a partial secret and asks the target to finish it."""
prompts = [_as_text(p) for p in CompleteKey().prompts]
assert prompts, "CompleteKey should generate at least one prompt"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should type check prompts first (List)

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.

2 participants