Software Engineering
Data that expires silently: CI needs to check the data, not just the code
Code tests freeze time and never see data age. How to set up a freshness check in CI that warns without blocking the merge and runs even when the repository is idle.
Rodrigo Lucas · · 10 min read
When I opened the base of a personal project for a round of improvements, 95 of the 110 items with an expiry date had already expired, and CI was green. The project was an assistant that could only recommend what was in a curated JSON base, and a good part of that base had start and end dates. Every test passed and the code was right, but the product was practically empty and the answers came back with almost nothing in them. Nobody had touched the code in weeks, and no test looked at the thing that had actually aged, which was the data.
A code test checks behavior for a given input, and the data is the input nobody tests, so a data file can become wrong without a single byte in the repository changing. Since data has a clock, the check that matters depends on today's date, and that leads to three decisions I would take to any similar project. It stays separate from unit tests, it warns without blocking the merge and it has its own schedule, because data expires precisely when nobody is pushing.
Why the code test does not catch it#
A good unit test is deterministic and gives the same output for the same input on any day. To get there we pin the clock, build small fixtures and isolate the network. All of that is correct, and it is exactly what guarantees the test will never notice the real data aging. The fixture has three items with dates hand-picked so that the "next 14 days" filter returns two, so the test passes today and will keep passing five years from now.
With real data, the bytes stay the same and the meaning changes. An item with dataFim: "2026-10-31" was useful content in October and became junk in November, and the code that filters by date is still correct, it just filters a list that turned into the past.
The failure mode does not help either. Expired data does not throw an exception or produce an error log, the system just answers with less. In my case the assistant, which was not allowed to make things up, politely said it did not have much to suggest, and as far as any error monitoring could tell, everything was fine.
Not all data expires the same way. The easiest kind carries its validity in the record itself (deadlines, validity periods, end dates), because you can compute from today how much of the base is still good, and that is the kind this post is about. A fact about the world that changes without notice, or a link to something someone else controls, has no expiry field, and there CI can only point at symptoms.
The freshness check#
The first check I put in CI was the most direct one possible. It counts how many items in the base are valid in the next 14 days and fails if the number drops below a minimum. In TypeScript, with the same runner as the tests, it looked like this.
import { expect, it } from "vitest";
import { itens } from "@/data/itens";
import { ocorreEntre, hoje, somarDias } from "@/lib/datas";
// Below this, the answer for the week starts coming back nearly empty.
const MINIMO = Number(process.env.FRESCOR_MINIMO ?? 20);
const DIAS = 14;
it(`base has at least ${MINIMO} items in the next ${DIAS} days`, () => {
const inicio = hoje();
const fim = somarDias(inicio, DIAS);
const vigentes = itens.filter((e) => ocorreEntre(e, inicio, fim));
const vencidos = itens.filter((e) => e.dataFim && e.dataFim < inicio);
console.log(`${inicio} → ${fim}: ${vigentes.length} of ${itens.length} current; ${vencidos.length} expired.`);
expect(vigentes.length).toBeGreaterThanOrEqual(MINIMO);
});
The threshold comes from the product. Twenty items in two weeks is the point where, in my judgment, the answer starts to feel empty, with no statistics behind it. It lives in an environment variable so it can be tightened or loosened without touching the code.
The check measures what the user sees. The count of expired items goes to the log as a diagnostic, but what fails the check is the amount of valid content in the window the product uses. A base with half its records expired and plenty happening next week is fine, and a base with nothing expired and nothing in the next 14 days is not.
And it lives in a separate file. Unit tests stay in *.test.ts and data checks in *.check.ts, selected by an environment variable in the runner config. That way npm test stays deterministic and npm run checar:dados is the only place where "today" enters the picture. Mixing the two makes the unit test depend on the calendar, and that is the kind of test everyone learns to ignore. Even separated, the check is still non-deterministic by construction (the same revision of the code can pass today and fail tomorrow), so the step name in CI has to make it clear that red there means stale data.
With the check in place, updating the base stopped being "I think it's stale" and became an acceptance criterion. I removed the 95 expired items, researched 68 new ones covering the following six weeks, and the commit only went in with the check passing. Before that it had been born red against the old base, which is the minimum for trusting a new check (I wrote about that in Tests that pass without protecting anything). It also left a written forecast, because the new base ran until mid-December and at some point before that the alarm would go off again, before the problem reached the user.
What dbt already does and what changes here#
In a data warehouse this idea comes ready-made. dbt has dbt source freshness (which the current docs treat as legacy in favor of dbt freshness), a freshness check configured with two thresholds, warn_after and error_after. It takes the max value of a load column, such as _etl_loaded_at, and compares it with the current time, so it answers how long ago new data arrived.
For periodically loaded data that is the right question, and in a warehouse I would not reinvent anything. My case had two differences. The base was a JSON file versioned in the repository, with no warehouse or pipeline, so the natural place for the check was the CI that already existed. And the question was a different one, because a freshly updated base can sit entirely in the past. What matters is whether there is still valid content from here on, looking at each record's end date. The split between warning and failing I took from dbt.
The record that disagrees with itself#
You cannot verify a fact about the world in CI, but you can verify whether a record agrees with itself. It is common for the same data to exist in two formats, free text for display and a structured field for computing. In my case it was a time of day, written by hand in both forms at different moments, and nothing guaranteed they said the same thing.
for (const registro of registros) {
if (!Array.isArray(registro.horarios) || !registro.horarioTexto) continue;
const inicioTexto = primeiraHora(registro.horarioTexto); // "9h" → 9
const inicioDados = Math.min(...registro.horarios.map((h) => hora(h.inicio)));
if (inicioTexto !== null && inicioTexto !== inicioDados) {
divergentes.push(`${registro.id}: text says ${inicioTexto}h, data says ${inicioDados}h`);
}
}
This version is naive on purpose and gives false positives when the first hour written in the text is not the smallest one in the structure. Even so, what is left after going through the list is the error that matters, like the text saying 9 a.m. and the structure saying 11 a.m. No test of the code that computes on top of the structure catches it, because that code computes correctly on wrong data. For the false positives, an explicit exception list works better than turning the check off. The long-term fix is to generate the text from the structure, and until then the check keeps the divergence from growing.
Where the check goes in CI#
This is where the main trade-off sits. A check that depends on today's date can turn red on a PR that only fixes a typo, and if it blocks the merge, the team (even if the team is just you) quickly learns to turn it off. In my project it runs as a step that does not bring the job down.
jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
# Depends on today's date: warns when the base ages, without blocking code PRs.
- name: Base has content in the next 14 days
run: npm run checar:dados
continue-on-error: true
With continue-on-error: true the step can fail and the job still passes. That solves the blocking and creates the opposite risk, because a yellow step inside a green job is easy to miss, and a warning nobody reads is the same as having no check. So the result has to go where someone will read it, like an annotation with ::warning or a Markdown summary in GITHUB_STEP_SUMMARY, both of which show up on the run page.
There was one piece my workflow was missing. The check ran on pull_request and push, so if nobody opened a PR it did not run, and the way out was a scheduled trigger.
on:
pull_request:
push:
branches: [main]
schedule:
- cron: "17 9 * * 1" # every Monday, away from the top of the hour
That trigger has fine print. It only runs on the default branch and can be delayed at peak times, and since the start of every hour is one of them, I used an odd minute. In a public repository, GitHub disables scheduled workflows after 60 days without activity in the repository, which catches exactly the idle project the schedule was supposed to cover. For a project that may stay quiet for months, the schedule needs some outside alert (an email, an issue opened by the workflow itself) or a periodic review on your part.
Source and confidence in each record#
A check that says "this item expired" or "this record diverges" only helps if you know where to verify it. In the new base, every record got two fields that no code reads in order to work, fonte (the URL the information came from) and confianca (high, medium or low). Of the 68 items added in the update, 54 had high confidence and 14 medium.
Without those fields, fixing a suspicious record means researching from scratch, and with them it means opening the source and comparing. They also make room for new checks, like rejecting a record without a source or, with a verification date, flagging what has not been checked in more than six months.
Even with all of that, the check only sees symptoms. It knows an item expired and that two fields disagree, but it does not know something stopped existing if the record has nothing that contradicts it, and for that the only option is to re-verify against the source from time to time, work done by a person or by a process you pay for. I also do not know whether twenty items is the right threshold. It came from a judgment about when the answer feels empty, and without telemetry on searches that come back empty I have no way to say whether it is too high or too low.
References#
updated on
01 blog
related
software engineering
A perfect Lighthouse SEO score does not prove SEO, the HTML your site serves does
Lighthouse gave my site an SEO score of 100 while the canonical pointed to a domain that returned 404. What the audit checks, what it cannot check and a 40-line checker that catches the defect.
software engineering
42 green checks and no citations: the index decides what AI cites
A site passed every SEO check and did not show up in any search engine. Blocking the training bot does not take anyone out of ChatGPT, but staying out of the index does.
software engineering
Tests that pass without protecting anything: watch the test fail before you trust it
A green CI that ran no tests, a spec that never saw the template, and another that breaks between midnight and 1 a.m. I only trust a test after seeing it fail for the right reason.
02 blog
Who writes
Contact
Let's swap ideas
Get the next articles
No spam, one email when a new article ships. Unsubscribe anytime.