Skip to content

test(backend): cover the 503 claim path and shared-task provenance - #18719

Merged
aryanorastar merged 4 commits into
mainfrom
fix/shared-action-items-test-wiring
Oct 5, 2026
Merged

aryanorastar merged 4 commits into
mainfrom
fix/shared-action-items-test-wiring

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Reduced to the increment that survives main.

This PR originally rewired backend/tests/unit/test_shared_action_items.py, whose six tests from #17830 had never passed (TypeError: accept_shared_action_items() got an unexpected keyword argument 'payload'). While it was open, main landed cf2471852b doing the same rewrite against the same handler API, so that work is no longer needed here.

What main's version does not cover is now the whole of this diff — +29 lines, no deletions:

  • try_accept_task_share returning None → 503. The handler distinguishes Redis being unreachable (None → 503) from a token already used (False → 409). main covers only the 409, so the two could collapse to one status without a test noticing.
  • shared_from provenance on each copy. The success test already patches upsert_action_item_vector but never asserts on it or on the copied payload, so the sender linkage and the vector indexing were both unverified.

Verification

8 passed (7 on main, plus the new case).

Mutation-checked — each new assertion fails when the handler breaks:

mutation result
503 unavailable → 409 1 failed
shared_from.sender_uid set to a wrong value 1 failed
upsert_action_item_vector call removed 1 failed

Handler restored byte-identical afterwards; git diff on routers/action_items.py is empty. The diff is one test file.

Failure class

Failure-Class: FC-fixture-mock-signature-drift

The branch still carries the original fix: commit that wired the tests to the handler, so the class stays declared. cf2471852b on main now covers that wiring; what this PR adds on top is coverage only and changes no production behavior.

Product invariants affected

none — tests only.

…test

The six tests added by #17830 have never passed. They were written against an
API that does not exist, so every one of them errored before reaching its
assertion:

  TypeError: accept_shared_action_items() got an unexpected keyword argument
  'payload'

Three separate mismatches, all in the tests:

  test called                             handler actually uses
  --------------------------------------  -----------------------------------
  accept_shared_action_items(payload=...)  parameter is named `request`
  redis_db.verify_task_share_token         redis_db.get_task_share
  action_items_db.get_action_items_by_ids  action_items_db.get_action_item

The fixture also passed task_ids and sender_id to AcceptSharedTasksRequest,
which only declares token, and the expected return shape
({'status', 'accepted_count', 'created_items'}) did not match the handler's
{'created', 'count'}. The undo assertion expected
undo_accept_task_share(token, task_ids); the real signature is (token, uid).

The handler is correct -- it implements exactly what #17830 describes, routing
deleted to 404 and locked to 402 -- so the tests are rewritten against it
rather than the other way round. Every scenario #17830 set out to cover is
kept, plus two the original missed: an expired share token (404) and a Redis
claim that returns None rather than False (503).

Verified: 8 passed, was 6 failed. Mutation-checked in both directions -- the
suite fails when the 402 becomes a 403, when the deleted-items guard is
short-circuited, and when the token rollback is removed.

Co-Authored-By: Claude Opus 5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified end to end before reading the description — the premise holds:

  • At this PR's merge-base (c05ba8e69f), backend/tests/unit/test_shared_action_items.py fails 6 of 7 tests exactly as described: TypeError: accept_shared_action_items() got an unexpected keyword argument 'payload', plus the wrong Redis/DB surface (verify_task_share_token / get_action_items_by_ids) and the wrong expected response shape.
  • The rewritten file passes 8/8 locally. Every assertion matches the real handler in routers/action_items.py: the request= kwarg and AcceptSharedTasksRequest(token=...) (lines 1000, 1057), get_task_share → 404 (1060-1061), self-accept → 400 (1064-1065), deleted → 404 vs locked → 402 ordering (1073-1084), try_accept_task_share returning None → 503 / False → 409 (1087-1091), the {"created", "count"} shape with shared_from provenance (1101-1130), and the undo_accept_task_share(token, uid) rollback (1119-1120). The Redis-unreachable → 503 case and the provenance / vector-upsert assertions are net-new coverage for this file.

One overlap to be aware of: main has since landed cf2471852b ("test(backend): restore shared-task acceptance coverage after request migration"), which rewrites the same tests against the same handler API — so this branch now conflicts with main, and a straight rebase would drop most of this diff.

What survives a rebase is exactly the delta worth keeping: the unavailable-claim → 503 test, the shared_from / upsert_action_item_vector assertions in the success test, and the ordered per-id _items() helper. A rebase reduced to those additions (or a small follow-up PR) against current main would be welcome; otherwise the core wiring fix is already on main and this can close with full credit — this PR diagnosed the failure first.

Flagging the keep-increment-vs-close call for a maintainer, since the overlapping commit landed on main shortly after this PR opened.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added superseded Superseded by a newer change on main backend Backend Task (python) labels Sep 24, 2026
@aryanorastar
aryanorastar requested a lite review from Copilot September 25, 2026 03:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Address the required patch.object usage and strengthen UID and per-item provenance assertions.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Reworks shared action-item tests to match the current handler API and expands edge-case coverage.

Changes:

  • Corrects request, Redis, database, response, and rollback expectations.
  • Adds expired-token and unavailable-claim coverage.
  • Verifies provenance, wake notifications, and rollback behavior.
File Summary
backend/​tests/​unit/​test_shared_action_items.py Updates and expands shared action-item handler tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ms-test-wiring

# Conflicts:
#	backend/tests/unit/test_shared_action_items.py
@aryanorastar aryanorastar removed the superseded Superseded by a newer change on main label Sep 25, 2026
@aryanorastar aryanorastar changed the title fix(backend): wire the shared-action-items tests to the handler they test test(backend): cover the 503 claim path and shared-task provenance Sep 25, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Taking the keep-the-increment path — retitled and reduced to +29 lines, no deletions on c0b44a6c36.

You were right that cf2471852b lands the same wiring fix, so that part is gone from this diff. What remains is what your review identified as worth keeping, minus one item:

  • try_accept_task_share returning None → 503. main covers the False → 409 path only, so the unreachable-Redis and already-used-token cases could collapse to one status unnoticed.
  • shared_from provenance and the vector upsert. main's success test patches upsert_action_item_vector but never asserts on it or on the copied payload, so the sender linkage and the indexing were both unverified.

I dropped the _items() helper rather than keeping it. main's dict-plus-lambda side_effect is equivalent and already the idiom in that file, so importing my ordered-positional version would have been churn for no behavioral gain — building on main's base kept this to an addition with zero deletions.

Mutation-checked each new assertion rather than trusting that it runs:

mutation result
503 unavailable → 409 1 failed
shared_from.sender_uid set wrong 1 failed
upsert_action_item_vector call removed 1 failed

8 passed on the merged head; routers/action_items.py restored byte-identical (empty git diff). Failure-class declaration dropped to none — this is coverage only now, and the FC-fixture-mock-signature-drift case belongs to cf2471852b.

…the first

The success test inspected only create_action_item.call_args_list[0], so a
regression in the second copy's shared_from would have passed while the comment
claimed each copy was covered. Now every call is checked: recipient uid,
sender_uid, the copy's own original_task_id, the share token, and completed,
plus the per-copy upsert_action_item_vector arguments.

Mutation-checked the gap that motivated this: corrupting original_task_id on
the last copy only, and passing a wrong id to upsert_action_item_vector, each
turn the suite red. Neither was caught before.

Co-Authored-By: Claude Opus 5 <[email protected]>

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Trusted backend contributor; test-only coverage PR (no prod code change), CI green. Approve-only per confidence gate (not a bug fix).

@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up verification on the reduced head 45ab5f8 — the keep-the-increment rework landed exactly as discussed, and everything checks out.

backend/tests/unit/test_shared_action_items.py is now a pure addition (+40/-0) on top of cf2471852b's rewrite: test_accept_shared_tasks_unavailable_claim_returns_503 pins the None → 503 branch (routers/action_items.py:1088-1089) that main leaves uncovered, and the success test now asserts the shared_from provenance (token/sender_uid/original_task_id per copy) plus both upsert_action_item_vector calls that were previously patched-but-unasserted.

Ran the file in a worktree: 8 passed in 2.00s. I also reproduced the mutation table independently — flipping the handler's 503 to 409 and corrupting sender_uid each fail exactly one test, so the new assertions genuinely bite.

Dropping the _items() helper in favor of main's dict-plus-lambda side_effect was the right call: same coverage, zero churn. The 503 test also asserts no partial side effects (create_action_item and _wake_task_changes never called) — the right shape for an availability failure, since a client retry must be safe.

Cleanly mergeable against main, checks green. Thanks for the careful reduction — this is exactly the delta worth keeping, and the mutation table matched my results line for line.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

…ms-test-wiring

# Conflicts:
#	backend/tests/unit/test_shared_action_items.py
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Conflict resolved on 52917063f6 — merge of current main. Still a pure addition: 1 file, +37 / −0.

main's #19436 moved accept_shared_action_items from one create_action_item call per copy to a single create_action_items_batch(uid, items). This PR's provenance assertions read create_action_item.call_args_list, which is now never called, so they were rewritten against the batch payload rather than dropped.

The intent is unchanged: every copy — not just the first — goes to the recipient in that one batch, carries sender_uid, its own original_task_id and the share token, starts completed = False, and gets indexed. I checked this still adds coverage rather than duplicating #19436: its test_ineligible_source_does_not_shift_copy_metadata pins original_task_id for a single copy, not sender, token or the multi-copy ordering.

Mutation-checked against the new batch handler rather than trusting that the tests run:

mutation result
shared_from.sender_uid corrupted 1 failed
every copy's original_task_id pinned to the first 2 failed

Handler restored byte-identical. test_shared_action_items.py: 14 passed.

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified on the current head 5291706 after the main merge — the rework against the batch write is exactly right, and this remains a clean, test-only increment (+37/−0, one file).

  • test_accept_shared_tasks_unavailable_claim_returns_503 pins the None → 503 branch at routers/action_items.py:1090-1091 that main leaves uncovered, and confirms no write and no wake fire on that path — so unavailable-Redis and already-used-token can no longer collapse into one status unnoticed.
  • The rewritten provenance assertions are stronger than what they replaced: they read the create_action_items_batch payload directly and check sender_uid, each copy's own original_task_id, the share token, and completed=False per copy, plus both upsert_action_item_vector calls that were previously patched-but-unasserted.
  • 14/14 pass locally against this head, and I mutation-checked both new assertion groups (503 → 409 at line 1091 fails the new test; corrupting original_task_id fails the success test), so the guards are live rather than decorative.

Note for merge: the earlier approval was on 45ab5f8, two heads back; since this head only re-resolves the main merge and reworks test assertions (no production changes), re-approval should be trivial. Thanks for keeping the increment intact through two rounds of main moving underneath it.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Test-coverage-only addition (no production code changed) on top of the real fix already merged to main as cf24718; covers two previously-untested branches (503 path, shared_from provenance). Approve-only — not itself a bug fix, so doesn't qualify for auto-merge, but low-risk and CI green.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Test-only addition covering the 503 path and shared-task provenance; approve-only per confidence gate, CI green.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Test-only addition (covers 503 claim path + provenance not covered by the sibling merge) — not a bug fix itself, approve-only. CI green, trusted backend author.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-affirming: test-only addition (+37/-0) covering 503-vs-409 and shared_from provenance branches. No production code -> approve-only.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@kodjima33 this is approved and green — needs a merge when you have a moment.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

test(backend): pure test-coverage addition (503 claim path), no production diff; approve-only

@aryanorastar
aryanorastar merged commit bd7f6b6 into main Oct 5, 2026
59 checks passed
@aryanorastar
aryanorastar deleted the fix/shared-action-items-test-wiring branch October 5, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants