|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Usage: bash apps/server/scripts/seed-scheduled-task-worktree-fixture.sh [new-directory] |
| 5 | +# Only creates a local Git fixture; register its project in an isolated T3 home. |
| 6 | +fixture_root="${1:-$(mktemp -d /tmp/t3-scheduled-worktree.XXXXXX)}" |
| 7 | +mkdir -p "$fixture_root" |
| 8 | +fixture_root="$(cd "$fixture_root" && pwd -P)" |
| 9 | +if [[ -e "$fixture_root/origin.git" || -e "$fixture_root/project" ]]; then |
| 10 | + printf 'Refusing to overwrite an existing fixture: %s\n' "$fixture_root" >&2 |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +git init --quiet --bare --object-format=sha1 --initial-branch=master "$fixture_root/origin.git" |
| 15 | + |
| 16 | +# The fixture data is an empty tree with a fixed identity, timestamp and message. |
| 17 | +# Reproduce the runtime evidence commit without depending on the caller's config. |
| 18 | +fixture_tree="$(git --git-dir="$fixture_root/origin.git" hash-object -w -t tree --stdin </dev/null)" |
| 19 | +fixture_commit="$( |
| 20 | + GIT_AUTHOR_NAME=Triage [email protected] \ |
| 21 | + GIT_COMMITTER_NAME=Triage [email protected] \ |
| 22 | + GIT_AUTHOR_DATE='2026-10-21T09:52:47+00:00' \ |
| 23 | + GIT_COMMITTER_DATE='2026-10-21T09:52:47+00:00' \ |
| 24 | + git --git-dir="$fixture_root/origin.git" -c commit.gpgsign=false commit-tree "$fixture_tree" -m fixture |
| 25 | +)" |
| 26 | +[[ "$fixture_commit" == 5cade2a196ef3c8da4151a9e8ced1c1b5a04c336 ]] |
| 27 | +git --git-dir="$fixture_root/origin.git" update-ref refs/heads/master "$fixture_commit" |
| 28 | +git clone --quiet --no-local "$fixture_root/origin.git" "$fixture_root/project" |
| 29 | +git -C "$fixture_root/project" symbolic-ref --delete refs/remotes/origin/HEAD |
| 30 | + |
| 31 | +git -C "$fixture_root/project" ls-remote --symref origin HEAD |
| 32 | +git -C "$fixture_root/project" show-ref |
| 33 | +if git -C "$fixture_root/project" show-ref --verify --quiet refs/remotes/origin/HEAD; then |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +printf '\nFixture project: %s/project\nExpected child HEAD: %s\n' "$fixture_root" "$fixture_commit" |
| 38 | +cat <<'SEQUENCE' |
| 39 | +
|
| 40 | +Actual isolated-server MCP sequence (use an agent thread in this fixture project): |
| 41 | +1. schedule_task({title:"master-fixture", prompt:"Reply OK only. Do not edit files, run commands, or commit.", schedule:{type:"interval",everyMs:3600000}, bindToCurrentThread:false}) |
| 42 | +2. Record returned scheduledTaskId. Read isolated SQLite in read-only mode: |
| 43 | + scheduled_tasks.thread_id must be null; workspace_strategy_json must be |
| 44 | + {"type":"worktree","baseRef":"refs/remotes/origin/master","startFromOrigin":true}. |
| 45 | +3. run_scheduled_task_now({taskId:<scheduledTaskId>}); record returned threadId. |
| 46 | +4. Await the child's completed provider run. Its persisted userMessageId must |
| 47 | + reference the scheduledTaskId; its events must leave preparing and reach |
| 48 | + completed. Check the durable thread's worktreePath/branch against actual |
| 49 | + git worktree list --porcelain, symbolic-ref HEAD and rev-parse HEAD there. |
| 50 | + Child HEAD and project refs/remotes/origin/master must equal the SHA above. |
| 51 | +5. delete_scheduled_task({scheduledTaskId:<scheduledTaskId>}); then |
| 52 | + list_scheduled_tasks({}) and a read-only scheduled_tasks query verify cleanup. |
| 53 | +
|
| 54 | +For explicit unbind, create a separate task with bindToCurrentThread:true; |
| 55 | +record its nonnull thread_id and root strategy, verify origin/HEAD is absent, |
| 56 | +then update_scheduled_task({scheduledTaskId:<id>,bindToCurrentThread:false}). |
| 57 | +Repeat steps 2-5; the returned fresh thread must differ from the bound thread. |
| 58 | +Scheduler lastRunStatus=succeeded alone does not prove workspace preparation. |
| 59 | +SEQUENCE |
0 commit comments