feat(plantare): schema v12 — bilateral signed columns + repo
Adds the deferred bilateral columns to Plantares (plantare-bilateral.md §"Schema delta"), all nullable/defaulted so v1 local rows coexist untouched: - pledgeId (the shared id both parties key their row by), debtorKey / creditorKey, debtorSignature / creditorSignature, movementId (the shared hand-over Movement for the provenance DAG), remoteState (proposed/accepted/declined — the handshake, distinct from status), returnKind (similar/workHours/other, default similar) + workHours. Repo: createPlantare grows optional bilateral params; plantareByPledgeId looks a row up by the shared id; applyPlantareSignatures counter-stamps an incoming accept; setPlantareRemoteState records a decline. The JSON codec carries every new field so they ride backups. Versioned migration is guarded/idempotent like the others; schema v12 dumped, test helper regenerated, migration test covers v1..v11 → v12. db + data + services 295/295 green.
This commit is contained in:
parent
3f622f7bf7
commit
01fba40ec2
11 changed files with 5322 additions and 17 deletions
|
|
@ -89,6 +89,70 @@ void main() {
|
|||
expect((await repo.watchPlantares().first).single.dueBy, due);
|
||||
});
|
||||
|
||||
test('a bilateral pledge stores keys/signatures and looks up by pledgeId',
|
||||
() async {
|
||||
final repo = newTestRepository(db);
|
||||
await repo.createPlantare(
|
||||
direction: PlantareDirection.iReturn,
|
||||
counterparty: 'Ana',
|
||||
pledgeId: 'pledge-1',
|
||||
debtorKey: 'dkey',
|
||||
creditorKey: 'ckey',
|
||||
creditorSignature: 'csig',
|
||||
remoteState: PlantareRemoteState.proposed,
|
||||
returnKind: PlantareReturnKind.workHours,
|
||||
workHours: 3,
|
||||
);
|
||||
|
||||
final row = await repo.plantareByPledgeId('pledge-1');
|
||||
expect(row, isNotNull);
|
||||
expect(row!.debtorKey, 'dkey');
|
||||
expect(row.creditorKey, 'ckey');
|
||||
expect(row.creditorSignature, 'csig');
|
||||
expect(row.debtorSignature, isNull);
|
||||
expect(row.remoteState, PlantareRemoteState.proposed);
|
||||
expect(row.returnKind, PlantareReturnKind.workHours);
|
||||
expect(row.workHours, 3);
|
||||
expect(await repo.plantareByPledgeId('nope'), isNull);
|
||||
});
|
||||
|
||||
test('accepting a proposal adds the counter-stub and flips to accepted',
|
||||
() async {
|
||||
final repo = newTestRepository(db);
|
||||
await repo.createPlantare(
|
||||
direction: PlantareDirection.owedToMe,
|
||||
pledgeId: 'pledge-2',
|
||||
debtorKey: 'dkey',
|
||||
creditorKey: 'ckey',
|
||||
creditorSignature: 'csig',
|
||||
remoteState: PlantareRemoteState.proposed,
|
||||
);
|
||||
|
||||
await repo.applyPlantareSignatures(
|
||||
pledgeId: 'pledge-2',
|
||||
debtorSignature: 'dsig',
|
||||
remoteState: PlantareRemoteState.accepted,
|
||||
movementId: 'mov-1',
|
||||
);
|
||||
|
||||
final row = await repo.plantareByPledgeId('pledge-2');
|
||||
expect(row!.debtorSignature, 'dsig');
|
||||
expect(row.creditorSignature, 'csig'); // untouched
|
||||
expect(row.remoteState, PlantareRemoteState.accepted);
|
||||
expect(row.movementId, 'mov-1');
|
||||
});
|
||||
|
||||
test('a v1 local note keeps the bilateral columns null (defaults)', () async {
|
||||
final repo = newTestRepository(db);
|
||||
final id = await repo.createPlantare(direction: PlantareDirection.iReturn);
|
||||
final row = (await repo.watchPlantares().first).single;
|
||||
expect(row.id, id);
|
||||
expect(row.pledgeId, isNull);
|
||||
expect(row.debtorKey, isNull);
|
||||
expect(row.remoteState, isNull);
|
||||
expect(row.returnKind, PlantareReturnKind.similar); // default
|
||||
});
|
||||
|
||||
test('commitments survive a backup round-trip (in exportInventory/import)',
|
||||
() async {
|
||||
final repoA = newTestRepository(db);
|
||||
|
|
@ -98,6 +162,12 @@ void main() {
|
|||
varietyId: vid,
|
||||
counterparty: 'Colectivo semillero',
|
||||
owedDescription: 'una mazorca',
|
||||
pledgeId: 'pledge-3',
|
||||
debtorKey: 'dkey',
|
||||
creditorKey: 'ckey',
|
||||
debtorSignature: 'dsig',
|
||||
creditorSignature: 'csig',
|
||||
remoteState: PlantareRemoteState.accepted,
|
||||
);
|
||||
|
||||
final snapshot = await repoA.exportInventory();
|
||||
|
|
@ -110,5 +180,10 @@ void main() {
|
|||
final onB = await repoB.watchPlantares().first;
|
||||
expect(onB.single.counterparty, 'Colectivo semillero');
|
||||
expect(onB.single.owedDescription, 'una mazorca');
|
||||
// The bilateral form rides the backup too.
|
||||
expect(onB.single.pledgeId, 'pledge-3');
|
||||
expect(onB.single.debtorSignature, 'dsig');
|
||||
expect(onB.single.creditorSignature, 'csig');
|
||||
expect(onB.single.remoteState, PlantareRemoteState.accepted);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue