Skip to content
Antoine Le LouëtIndependent senior developer (Home)
Back to the Journal

Advice3 min read

Developing with AI: keep a feature easy to change

A status filter followed by an owner filter shows how to retain business rules and tests alongside generated code.

The status filter's contract is preserved when the owner filter is added and combined with it.
The second change must preserve the rules checked during the first.

Write the rule before the first generation

The demonstration requirement is limited: filter requests by status, returning everything when the filter is absent. The data is fictional. Code for both stages was produced by Codex during preparation on 19 and 20 October 2026; no other agent or commercial account was used.

The precise model version is not exposed in the material, and the settings do not form a comparative protocol. The aim is to retain a change that can be replayed, not to evaluate a model or measure time savings.

A short brief that fixes the invariants

Text · first lab instruction
Ajouter un filtre par statut à une liste de demandes.
Si le statut est absent, retourner toutes les demandes.
Ne pas modifier les lignes d’entrée.
Conserver une fonction pure et les cas de test.
Ne pas ajouter de dépendance.
JavaScript · first generated version
export function filterRequests(rows, status) {
  return status === undefined
    ? rows
    : rows.filter(row => row.status === status);
}

The first check uses three requests, two of them open. The open-status and missing-filter cases passed on Node.js 24.13.0. The contract defines undefined as absence; an empty string does not implicitly carry that meaning.

Add an owner without losing the first rule

Text · second instruction
Ajouter un propriétaire facultatif.
Combiner les deux critères avec ET lorsqu’ils sont présents.
Préserver le comportement du filtre de statut absent.
Vérifier aussi un résultat vide.

The second version retains status selection and combines the owner in the predicate. The example checks an owner with status, the owner alone, no match and the existing behaviour. All these assertions passed. No manual correction after a failure was needed in this small experiment.

Read the combined rule and its limits

JavaScript · second version principle
return rows.filter(row =>
  (status === undefined || row.status === status) &&
  (owner === undefined || row.owner === owner)
);

Owner and status combine in the same predicate. A request passes only if it satisfies every criterion present. Checking an empty result prevents replacing no match with the full list.

Keep what the next change needs to know

  • Decision: criteria combine with AND; absence is expressed by undefined.
  • Boundary: pure function, no network access, fictional owner identifiers.
  • Evidence: commands, data and assertions from both stages.
  • Limitations: pagination, authorisation and persistence were not examined.

The files stage-1.mjs, stage-2.mjs and run.mjs retain both states in the lab linked in the sources. The next person can therefore recover the requirement without reconstructing a conversation. For a real filter, data authorisation must be checked separately on the server; a selection function provides no such guarantee.

Sources and useful links

Share on LinkedIn (new tab)

Keep reading
All articles in this category