test(node): make AuditLogger 'log() writes valid JSONL' test hermetic (sable-883t) - #211
Merged
Merged
Conversation
The gauntlet's 'AuditLogger — Error Paths' block never mocked ConfigManager, so AuditLogger.log() read the machine-global ~/.rafter/config.json and silently no-opped unless agent.audit.logAllActions happened to be set there. On a box whose global config omits the flag, 'log() writes valid JSONL entry' failed; on one that has it, it passed — a non-hermetic, machine-dependent test. Mock ConfigManager.prototype.load to return logAllActions: true in the block's beforeEach (mirroring node/tests/audit-logger.test.ts and the already-hermetic Python test_log_writes_valid_jsonl), and restore mocks in afterEach. Also annotate the pre-existing implicit-any .mock.calls callbacks surfaced while here. Fixes sable-883t.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
AuditLogger — Error Pathsblock innode/tests/error-handling-gauntlet.test.tsnever mockedConfigManager.AuditLogger.log()loads the machine-global~/.rafter/config.jsonand silently no-ops unlessagent.audit.logAllActionsis set there. Solog() writes valid JSONL entrypasses or fails depending on the box's global config — non-hermetic. On this dev box (~/.rafter/config.jsonexists but omits the flag) it was failing.Fix
ConfigManager.prototype.loadto returnlogAllActions: truein the block'sbeforeEach, andvi.restoreAllMocks()inafterEach. This mirrors the existing pattern innode/tests/audit-logger.test.tsand brings Node to parity with the already-hermetic Pythontest_log_writes_valid_jsonl.any.mock.callscallbacks in the same file (surfaced by the language server while editing).Verification
npx vitest run tests/error-handling-gauntlet.test.ts→ 58/58 pass.npx tsc --noEmit -p tsconfig.json→ 0 errors.~/.rafter/config.jsonlackslogAllActions, so the target test was genuinely failing here before the change and passes after.Parity
Python side already mocks config in its mirror test — no Python change needed.
Fixes sable-883t. Test-only; no runtime behavior change.