Files
software-mansion__argent/scripts/download-simulator-server.sh
filip131311 b232114422 docs: audit every comment in src against the code it describes (#931)
Audits every comment in `src/` and `scripts/` against the code it
describes.

**462 files, 57 commits, net −8,194 lines.** Comment text only — the
whole branch is code-identical to `main`.

## Method

One subagent per file, strictly sequential. Scope was `src/` +
`scripts/` (459 files); three more files were added at the end because
they carried dead references of the same kind — two test headers citing
design docs that do not exist, and `publish-npm.yml` citing a retired
workflow. Each agent verified every comment — line, block, JSDoc, file
header, trailing — against the surrounding code and the rest of the
repo, following identifiers, paths, tool ids, config keys, env vars and
issue links to see whether they still exist and still behave as
described. Rules:

- **A false or misleading comment is deleted, not reworded.** If a claim
could not be confirmed by reading the source, it went. That is why the
deletion count is so much larger than the rewrite count.
- Survivors are cut to the shortest form carrying something the code
does not already say. Restatement, preamble, hedging, changelog prose
and ASCII banners are gone; the non-obvious *why* stays.
- Preserved byte-identical: license headers, pragmas and directives
(`@ts-*`, `eslint-disable`, shebangs, `/// <reference>`), JSDoc tag
tokens, everything inside a string or template literal, and the sole
comment inside an otherwise empty block (ESLint `no-empty` counts a
comment-bearing block as non-empty).

## Verification

Every file passed two independent gates before being recorded as done:

1. `comments-only` — the required check.
2. A second comment-stripping comparator with a proper mode stack,
written for this pass because `comments-only`'s flat scanner desyncs on
nested template literals and quote-bearing regex literals and then
reports comment lines as code changes. Two files hit that false FAIL
(`utils/android-profiler/pipeline/index.ts`,
`scripts/extract-tools.mjs`); in both the "changed code" it printed was
literally `//` lines, and the second checker confirmed the code was
byte-identical.

After the last file, all 462 changed files were re-checked against
`main` with the same comparator, rather than trusting any agent's
self-report. **459 code-identical; 2 are non-code (`.svg`, `.md`); 1
intentional.**

The intentional one is `packages/argent/scripts/bundle-tools.cjs`: the
changed template literal *is* the comment header of the file it
generates, `packages/native-devtools-android/src/bundled-meta.ts`.
Fixing only the generated file would have been reverted by the next
build, so the generator changed too — and it has been verified to
reproduce the committed generated file byte-for-byte.

## Representative false claims removed

Not wording nits — statements a reader would have acted on:

- **Reversed directions.** `proxyStart`'s JSDoc had the tunnel backwards
(it is a reverse tunnel: the host binds first and the simulator dials
in). A `paste()` doc had the pasteboard copy direction reversed.
- **Contradicted by the code below it.** A timeout budget multiplied by
three where the probes run concurrently — the same comment said so six
lines later. A "warn once" that warns on every call. A "binary search"
that is a linear scan.
- **Named things that do not exist.** A `vega-fast-cli` binary, a
`finish-recording.ts`, a `publish-next.yml` workflow, two
`profiler-react19-*.md` design docs, a `DebuggerTarget.ts`, a commit
hash git does not know, two tool ids, an `ensureEnv` cycle.
- **Wrong by construction.** "Welford accumulators" across four files
where the code keeps naive `n`/`sum`/`sumSq`; `sum`/`sumSq` documented
over `actualDuration` when reduce sums `selfDuration`; a strict-mode
halving written `n/2` where the code ceils; field docs listing enum
values the producers never emit.
- **Guarantees the code does not make.** A validation matrix claiming to
cover "EVERY tool" that skips flagless ones; a Pareto cutoff that
`slice(0, 20)` makes inert; an idempotence claim where the real rule is
at-or-ahead; a capability note describing a clean 400 the shape-based
device resolver can never produce.
- **Unverifiable assertions** about prebuilt binaries, external CLIs and
the cloud SDK — deleted rather than kept as folklore, since nothing in
the repo can confirm them.
- **Stale numbers**: invented Android tool versions, hard-coded tool
counts and description lengths that had drifted.

## Review

A Fable agent reviewed both halves adversarially for over-deletion,
misread code, `no-empty` hazards and byte-identity violations.
Second-half verdict: **SHIP**, with two one-line restores, both applied
in the final commit — the `npm view ""` rationale behind a blank-token
guard, and the note that `argent-mcp` keeps a copy of
`SECRET_PLACEHOLDER_MARKER` it cannot import.

## Code issues surfaced but deliberately not fixed

This pass changes comments only. Eight genuine findings are logged for a
follow-up:

1. `telemetry/src/consent.ts` — a non-ENOENT read error returns null and
falls through to the default-on path, so file errors *can* silently flip
telemetry on.
2. `chromium-server/navigation.ts` — `navigate()` is reachable from
`POST /api/navigate` with only a `typeof === "string"` check; open-url's
schema is a bare `z.string()`, so the "already validated by zod" premise
never held.
3. `http.ts` — `constantTimeEqual` returns early on a length mismatch,
so the auth token's length is observable.
4. `describe/index.ts:~114` — the ios-remote branch passes `{ isTvOs:
false }` unconditionally, so a remote tvOS simulator takes the iOS
ax-service path, though `isRemoteTvOsSimulator` exists and shake/paste
do use it.
5. `devices/boot-device.ts` — `-crash-report-mode never` is passed
unconditionally *and* appended again by the feature-detecting path, so
every emulator spawn passes it twice.
6. `react-profiler/pipeline/04-rank.ts` — `PARETO_THRESHOLD_PCT` is
dead: `slice(0, 20)` always wins.
7. `reaped-sessions.ts` — a user-facing hint string tells the agent that
`react-profiler-start { force: true }` disposes the debugger and
profiler session; it does not. Left byte-identical because it is a
string literal, not a comment.
8. `utils/simctl-backend.ts` — `localSimctl` is exported with no
importers anywhere.

## Docs

No documentation change is needed: this pass touches only source
comments, and no user-facing capability, tool, CLI flag, config key or
flow-file behaviour changed.

---------

Co-authored-by: filip131311 <f.kaminski2000@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-24 12:16:20 +02:00

133 lines
5.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Downloads simulator-server (argent variant) for every supported host platform
# into platform-keyed subdirectories of packages/native-devtools-ios/bin/ — the
# layout packages/argent/scripts/bundle-tools.cjs and the runtime resolver in
# @argent/native-devtools-ios both expect.
#
# Usage: ./scripts/download-simulator-server.sh [release-tag]
#
# Requires an authenticated gh CLI: the release repo is public, but
# `gh release download` still needs auth.
REPO="software-mansion-labs/simulator-server-releases"
TAG="${1:-radon-main}"
DEST_DIR="packages/native-devtools-ios/bin"
# release-asset-name → host platform key; the keys mirror hostPlatformKey() in
# @argent/native-devtools-ios so the resolver can look up by host.
declare -a TARGETS=(
"simulator-server-argent-macos:darwin"
"simulator-server-argent-linux:linux"
"simulator-server-argent-linux-arm64:linux-arm64"
"simulator-server-argent-windows.exe:win32"
)
mkdir -p "${DEST_DIR}"
for entry in "${TARGETS[@]}"; do
ASSET_NAME="${entry%%:*}"
PLATFORM="${entry##*:}"
PLATFORM_DIR="${DEST_DIR}/${PLATFORM}"
# Must match simulatorServerBinaryName() in the resolver and the dispatcher.
if [[ "${PLATFORM}" == "win32" ]]; then
BIN_BASENAME="simulator-server.exe"
else
BIN_BASENAME="simulator-server"
fi
# Purge first so a previous run's stale binary can't ship when this run's
# download fails and the branch below only warns and continues.
rm -rf "${PLATFORM_DIR}"
mkdir -p "${PLATFORM_DIR}"
echo "Downloading ${ASSET_NAME} → ${PLATFORM_DIR}/${BIN_BASENAME}"
# Tolerate missing assets so macOS-only consumers still work when another
# platform's artifact lags a release. Capture gh's stderr rather than
# discarding it: "not authenticated" vs "asset missing" vs "rate-limited".
GH_STDERR="$(mktemp)"
if ! gh release download "${TAG}" \
--repo "${REPO}" \
--pattern "${ASSET_NAME}" \
--dir "${PLATFORM_DIR}" \
--clobber 2>"${GH_STDERR}"; then
GH_MSG=$(<"${GH_STDERR}")
rm -f "${GH_STDERR}"
echo " ⚠ ${ASSET_NAME} not downloaded — skipping (binary won't be available on ${PLATFORM} hosts)"
[[ -n "${GH_MSG}" ]] && printf ' gh: %s\n' "${GH_MSG//$'\n'/$'\n gh: '}"
# Empty (purged above), so the dir disappears and the inventory stays clean.
rmdir "${PLATFORM_DIR}" 2>/dev/null || true
continue
fi
rm -f "${GH_STDERR}"
mv "${PLATFORM_DIR}/${ASSET_NAME}" "${PLATFORM_DIR}/${BIN_BASENAME}"
chmod +x "${PLATFORM_DIR}/${BIN_BASENAME}"
# A wrong-arch binary is worse than a missing one: the resolver picks it and
# the user gets ENOEXEC at spawn with no hint. Fail hard here, unlike the
# missing-asset case, because a mislabeled asset is an upstream packaging bug.
if command -v file >/dev/null 2>&1; then
DESC="$(file -b "${PLATFORM_DIR}/${BIN_BASENAME}")"
case "${PLATFORM}" in
darwin) EXPECT="Mach-O universal" ;;
linux) EXPECT="ELF 64-bit.*x86-64" ;;
linux-arm64) EXPECT="ELF 64-bit.*aarch64" ;;
win32) EXPECT="PE32\+.*x86-64" ;;
*) EXPECT="" ;;
esac
if [[ -n "${EXPECT}" ]] && ! [[ "${DESC}" =~ ${EXPECT} ]]; then
echo "✗ ${ASSET_NAME} has the wrong architecture for ${PLATFORM}:" >&2
echo " got: ${DESC}" >&2
echo " expected: ${EXPECT}" >&2
exit 1
fi
echo " ✓ arch ok: ${DESC}"
fi
done
echo ""
echo "Downloaded simulator-server binaries:"
find "${DEST_DIR}" \( -name simulator-server -o -name 'simulator-server.exe' \) -type f -exec ls -la {} \;
# The simulator-server `android_device` controller pushes the screen-sharing
# agent (host-independent .jar + per-ABI .so) to the phone over adb, resolving
# it from `resources/android/` relative to its working directory — which the
# blueprint sets to the binary's own platform dir. The payload runs on the
# phone, so one tarball serves every host; extract a copy next to each binary.
# A missing asset is tolerated: physical-device support is then unavailable.
AGENT_ASSET="screen-sharing-agent.tar.gz"
AGENT_TMP="$(mktemp -d)"
echo ""
echo "Downloading ${AGENT_ASSET} (Android physical-device screen-sharing agent)"
GH_STDERR="$(mktemp)"
if gh release download "${TAG}" \
--repo "${REPO}" \
--pattern "${AGENT_ASSET}" \
--dir "${AGENT_TMP}" \
--clobber 2>"${GH_STDERR}"; then
rm -f "${GH_STDERR}"
while IFS= read -r bin; do
plat_dir="$(dirname "${bin}")"
res_dir="${plat_dir}/resources/android"
rm -rf "${res_dir}"
mkdir -p "${res_dir}"
tar -xzf "${AGENT_TMP}/${AGENT_ASSET}" -C "${res_dir}"
echo " ✓ screen-sharing agent → ${res_dir}"
done < <(find "${DEST_DIR}" \( -name simulator-server -o -name 'simulator-server.exe' \) -type f)
else
GH_MSG=$(<"${GH_STDERR}")
rm -f "${GH_STDERR}"
echo " ⚠ ${AGENT_ASSET} not downloaded — physical Android device support will be unavailable"
[[ -n "${GH_MSG}" ]] && printf ' gh: %s\n' "${GH_MSG//$'\n'/$'\n gh: '}"
fi
rm -rf "${AGENT_TMP}"
# Only the macOS binary carries an Apple signature; codesign would noisily fail
# on the others.
if command -v codesign &>/dev/null && [[ -f "${DEST_DIR}/darwin/simulator-server" ]]; then
codesign -dvv "${DEST_DIR}/darwin/simulator-server" 2>&1 \
|| echo "Warning: macOS signature verification failed"
fi