Skip to content

Make adversarial generator seedable and random-looking#24

Merged
daedalus merged 2 commits intomasterfrom
copilot/ensure-deterministic-adversarial-generator
May 6, 2026
Merged

Make adversarial generator seedable and random-looking#24
daedalus merged 2 commits intomasterfrom
copilot/ensure-deterministic-adversarial-generator

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

The adversarial generator always produced identical, hardcoded pairs (fixed module names, parameter names, types), making outputs recognizable and non-reproducible-on-demand. Now every pair is randomized but fully reproducible via an optional seed parameter.

Changes

adversarial_generator.py

  • Added name pools: _MODULES, _FUNC_NAMES, _PARAM_NAMES, _SCALAR_TYPES, _MISLEADING_KWONLY_NAMES, _DECORATOR_NAMES, _VERSION_SUFFIXES
  • Added _rand_fqname(rng) and _rand_params(rng, n) helpers
  • All 10 _strategy_* functions now accept a random.Random instance — module names, function names, parameter names, types, and decorators are all drawn from pools via the RNG
  • generate() and generate_all() accept a seed keyword argument; a random.Random(seed) is created and threaded through all strategy calls

tests/test_adversarial_generator.py

  • Added TestSeeding class covering: same seed → identical output, different seeds → different output, string seeds, unseeded invocation, and fqname variance across 20 seeds

Usage

# Reproducible — same seed always yields the same pair
p1 = generate("type_narrowing_disguised_as_cleanup", seed=42)
p2 = generate("type_narrowing_disguised_as_cleanup", seed=42)
assert p1.old_signatures == p2.old_signatures  # True

# Random-looking — different seeds yield different names
p3 = generate("type_narrowing_disguised_as_cleanup", seed=99)
# p3 will have different fqname, param names, and types than p1

# Unseeded — draws OS entropy, non-reproducible
p4 = generate("type_narrowing_disguised_as_cleanup")

# Seed the full batch
pairs = generate_all(seed=7)

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Sorry @Copilot, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@daedalus daedalus marked this pull request as ready for review May 6, 2026 21:08
@daedalus daedalus merged commit 918dc84 into master May 6, 2026
1 check was pending
@daedalus daedalus deleted the copilot/ensure-deterministic-adversarial-generator branch May 6, 2026 21:08
@codacy-production
Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 12 high · 1 medium · 4 minor

Alerts:
⚠ 17 issues (≤ 0 issues of at least minor severity)

Results:
17 new issues

Category Results
Documentation 4 minor
Security 1 medium
12 high

View in Codacy

🟢 Metrics 20 complexity · 0 duplication

Metric Results
Complexity 20
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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