@synopackageland/cli 0.4.0 → 0.4.1

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 (438) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/dist/build-spk/generator.js +3 -0
  4. package/dist/build-spk/notices.d.ts +5 -0
  5. package/dist/build-spk/notices.js +60 -0
  6. package/dist/cli.js +9 -2
  7. package/dist/error-registry.js +20 -0
  8. package/dist/init.d.ts +4 -0
  9. package/dist/init.js +20 -12
  10. package/dist/standalone/build.js +3 -1
  11. package/dist/standalone/daemon.d.ts +23 -0
  12. package/dist/standalone/daemon.js +114 -0
  13. package/dist/standalone/dsm-window.d.ts +1 -1
  14. package/dist/standalone/dsm-window.js +50 -10
  15. package/dist/standalone/helper-inventory.d.ts +16 -0
  16. package/dist/standalone/helper-inventory.js +2 -0
  17. package/dist/standalone/helper.d.ts +2 -12
  18. package/dist/standalone/helper.js +8 -7
  19. package/dist/standalone/host-adapter.d.ts +5 -0
  20. package/dist/standalone/host-adapter.js +148 -0
  21. package/dist/standalone/host-platform.d.ts +13 -0
  22. package/dist/standalone/host-platform.js +42 -0
  23. package/dist/standalone/host-types.d.ts +49 -0
  24. package/dist/standalone/host-types.js +1 -0
  25. package/dist/standalone/inspect-helper.d.ts +6 -0
  26. package/dist/standalone/inspect-helper.js +88 -0
  27. package/dist/standalone/inspect-spk.d.ts +2 -0
  28. package/dist/standalone/inspect-spk.js +49 -0
  29. package/dist/standalone/lifecycle-helper.d.ts +2 -0
  30. package/dist/standalone/lifecycle-helper.js +12 -0
  31. package/dist/standalone/lifecycle.d.ts +3 -0
  32. package/dist/standalone/lifecycle.js +53 -0
  33. package/dist/standalone/manifest.d.ts +2 -0
  34. package/dist/standalone/manifest.js +4 -1
  35. package/dist/standalone/reopen-events.d.ts +2 -0
  36. package/dist/standalone/reopen-events.js +28 -0
  37. package/dist/standalone/root-messages.js +9 -0
  38. package/dist/standalone/root-window.d.ts +4 -3
  39. package/dist/standalone/root-window.js +17 -5
  40. package/dist/standalone/spk.d.ts +4 -3
  41. package/dist/standalone/spk.js +20 -33
  42. package/dist/template-paths.d.ts +2 -0
  43. package/dist/template-paths.js +9 -0
  44. package/dist/templates/_daemon/fixture_linux_test.go +15 -0
  45. package/dist/templates/_daemon/fixture_other_test.go +7 -0
  46. package/dist/templates/_daemon/go.mod +3 -0
  47. package/dist/templates/_daemon/main.go +608 -0
  48. package/dist/templates/_daemon/main_test.go +242 -0
  49. package/dist/templates/_daemon/process_linux.go +55 -0
  50. package/dist/templates/_daemon/process_linux_test.go +161 -0
  51. package/dist/templates/_daemon/process_other.go +14 -0
  52. package/dist/templates/_daemon/testdata/child.go +41 -0
  53. package/dist/templates/_shared/GO-LICENSE +27 -0
  54. package/dist/templates/_shared/GO-PATENTS +22 -0
  55. package/dist/templates/_shared/LICENSES/TEMPLATE.txt +21 -0
  56. package/dist/templates/_shared/notice-overrides/index.json +14 -0
  57. package/dist/templates/_shared/notice-overrides/utils-0.4.2-LICENSE +21 -0
  58. package/dist/templates/_shared/notice-overrides/utils-0.5.0-LICENSE +21 -0
  59. package/dist/templates/_shared/third-party-notices.mjs +51 -0
  60. package/dist/templates/native-go/README.md +57 -1
  61. package/dist/templates/native-go/backend/THIRD_PARTY_NOTICES.txt +59 -0
  62. package/dist/templates/native-go/backend/cmd/dsm-readonly-probe/main_linux.go +46 -0
  63. package/dist/templates/native-go/backend/go.mod +4 -0
  64. package/dist/templates/native-go/backend/go.sum +4 -0
  65. package/dist/templates/native-go/backend/internal/api/binary.go +154 -0
  66. package/dist/templates/native-go/backend/internal/api/binary_test.go +165 -0
  67. package/dist/templates/native-go/backend/internal/api/registry.go +14 -4
  68. package/dist/templates/native-go/backend/internal/api/server.go +4 -0
  69. package/dist/templates/native-go/backend/internal/app/nas_cgi_artifact_test.go +121 -0
  70. package/dist/templates/native-go/backend/internal/app/nas_refusal_test.go +46 -0
  71. package/dist/templates/native-go/backend/internal/app/routes.go +11 -0
  72. package/dist/templates/native-go/backend/internal/app/routes_test.go +10 -5
  73. package/dist/templates/native-go/backend/internal/dsmprobe/collector_linux.go +335 -0
  74. package/dist/templates/native-go/backend/internal/dsmprobe/collector_linux_test.go +41 -0
  75. package/dist/templates/native-go/backend/internal/dsmprobe/protocol.go +179 -0
  76. package/dist/templates/native-go/backend/internal/dsmprobe/protocol_test.go +29 -0
  77. package/dist/templates/native-go/backend/internal/helper/cohort.go +393 -0
  78. package/dist/templates/native-go/backend/internal/helper/cohort_publication.go +18 -0
  79. package/dist/templates/native-go/backend/internal/helper/cohort_publication_test.go +105 -0
  80. package/dist/templates/native-go/backend/internal/helper/cohort_test.go +372 -0
  81. package/dist/templates/native-go/backend/internal/helper/control.go +226 -21
  82. package/dist/templates/native-go/backend/internal/helper/control_test.go +10 -2
  83. package/dist/templates/native-go/backend/internal/helper/data_contract.go +242 -0
  84. package/dist/templates/native-go/backend/internal/helper/data_contract_test.go +51 -0
  85. package/dist/templates/native-go/backend/internal/helper/data_decode.go +184 -0
  86. package/dist/templates/native-go/backend/internal/helper/data_decode_pointer_test.go +30 -0
  87. package/dist/templates/native-go/backend/internal/helper/data_protocol.go +416 -0
  88. package/dist/templates/native-go/backend/internal/helper/data_protocol_test.go +449 -0
  89. package/dist/templates/native-go/backend/internal/helper/dsm_acl_linux.go +139 -0
  90. package/dist/templates/native-go/backend/internal/helper/dsm_acl_linux_test.go +121 -0
  91. package/dist/templates/native-go/backend/internal/helper/dsm_acl_syscall_linux.go +95 -0
  92. package/dist/templates/native-go/backend/internal/helper/dsm_acl_syscall_linux_test.go +56 -0
  93. package/dist/templates/native-go/backend/internal/helper/dsm_bridge_linux.go +144 -0
  94. package/dist/templates/native-go/backend/internal/helper/dsm_bridge_linux_test.go +89 -0
  95. package/dist/templates/native-go/backend/internal/helper/dsm_home_linux.go +107 -0
  96. package/dist/templates/native-go/backend/internal/helper/dsm_home_linux_test.go +82 -0
  97. package/dist/templates/native-go/backend/internal/helper/dsm_probe_transport_linux.go +151 -0
  98. package/dist/templates/native-go/backend/internal/helper/dsm_probe_transport_linux_test.go +66 -0
  99. package/dist/templates/native-go/backend/internal/helper/grant_authority.go +516 -0
  100. package/dist/templates/native-go/backend/internal/helper/grant_authority_contract.go +88 -0
  101. package/dist/templates/native-go/backend/internal/helper/grant_authority_test.go +510 -0
  102. package/dist/templates/native-go/backend/internal/helper/grant_cohort.go +389 -0
  103. package/dist/templates/native-go/backend/internal/helper/grant_cohort_test.go +239 -0
  104. package/dist/templates/native-go/backend/internal/helper/grant_delivery.go +49 -0
  105. package/dist/templates/native-go/backend/internal/helper/grant_delivery_methods.go +273 -0
  106. package/dist/templates/native-go/backend/internal/helper/grant_delivery_test.go +322 -0
  107. package/dist/templates/native-go/backend/internal/helper/grant_operation_contract.go +47 -0
  108. package/dist/templates/native-go/backend/internal/helper/grant_readonly_test.go +180 -0
  109. package/dist/templates/native-go/backend/internal/helper/grant_repository_linux.go +415 -0
  110. package/dist/templates/native-go/backend/internal/helper/grant_repository_linux_test.go +468 -0
  111. package/dist/templates/native-go/backend/internal/helper/grant_rpc.go +147 -0
  112. package/dist/templates/native-go/backend/internal/helper/grant_rpc_test.go +51 -0
  113. package/dist/templates/native-go/backend/internal/helper/grant_snapshot.go +75 -0
  114. package/dist/templates/native-go/backend/internal/helper/grant_supervisor_linux.go +134 -0
  115. package/dist/templates/native-go/backend/internal/helper/grant_supervisor_linux_test.go +254 -0
  116. package/dist/templates/native-go/backend/internal/helper/lease.go +112 -0
  117. package/dist/templates/native-go/backend/internal/helper/lease_linux.go +44 -0
  118. package/dist/templates/native-go/backend/internal/helper/lease_other.go +8 -0
  119. package/dist/templates/native-go/backend/internal/helper/lifecycle.go +234 -0
  120. package/dist/templates/native-go/backend/internal/helper/lifecycle_test.go +473 -0
  121. package/dist/templates/native-go/backend/internal/helper/managed_pilot.go +284 -0
  122. package/dist/templates/native-go/backend/internal/helper/managed_pilot_repository_linux.go +74 -0
  123. package/dist/templates/native-go/backend/internal/helper/managed_pilot_repository_linux_test.go +40 -0
  124. package/dist/templates/native-go/backend/internal/helper/managed_pilot_test.go +210 -0
  125. package/dist/templates/native-go/backend/internal/helper/nas_shipped_refusal_linux_test.go +97 -0
  126. package/dist/templates/native-go/backend/internal/helper/native_discovery.go +79 -0
  127. package/dist/templates/native-go/backend/internal/helper/native_identity.go +89 -0
  128. package/dist/templates/native-go/backend/internal/helper/native_provider.go +159 -0
  129. package/dist/templates/native-go/backend/internal/helper/native_provider_test.go +421 -0
  130. package/dist/templates/native-go/backend/internal/helper/observation.go +204 -0
  131. package/dist/templates/native-go/backend/internal/helper/observation_health_test.go +115 -0
  132. package/dist/templates/native-go/backend/internal/helper/observation_reload_budget_test.go +117 -0
  133. package/dist/templates/native-go/backend/internal/helper/observation_test.go +196 -0
  134. package/dist/templates/native-go/backend/internal/helper/observer_diagnostic.go +109 -0
  135. package/dist/templates/native-go/backend/internal/helper/observer_diagnostic_linux.go +76 -0
  136. package/dist/templates/native-go/backend/internal/helper/observer_diagnostic_linux_test.go +124 -0
  137. package/dist/templates/native-go/backend/internal/helper/observer_diagnostic_test.go +98 -0
  138. package/dist/templates/native-go/backend/internal/helper/operation_bootstrap_linux.go +193 -0
  139. package/dist/templates/native-go/backend/internal/helper/operation_credentials_linux.go +56 -0
  140. package/dist/templates/native-go/backend/internal/helper/operation_linux.go +480 -0
  141. package/dist/templates/native-go/backend/internal/helper/operation_linux_test.go +528 -0
  142. package/dist/templates/native-go/backend/internal/helper/process_linux.go +11 -1
  143. package/dist/templates/native-go/backend/internal/helper/publication_test.go +178 -0
  144. package/dist/templates/native-go/backend/internal/helper/read_stream_cohort_linux_test.go +156 -0
  145. package/dist/templates/native-go/backend/internal/helper/read_transfer.go +40 -0
  146. package/dist/templates/native-go/backend/internal/helper/read_transfer_linux.go +109 -0
  147. package/dist/templates/native-go/backend/internal/helper/read_transfer_linux_test.go +118 -0
  148. package/dist/templates/native-go/backend/internal/helper/read_transfer_test.go +177 -0
  149. package/dist/templates/native-go/backend/internal/helper/readonly.go +105 -0
  150. package/dist/templates/native-go/backend/internal/helper/readonly_admission.go +85 -0
  151. package/dist/templates/native-go/backend/internal/helper/readonly_cohort_linux_test.go +253 -0
  152. package/dist/templates/native-go/backend/internal/helper/readonly_linux_test.go +378 -0
  153. package/dist/templates/native-go/backend/internal/helper/readonly_mount_linux.go +65 -0
  154. package/dist/templates/native-go/backend/internal/helper/readonly_mount_proxy_linux.go +113 -0
  155. package/dist/templates/native-go/backend/internal/helper/readonly_operations_linux.go +168 -0
  156. package/dist/templates/native-go/backend/internal/helper/readonly_resolver_linux.go +241 -0
  157. package/dist/templates/native-go/backend/internal/helper/readonly_test.go +40 -0
  158. package/dist/templates/native-go/backend/internal/helper/relaxed_identity.go +252 -0
  159. package/dist/templates/native-go/backend/internal/helper/relaxed_identity_contract.go +105 -0
  160. package/dist/templates/native-go/backend/internal/helper/relaxed_identity_test.go +406 -0
  161. package/dist/templates/native-go/backend/internal/helper/relaxed_invalidation.go +200 -0
  162. package/dist/templates/native-go/backend/internal/helper/repair.go +132 -0
  163. package/dist/templates/native-go/backend/internal/helper/repair_test.go +271 -0
  164. package/dist/templates/native-go/backend/internal/helper/s1r_actor_acl_linux_test.go +303 -0
  165. package/dist/templates/native-go/backend/internal/helper/s1r_actor_fixture_linux_test.go +184 -0
  166. package/dist/templates/native-go/backend/internal/helper/s1r_actor_races_linux_test.go +231 -0
  167. package/dist/templates/native-go/backend/internal/helper/s1r_fixture_contract_linux_test.go +18 -0
  168. package/dist/templates/native-go/backend/internal/helper/server_linux.go +44 -3
  169. package/dist/templates/native-go/backend/internal/helper/status.go +74 -11
  170. package/dist/templates/native-go/backend/internal/helper/status_test.go +83 -0
  171. package/dist/templates/native-go/backend/internal/helper/supervision.go +28 -5
  172. package/dist/templates/native-go/backend/internal/helper/supervisor_frame.go +76 -0
  173. package/dist/templates/native-go/backend/internal/helper/supervisor_frame_linux_test.go +69 -0
  174. package/dist/templates/native-go/backend/internal/helper/supervisor_frame_test.go +107 -0
  175. package/dist/templates/native-go/backend/internal/helper/supervisor_linux.go +187 -16
  176. package/dist/templates/native-go/backend/internal/helper/supervisor_linux_test.go +618 -7
  177. package/dist/templates/native-go/backend/internal/helper/supervisor_socket_eof_test.go +74 -0
  178. package/dist/templates/native-go/backend/internal/helper/supervisor_socket_test.go +45 -0
  179. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/create.json +23 -0
  180. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/frames.json +67 -0
  181. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/grant-store.json +52 -0
  182. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/intent.json +20 -0
  183. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/list.json +20 -0
  184. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/publish.json +20 -0
  185. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/read.json +22 -0
  186. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/stat.json +22 -0
  187. package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/write-stream.json +22 -0
  188. package/dist/templates/native-go/backend/internal/helper/unit_connection.go +75 -0
  189. package/dist/templates/native-go/backend/internal/helper/unit_connection_linux_test.go +135 -0
  190. package/dist/templates/native-go/backend/internal/helper/unit_connection_test.go +133 -0
  191. package/dist/templates/native-go/backend/internal/helper/unit_frame_test.go +32 -0
  192. package/dist/templates/native-go/backend/internal/helper/unit_linux.go +364 -0
  193. package/dist/templates/native-go/backend/internal/helper/unit_linux_test.go +46 -0
  194. package/dist/templates/native-go/backend/internal/helper/unit_mechanisms_linux_test.go +217 -0
  195. package/dist/templates/native-go/backend/internal/helper/unit_padding_linux_test.go +178 -0
  196. package/dist/templates/native-go/backend/internal/helper/unit_query_linux.go +111 -0
  197. package/dist/templates/native-go/backend/internal/helper/unit_reload_linux_test.go +372 -0
  198. package/dist/templates/native-go/backend/internal/helper/unit_reload_sequence_linux_test.go +232 -0
  199. package/dist/templates/native-go/backend/internal/helper/write.go +77 -0
  200. package/dist/templates/native-go/backend/internal/helper/write_admission.go +260 -0
  201. package/dist/templates/native-go/backend/internal/helper/write_admission_test.go +135 -0
  202. package/dist/templates/native-go/backend/internal/helper/write_cohort_linux_test.go +218 -0
  203. package/dist/templates/native-go/backend/internal/helper/write_files_linux.go +202 -0
  204. package/dist/templates/native-go/backend/internal/helper/write_files_linux_test.go +199 -0
  205. package/dist/templates/native-go/backend/internal/helper/write_intent_linux.go +116 -0
  206. package/dist/templates/native-go/backend/internal/helper/write_intent_linux_test.go +74 -0
  207. package/dist/templates/native-go/backend/internal/helper/write_operation_linux.go +245 -0
  208. package/dist/templates/native-go/backend/internal/helper/write_test.go +53 -0
  209. package/dist/templates/native-go/ui/app.js +8 -1
  210. package/dist/templates/native-go-better-auth/node/build.mjs +2 -0
  211. package/dist/templates/native-go-vue/README.md +115 -1
  212. package/dist/templates/native-go-vue/frontend/DESIGN.md +1 -1
  213. package/dist/templates/native-go-vue/frontend/package-lock.json +132 -229
  214. package/dist/templates/native-go-vue/frontend/package.json +1 -1
  215. package/dist/templates/native-go-vue/frontend/src/App.vue +33 -6
  216. package/dist/templates/native-go-vue/frontend/src/context.ts +41 -2
  217. package/dist/templates/native-go-vue/frontend/src/main.ts +4 -1
  218. package/dist/templates/native-go-vue/frontend/src/nas/NasGrantSettings.vue +74 -0
  219. package/dist/templates/native-go-vue/frontend/src/nas/NasPathPicker.vue +106 -0
  220. package/dist/templates/native-go-vue/frontend/src/nas/NasUnavailable.vue +20 -0
  221. package/dist/templates/native-go-vue/frontend/src/nas/i18n/de.json +74 -0
  222. package/dist/templates/native-go-vue/frontend/src/nas/i18n/en.json +74 -0
  223. package/dist/templates/native-go-vue/frontend/src/nas/i18n/es.json +74 -0
  224. package/dist/templates/native-go-vue/frontend/src/nas/i18n/fr.json +74 -0
  225. package/dist/templates/native-go-vue/frontend/src/nas/i18n/it.json +74 -0
  226. package/dist/templates/native-go-vue/frontend/src/nas/i18n/ja.json +74 -0
  227. package/dist/templates/native-go-vue/frontend/src/nas/i18n/ko.json +74 -0
  228. package/dist/templates/native-go-vue/frontend/src/nas/i18n/zh-CN.json +74 -0
  229. package/dist/templates/native-go-vue/frontend/src/nas/i18n/zh-TW.json +74 -0
  230. package/dist/templates/native-go-vue/frontend/src/nas/i18n.ts +38 -0
  231. package/dist/templates/native-go-vue/frontend/src/nas/mock-provider.ts +119 -0
  232. package/dist/templates/native-go-vue/frontend/src/nas/provider.ts +59 -0
  233. package/dist/templates/native-go-vue/frontend/src/nas/use-request.ts +27 -0
  234. package/dist/templates/native-go-vue/frontend/src/style.css +17 -0
  235. package/dist/templates/native-go-vue/frontend/test/apps.test.ts +44 -2
  236. package/dist/templates/native-go-vue/frontend/test/nas-provider.test.ts +81 -0
  237. package/dist/templates/native-go-vue/frontend/test/nas-request.test.ts +21 -0
  238. package/dist/templates/native-go-vue/frontend/test/nas-ui.test.ts +261 -0
  239. package/dist/templates/native-go-vue/frontend/tsconfig.json +1 -1
  240. package/dist/templates/native-go-vue/frontend/vite.config.ts +6 -4
  241. package/package.json +3 -2
  242. package/templates/_daemon/fixture_linux_test.go +15 -0
  243. package/templates/_daemon/fixture_other_test.go +7 -0
  244. package/templates/_daemon/go.mod +3 -0
  245. package/templates/_daemon/main.go +608 -0
  246. package/templates/_daemon/main_test.go +242 -0
  247. package/templates/_daemon/process_linux.go +55 -0
  248. package/templates/_daemon/process_linux_test.go +161 -0
  249. package/templates/_daemon/process_other.go +14 -0
  250. package/templates/_daemon/testdata/child.go +41 -0
  251. package/templates/_shared/GO-LICENSE +27 -0
  252. package/templates/_shared/GO-PATENTS +22 -0
  253. package/templates/_shared/LICENSES/TEMPLATE.txt +21 -0
  254. package/templates/_shared/notice-overrides/index.json +14 -0
  255. package/templates/_shared/notice-overrides/utils-0.4.2-LICENSE +21 -0
  256. package/templates/_shared/notice-overrides/utils-0.5.0-LICENSE +21 -0
  257. package/templates/_shared/third-party-notices.mjs +51 -0
  258. package/templates/native-go/README.md +57 -1
  259. package/templates/native-go/backend/THIRD_PARTY_NOTICES.txt +59 -0
  260. package/templates/native-go/backend/cmd/dsm-readonly-probe/main_linux.go +46 -0
  261. package/templates/native-go/backend/go.mod +4 -0
  262. package/templates/native-go/backend/go.sum +4 -0
  263. package/templates/native-go/backend/internal/api/binary.go +154 -0
  264. package/templates/native-go/backend/internal/api/binary_test.go +165 -0
  265. package/templates/native-go/backend/internal/api/registry.go +14 -4
  266. package/templates/native-go/backend/internal/api/server.go +4 -0
  267. package/templates/native-go/backend/internal/app/nas_cgi_artifact_test.go +121 -0
  268. package/templates/native-go/backend/internal/app/nas_refusal_test.go +46 -0
  269. package/templates/native-go/backend/internal/app/routes.go +11 -0
  270. package/templates/native-go/backend/internal/app/routes_test.go +10 -5
  271. package/templates/native-go/backend/internal/dsmprobe/collector_linux.go +335 -0
  272. package/templates/native-go/backend/internal/dsmprobe/collector_linux_test.go +41 -0
  273. package/templates/native-go/backend/internal/dsmprobe/protocol.go +179 -0
  274. package/templates/native-go/backend/internal/dsmprobe/protocol_test.go +29 -0
  275. package/templates/native-go/backend/internal/helper/cohort.go +393 -0
  276. package/templates/native-go/backend/internal/helper/cohort_publication.go +18 -0
  277. package/templates/native-go/backend/internal/helper/cohort_publication_test.go +105 -0
  278. package/templates/native-go/backend/internal/helper/cohort_test.go +372 -0
  279. package/templates/native-go/backend/internal/helper/control.go +226 -21
  280. package/templates/native-go/backend/internal/helper/control_test.go +10 -2
  281. package/templates/native-go/backend/internal/helper/data_contract.go +242 -0
  282. package/templates/native-go/backend/internal/helper/data_contract_test.go +51 -0
  283. package/templates/native-go/backend/internal/helper/data_decode.go +184 -0
  284. package/templates/native-go/backend/internal/helper/data_decode_pointer_test.go +30 -0
  285. package/templates/native-go/backend/internal/helper/data_protocol.go +416 -0
  286. package/templates/native-go/backend/internal/helper/data_protocol_test.go +449 -0
  287. package/templates/native-go/backend/internal/helper/dsm_acl_linux.go +139 -0
  288. package/templates/native-go/backend/internal/helper/dsm_acl_linux_test.go +121 -0
  289. package/templates/native-go/backend/internal/helper/dsm_acl_syscall_linux.go +95 -0
  290. package/templates/native-go/backend/internal/helper/dsm_acl_syscall_linux_test.go +56 -0
  291. package/templates/native-go/backend/internal/helper/dsm_bridge_linux.go +144 -0
  292. package/templates/native-go/backend/internal/helper/dsm_bridge_linux_test.go +89 -0
  293. package/templates/native-go/backend/internal/helper/dsm_home_linux.go +107 -0
  294. package/templates/native-go/backend/internal/helper/dsm_home_linux_test.go +82 -0
  295. package/templates/native-go/backend/internal/helper/dsm_probe_transport_linux.go +151 -0
  296. package/templates/native-go/backend/internal/helper/dsm_probe_transport_linux_test.go +66 -0
  297. package/templates/native-go/backend/internal/helper/grant_authority.go +516 -0
  298. package/templates/native-go/backend/internal/helper/grant_authority_contract.go +88 -0
  299. package/templates/native-go/backend/internal/helper/grant_authority_test.go +510 -0
  300. package/templates/native-go/backend/internal/helper/grant_cohort.go +389 -0
  301. package/templates/native-go/backend/internal/helper/grant_cohort_test.go +239 -0
  302. package/templates/native-go/backend/internal/helper/grant_delivery.go +49 -0
  303. package/templates/native-go/backend/internal/helper/grant_delivery_methods.go +273 -0
  304. package/templates/native-go/backend/internal/helper/grant_delivery_test.go +322 -0
  305. package/templates/native-go/backend/internal/helper/grant_operation_contract.go +47 -0
  306. package/templates/native-go/backend/internal/helper/grant_readonly_test.go +180 -0
  307. package/templates/native-go/backend/internal/helper/grant_repository_linux.go +415 -0
  308. package/templates/native-go/backend/internal/helper/grant_repository_linux_test.go +468 -0
  309. package/templates/native-go/backend/internal/helper/grant_rpc.go +147 -0
  310. package/templates/native-go/backend/internal/helper/grant_rpc_test.go +51 -0
  311. package/templates/native-go/backend/internal/helper/grant_snapshot.go +75 -0
  312. package/templates/native-go/backend/internal/helper/grant_supervisor_linux.go +134 -0
  313. package/templates/native-go/backend/internal/helper/grant_supervisor_linux_test.go +254 -0
  314. package/templates/native-go/backend/internal/helper/lease.go +112 -0
  315. package/templates/native-go/backend/internal/helper/lease_linux.go +44 -0
  316. package/templates/native-go/backend/internal/helper/lease_other.go +8 -0
  317. package/templates/native-go/backend/internal/helper/lifecycle.go +234 -0
  318. package/templates/native-go/backend/internal/helper/lifecycle_test.go +473 -0
  319. package/templates/native-go/backend/internal/helper/managed_pilot.go +284 -0
  320. package/templates/native-go/backend/internal/helper/managed_pilot_repository_linux.go +74 -0
  321. package/templates/native-go/backend/internal/helper/managed_pilot_repository_linux_test.go +40 -0
  322. package/templates/native-go/backend/internal/helper/managed_pilot_test.go +210 -0
  323. package/templates/native-go/backend/internal/helper/nas_shipped_refusal_linux_test.go +97 -0
  324. package/templates/native-go/backend/internal/helper/native_discovery.go +79 -0
  325. package/templates/native-go/backend/internal/helper/native_identity.go +89 -0
  326. package/templates/native-go/backend/internal/helper/native_provider.go +159 -0
  327. package/templates/native-go/backend/internal/helper/native_provider_test.go +421 -0
  328. package/templates/native-go/backend/internal/helper/observation.go +204 -0
  329. package/templates/native-go/backend/internal/helper/observation_health_test.go +115 -0
  330. package/templates/native-go/backend/internal/helper/observation_reload_budget_test.go +117 -0
  331. package/templates/native-go/backend/internal/helper/observation_test.go +196 -0
  332. package/templates/native-go/backend/internal/helper/observer_diagnostic.go +109 -0
  333. package/templates/native-go/backend/internal/helper/observer_diagnostic_linux.go +76 -0
  334. package/templates/native-go/backend/internal/helper/observer_diagnostic_linux_test.go +124 -0
  335. package/templates/native-go/backend/internal/helper/observer_diagnostic_test.go +98 -0
  336. package/templates/native-go/backend/internal/helper/operation_bootstrap_linux.go +193 -0
  337. package/templates/native-go/backend/internal/helper/operation_credentials_linux.go +56 -0
  338. package/templates/native-go/backend/internal/helper/operation_linux.go +480 -0
  339. package/templates/native-go/backend/internal/helper/operation_linux_test.go +528 -0
  340. package/templates/native-go/backend/internal/helper/process_linux.go +11 -1
  341. package/templates/native-go/backend/internal/helper/publication_test.go +178 -0
  342. package/templates/native-go/backend/internal/helper/read_stream_cohort_linux_test.go +156 -0
  343. package/templates/native-go/backend/internal/helper/read_transfer.go +40 -0
  344. package/templates/native-go/backend/internal/helper/read_transfer_linux.go +109 -0
  345. package/templates/native-go/backend/internal/helper/read_transfer_linux_test.go +118 -0
  346. package/templates/native-go/backend/internal/helper/read_transfer_test.go +177 -0
  347. package/templates/native-go/backend/internal/helper/readonly.go +105 -0
  348. package/templates/native-go/backend/internal/helper/readonly_admission.go +85 -0
  349. package/templates/native-go/backend/internal/helper/readonly_cohort_linux_test.go +253 -0
  350. package/templates/native-go/backend/internal/helper/readonly_linux_test.go +378 -0
  351. package/templates/native-go/backend/internal/helper/readonly_mount_linux.go +65 -0
  352. package/templates/native-go/backend/internal/helper/readonly_mount_proxy_linux.go +113 -0
  353. package/templates/native-go/backend/internal/helper/readonly_operations_linux.go +168 -0
  354. package/templates/native-go/backend/internal/helper/readonly_resolver_linux.go +241 -0
  355. package/templates/native-go/backend/internal/helper/readonly_test.go +40 -0
  356. package/templates/native-go/backend/internal/helper/relaxed_identity.go +252 -0
  357. package/templates/native-go/backend/internal/helper/relaxed_identity_contract.go +105 -0
  358. package/templates/native-go/backend/internal/helper/relaxed_identity_test.go +406 -0
  359. package/templates/native-go/backend/internal/helper/relaxed_invalidation.go +200 -0
  360. package/templates/native-go/backend/internal/helper/repair.go +132 -0
  361. package/templates/native-go/backend/internal/helper/repair_test.go +271 -0
  362. package/templates/native-go/backend/internal/helper/s1r_actor_acl_linux_test.go +303 -0
  363. package/templates/native-go/backend/internal/helper/s1r_actor_fixture_linux_test.go +184 -0
  364. package/templates/native-go/backend/internal/helper/s1r_actor_races_linux_test.go +231 -0
  365. package/templates/native-go/backend/internal/helper/s1r_fixture_contract_linux_test.go +18 -0
  366. package/templates/native-go/backend/internal/helper/server_linux.go +44 -3
  367. package/templates/native-go/backend/internal/helper/status.go +74 -11
  368. package/templates/native-go/backend/internal/helper/status_test.go +83 -0
  369. package/templates/native-go/backend/internal/helper/supervision.go +28 -5
  370. package/templates/native-go/backend/internal/helper/supervisor_frame.go +76 -0
  371. package/templates/native-go/backend/internal/helper/supervisor_frame_linux_test.go +69 -0
  372. package/templates/native-go/backend/internal/helper/supervisor_frame_test.go +107 -0
  373. package/templates/native-go/backend/internal/helper/supervisor_linux.go +187 -16
  374. package/templates/native-go/backend/internal/helper/supervisor_linux_test.go +618 -7
  375. package/templates/native-go/backend/internal/helper/supervisor_socket_eof_test.go +74 -0
  376. package/templates/native-go/backend/internal/helper/supervisor_socket_test.go +45 -0
  377. package/templates/native-go/backend/internal/helper/testdata/protocol2/create.json +23 -0
  378. package/templates/native-go/backend/internal/helper/testdata/protocol2/frames.json +67 -0
  379. package/templates/native-go/backend/internal/helper/testdata/protocol2/grant-store.json +52 -0
  380. package/templates/native-go/backend/internal/helper/testdata/protocol2/intent.json +20 -0
  381. package/templates/native-go/backend/internal/helper/testdata/protocol2/list.json +20 -0
  382. package/templates/native-go/backend/internal/helper/testdata/protocol2/publish.json +20 -0
  383. package/templates/native-go/backend/internal/helper/testdata/protocol2/read.json +22 -0
  384. package/templates/native-go/backend/internal/helper/testdata/protocol2/stat.json +22 -0
  385. package/templates/native-go/backend/internal/helper/testdata/protocol2/write-stream.json +22 -0
  386. package/templates/native-go/backend/internal/helper/unit_connection.go +75 -0
  387. package/templates/native-go/backend/internal/helper/unit_connection_linux_test.go +135 -0
  388. package/templates/native-go/backend/internal/helper/unit_connection_test.go +133 -0
  389. package/templates/native-go/backend/internal/helper/unit_frame_test.go +32 -0
  390. package/templates/native-go/backend/internal/helper/unit_linux.go +364 -0
  391. package/templates/native-go/backend/internal/helper/unit_linux_test.go +46 -0
  392. package/templates/native-go/backend/internal/helper/unit_mechanisms_linux_test.go +217 -0
  393. package/templates/native-go/backend/internal/helper/unit_padding_linux_test.go +178 -0
  394. package/templates/native-go/backend/internal/helper/unit_query_linux.go +111 -0
  395. package/templates/native-go/backend/internal/helper/unit_reload_linux_test.go +372 -0
  396. package/templates/native-go/backend/internal/helper/unit_reload_sequence_linux_test.go +232 -0
  397. package/templates/native-go/backend/internal/helper/write.go +77 -0
  398. package/templates/native-go/backend/internal/helper/write_admission.go +260 -0
  399. package/templates/native-go/backend/internal/helper/write_admission_test.go +135 -0
  400. package/templates/native-go/backend/internal/helper/write_cohort_linux_test.go +218 -0
  401. package/templates/native-go/backend/internal/helper/write_files_linux.go +202 -0
  402. package/templates/native-go/backend/internal/helper/write_files_linux_test.go +199 -0
  403. package/templates/native-go/backend/internal/helper/write_intent_linux.go +116 -0
  404. package/templates/native-go/backend/internal/helper/write_intent_linux_test.go +74 -0
  405. package/templates/native-go/backend/internal/helper/write_operation_linux.go +245 -0
  406. package/templates/native-go/backend/internal/helper/write_test.go +53 -0
  407. package/templates/native-go/ui/app.js +8 -1
  408. package/templates/native-go-better-auth/node/build.mjs +2 -0
  409. package/templates/native-go-vue/README.md +115 -1
  410. package/templates/native-go-vue/frontend/DESIGN.md +1 -1
  411. package/templates/native-go-vue/frontend/package-lock.json +132 -229
  412. package/templates/native-go-vue/frontend/package.json +1 -1
  413. package/templates/native-go-vue/frontend/src/App.vue +33 -6
  414. package/templates/native-go-vue/frontend/src/context.ts +41 -2
  415. package/templates/native-go-vue/frontend/src/main.ts +4 -1
  416. package/templates/native-go-vue/frontend/src/nas/NasGrantSettings.vue +74 -0
  417. package/templates/native-go-vue/frontend/src/nas/NasPathPicker.vue +106 -0
  418. package/templates/native-go-vue/frontend/src/nas/NasUnavailable.vue +20 -0
  419. package/templates/native-go-vue/frontend/src/nas/i18n/de.json +74 -0
  420. package/templates/native-go-vue/frontend/src/nas/i18n/en.json +74 -0
  421. package/templates/native-go-vue/frontend/src/nas/i18n/es.json +74 -0
  422. package/templates/native-go-vue/frontend/src/nas/i18n/fr.json +74 -0
  423. package/templates/native-go-vue/frontend/src/nas/i18n/it.json +74 -0
  424. package/templates/native-go-vue/frontend/src/nas/i18n/ja.json +74 -0
  425. package/templates/native-go-vue/frontend/src/nas/i18n/ko.json +74 -0
  426. package/templates/native-go-vue/frontend/src/nas/i18n/zh-CN.json +74 -0
  427. package/templates/native-go-vue/frontend/src/nas/i18n/zh-TW.json +74 -0
  428. package/templates/native-go-vue/frontend/src/nas/i18n.ts +38 -0
  429. package/templates/native-go-vue/frontend/src/nas/mock-provider.ts +119 -0
  430. package/templates/native-go-vue/frontend/src/nas/provider.ts +59 -0
  431. package/templates/native-go-vue/frontend/src/nas/use-request.ts +27 -0
  432. package/templates/native-go-vue/frontend/src/style.css +17 -0
  433. package/templates/native-go-vue/frontend/test/apps.test.ts +44 -2
  434. package/templates/native-go-vue/frontend/test/nas-provider.test.ts +81 -0
  435. package/templates/native-go-vue/frontend/test/nas-request.test.ts +21 -0
  436. package/templates/native-go-vue/frontend/test/nas-ui.test.ts +261 -0
  437. package/templates/native-go-vue/frontend/tsconfig.json +1 -1
  438. package/templates/native-go-vue/frontend/vite.config.ts +6 -4
@@ -0,0 +1,510 @@
1
+ package helper
2
+
3
+ import (
4
+ "bytes"
5
+ "context"
6
+ "encoding/json"
7
+ "math"
8
+ "sync"
9
+ "sync/atomic"
10
+ "testing"
11
+ "time"
12
+ )
13
+
14
+ type memoryGrantRepository struct {
15
+ policy GrantPolicy
16
+ store GrantStore
17
+ fail Code
18
+ qFailure Code
19
+ q GrantQuiescence
20
+ inTransaction bool
21
+ commits int
22
+ }
23
+
24
+ func (r *memoryGrantRepository) SaveQuiescence(q GrantQuiescence) Code {
25
+ r.q = q
26
+ if r.qFailure != "" {
27
+ return r.qFailure
28
+ }
29
+ return r.fail
30
+ }
31
+ func (r *memoryGrantRepository) Transact(fn func(GrantPolicy, *GrantStore) (bool, Code)) Code {
32
+ r.inTransaction = true
33
+ defer func() { r.inTransaction = false }()
34
+ b, _ := json.Marshal(r.store)
35
+ next, c := DecodeGrantStore(bytes.NewReader(b))
36
+ if c != "" {
37
+ return c
38
+ }
39
+ write, c := fn(r.policy, &next)
40
+ if c != "" {
41
+ return c
42
+ }
43
+ if write {
44
+ if r.fail != "" {
45
+ return r.fail
46
+ }
47
+ r.store = next
48
+ r.commits++
49
+ }
50
+ return ""
51
+ }
52
+
53
+ type consentStub struct {
54
+ selection ConsentSelection
55
+ code Code
56
+ after func()
57
+ }
58
+
59
+ func (s *consentStub) ValidateConsent(_ context.Context, _ NativeActor, _ string, _ ScopeKind, _ []Action) (ConsentSelection, Code) {
60
+ if s.after != nil {
61
+ s.after()
62
+ }
63
+ return s.selection, s.code
64
+ }
65
+
66
+ type cohortStub struct {
67
+ drain func(context.Context, GrantDrainKey) (GrantQuiescence, Code)
68
+ }
69
+
70
+ func (s cohortStub) DrainGrant(ctx context.Context, key GrantDrainKey) (GrantQuiescence, Code) {
71
+ return s.drain(ctx, key)
72
+ }
73
+ func completeGrantProof(key GrantDrainKey) GrantQuiescence {
74
+ return GrantQuiescence{Key: key, ChildrenReaped: true, RelayClosed: true, LeasesClosed: true, FDsClosed: true, EffectsRecorded: true}
75
+ }
76
+ func grantAuthorityFixture(t *testing.T) (*GrantAuthority, *memoryGrantRepository, *NativeProvider, *fakeNativeSession, *fakeLocalAccount, *consentStub, SessionCarriers, time.Time) {
77
+ t.Helper()
78
+ p, s, a, carriers, now := nativeFixture()
79
+ store, c := DecodeGrantStore(bytes.NewReader(dataFixture(t, "grant-store")))
80
+ if c != "" {
81
+ t.Fatal(c)
82
+ }
83
+ g := store.Grants[0]
84
+ r := &memoryGrantRepository{policy: GrantPolicy{Inventory: g.Inventory, Epoch: g.LastValidated.Epoch, ApprovalBinding: g.ApprovalBinding, CapabilityDigest: g.CapabilityDigest, Enabled: true}, store: GrantStore{Schema: 1, Revision: 1, Grants: []Grant{}}}
85
+ scope := g.Scope
86
+ scope.Kind = ScopePersonal
87
+ scope.Segments = []string{"chosen"}
88
+ validator := &consentStub{selection: ConsentSelection{Principal: a.value.Principal, SessionRef: s.value.SessionRef, Scope: scope, Binding: g.LastValidated, CheckedAt: now}}
89
+ auth, c := NewGrantAuthority(r, p, validator, cohortStub{func(ctx context.Context, key GrantDrainKey) (GrantQuiescence, Code) {
90
+ return completeGrantProof(key), ""
91
+ }})
92
+ if c != "" {
93
+ t.Fatal(c)
94
+ }
95
+ auth.now = func() time.Time { return now }
96
+ return auth, r, p, s, a, validator, carriers, now
97
+ }
98
+ func prepareGrant(t *testing.T, a *GrantAuthority, c SessionCarriers, kind ScopeKind) Intent {
99
+ t.Helper()
100
+ i, code := a.Prepare(context.Background(), c, grantRef('5'), kind, []Action{ActionRead})
101
+ if code != "" {
102
+ t.Fatal(code)
103
+ }
104
+ return i
105
+ }
106
+ func confirmGrant(t *testing.T, a *GrantAuthority, r *memoryGrantRepository, c SessionCarriers, i Intent) Grant {
107
+ t.Helper()
108
+ g, code := a.Confirm(context.Background(), c, i.ID, i.SummaryDigest, r.store.Revision)
109
+ if code != "" {
110
+ t.Fatal(code)
111
+ }
112
+ return g
113
+ }
114
+ func grantRef(c byte) string { return string(bytes.Repeat([]byte{c}, 64)) }
115
+ func admissionFor(t *testing.T, p *NativeProvider, c SessionCarriers, g Grant) GrantAdmission {
116
+ t.Helper()
117
+ actor, code := p.Resolve(context.Background(), c)
118
+ if code != "" {
119
+ t.Fatal(code)
120
+ }
121
+ return GrantAdmission{Actor: actor, GrantID: g.ID, Revision: g.Revision, Action: ActionRead, Binding: g.LastValidated, Continuous: true}
122
+ }
123
+ func TestGrantAuthorityConsentCASAndReplay(t *testing.T) {
124
+ a, r, _, s, _, v, c, _ := grantAuthorityFixture(t)
125
+ i := prepareGrant(t, a, c, ScopePersonal)
126
+ if _, code := a.Confirm(context.Background(), c, i.ID, grantRef('8'), r.store.Revision); code != ErrDenied {
127
+ t.Fatal(code)
128
+ }
129
+ if _, code := a.Confirm(context.Background(), c, i.ID, i.SummaryDigest, r.store.Revision+1); code != ErrStale {
130
+ t.Fatal(code)
131
+ }
132
+ g := confirmGrant(t, a, r, c, i)
133
+ if g.State != GrantActive || g.Revision != 1 || g.Owner != v.selection.Principal || g.LastValidated != v.selection.Binding || r.store.Revision != 2 || len(r.store.Grants) != 1 || s.calls < 3 {
134
+ t.Fatal("confirm did not durably bind fresh consent")
135
+ }
136
+ if _, code := a.Confirm(context.Background(), c, i.ID, i.SummaryDigest, r.store.Revision); code != ErrReplay {
137
+ t.Fatal(code)
138
+ }
139
+ g.Actions[0] = ActionCreate
140
+ g.Scope.Segments[0] = "mutated"
141
+ if r.store.Grants[0].Actions[0] != ActionRead || r.store.Grants[0].Scope.Segments[0] != "chosen" {
142
+ t.Fatal("mutable authority alias")
143
+ }
144
+ }
145
+ func TestGrantAuthoritySingleWinner(t *testing.T) {
146
+ a, r, _, _, _, _, c, _ := grantAuthorityFixture(t)
147
+ i := prepareGrant(t, a, c, ScopePersonal)
148
+ // The native stubs count calls, so serialize their observations separately.
149
+ _, s, acct, _, now := nativeFixture()
150
+ lock := &sync.Mutex{}
151
+ a.native = NewNativeProvider(lockedSession{lock, s.value}, lockedAccount{lock, acct.value})
152
+ a.native.now = func() time.Time { return now }
153
+ var wins atomic.Int32
154
+ var wg sync.WaitGroup
155
+ for n := 0; n < 16; n++ {
156
+ wg.Add(1)
157
+ go func() {
158
+ defer wg.Done()
159
+ _, code := a.Confirm(context.Background(), c, i.ID, i.SummaryDigest, 1)
160
+ if code == "" {
161
+ wins.Add(1)
162
+ } else if code != ErrReplay && code != ErrStale {
163
+ t.Error(code)
164
+ }
165
+ }()
166
+ }
167
+ wg.Wait()
168
+ if wins.Load() != 1 || len(r.store.Grants) != 1 {
169
+ t.Fatal(wins.Load())
170
+ }
171
+ }
172
+
173
+ type lockedSession struct {
174
+ mu *sync.Mutex
175
+ value NativeSession
176
+ }
177
+
178
+ func (s lockedSession) ValidateSession(context.Context, SessionCarriers) (NativeSession, Code) {
179
+ s.mu.Lock()
180
+ defer s.mu.Unlock()
181
+ return s.value, ""
182
+ }
183
+
184
+ type lockedAccount struct {
185
+ mu *sync.Mutex
186
+ value LocalAccount
187
+ }
188
+
189
+ func (a lockedAccount) LookupLocalAccount(context.Context, string) (LocalAccount, Code) {
190
+ a.mu.Lock()
191
+ defer a.mu.Unlock()
192
+ return a.value, ""
193
+ }
194
+ func TestGrantAuthorityIntentLimitsAndExpiry(t *testing.T) {
195
+ a, r, _, _, _, _, c, now := grantAuthorityFixture(t)
196
+ var first Intent
197
+ for n := 0; n < MaxLiveIntents; n++ {
198
+ i := prepareGrant(t, a, c, ScopePersonal)
199
+ if n == 0 {
200
+ first = i
201
+ }
202
+ }
203
+ if _, code := a.Prepare(context.Background(), c, grantRef('5'), ScopePersonal, []Action{ActionRead}); code != ErrBusy {
204
+ t.Fatal(code)
205
+ }
206
+ a.now = func() time.Time { return now.Add(IntentTTL) }
207
+ if _, code := a.Confirm(context.Background(), c, first.ID, first.SummaryDigest, r.store.Revision); code != ErrExpired {
208
+ t.Fatal(code)
209
+ }
210
+ if len(r.store.Grants) != 0 {
211
+ t.Fatal("expired intent wrote authority")
212
+ }
213
+ }
214
+ func TestGrantAuthorityFreshRoleScopeAndSession(t *testing.T) {
215
+ tests := []struct {
216
+ name string
217
+ change func(*GrantAuthority, *memoryGrantRepository, *fakeNativeSession, *fakeLocalAccount, *consentStub)
218
+ want Code
219
+ }{
220
+ {"session", func(_ *GrantAuthority, _ *memoryGrantRepository, s *fakeNativeSession, _ *fakeLocalAccount, _ *consentStub) {
221
+ s.value.SessionRef = grantRef('9')
222
+ }, ErrStale},
223
+ {"disabled account", func(_ *GrantAuthority, _ *memoryGrantRepository, _ *fakeNativeSession, acct *fakeLocalAccount, _ *consentStub) {
224
+ acct.value.Enabled = false
225
+ }, ErrDenied},
226
+ {"scope replacement", func(_ *GrantAuthority, _ *memoryGrantRepository, _ *fakeNativeSession, _ *fakeLocalAccount, v *consentStub) {
227
+ v.selection.Scope.ObjectRef = grantRef('9')
228
+ }, ErrStale},
229
+ {"unknown proof", func(_ *GrantAuthority, _ *memoryGrantRepository, _ *fakeNativeSession, _ *fakeLocalAccount, v *consentStub) {
230
+ v.selection.Binding.ScopeProof = ""
231
+ }, ErrSuspended},
232
+ {"ACL denial", func(_ *GrantAuthority, _ *memoryGrantRepository, _ *fakeNativeSession, _ *fakeLocalAccount, v *consentStub) {
233
+ v.code = ErrDenied
234
+ }, ErrDenied},
235
+ {"approval changed", func(_ *GrantAuthority, r *memoryGrantRepository, _ *fakeNativeSession, _ *fakeLocalAccount, _ *consentStub) {
236
+ r.policy.ApprovalBinding = grantRef('9')
237
+ }, ErrFenced},
238
+ {"new epoch", func(_ *GrantAuthority, r *memoryGrantRepository, _ *fakeNativeSession, _ *fakeLocalAccount, _ *consentStub) {
239
+ r.policy.Epoch = grantRef('9')
240
+ }, ErrFenced},
241
+ {"role removed", func(_ *GrantAuthority, _ *memoryGrantRepository, _ *fakeNativeSession, acct *fakeLocalAccount, _ *consentStub) {
242
+ acct.value.Admin = false
243
+ }, ErrStale},
244
+ }
245
+ for _, tt := range tests {
246
+ t.Run(tt.name, func(t *testing.T) {
247
+ a, r, _, s, acct, v, c, _ := grantAuthorityFixture(t)
248
+ v.selection.Scope.Kind = ScopeShared
249
+ i := prepareGrant(t, a, c, ScopeShared)
250
+ tt.change(a, r, s, acct, v)
251
+ if _, code := a.Confirm(context.Background(), c, i.ID, i.SummaryDigest, r.store.Revision); code != tt.want {
252
+ t.Fatalf("%q want %q", code, tt.want)
253
+ }
254
+ if len(r.store.Grants) != 0 {
255
+ t.Fatal("invalid confirm persisted")
256
+ }
257
+ })
258
+ }
259
+ a, _, _, _, acct, v, c, _ := grantAuthorityFixture(t)
260
+ acct.value.Admin = false
261
+ v.selection.Scope.Kind = ScopeShared
262
+ if _, code := a.Prepare(context.Background(), c, grantRef('5'), ScopeShared, []Action{ActionRead}); code != ErrDenied {
263
+ t.Fatal(code)
264
+ }
265
+ }
266
+ func TestGrantAuthorityFenceWinsConfirmOutsideIO(t *testing.T) {
267
+ a, r, _, _, _, v, c, _ := grantAuthorityFixture(t)
268
+ i := prepareGrant(t, a, c, ScopePersonal)
269
+ v.after = func() { a.Fence() }
270
+ if _, code := a.Confirm(context.Background(), c, i.ID, i.SummaryDigest, r.store.Revision); code != ErrFenced {
271
+ t.Fatal(code)
272
+ }
273
+ if len(r.store.Grants) != 0 {
274
+ t.Fatal("fence lost to confirm")
275
+ }
276
+ }
277
+ func TestGrantAuthorityRevokeRBeforeQAndIndividual(t *testing.T) {
278
+ a, r, p, _, _, _, c, _ := grantAuthorityFixture(t)
279
+ one := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
280
+ two := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
281
+ admitted := admissionFor(t, p, c, one)
282
+ other := admissionFor(t, p, c, two)
283
+ entered := make(chan GrantDrainKey, 1)
284
+ release := make(chan struct{})
285
+ a.cohort = cohortStub{func(ctx context.Context, k GrantDrainKey) (GrantQuiescence, Code) {
286
+ entered <- k
287
+ <-release
288
+ return completeGrantProof(k), ""
289
+ }}
290
+ type outcome struct {
291
+ r RevokeResult
292
+ c Code
293
+ }
294
+ done := make(chan outcome, 1)
295
+ go func() {
296
+ result, code := a.Revoke(context.Background(), c, one.ID, one.Revision, 3)
297
+ done <- outcome{result, code}
298
+ }()
299
+ key := <-entered
300
+ if r.store.Grants[0].State != GrantRevoked || r.store.Revision != 4 || key.Revision != 2 {
301
+ t.Fatal("drain before durable R")
302
+ }
303
+ if code := a.WithGrantAdmission(admitted, func(Grant, NativeActor) Code { t.Fatal("admitted after R"); return "" }); code != ErrRevoked {
304
+ t.Fatal(code)
305
+ }
306
+ if code := a.WithGrantAdmission(other, func(Grant, NativeActor) Code { return "" }); code != "" {
307
+ t.Fatal("unrelated grant stopped", code)
308
+ }
309
+ close(release)
310
+ result := <-done
311
+ if result.c != "" || !result.r.Revoked || !result.r.Drained || result.r.Revision != 2 {
312
+ t.Fatal(result)
313
+ }
314
+ if _, code := a.Revoke(context.Background(), c, one.ID, 1, 3); code != ErrStale {
315
+ t.Fatal("CAS replay", code)
316
+ }
317
+ }
318
+ func TestGrantAuthorityQuiescenceRequiresEveryProof(t *testing.T) {
319
+ for _, part := range []string{"children", "relay", "leases", "fds", "effects", "binding", "timeout", "nil"} {
320
+ t.Run(part, func(t *testing.T) {
321
+ a, r, _, _, _, _, c, _ := grantAuthorityFixture(t)
322
+ g := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
323
+ a.cohort = cohortStub{func(ctx context.Context, k GrantDrainKey) (GrantQuiescence, Code) {
324
+ if _, ok := ctx.Deadline(); !ok {
325
+ t.Fatal("no drain deadline")
326
+ }
327
+ q := completeGrantProof(k)
328
+ switch part {
329
+ case "children":
330
+ q.ChildrenReaped = false
331
+ case "relay":
332
+ q.RelayClosed = false
333
+ case "leases":
334
+ q.LeasesClosed = false
335
+ case "fds":
336
+ q.FDsClosed = false
337
+ case "effects":
338
+ q.EffectsRecorded = false
339
+ case "binding":
340
+ q.Key.Epoch = grantRef('9')
341
+ case "timeout":
342
+ return q, ErrTimeout
343
+ }
344
+ return q, ""
345
+ }}
346
+ if part == "nil" {
347
+ a.cohort = nil
348
+ }
349
+ result, code := a.Revoke(context.Background(), c, g.ID, 1, 2)
350
+ if !result.Revoked || result.Drained || code != ErrCleanupRequired || r.store.Grants[0].State != GrantRevoked {
351
+ t.Fatalf("false Q: %#v %q", result, code)
352
+ }
353
+ // Idempotent status/drain retry requires CURRENT CAS and cannot un-revoke.
354
+ a.cohort = cohortStub{func(ctx context.Context, k GrantDrainKey) (GrantQuiescence, Code) { return completeGrantProof(k), "" }}
355
+ result, code = a.Revoke(context.Background(), c, g.ID, 2, 3)
356
+ if code != "" || !result.Drained || r.store.Revision != 3 {
357
+ t.Fatal(result, code)
358
+ }
359
+ })
360
+ }
361
+ }
362
+ func TestGrantAuthorityCommitFailureNeverReportsR(t *testing.T) {
363
+ for _, failure := range []Code{ErrUnavailable, ErrCommitUncertain} {
364
+ t.Run(string(failure), func(t *testing.T) {
365
+ a, r, p, _, _, _, c, _ := grantAuthorityFixture(t)
366
+ g := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
367
+ admission := admissionFor(t, p, c, g)
368
+ r.fail = failure
369
+ result, code := a.Revoke(context.Background(), c, g.ID, 1, 2)
370
+ if result.Revoked || result.Drained || code != failure {
371
+ t.Fatal(result, code)
372
+ }
373
+ if code = a.WithGrantAdmission(admission, func(Grant, NativeActor) Code { t.Fatal("new admission after failed R"); return "" }); code != ErrFenced {
374
+ t.Fatal(code)
375
+ }
376
+ })
377
+ }
378
+ }
379
+ func TestGrantAuthorityRestartAndUnknownContinuitySuspend(t *testing.T) {
380
+ a, r, p, _, _, v, c, _ := grantAuthorityFixture(t)
381
+ g := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
382
+ admission := admissionFor(t, p, c, g)
383
+ admission.Continuous = false
384
+ if code := a.WithGrantAdmission(admission, func(Grant, NativeActor) Code { t.Fatal("unknown continuity"); return "" }); code != ErrSuspended {
385
+ t.Fatal(code)
386
+ }
387
+ if r.store.Grants[0].State != GrantSuspended || r.store.Grants[0].Revision != 2 {
388
+ t.Fatal("suspension not durable")
389
+ }
390
+ admission.Continuous = true
391
+ admission.Revision = 2
392
+ if code := a.WithGrantAdmission(admission, func(Grant, NativeActor) Code { return "" }); code != ErrSuspended {
393
+ t.Fatal("auto unsuspend", code)
394
+ }
395
+ fresh := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
396
+ if fresh.ID == g.ID {
397
+ t.Fatal("ID reuse")
398
+ }
399
+ // Opening authority ALWAYS suspends active records, even identical epoch.
400
+ reopened, code := NewGrantAuthority(r, p, v, a.cohort)
401
+ if code != "" {
402
+ t.Fatal(code)
403
+ }
404
+ reopened.now = a.now
405
+ if r.store.Grants[1].State != GrantSuspended {
406
+ t.Fatal("restored active grant")
407
+ }
408
+ // Revoked tombstones survive both reconciliation and reconsent.
409
+ if _, code := reopened.Revoke(context.Background(), c, g.ID, 2, r.store.Revision); code != "" {
410
+ t.Fatal(code)
411
+ }
412
+ _, code = NewGrantAuthority(r, p, v, a.cohort)
413
+ if code != "" || r.store.Grants[0].State != GrantRevoked {
414
+ t.Fatal("tombstone resurrected", code)
415
+ }
416
+ }
417
+ func TestGrantAuthorityBoundsAndAuthorization(t *testing.T) {
418
+ a, r, p, s, acct, v, c, _ := grantAuthorityFixture(t)
419
+ g := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
420
+ acct.value.Admin = false
421
+ acct.value.Principal.SubjectRef = grantRef('9')
422
+ acct.value.Principal.InstanceRef = grantRef('8')
423
+ s.value.AccountInstanceRef = acct.value.Principal.InstanceRef
424
+ if _, code := a.Revoke(context.Background(), c, g.ID, 1, 2); code != ErrDenied {
425
+ t.Fatal("other person revoked", code)
426
+ }
427
+ admission := admissionFor(t, p, c, g)
428
+ if code := a.WithGrantAdmission(admission, func(Grant, NativeActor) Code { t.Fatal("other person's data"); return "" }); code != ErrDenied {
429
+ t.Fatal(code)
430
+ }
431
+ acct.value.Admin = true
432
+ if result, code := a.Revoke(context.Background(), c, g.ID, 1, 2); code != "" || !result.Revoked {
433
+ t.Fatal("admin safe revoke", code)
434
+ }
435
+ v.selection.Principal = acct.value.Principal
436
+ v.selection.SessionRef = s.value.SessionRef
437
+ // Tombstones occupy the cap and never get evicted for new consent.
438
+ original := r.store.Grants[0]
439
+ for len(r.store.Grants) < MaxGrants {
440
+ n := original
441
+ n.ID = uniqueGrantTestID(len(r.store.Grants))
442
+ r.store.Grants = append(r.store.Grants, n)
443
+ }
444
+ if _, code := a.Confirm(context.Background(), c, prepareGrant(t, a, c, ScopePersonal).ID, grantRef('9'), r.store.Revision); code != ErrDenied {
445
+ t.Fatal(code)
446
+ }
447
+ i := prepareGrant(t, a, c, ScopePersonal)
448
+ if _, code := a.Confirm(context.Background(), c, i.ID, i.SummaryDigest, r.store.Revision); code != ErrLimit {
449
+ t.Fatal("cap", code)
450
+ }
451
+ r.store.Grants = r.store.Grants[:1]
452
+ r.store.Revision = math.MaxUint64
453
+ i = prepareGrant(t, a, c, ScopePersonal)
454
+ if _, code := a.Confirm(context.Background(), c, i.ID, i.SummaryDigest, r.store.Revision); code != ErrLimit {
455
+ t.Fatal("revision overflow", code)
456
+ }
457
+ }
458
+ func uniqueGrantTestID(n int) string {
459
+ b := make([]byte, 32)
460
+ b[0] = byte(n)
461
+ b[1] = byte(n >> 8)
462
+ const digits = "0123456789abcdef"
463
+ out := make([]byte, 64)
464
+ for i, v := range b {
465
+ out[i*2] = digits[v>>4]
466
+ out[i*2+1] = digits[v&15]
467
+ }
468
+ return string(out)
469
+ }
470
+
471
+ func TestGrantAuthorityFailedSuspensionLatchesDeny(t *testing.T) {
472
+ for _, failure := range []string{"overflow", "size", "disk"} {
473
+ t.Run(failure, func(t *testing.T) {
474
+ a, r, p, _, _, _, c, _ := grantAuthorityFixture(t)
475
+ g := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
476
+ proof := admissionFor(t, p, c, g)
477
+ proof.Continuous = false
478
+ switch failure {
479
+ case "overflow":
480
+ r.store.Revision = math.MaxUint64
481
+ case "size":
482
+ r.fail = ErrLimit
483
+ case "disk":
484
+ r.fail = ErrUnavailable
485
+ }
486
+ if code := a.WithGrantAdmission(proof, func(Grant, NativeActor) Code { t.Fatal("unknown continuity admitted"); return "" }); code == "" {
487
+ t.Fatal("suspension failure succeeded")
488
+ }
489
+ proof.Continuous = true
490
+ r.fail = ""
491
+ if code := a.WithGrantAdmission(proof, func(Grant, NativeActor) Code { t.Fatal("failed suspension resurrected"); return "" }); code != ErrFenced {
492
+ t.Fatal(code)
493
+ }
494
+ })
495
+ }
496
+ }
497
+ func TestGrantAuthorityBusyQDoesNotStopOtherGrants(t *testing.T) {
498
+ a, r, p, _, _, _, c, _ := grantAuthorityFixture(t)
499
+ one := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
500
+ two := confirmGrant(t, a, r, c, prepareGrant(t, a, c, ScopePersonal))
501
+ proof := admissionFor(t, p, c, two)
502
+ r.qFailure = ErrBusy
503
+ result, code := a.Revoke(context.Background(), c, one.ID, 1, 3)
504
+ if code != ErrCleanupRequired || !result.Revoked || result.Drained {
505
+ t.Fatal(result, code)
506
+ }
507
+ if code := a.WithGrantAdmission(proof, func(Grant, NativeActor) Code { return "" }); code != "" {
508
+ t.Fatal("Q lock contention stopped unrelated grant", code)
509
+ }
510
+ }