research-master 0.1.40

MCP server for searching and downloading academic papers from multiple research sources
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
//! Unified tool handlers with smart source selection.

use std::sync::Arc;

use serde_json::Value;

use super::tools::ToolHandler;

/// Helper function to auto-detect the appropriate source for a paper ID
fn auto_detect_source(
    sources: &Arc<Vec<Arc<dyn crate::sources::Source>>>,
    paper_id: &str,
) -> Result<Arc<dyn crate::sources::Source>, String> {
    let paper_id_lower = paper_id.to_lowercase();

    // arXiv: arXiv:1234.5678 or numeric format like 1234.5678
    if paper_id_lower.starts_with("arxiv:")
        || (paper_id.len() > 4 && paper_id.chars().take(9).all(|c| c.is_numeric() || c == '.'))
    {
        return sources
            .iter()
            .find(|s| s.id() == "arxiv")
            .cloned()
            .ok_or_else(|| "arXiv source not available".to_string());
    }

    // PMC: PMC followed by digits
    if paper_id_upper_start(paper_id, "PMC") {
        return sources
            .iter()
            .find(|s| s.id() == "pmc")
            .cloned()
            .ok_or_else(|| "PMC source not available".to_string());
    }

    // HAL: hal- followed by digits
    if paper_id_lower.starts_with("hal-") {
        return sources
            .iter()
            .find(|s| s.id() == "hal")
            .cloned()
            .ok_or_else(|| "HAL source not available".to_string());
    }

    // IACR: format like 2023/1234
    if paper_id.chars().filter(|&c| c == '/').count() == 1 {
        return sources
            .iter()
            .find(|s| s.id() == "iacr")
            .cloned()
            .ok_or_else(|| "IACR source not available".to_string());
    }

    // DOI format (10.xxxx/xxxxxx) - prefer Semantic Scholar for DOI lookup
    if paper_id.starts_with("10.") {
        // First, explicitly check for Semantic Scholar (preferred)
        if let Some(source) = sources
            .iter()
            .find(|s| s.id() == "semantic" && s.supports_doi_lookup())
        {
            return Ok(Arc::clone(source));
        }
        // Fallback to any DOI-capable source
        if let Some(source) = sources.iter().find(|s| s.supports_doi_lookup()) {
            return Ok(Arc::clone(source));
        }
    }

    // Default: try arXiv first, then semantic
    if let Some(source) = sources.iter().find(|s| s.id() == "arxiv") {
        return Ok(Arc::clone(source));
    }

    if let Some(source) = sources.iter().find(|s| s.id() == "semantic") {
        return Ok(Arc::clone(source));
    }

    Err("Could not auto-detect source. Please specify source explicitly.".to_string())
}

/// Helper function to check if a string starts with a specific prefix (case-insensitive)
fn paper_id_upper_start(paper_id: &str, prefix: &str) -> bool {
    if paper_id.len() < prefix.len() {
        return false;
    }

    paper_id[..prefix.len()].to_uppercase() == prefix
}

/// Handler for searching papers across all or specific sources
#[derive(Debug)]
pub struct SearchPapersHandler {
    pub sources: Arc<Vec<Arc<dyn crate::sources::Source>>>,
}

#[async_trait::async_trait]
impl ToolHandler for SearchPapersHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let query = args
            .get("query")
            .and_then(|v| v.as_str())
            .ok_or("Missing 'query' parameter")?;

        let max_results = args
            .get("max_results")
            .and_then(|v| v.as_u64())
            .unwrap_or(10) as usize;

        let year = args
            .get("year")
            .and_then(|v| v.as_str())
            .map(|s| s.to_string());

        let category = args
            .get("category")
            .and_then(|v| v.as_str())
            .map(|s| s.to_string());

        let source_filter = args.get("source").and_then(|v| v.as_str());

        let mut all_results = Vec::new();

        for source in self.sources.iter() {
            // Filter by source if specified
            if let Some(filter) = source_filter {
                if source.id() != filter {
                    continue;
                }
            }

            // Skip sources that don't support search
            if !source.supports_search() {
                continue;
            }

            let mut search_query = crate::models::SearchQuery::new(query).max_results(max_results);

            if let Some(ref year) = year {
                search_query = search_query.year(year);
            }
            if let Some(ref cat) = category {
                search_query = search_query.category(cat);
            }

            match source.search(&search_query).await {
                Ok(response) => {
                    all_results.extend(response.papers);
                }
                Err(e) => {
                    tracing::warn!("Search failed for {}: {}", source.id(), e);
                }
            }
        }

        serde_json::to_value(all_results).map_err(|e| e.to_string())
    }
}

/// Handler for searching papers by author
#[derive(Debug)]
pub struct SearchByAuthorHandler {
    pub sources: Arc<Vec<Arc<dyn crate::sources::Source>>>,
}

#[async_trait::async_trait]
impl ToolHandler for SearchByAuthorHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let author = args
            .get("author")
            .and_then(|v| v.as_str())
            .ok_or("Missing 'author' parameter")?;

        let max_results = args
            .get("max_results")
            .and_then(|v| v.as_u64())
            .unwrap_or(10) as usize;

        let year = args.get("year").and_then(|v| v.as_str());

        let source_filter = args.get("source").and_then(|v| v.as_str());

        let mut all_results = Vec::new();

        for source in self.sources.iter() {
            // Filter by source if specified
            if let Some(filter) = source_filter {
                if source.id() != filter {
                    continue;
                }
            }

            // Skip sources that don't support author search
            if !source.supports_author_search() {
                continue;
            }

            match source.search_by_author(author, max_results, year).await {
                Ok(response) => {
                    all_results.extend(response.papers);
                }
                Err(e) => {
                    tracing::warn!("Author search failed for {}: {}", source.id(), e);
                }
            }
        }

        serde_json::to_value(all_results).map_err(|e| e.to_string())
    }
}

/// Handler for getting paper metadata with auto-detection
#[derive(Debug)]
pub struct GetPaperHandler {
    pub sources: Arc<Vec<Arc<dyn crate::sources::Source>>>,
}

#[async_trait::async_trait]
impl ToolHandler for GetPaperHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let paper_id = args
            .get("paper_id")
            .and_then(|v| v.as_str())
            .ok_or("Missing 'paper_id' parameter")?;

        let source_override = args.get("source").and_then(|v| v.as_str());

        // Find the appropriate source
        let source = self.find_source(paper_id, source_override)?;

        // For now, we'll do a search with the paper ID as the query
        let search_query = crate::models::SearchQuery::new(paper_id).max_results(1);

        let response = source
            .search(&search_query)
            .await
            .map_err(|e| e.to_string())?;

        if response.papers.is_empty() {
            return Err(format!("Paper '{}' not found in {}", paper_id, source.id()));
        }

        serde_json::to_value(&response.papers[0]).map_err(|e| e.to_string())
    }
}

/// Handler for downloading papers with auto-detection
#[derive(Debug)]
pub struct DownloadPaperHandler {
    pub sources: Arc<Vec<Arc<dyn crate::sources::Source>>>,
}

#[async_trait::async_trait]
impl ToolHandler for DownloadPaperHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let paper_id = args
            .get("paper_id")
            .and_then(|v| v.as_str())
            .ok_or("Missing 'paper_id' parameter")?;

        let source_override = args.get("source").and_then(|v| v.as_str());

        let output_path = args
            .get("output_path")
            .and_then(|v| v.as_str())
            .unwrap_or("./downloads");

        // Find the appropriate source
        let source = self.find_source(paper_id, source_override)?;

        let request = crate::models::DownloadRequest::new(paper_id, output_path);

        let result = source.download(&request).await.map_err(|e| e.to_string())?;

        serde_json::to_value(result).map_err(|e| e.to_string())
    }
}

/// Handler for reading papers (PDF text extraction) with auto-detection
#[derive(Debug)]
pub struct ReadPaperHandler {
    pub sources: Arc<Vec<Arc<dyn crate::sources::Source>>>,
}

#[async_trait::async_trait]
impl ToolHandler for ReadPaperHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let paper_id = args
            .get("paper_id")
            .and_then(|v| v.as_str())
            .ok_or("Missing 'paper_id' parameter")?;

        let source_override = args.get("source").and_then(|v| v.as_str());

        // Find the appropriate source
        let source = self.find_source(paper_id, source_override)?;

        let request = crate::models::ReadRequest::new(paper_id, "./downloads");

        let result = source.read(&request).await.map_err(|e| e.to_string())?;

        serde_json::to_value(result).map_err(|e| e.to_string())
    }
}

/// Handler for getting citations
#[derive(Debug)]
pub struct GetCitationsHandler {
    pub sources: Arc<Vec<Arc<dyn crate::sources::Source>>>,
}

#[async_trait::async_trait]
impl ToolHandler for GetCitationsHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let paper_id = args
            .get("paper_id")
            .and_then(|v| v.as_str())
            .ok_or("Missing 'paper_id' parameter")?;

        let source_override = args.get("source").and_then(|v| v.as_str());

        let max_results = args
            .get("max_results")
            .and_then(|v| v.as_u64())
            .unwrap_or(20) as usize;

        // Default to Semantic Scholar if not specified
        let source_id = source_override.unwrap_or("semantic");

        let source = self
            .sources
            .iter()
            .find(|s| s.id() == source_id)
            .ok_or_else(|| format!("Source '{}' not found", source_id))?;

        if !source.supports_citations() {
            return Err(format!("Source '{}' does not support citations", source_id));
        }

        let request = crate::models::CitationRequest::new(paper_id).max_results(max_results);

        let response = source
            .get_citations(&request)
            .await
            .map_err(|e| e.to_string())?;

        serde_json::to_value(response).map_err(|e| e.to_string())
    }
}

/// Handler for getting references
#[derive(Debug)]
pub struct GetReferencesHandler {
    pub sources: Arc<Vec<Arc<dyn crate::sources::Source>>>,
}

#[async_trait::async_trait]
impl ToolHandler for GetReferencesHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let paper_id = args
            .get("paper_id")
            .and_then(|v| v.as_str())
            .ok_or("Missing 'paper_id' parameter")?;

        let source_override = args.get("source").and_then(|v| v.as_str());

        let max_results = args
            .get("max_results")
            .and_then(|v| v.as_u64())
            .unwrap_or(20) as usize;

        // Default to Semantic Scholar if not specified
        let source_id = source_override.unwrap_or("semantic");

        let source = self
            .sources
            .iter()
            .find(|s| s.id() == source_id)
            .ok_or_else(|| format!("Source '{}' not found", source_id))?;

        if !source.supports_citations() {
            return Err(format!(
                "Source '{}' does not support references",
                source_id
            ));
        }

        let request = crate::models::CitationRequest::new(paper_id).max_results(max_results);

        let response = source
            .get_references(&request)
            .await
            .map_err(|e| e.to_string())?;

        serde_json::to_value(response).map_err(|e| e.to_string())
    }
}

/// Handler for DOI lookup
#[derive(Debug)]
pub struct LookupByDoiHandler {
    pub sources: Arc<Vec<Arc<dyn crate::sources::Source>>>,
}

#[async_trait::async_trait]
impl ToolHandler for LookupByDoiHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let doi = args
            .get("doi")
            .and_then(|v| v.as_str())
            .ok_or("Missing 'doi' parameter")?;

        let source_filter = args.get("source").and_then(|v| v.as_str());

        // Try each source that supports DOI lookup
        for source in self.sources.iter() {
            // Filter by source if specified
            if let Some(filter) = source_filter {
                if source.id() != filter {
                    continue;
                }
            }

            // Skip sources that don't support DOI lookup
            if !source.supports_doi_lookup() {
                continue;
            }

            match source.get_by_doi(doi).await {
                Ok(paper) => {
                    return serde_json::to_value(paper).map_err(|e| e.to_string());
                }
                Err(e) => {
                    tracing::debug!("DOI lookup failed for {}: {}", source.id(), e);
                }
            }
        }

        Err(format!("Paper with DOI '{}' not found", doi))
    }
}

/// Handler for deduplicating papers
#[derive(Debug)]
pub struct DeduplicatePapersHandler;

#[async_trait::async_trait]
impl ToolHandler for DeduplicatePapersHandler {
    async fn execute(&self, args: Value) -> Result<Value, String> {
        let papers: Vec<crate::models::Paper> = serde_json::from_value(
            args.get("papers")
                .ok_or("Missing 'papers' parameter")?
                .clone(),
        )
        .map_err(|e| format!("Invalid papers array: {}", e))?;

        let strategy_str = args
            .get("strategy")
            .and_then(|v| v.as_str())
            .unwrap_or("first");

        let strategy = match strategy_str {
            "last" => crate::utils::DuplicateStrategy::Last,
            "mark" => crate::utils::DuplicateStrategy::Mark,
            _ => crate::utils::DuplicateStrategy::First,
        };

        let deduped = crate::utils::deduplicate_papers(papers, strategy);

        serde_json::to_value(deduped).map_err(|e| e.to_string())
    }
}

// Helper trait for source auto-detection
impl GetPaperHandler {
    fn find_source(
        &self,
        paper_id: &str,
        source_override: Option<&str>,
    ) -> Result<Arc<dyn crate::sources::Source>, String> {
        // If source is explicitly specified, use it
        if let Some(source_id) = source_override {
            return self
                .sources
                .iter()
                .find(|s| s.id() == source_id)
                .cloned()
                .ok_or_else(|| format!("Source '{}' not found", source_id));
        }

        // Use shared auto-detection logic
        auto_detect_source(&self.sources, paper_id)
    }
}

impl DownloadPaperHandler {
    fn find_source(
        &self,
        paper_id: &str,
        source_override: Option<&str>,
    ) -> Result<Arc<dyn crate::sources::Source>, String> {
        // If source is explicitly specified, use it
        if let Some(source_id) = source_override {
            return self
                .sources
                .iter()
                .find(|s| s.id() == source_id)
                .cloned()
                .ok_or_else(|| format!("Source '{}' not found", source_id));
        }

        // Use shared auto-detection logic
        auto_detect_source(&self.sources, paper_id)
    }
}

impl ReadPaperHandler {
    fn find_source(
        &self,
        paper_id: &str,
        source_override: Option<&str>,
    ) -> Result<Arc<dyn crate::sources::Source>, String> {
        // If source is explicitly specified, use it
        if let Some(source_id) = source_override {
            return self
                .sources
                .iter()
                .find(|s| s.id() == source_id)
                .cloned()
                .ok_or_else(|| format!("Source '{}' not found", source_id));
        }

        // Use shared auto-detection logic
        auto_detect_source(&self.sources, paper_id)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::models::{CitationRequest, DownloadRequest, ReadRequest};
    use crate::sources::{Source, SourceCapabilities};
    use std::sync::Arc;

    // Mock source for testing
    #[derive(Debug)]
    struct MockSource {
        id: String,
        capabilities: SourceCapabilities,
    }

    impl MockSource {
        fn new(id: &str, capabilities: SourceCapabilities) -> Self {
            Self {
                id: id.to_string(),
                capabilities,
            }
        }
    }

    #[async_trait::async_trait]
    impl Source for MockSource {
        fn id(&self) -> &str {
            &self.id
        }

        fn name(&self) -> &str {
            &self.id
        }

        fn capabilities(&self) -> SourceCapabilities {
            self.capabilities
        }

        async fn search(
            &self,
            _query: &crate::models::SearchQuery,
        ) -> Result<crate::models::SearchResponse, crate::sources::SourceError> {
            unimplemented!()
        }

        async fn download(
            &self,
            _request: &DownloadRequest,
        ) -> Result<crate::models::DownloadResult, crate::sources::SourceError> {
            unimplemented!()
        }

        async fn read(
            &self,
            _request: &ReadRequest,
        ) -> Result<crate::models::ReadResult, crate::sources::SourceError> {
            unimplemented!()
        }

        async fn get_citations(
            &self,
            _request: &CitationRequest,
        ) -> Result<crate::models::SearchResponse, crate::sources::SourceError> {
            unimplemented!()
        }

        async fn get_references(
            &self,
            _request: &CitationRequest,
        ) -> Result<crate::models::SearchResponse, crate::sources::SourceError> {
            unimplemented!()
        }

        fn supports_doi_lookup(&self) -> bool {
            self.capabilities.contains(SourceCapabilities::DOI_LOOKUP)
        }

        async fn get_by_doi(
            &self,
            _doi: &str,
        ) -> Result<crate::models::Paper, crate::sources::SourceError> {
            unimplemented!()
        }

        async fn get_related(
            &self,
            _request: &CitationRequest,
        ) -> Result<crate::models::SearchResponse, crate::sources::SourceError> {
            unimplemented!()
        }

        fn validate_id(&self, _id: &str) -> Result<(), crate::sources::SourceError> {
            Ok(())
        }
    }

    fn make_test_sources() -> Vec<Arc<dyn Source>> {
        vec![
            Arc::new(MockSource::new("arxiv", SourceCapabilities::all())),
            Arc::new(MockSource::new("semantic", SourceCapabilities::all())),
            Arc::new(MockSource::new("pmc", SourceCapabilities::all())),
            Arc::new(MockSource::new("hal", SourceCapabilities::all())),
            Arc::new(MockSource::new("iacr", SourceCapabilities::all())),
        ]
    }

    #[test]
    fn test_auto_detect_arxiv_numeric() {
        let sources = make_test_sources();
        let result = auto_detect_source(&Arc::new(sources), "2301.12345");
        assert!(result.is_ok());
        assert_eq!(result.unwrap().id(), "arxiv");
    }

    #[test]
    fn test_auto_detect_arxiv_prefix() {
        let sources = make_test_sources();
        let result = auto_detect_source(&Arc::new(sources), "arxiv:2301.12345");
        assert!(result.is_ok());
        assert_eq!(result.unwrap().id(), "arxiv");
    }

    #[test]
    fn test_auto_detect_pmc() {
        let sources = make_test_sources();
        let result = auto_detect_source(&Arc::new(sources), "PMC12345");
        assert!(result.is_ok());
        assert_eq!(result.unwrap().id(), "pmc");
    }

    #[test]
    fn test_auto_detect_pmc_lowercase() {
        let sources = make_test_sources();
        let result = auto_detect_source(&Arc::new(sources), "pmc12345");
        assert!(result.is_ok());
        assert_eq!(result.unwrap().id(), "pmc");
    }

    #[test]
    fn test_auto_detect_hal() {
        let sources = make_test_sources();
        let result = auto_detect_source(&Arc::new(sources), "hal-12345");
        assert!(result.is_ok());
        assert_eq!(result.unwrap().id(), "hal");
    }

    #[test]
    fn test_auto_detect_iacr() {
        let sources = make_test_sources();
        let result = auto_detect_source(&Arc::new(sources), "2023/1234");
        assert!(result.is_ok());
        assert_eq!(result.unwrap().id(), "iacr");
    }

    #[test]
    fn test_auto_detect_doi() {
        // DOI format without slash-like pattern would go to semantic
        // 10.xxxx/xxxxx has a slash, so it matches iacr pattern first
        let sources = make_test_sources();
        let result = auto_detect_source(&Arc::new(sources), "10.12345/testpaper");
        assert!(result.is_ok());
        // Due to slash detection, iacr matches first (single slash pattern)
        assert_eq!(result.unwrap().id(), "iacr");
    }

    #[test]
    fn test_auto_detect_doi_no_slash() {
        // DOI without slash - arxiv is checked first in fallback
        let sources = make_test_sources();
        let result = auto_detect_source(&Arc::new(sources), "10.12345.67890");
        assert!(result.is_ok());
        // Fallback order is arxiv first, then semantic
        assert_eq!(result.unwrap().id(), "arxiv");
    }

    #[test]
    fn test_auto_detect_fallback() {
        let sources = make_test_sources();
        // Unknown format should fall back to arxiv
        let result = auto_detect_source(&Arc::new(sources), "unknown-id-123");
        assert!(result.is_ok());
        assert_eq!(result.unwrap().id(), "arxiv");
    }

    #[test]
    fn test_auto_detect_source_not_available() {
        // Create sources without arxiv, and without semantic
        let sources: Vec<Arc<dyn Source>> =
            vec![Arc::new(MockSource::new("pmc", SourceCapabilities::SEARCH))];
        // PMC ID should work, but unknown ID should fail since no fallback
        let result = auto_detect_source(&Arc::new(sources), "unknown-id");
        assert!(result.is_err());
    }

    #[test]
    fn test_paper_id_upper_start_basic() {
        assert!(paper_id_upper_start("PMC12345", "PMC"));
        assert!(paper_id_upper_start("pmc12345", "PMC"));
        assert!(paper_id_upper_start("Pmc12345", "PMC"));
        assert!(!paper_id_upper_start("ABC12345", "PMC"));
        assert!(!paper_id_upper_start("PM", "PMC")); // Too short
    }

    #[test]
    fn test_paper_id_upper_start_edge_cases() {
        assert!(!paper_id_upper_start("", "PMC"));
        assert!(!paper_id_upper_start("PM", "PMC"));
    }
}