Skip to content

Commit f0ccdda

Browse files
radimclaude
andcommitted
test(regresql-stub): cover synthetic slug from Owners
Lock in the slug priority — explicit RegresqlMeta["name"] beats a synthetic slug built from application/controller/action, which beats the q##-<fp8> fingerprint fallback. Also covers the job-only path for background workers and the rule that `job` is ignored when an HTTP triple is present (avoids ugly hybrid slugs). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2c22903 commit f0ccdda

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

cmd/qshape/regresql_stub_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,62 @@ func mustContain(t *testing.T, s, sub string) {
146146
t.Errorf("output missing %q. full:\n%s", sub, s)
147147
}
148148
}
149+
150+
// TestStubSlugFor_SynthesizesFromOwners: marginalia / sqlcommenter
151+
// workloads (Rails, Datadog) don't typically carry a `name` tag —
152+
// they carry application / controller / action. Rather than fall
153+
// back to q##-<fp8> for the dominant case, the slug is synthesized
154+
// by joining those three (sanitized) so a stub becomes e.g.
155+
// `billing-orderscontroller-show.sql`. Job-only tags also work
156+
// (background workers) when no HTTP triple is present.
157+
func TestStubSlugFor_SynthesizesFromOwners(t *testing.T) {
158+
cases := []struct {
159+
name string
160+
owners map[string]string
161+
want string
162+
}{
163+
{
164+
"controller+action",
165+
map[string]string{"controller": "OrdersController", "action": "show"},
166+
"orderscontroller-show",
167+
},
168+
{
169+
"application+controller+action",
170+
map[string]string{"application": "billing", "controller": "Orders", "action": "show"},
171+
"billing-orders-show",
172+
},
173+
{
174+
"job-only",
175+
map[string]string{"job": "EmailDigestJob"},
176+
"emaildigestjob",
177+
},
178+
{
179+
"job-ignored-when-http-present",
180+
map[string]string{"controller": "X", "job": "ignored"},
181+
"x",
182+
},
183+
}
184+
for _, c := range cases {
185+
t.Run(c.name, func(t *testing.T) {
186+
cl := qshape.Cluster{Fingerprint: "sha1:abc12345", Owners: c.owners}
187+
if got := stubSlugFor(1, cl); got != c.want {
188+
t.Errorf("got %q, want %q", got, c.want)
189+
}
190+
})
191+
}
192+
}
193+
194+
// TestStubSlugFor_NameWinsOverSynthetic: explicit RegresqlMeta["name"]
195+
// is always preferred over a synthetic owner-derived slug. This is
196+
// the ordering documented in stubSlugFor — explicit > synthetic >
197+
// fallback.
198+
func TestStubSlugFor_NameWinsOverSynthetic(t *testing.T) {
199+
c := qshape.Cluster{
200+
Fingerprint: "sha1:abc12345",
201+
RegresqlMeta: map[string]string{"name": "MyExplicitName"},
202+
Owners: map[string]string{"controller": "Other"},
203+
}
204+
if got := stubSlugFor(1, c); got != "myexplicitname" {
205+
t.Errorf("got %q, want myexplicitname", got)
206+
}
207+
}

0 commit comments

Comments
 (0)