From 60cd4516cd1ad54d778b33b22df289dfe86ee0d8 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 13:42:21 -0500 Subject: [PATCH] Inventory workspace Git state without hidden gaps or filter execution Actual authors OpenAI Codex Kepler and parent. Complete observations are not a clean-state or mathematical certificate.15 normal/optimized tests, baseline11 plus four source mutants, runner refusal controls and privacy-safe recovery summary. --- .../EVIDENCE.json | 65 +++ .../cbz-workspace-hygiene-20261029/README.md | 36 ++ .../SOURCE.json | 29 + .../collector-normal.log | 16 + .../collector-optimized.log | 16 + .../final15-normal.log | 20 + .../final15-optimized.log | 20 + .../mutation-baseline.log | 16 + .../mutation-disable-redaction.log | 15 + .../mutation-exclude-node-modules.log | 15 + .../mutation-execute-clean-filter.log | 15 + .../mutation-false-complete.log | 15 + .../mutations.json | 133 +++++ .../runner-controls.json | 14 + .../runner-normal-initial.log | 9 + .../runner-optimized-initial.log | 9 + tests/test_workspace_git_inventory.py | 153 ++++++ .../test_workspace_git_inventory_mutations.py | 107 ++++ tools/workspace_git_inventory.py | 496 ++++++++++++++++++ tools/workspace_git_inventory_mutations.py | 156 ++++++ 20 files changed, 1355 insertions(+) create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/EVIDENCE.json create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/README.md create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/SOURCE.json create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/collector-normal.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/collector-optimized.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/final15-normal.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/final15-optimized.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/mutation-baseline.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/mutation-disable-redaction.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/mutation-exclude-node-modules.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/mutation-execute-clean-filter.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/mutation-false-complete.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/mutations.json create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/runner-controls.json create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/runner-normal-initial.log create mode 100644 docs/reports/cbz-workspace-hygiene-20261029/runner-optimized-initial.log create mode 100644 tests/test_workspace_git_inventory.py create mode 100644 tests/test_workspace_git_inventory_mutations.py create mode 100644 tools/workspace_git_inventory.py create mode 100644 tools/workspace_git_inventory_mutations.py diff --git a/docs/reports/cbz-workspace-hygiene-20261029/EVIDENCE.json b/docs/reports/cbz-workspace-hygiene-20261029/EVIDENCE.json new file mode 100644 index 000000000..06c7d961e --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/EVIDENCE.json @@ -0,0 +1,65 @@ +{ + "scope": "Public synthetic self-test/source evidence only; raw private inventory and recovery archive locators withheld", + "files": { + "README.md": { + "bytes": 6208, + "sha256": "280e9f4192acebc9c722c1ba633f2b8a9b4d51e44edc45b3f167748c79715379" + }, + "SOURCE.json": { + "bytes": 1007, + "sha256": "90714405faf67ef7985ddf74a2c96e66ac896c2a04952a98229474061448a5db" + }, + "collector-normal.log": { + "bytes": 1856, + "sha256": "c8d55853c5082525da552587a83a2fa613038e13fd919d0f13d8b8e397296a8d" + }, + "collector-optimized.log": { + "bytes": 1856, + "sha256": "279c793570bf5e751a18833d74e47989d06b570ee283dae9d4beb6dcbc5e9d59" + }, + "final15-normal.log": { + "bytes": 2590, + "sha256": "557a06a0ccc8aa86b5c7d35e74232e623668328c506f5c0ac34ba58cc8accfef" + }, + "final15-optimized.log": { + "bytes": 2590, + "sha256": "d48e77490ff4e8e44477d19be4e99d47824112678575e9358ce12f1f20d1b843" + }, + "mutation-baseline.log": { + "bytes": 1680, + "sha256": "0f967c385208a3b391994b748ef2db56f5d34e8e05e6fac25d8e3758484e2f4b" + }, + "mutation-disable-redaction.log": { + "bytes": 8020, + "sha256": "51cfc84a530574fcd6d0e5e2968f9202002d937f9a6a7a9a88f3315e24db937c" + }, + "mutation-exclude-node-modules.log": { + "bytes": 3205, + "sha256": "87012cb90d2e361378a8b1fe20b72821b611bab83e2d03ef2d7dd76b09312886" + }, + "mutation-execute-clean-filter.log": { + "bytes": 967, + "sha256": "af01905297a9abcb151c556f7c44e2334344dadca186c874914d2d867e6339a9" + }, + "mutation-false-complete.log": { + "bytes": 970, + "sha256": "baa10781039acb92e64b3127fd38c739a8f6ee367733cb911b687bac53b3fc13" + }, + "mutations.json": { + "bytes": 4667, + "sha256": "e3d0afc776ab553c6a06a62cc77b293f64bfef5adc6697fd4be40e54a5ed5676" + }, + "runner-controls.json": { + "bytes": 219, + "sha256": "288366545e640d29f82dd9a5a6c39a95429f2db024756ac88323875ab3fcedd0" + }, + "runner-normal-initial.log": { + "bytes": 766, + "sha256": "66b0c8ad4babb0463f431bf761b4d7e289e2cc14b9e845e97fee665d9ad76d2d" + }, + "runner-optimized-initial.log": { + "bytes": 766, + "sha256": "f9a2e4e802dcb12fde08564b1a9993a168aaa7d7d13dd68ccbf853d8cb5fcdcc" + } + } +} diff --git a/docs/reports/cbz-workspace-hygiene-20261029/README.md b/docs/reports/cbz-workspace-hygiene-20261029/README.md new file mode 100644 index 000000000..041b468f8 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/README.md @@ -0,0 +1,36 @@ +# Read-only workspace Git inventory + +The federation census initially missed nested execution fixtures and an empty package-cache `.git` marker. This stdlib tool records every physical Git candidate, linked worktree, common store, ref/tag/stash, configured redacted remote and submodule. It preserves unusual path bytes and fails closed on uncovered paths, malformed markers, Git errors, deadlines or output limits. An exit0 means **complete observations, not clean Git or CBZ-0**. + +This is a disjoint contribution to [the canonical consolidation](https://github.com/d6g8k5htny-coder/main/issues/684). It does not certify mathematical claims or replace G0–G4, remote repository inventory, regression, pin or status-truth gates. No dependency, mathematical source, scientific disposition or existing test is changed. + +## Reproduce and register + +Use Python3.11+ and Git on a POSIX host; actual parent verification used Python3.12.14 and Git2.52.0. No third-party imports or network access are needed. Output parents must already exist; output files/directories must be new. + +```sh +python3 -S -B tools/workspace_git_inventory.py --root /workspace --output /private/existing-parent/new-inventory.json --command-timeout 10 --total-timeout 900 +python3 -S -B -m unittest tests.test_workspace_git_inventory tests.test_workspace_git_inventory_mutations -v +python3 -S -B -O -m unittest tests.test_workspace_git_inventory tests.test_workspace_git_inventory_mutations -v +python3 -S -B tools/workspace_git_inventory_mutations.py --output /private/existing-parent/new-mutation-directory +``` + +Collector output is exclusive-create0600. The companion creates an exclusive0700 directory and0600 logs/results. It derives source/test paths from its own location and uses its running interpreter. Defaults:10seconds per Git command,1800seconds overall and32MiB combined output per command; failures kill/reap only owned children. The companion requires all11 core tests to pass with zero skips/errors before four known mutations. A surviving mutant or test error cannot count as detection. It retains source/mutant identities and metrics, then removes its owned temporary mutant copies. + +Registry handoff for canonical GOVERNANCE/TOOLING/STATUS: register `tools/workspace_git_inventory.py` as a read-only Phase1/G10 assessment tool and `tools/workspace_git_inventory_mutations.py` as its self-test companion. Both are self-contained, maintenance owner none, serving criteria1/9/11 and G10/G11 assessment. The collector performs no mathematical certification and does not turn dirty states into a failing completeness check; gate consumers must inspect the recorded state and combine remote branch/PR evidence. + +## Verification and observed cleanup + +The11 collector tests cover nested/node_modules repositories, linked and bare stores, refs/tags/stash/submodules, shallow/unborn/detached state, LF/tab/non-UTF8/rename paths, metadata nonmutation, clean-filter execution prevention, credential redaction, broken markers, symlink boundaries, bounded hangs and output. Four companion tests exercise required/private/exclusive output, failed-baseline refusal, a surviving no-op mutant and test-error refusal. The independently run companion baseline passes11 and detects4/4 weakened collectors by assertion failures. It was also run from `/tmp` to verify directory independence. Core tests passed under both Python3.11.17 and3.12.14. Versioned final normal/optimized test logs and source hashes accompany this report. The companion's internal child core suite uses its explicit-S/-B flags; the separate optimized core suite checks optimized collector behavior. + +Initial private census:74candidates,24stores,73worktree observations,17dirty worktrees and0stashes. Its sole error was a zero-byte invalid Git marker in derived package cache; it correctly returned incomplete/exit1. Later complete census found65worktrees after the scratch fixtures were retired. After53 retired Atlas roots were archived and removed, the next complete census recorded10stores/12worktrees/0errors/0stashes; only this author checkout was dirty. These are interval observations, not a current or global G10-pass claim. + +Recovery was verified before local cleanup:112,040 scratch entries and138,102 retired-root entries matched independent filesystem/path censuses and native tar byte comparison. Fifty stale IPC sockets were explicitly recorded as non-file endpoints. A native-verified all-ref/reflog Git bundle restored all42 distinct retired HEAD commits in a fresh temporary mirror. Entire shared Git metadata, including original indexes/staging states, was separately byte-verified;23 old local engineering branches were then conditionally pruned at their archived SHAs. No mathematical source branch was pruned by this unit. Private archive locators, raw inventory paths and custody mappings remain private. + +An existing Python3.11 installation was discovered to have lived in scratch. Its exact archived runtime was restored to a maintained location, owner-local link repaired, member bytes/modes verified, and11 normal/optimized core tests rerun. Initial missing-runtime and comparison failures are retained privately; they are not relabelled successful checks. DefaultPython3.12 remained available. + +## Limits and authority + +Observations are non-atomic. Internal directory symlinks are followed once; Git metadata aliases are excluded. External directory links and coverage errors are explicit incompleteness. Git ignore rules still apply to untracked status; discovery has no node_modules or cache exclusion. Configured hooks, clean/process filters, fsmonitor, automatic maintenance, optional locks and lazy network fetch are disabled for collection. No unreachable-object/reflog audit, remote fetch, preservation/deletion, proof closure, all-platform guarantee or global baseline pass follows from collector exit0. + +Actual authors: OpenAI/Codex Kepler for the collector/migration/companion, parent for permanent companion tests and integration. Self-review and actual automated controls; organizational-independence credit0 and scientific effect NONE. Canonical baseline documents and serial remote integration remain with #684's existing writer. diff --git a/docs/reports/cbz-workspace-hygiene-20261029/SOURCE.json b/docs/reports/cbz-workspace-hygiene-20261029/SOURCE.json new file mode 100644 index 000000000..47ded4cbc --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/SOURCE.json @@ -0,0 +1,29 @@ +{ + "base": "81acc060341e8a31cc4cd4f9523ef71fb6c06175", + "files": { + "tools/workspace_git_inventory.py": { + "bytes": 24122, + "sha256": "26227abc4b92cc2b9dc5e487158aacdde1b87c6d97d3a4b0929c0702e3d37301" + }, + "tools/workspace_git_inventory_mutations.py": { + "bytes": 7717, + "sha256": "086e44a9ca848db5b2b987198d30ef9008675b9495ebe75a68a09c5b63eda383" + }, + "tests/test_workspace_git_inventory.py": { + "bytes": 10223, + "sha256": "cfd1c780d093a0d08c86c2a22a01c1215e0443f222647d20fef9fc57a48511b4" + }, + "tests/test_workspace_git_inventory_mutations.py": { + "bytes": 4784, + "sha256": "e1d94f8302e09a6198466ab5913972206500c7be1b50f4c04fd99cc86c63be1a" + } + }, + "verification": { + "normal_tests": 15, + "optimized_tests": 15, + "core_baseline_tests": 11, + "known_mutations": 4, + "detected_mutations": 4 + }, + "scope": "Self-tested engineering observation tool, not LayerA mathematical certification, cleanGit or globalgate/CBZ claim" +} diff --git a/docs/reports/cbz-workspace-hygiene-20261029/collector-normal.log b/docs/reports/cbz-workspace-hygiene-20261029/collector-normal.log new file mode 100644 index 000000000..bf1f7cd1a --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/collector-normal.log @@ -0,0 +1,16 @@ +test_broken_marker_and_external_directory_boundary_are_not_silent (test_workspace_git_inventory.InventoryTests.test_broken_marker_and_external_directory_boundary_are_not_silent) ... ok +test_cli_private_output_and_nonzero_incomplete (test_workspace_git_inventory.InventoryTests.test_cli_private_output_and_nonzero_incomplete) ... ok +test_closed_streams_do_not_leave_a_hanging_child (test_workspace_git_inventory.InventoryTests.test_closed_streams_do_not_leave_a_hanging_child) ... ok +test_hanging_git_is_killed_and_reported (test_workspace_git_inventory.InventoryTests.test_hanging_git_is_killed_and_reported) ... ok +test_metadata_directory_alias_does_not_escape_git_exclusion (test_workspace_git_inventory.InventoryTests.test_metadata_directory_alias_does_not_escape_git_exclusion) ... ok +test_nested_linked_state_refs_stash_and_redacted_remotes (test_workspace_git_inventory.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) ... ok +test_output_limit_and_total_deadline_are_explicit (test_workspace_git_inventory.InventoryTests.test_output_limit_and_total_deadline_are_explicit) ... ok +test_rename_arbitrary_path_bytes_and_symlink_cycle (test_workspace_git_inventory.InventoryTests.test_rename_arbitrary_path_bytes_and_symlink_cycle) ... ok +test_status_does_not_execute_configured_clean_filter (test_workspace_git_inventory.InventoryTests.test_status_does_not_execute_configured_clean_filter) ... ok +test_submodule_bare_store_shallow_and_internal_symlink (test_workspace_git_inventory.InventoryTests.test_submodule_bare_store_shallow_and_internal_symlink) ... ok +test_unborn_and_detached_heads_are_observations_not_errors (test_workspace_git_inventory.InventoryTests.test_unborn_and_detached_heads_are_observations_not_errors) ... ok + +---------------------------------------------------------------------- +Ran 11 tests in 1.094s + +OK diff --git a/docs/reports/cbz-workspace-hygiene-20261029/collector-optimized.log b/docs/reports/cbz-workspace-hygiene-20261029/collector-optimized.log new file mode 100644 index 000000000..fabc6cc93 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/collector-optimized.log @@ -0,0 +1,16 @@ +test_broken_marker_and_external_directory_boundary_are_not_silent (test_workspace_git_inventory.InventoryTests.test_broken_marker_and_external_directory_boundary_are_not_silent) ... ok +test_cli_private_output_and_nonzero_incomplete (test_workspace_git_inventory.InventoryTests.test_cli_private_output_and_nonzero_incomplete) ... ok +test_closed_streams_do_not_leave_a_hanging_child (test_workspace_git_inventory.InventoryTests.test_closed_streams_do_not_leave_a_hanging_child) ... ok +test_hanging_git_is_killed_and_reported (test_workspace_git_inventory.InventoryTests.test_hanging_git_is_killed_and_reported) ... ok +test_metadata_directory_alias_does_not_escape_git_exclusion (test_workspace_git_inventory.InventoryTests.test_metadata_directory_alias_does_not_escape_git_exclusion) ... ok +test_nested_linked_state_refs_stash_and_redacted_remotes (test_workspace_git_inventory.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) ... ok +test_output_limit_and_total_deadline_are_explicit (test_workspace_git_inventory.InventoryTests.test_output_limit_and_total_deadline_are_explicit) ... ok +test_rename_arbitrary_path_bytes_and_symlink_cycle (test_workspace_git_inventory.InventoryTests.test_rename_arbitrary_path_bytes_and_symlink_cycle) ... ok +test_status_does_not_execute_configured_clean_filter (test_workspace_git_inventory.InventoryTests.test_status_does_not_execute_configured_clean_filter) ... ok +test_submodule_bare_store_shallow_and_internal_symlink (test_workspace_git_inventory.InventoryTests.test_submodule_bare_store_shallow_and_internal_symlink) ... ok +test_unborn_and_detached_heads_are_observations_not_errors (test_workspace_git_inventory.InventoryTests.test_unborn_and_detached_heads_are_observations_not_errors) ... ok + +---------------------------------------------------------------------- +Ran 11 tests in 1.049s + +OK diff --git a/docs/reports/cbz-workspace-hygiene-20261029/final15-normal.log b/docs/reports/cbz-workspace-hygiene-20261029/final15-normal.log new file mode 100644 index 000000000..5c25234c8 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/final15-normal.log @@ -0,0 +1,20 @@ +test_broken_marker_and_external_directory_boundary_are_not_silent (tests.test_workspace_git_inventory.InventoryTests.test_broken_marker_and_external_directory_boundary_are_not_silent) ... ok +test_cli_private_output_and_nonzero_incomplete (tests.test_workspace_git_inventory.InventoryTests.test_cli_private_output_and_nonzero_incomplete) ... ok +test_closed_streams_do_not_leave_a_hanging_child (tests.test_workspace_git_inventory.InventoryTests.test_closed_streams_do_not_leave_a_hanging_child) ... ok +test_hanging_git_is_killed_and_reported (tests.test_workspace_git_inventory.InventoryTests.test_hanging_git_is_killed_and_reported) ... ok +test_metadata_directory_alias_does_not_escape_git_exclusion (tests.test_workspace_git_inventory.InventoryTests.test_metadata_directory_alias_does_not_escape_git_exclusion) ... ok +test_nested_linked_state_refs_stash_and_redacted_remotes (tests.test_workspace_git_inventory.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) ... ok +test_output_limit_and_total_deadline_are_explicit (tests.test_workspace_git_inventory.InventoryTests.test_output_limit_and_total_deadline_are_explicit) ... ok +test_rename_arbitrary_path_bytes_and_symlink_cycle (tests.test_workspace_git_inventory.InventoryTests.test_rename_arbitrary_path_bytes_and_symlink_cycle) ... ok +test_status_does_not_execute_configured_clean_filter (tests.test_workspace_git_inventory.InventoryTests.test_status_does_not_execute_configured_clean_filter) ... ok +test_submodule_bare_store_shallow_and_internal_symlink (tests.test_workspace_git_inventory.InventoryTests.test_submodule_bare_store_shallow_and_internal_symlink) ... ok +test_unborn_and_detached_heads_are_observations_not_errors (tests.test_workspace_git_inventory.InventoryTests.test_unborn_and_detached_heads_are_observations_not_errors) ... ok +test_failed_baseline_never_runs_mutations (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_failed_baseline_never_runs_mutations) ... ok +test_requires_new_output_and_keeps_private_success_evidence (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_requires_new_output_and_keeps_private_success_evidence) ... ok +test_surviving_mutant_is_failure (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_surviving_mutant_is_failure) ... ok +test_test_error_cannot_count_as_mutation_detection (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_test_error_cannot_count_as_mutation_detection) ... ok + +---------------------------------------------------------------------- +Ran 15 tests in 7.141s + +OK diff --git a/docs/reports/cbz-workspace-hygiene-20261029/final15-optimized.log b/docs/reports/cbz-workspace-hygiene-20261029/final15-optimized.log new file mode 100644 index 000000000..3e0a00669 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/final15-optimized.log @@ -0,0 +1,20 @@ +test_broken_marker_and_external_directory_boundary_are_not_silent (tests.test_workspace_git_inventory.InventoryTests.test_broken_marker_and_external_directory_boundary_are_not_silent) ... ok +test_cli_private_output_and_nonzero_incomplete (tests.test_workspace_git_inventory.InventoryTests.test_cli_private_output_and_nonzero_incomplete) ... ok +test_closed_streams_do_not_leave_a_hanging_child (tests.test_workspace_git_inventory.InventoryTests.test_closed_streams_do_not_leave_a_hanging_child) ... ok +test_hanging_git_is_killed_and_reported (tests.test_workspace_git_inventory.InventoryTests.test_hanging_git_is_killed_and_reported) ... ok +test_metadata_directory_alias_does_not_escape_git_exclusion (tests.test_workspace_git_inventory.InventoryTests.test_metadata_directory_alias_does_not_escape_git_exclusion) ... ok +test_nested_linked_state_refs_stash_and_redacted_remotes (tests.test_workspace_git_inventory.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) ... ok +test_output_limit_and_total_deadline_are_explicit (tests.test_workspace_git_inventory.InventoryTests.test_output_limit_and_total_deadline_are_explicit) ... ok +test_rename_arbitrary_path_bytes_and_symlink_cycle (tests.test_workspace_git_inventory.InventoryTests.test_rename_arbitrary_path_bytes_and_symlink_cycle) ... ok +test_status_does_not_execute_configured_clean_filter (tests.test_workspace_git_inventory.InventoryTests.test_status_does_not_execute_configured_clean_filter) ... ok +test_submodule_bare_store_shallow_and_internal_symlink (tests.test_workspace_git_inventory.InventoryTests.test_submodule_bare_store_shallow_and_internal_symlink) ... ok +test_unborn_and_detached_heads_are_observations_not_errors (tests.test_workspace_git_inventory.InventoryTests.test_unborn_and_detached_heads_are_observations_not_errors) ... ok +test_failed_baseline_never_runs_mutations (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_failed_baseline_never_runs_mutations) ... ok +test_requires_new_output_and_keeps_private_success_evidence (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_requires_new_output_and_keeps_private_success_evidence) ... ok +test_surviving_mutant_is_failure (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_surviving_mutant_is_failure) ... ok +test_test_error_cannot_count_as_mutation_detection (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_test_error_cannot_count_as_mutation_detection) ... ok + +---------------------------------------------------------------------- +Ran 15 tests in 7.837s + +OK diff --git a/docs/reports/cbz-workspace-hygiene-20261029/mutation-baseline.log b/docs/reports/cbz-workspace-hygiene-20261029/mutation-baseline.log new file mode 100644 index 000000000..9e9664674 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/mutation-baseline.log @@ -0,0 +1,16 @@ +test_broken_marker_and_external_directory_boundary_are_not_silent (census_tests.InventoryTests.test_broken_marker_and_external_directory_boundary_are_not_silent) ... ok +test_cli_private_output_and_nonzero_incomplete (census_tests.InventoryTests.test_cli_private_output_and_nonzero_incomplete) ... ok +test_closed_streams_do_not_leave_a_hanging_child (census_tests.InventoryTests.test_closed_streams_do_not_leave_a_hanging_child) ... ok +test_hanging_git_is_killed_and_reported (census_tests.InventoryTests.test_hanging_git_is_killed_and_reported) ... ok +test_metadata_directory_alias_does_not_escape_git_exclusion (census_tests.InventoryTests.test_metadata_directory_alias_does_not_escape_git_exclusion) ... ok +test_nested_linked_state_refs_stash_and_redacted_remotes (census_tests.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) ... ok +test_output_limit_and_total_deadline_are_explicit (census_tests.InventoryTests.test_output_limit_and_total_deadline_are_explicit) ... ok +test_rename_arbitrary_path_bytes_and_symlink_cycle (census_tests.InventoryTests.test_rename_arbitrary_path_bytes_and_symlink_cycle) ... ok +test_status_does_not_execute_configured_clean_filter (census_tests.InventoryTests.test_status_does_not_execute_configured_clean_filter) ... ok +test_submodule_bare_store_shallow_and_internal_symlink (census_tests.InventoryTests.test_submodule_bare_store_shallow_and_internal_symlink) ... ok +test_unborn_and_detached_heads_are_observations_not_errors (census_tests.InventoryTests.test_unborn_and_detached_heads_are_observations_not_errors) ... ok + +---------------------------------------------------------------------- +Ran 11 tests in 1.013s + +OK diff --git a/docs/reports/cbz-workspace-hygiene-20261029/mutation-disable-redaction.log b/docs/reports/cbz-workspace-hygiene-20261029/mutation-disable-redaction.log new file mode 100644 index 000000000..a0720466e --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/mutation-disable-redaction.log @@ -0,0 +1,15 @@ +test_nested_linked_state_refs_stash_and_redacted_remotes (census_tests.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) ... FAIL + +====================================================================== +FAIL: test_nested_linked_state_refs_stash_and_redacted_remotes (census_tests.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz-workspace-git-hygiene-20261029/tests/test_workspace_git_inventory.py", line 59, in test_nested_linked_state_refs_stash_and_redacted_remotes + raw=json.dumps(d);self.assertNotIn('password',raw);self.assertNotIn('token=secret',raw) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: 'password' unexpectedly found in '{"schema_version": 1, "started_at": "2026-10-29T18:06:54.833602+00:00", "root": "/tmp/tmpkjds4k1d/workspace", "purpose": "Observed Git census only; not a clean-state or mathematical certification", "non_atomic_observations": true, "complete": true, "errors": [], "policy": {"walk_exclusions": ["Git metadata internals only; node_modules is searched"], "symlinks": "Follow internal directory targets once by device/inode; record all links; external directory targets are uncovered/incomplete", "paths": "NUL Git records; filesystem surrogateescape; JSON ensure_ascii=true", "read_only": "Optional locks, hooks, filters, maintenance and lazy network fetch disabled; no Git mutation commands", "status": "porcelain v1 -z --untracked-files=all; Git ignore rules still apply", "url_redaction": "userinfo and known credential query values redacted"}, "limits": {"git_timeout_seconds": 10, "total_timeout_seconds": 1800, "max_command_bytes": 33554432}, "stores": [{"path": "/tmp/tmpkjds4k1d/workspace/primary/.git", "representative": "/tmp/tmpkjds4k1d/workspace/linked\\nworktree", "refs": [{"name": "refs/heads/linked-branch", "object": "9a556deca51a0f42fa7f44b6c733db3b75812031", "type": "commit", "peeled_object": "", "peeled_type": "", "symbolic_target": ""}, {"name": "refs/heads/master", "object": "9a556deca51a0f42fa7f44b6c733db3b75812031", "type": "commit", "peeled_object": "", "peeled_type": "", "symbolic_target": ""}, {"name": "refs/heads/other", "object": "9a556deca51a0f42fa7f44b6c733db3b75812031", "type": "commit", "peeled_object": "", "peeled_type": "", "symbolic_target": ""}, {"name": "refs/stash", "object": "dcc96842f8652e906fe6f6cb460bb066c79b3569", "type": "commit", "peeled_object": "", "peeled_type": "", "symbolic_target": ""}, {"name": "refs/tags/annotated", "object": "1cfdd51b37a81b08bb32d999052858a669f5f9a6", "type": "tag", "peeled_object": "9a556deca51a0f42fa7f44b6c733db3b75812031", "peeled_type": "commit", "symbolic_target": ""}, {"name": "refs/tags/v1", "object": "9a556deca51a0f42fa7f44b6c733db3b75812031", "type": "commit", "peeled_object": "", "peeled_type": "", "symbolic_target": ""}], "remotes": [{"name": "origin", "fetch_urls": ["https://name:password@example.invalid/repo.git?token=secret"], "push_urls": []}, {"name": "scp", "fetch_urls": ["[REDACTED]@example.invalid:repo.git"], "push_urls": []}], "bare": false, "shallow": false, "registered_worktrees": [{"worktree": "/tmp/tmpkjds4k1d/workspace/primary", "HEAD": "9a556deca51a0f42fa7f44b6c733db3b75812031", "branch": "refs/heads/master"}, {"worktree": "/tmp/tmpkjds4k1d/workspace/linked\\nworktree", "HEAD": "9a556deca51a0f42fa7f44b6c733db3b75812031", "branch": "refs/heads/linked-branch"}], "stashes": [{"object": "dcc96842f8652e906fe6f6cb460bb066c79b3569", "selector": "stash@{0}"}]}, {"path": "/tmp/tmpkjds4k1d/workspace/primary/nested/.git", "representative": "/tmp/tmpkjds4k1d/workspace/primary/nested", "refs": [{"name": "refs/heads/master", "object": "9a556deca51a0f42fa7f44b6c733db3b75812031", "type": "commit", "peeled_object": "", "peeled_type": "", "symbolic_target": ""}], "remotes": [], "bare": false, "shallow": false, "registered_worktrees": [{"worktree": "/tmp/tmpkjds4k1d/workspace/primary/nested", "HEAD": "9a556deca51a0f42fa7f44b6c733db3b75812031", "branch": "refs/heads/master"}], "stashes": []}, {"path": "/tmp/tmpkjds4k1d/workspace/primary/node_modules/package/.git", "representative": "/tmp/tmpkjds4k1d/workspace/primary/node_modules/package", "refs": [{"name": "refs/heads/master", "object": "9a556deca51a0f42fa7f44b6c733db3b75812031", "type": "commit", "peeled_object": "", "peeled_type": "", "symbolic_target": ""}], "remotes": [], "bare": false, "shallow": false, "registered_worktrees": [{"worktree": "/tmp/tmpkjds4k1d/workspace/primary/node_modules/package", "HEAD": "9a556deca51a0f42fa7f44b6c733db3b75812031", "branch": "refs/heads/master"}], "stashes": []}], "worktrees": [{"path": "/tmp/tmpkjds4k1d/workspace/linked\\nworktree", "common_store": "/tmp/tmpkjds4k1d/workspace/primary/.git", "observed_at": "2026-10-29T18:06:54.884637+00:00", "exists": true, "head": "9a556deca51a0f42fa7f44b6c733db3b75812031", "branch": "refs/heads/linked-branch", "status": [], "submodules": [], "remotes": [{"name": "origin", "fetch_urls": ["https://name:password@example.invalid/repo.git?token=secret"], "push_urls": []}, {"name": "scp", "fetch_urls": ["[REDACTED]@example.invalid:repo.git"], "push_urls": []}], "bare": false, "git_dir": "/tmp/tmpkjds4k1d/workspace/primary/.git/worktrees/linked-worktree", "detached": false, "unborn": false, "local_refs": [{"name": "refs/worktree/census", "object": "9a556deca51a0f42fa7f44b6c733db3b75812031", "type": "commit", "peeled_object": "", "peeled_type": "", "symbolic_target": ""}]}, {"path": "/tmp/tmpkjds4k1d/workspace/primary", "common_store": "/tmp/tmpkjds4k1d/workspace/primary/.git", "observed_at": "2026-10-29T18:06:54.896687+00:00", "exists": true, "head": "9a556deca51a0f42fa7f44b6c733db3b75812031", "branch": "refs/heads/master", "status": [{"xy": " M", "path": "tracked"}, {"xy": "??", "path": "nested/"}, {"xy": "??", "path": "node_modules/package/"}, {"xy": "??", "path": "untracked\\nname\\tand spaces"}], "submodules": [], "remotes": [{"name": "origin", "fetch_urls": ["https://name:password@example.invalid/repo.git?token=secret"], "push_urls": []}, {"name": "scp", "fetch_urls": ["[REDACTED]@example.invalid:repo.git"], "push_urls": []}], "bare": false, "git_dir": "/tmp/tmpkjds4k1d/workspace/primary/.git", "detached": false, "unborn": false, "local_refs": []}, {"path": "/tmp/tmpkjds4k1d/workspace/primary/nested", "common_store": "/tmp/tmpkjds4k1d/workspace/primary/nested/.git", "observed_at": "2026-10-29T18:06:54.908211+00:00", "exists": true, "head": "9a556deca51a0f42fa7f44b6c733db3b75812031", "branch": "refs/heads/master", "status": [], "submodules": [], "remotes": [], "bare": false, "git_dir": "/tmp/tmpkjds4k1d/workspace/primary/nested/.git", "detached": false, "unborn": false, "local_refs": []}, {"path": "/tmp/tmpkjds4k1d/workspace/primary/node_modules/package", "common_store": "/tmp/tmpkjds4k1d/workspace/primary/node_modules/package/.git", "observed_at": "2026-10-29T18:06:54.920511+00:00", "exists": true, "head": "9a556deca51a0f42fa7f44b6c733db3b75812031", "branch": "refs/heads/master", "status": [], "submodules": [], "remotes": [], "bare": false, "git_dir": "/tmp/tmpkjds4k1d/workspace/primary/node_modules/package/.git", "detached": false, "unborn": false, "local_refs": []}], "discovered_roots": ["/tmp/tmpkjds4k1d/workspace/linked\\nworktree", "/tmp/tmpkjds4k1d/workspace/primary", "/tmp/tmpkjds4k1d/workspace/primary/nested", "/tmp/tmpkjds4k1d/workspace/primary/node_modules/package"], "symlinks": [], "git_metadata_not_traversed": ["/tmp/tmpkjds4k1d/workspace/primary/.git", "/tmp/tmpkjds4k1d/workspace/primary/nested/.git", "/tmp/tmpkjds4k1d/workspace/primary/node_modules/package/.git", "/tmp/tmpkjds4k1d/workspace/linked\\nworktree/.git"], "directories_visited": 6, "empty_discovery": false, "finished_at": "2026-10-29T18:06:54.932532+00:00", "git_commands": 66}' + +---------------------------------------------------------------------- +Ran 1 test in 0.167s + +FAILED (failures=1) diff --git a/docs/reports/cbz-workspace-hygiene-20261029/mutation-exclude-node-modules.log b/docs/reports/cbz-workspace-hygiene-20261029/mutation-exclude-node-modules.log new file mode 100644 index 000000000..06d193f27 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/mutation-exclude-node-modules.log @@ -0,0 +1,15 @@ +test_nested_linked_state_refs_stash_and_redacted_remotes (census_tests.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) ... FAIL + +====================================================================== +FAIL: test_nested_linked_state_refs_stash_and_redacted_remotes (census_tests.InventoryTests.test_nested_linked_state_refs_stash_and_redacted_remotes) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz-workspace-git-hygiene-20261029/tests/test_workspace_git_inventory.py", line 48, in test_nested_linked_state_refs_stash_and_redacted_remotes + for p in [repo,linked,nested,dependency]:self.assertIn(str(p),roots) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: '/tmp/tmp8gn6iebb/workspace/primary/node_modules/package' not found in {'/tmp/tmp8gn6iebb/workspace/linked\nworktree': {'path': '/tmp/tmp8gn6iebb/workspace/linked\nworktree', 'common_store': '/tmp/tmp8gn6iebb/workspace/primary/.git', 'observed_at': '2026-10-29T18:06:54.639754+00:00', 'exists': True, 'head': '9a556deca51a0f42fa7f44b6c733db3b75812031', 'branch': 'refs/heads/linked-branch', 'status': [], 'submodules': [], 'remotes': [{'name': 'origin', 'fetch_urls': ['https://[REDACTED]@example.invalid/repo.git?token=[REDACTED]'], 'push_urls': []}, {'name': 'scp', 'fetch_urls': ['[REDACTED]@example.invalid:repo.git'], 'push_urls': []}], 'bare': False, 'git_dir': '/tmp/tmp8gn6iebb/workspace/primary/.git/worktrees/linked-worktree', 'detached': False, 'unborn': False, 'local_refs': [{'name': 'refs/worktree/census', 'object': '9a556deca51a0f42fa7f44b6c733db3b75812031', 'type': 'commit', 'peeled_object': '', 'peeled_type': '', 'symbolic_target': ''}]}, '/tmp/tmp8gn6iebb/workspace/primary': {'path': '/tmp/tmp8gn6iebb/workspace/primary', 'common_store': '/tmp/tmp8gn6iebb/workspace/primary/.git', 'observed_at': '2026-10-29T18:06:54.652077+00:00', 'exists': True, 'head': '9a556deca51a0f42fa7f44b6c733db3b75812031', 'branch': 'refs/heads/master', 'status': [{'xy': ' M', 'path': 'tracked'}, {'xy': '??', 'path': 'nested/'}, {'xy': '??', 'path': 'node_modules/package/'}, {'xy': '??', 'path': 'untracked\nname\tand spaces'}], 'submodules': [], 'remotes': [{'name': 'origin', 'fetch_urls': ['https://[REDACTED]@example.invalid/repo.git?token=[REDACTED]'], 'push_urls': []}, {'name': 'scp', 'fetch_urls': ['[REDACTED]@example.invalid:repo.git'], 'push_urls': []}], 'bare': False, 'git_dir': '/tmp/tmp8gn6iebb/workspace/primary/.git', 'detached': False, 'unborn': False, 'local_refs': []}, '/tmp/tmp8gn6iebb/workspace/primary/nested': {'path': '/tmp/tmp8gn6iebb/workspace/primary/nested', 'common_store': '/tmp/tmp8gn6iebb/workspace/primary/nested/.git', 'observed_at': '2026-10-29T18:06:54.665706+00:00', 'exists': True, 'head': '9a556deca51a0f42fa7f44b6c733db3b75812031', 'branch': 'refs/heads/master', 'status': [], 'submodules': [], 'remotes': [], 'bare': False, 'git_dir': '/tmp/tmp8gn6iebb/workspace/primary/nested/.git', 'detached': False, 'unborn': False, 'local_refs': []}} + +---------------------------------------------------------------------- +Ran 1 test in 0.141s + +FAILED (failures=1) diff --git a/docs/reports/cbz-workspace-hygiene-20261029/mutation-execute-clean-filter.log b/docs/reports/cbz-workspace-hygiene-20261029/mutation-execute-clean-filter.log new file mode 100644 index 000000000..7982a6f0c --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/mutation-execute-clean-filter.log @@ -0,0 +1,15 @@ +test_status_does_not_execute_configured_clean_filter (census_tests.InventoryTests.test_status_does_not_execute_configured_clean_filter) ... FAIL + +====================================================================== +FAIL: test_status_does_not_execute_configured_clean_filter (census_tests.InventoryTests.test_status_does_not_execute_configured_clean_filter) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz-workspace-git-hygiene-20261029/tests/test_workspace_git_inventory.py", line 128, in test_status_does_not_execute_configured_clean_filter + d=self.census();self.assertTrue(d['complete'],d['errors']);self.assertFalse(marker.exists()) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: True is not false + +---------------------------------------------------------------------- +Ran 1 test in 0.117s + +FAILED (failures=1) diff --git a/docs/reports/cbz-workspace-hygiene-20261029/mutation-false-complete.log b/docs/reports/cbz-workspace-hygiene-20261029/mutation-false-complete.log new file mode 100644 index 000000000..e22d945e7 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/mutation-false-complete.log @@ -0,0 +1,15 @@ +test_broken_marker_and_external_directory_boundary_are_not_silent (census_tests.InventoryTests.test_broken_marker_and_external_directory_boundary_are_not_silent) ... FAIL + +====================================================================== +FAIL: test_broken_marker_and_external_directory_boundary_are_not_silent (census_tests.InventoryTests.test_broken_marker_and_external_directory_boundary_are_not_silent) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/workspace/cbz-workspace-git-hygiene-20261029/tests/test_workspace_git_inventory.py", line 81, in test_broken_marker_and_external_directory_boundary_are_not_silent + d=self.census();self.assertFalse(d['complete']);self.assertTrue(d['errors']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +AssertionError: True is not false + +---------------------------------------------------------------------- +Ran 1 test in 0.049s + +FAILED (failures=1) diff --git a/docs/reports/cbz-workspace-hygiene-20261029/mutations.json b/docs/reports/cbz-workspace-hygiene-20261029/mutations.json new file mode 100644 index 000000000..04fc58ea0 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/mutations.json @@ -0,0 +1,133 @@ +{ + "schema_version": 1, + "purpose": "Git census self-tests only; no mathematical certification or Git cleanliness claim", + "started_at": "2026-10-29T18:06:53.363254+00:00", + "python": "3.12.14 (main, Aug 25 2026, 14:00:49) [Clang 22.1.3 ]", + "python_executable": "/opt/codex/runtimes/codex-primary-runtime/dependencies/python/bin/python3", + "sources": { + "collector": { + "path": "/workspace/cbz-workspace-git-hygiene-20261029/tools/workspace_git_inventory.py", + "sha256": "26227abc4b92cc2b9dc5e487158aacdde1b87c6d97d3a4b0929c0702e3d37301", + "bytes": 24122 + }, + "tests": { + "path": "/workspace/cbz-workspace-git-hygiene-20261029/tests/test_workspace_git_inventory.py", + "sha256": "cfd1c780d093a0d08c86c2a22a01c1215e0443f222647d20fef9fc57a48511b4", + "bytes": 10223 + }, + "runner": { + "path": "/workspace/cbz-workspace-git-hygiene-20261029/tools/workspace_git_inventory_mutations.py", + "sha256": "086e44a9ca848db5b2b987198d30ef9008675b9495ebe75a68a09c5b63eda383", + "bytes": 7717 + } + }, + "baseline": { + "test": "entire suite", + "log": "baseline.log", + "metrics": "baseline.json", + "timeout_seconds": 60, + "returncode": 0, + "tests_run": 11, + "successful": true, + "failures": 0, + "errors": 0, + "skipped": 0, + "expected_failures": 0, + "unexpected_successes": 0, + "passed": true + }, + "mutations": [ + { + "test": "test_nested_linked_state_refs_stash_and_redacted_remotes", + "log": "exclude-node-modules.log", + "metrics": "exclude-node-modules.json", + "timeout_seconds": 20, + "returncode": 1, + "tests_run": 1, + "successful": false, + "failures": 1, + "errors": 0, + "skipped": 0, + "expected_failures": 0, + "unexpected_successes": 0, + "mutation": "exclude-node-modules", + "source_sha256": "26227abc4b92cc2b9dc5e487158aacdde1b87c6d97d3a4b0929c0702e3d37301", + "mutant_sha256": "738a7606715fa6d525ef42e08df30c430778f0a3b9fef0e5c164e35675eb6ec7", + "replacement": { + "old": "if entry.name == '.git':", + "new": "if entry.name in ('.git', 'node_modules'):" + }, + "detected_by_assertion": true + }, + { + "test": "test_nested_linked_state_refs_stash_and_redacted_remotes", + "log": "disable-redaction.log", + "metrics": "disable-redaction.json", + "timeout_seconds": 20, + "returncode": 1, + "tests_run": 1, + "successful": false, + "failures": 1, + "errors": 0, + "skipped": 0, + "expected_failures": 0, + "unexpected_successes": 0, + "mutation": "disable-redaction", + "source_sha256": "26227abc4b92cc2b9dc5e487158aacdde1b87c6d97d3a4b0929c0702e3d37301", + "mutant_sha256": "ce0e30dda743732a436d0d0ea2de2420741bd67e1d0e0b8e0637b7a99605b431", + "replacement": { + "old": "def _redact(value):\n", + "new": "def _redact(value):\n return value\n" + }, + "detected_by_assertion": true + }, + { + "test": "test_status_does_not_execute_configured_clean_filter", + "log": "execute-clean-filter.log", + "metrics": "execute-clean-filter.json", + "timeout_seconds": 20, + "returncode": 1, + "tests_run": 1, + "successful": false, + "failures": 1, + "errors": 0, + "skipped": 0, + "expected_failures": 0, + "unexpected_successes": 0, + "mutation": "execute-clean-filter", + "source_sha256": "26227abc4b92cc2b9dc5e487158aacdde1b87c6d97d3a4b0929c0702e3d37301", + "mutant_sha256": "43c4e2f57394deaf470b40681ff797e64f77a1d3f110ab2437cb3bb60efccc0b", + "replacement": { + "old": "settings += [prefix + '.clean=', prefix + '.process=', prefix + '.required=false']", + "new": "settings += []" + }, + "detected_by_assertion": true + }, + { + "test": "test_broken_marker_and_external_directory_boundary_are_not_silent", + "log": "false-complete.log", + "metrics": "false-complete.json", + "timeout_seconds": 20, + "returncode": 1, + "tests_run": 1, + "successful": false, + "failures": 1, + "errors": 0, + "skipped": 0, + "expected_failures": 0, + "unexpected_successes": 0, + "mutation": "false-complete", + "source_sha256": "26227abc4b92cc2b9dc5e487158aacdde1b87c6d97d3a4b0929c0702e3d37301", + "mutant_sha256": "b9128e53cd5341e3a9d36b4923b1b17aa3b59080378bb64d6c6ff63a8097302b", + "replacement": { + "old": "complete=not reader.errors", + "new": "complete=True" + }, + "detected_by_assertion": true + } + ], + "errors": [], + "complete": true, + "all_detected": true, + "finished_at": "2026-10-29T18:06:55.340338+00:00" +} diff --git a/docs/reports/cbz-workspace-hygiene-20261029/runner-controls.json b/docs/reports/cbz-workspace-hygiene-20261029/runner-controls.json new file mode 100644 index 000000000..4054483e5 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/runner-controls.json @@ -0,0 +1,14 @@ +[ + { + "control": "broken Git rejects baseline before mutations", + "passed": true + }, + { + "control": "survivor-rejected", + "passed": true + }, + { + "control": "error-rejected", + "passed": true + } +] diff --git a/docs/reports/cbz-workspace-hygiene-20261029/runner-normal-initial.log b/docs/reports/cbz-workspace-hygiene-20261029/runner-normal-initial.log new file mode 100644 index 000000000..9d5495ab1 --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/runner-normal-initial.log @@ -0,0 +1,9 @@ +test_failed_baseline_never_runs_mutations (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_failed_baseline_never_runs_mutations) ... ok +test_requires_new_output_and_keeps_private_success_evidence (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_requires_new_output_and_keeps_private_success_evidence) ... ok +test_surviving_mutant_is_failure (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_surviving_mutant_is_failure) ... ok +test_test_error_cannot_count_as_mutation_detection (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_test_error_cannot_count_as_mutation_detection) ... ok + +---------------------------------------------------------------------- +Ran 4 tests in 6.911s + +OK diff --git a/docs/reports/cbz-workspace-hygiene-20261029/runner-optimized-initial.log b/docs/reports/cbz-workspace-hygiene-20261029/runner-optimized-initial.log new file mode 100644 index 000000000..997018a5b --- /dev/null +++ b/docs/reports/cbz-workspace-hygiene-20261029/runner-optimized-initial.log @@ -0,0 +1,9 @@ +test_failed_baseline_never_runs_mutations (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_failed_baseline_never_runs_mutations) ... ok +test_requires_new_output_and_keeps_private_success_evidence (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_requires_new_output_and_keeps_private_success_evidence) ... ok +test_surviving_mutant_is_failure (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_surviving_mutant_is_failure) ... ok +test_test_error_cannot_count_as_mutation_detection (tests.test_workspace_git_inventory_mutations.MutationRunnerTests.test_test_error_cannot_count_as_mutation_detection) ... ok + +---------------------------------------------------------------------- +Ran 4 tests in 6.736s + +OK diff --git a/tests/test_workspace_git_inventory.py b/tests/test_workspace_git_inventory.py new file mode 100644 index 000000000..a472cb281 --- /dev/null +++ b/tests/test_workspace_git_inventory.py @@ -0,0 +1,153 @@ +"""Real-Git census tests: discovery, native state, failure boundaries and privacy.""" +import importlib.util +import json +import os +from pathlib import Path +import signal +import stat +import subprocess +import tempfile +import unittest + +TOOL=Path(__file__).resolve().parents[1]/'tools/workspace_git_inventory.py' + + +class InventoryTests(unittest.TestCase): + def setUp(self): + self.temp=tempfile.TemporaryDirectory();self.addCleanup(self.temp.cleanup) + self.root=Path(self.temp.name)/'workspace';self.root.mkdir() + + def git(self,path,*args): + return subprocess.check_output(['git','-C',str(path),*args],stderr=subprocess.PIPE) + + def repo(self,name): + p=self.root/name;p.mkdir(parents=True);self.git(p,'init','-q') + self.git(p,'config','user.name','Census Test');self.git(p,'config','user.email','census@example.invalid') + (p/'tracked').write_text('initial\n');self.git(p,'add','tracked');self.git(p,'commit','-qm','initial') + return p + + def census(self,**options): + spec=importlib.util.spec_from_file_location('git_inventory',TOOL) + module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module) + return module.inventory(self.root,**options) + + def test_nested_linked_state_refs_stash_and_redacted_remotes(self): + repo=self.repo('primary');self.git(repo,'branch','other');self.git(repo,'tag','v1') + self.git(repo,'tag','-am','annotated test','annotated') + (repo/'tracked').write_text('stashed\n');self.git(repo,'stash','push','-qm','retained stash') + self.git(repo,'remote','add','origin','https://name:password@example.invalid/repo.git?token=secret') + self.git(repo,'remote','add','scp','private-user@example.invalid:repo.git') + linked=self.root/('linked'+chr(10)+'worktree');self.git(repo,'worktree','add','-qb','linked-branch',str(linked)) + self.git(linked,'update-ref','refs/worktree/census','HEAD') + nested=self.repo('primary/nested');dependency=self.repo('primary/node_modules/package') + (repo/'tracked').write_text('dirty\n');name='untracked'+chr(10)+'name'+chr(9)+'and spaces';(repo/name).write_text('new') + before=(repo/'.git/index').read_bytes() + metadata={str(p.relative_to(repo/'.git')):p.read_bytes() for p in (repo/'.git').rglob('*') if p.is_file()} + d=self.census();self.assertTrue(d['complete'],d['errors']) + roots={r['path']:r for r in d['worktrees']} + for p in [repo,linked,nested,dependency]:self.assertIn(str(p),roots) + self.assertEqual(len(d['stores']),3) + self.assertEqual(roots[str(linked)]['branch'],'refs/heads/linked-branch') + self.assertTrue(any(r['name']=='refs/worktree/census'for r in roots[str(linked)]['local_refs'])) + status=roots[str(repo)]['status'];self.assertTrue(any(r['path']==name and r['xy']=='??'for r in status)) + self.assertTrue(any(r['path']=='tracked'and'M'in r['xy']for r in status)) + store=next(s for s in d['stores']if s['path']==str(repo/'.git')) + refs={r['name']:r['object']for r in store['refs']};self.assertIn('refs/heads/other',refs);self.assertIn('refs/tags/v1',refs) + tag=next(r for r in store['refs']if r['name']=='refs/tags/annotated') + self.assertEqual(tag['type'],'tag');self.assertEqual(tag['peeled_object'],self.git(repo,'rev-parse','HEAD').decode().strip()) + self.assertEqual(len(store['stashes']),1) + raw=json.dumps(d);self.assertNotIn('password',raw);self.assertNotIn('token=secret',raw) + self.assertIn('REDACTED',raw);self.assertEqual((repo/'.git/index').read_bytes(),before) + self.assertNotIn('private-user',raw) + self.assertEqual(metadata,{str(p.relative_to(repo/'.git')):p.read_bytes() for p in (repo/'.git').rglob('*') if p.is_file()}) + + def test_submodule_bare_store_shallow_and_internal_symlink(self): + source=self.repo('source');parent=self.repo('parent') + subpath='sub'+chr(10)+'module' + self.git(parent,'-c','protocol.file.allow=always','submodule','add','-q','--name','module',str(source),subpath) + bare=self.root/'bare.git';subprocess.check_call(['git','clone','-q','--bare',str(source),str(bare)]) + shallow=self.root/'shallow';subprocess.check_call(['git','clone','-q','--depth','1',source.as_uri(),str(shallow)]) + (self.root/'alias').symlink_to(parent,target_is_directory=True) + d=self.census();self.assertTrue(d['complete'],d['errors']) + work=next(r for r in d['worktrees']if r['path']==str(parent)) + self.assertEqual(work['submodules'][0]['path'],subpath);self.assertTrue(work['submodules'][0]['initialized']) + self.assertTrue(next(s for s in d['stores']if s['path']==str(shallow/'.git'))['shallow']) + self.assertTrue(any(s['path']==str(bare)and s['bare']for s in d['stores'])) + self.assertTrue(any(s['path']==str(self.root/'alias')for s in d['symlinks'])) + + def test_broken_marker_and_external_directory_boundary_are_not_silent(self): + self.repo('good');broken=self.root/'broken';broken.mkdir();(broken/'.git').write_text('gitdir: /does/not/exist\n') + external=Path(self.temp.name)/'outside';external.mkdir();(self.root/'external').symlink_to(external,target_is_directory=True) + d=self.census();self.assertFalse(d['complete']);self.assertTrue(d['errors']) + self.assertTrue(any(e['kind']=='external_directory_symlink'for e in d['errors'])) + self.assertIn(str(broken),d['discovered_roots']) + + def test_cli_private_output_and_nonzero_incomplete(self): + self.repo('good');bad=self.root/'broken';bad.mkdir();(bad/'.git').write_text('invalid\n') + out=Path(self.temp.name)/'inventory.json' + r=subprocess.run(['python3','-S',str(TOOL),'--root',str(self.root),'--output',str(out)],capture_output=True,text=True) + self.assertNotEqual(r.returncode,0);self.assertTrue(out.exists(),r.stderr) + self.assertEqual(stat.S_IMODE(out.stat().st_mode),0o600) + self.assertFalse(json.loads(out.read_bytes())['complete']) + + def test_hanging_git_is_killed_and_reported(self): + self.repo('repo');fake=Path(self.temp.name)/'git-hang' + fake.write_text('#!/usr/bin/env python3\nimport time\ntime.sleep(30)\n');fake.chmod(0o700) + d=self.census(git=str(fake),command_timeout=.1,total_timeout=3) + self.assertFalse(d['complete']);self.assertTrue(any(e['kind']=='timeout'for e in d['errors'])) + + def test_closed_streams_do_not_leave_a_hanging_child(self): + self.repo('repo');fake=Path(self.temp.name)/'git-closed';pidfile=Path(self.temp.name)/'pid' + fake.write_text('#!/usr/bin/env python3\nimport os,time,pathlib\npathlib.Path('+repr(str(pidfile))+').write_text(str(os.getpid()))\nos.close(1)\nos.close(2)\ntime.sleep(30)\n') + fake.chmod(0o700) + try: + d=self.census(git=str(fake),command_timeout=.1,total_timeout=3) + self.assertFalse(d['complete']);self.assertTrue(any(e['kind']=='timeout'for e in d['errors'])) + with self.assertRaises(ProcessLookupError):os.kill(int(pidfile.read_text()),0) + finally: + if pidfile.exists(): + try:os.killpg(int(pidfile.read_text()),signal.SIGKILL) + except ProcessLookupError:pass + + def test_rename_arbitrary_path_bytes_and_symlink_cycle(self): + repo=self.repo('repo');old='old'+chr(10)+'name';new='new'+chr(9)+os.fsdecode(b'\xff') + (repo/old).write_text('content');self.git(repo,'add',old);self.git(repo,'commit','-qm','path') + self.git(repo,'mv',old,new) + (self.root/'cycle-a').symlink_to(self.root/'cycle-b');(self.root/'cycle-b').symlink_to(self.root/'cycle-a') + d=self.census();self.assertFalse(d['complete']);self.assertTrue(any(e['kind']=='filesystem'for e in d['errors'])) + r=next(w for w in d['worktrees']if w['path']==str(repo)) + renamed=next(r for r in r['status']if'R'in r['xy']) + self.assertEqual((renamed['path'],renamed['original_path']),(new,old)) + self.assertEqual(json.loads(json.dumps(d))['worktrees'],d['worktrees']) + + def test_status_does_not_execute_configured_clean_filter(self): + repo=self.repo('filtered');marker=Path(self.temp.name)/'FILTER-RAN' + script=Path(self.temp.name)/'filter.py';script.write_text('import pathlib,sys\npathlib.Path('+repr(str(marker))+').write_text("bad")\nsys.stdout.write(sys.stdin.read())\n') + self.git(repo,'config','filter.audit.clean','python3 '+str(script)) + (repo/'.gitattributes').write_text('tracked filter=audit\n');(repo/'tracked').write_text('changed\n') + d=self.census();self.assertTrue(d['complete'],d['errors']);self.assertFalse(marker.exists()) + + def test_output_limit_and_total_deadline_are_explicit(self): + self.repo('repo');fake=Path(self.temp.name)/'git-noisy' + fake.write_text('#!/usr/bin/env python3\nimport sys\nsys.stdout.write("x"*100000)\n');fake.chmod(0o700) + d=self.census(git=str(fake),max_command_bytes=128) + self.assertFalse(d['complete']);self.assertTrue(any(e['kind']=='output_limit'for e in d['errors'])) + d=self.census(total_timeout=0) + self.assertFalse(d['complete']);self.assertTrue(any(e['kind']=='deadline'for e in d['errors'])) + + def test_metadata_directory_alias_does_not_escape_git_exclusion(self): + repo=self.repo('repo');hidden=repo/'.git/objects/hidden';hidden.mkdir() + self.git(hidden,'init','-q');(self.root/'objects-alias').symlink_to(repo/'.git/objects',target_is_directory=True) + d=self.census();self.assertTrue(d['complete'],d['errors']) + self.assertNotIn(str(hidden),d['discovered_roots']) + + def test_unborn_and_detached_heads_are_observations_not_errors(self): + empty=self.root/'unborn';empty.mkdir();self.git(empty,'init','-q') + repo=self.repo('detached');self.git(repo,'checkout','-q','--detach') + d=self.census();self.assertTrue(d['complete'],d['errors']) + by={w['path']:w for w in d['worktrees']} + self.assertTrue(by[str(empty)]['unborn']);self.assertIsNone(by[str(empty)]['head']) + self.assertTrue(by[str(repo)]['detached']);self.assertIsNone(by[str(repo)]['branch']) + + +if __name__=='__main__':unittest.main() diff --git a/tests/test_workspace_git_inventory_mutations.py b/tests/test_workspace_git_inventory_mutations.py new file mode 100644 index 000000000..3adb35ccf --- /dev/null +++ b/tests/test_workspace_git_inventory_mutations.py @@ -0,0 +1,107 @@ +"""CLI and false-success controls for the census mutation self-test runner.""" +import hashlib +import json +import os +from pathlib import Path +import shutil +import stat +import subprocess +import sys +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[1] + + +class MutationRunnerTests(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + self.source = self.root / 'source' + (self.source / 'tools').mkdir(parents=True) + (self.source / 'tests').mkdir() + for path in ['tools/workspace_git_inventory.py', 'tools/workspace_git_inventory_mutations.py', 'tests/test_workspace_git_inventory.py']: + shutil.copyfile(ROOT / path, self.source / path) + self.runner = self.source / 'tools/workspace_git_inventory_mutations.py' + self.output = self.root / 'evidence' + + def run_cli(self, *, override=None, env=None, output=True): + interpreter = [sys.executable, '-S', '-B'] + if sys.flags.optimize: + interpreter.append('-' + 'O' * sys.flags.optimize) + if override is None: + command = [*interpreter, str(self.runner)] + else: + driver = ( + 'import importlib.util,sys\n' + 'p=sys.argv[1];s=importlib.util.spec_from_file_location("runner",p)\n' + 'm=importlib.util.module_from_spec(s);s.loader.exec_module(m)\n' + + override + '\n' + 'sys.argv=[p]+sys.argv[2:];raise SystemExit(m.main())\n') + command = [*interpreter, '-c', driver, str(self.runner)] + if output: + command += ['--output', str(self.output)] + return subprocess.run(command, cwd=self.root, env=env, capture_output=True, text=True, timeout=90) + + def report(self): + return json.loads((self.output / 'results.json').read_bytes()) + + def test_requires_new_output_and_keeps_private_success_evidence(self): + missing = self.run_cli(output=False) + self.assertEqual(missing.returncode, 2) + self.assertFalse(self.output.exists()) + result = self.run_cli() + self.assertEqual(result.returncode, 0, result.stderr + result.stdout) + report = self.report() + self.assertTrue(report['complete']) + self.assertTrue(report['baseline']['passed']) + self.assertEqual(report['baseline']['tests_run'], 11) + self.assertEqual(len(report['mutations']), 4) + self.assertTrue(all(row['detected_by_assertion'] for row in report['mutations'])) + self.assertEqual(stat.S_IMODE(self.output.stat().st_mode), 0o700) + for path in self.output.iterdir(): + self.assertEqual(stat.S_IMODE(path.stat().st_mode), 0o600) + before = {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in self.output.iterdir()} + repeated = self.run_cli() + self.assertEqual(repeated.returncode, 2) + self.assertEqual(before, {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in self.output.iterdir()}) + + def test_failed_baseline_never_runs_mutations(self): + fake = self.root / 'bin' + fake.mkdir() + git = fake / 'git' + git.write_text('#!/bin/sh\nexit 7\n') + git.chmod(0o700) + env = os.environ.copy() + env['PATH'] = str(fake) + os.pathsep + env['PATH'] + result = self.run_cli(env=env) + self.assertEqual(result.returncode, 1, result.stderr) + report = self.report() + self.assertFalse(report['baseline']['passed']) + self.assertEqual(report['mutations'], []) + self.assertFalse(report['complete']) + + def test_surviving_mutant_is_failure(self): + result = self.run_cli(override='n,o,_new,t=m.CASES[0];m.CASES[0]=(n,o,o,t)') + self.assertEqual(result.returncode, 1, result.stderr) + report = self.report() + self.assertTrue(report['baseline']['passed']) + self.assertEqual(report['mutations'][0]['returncode'], 0) + self.assertFalse(report['mutations'][0]['detected_by_assertion']) + self.assertFalse(report['all_detected']) + self.assertFalse(report['complete']) + + def test_test_error_cannot_count_as_mutation_detection(self): + result = self.run_cli(override='n,o,new,_t=m.CASES[0];m.CASES[0]=(n,o,new,"nonexistent_test")') + self.assertEqual(result.returncode, 1, result.stderr) + report = self.report() + self.assertTrue(report['baseline']['passed']) + self.assertEqual(report['mutations'][0]['errors'], 1) + self.assertFalse(report['mutations'][0]['detected_by_assertion']) + self.assertFalse(report['all_detected']) + self.assertFalse(report['complete']) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/workspace_git_inventory.py b/tools/workspace_git_inventory.py new file mode 100644 index 000000000..8f0593721 --- /dev/null +++ b/tools/workspace_git_inventory.py @@ -0,0 +1,496 @@ +#!/usr/bin/env python3 +"""Read-only recursive Git observations, not a clean-state or mathematical certificate. + +Search every physical directory, including ignored/node_modules directories, +except Git metadata internals. Follow internal directory symlinks once by inode; +record external directory links as uncovered boundaries (incomplete/nonzero). +Git output uses NUL records. JSON ensure_ascii preserves arbitrary path bytes +through Python's filesystem surrogateescape convention. No network is needed. +""" +from __future__ import annotations + +import argparse +import datetime +import json +import math +import os +from pathlib import Path +import re +import selectors +import signal +import subprocess +import time + + +def _now(): + return datetime.datetime.now(datetime.timezone.utc).isoformat() + + +def _text(raw): + return os.fsdecode(raw) + + +def _line(raw): + return _text(raw[:-1] if raw.endswith(b'\n') else raw) + + +def _redact(value): + if isinstance(value, dict): + return {key: _redact(item) for key, item in value.items()} + if isinstance(value, list): + return [_redact(item) for item in value] + if not isinstance(value, str): + return value + value = re.sub(r'([A-Za-z][A-Za-z0-9+.-]*://)[^/\s]+@', + r'\1[REDACTED]@', value) + value = re.sub(r'(?i)([?&](?:access_token|token|password|passwd|secret|signature|key|auth)=)[^&#\s]*', + r'\1[REDACTED]', value) + return value + + +def _remote_url(value): + value = _redact(value) + if '://' not in value: + value = re.sub(r'^[^/\s]+@(?=[^/:\s]+:)', '[REDACTED]@', value) + return value + + +class Git: + def __init__(self, git, command_timeout, total_timeout, max_command_bytes): + self.executable = git + self.command_timeout = command_timeout + self.deadline = time.monotonic() + total_timeout + self.max_bytes = max_command_bytes + self.errors = [] + self.commands = 0 + self.env = os.environ.copy() + for name in ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_INDEX_FILE', + 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_NAMESPACE']: + self.env.pop(name, None) + self.env.update(GIT_OPTIONAL_LOCKS='0', GIT_TERMINAL_PROMPT='0', GIT_NO_LAZY_FETCH='1') + self.base = ['core.fsmonitor=false', 'core.untrackedCache=false', + 'core.hooksPath=/dev/null', 'maintenance.auto=false', 'gc.auto=0', + 'core.quotePath=false', 'protocol.allow=never'] + self.base += ['protocol.' + name + '.allow=never' + for name in ['http', 'https', 'ssh', 'git', 'file', 'ext']] + + def error(self, kind, path, operation, **detail): + self.errors.append({'kind': kind, 'path': str(path), 'operation': operation, **detail}) + + def expired(self): + return time.monotonic() >= self.deadline + + def run(self, cwd, *args, allowed=(0,), settings=()): + operation = ' '.join(args[:3]) + remaining = self.deadline - time.monotonic() + if remaining <= 0: + self.error('deadline', cwd, operation) + return None + command = [self.executable, '--no-optional-locks'] + for setting in [*self.base, *settings]: + command += ['-c', setting] + command += ['-C', str(cwd), *args] + self.commands += 1 + try: + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=self.env, start_new_session=True) + except OSError as exc: + self.error('spawn', cwd, operation, message=str(exc)) + return None + streams = {process.stdout: bytearray(), process.stderr: bytearray()} + selector = selectors.DefaultSelector() + for stream in streams: + selector.register(stream, selectors.EVENT_READ) + cutoff = time.monotonic() + min(self.command_timeout, remaining) + failure = None + try: + while selector.get_map(): + if time.monotonic() >= cutoff: + failure = 'timeout' + break + for key, _ in selector.select(min(.1, max(0, cutoff - time.monotonic()))): + chunk = os.read(key.fd, 65536) + if not chunk: + selector.unregister(key.fileobj) + continue + if sum(len(b) for b in streams.values()) + len(chunk) > self.max_bytes: + failure = 'output_limit' + break + streams[key.fileobj].extend(chunk) + if failure: + break + if not failure: + try: + code = process.wait(timeout=max(0, cutoff - time.monotonic())) + except subprocess.TimeoutExpired: + failure = 'timeout' + if failure: + try: + os.killpg(process.pid, signal.SIGKILL) + except ProcessLookupError: + pass + try: + code = process.wait(timeout=1) + except subprocess.TimeoutExpired: + self.error('child_not_reaped', cwd, operation, pid=process.pid) + code = None + finally: + selector.close() + for stream in streams: + stream.close() + out, err = bytes(streams[process.stdout]), bytes(streams[process.stderr]) + if failure: + self.error(failure, cwd, operation, stderr=_text(err), output_bytes=len(out)) + return None + if code not in allowed or err: + self.error('git_error' if code not in allowed else 'git_stderr', cwd, operation, + returncode=code, stderr=_text(err)) + return None + return code, out + + +def _discover(root, git): + stack = [root] + visited = set() + roots = set() + symlinks = [] + skipped_metadata = [] + while stack: + if git.expired(): + git.error('deadline', root, 'recursive discovery', pending_directories=len(stack)) + break + directory = stack.pop() + try: + stat = directory.stat() + identity = stat.st_dev, stat.st_ino + if identity in visited: + continue + visited.add(identity) + if os.path.lexists(directory / '.git'): + roots.add(str(directory.resolve())) + # Bare stores (and metadata aliases) have no .git child. + if (directory / 'HEAD').is_file() and (directory / 'objects').is_dir(): + roots.add(str(directory.resolve())) + skipped_metadata.append(str(directory)) + continue + with os.scandir(directory) as entries: + for entry in entries: + if git.expired(): + git.error('deadline', directory, 'recursive discovery') + break + if entry.name == '.git': + skipped_metadata.append(entry.path) + continue + try: + if entry.is_symlink(): + target = Path(entry.path).resolve() + is_directory = entry.is_dir() + record = {'path': entry.path, 'target': str(target), + 'directory': is_directory, 'exists': target.exists()} + symlinks.append(record) + if is_directory: + if any(parent.name == '.git' or + ((parent / 'HEAD').is_file() and (parent / 'objects').is_dir()) + for parent in target.parents): + record['not_followed'] = 'Git metadata internals' + skipped_metadata.append(str(target)) + elif target.is_relative_to(root): + stack.append(target) + else: + git.error('external_directory_symlink', entry.path, + 'recursive discovery', target=str(target)) + continue + if entry.is_dir(follow_symlinks=False): + stack.append(Path(entry.path)) + except (OSError, RuntimeError) as exc: + git.error('filesystem', entry.path, 'recursive discovery', message=str(exc)) + except OSError as exc: + git.error('filesystem', directory, 'recursive discovery', message=str(exc)) + return sorted(roots), symlinks, skipped_metadata, len(visited) + + +def _config(git, cwd, pattern, source=(), settings=()): + result = git.run(cwd, 'config', *source, '--null', '--name-only', '--get-regexp', pattern, + allowed=(0, 1), settings=settings) + if result is None: + return {} + values = {} + for key in result[1].split(b'\0'): + if not key: + continue + name = _text(key) + value = git.run(cwd, 'config', *source, '--null', '--get-all', name, allowed=(0, 1), settings=settings) + if value is not None: + values[name] = [_text(v) for v in value[1].split(b'\0')[:-1]] + return values + + +def _settings_and_remotes(git, cwd): + # Reading config does not execute it. Disable filter programs for status; + # URL overrides and protocol denial also prevent lazy partial-clone fetch. + names = git.run(cwd, 'config', '--null', '--name-only', '--get-regexp', + r'^(filter\..*\.(clean|process|required)|remote\..*\.(url|pushurl|promisor)|protocol\..*\.allow)$', + allowed=(0, 1)) + settings = [] + remotes = {} + if names is None: + return settings, [] + for raw in names[1].split(b'\0'): + if not raw: + continue + key = _text(raw) + if key.startswith('filter.'): + prefix = key.rsplit('.', 1)[0] + settings += [prefix + '.clean=', prefix + '.process=', prefix + '.required=false'] + elif key.startswith('protocol.'): + settings.append(key + '=never') + elif key.startswith('remote.'): + name, field = key[7:].rsplit('.', 1) + settings += ['remote.' + name + '.url=', 'remote.' + name + '.pushurl=', + 'remote.' + name + '.promisor=false'] + row = remotes.setdefault(name, {'name': name, 'fetch_urls': [], 'push_urls': []}) + if field in ('url', 'pushurl'): + result = git.run(cwd, 'config', '--null', '--get-all', key, allowed=(0, 1)) + if result is not None: + row['fetch_urls' if field == 'url' else 'push_urls'] = [ + _remote_url(_text(v)) for v in result[1].split(b'\0')[:-1]] + return list(dict.fromkeys(settings)), list(remotes.values()) + + +def _refs(git, cwd, settings, prefixes=()): + result = git.run(cwd, 'for-each-ref', + '--format=%(refname)%00%(objectname)%00%(objecttype)%00%(*objectname)%00%(*objecttype)%00%(symref)%00', + *prefixes, settings=settings) + rows = [] + if result is None: + return rows + fields = result[1].split(b'\0') + if fields[-1] in (b'', b'\n'): + fields.pop() + if len(fields) % 6: + git.error('parse', cwd, 'refs', message='Invalid NUL field count') + return rows + for i in range(0, len(fields), 6): + names = ['name', 'object', 'type', 'peeled_object', 'peeled_type', 'symbolic_target'] + row = dict(zip(names, map(_text, fields[i:i + 6]))) + row['name'] = row['name'].removeprefix('\n') + rows.append(row) + return rows + + +def _registered_worktrees(git, cwd, settings): + result = git.run(cwd, 'worktree', 'list', '--porcelain', '-z', settings=settings) + rows = [] + if result is None: + return rows + for block in result[1].split(b'\0\0'): + if not block: + continue + row = {} + for field in block.split(b'\0'): + if not field: + continue + key, _, value = field.partition(b' ') + row[_text(key)] = _text(value) if value else True + if 'worktree' not in row: + git.error('parse', cwd, 'worktree list', message='Missing worktree path') + else: + rows.append(row) + return rows + + +def _status(git, path, settings): + result = git.run(path, 'status', '--porcelain=v1', '-z', '--untracked-files=all', + '--ignore-submodules=none', settings=settings) + if result is None: + return None + fields = result[1].split(b'\0') + if fields[-1] == b'': + fields.pop() + rows = [] + i = 0 + while i < len(fields): + raw = fields[i] + i += 1 + if len(raw) < 4 or raw[2:3] != b' ': + git.error('parse', path, 'status', message='Invalid porcelain record') + return None + row = {'xy': _text(raw[:2]), 'path': _text(raw[3:])} + if b'R' in raw[:2] or b'C' in raw[:2]: + if i == len(fields): + git.error('parse', path, 'status', message='Missing rename origin') + return None + row['original_path'] = _text(fields[i]) + i += 1 + rows.append(row) + return rows + + +def _submodules(git, path, settings, bare, head): + result = git.run(path, *(['ls-tree', '-r', '-z', 'HEAD'] if bare else ['ls-files', '--stage', '-z']), + settings=settings) if not bare or head else (0, b'') + modules = {} + if result is not None: + for raw in result[1].split(b'\0'): + if not raw: + continue + header, separator, name = raw.partition(b'\t') + fields = header.split() + if not separator or len(fields) != 3: + git.error('parse', path, 'submodule index/tree', message='Invalid entry') + continue + if fields[0] == b'160000': + modules[_text(name)] = {'path': _text(name), 'object': _text(fields[2] if bare else fields[1]), + 'index_stage': None if bare else int(fields[2])} + source = ('--blob', 'HEAD:.gitmodules') if bare else ('--file', str(path / '.gitmodules')) + if (bare and modules) or (not bare and (path / '.gitmodules').exists()): + config = _config(git, path, r'^submodule\..*\.(path|url)$', source, settings) + for key, values in config.items(): + if key.endswith('.path'): + name = key[len('submodule.'):-len('.path')] + for module_path in values: + row = modules.setdefault(module_path, {'path': module_path, 'object': None, 'index_stage': None}) + row['name'] = name + row['urls'] = [_remote_url(url) for url in config.get('submodule.' + name + '.url', [])] + for row in modules.values(): + row['initialized'] = False if bare else os.path.lexists(path / row['path'] / '.git') + return sorted(modules.values(), key=lambda row: os.fsencode(row['path'])) + + +def inventory(root, *, git='git', command_timeout=10, total_timeout=1800, max_command_bytes=32 * 1024 * 1024): + reader = Git(git, command_timeout, total_timeout, max_command_bytes) + try: + root = Path(root).resolve() + except (OSError, RuntimeError) as exc: + reader.error('filesystem', root, 'resolve root', message=str(exc)) + root = Path(os.path.abspath(root)) + report = {'schema_version': 1, 'started_at': _now(), 'root': str(root), + 'purpose': 'Observed Git census only; not a clean-state or mathematical certification', + 'non_atomic_observations': True, 'complete': False, 'errors': reader.errors, + 'policy': {'walk_exclusions': ['Git metadata internals only; node_modules is searched'], + 'symlinks': 'Follow internal directory targets once by device/inode; record all links; external directory targets are uncovered/incomplete', + 'paths': 'NUL Git records; filesystem surrogateescape; JSON ensure_ascii=true', + 'read_only': 'Optional locks, hooks, filters, maintenance and lazy network fetch disabled; no Git mutation commands', + 'status': 'porcelain v1 -z --untracked-files=all; Git ignore rules still apply', + 'url_redaction': 'userinfo and known credential query values redacted'}, + 'limits': {'git_timeout_seconds': command_timeout, 'total_timeout_seconds': total_timeout, + 'max_command_bytes': max_command_bytes}, 'stores': [], 'worktrees': []} + roots, links, skipped, directory_count = _discover(root, reader) + report.update(discovered_roots=roots, symlinks=links, git_metadata_not_traversed=skipped, + directories_visited=directory_count, empty_discovery=not roots) + stores = {} + candidates = {} + for path in roots: + if reader.expired(): + reader.error('deadline', path, 'repository census') + break + common = reader.run(path, 'rev-parse', '--path-format=absolute', '--git-common-dir') + if common is None: + continue + common_path = str(Path(_line(common[1])).resolve()) + if common_path not in stores: + settings, remotes = _settings_and_remotes(reader, path) + bare = reader.run(common_path, 'rev-parse', '--is-bare-repository', settings=settings) + shallow = reader.run(common_path, 'rev-parse', '--is-shallow-repository', settings=settings) + refs = [ref for ref in _refs(reader, path, settings) + if not ref['name'].startswith(('refs/worktree/', 'refs/bisect/', 'refs/rewritten/'))] + registered = _registered_worktrees(reader, path, settings) + store = {'path': common_path, 'representative': path, 'refs': refs, 'remotes': remotes, + 'bare': None if bare is None else _line(bare[1]) == 'true', + 'shallow': None if shallow is None else _line(shallow[1]) == 'true', + 'registered_worktrees': registered, 'stashes': []} + if any(row['name'] == 'refs/stash' for row in refs): + stashes = reader.run(path, 'stash', 'list', '-z', '--format=%H%x00%gd', settings=settings) + if stashes is not None: + fields = stashes[1].split(b'\0') + if fields[-1] == b'': + fields.pop() + if len(fields) % 2: + reader.error('parse', path, 'stash list', message='Invalid NUL field count') + else: + store['stashes'] = [{'object': _text(fields[i]), 'selector': _text(fields[i + 1])} + for i in range(0, len(fields), 2)] + stores[common_path] = store, settings + for row in registered: + candidates[str(Path(row['worktree']).resolve())] = common_path + inside = reader.run(path, 'rev-parse', '--is-inside-work-tree') + if inside is not None and _line(inside[1]) == 'true': + candidates[path] = common_path + # Include worktree-specific config, then propagate safe filter/remote + # overrides through Git's own recursive submodule status subprocesses too. + per_worktree_settings = {} + per_worktree_remotes = {} + for path in sorted(candidates): + if reader.expired(): + reader.error('deadline', path, 'worktree configuration') + break + if Path(path).is_dir(): + per_worktree_settings[path], per_worktree_remotes[path] = _settings_and_remotes(reader, path) + all_settings = list(dict.fromkeys(setting for _, settings in stores.values() + for setting in settings)) + all_settings += list(dict.fromkeys(setting for settings in per_worktree_settings.values() + for setting in settings)) + for path, common in sorted(candidates.items()): + if reader.expired(): + reader.error('deadline', path, 'worktree census') + break + work = {'path': path, 'common_store': common, 'observed_at': _now(), + 'exists': Path(path).is_dir(), 'head': None, 'branch': None, + 'status': None, 'submodules': [], 'remotes': per_worktree_remotes.get(path, [])} + report['worktrees'].append(work) + if not work['exists']: + reader.error('missing_worktree', path, 'worktree census') + continue + settings = list(dict.fromkeys([*stores[common][1], *all_settings])) + bare = reader.run(path, 'rev-parse', '--is-bare-repository', settings=settings) + work['bare'] = None if bare is None else _line(bare[1]) == 'true' + git_dir = reader.run(path, 'rev-parse', '--path-format=absolute', '--git-dir', settings=settings) + work['git_dir'] = None if git_dir is None else _line(git_dir[1]) + head = reader.run(path, 'rev-parse', '--verify', '--quiet', 'HEAD', allowed=(0, 1), settings=settings) + branch = reader.run(path, 'symbolic-ref', '--quiet', 'HEAD', allowed=(0, 1), settings=settings) + work['head'] = _line(head[1]) if head and head[0] == 0 else None + work['branch'] = _line(branch[1]) if branch and branch[0] == 0 else None + work['detached'] = branch is not None and branch[0] == 1 + work['unborn'] = work['head'] is None and work['branch'] is not None + work['local_refs'] = _refs(reader, path, settings, + ('refs/worktree', 'refs/bisect', 'refs/rewritten')) + if head is not None and work['head'] is None and work['branch'] is None: + reader.error('unresolved_head', path, 'HEAD identity') + if work['bare'] is False: + work['status'] = _status(reader, Path(path), settings) + work['submodules'] = _submodules(reader, Path(path), settings, work['bare'], work['head']) + final_head = reader.run(path, 'rev-parse', '--verify', '--quiet', 'HEAD', allowed=(0, 1), settings=settings) + if head is not None and final_head is not None and head != final_head: + reader.error('changed_during_observation', path, 'HEAD identity') + report['stores'] = [stores[path][0] for path in sorted(stores)] + report.update(finished_at=_now(), git_commands=reader.commands, complete=not reader.errors) + return _redact(report) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--root', type=Path, default=Path('/workspace')) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--git', default='git') + parser.add_argument('--command-timeout', type=float, default=10) + parser.add_argument('--total-timeout', type=float, default=1800) + parser.add_argument('--max-command-bytes', type=int, default=32 * 1024 * 1024) + args = parser.parse_args() + if (not math.isfinite(args.command_timeout) or not math.isfinite(args.total_timeout) or + args.command_timeout <= 0 or args.total_timeout <= 0 or args.max_command_bytes <= 0): + parser.error('All resource limits must be positive and finite') + report = inventory(args.root, git=args.git, command_timeout=args.command_timeout, + total_timeout=args.total_timeout, max_command_bytes=args.max_command_bytes) + descriptor = os.open(args.output, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600) + with os.fdopen(descriptor, 'w', encoding='utf-8') as output: + os.fchmod(output.fileno(), 0o600) + json.dump(report, output, ensure_ascii=True, indent=2) + output.write('\n') + print(json.dumps({'output': str(args.output), 'complete': report['complete'], + 'stores': len(report['stores']), 'worktrees': len(report['worktrees']), + 'errors': len(report['errors'])})) + return 0 if report['complete'] else 1 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/tools/workspace_git_inventory_mutations.py b/tools/workspace_git_inventory_mutations.py new file mode 100644 index 000000000..48b14f7ca --- /dev/null +++ b/tools/workspace_git_inventory_mutations.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 +"""Verify the Git census baseline and four adverse mutations, not Git cleanliness. + +Requires a NEW --output directory. Retains private logs, hashes and results there; +mutant sources exist only in an owned temporary directory. Uses Python stdlib. +""" +from __future__ import annotations + +import argparse +import datetime +import hashlib +import json +import os +from pathlib import Path +import signal +import subprocess +import sys +import tempfile + + +CASES = [ + ('exclude-node-modules', "if entry.name == '.git':", "if entry.name in ('.git', 'node_modules'):", + 'test_nested_linked_state_refs_stash_and_redacted_remotes'), + ('disable-redaction', 'def _redact(value):\n', 'def _redact(value):\n return value\n', + 'test_nested_linked_state_refs_stash_and_redacted_remotes'), + ('execute-clean-filter', "settings += [prefix + '.clean=', prefix + '.process=', prefix + '.required=false']", + 'settings += []', 'test_status_does_not_execute_configured_clean_filter'), + ('false-complete', 'complete=not reader.errors', 'complete=True', + 'test_broken_marker_and_external_directory_boundary_are_not_silent'), +] + +DRIVER = r''' +import importlib.util, json, os, pathlib, sys, unittest +test, tool, result, name = sys.argv[1:] +spec = importlib.util.spec_from_file_location('census_tests', test) +module = importlib.util.module_from_spec(spec) +spec.loader.exec_module(module) +module.TOOL = pathlib.Path(tool) +suite = (unittest.defaultTestLoader.loadTestsFromName('InventoryTests.' + name, module) + if name else unittest.defaultTestLoader.loadTestsFromModule(module)) +run = unittest.TextTestRunner(verbosity=2).run(suite) +summary = {'tests_run': run.testsRun, 'successful': run.wasSuccessful(), + 'failures': len(run.failures), 'errors': len(run.errors), + 'skipped': len(run.skipped), 'expected_failures': len(run.expectedFailures), + 'unexpected_successes': len(run.unexpectedSuccesses)} +with os.fdopen(os.open(result, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), 'w') as output: + json.dump(summary, output) +raise SystemExit(0 if run.wasSuccessful() else 1) +''' + + +def _now(): + return datetime.datetime.now(datetime.timezone.utc).isoformat() + + +def _sha(raw): + return hashlib.sha256(raw).hexdigest() + + +def _write_json(path, value): + with os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), + 'w', encoding='utf-8') as output: + json.dump(value, output, ensure_ascii=True, indent=2) + output.write('\n') + + +def _trial(test, tool, output, label, name='', timeout=20): + metrics = output / (label + '.json') + log = output / (label + '.log') + row = {'test': name or 'entire suite', 'log': log.name, 'metrics': metrics.name, + 'timeout_seconds': timeout} + with os.fdopen(os.open(log, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), 'wb') as stream: + child = subprocess.Popen([sys.executable, '-S', '-B', '-c', DRIVER, + str(test), str(tool), str(metrics), name], + stdout=stream, stderr=subprocess.STDOUT, start_new_session=True) + try: + row['returncode'] = child.wait(timeout=timeout) + except subprocess.TimeoutExpired: + os.killpg(child.pid, signal.SIGKILL) + child.wait() + row.update(returncode=child.returncode, error='timeout') + if 'error' not in row: + try: + row.update(json.loads(metrics.read_bytes())) + except (OSError, ValueError) as exc: + row['error'] = 'Missing/invalid test metrics: ' + str(exc) + return row + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--output', required=True, type=Path, help='New private evidence directory') + args = parser.parse_args() + output = args.output.absolute() + try: + output.mkdir(mode=0o700) + output.chmod(0o700) + except OSError as exc: + parser.error('Cannot exclusively create output directory: ' + str(exc)) + os.umask(0o077) + root = Path(__file__).resolve().parents[1] + tool = root / 'tools/workspace_git_inventory.py' + test = root / 'tests/test_workspace_git_inventory.py' + report = {'schema_version': 1, 'purpose': 'Git census self-tests only; no mathematical certification or Git cleanliness claim', + 'started_at': _now(), 'python': sys.version, 'python_executable': sys.executable, + 'sources': {}, 'baseline': {}, 'mutations': [], 'errors': [], + 'complete': False, 'all_detected': False} + try: + original = tool.read_bytes() + for label, path in [('collector', tool), ('tests', test), ('runner', Path(__file__).resolve())]: + raw = path.read_bytes() + report['sources'][label] = {'path': str(path), 'sha256': _sha(raw), 'bytes': len(raw)} + baseline = _trial(test, tool, output, 'baseline', timeout=60) + baseline['passed'] = (baseline.get('returncode') == 0 and baseline.get('tests_run') == 11 and + baseline.get('successful') is True and + all(baseline.get(key) == 0 for key in + ('failures', 'errors', 'skipped', 'expected_failures', 'unexpected_successes'))) + report['baseline'] = baseline + if baseline['passed']: + text = original.decode('utf-8') + with tempfile.TemporaryDirectory(prefix='workspace-git-inventory-mutations-') as temporary: + for name, old, new, selected in CASES: + if text.count(old) != 1: + raise ValueError('Mutation target is not unique: ' + name) + mutant = Path(temporary) / (name + '.py') + raw = text.replace(old, new).encode('utf-8') + mutant.write_bytes(raw) + row = _trial(test, mutant, output, name, selected) + row.update(mutation=name, source_sha256=_sha(original), mutant_sha256=_sha(raw), + replacement={'old': old, 'new': new}) + row['detected_by_assertion'] = ( + row.get('returncode') == 1 and row.get('tests_run') == 1 and + row.get('failures') == 1 and row.get('successful') is False and + all(row.get(key) == 0 for key in + ('errors', 'skipped', 'expected_failures', 'unexpected_successes')) and 'error' not in row) + report['mutations'].append(row) + else: + report['errors'].append('Baseline did not pass all 11 tests without skips/errors; no mutations run') + for label, source in report['sources'].items(): + if _sha(Path(source['path']).read_bytes()) != source['sha256']: + report['errors'].append('Source changed during verification: ' + label) + report['all_detected'] = (len(report['mutations']) == 4 and + all(row['detected_by_assertion'] for row in report['mutations'])) + report['complete'] = bool(baseline['passed'] and report['all_detected'] and not report['errors']) + except Exception as exc: + report['errors'].append(type(exc).__name__ + ': ' + str(exc)) + report['finished_at'] = _now() + _write_json(output / 'results.json', report) + print(json.dumps({'output': str(output), 'baseline_passed': report['baseline'].get('passed', False), + 'mutations': len(report['mutations']), 'all_detected': report['all_detected'], + 'complete': report['complete']})) + return 0 if report['complete'] else 1 + + +if __name__ == '__main__': + raise SystemExit(main())