Reconcile .env.example with the environment variables the server reads, and guard the drift - #5926
Merged
Conversation
…e drift (#5706) .env.example is the only place a fresh install can discover what it can configure, and every one of these variables is read lazily with a silent fallback — so an undocumented one is invisible: the feature just uses its default and nothing says otherwise. The file had rotted in both directions. Forward: 16 variables the server reads were undocumented, including the two that made the gap actively confusing. signalSync.js reads SIGNAL_DIR, SIGNAL_CONFIG_PATH and SIGNAL_DB_PATH in one three-line block and only the middle one was documented, so relocating a Signal install configured half of it. Each new entry names its reading module and its default. Reverse: PORTOS_UI_MAX_MEMORY was still advertised long after #5322 made the Vite ceiling a fixed constant. Setting it did nothing; it is now removed. server/envExampleDrift.test.js checks both directions so this cannot recur. The forward scan covers server runtime modules with string and comment content blanked, so a `process.env.X` inside a vite config PortOS GENERATES for a user is not mistaken for a PortOS setting. The reverse scan is deliberately wide — every tracked code file in the repo, any language — because a false "this is dead" would block CI over a real setting; prose and tests are excluded so a doc mention cannot vouch for a key nothing reads. Its INHERITED_ENV allowlist is a category list with a reason per entry (OS-, toolchain- and test-harness- provided names a user would never put in .env) rather than a snapshot of today's diff, so it keeps meaning something as the tree grows. Registered in ALWAYS_RUN_TESTS because any server file can add a process.env read and .env.example is not a scope the selector routes anywhere.
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.
Summary
.env.examplehad drifted from what the server actually reads, in both directions. Every one of these variables is read lazily with a silent fallback, so an undocumented one is invisible — the feature just uses its default and nothing says otherwise.signalSync.jsreadsSIGNAL_DIR,SIGNAL_CONFIG_PATHandSIGNAL_DB_PATHin one three-line block and only the middle one was documented, so relocating a Signal install configured half of it.PORTOS_UI_MAX_MEMORYwas still advertised long after Configure portos-ui to restart before CoS memory warnings #5322 made the Vite ceiling a fixed constant — setting it did nothing.server/envExampleDrift.test.js, a guard for both directions, registered inALWAYS_RUN_TESTS(any server file can add aprocess.envread, and.env.exampleis not a scope the CI selector routes anywhere).Beyond the 13 variables the issue named, the same scan also turned up
PORT,PYTHON_BINandSLOTSTREAM_MODEL_DIR; all three are documented here too.How the guard avoids false positives
process.env.Xinside a vite config PortOS generates for a user is not mistaken for a PortOS setting.INHERITED_ENVis a category allowlist with a reason per entry — OS-, toolchain- and test-harness-provided names a user would never put in.env— rather than a snapshot of today's diff, so it keeps meaning something as the tree grows.All added values are placeholders. No real host, path, or credential appears anywhere in the diff.
Test plan
cd server && npx vitest run envExampleDrift.test.js— passes in both directions (~0.5s).process.env.PORTOS_PROBE_UNDOCUMENTEDread and a# PORTOS_PROBE_DEAD_VAR=line makes the guard fail on exactly those two, naming the file for the first. Both probes reverted.cd server && npm test— 37,674 passing. The 17 failures are pre-existing 10-second timeout flakes from running a large suite in a worktree underdata/; all 9 affected files pass when run on their own.scripts/repo-scan-guards.test.jsandscripts/ci-test-plan.test.jsconfirm the new scanner is registered.Closes #5706