Skip to content

Commit 6e9df46

Browse files
committed
fix(poetry): skip binary verification when env vars bypass invocation
Guard _verifyPoetryAccessible with an env-var bypass check so poetry does not need to be installed when both TRUSTIFY_DA_POETRY_SHOW_TREE and TRUSTIFY_DA_POETRY_SHOW_ALL are set. Implements TC-4660 Assisted-by: Claude Code
1 parent 611cfd5 commit 6e9df46

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

src/providers/python_poetry.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ export default class Python_poetry extends Base_pyproject {
6161
// eslint-disable-next-line no-unused-vars
6262
async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
6363
let poetryBin = getCustomPath('poetry', opts)
64-
this._verifyPoetryAccessible(poetryBin)
64+
let envBypass = environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')
65+
&& environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL')
66+
if (!envBypass) {
67+
this._verifyPoetryAccessible(poetryBin)
68+
}
6569
let hasDevGroup = !!(parsed.tool?.poetry?.group?.dev || parsed.tool?.poetry?.['dev-dependencies'])
6670
let treeOutput = this._getPoetryShowTreeOutput(manifestDir, hasDevGroup, poetryBin)
6771
let showAllOutput = this._getPoetryShowAllOutput(manifestDir, poetryBin)

test/providers/python_pyproject.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,4 +697,54 @@ suite('testing python-poetry error handling', () => {
697697
expect(() => instance._verifyPoetryAccessible('poetry'))
698698
.to.throw('failed to check for poetry binary')
699699
}).timeout(TIMEOUT)
700+
701+
/** Verifies that _getDependencyData skips binary verification when both env vars bypass poetry. */
702+
test('verify _getDependencyData skips binary check when both env vars are set', async () => {
703+
let provider = await esmock('../../src/providers/python_poetry.js', {
704+
'../../src/tools.js': {
705+
getCustomPath: () => '/nonexistent/poetry',
706+
environmentVariableIsPopulated: (name) => {
707+
return name === 'TRUSTIFY_DA_POETRY_SHOW_TREE' || name === 'TRUSTIFY_DA_POETRY_SHOW_ALL'
708+
},
709+
invokeCommand: () => {
710+
let err = new Error('spawn /nonexistent/poetry ENOENT')
711+
err.code = 'ENOENT'
712+
throw err
713+
}
714+
}
715+
})
716+
717+
let instance = new provider.default()
718+
instance._getPoetryShowTreeOutput = () => ''
719+
instance._getPoetryShowAllOutput = () => ''
720+
instance._parsePoetryShowAll = () => new Map()
721+
instance._findLockFileDir = () => '/tmp'
722+
instance._extractMarkerData = () => ({})
723+
instance._parsePoetryTree = () => ({ directDeps: [], graph: new Map() })
724+
725+
await instance._getDependencyData('/tmp', '/tmp', { tool: {} }, {})
726+
}).timeout(TIMEOUT)
727+
728+
/** Verifies that _getDependencyData runs binary verification when env vars are not set. */
729+
test('verify _getDependencyData runs binary check when env vars are not set', async () => {
730+
let provider = await esmock('../../src/providers/python_poetry.js', {
731+
'../../src/tools.js': {
732+
getCustomPath: () => '/nonexistent/poetry',
733+
environmentVariableIsPopulated: () => false,
734+
invokeCommand: () => {
735+
let err = new Error('spawn /nonexistent/poetry ENOENT')
736+
err.code = 'ENOENT'
737+
throw err
738+
}
739+
}
740+
})
741+
742+
let instance = new provider.default()
743+
try {
744+
await instance._getDependencyData('/tmp', '/tmp', { tool: {} }, {})
745+
expect.fail('Expected error to be thrown')
746+
} catch (e) {
747+
expect(e.message).to.include('poetry is not accessible')
748+
}
749+
}).timeout(TIMEOUT)
700750
})

0 commit comments

Comments
 (0)