|
1 | 1 | import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises' |
2 | 2 | import { tmpdir } from 'node:os' |
3 | 3 | import { join } from 'node:path' |
4 | | -import { describe, expect, it } from 'vitest' |
| 4 | +import { describe, expect, it, onTestFinished } from 'vitest' |
5 | 5 | import type { Context } from '@deepseek-ai/cordis' |
6 | 6 | import type { Agent } from '@deepseek-ai/dsh-agent' |
7 | 7 | import type { |
@@ -337,6 +337,11 @@ describe('/loopx-init implementation', () => { |
337 | 337 | }) |
338 | 338 |
|
339 | 339 | it('selects an available Python 3.11+ interpreter for install and readback', async () => { |
| 340 | + const pythonPath = await mkdtemp(join(tmpdir(), 'loopx-installed-pythons-')) |
| 341 | + onTestFinished(() => rm(pythonPath, { recursive: true, force: true })) |
| 342 | + for (const name of ['python3.14', 'python3.13']) { |
| 343 | + await writeFile(join(pythonPath, name), '# fixture executable\n') |
| 344 | + } |
340 | 345 | const calls: Array<{ readonly file: string; readonly args: readonly string[] }> = [] |
341 | 346 | let installed = false |
342 | 347 | const runner: FileRunner = async (file, args) => { |
@@ -374,6 +379,7 @@ describe('/loopx-init implementation', () => { |
374 | 379 |
|
375 | 380 | const result = await initializeLoopX({ |
376 | 381 | runner, |
| 382 | + env: { PATH: pythonPath }, |
377 | 383 | skillsDir: '/fixture/skills', |
378 | 384 | runtimeDir: '/fixture/runtime', |
379 | 385 | }) |
@@ -406,6 +412,11 @@ describe('/loopx-init implementation', () => { |
406 | 412 | }) |
407 | 413 |
|
408 | 414 | it('skips an implicit version-compatible Python that cannot run pip', async () => { |
| 415 | + const pythonPath = await mkdtemp(join(tmpdir(), 'loopx-installed-pythons-')) |
| 416 | + onTestFinished(() => rm(pythonPath, { recursive: true, force: true })) |
| 417 | + for (const name of ['python3.14']) { |
| 418 | + await writeFile(join(pythonPath, name), '# fixture executable\n') |
| 419 | + } |
409 | 420 | const calls: Array<{ readonly file: string; readonly args: readonly string[] }> = [] |
410 | 421 | let installed = false |
411 | 422 | const runner: FileRunner = async (file, args) => { |
@@ -450,6 +461,7 @@ describe('/loopx-init implementation', () => { |
450 | 461 |
|
451 | 462 | const result = await initializeLoopX({ |
452 | 463 | runner, |
| 464 | + env: { PATH: pythonPath }, |
453 | 465 | skillsDir: '/fixture/skills', |
454 | 466 | runtimeDir: '/fixture/runtime', |
455 | 467 | }) |
@@ -493,7 +505,8 @@ describe('/loopx-init implementation', () => { |
493 | 505 | stage: 'install_cli', |
494 | 506 | causeKind: 'missing', |
495 | 507 | }) |
496 | | - expect(calls.some(call => call.file === 'python3.14')).toBe(false) |
| 508 | + expect(calls.filter(call => call.args[0] === '-c') |
| 509 | + .every(call => call.file === '/configured/python')).toBe(true) |
497 | 510 | expect(calls.some(call => ( |
498 | 511 | call.file === '/configured/python' |
499 | 512 | && call.args.join(' ') === '-m pip --version' |
|
0 commit comments