From 44fb49a96faaf7e276a1583ac71751a4fb06784b Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Sat, 15 Aug 2026 22:34:11 -0400 Subject: [PATCH] Refresh stored rule template/display when their computed form drifts They are outside the rule key, so a format change (like the one in the previous commit) silently disabled rename detection for existing records. Co-Authored-By: Claude Fable 5 --- tools/build/db.ts | 16 ++++++++++++++++ tools/build/index.ts | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tools/build/db.ts b/tools/build/db.ts index 4a93f95d..1eec899e 100644 --- a/tools/build/db.ts +++ b/tools/build/db.ts @@ -211,6 +211,22 @@ export class BuildDb { this.db.prepare('DELETE FROM rules WHERE id = ?').run(id); } + // template/display are pure functions of the rule declaration but are not + // part of the rule key; refresh stored values that have drifted (e.g. the + // template format changed in a newer version of this tool), otherwise + // rename detection quietly stops matching older records. + refreshRuleMeta(entries : {id : bigint, template : string, display : string | null}[]) : void { + if (entries.length === 0) { + return; + } + const update = this.db.prepare('UPDATE rules SET template = ?, display = ? WHERE id = ?'); + this.db.transaction(() => { + for (const e of entries) { + update.run(e.template, e.display, e.id); + } + })(); + } + close() : void { this.db.pragma('wal_checkpoint(TRUNCATE)'); this.db.close(); diff --git a/tools/build/index.ts b/tools/build/index.ts index b6ad28bb..3020a2e6 100644 --- a/tools/build/index.ts +++ b/tools/build/index.ts @@ -100,14 +100,30 @@ async function main() : Promise { } return st; }; + const stored = db.loadStoredRules(); const plan = computePlan({ current: rules, - stored: db.loadStoredRules(), + stored, hashes, statOutput, adopt: Boolean(opts.adopt), }); + // Keep stored template/display in sync for key-matched rules; they are + // outside the key, so e.g. a template format change in this tool would + // otherwise silently disable rename detection for old records. + if (!dryRun) { + const storedByKey = new Map(stored.map(s => [s.key, s])); + const staleMeta = []; + for (const decl of rules) { + const s = storedByKey.get(decl.key); + if (s !== undefined && (s.template !== decl.template || s.display !== decl.display)) { + staleMeta.push({id: s.id, template: decl.template, display: decl.display}); + } + } + db.refreshRuleMeta(staleMeta); + } + const staleOutputs = []; const currentOutputs = new Set(rules.flatMap(r => r.outputs)); for (const s of plan.stale) {