relate-executor 1.5.0

In-memory graph and Cypher physical executor
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
//! Local CSV capability (ADR-0081, ADR-0108). A local target is opened and
//! then verified against the physical identity recorded at validation, so a
//! concurrent filesystem mutation between inspection and open cannot
//! substitute the file that is read.
//!
//! The module splits into [`policy`] (the validated source capability: the
//! local-file root and the http(s) target validation, each behind its own
//! read), [`remote`] (the host-supplied fetcher hook and the source
//! classification, ADR-0723), [`errors`] (the wording both share) and
//! [`parse`] (RFC 4180 record/field splitting and row values); this root
//! keeps the per-statement [`CsvReader`] memoization that composes them.

mod errors;
mod parse;
mod policy;
mod remote;

use std::borrow::Cow;
#[cfg(test)]
use std::cell::Cell;
use std::cell::RefCell;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;

use relate_core::Result;

pub(crate) use parse::{field_terminator_char, record_value, split_csv_line, RecordCursor};
pub use policy::CsvPolicy;
#[cfg(test)]
pub(crate) use policy::DEFAULT_MAX_BYTES;
pub use remote::{CsvRemote, RemoteFailure};

/// CIP-202's canned `artists.csv` is a dialect fixture, not a local-file
/// capability or a network fetch: the TCK/CIP scenarios name this exact URL
/// and expect these rows, while every other remote source stays denied by
/// policy (ADR-0081).
const CIP202_ARTISTS_URL: &str = "https://data.neo4j.com/bands/artists.csv";
const CIP202_ARTISTS_CSV: &str = "1,ABBA,1992\n2,Roxette,1986\n3,Europe,1979\n";

/// The hidden row column `LOAD CSV` stamps on every row it builds: the
/// 1-based record number inside its source, the header record counting as
/// line 1 under `WITH HEADERS`. `linenumber()` reads it back. A `__` name,
/// so it is an internal key — never projected, never listed by `*`.
pub(crate) const LINE_KEY: &str = "__load_csv_line";

/// The hidden row column carrying the source the clause read, spelled as
/// the query spelled it (never the resolved host path, ADR-0081).
/// `file()` reads it back.
pub(crate) const FILE_KEY: &str = "__load_csv_file";

/// One memo per statement, shared across its nested clauses even when the
/// execution view is reused for subsequent statements.
pub(crate) struct CsvReader<'a> {
    policy: &'a CsvPolicy,
    source_memo: RefCell<HashMap<String, Arc<str>>>,
    canonical_memo: RefCell<HashMap<PathBuf, Arc<str>>>,
    #[cfg(test)]
    reads: Cell<usize>,
}

impl<'a> CsvReader<'a> {
    pub(crate) fn new(policy: &'a CsvPolicy) -> Self {
        let reader = Self {
            policy,
            source_memo: RefCell::new(HashMap::new()),
            canonical_memo: RefCell::new(HashMap::new()),
            #[cfg(test)]
            reads: Cell::new(0),
        };
        reader.seed_canned_sources();
        reader
    }

    /// Start a top-level statement on this view. Internal seeded execution
    /// keeps both memos intact for the duration of that statement.
    pub(crate) fn begin_statement(&self) {
        self.source_memo.borrow_mut().clear();
        self.canonical_memo.borrow_mut().clear();
        self.seed_canned_sources();
    }

    /// Seed the canned dialect fixtures into the source memo, so `load`
    /// keeps one uniform flow — memo hit, then the confinement policy —
    /// with no fixture check bolted onto the read path. The canned data is
    /// immutable and never a physical read.
    fn seed_canned_sources(&self) {
        // Under the same canonical rule `load` keys by, so the two producers
        // of a memo key cannot drift.
        let key = remote::RemoteUrl::parse(CIP202_ARTISTS_URL)
            .expect("the fixture URL is an http(s) URL")
            .canonical();
        self.source_memo
            .borrow_mut()
            .insert(key, Arc::from(CIP202_ARTISTS_CSV));
    }

    pub(crate) fn load(&self, source: &str) -> Result<Arc<str>> {
        // One identity for the memo and the dispatch: an http(s) source is
        // its canonical URL (fragment dropped, scheme and host lowercased), so
        // every spelling of one URL shares one entry — and the seeded fixture
        // stays authoritative for all of them, never reaching the host's
        // fetcher.
        let remote = remote::RemoteUrl::parse(source);
        let key = match &remote {
            Some(url) => Cow::Owned(url.canonical()),
            None => Cow::Borrowed(source),
        };
        if let Some(text) = self.source_memo.borrow().get(key.as_ref()) {
            return Ok(text.clone());
        }
        let text = match &remote {
            Some(url) => self.load_remote(url, &key)?,
            None => self.load_local(source)?,
        };
        self.source_memo
            .borrow_mut()
            .insert(key.into_owned(), text.clone());
        Ok(text)
    }

    /// An http(s) source through the host's fetcher (ADR-0723): one request
    /// per distinct URL per statement, memoized by [`Self::load`].
    fn load_remote(&self, url: &remote::RemoteUrl<'_>, canonical: &str) -> Result<Arc<str>> {
        let target = self.policy.remote_target(url, canonical)?;
        #[cfg(test)]
        self.reads.set(self.reads.get() + 1);
        Ok(self.policy.read_remote(&target)?.into())
    }

    /// A local file under the policy's root, memoized by canonical target.
    fn load_local(&self, source: &str) -> Result<Arc<str>> {
        let target = self.policy.target(source)?;
        let cached = self.canonical_memo.borrow().get(&target.path).cloned();
        if let Some(text) = cached {
            return Ok(text);
        }
        #[cfg(test)]
        self.reads.set(self.reads.get() + 1);
        let text: Arc<str> = self.policy.read(&target)?.into();
        self.canonical_memo
            .borrow_mut()
            .insert(target.path, text.clone());
        Ok(text)
    }

    /// The physical reads this reader performed — asserted by the
    /// engine-level `LOAD CSV` tests in `exec::load_csv::tests`.
    #[cfg(test)]
    pub(crate) fn read_count(&self) -> usize {
        self.reads.get()
    }
}

/// A fresh temporary directory per test; cleanup is drop-based
/// (`TempDir`), so no test needs a remove_dir_all tail. Shared by the
/// reader/policy tests here and the engine-level `LOAD CSV` tests in
/// `exec::load_csv::tests`.
#[cfg(test)]
pub(crate) fn test_root() -> tempfile::TempDir {
    tempfile::tempdir().unwrap()
}

/// The `file:///…` URL spelling of an absolute path, without introducing a
/// URL authority or Windows backslashes. Same audience as [`test_root`].
#[cfg(test)]
pub(crate) fn local_file_url(path: &std::path::Path) -> String {
    let path = path.to_str().unwrap().replace('\\', "/");
    format!("file:///{}", path.trim_start_matches('/'))
}

#[cfg(test)]
mod tests {
    use super::errors::{
        byte_limit_exceeded, credentials_refused, malformed_url, not_enabled, not_utf8,
    };
    use super::policy::unavailable;
    use super::*;
    use std::fs;
    use std::sync::Mutex;

    /// A fetcher with a canned answer that records every request, so a test
    /// can assert both what the engine returned and what it sent.
    #[derive(Debug)]
    struct StubRemote {
        answer: std::result::Result<Vec<u8>, RemoteFailure>,
        calls: Mutex<Vec<(String, u64)>>,
    }

    impl StubRemote {
        fn serving(body: &[u8]) -> Arc<Self> {
            Self::answering(Ok(body.to_vec()))
        }

        fn answering(answer: std::result::Result<Vec<u8>, RemoteFailure>) -> Arc<Self> {
            Arc::new(Self {
                answer,
                calls: Mutex::new(Vec::new()),
            })
        }

        fn calls(&self) -> Vec<(String, u64)> {
            self.calls.lock().unwrap().clone()
        }
    }

    impl CsvRemote for StubRemote {
        fn fetch(&self, url: &str, max_bytes: u64) -> std::result::Result<Vec<u8>, RemoteFailure> {
            self.calls.lock().unwrap().push((url.to_owned(), max_bytes));
            self.answer.clone()
        }
    }

    #[test]
    fn reader_denies_remote_urls_with_or_without_root() {
        let dir = test_root();
        let root = dir.path();
        for policy in [
            CsvPolicy::default(),
            CsvPolicy::new(Some(root.to_path_buf()), None).unwrap(),
        ] {
            let reader = CsvReader::new(&policy);
            // The CIP-202 canned fixture is the one remote URL that loads.
            assert_eq!(
                reader
                    .load("https://data.neo4j.com/bands/artists.csv")
                    .unwrap()
                    .as_ref(),
                "1,ABBA,1992\n2,Roxette,1986\n3,Europe,1979\n"
            );
            // Every other http(s) source is denied, with the message that
            // says remote sources are off — not the generic file error.
            for source in [
                "https://other.example/data.csv",
                "http://other.example/data.csv",
                "HTTPS://other.example/data.csv",
                "https://data.neo4j.com/bands/other.csv",
            ] {
                assert_eq!(reader.load(source).unwrap_err(), not_enabled(), "{source}");
            }
            // Other schemes keep the generic local-file denial.
            for source in ["ftp://other.example/data.csv", "s3://bucket/data.csv"] {
                assert_eq!(reader.load(source).unwrap_err(), unavailable(), "{source}");
            }
            assert_eq!(reader.read_count(), 0);
        }
    }

    #[test]
    fn a_remote_source_is_read_through_the_host_fetcher() {
        let remote = StubRemote::serving(b"a,b\n1,2\n");
        let policy = CsvPolicy::default().with_remote(remote.clone());
        let reader = CsvReader::new(&policy);

        let text = reader
            .load("https://example.org/rows.csv?sig=1#top")
            .unwrap();
        assert_eq!(text.as_ref(), "a,b\n1,2\n");
        // The fragment is dropped, the query kept, and the policy's byte
        // limit is what the host is told to enforce.
        assert_eq!(
            remote.calls(),
            vec![(
                "https://example.org/rows.csv?sig=1".to_owned(),
                DEFAULT_MAX_BYTES
            )]
        );
        assert_eq!(reader.read_count(), 1);
    }

    /// Every spelling of one URL is one source: fragment variants share the
    /// memo entry, so one statement fetches the resource once.
    #[test]
    fn spellings_of_one_url_share_one_fetch() {
        let remote = StubRemote::serving(b"x\n");
        let policy = CsvPolicy::default().with_remote(remote.clone());
        let reader = CsvReader::new(&policy);
        let first = reader.load("https://example.org/rows.csv#a").unwrap();
        let second = reader.load("https://example.org/rows.csv#b").unwrap();
        let bare = reader.load("https://example.org/rows.csv").unwrap();
        assert!(Arc::ptr_eq(&first, &second) && Arc::ptr_eq(&first, &bare));
        assert_eq!(remote.calls().len(), 1);
    }

    /// The scheme and host are case-insensitive: their spellings are one
    /// source and the host receives the canonical URL. The path is
    /// case-sensitive, so a different path case is a different source.
    #[test]
    fn scheme_and_host_case_make_no_second_source() {
        let remote = StubRemote::serving(b"x\n");
        let policy = CsvPolicy::default().with_remote(remote.clone());
        let reader = CsvReader::new(&policy);
        let first = reader.load("HTTPS://Example.ORG/rows.csv?sig=1#a").unwrap();
        let second = reader.load("https://example.org/rows.csv?sig=1").unwrap();
        assert!(Arc::ptr_eq(&first, &second));
        assert_eq!(
            remote.calls(),
            vec![(
                "https://example.org/rows.csv?sig=1".to_owned(),
                DEFAULT_MAX_BYTES
            )]
        );
        reader.load("https://example.org/ROWS.csv?sig=1").unwrap();
        assert_eq!(remote.calls().len(), 2);
    }

    #[test]
    fn a_remote_source_is_fetched_once_per_statement() {
        let remote = StubRemote::serving(b"x\n");
        let policy = CsvPolicy::default().with_remote(remote.clone());
        let reader = CsvReader::new(&policy);

        let first = reader.load("https://example.org/rows.csv").unwrap();
        let second = reader.load("https://example.org/rows.csv").unwrap();
        assert!(Arc::ptr_eq(&first, &second));
        assert_eq!(remote.calls().len(), 1);

        // A new statement gets a new memo: the snapshot is per statement.
        reader.begin_statement();
        reader.load("https://example.org/rows.csv").unwrap();
        assert_eq!(remote.calls().len(), 2);
    }

    #[test]
    fn every_host_failure_is_worded_by_the_engine_without_the_url() {
        for failure in [
            RemoteFailure::Status(404),
            RemoteFailure::Status(503),
            RemoteFailure::ExceededLimit,
            RemoteFailure::Timeout,
            RemoteFailure::Redirect,
            RemoteFailure::Unreachable,
        ] {
            let policy = CsvPolicy::default().with_remote(StubRemote::answering(Err(failure)));
            let reader = CsvReader::new(&policy);
            let error = reader
                .load("https://secret-host.example/private/rows.csv")
                .unwrap_err();
            assert_eq!(error, failure.into_error());
            let text = format!("{error:?}");
            assert!(!text.contains("secret-host"), "{text}");
            assert!(!text.contains("private"), "{text}");
        }
    }

    #[test]
    fn the_byte_limit_binds_even_a_host_that_ignores_it() {
        let policy = CsvPolicy::new(None, Some(4))
            .unwrap()
            .with_remote(StubRemote::serving(b"12345"));
        let error = CsvReader::new(&policy)
            .load("https://example.org/big.csv")
            .unwrap_err();
        assert_eq!(error, byte_limit_exceeded());

        // Exactly at the limit is accepted.
        let policy = CsvPolicy::new(None, Some(5))
            .unwrap()
            .with_remote(StubRemote::serving(b"12345"));
        let text = CsvReader::new(&policy)
            .load("https://example.org/ok.csv")
            .unwrap();
        assert_eq!(text.as_ref(), "12345");
    }

    #[test]
    fn a_remote_body_that_is_not_utf8_is_refused() {
        let policy = CsvPolicy::default().with_remote(StubRemote::serving(&[0xff, 0xfe, b'\n']));
        let error = CsvReader::new(&policy)
            .load("https://example.org/binary.csv")
            .unwrap_err();
        assert_eq!(error, not_utf8());
    }

    #[test]
    fn credentials_in_a_url_are_refused_before_any_request() {
        let remote = StubRemote::serving(b"x\n");
        let policy = CsvPolicy::default().with_remote(remote.clone());
        let reader = CsvReader::new(&policy);
        for source in [
            "https://user:secret@example.org/rows.csv",
            "http://user@example.org/rows.csv",
        ] {
            assert_eq!(
                reader.load(source).unwrap_err(),
                credentials_refused(),
                "{source}"
            );
        }
        assert!(remote.calls().is_empty());
        assert_eq!(reader.read_count(), 0);
    }

    #[test]
    fn a_malformed_url_never_reaches_the_host() {
        let remote = StubRemote::serving(b"x\n");
        let policy = CsvPolicy::default().with_remote(remote.clone());
        let reader = CsvReader::new(&policy);
        for source in [
            "https://example.org/a\r\nX-Injected: 1",
            "https://example.org/a\nb.csv",
            "https://example.org/a b.csv",
            "http://example.org/\0",
        ] {
            assert_eq!(
                reader.load(source).unwrap_err(),
                malformed_url(),
                "{source:?}"
            );
        }
        assert!(remote.calls().is_empty());
        assert_eq!(reader.read_count(), 0);
    }

    #[test]
    fn enabling_remote_sources_neither_enables_local_files_nor_reaches_the_hook() {
        let remote = StubRemote::serving(b"remote\n");
        let policy = CsvPolicy::default().with_remote(remote.clone());
        let reader = CsvReader::new(&policy);
        // No root: every local spelling stays denied, and none is sent out.
        for source in [
            "rows.csv",
            "dir/rows.csv",
            "file:///tmp/rows.csv",
            "ftp://example.org/rows.csv",
        ] {
            assert_eq!(reader.load(source).unwrap_err(), unavailable(), "{source}");
        }
        assert!(remote.calls().is_empty());
    }

    #[test]
    fn a_root_and_a_remote_are_independent_capabilities() {
        let dir = test_root();
        fs::write(dir.path().join("rows.csv"), "local\n").unwrap();
        let remote = StubRemote::serving(b"remote\n");
        let policy = CsvPolicy::new(Some(dir.path().to_path_buf()), None)
            .unwrap()
            .with_remote(remote.clone());
        let reader = CsvReader::new(&policy);

        assert_eq!(reader.load("rows.csv").unwrap().as_ref(), "local\n");
        assert_eq!(
            reader
                .load("https://example.org/rows.csv")
                .unwrap()
                .as_ref(),
            "remote\n"
        );
        assert_eq!(remote.calls().len(), 1);
    }

    #[test]
    fn the_canned_fixture_is_never_fetched_even_when_remote_is_enabled() {
        let remote = StubRemote::serving(b"from the network\n");
        let policy = CsvPolicy::default().with_remote(remote.clone());
        let reader = CsvReader::new(&policy);
        // Every spelling of the fixture URL is the fixture: neither a fragment
        // nor the case of the scheme or host may route it past the seed to a
        // live request.
        for source in [
            "https://data.neo4j.com/bands/artists.csv",
            "https://data.neo4j.com/bands/artists.csv#top",
            "HTTPS://data.neo4j.com/bands/artists.csv",
            "https://DATA.NEO4J.COM/bands/artists.csv",
            "Https://Data.Neo4j.Com/bands/artists.csv#x",
        ] {
            assert_eq!(
                reader.load(source).unwrap().as_ref(),
                "1,ABBA,1992\n2,Roxette,1986\n3,Europe,1979\n",
                "{source}"
            );
        }
        assert!(remote.calls().is_empty());

        // And with no fetcher the fragment spelling still serves the fixture.
        let denied = CsvPolicy::default();
        let text = CsvReader::new(&denied)
            .load("https://data.neo4j.com/bands/artists.csv#top")
            .unwrap();
        assert_eq!(
            text.as_ref(),
            "1,ABBA,1992\n2,Roxette,1986\n3,Europe,1979\n"
        );
    }

    #[test]
    fn source_memo_survives_removal_within_view() {
        let dir = test_root();
        let root = dir.path();
        let path = root.join("rows.csv");
        fs::write(&path, "original\n").unwrap();
        let policy = CsvPolicy::new(Some(root.to_path_buf()), None).unwrap();
        let reader = CsvReader::new(&policy);

        let first = reader.load("rows.csv").unwrap();
        fs::remove_file(path).unwrap();
        let second = reader.load("rows.csv").unwrap();
        assert_eq!(second.as_ref(), "original\n");
        assert!(Arc::ptr_eq(&first, &second));
        assert_eq!(reader.read_count(), 1);

        let fresh = CsvReader::new(&policy);
        assert_eq!(fresh.load("rows.csv").unwrap_err(), unavailable());
        assert_eq!(fresh.read_count(), 0);
    }

    #[cfg(unix)]
    #[test]
    fn source_memo_survives_in_root_symlink_retarget() {
        use std::os::unix::fs::symlink;

        let dir = test_root();
        let root = dir.path();
        fs::write(root.join("first.csv"), "first\n").unwrap();
        fs::write(root.join("second.csv"), "second\n").unwrap();
        let alias = root.join("alias.csv");
        symlink("first.csv", &alias).unwrap();
        let policy = CsvPolicy::new(Some(root.to_path_buf()), None).unwrap();
        let reader = CsvReader::new(&policy);

        let first = reader.load("alias.csv").unwrap();
        fs::remove_file(&alias).unwrap();
        symlink("second.csv", &alias).unwrap();
        let second = reader.load("alias.csv").unwrap();
        assert_eq!(second.as_ref(), "first\n");
        assert!(Arc::ptr_eq(&first, &second));
        assert_eq!(reader.read_count(), 1);

        let fresh = CsvReader::new(&policy);
        assert_eq!(fresh.load("alias.csv").unwrap().as_ref(), "second\n");
        assert_eq!(fresh.read_count(), 1);
    }

    #[cfg(unix)]
    #[test]
    fn source_memo_survives_escape_retarget_but_fresh_view_denies() {
        use std::os::unix::fs::symlink;

        let dir = test_root();
        let root = dir.path();
        let outside_dir = test_root();
        let outside = outside_dir.path();
        fs::write(root.join("inside.csv"), "inside\n").unwrap();
        fs::write(outside.join("outside.csv"), "outside\n").unwrap();
        let alias = root.join("alias.csv");
        symlink("inside.csv", &alias).unwrap();
        let policy = CsvPolicy::new(Some(root.to_path_buf()), None).unwrap();
        let reader = CsvReader::new(&policy);

        let first = reader.load("alias.csv").unwrap();
        fs::remove_file(&alias).unwrap();
        symlink(outside.join("outside.csv"), &alias).unwrap();
        let second = reader.load("alias.csv").unwrap();
        assert!(Arc::ptr_eq(&first, &second));
        assert_eq!(second.as_ref(), "inside\n");
        assert_eq!(reader.read_count(), 1);

        let fresh = CsvReader::new(&policy);
        assert_eq!(fresh.load("alias.csv").unwrap_err(), unavailable());
        assert_eq!(fresh.read_count(), 0);
    }

    #[cfg(unix)]
    #[test]
    fn distinct_sources_share_canonical_memo_and_arc() {
        use std::os::unix::fs::symlink;

        let dir = test_root();
        let root = dir.path();
        fs::write(root.join("rows.csv"), "shared\n").unwrap();
        symlink("rows.csv", root.join("alias.csv")).unwrap();
        let policy = CsvPolicy::new(Some(root.to_path_buf()), None).unwrap();
        let reader = CsvReader::new(&policy);

        let first = reader.load("rows.csv").unwrap();
        let alias = reader.load("alias.csv").unwrap();
        let url = reader
            .load(&local_file_url(&root.join("rows.csv")))
            .unwrap();
        assert!(Arc::ptr_eq(&first, &alias));
        assert!(Arc::ptr_eq(&first, &url));
        assert_eq!(reader.read_count(), 1);
    }

    #[test]
    fn failed_source_is_retryable_after_creation() {
        let dir = test_root();
        let root = dir.path();
        let policy = CsvPolicy::new(Some(root.to_path_buf()), None).unwrap();
        let reader = CsvReader::new(&policy);

        assert_eq!(reader.load("later.csv").unwrap_err(), unavailable());
        assert_eq!(reader.read_count(), 0);
        fs::write(root.join("later.csv"), "created\n").unwrap();
        assert_eq!(reader.load("later.csv").unwrap().as_ref(), "created\n");
        assert_eq!(reader.read_count(), 1);
    }
}