76 lines
3.1 KiB
TypeScript
76 lines
3.1 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
buildLeaderTaskSummary,
|
|
formatShanghaiTimestamp,
|
|
isLeaderTaskSummaryStatus
|
|
} from '../src/leadership-task-summary.js';
|
|
|
|
const base = {
|
|
taskId: 'TASK-20260907-001',
|
|
businessRouteId: 'arrangement_hotel_create',
|
|
assigneeUsername: 'employee-a',
|
|
createdAt: '2026-09-07T00:05:06.000Z'
|
|
};
|
|
|
|
test('leader summary projects only stable outcomes', () => {
|
|
assert.equal(buildLeaderTaskSummary({ ...base, status: 'running' }), null);
|
|
assert.equal(buildLeaderTaskSummary({ ...base, status: 'awaiting_confirmation' }), null);
|
|
assert.equal(isLeaderTaskSummaryStatus('completed'), true);
|
|
assert.equal(isLeaderTaskSummaryStatus('execution_uncertain'), true);
|
|
assert.equal(isLeaderTaskSummaryStatus('running'), false);
|
|
});
|
|
|
|
test('completed leader summary exposes only whitelisted business identifiers', () => {
|
|
const result = buildLeaderTaskSummary({
|
|
...base,
|
|
status: 'completed',
|
|
successReceipt: {
|
|
group_numbers: ['LW-260907A-B', '张三', '13800138000'],
|
|
order_number: 'D12345',
|
|
customer_name: '绝密客户',
|
|
passenger_names: ['游客甲', '游客乙'],
|
|
phone: '13900139000',
|
|
url: 'https://secret.example/token',
|
|
technical_error: 'stack trace'
|
|
}
|
|
});
|
|
assert.ok(result);
|
|
assert.equal(result.milestone, 'final');
|
|
assert.equal(result.deliveryStatus, 'completed');
|
|
assert.match(result.messageText, /employee-a/);
|
|
assert.match(result.messageText, /安排酒店/);
|
|
assert.match(result.messageText, /LW-260907A-B/);
|
|
assert.match(result.messageText, /D12345/);
|
|
assert.match(result.messageText, /2026-09-07 08:05:06/);
|
|
assert.doesNotMatch(result.messageText, /绝密客户|游客甲|13800138000|13900139000|secret\.example|stack trace|张三/);
|
|
});
|
|
|
|
test('failure, uncertainty, cancellation and dry-run use stable safe wording', () => {
|
|
const failed = buildLeaderTaskSummary({ ...base, status: 'operation_blocked' });
|
|
const uncertain = buildLeaderTaskSummary({ ...base, status: 'saved_unverified' });
|
|
const cancelled = buildLeaderTaskSummary({ ...base, status: 'cancelled' });
|
|
const dryRun = buildLeaderTaskSummary({ ...base, status: 'dry_run' });
|
|
assert.equal(failed?.resultText, '本次工作未完成,请在平台查看业务结果。');
|
|
assert.equal(uncertain?.milestone, 'needs_review');
|
|
assert.match(uncertain?.messageText || '', /需人工核验|请勿重复提交/);
|
|
assert.equal(cancelled?.deliveryStatus, 'cancelled');
|
|
assert.match(dryRun?.resultText || '', /尚未正式提交/);
|
|
});
|
|
|
|
test('a stable result after needs-review produces one result-update milestone', () => {
|
|
const result = buildLeaderTaskSummary({
|
|
...base,
|
|
status: 'completed',
|
|
hadNeedsReview: true,
|
|
successReceipt: { group_number: 'LW-260907A-B' }
|
|
});
|
|
assert.equal(result?.milestone, 'resolved');
|
|
assert.match(result?.messageText || '', /员工任务摘要·结果更新/);
|
|
});
|
|
|
|
test('Shanghai timestamp formatting is deterministic and invalid-safe', () => {
|
|
assert.equal(formatShanghaiTimestamp(base.createdAt), '2026-09-07 08:05:06');
|
|
assert.equal(formatShanghaiTimestamp('not-a-date'), '时间未记录');
|
|
});
|