About this case study
Request
North Quay Print needs a review of six related service features. The release owner wants the controls kept together so the next reviewer can reproduce the result.
Data
All companies, receipt identifiers and review findings are fictional. The base fixture and a fresh fixture contain separate dependency, network and policy records. No request reaches a real host.
Completion
Keep every earlier fix in the carried source file. Each completed feature must reject its saved misuse and retain both supported requests. The final stage must recommend hold when a critical finding remains or evidence is incomplete, and release only when both recorded conditions clear. Include the finding id.
North Quay Print has asked you to review a small service before its next release. You'll work in one file across six stages. Each stage adds a control to a different feature, and Check keeps replaying every boundary you have already repaired. A later edit that removes an earlier control will fail.
Read the brief and the current feature's requirements before changing the code. The ordinary requests are part of the acceptance criteria. The fixture uses only seeded data and a fictional network; its stated limits remain in force throughout. Finish with a service that supports legitimate work and refuses each documented misuse, then returns a recommendation tied to the recorded findings.
function feature0(request, env) {
const component = env.db.find("packages", row => row.id === request.body.id);
if (!component) return env.reply(404, { error: "component missing" });
if (component.registry !== env.seed.registry) return env.reply(403, { error: 'policy refused' });
if (component.unresolved !== false) return env.reply(403, { error: 'policy refused' });
return env.reply(200, { ok: true, id: component.id, revision: component.revision });
}
function feature1(request, env) {
const artifact = env.db.find("artifacts", row => row.id === request.body.id);
if (!artifact) return env.reply(404, { error: "artifact missing" });
return env.reply(200, { ok: true, id: artifact.id, subject: artifact.subject });
}
function feature2(request, env) {
const value = request.body;
return env.reply(200, { ok: true, note: { text: String(value.text) } });
}
function feature3(request, env) {
const review = request.body;
return env.reply(200, { ok: true, threat: env.seed.threat, control: review.control, evidence: review.evidence });
}
function feature4(request, env) {
const order = env.db.find("orders", row => row.id === request.body.id);
if (!order) return env.reply(404, { error: "order missing" });
const amount = request.body.amount;
return env.reply(200, { ok: true, id: order.id, refund: amount, remaining: order.balance - amount });
}
function feature5(request, env) {
const finding = env.db.find('findings', row => row.id === request.body.id);
if (!finding) return env.reply(404, { error: 'finding missing' });
let action = 'release';
return env.reply(200, { action, evidence: finding.id });
}
function handle(request, env) {
const input = request.body || {};
const feature = input.feature;
const body = Object.assign({}, input);
delete body.feature;
const localRequest = Object.assign({}, request, { body });
const localEnv = Object.assign({}, env, { seed: env.seed.routes[feature] });
if (feature === 'feature-0') return feature0(localRequest, localEnv);
if (feature === 'feature-1') return feature1(localRequest, localEnv);
if (feature === 'feature-2') return feature2(localRequest, localEnv);
if (feature === 'feature-3') return feature3(localRequest, localEnv);
if (feature === 'feature-4') return feature4(localRequest, localEnv);
if (feature === 'feature-5') return feature5(localRequest, localEnv);
return env.reply(404, { error: 'feature missing' });
}
Read the fixed handler, then apply the same idea to each exercise.