(t *testing.T)
| 489 | } |
| 490 | |
| 491 | func TestCodeSQLGraphQLFileLifecycleMutations(t *testing.T) { |
| 492 | source := t.TempDir() |
| 493 | const deleteSrc = "package main\n\nfunc DeleteMe() {}\n" |
| 494 | const moveSrc = "package main\n\nfunc MoveMe() {}\n" |
| 495 | writeTestFile(t, filepath.Join(source, "delete_me.go"), deleteSrc) |
| 496 | writeTestFile(t, filepath.Join(source, "move_me.go"), moveSrc) |
| 497 | |
| 498 | conf := &Config{ |
| 499 | Core: Core{ |
| 500 | DisableAllowList: true, |
| 501 | Sources: []core.SourceConfig{ |
| 502 | { |
| 503 | Name: "code", |
| 504 | Kind: "code", |
| 505 | Path: source, |
| 506 | Capabilities: map[string]bool{ |
| 507 | "code.write": true, |
| 508 | "code.watch": false, |
| 509 | }, |
| 510 | }, |
| 511 | }, |
| 512 | }, |
| 513 | Serv: Serv{ |
| 514 | ConfigPath: filepath.Join(t.TempDir(), "config"), |
| 515 | MCP: MCPConfig{Disable: true}, |
| 516 | }, |
| 517 | } |
| 518 | |
| 519 | s, err := newGraphJinService(conf, nil) |
| 520 | if err != nil { |
| 521 | t.Fatal(err) |
| 522 | } |
| 523 | defer closeTestService(s) |
| 524 | |
| 525 | hashes := map[string]string{} |
| 526 | res, err := s.gj.GraphQL(context.Background(), `query { |
| 527 | gj_code(where: { kind: { eq: "file" } }, order_by: { path: asc }) { path hash } |
| 528 | }`, nil, nil) |
| 529 | if err != nil { |
| 530 | t.Fatal(err) |
| 531 | } |
| 532 | var filesOut struct { |
| 533 | GJCode []struct { |
| 534 | Path string `json:"path"` |
| 535 | Hash string `json:"hash"` |
| 536 | } `json:"gj_code"` |
| 537 | } |
| 538 | if err := json.Unmarshal(res.Data, &filesOut); err != nil { |
| 539 | t.Fatalf("gj_code file response: %v\n%s", err, res.Data) |
| 540 | } |
| 541 | for _, file := range filesOut.GJCode { |
| 542 | hashes[file.Path] = file.Hash |
| 543 | } |
| 544 | if hashes["delete_me.go"] == "" || hashes["move_me.go"] == "" { |
| 545 | t.Fatalf("missing source hashes: %#v", hashes) |
| 546 | } |
| 547 | |
| 548 | vars, err := json.Marshal(map[string]interface{}{ |
nothing calls this directly
no test coverage detected