36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
package service
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
)
|
||
|
|
|
||
|
|
// A refusal sentinel must be reported as a refusal, because it needs a different
|
||
|
|
// decision (retry or skip the page) than a structurally incomplete answer.
|
||
|
|
func TestWikiPageBodyReportsTheRefusalSentinelSeparately(t *testing.T) {
|
||
|
|
content := "SUMMARY: headline\n\n## Body\nSome text.\n\n" + wikiPageRepairUnsafeMarker
|
||
|
|
err := validateWikiPageBody(content, true)
|
||
|
|
require.Error(t, err)
|
||
|
|
require.Contains(t, err.Error(), "unsafe to generate")
|
||
|
|
require.Contains(t, err.Error(), wikiPageRepairUnsafeMarker)
|
||
|
|
}
|
||
|
|
|
||
|
|
// The structural failures keep the historical wording so existing assertions and the
|
||
|
|
// operators' mental model stay valid, with the shape appended for diagnosis.
|
||
|
|
func TestWikiPageBodyNamesTheStructuralFailure(t *testing.T) {
|
||
|
|
err := validateWikiPageBody("SUMMARY: headline\n\n ", true)
|
||
|
|
require.Error(t, err)
|
||
|
|
require.Contains(t, err.Error(), "complete wiki page requires a nonempty summary and body")
|
||
|
|
require.Contains(t, err.Error(), "empty body")
|
||
|
|
|
||
|
|
err = validateWikiPageBody("## Body only\nText without the summary line.", true)
|
||
|
|
require.Error(t, err)
|
||
|
|
require.Contains(t, err.Error(), "missing SUMMARY line")
|
||
|
|
|
||
|
|
require.NoError(t, validateWikiPageBody("SUMMARY: headline\n\n## Body\nText.", true))
|
||
|
|
require.NoError(t, validateWikiPageBody("## Body only\nText.", false))
|
||
|
|
require.Less(t, strings.Count(err.Error(), "complete wiki page"), 2)
|
||
|
|
}
|