Page: a changed file belongs to a session root

Job: explanation

Level: mid grug (level 2 of 6)

Source lines:

  • SageFs.Core/LiveTestFileRouting.fs:61#eitherOn
  • SageFs.Core/LiveTestWatcherCore.fs:187#isScratchName

a changed file belongs to a session root

mid grug (level 2 of 6)explanationteaches: session-roots, live-test-ownership

explanation

this page says why the code has this shape and what a reader must be careful of.

why this exists

Several sessions can be open at once, each with its own working directory. When a file changes, the watcher has to decide which sessions care. SageFs.Core/LiveTestFileRouting.fs:61#eitherOn combines activation rules, and SageFs.Core/LiveTestWatcherCore.fs:187#isScratchName keeps generated scratch files out of that decision.

source anchor: this line is in the file

run sed -n '61,72p' SageFs.Core/LiveTestFileRouting.fs

It prints:

  let eitherOn (first: LiveTestingActivation) (second: LiveTestingActivation) : LiveTestingActivation =
    match first, second with
    | LiveTestingActivation.Inactive, LiveTestingActivation.Inactive -> LiveTestingActivation.Inactive
    | LiveTestingActivation.Active, LiveTestingActivation.Active
    | LiveTestingActivation.Active, LiveTestingActivation.Inactive
    | LiveTestingActivation.Inactive, LiveTestingActivation.Active -> LiveTestingActivation.Active
  /// The sessions whose working directory is the most specific one containing `path`. Sessions
  /// that share that directory all own the path. A session with no working directory owns nothing.
  let owners (roots: SessionRoot list) (path: string) : SessionId list =
    let dirSessions =
      roots

The cited file SageFs.Core/LiveTestFileRouting.fs ships with this site at the same path. Run the command from the school folder, or open SageFs.Core/LiveTestFileRouting.fs.

what breaks

A watcher that treats every changed file as belonging to every session reruns unrelated tests. A watcher that uses the process working directory misses a session opened in another checkout.

where it fits

Repo paths resolve where files are. This module decides who owns a file after it changes.

try it

Run the grep above from this repository root. Then open two sessions in different folders and change one file. Only the session whose root contains that file should see its tests rerun.

reference: every connection to this page
where this fits

This is reference. The next page in the reading order is at the bottom of the page.

path order: repo paths are found at runtime

flowchart LR
  A0["repo paths are found at runtime"]
  H["you are here: a changed file belongs to a session root"]
  A0 --> H

grill: say it out loud, then tap

Grug asks. Say the answer out loud, then tap. Grug remembers what you miss and asks again in the pop quiz.

a badge says two things: the number is its level, the colour is the kind of answer it asks for. The six levels are level 1 of 6 recall a fact; level 2 of 6 recall a detail; level 3 of 6 trace a path; level 4 of 6 trace a longer path; level 5 of 6 predict or judge; level 6 of 6 judge a transfer. Colour and level are independent: a high-level question can still ask for a fact, and the colour tells you which it is.

level 2 of 6Q1 · Two sessions have different working directories and one file changes. Which session owns it?
try first, then show answer

1. The one whose root contains the file

why

Routing is by declared session root, so only the session whose directory contains the file should react.

level 1 of 6Q2 · Which session field defines the root used for routing?
try first, then show answer

WorkingDirectory

why

WorkingDirectory on a session root is the path the watcher compares against a changed file.

level 2 of 6Q3 · A scratch file changes under a watched directory. What happens?
try first, then show answer

3. It is classified as scratch and left out

why

Scratch names are classified before routing, so generated files do not start test runs.

level 1 of 6Q4 · Which function combines activation rules for routing?
try first, then show answer

eitherOn

why

eitherOn joins two activation rules before the route is decided.