MCPcopy
hub / github.com/dosco/graphjin / TestCodeSQLWatcherInvalidatesResponseCache

Function TestCodeSQLWatcherInvalidatesResponseCache

serv/codesql_test.go:690–771  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

688}
689
690func TestCodeSQLWatcherInvalidatesResponseCache(t *testing.T) {
691 source := t.TempDir()
692 const before = `package main
693
694func WatchMe() int {
695 return 1
696}
697`
698 writeTestFile(t, filepath.Join(source, "main.go"), before)
699
700 conf := &Config{
701 Core: Core{
702 DisableAllowList: true,
703 Sources: []core.SourceConfig{
704 {Name: "code", Kind: "code", Path: source},
705 },
706 },
707 Serv: Serv{
708 ConfigPath: filepath.Join(t.TempDir(), "config"),
709 MCP: MCPConfig{Disable: true},
710 },
711 }
712
713 s, err := newGraphJinService(conf, nil)
714 if err != nil {
715 t.Fatal(err)
716 }
717 defer closeTestService(s)
718
719 query := `query GetWatchMe {
720 gj_code(where: { kind: { eq: "symbol" }, name: { eq: "WatchMe" } }) {
721 code
722 hash
723 }
724 }`
725 res, err := s.gj.GraphQL(context.Background(), query, nil, nil)
726 if err != nil {
727 t.Fatal(err)
728 }
729 var initial struct {
730 GJCode []struct {
731 Code string `json:"code"`
732 Hash string `json:"hash"`
733 } `json:"gj_code"`
734 }
735 if err := json.Unmarshal(res.Data, &initial); err != nil {
736 t.Fatalf("initial response: %v\n%s", err, res.Data)
737 }
738 if len(initial.GJCode) != 1 {
739 t.Fatalf("initial symbols = %d, want 1", len(initial.GJCode))
740 }
741
742 after := strings.Replace(before, "return 1", "return 2", 1)
743 writeTestFile(t, filepath.Join(source, "main.go"), after)
744
745 deadline := time.Now().Add(5 * time.Second)
746 for {
747 res, err = s.gj.GraphQL(context.Background(), query, nil, nil)

Callers

nothing calls this directly

Calls 4

writeTestFileFunction · 0.85
newGraphJinServiceFunction · 0.85
closeTestServiceFunction · 0.85
GraphQLMethod · 0.45

Tested by

no test coverage detected