From e60e6286d2d70e69148edab76a308b7010b47343 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Mon, 12 Oct 2026 06:31:52 -0600 Subject: [PATCH 1/5] test(logging): pin caller-impact shapes for the v5.2.15 -> v5.3.0 rotation-inheritance change #1877/#1880 made updateLogger() fall back to mainLoggerRef.rotation when a logger's own config omits a rotation block, so a tagged/component logger with its own path now inherits main's rotation instead of silently never rotating. That change is already pinned by the existing #1877 describe block; this adds the shapes an upgrade-impact scanner needs to classify: plain logger.info/ warn/error sharing main's default path (unaffected - same shared per-path file sink before and after), logger.withTag()/tagged loggers (unaffected - never touch rotation resolution), level filtering (unaffected - the mainLogger -> mainLoggerRef parameter is never passed by production code), and a concrete reproduction of the operational risk the fix itself introduces: a descriptor opened on a previously-never-rotated component log before rotation stops seeing new writes once the file gets renamed out from under it. No runtime behavior change; main behaves identically to v5.3.0 here (the only diff since is unrelated bigint-stat precision fixes for Windows inode identity). Dispatch-Task: harper-upgrade-rule-logger-rotation-530 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01524gnfYt96yuXWh7KqpsET --- .../utility/logging/harper_logger.test.js | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/unitTests/utility/logging/harper_logger.test.js b/unitTests/utility/logging/harper_logger.test.js index f4180283c7..9e602679af 100644 --- a/unitTests/utility/logging/harper_logger.test.js +++ b/unitTests/utility/logging/harper_logger.test.js @@ -1239,6 +1239,154 @@ describe('Test harper_logger module', () => { }); }); + // Pins the caller-impact rule for the v5.2.15 -> v5.3.0 change above (#1877/#1880): which + // `logger` usage shapes see a behavior change and which don't. The describe block above + // already pins the affected shape itself (a component/external logger with its own path and + // no rotation block, reached through updateLogger); these pin the shapes the rule says are + // unaffected, plus the one operational risk the fix itself introduces for existing rotation. + describe('Test caller-impact shapes for the v5.2.15 -> v5.3.0 rotation-inheritance change (#1877/#1880)', () => { + const CALLER_SHAPES_DIR = path.join(__dirname, 'callerImpactShapesTest'); + let shapeCaseDir; + let shapeCase = 0; + let shapeLoggersToCleanup; + + beforeEach(() => { + shapeCaseDir = path.join(CALLER_SHAPES_DIR, `case${shapeCase++}`); + fs.mkdirpSync(shapeCaseDir); + shapeLoggersToCleanup = []; + }); + + afterEach(async () => { + for (const logger of shapeLoggersToCleanup) { + const currentPath = logger.path; + updateLogger(logger, { path: currentPath }, undefined, logger); + logger.closeLogFile?.(); + } + await new Promise((resolve) => setTimeout(resolve, 150)); + fs.removeSync(shapeCaseDir); + }); + + it("shape: plain logger.info/warn/error sharing main's default log path were already bound by main's rotation before this fix — getFileLogger caches one sink per path, so no updateLogger call on this logger was ever needed", async () => { + const mainRotation = { enabled: true, maxSize: '1K' }; + const mainLogPath = path.join(shapeCaseDir, 'hdb.log'); + const testMainLogger = createLogger({ path: mainLogPath, level: 'info' }); + shapeLoggersToCleanup.push(testMainLogger); + updateLogger(testMainLogger, { path: mainLogPath, rotation: mainRotation }, undefined, testMainLogger); + + // This is exactly how the real externalLogger (what logger.info/warn/error write + // through) is built when no `logging.external:` block has ever been configured: + // forComponent copies main's path, and updateLogger is never called on it at all. The + // v5.2.15 -> v5.3.0 fix lives entirely inside updateLogger, so this caller never reaches + // the changed code. + const externalLikeLogger = testMainLogger.forComponent('external'); + shapeLoggersToCleanup.push(externalLikeLogger); + + for (let i = 0; i < 30; i++) externalLikeLogger.info('x'.repeat(80)); + // Writes through this logger alone must still trip main's maxSize: getFileLogger's + // fileLoggers cache is keyed by path, so a logger sharing main's path shares its + // write-path size guard too, regardless of its own stale/absent `.rotation` property. + const rotatedDir = path.join(shapeCaseDir, 'rotated'); + await waitFor(() => fs.pathExistsSync(rotatedDir) && fs.readdirSync(rotatedDir).length > 0, { + timeout: 5000, + message: "expected writes through the shared default path to already be bound by main's rotation", + }); + }); + + it("shape: logger.withTag()/tagged loggers write through their underlying logger's sink and never resolve rotation themselves", async () => { + const logPath = path.join(shapeCaseDir, 'component.log'); + const underlying = createLogger({ path: logPath, level: 'info' }); + shapeLoggersToCleanup.push(underlying); + // Install a real rotation policy the same way updateLogger always does, so there is an + // actual policy for withTag to (not) disturb, rather than two undefineds matching + // trivially. + updateLogger(underlying, { path: logPath, rotation: { enabled: true, maxSize: '1K' } }, undefined, underlying); + const rotationBefore = underlying.rotation; + + const tagged = harperLoggerModule.loggerWithTag('shapeTwo', false, underlying); + tagged.info('tagged line'); + + await waitFor(() => fs.existsSync(logPath) && fs.readFileSync(logPath, 'utf8').includes('tagged line')); + const log = fs.readFileSync(logPath, 'utf8'); + assert.ok(log.includes('[shapeTwo]'), 'the tag is prefixed onto the line written through the underlying sink'); + assert.strictEqual( + underlying.rotation, + rotationBefore, + 'withTag must never touch the rotation policy of the logger it wraps' + ); + }); + + it('shape: tooling tailing a component log file by an already-open descriptor stops seeing new writes once inherited rotation renames the file out from under it', async () => { + const mainRotation = { enabled: true, maxSize: '1K' }; + const mainLogPath = path.join(shapeCaseDir, 'hdb.log'); + const testMainLogger = createLogger({ path: mainLogPath, level: 'info' }); + shapeLoggersToCleanup.push(testMainLogger); + updateLogger(testMainLogger, { path: mainLogPath, rotation: mainRotation }, undefined, testMainLogger); + + const componentLogPath = path.join(shapeCaseDir, 'tailed-component.log'); + const componentLogger = testMainLogger.forComponent('tailed'); + shapeLoggersToCleanup.push(componentLogger); + // The #1877 shape: its own path, no rotation block of its own — this now inherits main's. + updateLogger(componentLogger, { path: componentLogPath }, 'tailed', testMainLogger); + assert.deepStrictEqual(componentLogger.rotation, mainRotation); + + componentLogger.info('before rotation, line one'); + await waitFor( + () => fs.existsSync(componentLogPath) && fs.readFileSync(componentLogPath, 'utf8').includes('line one') + ); + + // Simulate a naive tailer (e.g. `tail -f`'s default fd-follow mode) that opened the file + // before rotation happened. + const tailerFd = fs.openSync(componentLogPath, 'r'); + + for (let i = 0; i < 30; i++) componentLogger.info(`padding ${i} ${'x'.repeat(80)}`); + const rotatedDir = path.join(shapeCaseDir, 'rotated'); + await waitFor(() => fs.pathExistsSync(rotatedDir) && fs.readdirSync(rotatedDir).length > 0, { + timeout: 5000, + message: 'expected the inherited main maxSize to rotate the component log', + }); + + componentLogger.info('after rotation, line two'); + await waitFor( + () => + fs.existsSync(componentLogPath) && + fs.readFileSync(componentLogPath, 'utf8').includes('after rotation, line two'), + { timeout: 5000, message: 'expected a fresh file at the same path to receive post-rotation writes' } + ); + + const staleRead = fs.readFileSync(tailerFd, 'utf8'); + fs.closeSync(tailerFd); + assert.ok(staleRead.includes('line one'), 'the stale descriptor still reads the pre-rotation generation'); + assert.ok( + !staleRead.includes('after rotation, line two'), + 'a descriptor opened before rotation never sees a post-rotation write' + ); + + const freshRead = fs.readFileSync(componentLogPath, 'utf8'); + assert.ok(freshRead.includes('after rotation, line two')); + assert.ok( + !freshRead.includes('line one'), + 'pre-rotation content moved to the archive, not the fresh file created at the same path' + ); + }); + + it('shape: level filtering is unaffected — production call sites omit mainLoggerRef, and the fix only changed how that default is spelled, not what it resolves to', () => { + const harper_logger = requireUncached(HARPER_LOGGER_MODULE); + const mainLoggerPrivate = harper_logger.__get__('mainLogger'); + mainLoggerPrivate.level = 1; // trace; distinct from createLogger's 'info' default below + + const probeDefault = harper_logger.createLogger({ level: 'info' }); + const probeExplicit = harper_logger.createLogger({ level: 'info' }); + const probePath = path.join(shapeCaseDir, 'unused.log'); + // Every production call site (applyLogSettings, forComponent) omits the 4th argument; + // this is that shape, compared against spelling the same default out explicitly. + harper_logger.updateLogger(probeDefault, { path: `${probePath}.a` }); + harper_logger.updateLogger(probeExplicit, { path: `${probePath}.b` }, undefined, mainLoggerPrivate); + + assert.strictEqual(probeDefault.level, mainLoggerPrivate.level); + assert.strictEqual(probeDefault.level, probeExplicit.level); + }); + }); + it('Test suppressLogging function', () => { const harper_logger = requireUncached(HARPER_LOGGER_MODULE); const fake_func = sandbox.stub().callsFake(() => {}); From 620f7c667abb579675b0d57880fc16b1c7a7d7a9 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Mon, 12 Oct 2026 06:55:39 -0600 Subject: [PATCH 2/5] test(logging): fix a real rotation-cascade race and tighten the caller-impact tests per review Round-1 cross-model review (codex/gemini/cursor-composer + harper-domain) surfaced one real bug and several legitimate robustness/style findings: - The tailer test's "line two" write raced a multi-rotation cascade (30 lines against a 1K cap rotates 3-4 times in milliseconds) and could land in an intermediate archive instead of the settled active file - caught by running the test standalone, not just as part of the suite. Fixed by waiting for the archive count to hold steady before writing past it. Reproduced the failure under debug logging before fixing it. - Reordered the "plain logger.info/warn/error" test so forComponent's own copy-at-creation of a logger's rotation (unrelated to this fix) can't be what delivers rotation - only the shared per-path file sink can. - Dropped the new rewire/private-state use in the level-resolution test (AGENTS.md: no new sinon/rewire; harper_logger.ts:117-119 already gives tests an explicit mainLoggerRef for this), replacing it with the same mainLoggerRef-substitution pattern the rest of the file uses. - Wrapped the tailer fd in try/finally so a timeout can't leak it. - Trimmed comments that narrated the test/code instead of stating a why, and untied the describe title from specific version numbers. Dispatch-Task: harper-upgrade-rule-logger-rotation-530 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01524gnfYt96yuXWh7KqpsET --- .../utility/logging/harper_logger.test.js | 124 +++++++++--------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/unitTests/utility/logging/harper_logger.test.js b/unitTests/utility/logging/harper_logger.test.js index 9e602679af..2652363c5b 100644 --- a/unitTests/utility/logging/harper_logger.test.js +++ b/unitTests/utility/logging/harper_logger.test.js @@ -1239,16 +1239,14 @@ describe('Test harper_logger module', () => { }); }); - // Pins the caller-impact rule for the v5.2.15 -> v5.3.0 change above (#1877/#1880): which - // `logger` usage shapes see a behavior change and which don't. The describe block above - // already pins the affected shape itself (a component/external logger with its own path and - // no rotation block, reached through updateLogger); these pin the shapes the rule says are - // unaffected, plus the one operational risk the fix itself introduces for existing rotation. - describe('Test caller-impact shapes for the v5.2.15 -> v5.3.0 rotation-inheritance change (#1877/#1880)', () => { + // Pins the caller-impact rule for #1877/#1880's rotation-inheritance fix: which `logger` + // usage shapes it changes and which it doesn't. The affected shape itself (a component/ + // external logger with its own path and no rotation block) is pinned above. + describe('Test caller-impact shapes for the logger rotation-inheritance fix (#1877/#1880)', () => { const CALLER_SHAPES_DIR = path.join(__dirname, 'callerImpactShapesTest'); let shapeCaseDir; let shapeCase = 0; - let shapeLoggersToCleanup; + let shapeLoggersToCleanup = []; beforeEach(() => { shapeCaseDir = path.join(CALLER_SHAPES_DIR, `case${shapeCase++}`); @@ -1263,32 +1261,27 @@ describe('Test harper_logger module', () => { logger.closeLogFile?.(); } await new Promise((resolve) => setTimeout(resolve, 150)); - fs.removeSync(shapeCaseDir); + if (shapeCaseDir) fs.removeSync(shapeCaseDir); }); - it("shape: plain logger.info/warn/error sharing main's default log path were already bound by main's rotation before this fix — getFileLogger caches one sink per path, so no updateLogger call on this logger was ever needed", async () => { + it("shape: plain logger.info/warn/error sharing main's default log path are unaffected — only the shared per-path sink (getFileLogger's cache), never a separate updateLogger call, binds this logger to main's rotation", async () => { const mainRotation = { enabled: true, maxSize: '1K' }; const mainLogPath = path.join(shapeCaseDir, 'hdb.log'); const testMainLogger = createLogger({ path: mainLogPath, level: 'info' }); shapeLoggersToCleanup.push(testMainLogger); - updateLogger(testMainLogger, { path: mainLogPath, rotation: mainRotation }, undefined, testMainLogger); - // This is exactly how the real externalLogger (what logger.info/warn/error write - // through) is built when no `logging.external:` block has ever been configured: - // forComponent copies main's path, and updateLogger is never called on it at all. The - // v5.2.15 -> v5.3.0 fix lives entirely inside updateLogger, so this caller never reaches - // the changed code. + // Created before main's own rotation is installed, so forComponent's copy-at-creation + // of `protoLogger.rotation` (unrelated to this fix) cannot be what delivers rotation + // below — only the shared file sink at mainLogPath can. const externalLikeLogger = testMainLogger.forComponent('external'); shapeLoggersToCleanup.push(externalLikeLogger); + updateLogger(testMainLogger, { path: mainLogPath, rotation: mainRotation }, undefined, testMainLogger); for (let i = 0; i < 30; i++) externalLikeLogger.info('x'.repeat(80)); - // Writes through this logger alone must still trip main's maxSize: getFileLogger's - // fileLoggers cache is keyed by path, so a logger sharing main's path shares its - // write-path size guard too, regardless of its own stale/absent `.rotation` property. const rotatedDir = path.join(shapeCaseDir, 'rotated'); await waitFor(() => fs.pathExistsSync(rotatedDir) && fs.readdirSync(rotatedDir).length > 0, { timeout: 5000, - message: "expected writes through the shared default path to already be bound by main's rotation", + message: "expected writes through the shared default path to be bound by main's rotation", }); }); @@ -1296,9 +1289,6 @@ describe('Test harper_logger module', () => { const logPath = path.join(shapeCaseDir, 'component.log'); const underlying = createLogger({ path: logPath, level: 'info' }); shapeLoggersToCleanup.push(underlying); - // Install a real rotation policy the same way updateLogger always does, so there is an - // actual policy for withTag to (not) disturb, rather than two undefineds matching - // trivially. updateLogger(underlying, { path: logPath, rotation: { enabled: true, maxSize: '1K' } }, undefined, underlying); const rotationBefore = underlying.rotation; @@ -1325,7 +1315,7 @@ describe('Test harper_logger module', () => { const componentLogPath = path.join(shapeCaseDir, 'tailed-component.log'); const componentLogger = testMainLogger.forComponent('tailed'); shapeLoggersToCleanup.push(componentLogger); - // The #1877 shape: its own path, no rotation block of its own — this now inherits main's. + // The #1877 shape: its own path, no rotation block of its own. updateLogger(componentLogger, { path: componentLogPath }, 'tailed', testMainLogger); assert.deepStrictEqual(componentLogger.rotation, mainRotation); @@ -1334,32 +1324,48 @@ describe('Test harper_logger module', () => { () => fs.existsSync(componentLogPath) && fs.readFileSync(componentLogPath, 'utf8').includes('line one') ); - // Simulate a naive tailer (e.g. `tail -f`'s default fd-follow mode) that opened the file - // before rotation happened. + // Simulates a tailer that follows the descriptor (e.g. `tail -f`'s default mode), + // opened before rotation renames the file out from under it. const tailerFd = fs.openSync(componentLogPath, 'r'); + try { + for (let i = 0; i < 30; i++) componentLogger.info(`padding ${i} ${'x'.repeat(80)}`); + const rotatedDir = path.join(shapeCaseDir, 'rotated'); + await waitFor(() => fs.pathExistsSync(rotatedDir) && fs.readdirSync(rotatedDir).length > 0, { + timeout: 5000, + message: 'expected the inherited main maxSize to rotate the component log', + }); + // The 30-line burst against a 1K cap rotates several times in a fast cascade; writing + // line two the instant the first archive appears can still land it in an + // intermediate generation that itself rotates again moments later. Wait for the + // archive count to hold steady across a poll before writing past the cascade. + let lastRotatedCount = -1; + await waitFor( + () => { + const count = fs.readdirSync(rotatedDir).length; + const settled = count === lastRotatedCount; + lastRotatedCount = count; + return settled; + }, + { timeout: 5000, interval: 200, message: 'expected the rotation cascade to settle' } + ); - for (let i = 0; i < 30; i++) componentLogger.info(`padding ${i} ${'x'.repeat(80)}`); - const rotatedDir = path.join(shapeCaseDir, 'rotated'); - await waitFor(() => fs.pathExistsSync(rotatedDir) && fs.readdirSync(rotatedDir).length > 0, { - timeout: 5000, - message: 'expected the inherited main maxSize to rotate the component log', - }); - - componentLogger.info('after rotation, line two'); - await waitFor( - () => - fs.existsSync(componentLogPath) && - fs.readFileSync(componentLogPath, 'utf8').includes('after rotation, line two'), - { timeout: 5000, message: 'expected a fresh file at the same path to receive post-rotation writes' } - ); + componentLogger.info('after rotation, line two'); + await waitFor( + () => + fs.existsSync(componentLogPath) && + fs.readFileSync(componentLogPath, 'utf8').includes('after rotation, line two'), + { timeout: 5000, message: 'expected a fresh file at the same path to receive post-rotation writes' } + ); - const staleRead = fs.readFileSync(tailerFd, 'utf8'); - fs.closeSync(tailerFd); - assert.ok(staleRead.includes('line one'), 'the stale descriptor still reads the pre-rotation generation'); - assert.ok( - !staleRead.includes('after rotation, line two'), - 'a descriptor opened before rotation never sees a post-rotation write' - ); + const staleRead = fs.readFileSync(tailerFd, 'utf8'); + assert.ok(staleRead.includes('line one'), 'the stale descriptor still reads the pre-rotation generation'); + assert.ok( + !staleRead.includes('after rotation, line two'), + 'a descriptor opened before rotation never sees a post-rotation write' + ); + } finally { + fs.closeSync(tailerFd); + } const freshRead = fs.readFileSync(componentLogPath, 'utf8'); assert.ok(freshRead.includes('after rotation, line two')); @@ -1369,21 +1375,17 @@ describe('Test harper_logger module', () => { ); }); - it('shape: level filtering is unaffected — production call sites omit mainLoggerRef, and the fix only changed how that default is spelled, not what it resolves to', () => { - const harper_logger = requireUncached(HARPER_LOGGER_MODULE); - const mainLoggerPrivate = harper_logger.__get__('mainLogger'); - mainLoggerPrivate.level = 1; // trace; distinct from createLogger's 'info' default below - - const probeDefault = harper_logger.createLogger({ level: 'info' }); - const probeExplicit = harper_logger.createLogger({ level: 'info' }); - const probePath = path.join(shapeCaseDir, 'unused.log'); - // Every production call site (applyLogSettings, forComponent) omits the 4th argument; - // this is that shape, compared against spelling the same default out explicitly. - harper_logger.updateLogger(probeDefault, { path: `${probePath}.a` }); - harper_logger.updateLogger(probeExplicit, { path: `${probePath}.b` }, undefined, mainLoggerPrivate); - - assert.strictEqual(probeDefault.level, mainLoggerPrivate.level); - assert.strictEqual(probeDefault.level, probeExplicit.level); + it('shape: a logger with no level of its own resolves it via mainLoggerRef, the same fallback this fix left in place — only the mainLogger -> mainLoggerRef parameter name changed on that line', () => { + const mainLogPath = path.join(shapeCaseDir, 'hdb.log'); + const testMainLogger = createLogger({ path: mainLogPath, level: 'trace' }); + shapeLoggersToCleanup.push(testMainLogger); + updateLogger(testMainLogger, { path: mainLogPath, level: 'trace' }, undefined, testMainLogger); + + const probe = testMainLogger.forComponent('levelProbe'); + shapeLoggersToCleanup.push(probe); + updateLogger(probe, { path: path.join(shapeCaseDir, 'probe.log') }, 'levelProbe', testMainLogger); + + assert.strictEqual(probe.level, testMainLogger.level); }); }); From d9fe89e7f030e6fcfd46e8762d369caabd343934 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Mon, 12 Oct 2026 07:16:06 -0600 Subject: [PATCH 3/5] test(logging): fix a mutation-proof gap in the level-fallback test, trim remaining narration Round-2 review found the rewritten level test couldn't actually catch its target: forComponent copies level at creation, and main was already at 'trace' by the time forComponent ran, so the probe inherited 'trace' before updateLogger's mainLoggerRef fallback ever ran. A mutation check (removing the `?? mainLoggerRef?.level` fallback and rebuilding) confirmed the test stayed green. Reordered it the same way as the first test: create the probe while main is still at 'info', then bump main to 'trace' and update the probe with no level of its own, so only the fallback can deliver 'trace'. Re-ran the same mutation check - the test now fails as expected, then restored and rebuilt clean. Also dropped the remaining comments that only restated adjacent code. Dispatch-Task: harper-upgrade-rule-logger-rotation-530 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01524gnfYt96yuXWh7KqpsET --- unitTests/utility/logging/harper_logger.test.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/unitTests/utility/logging/harper_logger.test.js b/unitTests/utility/logging/harper_logger.test.js index 2652363c5b..3118656933 100644 --- a/unitTests/utility/logging/harper_logger.test.js +++ b/unitTests/utility/logging/harper_logger.test.js @@ -1239,9 +1239,8 @@ describe('Test harper_logger module', () => { }); }); - // Pins the caller-impact rule for #1877/#1880's rotation-inheritance fix: which `logger` - // usage shapes it changes and which it doesn't. The affected shape itself (a component/ - // external logger with its own path and no rotation block) is pinned above. + // The affected shape itself is pinned above; these pin the unaffected shapes plus one + // operational risk the fix introduces for logs that previously never rotated. describe('Test caller-impact shapes for the logger rotation-inheritance fix (#1877/#1880)', () => { const CALLER_SHAPES_DIR = path.join(__dirname, 'callerImpactShapesTest'); let shapeCaseDir; @@ -1315,7 +1314,6 @@ describe('Test harper_logger module', () => { const componentLogPath = path.join(shapeCaseDir, 'tailed-component.log'); const componentLogger = testMainLogger.forComponent('tailed'); shapeLoggersToCleanup.push(componentLogger); - // The #1877 shape: its own path, no rotation block of its own. updateLogger(componentLogger, { path: componentLogPath }, 'tailed', testMainLogger); assert.deepStrictEqual(componentLogger.rotation, mainRotation); @@ -1377,12 +1375,17 @@ describe('Test harper_logger module', () => { it('shape: a logger with no level of its own resolves it via mainLoggerRef, the same fallback this fix left in place — only the mainLogger -> mainLoggerRef parameter name changed on that line', () => { const mainLogPath = path.join(shapeCaseDir, 'hdb.log'); - const testMainLogger = createLogger({ path: mainLogPath, level: 'trace' }); + const testMainLogger = createLogger({ path: mainLogPath, level: 'info' }); shapeLoggersToCleanup.push(testMainLogger); - updateLogger(testMainLogger, { path: mainLogPath, level: 'trace' }, undefined, testMainLogger); + updateLogger(testMainLogger, { path: mainLogPath, level: 'info' }, undefined, testMainLogger); + // Created while main is still at 'info', so forComponent's own copy-at-creation of + // `protoLogger.level` (unrelated to this fix) cannot be what delivers 'trace' below — + // only updateLogger's mainLoggerRef fallback, with no level of its own, can. const probe = testMainLogger.forComponent('levelProbe'); shapeLoggersToCleanup.push(probe); + + updateLogger(testMainLogger, { path: mainLogPath, level: 'trace' }, undefined, testMainLogger); updateLogger(probe, { path: path.join(shapeCaseDir, 'probe.log') }, 'levelProbe', testMainLogger); assert.strictEqual(probe.level, testMainLogger.level); From f8ead8b874063c651c1579c21d7c61be501c0f2a Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Mon, 12 Oct 2026 07:32:28 -0600 Subject: [PATCH 4/5] test(logging): close the last level-test mutation gap, drop PR-history asides from comments Round-3 review found one gap left: deleting the whole level-assignment line (not just its mainLoggerRef fallback) left both main and the probe at their starting 'info' level, so the equality assertion still passed. Capture the probe's pre-fallback level and assert it actually changed, which only the fallback running can produce. Reconfirmed with the same mutation-check process as the prior two rounds (delete the line, rebuild, see it fail; restore, rebuild, confirm clean). Also dropped the "(unrelated to this fix)" / PR-number asides review legs kept flagging as narration, keeping only the structural why. Dispatch-Task: harper-upgrade-rule-logger-rotation-530 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01524gnfYt96yuXWh7KqpsET --- unitTests/utility/logging/harper_logger.test.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/unitTests/utility/logging/harper_logger.test.js b/unitTests/utility/logging/harper_logger.test.js index 3118656933..f33d5eb698 100644 --- a/unitTests/utility/logging/harper_logger.test.js +++ b/unitTests/utility/logging/harper_logger.test.js @@ -1269,9 +1269,9 @@ describe('Test harper_logger module', () => { const testMainLogger = createLogger({ path: mainLogPath, level: 'info' }); shapeLoggersToCleanup.push(testMainLogger); - // Created before main's own rotation is installed, so forComponent's copy-at-creation - // of `protoLogger.rotation` (unrelated to this fix) cannot be what delivers rotation - // below — only the shared file sink at mainLogPath can. + // Created before main's own rotation is installed, so forComponent's own copy-at-creation + // of `protoLogger.rotation` cannot be what delivers rotation below — only the shared file + // sink at mainLogPath can. const externalLikeLogger = testMainLogger.forComponent('external'); shapeLoggersToCleanup.push(externalLikeLogger); updateLogger(testMainLogger, { path: mainLogPath, rotation: mainRotation }, undefined, testMainLogger); @@ -1380,15 +1380,20 @@ describe('Test harper_logger module', () => { updateLogger(testMainLogger, { path: mainLogPath, level: 'info' }, undefined, testMainLogger); // Created while main is still at 'info', so forComponent's own copy-at-creation of - // `protoLogger.level` (unrelated to this fix) cannot be what delivers 'trace' below — - // only updateLogger's mainLoggerRef fallback, with no level of its own, can. + // `protoLogger.level` cannot be what delivers 'trace' below — only updateLogger's + // mainLoggerRef fallback, with no level of its own, can. const probe = testMainLogger.forComponent('levelProbe'); shapeLoggersToCleanup.push(probe); + const levelBeforeFallback = probe.level; updateLogger(testMainLogger, { path: mainLogPath, level: 'trace' }, undefined, testMainLogger); updateLogger(probe, { path: path.join(shapeCaseDir, 'probe.log') }, 'levelProbe', testMainLogger); assert.strictEqual(probe.level, testMainLogger.level); + // Guards against a mutant that drops the whole level assignment rather than just its + // fallback: main's own level would then also never move off its starting value, so the + // equality above would hold trivially without the fallback ever running. + assert.notStrictEqual(probe.level, levelBeforeFallback); }); }); From 8d93748b58f41573da25c6b65f62f23fc6d6ef8f Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Mon, 12 Oct 2026 07:39:28 -0600 Subject: [PATCH 5/5] test(logging): trim remaining narrating comments per round-4 review No logic change: drops the describe-block header, the tailer-simulation restatement, the polling-loop restatement, and shortens the mutation-guard comment to the one clause that states why, per round-4's nit. Dispatch-Task: harper-upgrade-rule-logger-rotation-530 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01524gnfYt96yuXWh7KqpsET --- unitTests/utility/logging/harper_logger.test.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/unitTests/utility/logging/harper_logger.test.js b/unitTests/utility/logging/harper_logger.test.js index f33d5eb698..87c51695df 100644 --- a/unitTests/utility/logging/harper_logger.test.js +++ b/unitTests/utility/logging/harper_logger.test.js @@ -1239,8 +1239,6 @@ describe('Test harper_logger module', () => { }); }); - // The affected shape itself is pinned above; these pin the unaffected shapes plus one - // operational risk the fix introduces for logs that previously never rotated. describe('Test caller-impact shapes for the logger rotation-inheritance fix (#1877/#1880)', () => { const CALLER_SHAPES_DIR = path.join(__dirname, 'callerImpactShapesTest'); let shapeCaseDir; @@ -1322,8 +1320,6 @@ describe('Test harper_logger module', () => { () => fs.existsSync(componentLogPath) && fs.readFileSync(componentLogPath, 'utf8').includes('line one') ); - // Simulates a tailer that follows the descriptor (e.g. `tail -f`'s default mode), - // opened before rotation renames the file out from under it. const tailerFd = fs.openSync(componentLogPath, 'r'); try { for (let i = 0; i < 30; i++) componentLogger.info(`padding ${i} ${'x'.repeat(80)}`); @@ -1334,8 +1330,7 @@ describe('Test harper_logger module', () => { }); // The 30-line burst against a 1K cap rotates several times in a fast cascade; writing // line two the instant the first archive appears can still land it in an - // intermediate generation that itself rotates again moments later. Wait for the - // archive count to hold steady across a poll before writing past the cascade. + // intermediate generation that itself rotates again moments later. let lastRotatedCount = -1; await waitFor( () => { @@ -1390,9 +1385,7 @@ describe('Test harper_logger module', () => { updateLogger(probe, { path: path.join(shapeCaseDir, 'probe.log') }, 'levelProbe', testMainLogger); assert.strictEqual(probe.level, testMainLogger.level); - // Guards against a mutant that drops the whole level assignment rather than just its - // fallback: main's own level would then also never move off its starting value, so the - // equality above would hold trivially without the fallback ever running. + // Main's level comes from the same assignment, so equality alone can't detect its removal. assert.notStrictEqual(probe.level, levelBeforeFallback); }); });