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.
import { loadReport } from "./service.js";
export function getReport(id) {
if (!Number.isInteger(id) || id <= 0) return { status: 400 };
return { status: 200, body: loadReport(id) };
}
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;
}
// 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
Optional explanation
Self-check, never gradedState 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.
- From app.request to the middleware chainTrace · Medium · honojs-hono
- Registering a new built-in driverArchitecture · Easy · unjs-unstorage
- Batch writes across two backendsDesign · Medium · unjs-unstorage
- Truncating a reactive arrayDesign · Medium · vuejs-core
- How a route's parameters get analyzedTrace · Hard · fastapi-fastapi
- From scan to a registered providerTrace · Hard · nestjs-nest
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
- SCIP Code Intelligence Protocol (SCIP maintainers)
- Dependencies (FastAPI documentation)
- Reactivity in Depth (Vue documentation)
- RFC 9111: HTTP Caching (IETF)