Skip to lesson
Exit
Capstone: Mock Loop1 / 3

1 min lesson

Applied-AI coding drill

Work through the cases in "Applied-AI coding drill", pairing each signal with the move that fits.

Step 1 of 3

Cursor lets you use GPT and Cursor itself during the technical screen. That isn't a gift. It inverts the test: they're no longer grading whether you can write the function, they're grading whether you can drive AI with judgment.

Pasting raw model output without reading it is the fastest documented path to rejection in this loop. So the drill isn't “can I get a working diff.” It's “can I defend every line I kept and catch the line I shouldn't have.”

Learn more

Full explanation

Full explanation

Streaming drill: a thin async generator with cancel + error handling you can defend line by linets
async function* streamCompletion(
  resp: Response,
  signal: AbortSignal,
): AsyncGenerator<string> {
  const reader = resp.body!.getReader();
  const decoder = new TextDecoder();
  let buffer = "";
  try {
    while (true) {
      if (signal.aborted) throw new DOMException("cancelled", "AbortError");
      const { done, value } = await reader.read();
      if (done) break;
      buffer += decoder.decode(value, { stream: true });
      // SSE frames are newline-delimited; only emit complete lines.
      let nl: number;
      while ((nl = buffer.indexOf("\n")) !== -1) {
        const line = buffer.slice(0, nl).trim();
        buffer = buffer.slice(nl + 1);
        if (line.startsWith("data: ")) {
          const data = line.slice(6);
          if (data === "[DONE]") return;
          yield JSON.parse(data).choices[0].delta.content ?? "";
        }
      }
    }
  } finally {
    reader.releaseLock(); // always free the stream, even on cancel
  }
}

The point of typing it isn't the code. It's that you can answer: why buffer before emitting, what happens on a half-received chunk, why releaseLock lives in finally. If the model wrote it and you can't, you don't keep it.