Skip to content

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

Merged
utksh1 merged 1 commit into
utksh1:mainfrom
shravanithouta108:test/workflow-api-edge-cases
Jun 15, 2026
Merged

test(backend): add workflow API edge-case coverage for empty steps an…#647
utksh1 merged 1 commit 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.

@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.

@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

@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 after the route-prefix update. This still needs changes because the tests call the real app without patching get_db or using the existing backend DB fixture. Valid workflow creation tests can hit the real database state and return unrelated failures, while the PR imports AsyncMock and patch but does not use them. Please wire the tests through the established test DB setup or patch backend.secuscan.routes.get_db with a controlled mock.

@shravanithouta108 shravanithouta108 force-pushed the test/workflow-api-edge-cases branch 2 times, most recently from c28184d to 157f902 Compare June 13, 2026 14:21

@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.

Rechecking after the latest test-class fixes: this is still blocked.

The frontend-checks job is failing on the current head. Also please verify the updated workflow route tests patch the same get_db call shape used by the routes; tests that replace an awaited function with an async generator can fail for the wrong reason instead of covering the intended API edge cases.

@shravanithouta108

Copy link
Copy Markdown
Contributor Author

Hi @utksh1 — all backend checks are passing. The only failing check is frontend-checks due to the pre-existing esbuild vulnerability (GHSA-gv7w-rqvm-qjhr, CVSS 8.1) in main. This PR adds only a single backend test file with zero frontend changes — no package.json, no node_modules, no frontend code touched. The vulnerability exists on main independently of this branch and requires upgrading esbuild in the main repo to resolve. Could you fix that on main or whitelist it in .audit-config.yaml so this PR can be evaluated on its actual changes?

@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.

Rechecking after the latest get_db patch: this is still blocked.

The frontend-checks job is failing on the current head. Please fix CI before this workflow API edge-case test coverage can be reconsidered.

@shravanithouta108 shravanithouta108 requested a review from utksh1 June 14, 2026 10:17

@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.

Rechecking after the latest audit-exception commit: this is still blocked.

Please keep this workflow API edge-case test PR focused on backend test coverage. Remove unrelated audit-config/esbuild exception changes from the branch; audit policy changes need a separate review path.

@utksh1 utksh1 force-pushed the test/workflow-api-edge-cases branch from 16ae428 to 7a212a7 Compare June 15, 2026 12:06
@shravanithouta108 shravanithouta108 force-pushed the test/workflow-api-edge-cases branch from 7a212a7 to 999b1a7 Compare June 15, 2026 12:10

@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.

Cleaned this branch to the focused workflow API test file and rebased it onto current main. Fresh checks are green.

@utksh1 utksh1 merged commit 17adbfa into utksh1:main Jun 15, 2026
11 checks passed
@utksh1 utksh1 added the gssoc:approved Admin validation: approved for GSSoC scoring label Jun 15, 2026
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 gssoc:approved Admin validation: approved for GSSoC scoring 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