Skip to content

L24 Codebase investigation capstone

30 minSuggested first: C3 and L19 to L23

Outcome

Investigate an unfamiliar code path and support a design claim with the input, call sequence, and a line of evidence.

The case

A toy endpoint serves a report from a cache or from a backing store. The three files below are an original, fixed teaching fixture. Assume every call is synchronous, valid ids are positive integers, the cache and the store already exist, and the store always succeeds.

Each of the four tasks is scored on its own. Read the requirements once, then use the file list rather than reading every file top to bottom. Record your choices before you check them.

route.jsJavaScript
import { loadReport } from "./service.js";
export function getReport(id) {
  if (!Number.isInteger(id) || id <= 0) return { status: 400 };
  return { status: 200, body: loadReport(id) };
}
service.jsJavaScript
import { cache, store } from "./adapters.js";
export function loadReport(id) {
  const hit = cache.get(id);
  if (hit !== undefined) return hit;
  const report = store.read(id);
  cache.set(id, report);
  return report;
}
adapters.jsJavaScript
// Teaching fixture: cache is a Map; store.read returns a report object.
export const cache = new Map();
export const store = { read: (id) => ({ id, title: "Report" }) };

Investigation tasks

1. Find

Counts toward completion

In route.js, select the line that rejects a non-positive id.

route.js Select one line

2. Trace

Counts toward completion

For id 7 with an empty cache, start at getReport and stop at the first call to cache.set. Add the functions entered, in order, including the start and the end. Leave out built-ins other than the named cache operations.

Your sequence

Add steps from the list, in the order they happen.

Steps

3. Architecture

Counts toward completion

Which file owns the choice between a cached result and a backing-store read?

Choose one answer

4. Design

Counts toward completion

The store's report for id 7 changes while the process stays up. What can happen on the next read?

Choose one answer

Optional explanation

Self-check, never graded

State the benefit of this cache, its limitation, and one remedy. Cite the branch or the write that supports each claim. This is for you: it's never graded or saved.

After the tasks

If you missed a task, the review link on it names the lesson to revisit: L02 for the guard, L10 for the call order, L12 for policy versus implementation, and L22 for the cache behavior. Then retry with a cache-hit input or an invalid id before moving on.

Practice on a real repository

Independently attempt the first two puzzles below and one Design puzzle. For a stretch, try a Trace in FastAPI or Nest. On each, write a private evidence note with the question, the input, the branch, and the stop rule, and submit only the code selections the puzzle asks for. After solving, read its solution through the puzzle page.

Related topics: Caching and storage, Code structure

Practice is optional. Solving a puzzle doesn't complete a lesson, and lessons never change a puzzle's points.

References