Commit a0a5a63
chore: align with katana-openapi-client safety + MCP fixes (#60)
* chore: add pre-push hook blocking direct pushes to main from non-main branches
When a feature branch is created via ``git checkout -b <name> origin/main``,
git sets the new local branch's upstream to ``origin/main``. A subsequent
``git push -u origin <name>`` then resolves to the tracked upstream and pushes
straight to main — bypassing PR review entirely. Our sister repo
(katana-openapi-client commit 30f3fd86) hit exactly this in production: a
non-PR push to main triggered semantic-release and published an unintended
PyPI build before the pipeline could be cancelled.
Statuspro has no equivalent guard. Adds the same mechanical line of defense
katana ported in #434:
- ``scripts/pre-push-guard.sh`` — pre-commit-compatible pre-push hook that
refuses pushes where ``remote_ref == refs/heads/main`` and ``local_ref !=
refs/heads/main``. Suggests the safe form (``git push -u origin
HEAD:refs/heads/<branch>``) in the rejection message.
- ``.pre-commit-config.yaml`` — adds ``default_install_hook_types:
[pre-commit, pre-push]`` and registers ``block-push-to-main`` in the
``pre-push`` stage. Existing ``pre-commit install`` invocations now
install both hook types.
Existing collaborators must re-run ``uv run pre-commit install`` once for
the pre-push hook to take effect; the README quick-start handles fresh
clones automatically.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(harness): adopt /open-pr push-refspec safety + worktree note
Pairs with the pre-push guard added in the previous commit. Documents the
push-refspec trap in two places that don't read CLAUDE.md mid-flow:
- ``.claude/skills/open-pr/SKILL.md`` CRITICAL block + Phase 5 — mandates
``git push -u origin HEAD:refs/heads/<branch>`` over the bare-branch form.
The bare form resolves to the local branch's tracked upstream; if a
branch was created via ``git checkout -b <name> origin/main`` the
upstream is ``origin/main`` and the bare push targets main.
- ``CLAUDE.md`` Known Pitfalls — same explanation, plus a worktree note
pointing out that pre-commit hooks (including the new pre-push guard)
aren't shared across worktrees and require ``pre-commit install`` per
worktree.
Lifted from katana-openapi-client's harness retro (PR #441) where the same
trap bit twice during PR development.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(mcp): mock time.perf_counter in observability timing tests
Both ``test_observe_service_timing_accuracy`` and
``test_observe_tool_timing_accuracy`` were measuring real time after
``await asyncio.sleep(...)`` and asserting the duration fell within
loose-lower-bound / tight-upper-bound brackets:
- tool variant: ``50 <= duration_ms < 200`` after a 100ms sleep
- service variant: ``50 <= duration_ms < 500`` after a 50ms sleep
The tool variant's ``< 200`` upper bound is the same flake pattern that
broke katana-openapi-client CI on Python 3.14 (235.7ms < 100ms in their
analogous service test, fixed in their #450 sweep). asyncio scheduler
+ GIL contention under CI runner load routinely pushes the measured
value well above tight upper bounds.
Both tests now mock ``time.perf_counter`` (the module-level binding the
decorator imports as ``time.perf_counter`` in ``statuspro_mcp.logging``)
with ``side_effect=[start, end]``. The computed duration is exact and
deterministic — no real sleep, no scheduler variance, exact-equality
assertion. The tests' name claims "timing accuracy" and now actually
tests that: the decorator computes ``(end - start) * 1000`` correctly.
Real asyncio scheduling latency was never the right thing to assert.
Test runtime drops from ~150ms (sleep-bound) to ~1ms (deterministic).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(mcp): use ShowToast for Cancel buttons (drop SendMessage round-trip)
Four Cancel buttons in Prefab preview UIs were sending fake user messages
back through the LLM ("Cancel the status change" / "Cancel the comment" /
"Cancel the due date change" / "Cancel the bulk update"). The model would
acknowledge in chat for what is functionally a "do nothing" action,
cluttering the conversation with a synthetic user message + LLM response.
Replaced with ``ShowToast`` (client-side only, no server trip per the
prefab_ui actions docstring): the user gets visible "Cancelled" feedback
in the iframe overlay, no chat message is appended, no LLM round-trip
happens, no tool is invoked.
Sites:
- ``build_status_change_preview_ui`` → "Status change cancelled"
- ``build_comment_preview_ui`` → "Comment cancelled"
- ``build_due_date_change_preview_ui`` → "Due date change cancelled"
- ``build_bulk_status_change_preview_ui`` → "Bulk update cancelled"
The two remaining ``SendMessage`` sites in ``prefab_ui.py`` (lines 232,
266) are intentional action triggers ("Add a comment to order...", etc.)
that prompt the LLM to follow up — those stay as is.
Ported from katana-openapi-client #440.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(mcp): coerce LLM-mistyped list inputs back into Python lists
LLMs occasionally serialize list-typed tool arguments as a single string
instead of a JSON array. Two shapes are observed in the wild:
1. CSV: ``order_ids='20486,20487,20488'``
2. JSON-stringified: ``order_ids='[20486, 20487, 20488]'``
Both make pydantic raise ``Input should be a valid list [type=list_type,
input_type=str]`` and the tool call aborts. The recovery is mechanical
and lossless — split on commas (or parse as JSON), strip whitespace,
hand pydantic a real list. So we do it.
Adds:
- ``statuspro_mcp/tools/list_coercion.py`` — a single ``coerce_str_list_input``
BeforeValidator that handles both shapes. Lists pass through unchanged;
non-string non-list inputs fall through to pydantic's normal type error
so genuinely malformed input still surfaces loudly. Six type aliases
(``CoercedStrList`` / ``CoercedIntList`` / ``CoercedStrIntList`` and
their ``Opt`` variants) collapse the per-field
``Annotated[list[X] | None, BeforeValidator(coerce_str_list_input)]``
boilerplate at call sites.
- 19 unit tests covering passthrough, CSV, JSON-array string, whitespace,
empty inputs, non-string inputs, mixed-type lists, and the
``min_length`` interaction.
Applied to seven LLM-facing list parameters in ``orders.py``:
- ``list_orders``: tags, tags_any, financial_status, fulfillment_status
- ``get_orders_batch``: order_ids
- ``lookup_orders_batch``: order_numbers
- ``bulk_update_order_status``: order_ids
Internal/response-side list fields don't need it — pydantic-on-pydantic
round-trips already use real lists.
Ported from katana-openapi-client #428 (mechanical port of the alias-based
collapse already merged there).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(mcp): tighten coerce_str_list_input per /simplify pass
Two micro-simplifications surfaced by a /simplify review of the freshly-
landed list_coercion module:
- ``json.JSONDecodeError`` is a subclass of ``ValueError`` (verified at
runtime). Drop the redundant tuple in the except clause; catch
``ValueError`` alone.
- The CSV fallback comprehension called ``item.strip()`` twice per item
(once in the filter, once in the projection). Use a walrus assignment
so the strip happens once: ``[stripped for item in s.split(",") if
(stripped := item.strip())]``.
Behavior identical; all 19 unit tests still pass. Diverges from the
katana-openapi-client upstream by these two lines — re-sync if/when
katana picks up the same cleanup.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 983beef commit a0a5a63
10 files changed
Lines changed: 422 additions & 35 deletions
File tree
- .claude/skills/open-pr
- scripts
- statuspro_mcp_server
- src/statuspro_mcp
- resources
- tools
- tests
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
143 | | - | |
| 144 | + | |
| 145 | + | |
144 | 146 | | |
145 | 147 | | |
146 | | - | |
| 148 | + | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
| |||
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
| |||
92 | 97 | | |
93 | 98 | | |
94 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
95 | 107 | | |
96 | 108 | | |
97 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
50 | 64 | | |
51 | 65 | | |
52 | 66 | | |
| |||
Lines changed: 87 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
| |||
377 | 382 | | |
378 | 383 | | |
379 | 384 | | |
380 | | - | |
| 385 | + | |
381 | 386 | | |
382 | 387 | | |
383 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
384 | 397 | | |
385 | | - | |
386 | | - | |
387 | 398 | | |
388 | 399 | | |
389 | 400 | | |
| |||
584 | 595 | | |
585 | 596 | | |
586 | 597 | | |
587 | | - | |
| 598 | + | |
588 | 599 | | |
589 | 600 | | |
590 | 601 | | |
| |||
635 | 646 | | |
636 | 647 | | |
637 | 648 | | |
638 | | - | |
| 649 | + | |
639 | 650 | | |
640 | 651 | | |
641 | 652 | | |
| |||
1029 | 1040 | | |
1030 | 1041 | | |
1031 | 1042 | | |
1032 | | - | |
| 1043 | + | |
1033 | 1044 | | |
1034 | 1045 | | |
1035 | 1046 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
380 | | - | |
| 381 | + | |
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
| |||
436 | 437 | | |
437 | 438 | | |
438 | 439 | | |
439 | | - | |
| 440 | + | |
440 | 441 | | |
441 | 442 | | |
442 | 443 | | |
| |||
491 | 492 | | |
492 | 493 | | |
493 | 494 | | |
494 | | - | |
| 495 | + | |
495 | 496 | | |
496 | 497 | | |
497 | 498 | | |
| |||
566 | 567 | | |
567 | 568 | | |
568 | 569 | | |
569 | | - | |
| 570 | + | |
570 | 571 | | |
571 | 572 | | |
572 | 573 | | |
| |||
0 commit comments