Skip to content

Commit fc5f677

Browse files
akoclaude
andcommitted
fix: ALTER SNIPPET no longer fails with "page not found" (#402)
The AST visitor sets ContainerType to "SNIPPET" (uppercase) but execAlterPage compared against lowercase "snippet", so the snippet branch was never taken and the call always fell through to findPageByName, producing "page not found". Fix: normalise ContainerType to lowercase via strings.ToLower before the comparison. Added regression test with uppercase ContainerType to cover the visitor-produced form. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2934e52 commit fc5f677

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

mdl/executor/cmd_alter_page.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func execAlterPage(ctx *ExecContext, s *ast.AlterPageStmt) error {
3030

3131
var unitID model.ID
3232
var containerID model.ID
33-
containerType := s.ContainerType
33+
containerType := strings.ToLower(s.ContainerType)
3434
if containerType == "" {
3535
containerType = "page"
3636
}

mdl/executor/cmd_alter_page_mock_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,38 @@ func TestAlterPage_Snippet_Success(t *testing.T) {
135135
assertContainsStr(t, buf.String(), "Altered snippet")
136136
}
137137

138+
// Issue #402 — visitor sets ContainerType to uppercase "SNIPPET"; executor
139+
// must normalise before comparing so the snippet branch is taken.
140+
func TestAlterPage_Snippet_UppercaseContainerType_Issue402(t *testing.T) {
141+
mod := mkModule("MyModule")
142+
snp := mkSnippet(mod.ID, "TestSnippet")
143+
saved := false
144+
mb := &mock.MockBackend{
145+
IsConnectedFunc: func() bool { return true },
146+
ListModulesFunc: func() ([]*model.Module, error) { return []*model.Module{mod}, nil },
147+
ListFoldersFunc: func() ([]*types.FolderInfo, error) { return nil, nil },
148+
ListSnippetsFunc: func() ([]*pages.Snippet, error) {
149+
return []*pages.Snippet{snp}, nil
150+
},
151+
OpenPageForMutationFunc: func(unitID model.ID) (backend.PageMutator, error) {
152+
return &mock.MockPageMutator{
153+
SaveFunc: func() error { saved = true; return nil },
154+
}, nil
155+
},
156+
}
157+
h := mkHierarchy(mod)
158+
withContainer(h, snp.ContainerID, mod.ID)
159+
ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h))
160+
assertNoError(t, execAlterPage(ctx, &ast.AlterPageStmt{
161+
ContainerType: "SNIPPET", // uppercase as produced by the AST visitor
162+
PageName: ast.QualifiedName{Module: "MyModule", Name: "TestSnippet"},
163+
}))
164+
if !saved {
165+
t.Error("expected Save to be called")
166+
}
167+
assertContainsStr(t, buf.String(), "Altered snippet")
168+
}
169+
138170
// ---------------------------------------------------------------------------
139171
// Open mutator error
140172
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)