Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: stack traceback error on some tests in the writefile function #229

Closed
2 tasks done
rbroggi opened this issue Dec 11, 2024 · 17 comments · Fixed by #250
Closed
2 tasks done

bug: stack traceback error on some tests in the writefile function #229

rbroggi opened this issue Dec 11, 2024 · 17 comments · Fixed by #250
Labels
bug Something isn't working

Comments

@rbroggi
Copy link

rbroggi commented Dec 11, 2024

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.2

Operating system/version

arch

Output from :checkhealth neotest-golang

neotest-golang: require("neotest-golang.health").check()

Requirements ~
- OK Binary 'go' found on PATH: /home/rb/.local/bin/go
- OK Found go.mod file for /home/rb/repo/efg/watch-sessions-api/test/setup_test.go in /home/rb/repo/efg/watch-sessions-api/go.mod
- OK Treesitter parser for go is installed
- OK neotest is available
- OK nvim-treesitter is available
- OK nio is available
- OK plenary is available
- ERROR CGO_ENABLED is disabled but -race is part of go_test_args.

DAP (optional) ~
- OK Binary 'dlv' found on PATH: /home/rb/.local/share/nvim/mason/bin/dlv
- OK dap is available
- OK dapui is available
- OK dap-go is available

Gotestsum (optional) ~
- OK Binary 'gotestsum' not found on PATH

Describe the bug

For some of my tests the writefile method fails as briefly discussed in this other issue.

neotest-golang: /home/rb/.local/share/nvim/lazy/nvim-nio/lua/nio/init.lua:119: The coroutine failed with this message: 
Vim:E974: Expected a Number or a String, Blob found
stack traceback:
	[C]: in function 'writefile'
	.../nvim/lazy/neotest-golang/lua/neotest-golang/process.lua:156: in function 'test_results'
	...are/nvim/lazy/neotest-golang/lua/neotest-golang/init.lua:161: in function 'results'
	...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:132: in function '_run_spec'
	...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:88>
stack traceback:
	...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:89: in function <...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:88>
	[C]: in function 'error'
	/home/rb/.local/share/nvim/lazy/nvim-nio/lua/nio/init.lua:119: in function 'gather'
	...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:94: in function '_run_tree'
	...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:65: in function <...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:22>
	[C]: in function 'xpcall'
	...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:84: in function 'run_tree'
	...al/share/nvim/lazy/neotest/lua/neotest/consumers/run.lua:85: in function 'func'
	/home/rb/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:173: in function </home/rb/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:172>

Those tests are frequently integration tests but I'm not sure this is the discriminant for the behavior.

I have collected a debug with the content that breaks the method since I'm unable to reproduce this issue on a reproducer:

I've placed the logger.debug({ "cmd output dbg test:", cmd_output }) right before the async.fn.writefile(cmd_output, cmd_output_path) call and here is what I got:

[neotest-golang] cmd output dbg test: { "\1\0\0\0\0\0\0z{\n", "  info2: 'no configuration specified. Using a default configuration for the set',\n", "  me: 'b644af016a14:27017',\n", "  ok: 1\n", "}\n", "\n", "=== RUN   Test_Name1\n", "=== PAUSE Test_Name1\n", "=== CONT  Test_Name1\n", "=== RUN   Test_Name1/by_id\n", "--- PASS: Test_Name1/by_id (0.00s)\n", "=== RUN   Test_Name1/newest\n", "--- PASS: Test_Name1/newest (0.00s)\n", "=== RUN   Test_Name1/upcoming\n", "--- PASS: Test_Name1/upcoming (0.00s)\n", "=== RUN   Test_Name1/upcoming_newest_first\n", "--- PASS: Test_Name1/upcoming_newest_first (0.00s)\n", "=== RUN   Test_Name1/finished\n", "--- PASS: Test_Name1/finished (0.00s)\n", "=== RUN   Test_Name1/wrong_status\n", "--- PASS: Test_Name1/wrong_status (0.00s)\n", "--- PASS: Test_Name1 (0.53s)\n", "PASS\n", "ok  \t<anonymized-path>\t4.102s\n" }

Sometimes seems that the cmd_output is not a String nor a Number. How can we correct that?

Steps To Reproduce

I am unable to find the discriminant of the type of test that actually generate a Blob output.

Expected Behavior

Either we should coalesce the Blob to a string or make the writefile method accept a Blob

Your Lua setup

No response

@rbroggi rbroggi added the bug Something isn't working label Dec 11, 2024
@rbroggi
Copy link
Author

rbroggi commented Dec 11, 2024

I have tried the following (without success):

  1. defining the following function:
function convert_blob_to_string(value)
  if type(value) == "number" or type(value) == "string" then
    return value
  else
    return tostring(value)
  end
end
  1. Tried:
    a. async.fn.writefile(cmd_output, convert_blob_to_string(cmd_output_path)) (same problem persists)
    b. async.fn.writefile(convert_blob_to_string(cmd_output), cmd_output_path) a different problem arises:
neotest-golang: /home/rb/.local/share/nvim/lazy/nvim-nio/lua/nio/init.lua:119: The coroutine failed with this message: 
Vim:E475: Invalid argument: writefile() first argument must be a List or a Blob
stack traceback:
  [C]: in function 'writefile'
  .../nvim/lazy/neotest-golang/lua/neotest-golang/process.lua:157: in function 'test_results'
  ...are/nvim/lazy/neotest-golang/lua/neotest-golang/init.lua:161: in function 'results'
  ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:132: in function '_run_spec'
  ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:88>
stack traceback:
  ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:89: in function <...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:88>
  [C]: in function 'error'
  /home/rb/.local/share/nvim/lazy/nvim-nio/lua/nio/init.lua:119: in function 'gather'
  ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:94: in function '_run_tree'
  ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:65: in function <...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:22>
  [C]: in function 'xpcall'
  ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:84: in function 'run_tree'
  ...al/share/nvim/lazy/neotest/lua/neotest/consumers/run.lua:85: in function 'func'
  /home/rb/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:173: in function </home/rb/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:172>

I have also printed the cmd_output_path and it seems a correct string for me:

cmd output path dbg test: /tmp/nvim.rb/E3XnNo/8

Here what I printed before the writefile method:

logger.debug({ "cmd output dbg test type:", type(cmd_output) })
logger.debug({ "cmd output dbg test:", cmd_output })
logger.debug({ "cmd output path dbg test type:", type(cmd_output_path) })
logger.debug({ "cmd output path dbg test:", cmd_output_path })

Here the outcome:

cmd output dbg test type: table
cmd output dbg test: { <already-pated-avbove> }
cmd output path dbg test type: string
cmd output path dbg test: /tmp/nvim.rb/j2X3Xk/8

@rbroggi
Copy link
Author

rbroggi commented Dec 11, 2024

Something that actually 'kinda worked' was using the following:

function convert_blob_to_string(value)
  if type(value) == "number" or type(value) == "string" then
    return value
  else
    return table_to_string(value)
  end
end

function table_to_string(t)
  local result = ""
  local function encode_value(v)
    if type(v) == "number" then
      return tostring(v)
    elseif type(v) == "string" then
      return '"' .. v .. '"'
    elseif type(v) == "boolean" then
      return v and "true" or "false"
    elseif type(v) == "table" then
      return table_to_string(v)
    else
      return "nil"
    end
  end

  local function encode_table(t)
    local result = "{"
    local first = true
    for k, v in pairs(t) do
      if not first then
        result = result .. ","
      end
      first = false
      result = result .. tostring(k) .. ":" .. encode_value(v)
    end
    result = result .. "}"
    return result
  end

  return encode_table(t)
end

and then:

async.fn.writefile(convert_blob_to_string(cmd_output), cmd_output_path)

The output is OFC horrible:

image

@fredrikaverpil
Copy link
Owner

Hey @rbroggi and thanks for this report. I haven't had time to dig into this one yet. In the meantime, if you set the runner to gotestsum (and make sure you have it installed), do you see any difference?

@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Dec 13, 2024

I just made a low-effort search and kind of seems the "Using default configuration for the set" is related to MongoDB: https://github.com/search?q=%22Using+a+default+configuration+for+the+set%22&type=code

Is that detail potentially significant here?
How did that part end up in your go test output?

@rbroggi
Copy link
Author

rbroggi commented Dec 13, 2024

I use testcontainers and indeed mongo is part of the containers. I tried to make a small reproducer with only mongo container but failed.

https://golang.testcontainers.org/modules/mongodb/

@rbroggi
Copy link
Author

rbroggi commented Dec 13, 2024

Hey @rbroggi and thanks for this report. I haven't had time to dig into this one yet. In the meantime, if you set the runner to gotestsum (and make sure you have it installed), do you see any difference?

Will try that later. Thx for the tip

@fredrikaverpil
Copy link
Owner

Sounds good. Based on the outcome of using gotestsum, I think we might have to set up some sort of minimal reproducible example that I can run locally on my machine - for me to get to the bottom of what the problem is, and providing a robust fix.

@rbroggi
Copy link
Author

rbroggi commented Dec 13, 2024

Hey @rbroggi and thanks for this report. I haven't had time to dig into this one yet. In the meantime, if you set the runner to gotestsum (and make sure you have it installed), do you see any difference?

Unfortunately no change here

@rbroggi
Copy link
Author

rbroggi commented Dec 13, 2024

I've spent a good amount of time trying to debug this and I think the bottom line is that somehow, I'm getting binary data being written to the test output. I couldn't find an easy way of reproducing it though which is making me a bit mad on why this is the case in my actual problem. I need to switch focus from that right now but will come back to it later.

@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Dec 13, 2024

No worries, no stress. I just don't think I can aid much here until we can reproduce it. I'm also not very keen on modifying the current code without understanding why. Ideally we'd be able to write a test for this case and assert the code is handling it correctly.

@rbroggi
Copy link
Author

rbroggi commented Dec 13, 2024

Ok, managed to create a reproducer:

https://github.com/fredrikaverpil/go-playground/pull/9/files#diff-994247e11b46166328bf9c5fde6290dca00620a6100b143670344f1c1b01d20bR22

It is not completely deterministic as it seems that not all bytes will screw the output sufficiently. This reproducer breaks the test most of the times though... It has nothing to do with mongo but with binary output. Some binary outputs simply screw the parser.

@fredrikaverpil
Copy link
Owner

That's excellent @rbroggi that you managed to set something reproducible up. I'll have a look, but I can't promise exactly when.

@rbroggi
Copy link
Author

rbroggi commented Dec 14, 2024

Had an inspiration this night and was convinced (and partially still am) that a utf-8 sanitization should do the trick. I tried some AI generated lua function since I have basically no experience in the language. Unfortunately no success. Maybe you can more successfully implement such sanitizer

@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Jan 2, 2025

@rbroggi sorry for the delay. I just checked out your PR branch to have a look.

When I have go set as the runner (and add the integration tag to my neotest-golang config), I get this output when I run the Test from the neotest summary pane and really quickly thereafter hit a (for "attach"). I get this:

{"Time":"2025-01-02T23:56:52.442264+01:00","Action":"start","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test"}
{"Time":"2025-01-02T23:56:52.65704+01:00","Action":"run","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test"}
{"Time":"2025-01-02T23:56:52.65715+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"=== RUN   Test\n"}
{"Time":"2025-01-02T23:56:52.657177+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"Ve\ufffd\ufffd\ufffd\ufffdZK\ufffd\ufffd\ufffd_\ufffd\ufffd\ufffd\ufffd\ufffde\u001c9\ufffd\ufffdH\ufffd\ufffd\ufffd\u001e \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd}h\ufffdv\n"}
{"Time":"2025-01-02T23:56:52.657203+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffd_\u0002k\ufffd\ufffdHd\ufffd\ufffd\ufffdΨ׮\ufffd\ufffd\ufffdU1\ufffd\ufffd'\ufffd\ufffd2\u001at\ufffdb\ufffdq\ufffd\ f\ufffdb\ufffd\ufffdN\u0018}\ufffd.\ufffd\ufffd\ufffd0\ufffd\ufffdty\ufffd\ufffdN\ufffdd\ufffdJ\ufffd\ufffd\ufffdMAҞ\u000b\ufffd\ufffdHZ\ufffd9\ufffd\u0004\ufffd2\ufffd\u001dP2e\ufffd\ufffd͈\ufffd\ufffd\ufffd\ufffdR@\ufffd\u001d"}
{"Time":"2025-01-02T23:56:52.65738+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffdeW\ufffd\ufffd\ufffd\ufffd\ufffd@\ufffd\ufffd\ufffd\u000e\ufffd\u001a$H@\u0007\ufffd6\b\ufffdV\u0014\ufffd\ufffd\ufff d\r\ufffd8X\u0013պ/\ufffd\ufffd\u000e\ufffd\ufffdܪ\ufffd\ufffd\ufffd\u0026\ufffd\ufffd/ \u0012\u000b\ufffd\u000f\ufffd\ufffd\ufffdIOz\ufffd\ufffdH\ufffdmR9/\ufffd\u0002e\ufffd\ufffd\r\ufffd\b\ufffd\ufffdi\ufffd6~a\ufffdV\ufffd\ufffd\rH\ufffdj9\u0013\ufffd\ufffd\ufffd\ufffd\ufffd\u001e\ufffd\u0013 \ufffd4l\ufffd0\ufffd=\ufffd\ufffd#vS\ufffdy\ufffd0_0RO\u001d\ufffdh\u0013\ufffdrR\ufffd\ufffd2\ufffd0\ufffdV \ufffdDZ\n"}
{"Time":"2025-01-02T23:56:52.657412+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffdHd\ufffd8\ufffd\ufffd^j\ufffd\ufffdpJ\ufffd\ufffd`\"\u001a.\u0001y\ufffd\u000f\ufffd\ufffd\ufffd\ufffd"}
{"Time":"2025-01-02T23:56:52.657429+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"xs\ufffd\\.\ufffd\ufffd\u001dz\ufffd\ufffdM\ufffd\r\ufffd\ufffd\ ufffd\ufffd.qSY\ufffdoJ\ufffdэ\u0011ӡ\ufffd\ufffd\ufffd^\ufffd\ufffd\u0010@K\ufffd.\ufffd\ufffd\u0012\ufffd\ufffd}\u003e \ufffd,\u0007\ufffd\ufffd\ufffdd\ufffd\ufffd]_w\ufffdb\u000e\t\ufffd\u0015qU\u001c\ufffdK\u001c2\u0002\ufffd"}
{"Time":"2025-01-02T23:56:52.657499+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"\ufffdG\ufffd\ufffd$g\ufffd\u0005]\ufffdrjykb\ufffd\u0017(̶X\ufff dv\ufffd\ufffd^\ufffd\ufffd]mM.N\u0015W\ufffdr\ufffd\ufffd\ufffd\u0018bn\ufffd\u0006`\ufffd\ufffd\ufffdH\u0010\ufffd\u00 0e\ufffd\ufffd-\ufffd\u0011\ufffd\ufffd\ufffd0\u000fE\ufffd\ufffdry\ufffd$E\ufffd7\ufffdp\u0026-xK`\ufffd\ufffd\u0013p\u fffd\u0005Sn$\ufffd\ufffdL\u0004!\ufffd\ufffd7~\ufffd[\ufffdL\u0018\u001d\ufffd4\ufffd\u00018\u0014\ufffd\ufffd~\ufffd\u fffd\ufffd\ufffdg\ufffd\ufffd^\ufffd\ufffd\ufffdL\bﴟ\ufffd\ufffdN\ufffd\ufffd%\u0026\ufffd3Wzi\u000b\ufffdZ\f\ufffdf\uff fd\ufffd\f/!\ufffd\ufffd\ufffd\ufffd {\u0000J1\ufffdk\u0004\ufffdC\ufffd\u000bmޘ\ufffd:\ufffd\ufffd\fz\ufffd\ufffd\u0010 ӺxE\u0001{\ufffd{@F/\u0018cN}\ufffd\ufffd\u001cF@\ufffdPY\u001eE0\ufffd\u001a[\ufffdč\u001f\t\ufffd\ufffd\ufffd\ufffd\u0 004\ufffd\ufffd\ufffd\u0010\ufffd\ufffdw\ufffd\ufffd\ufffd\ufffd2\ufffd^\ufffd,o\ufffd\ufffd\ufffd00\u0001!\ufffdT\ufffd \ufffd\ufffdp\ufffd\u003cwEcSLA\u0004\ufffdT\ufffdY]\ufffd\ufffd/eK3\"\ufffdB\ufffd\u0014\"\ufffd\ufffdz\ufffd\ufffd#\uf ffdz\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd׺'\u000e\ufffd\ufffd\ufffdhe\ufffd\ufffd~\u0005\ufffd\\\ufffd\t\ufff d\ufffd\ufffd\ufffdq\ufffd\ufffdV\ufffd\u0018ڂ\ufffd\ufffd\u0017\ufffdA3\ufffd/\ufffd\u0004\ufffd\u001c\ufffd\u0015\ufff do\ufffdZ+\ufffd\f\ufffd\ufffdM\ufffd\ufffd`\ufffd\ufffdr\ufffdh*z\ufffd\u0017G\ufffd\ufffd\u001c\ufffd\u001b\ufffdQ\uff fd\ufffd\ufffd\ufffd\ufffd2\"\u0010\ufffd?\u000e\ufffd6ڻ \ufffd\u001a\ufffd"}
{"Time":"2025-01-02T23:56:52.657602+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffd\u0015\u003c_\u000bDZry\ufffd.\u0012\u0015\ufffdP$[\u fffd$\ufffdg\ufffd"}
{"Time":"2025-01-02T23:56:52.657621+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"\ufffd\u00053Fnl\ufffdb\u001d%hэ\u003er\ufffd\ufffd\u0006\ufffd\ ufffd\ufffd\u0002-5\ufffd\u000e \ufffdڛD\ufffd\ufffdGA\ufffd\ufffd.3\ufffd\ufffde\ufffd\ufffdQ]\ufffd5\u000bd\ufffd\ufff d\ufffd\ufffd\ufffd9\ufffd\ufffd\u0005\ufffd\u0019\ufffd\ufffd\ufffd\ufffd0\ufffd=+7\f\ufffdG\f\u001c\ufffd\u0004\u00266 \ufffd\ufffd\ufffd\ufffd\u0003}M9\ufffd\ufffd\ufffd\ufffdR\ufffdW\u001dN\ufffdy\ufffd\ufffd\ufffdP\ufffd^\ufffd\ufffd{Ng \ufffd\u001aà\ufffd\ufffdQ\tP\ufffd9\ufffdz\ufffd\ufffd\ufffd\ufffd:\ufffd\u0002\ufffd\ufffd@\ufffdv\u0014\ufffd!ys\u000 7\ufffdW\ufffd#{[Hl\u0011\u0004'\ufffdz\ufffd\ufffdn\u0014\ufffd \ufffd\ufffdG0n\n"}
{"Time":"2025-01-02T23:56:52.657759+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffd\ufffd\ufffda\ufffd vPF-\ufffdM\ufffd#\ufffd\ufffd\u fffd\ufffd\ufffd\u0019:\u0005\ufffd\ufffdx\ufffdLC\ufffd\ufffd B\ufffd0\ufffdsf\u0002Ax\ufffd--- PASS: Test (0.00s)\n"}
{"Time":"2025-01-02T23:56:52.657771+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Output":"PASS\n"}
{"Time":"2025-01-02T23:56:53.661516+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Output":"ok  \tgithub.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/cor e/test\t1.219s\n"}
{"Time":"2025-01-02T23:56:53.661596+01:00","Action":"pass","Package":"github.com/fredrikaverpil/go-playground/bugs/neote st-golang/internal/core/test","Elapsed":1.22}

Switching over to the gotestsum runner, I get this instead:

{"Time":"2025-01-03T10:00:37.193426+01:00","Action":"start","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang"}
{"Time":"2025-01-03T10:00:37.193486+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang","Output":"?   \tgithub.com/fredrikaverpil/go-playground/bugs/neotest-golang\t[no test files]\n"}
{"Time":"2025-01-03T10:00:37.193494+01:00","Action":"skip","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang","Elapsed":0}
{"Time":"2025-01-03T10:00:37.214638+01:00","Action":"start","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test"}
{"Time":"2025-01-03T10:00:37.214674+01:00","Action":"run","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test"}
{"Time":"2025-01-03T10:00:37.214677+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"=== RUN   Test\n"}
{"Time":"2025-01-03T10:00:37.214683+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffdK9\ufffd\ufffdnG\ufffd\u00196\ufffd\ufffd\fw7t\ufffd\ufffd\ufffd)\ufffd'\ufffd\u0015\ufffd;\ufffd\b\ufffd\u001e\ufffdx\ufffd\u003e@\ufffdR\ufffd\ufffd%j\u0002N|\ufffd\ufffde\ufffdN\ufffd1:\ufffd\u0007\ufffd\ufffd\ufffdbt\ufffd\u0015\u0004\ufffdo\ufffd\u0012\u001f\ufffd\ufffd\b\ufffd%\ufffd\ufffd8\ufffd\ufffd/\ufffd\ufffd\ufffd\ufffd\ufffd\ufffdӹ\ufffd\u0000\ufffd\u0026i\ufffd\u001aY\ufffdY\ufffdN\ufffdʖZ\ufffdqS\ufffd|h\u001c\ufffdΧAK\ufffd }\f\ufffdK~{\u001f\ufffd\ufffdiSF\ufffd\u0015\b\u0018\u000b\ufffdi\ufffd\ufffd{/\ufffd\ufffdL`\ufffd\u0012\ufffd\u0010w\ufffdy\ufffdܺ\u0003\ufffd\ufffd2ud\ufffd\u0014\ufffd\ufffd\u0000\ufffd4\ufffd\u0013a\ufffd\ufffd4\ufffdc\ufffd:U~\u001b*\\\ufffd,\ufffd\ufffd\ufffdQ꣋\u0004\ufffd\ufffd\ufffdea\ufffda\u001d\ufffd\b\ufffd[A|w\ufffd}\ufffd{\ufffd\ufffd\ufffd\ufffd\ufffd\ufffdڲ]r$`U\u0015rv\ufffdW\u0014\u0007\ufffd\"\ufffd#\ufffdv\ufffd\ufffd嵃\ufffd\ufffd5\ufffdu\ufffd\ufffd"}
{"Time":"2025-01-03T10:00:37.214695+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffdIpᤥ�^\ufffd1\ufffd\ufffd\ufffd\u0001z\ufffd\ufffdFg\ufffd\u0014\ufffd\ufffd\u0002\ufffd~O\ufffd\ufffd[k\u000eɛ\ufffd\ufffdu?\ufffdP5\ufffd\u0011\ufffd\ufffd\u0026]\ufffd\ufffd\ufffd�\ufffd\ufffd\ufffdO\ufffd\ufffd\u0018\ufffd`\ufffd\ufffd.\u0000\ufffd\ufffdQ\ufffd\ufffd\ufffdf\ufffd\ufffdg\u000b5P\u0014Od\ufffd\ufffdd\ufffd\ufffd\u0011~\\\u00102ȑſYJ\ufffd\u000e\ufffd\ufffd\ufffdƱ\u0002u\ufffdm\r\ufffd\u0017\ufffd\ufffd)#wc\ufffdԁ\ufffdK8\ufffd\ufffd\ufffd\ufffd\n"}
{"Time":"2025-01-03T10:00:37.214703+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffd;\ufffd\ufffd;\ufffd\ufffdZ\ufffd\ufffd\\\ufffd\ufffdJ.\ufffd8\ufffdqQI\ufffd�{_\ufffd\ufffdU\u003e5\ufffdVC\u001e\u0010\ufffdR\ufffd߄\ufffdOK\ufffdP\ufffd\r\ufffd»\ufffd\u0011.\ufffdY\ufffd\ufffdD \u0003\ufffd\ufffd.\ufffd\ufffd$\ufffdKւ\ufffd\u001f\ufffd\ufffd_\ufffd\ufffd6\ufffd;\ufffd\ufffdޠ\u001ac\ufffdH\ufffd\u0013\ufffd�r\u001c\u0003?\ufffd\ufffd\ufffd,|l"}
{"Time":"2025-01-03T10:00:37.214716+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\b\ufffd\ufffd\ufffdc\u0004\ufffd\ufffd\ufffdX\ufffd\ufffd\u0014\ufffds\ufffd\u000e\ufffd\u0007 D"}
{"Time":"2025-01-03T10:00:37.214723+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\u000b\ufffd\ufffd\ufffdbV+\ufffdt\ufffdg\ufffd4\ufffd\u0015\u001c\ufffd\u003eo\ufffd\u003e+\ufffd\ufffd\ufffd\ufffd\u001f\ufffd\u0007H@-\ufffd\ufffd\ufffd\ufffdr5!\ufffdQXӑď\ufffd!\ufffdJ\u0013㲀\ufffd\ufffd\ufffdgp\u0017]P\ufffd\u001d\ufffd\ufffd4\ufffd\ufffd\u003ckwz\u0002\ufffdY\ufffd\ufffdT\ufffdR\ufffd\u0017V\ufffdi\"\ufffd5~c\ufffd3\ufffd/\ufffdpD\ufffd)\ufffd\ufffd\ufffd\u001c0\ufffdχrQS\ufffd\u001b\ufffd$\ufffd\ufffd/+7\u0015\u0013\ufffd\u000e\u0017\u0004C\ufffd`\ufffd2\ufffd;\ufffdN\ufffd\",W\ufffd\ufffd\ufffd\ufffd\u0001\ufffdy\ufffd\ufffd\ufffd\\-\ufffd\ufffd\ufffd\ufffd'\ufffd\n"}
{"Time":"2025-01-03T10:00:37.214734+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"޵\ufffd2'\ufffd\ufffd\ufffd!\ufffd\ufffd\u0017\ufffd\ufffd?\ufffd$?\ufffd\ufffdU\u0018\ufffdi-m\ufffd\ufffd\ufffdn\ufffd\ufffds\ufffd\ufffd\ufffd\ufffd\fe2\u0004\ufffd\ufffdf\ufffd\u0014\ufffd\ufffd*\ufffdD\ufffd$\u001c\ufffdy\ufffdX\u0014\ufffd\ufffd\ufffdI\ufffd\u003c\ufffd\u0004\ufffd\ufffd[\ufffd:\ufffde"}
{"Time":"2025-01-03T10:00:37.21474+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"2\ufffdژ\ufffd\ufffd\ufffdw\n"}
{"Time":"2025-01-03T10:00:37.214745+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffd\ufffd\u0012Pʇ\ufffdB\ufffd\u0002\ufffd\ufffd\ufffd_\n"}
{"Time":"2025-01-03T10:00:37.214749+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffd\ufffdм*\ufffd\ufffd\u0014\ufffd\ufffdQ*rY\ufffd\ufffd۸\ufffdŹ0\u001b\"\ufffdf2_\ufffd\n"}
{"Time":"2025-01-03T10:00:37.214753+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"v\ufffd\ufffdK\ufffdd\u0007\ufffd\ufffdC\ufffd\u0006\ufffd\ufffd%\u0014\ufffdq\ufffd\ufffd\ufffd %p:\ufffd\ufffd\ufffdN\ufffd\ufffd\ufffd�\ufffd\ufffdt\\3Wfpc\ufffd\u001bS\ufffd\ufffdO\ufffd\u0004(\ufffd.\ufffdfD\ufffd \tO\ufffd.3\u0012\ufffd\u0017D\ufffd$\ufffd\ufffdo8\ufffd1\ufffd\ufffd\ufffdOZ\ufffd\ufffdF\ufffd\ufffd\ufffdk\ufffd\ufffdq4\ufffd\ufffd\ufffd\ufffd\ufffd\ufffdT\u000e݅dO\ufffd\ufffdg\ufffd\u0019n\ufffd\tϣ\ufffdh\ufffd;v7\ufffd\ufffdqNuN\ufffdQon\ufffd\ufffd\ufffd|\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0013\u001f\ufffd=\ufffd\u0015\ufffd\ufffda\u0019/}v\ufffd\u001d\ufffd\ufffd\t\ufffd\ufffd\u0013[E\ufffd\u000b)\ufffd1\ufffd\ufffd\ufffd\ufffd\ufffdT\u000e\ufffd\ufffdb\r\ufffdy6\ufffdW\ufffd\ufffdQ\ufffd\u0014\u0018\ufffd.\ufffd\ufffd\ufffdS\u00143:\ufffd\ufffd\ufffdi\ufffd\u0003g(\ufffd--- PASS: Test (0.00s)\n"}
{"Time":"2025-01-03T10:00:37.21476+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Output":"PASS\n"}
{"Time":"2025-01-03T10:00:37.214763+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Output":"ok  \tgithub.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test\t(cached)\n"}
{"Time":"2025-01-03T10:00:37.214767+01:00","Action":"pass","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Elapsed":0}

I guess it's the os.Stdout.Write(b) at the end of the test which causes this problem, as it fills the buffer with random bytes, which when written directly to stdout produces garbage characters since many of these bytes aren't valid UTF-8 characters or printable ASCII characters.

This test encodes the bytes so that the test doesn't fail:

func TestEncoded(t *testing.T) {
	b := make([]byte, 1000)
	_, err := rand.Read(b)
	require.NoError(t, err)
	t.Logf("Random bytes (hex): %x", b)
}

Is this really representative of the issue you saw with the testcontainer?
There's no way I can take the output and make sense of it like you did in #229 (comment)

Not even go test seems like it can make sense of the Test test:

$ go test -v ./...
?       github.com/fredrikaverpil/go-playground/bugs/neotest-golang     [no test files]
=== RUN   TestSomething
--- PASS: TestSomething (0.00s)
PASS
ok      github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/dto   (cached)

@rbroggi
Copy link
Author

rbroggi commented Jan 3, 2025

@rbroggi sorry for the delay. I just checked out your PR branch to have a look.

When I have go set as the runner (and add the integration tag to my neotest-golang config), I get this output when I run the Test from the neotest summary pane and really quickly thereafter hit a (for "attach"). I get this:

{"Time":"2025-01-02T23:56:52.442264+01:00","Action":"start","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test"}
{"Time":"2025-01-02T23:56:52.65704+01:00","Action":"run","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test"}
{"Time":"2025-01-02T23:56:52.65715+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"=== RUN   Test\n"}
{"Time":"2025-01-02T23:56:52.657177+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"Ve\ufffd\ufffd\ufffd\ufffdZK\ufffd\ufffd\ufffd_\ufffd\ufffd\ufffd\ufffd\ufffde\u001c9\ufffd\ufffdH\ufffd\ufffd\ufffd\u001e \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd}h\ufffdv\n"}
{"Time":"2025-01-02T23:56:52.657203+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffd_\u0002k\ufffd\ufffdHd\ufffd\ufffd\ufffdΨ׮\ufffd\ufffd\ufffdU1\ufffd\ufffd'\ufffd\ufffd2\u001at\ufffdb\ufffdq\ufffd\ f\ufffdb\ufffd\ufffdN\u0018}\ufffd.\ufffd\ufffd\ufffd0\ufffd\ufffdty\ufffd\ufffdN\ufffdd\ufffdJ\ufffd\ufffd\ufffdMAҞ\u000b\ufffd\ufffdHZ\ufffd9\ufffd\u0004\ufffd2\ufffd\u001dP2e\ufffd\ufffd͈\ufffd\ufffd\ufffd\ufffdR@\ufffd\u001d"}
{"Time":"2025-01-02T23:56:52.65738+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffdeW\ufffd\ufffd\ufffd\ufffd\ufffd@\ufffd\ufffd\ufffd\u000e\ufffd\u001a$H@\u0007\ufffd6\b\ufffdV\u0014\ufffd\ufffd\ufff d\r\ufffd8X\u0013պ/\ufffd\ufffd\u000e\ufffd\ufffdܪ\ufffd\ufffd\ufffd\u0026\ufffd\ufffd/ \u0012\u000b\ufffd\u000f\ufffd\ufffd\ufffdIOz\ufffd\ufffdH\ufffdmR9/\ufffd\u0002e\ufffd\ufffd\r\ufffd\b\ufffd\ufffdi\ufffd6~a\ufffdV\ufffd\ufffd\rH\ufffdj9\u0013\ufffd\ufffd\ufffd\ufffd\ufffd\u001e\ufffd\u0013 \ufffd4l\ufffd0\ufffd=\ufffd\ufffd#vS\ufffdy\ufffd0_0RO\u001d\ufffdh\u0013\ufffdrR\ufffd\ufffd2\ufffd0\ufffdV \ufffdDZ\n"}
{"Time":"2025-01-02T23:56:52.657412+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test","Test":"Test","Output":"\ufffdHd\ufffd8\ufffd\ufffd^j\ufffd\ufffdpJ\ufffd\ufffd`\"\u001a.\u0001y\ufffd\u000f\ufffd\ufffd\ufffd\ufffd"}
{"Time":"2025-01-02T23:56:52.657429+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"xs\ufffd\\.\ufffd\ufffd\u001dz\ufffd\ufffdM\ufffd\r\ufffd\ufffd\ ufffd\ufffd.qSY\ufffdoJ\ufffdэ\u0011ӡ\ufffd\ufffd\ufffd^\ufffd\ufffd\u0010@K\ufffd.\ufffd\ufffd\u0012\ufffd\ufffd}\u003e \ufffd,\u0007\ufffd\ufffd\ufffdd\ufffd\ufffd]_w\ufffdb\u000e\t\ufffd\u0015qU\u001c\ufffdK\u001c2\u0002\ufffd"}
{"Time":"2025-01-02T23:56:52.657499+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"\ufffdG\ufffd\ufffd$g\ufffd\u0005]\ufffdrjykb\ufffd\u0017(̶X\ufff dv\ufffd\ufffd^\ufffd\ufffd]mM.N\u0015W\ufffdr\ufffd\ufffd\ufffd\u0018bn\ufffd\u0006`\ufffd\ufffd\ufffdH\u0010\ufffd\u00 0e\ufffd\ufffd-\ufffd\u0011\ufffd\ufffd\ufffd0\u000fE\ufffd\ufffdry\ufffd$E\ufffd7\ufffdp\u0026-xK`\ufffd\ufffd\u0013p\u fffd\u0005Sn$\ufffd\ufffdL\u0004!\ufffd\ufffd7~\ufffd[\ufffdL\u0018\u001d\ufffd4\ufffd\u00018\u0014\ufffd\ufffd~\ufffd\u fffd\ufffd\ufffdg\ufffd\ufffd^\ufffd\ufffd\ufffdL\bﴟ\ufffd\ufffdN\ufffd\ufffd%\u0026\ufffd3Wzi\u000b\ufffdZ\f\ufffdf\uff fd\ufffd\f/!\ufffd\ufffd\ufffd\ufffd {\u0000J1\ufffdk\u0004\ufffdC\ufffd\u000bmޘ\ufffd:\ufffd\ufffd\fz\ufffd\ufffd\u0010 ӺxE\u0001{\ufffd{@F/\u0018cN}\ufffd\ufffd\u001cF@\ufffdPY\u001eE0\ufffd\u001a[\ufffdč\u001f\t\ufffd\ufffd\ufffd\ufffd\u0 004\ufffd\ufffd\ufffd\u0010\ufffd\ufffdw\ufffd\ufffd\ufffd\ufffd2\ufffd^\ufffd,o\ufffd\ufffd\ufffd00\u0001!\ufffdT\ufffd \ufffd\ufffdp\ufffd\u003cwEcSLA\u0004\ufffdT\ufffdY]\ufffd\ufffd/eK3\"\ufffdB\ufffd\u0014\"\ufffd\ufffdz\ufffd\ufffd#\uf ffdz\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd׺'\u000e\ufffd\ufffd\ufffdhe\ufffd\ufffd~\u0005\ufffd\\\ufffd\t\ufff d\ufffd\ufffd\ufffdq\ufffd\ufffdV\ufffd\u0018ڂ\ufffd\ufffd\u0017\ufffdA3\ufffd/\ufffd\u0004\ufffd\u001c\ufffd\u0015\ufff do\ufffdZ+\ufffd\f\ufffd\ufffdM\ufffd\ufffd`\ufffd\ufffdr\ufffdh*z\ufffd\u0017G\ufffd\ufffd\u001c\ufffd\u001b\ufffdQ\uff fd\ufffd\ufffd\ufffd\ufffd2\"\u0010\ufffd?\u000e\ufffd6ڻ \ufffd\u001a\ufffd"}
{"Time":"2025-01-02T23:56:52.657602+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffd\u0015\u003c_\u000bDZry\ufffd.\u0012\u0015\ufffdP$[\u fffd$\ufffdg\ufffd"}
{"Time":"2025-01-02T23:56:52.657621+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"\ufffd\u00053Fnl\ufffdb\u001d%hэ\u003er\ufffd\ufffd\u0006\ufffd\ ufffd\ufffd\u0002-5\ufffd\u000e \ufffdڛD\ufffd\ufffdGA\ufffd\ufffd.3\ufffd\ufffde\ufffd\ufffdQ]\ufffd5\u000bd\ufffd\ufff d\ufffd\ufffd\ufffd9\ufffd\ufffd\u0005\ufffd\u0019\ufffd\ufffd\ufffd\ufffd0\ufffd=+7\f\ufffdG\f\u001c\ufffd\u0004\u00266 \ufffd\ufffd\ufffd\ufffd\u0003}M9\ufffd\ufffd\ufffd\ufffdR\ufffdW\u001dN\ufffdy\ufffd\ufffd\ufffdP\ufffd^\ufffd\ufffd{Ng \ufffd\u001aà\ufffd\ufffdQ\tP\ufffd9\ufffdz\ufffd\ufffd\ufffd\ufffd:\ufffd\u0002\ufffd\ufffd@\ufffdv\u0014\ufffd!ys\u000 7\ufffdW\ufffd#{[Hl\u0011\u0004'\ufffdz\ufffd\ufffdn\u0014\ufffd \ufffd\ufffdG0n\n"}
{"Time":"2025-01-02T23:56:52.657759+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Test":"Test","Output":"\ufffd\ufffd\ufffd\ufffda\ufffd vPF-\ufffdM\ufffd#\ufffd\ufffd\u fffd\ufffd\ufffd\u0019:\u0005\ufffd\ufffdx\ufffdLC\ufffd\ufffd B\ufffd0\ufffdsf\u0002Ax\ufffd--- PASS: Test (0.00s)\n"}
{"Time":"2025-01-02T23:56:52.657771+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Output":"PASS\n"}
{"Time":"2025-01-02T23:56:53.661516+01:00","Action":"output","Package":"github.com/fredrikaverpil/go-playground/bugs/neo test-golang/internal/core/test","Output":"ok  \tgithub.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/cor e/test\t1.219s\n"}
{"Time":"2025-01-02T23:56:53.661596+01:00","Action":"pass","Package":"github.com/fredrikaverpil/go-playground/bugs/neote st-golang/internal/core/test","Elapsed":1.22}

Switching over to the gotestsum runner, I get this instead:

=== RUN   Test
N���|6\�k?�:ը�aS4       @'�H�i�!G�+P�%����ӹV�N�<��z}+q��X���`��Ԍ�����
1i#����>�����N�r�!������-�x��Vb���G�G0�%<��5����!�`

                                                   #7JF�������z<I��
��R�;Zlb                                                           #�$��~����%ᱞj�T疋�V#�Rm�����V�����2a�w�N��_
        D)8$�^\��L�!@Q�O�FA��A>����7z7HU�����3�7}�saa�"j���}�d�ɖ1.�MF�
�k����/  ������a1d�~�4B�;���ˀ���yB�)7k��Z^����s��JȻ7��?� ���r�U���'J1_�?�?B��]�6�t�Q��a��P�W���O��R�sv���Y*��+�2jig]Pgn`��#�9�
                                                                                                                              E�6�>��e�p������w�eM�-:�Ò{:2��c��V�,*�
OԳ0�I�d-:L�H9m���| ]��J��"                                                                                                                                          ��V[����rT+O_I%ȶ;�O8N���    !:�̑�"�owZК��9 a3���B^��NC����&��y������~�r���p��Ҁ�`�
��FX��v���[�Lx�
               0ȣ}�B�`YҮ��������6�
&G��5b\%�g��?�Y@D=�)){�b
<'#
   {���
�8g"����#���QY�k�����C`��?��7
_J'0B��.%A����1r��G�Ĝq+D�Do�K���
'�9j�JF��@��C���1c�,�q�����Bf�_D+����:� ~'/[r��ڰۇ��7���Q.��q2�DX1�w��
                                                                     !��!@yvQ��*bvʡ\ը�����+���x"������?�'���<��U���6���q
SUU��������n9{��Jqˮ.ز� �NՖ��:��5*--- PASS: Test (0.00s)
PASS
ok      github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test  1.225s

=== Failed
=== FAIL: internal/core/test Test (unknown)
N���|6\�k?�:ը�aS4       @'�H�i�!G�+P�%����ӹV�N�<��z}+q��X���`��Ԍ�����
1i#����>�����N�r�!������-�x��Vb���G�G0�%<��5����!�`

                                                   #7JF�������z<I��
��R�;Zlb                                                           #�$��~����%ᱞj�T疋�V#�Rm�����V�����2a�w�N��_
        D)8$�^\��L�!@Q�O�FA��A>����7z7HU�����3�7}�saa�"j���}�d�ɖ1.�MF�
�k����/  ������a1d�~�4B�;���ˀ���yB�)7k��Z^����s��JȻ7��?� ���r�U���'J1_�?�?B��]�6�t�Q��a��P�W���O��R�sv���Y*��+�2jig]Pgn`
��#�9�

      E�6�>��e�p������w�eM�-:�Ò{:2��c��V�,*�
OԳ0�I�d-:L�H9m���| ]��J��"
                                            ��V[����rT+O_I%ȶ;�O8N���    !:�̑�"�owZК��9 a3���B^��NC����&��y������~�r���p��
Ҁ�`�
��FX��v���[�Lx�
               0ȣ}�B�`YҮ��������6�
&G��5b\%�g��?�Y@D=�)){�b
<'#
   {���
�8g"����#���QY�k�����C`��?��7
_J'0B��.%A����1r��G�Ĝq+D�Do�K���
'�9j�JF��@��C���1c�,�q�����Bf�_D+����:� ~'/[r��ڰۇ��7���Q.��q2�DX1�w��
                                                                     !��!@yvQ��*bvʡ\ը�����+���x"������?�'���<��U���6���q
SUU��������n9{��Jqˮ.ز� �NՖ��:��5*--- PASS: Test (0.00s)

DONE 1 tests, 1 failure in 1.496s

I guess it's the os.Stdout.Write(b) at the end of the test which causes this problem, as it fills the buffer with random bytes, which when written directly to stdout produces garbage characters since many of these bytes aren't valid UTF-8 characters or printable ASCII characters.

This test encodes the bytes so that the test doesn't fail:

func TestEncoded(t *testing.T) {
	b := make([]byte, 1000)
	_, err := rand.Read(b)
	require.NoError(t, err)
	t.Logf("Random bytes (hex): %x", b)
}

Is this really representative of the issue you saw with the testcontainer?
There's no way I can take the output and make sense of it like you did in #229 (comment)

Not even go test seems like it can make sense of the Test test:

$ go test -v ./...
?       github.com/fredrikaverpil/go-playground/bugs/neotest-golang     [no test files]
=== RUN   TestSomething
--- PASS: TestSomething (0.00s)
PASS
ok      github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/dto   (cached)

Hey, @fredrikaverpil,

Yep I'm quite confident this is exactly the issue and it is the same error that I faced while using testcontainer (even though it's not a testcontainers fault but the result of a binary log of one of the containers).

I'm quite confident that the issue is indeed a non - UTF-8 valid byte sequence, this is why I setup the reproducer like this.

The test should not fail IMO due to that. Do you agree?

@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Jan 3, 2025

Not even go test seems like it can make sense of the Test test

Whoops, I need to correct myself here; I forgot the build tag, and with that added go test did work and pass.

The test should not fail IMO due to that. Do you agree?

Yes, it's possible that neotest-golang should perform sanitization. However, I'm still skeptical towards whether your test example is representative of what is going on in the mongodb testcontainers example.

Anyhow, I tried to do something about this in the sanitization branch: #250
You can try it out with your testcontainer:

{ "fredrikaverpil/neotest-golang", branch = "sanitization" }

But I'm unfortunately unable to completely eliminate all garbage that gets added by os.Stdout.Write(b) (and I renamed your test in the output below to TestBytes locally):

{ {
    Action = "start",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Time = "2025-01-03T13:16:05.603446+01:00"
  }, {
    Action = "run",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.915652+01:00"
  }, {
    Action = "output",
    Output = "=== RUN   TestBytes\n",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.91572+01:00"
  }, {
    Action = "output",
    Output = 'GF7<rp"*&qT}5',
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.915783+01:00"
  }, {
    Action = "output",
    Output = "+\n",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.91581+01:00"
  }, {
    Action = "output",
    Output = "n\ab)_b\vkwy0l;\16\0186i\26NKaFzmw\25\14-\1\25Z}qdTW)-C\14{n8S]S\r\0046J<k{J0<\f\30&2-\v\30\bB\0065if&~\t\21R\15=Dl\23P1\3s\17{\1A;`M_\14\0050W\21n\bapV\15maO]r^\18TsVG\0{]F\26\6m!Mn+qt*\26Y\"6\3cH\23\va\v~Y}~`ses0r\16h\127\27cD\17\"\127!NbVgn;\30o{gNimO{$NV]T/XDbaakPL}i\14\4o\127&\15g]nyv*m\29Q@l\16'\27qF\20d",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.915827+01:00"
  }, {
    Action = "output",
    Output = "n['^Sx\23wl\16m\rpuaJ",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.915901+01:00"
  }, {
    Action = "output",
    Output = '\vYd5%eQ\24HF\28vp3 6[I\0\17N8qQ\5^\\syB"\aJB<c\14\19=H\vzrlp~\t,6& \4[@U1xA4\3JV|\5$tv<3:y\127xVj$JKXn,',
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.91592+01:00"
  }, {
    Action = "output",
    Output = "9\21\30^|\f?YH &,W5 *+98\\*R\2>\0314a7k6\t&Q\24\"U,e(1b\23|0Ug+tc\18B\rk\aE\17U5#\21>sNA/:V0~\3p.\3u \\\21JKknW@$\4\127ye\v\tM'\15\n",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.915953+01:00"
  }, {
    Action = "output",
    Output = "'\23v\0040j{g\15Xj\25\127%`P]!(/U\30\18_\15}&\0027#^3@[c\19ay<et\"yV-\v7\20R*\24%ni\31[\tS\14<\26Rg~;^|f\6D\31alURk1\"A`\t\17\16\vw--- PASS: TestBytes (0.00s)\n",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Test = "TestBytes",
    Time = "2025-01-03T13:16:05.915981+01:00"
  }, {
    Action = "output",
    Output = "PASS\n",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Time = "2025-01-03T13:16:05.916012+01:00"
  }, {
    Action = "output",
    Output = "ok  \tgithub.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test\t1.320s\n",
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Time = "2025-01-03T13:16:06.9239+01:00"
  }, {
    Action = "pass",
    Elapsed = 1.321,
    Package = "github.com/fredrikaverpil/go-playground/bugs/neotest-golang/internal/core/test",
    Time = "2025-01-03T13:16:06.923994+01:00"
  } }

Maybe have a look at the implementation... and see if you can spot what I'm doing wrong.

@fredrikaverpil
Copy link
Owner

@rbroggi I've merged the implementation. Please open up a new issue if the issue persist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants