@synopackageland/cli 0.6.1 → 0.7.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 (578) hide show
  1. package/CHANGELOG.md +613 -0
  2. package/README.md +81 -89
  3. package/dist/add.js +39 -16
  4. package/dist/build-spk/delegate-scope.d.ts +6 -0
  5. package/dist/build-spk/delegate-scope.js +34 -0
  6. package/dist/build-spk/dsm-arch.d.ts +7 -1
  7. package/dist/build-spk/dsm-arch.js +24 -28
  8. package/dist/build-spk/dsm-platforms.json +39 -0
  9. package/dist/build-spk/dsm-version.d.ts +11 -0
  10. package/dist/build-spk/dsm-version.js +17 -0
  11. package/dist/build-spk/gateway.d.ts +1 -1
  12. package/dist/build-spk/gateway.js +2 -2
  13. package/dist/build-spk/generator.js +30 -5
  14. package/dist/build-spk/notices.js +4 -1
  15. package/dist/build-spk/resource-worker.js +3 -0
  16. package/dist/build-spk/wizard-messages.d.ts +66 -0
  17. package/dist/build-spk/wizard-messages.js +75 -9
  18. package/dist/cli.js +15 -7
  19. package/dist/contract/schema-validate.js +8 -0
  20. package/dist/contract/validate.js +30 -0
  21. package/dist/deploy/deploy.d.ts +1 -1
  22. package/dist/deploy/deploy.js +8 -0
  23. package/dist/deploy/plan.js +1 -1
  24. package/dist/deploy/spk-version.js +1 -1
  25. package/dist/error-registry.js +43 -15
  26. package/dist/host/dsm-client.d.ts +8 -4
  27. package/dist/host/dsm-client.js +10 -4
  28. package/dist/host/types.d.ts +2 -1
  29. package/dist/info.js +18 -2
  30. package/dist/init.d.ts +3 -0
  31. package/dist/init.js +49 -18
  32. package/dist/package-metadata.d.ts +21 -0
  33. package/dist/package-metadata.js +101 -0
  34. package/dist/portal/alias.d.ts +25 -0
  35. package/dist/portal/alias.js +48 -0
  36. package/dist/portal/package.d.ts +33 -0
  37. package/dist/portal/package.js +116 -0
  38. package/dist/runtime/delegate-contract.d.ts +79 -0
  39. package/dist/runtime/delegate-contract.js +27 -0
  40. package/dist/runtime/executor-build.d.ts +1 -1
  41. package/dist/runtime/executor-build.js +5 -4
  42. package/dist/runtime/executor-inspect.d.ts +3 -0
  43. package/dist/runtime/executor-inspect.js +11 -5
  44. package/dist/runtime/executor-policy.d.ts +12 -0
  45. package/dist/runtime/executor-policy.js +43 -3
  46. package/dist/runtime/executor-scope-task.d.ts +4 -0
  47. package/dist/runtime/executor-scope-task.js +21 -0
  48. package/dist/runtime/executor-tasks.d.ts +2 -1
  49. package/dist/runtime/executor-tasks.js +4 -4
  50. package/dist/skill.js +1 -0
  51. package/dist/standalone/api-permissions.d.ts +10 -0
  52. package/dist/standalone/api-permissions.js +19 -2
  53. package/dist/standalone/background.d.ts +16 -0
  54. package/dist/standalone/background.js +69 -2
  55. package/dist/standalone/binary.d.ts +1 -1
  56. package/dist/standalone/binary.js +22 -8
  57. package/dist/standalone/build.d.ts +1 -1
  58. package/dist/standalone/build.js +38 -8
  59. package/dist/standalone/daemon.d.ts +1 -1
  60. package/dist/standalone/daemon.js +2 -1
  61. package/dist/standalone/dsm-window.d.ts +3 -1
  62. package/dist/standalone/dsm-window.js +72 -15
  63. package/dist/standalone/inspect-spk.d.ts +8 -0
  64. package/dist/standalone/inspect-spk.js +105 -26
  65. package/dist/standalone/lifecycle.js +86 -8
  66. package/dist/standalone/manifest.d.ts +13 -0
  67. package/dist/standalone/manifest.js +57 -8
  68. package/dist/standalone/native-authorization-window.d.ts +1 -1
  69. package/dist/standalone/native-authorization-window.js +2 -0
  70. package/dist/standalone/native-layout.d.ts +3 -0
  71. package/dist/standalone/native-layout.js +37 -5
  72. package/dist/standalone/portal-window.d.ts +21 -0
  73. package/dist/standalone/portal-window.js +155 -0
  74. package/dist/standalone/portal.d.ts +4 -0
  75. package/dist/standalone/portal.js +4 -0
  76. package/dist/standalone/resource.d.ts +5 -3
  77. package/dist/standalone/resource.js +6 -3
  78. package/dist/standalone/root-window.js +62 -15
  79. package/dist/standalone/spk.d.ts +1 -1
  80. package/dist/standalone/spk.js +25 -7
  81. package/dist/templates/_daemon/main_test.go +61 -8
  82. package/dist/templates/_executor/README.md +127 -16
  83. package/dist/templates/_executor/anchor.go +146 -0
  84. package/dist/templates/_executor/anchor_test.go +126 -0
  85. package/dist/templates/_executor/apppriv_review_test.go +1 -1
  86. package/dist/templates/_executor/cancel_contract_test.go +236 -0
  87. package/dist/templates/_executor/copy.go +64 -0
  88. package/dist/templates/_executor/copy_test.go +88 -0
  89. package/dist/templates/_executor/dsm.go +23 -10
  90. package/dist/templates/_executor/dsm_test.go +95 -1
  91. package/dist/templates/_executor/executor.go +260 -49
  92. package/dist/templates/_executor/executor_test.go +36 -6
  93. package/dist/templates/_executor/identity.go +27 -1
  94. package/dist/templates/_executor/identity_kernel_linux_test.go +60 -0
  95. package/dist/templates/_executor/identity_linux.go +82 -0
  96. package/dist/templates/_executor/identity_security_test.go +43 -0
  97. package/dist/templates/_executor/internal/lifecycle/lifecycle.go +5 -0
  98. package/dist/templates/_executor/internal/lifecycle/lifecycle_test.go +61 -3
  99. package/dist/templates/_executor/internal/taskscript/boot.sh +9 -9
  100. package/dist/templates/_executor/internal/taskscript/cmd/main.go +2 -2
  101. package/dist/templates/_executor/internal/taskscript/control.sh +15 -10
  102. package/dist/templates/_executor/internal/taskscript/tasks.go +5 -3
  103. package/dist/templates/_executor/lifecycle_test.go +11 -0
  104. package/dist/templates/_executor/link_linux.go +28 -0
  105. package/dist/templates/_executor/long_running_test.go +530 -0
  106. package/dist/templates/_executor/main.go +72 -20
  107. package/dist/templates/_executor/move_linux.go +490 -0
  108. package/dist/templates/_executor/move_linux_test.go +460 -0
  109. package/dist/templates/_executor/move_validation.go +46 -0
  110. package/dist/templates/_executor/move_validation_test.go +187 -0
  111. package/dist/templates/_executor/operations.go +926 -0
  112. package/dist/templates/_executor/platform_linux.go +24 -173
  113. package/dist/templates/_executor/platform_linux_test.go +9 -65
  114. package/dist/templates/_executor/platform_other.go +30 -4
  115. package/dist/templates/_executor/process.go +3 -0
  116. package/dist/templates/_executor/records.go +242 -0
  117. package/dist/templates/_executor/scope_cancel_contract_test.go +91 -0
  118. package/dist/templates/_executor/scope_client.go +37 -0
  119. package/dist/templates/_executor/scope_contract.go +12 -0
  120. package/dist/templates/_executor/selected_scope.go +146 -0
  121. package/dist/templates/_executor/selected_scope_test.go +186 -0
  122. package/dist/templates/_executor/status_disabled_test.go +33 -0
  123. package/dist/templates/_executor/store.go +4 -3
  124. package/dist/templates/_executor/supervise.go +109 -0
  125. package/dist/templates/_executor/supervise_test.go +130 -0
  126. package/dist/templates/_executor/task_race_review_test.go +1 -1
  127. package/dist/templates/_executor/tasks.go +7 -8
  128. package/dist/templates/_executor/tasks_review_test.go +1 -1
  129. package/dist/templates/_executor/tasks_test.go +4 -4
  130. package/dist/templates/_executor/watch.go +8 -0
  131. package/dist/templates/_executor/watch_test.go +23 -2
  132. package/dist/templates/_executor/write_review_linux_test.go +4 -12
  133. package/dist/templates/_shared/AGENTS.md +129 -0
  134. package/dist/templates/binary/dsm-package.yaml +24 -0
  135. package/dist/templates/binary/i18n/messages/de.json +4 -0
  136. package/dist/templates/binary/i18n/messages/en.json +4 -0
  137. package/dist/templates/binary/i18n/messages/es.json +4 -0
  138. package/dist/templates/binary/i18n/messages/fr.json +4 -0
  139. package/dist/templates/binary/i18n/messages/it.json +4 -0
  140. package/dist/templates/binary/i18n/messages/ja.json +4 -0
  141. package/dist/templates/binary/i18n/messages/ko.json +4 -0
  142. package/dist/templates/binary/i18n/messages/zh-CN.json +4 -0
  143. package/dist/templates/binary/i18n/messages/zh-TW.json +4 -0
  144. package/dist/templates/binary/ui/app.js +19 -4
  145. package/dist/templates/native-authorization/AuthorizationGate.vue +5 -3
  146. package/dist/templates/native-authorization/i18n/de.json +1 -0
  147. package/dist/templates/native-authorization/i18n/en.json +1 -0
  148. package/dist/templates/native-authorization/i18n/es.json +2 -1
  149. package/dist/templates/native-authorization/i18n/fr.json +1 -0
  150. package/dist/templates/native-authorization/i18n/it.json +11 -10
  151. package/dist/templates/native-authorization/i18n/ja.json +1 -0
  152. package/dist/templates/native-authorization/i18n/ko.json +10 -9
  153. package/dist/templates/native-authorization/i18n/zh-CN.json +6 -5
  154. package/dist/templates/native-authorization/i18n/zh-TW.json +6 -5
  155. package/dist/templates/native-go/README.md +43 -10
  156. package/dist/templates/native-go/backend/cmd/app/main.go +27 -7
  157. package/dist/templates/native-go/backend/internal/api/entry_test.go +47 -0
  158. package/dist/templates/native-go/backend/internal/api/permissions_test.go +3 -3
  159. package/dist/templates/native-go/backend/internal/api/registry.go +11 -0
  160. package/dist/templates/native-go/backend/internal/api/sdk-permissions.json +14 -1
  161. package/dist/templates/native-go/backend/internal/api/server.go +18 -5
  162. package/dist/templates/native-go/backend/internal/app/delegate_config.go +57 -0
  163. package/dist/templates/native-go/backend/internal/app/delegate_config_test.go +28 -0
  164. package/dist/templates/native-go/backend/internal/app/portal.go +30 -0
  165. package/dist/templates/native-go/backend/internal/app/portal_test.go +55 -0
  166. package/dist/templates/native-go/backend/internal/app/routes.go +8 -2
  167. package/dist/templates/native-go/backend/internal/background/runner.go +1 -1
  168. package/dist/templates/native-go/backend/internal/background/store.go +16 -14
  169. package/dist/templates/native-go/backend/internal/dsm/admin.go +8 -2
  170. package/dist/templates/native-go/backend/internal/dsm/admin_linux.go +43 -13
  171. package/dist/templates/native-go/backend/internal/dsm/admin_linux_test.go +56 -0
  172. package/dist/templates/native-go/backend/internal/dsm/admin_other.go +4 -1
  173. package/dist/templates/native-go/backend/internal/dsm/apppriv.go +30 -0
  174. package/dist/templates/native-go/backend/internal/dsm/bridge_file.go +75 -0
  175. package/dist/templates/native-go/backend/internal/dsm/bridge_file_test.go +57 -0
  176. package/dist/templates/native-go/backend/internal/dsm/entry.go +177 -0
  177. package/dist/templates/native-go/backend/internal/dsm/entry_test.go +315 -0
  178. package/dist/templates/native-go/backend/internal/dsm/native/admin-armv7.elf +0 -0
  179. package/dist/templates/native-go/backend/internal/dsm/native/apppriv-aarch64.elf +0 -0
  180. package/dist/templates/native-go/backend/internal/dsm/native/apppriv-armv7.elf +0 -0
  181. package/dist/templates/native-go/backend/internal/dsm/native/apppriv-x86_64.elf +0 -0
  182. package/dist/templates/native-go/backend/internal/dsm/native/apppriv_check.c +33 -0
  183. package/dist/templates/native-go/backend/internal/dsm/native/build.sh +13 -4
  184. package/dist/templates/native-go/backend/internal/dsm/native/provenance.json +9 -3
  185. package/dist/templates/native-go/backend/internal/filestation/check_permission.go +71 -0
  186. package/dist/templates/native-go/backend/internal/filestation/check_permission_test.go +77 -0
  187. package/dist/templates/native-go/backend/internal/filestation/sdk_policy_test.go +39 -0
  188. package/dist/templates/native-go/backend/internal/filestation/service.go +1 -1
  189. package/dist/templates/native-go/backend/internal/portal/portal.go +138 -0
  190. package/dist/templates/native-go/backend/internal/portal/portal_test.go +89 -0
  191. package/dist/templates/native-go/dsm-package.yaml +20 -1
  192. package/dist/templates/native-go/i18n/glossary.json +2 -1
  193. package/dist/templates/native-go/i18n/messages/de.json +1 -0
  194. package/dist/templates/native-go/i18n/messages/en.json +1 -0
  195. package/dist/templates/native-go/i18n/messages/es.json +1 -0
  196. package/dist/templates/native-go/i18n/messages/fr.json +1 -0
  197. package/dist/templates/native-go/i18n/messages/it.json +1 -0
  198. package/dist/templates/native-go/i18n/messages/ja.json +1 -0
  199. package/dist/templates/native-go/i18n/messages/ko.json +1 -0
  200. package/dist/templates/native-go/i18n/messages/zh-CN.json +1 -0
  201. package/dist/templates/native-go/i18n/messages/zh-TW.json +1 -0
  202. package/dist/templates/native-go/ui/app.css +10 -0
  203. package/dist/templates/native-go/ui/app.js +11 -1
  204. package/dist/templates/native-go-delegate/DELEGATE.md +126 -5
  205. package/dist/templates/native-go-delegate/backend/cmd/background-worker/main.go +7 -0
  206. package/dist/templates/native-go-delegate/backend/internal/app/delegate.go +11 -1
  207. package/dist/templates/native-go-delegate/backend/internal/app/delegate_routes_test.go +14 -0
  208. package/dist/templates/native-go-delegate/backend/internal/background/delegated_moves.go +270 -0
  209. package/dist/templates/native-go-delegate/backend/internal/delegate/admission_recovery_test.go +410 -0
  210. package/dist/templates/native-go-delegate/backend/internal/delegate/cancel_contract_test.go +95 -0
  211. package/dist/templates/native-go-delegate/backend/internal/delegate/client.go +8 -0
  212. package/dist/templates/native-go-delegate/backend/internal/delegate/destination.go +110 -0
  213. package/dist/templates/native-go-delegate/backend/internal/delegate/destination_state.go +117 -0
  214. package/dist/templates/native-go-delegate/backend/internal/delegate/destination_state_test.go +60 -0
  215. package/dist/templates/native-go-delegate/backend/internal/delegate/destination_test.go +116 -0
  216. package/dist/templates/native-go-delegate/backend/internal/delegate/example.go +81 -0
  217. package/dist/templates/native-go-delegate/backend/internal/delegate/example_test.go +91 -0
  218. package/dist/templates/native-go-delegate/backend/internal/delegate/executor_contract_test.go +511 -0
  219. package/dist/templates/native-go-delegate/backend/internal/delegate/files.go +1 -1
  220. package/dist/templates/native-go-delegate/backend/internal/delegate/long_running_routes.go +92 -0
  221. package/dist/templates/native-go-delegate/backend/internal/delegate/long_running_routes_test.go +99 -0
  222. package/dist/templates/native-go-delegate/backend/internal/delegate/move.go +348 -0
  223. package/dist/templates/native-go-delegate/backend/internal/delegate/move_test.go +351 -0
  224. package/dist/templates/native-go-delegate/backend/internal/delegate/operations_list.go +65 -0
  225. package/dist/templates/native-go-delegate/backend/internal/delegate/operations_list_test.go +114 -0
  226. package/dist/templates/native-go-delegate/backend/internal/delegate/retry_test.go +1 -1
  227. package/dist/templates/native-go-delegate/backend/internal/delegate/service.go +58 -17
  228. package/dist/templates/native-go-delegate/backend/internal/delegate/staging.go +121 -0
  229. package/dist/templates/native-go-delegate/backend/internal/delegate/status_disabled_test.go +51 -0
  230. package/dist/templates/native-go-delegate/backend/internal/delegate/testdata/executor_contract.txt +112 -0
  231. package/dist/templates/native-go-delegate/backend/internal/delegate/transient_contract_test.go +137 -0
  232. package/dist/templates/native-go-delegate/backend/internal/filestation/files.go +1 -31
  233. package/dist/templates/native-go-delegate/frontend/src/CapabilityPanels.vue +30 -3
  234. package/dist/templates/native-go-delegate/frontend/src/delegate/BackgroundSavePanel.vue +113 -0
  235. package/dist/templates/native-go-delegate/frontend/src/delegate/copy.ts +5 -6
  236. package/dist/templates/native-go-delegate/frontend/test/background-save.test.ts +121 -0
  237. package/dist/templates/native-go-delegate/frontend/test/scope-settings.test.ts +49 -0
  238. package/dist/templates/native-go-delegate/test.sh +1 -0
  239. package/dist/templates/native-go-jobs/frontend/src/background/i18n/de.json +2 -2
  240. package/dist/templates/native-go-jobs/frontend/src/background/i18n/en.json +2 -2
  241. package/dist/templates/native-go-jobs/frontend/src/background/i18n/es.json +12 -12
  242. package/dist/templates/native-go-jobs/frontend/src/background/i18n/fr.json +4 -4
  243. package/dist/templates/native-go-jobs/frontend/src/background/i18n/it.json +17 -17
  244. package/dist/templates/native-go-jobs/frontend/src/background/i18n/ja.json +7 -7
  245. package/dist/templates/native-go-jobs/frontend/src/background/i18n/ko.json +15 -15
  246. package/dist/templates/native-go-jobs/frontend/src/background/i18n/zh-CN.json +3 -3
  247. package/dist/templates/native-go-jobs/frontend/src/background/i18n/zh-TW.json +2 -2
  248. package/dist/templates/native-go-jobs/frontend/test/background.test.ts +25 -28
  249. package/dist/templates/native-go-vue/README.md +4 -0
  250. package/dist/templates/native-go-vue/frontend/package-lock.json +4 -4
  251. package/dist/templates/native-go-vue/frontend/package.json +1 -1
  252. package/dist/templates/native-go-vue/frontend/src/App.vue +18 -13
  253. package/dist/templates/native-go-vue/frontend/src/context.ts +31 -0
  254. package/dist/templates/native-go-vue/frontend/src/delegate/ExecutorSettings.vue +52 -8
  255. package/dist/templates/native-go-vue/frontend/src/delegate/catalogs.ts +11 -0
  256. package/dist/templates/native-go-vue/frontend/src/delegate/copy.test.ts +12 -0
  257. package/dist/templates/native-go-vue/frontend/src/delegate/copy.ts +4 -4
  258. package/dist/templates/native-go-vue/frontend/src/delegate/executor-setup.ts +4 -2
  259. package/dist/templates/native-go-vue/frontend/src/delegate/facade.test.ts +100 -0
  260. package/dist/templates/native-go-vue/frontend/src/delegate/facade.ts +85 -0
  261. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/de.json +46 -0
  262. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/en.json +12 -2
  263. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/es.json +46 -0
  264. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/fr.json +46 -0
  265. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/it.json +46 -0
  266. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/ja.json +46 -0
  267. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/ko.json +46 -0
  268. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/de.json +42 -0
  269. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/en.json +42 -0
  270. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/es.json +42 -0
  271. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/fr.json +42 -0
  272. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/it.json +42 -0
  273. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/ja.json +42 -0
  274. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/ko.json +42 -0
  275. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/zh-CN.json +42 -0
  276. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/save/zh-TW.json +42 -0
  277. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/zh-CN.json +46 -0
  278. package/dist/templates/native-go-vue/frontend/src/delegate/i18n/zh-TW.json +15 -5
  279. package/dist/templates/native-go-vue/frontend/src/delegate/long-running.ts +57 -0
  280. package/dist/templates/native-go-vue/frontend/src/delegate/save-copy.test.ts +12 -0
  281. package/dist/templates/native-go-vue/frontend/src/delegate/save-copy.ts +24 -0
  282. package/dist/templates/native-go-vue/frontend/src/delegate/scoped-picker.test.ts +12 -0
  283. package/dist/templates/native-go-vue/frontend/src/delegate/scoped-picker.ts +21 -0
  284. package/dist/templates/native-go-vue/frontend/src/files/files.test.ts +7 -0
  285. package/dist/templates/native-go-vue/frontend/src/i18n/de.json +20 -0
  286. package/dist/templates/native-go-vue/frontend/src/i18n/en.json +20 -0
  287. package/dist/templates/native-go-vue/frontend/src/i18n/es.json +20 -0
  288. package/dist/templates/native-go-vue/frontend/src/i18n/fr.json +20 -0
  289. package/dist/templates/native-go-vue/frontend/src/i18n/it.json +20 -0
  290. package/dist/templates/native-go-vue/frontend/src/i18n/ja.json +20 -0
  291. package/dist/templates/native-go-vue/frontend/src/i18n/ko.json +20 -0
  292. package/dist/templates/native-go-vue/frontend/src/i18n/zh-CN.json +20 -0
  293. package/dist/templates/native-go-vue/frontend/src/i18n/zh-TW.json +20 -0
  294. package/dist/templates/native-go-vue/frontend/src/i18n.ts +13 -0
  295. package/dist/templates/native-go-vue/frontend/src/identity/LoginPage.vue +16 -14
  296. package/dist/templates/native-go-vue/frontend/src/identity/i18n/de.json +27 -0
  297. package/dist/templates/native-go-vue/frontend/src/identity/i18n/en.json +27 -0
  298. package/dist/templates/native-go-vue/frontend/src/identity/i18n/es.json +27 -0
  299. package/dist/templates/native-go-vue/frontend/src/identity/i18n/fr.json +27 -0
  300. package/dist/templates/native-go-vue/frontend/src/identity/i18n/it.json +27 -0
  301. package/dist/templates/native-go-vue/frontend/src/identity/i18n/ja.json +27 -0
  302. package/dist/templates/native-go-vue/frontend/src/identity/i18n/ko.json +27 -0
  303. package/dist/templates/native-go-vue/frontend/src/identity/i18n/zh-CN.json +27 -0
  304. package/dist/templates/native-go-vue/frontend/src/identity/i18n/zh-TW.json +27 -0
  305. package/dist/templates/native-go-vue/frontend/src/identity/i18n.ts +14 -0
  306. package/dist/templates/native-go-vue/frontend/src/identity/session.test.ts +4 -0
  307. package/dist/templates/native-go-vue/frontend/src/identity/session.ts +9 -8
  308. package/dist/templates/native-go-vue/frontend/src/nas/NasPicker.vue +31 -12
  309. package/dist/templates/native-go-vue/frontend/src/nas/destination.test.ts +48 -0
  310. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/de.json +1 -1
  311. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/en.json +1 -1
  312. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/es.json +10 -10
  313. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/fr.json +1 -1
  314. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/it.json +12 -12
  315. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/ja.json +15 -15
  316. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/ko.json +12 -12
  317. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/zh-CN.json +1 -1
  318. package/dist/templates/native-go-vue/frontend/src/nas/i18n/files/zh-TW.json +1 -1
  319. package/dist/templates/native-go-vue/frontend/src/portal/PortalSettings.vue +39 -0
  320. package/dist/templates/native-go-vue/frontend/src/shell/i18n/fr.json +1 -1
  321. package/dist/templates/native-go-vue/frontend/src/shell/i18n/ja.json +1 -1
  322. package/dist/templates/native-go-vue/frontend/test/apps.test.ts +14 -0
  323. package/dist/templates/native-go-vue/frontend/test/portal-settings.test.ts +71 -0
  324. package/dist/templates/native-go-vue/frontend/test/shell-i18n.test.ts +50 -0
  325. package/package.json +5 -1
  326. package/schema/package-metadata.schema.json +101 -0
  327. package/schema/synology-app.schema.json +112 -0
  328. package/skills/SKILL.md +106 -4
  329. package/skills/reference/create.md +101 -2
  330. package/skills/reference/deploy.md +2 -2
  331. package/skills/reference/files.md +113 -2
  332. package/skills/reference/identity.md +70 -1
  333. package/skills/reference/portal.md +17 -0
  334. package/skills/reference/ui-vue.md +12 -0
  335. package/templates/_daemon/main_test.go +61 -8
  336. package/templates/_executor/README.md +127 -16
  337. package/templates/_executor/anchor.go +146 -0
  338. package/templates/_executor/anchor_test.go +126 -0
  339. package/templates/_executor/apppriv_review_test.go +1 -1
  340. package/templates/_executor/cancel_contract_test.go +236 -0
  341. package/templates/_executor/copy.go +64 -0
  342. package/templates/_executor/copy_test.go +88 -0
  343. package/templates/_executor/dsm.go +23 -10
  344. package/templates/_executor/dsm_test.go +95 -1
  345. package/templates/_executor/executor.go +260 -49
  346. package/templates/_executor/executor_test.go +36 -6
  347. package/templates/_executor/identity.go +27 -1
  348. package/templates/_executor/identity_kernel_linux_test.go +60 -0
  349. package/templates/_executor/identity_linux.go +82 -0
  350. package/templates/_executor/identity_security_test.go +43 -0
  351. package/templates/_executor/internal/lifecycle/lifecycle.go +5 -0
  352. package/templates/_executor/internal/lifecycle/lifecycle_test.go +61 -3
  353. package/templates/_executor/internal/taskscript/boot.sh +9 -9
  354. package/templates/_executor/internal/taskscript/cmd/main.go +2 -2
  355. package/templates/_executor/internal/taskscript/control.sh +15 -10
  356. package/templates/_executor/internal/taskscript/tasks.go +5 -3
  357. package/templates/_executor/lifecycle_test.go +11 -0
  358. package/templates/_executor/link_linux.go +28 -0
  359. package/templates/_executor/long_running_test.go +530 -0
  360. package/templates/_executor/main.go +72 -20
  361. package/templates/_executor/move_linux.go +490 -0
  362. package/templates/_executor/move_linux_test.go +460 -0
  363. package/templates/_executor/move_validation.go +46 -0
  364. package/templates/_executor/move_validation_test.go +187 -0
  365. package/templates/_executor/operations.go +926 -0
  366. package/templates/_executor/platform_linux.go +24 -173
  367. package/templates/_executor/platform_linux_test.go +9 -65
  368. package/templates/_executor/platform_other.go +30 -4
  369. package/templates/_executor/process.go +3 -0
  370. package/templates/_executor/records.go +242 -0
  371. package/templates/_executor/scope_cancel_contract_test.go +91 -0
  372. package/templates/_executor/scope_client.go +37 -0
  373. package/templates/_executor/scope_contract.go +12 -0
  374. package/templates/_executor/selected_scope.go +146 -0
  375. package/templates/_executor/selected_scope_test.go +186 -0
  376. package/templates/_executor/status_disabled_test.go +33 -0
  377. package/templates/_executor/store.go +4 -3
  378. package/templates/_executor/supervise.go +109 -0
  379. package/templates/_executor/supervise_test.go +130 -0
  380. package/templates/_executor/task_race_review_test.go +1 -1
  381. package/templates/_executor/tasks.go +7 -8
  382. package/templates/_executor/tasks_review_test.go +1 -1
  383. package/templates/_executor/tasks_test.go +4 -4
  384. package/templates/_executor/watch.go +8 -0
  385. package/templates/_executor/watch_test.go +23 -2
  386. package/templates/_executor/write_review_linux_test.go +4 -12
  387. package/templates/_shared/AGENTS.md +129 -0
  388. package/templates/binary/dsm-package.yaml +24 -0
  389. package/templates/binary/i18n/messages/de.json +4 -0
  390. package/templates/binary/i18n/messages/en.json +4 -0
  391. package/templates/binary/i18n/messages/es.json +4 -0
  392. package/templates/binary/i18n/messages/fr.json +4 -0
  393. package/templates/binary/i18n/messages/it.json +4 -0
  394. package/templates/binary/i18n/messages/ja.json +4 -0
  395. package/templates/binary/i18n/messages/ko.json +4 -0
  396. package/templates/binary/i18n/messages/zh-CN.json +4 -0
  397. package/templates/binary/i18n/messages/zh-TW.json +4 -0
  398. package/templates/binary/ui/app.js +19 -4
  399. package/templates/native-authorization/AuthorizationGate.vue +5 -3
  400. package/templates/native-authorization/i18n/de.json +1 -0
  401. package/templates/native-authorization/i18n/en.json +1 -0
  402. package/templates/native-authorization/i18n/es.json +2 -1
  403. package/templates/native-authorization/i18n/fr.json +1 -0
  404. package/templates/native-authorization/i18n/it.json +11 -10
  405. package/templates/native-authorization/i18n/ja.json +1 -0
  406. package/templates/native-authorization/i18n/ko.json +10 -9
  407. package/templates/native-authorization/i18n/zh-CN.json +6 -5
  408. package/templates/native-authorization/i18n/zh-TW.json +6 -5
  409. package/templates/native-go/README.md +43 -10
  410. package/templates/native-go/backend/cmd/app/main.go +27 -7
  411. package/templates/native-go/backend/internal/api/entry_test.go +47 -0
  412. package/templates/native-go/backend/internal/api/permissions_test.go +3 -3
  413. package/templates/native-go/backend/internal/api/registry.go +11 -0
  414. package/templates/native-go/backend/internal/api/sdk-permissions.json +14 -1
  415. package/templates/native-go/backend/internal/api/server.go +18 -5
  416. package/templates/native-go/backend/internal/app/delegate_config.go +57 -0
  417. package/templates/native-go/backend/internal/app/delegate_config_test.go +28 -0
  418. package/templates/native-go/backend/internal/app/portal.go +30 -0
  419. package/templates/native-go/backend/internal/app/portal_test.go +55 -0
  420. package/templates/native-go/backend/internal/app/routes.go +8 -2
  421. package/templates/native-go/backend/internal/background/runner.go +1 -1
  422. package/templates/native-go/backend/internal/background/store.go +16 -14
  423. package/templates/native-go/backend/internal/dsm/admin.go +8 -2
  424. package/templates/native-go/backend/internal/dsm/admin_linux.go +43 -13
  425. package/templates/native-go/backend/internal/dsm/admin_linux_test.go +56 -0
  426. package/templates/native-go/backend/internal/dsm/admin_other.go +4 -1
  427. package/templates/native-go/backend/internal/dsm/apppriv.go +30 -0
  428. package/templates/native-go/backend/internal/dsm/bridge_file.go +75 -0
  429. package/templates/native-go/backend/internal/dsm/bridge_file_test.go +57 -0
  430. package/templates/native-go/backend/internal/dsm/entry.go +177 -0
  431. package/templates/native-go/backend/internal/dsm/entry_test.go +315 -0
  432. package/templates/native-go/backend/internal/dsm/native/admin-armv7.elf +0 -0
  433. package/templates/native-go/backend/internal/dsm/native/apppriv-aarch64.elf +0 -0
  434. package/templates/native-go/backend/internal/dsm/native/apppriv-armv7.elf +0 -0
  435. package/templates/native-go/backend/internal/dsm/native/apppriv-x86_64.elf +0 -0
  436. package/templates/native-go/backend/internal/dsm/native/apppriv_check.c +33 -0
  437. package/templates/native-go/backend/internal/dsm/native/build.sh +13 -4
  438. package/templates/native-go/backend/internal/dsm/native/provenance.json +9 -3
  439. package/templates/native-go/backend/internal/filestation/check_permission.go +71 -0
  440. package/templates/native-go/backend/internal/filestation/check_permission_test.go +77 -0
  441. package/templates/native-go/backend/internal/filestation/sdk_policy_test.go +39 -0
  442. package/templates/native-go/backend/internal/filestation/service.go +1 -1
  443. package/templates/native-go/backend/internal/portal/portal.go +138 -0
  444. package/templates/native-go/backend/internal/portal/portal_test.go +89 -0
  445. package/templates/native-go/dsm-package.yaml +20 -1
  446. package/templates/native-go/i18n/glossary.json +2 -1
  447. package/templates/native-go/i18n/messages/de.json +1 -0
  448. package/templates/native-go/i18n/messages/en.json +1 -0
  449. package/templates/native-go/i18n/messages/es.json +1 -0
  450. package/templates/native-go/i18n/messages/fr.json +1 -0
  451. package/templates/native-go/i18n/messages/it.json +1 -0
  452. package/templates/native-go/i18n/messages/ja.json +1 -0
  453. package/templates/native-go/i18n/messages/ko.json +1 -0
  454. package/templates/native-go/i18n/messages/zh-CN.json +1 -0
  455. package/templates/native-go/i18n/messages/zh-TW.json +1 -0
  456. package/templates/native-go/ui/app.css +10 -0
  457. package/templates/native-go/ui/app.js +11 -1
  458. package/templates/native-go-delegate/DELEGATE.md +126 -5
  459. package/templates/native-go-delegate/backend/cmd/background-worker/main.go +7 -0
  460. package/templates/native-go-delegate/backend/internal/app/delegate.go +11 -1
  461. package/templates/native-go-delegate/backend/internal/app/delegate_routes_test.go +14 -0
  462. package/templates/native-go-delegate/backend/internal/background/delegated_moves.go +270 -0
  463. package/templates/native-go-delegate/backend/internal/delegate/admission_recovery_test.go +410 -0
  464. package/templates/native-go-delegate/backend/internal/delegate/cancel_contract_test.go +95 -0
  465. package/templates/native-go-delegate/backend/internal/delegate/client.go +8 -0
  466. package/templates/native-go-delegate/backend/internal/delegate/destination.go +110 -0
  467. package/templates/native-go-delegate/backend/internal/delegate/destination_state.go +117 -0
  468. package/templates/native-go-delegate/backend/internal/delegate/destination_state_test.go +60 -0
  469. package/templates/native-go-delegate/backend/internal/delegate/destination_test.go +116 -0
  470. package/templates/native-go-delegate/backend/internal/delegate/example.go +81 -0
  471. package/templates/native-go-delegate/backend/internal/delegate/example_test.go +91 -0
  472. package/templates/native-go-delegate/backend/internal/delegate/executor_contract_test.go +511 -0
  473. package/templates/native-go-delegate/backend/internal/delegate/files.go +1 -1
  474. package/templates/native-go-delegate/backend/internal/delegate/long_running_routes.go +92 -0
  475. package/templates/native-go-delegate/backend/internal/delegate/long_running_routes_test.go +99 -0
  476. package/templates/native-go-delegate/backend/internal/delegate/move.go +348 -0
  477. package/templates/native-go-delegate/backend/internal/delegate/move_test.go +351 -0
  478. package/templates/native-go-delegate/backend/internal/delegate/operations_list.go +65 -0
  479. package/templates/native-go-delegate/backend/internal/delegate/operations_list_test.go +114 -0
  480. package/templates/native-go-delegate/backend/internal/delegate/retry_test.go +1 -1
  481. package/templates/native-go-delegate/backend/internal/delegate/service.go +58 -17
  482. package/templates/native-go-delegate/backend/internal/delegate/staging.go +121 -0
  483. package/templates/native-go-delegate/backend/internal/delegate/status_disabled_test.go +51 -0
  484. package/templates/native-go-delegate/backend/internal/delegate/testdata/executor_contract.txt +112 -0
  485. package/templates/native-go-delegate/backend/internal/delegate/transient_contract_test.go +137 -0
  486. package/templates/native-go-delegate/backend/internal/filestation/files.go +1 -31
  487. package/templates/native-go-delegate/frontend/src/CapabilityPanels.vue +30 -3
  488. package/templates/native-go-delegate/frontend/src/delegate/BackgroundSavePanel.vue +113 -0
  489. package/templates/native-go-delegate/frontend/src/delegate/copy.ts +5 -6
  490. package/templates/native-go-delegate/frontend/test/background-save.test.ts +121 -0
  491. package/templates/native-go-delegate/frontend/test/scope-settings.test.ts +49 -0
  492. package/templates/native-go-delegate/test.sh +1 -0
  493. package/templates/native-go-jobs/frontend/src/background/i18n/de.json +2 -2
  494. package/templates/native-go-jobs/frontend/src/background/i18n/en.json +2 -2
  495. package/templates/native-go-jobs/frontend/src/background/i18n/es.json +12 -12
  496. package/templates/native-go-jobs/frontend/src/background/i18n/fr.json +4 -4
  497. package/templates/native-go-jobs/frontend/src/background/i18n/it.json +17 -17
  498. package/templates/native-go-jobs/frontend/src/background/i18n/ja.json +7 -7
  499. package/templates/native-go-jobs/frontend/src/background/i18n/ko.json +15 -15
  500. package/templates/native-go-jobs/frontend/src/background/i18n/zh-CN.json +3 -3
  501. package/templates/native-go-jobs/frontend/src/background/i18n/zh-TW.json +2 -2
  502. package/templates/native-go-jobs/frontend/test/background.test.ts +25 -28
  503. package/templates/native-go-vue/README.md +4 -0
  504. package/templates/native-go-vue/frontend/package-lock.json +4 -4
  505. package/templates/native-go-vue/frontend/package.json +1 -1
  506. package/templates/native-go-vue/frontend/src/App.vue +18 -13
  507. package/templates/native-go-vue/frontend/src/context.ts +31 -0
  508. package/templates/native-go-vue/frontend/src/delegate/ExecutorSettings.vue +52 -8
  509. package/templates/native-go-vue/frontend/src/delegate/catalogs.ts +11 -0
  510. package/templates/native-go-vue/frontend/src/delegate/copy.test.ts +12 -0
  511. package/templates/native-go-vue/frontend/src/delegate/copy.ts +4 -4
  512. package/templates/native-go-vue/frontend/src/delegate/executor-setup.ts +4 -2
  513. package/templates/native-go-vue/frontend/src/delegate/facade.test.ts +100 -0
  514. package/templates/native-go-vue/frontend/src/delegate/facade.ts +85 -0
  515. package/templates/native-go-vue/frontend/src/delegate/i18n/de.json +46 -0
  516. package/templates/native-go-vue/frontend/src/delegate/i18n/en.json +12 -2
  517. package/templates/native-go-vue/frontend/src/delegate/i18n/es.json +46 -0
  518. package/templates/native-go-vue/frontend/src/delegate/i18n/fr.json +46 -0
  519. package/templates/native-go-vue/frontend/src/delegate/i18n/it.json +46 -0
  520. package/templates/native-go-vue/frontend/src/delegate/i18n/ja.json +46 -0
  521. package/templates/native-go-vue/frontend/src/delegate/i18n/ko.json +46 -0
  522. package/templates/native-go-vue/frontend/src/delegate/i18n/save/de.json +42 -0
  523. package/templates/native-go-vue/frontend/src/delegate/i18n/save/en.json +42 -0
  524. package/templates/native-go-vue/frontend/src/delegate/i18n/save/es.json +42 -0
  525. package/templates/native-go-vue/frontend/src/delegate/i18n/save/fr.json +42 -0
  526. package/templates/native-go-vue/frontend/src/delegate/i18n/save/it.json +42 -0
  527. package/templates/native-go-vue/frontend/src/delegate/i18n/save/ja.json +42 -0
  528. package/templates/native-go-vue/frontend/src/delegate/i18n/save/ko.json +42 -0
  529. package/templates/native-go-vue/frontend/src/delegate/i18n/save/zh-CN.json +42 -0
  530. package/templates/native-go-vue/frontend/src/delegate/i18n/save/zh-TW.json +42 -0
  531. package/templates/native-go-vue/frontend/src/delegate/i18n/zh-CN.json +46 -0
  532. package/templates/native-go-vue/frontend/src/delegate/i18n/zh-TW.json +15 -5
  533. package/templates/native-go-vue/frontend/src/delegate/long-running.ts +57 -0
  534. package/templates/native-go-vue/frontend/src/delegate/save-copy.test.ts +12 -0
  535. package/templates/native-go-vue/frontend/src/delegate/save-copy.ts +24 -0
  536. package/templates/native-go-vue/frontend/src/delegate/scoped-picker.test.ts +12 -0
  537. package/templates/native-go-vue/frontend/src/delegate/scoped-picker.ts +21 -0
  538. package/templates/native-go-vue/frontend/src/files/files.test.ts +7 -0
  539. package/templates/native-go-vue/frontend/src/i18n/de.json +20 -0
  540. package/templates/native-go-vue/frontend/src/i18n/en.json +20 -0
  541. package/templates/native-go-vue/frontend/src/i18n/es.json +20 -0
  542. package/templates/native-go-vue/frontend/src/i18n/fr.json +20 -0
  543. package/templates/native-go-vue/frontend/src/i18n/it.json +20 -0
  544. package/templates/native-go-vue/frontend/src/i18n/ja.json +20 -0
  545. package/templates/native-go-vue/frontend/src/i18n/ko.json +20 -0
  546. package/templates/native-go-vue/frontend/src/i18n/zh-CN.json +20 -0
  547. package/templates/native-go-vue/frontend/src/i18n/zh-TW.json +20 -0
  548. package/templates/native-go-vue/frontend/src/i18n.ts +13 -0
  549. package/templates/native-go-vue/frontend/src/identity/LoginPage.vue +16 -14
  550. package/templates/native-go-vue/frontend/src/identity/i18n/de.json +27 -0
  551. package/templates/native-go-vue/frontend/src/identity/i18n/en.json +27 -0
  552. package/templates/native-go-vue/frontend/src/identity/i18n/es.json +27 -0
  553. package/templates/native-go-vue/frontend/src/identity/i18n/fr.json +27 -0
  554. package/templates/native-go-vue/frontend/src/identity/i18n/it.json +27 -0
  555. package/templates/native-go-vue/frontend/src/identity/i18n/ja.json +27 -0
  556. package/templates/native-go-vue/frontend/src/identity/i18n/ko.json +27 -0
  557. package/templates/native-go-vue/frontend/src/identity/i18n/zh-CN.json +27 -0
  558. package/templates/native-go-vue/frontend/src/identity/i18n/zh-TW.json +27 -0
  559. package/templates/native-go-vue/frontend/src/identity/i18n.ts +14 -0
  560. package/templates/native-go-vue/frontend/src/identity/session.test.ts +4 -0
  561. package/templates/native-go-vue/frontend/src/identity/session.ts +9 -8
  562. package/templates/native-go-vue/frontend/src/nas/NasPicker.vue +31 -12
  563. package/templates/native-go-vue/frontend/src/nas/destination.test.ts +48 -0
  564. package/templates/native-go-vue/frontend/src/nas/i18n/files/de.json +1 -1
  565. package/templates/native-go-vue/frontend/src/nas/i18n/files/en.json +1 -1
  566. package/templates/native-go-vue/frontend/src/nas/i18n/files/es.json +10 -10
  567. package/templates/native-go-vue/frontend/src/nas/i18n/files/fr.json +1 -1
  568. package/templates/native-go-vue/frontend/src/nas/i18n/files/it.json +12 -12
  569. package/templates/native-go-vue/frontend/src/nas/i18n/files/ja.json +15 -15
  570. package/templates/native-go-vue/frontend/src/nas/i18n/files/ko.json +12 -12
  571. package/templates/native-go-vue/frontend/src/nas/i18n/files/zh-CN.json +1 -1
  572. package/templates/native-go-vue/frontend/src/nas/i18n/files/zh-TW.json +1 -1
  573. package/templates/native-go-vue/frontend/src/portal/PortalSettings.vue +39 -0
  574. package/templates/native-go-vue/frontend/src/shell/i18n/fr.json +1 -1
  575. package/templates/native-go-vue/frontend/src/shell/i18n/ja.json +1 -1
  576. package/templates/native-go-vue/frontend/test/apps.test.ts +14 -0
  577. package/templates/native-go-vue/frontend/test/portal-settings.test.ts +71 -0
  578. package/templates/native-go-vue/frontend/test/shell-i18n.test.ts +50 -0
@@ -0,0 +1,146 @@
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "errors"
6
+ "os"
7
+ "os/exec"
8
+ "path/filepath"
9
+ "regexp"
10
+ "strings"
11
+ "syscall"
12
+ )
13
+
14
+ // Package Center writes the SPK INFO as root. The package account cannot change
15
+ // it, so its executor digest authorizes executor-only upgrades under the
16
+ // administrator-approved policy without a new PasswordConfirm.
17
+ const executorAnchorKey = "synopkgland_executor_sha256"
18
+
19
+ var anchorRE = regexp.MustCompile(`^"([a-f0-9]{64})"$`)
20
+
21
+ type pinState int
22
+
23
+ const (
24
+ pinsDiffer pinState = iota
25
+ pinsMatch
26
+ pinsAnchored
27
+ )
28
+
29
+ func executorAnchor(info string, trusted func(os.FileInfo) bool) (string, error) {
30
+ b, stat, err := readLifecycleFile(info, 65536)
31
+ if err != nil {
32
+ return "", err
33
+ }
34
+ if !trusted(stat) {
35
+ return "", errors.New("untrusted package INFO")
36
+ }
37
+ anchor := ""
38
+ for _, line := range strings.Split(string(b), "\n") {
39
+ value, ok := strings.CutPrefix(line, executorAnchorKey+"=")
40
+ if !ok {
41
+ continue
42
+ }
43
+ m := anchorRE.FindStringSubmatch(value)
44
+ if m == nil || anchor != "" {
45
+ return "", errors.New("executor anchor")
46
+ }
47
+ anchor = m[1]
48
+ }
49
+ if anchor == "" {
50
+ return "", errors.New("executor anchor")
51
+ }
52
+ return anchor, nil
53
+ }
54
+
55
+ func rootOwnedReadOnly(info os.FileInfo) bool {
56
+ return ownedByRoot(info) && info.Mode().Perm()&0022 == 0
57
+ }
58
+
59
+ func packagePins(ctx context.Context, dir, info string, trusted func(os.FileInfo) bool, executorDigest, policyDigest string) pinState {
60
+ if samePackagePins(ctx, dir, executorDigest, policyDigest) {
61
+ return pinsMatch
62
+ }
63
+ dir, err := filepath.EvalSymlinks(dir)
64
+ if err != nil {
65
+ return pinsDiffer
66
+ }
67
+ if pd, err := digestFile(ctx, dir+"/policy.json", maxPolicyBytes); err != nil || pd != policyDigest {
68
+ return pinsDiffer
69
+ }
70
+ anchor, err := executorAnchor(info, trusted)
71
+ if err != nil {
72
+ return pinsDiffer
73
+ }
74
+ if ed, err := digestFile(ctx, dir+"/executor", maxExecutorBytes); err != nil || ed != anchor {
75
+ return pinsDiffer
76
+ }
77
+ return pinsAnchored
78
+ }
79
+
80
+ // The policy is unchanged, so root scripts (pinned by policy digests) stay too.
81
+ // Verify the protected copy, never the package-reachable source.
82
+ func installAnchored(ctx context.Context, source, info string, trusted func(os.FileInfo) bool, runtime string) error {
83
+ anchor, err := executorAnchor(info, trusted)
84
+ if err != nil {
85
+ return err
86
+ }
87
+ src, err := openRegular(filepath.Join(source, "executor"))
88
+ if err != nil {
89
+ return err
90
+ }
91
+ defer src.Close()
92
+ stat, err := src.Stat()
93
+ if err != nil || stat.Size() > maxExecutorBytes {
94
+ return errors.New("executor size")
95
+ }
96
+ staged, err := os.CreateTemp(runtime, ".executor-")
97
+ if err != nil {
98
+ return err
99
+ }
100
+ defer os.Remove(staged.Name())
101
+ err = copyExact(staged, src, stat.Size())
102
+ if err == nil {
103
+ err = staged.Chmod(0700)
104
+ }
105
+ if err == nil {
106
+ err = staged.Sync()
107
+ }
108
+ if closeErr := staged.Close(); err == nil {
109
+ err = closeErr
110
+ }
111
+ if err != nil {
112
+ return err
113
+ }
114
+ if digest, err := digestFile(ctx, staged.Name(), maxExecutorBytes); err != nil || digest != anchor {
115
+ return errors.New("executor anchor mismatch")
116
+ }
117
+ return os.Rename(staged.Name(), filepath.Join(runtime, "executor"))
118
+ }
119
+
120
+ // Root control start replaces this monitor with the newly installed runtime.
121
+ func startInstalled(runtime, pkg string) error {
122
+ cmd := exec.Command(filepath.Join(runtime, "executor"), "control", "start", "--package", pkg)
123
+ cmd.Env = []string{"PATH=/usr/bin:/bin", "LANG=C"}
124
+ cmd.Dir = "/"
125
+ cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
126
+ if err := cmd.Start(); err != nil {
127
+ return err
128
+ }
129
+ return cmd.Process.Release()
130
+ }
131
+
132
+ func approvedPins(state pinState, install, start func() error, log func(string)) bool {
133
+ if state != pinsAnchored {
134
+ return state == pinsMatch
135
+ }
136
+ if err := install(); err != nil {
137
+ log("executor upgrade refused: INFO-anchored executor could not be installed")
138
+ return false
139
+ }
140
+ if err := start(); err != nil {
141
+ log("executor upgrade installed; root start failed")
142
+ return false
143
+ }
144
+ log("executor upgrade: INFO-anchored executor installed under the approved policy")
145
+ return false
146
+ }
@@ -0,0 +1,126 @@
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "errors"
6
+ "os"
7
+ "path/filepath"
8
+ "strings"
9
+ "testing"
10
+ )
11
+
12
+ func trustAll(os.FileInfo) bool { return true }
13
+
14
+ // anchoredPackage writes a target executor/policy pair and the package INFO.
15
+ func anchoredPackage(t *testing.T, executor, policy string, anchors ...string) (target, info string) {
16
+ t.Helper()
17
+ pkg := realTestPath(t, t.TempDir())
18
+ target = filepath.Join(pkg, "target", "executor")
19
+ os.MkdirAll(target, 0755)
20
+ os.WriteFile(filepath.Join(target, "executor"), []byte(executor), 0755)
21
+ os.WriteFile(filepath.Join(target, "policy.json"), []byte(policy), 0644)
22
+ text := "package=\"TestApp\"\n"
23
+ for _, a := range anchors {
24
+ text += "synopkgland_executor_sha256=\"" + a + "\"\n"
25
+ }
26
+ info = filepath.Join(pkg, "INFO")
27
+ os.WriteFile(info, []byte(text), 0644)
28
+ return target, info
29
+ }
30
+
31
+ func TestExecutorAnchorRequiresOneLowercaseDigestInTrustedINFO(t *testing.T) {
32
+ digest := hashBytes([]byte("new executor"))
33
+ _, info := anchoredPackage(t, "new executor", "policy", digest)
34
+ if got, err := executorAnchor(info, trustAll); err != nil || got != digest {
35
+ t.Fatal("anchor", got, err)
36
+ }
37
+ if _, err := executorAnchor(info, func(os.FileInfo) bool { return false }); err == nil {
38
+ t.Fatal("package-writable INFO accepted")
39
+ }
40
+ for name, anchors := range map[string][]string{"missing": nil, "duplicate": {digest, digest}, "uppercase": {strings.ToUpper(digest)}, "short": {digest[:63]}} {
41
+ _, info := anchoredPackage(t, "new executor", "policy", anchors...)
42
+ if _, err := executorAnchor(info, trustAll); err == nil {
43
+ t.Fatal(name, "anchor accepted")
44
+ }
45
+ }
46
+ }
47
+
48
+ func TestPackagePinsAcceptAnExecutorUpgradeOnlyUnderTheApprovedPolicyAndINFOAnchor(t *testing.T) {
49
+ ctx := context.Background()
50
+ ed, pd := hashBytes([]byte("approved executor")), hashBytes([]byte("approved policy"))
51
+ upgraded := hashBytes([]byte("new executor"))
52
+ for _, tc := range []struct {
53
+ name, executor, policy string
54
+ anchors []string
55
+ want pinState
56
+ }{
57
+ {"same bytes", "approved executor", "approved policy", nil, pinsMatch},
58
+ {"anchored executor", "new executor", "approved policy", []string{upgraded}, pinsAnchored},
59
+ {"unanchored executor", "new executor", "approved policy", nil, pinsDiffer},
60
+ {"different anchor", "new executor", "approved policy", []string{ed}, pinsDiffer},
61
+ {"changed policy", "new executor", "wider policy", []string{upgraded}, pinsDiffer},
62
+ {"changed policy only", "approved executor", "wider policy", []string{ed}, pinsDiffer},
63
+ } {
64
+ t.Run(tc.name, func(t *testing.T) {
65
+ target, info := anchoredPackage(t, tc.executor, tc.policy, tc.anchors...)
66
+ if got := packagePins(ctx, target, info, trustAll, ed, pd); got != tc.want {
67
+ t.Fatal("pin state", got)
68
+ }
69
+ })
70
+ }
71
+ }
72
+
73
+ func TestInstallAnchoredReplacesOnlyTheProtectedExecutorWithVerifiedBytes(t *testing.T) {
74
+ ctx := context.Background()
75
+ for _, anchored := range []bool{true, false} {
76
+ t.Run(map[bool]string{true: "anchored", false: "swapped after check"}[anchored], func(t *testing.T) {
77
+ anchor := hashBytes([]byte("new executor"))
78
+ target, info := anchoredPackage(t, "new executor", "approved policy", anchor)
79
+ if !anchored {
80
+ os.WriteFile(filepath.Join(target, "executor"), []byte("package swapped"), 0755)
81
+ }
82
+ runtime := realTestPath(t, t.TempDir())
83
+ os.WriteFile(filepath.Join(runtime, "executor"), []byte("approved executor"), 0700)
84
+ os.WriteFile(filepath.Join(runtime, "policy.json"), []byte("approved policy"), 0600)
85
+ err := installAnchored(ctx, target, info, trustAll, runtime)
86
+ b, _ := os.ReadFile(filepath.Join(runtime, "executor"))
87
+ if anchored && (err != nil || string(b) != "new executor") {
88
+ t.Fatal("anchored executor not installed", err, string(b))
89
+ }
90
+ if !anchored && (err == nil || string(b) != "approved executor") {
91
+ t.Fatal("unanchored executor installed", err, string(b))
92
+ }
93
+ if info, err := os.Stat(filepath.Join(runtime, "executor")); err != nil || info.Mode().Perm() != 0700 {
94
+ t.Fatal("protected executor mode", err)
95
+ }
96
+ entries, _ := os.ReadDir(runtime)
97
+ if len(entries) != 2 {
98
+ t.Fatal("staging copy left in runtime", entries)
99
+ }
100
+ })
101
+ }
102
+ }
103
+
104
+ func TestApprovedPinsHandOverAnAnchoredUpgradeToRootStart(t *testing.T) {
105
+ for _, tc := range []struct {
106
+ name string
107
+ state pinState
108
+ installErr error
109
+ open bool
110
+ installs int
111
+ starts int
112
+ }{
113
+ {"match", pinsMatch, nil, true, 0, 0},
114
+ {"differ", pinsDiffer, nil, false, 0, 0},
115
+ {"anchored", pinsAnchored, nil, false, 1, 1},
116
+ {"install failed", pinsAnchored, errors.New("digest"), false, 1, 0},
117
+ } {
118
+ t.Run(tc.name, func(t *testing.T) {
119
+ installs, starts := 0, 0
120
+ open := approvedPins(tc.state, func() error { installs++; return tc.installErr }, func() error { starts++; return nil }, func(string) {})
121
+ if open != tc.open || installs != tc.installs || starts != tc.starts {
122
+ t.Fatal("handover", open, installs, starts)
123
+ }
124
+ })
125
+ }
126
+ }
@@ -20,7 +20,7 @@ func TestReviewAppPrivRejectsAmbiguousOrError(t *testing.T) {
20
20
  for name, reply := range cases {
21
21
  t.Run(name, func(t *testing.T) {
22
22
  d := &liveDSM{Command: &cmdStub{reply: reply}}
23
- if d.Allow(context.Background(), Subject{Username: "alice"}, "app") == nil {
23
+ if d.Allow(context.Background(), Subject{Username: "alice"}, "app", "") == nil {
24
24
  t.Fatal("unsafe AppPriv response allowed")
25
25
  }
26
26
  })
@@ -0,0 +1,236 @@
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "strings"
7
+ "sync"
8
+ "testing"
9
+ "time"
10
+ )
11
+
12
+ // stubbornMoveWriter keeps copying after its context ends until released, like
13
+ // a slow write syscall, so the canceling window can be observed.
14
+ type stubbornMoveWriter struct {
15
+ copying, release, published chan struct{}
16
+ publishing, finishPublish chan struct{}
17
+ once sync.Once
18
+ }
19
+
20
+ func (w *stubbornMoveWriter) let() { w.once.Do(func() { close(w.release) }) }
21
+
22
+ func newStubbornWriter() *stubbornMoveWriter {
23
+ return &stubbornMoveWriter{copying: make(chan struct{}), release: make(chan struct{}), published: make(chan struct{})}
24
+ }
25
+ func (w *stubbornMoveWriter) Write(context.Context, Subject, string, string, string, string) error {
26
+ return nil
27
+ }
28
+ func (w *stubbornMoveWriter) Move(_ context.Context, _ Subject, op Operation, d Delegation, guard func(func() (MoveReceipt, error)) (MoveReceipt, error)) (MoveReceipt, error) {
29
+ close(w.copying)
30
+ <-w.release
31
+ return guard(func() (MoveReceipt, error) {
32
+ if w.publishing != nil {
33
+ close(w.publishing)
34
+ <-w.finishPublish
35
+ }
36
+ close(w.published)
37
+ return MoveReceipt{Path: d.Path + "/" + op.Name}, nil
38
+ })
39
+ }
40
+
41
+ func operationOf(t *testing.T, r Response) map[string]any {
42
+ t.Helper()
43
+ if !r.OK {
44
+ t.Fatal(r)
45
+ }
46
+ b, _ := json.Marshal(r.Result)
47
+ out := map[string]any{}
48
+ json.Unmarshal(b, &out)
49
+ return out
50
+ }
51
+ func wantOperation(t *testing.T, r Response, state, code, reason string) {
52
+ t.Helper()
53
+ out := operationOf(t, r)
54
+ got, _ := out["code"].(string)
55
+ why, _ := out["reason"].(string)
56
+ if out["state"] != state || got != code || why != reason {
57
+ t.Fatalf("want %s/%s/%s, got %v", state, code, reason, out)
58
+ }
59
+ }
60
+ func startedCopy(t *testing.T, e *Executor, w *stubbornMoveWriter, id, job string) {
61
+ t.Helper()
62
+ if err := e.startOperations(context.Background()); err != nil {
63
+ t.Fatal(err)
64
+ }
65
+ // Cleanups run in reverse: release the writer, then stop.
66
+ t.Cleanup(e.stopOperations)
67
+ t.Cleanup(w.let)
68
+ if r := offline(e, "files.moveFromStaging", moveParams(id, job)); !r.OK {
69
+ t.Fatal(r)
70
+ }
71
+ select {
72
+ case <-w.copying:
73
+ case <-time.After(2 * time.Second):
74
+ t.Fatal("copy did not start")
75
+ }
76
+ }
77
+
78
+ func TestCancelCopyingAcknowledgesDurablyUntilCanceled(t *testing.T) {
79
+ e, _, _ := setup(t)
80
+ id := longGrant(t, e)
81
+ w := newStubbornWriter()
82
+ e.Writer = w
83
+ startedCopy(t, e, w, id, "job")
84
+ ref := map[string]any{"delegation_id": id, "job_id": "job"}
85
+ for i := 0; i < 2; i++ {
86
+ // A repeated cancel after a lost reply returns the same acknowledgement.
87
+ wantOperation(t, offline(e, "files.cancelOperation", ref), "copying", "CANCEL_REQUESTED", "operation-canceled-by-user")
88
+ }
89
+ wantOperation(t, offline(e, "files.operationStatus", ref), "copying", "CANCEL_REQUESTED", "operation-canceled-by-user")
90
+ e.commitMu.Lock()
91
+ op, err := e.Store.GetOperation("job")
92
+ e.commitMu.Unlock()
93
+ if err != nil || op.CancelRequested != "operation-canceled-by-user" {
94
+ t.Fatal("cancel intent not durable", op, err)
95
+ }
96
+ w.let()
97
+ waitState(t, e, "job", "canceled")
98
+ select {
99
+ case <-w.published:
100
+ t.Fatal("published after cancel acknowledgement")
101
+ default:
102
+ }
103
+ wantOperation(t, offline(e, "files.cancelOperation", ref), "canceled", "OPERATION_CANCELED", "operation-canceled-by-user")
104
+ wantOperation(t, offline(e, "files.moveFromStaging", moveParams(id, "job")), "canceled", "OPERATION_CANCELED", "operation-canceled-by-user")
105
+ }
106
+
107
+ func TestCancelRequestedCopySettlesCanceledAcrossStopAndCrash(t *testing.T) {
108
+ t.Run("stop-while-canceling", func(t *testing.T) {
109
+ e, _, _ := setup(t)
110
+ id := longGrant(t, e)
111
+ w := newStubbornWriter()
112
+ e.Writer = w
113
+ startedCopy(t, e, w, id, "job")
114
+ ref := map[string]any{"delegation_id": id, "job_id": "job"}
115
+ wantOperation(t, offline(e, "files.cancelOperation", ref), "copying", "CANCEL_REQUESTED", "operation-canceled-by-user")
116
+ stopped := make(chan struct{})
117
+ go func() { e.stopOperations(); close(stopped) }()
118
+ w.let()
119
+ <-stopped
120
+ if err := e.startOperations(context.Background()); err != nil {
121
+ t.Fatal(err)
122
+ }
123
+ defer e.stopOperations()
124
+ wantOperation(t, offline(e, "files.operationStatus", ref), "canceled", "OPERATION_CANCELED", "operation-canceled-by-user")
125
+ })
126
+ for _, intent := range []bool{false, true} {
127
+ name := map[bool]string{false: "crash-before-publish", true: "crash-after-publish-intent"}[intent]
128
+ t.Run(name, func(t *testing.T) {
129
+ e, _, _ := setup(t)
130
+ id := longGrant(t, e)
131
+ op := Operation{Version: 1, Package: e.Policy.Package, ID: id, Job: "job", State: "copying", CancelRequested: "operation-canceled-by-user", PublishIntent: intent, Staging: "result", Name: "out.csv", Size: 123}
132
+ if e.Store.PutOperation(op) != nil {
133
+ t.Fatal("put")
134
+ }
135
+ w := newStubbornWriter()
136
+ e.Writer = w
137
+ if err := e.startOperations(context.Background()); err != nil {
138
+ t.Fatal(err)
139
+ }
140
+ defer e.stopOperations()
141
+ ref := map[string]any{"delegation_id": id, "job_id": "job"}
142
+ if intent {
143
+ // A publish that may have happened is never reported as canceled.
144
+ wantOperation(t, offline(e, "files.operationStatus", ref), "uncertain", "uncertain", "")
145
+ return
146
+ }
147
+ wantOperation(t, offline(e, "files.operationStatus", ref), "canceled", "OPERATION_CANCELED", "operation-canceled-by-user")
148
+ })
149
+ }
150
+ }
151
+
152
+ func TestCancelBeforeAdmissionLeavesTombstoneThatIsNeverAdmitted(t *testing.T) {
153
+ e, f, _ := setup(t)
154
+ id := longGrant(t, e)
155
+ w := newStubbornWriter()
156
+ e.Writer = w
157
+ if err := e.startOperations(context.Background()); err != nil {
158
+ t.Fatal(err)
159
+ }
160
+ defer e.stopOperations()
161
+ ref := map[string]any{"delegation_id": id, "job_id": "job"}
162
+ if r := offline(e, "files.operationStatus", ref); r.Code != "operation-not-found" {
163
+ t.Fatal(r)
164
+ }
165
+ if r := offline(e, "files.cancelOperation", map[string]any{"delegation_id": strings.Repeat("f", 64), "job_id": "job"}); r.Code != "operation-not-found" {
166
+ t.Fatal("canceled under an unknown grant", r)
167
+ }
168
+ f.user.Username = "bob"
169
+ if r := request(e, "files.cancelOperation", ref); r.Code != "operation-not-found" {
170
+ t.Fatal("another owner canceled", r)
171
+ }
172
+ f.user.Username = "alice"
173
+ for i := 0; i < 2; i++ {
174
+ wantOperation(t, offline(e, "files.cancelOperation", ref), "canceled", "OPERATION_CANCELED", "operation-canceled-by-user")
175
+ }
176
+ // The original admission, arriving late or replayed, finds the tombstone.
177
+ for i := 0; i < 2; i++ {
178
+ wantOperation(t, offline(e, "files.moveFromStaging", moveParams(id, "job")), "canceled", "OPERATION_CANCELED", "operation-canceled-by-user")
179
+ }
180
+ wantOperation(t, offline(e, "files.operationStatus", ref), "canceled", "OPERATION_CANCELED", "operation-canceled-by-user")
181
+ other := map[string]any{"delegation_id": longGrant(t, e), "job_id": "job"}
182
+ if r := offline(e, "files.cancelOperation", other); r.Code != "operation-not-found" {
183
+ t.Fatal("tombstone answered another grant", r)
184
+ }
185
+ select {
186
+ case <-w.copying:
187
+ t.Fatal("canceled reference was copied")
188
+ case <-time.After(50 * time.Millisecond):
189
+ }
190
+ }
191
+
192
+ func TestCancelQueuedNeverCopies(t *testing.T) {
193
+ e, _, _ := setup(t)
194
+ id := longGrant(t, e)
195
+ w := newStubbornWriter()
196
+ e.Writer = w
197
+ startedCopy(t, e, w, id, "active")
198
+ if r := offline(e, "files.moveFromStaging", moveParams(id, "queued")); !r.OK {
199
+ t.Fatal(r)
200
+ }
201
+ ref := map[string]any{"delegation_id": id, "job_id": "queued"}
202
+ for i := 0; i < 2; i++ {
203
+ wantOperation(t, offline(e, "files.cancelOperation", ref), "canceled", "OPERATION_CANCELED", "operation-canceled-by-user")
204
+ }
205
+ w.let()
206
+ waitState(t, e, "active", "committed")
207
+ if op := waitState(t, e, "queued", "canceled"); op.Part != nil || op.PublishIntent {
208
+ t.Fatal("canceled queued operation copied", op)
209
+ }
210
+ }
211
+
212
+ func TestCancelRacingPublishReturnsCommitted(t *testing.T) {
213
+ e, _, _ := setup(t)
214
+ id := longGrant(t, e)
215
+ w := newStubbornWriter()
216
+ w.publishing, w.finishPublish = make(chan struct{}), make(chan struct{})
217
+ e.Writer = w
218
+ startedCopy(t, e, w, id, "job")
219
+ w.let()
220
+ <-w.publishing
221
+ reply := make(chan Response, 1)
222
+ go func() {
223
+ reply <- offline(e, "files.cancelOperation", map[string]any{"delegation_id": id, "job_id": "job"})
224
+ }()
225
+ select {
226
+ case r := <-reply:
227
+ t.Fatal("cancel answered inside the publish fence", r)
228
+ case <-time.After(50 * time.Millisecond):
229
+ }
230
+ close(w.finishPublish)
231
+ out := operationOf(t, <-reply)
232
+ if out["state"] != "committed" || out["receipt"] == nil || out["code"] != nil {
233
+ t.Fatal("cancel after publish must report committed", out)
234
+ }
235
+ waitState(t, e, "job", "committed")
236
+ }
@@ -0,0 +1,64 @@
1
+ package main
2
+
3
+ import (
4
+ "bufio"
5
+ "errors"
6
+ "io"
7
+ )
8
+
9
+ // errParentGone means the move parent closed or broke the control pipe during
10
+ // the copy: it exited or was killed, so no one can ever send publish.
11
+ var errParentGone = errors.New("parent gone")
12
+
13
+ type controlLine struct {
14
+ line string
15
+ err error
16
+ }
17
+
18
+ // awaitControl reads the parent's next decision in the background. Pipe EOF
19
+ // is the parent-death signal on every kernel, including 3.10, and unlike
20
+ // PR_SET_PDEATHSIG it survives the child's identity drop and Go's threads.
21
+ func awaitControl(r *bufio.Reader) <-chan controlLine {
22
+ next := make(chan controlLine, 1)
23
+ go func() {
24
+ line, err := r.ReadString('\n')
25
+ next <- controlLine{line, err}
26
+ }()
27
+ return next
28
+ }
29
+
30
+ // copyUnlessParentGone copies exactly size bytes, checking control between
31
+ // chunks. The parent writes nothing during a copy, so any arrival ends it.
32
+ func copyUnlessParentGone(out io.Writer, src io.Reader, size int64, control <-chan controlLine) error {
33
+ limited := io.LimitReader(src, size+1)
34
+ buf := make([]byte, 1<<20)
35
+ var n int64
36
+ for {
37
+ select {
38
+ case <-control:
39
+ return errParentGone
40
+ default:
41
+ }
42
+ m, err := limited.Read(buf)
43
+ if m > 0 {
44
+ if _, werr := out.Write(buf[:m]); werr != nil {
45
+ return werr
46
+ }
47
+ n += int64(m)
48
+ }
49
+ if err == io.EOF {
50
+ break
51
+ }
52
+ if err != nil {
53
+ return err
54
+ }
55
+ }
56
+ if n != size {
57
+ return errors.New("size mismatch")
58
+ }
59
+ return nil
60
+ }
61
+
62
+ func copyExact(out io.Writer, src io.Reader, size int64) error {
63
+ return copyUnlessParentGone(out, src, size, nil)
64
+ }
@@ -0,0 +1,88 @@
1
+ package main
2
+
3
+ import (
4
+ "bufio"
5
+ "bytes"
6
+ "errors"
7
+ "io"
8
+ "os"
9
+ "testing"
10
+ "time"
11
+ )
12
+
13
+ type endlessZeros struct{ read int64 }
14
+
15
+ func (z *endlessZeros) Read(p []byte) (int, error) {
16
+ clear(p)
17
+ z.read += int64(len(p))
18
+ return len(p), nil
19
+ }
20
+
21
+ // The move parent holds the child's control pipe open for the whole copy. If
22
+ // the parent dies, the pipe closes and the child must stop copying at once
23
+ // rather than fill a part file nobody can publish.
24
+ func TestCopyStopsWhenParentClosesControl(t *testing.T) {
25
+ r, w, err := os.Pipe()
26
+ if err != nil {
27
+ t.Fatal(err)
28
+ }
29
+ defer r.Close()
30
+ control := awaitControl(bufio.NewReader(r))
31
+ src := &endlessZeros{}
32
+ done := make(chan error, 1)
33
+ go func() { done <- copyUnlessParentGone(io.Discard, src, 1<<50, control) }()
34
+ time.Sleep(50 * time.Millisecond)
35
+ w.Close()
36
+ select {
37
+ case err := <-done:
38
+ if !errors.Is(err, errParentGone) {
39
+ t.Fatal("want errParentGone, got", err)
40
+ }
41
+ case <-time.After(2 * time.Second):
42
+ t.Fatal("copy continued after the parent closed control")
43
+ }
44
+ }
45
+
46
+ // The parent never writes during the copy; anything arriving there is a
47
+ // protocol violation and stops the copy too.
48
+ func TestCopyStopsOnUnexpectedControlInput(t *testing.T) {
49
+ r, w, err := os.Pipe()
50
+ if err != nil {
51
+ t.Fatal(err)
52
+ }
53
+ defer r.Close()
54
+ defer w.Close()
55
+ control := awaitControl(bufio.NewReader(r))
56
+ done := make(chan error, 1)
57
+ go func() { done <- copyUnlessParentGone(io.Discard, &endlessZeros{}, 1<<50, control) }()
58
+ w.Write([]byte("P\n"))
59
+ select {
60
+ case err := <-done:
61
+ if err == nil {
62
+ t.Fatal("copy accepted early control input")
63
+ }
64
+ case <-time.After(2 * time.Second):
65
+ t.Fatal("copy ignored control input")
66
+ }
67
+ }
68
+
69
+ func TestCopyKeepsExactSizeAndLeavesDecisionForCaller(t *testing.T) {
70
+ r, w, err := os.Pipe()
71
+ if err != nil {
72
+ t.Fatal(err)
73
+ }
74
+ defer r.Close()
75
+ control := awaitControl(bufio.NewReader(r))
76
+ var out bytes.Buffer
77
+ if err = copyUnlessParentGone(&out, bytes.NewReader(make([]byte, 3<<20)), 3<<20, control); err != nil || out.Len() != 3<<20 {
78
+ t.Fatal(out.Len(), err)
79
+ }
80
+ if copyUnlessParentGone(io.Discard, bytes.NewReader(make([]byte, 4)), 3, control) == nil {
81
+ t.Fatal("excess bytes accepted")
82
+ }
83
+ w.Write([]byte("P\n"))
84
+ if got := <-control; got.line != "P\n" || got.err != nil {
85
+ t.Fatal("decision lost", got)
86
+ }
87
+ w.Close()
88
+ }