claude-dev-env 2.9.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +2 -2
- package/_shared/advisor/CLAUDE.md +3 -2
- package/_shared/advisor/advisor-protocol.md +74 -108
- package/_shared/advisor/reference/advisor-block.md +37 -0
- package/_shared/advisor/reference/cli-chain.md +45 -0
- package/_shared/advisor/reference/consult-format.md +41 -0
- package/_shared/advisor/reference/lifecycle.md +21 -0
- package/_shared/advisor/reference/sol-rung.md +31 -0
- package/_shared/advisor/reference/spawn-walk-log.md +31 -0
- package/_shared/advisor/reference/third-party-bind.md +30 -0
- package/_shared/advisor/reference/warm-up.md +33 -0
- package/_shared/advisor/scripts/codex_sol_advisor.py +449 -0
- package/_shared/advisor/scripts/config/advisor_scripts_constants/advisor_route_constants.py +21 -0
- package/_shared/advisor/scripts/config/advisor_scripts_constants/model_tier_run_validator_constants.py +19 -17
- package/_shared/advisor/scripts/config/advisor_scripts_constants/sol_advisor_constants.py +28 -0
- package/_shared/advisor/scripts/model_tier_run_validator.py +32 -9
- package/_shared/advisor/scripts/tests/test_codex_sol_advisor.py +474 -0
- package/_shared/advisor/scripts/tests/test_model_tier_run_validator.py +79 -0
- package/_shared/advisor/scripts/tests/test_tier_model_ids.py +39 -17
- package/_shared/advisor/scripts/tier_model_ids.py +24 -0
- package/_shared/pr-loop/CLAUDE.md +1 -1
- package/_shared/pr-loop/audit-contract.md +17 -6
- package/_shared/pr-loop/audit-reply-template.md +4 -4
- package/_shared/pr-loop/code-rules-gate.md +3 -5
- package/_shared/pr-loop/fix-protocol.md +2 -3
- package/_shared/pr-loop/gh-payloads.md +1 -1
- package/_shared/pr-loop/scripts/CLAUDE.md +1 -1
- package/_shared/pr-loop/scripts/README.md +1 -1
- package/_shared/pr-loop/scripts/code_rules_gate.py +2 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/gate_running.py +16 -1
- package/_shared/pr-loop/scripts/code_rules_gate_parts/git_blob_readers.py +11 -5
- package/_shared/pr-loop/scripts/preflight.py +9 -4
- package/_shared/pr-loop/scripts/reviews_disabled.py +50 -22
- package/_shared/pr-loop/scripts/tests/conftest.py +20 -0
- package/_shared/pr-loop/scripts/tests/test_claude_permissions_common.py +6 -6
- package/_shared/pr-loop/scripts/tests/test_reviews_disabled.py +50 -6
- package/_shared/pr-loop/scripts/tests/test_revoke_project_claude_permissions.py +1 -1
- package/_shared/pr-loop/state-schema.md +5 -14
- package/agents/CLAUDE.md +2 -2
- package/agents/clean-coder.md +58 -548
- package/agents/code-quality-agent.md +10 -2
- package/agents/code-verifier.md +1 -1
- package/agents/test_agent_frontmatter.py +32 -40
- package/audit-rubrics/CLAUDE.md +2 -1
- package/audit-rubrics/audit-categories.json +704 -0
- package/audit-rubrics/prompts/category-i-concurrency.md +1 -1
- package/bin/CLAUDE.md +16 -5
- package/bin/ever-shipped-skills.mjs +2 -0
- package/bin/install-plan.mjs +402 -0
- package/bin/install-transaction.mjs +455 -0
- package/bin/install.mjs +593 -147
- package/bin/install.plan.test.mjs +194 -0
- package/bin/install.profile-root.test.mjs +154 -0
- package/bin/install.profiles.test.mjs +253 -0
- package/bin/install.settings-defaults.test.mjs +200 -0
- package/bin/install.transaction.test.mjs +400 -0
- package/bin/install.uninstall-transaction.test.mjs +418 -0
- package/bin/merge_managed_permissions.mjs +130 -0
- package/bin/resolve-install-root.mjs +181 -0
- package/bin/select-install-targets.mjs +401 -0
- package/commands/CLAUDE.md +0 -2
- package/docs/references/CLAUDE.md +3 -1
- package/docs/references/advisor-tool.md +25 -7
- package/docs/references/prose-style-enforcement.md +25 -0
- package/docs/references/team-advisor-skill.md +3 -3
- package/docs/references/weak-executor-advisor.md +91 -0
- package/hooks/blocking/CLAUDE.md +6 -6
- package/hooks/blocking/_path_setup.py +9 -5
- package/hooks/blocking/code_rules_docstrings.py +124 -30
- package/hooks/blocking/code_rules_enforcer.py +161 -16
- package/hooks/blocking/code_rules_shared.py +40 -23
- package/hooks/blocking/config/CLAUDE.md +3 -5
- package/hooks/blocking/config/prose_style_enforcement_constants.py +38 -0
- package/hooks/blocking/config/test_prose_style_enforcement_constants.py +45 -0
- package/hooks/blocking/eli11_reply_enforcer.py +70 -113
- package/hooks/blocking/hedging_language_blocker.py +103 -20
- package/hooks/blocking/hook_prose_detector_consistency.py +6 -0
- package/hooks/blocking/intent_only_ending_blocker.py +6 -0
- package/hooks/blocking/plain_language_blocker.py +139 -20
- package/hooks/blocking/pre_tool_use_dispatcher.py +102 -20
- package/hooks/blocking/state_description_blocker.py +7 -1
- package/hooks/blocking/tdd_enforcer.py +8 -0
- package/hooks/blocking/test__path_setup.py +28 -0
- package/hooks/blocking/test_code_rules_enforcer_agent_home_tooling.py +99 -0
- package/hooks/blocking/test_code_rules_enforcer_docstring_args_span_scope.py +232 -10
- package/hooks/blocking/test_code_rules_enforcer_ephemeral.py +1 -1
- package/hooks/blocking/test_code_rules_enforcer_join_separator_magic.py +41 -0
- package/hooks/blocking/test_code_rules_enforcer_string_magic.py +98 -0
- package/hooks/blocking/test_eli11_reply_enforcer.py +98 -165
- package/hooks/blocking/test_fable_spawn_gate.py +18 -11
- package/hooks/blocking/test_hedging_language_blocker.py +120 -1
- package/hooks/blocking/test_hook_prose_detector_consistency.py +28 -8
- package/hooks/blocking/test_intent_only_ending_blocker.py +27 -2
- package/hooks/blocking/test_package_inventory_stale_blocker.py +11 -4
- package/hooks/blocking/test_plain_language_blocker.py +129 -19
- package/hooks/blocking/test_plain_language_blocker_allowlist.py +70 -26
- package/hooks/blocking/test_pre_tool_use_dispatcher.py +99 -26
- package/hooks/blocking/test_pre_tool_use_dispatcher_native.py +87 -50
- package/hooks/blocking/test_state_description_blocker.py +45 -2
- package/hooks/blocking/test_stop_dispatcher.py +11 -7
- package/hooks/blocking/test_volatile_path_in_post_blocker.py +12 -12
- package/hooks/blocking/volatile_path_in_post_blocker.py +2 -2
- package/hooks/hooks.json +15 -0
- package/hooks/hooks_constants/CLAUDE.md +14 -3
- package/hooks/hooks_constants/ask_user_question_shape.py +281 -0
- package/hooks/hooks_constants/code_rules_enforcer_constants.py +2 -1
- package/hooks/hooks_constants/eli11_reply_enforcer_constants.py +5 -12
- package/hooks/hooks_constants/hedging_uncertainty_constants.py +42 -0
- package/hooks/hooks_constants/issue_tracker_session_starter_constants.py +23 -0
- package/hooks/hooks_constants/orchestrator_auto_starter_constants.py +23 -0
- package/hooks/hooks_constants/piped_pytest_blocker_constants.py +4 -1
- package/hooks/hooks_constants/plain_language_blocker_constants.py +4 -1
- package/hooks/hooks_constants/pre_tool_use_dispatcher_constants.py +6 -0
- package/hooks/hooks_constants/project_paths_reader.py +31 -4
- package/hooks/hooks_constants/prose_matcher_precision_constants.py +40 -0
- package/hooks/hooks_constants/pytest_invocation.py +354 -0
- package/hooks/hooks_constants/session_start_injector.py +163 -0
- package/hooks/hooks_constants/session_start_injector_constants.py +46 -0
- package/hooks/hooks_constants/shell_command_pipeline.py +397 -0
- package/hooks/hooks_constants/shell_command_segments.py +5 -0
- package/hooks/hooks_constants/test_ask_user_question_shape.py +167 -0
- package/hooks/hooks_constants/test_project_paths_reader.py +29 -0
- package/hooks/hooks_constants/test_prose_metrics_parity.py +8 -0
- package/hooks/hooks_constants/test_pytest_invocation.py +130 -0
- package/hooks/hooks_constants/test_session_start_injector.py +168 -0
- package/hooks/hooks_constants/test_shell_command_pipeline.py +135 -0
- package/hooks/hooks_constants/volatile_path_in_post_blocker_constants.py +1 -1
- package/hooks/hooks_constants/working_style_prompt_constants.py +30 -0
- package/hooks/observability/CLAUDE.md +2 -0
- package/hooks/observability/prose_matcher_advisory.py +237 -0
- package/hooks/observability/test_prose_matcher_advisory.py +143 -0
- package/hooks/session/CLAUDE.md +9 -1
- package/hooks/session/_path_setup.py +13 -0
- package/hooks/session/issue_tracker_session_starter.py +135 -0
- package/hooks/session/orchestrator_auto_starter.py +100 -0
- package/hooks/session/test__path_setup.py +28 -0
- package/hooks/session/test_issue_tracker_session_starter.py +104 -0
- package/hooks/session/test_orchestrator_auto_starter.py +99 -0
- package/hooks/session/test_working_style_prompt.py +47 -0
- package/hooks/session/untracked_repo_detector.py +1 -24
- package/hooks/session/working_style_prompt.py +36 -0
- package/hooks/validators/_path_setup.py +19 -0
- package/hooks/validators/run_all_validators.py +8 -13
- package/installable-surfaces.manifest.json +21 -0
- package/output-styles/CLAUDE.md +1 -3
- package/package.json +4 -2
- package/rules/CLAUDE.md +1 -0
- package/rules/durable-post-artifacts.md +2 -2
- package/rules/eli11-replies.md +6 -1
- package/rules/hedging-claims.md +4 -2
- package/rules/long-horizon-autonomy.md +3 -1
- package/rules/opus5-communication-contract.md +45 -0
- package/rules/plain-language.md +2 -2
- package/rules/research-mode.md +1 -1
- package/scripts/CLAUDE.md +11 -0
- package/scripts/Sync-RepoMain.ps1 +215 -0
- package/scripts/active_capability_references.py +218 -0
- package/scripts/ci/windows-installer-lifecycle.ps1 +78 -0
- package/scripts/claude_chain_runner.py +394 -6
- package/scripts/claude_chain_usage.py +1 -1
- package/scripts/codex_compat_materializer.py +105 -85
- package/scripts/dev_env_scripts_constants/CLAUDE.md +2 -0
- package/scripts/dev_env_scripts_constants/active_capability_constants.py +46 -0
- package/scripts/dev_env_scripts_constants/claude_chain_constants.py +74 -0
- package/scripts/dev_env_scripts_constants/verify_installable_package_constants.py +116 -0
- package/scripts/profile-isolation-launchers/config/mcp-bundles.json +25 -0
- package/scripts/profile-isolation-launchers/config/profile-isolation-constants.mjs +60 -0
- package/scripts/profile-isolation-launchers/config/profiles.manifest.json +54 -0
- package/scripts/profile-isolation-launchers/config/shared-allowlist.json +64 -0
- package/scripts/profile-isolation-launchers/launcher-runtime.mjs +180 -0
- package/scripts/profile-isolation-launchers/lib/profile-manifest.mjs +288 -0
- package/scripts/profile-isolation-launchers/mcp-bundles.mjs +275 -0
- package/scripts/profile-isolation-launchers/profile-isolation-contract.test.mjs +221 -0
- package/scripts/profile-isolation-launchers/tests/launcher-runtime.test.mjs +108 -0
- package/scripts/profile-isolation-launchers/tests/mcp-bundles.test.mjs +147 -0
- package/scripts/profile-isolation-launchers/tests/shortcut-contract.test.ps1 +102 -0
- package/scripts/profile-isolation-launchers/tests/version-compatibility.test.mjs +210 -0
- package/scripts/profile-isolation-launchers/version-compatibility.mjs +299 -0
- package/scripts/profile-isolation-launchers/windows/shortcut-inventory.ps1 +127 -0
- package/scripts/profile-isolation-launchers/windows/shortcut-manifest.json +51 -0
- package/scripts/profile-isolation-launchers/windows/shortcut-reconcile.ps1 +77 -0
- package/scripts/spawn_grok_batch.py +3 -0
- package/scripts/test_active_capability_references.py +108 -0
- package/scripts/test_claude_chain_runner.py +414 -82
- package/scripts/test_claude_chain_usage.py +12 -12
- package/scripts/test_resolve_worker_spawn.py +2 -2
- package/scripts/test_verify_installable_package.py +208 -0
- package/scripts/tests/test_codex_compat_materializer.py +33 -0
- package/scripts/verify_installable_package.py +612 -0
- package/settings.json +10 -0
- package/skills/CLAUDE.md +2 -0
- package/skills/_shared/advisor/CLAUDE.md +1 -1
- package/skills/_shared/advisor/scripts/README.md +2 -0
- package/skills/_shared/pr-loop/scripts/CLAUDE.md +1 -0
- package/skills/_shared/pr-loop/scripts/audit_category_schema.py +355 -0
- package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/CLAUDE.md +1 -0
- package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/audit_category_schema_constants.py +32 -0
- package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/path_resolver_constants.py +7 -19
- package/skills/_shared/pr-loop/scripts/test_audit_category_schema.py +94 -0
- package/skills/_shared/pr-loop/scripts/test_build_audit_prompt.py +21 -0
- package/skills/autoconverge/reference/convergence.md +2 -1
- package/skills/autoconverge/reference/stop-conditions.md +5 -3
- package/skills/beat-sheet/SKILL.md +54 -0
- package/skills/beat-sheet/reference/visual-beats.md +29 -0
- package/skills/bugteam/CONSTRAINTS.md +4 -4
- package/skills/bugteam/EXAMPLES.md +1 -1
- package/skills/bugteam/reference/README.md +1 -1
- package/skills/e-code-review/SKILL.md +26 -5
- package/skills/e-code-review/reference/effort-evaluation.md +35 -0
- package/skills/e-code-review/reference/medium.md +15 -4
- package/skills/e-code-review/scripts/config/e_code_review_effort_constants/__init__.py +41 -0
- package/skills/e-code-review/scripts/config/e_code_review_effort_constants/effort_constants.py +40 -0
- package/skills/e-code-review/scripts/e_code_review_scripts_constants/finding_pipeline_constants.py +49 -0
- package/skills/e-code-review/scripts/effort_defaults_evidence.json +186 -0
- package/skills/e-code-review/scripts/effort_evaluation.py +362 -0
- package/skills/e-code-review/scripts/finding_pipeline.py +140 -0
- package/skills/e-code-review/scripts/fixtures/demanding.json +26 -0
- package/skills/e-code-review/scripts/fixtures/easy.json +14 -0
- package/skills/e-code-review/scripts/fixtures/medium.json +20 -0
- package/skills/e-code-review/scripts/grok_code_review.py +16 -7
- package/skills/e-code-review/scripts/test_effort_evaluation.py +180 -0
- package/skills/e-code-review/scripts/test_finding_pipeline.py +197 -0
- package/skills/e-code-review/scripts/test_grok_code_review.py +77 -0
- package/skills/grokify/SKILL.md +1 -1
- package/skills/grokify/templates/handoff-template.md +2 -2
- package/skills/orchestrator/SKILL.md +5 -4
- package/skills/plan-to-pr/scripts/create_packet.py +4 -4
- package/skills/plan-to-pr/scripts/load_skill_constants.py +41 -0
- package/skills/plan-to-pr/scripts/validate_packet.py +4 -4
- package/skills/plan-to-pr/scripts/validate_protocol.py +4 -1
- package/skills/plan-to-pr/scripts/validate_run.py +4 -1
- package/skills/pr-converge/scripts/check_convergence.py +21 -19
- package/skills/pr-converge/scripts/check_convergence_availability.py +50 -7
- package/skills/pr-converge/scripts/conftest.py +35 -0
- package/skills/pr-converge/scripts/test_check_convergence_availability.py +65 -0
- package/skills/pr-converge/scripts/test_check_convergence_codex.py +11 -1
- package/skills/pr-converge/scripts/test_check_convergence_contract.py +9 -2
- package/skills/pr-loop-cloud-transport/SKILL.md +1 -1
- package/skills/rebase/SKILL.md +15 -3
- package/skills/reviewer-gates/SKILL.md +2 -2
- package/skills/show/SKILL.md +51 -0
- package/skills/show/references/accessibility.md +7 -0
- package/skills/show/references/art.md +3 -0
- package/skills/show/references/charts.md +3 -0
- package/skills/show/references/core-design.md +14 -0
- package/skills/show/references/erds.md +3 -0
- package/skills/show/references/flowcharts.md +3 -0
- package/skills/show/references/host-and-html.md +3 -0
- package/skills/show/references/illustrative-diagrams.md +10 -0
- package/skills/show/references/interaction.md +3 -0
- package/skills/show/references/mockups.md +3 -0
- package/skills/show/references/quality-gates.md +7 -0
- package/skills/show/references/structural-diagrams.md +3 -0
- package/skills/show/references/subject-inventory.md +21 -0
- package/skills/show/references/svg-contract.md +22 -0
- package/skills/show/routing.yaml +30 -0
- package/skills/show/samples/pr1262-v2.svg +222 -0
- package/skills/show/scripts/README.md +6 -0
- package/skills/show/scripts/validate-artifact.py +91 -0
- package/skills/show/scripts/validate-package.py +18 -0
- package/skills/show/templates/html-widget.html +4 -0
- package/skills/show/templates/svg-base.svg +19 -0
- package/skills/show/tests/fixtures/css-var.svg +6 -0
- package/skills/show/tests/fixtures/dead-ref.svg +7 -0
- package/skills/show/tests/fixtures/filled-glyph.svg +8 -0
- package/skills/show/tests/fixtures/inherited-fill.svg +18 -0
- package/skills/show/tests/fixtures/invalid.svg +1 -0
- package/skills/show/tests/fixtures/large-canvas.svg +21 -0
- package/skills/show/tests/fixtures/unfilled-connector.svg +15 -0
- package/skills/show/tests/fixtures/valid.html +1 -0
- package/skills/show/tests/test_validate-artifact.py +74 -0
- package/skills/show/tests/test_validators.py +59 -0
- package/skills/show/workflows/create-visual.md +13 -0
- package/skills/show/workflows/review-visual.md +20 -0
- package/skills/split-pr/SKILL.md +85 -0
- package/skills/split-pr/reference/path-layers.md +16 -0
- package/skills/split-pr/reference/proposal-format.md +15 -0
- package/skills/split-pr/reference/split-further-loop.md +10 -0
- package/skills/split-pr/reference/splitting-principles.md +26 -0
- package/skills/split-pr/scripts/analyze_pr.py +279 -0
- package/skills/split-pr/scripts/categorize_files.py +106 -0
- package/skills/split-pr/scripts/config/__init__.py +1 -0
- package/skills/split-pr/scripts/config/dependency_constants.py +14 -0
- package/skills/split-pr/scripts/config/git_operations_constants.py +36 -0
- package/skills/split-pr/scripts/config/packing_constants.py +61 -0
- package/skills/split-pr/scripts/config/plan_constants.py +49 -0
- package/skills/split-pr/scripts/config/split_pr_constants.py +110 -0
- package/skills/split-pr/scripts/execute_split_slices.py +82 -0
- package/skills/split-pr/scripts/pack_files_into_slices.py +212 -0
- package/skills/split-pr/scripts/split_pr_dependency_graph.py +70 -0
- package/skills/split-pr/scripts/split_pr_git_operations.py +184 -0
- package/skills/split-pr/scripts/split_pr_layer_order.py +58 -0
- package/skills/split-pr/scripts/split_pr_paginate.py +119 -0
- package/skills/split-pr/scripts/split_pr_process_runner.py +52 -0
- package/skills/split-pr/scripts/split_pr_script_types.py +126 -0
- package/skills/split-pr/scripts/split_pr_title.py +41 -0
- package/skills/split-pr/scripts/test_analyze_pr.py +228 -0
- package/skills/split-pr/scripts/test_categorize_files.py +55 -0
- package/skills/split-pr/scripts/test_categorize_files_packing.py +59 -0
- package/skills/split-pr/scripts/test_execute_split_slices.py +99 -0
- package/skills/split-pr/scripts/test_split_pr_dependency_graph.py +47 -0
- package/skills/split-pr/scripts/test_split_pr_git_operations.py +125 -0
- package/skills/split-pr/scripts/test_split_pr_layer_order.py +36 -0
- package/skills/split-pr/scripts/test_split_pr_paginate.py +65 -0
- package/skills/split-pr/scripts/test_split_pr_script_types.py +73 -0
- package/skills/split-pr/scripts/test_split_pr_title.py +28 -0
- package/skills/split-pr/scripts/test_verify_dependency_graph.py +46 -0
- package/skills/split-pr/scripts/test_verify_plan.py +56 -0
- package/skills/split-pr/scripts/test_verify_plan_contract.py +50 -0
- package/skills/split-pr/scripts/test_verify_plan_path_normalization.py +45 -0
- package/skills/split-pr/scripts/verify_dependency_graph.py +111 -0
- package/skills/split-pr/scripts/verify_plan.py +139 -0
- package/skills/team-advisor/SKILL.md +7 -4
- package/skills/team-advisor/reference/advisor-docs-review.md +207 -0
- package/system-prompts/software-engineer.xml +11 -2
- package/commands/initialize.md +0 -90
- package/commands/stubcheck.md +0 -88
- package/output-styles/caveman-agent.md +0 -37
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Managed permission defaults: pack inclusion, install merge, idempotence, uninstall.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import { strict as assert } from 'node:assert';
|
|
7
|
+
import {
|
|
8
|
+
mkdtempSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
readFileSync,
|
|
12
|
+
existsSync,
|
|
13
|
+
} from 'node:fs';
|
|
14
|
+
import { tmpdir } from 'node:os';
|
|
15
|
+
import { join, dirname } from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { spawnSync } from 'node:child_process';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
managedDenyEntriesFromPackageSettings,
|
|
21
|
+
mergeManagedPermissionsIntoSettings,
|
|
22
|
+
pruneManagedPermissionsFromSettings,
|
|
23
|
+
} from './merge_managed_permissions.mjs';
|
|
24
|
+
|
|
25
|
+
const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
26
|
+
const PACKAGE_SETTINGS_PATH = join(PACKAGE_ROOT, 'settings.json');
|
|
27
|
+
const INSTALL_ENTRY = join(PACKAGE_ROOT, 'bin', 'install.mjs');
|
|
28
|
+
|
|
29
|
+
const EXPECTED_DENY_ENTRIES = [
|
|
30
|
+
'Edit($HOME/.claude/verification/**)',
|
|
31
|
+
'Write($HOME/.claude/code-review-stamps/**)',
|
|
32
|
+
'Edit($HOME/.claude/code-review-stamps/**)',
|
|
33
|
+
'MultiEdit($HOME/.claude/code-review-stamps/**)',
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
function packageDenyEntries() {
|
|
37
|
+
const packageSettings = JSON.parse(readFileSync(PACKAGE_SETTINGS_PATH, 'utf8'));
|
|
38
|
+
return managedDenyEntriesFromPackageSettings(packageSettings);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function runInstallerInSandbox(sandboxHome, installerArguments = []) {
|
|
42
|
+
const gitConfigGlobal = join(sandboxHome, '.gitconfig-sandbox');
|
|
43
|
+
writeFileSync(gitConfigGlobal, '[safe]\n\tdirectory = *\n');
|
|
44
|
+
return spawnSync(process.execPath, [INSTALL_ENTRY, ...installerArguments], {
|
|
45
|
+
cwd: PACKAGE_ROOT,
|
|
46
|
+
encoding: 'utf8',
|
|
47
|
+
env: {
|
|
48
|
+
...process.env,
|
|
49
|
+
HOME: sandboxHome,
|
|
50
|
+
USERPROFILE: sandboxHome,
|
|
51
|
+
GIT_CONFIG_GLOBAL: gitConfigGlobal,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
test('package settings.json publishes exactly the four managed deny entries', () => {
|
|
57
|
+
const denyEntries = packageDenyEntries();
|
|
58
|
+
assert.equal(denyEntries.length, 4);
|
|
59
|
+
assert.deepEqual(denyEntries, EXPECTED_DENY_ENTRIES);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('an array-valued permissions field is replaced so managed denies survive a round trip', () => {
|
|
63
|
+
const targetSettings = { permissions: [] };
|
|
64
|
+
const result = mergeManagedPermissionsIntoSettings(targetSettings, EXPECTED_DENY_ENTRIES);
|
|
65
|
+
assert.equal(result.addedCount, EXPECTED_DENY_ENTRIES.length);
|
|
66
|
+
assert.equal(Array.isArray(targetSettings.permissions), false);
|
|
67
|
+
const roundTripped = JSON.parse(JSON.stringify(targetSettings));
|
|
68
|
+
assert.deepEqual(roundTripped.permissions.deny, EXPECTED_DENY_ENTRIES);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('npm pack includes package settings.json in the published artifact', () => {
|
|
72
|
+
const packResult = spawnSync('npm', ['pack', '--dry-run', '--json'], {
|
|
73
|
+
cwd: PACKAGE_ROOT,
|
|
74
|
+
encoding: 'utf8',
|
|
75
|
+
shell: process.platform === 'win32',
|
|
76
|
+
});
|
|
77
|
+
assert.equal(packResult.status, 0, packResult.stderr || packResult.stdout);
|
|
78
|
+
const packPayload = JSON.parse(packResult.stdout);
|
|
79
|
+
const files = Array.isArray(packPayload)
|
|
80
|
+
? packPayload[0]?.files ?? []
|
|
81
|
+
: packPayload.files ?? [];
|
|
82
|
+
const paths = files.map((eachFile) => (
|
|
83
|
+
typeof eachFile === 'string' ? eachFile : eachFile.path
|
|
84
|
+
));
|
|
85
|
+
assert.ok(
|
|
86
|
+
paths.some((eachPath) => eachPath === 'settings.json' || eachPath.endsWith('/settings.json')),
|
|
87
|
+
`settings.json missing from pack files: ${paths.filter((p) => String(p).includes('settings')).join(', ') || 'none'}`,
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('mergeManagedPermissionsIntoSettings adds each package deny exactly once', () => {
|
|
92
|
+
const target = {
|
|
93
|
+
permissions: {
|
|
94
|
+
allow: ['Bash(git status)'],
|
|
95
|
+
deny: ['Bash(rm -rf /)'],
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
const first = mergeManagedPermissionsIntoSettings(target, EXPECTED_DENY_ENTRIES);
|
|
99
|
+
assert.equal(first.addedCount, 4);
|
|
100
|
+
assert.equal(first.alreadyPresentCount, 0);
|
|
101
|
+
assert.equal(target.permissions.deny.filter((each) => EXPECTED_DENY_ENTRIES.includes(each)).length, 4);
|
|
102
|
+
assert.ok(target.permissions.deny.includes('Bash(rm -rf /)'));
|
|
103
|
+
assert.deepEqual(target.permissions.allow, ['Bash(git status)']);
|
|
104
|
+
|
|
105
|
+
const second = mergeManagedPermissionsIntoSettings(target, EXPECTED_DENY_ENTRIES);
|
|
106
|
+
assert.equal(second.addedCount, 0);
|
|
107
|
+
assert.equal(second.alreadyPresentCount, 4);
|
|
108
|
+
assert.equal(
|
|
109
|
+
target.permissions.deny.filter((each) => each === EXPECTED_DENY_ENTRIES[0]).length,
|
|
110
|
+
1,
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('pruneManagedPermissionsFromSettings removes only package-owned deny entries', () => {
|
|
115
|
+
const target = {
|
|
116
|
+
permissions: {
|
|
117
|
+
allow: ['Bash(git status)'],
|
|
118
|
+
ask: ['Edit(./**)'],
|
|
119
|
+
deny: [
|
|
120
|
+
'Bash(rm -rf /)',
|
|
121
|
+
...EXPECTED_DENY_ENTRIES,
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const outcome = pruneManagedPermissionsFromSettings(target, EXPECTED_DENY_ENTRIES);
|
|
126
|
+
assert.equal(outcome.removedCount, 4);
|
|
127
|
+
assert.deepEqual(target.permissions.deny, ['Bash(rm -rf /)']);
|
|
128
|
+
assert.deepEqual(target.permissions.allow, ['Bash(git status)']);
|
|
129
|
+
assert.deepEqual(target.permissions.ask, ['Edit(./**)']);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('sandbox install adds all four deny entries once and is idempotent on repeat', () => {
|
|
133
|
+
const sandboxHome = mkdtempSync(join(tmpdir(), 'cde-settings-defaults-'));
|
|
134
|
+
try {
|
|
135
|
+
const firstInstall = runInstallerInSandbox(sandboxHome, []);
|
|
136
|
+
assert.equal(firstInstall.status, 0, firstInstall.stderr || firstInstall.stdout);
|
|
137
|
+
|
|
138
|
+
const settingsPath = join(sandboxHome, '.claude', 'settings.json');
|
|
139
|
+
assert.ok(existsSync(settingsPath), 'settings.json written');
|
|
140
|
+
const firstSettings = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
|
141
|
+
const firstDeny = firstSettings.permissions?.deny ?? [];
|
|
142
|
+
for (const eachEntry of EXPECTED_DENY_ENTRIES) {
|
|
143
|
+
assert.ok(firstDeny.includes(eachEntry), `missing deny: ${eachEntry}`);
|
|
144
|
+
assert.equal(
|
|
145
|
+
firstDeny.filter((candidate) => candidate === eachEntry).length,
|
|
146
|
+
1,
|
|
147
|
+
`deny not unique: ${eachEntry}`,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const manifestPath = join(sandboxHome, '.claude', '.claude-dev-env-manifest.json');
|
|
152
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
153
|
+
assert.deepEqual(manifest.managedPermissions?.deny, EXPECTED_DENY_ENTRIES);
|
|
154
|
+
|
|
155
|
+
const secondInstall = runInstallerInSandbox(sandboxHome, []);
|
|
156
|
+
assert.equal(secondInstall.status, 0, secondInstall.stderr || secondInstall.stdout);
|
|
157
|
+
const secondSettings = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
|
158
|
+
const secondDeny = secondSettings.permissions?.deny ?? [];
|
|
159
|
+
for (const eachEntry of EXPECTED_DENY_ENTRIES) {
|
|
160
|
+
assert.equal(
|
|
161
|
+
secondDeny.filter((candidate) => candidate === eachEntry).length,
|
|
162
|
+
1,
|
|
163
|
+
`repeat install duplicated deny: ${eachEntry}`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
} finally {
|
|
167
|
+
rmSync(sandboxHome, { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('sandbox uninstall removes only package-owned permission entries and keeps user entries', () => {
|
|
172
|
+
const sandboxHome = mkdtempSync(join(tmpdir(), 'cde-settings-uninstall-'));
|
|
173
|
+
try {
|
|
174
|
+
const install = runInstallerInSandbox(sandboxHome, []);
|
|
175
|
+
assert.equal(install.status, 0, install.stderr || install.stdout);
|
|
176
|
+
|
|
177
|
+
const settingsPath = join(sandboxHome, '.claude', 'settings.json');
|
|
178
|
+
const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
|
179
|
+
settings.permissions = settings.permissions ?? {};
|
|
180
|
+
settings.permissions.allow = [...(settings.permissions.allow ?? []), 'Bash(git status)'];
|
|
181
|
+
settings.permissions.ask = [...(settings.permissions.ask ?? []), 'Edit(./**)'];
|
|
182
|
+
settings.permissions.deny = [...(settings.permissions.deny ?? []), 'Bash(rm -rf /)'];
|
|
183
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 4) + '\n');
|
|
184
|
+
|
|
185
|
+
const uninstall = runInstallerInSandbox(sandboxHome, ['--uninstall']);
|
|
186
|
+
assert.equal(uninstall.status, 0, uninstall.stderr || uninstall.stdout);
|
|
187
|
+
|
|
188
|
+
assert.ok(existsSync(settingsPath), 'settings.json remains for user entries');
|
|
189
|
+
const after = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
|
190
|
+
const denyAfter = after.permissions?.deny ?? [];
|
|
191
|
+
for (const eachEntry of EXPECTED_DENY_ENTRIES) {
|
|
192
|
+
assert.ok(!denyAfter.includes(eachEntry), `managed deny still present: ${eachEntry}`);
|
|
193
|
+
}
|
|
194
|
+
assert.ok(denyAfter.includes('Bash(rm -rf /)'), 'user deny preserved');
|
|
195
|
+
assert.ok((after.permissions?.allow ?? []).includes('Bash(git status)'), 'user allow preserved');
|
|
196
|
+
assert.ok((after.permissions?.ask ?? []).includes('Edit(./**)'), 'user ask preserved');
|
|
197
|
+
} finally {
|
|
198
|
+
rmSync(sandboxHome, { recursive: true, force: true });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Install transaction journal and fault-injection recovery (control-plane E2 / P-18).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import { strict as assert } from 'node:assert';
|
|
7
|
+
import {
|
|
8
|
+
existsSync,
|
|
9
|
+
mkdtempSync,
|
|
10
|
+
mkdirSync,
|
|
11
|
+
readFileSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
writeFileSync,
|
|
14
|
+
} from 'node:fs';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { dirname, join } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
19
|
+
import {
|
|
20
|
+
FAULT_PHASES,
|
|
21
|
+
INSTALL_FAULT_ENV,
|
|
22
|
+
InstallTransactionFaultError,
|
|
23
|
+
capturePriorInstallSnapshot,
|
|
24
|
+
discardInstallTransactionJournal,
|
|
25
|
+
readGlobalCoreHooksPath,
|
|
26
|
+
resolveFaultPhaseFromEnvironment,
|
|
27
|
+
restorePriorInstallSnapshot,
|
|
28
|
+
runWithInstallTransaction,
|
|
29
|
+
throwIfFaultPhase,
|
|
30
|
+
writeGlobalCoreHooksPath,
|
|
31
|
+
} from './install-transaction.mjs';
|
|
32
|
+
|
|
33
|
+
const THIS_DIRECTORY = dirname(fileURLToPath(import.meta.url));
|
|
34
|
+
const INSTALLER_PATH = join(THIS_DIRECTORY, 'install.mjs');
|
|
35
|
+
|
|
36
|
+
function sandbox() {
|
|
37
|
+
const root = mkdtempSync(join(tmpdir(), 'cdev-txn-'));
|
|
38
|
+
const managedRoot = join(root, 'managed');
|
|
39
|
+
mkdirSync(managedRoot, { recursive: true });
|
|
40
|
+
return {
|
|
41
|
+
root,
|
|
42
|
+
managedRoot,
|
|
43
|
+
settingsPath: join(managedRoot, 'settings.json'),
|
|
44
|
+
manifestFilePath: join(managedRoot, '.claude-dev-env-manifest.json'),
|
|
45
|
+
journalParent: join(managedRoot, '.claude-dev-env-txn'),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function writeFileWithParents(filePath, contents) {
|
|
50
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
51
|
+
writeFileSync(filePath, contents);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test('resolveFaultPhaseFromEnvironment accepts known phases and rejects unknown', () => {
|
|
55
|
+
assert.equal(resolveFaultPhaseFromEnvironment({}), null);
|
|
56
|
+
assert.equal(
|
|
57
|
+
resolveFaultPhaseFromEnvironment({ [INSTALL_FAULT_ENV]: FAULT_PHASES.AFTER_SETTINGS_WRITE }),
|
|
58
|
+
FAULT_PHASES.AFTER_SETTINGS_WRITE,
|
|
59
|
+
);
|
|
60
|
+
assert.throws(
|
|
61
|
+
() => resolveFaultPhaseFromEnvironment({ [INSTALL_FAULT_ENV]: 'not-a-phase' }),
|
|
62
|
+
/Unknown/,
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('throwIfFaultPhase throws only on the matching phase', () => {
|
|
67
|
+
assert.doesNotThrow(() => throwIfFaultPhase(FAULT_PHASES.AFTER_FILE_STAGING, null));
|
|
68
|
+
assert.doesNotThrow(
|
|
69
|
+
() => throwIfFaultPhase(FAULT_PHASES.AFTER_FILE_STAGING, FAULT_PHASES.AFTER_SETTINGS_WRITE),
|
|
70
|
+
);
|
|
71
|
+
assert.throws(
|
|
72
|
+
() => throwIfFaultPhase(FAULT_PHASES.AFTER_GIT_CONFIG, FAULT_PHASES.AFTER_GIT_CONFIG),
|
|
73
|
+
(error) => error instanceof InstallTransactionFaultError
|
|
74
|
+
&& error.phase === FAULT_PHASES.AFTER_GIT_CONFIG,
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('capture and restore recover settings, manifest, files, and hooksPath', () => {
|
|
79
|
+
const box = sandbox();
|
|
80
|
+
const gitConfigPath = join(box.root, '.gitconfig');
|
|
81
|
+
writeFileSync(gitConfigPath, '');
|
|
82
|
+
const priorHooksDirectory = join(box.managedRoot, 'hooks', 'git-hooks');
|
|
83
|
+
mkdirSync(priorHooksDirectory, { recursive: true });
|
|
84
|
+
const env = {
|
|
85
|
+
...process.env,
|
|
86
|
+
HOME: box.root,
|
|
87
|
+
USERPROFILE: box.root,
|
|
88
|
+
GIT_CONFIG_GLOBAL: gitConfigPath,
|
|
89
|
+
};
|
|
90
|
+
const io = { env, execFileSync };
|
|
91
|
+
|
|
92
|
+
writeFileWithParents(box.settingsPath, '{"hooks":{"SessionStart":[]}}\n');
|
|
93
|
+
const priorFile = join(box.managedRoot, 'rules', 'keep.md');
|
|
94
|
+
writeFileWithParents(priorFile, 'prior-rules\n');
|
|
95
|
+
writeFileWithParents(
|
|
96
|
+
box.manifestFilePath,
|
|
97
|
+
`${JSON.stringify({ files: [priorFile], skills: ['keep'] }, null, 2)}\n`,
|
|
98
|
+
);
|
|
99
|
+
writeGlobalCoreHooksPath(priorHooksDirectory, io);
|
|
100
|
+
|
|
101
|
+
const snapshot = capturePriorInstallSnapshot({
|
|
102
|
+
managedRoot: box.managedRoot,
|
|
103
|
+
manifestFilePath: box.manifestFilePath,
|
|
104
|
+
settingsPath: box.settingsPath,
|
|
105
|
+
priorManifestFiles: [priorFile],
|
|
106
|
+
journalParentDirectory: box.journalParent,
|
|
107
|
+
io,
|
|
108
|
+
});
|
|
109
|
+
assert.equal(snapshot.settingsExisted, true);
|
|
110
|
+
assert.equal(snapshot.manifestExisted, true);
|
|
111
|
+
assert.equal(snapshot.priorHooksPath, priorHooksDirectory);
|
|
112
|
+
assert.equal(snapshot.allFileEntries.length, 1);
|
|
113
|
+
|
|
114
|
+
const newFile = join(box.managedRoot, 'rules', 'new.md');
|
|
115
|
+
writeFileWithParents(newFile, 'new-content\n');
|
|
116
|
+
writeFileSync(priorFile, 'corrupted\n');
|
|
117
|
+
writeFileSync(box.settingsPath, '{"hooks":{"broken":true}}\n');
|
|
118
|
+
writeFileSync(box.manifestFilePath, '{"files":[],"skills":[]}\n');
|
|
119
|
+
writeGlobalCoreHooksPath(join(box.managedRoot, 'other-hooks'), io);
|
|
120
|
+
|
|
121
|
+
restorePriorInstallSnapshot(snapshot, {
|
|
122
|
+
allWrittenPaths: [newFile, priorFile, box.settingsPath, box.manifestFilePath],
|
|
123
|
+
io,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
assert.equal(readFileSync(priorFile, 'utf8'), 'prior-rules\n');
|
|
127
|
+
assert.equal(readFileSync(box.settingsPath, 'utf8'), '{"hooks":{"SessionStart":[]}}\n');
|
|
128
|
+
assert.deepEqual(JSON.parse(readFileSync(box.manifestFilePath, 'utf8')).skills, ['keep']);
|
|
129
|
+
assert.equal(existsSync(newFile), false);
|
|
130
|
+
assert.equal(readGlobalCoreHooksPath(io), priorHooksDirectory);
|
|
131
|
+
|
|
132
|
+
discardInstallTransactionJournal(snapshot);
|
|
133
|
+
rmSync(box.root, { recursive: true, force: true });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('runWithInstallTransaction restores prior state on injected fault', () => {
|
|
137
|
+
const box = sandbox();
|
|
138
|
+
const gitConfigPath = join(box.root, '.gitconfig');
|
|
139
|
+
writeFileSync(gitConfigPath, '');
|
|
140
|
+
const env = {
|
|
141
|
+
...process.env,
|
|
142
|
+
HOME: box.root,
|
|
143
|
+
USERPROFILE: box.root,
|
|
144
|
+
GIT_CONFIG_GLOBAL: gitConfigPath,
|
|
145
|
+
};
|
|
146
|
+
const io = { env, execFileSync };
|
|
147
|
+
const priorFile = join(box.managedRoot, 'docs', 'a.md');
|
|
148
|
+
writeFileWithParents(priorFile, 'keep-me\n');
|
|
149
|
+
writeFileWithParents(box.settingsPath, '{"ok":true}\n');
|
|
150
|
+
writeFileWithParents(
|
|
151
|
+
box.manifestFilePath,
|
|
152
|
+
`${JSON.stringify({ files: [priorFile], skills: [] })}\n`,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const snapshot = capturePriorInstallSnapshot({
|
|
156
|
+
managedRoot: box.managedRoot,
|
|
157
|
+
manifestFilePath: box.manifestFilePath,
|
|
158
|
+
settingsPath: box.settingsPath,
|
|
159
|
+
priorManifestFiles: [priorFile],
|
|
160
|
+
journalParentDirectory: box.journalParent,
|
|
161
|
+
io,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
assert.throws(
|
|
165
|
+
() => runWithInstallTransaction({
|
|
166
|
+
snapshot,
|
|
167
|
+
faultPhase: FAULT_PHASES.AFTER_SETTINGS_WRITE,
|
|
168
|
+
io,
|
|
169
|
+
runMutations: ({ throwIfFault, recordWrittenPath }) => {
|
|
170
|
+
writeFileSync(priorFile, 'mutated\n');
|
|
171
|
+
recordWrittenPath(priorFile);
|
|
172
|
+
writeFileSync(box.settingsPath, '{"ok":false}\n');
|
|
173
|
+
recordWrittenPath(box.settingsPath);
|
|
174
|
+
throwIfFault(FAULT_PHASES.AFTER_SETTINGS_WRITE);
|
|
175
|
+
writeFileSync(box.manifestFilePath, '{"files":[]}\n');
|
|
176
|
+
},
|
|
177
|
+
}),
|
|
178
|
+
(error) => error instanceof InstallTransactionFaultError,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
assert.equal(readFileSync(priorFile, 'utf8'), 'keep-me\n');
|
|
182
|
+
assert.equal(readFileSync(box.settingsPath, 'utf8'), '{"ok":true}\n');
|
|
183
|
+
assert.deepEqual(JSON.parse(readFileSync(box.manifestFilePath, 'utf8')).files, [priorFile]);
|
|
184
|
+
rmSync(box.root, { recursive: true, force: true });
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('runWithInstallTransaction commits and discards journal on success', () => {
|
|
188
|
+
const box = sandbox();
|
|
189
|
+
const gitConfigPath = join(box.root, '.gitconfig');
|
|
190
|
+
writeFileSync(gitConfigPath, '');
|
|
191
|
+
const io = {
|
|
192
|
+
env: {
|
|
193
|
+
...process.env,
|
|
194
|
+
HOME: box.root,
|
|
195
|
+
USERPROFILE: box.root,
|
|
196
|
+
GIT_CONFIG_GLOBAL: gitConfigPath,
|
|
197
|
+
},
|
|
198
|
+
execFileSync,
|
|
199
|
+
};
|
|
200
|
+
const priorFile = join(box.managedRoot, 'docs', 'a.md');
|
|
201
|
+
writeFileWithParents(priorFile, 'v1\n');
|
|
202
|
+
writeFileWithParents(
|
|
203
|
+
box.manifestFilePath,
|
|
204
|
+
`${JSON.stringify({ files: [priorFile], skills: [] })}\n`,
|
|
205
|
+
);
|
|
206
|
+
const snapshot = capturePriorInstallSnapshot({
|
|
207
|
+
managedRoot: box.managedRoot,
|
|
208
|
+
manifestFilePath: box.manifestFilePath,
|
|
209
|
+
settingsPath: box.settingsPath,
|
|
210
|
+
priorManifestFiles: [priorFile],
|
|
211
|
+
journalParentDirectory: box.journalParent,
|
|
212
|
+
io,
|
|
213
|
+
});
|
|
214
|
+
const journalRoot = snapshot.journalRoot;
|
|
215
|
+
|
|
216
|
+
runWithInstallTransaction({
|
|
217
|
+
snapshot,
|
|
218
|
+
faultPhase: null,
|
|
219
|
+
io,
|
|
220
|
+
runMutations: ({ throwIfFault, recordWrittenPath }) => {
|
|
221
|
+
writeFileSync(priorFile, 'v2\n');
|
|
222
|
+
recordWrittenPath(priorFile);
|
|
223
|
+
throwIfFault(FAULT_PHASES.AFTER_FILE_STAGING);
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
assert.equal(readFileSync(priorFile, 'utf8'), 'v2\n');
|
|
228
|
+
assert.equal(existsSync(journalRoot), false);
|
|
229
|
+
rmSync(box.root, { recursive: true, force: true });
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Spawn the real installer against a sandbox home with optional fault phase.
|
|
234
|
+
*
|
|
235
|
+
* @param {string} homeDirectory
|
|
236
|
+
* @param {string[]} extraArguments
|
|
237
|
+
* @param {{ faultPhase?: string|null }} [options]
|
|
238
|
+
*/
|
|
239
|
+
function runInstaller(homeDirectory, extraArguments, options = {}) {
|
|
240
|
+
const childEnvironment = {
|
|
241
|
+
...process.env,
|
|
242
|
+
HOME: homeDirectory,
|
|
243
|
+
USERPROFILE: homeDirectory,
|
|
244
|
+
GIT_CONFIG_GLOBAL: join(homeDirectory, '.gitconfig'),
|
|
245
|
+
};
|
|
246
|
+
if (options.faultPhase) {
|
|
247
|
+
childEnvironment[INSTALL_FAULT_ENV] = options.faultPhase;
|
|
248
|
+
} else {
|
|
249
|
+
delete childEnvironment[INSTALL_FAULT_ENV];
|
|
250
|
+
}
|
|
251
|
+
return spawnSync(process.execPath, [INSTALLER_PATH, ...extraArguments], {
|
|
252
|
+
cwd: THIS_DIRECTORY,
|
|
253
|
+
encoding: 'utf8',
|
|
254
|
+
env: childEnvironment,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function seedPriorInstall(homeDirectory) {
|
|
259
|
+
const claudeDirectory = join(homeDirectory, '.claude');
|
|
260
|
+
const rulesFile = join(claudeDirectory, 'rules', 'prior.md');
|
|
261
|
+
writeFileWithParents(rulesFile, 'prior-body\n');
|
|
262
|
+
writeFileWithParents(
|
|
263
|
+
join(claudeDirectory, 'settings.json'),
|
|
264
|
+
`${JSON.stringify({ hooks: { UserPromptSubmit: [] }, customMarker: 'prior-settings' }, null, 2)}\n`,
|
|
265
|
+
);
|
|
266
|
+
writeFileWithParents(
|
|
267
|
+
join(claudeDirectory, '.claude-dev-env-manifest.json'),
|
|
268
|
+
`${JSON.stringify({
|
|
269
|
+
packageName: 'claude-dev-env',
|
|
270
|
+
files: [rulesFile],
|
|
271
|
+
skills: [],
|
|
272
|
+
}, null, 2)}\n`,
|
|
273
|
+
);
|
|
274
|
+
writeFileSync(join(homeDirectory, '.gitconfig'), '');
|
|
275
|
+
return { claudeDirectory, rulesFile };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
test('installer fault after_file_staging restores prior managed installation', () => {
|
|
279
|
+
const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-txn-e2e-'));
|
|
280
|
+
try {
|
|
281
|
+
const { claudeDirectory, rulesFile } = seedPriorInstall(homeDirectory);
|
|
282
|
+
const priorSettings = readFileSync(join(claudeDirectory, 'settings.json'), 'utf8');
|
|
283
|
+
const priorManifest = readFileSync(
|
|
284
|
+
join(claudeDirectory, '.claude-dev-env-manifest.json'),
|
|
285
|
+
'utf8',
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
const failedRun = runInstaller(homeDirectory, ['--only', 'journal'], {
|
|
289
|
+
faultPhase: FAULT_PHASES.AFTER_FILE_STAGING,
|
|
290
|
+
});
|
|
291
|
+
assert.notEqual(failedRun.status, 0, failedRun.stdout + failedRun.stderr);
|
|
292
|
+
assert.match(`${failedRun.stdout}${failedRun.stderr}`, /fault|restored|aborted/i);
|
|
293
|
+
|
|
294
|
+
assert.equal(readFileSync(rulesFile, 'utf8'), 'prior-body\n');
|
|
295
|
+
assert.equal(readFileSync(join(claudeDirectory, 'settings.json'), 'utf8'), priorSettings);
|
|
296
|
+
assert.equal(
|
|
297
|
+
readFileSync(join(claudeDirectory, '.claude-dev-env-manifest.json'), 'utf8'),
|
|
298
|
+
priorManifest,
|
|
299
|
+
);
|
|
300
|
+
} finally {
|
|
301
|
+
rmSync(homeDirectory, { recursive: true, force: true });
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
test('installer fault after_settings_write restores prior settings and files', () => {
|
|
306
|
+
const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-txn-e2e-settings-'));
|
|
307
|
+
try {
|
|
308
|
+
const { claudeDirectory, rulesFile } = seedPriorInstall(homeDirectory);
|
|
309
|
+
const priorSettings = readFileSync(join(claudeDirectory, 'settings.json'), 'utf8');
|
|
310
|
+
|
|
311
|
+
const failedRun = runInstaller(homeDirectory, [], {
|
|
312
|
+
faultPhase: FAULT_PHASES.AFTER_SETTINGS_WRITE,
|
|
313
|
+
});
|
|
314
|
+
assert.notEqual(failedRun.status, 0, failedRun.stdout + failedRun.stderr);
|
|
315
|
+
assert.equal(readFileSync(join(claudeDirectory, 'settings.json'), 'utf8'), priorSettings);
|
|
316
|
+
assert.equal(readFileSync(rulesFile, 'utf8'), 'prior-body\n');
|
|
317
|
+
assert.match(
|
|
318
|
+
readFileSync(join(claudeDirectory, '.claude-dev-env-manifest.json'), 'utf8'),
|
|
319
|
+
/prior\.md|prior-body|claude-dev-env/,
|
|
320
|
+
);
|
|
321
|
+
} finally {
|
|
322
|
+
rmSync(homeDirectory, { recursive: true, force: true });
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test('installer fault after_manifest_write restores prior manifest', () => {
|
|
327
|
+
const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-txn-e2e-manifest-'));
|
|
328
|
+
try {
|
|
329
|
+
const { claudeDirectory } = seedPriorInstall(homeDirectory);
|
|
330
|
+
const priorManifest = readFileSync(
|
|
331
|
+
join(claudeDirectory, '.claude-dev-env-manifest.json'),
|
|
332
|
+
'utf8',
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
const failedRun = runInstaller(homeDirectory, ['--only', 'journal'], {
|
|
336
|
+
faultPhase: FAULT_PHASES.AFTER_MANIFEST_WRITE,
|
|
337
|
+
});
|
|
338
|
+
assert.notEqual(failedRun.status, 0, failedRun.stdout + failedRun.stderr);
|
|
339
|
+
assert.equal(
|
|
340
|
+
readFileSync(join(claudeDirectory, '.claude-dev-env-manifest.json'), 'utf8'),
|
|
341
|
+
priorManifest,
|
|
342
|
+
);
|
|
343
|
+
} finally {
|
|
344
|
+
rmSync(homeDirectory, { recursive: true, force: true });
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test('installer fault after_git_config restores prior core.hooksPath', () => {
|
|
349
|
+
const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-txn-e2e-git-'));
|
|
350
|
+
try {
|
|
351
|
+
seedPriorInstall(homeDirectory);
|
|
352
|
+
const gitConfigPath = join(homeDirectory, '.gitconfig');
|
|
353
|
+
const priorHooksPath = join(homeDirectory, 'prior-git-hooks');
|
|
354
|
+
mkdirSync(priorHooksPath, { recursive: true });
|
|
355
|
+
writeGlobalCoreHooksPath(priorHooksPath, {
|
|
356
|
+
env: {
|
|
357
|
+
...process.env,
|
|
358
|
+
HOME: homeDirectory,
|
|
359
|
+
USERPROFILE: homeDirectory,
|
|
360
|
+
GIT_CONFIG_GLOBAL: gitConfigPath,
|
|
361
|
+
},
|
|
362
|
+
execFileSync,
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
const failedRun = runInstaller(homeDirectory, [], {
|
|
366
|
+
faultPhase: FAULT_PHASES.AFTER_GIT_CONFIG,
|
|
367
|
+
});
|
|
368
|
+
assert.notEqual(failedRun.status, 0, failedRun.stdout + failedRun.stderr);
|
|
369
|
+
|
|
370
|
+
const restored = readGlobalCoreHooksPath({
|
|
371
|
+
env: {
|
|
372
|
+
...process.env,
|
|
373
|
+
HOME: homeDirectory,
|
|
374
|
+
USERPROFILE: homeDirectory,
|
|
375
|
+
GIT_CONFIG_GLOBAL: gitConfigPath,
|
|
376
|
+
},
|
|
377
|
+
execFileSync,
|
|
378
|
+
});
|
|
379
|
+
assert.equal(restored, priorHooksPath);
|
|
380
|
+
} finally {
|
|
381
|
+
rmSync(homeDirectory, { recursive: true, force: true });
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test('successful install after prior install leaves one manifest and no fault', () => {
|
|
386
|
+
const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-txn-e2e-ok-'));
|
|
387
|
+
try {
|
|
388
|
+
seedPriorInstall(homeDirectory);
|
|
389
|
+
const okRun = runInstaller(homeDirectory, ['--only', 'journal']);
|
|
390
|
+
assert.equal(okRun.status, 0, okRun.stdout + okRun.stderr);
|
|
391
|
+
const manifestPath = join(homeDirectory, '.claude', '.claude-dev-env-manifest.json');
|
|
392
|
+
assert.equal(existsSync(manifestPath), true);
|
|
393
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
394
|
+
assert.ok(Array.isArray(manifest.files));
|
|
395
|
+
assert.equal(existsSync(join(homeDirectory, '.claude', '.claude-dev-env-txn')), false);
|
|
396
|
+
} finally {
|
|
397
|
+
rmSync(homeDirectory, { recursive: true, force: true });
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|