packages feed

cachix 1.14.0 → 1.15.0

raw patch · 15 files changed

+357/−28 lines, 15 files

Files

CHANGELOG.md view
@@ -7,6 +7,17 @@  ## [Unreleased] +## [1.15.0] - 2026-11-16++### Added++- `cachix pins get CACHE PIN [--json]`: show pin metadata and its latest revision.++### Fixed++- daemon: report failed narinfo queries to waiting clients and continue processing later batches+- nix: evaluate package outputs without import from derivation+ ## [1.14.0] - 2026-11-05  ### Added
README.md view
@@ -1,1 +1,23 @@ https://github.com/cachix/cachix/blob/master/README.md++## Pin information++Get a pin's metadata and latest revision:++```sh+cachix pins get mycache 'mypin:1.0.0'+cachix pins get mycache 'mypin:1.0.0' --json+```++The JSON output contains the pin name, creation time, retention policy, and+`lastRevision`. The latest revision includes its store path, revision number,+creation time, artifacts, and `orphaned` status. An orphaned revision has no+store path metadata in the cache. Its store path lacks the name suffix and its+artifact links are unavailable.++Pin names are literal: a colon does not select a revision. Public caches allow+anonymous reads. Private caches require an authentication token with read access.+A missing pin produces a nonzero exit status.++The command uses the existing pin listing API and selects the exact pin name+locally. It does not require a server upgrade.
cachix.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.2 name:               cachix-version:            1.14.0+version:            1.15.0 synopsis:   Command-line client for Nix binary cache hosting https://cachix.org @@ -270,6 +270,7 @@     ClientSpec     CommandConfigSpec     CommandListSpec+    CommandPinSpec     Daemon.NarinfoQuerySpec     Daemon.PostBuildHookSpec     Daemon.ProtocolSpec
src/Cachix/Client.hs view
@@ -48,7 +48,8 @@     Doctor doctorOptions -> Command.doctor env doctorOptions     GenerateKeypair name -> Command.generateKeypair env name     Import pushOptions name uri -> Command.import' env pushOptions name uri-    Pin pingArgs -> Command.pin env pingArgs+    Pin pinArgs -> Command.pin env pinArgs+    PinGet pinArgs -> Command.getPin env pinArgs     Push (PushPaths opts name cliPaths) -> Command.push env opts name cliPaths     Push (PushWatchStore _ _) ->       throwIO $ DeprecatedCommand "DEPRECATED: cachix watch-store has replaced cachix push --watch-store."
src/Cachix/Client/Command.hs view
@@ -8,6 +8,7 @@     Import.import',     List.list,     Pin.pin,+    Pin.getPin,     Push.push,     Watch.watchExec,     Watch.watchExecDaemon,
src/Cachix/Client/Command/Pin.hs view
@@ -1,4 +1,4 @@-module Cachix.Client.Command.Pin (pin) where+module Cachix.Client.Command.Pin (pin, getPin) where  import Cachix.API qualified as API import Cachix.API.Error@@ -6,14 +6,19 @@ import Cachix.Client.Config qualified as Config import Cachix.Client.Env (Env (..)) import Cachix.Client.Exception (CachixException (..))-import Cachix.Client.OptionsParser (PinOptions (..))+import Cachix.Client.OptionsParser (PinGetOptions (..), PinOptions (..)) import Cachix.Client.Retry (retryClientM) import Cachix.Client.Servant+import Cachix.Types.Pin qualified as Pin import Cachix.Types.PinCreate qualified as PinCreate+import Cachix.Types.PinRevision qualified as PinRevision+import Data.Aeson qualified as Aeson+import Data.ByteString.Lazy.Char8 qualified as LBS import Data.Text qualified as T import Hercules.CNix.Store (storePathToPath, withStore) import Protolude hiding (toS) import Protolude.Conv+import Servant.Auth.Client (Token (..)) import System.Directory (doesFileExist)  pin :: Env -> PinOptions -> IO ()@@ -44,3 +49,33 @@       let artifactPath = storePath <> "/" <> fromMaybe artifact (T.stripPrefix "/" artifact)       exists <- doesFileExist (toS artifactPath)       unless exists $ throwIO $ ArtifactNotFound $ "Artifact " <> artifactPath <> " doesn't exist."++getPin :: Env -> PinGetOptions -> IO ()+getPin env opts = do+  token <- fromMaybe (Token "") <$> Config.getAuthTokenMaybe (config env)+  pins <- escalate =<< retryClientM (clientenv env) (listPins token (pinGetCacheName opts))+  result <- case find ((== pinGetName opts) . Pin.name) pins of+    Just info -> pure info+    Nothing -> throwIO $ PinNotFound $ "Pin " <> pinGetName opts <> " was not found in cache " <> pinGetCacheName opts <> "."+  if pinGetJson opts+    then LBS.putStrLn $ Aeson.encode result+    else putText $ renderPin result++renderPin :: Pin.Pin -> Text+renderPin info =+  T.intercalate "\n" $+    [ "Name: " <> Pin.name info,+      "Created: " <> show (Pin.createdOn info),+      "Retention: " <> renderKeep (Pin.keep info),+      "Store path: " <> PinRevision.storePath latest,+      "Revision: " <> show (PinRevision.revision latest),+      "Revision created: " <> show (PinRevision.createdOn latest),+      "Orphaned: " <> if PinRevision.orphaned latest then "yes" else "no"+    ]+      <> ["Artifact: " <> artifact | artifact <- PinRevision.artifacts latest]+  where+    latest = Pin.lastRevision info+    renderKeep = \case+      PinCreate.Days days -> "Revisions from the last " <> show days <> " days"+      PinCreate.Revisions count -> "Last " <> show count <> " revisions"+      PinCreate.Forever -> "Forever"
src/Cachix/Client/Exception.hs view
@@ -18,6 +18,7 @@   | NarHashMismatch Text   | DeprecatedCommand Text   | ArtifactNotFound Text+  | PinNotFound Text   | AccessDeniedBinaryCache Text   | BinaryCacheNotFound Text   | ImportUnsupportedHash Text@@ -34,6 +35,7 @@   displayException (NoInput s) = toS s   displayException (NoConfig s) = toS s   displayException (ArtifactNotFound s) = toS s+  displayException (PinNotFound s) = toS s   displayException (NoSigningKey s) = toS s   displayException (NetRcParseError s) = toS s   displayException (IncludeNotFound s) = toS s
src/Cachix/Client/OptionsParser.hs view
@@ -22,6 +22,7 @@      -- * Pin options     PinOptions (..),+    PinGetOptions (..),      -- * Doctor options     DoctorOptions (..),@@ -92,6 +93,7 @@   | Push PushArguments   | Import PushOptions Text URI   | Pin PinOptions+  | PinGet PinGetOptions   | WatchStore PushOptions Text   | WatchExec WatchExecMode PushOptions NarinfoQueryOptions Text Text [Text]   | Use BinaryCacheName InstallationMode.UseOptions@@ -115,6 +117,13 @@   }   deriving (Show) +data PinGetOptions = PinGetOptions+  { pinGetCacheName :: BinaryCacheName,+    pinGetName :: Text,+    pinGetJson :: Bool+  }+  deriving (Show)+ data PushOptions = PushOptions   { -- | The compression level to use.     compressionLevel :: Int,@@ -273,7 +282,8 @@         fold           [ commandGroup "Store path commands:",             hidden,-            command "pin" $ infoH pinCommand $ progDesc "Pin a store path to prevent it from being garbage collected"+            command "pin" (infoH pinCommand $ progDesc "Pin a store path to prevent it from being garbage collected"),+            command "pins" (infoH pinsCommand $ progDesc "Manage pins")           ]      daemonCommands =@@ -481,6 +491,18 @@  pinCommand :: Parser CachixCommand pinCommand = Pin <$> pinOptionsParser++pinsCommand :: Parser CachixCommand+pinsCommand =+  subparser $+    command "get" (infoH (PinGet <$> pinGetOptionsParser) $ progDesc "Get pin metadata and its latest revision")++pinGetOptionsParser :: Parser PinGetOptions+pinGetOptionsParser =+  PinGetOptions+    <$> cacheNameParser+    <*> strArgument (metavar "PIN-NAME")+    <*> switch (long "json" <> help "Output pin metadata as JSON")  pinOptionsParser :: Parser PinOptions pinOptionsParser =
src/Cachix/Client/Servant.hs view
@@ -5,6 +5,7 @@ module Cachix.Client.Servant   ( isErr,     cachixClient,+    listPins,     deployClientV1,     deployClientV2,     withResponseTimeout,@@ -14,12 +15,14 @@ import Cachix.API qualified as API import Cachix.API.Deploy.V1 qualified as API.Deploy.V1 import Cachix.API.Deploy.V2 qualified as API.Deploy.V2+import Cachix.API.Pins qualified as API.Pins import Cachix.Types.ContentTypes ()+import Cachix.Types.Pin qualified as Pin import Network.HTTP.Client qualified as HTTP import Network.HTTP.Types (Status) import Protolude import Servant.API.Generic-import Servant.Auth.Client ()+import Servant.Auth.Client (Token) import Servant.Client qualified import Servant.Client.Streaming import Servant.Conduit ()@@ -40,6 +43,9 @@  cachixClient :: API.BinaryCacheAPI (AsClientT ClientM) cachixClient = fromServant $ client (Proxy @API.API)++listPins :: Token -> Text -> ClientM [Pin.Pin]+listPins = client (Proxy @API.Pins.API)  deployClientV1 :: API.Deploy.V1.DeployAPI (AsClientT ClientM) deployClientV1 = fromServant $ client (Proxy @API.Deploy.V1.API)
src/Cachix/Daemon/NarinfoQuery.hs view
@@ -32,8 +32,10 @@ import Data.Time (NominalDiffTime, UTCTime, addUTCTime, diffUTCTime, getCurrentTime) import Hercules.CNix.Store (StorePath, getStorePathHash) import Katip qualified-import Protolude+import Protolude hiding (toS)+import Protolude.Conv (toS) import UnliftIO.Async qualified as Async+import UnliftIO.Exception qualified as Exception  -- | Type alias for the positive narinfo cache. -- Keys are store path hashes.@@ -107,7 +109,7 @@     -- | Handle to the processor thread     nqmProcessorThread :: !(MVar (Async ())),     -- | Callback to handle query responses-    nqmCallback :: !(requestId -> NarinfoResponse -> IO ()),+    nqmCallback :: !(requestId -> Either Text NarinfoResponse -> IO ()),     -- | Cache for path existence information     nqmCache :: !(TVar NarinfoCache),     -- | Cached current time for TTL calculations (updated periodically)@@ -117,7 +119,7 @@   }  -- | Create a new narinfo query manager-new :: (MonadIO m) => NarinfoQueryOptions -> (requestId -> NarinfoResponse -> IO ()) -> m (NarinfoQueryManager requestId)+new :: (MonadIO m) => NarinfoQueryOptions -> (requestId -> Either Text NarinfoResponse -> IO ()) -> m (NarinfoQueryManager requestId) new nqmConfig nqmCallback = liftIO $ do   nqmState <- newTVarIO initialState   nqmProcessorThread <- newEmptyMVar@@ -358,7 +360,31 @@   ([StorePath] -> m ([StorePath], [StorePath])) ->   ReadyBatch requestId ->   m ()-processReadyBatch manager@NarinfoQueryManager {nqmCallback} processBatch ReadyBatch {rbRequests, rbAllPaths, rbBatchStartTime} = do+processReadyBatch manager@NarinfoQueryManager {nqmCallback} processBatch readyBatch@ReadyBatch {rbRequests} = do+  -- Catch batch failures, not cancellation or exceptions from response callbacks.+  result <- Exception.tryAny $ queryMissingPaths manager processBatch readyBatch+  case result of+    Left err -> do+      let reason = "Failed to query missing paths: " <> toS (displayException err)+      Katip.katipAddContext (Katip.sl "error" (displayException err)) $+        Katip.logFM Katip.ErrorS "Failed to query missing paths"+      liftIO $ for_ rbRequests $ \NarinfoRequest {qrRequestId} ->+        nqmCallback qrRequestId (Left reason)+    Right missingPathsSet ->+      liftIO $ forM_ rbRequests $ \NarinfoRequest {qrRequestId, qrStorePaths} -> do+        let qrStorePathsSet = Set.fromList qrStorePaths+            missingPathsForRequest = qrStorePathsSet `Set.intersection` missingPathsSet+            response = NarinfoResponse qrStorePathsSet missingPathsForRequest+        nqmCallback qrRequestId (Right response)++-- | Query missing paths and update the positive cache.+queryMissingPaths ::+  (Katip.KatipContext m) =>+  NarinfoQueryManager requestId ->+  ([StorePath] -> m ([StorePath], [StorePath])) ->+  ReadyBatch requestId ->+  m (Set StorePath)+queryMissingPaths manager processBatch ReadyBatch {rbRequests, rbAllPaths, rbBatchStartTime} = do   -- Process the batch if we have paths to query   (allPathsInClosure, missingPaths) <-     if null rbAllPaths@@ -408,12 +434,4 @@       & Katip.katipAddContext (Katip.sl "count" (Set.size existingPathsSet))     updateCache manager existingPathsSet -  -- Respond to each request using the manager's callback-  liftIO $ forM_ rbRequests $ \NarinfoRequest {qrRequestId, qrStorePaths} -> do-    -- Find the missing paths for this requests from the batch-    let qrStorePathsSet = Set.fromList qrStorePaths-        missingPathsForRequest = qrStorePathsSet `Set.intersection` missingPathsSet-        response = NarinfoResponse qrStorePathsSet missingPathsForRequest--    -- Call the manager's callback with request ID and response-    nqmCallback qrRequestId response+  return missingPathsSet
src/Cachix/Daemon/PushManager.hs view
@@ -381,7 +381,9 @@   case task of     QueryMissingPaths pushId ->       runQueryMissingPathsTask pushParams pushId-    HandleMissingPathsResponse pushId batchResponse ->+    HandleMissingPathsResponse pushId (Left reason) ->+      failPushJob pushId reason+    HandleMissingPathsResponse pushId (Right batchResponse) ->       runHandleMissingPathsResponseTask pushParams pushId batchResponse     PushPath filePath ->       runPushPathTask pushParams filePath
src/Cachix/Daemon/Types/PushManager.hs view
@@ -38,7 +38,7 @@ -- Tasks are prioritized by their Ord instance data Task   = QueryMissingPaths Protocol.PushRequestId-  | HandleMissingPathsResponse Protocol.PushRequestId NarinfoQuery.NarinfoResponse+  | HandleMissingPathsResponse Protocol.PushRequestId (Either Text NarinfoQuery.NarinfoResponse)   | PushPath FilePath   deriving stock (Eq) 
+ test/CommandPinSpec.hs view
@@ -0,0 +1,110 @@+module CommandPinSpec (spec) where++import Cachix.Client.OptionsParser+import Cachix.Types.PinCreate (Keep (..))+import Data.Aeson qualified as Aeson+import Data.ByteString qualified as BS+import Network.Socket.ByteString qualified as Socket+import Protolude+import StalledServer (withServer)+import System.Environment (getEnvironment, withArgs)+import System.IO.Temp (withSystemTempDirectory)+import System.Process qualified as Process+import Test.Hspec++spec :: Spec+spec = do+  describe "pin command parsing" $ do+    it "preserves pin creation with artifacts and retention" $ do+      (_, command) <- withArgs ["pin", "mycache", "release", "/nix/store/example", "--artifact", "bin/tool", "--keep-days", "3"] getOpts+      case command of+        Pin opts -> do+          pinCacheName opts `shouldBe` "mycache"+          pinName opts `shouldBe` "release"+          pinStorePath opts `shouldBe` "/nix/store/example"+          pinArtifacts opts `shouldBe` ["bin/tool"]+          pinKeep opts `shouldBe` Just (Days 3)+        other -> expectationFailure $ "Expected pin creation, got " <> show other++    for_ ["get", "create"] $ \cacheName ->+      it ("preserves pin creation for a cache named " <> cacheName) $ do+        (_, command) <- withArgs ["pin", cacheName, "release", "/nix/store/example"] getOpts+        case command of+          Pin opts -> do+            pinCacheName opts `shouldBe` toS cacheName+            pinName opts `shouldBe` "release"+            pinStorePath opts `shouldBe` "/nix/store/example"+          other -> expectationFailure $ "Expected pin creation, got " <> show other++    it "parses a literal pin name containing a colon" $ do+      (_, command) <- withArgs ["pins", "get", "mycache", "mypin:1.0.0", "--json"] getOpts+      case command of+        PinGet opts -> do+          pinGetCacheName opts `shouldBe` "mycache"+          pinGetName opts `shouldBe` "mypin:1.0.0"+          pinGetJson opts `shouldBe` True+        other -> expectationFailure $ "Expected pin lookup, got " <> show other++  describe "pins get" $ do+    it "outputs a JSON object without requiring authentication for a public cache" $ do+      (code, output, _) <- runLookup "200 OK" pinList ["--json"]+      code `shouldBe` ExitSuccess+      (Aeson.eitherDecodeStrict $ encodeUtf8 (toS output :: Text) :: Either [Char] Aeson.Value) `shouldBe` Aeson.eitherDecodeStrict metadata++    it "shows metadata in readable output by default" $ do+      (code, output, _) <- runLookup "200 OK" pinList []+      code `shouldBe` ExitSuccess+      output `shouldContain` "Name: mypin:1.0.0"+      output `shouldContain` "Revision: 2"+      output `shouldContain` "Retention: Revisions from the last 3 days"+      output `shouldContain` "Artifact: bin/tool"++    it "exits unsuccessfully for a missing pin without JSON on stdout" $ do+      (code, output, errors) <- runLookup "200 OK" ("[" <> metadataFor "mypin:1.0.0-other" <> "]") ["--json"]+      code `shouldSatisfy` (/= ExitSuccess)+      output `shouldBe` ""+      errors `shouldContain` "Pin mypin:1.0.0 was not found in cache mycache."++    it "reports a missing pin when the cache has no pins" $ do+      (code, output, errors) <- runLookup "200 OK" "[]" ["--json"]+      code `shouldSatisfy` (/= ExitSuccess)+      output `shouldBe` ""+      errors `shouldContain` "Pin mypin:1.0.0 was not found in cache mycache."++    it "preserves authorization failures from the listing endpoint" $ do+      (code, output, errors) <- runLookup "403 Forbidden" "" ["--json"]+      code `shouldSatisfy` (/= ExitSuccess)+      output `shouldBe` ""+      errors `shouldContain` "403"+      errors `shouldNotContain` "was not found in cache"++pinList :: ByteString+pinList = "[" <> metadataFor "mypin:1.0.0-other" <> "," <> metadata <> "]"++metadata :: ByteString+metadata = metadataFor "mypin:1.0.0"++metadataFor :: ByteString -> ByteString+metadataFor name = "{\"name\":\"" <> name <> "\",\"createdOn\":\"2026-01-01T00:00:00Z\",\"keep\":{\"tag\":\"Days\",\"contents\":3},\"lastRevision\":{\"storePath\":\"/nix/store/example\",\"revision\":2,\"createdOn\":\"2026-01-02T00:00:00Z\",\"artifacts\":[\"bin/tool\"],\"orphaned\":false}}"++runLookup :: ByteString -> ByteString -> [Text] -> IO (ExitCode, [Char], [Char])+runLookup status body extra =+  withSystemTempDirectory "cachix-pin-get" $ \dir ->+    withServer respond $ \port _ -> do+      environment <- getEnvironment+      let overrides = [("XDG_CONFIG_HOME", dir), ("no_proxy", "127.0.0.1"), ("NO_PROXY", "127.0.0.1")]+          cleanEnvironment = filter (\(key, _) -> key `notElem` (["CACHIX_AUTH_TOKEN", "CACHIX_SIGNING_KEY"] <> map fst overrides)) environment+          args = ["--config", dir <> "/cachix.dhall", "--hostname", "http://127.0.0.1:" <> show port, "pins", "get", "mycache", "mypin:1.0.0"] <> map toS extra+      Process.readCreateProcessWithExitCode (Process.proc "cachix" args) {Process.env = Just $ overrides <> cleanEnvironment} ""+  where+    respond connection = do+      headers <- readHeaders connection ""+      let correctEndpoint = "GET /api/v1/cache/mycache/pin " `BS.isPrefixOf` headers+          responseStatus = if correctEndpoint then status else "404 Not Found"+          responseBody = if correctEndpoint then body else ""+      Socket.sendAll connection $ "HTTP/1.1 " <> responseStatus <> "\r\nContent-Type: application/json\r\nConnection: close\r\nContent-Length: " <> show (BS.length responseBody) <> "\r\n\r\n" <> responseBody+    readHeaders connection received+      | "\r\n\r\n" `BS.isInfixOf` received = pure received+      | otherwise = do+          chunk <- Socket.recv connection 4096+          if BS.null chunk then pure received else readHeaders connection (received <> chunk)
test/Daemon/NarinfoQuerySpec.hs view
@@ -11,7 +11,9 @@ import Hercules.CNix qualified as CNix import Hercules.CNix.Store (Store, StorePath, withStoreFromURI) import Katip qualified-import Protolude+import Protolude hiding (toS)+import Protolude.Conv (toS)+import System.IO.Error (userError) import Test.Hspec import UnliftIO.Async qualified as Async import UnliftIO.Timeout (timeout)@@ -32,7 +34,7 @@ -- Test data structure to track callback calls data CallbackCall requestId = CallbackCall   { ccRequestId :: requestId,-    ccResponse :: NarinfoResponse,+    ccResponse :: Either Text NarinfoResponse,     ccTimestamp :: UTCTime   }   deriving (Show, Eq)@@ -63,7 +65,7 @@ createMockCallback ::   TVar [CallbackCall requestId] ->   requestId ->-  NarinfoResponse ->+  Either Text NarinfoResponse ->   IO () createMockCallback callsVar requestId response = do   now <- getCurrentTime@@ -136,6 +138,84 @@   -- Initialize the CNix library   runIO CNix.init +  describe "Query failures" $ do+    it "responds to every request in a failed batch and processes later requests" $ withStoreFromURI "dummy://" $ \store -> do+      path1 <- mockStorePath store 1+      path2 <- mockStorePath store 2+      calls <- newTVarIO (0 :: Int)+      callbacks <- newTVarIO []+      let config = defaultNarinfoQueryOptions {nqoMaxWaitTime = 0}+          processBatch paths = do+            call <- atomically $ do+              modifyTVar' calls (+ 1)+              readTVar calls+            if call == 1+              then throwIO $ userError "query failed"+              else pure (paths, [])+      manager <- NarinfoQuery.new config (createMockCallback callbacks)+      -- Queue both requests before starting so they belong to the same batch.+      NarinfoQuery.submitRequest manager (1 :: Int) [path1]+      NarinfoQuery.submitRequest manager (2 :: Int) [path2]+      startQueryProcessorAsync manager processBatch+      flip finally (NarinfoQuery.stop manager) $ do+        waitForCallbacks callbacks 2+        failed <- reverse <$> readTVarIO callbacks+        map ccRequestId failed `shouldBe` [1, 2]+        for_ failed $ \callback ->+          case ccResponse callback of+            Left reason -> (toS reason :: [Char]) `shouldContain` "query failed"+            Right _ -> expectationFailure "Expected a failed query"+        NarinfoQuery.lookupCache manager path1 `shouldReturn` False+        NarinfoQuery.lookupCache manager path2 `shouldReturn` False+        NarinfoQuery.submitRequest manager (3 :: Int) [path1]+        waitForCallbacks callbacks 3+        readTVarIO calls `shouldReturn` 2+        responses <- readTVarIO callbacks+        map ccResponse (take 1 responses)+          `shouldBe` [Right (NarinfoQuery.NarinfoResponse (Set.singleton path1) Set.empty)]+        -- A cache-only request must still finish after the failed batch.+        NarinfoQuery.submitRequest manager (4 :: Int) [path1]+        waitForCallbacks callbacks 4+        readTVarIO calls `shouldReturn` 2+        completed <- reverse <$> readTVarIO callbacks+        map ccRequestId completed `shouldBe` [1, 2, 3, 4]++    it "processes requests queued while a failing query is in flight" $ withStoreFromURI "dummy://" $ \store -> do+      path1 <- mockStorePath store 1+      path2 <- mockStorePath store 2+      started <- newEmptyTMVarIO+      release <- newEmptyTMVarIO+      calls <- newTVarIO (0 :: Int)+      callbacks <- newTVarIO []+      let config = defaultNarinfoQueryOptions {nqoMaxWaitTime = 0}+          processBatch paths = do+            call <- atomically $ do+              modifyTVar' calls (+ 1)+              readTVar calls+            when (call == 1) $ do+              atomically $ putTMVar started ()+              atomically $ takeTMVar release+              throwIO $ userError "query failed"+            pure (paths, [])+      manager <- NarinfoQuery.new config (createMockCallback callbacks)+      startQueryProcessorAsync manager processBatch+      let cleanup = do+            atomically $ void $ tryPutTMVar release ()+            NarinfoQuery.stop manager+      flip finally cleanup $ do+        NarinfoQuery.submitRequest manager (1 :: Int) [path1]+        waitForSTM 5_000_000 (not <$> isEmptyTMVar started)+        NarinfoQuery.submitRequest manager (2 :: Int) [path2]+        atomically $ putTMVar release ()+        waitForCallbacks callbacks 2+        completed <- reverse <$> readTVarIO callbacks+        map ccRequestId completed `shouldBe` [1, 2]+        case map ccResponse completed of+          [Left reason, Right response] -> do+            (toS reason :: [Char]) `shouldContain` "query failed"+            response `shouldBe` NarinfoQuery.NarinfoResponse (Set.singleton path2) Set.empty+          _ -> expectationFailure "Expected a failed query followed by a successful query"+   describe "Batching" $ do     it "triggers batch when size threshold is reached" $ withStoreFromURI "dummy://" $ \store -> do       path1 <- mockStorePath store 1@@ -239,8 +319,8 @@         -- Second response should contain both paths (path1 from cache + path2 from batch)         callbacks <- readTVarIO tcCallbackCalls         let secondResponse = case head callbacks of-              Just (CallbackCall _ response _) -> response-              Nothing -> panic "Expected callback call"+              Just (CallbackCall _ (Right response) _) -> response+              _ -> panic "Expected successful callback"         NarinfoQuery.nrAllPaths secondResponse `shouldBe` Set.fromList [path1, path2]      it "distributes correct paths to each request" $ withStoreFromURI "dummy://" $ \store -> do@@ -271,8 +351,8 @@          -- Find responses by request ID         let findResponse rid = find (\(CallbackCall r _ _) -> r == rid) callbacks-        Just (CallbackCall _ response1 _) <- return $ findResponse 1-        Just (CallbackCall _ response2 _) <- return $ findResponse 2+        Just (CallbackCall _ (Right response1) _) <- return $ findResponse 1+        Just (CallbackCall _ (Right response2) _) <- return $ findResponse 2          -- Request 1 should get: existing=[1,3], missing=[2]         NarinfoQuery.nrAllPaths response1 `shouldBe` Set.fromList [path1, path2, path3]
test/Daemon/PushManagerSpec.hs view
@@ -151,6 +151,24 @@             }      describe "failing jobs" $ do+      it "notifies subscribers when a batched narinfo query fails" $ do+        events <- newTVarIO []+        withPushManagerOnEvent (recordEvents events) $ \pm -> do+          runPushManager pm $ do+            let request = Protocol.PushRequest {Protocol.storePaths = ["foo"], Protocol.subscribeToUpdates = True}+            Just pushId <- addPushJobFromRequest request+            handleTask $ HandleMissingPathsResponse pushId (Left "Failed to query missing paths")+            withPushJob pushId $ \pushJob ->+              liftIO $ PushJob.status pushJob `shouldBe` Failed+            count <- pendingJobCount+            liftIO $ count `shouldBe` 0++          messages <- map eventMessage . reverse <$> readTVarIO events+          messages+            `shouldBe` [ PushStorePathFailed "foo" "Failed to query missing paths",+                         PushFinished+                       ]+       it "notifies subscribers when a job fails before closure resolution" $ do         events <- newTVarIO []         withPushManagerOnEvent (recordEvents events) $ \pm -> do