feat(versionresolver): support skip-forward resume for orphan ledger versions
This commit is contained in:
@@ -109,18 +109,48 @@ tap.test('computePlan: returns sub-slice when target is mid-chain', async () =>
|
||||
expect(plan.map((s) => s.id)).toEqual(['a', 'b']);
|
||||
});
|
||||
|
||||
tap.test('computePlan: throws when current does not match any step from', async () => {
|
||||
tap.test('computePlan: skip-forward resume when current is inside a step range', async () => {
|
||||
// Chain: 1.0.0 → 1.1.0 → 2.0.0 → 3.0.0
|
||||
// Orphan install is stamped at 1.2.5 (between steps b and c). The planner
|
||||
// should resume at the first step whose toVersion > 1.2.5 (step b: 1.1.0 → 2.0.0),
|
||||
// then run step c to reach the target.
|
||||
const steps = [
|
||||
makeStep('a', '1.0.0', '1.1.0'),
|
||||
makeStep('b', '1.1.0', '2.0.0'),
|
||||
makeStep('c', '2.0.0', '3.0.0'),
|
||||
];
|
||||
const plan = VersionResolver.computePlan(steps, '1.2.5', '3.0.0');
|
||||
expect(plan.map((s) => s.id)).toEqual(['b', 'c']);
|
||||
});
|
||||
|
||||
tap.test('computePlan: skip-forward when current is below the first step fromVersion', async () => {
|
||||
// Chain: 1.0.0 → 1.1.0 → 2.0.0
|
||||
// Current 0.9.0 (below the chain's starting point). Should resume at step a
|
||||
// (its toVersion 1.1.0 > 0.9.0).
|
||||
const steps = [
|
||||
makeStep('a', '1.0.0', '1.1.0'),
|
||||
makeStep('b', '1.1.0', '2.0.0'),
|
||||
];
|
||||
const plan = VersionResolver.computePlan(steps, '0.9.0', '2.0.0');
|
||||
expect(plan.map((s) => s.id)).toEqual(['a', 'b']);
|
||||
});
|
||||
|
||||
tap.test('computePlan: throws TARGET_NOT_REACHABLE when current is past all step toVersions', async () => {
|
||||
// Chain: 1.0.0 → 1.1.0 → 2.0.0
|
||||
// Current 2.5.0 (past the chain's ending point), target 3.0.0.
|
||||
// No step can advance us (all toVersions ≤ 2.5.0 < target). Throw.
|
||||
const steps = [
|
||||
makeStep('a', '1.0.0', '1.1.0'),
|
||||
makeStep('b', '1.1.0', '2.0.0'),
|
||||
];
|
||||
let caught: SmartMigrationError | undefined;
|
||||
try {
|
||||
VersionResolver.computePlan(steps, '1.0.5', '2.0.0');
|
||||
VersionResolver.computePlan(steps, '2.5.0', '3.0.0');
|
||||
} catch (err) {
|
||||
caught = err as SmartMigrationError;
|
||||
}
|
||||
expect(caught!.code).toEqual('CHAIN_NOT_AT_CURRENT');
|
||||
expect(caught).toBeDefined();
|
||||
expect(caught!.code).toEqual('TARGET_NOT_REACHABLE');
|
||||
});
|
||||
|
||||
tap.test('computePlan: throws when target overshoots', async () => {
|
||||
|
||||
Reference in New Issue
Block a user