import assert from 'node:assert/strict'; import test from 'node:test'; import { buildGoalContextEnvelope } from './goal-run-context.mjs'; import { buildGoalContinueUserMessage, deriveGoalTitleFromText, isGoalRunEnabledForUser, isGoalRunIntent, } from './goal-run-intent.mjs'; test('isGoalRunIntent detects long-running task phrases', () => { assert.equal(isGoalRunIntent('帮我分阶段完成下季度产品规划'), true); assert.equal(isGoalRunIntent('你好'), false); }); test('isGoalRunEnabledForUser respects feature flag and canary list', () => { assert.equal(isGoalRunEnabledForUser('user-a', { GOAL_RUN_ENABLED: '0' }), false); assert.equal(isGoalRunEnabledForUser('user-a', { GOAL_RUN_ENABLED: '1' }), true); assert.equal( isGoalRunEnabledForUser('user-a', { GOAL_RUN_ENABLED: '1', GOAL_RUN_CANARY_USER_IDS: 'user-b', }), false, ); assert.equal( isGoalRunEnabledForUser('user-a', { GOAL_RUN_ENABLED: '1', GOAL_RUN_CANARY_USER_IDS: 'user-a,user-b', }), true, ); }); test('buildGoalContextEnvelope renders friendly goal summary', () => { const envelope = buildGoalContextEnvelope({ title: '准备下季度产品规划', currentCheckpointId: 'cp-1', checkpoints: [ { id: 'cp-1', title: '启动', status: 'running', outputSummary: null }, { id: 'cp-0', title: '调研', status: 'approved', outputSummary: '完成竞品列表' }, ], }); assert.match(envelope, /【Goal Context】/); assert.match(envelope, /准备下季度产品规划/); assert.match(envelope, /完成竞品列表/); }); test('deriveGoalTitleFromText truncates long titles', () => { const title = deriveGoalTitleFromText('a'.repeat(120), 20); assert.equal(title.length, 20); assert.match(title, /…$/); }); test('buildGoalContinueUserMessage renders continue text', () => { const message = buildGoalContinueUserMessage('先聚焦竞品', { id: 'msg-1' }); assert.equal(message.id, 'msg-1'); assert.match(message.metadata.displayText, /继续下一阶段/); assert.match(message.metadata.displayText, /竞品/); });