feat(mocks): emulate the %mpeinit diagnostics dump
Build / Build-and-ng-test (pull_request) Successful in 5m21s
Lighthouse Checks / lighthouse (pull_request) Successful in 21m19s
Build / Build-and-test-development (pull_request) Successful in 28m58s

The SAS %mpeinit macro dumps work.browser_url_vars and work.browser_info
to the log when _debug is on (2477, fields,log,trace, 131 or 128). The JS
mocks had no equivalent, so a mocked session could not show what the
client sent.

Add mpeinit() to dcMockUtils.js and call it at the bottom of the file -
the same place the SAS services call %mpeinit - so every mock service that
eval()s the utilities dumps the two input tables. console.log output is
returned in the request log, so it lands in Data Controller's SAS Log tab
exactly as the SAS version does.

The tables are read with fetchRaw, so both the JSON body shape and the
multipart _WEBIN_NAME / _WEBIN_FILEREF shape work. Values are dumped with
the same NOTE: prefixes and name=value formatting as the macro.
This commit is contained in:
dc committed 2026-09-27 22:08:31 +00:00
1 parent 10122312cb
commit 200ee8931d
1 file changed
+71
+71
View File
@@ -5,6 +5,7 @@
* Provides:
* - fetchTable / fetchRaw / parseCsv : emulate SAS %webout(FETCH)
* - webOutOpen / webOutObj / webOutClose : emulate SAS %webout(OPEN/OBJ/CLOSE)
* - mpeinit : emulate the %mpeinit debug dump
* - formatSasValue : apply a SAS format to a numeric value
* - parseFormattedToSas : convert an ISO string back to a SAS numeric
* - getDdType : derive DATE/DATETIME/TIME/N/C from a column format
@@ -1209,3 +1210,73 @@ function webOutSend(tables) {
}
webOutClose()
}
// ─── %mpeinit() emulation ────────────────────────────────────────────────────
/**
* The `_debug` values that mean "debug on", mirroring the test in mpeinit.sas.
*
* 131 is what the adapter sends - SASjsApiClient.executeJob() puts it on every
* server-mode request, and on the multipart form when the payload goes out as
* FormData. 128 is what arrives on the Viya WEB JES path when runAsTask is
* enabled, and 2477 / 'fields,log,trace' are the SASjs debug values.
*/
const MPEINIT_DEBUG_VALUES = ['2477', 'fields,log,trace', '131', '128']
/* Mirrors the &mpeinit=1 guard in the SAS macro: dump once per execution. */
let _mpeinitDone = false
/**
* Dumps the browser_url_vars and browser_info input tables, mirroring the
* debug block of %mpeinit (sas/sasjs/macros/mpeinit.sas).
*
* The SAS macro reads work.browser_url_vars (name/value pairs taken from the
* query string) and work.browser_info (the browser fingerprint). Both arrive
* here as input tables - see fetchRaw() - and are dumped with console.log,
* which SASjs Server returns in the request's log (after its
* SASJS_LOGS_SEPARATOR marker), so the dump shows up in Data Controller's
* SAS Log tab exactly as the SAS version does.
*
* Called at the bottom of this file, so the services that eval() it dump the
* tables at startup - the same place %mpeinit() runs in the SAS services.
* That covers every diagnostics-carrying service (startup, editors, auditors);
* the mocks that do not load this file (lineage, metanav, usernav, a few
* public ones) have no equivalent startup step in the SAS app either.
*
* Difference from the SAS version: the header line is printed once per table,
* where SAS repeats it for every row (its PUTLOG sits inside the SET loop).
*/
function mpeinit() {
if (_mpeinitDone) return
const debugValue = typeof _debug === 'undefined' ? '' : _debug
if (MPEINIT_DEBUG_VALUES.indexOf(String(debugValue)) < 0) return
_mpeinitDone = true
const urlVars = fetchRaw('browser_url_vars')
if (urlVars === null) {
console.log('NOTE: mpeinit: no work.browser_url_vars on this request')
} else {
console.log('NOTE: mpeinit: work.browser_url_vars:')
parseCsv(urlVars).forEach(row => {
console.log(
'name=' + colVal(row, 'name') + ' value=' + colVal(row, 'value')
)
})
}
const browserInfo = fetchRaw('browser_info')
if (browserInfo === null) {
console.log('NOTE: mpeinit: no work.browser_info on this request')
} else {
console.log('NOTE: mpeinit: work.browser_info:')
parseCsv(browserInfo).forEach(row => {
console.log(Object.keys(row).map(col => col + '=' + row[col]).join(' '))
})
}
}
/* Every service that eval()s this file runs %mpeinit() at startup, the same
place the SAS services call it. */
mpeinit()