4.2 KiB
Task 003 — KS-2 regression coverage
Goal
Strengthen the regression test coverage of the existing KS-2 service without changing production behavior.
The current KS-2 implementation has already passed the read-only business-rules audit. This task formalizes several important rules as explicit regression tests.
Scope
1. Cross-project integrity
Add a test proving that KS-2 cannot be created/issued using a WorkItem from another project.
Expected behavior:
- the KS-2 operation is rejected;
- no partial KS-2 data remains after the failed operation.
Use the existing project/work-item/daily-report fixtures and service API.
2. Positive quantity
Add a test proving that KS-2 item quantity must be strictly greater than zero.
Cover at least:
- quantity
0; - negative quantity.
Expected behavior:
- validation error;
- no invalid KS-2 draft/item is persisted.
3. Duplicate WorkItem in one KS-2
Add a test proving that the same WorkItem cannot appear twice in a single KS-2.
Expected behavior:
- validation error;
- no invalid duplicate KS-2 item is persisted.
4. Server-side amount calculation
Add a test proving that KS-2 amount is calculated on the server from:
quantity × WorkItem.unit_price
The client/request must not be able to supply an arbitrary amount.
Expected behavior:
- persisted/calculated amount equals server-side quantity × WorkItem price;
- a client-supplied arbitrary amount, if the current API accepts such a field, must not override the server calculation.
Follow the existing service/API design. Do not redesign the API for this test.
5. Atomic rollback on issue failure
Add a regression test for the atomicity rule:
If issuing a KS-2 fails because one of its requested quantities cannot be allocated from available actual volume, the operation must not leave partially created/updated source records.
Expected behavior:
- issue fails;
- no partial
KS2ItemSourceallocations remain from the failed operation; - previously existing valid data remains unchanged.
Use the smallest scenario that reliably exercises the existing transactional behavior.
6. Issued KS-2 is immutable
Add a test proving that an issued KS-2 cannot subsequently be edited or otherwise modified through the normal service workflow.
Expected behavior:
- modification is rejected;
- issued KS-2 data remains unchanged.
Use the existing status/service semantics; do not invent a new status model.
7. Repeated issue is rejected
Add a test proving that an already issued KS-2 cannot be issued a second time.
Expected behavior:
- second issue attempt is rejected;
- no duplicate source allocations are created;
- original issued data remains unchanged.
Constraints
- Production code must not be changed unless a test exposes a genuine existing defect required to satisfy an already-defined business rule.
- Do not redesign the KS-2 model or service.
- Do not add unrelated tests.
- Do not add cross-project tests beyond the specific KS-2 integrity scenario described above.
- Reuse existing fixtures/helpers and test style.
- Keep the task focused on
tests/test_ks2.pyunless a minimal test-support change is genuinely required. - Do not commit or push.
Files to read first
Before editing, read:
AGENTS.mddocs/tasks/001-ks2-regression-tests.mddocs/implementation/001-ks2-regression-tests.mddocs/tasks/002-ks2-readonly-audit.mddocs/implementation/002-ks2-readonly-audit.mdapp/models/ks2.pyapp/services/ks2_service.pytests/test_ks2.py- related Daily Report models/services used by the KS-2 tests
Verification
Run:
pytest -q
git diff --check
The implementation report must contain the actual command results. Do not claim a command was run unless its output was observed.
Implementation report
Create:
docs/implementation/003-ks2-regression-coverage.md
The report must include:
- Status
- What was done
- Changed files
- Tests added, by test name
- Verification results
- Deviations
- Follow-up / Open Questions
If production code was changed, explain exactly why in Deviations.
Completion criterion
The task is complete only when the requested regression coverage is implemented, verification has been run, and the implementation report has been created.