Skip to content

Tests for the watched paths store#16

Merged
vittorius merged 9 commits intomainfrom
tests-for-path-store
Jan 17, 2026
Merged

Tests for the watched paths store#16
vittorius merged 9 commits intomainfrom
tests-for-path-store

Conversation

@vittorius
Copy link
Owner

@vittorius vittorius commented Jan 9, 2026

  • Added tests for "watcher" methods in PathStore
  • Extracted WatchedSet type into a separate module (tests TBA)

PR train:

@vittorius vittorius force-pushed the tests-for-path-store branch 2 times, most recently from a51f8c5 to 83b511b Compare January 13, 2026 10:48
{
"label": "cargo nextest tests",
"command": "cargo nextest run tests",
"label": "cargo nextest tests (crate root)",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, wasn't working properly

// "NEXTEST_SUCCESS_OUTPUT": "immediate"
},
},
{
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turned out to be redundant

use crate::watching::WatchedSet;

#[derive(Debug)]
pub struct PathStore {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed from Store

@vittorius vittorius force-pushed the tests-for-path-store branch from 83b511b to fffc384 Compare January 15, 2026 00:17
@vittorius vittorius marked this pull request as ready for review January 15, 2026 00:21
@vittorius vittorius force-pushed the tests-for-path-store branch from fffc384 to a0c329a Compare January 15, 2026 14:00
Copy link

@bloodfeast bloodfeast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple notes, overall good job!

"event did not provide the path of the modified file"
))?;

let body = fs::read_to_string(&path).with_context(|| "Could not read the modified file")?;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.fs::read_to_string is synchronous and will block the async runtime's thread.

  • You could use tokio::fs::read_to_string and make the function async
async fn process_and_sync(client: &dyn Client, event: &Event) -> Result<()> {
  let path = event.paths.first()
      .ok_or_else(|| anyhow!("event missing path"))?;
  
  let body = tokio::fs::read_to_string(path).await
      .with_context(|| format!("failed to read {}", path.display()))?;
  
  let data = LocalFileData::new(path.clone(), body)?;
  client.sync_file(data).await
}
  1. adding the path here would be useful context
.with_context(|| format!("Could not read modified file: {}", path.display()))?;


impl PathStore {
pub fn new(client: Arc<dyn Client>) -> Result<Self> {
let event_handler = Box::new(move |event| {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could filter here before the async overhead

        let EventKind::Modify(ModifyKind::Data(_)) = event.kind else {
            return Box::pin(async {}) as Pin<Box<dyn Future<Output = ()> + Send>>;
        };

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to keep this logic in the process_event function

@vittorius vittorius merged commit 29728ec into main Jan 17, 2026
8 checks passed
@vittorius vittorius deleted the tests-for-path-store branch January 17, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants