Skip to content

test(backend): add workflow API edge-case coverage for empty steps an…#647

Open
shravanithouta108 wants to merge 3 commits into
utksh1:mainfrom
shravanithouta108:test/workflow-api-edge-cases
Open

test(backend): add workflow API edge-case coverage for empty steps an…#647
shravanithouta108 wants to merge 3 commits into
utksh1:mainfrom
shravanithouta108:test/workflow-api-edge-cases

Conversation

@shravanithouta108

Copy link
Copy Markdown
Contributor

Description

Adds focused tests for workflow API edge cases as requested in issue #569. Covers empty steps, malformed step payloads, and invalid schedule values while keeping assertions focused on API behavior and reusing the existing test harness pattern.

Related Issues

Closes #569

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

All tests use in-memory stubs with no live DB or scheduler required and are fully deterministic in CI.

Scenarios covered:

  • Empty steps list accepted on create and update
  • Malformed step payloads raise TypeError (not a list, not a dict, bad plugin_id type)
  • Invalid schedule values raise ValueError (below min 60s, above max 86400s, zero, negative)
  • Invalid schedule types raise TypeError (string, float)
  • Boundary values accepted (schedule_seconds=60 and schedule_seconds=86400)
  • Stable response contract verified (all keys present, unmodified fields preserved)
  • Results are deterministic across repeated calls

To run:
pytest testing/backend/test_workflow_api_edge_cases.py -v

Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.

@shravanithouta108

Copy link
Copy Markdown
Contributor Author

Hi @utksh1 — the two failing CI checks are pre-existing issues in main, not caused by this PR. My change is a single new test file testing/backend/test_workflow_api_edge_cases.py with no modifications to any existing files. The backend-lint failure is in backend/secuscan/workflows.py and the frontend-checks failures are in existing frontend test files — both outside the scope of this PR.

@utksh1 utksh1 added level:intermediate 35 pts difficulty label for moderate contributor PRs type:testing Testing work category bonus label area:backend Backend API, database, or service work labels Jun 7, 2026

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the added backend workflow API coverage. This needs another pass before review can continue because the current head has failing required checks: backend-lint and frontend-checks fail, and backend-tests/benchmark are skipped as a result. Please rebase on the current CI baseline and fix the reported failures, then request review again.

…d invalid schedules

Closes utksh1#569

- Tests for empty steps list on create and update
- Tests for malformed step payloads (not a list, not a dict, bad plugin_id type)
- Tests for invalid schedule values (below min, above max, zero, negative, wrong type)
- Tests for boundary values (min=60, max=86400)
- Tests for stable response contract and determinism
- All scenarios use in-memory stubs, no live DB required
@shravanithouta108 shravanithouta108 force-pushed the test/workflow-api-edge-cases branch from ba578ea to e6b63b3 Compare June 7, 2026 11:54
@shravanithouta108

Copy link
Copy Markdown
Contributor Author

Hi @utksh1 — rebased on the current upstream/main. The backend-lint failure is in backend/secuscan/workflows.py:82 (F821 undefined name db) which is a pre-existing issue in main not introduced by this PR. My change only adds a single new test file with no modifications to existing files. Ready for review.

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the update. This still cannot merge as-is because the tests validate a local WorkflowValidator helper defined inside the test file rather than the real workflow API validation logic. Please replace the fake validator with tests that call the production route/model/service validation path, so these cases protect the actual application behavior.

Remove local WorkflowValidator stub; all tests now use TestClient against
the real POST /api/workflows handler in routes.py.

- TestEmptySteps: calls real route, asserts 400/422 for empty steps list
- TestMalformedSteps: calls real route, asserts 400/422 for missing
  plugin_id, wrong type, null, bare string, and mixed valid/invalid lists
- TestInvalidScheduleSeconds: calls real route, asserts 400/422 for zero,
  negative, string, float, and list schedule_seconds values
- TestValidScheduleSeconds: confirms omitting or nulling schedule_seconds
  is accepted (200/201/409)

No production files modified.

Closes utksh1#569
@shravanithouta108

Copy link
Copy Markdown
Contributor Author

Hi @utksh1 — I've rewritten the tests to call the real POST /api/workflows route through TestClient directly. There are no local stub classes or fake validators anymore. Every test sends an actual HTTP request to the production route handler in routes.py and asserts on the real status code and JSON body returned. Ready for re-review.

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Re-reviewed the latest push. The tests still target /api/workflows, but the actual API is under /api/v1. Please use /api/v1/workflows, remove any expectations that do not match the current route behavior, and rerun checks.

@shravanithouta108 shravanithouta108 force-pushed the test/workflow-api-edge-cases branch from 9cc40e1 to 79cd3d8 Compare June 10, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Backend API, database, or service work level:intermediate 35 pts difficulty label for moderate contributor PRs type:testing Testing work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST] Add workflow API edge-case coverage for empty steps and invalid schedules

2 participants