fix(WP-0017/E4): Layer 3 error fixes — round 2 (18 files)

Fixes 46 compile errors across 18 controllers and views:
- BridgeResponse missing from explicit import lists (Widgets, RequirementCandidates,
  DecisionRecords, AgentDelegations) — dot-notation HasField resolution fails without
  the type in scope under DuplicateRecordFields
- unId not in IHP v1.5 — replaced all fmap (Id . unId) with fmap coerce
- respondWith not in IHP — replaced with plain redirectTo in 5 controllers
- [hubId] list param to sqlQuery — replaced with (Only hubId) tuple
- deleteWhere not in IHP — replaced with query/filterWhere/fetch/deleteRecords
- fill @'["label"] mismatch — field is label_ in generated types, not label
- PersistUUID/toUUID (persistent-style) — replaced with (Only id)
- intercalate + jsonArrayTexts ambiguity in GovernanceTemplates — hid Index import,
  removed local duplicates, added Data.Text (intercalate)
- Int16 not in scope in AntifragilityDashboard — changed to Int (score :: Int)
- typeArraySection type mismatch in HubCapabilityManifests/Edit — unified to [Text]
- renderForm arity mismatch — added action param to DecisionRecords/New.renderForm
- Missing qualified Data.Aeson import in AdaptiveThresholds
- Missing ?request::Request constraint in Api/V2/WidgetPatterns.renderJsonWithStatus

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-12 12:17:45 +00:00
parent c40f11d657
commit 3737845e02
18 changed files with 120 additions and 159 deletions

View File

@@ -9,6 +9,7 @@ import Generated.Types
import IHP.Prelude
import IHP.ControllerPrelude
import Data.Aeson (decode, encode, object, (.=))
import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as LBS
instance Controller WidgetPatternsController where
@@ -16,17 +17,18 @@ instance Controller WidgetPatternsController where
-- List all published patterns with adopter count
action WidgetPatternsAction = autoRefresh do
patterns <- sqlQuery
"SELECT wp.*, \
\ COUNT(pa.id) AS adopter_count, \
\ MAX(wpv.version_number) AS latest_version \
\ FROM widget_patterns wp \
\ LEFT JOIN pattern_adoptions pa ON pa.widget_pattern_id = wp.id \
\ LEFT JOIN widget_pattern_versions wpv ON wpv.widget_pattern_id = wp.id \
\ WHERE wp.is_published = TRUE \
\ GROUP BY wp.id \
\ ORDER BY adopter_count DESC, wp.name ASC"
()
basePatterns <- query @WidgetPattern
|> filterWhere (#isPublished, True)
|> orderByAsc #name
|> fetch
patterns <- mapM (\p -> do
adopterCount <- sqlQueryScalar
"SELECT COUNT(*) FROM pattern_adoptions WHERE widget_pattern_id = ?"
(Only p.id)
latestVersion <- sqlQueryScalar
"SELECT MAX(version_number) FROM widget_pattern_versions WHERE widget_pattern_id = ?"
(Only p.id)
pure (p, fromMaybe 0 adopterCount, latestVersion)) basePatterns
render IndexView { patterns }
-- Detail with version history and aggregate adoption stats (T07)
@@ -92,9 +94,9 @@ instance Controller WidgetPatternsController where
typeOwner <- sqlQuery
"SELECT owner_hub_id FROM widget_type_registry WHERE name = ?"
(Only pattern.widgetType)
let isCross = case (typeOwner :: [(Maybe (Id Hub))]) of
[Just ownerId] -> ownerId /= pattern.hubId
_ -> False
let isCross = case (typeOwner :: [Only (Maybe (Id Hub))]) of
[Only (Just ownerId)] -> ownerId /= pattern.hubId
_ -> False
pattern <- pattern |> set #isCrossHub isCross |> createRecord
setSuccessMessage "Pattern created"
redirectTo EditWidgetPatternAction { widgetPatternId = pattern.id }
@@ -199,17 +201,17 @@ instance Controller WidgetPatternsController where
-- Create a draft manifest amendment
let existingTypes = maybe [] (jsonArrayTexts . (.declaredWidgetTypes)) mManifest
let newTypes = existingTypes ++ [pattern.widgetType]
let newTypesJson = toJSON newTypes
let newTypesJson = A.toJSON newTypes
draft <- newRecord @HubCapabilityManifest
|> set #hubId hubId
|> set #status "draft"
|> set #declaredWidgetTypes newTypesJson
|> set #declaredEventTypes
(maybe (toJSON ([] :: [Text])) (.declaredEventTypes) mManifest)
(maybe (A.toJSON ([] :: [Text])) (.declaredEventTypes) mManifest)
|> set #declaredAnnotationCategories
(maybe (toJSON ([] :: [Text])) (.declaredAnnotationCategories) mManifest)
(maybe (A.toJSON ([] :: [Text])) (.declaredAnnotationCategories) mManifest)
|> set #declaredPolicyScopes
(maybe (toJSON ([] :: [Text])) (.declaredPolicyScopes) mManifest)
(maybe (A.toJSON ([] :: [Text])) (.declaredPolicyScopes) mManifest)
|> createRecord
setSuccessMessage "Pattern adopted. A manifest amendment draft has been created — please review and activate it."
redirectTo ShowHubCapabilityManifestAction { hubCapabilityManifestId = draft.id }
@@ -232,6 +234,3 @@ jsonArrayTexts val = case decode (encode val) of
Just (arr :: [Text]) -> arr
Nothing -> []
-- | Convert a list to a JSON Value.
toJSON :: [Text] -> Value
toJSON ts = Data.Aeson.toJSON ts