From 0633cad75a80af533af9dfc5540a314d3c980b43 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 15 Oct 2026 09:06:09 +0000 Subject: [PATCH] =?UTF-8?q?test:=20=E8=A3=9C=E6=B8=AC=E5=A5=BD=E6=84=9F?= =?UTF-8?q?=E5=BA=A6=E8=88=87=E9=97=9C=E4=BF=82=E8=A6=8F=E5=89=87=EF=BC=8C?= =?UTF-8?q?=E4=B8=A6=E4=BF=AE=E6=AD=A3=E7=A7=BB=E8=BD=89=E9=97=9C=E4=BF=82?= =?UTF-8?q?=E6=9C=AA=E5=B8=B6=E5=87=BA=E5=8E=9F=E6=88=80=E4=BA=BA=E5=90=8D?= =?UTF-8?q?=E7=A8=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- hooks/register.tsx | 6 +-- hooks/routing.test.ts | 102 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 5 deletions(-) diff --git a/hooks/register.tsx b/hooks/register.tsx index afaaf31..fc91b67 100644 --- a/hooks/register.tsx +++ b/hooks/register.tsx @@ -6,7 +6,7 @@ import type { Axes } from './characters' import { EXTRACT_COMMAND, runExtract } from './extractCommand' import { applyEvent, hearts, initialAffinity, stageName, stageVoice, dayKey } from './affinity' import type { Affinity } from './affinity' -import { relationOf, relationText } from './relation' +import { latestEntry, relationOf, relationText } from './relation' import { CLASSIFY_PROMPT, choose, parseRoute } from './router' import type { Effort, ModelName, Route } from './router' import { REWRITE_SYSTEM, needsSonnet, protect, restore, withPrefix } from './rewrite' @@ -383,9 +383,9 @@ export const register: Register = (on, options) => { let text = personaSection(c, applyOverrides(c.axes, overrides())) if (flag('affinity', true)) { const a = await loadAffinity($, c.slug) - text += `\n${stageVoice(a.score)}\n${relationText(relationOf(c.timeline, a.score, flag('romance', false)))}` + text += `\n${stageVoice(a.score)}\n${relationText(relationOf(c.timeline, a.score, flag('romance', false)), latestEntry(c.timeline)?.romance)}` } else { - text += `\n${relationText(relationOf(c.timeline, 0, false))}` + text += `\n${relationText(relationOf(c.timeline, 0, false), latestEntry(c.timeline)?.romance)}` } if (delegating) text += '\n本輪的實際工作已交給背景工作線處理,你不要自己動手做。請只用角色口吻簡短告知已開始處理;完成後會有回報,屆時再向使用者說明結果。' return { diff --git a/hooks/routing.test.ts b/hooks/routing.test.ts index 79a1ae9..1134700 100644 --- a/hooks/routing.test.ts +++ b/hooks/routing.test.ts @@ -1,11 +1,11 @@ import { expect, mock, test } from 'claude-code/testing' -type Ctl = { complete: (e: any) => unknown; usage: unknown; seen?: any; submitted: string[] } +type Ctl = { complete: (e: any) => unknown; usage: unknown; seen?: any; submitted: string[]; clock?: any } const setup = (on: any): Ctl => { const ctl: Ctl = { complete: () => ({ isAnswered: false, reason: 'aborted' }), usage: { rateLimits: [], context: {} }, submitted: [] } mock.store(on) - mock.clock(on, { now: Date.parse('2026-10-15T08:00:00Z') }) + ctl.clock = mock.clock(on, { now: Date.parse('2026-10-15T08:00:00Z') }) on('ui.log', () => ({ value: undefined }) as never) on('command.register', () => ({ value: { name: 'x' } }) as never) on('session.start', () => ({ cwd: '/tmp' }) as never) @@ -143,6 +143,104 @@ test('未成年角色維持友情,即使好感度最高且開啟戀愛式依 expect((await personaText($)).includes('關係定位:友情')).toBe(true) }) +// 以 fs 事件邊界提供角色包(characters/index.json),讓外掛自行載入成年角色。 +const packs = (on: any, list: { slug: string; romance?: string }[]) => { + const files = new Map() + files.set('index.json', JSON.stringify({ packs: list.map(p => ({ work: 'tw', workName: '測試作品', slug: p.slug })) })) + for (const p of list) { + files.set( + `tw/${p.slug}.json`, + JSON.stringify({ + work: 'tw', + slug: p.slug, + name: '成年測試', + persona: { selfRef: '我', address: '你', tone: '平穩', catchphrase: '好', values: '可靠', taboos: '無' }, + axes: { gentle: 5, tsundere: 5, lively: 5, formal: 5, talkative: 5, humor: 5, proactive: 5, expressive: 5 }, + anime: { moe: '', speech: '', emotions: '', kaomoji: '', themeColor: 'cyan' }, + timeline: [ + { chapter: '第1章', age: 17, relationships: [] }, + { chapter: '第2章', age: 20, relationships: p.romance ? [{ with: p.romance, kind: 'romantic' }] : [] }, + ], + }), + ) + } + const key = (path: string) => path.replace(/^.*\/characters\//, '') + on('fs.exists', (_$: any, e: any) => ({ value: files.has(key(e.path)) }) as never) + on('fs.read', (_$: any, e: any) => ({ value: files.get(key(e.path)) ?? '' }) as never) +} + +test('成年且原作有戀愛關係:關係移轉給使用者,原戀人退為過去的重要人物', async ($, on) => { + setup(on) + packs(on, [{ slug: 'lover', romance: '桐人' }]) + await start($, 'tw-lover') + const t = await personaText($) + expect(t.includes('已移轉給使用者')).toBe(true) + expect(t.includes('桐人')).toBe(true) + expect(t.includes('過去的重要人物')).toBe(true) +}) + +test('成年但原作無戀愛關係:需最高階段且明確開啟才進入戀愛式依賴', async ($, on) => { + setup(on) + packs(on, [{ slug: 'plain' }]) + await start($, 'tw-plain') + await $.command.run({ command: 'anima-affinity', args: '100' } as never) + expect((await personaText($)).includes('戀愛式依賴')).toBe(false) +}) + +test('成年無戀愛、最高階段但未在 /config 開啟:維持夥伴關係', { options: { romance: false } }, async ($, on) => { + setup(on) + packs(on, [{ slug: 'plain' }]) + await start($, 'tw-plain') + await $.command.run({ command: 'anima-affinity', args: '100' } as never) + expect((await personaText($)).includes('夥伴與朋友')).toBe(true) +}) + +test('成年無戀愛、已開啟但好感度未達最高階段:不進入戀愛式依賴', { options: { romance: true } }, async ($, on) => { + setup(on) + packs(on, [{ slug: 'plain' }]) + await start($, 'tw-plain') + await $.command.run({ command: 'anima-affinity', args: '79' } as never) + expect((await personaText($)).includes('戀愛式依賴')).toBe(false) +}) + +test('成年無戀愛、最高階段且已開啟:進入戀愛式依賴', { options: { romance: true } }, async ($, on) => { + setup(on) + packs(on, [{ slug: 'plain' }]) + await start($, 'tw-plain') + await $.command.run({ command: 'anima-affinity', args: '80' } as never) + expect((await personaText($)).includes('戀愛式依賴')).toBe(true) +}) + +test('長期不互動好感度緩慢下降,但不跨階段掉落', async ($, on) => { + const ctl = setup(on) + ctl.complete = () => route('haiku') + await start($) + await submit($, '你好') + await $.command.run({ command: 'anima-affinity', args: '45' } as never) + await ctl.clock.advance(30 * 86_400_000) + await submit($, '我回來了') + const n = await affinity($) + expect(n < 45).toBe(true) + expect(n >= 40).toBe(true) +}) + +test('個性軸影響扣分倍率:傲嬌角色掉得比溫柔角色多', async ($, on) => { + const ctl = setup(on) + ctl.complete = () => route('haiku') + packs(on, [{ slug: 'plain' }]) + const run = async (slug: string) => { + await start($, slug) + await submit($, '你好') + await $.command.run({ command: 'anima-affinity', args: '70' } as never) + await ctl.clock.advance(8 * 86_400_000) + await submit($, '我回來了') + return affinity($) + } + const proud = await run('tw-plain') + const calm = await run('sao-suguha') + expect(proud < calm).toBe(true) +}) + const workRoute = (model: string, work: boolean) => ({ isAnswered: true, usage, text: `{"difficulty":8,"model":"${model}","effort":"high","tone":"neutral","ack":"好,我來處理。","work":${work}}` }) test('需要動手的要求交給背景工作線,對話線改用 Haiku', async ($, on) => {