Skip to content

Extract MCP work-proof guidance helpers#382

Merged
ramimbo merged 3 commits into
ramimbo:mainfrom
szw9999:codex-mrwk-structured-guidance-round2
May 26, 2026
Merged

Extract MCP work-proof guidance helpers#382
ramimbo merged 3 commits into
ramimbo:mainfrom
szw9999:codex-mrwk-structured-guidance-round2

Conversation

@szw9999
Copy link
Copy Markdown
Contributor

@szw9999 szw9999 commented May 26, 2026

Refs #377
Refs #378

Summary

  • Extract MCP work-proof text and structured guidance builders from app/main.py into app/mcp_work_proof.py.
  • Keep submit_work_proof text behavior unchanged while making the MCP guidance boundary easier to review and extend.
  • Make structured JSON guidance more consistent by keeping generic and bounty-specific responses on the same field set.
  • Distinguish an open-but-full bounty from a closed/paid bounty in structured next-action guidance.
  • Add focused unit coverage for the extracted helpers and preserve existing MCP regression coverage.

Complexity reduced

app/main.py no longer owns the long nested work-proof guidance builders inside _call_mcp_tool. The MCP tool dispatch now calls a focused module for guidance formatting, so future submit_work_proof changes can be reviewed without expanding the already-large route/app entrypoint.

Evidence

  • Existing public text-mode submit_work_proof output remains covered by the existing MCP tests.
  • Structured generic guidance now includes the same core keys as bounty-specific guidance: max_awards, awards_paid, available_mrwk, and title.
  • Structured submission requirements now receive explicit availability state instead of a boolean, so consumers can tell "closed/paid" from "open but full".

Validation

  • .venv\Scripts\python.exe -m pytest tests\test_mcp_work_proof.py tests\test_api_mcp.py::test_mcp_submit_work_proof_returns_bounty_specific_guidance tests\test_api_mcp.py::test_mcp_submit_work_proof_keeps_generic_guidance tests\test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_bounty_guidance tests\test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_generic_guidance tests\test_api_mcp.py::test_mcp_submit_work_proof_structures_terminal_bounty_availability tests\test_api_mcp.py::test_mcp_submit_work_proof_scopes_issue_number_by_repo tests\test_api_mcp.py::test_mcp_submit_work_proof_rejects_invalid_bounty_selectors tests\test_api_mcp.py::test_mcp_submit_work_proof_rejects_ambiguous_issue_number -q
  • .venv\Scripts\python.exe -m ruff format --check app\mcp_work_proof.py app\main.py tests\test_mcp_work_proof.py tests\test_api_mcp.py
  • .venv\Scripts\python.exe -m ruff check app\mcp_work_proof.py tests\test_mcp_work_proof.py tests\test_api_mcp.py
  • .venv\Scripts\python.exe -m mypy app
  • git diff --check

Summary by CodeRabbit

  • Refactor

    • Reorganized work proof guidance and submission requirements into a dedicated module for improved code maintainability.
    • Enhanced bounty submission requirements with better handling of availability states.
  • Tests

    • Added comprehensive test coverage for work proof guidance generation and submission requirement validation.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 90f94c07-eaa2-4df6-90af-3c3980330dd3

📥 Commits

Reviewing files that changed from the base of the PR and between f41fa4f and 298fb82.

📒 Files selected for processing (1)
  • tests/test_mcp_work_proof.py

📝 Walkthrough

Walkthrough

Extract work-proof guidance logic from app/main.py into a new app/mcp_work_proof module providing: work_proof_guidance (text), work_proof_submission_requirements (structured), work_proof_guidance_json (bounty-specific JSON), and generic_work_proof_guidance_json; update main.py imports and add tests validating behaviors.

Changes

MCP Work-Proof Guidance Refactoring

Layer / File(s) Summary
Module setup and text guidance
app/mcp_work_proof.py
Adds SubmissionAvailability type and work_proof_guidance(bounty) producing human-readable guidance with availability and safety exclusions.
Structured submission requirements
app/mcp_work_proof.py
work_proof_submission_requirements(...) returns a requirements dict with reference formats, claim command/attempt endpoint, evidence rules, acceptance trigger, public metadata avoidance, and availability-dependent first next_action.
Availability mapping
app/mcp_work_proof.py
_submission_availability(bounty_data) maps bounty status and awards_remaining to open, full, closed, or unknown.
JSON guidance functions
app/mcp_work_proof.py
work_proof_guidance_json(bounty) computes can_submit, availability_warnings, and nests submission_requirements; generic_work_proof_guidance_json() returns same schema with placeholder/None bounty fields and availability="unknown".
Main module integration
app/main.py
Imports generic_work_proof_guidance_json, work_proof_guidance, and work_proof_guidance_json from app.mcp_work_proof, removing the prior inline guidance implementation.
Test coverage
tests/test_mcp_work_proof.py, tests/test_api_mcp.py
Adds helpers and pytest tests to validate submission requirement variants (closed/full), guidance JSON for open/blocked states, text guidance safety rules, generic guidance placeholders, and updates API test to expect nullable max_awards, awards_paid, and title.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ramimbo/mergework#339: The main PR refactors the work-proof guidance/JSON generation in submit_work_proof to use new helpers in app/mcp_work_proof.py, which is the same guidance logic that PR #339 extended with structured availability (can_submit, availability, availability_warnings).
  • ramimbo/mergework#287: The main PR refactors and centralizes the submit_work_proof work-proof guidance logic (previously implemented in app/main.py in #287) into new helper functions in app/mcp_work_proof.py, while updating app/main.py to import and use them.
  • ramimbo/mergework#347: The main PR’s refactor that moves/centralizes the submit_work_proof guidance generation into app/mcp_work_proof.py directly corresponds to the retrieved PR’s introduction of the structured submission_requirements JSON (including state-aware next_actions) and its wiring into work_proof_guidance_json/generic_work_proof_guidance_json.

Suggested labels

mrwk:accepted, mrwk:paid

Suggested reviewers

  • TateLyman
  • ayskobtw-lil
  • weilixiong
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Extract MCP work-proof guidance helpers' clearly and concisely describes the main refactoring objective—moving guidance builders from app/main.py to app/mcp_work_proof.py.
Description check ✅ Passed The description includes a clear summary of objectives, detailed evidence of changes, and comprehensive validation steps covering tests and linting, though the MRWK related bounty/issue section correctly references #377 and #378.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/mcp_work_proof.py`:
- Around line 42-47: The function work_proof_submission_requirements currently
accepts only can_submit: bool|None which conflates "bounty closed" and "bounty
open but full"; change its signature to accept an explicit availability status
(e.g., availability: Literal['available','full','closed', None] or an enum) and
update its internal branching to use that status to produce distinct
next_actions for 'closed' vs 'full'; update callers such as
work_proof_guidance_json to pass the new availability status instead of a
boolean, and adjust any other call sites that pass can_submit (including the
other referenced usages) so the UI can show "wait for reopen" when closed and
"join waitlist / check later" when full.
- Around line 161-177: The generic JSON schema returned by
generic_work_proof_guidance_json() is missing keys present in
work_proof_guidance_json() which makes the response shape inconsistent; update
generic_work_proof_guidance_json() to include the same keys (add "max_awards",
"awards_paid", "available_mrwk", and "title") with None (or appropriate
None-equivalent) placeholders so both functions return the same key set and
consumers/schema validation remain stable.

In `@tests/test_mcp_work_proof.py`:
- Around line 6-21: Add a parallel test function (e.g.,
test_work_proof_submission_requirements_choose_open_bounty_for_open_state) that
calls work_proof_submission_requirements with the same bounty_id and
issue_number but can_submit=True, then assert reference_formats and
attempt_endpoint still match, assert that the next_actions no longer require the
"choose_open_bounty" action (i.e., there is no action with id
"choose_open_bounty" marked required=True or that action is absent), and assert
that "price claims" is not present in
requirements["public_metadata_must_avoid"]; use the same function name
work_proof_submission_requirements to locate the logic.
- Around line 15-19: The test currently accesses requirements["next_actions"][0]
directly which can raise unclear errors if the list is empty or reordered;
update the assertion in tests/test_mcp_work_proof.py to locate the action by id
(e.g., use next(...) to find the dict where item["id"] == "choose_open_bounty"),
assert that the found action is not None, and then compare its keys/values to
the expected {"id":"choose_open_bounty","required":True,"text":...};
alternatively assert the list length or that
any(item["id"]=="choose_open_bounty" and item["required"] and
item["text"]==expected_text for item in requirements["next_actions"]) to make
the check robust.
- Around line 31-32: The assertions are brittle because they index into
guidance["submission_requirements"]["next_actions"] and guidance["safety_rules"]
directly; change them to robust checks such as asserting the list has expected
length (e.g., len(guidance["submission_requirements"]["next_actions"]) > 0) and
using any(...) to find an element with id "select_bounty" (e.g., any(a.get("id")
== "select_bounty" for a in
guidance["submission_requirements"]["next_actions"])), and similarly use
any("private keys" in s for s in guidance["safety_rules"]) to confirm presence
rather than relying on [0].
- Line 3: Add tests for the remaining helpers by calling work_proof_guidance and
work_proof_guidance_json and asserting their returned structures contain
expected elements (check keys/ids rather than list positions); add a new case
for work_proof_submission_requirements(..., can_submit=True) and assert the
returned can_submit flag and related fields are correct; replace brittle
position-based checks like next_actions[0] with searches that assert the
presence and properties of an action by its id (e.g., find action where
action["id"] == "<expected_id>") so tests are resilient to ordering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1fa2f31e-8717-4488-bd95-faf0bc77a0b8

📥 Commits

Reviewing files that changed from the base of the PR and between 04153ee and b67edd5.

📒 Files selected for processing (3)
  • app/main.py
  • app/mcp_work_proof.py
  • tests/test_mcp_work_proof.py

Comment thread app/mcp_work_proof.py
Comment thread app/mcp_work_proof.py
Comment thread tests/test_mcp_work_proof.py Outdated
Comment thread tests/test_mcp_work_proof.py
Comment thread tests/test_mcp_work_proof.py Outdated
Comment thread tests/test_mcp_work_proof.py Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
tests/test_mcp_work_proof.py (1)

90-90: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid order-coupled assertion for next_actions.

This assertion is still brittle on list ordering; assert by action id presence (or use _action(...)) instead of [0].

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_mcp_work_proof.py` at line 90, The assertion is brittle because it
assumes ordering of guidance["submission_requirements"]["next_actions"]; change
the check in tests/test_mcp_work_proof.py to assert presence by action id
instead of indexing (e.g., verify that an element with id "confirm_award_slot"
exists in guidance["submission_requirements"]["next_actions"] or use the helper
_action(...) if available), so the test passes regardless of list order.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@tests/test_mcp_work_proof.py`:
- Line 90: The assertion is brittle because it assumes ordering of
guidance["submission_requirements"]["next_actions"]; change the check in
tests/test_mcp_work_proof.py to assert presence by action id instead of indexing
(e.g., verify that an element with id "confirm_award_slot" exists in
guidance["submission_requirements"]["next_actions"] or use the helper
_action(...) if available), so the test passes regardless of list order.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c0de5168-73bf-4c07-a92b-ababc319984a

📥 Commits

Reviewing files that changed from the base of the PR and between b67edd5 and f41fa4f.

📒 Files selected for processing (3)
  • app/mcp_work_proof.py
  • tests/test_api_mcp.py
  • tests/test_mcp_work_proof.py

Copy link
Copy Markdown
Contributor

@tolga-tom-nook tolga-tom-nook left a comment

Choose a reason for hiding this comment

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

Reviewed head f41fa4f for the #340 review bounty.

PASS: I verified the extraction keeps submit_work_proof behavior intact while moving the work-proof guidance boundary into app/mcp_work_proof.py. The PR also appears to have addressed the material schema/availability concerns from the bot review: generic and bounty-specific JSON guidance now share the nullable accounting/title keys, and open/full/closed/unknown submission availability is represented separately in work_proof_submission_requirements().

Evidence checked:

  • inspected app/mcp_work_proof.py, app/main.py, and tests/test_mcp_work_proof.py
  • confirmed app/main.py imports/calls the extracted guidance helpers without route behavior changes
  • confirmed full bounty/full/open/generic guidance paths have focused tests

Validation run locally:

  • uv run --extra dev python -m pytest tests/test_mcp_work_proof.py tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_bounty_specific_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_keeps_generic_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_bounty_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_generic_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_structures_terminal_bounty_availability tests/test_api_mcp.py::test_mcp_submit_work_proof_scopes_issue_number_by_repo tests/test_api_mcp.py::test_mcp_submit_work_proof_rejects_invalid_bounty_selectors tests/test_api_mcp.py::test_mcp_submit_work_proof_rejects_ambiguous_issue_number -q → 24 passed
  • uv run --extra dev python -m ruff check app/mcp_work_proof.py app/main.py tests/test_mcp_work_proof.py → passed
  • uv run --extra dev python -m mypy app → passed
  • uv run --extra dev python -m pytest -q → 359 passed

No requested changes from my review.

Copy link
Copy Markdown

@aiautotool aiautotool left a comment

Choose a reason for hiding this comment

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

Reviewed the MCP work-proof guidance extraction against origin/main. The text guidance path remains equivalent, the structured guidance keeps the bounty-specific fields while adding the generic fields covered by tests, and the new availability branch correctly distinguishes closed from open-but-full bounties.\n\nLocal evidence:\n- python -m pytest tests/test_mcp_work_proof.py plus the listed submit_work_proof MCP regression tests -q -> 24 passed\n- python -m ruff check app/mcp_work_proof.py app/main.py tests/test_mcp_work_proof.py tests/test_api_mcp.py -> pass\n- python -m ruff format --check app/mcp_work_proof.py app/main.py tests/test_mcp_work_proof.py tests/test_api_mcp.py -> pass\n- python -m mypy app/main.py app/mcp_work_proof.py -> pass\n- git diff --check origin/main...HEAD -> pass

Copy link
Copy Markdown
Contributor

@tolga-tom-nook tolga-tom-nook left a comment

Choose a reason for hiding this comment

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

Follow-up re-review after head changed from f41fa4f to 298fb82.

PASS: the new commit only stabilizes the work-proof guidance test assertion; I rechecked the focused guidance surface and did not find behavior drift.

Validation rerun locally on head 298fb82:

  • ./.venv/bin/python -m pytest tests/test_mcp_work_proof.py tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_bounty_specific_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_keeps_generic_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_bounty_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_generic_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_structures_terminal_bounty_availability tests/test_api_mcp.py::test_mcp_submit_work_proof_scopes_issue_number_by_repo tests/test_api_mcp.py::test_mcp_submit_work_proof_rejects_invalid_bounty_selectors tests/test_api_mcp.py::test_mcp_submit_work_proof_rejects_ambiguous_issue_number -q -> 24 passed
  • ./.venv/bin/python -m ruff check app/mcp_work_proof.py app/main.py tests/test_mcp_work_proof.py -> passed
  • ./.venv/bin/python -m mypy app -> passed
  • ./.venv/bin/python -m pytest -q -> 359 passed

No requested changes from my follow-up review.

@ramimbo ramimbo merged commit a1795ed into ramimbo:main May 26, 2026
2 checks passed
@ramimbo ramimbo added mrwk:accepted Maintainer accepted for payout mrwk:paid Ledger payment recorded labels May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mrwk:accepted Maintainer accepted for payout mrwk:paid Ledger payment recorded

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants