Multiple completions #WH6 - failing test case

I’m stuck on Stage Multiple completions #WH6.

As suggested in Builtin completion #QP2 I am using the readline NuGet package. And I am having trouble with one of the test ("$ custom ”. Autocomplete with 1 found match).

The main issue is I am struggling to replicate it on my local:

Screen Recording 2026-01-21 at 15.38.35.mov video-to-gif output image

This is my code:

    public string[] GetSuggestions(string text, int index)
    {
        if (string.IsNullOrWhiteSpace(text))
            return null!;

        var matches = _commands
            .Concat(FileExecuter.FindExecutablesAtPath())
            .Where(c => c.StartsWith(text, StringComparison.OrdinalIgnoreCase))
            .Distinct()
            .OrderBy(c => c)
            .ToList();

        if (matches.Count == 0)
        {
            _tabCount = 0;
            Console.Write("\x07");
            return null!;
        }

        if (matches.Count == 1)
        {
            _tabCount = 0;
            return [$"{matches[0]} "];
        }

        ...

The failing test:

[tester::#GY5] ✓ Received prompt ($ )
[tester::#GY5] Typed "custom"
[tester::#GY5] ✓ Prompt line matches "$ custom"
[tester::#GY5] Pressed "<TAB>" (expecting autocomplete to "custom_exe_5432")
[your-program] $ custom
[tester::#GY5] ^ Line does not match expected value.
[tester::#GY5] Expected: "$ custom_exe_5432 "
[tester::#GY5] Received: "$ custom"
[tester::#GY5] Assertion failed.
[tester::#GY5] Test failed

But if I update my code:

        if (matches.Count == 1)
        {
            Console.WriteLine(matches[0]); // <- new line added
            _tabCount = 0;
            return [$"{matches[0]} "];
        }
[tester::#GY5] ✓ Received prompt ($ )
[tester::#GY5] Typed "custom"
[tester::#GY5] ✓ Prompt line matches "$ custom"
[tester::#GY5] Pressed "<TAB>" (expecting autocomplete to "custom_exe_6608")
[your-program] $ customcustom_exe_6608
[tester::#GY5] ^ Line does not match expected value.
[tester::#GY5] Expected: "$ custom_exe_6608 "
[tester::#GY5] Received: "$ customcustom_exe_6608"
[tester::#GY5] Assertion failed.
[tester::#GY5] Test failed

Showing that matches[0] does contain custom_exe_6608, it just isn’t showing in the test. Maybe it’s not showing in time? Any help would be appreciated! I’m sure I’m missing something silly :upside_down_face:

Hey @goose-729, I tried running your code locally, and was able to replicate the issue like this:

  1. Typed code and TAB

  2. Typed cr and TAB

    • Expected: completing to codecrafters
    • Actual: completing to codecrcodecrcodecrafters

  1. Pressed DEL a bunch of times, but couldn’t delete the whole command, with codecrcodecr stuck in there.

Let me know if you’d like help debugging this further.

Ah, apologies, I didn’t realise you could run my code. I had a change on my local that wasn’t pushed. That has been pushed now, hopefully it will fix that issue?

@goose-729 Looks like the string[] returned from GetSuggestions() is being ignored now.

After some trial and error, I was able to narrow it down to Separators. Namely, the string[] now works with just a small change: reverting Separators to its earlier value:


Suggestions:

  1. Use our CLI to test against previous stages by running:
codecrafters test --previous
  1. Focus on fixing the early stages first, as later stages depend on them.

Let me know if you’d like a hand debugging this further.

Awesome, thanks Andy for the help, found a solution with your change (see below if others are interested). Turns out it was something small, just needed a second pair of eyes :eyes:

And thanks for tips for running previous stages, was wondering if there was a way to do that!

:folded_hands:

1 Like