Skip to content

Instantly share code, notes, and snippets.

@drewstone
Created October 20, 2026 23:24
Show Gist options
  • Select an option

  • Save drewstone/3ef2a45d2dbc454965edbf9ded1c05af to your computer and use it in GitHub Desktop.

Select an option

Save drewstone/3ef2a45d2dbc454965edbf9ded1c05af to your computer and use it in GitHub Desktop.
Sandbox SDK error class split: byte-identical move and public export evidence
#!/usr/bin/env node
// One-off delivery evidence, deliberately outside product source.
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { resolve } from 'node:path';
const [base, sdkArgument] = process.argv.slice(2);
assert(base && sdkArgument, 'Usage: check-error-classes-move.mjs <base> <sdk-directory>');
const sdk = resolve(sdkArgument);
const ts = createRequire(resolve(sdk, 'package.json'))('typescript');
const sourcePath = 'products/sandbox/sdk/src/errors.ts';
const before = execFileSync('git', ['show', `${base}:${sourcePath}`], { cwd: sdk, encoding: 'utf8' });
const after = readFileSync(resolve(sdk, 'src/errors.ts'), 'utf8');
const moved = readFileSync(resolve(sdk, 'src/error-classes.ts'), 'utf8');
const parse = text => {
const file = ts.createSourceFile('errors.ts', text, ts.ScriptTarget.Latest, true);
assert.equal(file.parseDiagnostics.length, 0);
return file;
};
const original = parse(before), current = parse(after), owner = parse(moved);
const declarations = file => file.statements.filter(node => !ts.isImportDeclaration(node) && !ts.isExportDeclaration(node));
const text = (file, node) => file.text.slice(node.getFullStart(), node.end).trim();
const exported = node => node.modifiers?.some(m => m.kind === ts.SyntaxKind.ExportKeyword);
const name = node => node.name?.text ?? node.declarationList.declarations[0].name.text;
const expectedMoved = declarations(original).filter(node => exported(node) && !ts.isFunctionDeclaration(node));
const retained = declarations(original).filter(node => !expectedMoved.includes(node));
assert.deepEqual(declarations(owner).map(node => text(owner, node)), expectedMoved.map(node => text(original, node)), 'All 27 moved declarations/JSDoc must be byte-identical and in original order');
assert.deepEqual(declarations(current).map(node => text(current, node)), retained.map(node => text(original, node)), 'All parsing declarations/JSDoc must remain byte-identical and in original order');
const reexports = current.statements.filter(ts.isExportDeclaration);
assert.equal(reexports.length, 1);
assert.equal(reexports[0].moduleSpecifier.text, './error-classes.js');
assert(reexports[0].exportClause && ts.isNamedExports(reexports[0].exportClause));
assert.deepEqual(reexports[0].exportClause.elements.map(item => {
assert(!item.propertyName, 'No renamed compatibility exports');
return item.name.text;
}).sort(), expectedMoved.map(name).sort());
const beforeExports = declarations(original).filter(exported).map(name).sort();
const afterExports = [...declarations(current).filter(exported).map(name), ...reexports[0].exportClause.elements.map(item => item.name.text)].sort();
assert.deepEqual(afterExports, beforeExports, 'The original import path exposes exactly the same 30 names');
const classImports = owner.statements.filter(ts.isImportDeclaration);
assert.equal(classImports.length, 1);
assert.equal(classImports[0].moduleSpecifier.text, './create-receipt-types.js');
assert.equal(classImports[0].importClause.isTypeOnly, true, 'Class owner has no runtime dependency or reverse edge');
const imports = current.statements.filter(ts.isImportDeclaration);
assert.equal(imports.length, 2);
assert.equal(imports[0].moduleSpecifier.text, '@tangle-network/runtime-contracts/file-transfer', 'Keep original runtime dependency evaluation before the class owner');
assert.equal(imports[1].moduleSpecifier.text, './error-classes.js');
for (const binding of imports[1].importClause.namedBindings.elements) {
assert(!binding.propertyName);
assert(expectedMoved.some(node => name(node) === binding.name.text));
}
const lines = value => value.split('\n').length - Number(value.endsWith('\n'));
assert(lines(after) < 1000 && lines(moved) < 1000);
console.log(JSON.stringify({
base, originalLines: lines(before), parsingLines: lines(after), classesLines: lines(moved),
movedDeclarations: expectedMoved.length, retainedDeclarations: retained.length,
publicExports: beforeExports.length, movedAndRetainedBodiesWithJSDoc: 'byte-identical',
constructorAndSetIdentity: 'one declaration each, original-path direct reexports',
classOwnerRuntimeDependencies: 0, deadCodeRemoved: 0, provenDuplicateOwnersRemoved: 0,
netSourceLines: lines(after) + lines(moved) - lines(before),
}, null, 2));
{
"base": "551b9daadd10cfea2b2b7b4f91b0355e546be94b",
"originalLines": 1177,
"parsingLines": 633,
"classesLines": 605,
"movedDeclarations": 27,
"retainedDeclarations": 21,
"publicExports": 30,
"movedAndRetainedBodiesWithJSDoc": "byte-identical",
"constructorAndSetIdentity": "one declaration each, original-path direct reexports",
"classOwnerRuntimeDependencies": 0,
"deadCodeRemoved": 0,
"provenDuplicateOwnersRemoved": 0,
"netSourceLines": 61
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment