pwn 0.5.795 → 0.5.796
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/bin/pwn_autoinc_version +4 -5
- data/bin/pwn_web_cache_deception +40 -29
- data/documentation/AWS.md +15 -5
- data/documentation/Diagrams.md +1 -1
- data/documentation/Home.md +2 -2
- data/documentation/How-PWN-Works.md +1 -1
- data/documentation/What-is-PWN.md +1 -1
- data/documentation/diagrams/aws-cloud-security.svg +1 -1
- data/documentation/diagrams/dot/aws-cloud-security.dot +1 -1
- data/documentation/diagrams/dot/network-infra-testing.dot +1 -1
- data/documentation/diagrams/network-infra-testing.svg +1 -1
- data/etc/default_cron/session_cleanup.rb +84 -51
- data/lib/pwn/ai/agent/assembly.rb +0 -2
- data/lib/pwn/ai/agent/btc.rb +0 -2
- data/lib/pwn/ai/agent/burp_suite.rb +0 -2
- data/lib/pwn/ai/agent/curriculum.rb +2 -2
- data/lib/pwn/ai/agent/dispatch.rb +3 -0
- data/lib/pwn/ai/agent/engagement.rb +96 -41
- data/lib/pwn/ai/agent/extrospection/osint/bridges.rb +2 -0
- data/lib/pwn/ai/agent/extrospection.rb +50 -13
- data/lib/pwn/ai/agent/gqrx.rb +0 -2
- data/lib/pwn/ai/agent/hacker_one.rb +0 -2
- data/lib/pwn/ai/agent/learning.rb +45 -13
- data/lib/pwn/ai/agent/loop.rb +12 -11
- data/lib/pwn/ai/agent/metrics.rb +1 -1
- data/lib/pwn/ai/agent/mission.rb +6 -3
- data/lib/pwn/ai/agent/policy.rb +1 -1
- data/lib/pwn/ai/agent/policy_evaluation.rb +2 -2
- data/lib/pwn/ai/agent/reflect.rb +1 -0
- data/lib/pwn/ai/agent/request_runtime.rb +1 -1
- data/lib/pwn/ai/agent/reward.rb +155 -53
- data/lib/pwn/ai/agent/sast.rb +0 -2
- data/lib/pwn/ai/agent/task_dag.rb +5 -3
- data/lib/pwn/ai/agent/task_summarizer.rb +21 -11
- data/lib/pwn/ai/agent/tool_guard.rb +19 -0
- data/lib/pwn/ai/agent/tools/ruby_eval.rb +1 -1
- data/lib/pwn/ai/agent/tools/verify.rb +7 -3
- data/lib/pwn/ai/agent/transparent_browser.rb +0 -2
- data/lib/pwn/ai/agent/turn_finalizer.rb +3 -0
- data/lib/pwn/ai/anthropic.rb +3 -3
- data/lib/pwn/ai/context.rb +2 -1
- data/lib/pwn/ai/gemini.rb +7 -5
- data/lib/pwn/ai/grok.rb +37 -18
- data/lib/pwn/ai/mcp.rb +17 -5
- data/lib/pwn/ai/ollama.rb +76 -35
- data/lib/pwn/ai/open_ai.rb +7 -19
- data/lib/pwn/ai/open_web_ui.rb +76 -40
- data/lib/pwn/aws/cloud_search_domain.rb +6 -0
- data/lib/pwn/aws/iam.rb +2 -2
- data/lib/pwn/aws/workspaces.rb +2 -2
- data/lib/pwn/aws.rb +0 -5
- data/lib/pwn/bounty/lifecycle_authz_replay.rb +1 -1
- data/lib/pwn/config.rb +17 -10
- data/lib/pwn/corpus.rb +33 -5
- data/lib/pwn/cron.rb +60 -17
- data/lib/pwn/driver.rb +2 -3
- data/lib/pwn/engagement.rb +28 -10
- data/lib/pwn/ffi/capstone.rb +3 -2
- data/lib/pwn/ffi/fftw.rb +8 -6
- data/lib/pwn/ffi/keystone.rb +3 -2
- data/lib/pwn/ffi/soapy_sdr.rb +10 -6
- data/lib/pwn/json_text.rb +25 -13
- data/lib/pwn/memory_index.rb +6 -4
- data/lib/pwn/module_skills.rb +3 -1
- data/lib/pwn/plugins/aflplusplus.rb +1 -0
- data/lib/pwn/plugins/ai_sandbox.rb +42 -10
- data/lib/pwn/plugins/android.rb +429 -466
- data/lib/pwn/plugins/artifact_registry.rb +12 -2
- data/lib/pwn/plugins/assembly.rb +9 -42
- data/lib/pwn/plugins/authentication_helper.rb +4 -3
- data/lib/pwn/plugins/baresip.rb +70 -28
- data/lib/pwn/plugins/binary_analysis.rb +14 -5
- data/lib/pwn/plugins/binary_parser.rb +42 -7
- data/lib/pwn/plugins/black_duck_binary_analysis.rb +3 -3
- data/lib/pwn/plugins/burp_suite.rb +15 -12
- data/lib/pwn/plugins/bus_pirate.rb +3 -7
- data/lib/pwn/plugins/char.rb +9 -3
- data/lib/pwn/plugins/credit_card.rb +7 -0
- data/lib/pwn/plugins/dao_ldap.rb +2 -2
- data/lib/pwn/plugins/dao_mongo.rb +1 -1
- data/lib/pwn/plugins/debugger.rb +1 -1
- data/lib/pwn/plugins/defect_dojo.rb +7 -3
- data/lib/pwn/plugins/detect_os.rb +1 -1
- data/lib/pwn/plugins/detonate.rb +9 -19
- data/lib/pwn/plugins/exploit_db.rb +1 -1
- data/lib/pwn/plugins/file_fu.rb +4 -1
- data/lib/pwn/plugins/findings.rb +76 -2
- data/lib/pwn/plugins/fuzz.rb +12 -3
- data/lib/pwn/plugins/gdb.rb +7 -2
- data/lib/pwn/plugins/gdbmi.rb +10 -6
- data/lib/pwn/plugins/git.rb +18 -13
- data/lib/pwn/plugins/github.rb +11 -6
- data/lib/pwn/plugins/google_workspace.rb +11 -3
- data/lib/pwn/plugins/hacker_one.rb +5 -1
- data/lib/pwn/plugins/httpx.rb +24 -8
- data/lib/pwn/plugins/ip_info.rb +11 -8
- data/lib/pwn/plugins/irc.rb +73 -45
- data/lib/pwn/plugins/jenkins.rb +2 -2
- data/lib/pwn/plugins/jira_data_center.rb +13 -6
- data/lib/pwn/plugins/jobs.rb +62 -4
- data/lib/pwn/plugins/log.rb +1 -1
- data/lib/pwn/plugins/monkey_patch.rb +1 -1
- data/lib/pwn/plugins/msr206.rb +157 -182
- data/lib/pwn/plugins/nessus_cloud.rb +2 -2
- data/lib/pwn/plugins/nexpose_vuln_scan.rb +44 -33
- data/lib/pwn/plugins/nuclei.rb +24 -8
- data/lib/pwn/plugins/ocr.rb +3 -1
- data/lib/pwn/plugins/open_api.rb +0 -4
- data/lib/pwn/plugins/openvas.rb +31 -43
- data/lib/pwn/plugins/packet.rb +40 -25
- data/lib/pwn/plugins/pony.rb +2 -2
- data/lib/pwn/plugins/preflight_checker.rb +1 -1
- data/lib/pwn/plugins/process_tube.rb +17 -2
- data/lib/pwn/plugins/ps.rb +6 -1
- data/lib/pwn/plugins/repl/ai.rb +1 -0
- data/lib/pwn/plugins/repl/ai_console.rb +12 -5
- data/lib/pwn/plugins/repl/mesh.rb +10 -2
- data/lib/pwn/plugins/sbom.rb +59 -27
- data/lib/pwn/plugins/scannable_codes.rb +3 -1
- data/lib/pwn/plugins/serial.rb +102 -44
- data/lib/pwn/plugins/shodan.rb +4 -10
- data/lib/pwn/plugins/sock.rb +16 -11
- data/lib/pwn/plugins/ssn.rb +3 -1
- data/lib/pwn/plugins/transparent_browser.rb +43 -3
- data/lib/pwn/plugins/vault.rb +92 -30
- data/lib/pwn/plugins/vin.rb +2 -1
- data/lib/pwn/plugins/vsphere.rb +2 -1
- data/lib/pwn/plugins/xxd.rb +3 -5
- data/lib/pwn/plugins/yubikey/security_domain/scp.rb +4 -0
- data/lib/pwn/plugins/yubikey/transport.rb +42 -11
- data/lib/pwn/plugins/yubikey.rb +21 -6
- data/lib/pwn/plugins/zaproxy.rb +3 -4
- data/lib/pwn/reports/ai_red_team.rb +4 -4
- data/lib/pwn/reports/pdf.rb +9 -5
- data/lib/pwn/reports/sast.rb +4 -4
- data/lib/pwn/sast/keystore.rb +2 -2
- data/lib/pwn/sast/logger.rb +1 -1
- data/lib/pwn/sast/php_type_juggling.rb +3 -6
- data/lib/pwn/sast/pom_version.rb +12 -6
- data/lib/pwn/sast/port.rb +1 -1
- data/lib/pwn/sast/sql.rb +3 -7
- data/lib/pwn/sast/test_case_engine.rb +62 -16
- data/lib/pwn/sast/type_script_type_juggling.rb +3 -6
- data/lib/pwn/sdr/decoder/base.rb +8 -0
- data/lib/pwn/sdr/decoder/lora.rb +1 -1
- data/lib/pwn/sdr/flipper_zero.rb +4 -7
- data/lib/pwn/sdr/gqrx.rb +35 -16
- data/lib/pwn/sdr/son_micro_rfid.rb +44 -26
- data/lib/pwn/sdr.rb +1 -1
- data/lib/pwn/session_trace.rb +7 -2
- data/lib/pwn/sessions.rb +307 -39
- data/lib/pwn/setup.rb +4 -3
- data/lib/pwn/version.rb +1 -1
- data/lib/pwn/www/app_cobalt_io.rb +14 -2
- data/lib/pwn/www/bing.rb +13 -1
- data/lib/pwn/www/bug_crowd.rb +14 -2
- data/lib/pwn/www/checkip.rb +13 -1
- data/lib/pwn/www/coinbase_pro.rb +14 -2
- data/lib/pwn/www/duckduckgo.rb +13 -1
- data/lib/pwn/www/facebook.rb +14 -2
- data/lib/pwn/www/github.rb +14 -2
- data/lib/pwn/www/google.rb +13 -1
- data/lib/pwn/www/hacker_one.rb +117 -33
- data/lib/pwn/www/linkedin.rb +14 -2
- data/lib/pwn/www/pandora.rb +14 -2
- data/lib/pwn/www/pastebin.rb +13 -1
- data/lib/pwn/www/paypal.rb +16 -4
- data/lib/pwn/www/synack.rb +14 -2
- data/lib/pwn/www/torch.rb +17 -3
- data/lib/pwn/www/trading_view.rb +14 -2
- data/lib/pwn/www/twitter.rb +14 -2
- data/lib/pwn/www/uber.rb +14 -2
- data/lib/pwn/www/upwork.rb +14 -2
- data/lib/pwn/www/wayback_machine.rb +16 -2
- data/lib/pwn/www/youtube.rb +13 -1
- data/pwn.gemspec +4 -0
- data/spec/integration/authentication_helper_oath_spec.rb +1 -1
- data/spec/integration/autoinc_lifecycle_supplement_spec.rb +47 -0
- data/spec/integration/gemspec_deleted_files_spec.rb +43 -0
- data/spec/integration/spec_curriculum_isolation_spec.rb +41 -0
- data/spec/integration/verify_acceptance_eui_regression_spec.rb +162 -0
- data/spec/integration/web_cache_lifecycle_closure_spec.rb +89 -0
- data/spec/integration/web_cache_lifecycle_supplement_spec.rb +70 -0
- data/spec/lib/pwn/ai/agent/analysis_errors_regression_spec.rb +33 -0
- data/spec/lib/pwn/ai/agent/curriculum_cooldown_regression_spec.rb +19 -0
- data/spec/lib/pwn/ai/agent/curriculum_spec.rb +2 -0
- data/spec/lib/pwn/ai/agent/engagement_boundary_regression_spec.rb +42 -0
- data/spec/lib/pwn/ai/agent/engagement_dispatch_review_spec.rb +82 -0
- data/spec/lib/pwn/ai/agent/engagement_roe_regression_spec.rb +25 -0
- data/spec/lib/pwn/ai/agent/engagement_scope_regression_spec.rb +37 -0
- data/spec/lib/pwn/ai/agent/extrospection/osint/bridges_spec.rb +4 -0
- data/spec/lib/pwn/ai/agent/extrospection_input_regression_spec.rb +31 -0
- data/spec/lib/pwn/ai/agent/extrospection_review_spec.rb +61 -0
- data/spec/lib/pwn/ai/agent/extrospection_serial_review_spec.rb +42 -0
- data/spec/lib/pwn/ai/agent/extrospection_spec.rb +9 -0
- data/spec/lib/pwn/ai/agent/extrospection_verification_regression_spec.rb +39 -0
- data/spec/lib/pwn/ai/agent/learning_last_answer_regression_spec.rb +32 -0
- data/spec/lib/pwn/ai/agent/learning_lifecycle_closure_spec.rb +84 -0
- data/spec/lib/pwn/ai/agent/learning_prune_regression_spec.rb +17 -0
- data/spec/lib/pwn/ai/agent/learning_spec.rb +2 -1
- data/spec/lib/pwn/ai/agent/loop_execution_audit_spec.rb +30 -0
- data/spec/lib/pwn/ai/agent/metrics_usage_regression_spec.rb +20 -0
- data/spec/lib/pwn/ai/agent/mission_execution_audit_spec.rb +27 -0
- data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +210 -18
- data/spec/lib/pwn/ai/agent/policy_confidence_regression_spec.rb +16 -0
- data/spec/lib/pwn/ai/agent/policy_evaluation_spec.rb +1 -1
- data/spec/lib/pwn/ai/agent/policy_evaluation_tmp_regression_spec.rb +36 -0
- data/spec/lib/pwn/ai/agent/reflect_model_regression_spec.rb +15 -0
- data/spec/lib/pwn/ai/agent/request_runtime_execution_audit_spec.rb +43 -0
- data/spec/lib/pwn/ai/agent/reward_binding_review_spec.rb +129 -0
- data/spec/lib/pwn/ai/agent/reward_dispatch_review_spec.rb +154 -0
- data/spec/lib/pwn/ai/agent/reward_envelope_regression_spec.rb +45 -0
- data/spec/lib/pwn/ai/agent/reward_turn_regression_spec.rb +40 -0
- data/spec/lib/pwn/ai/agent/swarm_spec.rb +2 -2
- data/spec/lib/pwn/ai/agent/task_dag_execution_audit_spec.rb +45 -0
- data/spec/lib/pwn/ai/agent/task_summarizer_failure_regression_spec.rb +26 -0
- data/spec/lib/pwn/ai/agent/tools/verify_execution_audit_spec.rb +33 -0
- data/spec/lib/pwn/ai/context_range_audit_spec.rb +24 -0
- data/spec/lib/pwn/ai/gemini_roundtrip_audit_spec.rb +33 -0
- data/spec/lib/pwn/ai/grok_reasoning_effort_spec.rb +43 -0
- data/spec/lib/pwn/ai/mcp_session_audit_spec.rb +36 -0
- data/spec/lib/pwn/ai/ollama_spec.rb +6 -11
- data/spec/lib/pwn/ai/open_web_ui_spec.rb +6 -11
- data/spec/lib/pwn/ai/provider_history_audit_spec.rb +44 -0
- data/spec/lib/pwn/ai/provider_operations_audit_spec.rb +53 -0
- data/spec/lib/pwn/ai/provider_review_history_stream_regression_spec.rb +143 -0
- data/spec/lib/pwn/ai/provider_review_tls_regression_spec.rb +62 -0
- data/spec/lib/pwn/ai/provider_stream_audit_spec.rb +49 -0
- data/spec/lib/pwn/aws/iam_decoding_regression_spec.rb +23 -0
- data/spec/lib/pwn/aws/services_runtime_regression_spec.rb +51 -0
- data/spec/lib/pwn/aws_spec.rb +6 -0
- data/spec/lib/pwn/banner_operational_audit_spec.rb +105 -0
- data/spec/lib/pwn/bounty/lifecycle_authz_replay_spec.rb +17 -0
- data/spec/lib/pwn/config_redaction_regression_spec.rb +24 -0
- data/spec/lib/pwn/config_skills_regression_spec.rb +38 -0
- data/spec/lib/pwn/corpus_core_review_regression_spec.rb +96 -0
- data/spec/lib/pwn/corpus_spec.rb +13 -0
- data/spec/lib/pwn/cron_core_review_regression_spec.rb +95 -0
- data/spec/lib/pwn/cron_execution_spec.rb +75 -0
- data/spec/lib/pwn/driver_core_review_regression_spec.rb +38 -0
- data/spec/lib/pwn/driver_spec.rb +13 -0
- data/spec/lib/pwn/engagement_core_review_regression_spec.rb +88 -0
- data/spec/lib/pwn/engagement_storage_regression_spec.rb +44 -0
- data/spec/lib/pwn/ffi/capstone_spec.rb +19 -0
- data/spec/lib/pwn/ffi/fftw_spec.rb +19 -0
- data/spec/lib/pwn/ffi/keystone_spec.rb +13 -0
- data/spec/lib/pwn/ffi/soapy_sdr_spec.rb +13 -0
- data/spec/lib/pwn/json_text_spec.rb +25 -0
- data/spec/lib/pwn/memory_index_spec.rb +23 -0
- data/spec/lib/pwn/module_skills_parsing_regression_spec.rb +34 -0
- data/spec/lib/pwn/plugins/ai_sandbox_boundary_review_spec.rb +57 -0
- data/spec/lib/pwn/plugins/ai_sandbox_spec.rb +10 -18
- data/spec/lib/pwn/plugins/android_review_fixes_spec.rb +121 -0
- data/spec/lib/pwn/plugins/android_transport_audit_spec.rb +64 -0
- data/spec/lib/pwn/plugins/api_import_namespace_audit_spec.rb +49 -0
- data/spec/lib/pwn/plugins/artifact_registry_namespace_audit_spec.rb +20 -0
- data/spec/lib/pwn/plugins/artifact_registry_review_fixes_spec.rb +63 -0
- data/spec/lib/pwn/plugins/assembly_namespace_audit_spec.rb +16 -0
- data/spec/lib/pwn/plugins/assembly_review_fixes_spec.rb +33 -0
- data/spec/lib/pwn/plugins/authentication_helper_spec.rb +14 -0
- data/spec/lib/pwn/plugins/baresip_review_fixes_spec.rb +127 -0
- data/spec/lib/pwn/plugins/baresip_transport_audit_spec.rb +59 -0
- data/spec/lib/pwn/plugins/binary_analysis_process_review_spec.rb +57 -0
- data/spec/lib/pwn/plugins/black_duck_namespace_audit_spec.rb +25 -0
- data/spec/lib/pwn/plugins/burp_suite_har_review_fixes_spec.rb +60 -0
- data/spec/lib/pwn/plugins/burp_suite_import_review_fixes_spec.rb +62 -0
- data/spec/lib/pwn/plugins/burp_suite_namespace_audit_spec.rb +37 -0
- data/spec/lib/pwn/plugins/bus_pirate_transport_audit_spec.rb +19 -0
- data/spec/lib/pwn/plugins/file_fu_namespace_audit_spec.rb +17 -0
- data/spec/lib/pwn/plugins/findings_structured_spec.rb +1 -1
- data/spec/lib/pwn/plugins/gdbmi_namespace_audit_spec.rb +28 -0
- data/spec/lib/pwn/plugins/gdbmi_review_fixes_spec.rb +73 -0
- data/spec/lib/pwn/plugins/github_argv_review_spec.rb +49 -0
- data/spec/lib/pwn/plugins/google_workspace_provider_review_oauth_spec.rb +80 -0
- data/spec/lib/pwn/plugins/irc_review_fixes_spec.rb +92 -0
- data/spec/lib/pwn/plugins/irc_transport_audit_spec.rb +37 -0
- data/spec/lib/pwn/plugins/jenkins_namespace_audit_spec.rb +12 -0
- data/spec/lib/pwn/plugins/jira_data_center_namespace_audit_spec.rb +44 -0
- data/spec/lib/pwn/plugins/jira_data_center_review_fixes_spec.rb +81 -0
- data/spec/lib/pwn/plugins/jsonl_elf_review_fixes_spec.rb +59 -0
- data/spec/lib/pwn/plugins/log_spec.rb +36 -20
- data/spec/lib/pwn/plugins/monkey_patch_spec.rb +16 -0
- data/spec/lib/pwn/plugins/msr206_readback_review_fixes_spec.rb +119 -0
- data/spec/lib/pwn/plugins/msr206_review_fixes_spec.rb +50 -0
- data/spec/lib/pwn/plugins/msr206_transport_audit_spec.rb +64 -0
- data/spec/lib/pwn/plugins/nessus_cloud_namespace_audit_spec.rb +14 -0
- data/spec/lib/pwn/plugins/nexpose_review_fixes_spec.rb +55 -0
- data/spec/lib/pwn/plugins/open_api_namespace_audit_spec.rb +22 -0
- data/spec/lib/pwn/plugins/packet_transport_audit_spec.rb +47 -0
- data/spec/lib/pwn/plugins/plugins_b_operational_regression_spec.rb +600 -0
- data/spec/lib/pwn/plugins/pony_namespace_audit_spec.rb +17 -0
- data/spec/lib/pwn/plugins/pony_review_fixes_spec.rb +33 -0
- data/spec/lib/pwn/plugins/process_tube_namespace_audit_spec.rb +19 -0
- data/spec/lib/pwn/plugins/ps_namespace_audit_spec.rb +12 -0
- data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +111 -0
- data/spec/lib/pwn/plugins/repl/ai_spec.rb +38 -0
- data/spec/lib/pwn/plugins/repl/mesh_spec.rb +52 -0
- data/spec/lib/pwn/plugins/sandbox_spec.rb +9 -7
- data/spec/lib/pwn/plugins/sbom_review_fixes_spec.rb +43 -0
- data/spec/lib/pwn/plugins/scannable_codes_namespace_audit_spec.rb +15 -0
- data/spec/lib/pwn/plugins/serial_review_fixes_spec.rb +76 -0
- data/spec/lib/pwn/plugins/serial_transport_audit_spec.rb +102 -0
- data/spec/lib/pwn/plugins/shodan_namespace_audit_spec.rb +10 -0
- data/spec/lib/pwn/plugins/sock_transport_audit_spec.rb +55 -0
- data/spec/lib/pwn/plugins/transparent_browser_navigation_review_spec.rb +21 -0
- data/spec/lib/pwn/plugins/vault_master_key_eui_regression_spec.rb +242 -0
- data/spec/lib/pwn/plugins/vault_spec.rb +58 -0
- data/spec/lib/pwn/plugins/vault_store_safety_spec.rb +1 -1
- data/spec/lib/pwn/plugins/xxd_namespace_audit_spec.rb +34 -0
- data/spec/lib/pwn/plugins/yubikey_hid_cleanup_review_fixes_spec.rb +52 -0
- data/spec/lib/pwn/plugins/yubikey_lifecycle_audit_spec.rb +65 -0
- data/spec/lib/pwn/plugins/yubikey_options_audit_spec.rb +30 -0
- data/spec/lib/pwn/plugins/yubikey_selector_audit_spec.rb +26 -0
- data/spec/lib/pwn/plugins/yubikey_spec.rb +1 -1
- data/spec/lib/pwn/plugins/zaproxy_namespace_audit_spec.rb +30 -0
- data/spec/lib/pwn/reports/empty_report_audit_spec.rb +18 -0
- data/spec/lib/pwn/reports/pdf_spec.rb +25 -0
- data/spec/lib/pwn/reports/provider_review_encoding_regression_spec.rb +45 -0
- data/spec/lib/pwn/sast/engine_runtime_regression_spec.rb +91 -0
- data/spec/lib/pwn/sast/filter_edge_regression_spec.rb +39 -0
- data/spec/lib/pwn/sast/formatter_review_fixes_spec.rb +178 -0
- data/spec/lib/pwn/sast/path_review_fixes_spec.rb +60 -0
- data/spec/lib/pwn/sast/pom_runtime_regression_spec.rb +37 -0
- data/spec/lib/pwn/sast/rules_runtime_regression_spec.rb +78 -0
- data/spec/lib/pwn/sast/sql_review_fixes_spec.rb +38 -0
- data/spec/lib/pwn/sdr/decoder/base_iq_spec.rb +21 -18
- data/spec/lib/pwn/sdr/decoder/base_review_fixes_spec.rb +49 -0
- data/spec/lib/pwn/sdr/decoder/base_validation_spec.rb +78 -0
- data/spec/lib/pwn/sdr/decoder/lora_spec.rb +9 -0
- data/spec/lib/pwn/sdr/flipper_zero_review_fixes_spec.rb +34 -0
- data/spec/lib/pwn/sdr/gqrx_operational_spec.rb +83 -0
- data/spec/lib/pwn/sdr/gqrx_review_fixes_spec.rb +22 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_review_fixes_spec.rb +113 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_serial_review_fixes_spec.rb +76 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_spec.rb +39 -0
- data/spec/lib/pwn/sdr_spec.rb +5 -0
- data/spec/lib/pwn/session_cleanup_default_spec.rb +1 -1
- data/spec/lib/pwn/session_cleanup_lifecycle_supplement_spec.rb +39 -0
- data/spec/lib/pwn/session_cleanup_payload_spec.rb +3 -2
- data/spec/lib/pwn/session_trace_lifecycle_supplement_spec.rb +39 -0
- data/spec/lib/pwn/sessions_archive_closure_spec.rb +126 -0
- data/spec/lib/pwn/sessions_lifecycle_closure_spec.rb +373 -0
- data/spec/lib/pwn/sessions_lifecycle_supplement_spec.rb +204 -0
- data/spec/lib/pwn/setup_operational_regression_spec.rb +36 -0
- data/spec/lib/pwn/www/browser_review_fixes_spec.rb +70 -0
- data/spec/lib/pwn/www/browser_runtime_regression_spec.rb +100 -0
- data/spec/lib/pwn/www/hacker_one_runtime_regression_spec.rb +146 -0
- data/spec/lib/pwn/www/pagination_review_fixes_spec.rb +84 -0
- data/spec/support/namespace_controller_observability_fixture.rb +141 -0
- data/spec/support/sandbox.rb +8 -5
- data/third_party/pwn_rdoc.jsonl +73 -31
- metadata +137 -18
- data/etc/default_skills/pwn/aws/elastic_transcoder/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/lambda_preview/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/ops_works/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/ops_works_cm/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/sms/SKILL.md +0 -48
- data/lib/pwn/aws/elastic_transcoder.rb +0 -95
- data/lib/pwn/aws/lambda_preview.rb +0 -95
- data/lib/pwn/aws/ops_works.rb +0 -95
- data/lib/pwn/aws/ops_works_cm.rb +0 -95
- data/lib/pwn/aws/sms.rb +0 -95
- data/spec/lib/pwn/aws/elastic_transcoder_spec.rb +0 -15
- data/spec/lib/pwn/aws/lambda_preview_spec.rb +0 -15
- data/spec/lib/pwn/aws/ops_works_cm_spec.rb +0 -15
- data/spec/lib/pwn/aws/ops_works_spec.rb +0 -15
- data/spec/lib/pwn/aws/sms_spec.rb +0 -15
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'timeout'
|
|
5
|
+
|
|
6
|
+
RSpec.describe PWN::Sessions, 'archive lifecycle closure' do
|
|
7
|
+
include_context 'pwn tmp sandbox'
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
allow(Dir).to receive(:home).and_return(@tmp)
|
|
11
|
+
@root = File.join(@tmp, '.pwn')
|
|
12
|
+
FileUtils.mkdir_p(@root)
|
|
13
|
+
stub_const('PWN::Sessions::SESSIONS_DIR', File.join(@root, 'sessions'))
|
|
14
|
+
stub_const('PWN::AI::Agent::Learning::LEARNING_FILE', File.join(@root, 'learning.jsonl'))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def cold(id)
|
|
18
|
+
session = described_class.create(id: id)
|
|
19
|
+
File.utime(Time.at(1), Time.at(1), session[:path])
|
|
20
|
+
session
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'R05 resumes owned archive publication after unlink failure and processes later candidates' do
|
|
24
|
+
first = cold('20000101_000000_00000001')
|
|
25
|
+
bytes = File.binread(first[:path])
|
|
26
|
+
allow(File).to receive(:delete).and_call_original
|
|
27
|
+
allow(File).to receive(:delete).with(first[:path]).and_raise(Errno::EACCES, 'synthetic unlink fault')
|
|
28
|
+
result = described_class.retain(days: 1)
|
|
29
|
+
expect(result[:gzipped]).to eq(0)
|
|
30
|
+
expect(result[:records]).to include(hash_including(id: first[:id], state: 'interrupted'))
|
|
31
|
+
expect(File.binread(first[:path])).to eq(bytes)
|
|
32
|
+
archive = File.binread("#{first[:path]}.gz")
|
|
33
|
+
allow(File).to receive(:delete).with(first[:path]).and_call_original
|
|
34
|
+
second = cold('20000101_000000_00000002')
|
|
35
|
+
retry_result = described_class.retain(days: 1)
|
|
36
|
+
expect(retry_result[:gzipped]).to eq(2)
|
|
37
|
+
expect(File.binread("#{first[:path]}.gz")).to eq(archive)
|
|
38
|
+
expect(File).not_to exist(first[:path])
|
|
39
|
+
expect(File).not_to exist(second[:path])
|
|
40
|
+
expect(File).to exist("#{second[:path]}.gz")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'R05 reports an unowned archive conflict without overwriting it or starving later candidates' do
|
|
44
|
+
first = cold('20000101_000000_00000001')
|
|
45
|
+
second = cold('20000101_000000_00000002')
|
|
46
|
+
File.write("#{first[:path]}.gz", 'foreign evidence')
|
|
47
|
+
result = described_class.retain(days: 1)
|
|
48
|
+
expect(result[:records]).to include(hash_including(id: first[:id], state: 'conflict'))
|
|
49
|
+
expect(result[:gzipped]).to eq(1)
|
|
50
|
+
expect(File.binread("#{first[:path]}.gz")).to eq('foreign evidence')
|
|
51
|
+
expect(File).to exist(first[:path])
|
|
52
|
+
expect(File).not_to exist(second[:path])
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'R06 keeps an unowned retention temporary when exclusive creation collides' do
|
|
56
|
+
session = cold('20000101_000000_00000001')
|
|
57
|
+
suffix = 'c' * 24
|
|
58
|
+
path = "#{session[:path]}.#{suffix}.tmp"
|
|
59
|
+
File.write(path, 'foreign temporary')
|
|
60
|
+
allow(SecureRandom).to receive(:hex).and_call_original
|
|
61
|
+
allow(SecureRandom).to receive(:hex).with(12).and_return(suffix)
|
|
62
|
+
begin
|
|
63
|
+
described_class.retain(days: 1)
|
|
64
|
+
rescue Errno::EEXIST
|
|
65
|
+
# Either a checked exception or a per-candidate conflict must preserve ownership.
|
|
66
|
+
end
|
|
67
|
+
expect(File.binread(path)).to eq('foreign temporary')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'R06 keeps an unowned compaction temporary after exclusive-create failure' do
|
|
71
|
+
session = cold('20000101_000000_00000001')
|
|
72
|
+
File.open(session[:path], 'a') { |file| file.puts(JSON.generate(role: 'tool', content: 'fixture ' * 100)) }
|
|
73
|
+
suffix = 'c' * 24
|
|
74
|
+
path = "#{session[:path]}.#{suffix}.tmp"
|
|
75
|
+
File.write(path, 'foreign temporary')
|
|
76
|
+
allow(SecureRandom).to receive(:hex).and_call_original
|
|
77
|
+
allow(SecureRandom).to receive(:hex).with(12).and_return(suffix)
|
|
78
|
+
expect { described_class.send(:compact_transcript!, path: session[:path], tool_max: 10) }.to raise_error(Errno::EEXIST)
|
|
79
|
+
expect(File.binread(path)).to eq('foreign temporary')
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'R06 leaves a replacement inode untouched after a tar failure' do
|
|
83
|
+
session = cold('20000101_000000_00000001')
|
|
84
|
+
temporary = nil
|
|
85
|
+
allow(described_class).to receive(:system) do |*_args, **options|
|
|
86
|
+
temporary = options.fetch(:out).path
|
|
87
|
+
File.unlink(temporary)
|
|
88
|
+
File.write(temporary, 'replacement owner')
|
|
89
|
+
false
|
|
90
|
+
end
|
|
91
|
+
expect { described_class.export(session_id: session[:id]) }.to raise_error(IOError, /tar failed/)
|
|
92
|
+
expect(File.binread(temporary)).to eq('replacement owner')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'R06 does not block or remove an owned temporary reacquired by another active holder' do
|
|
96
|
+
session = cold('20000101_000000_00000001')
|
|
97
|
+
held = nil
|
|
98
|
+
temporary = nil
|
|
99
|
+
allow(described_class).to receive(:system).and_return(false)
|
|
100
|
+
allow(described_class).to receive(:remove_owned_temporary).and_wrap_original do |method, options|
|
|
101
|
+
temporary = options[:path]
|
|
102
|
+
held = File.open(temporary, File::RDWR) # rubocop:disable Style/FileOpen -- independently held until example ensure
|
|
103
|
+
held.flock(File::LOCK_EX)
|
|
104
|
+
method.call(options)
|
|
105
|
+
end
|
|
106
|
+
expect { Timeout.timeout(3) { described_class.export(session_id: session[:id]) } }.to raise_error(IOError, /tar failed/)
|
|
107
|
+
expect(File).to exist(temporary)
|
|
108
|
+
ensure
|
|
109
|
+
held&.close
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'R06 reserves the export temporary before invoking tar and preserves a collision' do
|
|
113
|
+
session = cold('20000101_000000_00000001')
|
|
114
|
+
directory = File.join(@root, 'exports')
|
|
115
|
+
FileUtils.mkdir_p(directory)
|
|
116
|
+
suffix = 'c' * 24
|
|
117
|
+
path = File.join(directory, ".#{session[:id]}.#{suffix}.tmp")
|
|
118
|
+
File.write(path, 'foreign temporary')
|
|
119
|
+
allow(SecureRandom).to receive(:hex).and_call_original
|
|
120
|
+
allow(SecureRandom).to receive(:hex).with(12).and_return(suffix)
|
|
121
|
+
allow(described_class).to receive(:system).and_return(false)
|
|
122
|
+
expect { described_class.export(session_id: session[:id]) }.to raise_error(Errno::EEXIST)
|
|
123
|
+
expect(described_class).not_to have_received(:system)
|
|
124
|
+
expect(File.binread(path)).to eq('foreign temporary')
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'timeout'
|
|
5
|
+
require File.expand_path('../../../etc/default_cron/session_cleanup', __dir__)
|
|
6
|
+
|
|
7
|
+
RSpec.shared_context 'lifecycle closure fixtures' do
|
|
8
|
+
include_context 'pwn tmp sandbox'
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
allow(Dir).to receive(:home).and_return(@tmp)
|
|
12
|
+
@root = File.join(@tmp, '.pwn')
|
|
13
|
+
FileUtils.mkdir_p(@root, mode: 0o700)
|
|
14
|
+
{
|
|
15
|
+
'PWN::Sessions::SESSIONS_DIR' => 'sessions',
|
|
16
|
+
'PWN::AI::Agent::Learning::LEARNING_FILE' => 'learning.jsonl',
|
|
17
|
+
'PWN::AI::Agent::Learning::DISPUTED_FILE' => 'learning/disputed.jsonl',
|
|
18
|
+
'PWN::AI::Agent::Learning::LESSONS_FILE' => 'lessons.json',
|
|
19
|
+
'PWN::Memory::MEMORY_FILE' => 'memory.json',
|
|
20
|
+
'PWN::AI::Agent::Mistakes::MISTAKES_FILE' => 'mistakes.json',
|
|
21
|
+
'PWN::Plugins::Findings::FILE' => 'findings.jsonl',
|
|
22
|
+
'PWN::Migrate::PWN_ROOT' => '.',
|
|
23
|
+
'PWN::Migrate::SCHEMA_FILE' => '.schema',
|
|
24
|
+
'PWN::Migrate::BACKUP_ROOT' => 'backup',
|
|
25
|
+
'PWN::Migrate::QUARANTINE_DIR' => 'quarantine'
|
|
26
|
+
}.each { |name, path| stub_const(name, File.join(@root, path)) }
|
|
27
|
+
@proc = File.join(@tmp, 'fixture-proc')
|
|
28
|
+
Dir.mkdir(@proc)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def cold(id = nil, tool: false)
|
|
32
|
+
session = PWN::Sessions.create(id: id)
|
|
33
|
+
File.open(session[:path], 'a') { |file| file.puts(JSON.generate(role: 'tool', content: 'synthetic observation ' * 8000)) } if tool
|
|
34
|
+
File.utime(Time.at(1), Time.at(1), session[:path])
|
|
35
|
+
session
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def inventory
|
|
39
|
+
Dir.glob(File.join(@root, '**', '*'), File::FNM_DOTMATCH).sort.to_h do |path|
|
|
40
|
+
stat = File.lstat(path)
|
|
41
|
+
[path, [stat.ino, stat.mode, stat.size, stat.mtime, stat.ctime, File.file?(path) ? Digest::SHA256.file(path).hexdigest : nil]]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def mutate(operation, session)
|
|
46
|
+
case operation
|
|
47
|
+
when :delete then PWN::Sessions.delete(session_id: session[:id], hot_days: 0)
|
|
48
|
+
when :retain then PWN::Sessions.retain(days: 1)
|
|
49
|
+
else PWN::Sessions.lean!(hot_days: 0, retain_days: 100_000, tool_content_max: 10)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
RSpec.describe 'session lifecycle closure' do
|
|
55
|
+
include_context 'lifecycle closure fixtures'
|
|
56
|
+
|
|
57
|
+
%i[delete retain compact].each do |operation|
|
|
58
|
+
it "R01 #{operation} fences a real Learning publisher after the final pin scan" do
|
|
59
|
+
session = cold(nil, tool: true)
|
|
60
|
+
reached = Queue.new
|
|
61
|
+
publisher = nil
|
|
62
|
+
allow(PWN::AI::Agent::Learning).to receive(:learning_lock).and_wrap_original do |method, *args|
|
|
63
|
+
reached << true if Thread.current == publisher
|
|
64
|
+
method.call(*args)
|
|
65
|
+
end
|
|
66
|
+
allow(PWN::Sessions).to receive(:protected_session_ids).and_wrap_original do |method, options|
|
|
67
|
+
pins = method.call(options)
|
|
68
|
+
if options[:include_activity] == false && publisher.nil?
|
|
69
|
+
go = Queue.new
|
|
70
|
+
publisher = Thread.new do
|
|
71
|
+
go.pop
|
|
72
|
+
PWN::AI::Agent::Learning.note_outcome(task: 'synthetic evidence', success: false, session_id: session[:id])
|
|
73
|
+
rescue IOError => e
|
|
74
|
+
e
|
|
75
|
+
end
|
|
76
|
+
go << true
|
|
77
|
+
Timeout.timeout(3) { reached.pop }
|
|
78
|
+
end
|
|
79
|
+
pins
|
|
80
|
+
end
|
|
81
|
+
mutate(operation, session)
|
|
82
|
+
expect(publisher).not_to be_nil
|
|
83
|
+
published = Timeout.timeout(3) { publisher.value }
|
|
84
|
+
if operation == :compact
|
|
85
|
+
expect(published).to be_a(Hash)
|
|
86
|
+
expect(PWN::Sessions.load(session_id: session[:id])).not_to be_empty
|
|
87
|
+
expect(PWN::Sessions.dependency_index[:dependencies][session[:id]]).to include(PWN::AI::Agent::Learning::LEARNING_FILE)
|
|
88
|
+
else
|
|
89
|
+
expect(published).to be_a(IOError)
|
|
90
|
+
expect(PWN::AI::Agent::Learning.outcomes).to eq([])
|
|
91
|
+
end
|
|
92
|
+
ensure
|
|
93
|
+
publisher&.kill if publisher&.alive?
|
|
94
|
+
publisher&.join
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "R01 #{operation} preserves source while the actual Learning publisher owns its lifetime" do
|
|
98
|
+
session = cold(nil, tool: true)
|
|
99
|
+
original = File.binread(session[:path])
|
|
100
|
+
ready = Queue.new
|
|
101
|
+
release = Queue.new
|
|
102
|
+
publisher = nil
|
|
103
|
+
allow(File).to receive(:open).and_wrap_original do |method, *args, &block|
|
|
104
|
+
if Thread.current == publisher && args.first == PWN::AI::Agent::Learning::LEARNING_FILE && args[1] == 'a'
|
|
105
|
+
ready << true
|
|
106
|
+
release.pop
|
|
107
|
+
end
|
|
108
|
+
method.call(*args, &block)
|
|
109
|
+
end
|
|
110
|
+
publisher = Thread.new do
|
|
111
|
+
PWN::AI::Agent::Learning.note_outcome(task: 'synthetic evidence', success: false, session_id: session[:id])
|
|
112
|
+
end
|
|
113
|
+
Timeout.timeout(3) { ready.pop }
|
|
114
|
+
begin
|
|
115
|
+
Timeout.timeout(3) { mutate(operation, session) }
|
|
116
|
+
rescue IOError
|
|
117
|
+
# Nonblocking contention is an explicit refusal, not permission to mutate.
|
|
118
|
+
end
|
|
119
|
+
expect(File.binread(session[:path])).to eq(original)
|
|
120
|
+
release << true
|
|
121
|
+
Timeout.timeout(3) { publisher.value }
|
|
122
|
+
expect(PWN::Sessions.dependency_index[:dependencies][session[:id]]).to include(PWN::AI::Agent::Learning::LEARNING_FILE)
|
|
123
|
+
expect(PWN::Sessions.load(session_id: session[:id])).not_to be_empty
|
|
124
|
+
ensure
|
|
125
|
+
release << true if release
|
|
126
|
+
publisher&.kill if publisher&.alive?
|
|
127
|
+
publisher&.join
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def publish_finding(session)
|
|
132
|
+
PWN::Plugins::Findings.record(title: 'Synthetic evidence', session_id: session[:id], engagement_id: 'fixture',
|
|
133
|
+
evidence: 'synthetic fixture evidence long enough to cite its source file', poc_artifacts: [session[:path]])
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'R02 scheduled sweep fences an actual Findings publisher after its final check' do
|
|
137
|
+
session = cold
|
|
138
|
+
entered = Queue.new
|
|
139
|
+
publisher = nil
|
|
140
|
+
allow(PWN::Plugins::Findings).to receive(:record).and_wrap_original do |method, options|
|
|
141
|
+
entered << true
|
|
142
|
+
method.call(options)
|
|
143
|
+
end
|
|
144
|
+
allow(PWN::Sessions).to receive(:delete).and_wrap_original do |method, options|
|
|
145
|
+
publisher = Thread.new do
|
|
146
|
+
publish_finding(session)
|
|
147
|
+
rescue IOError => e
|
|
148
|
+
e
|
|
149
|
+
end
|
|
150
|
+
Timeout.timeout(3) { entered.pop }
|
|
151
|
+
method.call(options)
|
|
152
|
+
end
|
|
153
|
+
result = PWN::SessionCleanup.sweep(dry_run: false, proc_root: @proc)
|
|
154
|
+
expect(result[:deleted_ids]).to include(session[:id])
|
|
155
|
+
expect(Timeout.timeout(3) { publisher.value }).to be_a(IOError)
|
|
156
|
+
expect(PWN::Plugins::Findings.report).to eq([])
|
|
157
|
+
expect(PWN::Plugins::Findings.evidence_verify(engagement_id: 'fixture')).to include(ok: true, rows: 0)
|
|
158
|
+
ensure
|
|
159
|
+
publisher&.kill if publisher&.alive?
|
|
160
|
+
publisher&.join
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'R02 coordinator retains the literal source while the actual Findings publisher owns it' do
|
|
164
|
+
session = cold
|
|
165
|
+
original = File.binread(session[:path])
|
|
166
|
+
ready = Queue.new
|
|
167
|
+
release = Queue.new
|
|
168
|
+
allow(PWN::Plugins::Findings).to receive(:evidence_anchor).and_wrap_original do |method, options|
|
|
169
|
+
ready << true
|
|
170
|
+
release.pop
|
|
171
|
+
method.call(options)
|
|
172
|
+
end
|
|
173
|
+
publisher = Thread.new { publish_finding(session) }
|
|
174
|
+
Timeout.timeout(3) { ready.pop }
|
|
175
|
+
begin
|
|
176
|
+
result = Timeout.timeout(3) { PWN::SessionCleanup.coordinate(dry_run: false, proc_root: @proc) }
|
|
177
|
+
expect(result[:phases][:maintenance][:deleted_ids]).to eq([])
|
|
178
|
+
rescue IOError => e
|
|
179
|
+
expect(e.message).to include('Dependency writer active')
|
|
180
|
+
ledger = Dir[File.join(@root, 'maintenance', 'runs', 'coordinator-*.json')].fetch(0)
|
|
181
|
+
expect(JSON.parse(File.read(ledger))['state']).to eq('interrupted')
|
|
182
|
+
end
|
|
183
|
+
expect(File.binread(session[:path])).to eq(original)
|
|
184
|
+
release << true
|
|
185
|
+
Timeout.timeout(3) { publisher.value }
|
|
186
|
+
expect(PWN::Plugins::Findings.evidence_verify(engagement_id: 'fixture')).to include(ok: true, rows: 1)
|
|
187
|
+
expect(PWN::Sessions.dependency_index[:dependencies][session[:id]]).to include(PWN::Plugins::Findings::FILE)
|
|
188
|
+
ensure
|
|
189
|
+
release << true if release
|
|
190
|
+
publisher&.kill if publisher&.alive?
|
|
191
|
+
publisher&.join
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
%i[learning findings].each do |producer|
|
|
195
|
+
it "R01/R02 excludes mutation while an actual #{producer} process publishes its first store row" do
|
|
196
|
+
session = cold
|
|
197
|
+
bytes = File.binread(session[:path])
|
|
198
|
+
store = producer == :learning ? PWN::AI::Agent::Learning::LEARNING_FILE : PWN::Plugins::Findings::FILE
|
|
199
|
+
ready_read, ready_write = IO.pipe
|
|
200
|
+
release_read, release_write = IO.pipe
|
|
201
|
+
parent = Process.pid
|
|
202
|
+
allow(File).to receive(:open).and_wrap_original do |method, *args, &block|
|
|
203
|
+
if Process.pid != parent && args.first == store && args[1] == 'a'
|
|
204
|
+
ready_write.write('r')
|
|
205
|
+
release_read.read(1)
|
|
206
|
+
end
|
|
207
|
+
method.call(*args, &block)
|
|
208
|
+
end
|
|
209
|
+
pid = fork do
|
|
210
|
+
ready_read.close
|
|
211
|
+
release_write.close
|
|
212
|
+
if producer == :learning
|
|
213
|
+
PWN::AI::Agent::Learning.note_outcome(task: 'process fixture', success: false, session_id: session[:id])
|
|
214
|
+
else
|
|
215
|
+
publish_finding(session)
|
|
216
|
+
end
|
|
217
|
+
exit! 0
|
|
218
|
+
rescue StandardError
|
|
219
|
+
exit! 1
|
|
220
|
+
end
|
|
221
|
+
ready_write.close
|
|
222
|
+
release_read.close
|
|
223
|
+
Timeout.timeout(3) { expect(ready_read.read(1)).to eq('r') }
|
|
224
|
+
expect(File).not_to exist(store)
|
|
225
|
+
expect { Timeout.timeout(3) { PWN::Sessions.delete(session_id: session[:id], force: true) } }.to raise_error(IOError)
|
|
226
|
+
expect(File.binread(session[:path])).to eq(bytes)
|
|
227
|
+
release_write.write('g')
|
|
228
|
+
status = Timeout.timeout(3) { Process.wait2(pid).last }
|
|
229
|
+
pid = nil
|
|
230
|
+
expect(status.success?).to be(true)
|
|
231
|
+
expect(PWN::Sessions.dependency_index[:dependencies][session[:id]]).to include(store)
|
|
232
|
+
expect(PWN::Sessions.load(session_id: session[:id])).not_to be_empty
|
|
233
|
+
expect(PWN::Plugins::Findings.evidence_verify(engagement_id: 'fixture')[:ok]).to be(true) if producer == :findings
|
|
234
|
+
ensure
|
|
235
|
+
if pid
|
|
236
|
+
Process.kill('KILL', pid)
|
|
237
|
+
Process.wait(pid)
|
|
238
|
+
end
|
|
239
|
+
[ready_read, ready_write, release_read, release_write].compact.each { |io| io.close unless io.closed? }
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it 'R04 lean reports recoverable partial deletion and counts the physically removed transcript' do
|
|
244
|
+
session = cold
|
|
245
|
+
bytes = File.binread(session[:path])
|
|
246
|
+
meta = PWN::Sessions.support_path(kind: :metadata, session_id: session[:id])
|
|
247
|
+
allow(File).to receive(:unlink).and_call_original
|
|
248
|
+
allow(File).to receive(:unlink).with(meta).and_raise(Errno::EACCES, 'synthetic metadata fault')
|
|
249
|
+
result = PWN::Sessions.lean!(hot_days: 0, retain_days: 1)
|
|
250
|
+
expect(result).to include(state: 'interrupted', deleted: 1, remaining: 0)
|
|
251
|
+
partial = result.fetch(:partial_deletions).fetch(0)
|
|
252
|
+
ledger = JSON.parse(File.read(partial.fetch(:ledger)))
|
|
253
|
+
expect(ledger['state']).to eq('interrupted')
|
|
254
|
+
expect(ledger['records'].first['deletion']['deleted_paths']).to include(session[:path])
|
|
255
|
+
expect(File.binread(File.join(File.dirname(partial[:ledger]), File.basename(session[:path])))).to eq(bytes)
|
|
256
|
+
allow(File).to receive(:unlink).with(meta).and_call_original
|
|
257
|
+
PWN::SessionCleanup.recover(ledger: partial[:ledger], dry_run: false)
|
|
258
|
+
expect(File.binread(session[:path])).to eq(bytes)
|
|
259
|
+
ensure
|
|
260
|
+
allow(File).to receive(:unlink).with(meta).and_call_original if meta
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it 'R04 coordinator interrupts after partial deletion and persists the exact outcome' do
|
|
264
|
+
session = cold
|
|
265
|
+
bytes = File.binread(session[:path])
|
|
266
|
+
meta = PWN::Sessions.support_path(kind: :metadata, session_id: session[:id])
|
|
267
|
+
allow(File).to receive(:unlink).and_call_original
|
|
268
|
+
allow(File).to receive(:unlink).with(meta).and_raise(Errno::EACCES, 'synthetic metadata fault')
|
|
269
|
+
expect(PWN::AI::Agent::Learning).not_to receive(:consolidate)
|
|
270
|
+
result = PWN::SessionCleanup.coordinate(dry_run: false, proc_root: @proc)
|
|
271
|
+
expect(result[:state]).to eq('interrupted')
|
|
272
|
+
maintenance = result[:phases][:maintenance]
|
|
273
|
+
expect(maintenance[:state]).to eq('interrupted')
|
|
274
|
+
expect(maintenance[:deleted_ids]).to include(session[:id])
|
|
275
|
+
expect(maintenance[:records].first[:deletion]).to include(state: 'interrupted', deleted_paths: [session[:path]], remaining_paths: [meta])
|
|
276
|
+
expect(JSON.parse(File.read(result[:transaction_ledger]))['state']).to eq('interrupted')
|
|
277
|
+
expect(JSON.parse(File.read(maintenance[:transaction_ledger]))['state']).to eq('interrupted')
|
|
278
|
+
ledger = File.join(maintenance[:archive_dir], 'ledger.json')
|
|
279
|
+
expect(JSON.parse(File.read(ledger))['records'].first['deletion']['state']).to eq('interrupted')
|
|
280
|
+
expect(File.binread(File.join(maintenance[:archive_dir], File.basename(session[:path])))).to eq(bytes)
|
|
281
|
+
allow(File).to receive(:unlink).with(meta).and_call_original
|
|
282
|
+
PWN::SessionCleanup.recover(ledger: ledger, dry_run: false)
|
|
283
|
+
expect(File.binread(session[:path])).to eq(bytes)
|
|
284
|
+
ensure
|
|
285
|
+
allow(File).to receive(:unlink).with(meta).and_call_original if meta
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
it 'R04 records interruption after transcript unlink before propagating cancellation to both parents' do
|
|
289
|
+
session = cold
|
|
290
|
+
bytes = File.binread(session[:path])
|
|
291
|
+
meta = PWN::Sessions.support_path(kind: :metadata, session_id: session[:id])
|
|
292
|
+
allow(File).to receive(:unlink).and_call_original
|
|
293
|
+
allow(File).to receive(:unlink).with(meta).and_raise(Interrupt, 'synthetic cancellation')
|
|
294
|
+
expect(PWN::AI::Agent::Learning).not_to receive(:consolidate)
|
|
295
|
+
expect { PWN::SessionCleanup.coordinate(dry_run: false, proc_root: @proc) }.to raise_error(Interrupt)
|
|
296
|
+
parents = Dir[File.join(@root, 'maintenance', 'runs', '*.json')].map { |path| JSON.parse(File.read(path)) }
|
|
297
|
+
expect(parents.length).to eq(2)
|
|
298
|
+
expect(parents.map { |row| row['state'] }).to eq(%w[interrupted interrupted])
|
|
299
|
+
ledger = Dir[File.join(@root, 'backup', '**', 'ledger.json')].find { |path| JSON.parse(File.read(path))['records']&.any? { |row| row['deletion'] } }
|
|
300
|
+
child = JSON.parse(File.read(ledger))['records'].find { |row| row['id'] == session[:id] }
|
|
301
|
+
expect(child['deletion']).to include('state' => 'interrupted', 'deleted_paths' => [session[:path]], 'remaining_paths' => [meta])
|
|
302
|
+
expect(File.binread(File.join(File.dirname(ledger), File.basename(session[:path])))).to eq(bytes)
|
|
303
|
+
ensure
|
|
304
|
+
allow(File).to receive(:unlink).with(meta).and_call_original if meta
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
it 'R10 commits ordinary coordinator work without confusing status inventory with admitted children' do
|
|
308
|
+
result = PWN::SessionCleanup.coordinate(dry_run: false, proc_root: @proc)
|
|
309
|
+
expect(result[:state]).to eq('committed')
|
|
310
|
+
expect(result[:phases].keys).to eq(%i[maintenance memory_consolidation learning_retention mistakes_retention policy_retention])
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
it 'R10 propagates the actual prepared backup-compaction failure through both parent ledgers' do
|
|
314
|
+
id = '20000101_000000_aabbccdd'
|
|
315
|
+
payload = "#{JSON.generate(role: 'system', content: 'Session started: synthetic')}\n"
|
|
316
|
+
digest = Digest::SHA256.hexdigest(payload)
|
|
317
|
+
%w[first second].each do |name|
|
|
318
|
+
dir = File.join(@root, 'session_cleanup_archive', name)
|
|
319
|
+
FileUtils.mkdir_p(dir)
|
|
320
|
+
File.write(File.join(dir, "#{id}.jsonl"), payload)
|
|
321
|
+
ledger = File.join(dir, 'ledger.json')
|
|
322
|
+
File.write(ledger, JSON.generate(dry_run: false, deleted_ids: [id], records: [{ id: id, deleted: true, files: { "#{id}.jsonl" => { sha256: digest } } }]))
|
|
323
|
+
File.utime(Time.at(1), Time.at(1), ledger)
|
|
324
|
+
end
|
|
325
|
+
allow(File).to receive(:link).and_wrap_original do |method, source, dest|
|
|
326
|
+
raise Errno::EACCES, 'synthetic compaction failure' if dest.include?('.compact-')
|
|
327
|
+
|
|
328
|
+
method.call(source, dest)
|
|
329
|
+
end
|
|
330
|
+
expect(PWN::AI::Agent::Learning).not_to receive(:consolidate)
|
|
331
|
+
result = PWN::SessionCleanup.coordinate(dry_run: false, proc_root: @proc)
|
|
332
|
+
expect(result[:state]).to eq('interrupted')
|
|
333
|
+
maintenance = result[:phases][:maintenance]
|
|
334
|
+
child = maintenance[:legacy_backups]
|
|
335
|
+
expect(child[:state]).to eq('interrupted')
|
|
336
|
+
expect(JSON.parse(File.read(child[:ledger]))['records']).to include(hash_including('state' => 'prepared'))
|
|
337
|
+
expect(JSON.parse(File.read(maintenance[:transaction_ledger]))['state']).to eq('interrupted')
|
|
338
|
+
expect(JSON.parse(File.read(result[:transaction_ledger]))['state']).to eq('interrupted')
|
|
339
|
+
expect(result[:phases]).not_to have_key(:learning_retention)
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
it 'R03 recovery preview resolves absent destinations without creating session or metadata directories' do
|
|
343
|
+
id = '20000101_000000_aabbccdd'
|
|
344
|
+
directory = File.join(@root, 'session_cleanup_archive', 'fixture')
|
|
345
|
+
FileUtils.mkdir_p(directory)
|
|
346
|
+
files = { "#{id}.jsonl" => "#{JSON.generate(role: 'system', content: 'Session started: fixture')}\n", "#{id}.meta.json" => JSON.generate(id: id, title: 'fixture') }
|
|
347
|
+
files.each { |name, bytes| File.write(File.join(directory, name), bytes) }
|
|
348
|
+
ledger = File.join(directory, 'ledger.json')
|
|
349
|
+
File.write(ledger, JSON.generate(dry_run: false, deleted_ids: [id], records: [{ id: id, files: files.transform_values { |bytes| { sha256: Digest::SHA256.hexdigest(bytes) } } }]))
|
|
350
|
+
before = inventory
|
|
351
|
+
PWN::SessionCleanup.recover(ledger: ledger, dry_run: true)
|
|
352
|
+
expect(inventory).to eq(before)
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
%i[lean! sweep maintain run coordinate reorganize].each do |operation|
|
|
356
|
+
[false, true].each do |compact|
|
|
357
|
+
it "R03 #{operation} dry-run is noncreating with #{compact ? 'incomplete compact layout' : 'absent store'}" do
|
|
358
|
+
if compact
|
|
359
|
+
root = PWN::Sessions.sessions_dir
|
|
360
|
+
File.write(File.join(root, '20000101_000000_aabbccdd.jsonl'), "#{JSON.generate(role: 'system', content: 'Session started: fixture')}\n")
|
|
361
|
+
File.write(File.join(root, '.layout-v2'), 'fixture')
|
|
362
|
+
end
|
|
363
|
+
before = inventory
|
|
364
|
+
if operation == :lean!
|
|
365
|
+
PWN::Sessions.lean!(dry_run: true)
|
|
366
|
+
else
|
|
367
|
+
PWN::SessionCleanup.public_send(operation, dry_run: true, proc_root: @proc)
|
|
368
|
+
end
|
|
369
|
+
expect(inventory).to eq(before)
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
end
|