Skip to content

chore(swift-sdk): script to get spv stortage from iOS sim#3950

Open
ZocoLini wants to merge 1 commit into
v3.1-devfrom
chore/spv-storage-script
Open

chore(swift-sdk): script to get spv stortage from iOS sim#3950
ZocoLini wants to merge 1 commit into
v3.1-devfrom
chore/spv-storage-script

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Script to easily extract the spv storage, making issues easier to debug

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Added a utility script for developers to extract SPV storage from iOS Simulator app containers, with interactive device and network selection capabilities.
  • Chores

    • Updated git ignore patterns for SDK maintenance.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new Bash script get_spv_storage.sh is added to packages/swift-sdk/ that extracts SwiftExampleApp SPV storage from an iOS Simulator container using xcrun simctl and jq, with interactive device and network selection. The .gitignore is updated to exclude the spv-storage-*/ output directories the script produces.

Changes

SPV Storage Extraction Utility

Layer / File(s) Summary
SPV extraction script and .gitignore output exclusion
packages/swift-sdk/get_spv_storage.sh, packages/swift-sdk/.gitignore
Adds a 254-line Bash script with CLI flag parsing (--bundle-id, --out, --device, --network), simulator enumeration via xcrun simctl and jq, app container resolution, SPV root verification, network selection (all, exact/prefix match, or interactive picker with du sizes), and timestamped copy of SPV directories to a local output path. Updates .gitignore to ignore spv-storage-*/ output directories alongside the existing logs-*/ pattern.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • shumkov
  • QuantumExplorer
  • llbartekll

Poem

🐰 Hopping through the simulator's maze,
With xcrun simctl and jq's gaze,
I sniff out the SPV with a timestamped hop,
Copy it cleanly—no reason to stop!
.gitignore guards the output with care,
A swift little rabbit, beyond compare! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title describes the main change (adding a script to extract SPV storage from iOS simulator), but contains a typo ('stortage' instead of 'storage') which slightly diminishes clarity.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/spv-storage-script

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

✅ Review complete (commit 81ae65d)

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

PR adds a Bash helper to extract SwiftExampleApp SPV storage from a booted iOS Simulator, plus a matching .gitignore entry. The script is solid (set -euo pipefail, Bash 3.2 aware, interactive pickers with sane defaults) and touches no consensus/Rust code. One material reliability issue worth fixing for the script's stated debugging purpose, plus one minor robustness nit.

🟡 1 suggestion(s) | 💬 1 nitpick(s)

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/swift-sdk/get_spv_storage.sh`:
- [SUGGESTION] packages/swift-sdk/get_spv_storage.sh:248-253: Repeated runs merge stale files into the extracted SPV store
  `mkdir -p "$OUT_DIR"` followed by `cp -R "$src/." "$OUT_DIR/"` overlays a fresh dump onto whatever is already in `OUT_DIR`. If the SPV store has shed/rotated/compacted segment or metadata files between runs, the older files linger in the destination and silently corrupt the snapshot. Since this script exists specifically to debug SPV storage state, a misleading hybrid dump is the worst-case failure mode. Either refuse to write into a non-empty destination, timestamp the default `OUT_DIR`, or stage into a temp dir and replace atomically.

Comment thread packages/swift-sdk/get_spv_storage.sh
Comment thread packages/swift-sdk/get_spv_storage.sh Outdated
@ZocoLini ZocoLini marked this pull request as draft June 23, 2026 07:23
@ZocoLini ZocoLini force-pushed the chore/spv-storage-script branch from 9fc1992 to ab4164a Compare June 23, 2026 10:50
@ZocoLini ZocoLini force-pushed the chore/spv-storage-script branch from ab4164a to 81ae65d Compare June 23, 2026 10:50
@ZocoLini ZocoLini marked this pull request as ready for review June 23, 2026 10:51

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
packages/swift-sdk/get_spv_storage.sh (1)

250-251: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Prevent stale snapshot overlay when --out already exists.

Line 250 + Line 251 currently merge new SPV files into any existing directory, which can leave deleted/rotated files behind and produce a corrupted debug snapshot. Refuse pre-existing output paths (or stage to a temp dir and replace atomically).

Suggested fix
 if [ -z "$OUT_DIR" ]; then
   stamp="$(date +%Y-%m-%dT%H-%M-%S)"
   OUT_DIR="spv-storage-${safe_name}-${label}-${stamp}"
+elif [ -e "$OUT_DIR" ]; then
+  echo "Output path already exists: $OUT_DIR" >&2
+  echo "Choose a different --out path or remove it first." >&2
+  exit 1
 fi
 
 mkdir -p "$OUT_DIR"
 cp -R "$src/." "$OUT_DIR/"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/swift-sdk/get_spv_storage.sh` around lines 250 - 251, The current
implementation uses cp -R to merge files into the output directory, which can
leave stale files behind if OUT_DIR already exists. Fix this by either checking
if OUT_DIR exists before proceeding and refusing to continue (with an
appropriate error message), or by staging files to a temporary directory first
and then atomically replacing the final output directory. This ensures a clean
snapshot without leftover deleted or rotated files that could corrupt the debug
output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@packages/swift-sdk/get_spv_storage.sh`:
- Around line 250-251: The current implementation uses cp -R to merge files into
the output directory, which can leave stale files behind if OUT_DIR already
exists. Fix this by either checking if OUT_DIR exists before proceeding and
refusing to continue (with an appropriate error message), or by staging files to
a temporary directory first and then atomically replacing the final output
directory. This ensures a clean snapshot without leftover deleted or rotated
files that could corrupt the debug output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8b86b5c3-b3d9-4ebf-a58a-59f3cbfe6e63

📥 Commits

Reviewing files that changed from the base of the PR and between c1ab74e and 81ae65d.

📒 Files selected for processing (2)
  • packages/swift-sdk/.gitignore
  • packages/swift-sdk/get_spv_storage.sh

@@ -0,0 +1,254 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put such things in the scripts folder inside the package or at the root level.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the is no such folder in the swift-sdk package, and all the scripts related to the swift-sdk are directly under the package folder (build_ios.sh, verify_build.sh, get_logs.sh and setup_ios_build.sh), not inside a scripts folder, changing were the swift-sdk scripts are written is a different PR, moving all of them at once, moving one alone only causes confusion

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

PR adds a developer utility shell script to extract SPV storage from the iOS Simulator and a .gitignore entry. Non-consensus-critical, self-contained. The script works as intended; only minor polish suggestions remain, the most substantive being that an explicit --out directory is silently merged into rather than checked for existing contents.

🟡 1 suggestion(s) | 💬 2 nitpick(s)

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/swift-sdk/get_spv_storage.sh`:
- [SUGGESTION] packages/swift-sdk/get_spv_storage.sh:245-251: Existing `--out` directory is silently merged into
  When the caller passes `--out`, `mkdir -p` followed by `cp -R "$src/." "$OUT_DIR/"` overlays the SPV snapshot on top of whatever already lives at that path. Files that have since been rotated or deleted from the simulator store will remain in the exported directory, producing a snapshot that no longer matches the selected simulator/network — exactly the kind of corrupt artifact a debug tool must not produce. Either refuse a non-empty target or remove it atomically before copying. The default timestamped path is unaffected.

Comment on lines +245 to +251
if [ -z "$OUT_DIR" ]; then
stamp="$(date +%Y-%m-%dT%H-%M-%S)"
OUT_DIR="spv-storage-${safe_name}-${label}-${stamp}"
fi

mkdir -p "$OUT_DIR"
cp -R "$src/." "$OUT_DIR/"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: Existing --out directory is silently merged into

When the caller passes --out, mkdir -p followed by cp -R "$src/." "$OUT_DIR/" overlays the SPV snapshot on top of whatever already lives at that path. Files that have since been rotated or deleted from the simulator store will remain in the exported directory, producing a snapshot that no longer matches the selected simulator/network — exactly the kind of corrupt artifact a debug tool must not produce. Either refuse a non-empty target or remove it atomically before copying. The default timestamped path is unaffected.

Suggested change
if [ -z "$OUT_DIR" ]; then
stamp="$(date +%Y-%m-%dT%H-%M-%S)"
OUT_DIR="spv-storage-${safe_name}-${label}-${stamp}"
fi
mkdir -p "$OUT_DIR"
cp -R "$src/." "$OUT_DIR/"
if [ -z "$OUT_DIR" ]; then
stamp="$(date +%Y-%m-%dT%H-%M-%S)"
OUT_DIR="spv-storage-${safe_name}-${label}-${stamp}"
fi
if [ -e "$OUT_DIR" ]; then
echo "Output path already exists: $OUT_DIR" >&2
echo "Choose a different --out path or remove it first." >&2
exit 1
fi
mkdir -p "$OUT_DIR"
cp -R "$src/." "$OUT_DIR/"

source: ['claude', 'codex']


# ---------- copy ----------

safe_name="$(printf '%s' "$NAME" | tr ' /' '__')"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: safe_name only sanitizes spaces and slashes

Simulator names commonly include parentheses (e.g. iPhone 16 Pro (3rd generation)), which then appear unescaped in the auto-generated OUT_DIR. Most shells/filesystems tolerate this but it's awkward in tooling and history. Sanitize all non-alphanumeric characters instead.

Suggested change
safe_name="$(printf '%s' "$NAME" | tr ' /' '__')"
safe_name="$(printf '%s' "$NAME" | tr -c 'A-Za-z0-9._-' '_')"

source: ['claude']

Comment on lines +221 to +224
if ! [[ "$choice" =~ ^[0-9]+$ ]] \
|| [ "$choice" -lt 1 ] || [ "$choice" -gt "${#networks[@]}" ]; then
echo "Choice out of range." >&2; exit 1
fi

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: Inconsistent indentation in pick_network validation

The if ! [[ ... ]] line is flush to column 1 while the continuation and then body use the function's standard 2-space indent. Purely cosmetic, but stands out next to the otherwise consistent style in the file.

Suggested change
if ! [[ "$choice" =~ ^[0-9]+$ ]] \
|| [ "$choice" -lt 1 ] || [ "$choice" -gt "${#networks[@]}" ]; then
echo "Choice out of range." >&2; exit 1
fi
if ! [[ "$choice" =~ ^[0-9]+$ ]] \
|| [ "$choice" -lt 1 ] || [ "$choice" -gt "${#networks[@]}" ]; then
echo "Choice out of range." >&2; exit 1
fi

source: ['claude']

@shumkov shumkov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we move to scripts in next PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants