mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 10:23:17 +08:00
feat(delivery): preserve text format intent
This commit is contained in:
parent
73f262711b
commit
dd66f5cbe1
5 changed files with 177 additions and 12 deletions
|
|
@ -330,3 +330,17 @@ test('mixed artifacts preserve order and merge existing receipt semantics', asyn
|
|||
await assertReleased(image);
|
||||
await assertReleased(file);
|
||||
});
|
||||
|
||||
test('a definitively failed base delivery is not treated as user-visible', async () => {
|
||||
const delivery = await deliverOutboundArtifacts({
|
||||
baseReceipt: createDeliveryReceipt({
|
||||
deliveryId: 'failed-text',
|
||||
presentation: 'telegram-rich-final',
|
||||
deliveryOutcome: 'failed',
|
||||
reason: 'telegram-provider-rejected',
|
||||
}),
|
||||
channelKey: 'telegram',
|
||||
});
|
||||
|
||||
assert.equal(delivery.userVisible, false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,10 +5,38 @@ import {
|
|||
artifactOutcomeForError,
|
||||
createArtifactFailureReceipt,
|
||||
createDeliveryReceipt,
|
||||
createTextDeliveryBlock,
|
||||
mergeDeliveryReceipts,
|
||||
providerMessageIdsFor,
|
||||
} from '../src/channels/shared/semantic/delivery.mjs';
|
||||
|
||||
test('text DeliveryBlocks preserve explicit format and legacy strings default to plain', () => {
|
||||
const legacy = createTextDeliveryBlock('legacy *text*');
|
||||
const markdown = createTextDeliveryBlock({
|
||||
kind: 'text',
|
||||
text: '# Harness answer',
|
||||
format: 'markdown',
|
||||
});
|
||||
|
||||
assert.deepEqual(legacy, {
|
||||
kind: 'text',
|
||||
text: 'legacy *text*',
|
||||
format: 'plain',
|
||||
});
|
||||
assert.deepEqual(markdown, {
|
||||
kind: 'text',
|
||||
text: '# Harness answer',
|
||||
format: 'markdown',
|
||||
});
|
||||
assert.equal(Object.isFrozen(legacy), true);
|
||||
assert.equal(Object.isFrozen(markdown), true);
|
||||
assert.throws(
|
||||
() => createTextDeliveryBlock({ kind: 'text', text: 'x', format: 'html' }),
|
||||
/plain or markdown/,
|
||||
);
|
||||
assert.throws(() => createTextDeliveryBlock(' '), /non-empty text/);
|
||||
});
|
||||
|
||||
test('DeliveryReceipt validates and freezes the shared versioned contract', () => {
|
||||
const receipt = createDeliveryReceipt({
|
||||
deliveryId: 'delivery-1',
|
||||
|
|
@ -102,3 +130,32 @@ test('text and multiple artifact attempts merge into one authoritative receipt',
|
|||
],
|
||||
});
|
||||
});
|
||||
|
||||
test('DeliveryReceipt optionally preserves final delivery outcome without changing legacy receipts', () => {
|
||||
const legacy = createDeliveryReceipt({
|
||||
deliveryId: 'legacy',
|
||||
presentation: 'telegram-text',
|
||||
});
|
||||
const uncertain = createDeliveryReceipt({
|
||||
deliveryId: 'rich',
|
||||
presentation: 'telegram-rich-final',
|
||||
deliveryOutcome: 'unknown',
|
||||
reason: 'telegram-timeout',
|
||||
});
|
||||
|
||||
assert.equal(Object.hasOwn(legacy, 'deliveryOutcome'), false);
|
||||
assert.deepEqual(uncertain, {
|
||||
schemaVersion: 1,
|
||||
deliveryId: 'rich',
|
||||
presentation: 'telegram-rich-final',
|
||||
providerMessageIds: [],
|
||||
deliveryOutcome: 'unknown',
|
||||
reason: 'telegram-timeout',
|
||||
artifacts: [],
|
||||
});
|
||||
assert.throws(() => createDeliveryReceipt({
|
||||
deliveryId: 'invalid',
|
||||
presentation: 'telegram-rich-final',
|
||||
deliveryOutcome: 'maybe',
|
||||
}), /deliveryOutcome/);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue