chore(ship-review): extract shared review-runtime helpers — sc-1414 part 2, cluster 1 - #312
Conversation
…art 2, cluster 1 The clone gate's inventory (#308) flagged repository/state.mts as a 4-clone hub: fail/errorMessage/gitEnvironment/objectValue copy-pasted across repository/, cache/, and the setup-manifest family, plus a duplicated lstat-probe. New cli/lib/ship/review/shared/common.mts owns them; the lstat-probe case imports the already-exported reviewSetupStat instead of a local twin. Behavior-preserving by construction: objectValue now takes the caller's full message (each call site's string reconstructed byte-identically from its old template), and gitEnvironment takes optional extra pins (cache/root passes GIT_NO_LAZY_FETCH + GIT_TERMINAL_PROMPT; the stripped-GIT_* + OPTIONAL_LOCKS=0 base is shared). gitnexus flags the fan-in as HIGH (these feed the review-setup verification paths) — mitigated by string-identical messages, identical env composition, and the full cli suite green (1182 tests). Repo-wide clone scan 60 -> 54; the six ship/review cluster clones are gone rather than baselined. Remaining fail() copies in files the gate did not flag are left for opportunistic cleanup. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe change centralizes review-runtime helpers, updates manifest and setup validation messages, applies sanitized Git environments, and routes source projection metadata lookup through the setup runtime. ChangesReview runtime helper consolidation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cli/lib/ship/review/shared/common.mts (1)
25-35: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winEnforce the sanitized Git environment contract.
The final spread allows
extra.GIT_OPTIONAL_LOCKSto override the required value'0'. It also allows callers to reintroduceGIT_DIR,GIT_INDEX_FILE, or other strippedGIT_*variables. Current callers pass fixed values, but the shared helper should enforce this invariant.Restrict Git overrides to an explicit allowlist and apply
GIT_OPTIONAL_LOCKS: '0'last.Proposed fix
export function gitEnvironment(extra: Record<string, string> = {}): NodeJS.ProcessEnv { const env = { ...process.env }; for (const name of Object.keys(env)) { if (name.startsWith('GIT_')) delete env[name]; } - return { ...env, GIT_OPTIONAL_LOCKS: '0', ...extra }; + const allowedGitOverrides = new Set(['GIT_NO_LAZY_FETCH', 'GIT_TERMINAL_PROMPT']); + for (const name of Object.keys(extra)) { + if (name.startsWith('GIT_') && !allowedGitOverrides.has(name)) { + fail(`unsupported Git environment override: ${name}`); + } + } + return { ...env, ...extra, GIT_OPTIONAL_LOCKS: '0' }; }🤖 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 `@cli/lib/ship/review/shared/common.mts` around lines 25 - 35, Update gitEnvironment so extra overrides are restricted to an explicit allowlist of permitted non-sanitized variables, preventing callers from restoring stripped GIT_* entries. Apply the allowlisted overrides before setting GIT_OPTIONAL_LOCKS to '0' last, ensuring that value cannot be overridden.
🤖 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.
Nitpick comments:
In `@cli/lib/ship/review/shared/common.mts`:
- Around line 25-35: Update gitEnvironment so extra overrides are restricted to
an explicit allowlist of permitted non-sanitized variables, preventing callers
from restoring stripped GIT_* entries. Apply the allowlisted overrides before
setting GIT_OPTIONAL_LOCKS to '0' last, ensuring that value cannot be
overridden.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 24f41954-17b9-44a7-9409-df83af8ab1fb
📒 Files selected for processing (8)
cli/lib/ship/review/cache/root.mtscli/lib/ship/review/repository/manifest.mtscli/lib/ship/review/repository/state.mtscli/lib/ship/review/setup-manifest-parse.mtscli/lib/ship/review/setup-manifest.mtscli/lib/ship/review/setup-profile.mtscli/lib/ship/review/shared/common.mtscli/lib/ship/review/source-projection.mts
Shortcut sc-1414 part 2, cluster 1 (epic 1399) — the biggest cluster from #308's clone inventory:
repository/state.mtswas a 4-clone hub.What
New
cli/lib/ship/review/shared/common.mtsowns the copy-pastedfail/errorMessage/objectValue/gitEnvironment;source-projection.mtsnow imports the already-exportedreviewSetupStatinstead of a localsafeStattwin. Seven files converted (repository/state, repository/manifest, cache/root, setup-manifest, setup-manifest-parse, setup-profile, source-projection). Net −36 lines.Behavior-preservation (these feed the review-setup verification paths — gitnexus flagged HIGH fan-in)
objectValuenow takes the caller's full message; every call site's string was reconstructed byte-identically from its old per-file template (three different wordings preserved exactly).gitEnvironment(extra?)composes the same env on both call sites: shared base = GIT_*-stripped +GIT_OPTIONAL_LOCKS=0;cache/rootlayersGIT_NO_LAZY_FETCH=1+GIT_TERMINAL_PROMPT=0exactly as before.Repo-wide clone scan 60 → 54 — the six cluster clones are gone rather than baselined. Remaining
fail()copies in unflagged files left for opportunistic cleanup. Next clusters (sync/LegacyAssetManifest, install-hooks, critique, decisions, reconcile) follow as separate PRs.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Refactor