Skip to content

Fix runString temp path to use tmpdir() and add regression test#320

Open
dusan-maintains wants to merge 1 commit into
extrabacon:masterfrom
dusan-maintains:maintenance/fix-runstring-temp-path
Open

Fix runString temp path to use tmpdir() and add regression test#320
dusan-maintains wants to merge 1 commit into
extrabacon:masterfrom
dusan-maintains:maintenance/fix-runstring-temp-path

Conversation

@dusan-maintains
Copy link
Copy Markdown

Summary

  • Fix PythonShell.runString() temp file path generation by calling tmpdir() instead of using the function reference.
  • Add a focused unit test that validates temp-file creation in OS temp dir and verifies handoff to PythonShell.run without spawning Python.

Why

  • Current code builds filePath with tmpdir + sep + ..., which uses the function object instead of the temp directory path.
  • This can produce invalid or non-existent paths for writeFileSync, making runString() fragile.

Test Plan

  • npm test -- --grep "temporary file in the OS temp directory"
    • Result in this environment: 1 passing.

Compatibility

  • No API changes.
  • Existing behavior is preserved; this only fixes temp-path construction and adds regression coverage.

ianhandy added a commit to ianhandy/python-shell that referenced this pull request Mar 16, 2026
- Fix runString() using tmpdir reference instead of tmpdir() call (fixes extrabacon#320)
- Replace exec() with execFile() to prevent command injection in
  checkSyntaxFile, getVersion, and getVersionSync
- Add temp file cleanup in runString() and checkSyntax() via .finally()
- Replace custom extend() with Object.assign
- Re-enable getVersion/getVersionSync tests (were disabled since extrabacon#158)
- Add GitHub Actions CI matrix (Node 18/20/22, Python 3.10/3.12, 3 OSes)
- Update minimum Node.js engine from 0.10 to 16

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ianhandy added a commit to ianhandy/python-shell that referenced this pull request Mar 16, 2026
- Fix runString() using tmpdir reference instead of tmpdir() call (fixes extrabacon#320)
- Replace exec() with execFile() to prevent command injection in
  checkSyntaxFile, getVersion, and getVersionSync
- Add temp file cleanup in runString() and checkSyntax() via .finally()
- Replace custom extend() with Object.assign
- Re-enable getVersion/getVersionSync tests (were disabled since extrabacon#158)
- Add GitHub Actions CI matrix (Node 18/20/22, Python 3.10/3.12, 3 OSes)
- Update minimum Node.js engine from 0.10 to 16
Copy link
Copy Markdown

@StantonMatt StantonMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this locally and compared it with the later duplicate refresh in #330.

This branch fixes the actual bug: tmpdir is imported as a function, so the old tmpdir + sep + ... path construction stringifies the function instead of using the OS temp directory. The new tmpdir() call makes runString() write to the expected temp path, and the test avoids spawning Python while still checking the generated file and handoff to PythonShell.run().

Local checks on this branch:

npm run compileOnce
npx mocha -r ts-node/register test/test-python-shell.ts --grep "temporary file"
npm test
npx prettier --check index.ts test/test-python-shell.ts
git diff --check origin/master...HEAD

All passed locally; full npm test reported 44 passing. GitHub reports no check runs for this PR, so there is no upstream CI result to claim.

The overlap with #330 is straightforward: both branches make the same minimal behavior fix and both pass the full local suite here. #330 uses path.join(tmpdir(), ...) and checks option identity in the regression test, while this PR keeps the existing sep style and checks equivalent handoff behavior. From a maintainer perspective, either branch can carry the fix; if this older PR is preferred, the only small thing I would consider is borrowing the path.join(tmpdir(), ...) shape from #330 for path construction consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants