11import { describe , it , expect , beforeEach , vi , afterEach } from 'vitest' ;
22
3- // --- Mocks ---
3+ // --- モック ---
44
5- // Mock registry ( registerChannel runs at import time)
5+ // レジストリのモック( registerChannel はインポート時に実行される)
66vi . mock ( './registry.js' , ( ) => ( { registerChannel : vi . fn ( ) } ) ) ;
77
8- // Mock env reader (used by the factory, not needed in unit tests)
8+ // 環境変数リーダーのモック(ファクトリで使用されるが、ユニットテストでは不要)
99vi . mock ( '../env.js' , ( ) => ( { readEnvFile : vi . fn ( ( ) => ( { } ) ) } ) ) ;
1010
11- // Mock config
11+ // 設定のモック
1212vi . mock ( '../config.js' , ( ) => ( {
1313 ASSISTANT_NAME : 'Andy' ,
1414 TRIGGER_PATTERN : / ^ @ A n d y \b / i,
1515} ) ) ;
1616
17- // Mock logger
17+ // ロガーのモック
1818vi . mock ( '../logger.js' , ( ) => ( {
1919 logger : {
2020 debug : vi . fn ( ) ,
@@ -24,7 +24,7 @@ vi.mock('../logger.js', () => ({
2424 } ,
2525} ) ) ;
2626
27- // --- discord.js mock ---
27+ // --- discord.js のモック ---
2828
2929type Handler = ( ...args : any [ ] ) => any ;
3030
@@ -76,7 +76,7 @@ vi.mock('discord.js', () => {
7676
7777 async login ( _token : string ) {
7878 this . _ready = true ;
79- // Fire the ready event
79+ // ready イベントを発火させる
8080 const readyHandlers = this . eventHandlers . get ( 'ready' ) || [ ] ;
8181 for ( const h of readyHandlers ) {
8282 h ( { user : this . user } ) ;
@@ -99,10 +99,10 @@ vi.mock('discord.js', () => {
9999 }
100100 }
101101
102- // Mock TextChannel type
102+ // TextChannel 型のモック
103103 class TextChannel { }
104104
105- // Mock ThreadChannel type
105+ // ThreadChannel 型のモック
106106 class ThreadChannel { }
107107
108108 return {
@@ -117,7 +117,7 @@ vi.mock('discord.js', () => {
117117
118118import { DiscordChannel , DiscordChannelOpts } from './discord.js' ;
119119
120- // --- Test helpers ---
120+ // --- テスト用ヘルパー ---
121121
122122function createTestOpts (
123123 overrides ?: Partial < DiscordChannelOpts > ,
@@ -159,7 +159,7 @@ function createMessage(overrides: {
159159} ) {
160160 const channelId = overrides . channelId ?? '1234567890123456' ;
161161 const authorId = overrides . authorId ?? '55512345' ;
162- const botId = '999888777' ; // matches mock client user id
162+ const botId = '999888777' ; // モッククライアントのユーザーIDと一致
163163 const isThreadChannel = overrides . isThread ?? false ;
164164
165165 const mentionsMap = new Map ( ) ;
@@ -216,7 +216,7 @@ async function triggerMessage(message: any) {
216216 for ( const h of handlers ) await h ( message ) ;
217217}
218218
219- // --- Tests ---
219+ // --- テスト ---
220220
221221describe ( 'DiscordChannel' , ( ) => {
222222 beforeEach ( ( ) => {
@@ -227,7 +227,7 @@ describe('DiscordChannel', () => {
227227 vi . restoreAllMocks ( ) ;
228228 } ) ;
229229
230- // --- Connection lifecycle ---
230+ // --- 接続ライフサイクル ---
231231
232232 describe ( 'connection lifecycle' , ( ) => {
233233 it ( 'resolves connect() when client is ready' , async ( ) => {
@@ -269,7 +269,7 @@ describe('DiscordChannel', () => {
269269 } ) ;
270270 } ) ;
271271
272- // --- Text message handling ---
272+ // --- テキストメッセージ処理 ---
273273
274274 describe ( 'text message handling' , ( ) => {
275275 it ( 'delivers message for registered channel' , async ( ) => {
@@ -436,7 +436,7 @@ describe('DiscordChannel', () => {
436436 } ) ;
437437 } ) ;
438438
439- // --- @mention translation ---
439+ // --- @メンション変換 ---
440440
441441 describe ( '@mention translation' , ( ) => {
442442 it ( 'translates <@botId> mention to trigger format' , async ( ) => {
@@ -471,8 +471,8 @@ describe('DiscordChannel', () => {
471471 } ) ;
472472 await triggerMessage ( msg ) ;
473473
474- // Should NOT prepend @Andy — already starts with trigger
475- // But the <@botId> should still be stripped
474+ // @Andy を先頭に付加しない — すでにトリガーで始まっている
475+ // ただし <@botId> は除去される
476476 expect ( opts . onMessage ) . toHaveBeenCalledWith (
477477 'dc:1234567890123456' ,
478478 expect . objectContaining ( {
@@ -521,7 +521,7 @@ describe('DiscordChannel', () => {
521521 } ) ;
522522 } ) ;
523523
524- // --- Attachments ---
524+ // --- 添付ファイル ---
525525
526526 describe ( 'attachments' , ( ) => {
527527 it ( 'stores image attachment with placeholder' , async ( ) => {
@@ -641,7 +641,7 @@ describe('DiscordChannel', () => {
641641 } ) ;
642642 } ) ;
643643
644- // --- Reply context ---
644+ // --- リプライ文脈 ---
645645
646646 describe ( 'reply context' , ( ) => {
647647 it ( 'includes reply author in content' , async ( ) => {
@@ -665,7 +665,7 @@ describe('DiscordChannel', () => {
665665 } ) ;
666666 } ) ;
667667
668- // --- sendMessage ---
668+ // --- メッセージ送信 ---
669669
670670 describe ( 'sendMessage' , ( ) => {
671671 it ( 'sends message via channel' , async ( ) => {
@@ -701,7 +701,7 @@ describe('DiscordChannel', () => {
701701 new Error ( 'Channel not found' ) ,
702702 ) ;
703703
704- // Should not throw
704+ // 例外を投げないこと
705705 await expect (
706706 channel . sendMessage ( 'dc:1234567890123456' , 'Will fail' ) ,
707707 ) . resolves . toBeUndefined ( ) ;
@@ -711,10 +711,10 @@ describe('DiscordChannel', () => {
711711 const opts = createTestOpts ( ) ;
712712 const channel = new DiscordChannel ( 'test-token' , new Set ( ) , opts ) ;
713713
714- // Don't connect — client is null
714+ // 接続しない — client が null
715715 await channel . sendMessage ( 'dc:1234567890123456' , 'No client' ) ;
716716
717- // No error, no API call
717+ // エラーも API 呼び出しもない
718718 } ) ;
719719
720720 it ( 'splits messages exceeding 2000 characters' , async ( ) => {
@@ -737,7 +737,7 @@ describe('DiscordChannel', () => {
737737 } ) ;
738738 } ) ;
739739
740- // --- createThread ---
740+ // --- スレッド作成 ---
741741
742742 describe ( 'createThread' , ( ) => {
743743 it ( 'creates message-linked thread when messageId is provided' , async ( ) => {
@@ -831,7 +831,7 @@ describe('DiscordChannel', () => {
831831 } ) ;
832832 } ) ;
833833
834- // --- ownsJid ---
834+ // --- JID の所有判定 ---
835835
836836 describe ( 'ownsJid' , ( ) => {
837837 it ( 'owns dc: JIDs' , ( ) => {
@@ -871,7 +871,7 @@ describe('DiscordChannel', () => {
871871 } ) ;
872872 } ) ;
873873
874- // --- setTyping ---
874+ // --- タイピング表示 ---
875875
876876 describe ( 'setTyping' , ( ) => {
877877 it ( 'sends typing indicator when isTyping is true' , async ( ) => {
@@ -897,22 +897,22 @@ describe('DiscordChannel', () => {
897897
898898 await channel . setTyping ( 'dc:1234567890123456' , false ) ;
899899
900- // channels.fetch should NOT be called
900+ // channels.fetch は呼ばれないこと
901901 expect ( currentClient ( ) . channels . fetch ) . not . toHaveBeenCalled ( ) ;
902902 } ) ;
903903
904904 it ( 'does nothing when client is not initialized' , async ( ) => {
905905 const opts = createTestOpts ( ) ;
906906 const channel = new DiscordChannel ( 'test-token' , new Set ( ) , opts ) ;
907907
908- // Don't connect
908+ // 接続しない
909909 await channel . setTyping ( 'dc:1234567890123456' , true ) ;
910910
911- // No error
911+ // エラーは出ない
912912 } ) ;
913913 } ) ;
914914
915- // --- Channel properties ---
915+ // --- チャンネルプロパティ ---
916916
917917 describe ( 'channel properties' , ( ) => {
918918 it ( 'has name "discord"' , ( ) => {
@@ -925,7 +925,7 @@ describe('DiscordChannel', () => {
925925 } ) ;
926926 } ) ;
927927
928- // --- Allowed bot filtering ---
928+ // --- 許可Botフィルタリング ---
929929
930930 describe ( 'allowed bot filtering' , ( ) => {
931931 const ALLOWED_BOT_ID = '111222333444555666' ;
@@ -1019,7 +1019,7 @@ describe('DiscordChannel', () => {
10191019 } ) ;
10201020 } ) ;
10211021
1022- // --- Thread detection ---
1022+ // --- スレッド検出 ---
10231023
10241024 describe ( 'thread detection' , ( ) => {
10251025 it ( 'sets is_thread=true and place_type=public_thread for thread messages' , async ( ) => {
@@ -1123,7 +1123,7 @@ describe('DiscordChannel', () => {
11231123 } ) ;
11241124 await triggerMessage ( msg ) ;
11251125
1126- // Should deliver even though thread itself is not registered yet
1126+ // スレッド自体はまだ登録されていないが配信されること
11271127 expect ( opts . onMessage ) . toHaveBeenCalledWith (
11281128 `dc:${ threadId } ` ,
11291129 expect . objectContaining ( {
@@ -1143,7 +1143,7 @@ describe('DiscordChannel', () => {
11431143 folder : 'test-server' ,
11441144 trigger : '@Andy' ,
11451145 added_at : '2024-01-01T00:00:00.000Z' ,
1146- // no thread_defaults
1146+ // thread_defaults なし
11471147 } ,
11481148 } ) ) ,
11491149 } ) ;
0 commit comments