[grade=A] P1-8: replace 66 console.* calls across 6 remaining files with structured logger

Files changed:
- src/security/crypto-utils.js: 16 calls → log tagged 'crypto'
- src/security/docker-security.js: 15 calls → log tagged 'security'
- src/managers/port-lock-manager.js: 16 calls → log tagged 'portlock'
- src/docker/self-updater.js: 10 calls → log tagged 'updater'
- src/security/event-workers.js: 5 calls → log tagged 'events'
- src/security/keychain-manager.js: 4 calls → log tagged 'keychain'

Fixed 2 bugs found during sweep:
- self-updater.js:161 — arrow expression body had trailing semicolon (SyntaxError)
- port-lock-manager.js:137 — log.error referenced 'port' var out of scope (ReferenceError)

1539/1539 Jest tests pass. All ESLint warnings pre-existing (0 new).
This commit is contained in:
Hermes
2026-08-10 20:23:58 -07:00
parent 191d3340a7
commit 7b04bc1d3c
6 changed files with 72 additions and 71 deletions
+11 -10
View File
@@ -10,6 +10,7 @@
const EventEmitter = require('events');
const https = require('https');
const http = require('http');
const { log } = require('../utils/logging');
const fs = require('fs');
const fsp = require('fs').promises;
const path = require('path');
@@ -86,7 +87,7 @@ class SelfUpdater extends EventEmitter {
start() {
if (!this.config.enabled || this.checkTimer) return;
console.log('[SelfUpdater] Starting auto-update checks every %ds', this.config.checkInterval / 1000);
log.info('updater', 'Starting auto-update checks', { intervalMs: this.config.checkInterval });
// First check after a short delay (let server finish startup)
setTimeout(() => {
@@ -124,7 +125,7 @@ class SelfUpdater extends EventEmitter {
return { version: pkg.version, commit };
} catch { /* try next candidate */ }
}
console.error('[SelfUpdater] getLocalVersion failed: no candidate package.json found');
log.error('updater', 'getLocalVersion failed: no candidate package.json found');
return { version: '0.0.0', commit: null };
}
@@ -158,7 +159,7 @@ class SelfUpdater extends EventEmitter {
// Fire-and-forget; the response shouldn't block on the container rebuild.
setImmediate(() => {
this._autoCheckAndApply().catch(err =>
console.error('[SelfUpdater] %s-triggered update error: %s', triggeredBy, err.message)
log.error('updater', err, { triggeredBy })
);
});
return { accepted: true, triggeredBy };
@@ -174,7 +175,7 @@ class SelfUpdater extends EventEmitter {
try {
remote = await this._fetchJson(`${this.config.updateUrl}/version.json`);
} catch (primaryErr) {
console.warn('[SelfUpdater] Primary server failed:', primaryErr.message, '— trying mirror');
log.warn('updater', 'Primary server failed, trying mirror', { error: primaryErr.message });
try {
remote = await this._fetchJson(`${this.config.mirrorUrl}/version.json`);
sourceUrl = this.config.mirrorUrl;
@@ -240,7 +241,7 @@ class SelfUpdater extends EventEmitter {
try {
await this._downloadFile(primaryUrl, tarballPath);
} catch (dlErr) {
console.warn('[SelfUpdater] Primary download failed:', dlErr.message, '— trying mirror');
log.warn('updater', 'Primary download failed, trying mirror', { error: dlErr.message });
// Ensure file is fully cleaned up before mirror attempt
try { fs.unlinkSync(tarballPath); } catch { /* ignore */ }
await this._downloadFile(mirrorUrl, tarballPath);
@@ -468,11 +469,11 @@ class SelfUpdater extends EventEmitter {
try {
const result = await this.checkForUpdate();
if (result.available && result.remote) {
console.log('[SelfUpdater] Update available: %s → %s', result.local.version, result.remote.version);
log.info('updater', 'Update available', { localVersion: result.local.version, remoteVersion: result.remote.version });
await this.applyUpdate(result.remote);
}
} catch (e) {
console.error('[SelfUpdater] Auto-update error:', e.message);
log.error('updater', e, { phase: 'autoUpdate' });
}
}
@@ -606,7 +607,7 @@ class SelfUpdater extends EventEmitter {
fs.mkdirSync(path.dirname(this.notifySecretFile), { recursive: true });
fs.writeFileSync(this.notifySecretFile, `${secret}\n`, { mode: 0o600 });
} catch (error) {
console.warn('[SelfUpdater] Failed to persist notify secret:', error.message);
log.warn('updater', 'Failed to persist notify secret', { error: error.message });
}
return secret;
}
@@ -626,7 +627,7 @@ class SelfUpdater extends EventEmitter {
fs.mkdirSync(path.dirname(this.config.instanceIdFile), { recursive: true });
fs.writeFileSync(this.config.instanceIdFile, `${instanceId}\n`, 'utf8');
} catch (error) {
console.warn('[SelfUpdater] Failed to persist instance ID:', error.message);
log.warn('updater', 'Failed to persist instance ID', { error: error.message });
}
return instanceId;
}
@@ -644,7 +645,7 @@ class SelfUpdater extends EventEmitter {
try {
fs.writeFileSync(historyPath, JSON.stringify(history, null, 2));
} catch (e) {
console.error('[SelfUpdater] Failed to save history:', e.message);
log.error('updater', e, { operation: 'saveHistory' });
}
}