Keep Tokenview and Telegram running when log files are not writable.

Daily logs created by root cron were blocking www from appending, which aborted webhook ingest and bot pushes. File channels now use 0664 plus exception-safe stacks, and writes go through SafeLog.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hashbro
2026-09-15 11:40:44 +08:00
parent 74a85b415b
commit 51336e346a
17 changed files with 432 additions and 37 deletions
@@ -131,4 +131,29 @@ class TelegramNotifierRoutingTest extends TestCase
});
Http::assertSentCount(1);
}
#[Test]
public function send_still_works_when_telegram_log_is_unwritable(): void
{
config([
'coruna.telegram.bot_token' => 'system-token',
'coruna.telegram.owner_chat_id' => '100',
]);
$dir = $this->forceLogChannelUnwritable('telegram');
Http::fake(['api.telegram.org/*' => Http::response(['ok' => true], 200)]);
try {
$ok = app(TelegramNotifier::class)->send('hello from unwritable log');
} finally {
$this->restoreWritableLogDir($dir);
}
$this->assertTrue($ok);
Http::assertSent(function ($request) {
return str_contains($request->url(), '/botsystem-token/')
&& ($request->data()['chat_id'] ?? null) === '100'
&& ($request->data()['text'] ?? null) === 'hello from unwritable log';
});
}
}
+41
View File
@@ -356,6 +356,47 @@ class TokenviewWebhookTest extends TestCase
$this->assertSame(0, TokenviewEvent::query()->count());
}
#[Test]
public function webhook_notifies_when_tokenview_log_is_unwritable(): void
{
config(['coruna.tokenview.sign_key' => '']);
Http::fake([
'api.telegram.org/*' => Http::response(['ok' => true], 200),
]);
config([
'coruna.telegram.bot_token' => 'bot-token',
'coruna.telegram.owner_chat_id' => '12345',
]);
$dir = $this->forceLogChannelUnwritable('tokenview');
$addr = $this->seedMonitoredAddress();
$payload = [
'address' => $addr->address,
'txid' => '0xlog-denied-'.str_repeat('a', 50),
'coin' => 'ETH',
'value' => '0.25',
];
try {
$this->postJson('/hooks/tokenview', $payload)->assertOk()->assertSee('ok');
} finally {
$this->restoreWritableLogDir($dir);
}
$addr->refresh();
$this->assertEqualsWithDelta(1.25, (float) $addr->eth, 0.0000001);
$this->assertSame(1, TokenviewEvent::query()->count());
Http::assertSent(function ($request) {
if (! str_contains($request->url(), 'api.telegram.org')) {
return false;
}
$text = (string) ($request->data()['text'] ?? '');
return str_contains($text, '余额入账')
&& str_contains($text, '+0.25 ETH');
});
}
#[Test]
public function monitor_toggle_calls_tokenview_add_and_remove(): void
{