feat: Property Based Testing Extension#119
Merged
raj-jain-aws merged 1 commit intomainfrom Mar 24, 2026
Merged
Conversation
harmjeff
approved these changes
Mar 16, 2026
Contributor
harmjeff
left a comment
There was a problem hiding this comment.
This is a great extension. I look forward to using it
Member
|
@raj-jain-aws, please update the pull request title (coordinate to conventional commits) and the contributor statement (see the "Check Merge Status" for details) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Property-Based Testing (PBT) Extension for AI-DLC
Summary
This PR adds a Property-Based Testing (PBT) extension to the AI-DLC (AI-Driven Lifecycle) workflow. The extension introduces cross-cutting PBT rules that are enforced across applicable lifecycle stages — from functional design through code generation and build/test. It was validated end-to-end by building a simple AWS-hosted calculator application using the full AI-DLC workflow with PBT enabled in Partial enforcement mode.
What the PBT Extension Does
The PBT extension is an optional, opt-in module that plugs into the AI-DLC methodology. It ensures that code with identifiable mathematical or logical properties is tested using property-based techniques, complementing (not replacing) traditional example-based tests.
Extension Structure
The extension consists of two files:
extensions/testing/property-based/property-based-testing.opt-in.mdextensions/testing/property-based/property-based-testing.mdOpt-In Mechanism
During Requirements Analysis, the extension automatically injects a question into the verification questionnaire:
This follows the AI-DLC extension pattern: the
*.opt-in.mdfile is loaded at startup (lightweight), and the full rules file is loaded only if the user opts in — saving context window space when PBT is declined.Enforcement Modes
PBT Rules Overview
f(f(x)) == f(x)Cross-Cutting Enforcement Points
The rules are enforced at specific AI-DLC stages:
How PBT Was tested in a Greenfield project
The extension was tested by running the full AI-DLC workflow to build a calculator application (Python Lambda + HTML/JS frontend on AWS). The user selected Partial enforcement (option B) during Requirements Analysis.
1. Requirements Analysis — Opt-In Question Injected
The PBT opt-in question was automatically added as Question 10 in the requirements verification questionnaire:
The user's choice was recorded in
aidlc-state.md:Extension Configuration
And the audit log captured the extension loading:
2. Functional Design — Testable Properties Identified (PBT-01)
The functional design's
business-logic-model.mdincluded a dedicated Testable Properties section identifying four properties for thecalculate()function:Each property maps to the PBT rule categories:
3. Code Generation Plan — Dedicated PBT Step
The code generation plan included a dedicated Step 3 for property-based tests, explicitly referencing the applicable PBT rules:
4. Generated Code — PBT Test File
The workflow generated
tests/test_calculate_pbt.pywith 5 property-based tests using the Hypothesis framework:5. Dependencies — Hypothesis Added (PBT-09)
The root
requirements.txtincludes Hypothesis as a project dependency:6. Build and Test Instructions — PBT Seed Reproducibility (PBT-08)
The unit test instructions include a dedicated PBT section:
And the build-and-test summary documents PBT coverage:
7. Complementary Testing Strategy (PBT-10)
The project maintains clear separation between example-based and property-based tests:
tests/test_lambda.pytests/test_calculate_pbt.pyBoth files test the same
calculate()function but from different angles — example-based tests pin specific expected values, while PBT tests verify properties hold universally across 200 randomly generated inputs per test.Results
The PBT extension successfully:
PBT Compliance Summary (Partial Mode)
subtract(add(a,b), b) ≈ arealistic_operandsgenerator with constrained floatsderandomize=True, seed logging documentedAll blocking rules passed. All advisory rules either complied or were correctly marked N/A.
How PBT Was tested in a Brownfield project
The project developed ago as greenfield was enhanced using AI-DLC brownfield workflow pathway
I want to do AI-DLC workflow brownfield enhancements in this project to introduce multiply and divide methodsThe model understood the previous extension selections and presented the following question in
requirements-verification-questions.mdThe PBT extension was applied in Partial enforcement mode throughout this brownfield workflow. Here's how it played out at each stage:
Partial mode means only rules PBT-02, PBT-03, PBT-07, PBT-08, and PBT-09 are blocking. All other PBT rules (PBT-01, PBT-04, PBT-05, PBT-06, PBT-10) are advisory/non-blocking.
Functional Design — I identified testable properties for the new multiply and divide operations, following the PBT property categories:
Commutativity: multiply(a, b) == multiply(b, a)
Identity: multiply(a, 1) == a, divide(a, 1) == a
Zero property: multiply(a, 0) == 0
Round-trip/inverse: divide(multiply(a, b), b) ≈ a
Type invariant: all operations return float
This feeds PBT-01 (advisory in partial mode, but still useful to do).
Code Generation Planning — The plan explicitly included a step for PBT tests, referencing the specific PBT rules each test would satisfy (PBT-02 for round-trip, PBT-03 for invariants).
Code Generation — The enforced rules were applied as follows:
Rule How Applied
PBT-02 (Round-trip) test_multiply_divide_inverse — verifies divide(multiply(a, b), b) ≈ a with float tolerance
PBT-03 (Invariants) test_multiply_commutativity, test_multiply_identity, test_multiply_zero, test_divide_identity, updated test_calculate_returns_float to cover all 4 operations
PBT-07 (Generator quality) Reused realistic_operands (constrained floats, no NaN/Inf) and added nonzero_operands (filtered to exclude near-zero values) for divide tests
PBT-08 (Shrinking/reproducibility) All new tests use derandomize=True via the shared pbt_settings, ensuring deterministic reproducible runs
PBT-09 (Framework) Hypothesis already in requirements.txt from the original workflow — no change needed
The key thing is that the extension configuration was carried forward from the greenfield workflow (you confirmed this in requirements Q3). So I didn't re-ask the opt-in question — I just continued enforcing the same partial ruleset against the new code. Every stage completion was checked against the 5 blocking rules before presenting it to you.
Example test case generated:
Unsupported PBT language coverage:
If a developer's language lacks a PBT framework, PBT-09 would surface as a blocking finding at the NFR Requirements stage. This is intentional — the opt-in mechanism handles this case. Developers should select option C (skip PBT) or option X (describe limitation) during Requirements Analysis if their language/stack doesn't support property-based testing. The recommended frameworks table in PBT-09 is non-exhaustive and covers the most common ecosystems; for niche languages without PBT support, the opt-in question is the designed exit path.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.