#!/usr/bin/env node /** * 远端 git.status 脚本的真 sh + 真 git 独立验证(随 2.4.33 引入,长期可复跑)。 * * 为什么需要它:单测(sidebar-0280-git-status / perf-remote-open-2433)把 SSH 出口整个 * 换成了伪造出口,脚本本身的 POSIX 正确性未被覆盖。本脚本在 WSL 的真 sh + 真 git 里 * 用【真实现 gitStatusRemote + 真解析器 + 真 handler】跑(只把 runPooled 换成 * `wsl -e sh -c`,其余一字不改),覆盖 numstat 短路的四个分支 + 降级链 + NOTREPO: * * E1 干净仓库:无 UNSTAGED/STAGED 段 → entries=[],分支身份齐全(短路生效且无害) * E2 脏仓库(暂存+未暂存+改名+未跟踪):守卫放行 → 行数与真 git numstat 一致 * E3 只有未跟踪:tracked=0 → 段缺席 → ?? 条目无行数(同本地 pathspec=[] 口径) * E4 PATH shim 让 status 失败:V=none → $T 不存在 → ${N:-0} 兜底 → 不炸、空页 * E5 非 git 目录 / 不存在的目录 → NOTREPO / isRepo:false(回归确认) * * 只读:不修改 lib/,临时仓库全部建在 WSL /tmp 下并用完即删。 */ import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { execFileSync } from 'node:child_process' const root = fileURLToPath(new URL('..', import.meta.url)) const src = readFileSync(root + '/lib/index.js', 'utf8') let pass = 0, fail = 0 const check = (cond, label) => { if (cond) { pass++; console.log(' ✓ ' + label) } else { fail++; console.log(' ✗ FAIL: ' + label) } } function grab(text, name) { const start = text.indexOf(name) if (start < 0) throw new Error(name + ' not found') const declStart = text.lastIndexOf('\n', start) let i = text.indexOf('{', start) let depth = 0 for (; i < text.length; i++) { if (text[i] === '{') depth++ else if (text[i] === '}') { depth--; if (depth === 0) break } } return text.slice(declStart + 1, i + 1) } const GIT_READ_ENV = /const GIT_READ_ENV = "([^"]+)"/.exec(src)[1] const STATUS_BLOCK = (() => { const a = src.indexOf('// ---- better-sidebar 0.28.0 的 git.status 形状') const b = src.indexOf(' async function gitStatusImpl') if (a < 0 || b < 0 || b <= a) throw new Error('lib/index.js 里找不到 git.status 实现段(标记被改动?)') return src.slice(a, b) })() /** 可注入的前缀(E4 用 PATH shim,脚本正文一字不改)。 */ let wslPrefix = '' /** wsl -e sh -c