fix(sl): stop baking drift-prone counts into overlay summaries (#270)

The auto-generated semantic-layer overlay description embedded
measure/segment/column counts that were computed once and never
recomputed, so the summary drifted and misreported its source after
measures were later appended. Make the auto fallback count-free, since
those counts are already rendered live from the body at `ktx sl list`/
`read` time; this removes the drift class without ever overwriting
human-authored descriptions (the fill-only-when-empty guard is untouched).

Adds a regression test that fails on main and passes after the fix, plus
guards for description preservation and the no-measures fallback.
This commit is contained in:
Andrey Avtomonov 2026-06-08 15:58:12 +02:00 committed by GitHub
parent 2c18a62de4
commit 5232578d44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 77 additions and 16 deletions

View file

@ -50,13 +50,6 @@ function humanizeIdentifier(value: string): string {
.toLowerCase();
}
function formatCount(count: number, singular: string, plural = `${singular}s`): string | null {
if (count <= 0) {
return null;
}
return `${count} ${count === 1 ? singular : plural}`;
}
function sourceFallback(source: Record<string, unknown>, sourceName: string): string {
const table = cleanText(source.table);
const sql = cleanText(source.sql);
@ -66,15 +59,10 @@ function sourceFallback(source: Record<string, unknown>, sourceName: string): st
if (sql) {
return `Semantic-layer source for ${sourceName} backed by curated SQL.`;
}
const counts = [
formatCount(Array.isArray(source.measures) ? source.measures.length : 0, 'measure'),
formatCount(Array.isArray(source.segments) ? source.segments.length : 0, 'segment'),
formatCount(Array.isArray(source.columns) ? source.columns.length : 0, 'computed column'),
].filter((item): item is string => Boolean(item));
return counts.length > 0
? `Semantic-layer overlay for ${sourceName} defining ${counts.join(', ')}.`
: `Semantic-layer overlay for ${sourceName}.`;
// Measure/segment/column counts are rendered live from the body at list/read
// time, so baking them into stored prose freezes a derived value that drifts
// as the source later gains measures. Keep the auto fallback count-free.
return `Semantic-layer overlay for ${sourceName}.`;
}
function columnFallback(column: Record<string, unknown>, sourceName: string): string {