-
Notifications
You must be signed in to change notification settings - Fork 11
fix(run): stop double-wrapping startup URLs when node.hostname is a URL #2219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dawsontoth
wants to merge
7
commits into
main
Choose a base branch
from
claude/harper-double-wrapped-urls-a5cb92
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+194
−12
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c6e7796
fix(run): stop double-wrapping startup URLs when node.hostname is a URL
dawsontoth 894e791
refactor(run): use template literals for startup URL lines
dawsontoth 90b020f
refactor(nodeName): address cross-model review findings
dawsontoth b1d8134
refactor(nodeName): tighten comments and pin the fallback path
dawsontoth 0487468
test(nodeName): restore coverage of getThisNodeHostname wiring
dawsontoth 2286755
test(run): cover startupLog banner URLs end-to-end (#2218)
dawsontoth d7b5c46
test(run): restore config in banner-test cleanup; trim helper comment
dawsontoth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| 'use strict'; | ||
|
|
||
| // End-to-end guard for the #2218 fix (double-wrapped startup URLs). The pure helper | ||
| // nodeNameToDisplayHost() is unit-tested in unitTests/server/nodeName.test.js, but nothing exercised | ||
| // startupLog() itself, so a call site that switched back from getThisNodeHostname() to | ||
| // getThisNodeName() would recreate the `http://http://host:port/` banner while that suite stayed | ||
| // green. This drives the real, exported startupLog() with a real (URL-valued) node.hostname and | ||
| // asserts the Operations-API HTTP/HTTPS and REST URL lines it prints are well-formed. | ||
|
|
||
| const testUtils = require('../testUtils.js'); | ||
| testUtils.preTestPrep(); | ||
|
|
||
| const assert = require('assert'); | ||
|
|
||
| const env = require('#src/utility/environment/environmentManager'); | ||
| const { CONFIG_PARAMS } = require('#src/utility/hdbTerms'); | ||
| const { clearThisNodeName } = require('#src/server/nodeName'); | ||
| const { startupLog } = require('#src/bin/run'); | ||
|
|
||
| describe('startupLog banner URLs (#2218 double-wrapped startup URLs)', () => { | ||
| const originalConsoleLog = console.log; | ||
| // initTestEnvironment() sets operationsApi_network_port=9925 and http_port=9926; the secure | ||
| // operations port is unset by default, so tests that need it set (and restore) it explicitly. Read | ||
| // the live ops port at assert time rather than caching it, so the expected URL always tracks the | ||
| // same config value startupLog() reads (no load-time-vs-run-time skew if another suite mutates it). | ||
| const opsPort = () => env.get(CONFIG_PARAMS.OPERATIONSAPI_NETWORK_PORT); | ||
|
|
||
| let originalNodeHostname; | ||
| let originalSecurePort; | ||
|
|
||
| beforeEach(() => { | ||
| originalNodeHostname = env.get(CONFIG_PARAMS.NODE_HOSTNAME); | ||
| originalSecurePort = env.get(CONFIG_PARAMS.OPERATIONSAPI_NETWORK_SECUREPORT); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| console.log = originalConsoleLog; | ||
| // Restore (not blank) the config this suite mutated so it can't leak into other suites in | ||
| // the same mocha process. | ||
| env.setProperty(CONFIG_PARAMS.NODE_HOSTNAME, originalNodeHostname); | ||
| env.setProperty(CONFIG_PARAMS.OPERATIONSAPI_NETWORK_SECUREPORT, originalSecurePort); | ||
| clearThisNodeName(); | ||
| }); | ||
|
|
||
| // Runs startupLog() with node.hostname set to `hostname`, captures the emitted banner, and | ||
| // returns it as a single string. | ||
| function bannerFor(hostname, portResolutions = new Map()) { | ||
| env.setProperty(CONFIG_PARAMS.NODE_HOSTNAME, hostname); | ||
| clearThisNodeName(); // getThisNodeName() memoizes; drop any value cached by an earlier test | ||
|
|
||
| const lines = []; | ||
| console.log = (...args) => lines.push(args.join(' ')); | ||
| try { | ||
| startupLog(portResolutions); | ||
| } finally { | ||
| console.log = originalConsoleLog; | ||
| } | ||
| return lines.join('\n'); | ||
| } | ||
|
|
||
| it('composes well-formed ops + REST URLs when node.hostname is a full URL', () => { | ||
|
dawsontoth marked this conversation as resolved.
|
||
| // A URL-valued node.hostname is exactly the #2218 trigger: getThisNodeName() returns the whole | ||
| // URL, so the pre-fix banner produced `http://http://localhost:9926:9925/`. | ||
| const restPort = 9926; | ||
| const portResolutions = new Map([[restPort, [{ name: 'rest', protocol_name: 'HTTP' }]]]); | ||
|
|
||
| const banner = bannerFor('http://localhost:9926', portResolutions); | ||
|
|
||
| assert.ok(!banner.includes('http://http://'), `banner double-wrapped a scheme:\n${banner}`); | ||
| assert.ok( | ||
| banner.includes(`http://localhost:${opsPort()}/`), | ||
| `expected the Operations-API URL http://localhost:${opsPort()}/ in banner:\n${banner}` | ||
| ); | ||
| assert.ok( | ||
| banner.includes(`http://localhost:${restPort}/`), | ||
| `expected the REST URL http://localhost:${restPort}/ in banner:\n${banner}` | ||
| ); | ||
| }); | ||
|
|
||
| it('composes well-formed HTTPS ops + REST URLs when node.hostname is a full URL', () => { | ||
| const securePort = 9935; | ||
| const restPort = 9927; | ||
| env.setProperty(CONFIG_PARAMS.OPERATIONSAPI_NETWORK_SECUREPORT, securePort); | ||
| const portResolutions = new Map([[restPort, [{ name: 'rest', protocol_name: 'HTTPS' }]]]); | ||
|
|
||
| const banner = bannerFor('https://localhost:9926', portResolutions); | ||
|
|
||
| assert.ok(!banner.includes('https://https://'), `banner double-wrapped a scheme:\n${banner}`); | ||
| assert.ok( | ||
| banner.includes(`https://localhost:${securePort}/`), | ||
| `expected the Operations-API URL https://localhost:${securePort}/ in banner:\n${banner}` | ||
| ); | ||
| assert.ok( | ||
| banner.includes(`https://localhost:${restPort}/`), | ||
| `expected the REST URL https://localhost:${restPort}/ in banner:\n${banner}` | ||
| ); | ||
| }); | ||
|
|
||
| it('leaves a plain bare-host node.hostname unchanged in composed URLs', () => { | ||
| // The complement of the URL case: normalization must not corrupt a hostname that was already | ||
| // bare (over-stripping would be just as wrong as double-wrapping). | ||
| const restPort = 9926; | ||
| const portResolutions = new Map([[restPort, [{ name: 'rest', protocol_name: 'HTTP' }]]]); | ||
|
|
||
| const banner = bannerFor('node-1.example.com', portResolutions); | ||
|
|
||
| assert.ok( | ||
| banner.includes(`http://node-1.example.com:${opsPort()}/`), | ||
| `expected the Operations-API URL http://node-1.example.com:${opsPort()}/ in banner:\n${banner}` | ||
| ); | ||
| assert.ok( | ||
| banner.includes(`http://node-1.example.com:${restPort}/`), | ||
| `expected the REST URL http://node-1.example.com:${restPort}/ in banner:\n${banner}` | ||
| ); | ||
| }); | ||
| }); | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swapping
getThisNodeNameforgetThisNodeHostnameis the only meaningful change, the rest is pure formatting.