Skip to content

Hoist the log tag into one constant per file - #519

Open
Pixnop wants to merge 10 commits into
devfrom
refactor/488-log-tag-constants
Open

Pixnop wants to merge 10 commits into
devfrom
refactor/488-log-tag-constants

Conversation

@Pixnop

@Pixnop Pixnop commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

What changes

One LOG_PREFIX constant per file, interpolated into the log lines, in the ten host files that carried more than one copy of their own provenance prefix. 195 hand-typed tags folded, and one spelling per file by construction. The name follows the three host files that already hoist theirs (backgroundHandlers.ts, optimumHandlers.ts, optimumManifest.ts); the renderer's twenty files call theirs LOG_TAG, and neither name changed here.

file tags folded note
src/ipc/handlers/gameHandlers.ts 63 16 were under the short [back] [ipc] [gameHandlers.ts]
src/ipc/handlers/modsHandlers.ts 33
src/ipc/handlers/pathsHandlers.ts 25
src/main/index.ts 16
src/config/configManager.ts 14 5 were under the short [back] [config] [configManager.ts]
src/ipc/adapters/modScan.ts 10 includes the cache sweep's origin field, which carries the same text into the sweep's lines
src/ipc/handlers/netHandlers.ts 10
src/ipc/handlers/utilsHandlers.ts 9
src/ipc/handlers/accountHandlers.ts 8 all were the bare file name
src/main/orphanedTempFiles.ts 7 all were the bare file name

36 log lines change text, every one of them from a bare or short file name to the path qualified spelling its neighbours already used. Grepping [back] [ipc] [ipc/handlers/gameHandlers.ts] now returns all 63 of that file's lines instead of 47.

The line count is close to a wash (+215/-214), because each log line is rewritten rather than removed and ten files gain a declaration. The saving is the repeated literal itself: those ten files go from 204014 bytes to 199213.

Plain strings that carried a tag became template literals on the way, which is what pulls them inside the reach of tests/log-provenance.test.ts for the first time.

What stays

  • src/ipc/network.ts keeps its two [back] [ipc] [network.ts] tags. Two lines and no concept removed is below the bar for a constant, even though the spelling is bare.
  • Six single-tag files (catalogCache.ts, appUpdaterHandlers.ts, autoUpdaterEvents.ts, consoleTransportSafety.ts, shouldPreventClose.ts, updaterLogger.ts) keep their literal, which is what the issue's own order asks: one occurrence is not worth a constant.
  • backgroundHandlers.ts, optimumHandlers.ts and optimumManifest.ts already hoisted theirs and are untouched.
  • The provenance rule itself, the redaction in logMessage, the hexagonal split, the path policy, the IPC validation at the boundary, the mutation tested guards and the accessibility work. tests/log-provenance.test.ts, tests/security-boundaries.test.ts, tests/text-contrast.test.ts and tests/i18n/i18n-parity.test.ts keep their rules.

Behaviour

No test file is touched and none is deleted. Before each commit, every tag carrying literal in the file was rendered back to plain text and diffed against the same rendering of the origin/dev version. The only difference is the constant's own declaration, so the 36 short spellings are the sole text change and the other 159 lines come out byte identical.

tests/log-provenance.test.ts was the one to watch. Its scan matches logMessage(, logMods( or window.api.utils.logMessage( followed by a template literal, so a per-file tagged wrapper would have quietly taken all these call sites out of it. The literal call shape is kept instead, and the scan grew rather than shrank: 261 matched calls and 293 interpolations on dev, 295 and 478 here. LOG_PREFIX ends in "PREFIX", which is not on the risky word list, so the test passes untouched.

origin/refactor/487-host-scaffolding adds a CHANGE_PERMS debug line to pathsHandlers.ts with the prefix typed out. git merge-tree reports no conflict between this branch and any of the eleven open branches, so whichever of the two lands second can fold that one line into the constant.

Gate

check result
npm run typecheck clean
npm run lint:ci 0 errors, 14 warnings, the same pre-existing react-hooks/exhaustive-deps ones as dev, none new
npm run format:check all matched files use Prettier code style
npm run test:coverage 242 files, 4461 passed, 2 skipped, the same counts as dev
coverage dev here
statements 94.57% 94.58%
branches 91.01% 91.02%
functions 95.22% 95.22%
lines 96.26% 96.29%

The three fractional gains are the ten new declarations, each one a covered statement.

Closes #488. Part of #492.

Sixty-three hand-typed provenance prefixes, sixteen of them under a shorter
spelling of the file name than the other forty-seven, become one constant the
log lines interpolate. Grepping the logs for this file now finds all of its
lines instead of three quarters of them.
Twenty-five copies of the same provenance prefix become one constant. The five
that were plain strings become template literals, which puts them inside the
reach of the log provenance scan for the first time.
Thirty-three copies of the same prefix become one constant.
Ten copies of the same prefix become one constant, including the cache sweep's
origin field, which carries the same text into the sweep's own log lines.
Fourteen copies under two spellings of the file name become one constant under
the path qualified spelling its neighbours use.
Seven copies of a bare file name become one constant, path qualified like the
rest of the host layer. The lines still go out through the injected log port,
so what the sweep's tests observe is unchanged.
Eight copies of a bare file name become one constant, path qualified like its
neighbours.
Sixteen copies of the same prefix become one constant.
Ten copies of the same prefix become one constant.
Nine copies of the same prefix become one constant. All but one were plain
strings, so they enter the log provenance scan for the first time.
@Pixnop
Pixnop requested a review from Zaldaryon September 20, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant