Skip to content

Commit 3e41c9c

Browse files
akoclaude
andcommitted
fix(catalog): SHOW CONTEXT type filters match the refs table's casing
SHOW CONTEXT's relationship sections filter refs on TargetType/SourceType, but the literals were lowercase ('entity', 'microflow', 'page') while the refs builder stores them uppercase ('ENTITY', 'MICROFLOW', 'PAGE'). SQLite '=' is case-sensitive, so 12 sub-queries silently matched nothing: "Entities Used", "Microflows Using This Entity", "Pages Displaying This Entity", "Related Entities", and the workflow context's microflow/page/entity sections all rendered empty. (RefKind filters were already correct — RefKind is stored lowercase.) Uppercase the 12 literals to match the stored values. Verified live on MxGraphStudioDemo: `show context of` a microflow now lists the entity it creates, and `show context of` that entity lists the 4 microflows and 3 pages using it. SHOW CALLERS/CALLEES/REFERENCES/IMPACT (cmd_search.go) were unaffected — they are kind-agnostic (references/impact) or RefKind-based (callers/callees use 'call'), so they already work and pick up the new ref kinds automatically. Also un-skip TestCatalogRefs_Association (association refs now extracted, gap 2) and add TestCatalogRefs_ShowContextResolvesTypes to guard the casing. Both are //go:build integration (need `mx create-project`, run in CI); verified live here since this devcontainer's mx can't create projects. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2f4827c commit 3e41c9c

2 files changed

Lines changed: 63 additions & 14 deletions

File tree

mdl/executor/cmd_context.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func assembleMicroflowContext(ctx *ExecContext, out *strings.Builder, name strin
113113
out.WriteString("### Entities Used\n\n")
114114
result, err = ctx.Catalog.Query(fmt.Sprintf(
115115
`select distinct TargetName, RefKind from refs
116-
where SourceName = '%s' and TargetType = 'entity'
116+
where SourceName = '%s' and TargetType = 'ENTITY'
117117
ORDER by RefKind, TargetName`, name))
118118
if err == nil && result.Count > 0 {
119119
out.WriteString("| Entity | Usage |\n")
@@ -212,7 +212,7 @@ func assembleEntityContext(ctx *ExecContext, out *strings.Builder, name string,
212212
out.WriteString("### Microflows Using This Entity\n\n")
213213
result, err = ctx.Catalog.Query(fmt.Sprintf(
214214
`select distinct SourceName, RefKind from refs
215-
where TargetName = '%s' and SourceType = 'microflow'
215+
where TargetName = '%s' and SourceType = 'MICROFLOW'
216216
ORDER by RefKind, SourceName limit 20`, name))
217217
if err == nil && result.Count > 0 {
218218
out.WriteString("| Microflow | Usage |\n")
@@ -232,7 +232,7 @@ func assembleEntityContext(ctx *ExecContext, out *strings.Builder, name string,
232232
out.WriteString("### Pages Displaying This Entity\n\n")
233233
result, err = ctx.Catalog.Query(fmt.Sprintf(
234234
`select distinct SourceName from refs
235-
where TargetName = '%s' and SourceType = 'page'
235+
where TargetName = '%s' and SourceType = 'PAGE'
236236
ORDER by SourceName limit 10`, name))
237237
if err == nil && result.Count > 0 {
238238
for _, row := range result.Rows {
@@ -247,10 +247,10 @@ func assembleEntityContext(ctx *ExecContext, out *strings.Builder, name string,
247247
out.WriteString("### Related Entities\n\n")
248248
result, err = ctx.Catalog.Query(fmt.Sprintf(
249249
`select distinct TargetName, RefKind from refs
250-
where SourceName = '%s' and TargetType = 'entity'
250+
where SourceName = '%s' and TargetType = 'ENTITY'
251251
union
252252
select distinct SourceName, RefKind from refs
253-
where TargetName = '%s' and SourceType = 'entity'
253+
where TargetName = '%s' and SourceType = 'ENTITY'
254254
ORDER by RefKind, TargetName limit 10`, name, name))
255255
if err == nil && result.Count > 0 {
256256
for _, row := range result.Rows {
@@ -287,7 +287,7 @@ func assemblePageContext(ctx *ExecContext, out *strings.Builder, name string, de
287287
out.WriteString("### Entities Used\n\n")
288288
result, err = ctx.Catalog.Query(fmt.Sprintf(
289289
`select distinct TargetName from refs
290-
where SourceName = '%s' and TargetType = 'entity'
290+
where SourceName = '%s' and TargetType = 'ENTITY'
291291
ORDER by TargetName`, name))
292292
if err == nil && result.Count > 0 {
293293
for _, row := range result.Rows {
@@ -302,7 +302,7 @@ func assemblePageContext(ctx *ExecContext, out *strings.Builder, name string, de
302302
out.WriteString("### Microflows Called\n\n")
303303
result, err = ctx.Catalog.Query(fmt.Sprintf(
304304
`select distinct TargetName from refs
305-
where SourceName = '%s' and TargetType = 'microflow'
305+
where SourceName = '%s' and TargetType = 'MICROFLOW'
306306
ORDER by TargetName limit 15`, name))
307307
if err == nil && result.Count > 0 {
308308
for _, row := range result.Rows {
@@ -345,7 +345,7 @@ func assembleEnumerationContext(ctx *ExecContext, out *strings.Builder, name str
345345
out.WriteString("### Used By Entities\n\n")
346346
result, err = ctx.Catalog.Query(fmt.Sprintf(
347347
`select distinct SourceName from refs
348-
where TargetName = '%s' and SourceType = 'entity'
348+
where TargetName = '%s' and SourceType = 'ENTITY'
349349
ORDER by SourceName limit 15`, name))
350350
if err == nil && result.Count > 0 {
351351
for _, row := range result.Rows {
@@ -360,7 +360,7 @@ func assembleEnumerationContext(ctx *ExecContext, out *strings.Builder, name str
360360
out.WriteString("### Used By Microflows\n\n")
361361
result, err = ctx.Catalog.Query(fmt.Sprintf(
362362
`select distinct SourceName from refs
363-
where TargetName = '%s' and SourceType = 'microflow'
363+
where TargetName = '%s' and SourceType = 'MICROFLOW'
364364
ORDER by SourceName limit 15`, name))
365365
if err == nil && result.Count > 0 {
366366
for _, row := range result.Rows {
@@ -515,7 +515,7 @@ func assembleWorkflowContext(ctx *ExecContext, out *strings.Builder, name string
515515
out.WriteString("### Microflows Called\n\n")
516516
result, err = ctx.Catalog.Query(fmt.Sprintf(
517517
`select distinct TargetName, RefKind from refs
518-
where SourceName = '%s' and TargetType = 'microflow'
518+
where SourceName = '%s' and TargetType = 'MICROFLOW'
519519
ORDER by RefKind, TargetName`, name))
520520
if err == nil && result.Count > 0 {
521521
out.WriteString("| Microflow | Usage |\n")
@@ -532,7 +532,7 @@ func assembleWorkflowContext(ctx *ExecContext, out *strings.Builder, name string
532532
out.WriteString("### Pages Used\n\n")
533533
result, err = ctx.Catalog.Query(fmt.Sprintf(
534534
`select distinct TargetName, RefKind from refs
535-
where SourceName = '%s' and TargetType = 'page'
535+
where SourceName = '%s' and TargetType = 'PAGE'
536536
ORDER by TargetName`, name))
537537
if err == nil && result.Count > 0 {
538538
for _, row := range result.Rows {
@@ -547,7 +547,7 @@ func assembleWorkflowContext(ctx *ExecContext, out *strings.Builder, name string
547547
out.WriteString("### Entities Used\n\n")
548548
result, err = ctx.Catalog.Query(fmt.Sprintf(
549549
`select distinct TargetName, RefKind from refs
550-
where SourceName = '%s' and TargetType = 'entity'
550+
where SourceName = '%s' and TargetType = 'ENTITY'
551551
ORDER by TargetName`, name))
552552
if err == nil && result.Count > 0 {
553553
for _, row := range result.Rows {

mdl/executor/roundtrip_catalog_refs_test.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ end;`, mod, mod)); err != nil {
151151
}
152152

153153
func TestCatalogRefs_Association(t *testing.T) {
154-
t.Skip("TODO: association references not yet extracted into refs table (RefKindAssociate defined but unused)")
155-
156154
env := setupTestEnv(t)
157155
defer env.teardown()
158156

@@ -169,7 +167,9 @@ func TestCatalogRefs_Association(t *testing.T) {
169167
}
170168

171169
buildCatalogFull(t, env)
170+
// An association emits an `associate` ref to each endpoint (FROM and TO).
172171
assertRefExists(t, env, mod+".RefChild_RefParent", mod+".RefParent", "associate")
172+
assertRefExists(t, env, mod+".RefChild_RefParent", mod+".RefChild", "associate")
173173
}
174174

175175
func TestCatalogRefs_MultipleRefKindsToSameTarget(t *testing.T) {
@@ -412,6 +412,55 @@ end;`, mod, mod)); err != nil {
412412
}
413413
}
414414

415+
// TestCatalogRefs_ShowContextResolvesTypes guards against the case-mismatch that
416+
// silently broke SHOW CONTEXT's relationship sections: they filter on
417+
// TargetType/SourceType, but those literals were lowercase ('entity') while the
418+
// refs builder stores uppercase ('ENTITY'), and SQLite '=' is case-sensitive — so
419+
// "Entities Used" / "Microflows Using This Entity" always rendered empty.
420+
func TestCatalogRefs_ShowContextResolvesTypes(t *testing.T) {
421+
env := setupTestEnv(t)
422+
defer env.teardown()
423+
424+
mod := testModule
425+
426+
if err := env.executeMDL(fmt.Sprintf(`create or modify persistent entity %s.CtxEntity (Name: String(100));`, mod)); err != nil {
427+
t.Fatal(err)
428+
}
429+
if err := env.executeMDL(fmt.Sprintf(`create microflow %s.CtxCreator () returns Boolean
430+
begin
431+
$Obj = create %s.CtxEntity;
432+
return true;
433+
end;`, mod, mod)); err != nil {
434+
t.Fatal(err)
435+
}
436+
437+
buildCatalogFull(t, env)
438+
439+
// Microflow context must list the entity it uses (TargetType = 'ENTITY').
440+
env.output.Reset()
441+
if err := env.executor.Execute(&ast.ShowStmt{
442+
ObjectType: ast.ShowContext,
443+
Name: parseQualifiedName(mod + ".CtxCreator"),
444+
}); err != nil {
445+
t.Fatalf("show context of microflow failed: %v", err)
446+
}
447+
if mfCtx := env.output.String(); !strings.Contains(mfCtx, mod+".CtxEntity") {
448+
t.Errorf("microflow context should list the entity it uses:\n%s", mfCtx)
449+
}
450+
451+
// Entity context must list the microflow that uses it (SourceType = 'MICROFLOW').
452+
env.output.Reset()
453+
if err := env.executor.Execute(&ast.ShowStmt{
454+
ObjectType: ast.ShowContext,
455+
Name: parseQualifiedName(mod + ".CtxEntity"),
456+
}); err != nil {
457+
t.Fatalf("show context of entity failed: %v", err)
458+
}
459+
if entCtx := env.output.String(); !strings.Contains(entCtx, mod+".CtxCreator") {
460+
t.Errorf("entity context should list the microflow using it:\n%s", entCtx)
461+
}
462+
}
463+
415464
func TestCatalogRefs_ShowReferencesNoResults(t *testing.T) {
416465
env := setupTestEnv(t)
417466
defer env.teardown()

0 commit comments

Comments
 (0)