@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.
- package/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/build-spk/generator.js +3 -0
- package/dist/build-spk/notices.d.ts +5 -0
- package/dist/build-spk/notices.js +60 -0
- package/dist/cli.js +9 -2
- package/dist/error-registry.js +20 -0
- package/dist/init.d.ts +4 -0
- package/dist/init.js +20 -12
- package/dist/standalone/build.js +3 -1
- package/dist/standalone/daemon.d.ts +23 -0
- package/dist/standalone/daemon.js +114 -0
- package/dist/standalone/dsm-window.d.ts +1 -1
- package/dist/standalone/dsm-window.js +50 -10
- package/dist/standalone/helper-inventory.d.ts +16 -0
- package/dist/standalone/helper-inventory.js +2 -0
- package/dist/standalone/helper.d.ts +2 -12
- package/dist/standalone/helper.js +8 -7
- package/dist/standalone/host-adapter.d.ts +5 -0
- package/dist/standalone/host-adapter.js +148 -0
- package/dist/standalone/host-platform.d.ts +13 -0
- package/dist/standalone/host-platform.js +42 -0
- package/dist/standalone/host-types.d.ts +49 -0
- package/dist/standalone/host-types.js +1 -0
- package/dist/standalone/inspect-helper.d.ts +6 -0
- package/dist/standalone/inspect-helper.js +88 -0
- package/dist/standalone/inspect-spk.d.ts +2 -0
- package/dist/standalone/inspect-spk.js +49 -0
- package/dist/standalone/lifecycle-helper.d.ts +2 -0
- package/dist/standalone/lifecycle-helper.js +12 -0
- package/dist/standalone/lifecycle.d.ts +3 -0
- package/dist/standalone/lifecycle.js +53 -0
- package/dist/standalone/manifest.d.ts +2 -0
- package/dist/standalone/manifest.js +4 -1
- package/dist/standalone/reopen-events.d.ts +2 -0
- package/dist/standalone/reopen-events.js +28 -0
- package/dist/standalone/root-messages.js +9 -0
- package/dist/standalone/root-window.d.ts +4 -3
- package/dist/standalone/root-window.js +17 -5
- package/dist/standalone/spk.d.ts +4 -3
- package/dist/standalone/spk.js +20 -33
- package/dist/template-paths.d.ts +2 -0
- package/dist/template-paths.js +9 -0
- package/dist/templates/_daemon/fixture_linux_test.go +15 -0
- package/dist/templates/_daemon/fixture_other_test.go +7 -0
- package/dist/templates/_daemon/go.mod +3 -0
- package/dist/templates/_daemon/main.go +608 -0
- package/dist/templates/_daemon/main_test.go +242 -0
- package/dist/templates/_daemon/process_linux.go +55 -0
- package/dist/templates/_daemon/process_linux_test.go +161 -0
- package/dist/templates/_daemon/process_other.go +14 -0
- package/dist/templates/_daemon/testdata/child.go +41 -0
- package/dist/templates/_shared/GO-LICENSE +27 -0
- package/dist/templates/_shared/GO-PATENTS +22 -0
- package/dist/templates/_shared/LICENSES/TEMPLATE.txt +21 -0
- package/dist/templates/_shared/notice-overrides/index.json +14 -0
- package/dist/templates/_shared/notice-overrides/utils-0.4.2-LICENSE +21 -0
- package/dist/templates/_shared/notice-overrides/utils-0.5.0-LICENSE +21 -0
- package/dist/templates/_shared/third-party-notices.mjs +51 -0
- package/dist/templates/native-go/README.md +57 -1
- package/dist/templates/native-go/backend/THIRD_PARTY_NOTICES.txt +59 -0
- package/dist/templates/native-go/backend/cmd/dsm-readonly-probe/main_linux.go +46 -0
- package/dist/templates/native-go/backend/go.mod +4 -0
- package/dist/templates/native-go/backend/go.sum +4 -0
- package/dist/templates/native-go/backend/internal/api/binary.go +154 -0
- package/dist/templates/native-go/backend/internal/api/binary_test.go +165 -0
- package/dist/templates/native-go/backend/internal/api/registry.go +14 -4
- package/dist/templates/native-go/backend/internal/api/server.go +4 -0
- package/dist/templates/native-go/backend/internal/app/nas_cgi_artifact_test.go +121 -0
- package/dist/templates/native-go/backend/internal/app/nas_refusal_test.go +46 -0
- package/dist/templates/native-go/backend/internal/app/routes.go +11 -0
- package/dist/templates/native-go/backend/internal/app/routes_test.go +10 -5
- package/dist/templates/native-go/backend/internal/dsmprobe/collector_linux.go +335 -0
- package/dist/templates/native-go/backend/internal/dsmprobe/collector_linux_test.go +41 -0
- package/dist/templates/native-go/backend/internal/dsmprobe/protocol.go +179 -0
- package/dist/templates/native-go/backend/internal/dsmprobe/protocol_test.go +29 -0
- package/dist/templates/native-go/backend/internal/helper/cohort.go +393 -0
- package/dist/templates/native-go/backend/internal/helper/cohort_publication.go +18 -0
- package/dist/templates/native-go/backend/internal/helper/cohort_publication_test.go +105 -0
- package/dist/templates/native-go/backend/internal/helper/cohort_test.go +372 -0
- package/dist/templates/native-go/backend/internal/helper/control.go +226 -21
- package/dist/templates/native-go/backend/internal/helper/control_test.go +10 -2
- package/dist/templates/native-go/backend/internal/helper/data_contract.go +242 -0
- package/dist/templates/native-go/backend/internal/helper/data_contract_test.go +51 -0
- package/dist/templates/native-go/backend/internal/helper/data_decode.go +184 -0
- package/dist/templates/native-go/backend/internal/helper/data_decode_pointer_test.go +30 -0
- package/dist/templates/native-go/backend/internal/helper/data_protocol.go +416 -0
- package/dist/templates/native-go/backend/internal/helper/data_protocol_test.go +449 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_acl_linux.go +139 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_acl_linux_test.go +121 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_acl_syscall_linux.go +95 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_acl_syscall_linux_test.go +56 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_bridge_linux.go +144 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_bridge_linux_test.go +89 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_home_linux.go +107 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_home_linux_test.go +82 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_probe_transport_linux.go +151 -0
- package/dist/templates/native-go/backend/internal/helper/dsm_probe_transport_linux_test.go +66 -0
- package/dist/templates/native-go/backend/internal/helper/grant_authority.go +516 -0
- package/dist/templates/native-go/backend/internal/helper/grant_authority_contract.go +88 -0
- package/dist/templates/native-go/backend/internal/helper/grant_authority_test.go +510 -0
- package/dist/templates/native-go/backend/internal/helper/grant_cohort.go +389 -0
- package/dist/templates/native-go/backend/internal/helper/grant_cohort_test.go +239 -0
- package/dist/templates/native-go/backend/internal/helper/grant_delivery.go +49 -0
- package/dist/templates/native-go/backend/internal/helper/grant_delivery_methods.go +273 -0
- package/dist/templates/native-go/backend/internal/helper/grant_delivery_test.go +322 -0
- package/dist/templates/native-go/backend/internal/helper/grant_operation_contract.go +47 -0
- package/dist/templates/native-go/backend/internal/helper/grant_readonly_test.go +180 -0
- package/dist/templates/native-go/backend/internal/helper/grant_repository_linux.go +415 -0
- package/dist/templates/native-go/backend/internal/helper/grant_repository_linux_test.go +468 -0
- package/dist/templates/native-go/backend/internal/helper/grant_rpc.go +147 -0
- package/dist/templates/native-go/backend/internal/helper/grant_rpc_test.go +51 -0
- package/dist/templates/native-go/backend/internal/helper/grant_snapshot.go +75 -0
- package/dist/templates/native-go/backend/internal/helper/grant_supervisor_linux.go +134 -0
- package/dist/templates/native-go/backend/internal/helper/grant_supervisor_linux_test.go +254 -0
- package/dist/templates/native-go/backend/internal/helper/lease.go +112 -0
- package/dist/templates/native-go/backend/internal/helper/lease_linux.go +44 -0
- package/dist/templates/native-go/backend/internal/helper/lease_other.go +8 -0
- package/dist/templates/native-go/backend/internal/helper/lifecycle.go +234 -0
- package/dist/templates/native-go/backend/internal/helper/lifecycle_test.go +473 -0
- package/dist/templates/native-go/backend/internal/helper/managed_pilot.go +284 -0
- package/dist/templates/native-go/backend/internal/helper/managed_pilot_repository_linux.go +74 -0
- package/dist/templates/native-go/backend/internal/helper/managed_pilot_repository_linux_test.go +40 -0
- package/dist/templates/native-go/backend/internal/helper/managed_pilot_test.go +210 -0
- package/dist/templates/native-go/backend/internal/helper/nas_shipped_refusal_linux_test.go +97 -0
- package/dist/templates/native-go/backend/internal/helper/native_discovery.go +79 -0
- package/dist/templates/native-go/backend/internal/helper/native_identity.go +89 -0
- package/dist/templates/native-go/backend/internal/helper/native_provider.go +159 -0
- package/dist/templates/native-go/backend/internal/helper/native_provider_test.go +421 -0
- package/dist/templates/native-go/backend/internal/helper/observation.go +204 -0
- package/dist/templates/native-go/backend/internal/helper/observation_health_test.go +115 -0
- package/dist/templates/native-go/backend/internal/helper/observation_reload_budget_test.go +117 -0
- package/dist/templates/native-go/backend/internal/helper/observation_test.go +196 -0
- package/dist/templates/native-go/backend/internal/helper/observer_diagnostic.go +109 -0
- package/dist/templates/native-go/backend/internal/helper/observer_diagnostic_linux.go +76 -0
- package/dist/templates/native-go/backend/internal/helper/observer_diagnostic_linux_test.go +124 -0
- package/dist/templates/native-go/backend/internal/helper/observer_diagnostic_test.go +98 -0
- package/dist/templates/native-go/backend/internal/helper/operation_bootstrap_linux.go +193 -0
- package/dist/templates/native-go/backend/internal/helper/operation_credentials_linux.go +56 -0
- package/dist/templates/native-go/backend/internal/helper/operation_linux.go +480 -0
- package/dist/templates/native-go/backend/internal/helper/operation_linux_test.go +528 -0
- package/dist/templates/native-go/backend/internal/helper/process_linux.go +11 -1
- package/dist/templates/native-go/backend/internal/helper/publication_test.go +178 -0
- package/dist/templates/native-go/backend/internal/helper/read_stream_cohort_linux_test.go +156 -0
- package/dist/templates/native-go/backend/internal/helper/read_transfer.go +40 -0
- package/dist/templates/native-go/backend/internal/helper/read_transfer_linux.go +109 -0
- package/dist/templates/native-go/backend/internal/helper/read_transfer_linux_test.go +118 -0
- package/dist/templates/native-go/backend/internal/helper/read_transfer_test.go +177 -0
- package/dist/templates/native-go/backend/internal/helper/readonly.go +105 -0
- package/dist/templates/native-go/backend/internal/helper/readonly_admission.go +85 -0
- package/dist/templates/native-go/backend/internal/helper/readonly_cohort_linux_test.go +253 -0
- package/dist/templates/native-go/backend/internal/helper/readonly_linux_test.go +378 -0
- package/dist/templates/native-go/backend/internal/helper/readonly_mount_linux.go +65 -0
- package/dist/templates/native-go/backend/internal/helper/readonly_mount_proxy_linux.go +113 -0
- package/dist/templates/native-go/backend/internal/helper/readonly_operations_linux.go +168 -0
- package/dist/templates/native-go/backend/internal/helper/readonly_resolver_linux.go +241 -0
- package/dist/templates/native-go/backend/internal/helper/readonly_test.go +40 -0
- package/dist/templates/native-go/backend/internal/helper/relaxed_identity.go +252 -0
- package/dist/templates/native-go/backend/internal/helper/relaxed_identity_contract.go +105 -0
- package/dist/templates/native-go/backend/internal/helper/relaxed_identity_test.go +406 -0
- package/dist/templates/native-go/backend/internal/helper/relaxed_invalidation.go +200 -0
- package/dist/templates/native-go/backend/internal/helper/repair.go +132 -0
- package/dist/templates/native-go/backend/internal/helper/repair_test.go +271 -0
- package/dist/templates/native-go/backend/internal/helper/s1r_actor_acl_linux_test.go +303 -0
- package/dist/templates/native-go/backend/internal/helper/s1r_actor_fixture_linux_test.go +184 -0
- package/dist/templates/native-go/backend/internal/helper/s1r_actor_races_linux_test.go +231 -0
- package/dist/templates/native-go/backend/internal/helper/s1r_fixture_contract_linux_test.go +18 -0
- package/dist/templates/native-go/backend/internal/helper/server_linux.go +44 -3
- package/dist/templates/native-go/backend/internal/helper/status.go +74 -11
- package/dist/templates/native-go/backend/internal/helper/status_test.go +83 -0
- package/dist/templates/native-go/backend/internal/helper/supervision.go +28 -5
- package/dist/templates/native-go/backend/internal/helper/supervisor_frame.go +76 -0
- package/dist/templates/native-go/backend/internal/helper/supervisor_frame_linux_test.go +69 -0
- package/dist/templates/native-go/backend/internal/helper/supervisor_frame_test.go +107 -0
- package/dist/templates/native-go/backend/internal/helper/supervisor_linux.go +187 -16
- package/dist/templates/native-go/backend/internal/helper/supervisor_linux_test.go +618 -7
- package/dist/templates/native-go/backend/internal/helper/supervisor_socket_eof_test.go +74 -0
- package/dist/templates/native-go/backend/internal/helper/supervisor_socket_test.go +45 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/create.json +23 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/frames.json +67 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/grant-store.json +52 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/intent.json +20 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/list.json +20 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/publish.json +20 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/read.json +22 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/stat.json +22 -0
- package/dist/templates/native-go/backend/internal/helper/testdata/protocol2/write-stream.json +22 -0
- package/dist/templates/native-go/backend/internal/helper/unit_connection.go +75 -0
- package/dist/templates/native-go/backend/internal/helper/unit_connection_linux_test.go +135 -0
- package/dist/templates/native-go/backend/internal/helper/unit_connection_test.go +133 -0
- package/dist/templates/native-go/backend/internal/helper/unit_frame_test.go +32 -0
- package/dist/templates/native-go/backend/internal/helper/unit_linux.go +364 -0
- package/dist/templates/native-go/backend/internal/helper/unit_linux_test.go +46 -0
- package/dist/templates/native-go/backend/internal/helper/unit_mechanisms_linux_test.go +217 -0
- package/dist/templates/native-go/backend/internal/helper/unit_padding_linux_test.go +178 -0
- package/dist/templates/native-go/backend/internal/helper/unit_query_linux.go +111 -0
- package/dist/templates/native-go/backend/internal/helper/unit_reload_linux_test.go +372 -0
- package/dist/templates/native-go/backend/internal/helper/unit_reload_sequence_linux_test.go +232 -0
- package/dist/templates/native-go/backend/internal/helper/write.go +77 -0
- package/dist/templates/native-go/backend/internal/helper/write_admission.go +260 -0
- package/dist/templates/native-go/backend/internal/helper/write_admission_test.go +135 -0
- package/dist/templates/native-go/backend/internal/helper/write_cohort_linux_test.go +218 -0
- package/dist/templates/native-go/backend/internal/helper/write_files_linux.go +202 -0
- package/dist/templates/native-go/backend/internal/helper/write_files_linux_test.go +199 -0
- package/dist/templates/native-go/backend/internal/helper/write_intent_linux.go +116 -0
- package/dist/templates/native-go/backend/internal/helper/write_intent_linux_test.go +74 -0
- package/dist/templates/native-go/backend/internal/helper/write_operation_linux.go +245 -0
- package/dist/templates/native-go/backend/internal/helper/write_test.go +53 -0
- package/dist/templates/native-go/ui/app.js +8 -1
- package/dist/templates/native-go-better-auth/node/build.mjs +2 -0
- package/dist/templates/native-go-vue/README.md +115 -1
- package/dist/templates/native-go-vue/frontend/DESIGN.md +1 -1
- package/dist/templates/native-go-vue/frontend/package-lock.json +132 -229
- package/dist/templates/native-go-vue/frontend/package.json +1 -1
- package/dist/templates/native-go-vue/frontend/src/App.vue +33 -6
- package/dist/templates/native-go-vue/frontend/src/context.ts +41 -2
- package/dist/templates/native-go-vue/frontend/src/main.ts +4 -1
- package/dist/templates/native-go-vue/frontend/src/nas/NasGrantSettings.vue +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/NasPathPicker.vue +106 -0
- package/dist/templates/native-go-vue/frontend/src/nas/NasUnavailable.vue +20 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/de.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/en.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/es.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/fr.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/it.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/ja.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/ko.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/zh-CN.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n/zh-TW.json +74 -0
- package/dist/templates/native-go-vue/frontend/src/nas/i18n.ts +38 -0
- package/dist/templates/native-go-vue/frontend/src/nas/mock-provider.ts +119 -0
- package/dist/templates/native-go-vue/frontend/src/nas/provider.ts +59 -0
- package/dist/templates/native-go-vue/frontend/src/nas/use-request.ts +27 -0
- package/dist/templates/native-go-vue/frontend/src/style.css +17 -0
- package/dist/templates/native-go-vue/frontend/test/apps.test.ts +44 -2
- package/dist/templates/native-go-vue/frontend/test/nas-provider.test.ts +81 -0
- package/dist/templates/native-go-vue/frontend/test/nas-request.test.ts +21 -0
- package/dist/templates/native-go-vue/frontend/test/nas-ui.test.ts +261 -0
- package/dist/templates/native-go-vue/frontend/tsconfig.json +1 -1
- package/dist/templates/native-go-vue/frontend/vite.config.ts +6 -4
- package/package.json +3 -2
- package/templates/_daemon/fixture_linux_test.go +15 -0
- package/templates/_daemon/fixture_other_test.go +7 -0
- package/templates/_daemon/go.mod +3 -0
- package/templates/_daemon/main.go +608 -0
- package/templates/_daemon/main_test.go +242 -0
- package/templates/_daemon/process_linux.go +55 -0
- package/templates/_daemon/process_linux_test.go +161 -0
- package/templates/_daemon/process_other.go +14 -0
- package/templates/_daemon/testdata/child.go +41 -0
- package/templates/_shared/GO-LICENSE +27 -0
- package/templates/_shared/GO-PATENTS +22 -0
- package/templates/_shared/LICENSES/TEMPLATE.txt +21 -0
- package/templates/_shared/notice-overrides/index.json +14 -0
- package/templates/_shared/notice-overrides/utils-0.4.2-LICENSE +21 -0
- package/templates/_shared/notice-overrides/utils-0.5.0-LICENSE +21 -0
- package/templates/_shared/third-party-notices.mjs +51 -0
- package/templates/native-go/README.md +57 -1
- package/templates/native-go/backend/THIRD_PARTY_NOTICES.txt +59 -0
- package/templates/native-go/backend/cmd/dsm-readonly-probe/main_linux.go +46 -0
- package/templates/native-go/backend/go.mod +4 -0
- package/templates/native-go/backend/go.sum +4 -0
- package/templates/native-go/backend/internal/api/binary.go +154 -0
- package/templates/native-go/backend/internal/api/binary_test.go +165 -0
- package/templates/native-go/backend/internal/api/registry.go +14 -4
- package/templates/native-go/backend/internal/api/server.go +4 -0
- package/templates/native-go/backend/internal/app/nas_cgi_artifact_test.go +121 -0
- package/templates/native-go/backend/internal/app/nas_refusal_test.go +46 -0
- package/templates/native-go/backend/internal/app/routes.go +11 -0
- package/templates/native-go/backend/internal/app/routes_test.go +10 -5
- package/templates/native-go/backend/internal/dsmprobe/collector_linux.go +335 -0
- package/templates/native-go/backend/internal/dsmprobe/collector_linux_test.go +41 -0
- package/templates/native-go/backend/internal/dsmprobe/protocol.go +179 -0
- package/templates/native-go/backend/internal/dsmprobe/protocol_test.go +29 -0
- package/templates/native-go/backend/internal/helper/cohort.go +393 -0
- package/templates/native-go/backend/internal/helper/cohort_publication.go +18 -0
- package/templates/native-go/backend/internal/helper/cohort_publication_test.go +105 -0
- package/templates/native-go/backend/internal/helper/cohort_test.go +372 -0
- package/templates/native-go/backend/internal/helper/control.go +226 -21
- package/templates/native-go/backend/internal/helper/control_test.go +10 -2
- package/templates/native-go/backend/internal/helper/data_contract.go +242 -0
- package/templates/native-go/backend/internal/helper/data_contract_test.go +51 -0
- package/templates/native-go/backend/internal/helper/data_decode.go +184 -0
- package/templates/native-go/backend/internal/helper/data_decode_pointer_test.go +30 -0
- package/templates/native-go/backend/internal/helper/data_protocol.go +416 -0
- package/templates/native-go/backend/internal/helper/data_protocol_test.go +449 -0
- package/templates/native-go/backend/internal/helper/dsm_acl_linux.go +139 -0
- package/templates/native-go/backend/internal/helper/dsm_acl_linux_test.go +121 -0
- package/templates/native-go/backend/internal/helper/dsm_acl_syscall_linux.go +95 -0
- package/templates/native-go/backend/internal/helper/dsm_acl_syscall_linux_test.go +56 -0
- package/templates/native-go/backend/internal/helper/dsm_bridge_linux.go +144 -0
- package/templates/native-go/backend/internal/helper/dsm_bridge_linux_test.go +89 -0
- package/templates/native-go/backend/internal/helper/dsm_home_linux.go +107 -0
- package/templates/native-go/backend/internal/helper/dsm_home_linux_test.go +82 -0
- package/templates/native-go/backend/internal/helper/dsm_probe_transport_linux.go +151 -0
- package/templates/native-go/backend/internal/helper/dsm_probe_transport_linux_test.go +66 -0
- package/templates/native-go/backend/internal/helper/grant_authority.go +516 -0
- package/templates/native-go/backend/internal/helper/grant_authority_contract.go +88 -0
- package/templates/native-go/backend/internal/helper/grant_authority_test.go +510 -0
- package/templates/native-go/backend/internal/helper/grant_cohort.go +389 -0
- package/templates/native-go/backend/internal/helper/grant_cohort_test.go +239 -0
- package/templates/native-go/backend/internal/helper/grant_delivery.go +49 -0
- package/templates/native-go/backend/internal/helper/grant_delivery_methods.go +273 -0
- package/templates/native-go/backend/internal/helper/grant_delivery_test.go +322 -0
- package/templates/native-go/backend/internal/helper/grant_operation_contract.go +47 -0
- package/templates/native-go/backend/internal/helper/grant_readonly_test.go +180 -0
- package/templates/native-go/backend/internal/helper/grant_repository_linux.go +415 -0
- package/templates/native-go/backend/internal/helper/grant_repository_linux_test.go +468 -0
- package/templates/native-go/backend/internal/helper/grant_rpc.go +147 -0
- package/templates/native-go/backend/internal/helper/grant_rpc_test.go +51 -0
- package/templates/native-go/backend/internal/helper/grant_snapshot.go +75 -0
- package/templates/native-go/backend/internal/helper/grant_supervisor_linux.go +134 -0
- package/templates/native-go/backend/internal/helper/grant_supervisor_linux_test.go +254 -0
- package/templates/native-go/backend/internal/helper/lease.go +112 -0
- package/templates/native-go/backend/internal/helper/lease_linux.go +44 -0
- package/templates/native-go/backend/internal/helper/lease_other.go +8 -0
- package/templates/native-go/backend/internal/helper/lifecycle.go +234 -0
- package/templates/native-go/backend/internal/helper/lifecycle_test.go +473 -0
- package/templates/native-go/backend/internal/helper/managed_pilot.go +284 -0
- package/templates/native-go/backend/internal/helper/managed_pilot_repository_linux.go +74 -0
- package/templates/native-go/backend/internal/helper/managed_pilot_repository_linux_test.go +40 -0
- package/templates/native-go/backend/internal/helper/managed_pilot_test.go +210 -0
- package/templates/native-go/backend/internal/helper/nas_shipped_refusal_linux_test.go +97 -0
- package/templates/native-go/backend/internal/helper/native_discovery.go +79 -0
- package/templates/native-go/backend/internal/helper/native_identity.go +89 -0
- package/templates/native-go/backend/internal/helper/native_provider.go +159 -0
- package/templates/native-go/backend/internal/helper/native_provider_test.go +421 -0
- package/templates/native-go/backend/internal/helper/observation.go +204 -0
- package/templates/native-go/backend/internal/helper/observation_health_test.go +115 -0
- package/templates/native-go/backend/internal/helper/observation_reload_budget_test.go +117 -0
- package/templates/native-go/backend/internal/helper/observation_test.go +196 -0
- package/templates/native-go/backend/internal/helper/observer_diagnostic.go +109 -0
- package/templates/native-go/backend/internal/helper/observer_diagnostic_linux.go +76 -0
- package/templates/native-go/backend/internal/helper/observer_diagnostic_linux_test.go +124 -0
- package/templates/native-go/backend/internal/helper/observer_diagnostic_test.go +98 -0
- package/templates/native-go/backend/internal/helper/operation_bootstrap_linux.go +193 -0
- package/templates/native-go/backend/internal/helper/operation_credentials_linux.go +56 -0
- package/templates/native-go/backend/internal/helper/operation_linux.go +480 -0
- package/templates/native-go/backend/internal/helper/operation_linux_test.go +528 -0
- package/templates/native-go/backend/internal/helper/process_linux.go +11 -1
- package/templates/native-go/backend/internal/helper/publication_test.go +178 -0
- package/templates/native-go/backend/internal/helper/read_stream_cohort_linux_test.go +156 -0
- package/templates/native-go/backend/internal/helper/read_transfer.go +40 -0
- package/templates/native-go/backend/internal/helper/read_transfer_linux.go +109 -0
- package/templates/native-go/backend/internal/helper/read_transfer_linux_test.go +118 -0
- package/templates/native-go/backend/internal/helper/read_transfer_test.go +177 -0
- package/templates/native-go/backend/internal/helper/readonly.go +105 -0
- package/templates/native-go/backend/internal/helper/readonly_admission.go +85 -0
- package/templates/native-go/backend/internal/helper/readonly_cohort_linux_test.go +253 -0
- package/templates/native-go/backend/internal/helper/readonly_linux_test.go +378 -0
- package/templates/native-go/backend/internal/helper/readonly_mount_linux.go +65 -0
- package/templates/native-go/backend/internal/helper/readonly_mount_proxy_linux.go +113 -0
- package/templates/native-go/backend/internal/helper/readonly_operations_linux.go +168 -0
- package/templates/native-go/backend/internal/helper/readonly_resolver_linux.go +241 -0
- package/templates/native-go/backend/internal/helper/readonly_test.go +40 -0
- package/templates/native-go/backend/internal/helper/relaxed_identity.go +252 -0
- package/templates/native-go/backend/internal/helper/relaxed_identity_contract.go +105 -0
- package/templates/native-go/backend/internal/helper/relaxed_identity_test.go +406 -0
- package/templates/native-go/backend/internal/helper/relaxed_invalidation.go +200 -0
- package/templates/native-go/backend/internal/helper/repair.go +132 -0
- package/templates/native-go/backend/internal/helper/repair_test.go +271 -0
- package/templates/native-go/backend/internal/helper/s1r_actor_acl_linux_test.go +303 -0
- package/templates/native-go/backend/internal/helper/s1r_actor_fixture_linux_test.go +184 -0
- package/templates/native-go/backend/internal/helper/s1r_actor_races_linux_test.go +231 -0
- package/templates/native-go/backend/internal/helper/s1r_fixture_contract_linux_test.go +18 -0
- package/templates/native-go/backend/internal/helper/server_linux.go +44 -3
- package/templates/native-go/backend/internal/helper/status.go +74 -11
- package/templates/native-go/backend/internal/helper/status_test.go +83 -0
- package/templates/native-go/backend/internal/helper/supervision.go +28 -5
- package/templates/native-go/backend/internal/helper/supervisor_frame.go +76 -0
- package/templates/native-go/backend/internal/helper/supervisor_frame_linux_test.go +69 -0
- package/templates/native-go/backend/internal/helper/supervisor_frame_test.go +107 -0
- package/templates/native-go/backend/internal/helper/supervisor_linux.go +187 -16
- package/templates/native-go/backend/internal/helper/supervisor_linux_test.go +618 -7
- package/templates/native-go/backend/internal/helper/supervisor_socket_eof_test.go +74 -0
- package/templates/native-go/backend/internal/helper/supervisor_socket_test.go +45 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/create.json +23 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/frames.json +67 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/grant-store.json +52 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/intent.json +20 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/list.json +20 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/publish.json +20 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/read.json +22 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/stat.json +22 -0
- package/templates/native-go/backend/internal/helper/testdata/protocol2/write-stream.json +22 -0
- package/templates/native-go/backend/internal/helper/unit_connection.go +75 -0
- package/templates/native-go/backend/internal/helper/unit_connection_linux_test.go +135 -0
- package/templates/native-go/backend/internal/helper/unit_connection_test.go +133 -0
- package/templates/native-go/backend/internal/helper/unit_frame_test.go +32 -0
- package/templates/native-go/backend/internal/helper/unit_linux.go +364 -0
- package/templates/native-go/backend/internal/helper/unit_linux_test.go +46 -0
- package/templates/native-go/backend/internal/helper/unit_mechanisms_linux_test.go +217 -0
- package/templates/native-go/backend/internal/helper/unit_padding_linux_test.go +178 -0
- package/templates/native-go/backend/internal/helper/unit_query_linux.go +111 -0
- package/templates/native-go/backend/internal/helper/unit_reload_linux_test.go +372 -0
- package/templates/native-go/backend/internal/helper/unit_reload_sequence_linux_test.go +232 -0
- package/templates/native-go/backend/internal/helper/write.go +77 -0
- package/templates/native-go/backend/internal/helper/write_admission.go +260 -0
- package/templates/native-go/backend/internal/helper/write_admission_test.go +135 -0
- package/templates/native-go/backend/internal/helper/write_cohort_linux_test.go +218 -0
- package/templates/native-go/backend/internal/helper/write_files_linux.go +202 -0
- package/templates/native-go/backend/internal/helper/write_files_linux_test.go +199 -0
- package/templates/native-go/backend/internal/helper/write_intent_linux.go +116 -0
- package/templates/native-go/backend/internal/helper/write_intent_linux_test.go +74 -0
- package/templates/native-go/backend/internal/helper/write_operation_linux.go +245 -0
- package/templates/native-go/backend/internal/helper/write_test.go +53 -0
- package/templates/native-go/ui/app.js +8 -1
- package/templates/native-go-better-auth/node/build.mjs +2 -0
- package/templates/native-go-vue/README.md +115 -1
- package/templates/native-go-vue/frontend/DESIGN.md +1 -1
- package/templates/native-go-vue/frontend/package-lock.json +132 -229
- package/templates/native-go-vue/frontend/package.json +1 -1
- package/templates/native-go-vue/frontend/src/App.vue +33 -6
- package/templates/native-go-vue/frontend/src/context.ts +41 -2
- package/templates/native-go-vue/frontend/src/main.ts +4 -1
- package/templates/native-go-vue/frontend/src/nas/NasGrantSettings.vue +74 -0
- package/templates/native-go-vue/frontend/src/nas/NasPathPicker.vue +106 -0
- package/templates/native-go-vue/frontend/src/nas/NasUnavailable.vue +20 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/de.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/en.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/es.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/fr.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/it.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/ja.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/ko.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/zh-CN.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n/zh-TW.json +74 -0
- package/templates/native-go-vue/frontend/src/nas/i18n.ts +38 -0
- package/templates/native-go-vue/frontend/src/nas/mock-provider.ts +119 -0
- package/templates/native-go-vue/frontend/src/nas/provider.ts +59 -0
- package/templates/native-go-vue/frontend/src/nas/use-request.ts +27 -0
- package/templates/native-go-vue/frontend/src/style.css +17 -0
- package/templates/native-go-vue/frontend/test/apps.test.ts +44 -2
- package/templates/native-go-vue/frontend/test/nas-provider.test.ts +81 -0
- package/templates/native-go-vue/frontend/test/nas-request.test.ts +21 -0
- package/templates/native-go-vue/frontend/test/nas-ui.test.ts +261 -0
- package/templates/native-go-vue/frontend/tsconfig.json +1 -1
- package/templates/native-go-vue/frontend/vite.config.ts +6 -4
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
package helper
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"crypto/rand"
|
|
6
|
+
"crypto/sha256"
|
|
7
|
+
"encoding/hex"
|
|
8
|
+
"encoding/json"
|
|
9
|
+
"errors"
|
|
10
|
+
"io"
|
|
11
|
+
"io/fs"
|
|
12
|
+
"os"
|
|
13
|
+
"path/filepath"
|
|
14
|
+
"strings"
|
|
15
|
+
"syscall"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
// Lifecycle is deliberately unknown to old strict approval parsers. A separate
|
|
19
|
+
// latch file alone would let an approved pre-M1g controller resurrect a helper.
|
|
20
|
+
type Binding struct {
|
|
21
|
+
Entered uint64 `json:"entered"`
|
|
22
|
+
Boot string `json:"boot"`
|
|
23
|
+
Install string `json:"install"`
|
|
24
|
+
}
|
|
25
|
+
type Lifecycle struct {
|
|
26
|
+
Schema int `json:"schema"`
|
|
27
|
+
Lease *Lease `json:"lease,omitempty"`
|
|
28
|
+
Epoch string `json:"epoch"`
|
|
29
|
+
Binding Binding `json:"binding"`
|
|
30
|
+
Phase string `json:"phase"`
|
|
31
|
+
Reason string `json:"reason,omitempty"`
|
|
32
|
+
SubReason string `json:"subReason,omitempty"`
|
|
33
|
+
Completion string `json:"completion,omitempty"`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func (l *Lifecycle) valid() bool {
|
|
37
|
+
if l == nil {
|
|
38
|
+
return true
|
|
39
|
+
} // legacy is diagnostic/cleanup only; never start/recover
|
|
40
|
+
if l.Schema != 2 || !digestPattern.MatchString(l.Epoch) || l.Binding.Boot == "" || l.Binding.Entered == 0 || !digestPattern.MatchString(l.Binding.Install) {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
if l.Lease != nil && l.Lease.Inode == 0 {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
if l.Phase != "running" && l.Phase != "fenced" && l.Phase != "stopped" {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
if l.Completion != "" {
|
|
50
|
+
return l.Phase == "stopped" && digestPattern.MatchString(l.Completion)
|
|
51
|
+
}
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var errBusy = errors.New("lifecycle busy")
|
|
56
|
+
|
|
57
|
+
func policyUpdate(c Client, change func(*Record) error) error {
|
|
58
|
+
if err := protected(c.StateDir, c.Owner, true); err != nil {
|
|
59
|
+
return err
|
|
60
|
+
}
|
|
61
|
+
f, err := os.OpenFile(filepath.Join(c.StateDir, "policy.lock"), os.O_CREATE|os.O_RDWR|syscall.O_NOFOLLOW, 0600)
|
|
62
|
+
if err != nil {
|
|
63
|
+
return err
|
|
64
|
+
}
|
|
65
|
+
defer f.Close()
|
|
66
|
+
if err := protected(f.Name(), c.Owner, false); err != nil {
|
|
67
|
+
return err
|
|
68
|
+
}
|
|
69
|
+
if err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
|
|
70
|
+
return errBusy
|
|
71
|
+
}
|
|
72
|
+
defer syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
|
|
73
|
+
r, err := readRecord(c.StateDir, c.Owner)
|
|
74
|
+
if errors.Is(err, fs.ErrNotExist) {
|
|
75
|
+
r = Record{Inventory: c.Expected}
|
|
76
|
+
} else if err != nil {
|
|
77
|
+
return err
|
|
78
|
+
}
|
|
79
|
+
if err := change(&r); err != nil {
|
|
80
|
+
return err
|
|
81
|
+
}
|
|
82
|
+
r.Schema = 2
|
|
83
|
+
return writeProtected(c.StateDir, "approval.json", r)
|
|
84
|
+
}
|
|
85
|
+
func fenceRecord(c Client, epoch, reason string, detail ...string) error {
|
|
86
|
+
return policyUpdate(c, func(r *Record) error {
|
|
87
|
+
if r.Lifecycle == nil || r.Lifecycle.Epoch != epoch || r.Inventory != c.Expected {
|
|
88
|
+
return errTrust
|
|
89
|
+
}
|
|
90
|
+
if r.Lifecycle.Phase == "stopped" {
|
|
91
|
+
return errTrust
|
|
92
|
+
}
|
|
93
|
+
r.Lifecycle.Phase = "fenced"
|
|
94
|
+
if r.Lifecycle.Reason == "" {
|
|
95
|
+
r.Lifecycle.Reason = reason
|
|
96
|
+
if len(detail) > 0 {
|
|
97
|
+
r.Lifecycle.SubReason = detail[0]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
r.Lifecycle.Completion = ""
|
|
101
|
+
r.Residual = true
|
|
102
|
+
return nil
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
func runtimeAbsent(c Client) bool {
|
|
106
|
+
for _, name := range []string{"process.json", "helper.sock", "supervisor.sock"} {
|
|
107
|
+
if _, err := os.Lstat(filepath.Join(c.RunDir, name)); !errors.Is(err, fs.ErrNotExist) {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return true
|
|
112
|
+
}
|
|
113
|
+
func completeRecord(c Client, epoch string, p Process, cohort ...*CohortCompletion) error {
|
|
114
|
+
var q *CohortCompletion
|
|
115
|
+
if len(cohort) > 1 {
|
|
116
|
+
return errTrust
|
|
117
|
+
}
|
|
118
|
+
if len(cohort) == 1 {
|
|
119
|
+
q = cohort[0]
|
|
120
|
+
if q != nil && !q.valid() {
|
|
121
|
+
return errTrust
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return policyUpdate(c, func(r *Record) error {
|
|
125
|
+
if r.Lifecycle == nil || r.Lifecycle.Epoch != epoch || r.Inventory != c.Expected || r.Lifecycle.Phase != "fenced" || !runtimeAbsent(c) || p.Inventory != r.Inventory || p.Boot != r.Lifecycle.Binding.Boot || p.Mode != "supervised" || p.PID <= 1 || p.Start == "" || p.Inode == 0 {
|
|
126
|
+
return errTrust
|
|
127
|
+
}
|
|
128
|
+
r.Lifecycle.Phase = "stopped"
|
|
129
|
+
proof := Completion{Epoch: epoch, Process: p, Cohort: q}
|
|
130
|
+
return storeCompletion(c, r, proof)
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// storeCompletion publishes the private artifact before the approval commit.
|
|
135
|
+
// The caller holds policy.lock and has already established runtime quiescence.
|
|
136
|
+
func storeCompletion(c Client, r *Record, proof Completion) error {
|
|
137
|
+
bytes, err := json.Marshal(proof)
|
|
138
|
+
if err != nil {
|
|
139
|
+
return err
|
|
140
|
+
}
|
|
141
|
+
if err := writeProtected(c.StateDir, "completion-"+r.Lifecycle.Epoch+".json", proof); err != nil {
|
|
142
|
+
return err
|
|
143
|
+
}
|
|
144
|
+
sum := sha256.Sum256(bytes)
|
|
145
|
+
r.Lifecycle.Completion = hex.EncodeToString(sum[:])
|
|
146
|
+
r.Residual = false
|
|
147
|
+
return nil
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
func finalizeStart(c Client, epoch string) error {
|
|
151
|
+
return policyUpdate(c, func(r *Record) error {
|
|
152
|
+
if !r.Enabled || r.Inventory != c.Expected || r.Lifecycle == nil || r.Lifecycle.Epoch != epoch || r.Lifecycle.Phase != "running" {
|
|
153
|
+
return errTrust
|
|
154
|
+
}
|
|
155
|
+
r.Residual = false
|
|
156
|
+
return nil
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
func newLifecycle(b Binding) (*Lifecycle, error) {
|
|
160
|
+
var nonce [32]byte
|
|
161
|
+
if _, err := rand.Read(nonce[:]); err != nil {
|
|
162
|
+
return nil, err
|
|
163
|
+
}
|
|
164
|
+
l := &Lifecycle{Schema: 2, Epoch: hex.EncodeToString(nonce[:]), Binding: b, Phase: "running"}
|
|
165
|
+
if !l.valid() {
|
|
166
|
+
return nil, errTrust
|
|
167
|
+
}
|
|
168
|
+
return l, nil
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Observe is injected only by tests. Production requires the fixed root bus
|
|
172
|
+
// observer; nil cannot mean permission to start.
|
|
173
|
+
type Observation func(context.Context, Inventory) (Binding, error)
|
|
174
|
+
|
|
175
|
+
// The approval digest is the commit point. An orphan private proof cannot
|
|
176
|
+
// authorize cleanup, and CGI status never needs access to private process IDs.
|
|
177
|
+
type Completion struct {
|
|
178
|
+
Epoch string `json:"epoch"`
|
|
179
|
+
Process Process `json:"process"`
|
|
180
|
+
Repair *RepairCompletion `json:"repair,omitempty"`
|
|
181
|
+
Cohort *CohortCompletion `json:"cohort,omitempty"`
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
func completionRecord(c Client, r Record) (Completion, error) {
|
|
185
|
+
var proof Completion
|
|
186
|
+
if r.Lifecycle == nil || r.Lifecycle.Phase != "stopped" || r.Lifecycle.Completion == "" {
|
|
187
|
+
return proof, errTrust
|
|
188
|
+
}
|
|
189
|
+
path := filepath.Join(c.StateDir, "completion-"+r.Lifecycle.Epoch+".json")
|
|
190
|
+
if err := protected(c.StateDir, c.Owner, true); err != nil {
|
|
191
|
+
return proof, err
|
|
192
|
+
}
|
|
193
|
+
f, err := os.OpenFile(path, os.O_RDONLY|syscall.O_NOFOLLOW, 0)
|
|
194
|
+
if err != nil {
|
|
195
|
+
return proof, err
|
|
196
|
+
}
|
|
197
|
+
defer f.Close()
|
|
198
|
+
st, err := f.Stat()
|
|
199
|
+
if err != nil {
|
|
200
|
+
return proof, err
|
|
201
|
+
}
|
|
202
|
+
stat, ok := st.Sys().(*syscall.Stat_t)
|
|
203
|
+
if !ok || stat.Uid != c.Owner || !st.Mode().IsRegular() || st.Mode().Perm() != 0600 || st.Size() > 4096 {
|
|
204
|
+
return proof, errTrust
|
|
205
|
+
}
|
|
206
|
+
bytes, err := io.ReadAll(io.LimitReader(f, 4097))
|
|
207
|
+
if err != nil {
|
|
208
|
+
return proof, err
|
|
209
|
+
}
|
|
210
|
+
sum := sha256.Sum256(bytes)
|
|
211
|
+
if hex.EncodeToString(sum[:]) != r.Lifecycle.Completion {
|
|
212
|
+
return proof, errTrust
|
|
213
|
+
}
|
|
214
|
+
d := json.NewDecoder(strings.NewReader(string(bytes)))
|
|
215
|
+
d.DisallowUnknownFields()
|
|
216
|
+
if d.Decode(&proof) != nil || d.Decode(new(any)) != io.EOF {
|
|
217
|
+
return proof, errTrust
|
|
218
|
+
}
|
|
219
|
+
if proof.Cohort != nil && (!proof.Cohort.valid() || proof.Repair != nil) {
|
|
220
|
+
return proof, errTrust
|
|
221
|
+
}
|
|
222
|
+
if proof.Repair != nil {
|
|
223
|
+
q := proof.Repair
|
|
224
|
+
if proof.Epoch != r.Lifecycle.Epoch || proof.Process != (Process{}) || q.Inventory != r.Inventory || q.Boot != r.Lifecycle.Binding.Boot || r.Lifecycle.Lease == nil || q.Lease != *r.Lifecycle.Lease {
|
|
225
|
+
return proof, errTrust
|
|
226
|
+
}
|
|
227
|
+
return proof, nil
|
|
228
|
+
}
|
|
229
|
+
p := proof.Process
|
|
230
|
+
if proof.Epoch != r.Lifecycle.Epoch || p.Inventory != r.Inventory || p.Mode != "supervised" || p.Boot != r.Lifecycle.Binding.Boot || p.PID <= 1 || p.Start == "" || p.Inode == 0 {
|
|
231
|
+
return proof, errTrust
|
|
232
|
+
}
|
|
233
|
+
return proof, nil
|
|
234
|
+
}
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
package helper
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"errors"
|
|
7
|
+
"os"
|
|
8
|
+
"path/filepath"
|
|
9
|
+
"strings"
|
|
10
|
+
"syscall"
|
|
11
|
+
"testing"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
func testBinding() Binding {
|
|
15
|
+
return Binding{Boot: "fixture-boot", Entered: 7, Install: strings.Repeat("c", 64)}
|
|
16
|
+
}
|
|
17
|
+
func testLifecycle(phase string) *Lifecycle {
|
|
18
|
+
return &Lifecycle{Schema: 2, Epoch: strings.Repeat("d", 64), Binding: testBinding(), Phase: phase}
|
|
19
|
+
}
|
|
20
|
+
func TestLifecycleUnavailableRefusesBeforeStart(t *testing.T) {
|
|
21
|
+
c, f := controlFixture(t)
|
|
22
|
+
c.Observe = func(context.Context, Inventory) (Binding, error) { return Binding{}, errors.New("bus unavailable") }
|
|
23
|
+
if c.Control(context.Background(), "enable") == nil || f.started != 0 {
|
|
24
|
+
t.Fatal("unknown authority started helper")
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
func TestLifecycleStopLatchAndExplicitRecover(t *testing.T) {
|
|
28
|
+
c, f := controlFixture(t)
|
|
29
|
+
r := Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("running")}
|
|
30
|
+
record(t, c.Client, r)
|
|
31
|
+
if err := fenceRecord(c.Client, r.Lifecycle.Epoch, "unit-stopped"); err != nil {
|
|
32
|
+
t.Fatal(err)
|
|
33
|
+
}
|
|
34
|
+
s := c.Status(context.Background())
|
|
35
|
+
if s.State != "failed" || s.Cleanup != "required" {
|
|
36
|
+
t.Fatal(s)
|
|
37
|
+
}
|
|
38
|
+
r, _ = readRecord(c.StateDir, c.Owner)
|
|
39
|
+
if !r.Enabled || r.Lifecycle.Phase != "fenced" {
|
|
40
|
+
t.Fatal(r)
|
|
41
|
+
}
|
|
42
|
+
if err := c.Control(context.Background(), "teardown"); err != nil {
|
|
43
|
+
t.Fatal(err)
|
|
44
|
+
}
|
|
45
|
+
if err := c.Control(context.Background(), "recover"); err != nil {
|
|
46
|
+
t.Fatal(err)
|
|
47
|
+
}
|
|
48
|
+
got, _ := readRecord(c.StateDir, c.Owner)
|
|
49
|
+
if got.Lifecycle.Epoch == r.Lifecycle.Epoch || got.Lifecycle.Phase != "running" || f.started != 1 {
|
|
50
|
+
t.Fatal(got)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
func TestLifecycleRecoverRejectsChangedInstallAndReboot(t *testing.T) {
|
|
54
|
+
for _, which := range []string{"install", "boot"} {
|
|
55
|
+
t.Run(which, func(t *testing.T) {
|
|
56
|
+
c, f := controlFixture(t)
|
|
57
|
+
record(t, c.Client, Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("stopped")})
|
|
58
|
+
c.Observe = func(context.Context, Inventory) (Binding, error) {
|
|
59
|
+
b := testBinding()
|
|
60
|
+
if which == "boot" {
|
|
61
|
+
b.Boot = "reboot"
|
|
62
|
+
} else {
|
|
63
|
+
b.Install = strings.Repeat("e", 64)
|
|
64
|
+
}
|
|
65
|
+
return b, nil
|
|
66
|
+
}
|
|
67
|
+
if c.Control(context.Background(), "recover") == nil || f.started != 0 {
|
|
68
|
+
t.Fatal("continuity changed")
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
func TestLifecycleOldStrictControllerCannotReplay(t *testing.T) {
|
|
74
|
+
c, _ := controlFixture(t)
|
|
75
|
+
record(t, c.Client, Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("stopped")})
|
|
76
|
+
b, _ := os.ReadFile(filepath.Join(c.StateDir, "approval.json"))
|
|
77
|
+
var legacy struct {
|
|
78
|
+
Inventory Inventory `json:"inventory"`
|
|
79
|
+
Enabled bool `json:"enabled"`
|
|
80
|
+
Residual bool `json:"residual,omitempty"`
|
|
81
|
+
}
|
|
82
|
+
d := json.NewDecoder(strings.NewReader(string(b)))
|
|
83
|
+
d.DisallowUnknownFields()
|
|
84
|
+
if d.Decode(&legacy) == nil {
|
|
85
|
+
t.Fatal("old payload can ignore latch")
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
func TestLifecycleStartupFinalizationCannotOverwriteFence(t *testing.T) {
|
|
89
|
+
c, _ := controlFixture(t)
|
|
90
|
+
r := Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("running")}
|
|
91
|
+
record(t, c.Client, r)
|
|
92
|
+
if err := fenceRecord(c.Client, r.Lifecycle.Epoch, "unit-stopped"); err != nil {
|
|
93
|
+
t.Fatal(err)
|
|
94
|
+
}
|
|
95
|
+
if finalizeStart(c.Client, r.Lifecycle.Epoch) == nil {
|
|
96
|
+
t.Fatal("startup overwrote fence")
|
|
97
|
+
}
|
|
98
|
+
got, _ := readRecord(c.StateDir, c.Owner)
|
|
99
|
+
if got.Lifecycle.Phase != "fenced" || !got.Residual {
|
|
100
|
+
t.Fatal(got)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
func TestLifecycleCompletionRequiresMatchingEpochAndIdentity(t *testing.T) {
|
|
104
|
+
c, f := controlFixture(t)
|
|
105
|
+
record(t, c.Client, Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("fenced"), Residual: true})
|
|
106
|
+
if completeRecord(c.Client, "wrong", f.current) == nil {
|
|
107
|
+
t.Fatal("wrong epoch completed")
|
|
108
|
+
}
|
|
109
|
+
if completeRecord(c.Client, strings.Repeat("d", 64), f.current) == nil {
|
|
110
|
+
t.Fatal("live runtime completed")
|
|
111
|
+
}
|
|
112
|
+
if err := c.teardown(); err != nil {
|
|
113
|
+
t.Fatal(err)
|
|
114
|
+
}
|
|
115
|
+
if err := completeRecord(c.Client, strings.Repeat("d", 64), f.current); err != nil {
|
|
116
|
+
t.Fatal(err)
|
|
117
|
+
}
|
|
118
|
+
r, _ := readRecord(c.StateDir, c.Owner)
|
|
119
|
+
proof, e := completionRecord(c.Client, r)
|
|
120
|
+
if e != nil {
|
|
121
|
+
t.Fatal(e)
|
|
122
|
+
}
|
|
123
|
+
if r.Residual || r.Lifecycle.Completion == "" || proof.Process != f.current {
|
|
124
|
+
t.Fatal(r)
|
|
125
|
+
}
|
|
126
|
+
if c.Status(context.Background()).State != "stopped" {
|
|
127
|
+
t.Fatal("completion not readable")
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
func TestLifecyclePolicyLockDoesNotBlockControllerStop(t *testing.T) {
|
|
132
|
+
c, _ := controlFixture(t)
|
|
133
|
+
lock, err := os.OpenFile(filepath.Join(c.StateDir, "policy.lock"), os.O_CREATE|os.O_RDWR, 0600)
|
|
134
|
+
if err != nil {
|
|
135
|
+
t.Fatal(err)
|
|
136
|
+
}
|
|
137
|
+
defer lock.Close()
|
|
138
|
+
if err := syscall.Flock(int(lock.Fd()), syscall.LOCK_EX); err != nil {
|
|
139
|
+
t.Fatal(err)
|
|
140
|
+
}
|
|
141
|
+
defer syscall.Flock(int(lock.Fd()), syscall.LOCK_UN)
|
|
142
|
+
if err := fenceRecord(c.Client, strings.Repeat("d", 64), "unit-stopped"); !errors.Is(err, errBusy) {
|
|
143
|
+
t.Fatal("fence blocked/replaced approval", err)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
func TestLifecycleMalformedSchemaAndCompletionRefuse(t *testing.T) {
|
|
147
|
+
for _, which := range []string{"schema", "epoch", "phase", "identity", "entered"} {
|
|
148
|
+
t.Run(which, func(t *testing.T) {
|
|
149
|
+
c, _ := controlFixture(t)
|
|
150
|
+
l := testLifecycle("stopped")
|
|
151
|
+
switch which {
|
|
152
|
+
case "schema":
|
|
153
|
+
l.Schema = 1
|
|
154
|
+
case "epoch":
|
|
155
|
+
l.Epoch = "old"
|
|
156
|
+
case "phase":
|
|
157
|
+
l.Phase = "ready"
|
|
158
|
+
case "entered":
|
|
159
|
+
l.Binding.Entered = 0
|
|
160
|
+
case "identity":
|
|
161
|
+
l.Completion = "wrong"
|
|
162
|
+
}
|
|
163
|
+
record(t, c.Client, Record{Inventory: c.Expected, Enabled: true, Lifecycle: l})
|
|
164
|
+
if _, err := readRecord(c.StateDir, c.Owner); err == nil {
|
|
165
|
+
t.Fatal("malformed policy accepted")
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
func TestLifecycleControllerAcceptsOnlyExactAutonomousCompletion(t *testing.T) {
|
|
172
|
+
c, f := controlFixture(t)
|
|
173
|
+
f.stopHook = func(p Process) error {
|
|
174
|
+
if err := cleanRuntime(c.Client, true); err != nil {
|
|
175
|
+
return err
|
|
176
|
+
}
|
|
177
|
+
if err := completeRecord(c.Client, strings.Repeat("d", 64), p); err != nil {
|
|
178
|
+
return err
|
|
179
|
+
}
|
|
180
|
+
return errTrust // supervisor exited before the controller's socket dial
|
|
181
|
+
}
|
|
182
|
+
if err := c.Control(context.Background(), "teardown"); err != nil {
|
|
183
|
+
t.Fatal("valid autonomous completion refused", err)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
func TestLifecyclePublicApprovalDoesNotDiscloseCompletionProcess(t *testing.T) {
|
|
188
|
+
c, f := controlFixture(t)
|
|
189
|
+
record(t, c.Client, Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("fenced"), Residual: true})
|
|
190
|
+
if err := c.teardown(); err != nil {
|
|
191
|
+
t.Fatal(err)
|
|
192
|
+
}
|
|
193
|
+
if err := completeRecord(c.Client, strings.Repeat("d", 64), f.current); err != nil {
|
|
194
|
+
t.Fatal(err)
|
|
195
|
+
}
|
|
196
|
+
b, _ := os.ReadFile(filepath.Join(c.StateDir, "approval.json"))
|
|
197
|
+
if strings.Contains(string(b), `"pid"`) || strings.Contains(string(b), `"inode"`) {
|
|
198
|
+
t.Fatal("private process identity disclosed")
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
func TestLifecycleRecoverRejectsMissingCompletionProof(t *testing.T) {
|
|
203
|
+
c, f := controlFixture(t)
|
|
204
|
+
record(t, c.Client, Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("fenced"), Residual: true})
|
|
205
|
+
if err := c.teardown(); err != nil {
|
|
206
|
+
t.Fatal(err)
|
|
207
|
+
}
|
|
208
|
+
if err := completeRecord(c.Client, strings.Repeat("d", 64), f.current); err != nil {
|
|
209
|
+
t.Fatal(err)
|
|
210
|
+
}
|
|
211
|
+
os.Remove(filepath.Join(c.StateDir, "completion-"+strings.Repeat("d", 64)+".json"))
|
|
212
|
+
if c.Control(context.Background(), "recover") == nil || f.started != 0 {
|
|
213
|
+
t.Fatal("missing completion bypassed")
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
func TestLifecycleDisableUpgradesLegacyGateAgainstReplay(t *testing.T) {
|
|
218
|
+
c, _ := controlFixture(t)
|
|
219
|
+
record(t, c.Client, Record{Inventory: c.Expected, Enabled: true})
|
|
220
|
+
if err := c.Control(context.Background(), "disable"); err != nil {
|
|
221
|
+
t.Fatal(err)
|
|
222
|
+
}
|
|
223
|
+
b, _ := os.ReadFile(filepath.Join(c.StateDir, "approval.json"))
|
|
224
|
+
var old struct {
|
|
225
|
+
Inventory Inventory `json:"inventory"`
|
|
226
|
+
Enabled bool `json:"enabled"`
|
|
227
|
+
Residual bool `json:"residual,omitempty"`
|
|
228
|
+
}
|
|
229
|
+
d := json.NewDecoder(strings.NewReader(string(b)))
|
|
230
|
+
d.DisallowUnknownFields()
|
|
231
|
+
if d.Decode(&old) == nil {
|
|
232
|
+
t.Fatal("legacy enable can replay disabled gate")
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
func TestLifecycleCrashAfterUnlinkWithoutCommitKeepsCleanupRequired(t *testing.T) {
|
|
237
|
+
c, f := controlFixture(t)
|
|
238
|
+
r := Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("fenced"), Residual: true}
|
|
239
|
+
record(t, c.Client, r)
|
|
240
|
+
if err := cleanRuntime(c.Client, true); err != nil {
|
|
241
|
+
t.Fatal(err)
|
|
242
|
+
}
|
|
243
|
+
if c.Control(context.Background(), "teardown") == nil || f.stopped != 0 {
|
|
244
|
+
t.Fatal("unlink alone certified completion")
|
|
245
|
+
}
|
|
246
|
+
got, _ := readRecord(c.StateDir, c.Owner)
|
|
247
|
+
if !got.Residual || got.Lifecycle.Phase != "fenced" {
|
|
248
|
+
t.Fatal("crash intent erased")
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
func TestLifecycleExplicitRepairAfterVerifiedNewBoot(t *testing.T) {
|
|
252
|
+
c, _ := controlFixture(t)
|
|
253
|
+
record(t, c.Client, Record{Inventory: c.Expected, Enabled: true, Lifecycle: testLifecycle("fenced"), Residual: true})
|
|
254
|
+
os.Remove(filepath.Join(c.RunDir, "process.json"))
|
|
255
|
+
c.Boot = func() (string, error) { return "verified-new-boot", nil }
|
|
256
|
+
if err := c.Control(context.Background(), "disable"); err != nil {
|
|
257
|
+
t.Fatal(err)
|
|
258
|
+
}
|
|
259
|
+
r, _ := readRecord(c.StateDir, c.Owner)
|
|
260
|
+
if r.Enabled || r.Residual {
|
|
261
|
+
t.Fatal("post-reboot disable failed")
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// The controller has read a fenced approval, but the owner finishes between
|
|
266
|
+
// that read and the process-record read. No timing sleeps or fake syscall error.
|
|
267
|
+
func TestLifecycleTeardownSnapshotAcceptsCommittedOwnerExit(t *testing.T) {
|
|
268
|
+
c, f := controlFixture(t)
|
|
269
|
+
if err := fenceRecord(c.Client, testLifecycle("running").Epoch, "admin-stop"); err != nil {
|
|
270
|
+
t.Fatal(err)
|
|
271
|
+
}
|
|
272
|
+
before, err := readRecord(c.StateDir, c.Owner)
|
|
273
|
+
if err != nil {
|
|
274
|
+
t.Fatal(err)
|
|
275
|
+
}
|
|
276
|
+
if err := cleanRuntime(c.Client, true); err != nil {
|
|
277
|
+
t.Fatal(err)
|
|
278
|
+
}
|
|
279
|
+
if err := completeRecord(c.Client, before.Lifecycle.Epoch, f.current); err != nil {
|
|
280
|
+
t.Fatal(err)
|
|
281
|
+
}
|
|
282
|
+
if err := c.teardownRecord(before, f.current); err != nil {
|
|
283
|
+
t.Fatal("exact committed completion rejected after approval snapshot", err)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
func TestLifecycleTeardownCompletionRejectsChangedWitness(t *testing.T) {
|
|
288
|
+
for _, kind := range []string{"epoch", "inventory", "binding", "lease", "pid", "start", "inode", "device", "digest", "orphan", "missing", "mode", "symlink", "runtime"} {
|
|
289
|
+
t.Run(kind, func(t *testing.T) {
|
|
290
|
+
c, f := controlFixture(t)
|
|
291
|
+
if err := fenceRecord(c.Client, testLifecycle("running").Epoch, "admin-stop"); err != nil {
|
|
292
|
+
t.Fatal(err)
|
|
293
|
+
}
|
|
294
|
+
before, err := readRecord(c.StateDir, c.Owner)
|
|
295
|
+
if err != nil {
|
|
296
|
+
t.Fatal(err)
|
|
297
|
+
}
|
|
298
|
+
if err := cleanRuntime(c.Client, true); err != nil {
|
|
299
|
+
t.Fatal(err)
|
|
300
|
+
}
|
|
301
|
+
if err := completeRecord(c.Client, before.Lifecycle.Epoch, f.current); err != nil {
|
|
302
|
+
t.Fatal(err)
|
|
303
|
+
}
|
|
304
|
+
r, err := readRecord(c.StateDir, c.Owner)
|
|
305
|
+
if err != nil {
|
|
306
|
+
t.Fatal(err)
|
|
307
|
+
}
|
|
308
|
+
proof, err := completionRecord(c.Client, r)
|
|
309
|
+
if err != nil {
|
|
310
|
+
t.Fatal(err)
|
|
311
|
+
}
|
|
312
|
+
path := filepath.Join(c.StateDir, "completion-"+r.Lifecycle.Epoch+".json")
|
|
313
|
+
switch kind {
|
|
314
|
+
case "epoch":
|
|
315
|
+
r.Lifecycle.Epoch = strings.Repeat("e", 64)
|
|
316
|
+
proof.Epoch = r.Lifecycle.Epoch
|
|
317
|
+
case "inventory":
|
|
318
|
+
r.Inventory.Version = "9.0.0-9999"
|
|
319
|
+
proof.Process.Inventory = r.Inventory
|
|
320
|
+
case "binding":
|
|
321
|
+
r.Lifecycle.Binding.Entered++
|
|
322
|
+
case "lease":
|
|
323
|
+
r.Lifecycle.Lease = &Lease{Device: 1, Inode: 999}
|
|
324
|
+
case "pid":
|
|
325
|
+
proof.Process.PID++
|
|
326
|
+
case "start":
|
|
327
|
+
proof.Process.Start = "101"
|
|
328
|
+
case "inode":
|
|
329
|
+
proof.Process.Inode++
|
|
330
|
+
case "device":
|
|
331
|
+
proof.Process.Device++
|
|
332
|
+
}
|
|
333
|
+
if err := storeCompletion(c.Client, &r, proof); err != nil {
|
|
334
|
+
t.Fatal(err)
|
|
335
|
+
}
|
|
336
|
+
switch kind {
|
|
337
|
+
case "digest":
|
|
338
|
+
r.Lifecycle.Completion = strings.Repeat("f", 64)
|
|
339
|
+
case "orphan":
|
|
340
|
+
r.Lifecycle.Phase = "fenced"
|
|
341
|
+
r.Lifecycle.Completion = ""
|
|
342
|
+
r.Residual = true
|
|
343
|
+
case "missing":
|
|
344
|
+
if err := os.Remove(path); err != nil {
|
|
345
|
+
t.Fatal(err)
|
|
346
|
+
}
|
|
347
|
+
case "mode":
|
|
348
|
+
if err := os.Chmod(path, 0644); err != nil {
|
|
349
|
+
t.Fatal(err)
|
|
350
|
+
}
|
|
351
|
+
case "symlink":
|
|
352
|
+
if err := os.Rename(path, path+".saved"); err != nil {
|
|
353
|
+
t.Fatal(err)
|
|
354
|
+
}
|
|
355
|
+
if err := os.Symlink(path+".saved", path); err != nil {
|
|
356
|
+
t.Fatal(err)
|
|
357
|
+
}
|
|
358
|
+
case "runtime":
|
|
359
|
+
if err := os.WriteFile(filepath.Join(c.RunDir, "helper.sock"), []byte("foreign"), 0600); err != nil {
|
|
360
|
+
t.Fatal(err)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
record(t, c.Client, r)
|
|
364
|
+
saved, err := os.ReadFile(filepath.Join(c.StateDir, "approval.json"))
|
|
365
|
+
if err != nil {
|
|
366
|
+
t.Fatal(err)
|
|
367
|
+
}
|
|
368
|
+
if err := c.teardownRecord(before, f.current); err == nil {
|
|
369
|
+
t.Fatal("changed/uncommitted completion accepted", kind)
|
|
370
|
+
}
|
|
371
|
+
after, err := os.ReadFile(filepath.Join(c.StateDir, "approval.json"))
|
|
372
|
+
if err != nil {
|
|
373
|
+
t.Fatal(err)
|
|
374
|
+
}
|
|
375
|
+
if string(saved) != string(after) || f.stopped != 0 || f.started != 0 {
|
|
376
|
+
t.Fatal("failed reconciliation changed evidence or touched process")
|
|
377
|
+
}
|
|
378
|
+
})
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
func TestLifecycleControlActionsAcceptExactOwnerCompletion(t *testing.T) {
|
|
383
|
+
for _, action := range []string{"teardown", "disable", "recover"} {
|
|
384
|
+
t.Run(action, func(t *testing.T) {
|
|
385
|
+
c, f := controlFixture(t)
|
|
386
|
+
f.stopHook = func(p Process) error {
|
|
387
|
+
if err := cleanRuntime(c.Client, true); err != nil {
|
|
388
|
+
return err
|
|
389
|
+
}
|
|
390
|
+
if err := completeRecord(c.Client, testLifecycle("running").Epoch, p); err != nil {
|
|
391
|
+
return err
|
|
392
|
+
}
|
|
393
|
+
return errTrust
|
|
394
|
+
}
|
|
395
|
+
if err := c.Control(context.Background(), action); err != nil {
|
|
396
|
+
t.Fatal(err)
|
|
397
|
+
}
|
|
398
|
+
r, err := readRecord(c.StateDir, c.Owner)
|
|
399
|
+
if err != nil {
|
|
400
|
+
t.Fatal(err)
|
|
401
|
+
}
|
|
402
|
+
if r.Residual || r.Enabled != (action != "disable") {
|
|
403
|
+
t.Fatal(r)
|
|
404
|
+
}
|
|
405
|
+
if action == "recover" {
|
|
406
|
+
if f.started != 1 || r.Lifecycle.Epoch == testLifecycle("running").Epoch {
|
|
407
|
+
t.Fatal("Recover did not create new epoch")
|
|
408
|
+
}
|
|
409
|
+
} else if f.started != 0 {
|
|
410
|
+
t.Fatal("Stop operation started helper")
|
|
411
|
+
}
|
|
412
|
+
})
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
func TestLifecycleTeardownRefusesUnwitnessedConcurrentCompletion(t *testing.T) {
|
|
417
|
+
c, f := controlFixture(t)
|
|
418
|
+
before, err := readRecord(c.StateDir, c.Owner)
|
|
419
|
+
if err != nil {
|
|
420
|
+
t.Fatal(err)
|
|
421
|
+
}
|
|
422
|
+
if err := fenceRecord(c.Client, before.Lifecycle.Epoch, "admin-stop"); err != nil {
|
|
423
|
+
t.Fatal(err)
|
|
424
|
+
}
|
|
425
|
+
if err := cleanRuntime(c.Client, true); err != nil {
|
|
426
|
+
t.Fatal(err)
|
|
427
|
+
}
|
|
428
|
+
if err := completeRecord(c.Client, before.Lifecycle.Epoch, f.current); err != nil {
|
|
429
|
+
t.Fatal(err)
|
|
430
|
+
}
|
|
431
|
+
if c.teardownFor(before, Process{}) == nil {
|
|
432
|
+
t.Fatal("concurrent exit accepted without saved owned identity")
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
func TestLifecycleTeardownUnlinkRaceStillRequiresCommittedProof(t *testing.T) {
|
|
437
|
+
for _, committed := range []bool{false, true} {
|
|
438
|
+
c, f := controlFixture(t)
|
|
439
|
+
f.stopHook = func(p Process) error {
|
|
440
|
+
if err := cleanRuntime(c.Client, true); err != nil {
|
|
441
|
+
return err
|
|
442
|
+
}
|
|
443
|
+
if committed {
|
|
444
|
+
return completeRecord(c.Client, testLifecycle("running").Epoch, p)
|
|
445
|
+
}
|
|
446
|
+
return nil
|
|
447
|
+
}
|
|
448
|
+
err := c.Control(context.Background(), "teardown")
|
|
449
|
+
if (err == nil) != committed {
|
|
450
|
+
t.Fatalf("commit=%v err=%v", committed, err)
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
func TestLifecycleOwnedStopCannotUseRepairCompletion(t *testing.T) {
|
|
456
|
+
c, f, _ := repairFixture(t)
|
|
457
|
+
before, err := readRecord(c.StateDir, c.Owner)
|
|
458
|
+
if err != nil {
|
|
459
|
+
t.Fatal(err)
|
|
460
|
+
}
|
|
461
|
+
if err := cleanRuntime(c.Client, true); err != nil {
|
|
462
|
+
t.Fatal(err)
|
|
463
|
+
}
|
|
464
|
+
if err := policyUpdate(c.Client, func(r *Record) error {
|
|
465
|
+
r.Lifecycle.Phase = "stopped"
|
|
466
|
+
return storeCompletion(c.Client, r, Completion{Epoch: r.Lifecycle.Epoch, Repair: &RepairCompletion{Inventory: r.Inventory, Boot: r.Lifecycle.Binding.Boot, Lease: *r.Lifecycle.Lease}})
|
|
467
|
+
}); err != nil {
|
|
468
|
+
t.Fatal(err)
|
|
469
|
+
}
|
|
470
|
+
if c.teardownRecord(before, f.current) == nil {
|
|
471
|
+
t.Fatal("repair artifact substituted for exact owned process proof")
|
|
472
|
+
}
|
|
473
|
+
}
|