/**
* Decodes the RPC recording goldens at a base commit and in the working tree, and prints which
* recorded behaviour moved: per golden, the checkpoint, the field and the JSON path, with both
* values. The committed files are content-addressed JSON, so their raw diff is hashes.
*
* pnpm --dir mobile rpc:diff [] [--summary ]
*
* `` defaults to the merge base with origin/main. `--summary` also appends a capped Markdown
* report to that file (CI passes `$GITHUB_STEP_SUMMARY`). A behaviour change exits 0: this reports,
* the recording suites judge. It exits non-zero only when git or a golden cannot be read.
*/
import { appendFileSync, readdirSync, readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { runProcess } from '../../src/shared/child-process/run-process.ts'
import { diffGoldenSets, formatChangeMarkdown, formatChangeText } from './rpc-diff-report.ts'
import {
decodeGoldenFile,
type DecodedGolden
} from '../src/test-support/rpc-recording/golden-difference.ts'
const GOLDENS = 'mobile/rpc-foundation/goldens'
// The corpus is ~16 MB; the default 8 MB capture would clip the batch read.
const MAX_OUTPUT_BYTES = 256 * 1024 * 1024
const root = resolve(import.meta.dirname, '../..')
async function git(args: string[], input?: string): Promise {
const result = await runProcess({
program: 'git',
args,
cwd: root,
input,
maxOutputBytes: MAX_OUTPUT_BYTES,
timeoutMs: 120_000
})
if (result.code !== 0 || result.outputTruncated) {
throw new Error(`git ${args.join(' ')} failed: ${result.stderr.trim() || 'output clipped'}`)
}
return result.stdout
}
function goldenId(path: string): string | null {
const match = /([^/]+)\.json$/.exec(path)
return match ? match[1]! : null
}
/** One `cat-file --batch` for the whole corpus rather than a process per golden. */
async function readBase(base: string): Promise