Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ tmp/
cli/.stryker-tmp/
cli/reports/
prototypes/model-studio/out

python_modules/
63 changes: 63 additions & 0 deletions demo-sparkles/preflight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# demo/preflight.sh — run at 20:40, before code freeze
# Confirms every dependency for all three scenarios is green

set -e

WORKER_URL="https://slicecheck.sadhak001.workers.dev"
REPO="neomatrix369/tripwire"
GITHUB_TOKEN="${GITHUB_TOKEN:?Set GITHUB_TOKEN env var}"

echo "━━━ SliceCheck Demo Preflight ━━━"
echo ""

# 1. Worker is live
echo -n "[1] Worker reachable... "
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$WORKER_URL/")
[ "$STATUS" = "200" ] && echo "✅ $WORKER_URL" || echo "❌ Got HTTP $STATUS — check wrangler deploy"

# 2. Audit endpoint returns HTML
echo -n "[2] Audit endpoint (closed PRs)... "
AUDIT=$(curl -s "$WORKER_URL/audit?repo=$REPO&state=closed&limit=3")
echo "$AUDIT" | grep -q "SliceCheck" && echo "✅ Returns HTML" || echo "❌ No SliceCheck in response — check Worker logs"

# 3. Audit endpoint (open PRs)
echo -n "[3] Audit endpoint (open PRs)... "
AUDIT_OPEN=$(curl -s "$WORKER_URL/audit?repo=$REPO&state=open&limit=5")
echo "$AUDIT_OPEN" | grep -q "SliceCheck" && echo "✅ Returns HTML" || echo "❌ Failed"

# 4. GitHub token has repo access
echo -n "[4] GitHub token — can read closed PRs... "
PR_COUNT=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/pulls?state=closed&per_page=3" | python3 -c "import sys,json; print(len(json.load(sys.stdin)))")
[ "$PR_COUNT" -gt "0" ] && echo "✅ $PR_COUNT closed PRs found" || echo "❌ 0 PRs returned — check token scope (needs repo)"

# 5. Webhook registered
echo -n "[5] Webhook registered on repo... "
HOOKS=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/hooks" | python3 -c \
"import sys,json; hooks=json.load(sys.stdin); print(next((h['config']['url'] for h in hooks if 'slicecheck' in h['config'].get('url','')), 'NOT FOUND'))")
echo "$HOOKS" | grep -q "slicecheck" && echo "✅ $HOOKS" || echo "⚠️ Not found — webhook scenario won't work. Register in GitHub → Repo → Settings → Webhooks"

# 6. gh CLI authenticated
echo -n "[6] gh CLI authenticated... "
gh auth status &>/dev/null && echo "✅" || echo "❌ Run: gh auth login"

# 7. Demo branch doesn't already exist (clean state)
echo -n "[7] Demo branch clean... "
git fetch --quiet
git branch -r | grep -q "demo/slicecheck-health" && echo "⚠️ Old demo branch exists — run: git push origin --delete demo/slicecheck-health" || echo "✅"

# 8. PROGRESS.md has the demo slice
echo -n "[8] PROGRESS.md has demo slice... "
grep -q "SliceCheck health endpoint" PROGRESS.md && echo "✅" || echo "❌ Add the demo slice to PROGRESS.md first"

# 9. Fallback GIF exists
echo -n "[9] Fallback GIF recorded... "
ls demo/fallback-*.gif &>/dev/null && echo "✅" || echo "⚠️ No fallback GIF found — run scenario 1 now and record it with Kap"

echo ""
echo "━━━ Preflight complete ━━━"
echo "AUDIT URL (closed): $WORKER_URL/audit?repo=$REPO&state=closed&limit=5"
echo "AUDIT URL (open): $WORKER_URL/audit?repo=$REPO&state=open&limit=5"
echo "WORKER HEALTH: $WORKER_URL/"
72 changes: 72 additions & 0 deletions demo-sparkles/scenario-1-create-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
# demo/scenario-1-create-pr.sh
# Creates a PR that DELIBERATELY fails SliceCheck.
# The implementation is real but missing tests and README —
# exactly what the PROGRESS.md slice requires.

set -e

WORKER_URL="https://slicecheck.sadhak001.workers.dev"
REPO="neomatrix369/tripwire"
BRANCH="demo/slicecheck-health-$(date +%s)"

echo "Creating demo branch: $BRANCH"
git checkout main && git pull
git checkout -b "$BRANCH"

# Add the health endpoint to slicecheck/src/entry.py
# This is REAL code — but it's missing tests and README update
cat >> slicecheck/src/entry.py << 'PYEOF'


async def handle_health(request, env):
"""GET /health — returns service status and secret presence check."""
import json

secrets_status = {
"github": "ok" if getattr(env, "GITHUB_TOKEN", None) else "missing",
"anthropic": "ok" if getattr(env, "ANTHROPIC_API_KEY", None) else "missing",
"webhook": "ok" if getattr(env, "GITHUB_WEBHOOK_SECRET", None) else "missing",
}
missing = [k for k, v in secrets_status.items() if v == "missing"]

body = {
"status": "degraded" if missing else "ok",
"version": "1.0.0",
"secrets": secrets_status,
}
if missing:
body["missing"] = missing

from workers import Response
return Response(
json.dumps(body),
headers={"content-type": "application/json"}
)
PYEOF

# Wire it into the router in entry.py
# (append a route — assumes the router is at the end of on_fetch)
sed -i '' 's|return Response("Not found", status=404)|if request.url.endswith("/health"):\n return await handle_health(request, env)\n return Response("Not found", status=404)|' slicecheck/src/entry.py

git add slicecheck/src/entry.py
git commit -m "Add SliceCheck health endpoint"

echo "Pushing branch..."
git push -u origin "$BRANCH"

echo "Opening PR..."
gh pr create \
--repo "$REPO" \
--title "Add SliceCheck health endpoint" \
--body "Adds GET /health to the SliceCheck Worker. Returns service status and secret presence." \
--base main \
--head "$BRANCH"

echo ""
echo "✅ PR opened. SliceCheck will fire in ~10 seconds."
echo "Watch: https://github.com/$REPO/pulls"
echo ""
echo "Expected verdict: ❌ FAIL — missing tests, missing README update"
echo ""
echo "When the FAIL comment appears, run: bash demo/scenario-1-push-fix.sh $BRANCH"
86 changes: 86 additions & 0 deletions demo-sparkles/scenario-1-push-fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
# demo/scenario-1-push-fix.sh
# Pushes the missing tests + README update.
# SliceCheck re-fires and posts ✅ PASS.

set -e

BRANCH="${1:?Usage: bash scenario-1-push-fix.sh <branch-name>}"
REPO="neomatrix369/tripwire"

git checkout "$BRANCH"

# Add the missing tests
mkdir -p slicecheck/tests
cat > slicecheck/tests/test_health.py << 'PYEOF'
"""Tests for SliceCheck /health endpoint."""
import pytest
from unittest.mock import MagicMock

# Import the handler directly
import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
from entry import handle_health

class FakeEnv:
GITHUB_TOKEN = "ghp_test"
ANTHROPIC_API_KEY = "sk-ant-test"
GITHUB_WEBHOOK_SECRET = "test-secret"

class FakeEnvMissing:
GITHUB_TOKEN = None
ANTHROPIC_API_KEY = "sk-ant-test"
GITHUB_WEBHOOK_SECRET = "test-secret"

@pytest.mark.asyncio
async def test_health_ok():
import json
fake_request = MagicMock()
fake_request.url = "https://example.com/health"
response = await handle_health(fake_request, FakeEnv())
body = json.loads(response.body)
assert body["status"] == "ok"
assert body["version"] == "1.0.0"
assert all(v == "ok" for v in body["secrets"].values())

@pytest.mark.asyncio
async def test_health_degraded_missing_github():
import json
fake_request = MagicMock()
fake_request.url = "https://example.com/health"
response = await handle_health(fake_request, FakeEnvMissing())
body = json.loads(response.body)
assert body["status"] == "degraded"
assert "github" in body["missing"]
PYEOF

# Add the missing README section
cat >> slicecheck/README.md << 'MDEOF'

## Health Check

Verify the Worker is running and all secrets are configured:

```bash
curl https://slicecheck.<your-account>.workers.dev/health
```

Healthy response:
```json
{"status":"ok","version":"1.0.0","secrets":{"github":"ok","anthropic":"ok","webhook":"ok"}}
```

Degraded response (missing secret):
```json
{"status":"degraded","version":"1.0.0","secrets":{"github":"missing","anthropic":"ok","webhook":"ok"},"missing":["github"]}
```
MDEOF

git add slicecheck/tests/test_health.py slicecheck/README.md
git commit -m "Add tests and README for health endpoint"
git push

echo ""
echo "✅ Fix pushed. SliceCheck will re-verify in ~10 seconds."
echo "Expected: ✅ PASS"
echo "Watch: https://github.com/$REPO/pulls"
20 changes: 20 additions & 0 deletions demo-sparkles/scenario-2-open-prs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# demo/scenario-2-open-prs.sh
# What this proves: current in-flight work,
# including PRs opened during this hackathon session.

WORKER_URL="https://slicecheck.sadhak001.workers.dev"
REPO="neomatrix369/tripwire"

AUDIT_URL="$WORKER_URL/audit?repo=$REPO&state=open&limit=10"

echo "Opening audit — open PRs (including PRs from this session)..."
echo "$AUDIT_URL"

open "$AUDIT_URL"

# Bonus: show the same repo works with other projects
# Uncomment to demonstrate portability:
# echo ""
# echo "Same Worker, different repo:"
# open "$WORKER_URL/audit?repo=neomatrix369/rag-params-finder&state=closed&limit=5"
30 changes: 30 additions & 0 deletions demo-sparkles/scenario-3-closed-prs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
# demo/scenario-3-closed-prs.sh
# What this proves: SliceCheck learns from history.
# Any repo, any past PRs, no webhook needed.

WORKER_URL="https://slicecheck.sadhak001.workers.dev"
REPO="neomatrix369/tripwire"

AUDIT_URL="$WORKER_URL/audit?repo=$REPO&state=closed&limit=8"

echo "Opening retrospective audit — closed PRs..."
echo "$AUDIT_URL"

# macOS
open "$AUDIT_URL"

# Linux alternative:
# xdg-open "$AUDIT_URL"

# Or show raw in terminal while browser loads:
echo ""
echo "Raw summary (while browser loads):"
curl -s "$AUDIT_URL" | python3 -c "
import sys, re
html = sys.stdin.read()
# Extract text between tags for terminal preview
text = re.sub(r'<[^>]+>', ' ', html)
text = re.sub(r'\s+', ' ', text)
print(text[:800])
"
Loading
Loading