GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-127146: Skip test_open_undecodable_uri on Emscripten by hoodmane · Pull Request #136510 · python/cpython

Conversation

@hoodmane

@hoodmane hoodmane commented Jul 10, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR #136326 removed the Emscripten skip for this file but it is still broken.

  • Issue: Emscripten: Get test suite passing #127146

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hoodmane
pythongh-127146: Skip test_open_undecodable_uri on Emscripten
5588bb4
PR python#136326 removed the Emscripten skip for this file but it
is still broken.
@hoodmane
hoodmane requested a review from freakboy3742 July 10, 2025 14:25
@hoodmane
hoodmane requested review from berkerpeksag and erlend-aasland as code owners July 10, 2025 14:25
@hoodmane hoodmane added the skip news label Jul 10, 2025
@bedevere-app bedevere-app Bot added awaiting review tests Tests in the Lib/test dir labels Jul 10, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jul 10, 2025
Emscripten: Get test suite passing #127146
Closed
@StanFromIreland

StanFromIreland commented Jul 10, 2025

Copy link
Copy Markdown
Member

cc @serhiy-storchaka

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed Jul 10, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am surprised. Is test_open_with_undecodable_path passed?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@freakboy3742

freakboy3742 commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

@serhiy-storchaka Both test_open_undecodable_uri and test_open_undecodable_path are failing in CI at present (ref).

FWIW - in both cases, the test path being used is b'@test_42_tmp\xe7w\xf0' - the path is defined, and it is successfully opened, so the get_undecodable_path() check is passing where previously the test was explicitly skipped on Emscripten.

When I run this locally, I get a warning in the console:

Warning -- files was modified by test.test_sqlite3.test_dbapi
Warning --   Before: []
Warning --   After:  ['@test_42_tmp�w�'] 
test test.test_sqlite3.test_dbapi failed

which suggests to me that the bad unicode isn't round-tripping consistently through the filesystem.

I agree that this should be a "skip both or skip neither" situation; and I'd definitely prefer to understand better why it needs to be skipped explicitly before restoring the skip.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Jul 11, 2025

Copy link
Copy Markdown
Member

I suppose that paths are Unicode strings on Emscripten. Python and SQLite can use different ways to decode bytes path to Unicode, so os.path.exists() does not see the file created by SQLite, and unlink() cannot remove it.

This is similar to Windows where we need to keep a separate skip.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hoodmane

hoodmane commented Jul 11, 2025

Copy link
Copy Markdown
Contributor Author

Well '@test_42_tmp\xe7w\xf0' does round trip through JavaScript, MEMFS, and NODEFS correctly. So I agree, this test should be fixable. I will investigate more.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hoodmane hoodmane closed this Jul 11, 2025
@hoodmane

hoodmane commented Jul 11, 2025

Copy link
Copy Markdown
Contributor Author

Both test_open_undecodable_uri and test_open_undecodable_path are failing in CI at present

Interesting. Locally only test_open_with_undecodable_path is failing for me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hoodmane

hoodmane commented Jul 11, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I changed the test to this and added syscall tracing:

    def get_undecodable_path(self):
        path = TESTFN_UNDECODABLE
        print("open", path)
        f = open(path, 'wb')
        print("close", path)
        f.close()
        print("unlink", path)
        unlink(path)
        return path

    @unittest.skipIf(sys.platform == "win32", "skipped on Windows")
    def test_open_with_undecodable_path(self):
        path = self.get_undecodable_path()
        self.addCleanup(unlink, path)
        print("sqlite.connect", path)
        c = sqlite.connect(path)
        with contextlib.closing(c) as cx:
            print("exists", path)
            exists = os.path.exists(path)
            print(" .. ", exists)
            self.assertTrue(exists)

The relevant part of the log looks like this:

open b'@test_42_tmp\xe7w\xf0'
___syscall_openat @test_42_tmp緰
close b'@test_42_tmp\xe7w\xf0'
_fd_close 3 /home/.../test_python_worker_601748æ/@test_42_tmp緰
unlink b'@test_42_tmp\xe7w\xf0'
___syscall_unlinkat @test_42_tmp緰
sqlite.connect b'@test_42_tmp\xe7w\xf0'
___syscall_openat /home/.../test_python_worker_601748æ/@test_42_tmp�w�
___syscall_stat64 /home/.../test_python_worker_601748æ/@test_42_tmp�w�
exists b'@test_42_tmp\xe7w\xf0'
___syscall_stat64 @test_42_tmp緰
 ..  False
___syscall_stat64 /home/.../test_python_worker_601748æ/@test_42_tmp�w�
_fd_close 3 /home/.../test_python_worker_601748æ/@test_42_tmp�w�
<unrelated teardown syscalls>
FAIL
___syscall_unlinkat @test_42_tmp緰
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hoodmane

hoodmane commented Jul 11, 2025

Copy link
Copy Markdown
Contributor Author

Okay I got it: the problem is that UTF8ArrayToString uses a different code path on strings with more than 16 bytes and the behaviors don't exactly match:

    // When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.
    if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
      return UTF8Decoder.decode({{{ getUnsharedTextDecoderView('heapOrArray', 'idx', 'endPtr') }}});
    }

https://github.com/emscripten-core/emscripten/blob/main/src/lib/libstrings.js#L57-L59

So when the file system decodes the string, it checks the length. If it's short, it uses the JS decoder, if it's long it uses the native decoder. sqlite fully resolves the path before opening the file, and the absolute path is longer than 16 bytes. Whereas the not fully resolved path is 15 bytes long and gets the correct slow path. Adding two extra bytes to TESTFN_UNDECODABLE makes the test pass.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hoodmane

hoodmane commented Jul 11, 2025

Copy link
Copy Markdown
Contributor Author

Upstream report:
emscripten-core/emscripten#24690

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@freakboy3742 freakboy3742 Awaiting requested review from freakboy3742
@berkerpeksag berkerpeksag Awaiting requested review from berkerpeksag
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@hoodmane @StanFromIreland @freakboy3742 @serhiy-storchaka
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.