deviant/scripts/migrate-chipnet-tests.mjs
walerikus 599202a721 chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP
Snapshot of accumulated work-in-progress on top of the baseline commit.

This session — retire Tier B from the wallet shell (single-tier model, glossary
"Tiers & trust"):
- SendFlow.tsx: BCH-only; removed the non-functional Tier-B send path, the D-4/D-5
  raw-BCH co-display, and the ADR-0013 friction ladder.
- ArtemisionScreen.tsx: Create wizard collapsed to a single 5-step on-chain genesis
  flow; tier-selection step + Tier-B branch (prepareTierBImport) deleted.
- QuickActions.tsx / SettingsScreen.tsx: receive note reworded; "Send friction
  thresholds" + "Tier explainer" rows removed; registry-trust note reworded.
- Verified: tsc clean, vitest 74/74, full preview walkthrough, no console errors.

Pre-existing uncommitted work also folded in:
- USDm -> FIATm family rename/reorg (Parameters/FIATm/, design records)
- ~130 chipnet + sim-fiatm scripts (catalytic-converter, hyperinflation backtests)
- snapshots 0153-0168; wiki updates (glossary, decisions, index); ADR-0044/0045
- mockups + additional shell screens (Agora, Apps, MainScreen, AssetDetail, ...)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 01:01:37 +02:00

154 lines
5.5 KiB
JavaScript

#!/usr/bin/env node
/**
* migrate-chipnet-tests.mjs — one-shot move of every chipnet test-state JSON
* from the project root into a new `ChipnetTests/` folder, with all script
* references updated. Wallet-key files (.chipnet-keys*.json) are explicitly
* NOT moved — they're wallet identity, referenced by ~70+ scripts and the
* shell tooling, and stay at root by design.
*
* Idempotent: re-running after the first move is a no-op (no files to move,
* scripts already updated).
*/
import { readdirSync, readFileSync, writeFileSync, renameSync, mkdirSync, existsSync, statSync } from 'node:fs';
import { join } from 'node:path';
const ROOT = join(import.meta.dirname, '..');
const DEST = 'ChipnetTests';
const DEST_ABS = join(ROOT, DEST);
const STATE_PATTERN = /^\.chipnet-[a-z0-9-]+\.json$/i;
const KEYS_PATTERN = /^\.chipnet-keys(-[a-z0-9]+)?\.json$/i;
function discoverStateFiles() {
return readdirSync(ROOT).filter((f) => STATE_PATTERN.test(f) && !KEYS_PATTERN.test(f));
}
function ensureDir(p) {
if (!existsSync(p)) mkdirSync(p, { recursive: true });
}
function moveFiles(files) {
ensureDir(DEST_ABS);
const moved = [];
for (const f of files) {
const src = join(ROOT, f);
const dst = join(DEST_ABS, f);
if (existsSync(dst)) {
console.log(` skip ${f} (already at destination)`);
continue;
}
if (!existsSync(src)) {
console.log(` skip ${f} (source missing)`);
continue;
}
renameSync(src, dst);
moved.push(f);
}
console.log(` moved ${moved.length} files into ${DEST}/`);
return moved;
}
function listScriptFiles() {
const dir = join(ROOT, 'scripts');
return readdirSync(dir)
.filter((f) => /\.(mjs|js|ts)$/.test(f))
.map((f) => join(dir, f));
}
/**
* Rewrite hard-coded references to each moved filename so the script reads
* from ChipnetTests/. We accept a few common path styles used in the repo:
* join(ROOT, '.chipnet-X.json') → join(ROOT, 'ChipnetTests', '.chipnet-X.json')
* '.chipnet-X.json' → 'ChipnetTests/.chipnet-X.json' (only if not already prefixed)
*/
function updateScripts(movedFiles) {
const scripts = listScriptFiles();
let totalReplacements = 0;
const updatedFiles = [];
for (const scriptPath of scripts) {
let content = readFileSync(scriptPath, 'utf8');
let scriptReplacements = 0;
for (const fname of movedFiles) {
// Escape filename for regex (only `.` matters in chipnet-* names).
const escaped = fname.replace(/\./g, '\\.');
// Style 1: join(ROOT, '.chipnet-X.json') — add 'ChipnetTests' segment.
const join1 = new RegExp(`join\\(\\s*ROOT\\s*,\\s*(['"])${escaped}\\1\\s*\\)`, 'g');
const next1 = content.replace(join1, (m, q) => `join(ROOT, ${q}${DEST}${q}, ${q}${fname}${q})`);
if (next1 !== content) {
const n = (content.match(join1) || []).length;
scriptReplacements += n;
content = next1;
}
// Style 2: bare string literal '.chipnet-X.json' — prefix with ChipnetTests/.
// Skip if already part of an updated join() (matched above) or already prefixed.
const bare = new RegExp(`(['"\`])${escaped}\\1`, 'g');
const next2 = content.replace(bare, (m, q, offset, str) => {
// Don't double-prefix if the preceding text already includes 'ChipnetTests'.
const window = str.slice(Math.max(0, offset - 30), offset);
if (window.includes(DEST)) return m;
return `${q}${DEST}/${fname}${q}`;
});
if (next2 !== content) {
const before = (content.match(bare) || []).length;
const afterStill = (next2.match(bare) || []).length;
scriptReplacements += before - afterStill;
content = next2;
}
}
if (scriptReplacements > 0) {
writeFileSync(scriptPath, content);
updatedFiles.push({ path: scriptPath.replace(ROOT + '\\', '').replace(ROOT + '/', ''), n: scriptReplacements });
totalReplacements += scriptReplacements;
}
}
console.log(` updated ${updatedFiles.length} script files with ${totalReplacements} path edits`);
for (const u of updatedFiles) console.log(` ${u.path} (${u.n})`);
}
function updateGitignore() {
const gi = join(ROOT, '.gitignore');
let content = readFileSync(gi, 'utf8');
if (content.includes(`${DEST}/`)) {
console.log(' .gitignore already mentions ChipnetTests/');
return;
}
const marker = '.chipnet-*.json';
const idx = content.indexOf(marker);
if (idx === -1) {
content += `\n# Chipnet test-state JSONs (moved by scripts/migrate-chipnet-tests.mjs)\n${DEST}/\n`;
} else {
const lineEnd = content.indexOf('\n', idx);
content = content.slice(0, lineEnd + 1) +
`# Chipnet test-state JSONs (moved by scripts/migrate-chipnet-tests.mjs).\n${DEST}/\n` +
content.slice(lineEnd + 1);
}
writeFileSync(gi, content);
console.log(' added ChipnetTests/ to .gitignore');
}
function main() {
console.log('=== chipnet-test migration ===');
const files = discoverStateFiles();
console.log(`discovered ${files.length} test-state files at root (keys excluded)`);
if (files.length === 0) {
console.log('nothing to move — already clean.');
process.exit(0);
}
const moved = moveFiles(files);
if (moved.length === 0) {
console.log('files already at destination — checking script references only…');
}
// Update scripts for the full original list (handles the case where files were
// moved earlier but scripts still need touching).
updateScripts(files);
updateGitignore();
console.log('=== done ===');
}
main();