loadConformanceTest loads one conformance test from the given path contained in the root dir.
(dir, path string)
| 382 | // loadConformanceTest loads one conformance test from the given path contained |
| 383 | // in the root dir. |
| 384 | func loadConformanceTest(dir, path string) (*conformanceTest, error) { |
| 385 | content, err := os.ReadFile(path) |
| 386 | if err != nil { |
| 387 | return nil, err |
| 388 | } |
| 389 | test := &conformanceTest{ |
| 390 | name: strings.TrimPrefix(path, dir+string(filepath.Separator)), |
| 391 | path: path, |
| 392 | archive: txtar.Parse(content), |
| 393 | } |
| 394 | if len(test.archive.Files) == 0 { |
| 395 | return nil, fmt.Errorf("txtar archive %q has no '-- filename --' sections", path) |
| 396 | } |
| 397 | |
| 398 | // decodeMessages loads JSON-RPC messages from the archive file. |
| 399 | decodeMessages := func(data []byte) ([]jsonrpc.Message, error) { |
| 400 | dec := json.NewDecoder(bytes.NewReader(data)) |
| 401 | var res []jsonrpc.Message |
| 402 | for dec.More() { |
| 403 | var raw json.RawMessage |
| 404 | if err := dec.Decode(&raw); err != nil { |
| 405 | return nil, err |
| 406 | } |
| 407 | m, err := jsonrpc2.DecodeMessage(raw) |
| 408 | if err != nil { |
| 409 | return nil, err |
| 410 | } |
| 411 | res = append(res, m) |
| 412 | } |
| 413 | return res, nil |
| 414 | } |
| 415 | // loadFeatures loads lists of named features from the archive file. |
| 416 | loadFeatures := func(data []byte) []string { |
| 417 | var feats []string |
| 418 | for line := range strings.Lines(string(data)) { |
| 419 | if f := strings.TrimSpace(line); f != "" { |
| 420 | feats = append(feats, f) |
| 421 | } |
| 422 | } |
| 423 | return feats |
| 424 | } |
| 425 | |
| 426 | seen := make(map[string]bool) // catch accidentally duplicate files |
| 427 | for _, f := range test.archive.Files { |
| 428 | if seen[f.Name] { |
| 429 | return nil, fmt.Errorf("duplicate file name %q", f.Name) |
| 430 | } |
| 431 | seen[f.Name] = true |
| 432 | switch f.Name { |
| 433 | case "tools": |
| 434 | test.tools = loadFeatures(f.Data) |
| 435 | case "prompts": |
| 436 | test.prompts = loadFeatures(f.Data) |
| 437 | case "resources": |
| 438 | test.resources = loadFeatures(f.Data) |
| 439 | case "client": |
| 440 | test.client, err = decodeMessages(f.Data) |
| 441 | if err != nil { |
no test coverage detected
searching dependent graphs…