Complete TASK-016 dark theme and persistent testtask candidate

This commit is contained in:
rob
2026-11-11 13:17:24 +00:00
parent 922d1f6bd7
commit 0cf051560b
17 changed files with 618 additions and 102 deletions
+147
View File
@@ -0,0 +1,147 @@
"""Exercise routing with a stub runner; never start a testtask session."""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
SCRIPTS = Path(__file__).resolve().parent
class HomeRoutingTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory(prefix='testtask-routing-')
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name) / 'project home'
self.root.mkdir()
self.git('init', '-b', 'codex')
(self.root / 'scripts').mkdir()
(self.root / '.roborto').mkdir()
(self.root / '.roborto/testtask.conf').write_text('# fixture only\n')
for name in ['testtask.sh', 'testtask_source.py', 'testtask-node.sh']:
shutil.copy2(SCRIPTS / name, self.root / 'scripts' / name)
self.git('add', '.')
self.git('-c', 'user.name=Routing Test', '-c', 'user.email=routing@example.invalid',
'commit', '-m', 'Fixture baseline')
self.bin = Path(self.temp.name) / 'bin'
self.bin.mkdir()
runner = self.bin / 'roborto-testtask'
runner.write_text('#!/bin/sh\nprintf "STUB_SOURCE=%s\\nSTUB_TASK=%s\\n" "$PWD" "$1"\n')
runner.chmod(0o755)
node = self.bin / 'node'
node.write_text('#!/bin/sh\nexit 0\n')
node.chmod(0o755)
self.env = {**os.environ, 'PATH': f'{self.bin}:/usr/bin:/bin',
'NVM_DIR': str(self.bin / 'no-nvm')}
def git(self, *args):
return subprocess.run(['git', '-C', str(self.root), *args], check=True,
text=True, capture_output=True)
def worktree(self, task, suffix):
path = Path(self.temp.name) / f'task {task} {suffix}'
self.git('worktree', 'add', '-b', f'task/{task}-{suffix}', str(path))
return path
def run_wrapper(self, *args, cwd=None):
return subprocess.run(['bash', str(self.root / 'scripts/testtask.sh'), *args],
cwd=cwd or self.root, env=self.env, text=True, capture_output=True)
def test_home_selects_task_and_preserves_dirty_untracked_source(self):
target = self.worktree('016', 'dark')
dirty = target / 'uncommitted.txt'
dirty.write_text('candidate data\n')
result = self.run_wrapper('016')
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn(f'STUB_SOURCE={target}', result.stdout)
self.assertIn('STUB_TASK=016', result.stdout)
self.assertEqual(dirty.read_text(), 'candidate data\n')
self.assertEqual(self.git('branch', '--show-current').stdout.strip(), 'codex')
def test_routes_each_number_independently_from_any_directory(self):
self.worktree('016', 'dark')
target = self.worktree('019', 'previous')
result = self.run_wrapper('019', cwd=self.bin)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn(f'STUB_SOURCE={target}', result.stdout)
def test_missing_source_never_runs_codex(self):
result = self.run_wrapper('099')
self.assertNotEqual(result.returncode, 0)
self.assertIn('no checked-out', result.stderr)
self.assertNotIn('STUB_SOURCE', result.stdout)
def test_ambiguous_source_fails(self):
self.worktree('016', 'one')
self.worktree('016', 'two')
result = self.run_wrapper('016')
self.assertNotEqual(result.returncode, 0)
self.assertIn('multiple worktrees', result.stderr)
self.assertNotIn('STUB_SOURCE', result.stdout)
def test_missing_worktree_reports_lost_candidate_without_runner(self):
target = self.worktree('016', 'lost')
shutil.rmtree(target)
result = self.run_wrapper('016')
self.assertNotEqual(result.returncode, 0)
self.assertIn('implementation is missing', result.stderr)
self.assertIn('uncommitted files', result.stderr)
self.assertNotIn('STUB_SOURCE', result.stdout)
def test_live_candidate_is_used_when_old_registration_is_missing(self):
missing = self.worktree('016', 'lost')
shutil.rmtree(missing)
target = self.worktree('016', 'restored')
result = self.run_wrapper('016')
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn(f'STUB_SOURCE={target}', result.stdout)
def test_node_is_selected_from_nvm_when_absent_from_path(self):
self.worktree('016', 'dark')
(self.bin / 'node').unlink()
nvm_dir = self.bin / 'no-nvm'
nvm_dir.mkdir()
node_bin = nvm_dir / 'bin'
node_bin.mkdir()
node = node_bin / 'node'
node.write_text('#!/bin/sh\nexit 0\n')
node.chmod(0o755)
(nvm_dir / 'nvm.sh').write_text(
'nvm() { export PATH="$NVM_DIR/bin:$PATH"; }\n')
result = self.run_wrapper('016')
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn('STUB_TASK=016', result.stdout)
def test_missing_node_fails_before_runner(self):
self.worktree('016', 'dark')
(self.bin / 'node').unlink()
result = self.run_wrapper('016')
self.assertNotEqual(result.returncode, 0)
self.assertIn('Node >=20.19 is required', result.stderr)
self.assertNotIn('STUB_SOURCE', result.stdout)
def test_check_validates_without_invoking_runner(self):
target = self.worktree('016', 'dark')
hook = target / '.roborto/testtask-hook'
hook.write_text('#!/bin/sh\n[ "$1" = validate ] || exit 99\n')
hook.chmod(0o755)
(target / '.roborto/testtask.conf').write_text(
'ROBORTO_HOOK="$ROBORTO_PROJECT_ROOT/.roborto/testtask-hook"\n'
'ROBORTO_WORKTREE="$ROBORTO_PROJECT_ROOT/.test-worktrees/task-$ROBORTO_TASK_ID"\n')
result = self.run_wrapper('--check', '016')
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn('preflight passed', result.stdout)
self.assertNotIn('STUB_SOURCE', result.stdout)
def test_invalid_arguments_fail_without_runner(self):
for args in [(), ('16',), ('../016',), ('016', '019')]:
with self.subTest(args=args):
result = self.run_wrapper(*args)
self.assertEqual(result.returncode, 2)
self.assertIn('Usage:', result.stderr)
self.assertNotIn('STUB_SOURCE', result.stdout)
if __name__ == '__main__':
unittest.main()
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Sourced by the wrapper and hook; select Node without changing the caller's shell.
testtask_node_ready() {
command -v node >/dev/null 2>&1 &&
node -e 'const [a,b]=process.versions.node.split(".").map(Number); process.exit(a>20 || (a===20 && b>=19) ? 0 : 1)' >/dev/null 2>&1
}
if ! testtask_node_ready; then
TESTTASK_NVM_SCRIPT="${NVM_DIR:-$HOME/.nvm}/nvm.sh"
if [[ -f "$TESTTASK_NVM_SCRIPT" ]]; then
source "$TESTTASK_NVM_SCRIPT"
nvm use 24 >/dev/null 2>&1 || true
fi
fi
if ! testtask_node_ready; then
echo 'testtask: Node >=20.19 is required; install Node 24 through nvm or put a supported Node on PATH.' >&2
return 1
fi
unset TESTTASK_NVM_SCRIPT
+27 -1
View File
@@ -1,7 +1,33 @@
#!/usr/bin/env bash
set -Eeuo pipefail
CHECK_ONLY=0
if [[ "${1:-}" == --check ]]; then
CHECK_ONLY=1
shift
fi
if [[ $# -ne 1 || ! "$1" =~ ^[0-9]{3}$ ]]; then
echo 'Usage: scripts/testtask.sh [--check] TASK_ID (three digits)' >&2
exit 2
fi
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
command -v python3 >/dev/null 2>&1 || {
echo 'testtask: Python 3 is required for source routing and snapshot verification.' >&2
exit 127
}
TASK_SOURCE="$(python3 "$SCRIPT_DIR/testtask_source.py" "$SCRIPT_DIR/.." "$1")"
printf 'testtask: TASK-%s source: %s\n' "$1" "$TASK_SOURCE"
source "$SCRIPT_DIR/testtask-node.sh"
if ! command -v roborto-testtask >/dev/null 2>&1; then
echo 'testtask: standalone roborto-testtask CLI is missing; install/configure it before running.' >&2
exit 127
fi
exec roborto-testtask "$@"
cd -- "$TASK_SOURCE"
if (( CHECK_ONLY )); then
export ROBORTO_PROJECT_ROOT="$TASK_SOURCE" ROBORTO_TASK_ID="$1"
source .roborto/testtask.conf
export ROBORTO_WORKTREE
"$ROBORTO_HOOK" validate
printf 'testtask: preflight passed (%s); no runner or browser started.\n' "$(node --version)"
exit 0
fi
exec roborto-testtask "$1"
+51
View File
@@ -0,0 +1,51 @@
"""Resolve a numbered task to its checked-out implementation, never a snapshot."""
import re
import subprocess
import sys
from pathlib import Path
def task_source(repository, task):
if not re.fullmatch(r'[0-9]{3}', task):
raise ValueError('task ID must contain exactly three digits')
listing = subprocess.check_output(
['git', '-C', str(repository), 'worktree', 'list', '--porcelain', '-z'],
).decode()
prefix = f'refs/heads/task/{task}'
candidates = []
missing = []
for entry in listing.split('\0\0'):
fields = dict(field.split(' ', 1) for field in entry.split('\0') if ' ' in field)
branch = fields.get('branch', '')
if branch == prefix or branch.startswith(prefix + '-'):
path = Path(fields['worktree'])
if 'prunable' in fields or not path.is_dir():
missing.append(path)
else:
candidates.append(path)
if not candidates and missing:
paths = ', '.join(map(str, missing))
raise ValueError(
f'TASK-{task} implementation is missing: {paths}. '
'Restore the source from a saved copy or rebuild the candidate in a persistent '
'worktree; its branch alone does not recover uncommitted files. '
'Refusing to test the integration baseline instead.'
)
if not candidates:
raise ValueError(f'no checked-out task/{task} branch; prepare its implementation worktree first')
if len(candidates) != 1:
raise ValueError(f'multiple worktrees match TASK-{task}; reconcile the duplicate task branches first')
source = candidates[0]
if not source.is_dir() or not (source / '.roborto/testtask.conf').is_file():
raise ValueError(f'task source is missing or has no testtask configuration: {source}')
return source
if __name__ == '__main__':
try:
if len(sys.argv) != 3:
raise ValueError('expected repository path and task ID')
print(task_source(Path(sys.argv[1]), sys.argv[2]))
except (ValueError, subprocess.CalledProcessError) as error:
print(f'testtask: {error}', file=sys.stderr)
sys.exit(2)