This commit is contained in:
rob
2026-12-02 15:44:24 +00:00
parent cbcc9fa4b5
commit 8d01d02cc0
17 changed files with 125 additions and 35 deletions
+17 -3
View File
@@ -2,7 +2,7 @@
This package is copied into generated applications. `scripts/testtask.sh` starts,
checks, or stops a **manual development environment**. `scripts/testrunner.sh`
runs configured automated suites. Both use `scripts/target.py` to select a Git
runs configured automated suites. Both use `.bortstack/testing/target.py` to select a Git
worktree; neither needs Forge at runtime. This package does not migrate existing
Roborto application launchers. Forge's earlier `distribution/testtask` is a
separate existing-project automated runner and remains unchanged for its
@@ -17,12 +17,26 @@ The application owns `.bortstack/testing.json` (see
`config/testing.example.json`). A no-argument command uses the current worktree
and its checked-out branch. A branch name uses its existing worktree; a task ID
uses `docs/TASKS.md` headings and `Branch/worktree: \`name\`` references or a
matching branch slug. A branch needs no task record. Missing, ambiguous, and
detached targets fail without Git mutation.
matching branch slug. A branch needs no task record. Task headings accept a colon or dash separator, and three-digit targets such
as `134` also look up `TASK-134`. Missing or ambiguous targets fail without
Git mutation.
Generated Flask/React projects expose only `testtask.sh`, `testrunner.sh`
and `create-chatgpt-snapshot.sh` under `scripts/`. The testing implementation
and template-specific hooks live under `.bortstack/testing/`.
## Manual environments
`./scripts/testtask.sh [target] [--start|--status|--stop]` starts by default.
To use prepared acceptance snapshots for manual task IDs, set
`manual.acceptance_snapshots` in the launching checkout's testing
configuration to a directory such as `.test-worktrees`. A task target then
requires a registered detached Git worktree named after the lowercased task ID,
such as `.test-worktrees/task-134`. The command runs against the existing
snapshot files and its testing configuration. Prepare and verify the snapshot
before launch. Missing snapshots fail explicitly. Branch targets and automated
suites continue to resolve their own worktrees.
The current adapter supports Docker Compose. It uses a unique project name
derived from the selected worktree and branch, checks declared host ports,
starts only that project, verifies configured loopback readiness URLs, and
@@ -3,7 +3,7 @@ import re
import subprocess
from pathlib import Path
HEADING = re.compile(r"^## ([A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+)\s+[—-]", re.M)
HEADING = re.compile(r"^## ([A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+)(?::|[ \t]+[—-])", re.M)
LABEL = re.compile(r"(?:Task )?[Bb]ranch(?:/worktree)?:\s*`([^`]+)`")
@@ -38,7 +38,19 @@ def associated(task_id, section, branches):
return found
def resolve(script_path, identifier=None):
def acceptance_snapshot(root, directory, task_id):
directory = (root / directory).resolve()
selected = (directory / task_id.lower()).resolve()
if not directory.is_relative_to(root) or not selected.is_relative_to(directory):
raise TargetError("acceptance snapshot path leaves its configured location")
for block in git(root, "worktree", "list", "--porcelain").split("\n\n"):
lines = block.splitlines()
if f"worktree {selected}" in lines and "detached" in lines and selected.is_dir():
return selected
raise TargetError(f"task {task_id} requires a registered detached acceptance snapshot at {selected}")
def resolve(script_path, identifier=None, snapshot_directory=None):
origin = Path.cwd() if identifier is None else script_path.parent
root = Path(git(origin, "rev-parse", "--show-toplevel")).resolve()
branches = set(git(root, "for-each-ref", "--format=%(refname:short)", "refs/heads").splitlines())
@@ -50,14 +62,19 @@ def resolve(script_path, identifier=None):
raise TargetError("current worktree has detached HEAD; specify a branch or task ID")
selected = Path(git(origin, "rev-parse", "--show-toplevel")).resolve()
else:
task_match = identifier in records
task_id = identifier
if re.fullmatch(r"[0-9]{3}", identifier):
task_id = f"TASK-{identifier}"
task_match = task_id in records
branch_match = identifier in branches
if task_match and branch_match:
raise TargetError(f"ambiguous identifier {identifier}: both task ID and branch; disambiguate in project records")
if task_match:
if len(records[identifier]) != 1:
if len(records[task_id]) != 1:
raise TargetError(f"ambiguous task ID {identifier}: duplicate records")
matches = associated(identifier, records[identifier][0], branches)
if snapshot_directory is not None:
return root, task_id, acceptance_snapshot(root, snapshot_directory, task_id)
matches = associated(task_id, records[task_id][0], branches)
if len(matches) != 1:
raise TargetError(f"task {identifier} maps to {len(matches)} branches: {', '.join(sorted(matches))}")
branch = next(iter(matches))
@@ -323,7 +323,16 @@ def main(argv):
parser.add_argument(f"--{name}", action="store_true")
args = parser.parse_args(argv)
try:
root, branch, tree = resolve(Path(__file__).resolve(), args.target)
script = Path(__file__).resolve()
snapshot_directory = None
if mode == "manual" and args.target:
project = script.parents[2]
origin_config = project / ".bortstack/testing.json"
if origin_config.is_file():
manual_config = config_for(project).get("manual")
if isinstance(manual_config, dict) and "acceptance_snapshots" in manual_config:
snapshot_directory = local_path(project, manual_config["acceptance_snapshots"])
root, branch, tree = resolve(script, args.target, snapshot_directory)
print(f"repository: {root}\nbranch: {branch}\nworktree: {tree}", flush=True)
config = config_for(tree)
return manual(mode, tree, branch, config, args) if mode == "manual" else automated(tree, config, args)
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
set -eu
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
exec python3 "$script_dir/toolkit.py" automated "$@"
exec python3 "$script_dir/../.bortstack/testing/toolkit.py" automated "$@"
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
set -eu
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
exec python3 "$script_dir/toolkit.py" manual "$@"
exec python3 "$script_dir/../.bortstack/testing/toolkit.py" manual "$@"