Practical coding · choose one unfamiliar systemSUPPORTING MATERIAL
REFERENCE SHELF
Your guided curriculum
SUPPORTING MATERIALIndex

Practical coding · choose one unfamiliar system

“You inherit a feature with passing happy-path checks and failing customer behavior. Make the contract visible, reproduce one failure, and repair the responsible boundary.”

Each linked page is a separate constructed project/session with concrete inputs, a reusable method, evolving diagrams and checks.

Order Project Property demonstrated
1 Bounded API fan-out Ordered partial results and at most K active asynchronous calls
2 Search results race Latest request wins even when cancellation is ignored
3 Quantity investigation Runtime validation and regression before repair
4 Transaction importer Multi-module debugging, exact money, retries and durable restart
5 Three-PR review Causal reproductions and release priorities
Backend/infra Bounded threaded executor Condition predicates, cancellation, deadlines and shutdown
Product Real bookmark editor Browser/API/SQLite behavior under races and conflicts

Prerequisites: coding route, runtime model. Existing TypeScript helpers (download file, source below) and tests (download file, source below) remain available. The importer starter deliberately fails before repair; its reference is separate. The executor and bookmark slice are runnable references: use their candidate briefs for independent attempts.

Read the supplied code · typescript.ts
TypeScript helpers · typescript.ts
/** Bounded workers: preserve input order; drain started work and report errors per item. */
export async function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T, index: number) => Promise<R>): Promise<PromiseSettledResult<R>[]> {
  if (!Number.isInteger(limit) || limit < 1) throw new RangeError('positive integer limit required');
  const out: PromiseSettledResult<R>[] = new Array(items.length);
  let next = 0;
  async function worker() {
    while (next < items.length) {
      const index = next++; // No await between reading and claiming the index.
      try { out[index] = { status: 'fulfilled', value: await fn(items[index], index) }; }
      catch (reason) { out[index] = { status: 'rejected', reason }; }
    }
  }
  await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
  return out;
}

/** Aborting old work saves resources where supported. The generation guard protects correctness. */
export function latestOnly<T>(load: (query: string, signal: AbortSignal) => Promise<T>, render: (value: T) => void) {
  let generation = 0;
  let active: AbortController | undefined;
  return async (query: string): Promise<boolean> => {
    const own = ++generation;
    active?.abort();
    const controller = new AbortController();
    active = controller;
    try {
      const value = await load(query, controller.signal);
      if (own !== generation) return false;
      render(value);
      return true;
    } catch (error) {
      if (own !== generation) return false;
      throw error; // Current request failure must be visible to the caller/UI.
    }
  };
}

export class LRU<K, V> {
  private readonly values = new Map<K, V>();
  private readonly capacity: number;
  constructor(capacity: number) {
    if (!Number.isInteger(capacity) || capacity < 0) throw new RangeError('nonnegative integer capacity required');
    this.capacity = capacity;
  }
  get(key: K): V | undefined {
    if (!this.values.has(key)) return undefined;
    const value = this.values.get(key) as V;
    this.values.delete(key);
    this.values.set(key, value);
    return value;
  }
  put(key: K, value: V) {
    if (this.capacity === 0) return;
    this.values.delete(key);
    this.values.set(key, value);
    if (this.values.size > this.capacity) this.values.delete(this.values.keys().next().value as K);
  }
}

export type Bookmark = { id: string; title: string; version: number };
/** Apply a server response only if no newer local/server version is known. */
export function reconcile(current: Bookmark, incoming: Bookmark): Bookmark {
  if (current.id !== incoming.id) throw new Error('different entity');
  return incoming.version >= current.version ? incoming : current;
}
Read the supplied code · typescript.test.ts
tests · typescript.test.ts
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mapLimit, latestOnly, LRU, reconcile } from './typescript.ts';

test('bounded concurrency, order, and rejection isolation', async () => {
  let active = 0, peak = 0;
  const result = await mapLimit([4,3,2,1],2,async value => {
    active++; peak=Math.max(active,peak);
    try {
      await new Promise(resolve=>setTimeout(resolve,value));
      if(value===3) throw new Error('test failure');
      return value*2;
    } finally { active--; }
  });
  assert.equal(peak,2);assert.equal(active,0);
  assert.deepEqual(result.map(x=>x.status==='fulfilled'?x.value:'error'),[8,'error',4,2]);
  assert.deepEqual(await mapLimit([],2,async x=>x),[]);
  await assert.rejects(mapLimit([1],0,async x=>x),RangeError);
});
test('stale result cannot render even if load ignores abort',async()=>{
  const pending: Record<string,(x:string)=>void> = {};
  const rendered:string[]=[];
  const search=latestOnly((q)=>new Promise<string>(r=>{pending[q]=r}),v=>rendered.push(v));
  const old=search('old'),fresh=search('new');
  pending.new('new');assert.equal(await fresh,true);
  pending.old('old');assert.equal(await old,false);
  assert.deepEqual(rendered,['new']);
});
test('current failure propagates',async()=>{
  const search=latestOnly(async()=>{throw new Error('offline')},()=>{});
  await assert.rejects(search('q'),/offline/);
});
test('LRU refresh, overwrite, and zero capacity',()=>{
  const c=new LRU<string,number>(2);c.put('a',1);c.put('b',2);c.get('a');c.put('c',3);
  assert.equal(c.get('b'),undefined);c.put('a',4);assert.equal(c.get('a'),4);
  const empty=new LRU(0);empty.put('a',1);assert.equal(empty.get('a'),undefined);
});
test('late response cannot regress version',()=>{
  const current={id:'a',title:'new',version:3};
  assert.equal(reconcile(current,{id:'a',title:'old',version:2}),current);
  assert.throws(()=>reconcile(current,{id:'b',title:'x',version:4}));
});

For AI-assisted review, first write the invariant and three adversarial cases; then ask an assistant to implement fan-out, inspect every await, and record accepted and rejected suggestions. Finish a changed version unaided. AI review and independent implementation are distinct skills; recruiter instructions govern a real interview.

Do not call green reference tests a candidate pass. Complete the assessment route on more than one unfamiliar occasion. Timed mock · Coding home