seihou-cli 0.16.0.1 → 0.16.0.2
raw patch · 8 files changed
+262/−16 lines, 8 filesdep ~seihou-corePVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependency ranges changed: seihou-core
API changes (from Hackage documentation)
+ Seihou.CLI.Update: LegacyTargetIsDependency :: Text -> [ParentVars] -> [Text] -> UpdateError
+ Seihou.CLI.Update: LegacyValuesNeedChoice :: [(VarName, Text)] -> [VarError] -> UpdateError
+ Seihou.CLI.Update: explainAmbiguousLegacyValues :: Manifest -> [UpdateWarning] -> UpdateError -> UpdateError
+ Seihou.CLI.Update: legacySavedValues :: Manifest -> [(ModuleInstance, Module, FilePath)] -> (SavedInstanceValues, [UpdateWarning])
+ Seihou.CLI.Update.Types: LegacyTargetIsDependency :: Text -> [ParentVars] -> [Text] -> UpdateError
+ Seihou.CLI.Update.Types: LegacyValuesNeedChoice :: [(VarName, Text)] -> [VarError] -> UpdateError
Files
- data/upgrade-prompt.md +14/−0
- help/update.md +6/−2
- seihou-cli.cabal +4/−4
- src/Seihou/CLI/Update.hs +66/−6
- src/Seihou/CLI/Update/Render.hs +26/−2
- src/Seihou/CLI/Update/Types.hs +9/−0
- test/Seihou/CLI/UpdateRenderSpec.hs +22/−1
- test/Seihou/CLI/UpdateSpec.hs +115/−1
data/upgrade-prompt.md view
@@ -116,6 +116,20 @@ root alongside newer applications: update fetches its saved remote and includes matching recorded dependencies in the normal preview. Later updates can name any target. +### legacy_value_ambiguous+The legacy manifest holds a value for a required variable, but another module+may have written it, so it was not reused. The message shows that value. Never+pass it back on your own: show the user the value and the module being updated,+ask which value this application needs, then rerun with `--var KEY=VALUE`.++### legacy_target_is_dependency+The legacy manifest records `{{module}}` only as a dependency of another module,+so updating it alone would record a second application owning the same files.+Update the application the message names (the module or recipe that depends on+`{{module}}`) instead; that upgrades the dependency with its binding. If the+message names none, read `.seihou/manifest.json` `modules` for the unbound root+that pulls `{{module}}` in, and ask the user before choosing.+ ### target_not_found `{{module}}` is not a recorded target. The message lists the ones that are. Ask the user which one they meant; do not guess.
help/update.md view
@@ -169,8 +169,12 @@ A manifest without recorded applications needs one explicit TARGET for its first update. That successful run seeds application identity, saved inputs,- ownership, generated baselines, and command receipts. Ambiguous legacy values- are reported rather than guessed.+ ownership, generated baselines, and command receipts. Name a root: a module+ the legacy manifest records only as a dependency is refused+ (legacy_target_is_dependency) with the application to update instead. A+ dependency binding wins over the flat legacy values; a value another module+ may have written is not reused but resolved again, and without a terminal+ legacy_value_ambiguous shows the held value and the --var to pass. SEE ALSO
seihou-cli.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: seihou-cli-version: 0.16.0.1+version: 0.16.0.2 synopsis: CLI for Seihou project scaffolding description: Command-line interface for Seihou, a composable project scaffolding@@ -166,7 +166,7 @@ generic-lens >=2.2 && <3, lens >=5.2 && <6, process >=1.6 && <2,- seihou-core ^>=0.16.0.1,+ seihou-core ^>=0.16.0.2, shikumi ^>=0.5.1.0, streamly-core >=0.3 && <0.5, temporary >=1.3 && <2,@@ -261,7 +261,7 @@ optparse-applicative >=0.18 && <1, process >=1.6 && <2, seihou-cli-internal,- seihou-core ^>=0.16.0.1,+ seihou-core ^>=0.16.0.2, temporary >=1.3 && <2, text >=2.0 && <3, time >=1.12 && <2,@@ -373,7 +373,7 @@ lens >=5.2 && <6, process >=1.6 && <2, seihou-cli-internal,- seihou-core ^>=0.16.0.1,+ seihou-core ^>=0.16.0.2, shikumi ^>=0.5.1.0, streamly-core >=0.3 && <0.5, tasty >=1.4 && <2,
src/Seihou/CLI/Update.hs view
@@ -16,6 +16,8 @@ applyProjectUpdate, withProjectUpdate, isUpdateNoOp,+ legacySavedValues,+ explainAmbiguousLegacyValues, ) where @@ -822,6 +824,11 @@ seedLegacyApplication :: UpdateRequest -> FilePath -> FilePath -> FilePath -> Manifest -> UTCTime -> Text -> IO (Either UpdateError ([AppliedComposition], [UpdateWarning], Maybe StagedSelection)) seedLegacyApplication request session projectRoot installed manifest now requested = case roots of+ -- Recorded only as some module's dependency: seeding it from the installed+ -- copy would add a second, unbound root owning the same files (BUG-7).+ [] | not (null dependencyBindings) -> do+ owners <- legacyDependencyOwners projectRoot manifest requested+ pure (Left (LegacyTargetIsDependency requested dependencyBindings owners)) [] -> fmap (fmap (\(apps, warnings) -> (apps, warnings, Nothing))) (seedInstalledLegacyApplication request projectRoot manifest now requested) (target, origin, version) : _ -> do let provisional = AppliedComposition (mkApplicationId target []) target origin version [] (Just (deriveNamespace (ModuleName requested))) Nothing [] Map.empty [] Nothing Nothing now@@ -842,7 +849,7 @@ namespace = deriveNamespace primary resolved <- resolveApplicationValues request namespace "" saved (artifactRecipeInputs expansion Nothing) overrides modulesInOrder case resolved of- Left err -> pure (Left err)+ Left err -> pure (Left (explainAmbiguousLegacyValues manifest legacyWarnings err)) Right (recipeValues, values) -> do origined <- traverse (withInstanceOrigin projectRoot catalog) modulesInOrder let recorded = buildAppliedComposition target origin version [] (Just namespace) Nothing origined values now & #recipeInputs .~ recordedRecipeInputs target recipeValues & #instances %~ map (restoreLegacyVersion manifest)@@ -854,7 +861,33 @@ roots = [(AppliedModuleTarget (applied ^. #name), applied ^. #origin, applied ^. #moduleVersion) | applied <- manifest ^. #modules, applied ^. #name == ModuleName requested, applied ^. #parentVars == emptyParentVars] <> [(AppliedRecipeTarget (recipe ^. #name), recipe ^. #origin, recipe ^. #recipeVersion) | recipe <- maybeToList (manifest ^. #recipe), recipe ^. #name == RecipeName requested]+ dependencyBindings = nubOrd [applied ^. #parentVars | applied <- manifest ^. #modules, applied ^. #name == ModuleName requested] +-- | The legacy roots (unbound module records and the recorded recipe) whose+-- installed composition includes the requested module. Best effort: a root+-- that is not installed here, or does not load, is left out.+legacyDependencyOwners :: FilePath -> Manifest -> Text -> IO [Text]+legacyDependencyOwners projectRoot manifest requested = do+ searchPaths <- defaultSearchPaths+ catMaybes <$> forM candidates (\candidate -> fmap (\includes -> if includes then Just candidate else Nothing) (includesRequested searchPaths candidate))+ where+ candidates =+ nubOrd+ ( [applied ^. #name . #unModuleName | applied <- manifest ^. #modules, applied ^. #parentVars == emptyParentVars, applied ^. #name /= ModuleName requested]+ <> [recipe ^. #name . #unRecipeName | recipe <- maybeToList (manifest ^. #recipe)]+ )+ includesRequested searchPaths candidate = do+ discovered <- discoverRunnable searchPaths (ModuleName candidate)+ loaded <- case discovered of+ Right (RunnableModule modul _) -> loadComposition searchPaths (modul ^. #name) []+ Right (RunnableRecipe recipe dir) -> do+ expanded <- loadRecipeChain projectRoot searchPaths recipe dir+ case expanded of+ Left err -> pure (Left err)+ Right expansion -> loadComposition searchPaths (expansion ^. #primary) (drop 1 (map (^. #dependency . #module_) (expansion ^. #members)))+ _ -> pure (Right [])+ pure (either (const False) (any (\(instanceId, _, _) -> instanceId ^. #module_ == ModuleName requested)) loaded)+ seedInstalledLegacyApplication :: UpdateRequest -> FilePath -> Manifest -> UTCTime -> Text -> IO (Either UpdateError ([AppliedComposition], [UpdateWarning])) seedInstalledLegacyApplication request projectRoot manifest now requested = do@@ -883,7 +916,7 @@ namespace = deriveNamespace primary resolved <- resolveApplicationValues request namespace "" saved (artifactRecipeInputs expansion Nothing) overrides modulesInOrder case resolved of- Left err -> pure (Left err)+ Left err -> pure (Left (explainAmbiguousLegacyValues manifest warnings err)) Right (recipeValues, resolvedValues) -> do targetOrigin <- detectArtifactOrigin projectRoot targetSource originedModules <- traverse (\(instanceId, modul, dir) -> (instanceId,modul,) <$> detectArtifactOrigin projectRoot dir) modulesInOrder@@ -906,21 +939,34 @@ where declarations = [(instanceId, declaration) | (instanceId, modul, _) <- modulesInOrder, declaration <- modul ^. #vars] counts = Map.fromListWith (+) [(declaration ^. #name, 1 :: Int) | (_, declaration) <- declarations]- reusable name = Map.lookup name counts == Just 1 || (sharedExport name && sameTypes name && not (any (Map.member name . (^. #parentVars . #unParentVars) . (\(instanceId, _, _) -> instanceId)) modulesInOrder))+ -- The flat legacy map is last-writer-wins across every module the+ -- project ever ran. A name some instance received through a dependency+ -- binding, in this composition or anywhere in the legacy records, was+ -- written by more than one instance, so the flat value cannot be+ -- attributed to any one of them.+ boundBy instanceId name = Map.member name (instanceId ^. #parentVars . #unParentVars)+ boundAnywhere name =+ any (\(instanceId, _, _) -> boundBy instanceId name) modulesInOrder+ || any (Map.member name . (^. #parentVars . #unParentVars)) (manifest ^. #modules)+ reusable name = not (boundAnywhere name) && (Map.lookup name counts == Just 1 || (sharedExport name && sameTypes name)) sharedExport name = any (\(_, modul, _) -> any (\export -> export ^. #var == name && maybe True (== name) (export ^. #alias)) (modul ^. #exports)) modulesInOrder sameTypes name = case [declaration ^. #type_ | (_, declaration) <- declarations, declaration ^. #name == name] of firstType : rest -> all (== firstType) rest; [] -> False+ -- A dependency binding is the instance's own value; the flat map must+ -- never outrank it, since a saved value beats a parent binding.+ unbound = [(instanceId, declaration) | (instanceId, declaration) <- declarations, not (boundBy instanceId (declaration ^. #name))] saved = Map.fromListWith Map.union [ (instanceId, Map.singleton (declaration ^. #name) value)- | (instanceId, declaration) <- declarations,+ | (instanceId, declaration) <- unbound, reusable (declaration ^. #name), Just value <- [Map.lookup (declaration ^. #name) (manifest ^. #vars)] ]+ -- Warn only where the flat value would otherwise have been used: an+ -- instance bound by its parent resolves to that binding regardless. ambiguous = [ AmbiguousLegacyValue name- | (name, count) <- Map.toAscList counts,- count > 1,+ | name <- Set.toAscList (Set.fromList [declaration ^. #name | (_, declaration) <- unbound]), not (reusable name), Map.member name (manifest ^. #vars) ]@@ -931,6 +977,20 @@ Map.notMember (declaration ^. #name) (manifest ^. #vars) ] warnings = ambiguous <> missing++-- | A required name left unresolved only because its legacy value was+-- ambiguous gets the legacy value beside the error, so the caller confirms+-- or replaces it rather than guessing; prompts are unavailable here.+explainAmbiguousLegacyValues :: Manifest -> [UpdateWarning] -> UpdateError -> UpdateError+explainAmbiguousLegacyValues manifest warnings = \case+ UpdateVariableErrors errors+ | not (null held) -> LegacyValuesNeedChoice held [e | e <- errors, not (isHeld e)]+ where+ ambiguous = Set.fromList [name | AmbiguousLegacyValue name <- warnings]+ held = nubOrd [(name, value) | MissingRequiredVar name <- errors, Set.member name ambiguous, Just value <- [Map.lookup name (manifest ^. #vars)]]+ isHeld (MissingRequiredVar name) = any ((== name) . fst) held+ isHeld _ = False+ err -> err restoreLegacyVersion :: Manifest -> AppliedInstanceState -> AppliedInstanceState restoreLegacyVersion manifest state =
src/Seihou/CLI/Update/Render.hs view
@@ -19,7 +19,7 @@ import Data.ByteString.Lazy (ByteString) import Data.Generics.Labels () import Data.Map.Strict qualified as Map-import Data.Maybe (fromMaybe, isNothing)+import Data.Maybe (fromMaybe, isNothing, mapMaybe) import Data.Set qualified as Set import Data.Text qualified as T import Seihou.CLI.ApplicationDisplay (applicationLabel, appliedTargetName, moduleNameText, parentVarsText)@@ -498,7 +498,7 @@ warningText (AmbiguousLegacyValue name) = "the legacy manifest value for " <> name ^. #unVarName- <> " is declared by more than one module, so it was not reused; it is resolved again"+ <> " may have been written by another module, so it was not reused; it is resolved again" warningText (MissingLegacyValue name) = "the legacy manifest has no value for required variable " <> name ^. #unVarName <> "; it is resolved again" warningText (MigrationCommandNotSimulated name command) =@@ -538,6 +538,8 @@ errorCode UpdateManifestUpgradeRequired {} = "manifest_upgrade_required" errorCode NoRecordedApplications = "no_recorded_applications" errorCode LegacyUpdateRequiresOneTarget = "legacy_update_requires_one_target"+errorCode LegacyTargetIsDependency {} = "legacy_target_is_dependency"+errorCode LegacyValuesNeedChoice {} = "legacy_value_ambiguous" errorCode UpdateTargetNotFound {} = "target_not_found" errorCode SharedPathRequiresApplications {} = "shared_path_requires_applications" errorCode SharedWriteEvidenceUnavailable {} = "shared_write_evidence_unavailable"@@ -590,6 +592,28 @@ errorMessage LegacyUpdateRequiresOneTarget = "This manifest predates recorded applications. Name exactly one target to update, and" <> " seihou records it as the first application."+errorMessage (LegacyTargetIsDependency target bindings owners) =+ "This manifest predates recorded applications and records "+ <> target+ <> " only as a dependency"+ <> boundAs+ <> ". Updating it alone would record a second, unbound application that owns the same files. "+ <> case owners of+ [] -> "Update the module or recipe that depends on it instead."+ _ -> "Update the application that depends on it instead: " <> T.intercalate ", " ["seihou update " <> owner | owner <- owners] <> "."+ where+ boundAs = case mapMaybe parentVarsText bindings of+ [] -> ""+ shown -> " " <> T.intercalate ", " shown+errorMessage (LegacyValuesNeedChoice held others) =+ "Pass "+ <> T.intercalate " " ["--var " <> name ^. #unVarName <> "=VALUE" | (name, _) <- held]+ <> ": this manifest predates recorded applications, and its legacy "+ <> T.intercalate "; " [name ^. #unVarName <> "=" <> value | (name, value) <- held]+ <> " may have been written by another module, so it was not reused. Confirm that value or choose the one this application needs."+ <> case others of+ [] -> ""+ _ -> " Also: " <> T.intercalate "; " (map formatVarError others) errorMessage (UpdateTargetNotFound target available) = "No recorded application matches '" <> target
src/Seihou/CLI/Update/Types.hs view
@@ -294,6 +294,15 @@ UpdateManifestUpgradeRequired FilePath ManifestSchemaVersion | NoRecordedApplications | LegacyUpdateRequiresOneTarget+ | -- | A legacy manifest records the named module only as a dependency+ -- (each record carries parent bindings), so seeding it would add a+ -- second, unbound root application. The recorded bindings, then the+ -- recorded roots whose installed composition includes the module.+ LegacyTargetIsDependency Text [ParentVars] [Text]+ | -- | Required inputs left unresolved because their legacy value may have+ -- been written by another module: each name with the value the legacy+ -- manifest holds, then any other variable errors.+ LegacyValuesNeedChoice [(VarName, Text)] [VarError] | UpdateTargetNotFound Text [Text] | -- | The path is known to require the ownership closure: selected -- owners, then the owners missing from the selection.
test/Seihou/CLI/UpdateRenderSpec.hs view
@@ -207,6 +207,8 @@ UpdateManifestUpgradeRequired ".seihou/manifest.json" (ManifestSchemaVersion 5), NoRecordedApplications, LegacyUpdateRequiresOneTarget,+ LegacyTargetIsDependency "exec-plan" [ParentVars (Map.singleton "skill.name" "exec-plan")] ["master-plan"],+ LegacyValuesNeedChoice [("skill.name", "release")] [], UpdateTargetNotFound "nope" ["alpha"], SharedPathRequiresApplications ".gitignore" Set.empty (Set.singleton skillRef), SharedWriteEvidenceUnavailable ".gitignore" [],@@ -228,6 +230,23 @@ ) failures + it "names the owner to update when a legacy target is only a dependency" $ do+ let binding = ParentVars (Map.singleton "skill.name" "exec-plan")+ rendered = renderUpdateHuman False (errorOutput (LegacyTargetIsDependency "exec-plan" [binding] ["master-plan"]))+ rendered `shouldSatisfy` T.isPrefixOf "Update failed [legacy_target_is_dependency]: "+ rendered `shouldSatisfy` T.isInfixOf "records exec-plan only as a dependency [skill.name=exec-plan]"+ rendered `shouldSatisfy` T.isInfixOf "instead: seihou update master-plan."+ renderUpdateHuman False (errorOutput (LegacyTargetIsDependency "exec-plan" [binding] []))+ `shouldSatisfy` T.isInfixOf "Update the module or recipe that depends on it instead."+ rendered `shouldNotSatisfy` leaksInternals++ it "leads an ambiguous legacy value with the --var remedy and shows the held value" $ do+ let rendered = renderUpdateHuman False (errorOutput (LegacyValuesNeedChoice [("skill.name", "release")] [MissingRequiredVar "other"]))+ rendered `shouldSatisfy` T.isPrefixOf "Update failed [legacy_value_ambiguous]: Pass --var skill.name=VALUE: "+ rendered `shouldSatisfy` T.isInfixOf "legacy skill.name=release may have been written by another module"+ rendered `shouldSatisfy` T.isInfixOf "Also: missing required variable: other"+ rendered `shouldNotSatisfy` leaksInternals+ it "keeps the machine error codes stable in JSON" $ mapM_ ( \(err, code) ->@@ -235,7 +254,9 @@ ) [ (SharedPathRequiresApplications ".gitignore" Set.empty (Set.singleton skillRef), "shared_path_requires_applications"), (SharedWriteEvidenceUnavailable ".gitignore" [], "shared_write_evidence_unavailable"),- (UpdateManifestUpgradeRequired "m" (ManifestSchemaVersion 5), "manifest_upgrade_required")+ (UpdateManifestUpgradeRequired "m" (ManifestSchemaVersion 5), "manifest_upgrade_required"),+ (LegacyTargetIsDependency "exec-plan" [] [], "legacy_target_is_dependency"),+ (LegacyValuesNeedChoice [] [], "legacy_value_ambiguous") ] it "shows a staged manifest preparation in the human and JSON plan" $ do
test/Seihou/CLI/UpdateSpec.hs view
@@ -26,7 +26,7 @@ import Data.Time (UTCTime (..), fromGregorian) import GHC.Generics (Generic) import Seihou.CLI.CommandExecution (CommandPolicy (..))-import Seihou.CLI.Update (PromptPolicy (..), UpdateRequest (..), UpdateSelection (..), applyProjectUpdate, isUpdateNoOp, withProjectUpdate)+import Seihou.CLI.Update (PromptPolicy (..), UpdateRequest (..), UpdateSelection (..), applyProjectUpdate, explainAmbiguousLegacyValues, isUpdateNoOp, legacySavedValues, withProjectUpdate) import Seihou.CLI.Update.Migrations (StagedMigrations (..), planAndStageMigrations) import Seihou.CLI.Update.Rebinding (alignPriorInstances) import Seihou.CLI.Update.Selection@@ -63,6 +63,62 @@ spec :: Spec spec = do+ describe "legacy saved values" $ do+ -- BUG-6: relay-pagination's legacy manifest, where the root link-skill+ -- last wrote skill.name=release into the flat map.+ let skillName = VarName "skill.name"+ intentions = VarName "intentions.enabled"+ bound value = ParentVars (Map.singleton skillName value)+ legacyManifest =+ (emptyManifest testTime)+ & #modules+ .~ [ AppliedModule "link-skill" (bound "master-plan") (LocalOrigin "link-skill") (Just "0.4.0") testTime Nothing,+ AppliedModule "link-skill" (bound "exec-plan") (LocalOrigin "link-skill") (Just "0.4.0") testTime Nothing,+ AppliedModule "exec-plan" (bound "exec-plan") (LocalOrigin "exec-plan") (Just "0.6.0") testTime Nothing,+ AppliedModule "master-plan" emptyParentVars (LocalOrigin "master-plan") (Just "0.6.0") testTime Nothing,+ AppliedModule "link-skill" emptyParentVars (LocalOrigin "link-skill") (Just "0.4.0") testTime Nothing+ ]+ & #vars+ .~ Map.fromList [(skillName, "release"), (intentions, "false"), (VarName "mp.skill.name", "master-plan")]+ execPlan = legacyModule "exec-plan" [legacyVar skillName, legacyVar intentions]+ masterPlan = legacyModule "master-plan" [legacyVar (VarName "mp.skill.name"), legacyVar intentions]+ linkSkill = legacyModule "link-skill" [legacyVar skillName]+ boundExecPlan = ModuleInstance "exec-plan" (bound "exec-plan")+ rootOf name = ModuleInstance name emptyParentVars+ savedFor instanceId = Map.findWithDefault Map.empty instanceId . fst++ it "never lets the flat map outrank a dependency binding" $ do+ let result = legacySavedValues legacyManifest [(rootOf "master-plan", masterPlan, ""), (boundExecPlan, execPlan, "")]+ Map.lookup skillName (savedFor boundExecPlan result) `shouldBe` Nothing+ Map.lookup (VarName "mp.skill.name") (savedFor (rootOf "master-plan") result) `shouldBe` Just "master-plan"+ -- exec-plan resolves to its binding, so skill.name is not reported.+ snd result `shouldBe` [AmbiguousLegacyValue intentions]++ it "treats a name bound anywhere in the legacy records as ambiguous" $ do+ let result = legacySavedValues legacyManifest [(rootOf "exec-plan", execPlan, "")]+ Map.lookup skillName (savedFor (rootOf "exec-plan") result) `shouldBe` Nothing+ Map.lookup intentions (savedFor (rootOf "exec-plan") result) `shouldBe` Just "false"+ snd result `shouldBe` [AmbiguousLegacyValue skillName]+ -- The root link-skill is resolved afresh too, rather than trusted.+ snd (legacySavedValues legacyManifest [(rootOf "link-skill", linkSkill, "")])+ `shouldBe` [AmbiguousLegacyValue skillName]++ it "names the held legacy value when an ambiguous required name stays unresolved" $ do+ -- A root link-skill cannot prompt without a terminal; the bare+ -- missing-variable error would leave the caller guessing.+ let (_, warnings) = legacySavedValues legacyManifest [(rootOf "link-skill", linkSkill, "")]+ unresolved = UpdateVariableErrors [MissingRequiredVar skillName, MissingRequiredVar (VarName "other")]+ explainAmbiguousLegacyValues legacyManifest warnings unresolved+ `shouldBe` LegacyValuesNeedChoice [(skillName, "release")] [MissingRequiredVar (VarName "other")]+ -- Without an ambiguity warning the error is left alone.+ explainAmbiguousLegacyValues legacyManifest [] unresolved `shouldBe` unresolved++ it "still reuses a value only the target's composition declares" $ do+ let manifest = legacyManifest & #modules .~ [] & #vars .~ Map.fromList [(skillName, "custom"), (intentions, "true")]+ result = legacySavedValues manifest [(rootOf "exec-plan", execPlan, "")]+ savedFor (rootOf "exec-plan") result `shouldBe` Map.fromList [(skillName, "custom"), (intentions, "true")]+ snd result `shouldBe` []+ describe "application selection" $ do it "matches every application containing a requested bare module" $ do let first = application (AppliedModuleTarget "one") [instanceState "shared"]@@ -507,6 +563,45 @@ other -> expectationFailure ("expected one legacy module instance, got " <> show other) other -> expectationFailure ("expected one seeded application, got " <> show other) + it "refuses a legacy target recorded only as a dependency and names its owner" $+ -- BUG-7: seeding exec-plan from its installed copy recorded a second,+ -- unbound root beside master-plan's bound instance.+ withSystemTempDirectory "seihou-update-legacy-dependency" $ \root -> do+ fixture <- prepareUpdateFixture root+ decoded <- manifestFromJSON <$> LBS.readFile (fixture ^. #manifestPath)+ let binding = ParentVars (Map.singleton "project.name" "bound")+ ownerDir = fixture ^. #xdgHome </> "seihou" </> "installed" </> "owner"+ ownerModule =+ T.replace+ ", dependencies = [] : List Text"+ ", dependencies = [{ module = \"demo\", vars = [{ name = \"project.name\", value = \"bound\" }] }]"+ (moduleDhall "owner" "1.0.0")+ legacy <- case decoded of+ Left err -> expectationFailure err >> pure (emptyManifest testTime)+ Right manifest ->+ pure+ ( withoutApplications manifest+ & #modules+ .~ [ AppliedModule "demo" binding (LocalOrigin "demo") (Just "1.0.0") testTime Nothing,+ AppliedModule "owner" emptyParentVars (LocalOrigin "owner") (Just "1.0.0") testTime Nothing,+ AppliedModule "unrelated" emptyParentVars (LocalOrigin "unrelated") (Just "1.0.0") testTime Nothing+ ]+ )+ LBS.writeFile (fixture ^. #manifestPath) (manifestToJSON legacy)+ createDirectoryIfMissing True ownerDir+ TIO.writeFile (ownerDir </> "module.dhall") ownerModule+ beforeManifest <- LBS.readFile (fixture ^. #manifestPath)+ let request = ((updateRequest False) & #selection .~ NamedUpdateTargets ["demo"])+ withSavedEnv "XDG_CONFIG_HOME" (Just (fixture ^. #xdgHome)) $+ withCurrentDirectory (fixture ^. #projectRoot) $ do+ result <- withProjectUpdate request $ \case+ Left err -> pure (Left err)+ Right plan -> applyProjectUpdate plan+ case result of+ Left err -> err `shouldBe` LegacyTargetIsDependency "demo" [binding] ["owner"]+ Right _ -> expectationFailure "expected the dependency-only legacy target to be refused"+ LBS.readFile (fixture ^. #manifestPath) `shouldReturn` beforeManifest+ it "rolls managed project and cache state back when a candidate command fails" $ withSystemTempDirectory "seihou-update-command-failure" $ \root -> do fixture <- prepareUpdateFixture root@@ -1216,6 +1311,25 @@ targetName = case target of AppliedModuleTarget name -> name ^. #unModuleName AppliedRecipeTarget name -> name ^. #unRecipeName++legacyModule :: ModuleName -> [VarDecl] -> Module+legacyModule name vars =+ Module+ { name,+ version = Nothing,+ description = Nothing,+ vars,+ exports = [],+ prompts = [],+ steps = [],+ commands = [],+ dependencies = [],+ removal = Nothing,+ migrations = []+ }++legacyVar :: VarName -> VarDecl+legacyVar name = VarDecl name VTText Nothing Nothing True Nothing instanceState :: ModuleName -> AppliedInstanceState instanceState name = instanceStateFrom name (LocalOrigin (name ^. #unModuleName))