# Too strict test on #wh6

**URL:** <https://forum.codecrafters.io/t/too-strict-test-on-wh6/6523>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [March 11, 2025, 7:01pm UTC](https://forum.codecrafters.io/t/too-strict-test-on-wh6/6523 "2025-03-11T19:01:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![66Gramms](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/66gramms/32/5141_2.png) [@66Gramms](https://forum.codecrafters.io/u/66Gramms)\
**Post date:** [March 11, 2025, 7:01pm UTC](https://forum.codecrafters.io/t/too-strict-test-on-wh6/6523/1 "2025-03-11T19:01:05Z")

</div>

createInterface has a member called `completer` which is exactly made for autocompletion, yet the tests are written in such a way that using the completer function is not accapted as it’s matches aren’t separated by 2 spaces and I haven’t found a way to change that.

So if you use the built-in way that is also recommended in the code that is given to you, you can’t complete this challange, or at least I haven’t found a way. Here is my relevant code:

```auto
const rl = createInterface({
  input: process.stdin,
  output: process.stdout,
  prompt: "$ ",
  completer: handleCompletion,
});

let previousLine = "";
function handleCompletion(line: string) {
  const matches = Array.from(Commands.keys())
    .filter((command) => command.startsWith(line))
    .map((input) => `${input} `);

  const executables: string[] = [];
  for (const dir of (process.env.PATH || "").split(PATH_SEPARATOR)) {
    try {
      const files = fs.readdirSync(dir);
      executables.push(
        ...files
          .filter((file) => file.startsWith(line))
          .map((input) => `${input} `)
      );
    } catch (err) {
      // Ignore errors (e.g., if a path does not exist)
    }
  }

  if (!matches.length && !executables.length) {
    process.stdout.write("\u0007"); // Ring bell if no matches
    return [[], line];
  }

  if (line !== previousLine && [...matches, ...executables].length > 1) {
    process.stdout.write("\u0007"); // Ring bell on first match
    previousLine = line;
    return [[], line];
  }

  return [[...matches, ...executables], line];
}

```

Results:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/6/6f74e67ae98eb1b76bae912eb2ad12d7f1f08132.png)

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [March 12, 2025, 7:42am UTC](https://forum.codecrafters.io/t/too-strict-test-on-wh6/6523/4 "2025-03-12T07:42:36Z")

</div>

Hey @66Gramms, you can manually write to stdout and return `[]` in the completer function to bypass the default behavior of displaying suggestions on separate lines.

Here’s an example to build on:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/5/53d2296c15491c7fcb19d3614de00e9e37219a23.png)

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/a/aec737325eae70d7814878a2babef9acfa11b7c4.png)

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [March 20, 2025, 3:28pm UTC](https://forum.codecrafters.io/t/too-strict-test-on-wh6/6523/6 "2025-03-20T15:28:00Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [March 25, 2025, 3:28pm UTC](https://forum.codecrafters.io/t/too-strict-test-on-wh6/6523/7 "2025-03-25T15:28:35Z")

</div>

Closed on March 25, 2025, 3:28pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
