Skip to content

[Tests + Fix]: Added unit tests, Fixed duplication in promptfoo config file generation, changed remaining "arguments" to args for CPEX - #45

Open
dhl123 wants to merge 9 commits into
mainfrom
hl/fix_pr
Open

[Tests + Fix]: Added unit tests, Fixed duplication in promptfoo config file generation, changed remaining "arguments" to args for CPEX#45
dhl123 wants to merge 9 commits into
mainfrom
hl/fix_pr

Conversation

@dhl123

@dhl123 dhl123 commented Aug 21, 2026

Copy link
Copy Markdown
Member

Summary

A cleanup and bug-fix pass over the test-generation pipeline, and test scripts creation, plus the unit and integration test suites.

Closes

#12 #46 #49

Changes

1. args-migration.

  • Changed arguments in docs/policy_creation.md, docs/test_generation.md, policy_cross_validation.mdREADME.md, and the two docs guides to args for cpex compatibility. (problems left in last PR)

2. agent's default value changes in promptfoo config.

  • Changed the default agent port from 8000 to 9000 in promptfooconfig.yaml files.

3. made adjusts to cpex hr-agent example

  • Delete guidance that cannot be enforced by opa (requires approval etc).
  • Added a readme file for running hr-agent example.

4. delete usage of top-k

  • We changed all openai client to aws. aws models only take either temp or topk, so we deleted topk.

5. null values handling in convert_test_case.py.

  • _convert_var in src/smith/test_generation/convert_test_case.py called int(None) / float(None) when a generated case supplied null for a numeric system variable, raising TypeError. Most often triggered by adversarial Promptfoo cases that omit an integer field (e.g. queries_this_session). Now returns None, leaving the field absent so OPA treats it as unset.

**6. remove any previously-appended tool-parameter block in promptfoo config generation (problems left in last PR)

  • Promptfoo config updates weren't idempotent. generate_promptfoo_config.py re-appended the tool-parameter block on every run, so the prompt grew each update. Added a sentinel marker and a strip step so the block is replaced instead of duplicated.

Problem identified when writing unit and integration tests.

7. Missing env setup values

  • Added variables the CLI reads but .env_template omitted. Added variables: TEST_OUTPUT_DIR, TEST_PATH, MCP_URL, TOP_P, MAX_LLM_CALLS.

8. Two modules read the environment themselvesattack.py and
attack_promptfoo.py called load_dotenv()/os.getenv inside the function the CLI
invokes. Both now take the value as a parameter, resolved in cli.py with every other
path. Three functions gained required parameters; cli.py is their only caller.

9. AST graph indices inherited across calls — node ids came from the size of two
module-level dicts that were never reset, so the same policy parsed twice produced
different graphs. init_graph now clears them first.

10. convert_test_coverage.py ran its whole pipeline at import — and crashed
without configuration, which broke the policy_testing unit lane. Environment
resolution and I/O moved into main(); the transformation logic extracted into
importable functions. Output byte-identical, so the frozen coverage numbers still hold.

11. apply_cross_validate crashed when the destination didn't existshutil.move
doesn't create directories, so promoting a case into an absent allow/ raised
FileNotFoundError mid-loop, leaving the tree partially applied. Added
os.makedirs(..., exist_ok=True) before each move.

12. Whitespace-only lines now dropped in decompose.pyremove_empty_line tested
len(strr) != 0, so a line of spaces survived and became a rule, spending an LLM call
to produce a meaningless record. Now judged with .strip(); line content untouched.

13. Discarded exit code hid Regal failuressubprocess.run ran without
check=True and its result was thrown away, and the shell pipeline reported sed's
status anyway. So a missing regal binary produced an empty report and a successful
flag: the same answer as a clean policy. Regal is now invoked directly and its exit
code classified (0 clean, 3 violations, anything else a failure). check=True
would have been wrong — it raises on 3, the normal result. Output byte-identical
wherever Regal actually runs.

Tests

  • To run the unit tests: make unit
  • To run the integration test: make integration

dhl123 added 2 commits August 21, 2026 14:34
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
@dhl123 dhl123 changed the title Fix: Fix tool parms' duplication in pormptfoo config file auto generation, change remaining arguments to args Fix: Fix duplication in pormptfoo config file auto generation, change remaining arguments to args Aug 21, 2026
@dhl123
dhl123 marked this pull request as ready for review August 21, 2026 19:19
@dhl123
dhl123 requested a review from araujof as a code owner August 21, 2026 19:19
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
@dhl123
dhl123 marked this pull request as draft September 2, 2026 20:01
@dhl123 dhl123 changed the title Fix: Fix duplication in pormptfoo config file auto generation, change remaining arguments to args Tests + Fix: Unit tests, Fix duplication in pormptfoo config file auto generation, change remaining arguments to args Sep 2, 2026
@dhl123 dhl123 linked an issue Sep 2, 2026 that may be closed by this pull request
5 tasks
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
@dhl123 dhl123 changed the title Tests + Fix: Unit tests, Fix duplication in pormptfoo config file auto generation, change remaining arguments to args [Tests + Fix]: Added unit tests, Fixed duplication in promptfoo config file generation, changed remaining "arguments" to args for CPEX Sep 4, 2026
@dhl123 dhl123 linked an issue Sep 9, 2026 that may be closed by this pull request
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
@dhl123
dhl123 marked this pull request as ready for review September 9, 2026 17:51
@araujof araujof self-assigned this Sep 9, 2026
@araujof araujof added bug Something isn't working tests labels Sep 9, 2026
@araujof araujof added this to the 0.1.2 milestone Sep 9, 2026
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
Signed-off-by: Hailun Ding <hailun.ding@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working tests

Projects

None yet

2 participants