You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LinearService constructor sets process.env.LINEAR_API_TOKEN as a side effect (src/lib/LinearService.ts:50), and all functions in src/utils/linear.ts rely on this env var being set via getLinearApiToken() → createLinearClient().
This caused a bug (#590) where il list --children called getLinearChildIssues without first instantiating LinearService, so the token was never in the environment.
Setting env vars as a side effect is fragile — any new code path that calls Linear utility functions without going through LinearService will hit the same UNAUTHORIZED error.
Desired behavior
All functions in src/utils/linear.ts should accept the API token as a parameter (with env var as fallback), passed down through the call stack. LinearService should stop setting process.env.LINEAR_API_TOKEN.
Scope
src/utils/linear.ts — Update all exported functions to accept an optional apiToken parameter and pass it to createLinearClient():
src/lib/LinearService.ts — Stop setting process.env.LINEAR_API_TOKEN. Instead, store the token as an instance property and pass it to each linear.ts function call.
src/utils/image-processor.ts — Check if it reads LINEAR_API_TOKEN from env; if so, update to accept it as a parameter.
Tests — Update LinearService.test.ts to remove env var assertions. Test files that set the env var for test setup are fine.
Problem
LinearServiceconstructor setsprocess.env.LINEAR_API_TOKENas a side effect (src/lib/LinearService.ts:50), and all functions insrc/utils/linear.tsrely on this env var being set viagetLinearApiToken()→createLinearClient().This caused a bug (#590) where
il list --childrencalledgetLinearChildIssueswithout first instantiatingLinearService, so the token was never in the environment.Setting env vars as a side effect is fragile — any new code path that calls Linear utility functions without going through
LinearServicewill hit the sameUNAUTHORIZEDerror.Desired behavior
All functions in
src/utils/linear.tsshould accept the API token as a parameter (with env var as fallback), passed down through the call stack.LinearServiceshould stop settingprocess.env.LINEAR_API_TOKEN.Scope
src/utils/linear.ts— Update all exported functions to accept an optionalapiTokenparameter and pass it tocreateLinearClient():fetchLinearIssuecreateLinearIssuecreateLinearChildIssuecreateLinearCommentupdateLinearIssueStategetLinearCommentupdateLinearCommentfetchLinearIssueCommentsgetLinearChildIssues(already done in Refactor Linear API token: pass through stack instead of setting env var #590)createLinearIssueRelationgetLinearIssueDependenciesdeleteLinearIssueRelationfetchLinearIssueList(already acceptsapiToken)findLinearIssueRelationsrc/lib/LinearService.ts— Stop settingprocess.env.LINEAR_API_TOKEN. Instead, store the token as an instance property and pass it to eachlinear.tsfunction call.src/utils/image-processor.ts— Check if it readsLINEAR_API_TOKENfrom env; if so, update to accept it as a parameter.Tests — Update
LinearService.test.tsto remove env var assertions. Test files that set the env var for test setup are fine.