| 1 | package skillwatch |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // ScanOnly exists so a caller can hold a real, closable service without a child |
| 9 | // process. It must behave like the degraded path the service already has: the |
| 10 | // subscription lives, no physical watch exists, and the root falls back to |
| 11 | // backoff scanning. |
| 12 | func TestScanOnlyServesSubscriptionsWithoutAPhysicalWatch(t *testing.T) { |
| 13 | svc := NewService(Options{ScanOnly: true, Stderr: io.Discard}) |
| 14 | defer svc.Close() |
| 15 | sub := svc.Subscribe(t.TempDir(), 2, countingScope, flatHash, func(string) {}) |
| 16 | defer sub.Release() |
| 17 | |
| 18 | diag := svc.Diagnostics() |
| 19 | if diag.LogicalSubscriptions != 1 { |
| 20 | t.Fatalf("logical subscriptions = %d, want 1", diag.LogicalSubscriptions) |
| 21 | } |
| 22 | if diag.PhysicalWatches != 0 { |
| 23 | t.Fatalf("physical watches = %d, want 0: scan-only must not register any", diag.PhysicalWatches) |
| 24 | } |
| 25 | if diag.DegradedRoots != 1 { |
| 26 | t.Fatalf("degraded roots = %d, want 1: the root must fall back to scanning", diag.DegradedRoots) |
| 27 | } |
| 28 | } |
| 29 |