@voxgig/sdkgen 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/ExternalTarget.js +1 -1
  3. package/dist/cmp/ExternalTarget.js.map +1 -1
  4. package/dist/helpers/naming.d.ts +4 -1
  5. package/dist/helpers/naming.js +119 -5
  6. package/dist/helpers/naming.js.map +1 -1
  7. package/dist/helpers/opShape.js +72 -0
  8. package/dist/helpers/opShape.js.map +1 -1
  9. package/dist/helpers/packageMeta.d.ts +2 -1
  10. package/dist/helpers/packageMeta.js +57 -20
  11. package/dist/helpers/packageMeta.js.map +1 -1
  12. package/dist/sdkgen.d.ts +3 -3
  13. package/dist/sdkgen.js +61 -18
  14. package/dist/sdkgen.js.map +1 -1
  15. package/dist/testkit.d.ts +39 -0
  16. package/dist/testkit.js +663 -0
  17. package/dist/testkit.js.map +1 -0
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/package.json +32 -8
  20. package/project/.sdk/src/cmp/c/Test_c.ts +5 -7
  21. package/project/.sdk/src/cmp/clojure/Test_clojure.ts +3 -7
  22. package/project/.sdk/src/cmp/cpp/Test_cpp.ts +4 -7
  23. package/project/.sdk/src/cmp/csharp/Package_csharp.ts +1 -1
  24. package/project/.sdk/src/cmp/csharp/Test_csharp.ts +5 -7
  25. package/project/.sdk/src/cmp/dart/Test_dart.ts +3 -4
  26. package/project/.sdk/src/cmp/elixir/Package_elixir.ts +1 -1
  27. package/project/.sdk/src/cmp/elixir/Test_elixir.ts +5 -6
  28. package/project/.sdk/src/cmp/go/EntityTypes_go.ts +1 -1
  29. package/project/.sdk/src/cmp/go/Entity_go.ts +1 -1
  30. package/project/.sdk/src/cmp/go/Gitignore_go.ts +6 -0
  31. package/project/.sdk/src/cmp/go/Main_go.ts +2 -2
  32. package/project/.sdk/src/cmp/go/Package_go.ts +1 -1
  33. package/project/.sdk/src/cmp/go/ReadmeExamplesTest_go.ts +59 -6
  34. package/project/.sdk/src/cmp/go/ReadmeExplanation_go.ts +1 -1
  35. package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +1 -1
  36. package/project/.sdk/src/cmp/go/ReadmeInstall_go.ts +1 -1
  37. package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +1 -1
  38. package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +1 -1
  39. package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +1 -1
  40. package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +1 -1
  41. package/project/.sdk/src/cmp/go/Test_go.ts +6 -8
  42. package/project/.sdk/src/cmp/go-cli/Main_go-cli.ts +6 -2
  43. package/project/.sdk/src/cmp/go-mcp/Main_go-mcp.ts +6 -2
  44. package/project/.sdk/src/cmp/java/Test_java.ts +4 -7
  45. package/project/.sdk/src/cmp/js/Package_js.ts +1 -1
  46. package/project/.sdk/src/cmp/js/Test_js.ts +4 -7
  47. package/project/.sdk/src/cmp/kotlin/Test_kotlin.ts +4 -7
  48. package/project/.sdk/src/cmp/lean/Test_lean.ts +3 -3
  49. package/project/.sdk/src/cmp/lua/Package_lua.ts +2 -2
  50. package/project/.sdk/src/cmp/lua/Test_lua.ts +5 -7
  51. package/project/.sdk/src/cmp/ocaml/Test_ocaml.ts +3 -7
  52. package/project/.sdk/src/cmp/perl/Package_perl.ts +1 -1
  53. package/project/.sdk/src/cmp/perl/Test_perl.ts +5 -7
  54. package/project/.sdk/src/cmp/php/EntityTypes_php.ts +13 -2
  55. package/project/.sdk/src/cmp/php/Package_php.ts +2 -2
  56. package/project/.sdk/src/cmp/php/Test_php.ts +5 -7
  57. package/project/.sdk/src/cmp/py/Package_py.ts +2 -2
  58. package/project/.sdk/src/cmp/py/Test_py.ts +5 -7
  59. package/project/.sdk/src/cmp/py-data/Main_py-data.ts +14 -19
  60. package/project/.sdk/src/cmp/rb/Package_rb.ts +3 -3
  61. package/project/.sdk/src/cmp/rb/ReadmeInstall_rb.ts +1 -1
  62. package/project/.sdk/src/cmp/rb/Test_rb.ts +5 -7
  63. package/project/.sdk/src/cmp/rust/Test_rust.ts +5 -7
  64. package/project/.sdk/src/cmp/scala/Test_scala.ts +5 -2
  65. package/project/.sdk/src/cmp/seneca-provider/Gitignore_seneca-provider.ts +161 -0
  66. package/project/.sdk/src/cmp/seneca-provider/Main_seneca-provider.ts +20 -11
  67. package/project/.sdk/src/cmp/swift/Test_swift.ts +5 -7
  68. package/project/.sdk/src/cmp/ts/Package_ts.ts +1 -1
  69. package/project/.sdk/src/cmp/ts/Test_ts.ts +8 -7
  70. package/project/.sdk/src/cmp/zig/Test_zig.ts +3 -7
  71. package/project/.sdk/tm/c/utility/make_point.c +64 -3
  72. package/project/.sdk/tm/clojure/src/sdk/core.clj +49 -14
  73. package/project/.sdk/tm/cpp/utility/pipeline.hpp +55 -3
  74. package/project/.sdk/tm/csharp/feature/TestFeature.cs +36 -2
  75. package/project/.sdk/tm/csharp/utility/MakePoint.cs +65 -2
  76. package/project/.sdk/tm/dart/lib/feature/test/TestFeature.dart +34 -4
  77. package/project/.sdk/tm/dart/lib/utility/MakePointUtility.dart +48 -2
  78. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +70 -10
  79. package/project/.sdk/tm/go/feature/test_feature.go +34 -2
  80. package/project/.sdk/tm/go/utility/make_point.go +66 -2
  81. package/project/.sdk/tm/java/feature/TestFeature.java +42 -2
  82. package/project/.sdk/tm/java/utility/MakePoint.java +61 -2
  83. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +22 -3
  84. package/project/.sdk/tm/js/src/utility/MakePointUtility.js +72 -2
  85. package/project/.sdk/tm/kotlin/feature/TestFeature.kt +31 -2
  86. package/project/.sdk/tm/kotlin/utility/MakePoint.kt +58 -2
  87. package/project/.sdk/tm/lean/src/SdkUtility.lean +28 -0
  88. package/project/.sdk/tm/lua/utility/make_point.lua +65 -2
  89. package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -2
  90. package/project/.sdk/tm/perl/utility/make_point.pm +55 -2
  91. package/project/.sdk/tm/php/feature/TestFeature.php +30 -1
  92. package/project/.sdk/tm/php/utility/MakePoint.php +49 -1
  93. package/project/.sdk/tm/py/pkg/utility/make_point.py +56 -2
  94. package/project/.sdk/tm/rb/utility/make_point.rb +42 -2
  95. package/project/.sdk/tm/rust/utility/make_point.rs +69 -2
  96. package/project/.sdk/tm/scala/feature/TestFeature.scala +36 -1
  97. package/project/.sdk/tm/scala/utility/Make.scala +57 -3
  98. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +29 -1
  99. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +51 -2
  100. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +22 -3
  101. package/project/.sdk/tm/ts/src/utility/MakePointUtility.ts +72 -2
  102. package/project/.sdk/tm/zig/core/utility.zig +66 -3
  103. package/project/sdkgen-package.json +1 -2
  104. package/src/cmp/ExternalTarget.ts +1 -1
  105. package/src/helpers/naming.ts +129 -5
  106. package/src/helpers/opShape.ts +85 -0
  107. package/src/helpers/packageMeta.ts +59 -20
  108. package/src/sdkgen.ts +68 -20
  109. package/src/testkit.ts +863 -0
  110. package/testkit.d.ts +3 -0
  111. package/testkit.js +12 -0
  112. package/project/.sdk/model/target/haskell.aontu +0 -72
  113. package/project/.sdk/src/cmp/haskell/Config_haskell.ts +0 -98
  114. package/project/.sdk/src/cmp/haskell/Entity_haskell.ts +0 -13
  115. package/project/.sdk/src/cmp/haskell/Gitignore_haskell.ts +0 -27
  116. package/project/.sdk/src/cmp/haskell/Main_haskell.ts +0 -123
  117. package/project/.sdk/src/cmp/haskell/Package_haskell.ts +0 -60
  118. package/project/.sdk/src/cmp/haskell/ReadmeEntity_haskell.ts +0 -186
  119. package/project/.sdk/src/cmp/haskell/ReadmeExamplesTest_haskell.ts +0 -135
  120. package/project/.sdk/src/cmp/haskell/ReadmeExplanation_haskell.ts +0 -48
  121. package/project/.sdk/src/cmp/haskell/ReadmeHowto_haskell.ts +0 -168
  122. package/project/.sdk/src/cmp/haskell/ReadmeInstall_haskell.ts +0 -51
  123. package/project/.sdk/src/cmp/haskell/ReadmeIntro_haskell.ts +0 -67
  124. package/project/.sdk/src/cmp/haskell/ReadmeModel_haskell.ts +0 -162
  125. package/project/.sdk/src/cmp/haskell/ReadmeOptions_haskell.ts +0 -74
  126. package/project/.sdk/src/cmp/haskell/ReadmeQuick_haskell.ts +0 -241
  127. package/project/.sdk/src/cmp/haskell/ReadmeRef_haskell.ts +0 -408
  128. package/project/.sdk/src/cmp/haskell/ReadmeTopHowto_haskell.ts +0 -31
  129. package/project/.sdk/src/cmp/haskell/ReadmeTopQuick_haskell.ts +0 -104
  130. package/project/.sdk/src/cmp/haskell/ReadmeTopTest_haskell.ts +0 -80
  131. package/project/.sdk/src/cmp/haskell/Test_haskell.ts +0 -300
  132. package/project/.sdk/src/cmp/haskell/tsconfig.json +0 -15
  133. package/project/.sdk/src/cmp/haskell/utility_haskell.ts +0 -166
  134. package/project/.sdk/tm/haskell/LICENSE +0 -21
  135. package/project/.sdk/tm/haskell/Makefile +0 -22
  136. package/project/.sdk/tm/haskell/VERSION +0 -1
  137. package/project/.sdk/tm/haskell/src/SdkFeatures.hs +0 -1440
  138. package/project/.sdk/tm/haskell/src/SdkHelpers.hs +0 -337
  139. package/project/.sdk/tm/haskell/src/SdkJson.hs +0 -111
  140. package/project/.sdk/tm/haskell/src/SdkRuntime.hs +0 -1219
  141. package/project/.sdk/tm/haskell/src/SdkTypes.hs +0 -195
  142. package/project/.sdk/tm/haskell/src/VoxgigStruct.hs +0 -2299
  143. package/project/.sdk/tm/haskell/src/Vregex.hs +0 -237
  144. package/project/.sdk/tm/haskell/src/feature/README.md +0 -5
  145. package/project/.sdk/tm/haskell/src/feature/audit/.gitkeep +0 -0
  146. package/project/.sdk/tm/haskell/src/feature/base/.gitkeep +0 -0
  147. package/project/.sdk/tm/haskell/src/feature/cache/.gitkeep +0 -0
  148. package/project/.sdk/tm/haskell/src/feature/clienttrack/.gitkeep +0 -0
  149. package/project/.sdk/tm/haskell/src/feature/debug/.gitkeep +0 -0
  150. package/project/.sdk/tm/haskell/src/feature/idempotency/.gitkeep +0 -0
  151. package/project/.sdk/tm/haskell/src/feature/log/.gitkeep +0 -0
  152. package/project/.sdk/tm/haskell/src/feature/metrics/.gitkeep +0 -0
  153. package/project/.sdk/tm/haskell/src/feature/netsim/.gitkeep +0 -0
  154. package/project/.sdk/tm/haskell/src/feature/paging/.gitkeep +0 -0
  155. package/project/.sdk/tm/haskell/src/feature/proxy/.gitkeep +0 -0
  156. package/project/.sdk/tm/haskell/src/feature/ratelimit/.gitkeep +0 -0
  157. package/project/.sdk/tm/haskell/src/feature/rbac/.gitkeep +0 -0
  158. package/project/.sdk/tm/haskell/src/feature/retry/.gitkeep +0 -0
  159. package/project/.sdk/tm/haskell/src/feature/streaming/.gitkeep +0 -0
  160. package/project/.sdk/tm/haskell/src/feature/telemetry/.gitkeep +0 -0
  161. package/project/.sdk/tm/haskell/src/feature/test/.gitkeep +0 -0
  162. package/project/.sdk/tm/haskell/src/feature/timeout/.gitkeep +0 -0
  163. package/project/.sdk/tm/haskell/test/Harness.hs +0 -281
  164. package/project/.sdk/tm/haskell/test/Runner.hs +0 -47
  165. package/project/.sdk/tm/haskell/test/StructCorpus.hs +0 -449
  166. package/project/.sdk/tm/haskell/test/TCustomUtility.hs +0 -38
  167. package/project/.sdk/tm/haskell/test/TFeature.hs +0 -794
  168. package/project/.sdk/tm/haskell/test/TNetsim.hs +0 -50
  169. package/project/.sdk/tm/haskell/test/TPipeline.hs +0 -334
  170. package/project/.sdk/tm/haskell/test/TPrimaryUtility.hs +0 -386
  171. package/project/.sdk/tm/haskell/test/Testutil.hs +0 -59
@@ -1,50 +0,0 @@
1
- -- Network-behaviour simulation over the offline mock transport. The `test`
2
- -- feature accepts an optional `net` config so unit tests can exercise slow,
3
- -- failing and offline conditions without a live server. These drive the
4
- -- transport through direct(), which needs no entity.
5
-
6
- module TNetsim (tests) where
7
-
8
- import Data.IORef (readIORef)
9
-
10
- import VoxgigStruct (Value (..))
11
- import SdkTypes
12
- import SdkHelpers
13
- import qualified SdkFeatures as F
14
- import qualified SdkClient as C
15
- import Testutil
16
-
17
- tests :: Counters -> IO ()
18
- tests c = do
19
- runTest c "netsim.offline_fails" $ do
20
- net <- jo [("offline", VBool True)]
21
- opt <- jo [("net", net)]
22
- sdk <- C.testSdk opt VNoval
23
- args <- jo [("path", VStr "/ping")]
24
- res <- F.direct sdk args
25
- ok <- getp res "ok"
26
- pure (not (isTrueV ok))
27
-
28
- runTest c "netsim.failstatus_surfaces_status" $ do
29
- net <- jo [("failTimes", VNum 1), ("failStatus", VNum 503)]
30
- opt <- jo [("net", net)]
31
- sdk <- C.testSdk opt VNoval
32
- args <- jo [("path", VStr "/ping")]
33
- res <- F.direct sdk args
34
- ok <- getp res "ok"
35
- st <- getp res "status"
36
- pure (not (isTrueV ok) && toInt st == 503)
37
-
38
- runTest c "netsim.errortimes_conn_error" $ do
39
- net <- jo [("errorTimes", VNum 1)]
40
- opt <- jo [("net", net)]
41
- sdk <- C.testSdk opt VNoval
42
- args <- jo [("path", VStr "/ping")]
43
- res <- F.direct sdk args
44
- ok <- getp res "ok"
45
- pure (not (isTrueV ok))
46
-
47
- runTest c "netsim.plain_test_mode" $ do
48
- sdk <- C.testSdk0
49
- m <- readIORef (clMode sdk)
50
- pure (m == "test")
@@ -1,334 +0,0 @@
1
- -- Direct unit tests for the operation-pipeline utilities (mirrors the dynamic
2
- -- donors' test_pipeline). Drives the error/edge branches a happy-path op never
3
- -- reaches. API-agnostic: everything is reached through the client utility.
4
-
5
- module TPipeline (tests) where
6
-
7
- import Data.IORef
8
- import Data.Maybe (isNothing)
9
-
10
- import VoxgigStruct (Value (..), emptyMap, emptyList, mkList, size, ismap, isNoval, vint)
11
- import SdkTypes
12
- import SdkHelpers
13
- import SdkRuntime
14
- import qualified SdkFeatures as F
15
- import qualified SdkClient as C
16
- import Testutil
17
-
18
- client :: IO Client
19
- client = C.testSdk0
20
-
21
- mkCtx :: Client -> String -> IO Context
22
- mkCtx cl opname = do
23
- root <- readIORef (clRootctx cl)
24
- makeContextImpl (defaultCtxSpec { csOpname = Just opname, csClient = Just cl, csUtility = Just (clUtility cl) }) root
25
-
26
- mkCtxCtrl :: Client -> String -> Value -> IO Context
27
- mkCtxCtrl cl opname ctrl = do
28
- root <- readIORef (clRootctx cl)
29
- makeContextImpl (defaultCtxSpec { csOpname = Just opname, csClient = Just cl, csUtility = Just (clUtility cl), csCtrl = Just ctrl }) root
30
-
31
- fullSpec :: IO Value
32
- fullSpec = do
33
- pm <- emptyMap; qm <- emptyMap; hm <- emptyMap
34
- newSpec =<< jo [("base", VStr "http://h"), ("prefix", VStr ""), ("suffix", VStr ""), ("path", VStr "a"), ("method", VStr "GET"), ("params", pm), ("query", qm), ("headers", hm), ("step", VStr "s")]
35
-
36
- respMap :: Int -> Value -> [(String, Value)] -> IO Value
37
- respMap status dat headers = do
38
- hm <- emptyMap
39
- mapM_ (\(k, v) -> setp hm (lower k) v) headers
40
- newResponse =<< jo [("status", vint status), ("statusText", VStr (if status < 400 then "OK" else "ERR")), ("headers", hm), ("json", jsonThunk dat), ("body", VStr "body")]
41
-
42
- namedFeature :: String -> Value -> IO Feature
43
- namedFeature nm opts = do
44
- active <- newIORef True; fopts <- newIORef opts
45
- pure Feature { fName = nm, fVersion = "0.0.1", fActive = active, fOptions = fopts, fInit = \_ _ -> pure (), fHook = \_ _ -> pure () }
46
-
47
- errCodeIs :: Value -> String -> IO Bool
48
- errCodeIs e code = do c <- errCode e; pure (c == code)
49
-
50
- tests :: Counters -> IO ()
51
- tests c = do
52
- -- feature order (PR review #2): makeOptions resolves the feature add-order
53
- -- into __derived__.featureorder. A map defaults test-first (so the test mock
54
- -- is the base transport), an explicit array preserves the developer order,
55
- -- and a map without test is deterministic (names sorted).
56
- let orderNames opts = do
57
- fo <- getpathS opts "__derived__.featureorder"
58
- case fo of
59
- VList ref -> do { xs <- readIORef ref; pure [s | VStr s <- xs] }
60
- _ -> pure []
61
- resolveOrder feature = do
62
- cl <- client
63
- ctx <- mkCtx cl "load"
64
- o <- jo [("feature", feature)]; writeIORef (cOptions ctx) o
65
- cfgo <- emptyMap; cf <- jo [("options", cfgo)]; writeIORef (cConfig ctx) cf
66
- makeOptionsUtil ctx
67
-
68
- runTest c "feature_order.map_test_first" $ do
69
- m <- jo [("active", VBool True)]; t <- jo [("active", VBool True)]
70
- feat <- jo [("metrics", m), ("test", t)]
71
- o <- resolveOrder feat
72
- order <- orderNames o
73
- pure (order == ["test", "metrics"])
74
-
75
- runTest c "feature_order.array_preserves_order" $ do
76
- e1 <- jo [("name", VStr "metrics"), ("active", VBool True)]
77
- e2 <- jo [("name", VStr "test"), ("active", VBool True)]
78
- feat <- ja [e1, e2]
79
- o <- resolveOrder feat
80
- order <- orderNames o
81
- ma <- getpathS o "feature.metrics.active"
82
- ta <- getpathS o "feature.test.active"
83
- pure (order == ["metrics", "test"] && isTrueV ma && isTrueV ta)
84
-
85
- runTest c "feature_order.map_no_test_deterministic" $ do
86
- r <- jo [("active", VBool True)]; ca <- jo [("active", VBool True)]
87
- feat <- jo [("retry", r), ("cache", ca)]
88
- o <- resolveOrder feat
89
- order <- orderNames o
90
- pure (order == ["cache", "retry"])
91
-
92
- runTest c "make_point.rejects_disallowed_op" $ do
93
- cl <- client; ctx <- mkCtx cl "nope"
94
- ao <- jo [("op", VStr "load")]; o <- jo [("allow", ao)]; writeIORef (cOptions ctx) o
95
- (_, merr) <- makePointUtil ctx
96
- case merr of Just e -> errCodeIs e "point_op_allow"; Nothing -> pure False
97
-
98
- runTest c "make_point.rejects_no_endpoints" $ do
99
- cl <- client; ctx <- mkCtx cl "load"
100
- (_, merr) <- makePointUtil ctx
101
- case merr of Just e -> errCodeIs e "point_no_points"; Nothing -> pure False
102
-
103
- runTest c "make_point.single_point" $ do
104
- cl <- client; ctx <- mkCtx cl "load"
105
- parts <- ja [VStr "a"]
106
- point <- jo [("method", VStr "GET"), ("parts", parts)]
107
- pts <- ja [point]
108
- op <- newOperation =<< jo [("name", VStr "load"), ("points", pts)]
109
- writeIORef (cOp ctx) op
110
- (out, merr) <- makePointUtil ctx
111
- m <- getp out "method"
112
- pt <- readIORef (cPoint ctx)
113
- pure (isNothing merr && vstring m == "GET" && ismap pt)
114
-
115
- runTest c "make_point.short_circuits_preset" $ do
116
- cl <- client; ctx <- mkCtx cl "load"
117
- preset <- jo [("method", VStr "GET")]
118
- out <- readIORef (cOut ctx); setp out "point" preset
119
- (o, merr) <- makePointUtil ctx
120
- m <- getp o "method"
121
- pure (isNothing merr && vstring m == "GET")
122
-
123
- runTest c "make_point.surfaces_feature_error" $ do
124
- cl <- client; ctx <- mkCtx cl "load"
125
- denied <- mkErr "rbac_denied" "no permission"
126
- out <- readIORef (cOut ctx); setp out "point" denied
127
- (_, merr) <- makePointUtil ctx
128
- case merr of Just e -> errCodeIs e "rbac_denied"; Nothing -> pure False
129
-
130
- runTest c "make_spec.short_circuits_preset" $ do
131
- cl <- client; ctx <- mkCtx cl "load"
132
- preset <- newSpec =<< jo [("method", VStr "GET")]
133
- out <- readIORef (cOut ctx); setp out "spec" preset
134
- (o, merr) <- makeSpecUtil ctx
135
- m <- getp o "method"
136
- pure (isNothing merr && vstring m == "GET")
137
-
138
- runTest c "make_spec.surfaces_feature_error" $ do
139
- cl <- client; ctx <- mkCtx cl "load"
140
- boom <- mkErr "boom" "boom"
141
- out <- readIORef (cOut ctx); setp out "spec" boom
142
- (_, merr) <- makeSpecUtil ctx
143
- case merr of Just e -> errCodeIs e "boom"; Nothing -> pure False
144
-
145
- runTest c "make_response.guard_no_spec" $ do
146
- cl <- client; ctx <- mkCtx cl "load"
147
- writeIORef (cSpec ctx) VNoval
148
- r <- respMap 200 VNoval []; writeIORef (cResponse ctx) r
149
- res <- newResult =<< emptyMap; writeIORef (cResult ctx) res
150
- (_, merr) <- makeResponseUtil ctx
151
- case merr of Just e -> errCodeIs e "response_no_spec"; Nothing -> pure False
152
-
153
- runTest c "make_response.4xx_sets_err_and_headers" $ do
154
- cl <- client; ctx <- mkCtx cl "load"
155
- sp <- fullSpec; writeIORef (cSpec ctx) sp
156
- r <- respMap 404 VNoval [("x-a", VStr "1")]; writeIORef (cResponse ctx) r
157
- res <- newResult =<< emptyMap; writeIORef (cResult ctx) res
158
- _ <- makeResponseUtil ctx
159
- rv <- readIORef (cResult ctx)
160
- errv <- getp rv "err"; isE <- isErr errv
161
- st <- getp rv "status"; ha <- getp rv "headers" >>= \h -> getp h "x-a"
162
- ok <- getp rv "ok"
163
- pure (isE && toInt st == 404 && vstring ha == "1" && not (isTrueV ok))
164
-
165
- runTest c "make_response.2xx_parses_body" $ do
166
- cl <- client; ctx <- mkCtx cl "load"
167
- sp <- fullSpec; writeIORef (cSpec ctx) sp
168
- d <- jo [("v", VNum 1)]
169
- r <- respMap 200 d []; writeIORef (cResponse ctx) r
170
- res <- newResult =<< emptyMap; writeIORef (cResult ctx) res
171
- _ <- makeResponseUtil ctx
172
- rv <- readIORef (cResult ctx)
173
- ok <- getp rv "ok"; bv <- getp rv "body" >>= \b -> getp b "v"
174
- pure (isTrueV ok && (case bv of VNum n -> n == 1; _ -> False))
175
-
176
- runTest c "make_response.records_explain" $ do
177
- cl <- client; ex <- emptyMap; ctrl <- jo [("explain", ex)]
178
- ctx <- mkCtxCtrl cl "load" ctrl
179
- sp <- fullSpec; writeIORef (cSpec ctx) sp
180
- d <- jo [("v", VNum 2)]; r <- respMap 200 d []; writeIORef (cResponse ctx) r
181
- res <- newResult =<< emptyMap; writeIORef (cResult ctx) res
182
- _ <- makeResponseUtil ctx
183
- ctrlV <- readIORef (cCtrl ctx); exv <- getp ctrlV "explain"; resv <- getp exv "result"
184
- pure (ismap resv)
185
-
186
- runTest c "make_result.guard_no_result" $ do
187
- cl <- client; ctx <- mkCtx cl "load"
188
- sp <- fullSpec; writeIORef (cSpec ctx) sp
189
- writeIORef (cResult ctx) VNoval
190
- (_, merr) <- makeResultUtil ctx
191
- case merr of Just e -> errCodeIs e "result_no_result"; Nothing -> pure False
192
-
193
- runTest c "make_result.list_wraps_resdata" $ do
194
- cl <- client; ctx <- mkCtx cl "list"
195
- ent <- F.makeEntity cl "planet" VNoval; writeIORef (cEntity ctx) (Just ent)
196
- sp <- fullSpec; writeIORef (cSpec ctx) sp
197
- a1 <- jo [("a", VNum 1)]; a2 <- jo [("a", VNum 2)]; rd <- ja [a1, a2]
198
- res <- newResult =<< jo [("resdata", rd)]; writeIORef (cResult ctx) res
199
- (ro, merr) <- makeResultUtil ctx
200
- n <- getp ro "resdata" >>= size
201
- pure (isNothing merr && n == 2)
202
-
203
- runTest c "make_request.guard_no_spec" $ do
204
- cl <- client; ctx <- mkCtx cl "load"
205
- writeIORef (cSpec ctx) VNoval
206
- (_, merr) <- makeRequestUtil ctx
207
- case merr of Just e -> errCodeIs e "request_no_spec"; Nothing -> pure False
208
-
209
- runTest c "make_request.transport_error_on_response" $ do
210
- cl <- client; ctx <- mkCtx cl "load"
211
- u <- copyUtility (clUtility cl)
212
- boom <- mkErr "boom" "boom"
213
- writeIORef (uFetcher u) (\_ _ _ -> pure (VNoval, Just boom))
214
- writeIORef (cUtility ctx) (Just u)
215
- sp <- fullSpec; writeIORef (cSpec ctx) sp
216
- (ro, _) <- makeRequestUtil ctx
217
- errv <- getp ro "err"; errCodeIs errv "boom"
218
-
219
- runTest c "make_request.null_transport" $ do
220
- cl <- client; ctx <- mkCtx cl "load"
221
- u <- copyUtility (clUtility cl)
222
- writeIORef (uFetcher u) (\_ _ _ -> pure (VNoval, Nothing))
223
- writeIORef (cUtility ctx) (Just u)
224
- sp <- fullSpec; writeIORef (cSpec ctx) sp
225
- (ro, _) <- makeRequestUtil ctx
226
- errv <- getp ro "err"; errCodeIs errv "request_no_response"
227
-
228
- runTest c "make_fetch_def.guard_no_spec" $ do
229
- cl <- client; ctx <- mkCtx cl "load"
230
- writeIORef (cSpec ctx) VNoval
231
- (_, merr) <- makeFetchDefUtil ctx
232
- case merr of Just e -> errCodeIs e "fetchdef_no_spec"; Nothing -> pure False
233
-
234
- runTest c "make_fetch_def.serialises_body" $ do
235
- cl <- client; ctx <- mkCtx cl "load"
236
- writeIORef (cResult ctx) VNoval
237
- sp <- fullSpec; setp sp "method" (VStr "POST"); b <- jo [("x", VNum 1)]; setp sp "body" b
238
- writeIORef (cSpec ctx) sp
239
- (fd, merr) <- makeFetchDefUtil ctx
240
- bs <- getp fd "body"
241
- rv <- readIORef (cResult ctx)
242
- pure (isNothing merr && (case bs of VStr s -> not (null s); _ -> False) && ismap rv)
243
-
244
- runTest c "done.returns_resdata_on_success" $ do
245
- cl <- client; ctx <- mkCtx cl "load"
246
- res <- newResult =<< jo [("ok", VBool True), ("resdata", VNum 42)]; writeIORef (cResult ctx) res
247
- r <- doneUtil ctx
248
- pure (case r of VNum n -> n == 42; _ -> False)
249
-
250
- runTest c "make_error.returns_resdata_when_throw_disabled" $ do
251
- cl <- client; ctrl <- jo [("throw_err", VBool False)]
252
- ctx <- mkCtxCtrl cl "load" ctrl
253
- res <- newResult =<< jo [("ok", VBool False), ("resdata", VStr "fallback")]; writeIORef (cResult ctx) res
254
- r <- makeErrorUtil ctx Nothing
255
- pure (vstring r == "fallback")
256
-
257
- runTest c "make_error.records_explain" $ do
258
- cl <- client; ex <- emptyMap; ctrl <- jo [("throw_err", VBool False), ("explain", ex)]
259
- ctx <- mkCtxCtrl cl "load" ctrl
260
- res <- newResult =<< jo [("ok", VBool False)]; writeIORef (cResult ctx) res
261
- _ <- makeErrorUtil ctx Nothing
262
- ctrlV <- readIORef (cCtrl ctx); exv <- getp ctrlV "explain"; errv <- getp exv "err"
263
- pure (ismap errv)
264
-
265
- runTest c "feature_add.appends_in_order" $ do
266
- cl <- client; ctx <- mkCtx cl "load"
267
- start <- readIORef (clFeatures cl) >>= \fs -> pure (map fName fs)
268
- a <- namedFeature "aaa" VNoval; z <- namedFeature "zzz" VNoval
269
- featureAddUtil ctx a; featureAddUtil ctx z
270
- names <- readIORef (clFeatures cl) >>= \fs -> pure (map fName fs)
271
- pure (names == start ++ ["aaa", "zzz"])
272
-
273
- runTest c "feature_add.ordering" $ do
274
- cl <- client; ctx <- mkCtx cl "load"
275
- writeIORef (clFeatures cl) []
276
- let names = readIORef (clFeatures cl) >>= \fs -> pure (map fName fs)
277
- fa <- namedFeature "a" VNoval; fb <- namedFeature "b" VNoval
278
- featureAddUtil ctx fa; featureAddUtil ctx fb
279
- n1 <- names
280
- ob <- jo [("__before__", VStr "b")]; z1 <- namedFeature "z1" ob; featureAddUtil ctx z1
281
- n2 <- names
282
- oa <- jo [("__after__", VStr "a")]; z2 <- namedFeature "z2" oa; featureAddUtil ctx z2
283
- n3 <- names
284
- orp <- jo [("__replace__", VStr "z1")]; z3 <- namedFeature "z3" orp; featureAddUtil ctx z3
285
- n4 <- names
286
- om <- jo [("__before__", VStr "missing")]; z4 <- namedFeature "z4" om; featureAddUtil ctx z4
287
- n5 <- names
288
- pure (n1 == ["a", "b"] && n2 == ["a", "z1", "b"] && n3 == ["a", "z2", "z1", "b"] && n4 == ["a", "z2", "z3", "b"] && n5 == ["a", "z2", "z3", "b", "z4"])
289
-
290
- runTest c "feature.transport_wrapping_order" $ do
291
- cl <- client; ctx <- readIORef (clRootctx cl) >>= \(Just r) -> pure r
292
- let u = clUtility cl
293
- order <- newIORef []
294
- writeIORef (uFetcher u) (\_ _ _ -> do modifyIORef order (++ ["server"]); r <- jo [("status", VNum 200), ("statusText", VStr "OK")]; pure (r, Nothing))
295
- let wrap tag = do inner <- readIORef (uFetcher u); writeIORef (uFetcher u) (\cc url fd -> do modifyIORef order (++ [tag]); inner cc url fd)
296
- wrap "first"; wrap "second"
297
- fetcher <- readIORef (uFetcher u)
298
- hm <- emptyMap; fd <- jo [("method", VStr "GET"), ("headers", hm)]
299
- _ <- fetcher ctx "http://h/a" fd
300
- o <- readIORef order
301
- pure (o == ["second", "first", "server"])
302
-
303
- runTest c "prepare_auth.apikey_prefix_space_joined" $ do
304
- cl <- client; ctx <- mkCtx cl "load"
305
- ap <- jo [("prefix", VStr "Bearer")]; o <- jo [("apikey", VStr "K"), ("auth", ap)]; writeIORef (clOptions cl) o
306
- hm <- emptyMap; sp <- newSpec =<< jo [("headers", hm)]; writeIORef (cSpec ctx) sp
307
- _ <- prepareAuthUtil ctx
308
- spv <- readIORef (cSpec ctx); h <- getp spv "headers"; av <- getp h "authorization"
309
- pure (vstring av == "Bearer K")
310
-
311
- runTest c "prepare_auth.empty_apikey_drops_header" $ do
312
- cl <- client; ctx <- mkCtx cl "load"
313
- ap <- jo [("prefix", VStr "Bearer")]; o <- jo [("apikey", VStr ""), ("auth", ap)]; writeIORef (clOptions cl) o
314
- stale <- jo [("authorization", VStr "stale")]; sp <- newSpec =<< jo [("headers", stale)]; writeIORef (cSpec ctx) sp
315
- _ <- prepareAuthUtil ctx
316
- spv <- readIORef (cSpec ctx); h <- getp spv "headers"; av <- getp h "authorization"
317
- pure (isNoval av)
318
-
319
- runTest c "result_headers.no_headers_empty_map" $ do
320
- cl <- client; ctx <- mkCtx cl "load"
321
- r <- newResponse =<< jo [("status", VNum 200)]; writeIORef (cResponse ctx) r
322
- res <- newResult =<< emptyMap; writeIORef (cResult ctx) res
323
- resultHeadersUtil ctx
324
- rv <- readIORef (cResult ctx); h <- getp rv "headers"; n <- size h
325
- pure (n == 0)
326
-
327
- runTest c "result_body.skips_absent_body" $ do
328
- cl <- client; ctx <- mkCtx cl "load"
329
- d <- jo [("a", VNum 1)]
330
- r <- newResponse =<< jo [("status", VNum 200), ("json", jsonThunk d)]; writeIORef (cResponse ctx) r
331
- res <- newResult =<< emptyMap; writeIORef (cResult ctx) res
332
- resultBodyUtil ctx
333
- rv <- readIORef (cResult ctx); b <- getp rv "body"
334
- pure (isNoval b)