fix(job): wire onTokensRefreshed into startComputeJob (#1461) - #1464
Conversation
Pass persistTokensRefreshedByAdapter(target) as the onTokensRefreshed callback to SASjs.startComputeJob in both executeJobViya (job execute command) and executeFlow (flow command), so rotated refresh tokens are persisted back to the target config during long-running compute jobs — the same pattern already used by executeScript in run.ts, executeCode.ts, and executeDeployScriptSasViya.ts. The adapter side (threading onTokensRefreshed through startComputeJob to executeComputeJob) is already in place; this completes the CLI wiring. Resolves #1461.
| macroVars?.macroVars | ||
| macroVars?.macroVars, | ||
| undefined, | ||
| persistTokensRefreshedByAdapter(target) |
There was a problem hiding this comment.
This call does not compile against the currently published adapter. CI fails at the build step with:
src/commands/job/internal/execute/viya.ts(117,7): error TS2554: Expected 2-9 arguments, but got 10.
The published @sasjs/adapter@4.18.0 startComputeJob signature ends at verboseMode?: VerboseMode (9 params) and has no onTokensRefreshed parameter yet — that parameter is added by adapter PR #899, which is not yet merged/published.
This PR is therefore blocked on #899 being merged and released (the ^4.18.0 range will then resolve to the new version). Until then CI is red on both Linux and Windows runners. Consider keeping this PR in draft, or landing it only after #899 is published.
| job.macroVars | ||
| job.macroVars, | ||
| undefined, | ||
| persistTokensRefreshedByAdapter(target) |
There was a problem hiding this comment.
Same TS2554 compile error here:
src/commands/flow/internal/executeFlow.ts(71,11): error TS2554: Expected 2-9 arguments, but got 10.
Blocked on adapter #899 for the same reason as viya.ts. The argument order itself is correct (verified against the PR #899 signature: …, variables, verboseMode, onTokensRefreshed), so once #899 is published this will compile — but it cannot merge in its current state.
There was a problem hiding this comment.
Hermes Agent Code Review
Verdict: REQUEST_CHANGES — the PR cannot compile against the currently published adapter; CI is red on both Linux and Windows. Blocked on adapter PR #899.
Critical
- TypeScript build failure (blocking). Both
startComputeJobcall sites pass 10 arguments, but the published@sasjs/adapter@4.18.0accepts at most 9 (it has noonTokensRefreshedparameter). CI output:Thesrc/commands/flow/internal/executeFlow.ts(71,11): error TS2554: Expected 2-9 arguments, but got 10. src/commands/job/internal/execute/viya.ts(117,7): error TS2554: Expected 2-9 arguments, but got 10.onTokensRefreshedparameter is introduced by adapter PR #899, which is not yet merged or published. This PR must wait for #899 to be merged, released, and for the CLI lockfile to pick up the new version (^4.18.0will resolve to it). I verified the published 4.18.0.d.tsdirectly:startComputeJob(..., variables?, verboseMode?)— no 10th param.
Warnings
- None beyond the above.
Suggestions
- Once #899 lands, the argument order here is correct (I verified it against the #899 signature:
…, variables, verboseMode, onTokensRefreshed). To avoid future off-by-one risk on these long positional calls, consider tracking the adapter's move to an options object if/when it happens. - The new test mocks
configUtils.persistTokensRefreshedByAdapterto returnjest.fn()and asserts the laststartComputeJobargisDefined()andtypeof === 'function'. Consider also asserting the returned function is the same instance the spy returned (e.g. capture it:const cb = jest.fn(); spy.mockImplementation(() => cb)thenexpect(callArgs[10]).toBe(cb)), which would prove the wiring end-to-end rather than just that a function was passed.
Looks Good
persistTokensRefreshedByAdapter(target)inutils/config.tsis well-implemented: it reuses the samesanitizeEnvValue+saveTokenspath asgetAuthConfig, so rotated Viya refresh tokens are persisted consistently and client/secret are preserved in.env.{target}. Good doc comment explaining the single-use/rotating token rationale.- Both call sites (
viya.ts,executeFlow.ts) thread the callback with the same argument order, and the two existing tests were updated consistently to expectexpect.any(Function)as the final arg. - The new dedicated test verifies
persistTokensRefreshedByAdapteris called withtargetand that a function reachesstartComputeJob.
Reviewed by Hermes Agent (GitHub App)
Coverage reportTotal coverage
Show files with reduced coverage 🔻Reduced coverage
Report generated by 🧪jest coverage report action from 36902e3 |
resolved by main's @sasjs/adapter bump to 4.19.0
Resolves #1461
Summary
sasjs job execute(andsasjs flow execute) didn't pass anonTokensRefreshedcallback toSASjs.startComputeJob, unlikeexecuteScriptinrun.ts,executeCode.ts, andexecuteDeployScriptSasViya.ts. For password-grant users with no client/secret fallback, a stale refresh token forces a manual re-login after long-running compute jobs.This PR wires
persistTokensRefreshedByAdapter(target)as theonTokensRefreshedcallback in both call sites:src/commands/job/internal/execute/viya.ts(executeJobViya)src/commands/flow/internal/executeFlow.ts(executeFlow)The adapter side (threading
onTokensRefreshedthroughstartComputeJobtoexecuteComputeJob) is already in place in@sasjs/adapter4.18.0; this completes the CLI wiring.Tests
Added a new test case in
src/commands/job/spec/execute.spec.tsverifying thatpersistTokensRefreshedByAdapter(target)is called with the target and that the resulting function is passed as the last argument tostartComputeJob. Also updated the two existing test cases to assertexpect.any(Function)for the new callback argument.