feat: add mm-worktree-task — launch MiniMax worktree implementation sub-sessions

Wraps ask-minimax-run to run a MiniMax M3 implementation sub-session in an
isolated git worktree, with the prompt assembled from a planner work item
(cp_cli item + documents + parent/siblings). Supports --dryrun, --collect,
and --upload, per the pattern used for the 2026-09-10 seven-worktree batch
(see agent-runtimes memory/gotchas-minimax.md).

Claude-Session: https://claude.ai/code/session_015nXvGNNNixJPFwZKZHNyha
This commit is contained in:
Paul O'Reilly
2026-09-10 22:57:55 +12:00
parent aa8883dbc5
commit 9a6d7135c5
8 changed files with 640 additions and 0 deletions

View File

@@ -0,0 +1 @@
{"documents": [{"name": "notes.md", "updated_at": "2026-09-01T00:00:00Z"}, {"name": "old-notes.md", "updated_at": "2020-01-01T00:00:00Z"}]}

View File

@@ -0,0 +1 @@
Some supporting notes.

View File

@@ -0,0 +1 @@
Stale notes, should not be bundled under recent.

View File

@@ -0,0 +1,11 @@
{
"id": "1f17f61e-317e-4e10-bcd6-bee6a3264379",
"title": "Wire up CI merge gate",
"label": "task",
"state": "open",
"flow_state": "ready",
"body": "Make the CI merge gate real: run tests on push to main, not just PRs.",
"tags": ["ci"],
"parent_id": null,
"related_items": []
}

141
tests/test-mm-worktree-task.sh Executable file
View File

@@ -0,0 +1,141 @@
#!/usr/bin/env bash
# test-mm-worktree-task.sh — Verify mm-worktree-task dryrun behaviour against the spec.
#
# Strategy: all assertions use --dryrun (-n) with fake item/docs fixtures, so
# no cp_cli calls, worktrees, branches, or launches happen.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
SCRIPT="$REPO_ROOT/scripts/mm-worktree-task"
FIXTURE_ITEM="$REPO_ROOT/tests/fixtures/mm-worktree-task-item.json"
FIXTURE_DOCS_DIR="$REPO_ROOT/tests/fixtures/mm-worktree-task-docs"
TEST_UUID="1f17f61e-317e-4e10-bcd6-bee6a3264379"
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
PASS=0
FAIL=0
assert_contains() {
local label=$1 needle=$2 haystack=$3
if [[ "$haystack" == *"$needle"* ]]; then
printf " ${GREEN}PASS${NC} %s\n" "$label"
PASS=$((PASS + 1))
else
printf " ${RED}FAIL${NC} %s\n" "$label"
printf " expected to contain: %s\n" "$needle"
FAIL=$((FAIL + 1))
fi
}
assert_not_contains() {
local label=$1 needle=$2 haystack=$3
if [[ "$haystack" != *"$needle"* ]]; then
printf " ${GREEN}PASS${NC} %s\n" "$label"
PASS=$((PASS + 1))
else
printf " ${RED}FAIL${NC} %s\n" "$label"
printf " expected NOT to contain: %s\n" "$needle"
FAIL=$((FAIL + 1))
fi
}
assert_eq() {
local label=$1 expected=$2 actual=$3
if [[ "$expected" == "$actual" ]]; then
printf " ${GREEN}PASS${NC} %s\n" "$label"
PASS=$((PASS + 1))
else
printf " ${RED}FAIL${NC} %s\n" "$label"
printf " expected: %s\n actual: %s\n" "$expected" "$actual"
FAIL=$((FAIL + 1))
fi
}
echo "== mm-worktree-task: --help =="
HELP_OUT="$("$SCRIPT" --help 2>&1)"
HELP_RC=$?
assert_eq "help exits 0" "0" "$HELP_RC"
assert_contains "help mentions usage" "Usage: mm-worktree-task" "$HELP_OUT"
assert_contains "help mentions --dryrun" "--dryrun" "$HELP_OUT"
echo
echo "== mm-worktree-task: missing uuid errors =="
MISSING_OUT="$("$SCRIPT" --dryrun 2>&1)"
MISSING_RC=$?
assert_eq "missing uuid exits 1" "1" "$MISSING_RC"
assert_contains "missing uuid error message" "item-uuid is required" "$MISSING_OUT"
echo
echo "== mm-worktree-task: --dryrun with fixture item =="
export MM_WORKTREE_TASK_FAKE_ITEM="$FIXTURE_ITEM"
export MM_WORKTREE_TASK_FAKE_DOCS_DIR="$FIXTURE_DOCS_DIR"
DRY_OUT="$("$SCRIPT" "$TEST_UUID" --slug testslug --dryrun 2>&1)"
DRY_RC=$?
assert_eq "dryrun exits 0" "0" "$DRY_RC"
assert_contains "dryrun shows the item title" "Wire up CI merge gate" "$DRY_OUT"
assert_contains "dryrun shows worktree path" ".claude/worktrees/mm-testslug" "$DRY_OUT"
assert_contains "dryrun shows branch name" "mm/testslug" "$DRY_OUT"
assert_contains "dryrun shows bundle path" "testslug-bundle.md" "$DRY_OUT"
assert_contains "dryrun shows the ask-minimax-run command" "ask-minimax-run" "$DRY_OUT"
assert_contains "dryrun command uses MiniMax-M3[1m] model" 'MiniMax-M3[1m]' "$DRY_OUT"
assert_contains "dryrun bundles recent doc notes.md" "notes.md (bundled below)" "$DRY_OUT"
assert_contains "dryrun lists old doc as available only" "old-notes.md (available only)" "$DRY_OUT"
assert_not_contains "dryrun does not bundle stale doc body" "Stale notes, should not be bundled" "$DRY_OUT"
assert_contains "dryrun mentions timeout default" "1800" "$DRY_OUT"
# No side effects
WORKTREE_PATH="$REPO_ROOT/.claude/worktrees/mm-testslug"
if [[ -d "$WORKTREE_PATH" ]]; then
printf " ${RED}FAIL${NC} dryrun did not create a worktree\n"
FAIL=$((FAIL + 1))
else
printf " ${GREEN}PASS${NC} dryrun did not create a worktree\n"
PASS=$((PASS + 1))
fi
echo
echo "== mm-worktree-task: --docs all bundles everything =="
DRY_ALL_OUT="$("$SCRIPT" "$TEST_UUID" --slug testslug2 --docs all --dryrun 2>&1)"
assert_contains "docs=all bundles old-notes.md" "old-notes.md (bundled below)" "$DRY_ALL_OUT"
echo
echo "== mm-worktree-task: --docs none bundles nothing =="
DRY_NONE_OUT="$("$SCRIPT" "$TEST_UUID" --slug testslug3 --docs none --dryrun 2>&1)"
assert_contains "docs=none has no documents section entries" "(none)" "$DRY_NONE_OUT"
echo
echo "== mm-worktree-task: --focus is appended to the prompt =="
DRY_FOCUS_OUT="$("$SCRIPT" "$TEST_UUID" --slug testslug4 --focus "Only touch CI files" --dryrun 2>&1)"
assert_contains "focus line present" "Only touch CI files" "$DRY_FOCUS_OUT"
echo
echo "== mm-worktree-task: --collect with no worktree errors =="
unset MM_WORKTREE_TASK_FAKE_ITEM
unset MM_WORKTREE_TASK_FAKE_DOCS_DIR
COLLECT_OUT="$("$SCRIPT" "$TEST_UUID" --slug does-not-exist-slug --collect 2>&1)"
COLLECT_RC=$?
assert_eq "collect with missing worktree exits 1" "1" "$COLLECT_RC"
assert_contains "collect error message" "no worktree found" "$COLLECT_OUT"
echo
echo "== mm-worktree-task: --upload without --collect errors =="
UPLOAD_OUT="$("$SCRIPT" "$TEST_UUID" --slug testslug --upload --dryrun 2>&1)"
UPLOAD_RC=$?
assert_eq "upload without collect exits 1" "1" "$UPLOAD_RC"
assert_contains "upload error message" "--upload requires --collect" "$UPLOAD_OUT"
echo
echo "=================================="
echo " PASS: $PASS FAIL: $FAIL"
echo "=================================="
if [[ $FAIL -gt 0 ]]; then
exit 1
fi
exit 0