Skip to content

Commit 73d3c60

Browse files
author
johnlanni
committed
test(ai-prompt-decorator): drop wasm host from regex helper test
The "regex rule supports capture references" subtest only exercises the applyReplaceRulesToContent helper on rules that parseConfig has compiled. Going through test.RunTest and host.GetMatchConfig in wasm mode requires an active common HTTP context, which the helper subtest never sets up, so CI failed with "http context is not a common http context" once a main.wasm artifact was present. Call parseConfig directly with gjson.ParseBytes to compile the regex rule and assert against the helper. This keeps the test focused on the helper logic and behaves identically in `go test` and CI regardless of whether main.wasm is built.
1 parent 745600f commit 73d3c60

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

plugins/wasm-go/extensions/ai-prompt-decorator/main_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm/types"
2323
"github.com/higress-group/wasm-go/pkg/test"
2424
"github.com/stretchr/testify/require"
25+
"github.com/tidwall/gjson"
2526
)
2627

2728
// 测试配置:基础装饰器配置
@@ -754,8 +755,11 @@ func TestApplyReplaceRulesToContent(t *testing.T) {
754755
})
755756

756757
t.Run("regex rule supports capture references", func(t *testing.T) {
757-
// parseConfig is normally responsible for compiling, so do it here too.
758-
cfgJSON, _ := json.Marshal(map[string]interface{}{
758+
// parseConfig is what compiles the regex in production, so call it
759+
// directly here instead of going through the wasm test host. This
760+
// keeps the helper-level test independent of the wasm runtime so it
761+
// behaves the same in `go test` and CI.
762+
cfgJSON, err := json.Marshal(map[string]interface{}{
759763
"prepend": []map[string]interface{}{},
760764
"append": []map[string]interface{}{},
761765
"replace": []map[string]interface{}{
@@ -766,14 +770,10 @@ func TestApplyReplaceRulesToContent(t *testing.T) {
766770
},
767771
},
768772
})
769-
test.RunTest(t, func(t *testing.T) {
770-
host, status := test.NewTestHost(json.RawMessage(cfgJSON))
771-
defer host.Reset()
772-
require.Equal(t, types.OnPluginStartStatusOK, status)
773-
cfg, err := host.GetMatchConfig()
774-
require.NoError(t, err)
775-
decoratorConfig := cfg.(*AIPromptDecoratorConfig)
776-
require.Equal(t, "hi world", applyReplaceRulesToContent("user", "hello world", decoratorConfig.Replace))
777-
})
773+
require.NoError(t, err)
774+
775+
var cfg AIPromptDecoratorConfig
776+
require.NoError(t, parseConfig(gjson.ParseBytes(cfgJSON), &cfg))
777+
require.Equal(t, "hi world", applyReplaceRulesToContent("user", "hello world", cfg.Replace))
778778
})
779779
}

0 commit comments

Comments
 (0)