BS-001 Initialize BortStack foundation and project workflow
This commit is contained in:
Executable
+74
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# BortStack ChatGPT snapshot generator
|
||||
#
|
||||
# Creates a lightweight repository snapshot containing the material
|
||||
# needed for ChatGPT/Codex engineering work while excluding dependencies,
|
||||
# Git history, caches, build output and other reproducible files.
|
||||
|
||||
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
DATE="$(date +%Y-%m-%d-%H%M)"
|
||||
BRANCH="$(git branch --show-current)"
|
||||
COMMIT="$(git rev-parse --short HEAD)"
|
||||
|
||||
OUTPUT_DIR="${REPO_ROOT}/snapshots"
|
||||
OUTPUT_FILE="${OUTPUT_DIR}/bortstack-chatgpt-${DATE}-${COMMIT}.zip"
|
||||
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
TEMP_FILE="$(mktemp "${OUTPUT_DIR}/.bortstack-chatgpt-XXXXXX.zip")"
|
||||
rm -f "$TEMP_FILE"
|
||||
trap 'rm -f "$TEMP_FILE"' EXIT
|
||||
|
||||
echo "BortStack ChatGPT Snapshot"
|
||||
echo "============================="
|
||||
echo "Branch: $BRANCH"
|
||||
echo "Commit: $COMMIT"
|
||||
echo "Output: $OUTPUT_FILE"
|
||||
echo
|
||||
|
||||
zip -r -y "$TEMP_FILE" . \
|
||||
-x ".git" \
|
||||
".git/*" \
|
||||
".aws/*" \
|
||||
".codex/*" \
|
||||
".agents/*" \
|
||||
".env" \
|
||||
".env.*" \
|
||||
"*/.env" \
|
||||
"*/.env.*" \
|
||||
"*.pem" \
|
||||
"*.key" \
|
||||
"*.sqlite" \
|
||||
"*.sqlite3" \
|
||||
"*.db" \
|
||||
".local/*" \
|
||||
"api/.venv/*" \
|
||||
"react/node_modules/*" \
|
||||
"react/dist/*" \
|
||||
"react/test-results/*" \
|
||||
"*/__pycache__/*" \
|
||||
"*.pyc" \
|
||||
"*.pyo" \
|
||||
"*/.pytest_cache/*" \
|
||||
"*/.cache/*" \
|
||||
"snapshots/*" \
|
||||
"*.log" \
|
||||
".DS_Store" \
|
||||
"image-artifacts/" \
|
||||
"image-artifacts/*" \
|
||||
".task-worktrees/" \
|
||||
".task-worktrees/*" \
|
||||
".test-worktrees/" \
|
||||
".test-worktrees/*"
|
||||
|
||||
mv -f "$TEMP_FILE" "$OUTPUT_FILE"
|
||||
|
||||
echo
|
||||
echo "Snapshot complete."
|
||||
echo "Size: $(du -h "$OUTPUT_FILE" | cut -f1)"
|
||||
echo "Branch: $BRANCH"
|
||||
echo "Commit: $COMMIT"
|
||||
echo "File: $OUTPUT_FILE"
|
||||
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Create an owned test-only copy of the exact non-ignored working state."""
|
||||
import fcntl
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
task = sys.argv[1] if len(sys.argv) == 2 else ''
|
||||
if len(task) != 3 or not task.isascii() or not task.isdigit():
|
||||
sys.exit('Usage: create-test-snapshot.py 001')
|
||||
branch = subprocess.check_output(['git', 'branch', '--show-current'], cwd=root, text=True).strip()
|
||||
if branch != f'bs-{task}':
|
||||
sys.exit(f'Refusing snapshot: expected bs-{task}, found {branch}')
|
||||
parent = root / '.test-worktrees'
|
||||
parent.mkdir(exist_ok=True)
|
||||
if parent.is_symlink():
|
||||
sys.exit('Refusing symlink snapshot parent')
|
||||
# Reuse wrapper-owned lock descriptor, or acquire it for standalone snapshot creation.
|
||||
lockpath = parent / 'session.lock'
|
||||
try:
|
||||
inherited = os.fstat(8)
|
||||
expected = lockpath.stat()
|
||||
if (inherited.st_dev, inherited.st_ino) != (expected.st_dev, expected.st_ino):
|
||||
raise OSError('unrelated descriptor')
|
||||
lockfd = 8
|
||||
except OSError:
|
||||
lockfd = os.open(lockpath, os.O_CREAT | os.O_WRONLY, 0o600)
|
||||
try:
|
||||
fcntl.flock(lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except BlockingIOError:
|
||||
sys.exit('testtask: another test session owns this snapshot')
|
||||
target = parent / f'task-{task}'
|
||||
marker = '.roborto-test-snapshot.json'
|
||||
owner = {'source': str(root), 'task': task}
|
||||
if target.exists():
|
||||
if target.is_symlink() or not (target / marker).is_file():
|
||||
sys.exit('Refusing to replace an unowned snapshot')
|
||||
previous = json.loads((target / marker).read_text())
|
||||
if previous.get('owner') != owner:
|
||||
sys.exit('Refusing snapshot with different owner')
|
||||
# git supplies tracked plus permitted untracked files, including local edits/deletions.
|
||||
paths = subprocess.check_output(['git', 'ls-files', '-z', '--cached', '--others', '--exclude-standard'], cwd=root).decode().split('\0')
|
||||
def permitted(rel):
|
||||
parts = Path(rel).parts
|
||||
return not any(x in {'.git', '.aws', '.agents', '.codex', '.roborto-runtime', '.test-worktrees', '.task-worktrees', 'node_modules', '.venv', '__pycache__', 'instance', 'dist', 'coverage'} for x in parts) and not any(x.startswith('.env') and x != '.env.example' for x in parts) and not rel.endswith(('.db', '.sqlite', '.sqlite3', '.pem', '.key', '.pyc'))
|
||||
manifest = {}
|
||||
stage = Path(tempfile.mkdtemp(prefix=f'.task-{task}-', dir=parent))
|
||||
try:
|
||||
for rel in sorted(set(filter(None, paths))):
|
||||
if not permitted(rel):
|
||||
continue
|
||||
src = root / rel
|
||||
if src.is_symlink():
|
||||
sys.exit(f'Refusing symlink in snapshot: {rel}')
|
||||
if not src.is_file():
|
||||
continue
|
||||
data = src.read_bytes()
|
||||
dst = stage / rel
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
dst.write_bytes(data)
|
||||
shutil.copymode(src, dst)
|
||||
manifest[rel] = hashlib.sha256(data).hexdigest()
|
||||
# Detect source edits while copying; compare every included file to its snapshot.
|
||||
for rel, digest in manifest.items():
|
||||
if hashlib.sha256((root / rel).read_bytes()).hexdigest() != digest:
|
||||
sys.exit(f'Source changed during snapshot: {rel}; rerun')
|
||||
(stage / marker).write_text(json.dumps({'owner': owner, 'branch': branch, 'files': manifest}, indent=2) + '\n')
|
||||
if target.exists():
|
||||
shutil.rmtree(target)
|
||||
os.rename(stage, target)
|
||||
print(f'Snapshot: {target} ({len(manifest)} files verified; test-only copy, not an editing worktree)')
|
||||
finally:
|
||||
if stage.exists():
|
||||
shutil.rmtree(stage)
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
if [[ "$#" -ne 1 || ! "$1" =~ ^(TASK-|BS-)?([0-9]{3})$ ]]; then
|
||||
echo 'Usage: ./scripts/testtask.sh TASK-XXX (for example: TASK-001)' >&2
|
||||
exit 2
|
||||
fi
|
||||
task="${BASH_REMATCH[2]}"
|
||||
branch="$(git -C "$root" branch --show-current)"
|
||||
if [[ -f "$root/.roborto/testtask.conf" && "$branch" == "bs-$task" ]]; then
|
||||
if ! command -v roborto-testtask >/dev/null 2>&1; then
|
||||
echo 'testtask: standalone roborto-testtask CLI is missing.' >&2
|
||||
exit 127
|
||||
fi
|
||||
mkdir -p "$root/.test-worktrees"
|
||||
exec 8>"$root/.test-worktrees/session.lock"
|
||||
flock -n 8 || { echo 'testtask: another test session is running in this worktree.' >&2; exit 1; }
|
||||
cd "$root"
|
||||
exec roborto-testtask "$task"
|
||||
fi
|
||||
candidate="$root/.task-worktrees/bs-$task"
|
||||
if [[ ! -x "$candidate/scripts/testtask.sh" ]]; then
|
||||
echo "testtask: TASK-$task maps to BS-$task; no prepared task worktree at $candidate" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf 'testtask: TASK-%s -> BS-%s (%s)\n' "$task" "$task" "$candidate"
|
||||
exec "$candidate/scripts/testtask.sh" "TASK-$task"
|
||||
Reference in New Issue
Block a user