[glm-grade=B] fix(notifications): repair UI/API contract drift — SMTP auth, event gate, test button (DC-092)
Three user-facing notification features were silently dead from contract
drift between the settings UI and the backend:
1. SMTP auth never applied: the UI sent email.user/email.pass while the
manager read username/password. Route now normalizes aliases; legacy
config files canonicalize at load.
2. Event toggles were cosmetic: UI sent camelCase keys (containerDown),
the send() gate read kebab-case ('container-down'). EVENT_ALIASES now
folds every known spelling (manager gate, route store, legacy files);
UI sends and reads canonical keys.
3. Deploy/auto-restart notifications always dropped: deploy-success/
deploy-failed/auto-restart were missing from DEFAULT events, and
send('test') was itself gated -> the Test button was a no-op. Defaults
added; 'test' bypasses the gate.
Also: strict boolean contract (string 'false' for secure/enabled rejected
— previously coerced truthy, silently forcing TLS), SMTP port bounds,
non-destructive credential merge (blank password no longer clobbers the
stored one), GET /config returns port/secure/to/username + hasPassword
(password never returned), full form prefill + keep-hint placeholder.
Verified live pre-fix: send('test')/'deploymentSuccess'/'auto-restart'
all returned 'not enabled'. Post-fix: +20 tests (route + manager),
full suite 2641/2641 (112 suites).
Judge: GLM-5.3 cold read via delegate_task (deleg_ad765d63), grade B,
ship, zero blockers; judge independently ran the DC-092 suites (38/38).
Polish #1 (canonical event for provider titles) folded in. Remaining
emitters with the same gate-miss class (recipeRemoved, workflow,
ssl-cert-expiry, dns-propagation, drift-detected, dependency-restart-*)
noted for a follow-up tick.
This commit is contained in:
@@ -214,4 +214,99 @@ describe('NotificationManager', () => {
|
||||
nm.stopHealthDaemon();
|
||||
expect(nm.healthDaemonInterval).toBeNull();
|
||||
});
|
||||
|
||||
// ── DC-092: event alias folding + legacy config canonicalization ──────────
|
||||
|
||||
test('DC-092: send() folds camelCase aliases onto canonical kebab keys', async () => {
|
||||
// deploymentSuccess (emitted by routes/apps/deploy.js) previously hit a
|
||||
// gate miss (no such key in events) and the notification was dropped.
|
||||
const result = await nm.send('deploymentSuccess', { text: 'deployed' });
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(nm.getHistory()[0].event).toBe('deploy-success');
|
||||
});
|
||||
|
||||
test('DC-092: send() accepts the canonical kebab spelling too', async () => {
|
||||
const result = await nm.send('deploy-success', { text: 'deployed' });
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(nm.getHistory()[0].event).toBe('deploy-success');
|
||||
});
|
||||
|
||||
test("DC-092: send('test') bypasses the events gate (Test button works)", async () => {
|
||||
const result = await nm.send('test', { text: 'Test Notification' });
|
||||
// No providers are enabled in the default config, so results is empty —
|
||||
// but the gate must NOT return 'Event test not enabled' like it used to.
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(nm.getHistory()[0].event).toBe('test');
|
||||
});
|
||||
|
||||
test('DC-092: send() still gates unknown and disabled events', async () => {
|
||||
const unknown = await nm.send('some-unknown-event', { text: 'x' });
|
||||
expect(unknown.success).toBe(false);
|
||||
expect(unknown.error).toMatch(/not enabled/i);
|
||||
|
||||
nm.config.events['container-down'] = false;
|
||||
const disabled = await nm.send('container-down', { text: 'x' });
|
||||
expect(disabled.success).toBe(false);
|
||||
expect(disabled.error).toMatch(/not enabled/i);
|
||||
});
|
||||
|
||||
test('DC-092: DEFAULT_CONFIG includes deploy/auto-restart events', () => {
|
||||
// Regression pin: these were absent entirely, so deploy notifications
|
||||
// were dropped for every install regardless of UI toggles.
|
||||
expect(nm.config.events['deploy-success']).toBe(true);
|
||||
expect(nm.config.events['deploy-failed']).toBe(true);
|
||||
expect(nm.config.events['auto-restart']).toBe(true);
|
||||
});
|
||||
|
||||
test('DC-092: legacy config with user/pass and camelCase events canonicalizes on load', () => {
|
||||
fs.existsSync.mockReturnValue(true);
|
||||
fs.readFileSync.mockReturnValue(JSON.stringify({
|
||||
enabled: true,
|
||||
providers: {
|
||||
email: {
|
||||
enabled: true,
|
||||
host: 'smtp.test',
|
||||
port: 465,
|
||||
secure: 'false', // legacy string — must normalize to boolean false
|
||||
to: 'me@test',
|
||||
from: 'from@test',
|
||||
user: 'legacy-user',
|
||||
pass: 'legacy-pass',
|
||||
}
|
||||
},
|
||||
events: {
|
||||
containerDown: false,
|
||||
deploymentSuccess: false,
|
||||
}
|
||||
}));
|
||||
const loaded = new NotificationManager({
|
||||
NOTIFICATIONS_FILE: NOTIF_FILE,
|
||||
log: { error: jest.fn(), info: jest.fn(), warn: jest.fn() },
|
||||
});
|
||||
const email = loaded.getConfig().providers.email;
|
||||
expect(email.username).toBe('legacy-user');
|
||||
expect(email.password).toBe('legacy-pass');
|
||||
expect(email.user).toBeUndefined();
|
||||
expect(email.pass).toBeUndefined();
|
||||
expect(email.secure).toBe(false);
|
||||
const events = loaded.getConfig().events;
|
||||
expect(events['container-down']).toBe(false);
|
||||
expect(events['deploy-success']).toBe(false);
|
||||
expect(events.containerDown).toBeUndefined();
|
||||
expect(events.deploymentSuccess).toBeUndefined();
|
||||
});
|
||||
|
||||
test('DC-092: canonical keys win when both spellings exist in a legacy file', () => {
|
||||
fs.existsSync.mockReturnValue(true);
|
||||
fs.readFileSync.mockReturnValue(JSON.stringify({
|
||||
providers: { email: { user: 'legacy', username: 'canonical' } },
|
||||
events: { containerDown: false, 'container-down': true },
|
||||
}));
|
||||
const loaded = new NotificationManager({
|
||||
NOTIFICATIONS_FILE: NOTIF_FILE,
|
||||
log: { error: jest.fn(), info: jest.fn(), warn: jest.fn() },
|
||||
});
|
||||
expect(loaded.getConfig().providers.email.username).toBe('canonical');
|
||||
expect(loaded.getConfig().events['container-down']).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user