Skip to content
Merged
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
10 changes: 5 additions & 5 deletions demo/run_protect_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ cd "$W"
"$SC" clone "$A" "$B" >/dev/null

[ -f "$B/secret/db.txt" ] && fail "unauthorized clone wrote the protected file to disk"
# But the ciphertext blob did travel: every object reachable in A is present in B,
# and none of B's objects expose the plaintext.
for obj in "$A"/.sc/objects/*; do
[ -f "$B/.sc/objects/$(basename "$obj")" ] || fail "clone dropped object $(basename "$obj")"
done
# But the ciphertext blob did travel: the clone's object store matches the
# origin's exactly, and none of B's objects expose the plaintext.
diff <(cd "$A" && find .sc/objects -type f | sort) \
<(cd "$B" && find .sc/objects -type f | sort) \
|| fail "clone object store differs from origin"
grep -raq "$SECRET_PLAINTEXT" "$B/.sc/objects" \
&& fail "plaintext leaked into the unauthorized clone's objects"
echo "B (no key): protected file ABSENT from checkout, ciphertext present in objects ✔"
Expand Down
69 changes: 69 additions & 0 deletions docs/superpowers/plans/2026-07-11-protect-demo-object-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Fix Stale Object-Presence Check in `run_protect_demo.sh` — Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Make `demo/run_protect_demo.sh` pass again by replacing its pre-P8 flat object-presence loop with the sorted `find`-diff idiom used by the other demos (closes issue #44).

**Architecture:** The demo verifies a clone received every object by globbing `.sc/objects/*` and testing `[ -f ]`, but P8's sharded layout (`objects/<aa>/<rest>`) makes that first glob level directories, so the check always fails. Replace it with a byte-path equality diff of both stores' recursive file listings — the established pattern in `demo/run_http_remote_demo.sh:107` and `demo/run_streaming_demo.sh:98`.

**Tech Stack:** Bash (`set -euo pipefail` demo script), `find`, `diff`. No Rust code changes.

## Global Constraints

- Only `demo/run_protect_demo.sh` changes — no Rust code, tests, or other docs.
- The demo must remain self-checking: every claim an assertion, non-zero exit before the success line on any failure.
- The demo must leave zero residue (existing `mktemp -d` + `trap 'rm -rf "$W"' EXIT` handles this — do not touch it).
- Spec: `docs/superpowers/specs/2026-07-11-protect-demo-object-check-design.md`.

---

### Task 1: Replace the flat object loop with a find-diff store-equality check

**Files:**
- Modify: `demo/run_protect_demo.sh:48-52`

**Interfaces:**
- Consumes: nothing from other tasks (single-task plan).
- Produces: a passing `demo/run_protect_demo.sh` (exit 0, four ✔ lines + `RESULT:` line).

- [ ] **Step 1: Reproduce the failure (the "failing test")**

Run: `bash demo/run_protect_demo.sh; echo "exit=$?"`
Expected: prints `A: secret/db.txt committed as ciphertext (control file is plaintext-readable) ✔`, then `FAIL: clone dropped object <aa>` (a two-hex-char shard directory name, e.g. `06`), then `exit=1`.

- [ ] **Step 2: Apply the fix**

In `demo/run_protect_demo.sh`, replace these lines (currently 48–52):

```bash
# But the ciphertext blob did travel: every object reachable in A is present in B,
# and none of B's objects expose the plaintext.
for obj in "$A"/.sc/objects/*; do
[ -f "$B/.sc/objects/$(basename "$obj")" ] || fail "clone dropped object $(basename "$obj")"
done
```

with:

```bash
# But the ciphertext blob did travel: the clone's object store matches the
# origin's exactly, and none of B's objects expose the plaintext.
diff <(cd "$A" && find .sc/objects -type f | sort) \
<(cd "$B" && find .sc/objects -type f | sort) \
|| fail "clone object store differs from origin"
```

The surrounding lines (the `[ -f "$B/secret/db.txt" ]` check above, the `grep -raq "$SECRET_PLAINTEXT"` check below) stay untouched.

- [ ] **Step 3: Run the demo twice to verify it passes**

Run: `bash demo/run_protect_demo.sh && bash demo/run_protect_demo.sh; echo "exit=$?"`
Expected: each run prints all four ✔ lines ending with
`RESULT: protected path committed as ciphertext, unreadable in an unauthorized clone, decrypts only for the recipient ✔`, and the final `exit=0`.

- [ ] **Step 4: Commit**

```bash
git add demo/run_protect_demo.sh
git commit -m "fix(demo): sharded-layout object check in run_protect_demo.sh (closes #44)"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Fix stale object-presence check in `run_protect_demo.sh`

**Issue:** [#44](https://github.com/git-agentic/src-control/issues/44) — `run_protect_demo.sh: stale pre-P8 object-presence check always fails`
**Date:** 2026-07-11
**Status:** Approved

## Problem

`demo/run_protect_demo.sh` fails on current main with `FAIL: clone dropped
object 06` (reproduced at HEAD). Lines 50–52 verify the clone received every
object by globbing `"$A"/.sc/objects/*` and testing each entry with `[ -f ]`.
That predates P8 (ADR-0015): the sharded loose-object layout stores objects as
`objects/<aa>/<rest>`, so the first glob level yields shard *directories* and
`[ -f ]` is always false — the check fails on the first entry, every run.

Everything before and after the broken loop passes: the ciphertext greps
(zstd-loose objects still expose the plaintext control marker), the
keyless-switch skip report, and the authorized decrypt.

## Fix

Replace the flat per-object loop with the sorted `find`-diff already used by
`demo/run_http_remote_demo.sh:107` and `demo/run_streaming_demo.sh:98`:

```bash
diff <(cd "$A" && find .sc/objects -type f | sort) \
<(cd "$B" && find .sc/objects -type f | sort) \
|| fail "clone object store differs from origin"
```

This is deliberately a *stronger* assertion than the original: byte-path
equality of the two object stores in both directions, not just A ⊆ B. A full
local clone of a loose-only repo produces an identical store layout (proven by
the two sibling demos, which diff across the wire). On failure, `diff` prints
the differing paths before `fail` fires, so the failure is self-explaining.

The comment above the check is updated to state the new claim ("the clone's
object store matches the origin's exactly"). Nothing else in the script
changes.

### Alternatives considered

- **Two-level per-object loop** (`objects/*/*` with shard-relative paths):
preserves the original one-way semantics but is a bespoke pattern; the
find-diff is the established idiom in this demo suite.
- **Recursive file-count comparison** (partial-clone style): weakest — equal
counts don't prove the same objects travelled. Only appropriate where
partial-clone asymmetry makes equality impossible, which doesn't apply here.

## Scope

- `demo/run_protect_demo.sh` — one hunk (comment + loop → diff). No Rust code,
tests, or other docs change; the demo is the test.

## Verification

Run `bash demo/run_protect_demo.sh` twice. Each run must print all four ✔
lines plus the final `RESULT:` line and exit 0; the mktemp workdir is removed
by the existing `trap`. The fix commit references and closes issue #44.
Loading