Files
moyi-model-intelligence-hub/prototype/tests/task-reconciliation.test.mjs
T

28 lines
1.8 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { reconciliationPayload } from '../src/services/task-reconciliation-state.ts'
const task = { id: 'test-task', updatedAt: '2026-10-21T11:00:00Z' }
test('success requires a server quote for the same frozen task version', () => {
assert.throws(() => reconciliationPayload(task, 'confirm_succeeded', 'bill', 'verified note', '', '', null, {}))
assert.throws(() => reconciliationPayload(task, 'confirm_succeeded', 'bill', 'verified note', '', '', { expectedCost: '1.44', expectedUpdatedAt: 'old' }, {}))
const value = reconciliationPayload(task, 'confirm_succeeded', ' bill ', ' verified note ', 'unused', 'unused', { expectedCost: '0.00000001', expectedUpdatedAt: task.updatedAt }, { usage: { input_tokens: 1, output_tokens: 1 } })
assert.equal(value.expectedCost, '0.00000001')
assert.equal(value.expectedUpdatedAt, task.updatedAt)
assert.equal(value.evidenceReference, 'bill')
assert.equal('providerTaskId' in value, false)
})
test('a failure confirmation cannot accidentally include a charge or generated result', () => {
const value = reconciliationPayload(task, 'confirm_failed', 'bill', 'verified note', 'unused', 'unused', { expectedCost: '100', expectedUpdatedAt: task.updatedAt }, { url: 'https://example.test/x' })
assert.equal('expectedCost' in value, false)
assert.equal('result' in value, false)
assert.equal('credentialFingerprint' in value, false)
})
test('resume only carries the original task binding and never a financial adjustment', () => {
const value = reconciliationPayload(task, 'resume_polling', 'bill', 'verified note', ' original-task ', ' fingerprint ', null, {})
assert.equal(value.providerTaskId, 'original-task')
assert.equal(value.credentialFingerprint, 'fingerprint')
assert.equal('result' in value, false)
assert.equal('expectedCost' in value, false)
})