|
19 | 19 | * # the third pass (#30053): plan (or apply) the hand series' private docblocks |
20 | 20 | * node scripts/codemod-split-engine.mjs --hand-docs --verify --base <ref> |
21 | 21 | * # re-prove the third pass on disk against engine.ts and its hand modules at <ref> |
| 22 | + * node scripts/codemod-split-engine.mjs --members <a,b> [--write] |
| 23 | + * # the fourth pass (#30055): plan (or apply) moving the named methods onto the split class |
| 24 | + * node scripts/codemod-split-engine.mjs --members --verify --base <ref> |
| 25 | + * # re-prove the fourth pass on disk against engine.ts and its modules at <ref> |
22 | 26 | * node scripts/codemod-split-engine.mjs --self-test |
23 | 27 | * node scripts/codemod-split-engine.mjs --help # this usage, on any tree (split or not) |
24 | 28 | * |
|
148 | 152 | * the class. Its section below (`HAND_STUB_MARK`) states the rule, the slices |
149 | 153 | * (`--modules`) and the proof, the undo of every move. |
150 | 154 | * |
| 155 | + * ## The fourth pass: named methods onto the split class (#30055) |
| 156 | + * |
| 157 | + * The first pass runs on an unsplit file only, so a method a stay rule held |
| 158 | + * when `main` was split (a path pin since retired, a return type since |
| 159 | + * spelled) moves by `--members`: on the split file, as the first pass would |
| 160 | + * have moved it, into the facet module it wrote. Its section below |
| 161 | + * (`MEMBERS_CARD`) states what it grows, what it refuses and the undo proof. |
| 162 | + * |
151 | 163 | * ts-morph is a root devDependency, resolved from the root manifest, as the |
152 | 164 | * pilot takes it. |
153 | 165 | * |
@@ -3917,6 +3929,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ |
3917 | 3929 | 'refusals': 6, |
3918 | 3930 | 'scoped classes (second pass)': 16, |
3919 | 3931 | 'hand-series docblocks (third pass)': 19, |
| 3932 | + 'named methods onto the split class (fourth pass)': 18, |
3920 | 3933 | }); |
3921 | 3934 | const SELF_TEST_BATTERY_FLOOR = 5; |
3922 | 3935 |
|
@@ -4094,6 +4107,32 @@ function needleInMethod(n: number): number { |
4094 | 4107 | `; |
4095 | 4108 | } |
4096 | 4109 |
|
| 4110 | +/** |
| 4111 | + * The fourth pass's fixture: the first pass's, with two methods a pin held |
| 4112 | + * when it split the file (`FOURTH_FIXTURE_PINS`), one private that reads a |
| 4113 | + * new host member, a new private static and an import only it reads, one |
| 4114 | + * protected that names a type only it imports. |
| 4115 | + */ |
| 4116 | +const FOURTH_FIXTURE_PINS = Object.freeze({ ...FIXTURE_PINS, pinnedHost: 'a fixture reader', pinnedTyped: 'a fixture reader' }); |
| 4117 | +function fourthFixtureSource() { |
| 4118 | + const pad = Array.from({ length: 12 }, (_, i) => ` const p${i} = ${i};`).join('\n'); |
| 4119 | + const extra = ` |
| 4120 | + /** A pinned private docblock: the fourth pass moves it with the body. */ |
| 4121 | + private async pinnedHost(object: string): Promise<string> { |
| 4122 | +${pad} |
| 4123 | + return this.other(object) + String(this.count) + String(this.knex) + helperImported(object) + String(ObjectQL.SECRET) + String(ObjectQL.bump) + fourthOnly(); |
| 4124 | + } |
| 4125 | +
|
| 4126 | + /** A pinned protected docblock: it stays on the class. */ |
| 4127 | + protected pinnedTyped(x: FourthShape): number { |
| 4128 | +${pad} |
| 4129 | + return x.n; |
| 4130 | + } |
| 4131 | +`; |
| 4132 | + return fixtureSource(extra).replace("import { seamHelper } from './engine-seam.js';\n", |
| 4133 | + "import { seamHelper } from './engine-seam.js';\nimport { fourthOnly } from './fourth-only.js';\nimport type { FourthShape } from './fourth-shape.js';\n"); |
| 4134 | +} |
| 4135 | + |
4097 | 4136 | const FIXTURE_SCOPED_CLASSES = Object.freeze([ |
4098 | 4137 | ['ObjectRepository', 'engine-object-repository.ts', 'Repository'], |
4099 | 4138 | ['ScopedContext', 'engine-scoped-context.ts', 'Context'], |
@@ -4552,6 +4591,63 @@ async function selfTest() { |
4552 | 4591 | refused(() => planHandDocs(tm, input, mods, { modules: ['engine-gone.ts'] }))); |
4553 | 4592 | } |
4554 | 4593 |
|
| 4594 | + open('named methods onto the split class (fourth pass)'); |
| 4595 | + { |
| 4596 | + const opts = { anchors: FIXTURE_ANCHORS, pins: FIXTURE_PINS, needles: FIXTURE_NEEDLES, classNeedles: FIXTURE_CLASS_NEEDLES }; |
| 4597 | + const source = fourthFixtureSource(); |
| 4598 | + const split = generate(tm, source, plan(tm, source, { ...opts, pins: FOURTH_FIXTURE_PINS })); |
| 4599 | + const input = split.host; |
| 4600 | + const mods = split.modules; |
| 4601 | + const names = ['pinnedTyped', 'pinnedHost']; |
| 4602 | + check('the first pass keeps the pinned methods on the class (path-reader)', |
| 4603 | + input.includes(' private async pinnedHost(object: string): Promise<string> {\n const p0') && input.includes(' protected pinnedTyped(x: FourthShape): number {\n const p0')); |
| 4604 | + const planned = planMembers(tm, input, mods, names, opts); |
| 4605 | + check('the plan takes both into their section\'s written module, in class order', |
| 4606 | + [...planned.modules.keys()].join() === 'engine-lifecycle.ts' && planned.records.map((r) => r.name).join() === 'pinnedHost,pinnedTyped', |
| 4607 | + planned.records.map((r) => `${r.name}->${r.module}`).join()); |
| 4608 | + const out = generateMembers(tm, input, mods, planned); |
| 4609 | + const again = generateMembers(tm, input, mods, planMembers(tm, input, mods, names, opts)); |
| 4610 | + const head = new Map([...mods, ...out.modules]); |
| 4611 | + const v = verifyMembers(tm, input, out.host, mods, head, opts); |
| 4612 | + check('the generated moves prove against their base', v.failures.length === 0 && v.moved.length === 2, v.failures.join(' | ')); |
| 4613 | + check('two runs on one input write byte-identical trees', |
| 4614 | + treeHash(new Map([['h', out.host], ...out.modules])) === treeHash(new Map([['h', again.host], ...again.modules]))); |
| 4615 | + const lifecycle = out.modules.get('engine-lifecycle.ts') ?? ''; |
| 4616 | + check('each stub is the first pass\'s stub, `async` dropped', |
| 4617 | + out.host.includes(` private pinnedHost(object: string): Promise<string> {\n // ${MARK} The body moved to \`engine-lifecycle.ts\`, ${DOC_MOVED} (see \`LifecycleHost\`).\n return LifecycleFacet.pinnedHost.call(lifecycleHost.of(this), object);\n }`) && |
| 4618 | + out.host.includes(` protected pinnedTyped(x: FourthShape): number {\n // ${MARK} The body moved to \`engine-lifecycle.ts\`.\n return LifecycleFacet.pinnedTyped(x);\n }`), |
| 4619 | + out.host.slice(out.host.indexOf('pinnedHost(') - 80, out.host.indexOf('pinnedHost(') + 300)); |
| 4620 | + check('a private docblock moves with its body; a protected one stays on the class', |
| 4621 | + lifecycle.includes(' /** A pinned private docblock: the fourth pass moves it with the body. */\n static async pinnedHost(') && !out.host.includes('A pinned private docblock') && |
| 4622 | + out.host.includes(' /** A pinned protected docblock: it stays on the class. */\n protected pinnedTyped(') && lifecycle.includes(` ${placeholderDoc('pinnedTyped')}\n static pinnedTyped(`)); |
| 4623 | + const listed = headerNamesOf(lifecycle, 'Lifecycle')?.names ?? []; |
| 4624 | + check('the header lists both, in class order after the members declared above them', |
| 4625 | + listed.indexOf('pinnedHost') > listed.indexOf('generic') && listed.indexOf('pinnedTyped') === listed.indexOf('pinnedHost') + 1, listed.join()); |
| 4626 | + check('a host member only a moved body reads joins the interface and the factory', |
| 4627 | + lifecycle.includes(" readonly knex: ObjectQLClass['knex'];") && out.host.includes(' get knex() { return engine.knex; },') && !input.includes('get knex()')); |
| 4628 | + check('a private static only a moved body reads joins the statics route', |
| 4629 | + out.host.includes(" readonly bump: (typeof ObjectQL)['bump'];") && out.host.includes(' bump: { get: () => ObjectQL.bump },') && !input.includes("['bump']")); |
| 4630 | + check('the module imports what the moved members read, ahead of the leaf; engine.ts drops what only the bodies read and keeps the type a stub still names, and the proof names the drops', |
| 4631 | + /import \{ fourthOnly \} from '\.\/fourth-only\.js';\nimport type \{ FourthShape \} from '\.\/fourth-shape\.js';\n(import[^\n]*\n)*import[^\n]*'\.\/engine-top-level\.js'/.test(lifecycle) && |
| 4632 | + out.pruned.join() === 'fourthOnly,helperImported' && v.pruned.join() === 'fourthOnly,helperImported' && |
| 4633 | + out.host.includes("import type { FourthShape } from './fourth-shape.js';"), `${out.pruned} | ${v.pruned}`); |
| 4634 | + check('a name the class does not declare refuses', refused(() => planMembers(tm, input, mods, ['gone'], opts))); |
| 4635 | + check('a method already moved refuses', refused(() => planMembers(tm, input, mods, ['movable'], opts))); |
| 4636 | + check('a method a stay rule holds refuses (inferred-return-type, and a pin that still stands)', |
| 4637 | + refused(() => planMembers(tm, input, mods, ['inferred'], opts)) && refused(() => planMembers(tm, input, mods, ['pinnedMethod'], opts))); |
| 4638 | + const fails = (host, edited) => verifyMembers(tm, input, host, mods, new Map([...head, ...edited]), opts).failures.length > 0; |
| 4639 | + check('one edited character in a moved body fails', fails(out.host, [['engine-lifecycle.ts', lifecycle.replace('return x.n;', 'return x.n + 1;')]])); |
| 4640 | + check('a host member no body reads, in the interface and the factory, fails', fails( |
| 4641 | + out.host.replace(' get knex() { return engine.knex; },', ' get knex() { return engine.knex; },\n get zed() { return engine.zed; },'), |
| 4642 | + [['engine-lifecycle.ts', lifecycle.replace(" readonly knex: ObjectQLClass['knex'];", " readonly knex: ObjectQLClass['knex'];\n readonly zed: ObjectQLClass['zed'];")]])); |
| 4643 | + check('an import nothing in the module reads fails', fails(out.host, [['engine-lifecycle.ts', lifecycle.replace("import { fourthOnly } from './fourth-only.js';", "import { fourthOnly, unread } from './fourth-only.js';")]])); |
| 4644 | + check('a stub that kept `async` fails', fails(out.host.replace(' private pinnedHost(object: string)', ' private async pinnedHost(object: string)'), [])); |
| 4645 | + check('an edit elsewhere in engine.ts, or in a module no moved member is in, fails', |
| 4646 | + fails(out.host.replace(' return 2 + VIA_SEAM', ' return 3 + VIA_SEAM'), []) && |
| 4647 | + fails(out.host, [[LEAF_MODULE, (mods.get(LEAF_MODULE) ?? '').replace('const LOCAL_VALUE = 1;', 'const LOCAL_VALUE = 2;')]])); |
| 4648 | + check('a head that moved nothing fails', verifyMembers(tm, input, input, mods, mods, opts).failures.some((f) => f.startsWith('nothing moved'))); |
| 4649 | + } |
| 4650 | + |
4555 | 4651 | const declared = Object.keys(SELF_TEST_BATTERIES); |
4556 | 4652 | if (declared.length < SELF_TEST_BATTERY_FLOOR) { |
4557 | 4653 | failed += 1; |
|
0 commit comments