GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。 NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは 別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
54 lines
2.2 KiB
JavaScript
54 lines
2.2 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { initialState, evaluate } = require('../src/alertState');
|
|
|
|
const opts = { alertThreshold: 3, realertIntervalMs: 30 * 60 * 1000 };
|
|
|
|
test('連続失敗がしきい値未満なら通知しない', () => {
|
|
let state = initialState();
|
|
let r = evaluate(state, false, 1000, opts);
|
|
assert.equal(r.action, 'none');
|
|
assert.equal(r.newState.consecutiveFailures, 1);
|
|
|
|
r = evaluate(r.newState, false, 2000, opts);
|
|
assert.equal(r.action, 'none');
|
|
assert.equal(r.newState.consecutiveFailures, 2);
|
|
});
|
|
|
|
test('しきい値到達で最初のアラートを1回だけ出す', () => {
|
|
let state = initialState();
|
|
state = evaluate(state, false, 1000, opts).newState;
|
|
state = evaluate(state, false, 2000, opts).newState;
|
|
const r = evaluate(state, false, 3000, opts);
|
|
assert.equal(r.action, 'alert-down');
|
|
assert.equal(r.newState.alerted, true);
|
|
assert.equal(r.newState.lastAlertAt, 3000);
|
|
});
|
|
|
|
test('アラート後、再通知間隔内は沈黙する', () => {
|
|
let state = { consecutiveFailures: 3, alerted: true, lastAlertAt: 1000 };
|
|
const r = evaluate(state, false, 1000 + 10 * 60 * 1000, opts); // 10分後
|
|
assert.equal(r.action, 'none');
|
|
});
|
|
|
|
test('再通知間隔を過ぎたら再度アラートする', () => {
|
|
let state = { consecutiveFailures: 3, alerted: true, lastAlertAt: 1000 };
|
|
const r = evaluate(state, false, 1000 + 31 * 60 * 1000, opts); // 31分後
|
|
assert.equal(r.action, 'alert-still-down');
|
|
assert.equal(r.newState.lastAlertAt, 1000 + 31 * 60 * 1000);
|
|
});
|
|
|
|
test('アラート中に復旧したら復旧通知を1回出し状態をリセットする', () => {
|
|
const state = { consecutiveFailures: 5, alerted: true, lastAlertAt: 1000 };
|
|
const r = evaluate(state, true, 5000, opts);
|
|
assert.equal(r.action, 'alert-recovered');
|
|
assert.deepEqual(r.newState, initialState());
|
|
});
|
|
|
|
test('アラート未発生のまま復旧した場合は通知しない', () => {
|
|
const state = { consecutiveFailures: 1, alerted: false, lastAlertAt: null };
|
|
const r = evaluate(state, true, 5000, opts);
|
|
assert.equal(r.action, 'none');
|
|
assert.deepEqual(r.newState, initialState());
|
|
});
|