alp-code 0.9.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/CHANGELOG.md +770 -0
- package/LICENSE +21 -0
- package/README.md +295 -0
- package/alp.config.yaml +5 -0
- package/dist/src/agents/agent-definition.js +28 -0
- package/dist/src/agents/capability-catalog.js +33 -0
- package/dist/src/agents/compaction.js +36 -0
- package/dist/src/agents/errors.js +12 -0
- package/dist/src/agents/librarian.js +38 -0
- package/dist/src/agents/main.js +37 -0
- package/dist/src/agents/memory-grant.js +29 -0
- package/dist/src/agents/model-context.js +70 -0
- package/dist/src/agents/modes.js +134 -0
- package/dist/src/agents/oracle.js +36 -0
- package/dist/src/agents/read-thread.js +38 -0
- package/dist/src/agents/registry.js +238 -0
- package/dist/src/agents/render-identity.js +38 -0
- package/dist/src/agents/review.js +37 -0
- package/dist/src/agents/search.js +37 -0
- package/dist/src/agents/shared/house-rules.js +33 -0
- package/dist/src/agents/shared/principal.js +18 -0
- package/dist/src/agents/shared/voice.js +29 -0
- package/dist/src/agents/titling.js +32 -0
- package/dist/src/agents/types.js +15 -0
- package/dist/src/backend/execution-backend.js +2 -0
- package/dist/src/backend/local-execution-store.js +144 -0
- package/dist/src/backend/local-process-backend.js +533 -0
- package/dist/src/backend/local-supervisor.js +104 -0
- package/dist/src/cli/alp.js +380 -0
- package/dist/src/cli/commands/context.js +203 -0
- package/dist/src/cli/commands/delegate.js +136 -0
- package/dist/src/cli/commands/identity-sync.js +31 -0
- package/dist/src/cli/commands/init.js +184 -0
- package/dist/src/cli/commands/mode.js +22 -0
- package/dist/src/cli/commands/principal.js +114 -0
- package/dist/src/cli/commands/run-main.js +90 -0
- package/dist/src/cli/commands/runtime.js +21 -0
- package/dist/src/cli/mode-preference-store.js +62 -0
- package/dist/src/cli/mode-selector.js +178 -0
- package/dist/src/cli/update-check.js +77 -0
- package/dist/src/context/checkpoint.js +134 -0
- package/dist/src/context/compact-journal.js +153 -0
- package/dist/src/context/compact-payload.js +121 -0
- package/dist/src/context/continuity.js +70 -0
- package/dist/src/context/types.js +2 -0
- package/dist/src/delegation/backend-registry.js +40 -0
- package/dist/src/delegation/delegation-service.js +300 -0
- package/dist/src/delegation/types.js +12 -0
- package/dist/src/execution/execution-policy.js +96 -0
- package/dist/src/execution/execution-service.js +115 -0
- package/dist/src/execution/execution-store.js +78 -0
- package/dist/src/execution/identity-capsule.js +65 -0
- package/dist/src/execution/types.js +12 -0
- package/dist/src/hooks/execution-bridge.js +84 -0
- package/dist/src/index.js +4 -0
- package/dist/src/memory/adapters/markdown-file-store.js +257 -0
- package/dist/src/memory/adapters/memory-api-client.js +2 -0
- package/dist/src/memory/adapters/memory-path-mapper.js +76 -0
- package/dist/src/memory/adapters/remote-api-store.js +25 -0
- package/dist/src/memory/context-ranker.js +21 -0
- package/dist/src/memory/errors.js +58 -0
- package/dist/src/memory/memory-service.js +149 -0
- package/dist/src/memory/memory-store.js +2 -0
- package/dist/src/memory/types.js +2 -0
- package/dist/src/policy/capability-policy.js +29 -0
- package/dist/src/policy/delegation-policy.js +25 -0
- package/dist/src/policy/errors.js +10 -0
- package/dist/src/policy/invariants.js +31 -0
- package/dist/src/policy/memory-policy.js +22 -0
- package/dist/src/policy/policy-engine.js +85 -0
- package/dist/src/policy/types.js +8 -0
- package/dist/src/policy/workspace-policy.js +77 -0
- package/dist/src/principal/principal-profile-store.js +89 -0
- package/dist/src/runtime/adapter-files.js +147 -0
- package/dist/src/runtime/claude-adapter.js +177 -0
- package/dist/src/runtime/codex-adapter.js +169 -0
- package/dist/src/runtime/permission-rules.js +156 -0
- package/dist/src/runtime/render-session-context.js +124 -0
- package/dist/src/runtime/render-task-input.js +33 -0
- package/dist/src/runtime/runtime-adapter.js +2 -0
- package/dist/src/runtime/runtime-preference-store.js +66 -0
- package/dist/src/runtime/runtime-selector.js +178 -0
- package/dist/src/runtime/types.js +2 -0
- package/dist/src/runtime/windows-shim.js +57 -0
- package/dist/src/state-paths.js +49 -0
- package/dist/src/workflow/output-validator.js +27 -0
- package/dist/src/workflow/repair-policy.js +8 -0
- package/dist/src/workflow/types.js +22 -0
- package/dist/src/workflow/workflow-runner.js +81 -0
- package/hooks/compact-record.cjs +109 -0
- package/hooks/session-boot.cjs +112 -0
- package/hooks/session-end.cjs +34 -0
- package/package.json +48 -0
- package/scaffold/memory/INDEX.md +27 -0
- package/scaffold/memory/README.md +76 -0
- package/scaffold/memory/projects/INDEX.md +22 -0
- package/scaffold/memory/projects/PROTOCOL.md +128 -0
- package/scaffold/memory/projects/_template/PROJECT.md +45 -0
- package/scripts/alp.cjs +126 -0
- package/scripts/alp.ps1 +4 -0
- package/scripts/alp.sh +3 -0
- package/scripts/bootstrap.cjs +144 -0
- package/scripts/checkout-release.cjs +30 -0
- package/scripts/delegate.cjs +19 -0
- package/scripts/doctor.cjs +158 -0
- package/scripts/doctor.sh +3 -0
- package/scripts/ensure-state.cjs +22 -0
- package/scripts/lib/cli-link.cjs +375 -0
- package/scripts/lib/codex-role.cjs +18 -0
- package/scripts/lib/delegation/command-runner.cjs +108 -0
- package/scripts/lib/delegation/config.cjs +81 -0
- package/scripts/lib/install-paths.cjs +154 -0
- package/scripts/lib/release-manifest.cjs +42 -0
- package/scripts/lib/semver-lite.cjs +20 -0
- package/scripts/lib/state.cjs +274 -0
- package/scripts/lib/uninstall.cjs +252 -0
- package/scripts/lib/update-check-worker.cjs +21 -0
- package/scripts/lib/update.cjs +395 -0
- package/scripts/run-role.cjs +42 -0
- package/scripts/run-role.ps1 +4 -0
- package/scripts/run-role.sh +3 -0
- package/scripts/sync-project-index.sh +167 -0
- package/skills/agent-memory/SKILL.md +109 -0
- package/skills/alp-debug/SKILL.md +90 -0
- package/skills/alp-debug/references/defense-in-depth.md +118 -0
- package/skills/alp-debug/references/investigation-methodology.md +106 -0
- package/skills/alp-debug/references/log-and-ci-analysis.md +96 -0
- package/skills/alp-debug/references/performance-diagnostics.md +112 -0
- package/skills/alp-debug/references/reporting-standards.md +120 -0
- package/skills/alp-debug/references/root-cause-tracing.md +134 -0
- package/skills/alp-debug/references/systematic-debugging.md +93 -0
- package/skills/alp-debug/references/verification.md +86 -0
- package/skills/alp-debug/scripts/find-polluter.sh +63 -0
- package/skills/alp-debug/scripts/find-polluter.test.md +102 -0
- package/skills/alp-plan/SKILL.md +128 -0
- package/skills/alp-plan/references/archive-workflow.md +77 -0
- package/skills/alp-plan/references/codebase-understanding.md +55 -0
- package/skills/alp-plan/references/output-standards.md +96 -0
- package/skills/alp-plan/references/plan-organization.md +129 -0
- package/skills/alp-plan/references/red-team-personas.md +76 -0
- package/skills/alp-plan/references/red-team-workflow.md +81 -0
- package/skills/alp-plan/references/research-phase.md +57 -0
- package/skills/alp-plan/references/scope-challenge.md +82 -0
- package/skills/alp-plan/references/solution-design.md +76 -0
- package/skills/alp-plan/references/validate-question-framework.md +89 -0
- package/skills/alp-plan/references/validate-workflow.md +83 -0
- package/skills/alp-predict/SKILL.md +98 -0
- package/skills/alp-scenario/SKILL.md +86 -0
- package/skills/code-review/SKILL.md +111 -0
- package/skills/code-review/references/code-review-reception.md +114 -0
- package/skills/code-review/references/edge-case-scouting.md +78 -0
- package/skills/code-review/references/verification-before-completion.md +117 -0
- package/skills/delegation/SKILL.md +46 -0
- package/skills/docs-seeker/.env.example +15 -0
- package/skills/docs-seeker/SKILL.md +87 -0
- package/skills/docs-seeker/package.json +25 -0
- package/skills/docs-seeker/references/advanced.md +82 -0
- package/skills/docs-seeker/references/context7-patterns.md +68 -0
- package/skills/docs-seeker/references/errors.md +72 -0
- package/skills/docs-seeker/scripts/analyze-llms-txt.js +211 -0
- package/skills/docs-seeker/scripts/detect-topic.js +172 -0
- package/skills/docs-seeker/scripts/fetch-docs.js +213 -0
- package/skills/docs-seeker/scripts/tests/run-tests.js +72 -0
- package/skills/docs-seeker/scripts/tests/test-analyze-llms.js +119 -0
- package/skills/docs-seeker/scripts/tests/test-detect-topic.js +112 -0
- package/skills/docs-seeker/scripts/tests/test-fetch-docs.js +84 -0
- package/skills/docs-seeker/scripts/utils/env-loader.js +94 -0
- package/skills/docs-seeker/workflows/library-search.md +73 -0
- package/skills/docs-seeker/workflows/repo-analysis.md +90 -0
- package/skills/docs-seeker/workflows/topic-search.md +69 -0
- package/skills/git/SKILL.md +121 -0
- package/skills/git/references/branch-management.md +90 -0
- package/skills/git/references/commit-standards.md +82 -0
- package/skills/git/references/gh-cli-guide.md +132 -0
- package/skills/git/references/safety-protocols.md +86 -0
- package/skills/git/references/workflow-commit.md +89 -0
- package/skills/git/references/workflow-merge.md +63 -0
- package/skills/git/references/workflow-pr.md +70 -0
- package/skills/git/references/workflow-push.md +62 -0
- package/skills/gkg/SKILL.md +87 -0
- package/skills/gkg/references/cli-commands.md +92 -0
- package/skills/gkg/references/http-api.md +99 -0
- package/skills/gkg/references/language-support.md +54 -0
- package/skills/problem-solving/SKILL.md +86 -0
- package/skills/problem-solving/references/attribution.md +48 -0
- package/skills/problem-solving/references/collision-zone-thinking.md +71 -0
- package/skills/problem-solving/references/inversion-exercise.md +88 -0
- package/skills/problem-solving/references/meta-pattern-recognition.md +80 -0
- package/skills/problem-solving/references/scale-game.md +82 -0
- package/skills/problem-solving/references/simplification-cascades.md +83 -0
- package/skills/problem-solving/references/when-stuck.md +76 -0
- package/skills/repomix/SKILL.md +94 -0
- package/skills/repomix/references/configuration.md +134 -0
- package/skills/repomix/references/usage-patterns.md +106 -0
- package/skills/repomix/scripts/.coverage +0 -0
- package/skills/repomix/scripts/README.md +179 -0
- package/skills/repomix/scripts/repomix_batch.py +455 -0
- package/skills/repomix/scripts/repos.example.json +15 -0
- package/skills/repomix/scripts/requirements.txt +15 -0
- package/skills/repomix/scripts/tests/test_repomix_batch.py +531 -0
- package/skills/research/SKILL.md +107 -0
- package/skills/security-scan/SKILL.md +101 -0
- package/skills/security-scan/references/secret-patterns.md +75 -0
- package/skills/security-scan/references/vulnerability-patterns.md +136 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for repomix_batch.py
|
|
3
|
+
|
|
4
|
+
Run with: pytest test_repomix_batch.py -v --cov=repomix_batch --cov-report=term-missing
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
import json
|
|
10
|
+
import subprocess
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from unittest.mock import Mock, patch, mock_open, MagicMock
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
# Add parent directory to path to import the module
|
|
16
|
+
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
17
|
+
|
|
18
|
+
from repomix_batch import (
|
|
19
|
+
RepomixConfig,
|
|
20
|
+
EnvLoader,
|
|
21
|
+
RepomixBatchProcessor,
|
|
22
|
+
load_repositories_from_file,
|
|
23
|
+
main
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TestRepomixConfig:
|
|
28
|
+
"""Test RepomixConfig dataclass."""
|
|
29
|
+
|
|
30
|
+
def test_default_values(self):
|
|
31
|
+
"""Test default configuration values."""
|
|
32
|
+
config = RepomixConfig()
|
|
33
|
+
assert config.style == "xml"
|
|
34
|
+
assert config.output_dir == "repomix-output"
|
|
35
|
+
assert config.remove_comments is False
|
|
36
|
+
assert config.include_pattern is None
|
|
37
|
+
assert config.ignore_pattern is None
|
|
38
|
+
assert config.no_security_check is False
|
|
39
|
+
assert config.verbose is False
|
|
40
|
+
|
|
41
|
+
def test_custom_values(self):
|
|
42
|
+
"""Test custom configuration values."""
|
|
43
|
+
config = RepomixConfig(
|
|
44
|
+
style="markdown",
|
|
45
|
+
output_dir="custom-output",
|
|
46
|
+
remove_comments=True,
|
|
47
|
+
include_pattern="src/**",
|
|
48
|
+
ignore_pattern="tests/**",
|
|
49
|
+
no_security_check=True,
|
|
50
|
+
verbose=True
|
|
51
|
+
)
|
|
52
|
+
assert config.style == "markdown"
|
|
53
|
+
assert config.output_dir == "custom-output"
|
|
54
|
+
assert config.remove_comments is True
|
|
55
|
+
assert config.include_pattern == "src/**"
|
|
56
|
+
assert config.ignore_pattern == "tests/**"
|
|
57
|
+
assert config.no_security_check is True
|
|
58
|
+
assert config.verbose is True
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class TestEnvLoader:
|
|
62
|
+
"""Test EnvLoader class."""
|
|
63
|
+
|
|
64
|
+
def test_parse_env_file_basic(self, tmp_path):
|
|
65
|
+
"""Test parsing basic .env file."""
|
|
66
|
+
env_file = tmp_path / ".env"
|
|
67
|
+
env_file.write_text("KEY1=value1\nKEY2=value2\n")
|
|
68
|
+
|
|
69
|
+
result = EnvLoader._parse_env_file(env_file)
|
|
70
|
+
assert result == {"KEY1": "value1", "KEY2": "value2"}
|
|
71
|
+
|
|
72
|
+
def test_parse_env_file_with_quotes(self, tmp_path):
|
|
73
|
+
"""Test parsing .env file with quoted values."""
|
|
74
|
+
env_file = tmp_path / ".env"
|
|
75
|
+
env_file.write_text('KEY1="value with spaces"\nKEY2=\'single quotes\'\n')
|
|
76
|
+
|
|
77
|
+
result = EnvLoader._parse_env_file(env_file)
|
|
78
|
+
assert result == {"KEY1": "value with spaces", "KEY2": "single quotes"}
|
|
79
|
+
|
|
80
|
+
def test_parse_env_file_with_comments(self, tmp_path):
|
|
81
|
+
"""Test parsing .env file with comments."""
|
|
82
|
+
env_file = tmp_path / ".env"
|
|
83
|
+
env_file.write_text("# Comment\nKEY1=value1\n\n# Another comment\nKEY2=value2\n")
|
|
84
|
+
|
|
85
|
+
result = EnvLoader._parse_env_file(env_file)
|
|
86
|
+
assert result == {"KEY1": "value1", "KEY2": "value2"}
|
|
87
|
+
|
|
88
|
+
def test_parse_env_file_with_empty_lines(self, tmp_path):
|
|
89
|
+
"""Test parsing .env file with empty lines."""
|
|
90
|
+
env_file = tmp_path / ".env"
|
|
91
|
+
env_file.write_text("KEY1=value1\n\n\nKEY2=value2\n")
|
|
92
|
+
|
|
93
|
+
result = EnvLoader._parse_env_file(env_file)
|
|
94
|
+
assert result == {"KEY1": "value1", "KEY2": "value2"}
|
|
95
|
+
|
|
96
|
+
def test_parse_env_file_with_equals_in_value(self, tmp_path):
|
|
97
|
+
"""Test parsing .env file with equals sign in value."""
|
|
98
|
+
env_file = tmp_path / ".env"
|
|
99
|
+
env_file.write_text("KEY1=value=with=equals\n")
|
|
100
|
+
|
|
101
|
+
result = EnvLoader._parse_env_file(env_file)
|
|
102
|
+
assert result == {"KEY1": "value=with=equals"}
|
|
103
|
+
|
|
104
|
+
def test_parse_env_file_invalid(self, tmp_path):
|
|
105
|
+
"""Test parsing invalid .env file."""
|
|
106
|
+
env_file = tmp_path / ".env"
|
|
107
|
+
env_file.write_text("INVALID LINE WITHOUT EQUALS\n")
|
|
108
|
+
|
|
109
|
+
result = EnvLoader._parse_env_file(env_file)
|
|
110
|
+
assert result == {}
|
|
111
|
+
|
|
112
|
+
def test_parse_env_file_not_found(self, tmp_path):
|
|
113
|
+
"""Test parsing non-existent .env file."""
|
|
114
|
+
env_file = tmp_path / "nonexistent.env"
|
|
115
|
+
result = EnvLoader._parse_env_file(env_file)
|
|
116
|
+
assert result == {}
|
|
117
|
+
|
|
118
|
+
@patch.dict(os.environ, {"PROCESS_VAR": "from_process"}, clear=True)
|
|
119
|
+
def test_load_env_files_process_env_priority(self):
|
|
120
|
+
"""Test that process environment has highest priority."""
|
|
121
|
+
with patch.object(Path, 'exists', return_value=False):
|
|
122
|
+
env_vars = EnvLoader.load_env_files()
|
|
123
|
+
assert env_vars.get("PROCESS_VAR") == "from_process"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class TestRepomixBatchProcessor:
|
|
127
|
+
"""Test RepomixBatchProcessor class."""
|
|
128
|
+
|
|
129
|
+
def test_init(self):
|
|
130
|
+
"""Test processor initialization."""
|
|
131
|
+
config = RepomixConfig()
|
|
132
|
+
processor = RepomixBatchProcessor(config)
|
|
133
|
+
assert processor.config == config
|
|
134
|
+
assert isinstance(processor.env_vars, dict)
|
|
135
|
+
|
|
136
|
+
@patch("subprocess.run")
|
|
137
|
+
def test_check_repomix_installed_success(self, mock_run):
|
|
138
|
+
"""Test checking if repomix is installed (success)."""
|
|
139
|
+
mock_run.return_value = Mock(returncode=0)
|
|
140
|
+
|
|
141
|
+
config = RepomixConfig()
|
|
142
|
+
processor = RepomixBatchProcessor(config)
|
|
143
|
+
assert processor.check_repomix_installed() is True
|
|
144
|
+
|
|
145
|
+
mock_run.assert_called_once()
|
|
146
|
+
args = mock_run.call_args
|
|
147
|
+
assert args[0][0] == ["repomix", "--version"]
|
|
148
|
+
|
|
149
|
+
@patch("subprocess.run")
|
|
150
|
+
def test_check_repomix_installed_failure(self, mock_run):
|
|
151
|
+
"""Test checking if repomix is installed (failure)."""
|
|
152
|
+
mock_run.return_value = Mock(returncode=1)
|
|
153
|
+
|
|
154
|
+
config = RepomixConfig()
|
|
155
|
+
processor = RepomixBatchProcessor(config)
|
|
156
|
+
assert processor.check_repomix_installed() is False
|
|
157
|
+
|
|
158
|
+
@patch("subprocess.run")
|
|
159
|
+
def test_check_repomix_installed_not_found(self, mock_run):
|
|
160
|
+
"""Test checking if repomix is not found."""
|
|
161
|
+
mock_run.side_effect = FileNotFoundError()
|
|
162
|
+
|
|
163
|
+
config = RepomixConfig()
|
|
164
|
+
processor = RepomixBatchProcessor(config)
|
|
165
|
+
assert processor.check_repomix_installed() is False
|
|
166
|
+
|
|
167
|
+
def test_get_extension(self):
|
|
168
|
+
"""Test getting file extension for style."""
|
|
169
|
+
assert RepomixBatchProcessor._get_extension("xml") == "xml"
|
|
170
|
+
assert RepomixBatchProcessor._get_extension("markdown") == "md"
|
|
171
|
+
assert RepomixBatchProcessor._get_extension("json") == "json"
|
|
172
|
+
assert RepomixBatchProcessor._get_extension("plain") == "txt"
|
|
173
|
+
assert RepomixBatchProcessor._get_extension("unknown") == "xml"
|
|
174
|
+
|
|
175
|
+
def test_build_command_local(self):
|
|
176
|
+
"""Test building command for local repository."""
|
|
177
|
+
config = RepomixConfig(style="markdown", remove_comments=True)
|
|
178
|
+
processor = RepomixBatchProcessor(config)
|
|
179
|
+
|
|
180
|
+
output_file = Path("output.md")
|
|
181
|
+
cmd = processor._build_command("/path/to/repo", output_file, is_remote=False)
|
|
182
|
+
|
|
183
|
+
assert cmd[0] == "repomix"
|
|
184
|
+
assert "/path/to/repo" in cmd
|
|
185
|
+
assert "--style" in cmd
|
|
186
|
+
assert "markdown" in cmd
|
|
187
|
+
assert "--remove-comments" in cmd
|
|
188
|
+
assert "-o" in cmd
|
|
189
|
+
|
|
190
|
+
def test_build_command_remote(self):
|
|
191
|
+
"""Test building command for remote repository."""
|
|
192
|
+
config = RepomixConfig()
|
|
193
|
+
processor = RepomixBatchProcessor(config)
|
|
194
|
+
|
|
195
|
+
output_file = Path("output.xml")
|
|
196
|
+
cmd = processor._build_command("owner/repo", output_file, is_remote=True)
|
|
197
|
+
|
|
198
|
+
assert cmd[0] == "npx"
|
|
199
|
+
assert "repomix" in cmd
|
|
200
|
+
assert "--remote" in cmd
|
|
201
|
+
assert "owner/repo" in cmd
|
|
202
|
+
|
|
203
|
+
def test_build_command_with_patterns(self):
|
|
204
|
+
"""Test building command with include/ignore patterns."""
|
|
205
|
+
config = RepomixConfig(
|
|
206
|
+
include_pattern="src/**/*.ts",
|
|
207
|
+
ignore_pattern="tests/**"
|
|
208
|
+
)
|
|
209
|
+
processor = RepomixBatchProcessor(config)
|
|
210
|
+
|
|
211
|
+
output_file = Path("output.xml")
|
|
212
|
+
cmd = processor._build_command("/path/to/repo", output_file, is_remote=False)
|
|
213
|
+
|
|
214
|
+
assert "--include" in cmd
|
|
215
|
+
assert "src/**/*.ts" in cmd
|
|
216
|
+
assert "-i" in cmd
|
|
217
|
+
assert "tests/**" in cmd
|
|
218
|
+
|
|
219
|
+
def test_build_command_verbose(self):
|
|
220
|
+
"""Test building command with verbose flag."""
|
|
221
|
+
config = RepomixConfig(verbose=True)
|
|
222
|
+
processor = RepomixBatchProcessor(config)
|
|
223
|
+
|
|
224
|
+
output_file = Path("output.xml")
|
|
225
|
+
cmd = processor._build_command("/path/to/repo", output_file, is_remote=False)
|
|
226
|
+
|
|
227
|
+
assert "--verbose" in cmd
|
|
228
|
+
|
|
229
|
+
def test_build_command_no_security_check(self):
|
|
230
|
+
"""Test building command with security check disabled."""
|
|
231
|
+
config = RepomixConfig(no_security_check=True)
|
|
232
|
+
processor = RepomixBatchProcessor(config)
|
|
233
|
+
|
|
234
|
+
output_file = Path("output.xml")
|
|
235
|
+
cmd = processor._build_command("/path/to/repo", output_file, is_remote=False)
|
|
236
|
+
|
|
237
|
+
assert "--no-security-check" in cmd
|
|
238
|
+
|
|
239
|
+
@patch("subprocess.run")
|
|
240
|
+
@patch("pathlib.Path.mkdir")
|
|
241
|
+
def test_process_repository_success(self, mock_mkdir, mock_run):
|
|
242
|
+
"""Test processing repository successfully."""
|
|
243
|
+
mock_run.return_value = Mock(returncode=0)
|
|
244
|
+
|
|
245
|
+
config = RepomixConfig()
|
|
246
|
+
processor = RepomixBatchProcessor(config)
|
|
247
|
+
|
|
248
|
+
success, message = processor.process_repository("/path/to/repo")
|
|
249
|
+
|
|
250
|
+
assert success is True
|
|
251
|
+
assert "Successfully processed" in message
|
|
252
|
+
mock_mkdir.assert_called_once()
|
|
253
|
+
mock_run.assert_called_once()
|
|
254
|
+
|
|
255
|
+
@patch("subprocess.run")
|
|
256
|
+
@patch("pathlib.Path.mkdir")
|
|
257
|
+
def test_process_repository_failure(self, mock_mkdir, mock_run):
|
|
258
|
+
"""Test processing repository with failure."""
|
|
259
|
+
mock_run.return_value = Mock(
|
|
260
|
+
returncode=1,
|
|
261
|
+
stderr="Error message",
|
|
262
|
+
stdout=""
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
config = RepomixConfig()
|
|
266
|
+
processor = RepomixBatchProcessor(config)
|
|
267
|
+
|
|
268
|
+
success, message = processor.process_repository("/path/to/repo")
|
|
269
|
+
|
|
270
|
+
assert success is False
|
|
271
|
+
assert "Failed to process" in message
|
|
272
|
+
assert "Error message" in message
|
|
273
|
+
|
|
274
|
+
@patch("subprocess.run")
|
|
275
|
+
@patch("pathlib.Path.mkdir")
|
|
276
|
+
def test_process_repository_timeout(self, mock_mkdir, mock_run):
|
|
277
|
+
"""Test processing repository with timeout."""
|
|
278
|
+
mock_run.side_effect = subprocess.TimeoutExpired(cmd=[], timeout=300)
|
|
279
|
+
|
|
280
|
+
config = RepomixConfig()
|
|
281
|
+
processor = RepomixBatchProcessor(config)
|
|
282
|
+
|
|
283
|
+
success, message = processor.process_repository("/path/to/repo")
|
|
284
|
+
|
|
285
|
+
assert success is False
|
|
286
|
+
assert "Timeout" in message
|
|
287
|
+
|
|
288
|
+
@patch("subprocess.run")
|
|
289
|
+
@patch("pathlib.Path.mkdir")
|
|
290
|
+
def test_process_repository_exception(self, mock_mkdir, mock_run):
|
|
291
|
+
"""Test processing repository with exception."""
|
|
292
|
+
mock_run.side_effect = Exception("Unexpected error")
|
|
293
|
+
|
|
294
|
+
config = RepomixConfig()
|
|
295
|
+
processor = RepomixBatchProcessor(config)
|
|
296
|
+
|
|
297
|
+
success, message = processor.process_repository("/path/to/repo")
|
|
298
|
+
|
|
299
|
+
assert success is False
|
|
300
|
+
assert "Error processing" in message
|
|
301
|
+
assert "Unexpected error" in message
|
|
302
|
+
|
|
303
|
+
@patch("subprocess.run")
|
|
304
|
+
@patch("pathlib.Path.mkdir")
|
|
305
|
+
def test_process_repository_with_custom_output(self, mock_mkdir, mock_run):
|
|
306
|
+
"""Test processing repository with custom output name."""
|
|
307
|
+
mock_run.return_value = Mock(returncode=0)
|
|
308
|
+
|
|
309
|
+
config = RepomixConfig()
|
|
310
|
+
processor = RepomixBatchProcessor(config)
|
|
311
|
+
|
|
312
|
+
success, message = processor.process_repository(
|
|
313
|
+
"/path/to/repo",
|
|
314
|
+
output_name="custom-output.xml"
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
assert success is True
|
|
318
|
+
assert "custom-output.xml" in message
|
|
319
|
+
|
|
320
|
+
@patch("subprocess.run")
|
|
321
|
+
@patch("pathlib.Path.mkdir")
|
|
322
|
+
def test_process_repository_remote(self, mock_mkdir, mock_run):
|
|
323
|
+
"""Test processing remote repository."""
|
|
324
|
+
mock_run.return_value = Mock(returncode=0)
|
|
325
|
+
|
|
326
|
+
config = RepomixConfig()
|
|
327
|
+
processor = RepomixBatchProcessor(config)
|
|
328
|
+
|
|
329
|
+
success, message = processor.process_repository(
|
|
330
|
+
"owner/repo",
|
|
331
|
+
is_remote=True
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
assert success is True
|
|
335
|
+
cmd = mock_run.call_args[0][0]
|
|
336
|
+
assert "npx" in cmd
|
|
337
|
+
assert "--remote" in cmd
|
|
338
|
+
|
|
339
|
+
@patch.object(RepomixBatchProcessor, "process_repository")
|
|
340
|
+
def test_process_batch_success(self, mock_process):
|
|
341
|
+
"""Test processing batch of repositories."""
|
|
342
|
+
mock_process.return_value = (True, "Success")
|
|
343
|
+
|
|
344
|
+
config = RepomixConfig()
|
|
345
|
+
processor = RepomixBatchProcessor(config)
|
|
346
|
+
|
|
347
|
+
repositories = [
|
|
348
|
+
{"path": "/repo1"},
|
|
349
|
+
{"path": "/repo2", "output": "custom.xml"},
|
|
350
|
+
{"path": "owner/repo", "remote": True}
|
|
351
|
+
]
|
|
352
|
+
|
|
353
|
+
results = processor.process_batch(repositories)
|
|
354
|
+
|
|
355
|
+
assert len(results["success"]) == 3
|
|
356
|
+
assert len(results["failed"]) == 0
|
|
357
|
+
assert mock_process.call_count == 3
|
|
358
|
+
|
|
359
|
+
@patch.object(RepomixBatchProcessor, "process_repository")
|
|
360
|
+
def test_process_batch_with_failures(self, mock_process):
|
|
361
|
+
"""Test processing batch with some failures."""
|
|
362
|
+
mock_process.side_effect = [
|
|
363
|
+
(True, "Success 1"),
|
|
364
|
+
(False, "Failed"),
|
|
365
|
+
(True, "Success 2")
|
|
366
|
+
]
|
|
367
|
+
|
|
368
|
+
config = RepomixConfig()
|
|
369
|
+
processor = RepomixBatchProcessor(config)
|
|
370
|
+
|
|
371
|
+
repositories = [
|
|
372
|
+
{"path": "/repo1"},
|
|
373
|
+
{"path": "/repo2"},
|
|
374
|
+
{"path": "/repo3"}
|
|
375
|
+
]
|
|
376
|
+
|
|
377
|
+
results = processor.process_batch(repositories)
|
|
378
|
+
|
|
379
|
+
assert len(results["success"]) == 2
|
|
380
|
+
assert len(results["failed"]) == 1
|
|
381
|
+
|
|
382
|
+
def test_process_batch_missing_path(self):
|
|
383
|
+
"""Test processing batch with missing path."""
|
|
384
|
+
config = RepomixConfig()
|
|
385
|
+
processor = RepomixBatchProcessor(config)
|
|
386
|
+
|
|
387
|
+
repositories = [
|
|
388
|
+
{"output": "custom.xml"} # Missing 'path'
|
|
389
|
+
]
|
|
390
|
+
|
|
391
|
+
results = processor.process_batch(repositories)
|
|
392
|
+
|
|
393
|
+
assert len(results["success"]) == 0
|
|
394
|
+
assert len(results["failed"]) == 1
|
|
395
|
+
assert "Missing 'path'" in results["failed"][0]
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
class TestLoadRepositoriesFromFile:
|
|
399
|
+
"""Test load_repositories_from_file function."""
|
|
400
|
+
|
|
401
|
+
def test_load_valid_json(self, tmp_path):
|
|
402
|
+
"""Test loading valid JSON file."""
|
|
403
|
+
json_file = tmp_path / "repos.json"
|
|
404
|
+
repos = [
|
|
405
|
+
{"path": "/repo1"},
|
|
406
|
+
{"path": "owner/repo", "remote": True}
|
|
407
|
+
]
|
|
408
|
+
json_file.write_text(json.dumps(repos))
|
|
409
|
+
|
|
410
|
+
result = load_repositories_from_file(str(json_file))
|
|
411
|
+
assert result == repos
|
|
412
|
+
|
|
413
|
+
def test_load_invalid_json(self, tmp_path):
|
|
414
|
+
"""Test loading invalid JSON file."""
|
|
415
|
+
json_file = tmp_path / "invalid.json"
|
|
416
|
+
json_file.write_text("not valid json {")
|
|
417
|
+
|
|
418
|
+
result = load_repositories_from_file(str(json_file))
|
|
419
|
+
assert result == []
|
|
420
|
+
|
|
421
|
+
def test_load_non_array_json(self, tmp_path):
|
|
422
|
+
"""Test loading JSON file with non-array content."""
|
|
423
|
+
json_file = tmp_path / "object.json"
|
|
424
|
+
json_file.write_text('{"path": "/repo"}')
|
|
425
|
+
|
|
426
|
+
result = load_repositories_from_file(str(json_file))
|
|
427
|
+
assert result == []
|
|
428
|
+
|
|
429
|
+
def test_load_nonexistent_file(self):
|
|
430
|
+
"""Test loading non-existent file."""
|
|
431
|
+
result = load_repositories_from_file("/nonexistent/file.json")
|
|
432
|
+
assert result == []
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
class TestMain:
|
|
436
|
+
"""Test main function."""
|
|
437
|
+
|
|
438
|
+
@patch("sys.argv", ["repomix_batch.py", "/repo1", "/repo2"])
|
|
439
|
+
@patch.object(RepomixBatchProcessor, "check_repomix_installed", return_value=True)
|
|
440
|
+
@patch.object(RepomixBatchProcessor, "process_batch")
|
|
441
|
+
def test_main_with_repos(self, mock_process_batch, mock_check):
|
|
442
|
+
"""Test main function with repository arguments."""
|
|
443
|
+
mock_process_batch.return_value = {"success": ["msg1", "msg2"], "failed": []}
|
|
444
|
+
|
|
445
|
+
result = main()
|
|
446
|
+
|
|
447
|
+
assert result == 0
|
|
448
|
+
mock_check.assert_called_once()
|
|
449
|
+
mock_process_batch.assert_called_once()
|
|
450
|
+
|
|
451
|
+
# Verify repositories passed
|
|
452
|
+
call_args = mock_process_batch.call_args[0][0]
|
|
453
|
+
assert len(call_args) == 2
|
|
454
|
+
assert call_args[0]["path"] == "/repo1"
|
|
455
|
+
assert call_args[1]["path"] == "/repo2"
|
|
456
|
+
|
|
457
|
+
@patch("sys.argv", ["repomix_batch.py", "-f", "repos.json"])
|
|
458
|
+
@patch.object(RepomixBatchProcessor, "check_repomix_installed", return_value=True)
|
|
459
|
+
@patch.object(RepomixBatchProcessor, "process_batch")
|
|
460
|
+
@patch("repomix_batch.load_repositories_from_file")
|
|
461
|
+
def test_main_with_file(self, mock_load, mock_process_batch, mock_check):
|
|
462
|
+
"""Test main function with file argument."""
|
|
463
|
+
mock_load.return_value = [{"path": "/repo1"}]
|
|
464
|
+
mock_process_batch.return_value = {"success": ["msg1"], "failed": []}
|
|
465
|
+
|
|
466
|
+
result = main()
|
|
467
|
+
|
|
468
|
+
assert result == 0
|
|
469
|
+
mock_load.assert_called_once_with("repos.json")
|
|
470
|
+
mock_process_batch.assert_called_once()
|
|
471
|
+
|
|
472
|
+
@patch("sys.argv", ["repomix_batch.py"])
|
|
473
|
+
@patch.object(RepomixBatchProcessor, "check_repomix_installed", return_value=True)
|
|
474
|
+
def test_main_no_repos(self, mock_check):
|
|
475
|
+
"""Test main function with no repositories."""
|
|
476
|
+
result = main()
|
|
477
|
+
assert result == 1
|
|
478
|
+
|
|
479
|
+
@patch("sys.argv", ["repomix_batch.py", "/repo1"])
|
|
480
|
+
@patch.object(RepomixBatchProcessor, "check_repomix_installed", return_value=False)
|
|
481
|
+
def test_main_repomix_not_installed(self, mock_check):
|
|
482
|
+
"""Test main function when repomix is not installed."""
|
|
483
|
+
result = main()
|
|
484
|
+
assert result == 1
|
|
485
|
+
|
|
486
|
+
@patch("sys.argv", ["repomix_batch.py", "/repo1"])
|
|
487
|
+
@patch.object(RepomixBatchProcessor, "check_repomix_installed", return_value=True)
|
|
488
|
+
@patch.object(RepomixBatchProcessor, "process_batch")
|
|
489
|
+
def test_main_with_failures(self, mock_process_batch, mock_check):
|
|
490
|
+
"""Test main function with processing failures."""
|
|
491
|
+
mock_process_batch.return_value = {
|
|
492
|
+
"success": ["msg1"],
|
|
493
|
+
"failed": ["error1"]
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
result = main()
|
|
497
|
+
assert result == 1
|
|
498
|
+
|
|
499
|
+
@patch("sys.argv", [
|
|
500
|
+
"repomix_batch.py",
|
|
501
|
+
"/repo1",
|
|
502
|
+
"--style", "markdown",
|
|
503
|
+
"--remove-comments",
|
|
504
|
+
"--verbose"
|
|
505
|
+
])
|
|
506
|
+
@patch.object(RepomixBatchProcessor, "check_repomix_installed", return_value=True)
|
|
507
|
+
@patch.object(RepomixBatchProcessor, "process_batch")
|
|
508
|
+
def test_main_with_options(self, mock_process_batch, mock_check):
|
|
509
|
+
"""Test main function with various options."""
|
|
510
|
+
mock_process_batch.return_value = {"success": ["msg1"], "failed": []}
|
|
511
|
+
|
|
512
|
+
result = main()
|
|
513
|
+
assert result == 0
|
|
514
|
+
|
|
515
|
+
# Verify config passed to processor
|
|
516
|
+
# The processor is created inside main, so we check it was called
|
|
517
|
+
mock_process_batch.assert_called_once()
|
|
518
|
+
|
|
519
|
+
@patch("sys.argv", ["repomix_batch.py", "/repo1", "--remote"])
|
|
520
|
+
@patch.object(RepomixBatchProcessor, "check_repomix_installed", return_value=True)
|
|
521
|
+
@patch.object(RepomixBatchProcessor, "process_batch")
|
|
522
|
+
def test_main_with_remote_flag(self, mock_process_batch, mock_check):
|
|
523
|
+
"""Test main function with --remote flag."""
|
|
524
|
+
mock_process_batch.return_value = {"success": ["msg1"], "failed": []}
|
|
525
|
+
|
|
526
|
+
result = main()
|
|
527
|
+
assert result == 0
|
|
528
|
+
|
|
529
|
+
# Verify remote flag is set
|
|
530
|
+
call_args = mock_process_batch.call_args[0][0]
|
|
531
|
+
assert call_args[0]["remote"] is True
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: research
|
|
3
|
+
description: Nghiên cứu kỹ thuật từ nguồn ngoài — đánh giá công nghệ, đối chiếu nhiều nguồn, xếp hạng phương án theo ngữ cảnh project. Kích hoạt khi cần biết nên chọn thư viện nào, cách làm nào đang là chuẩn, hoặc một khẳng định ngoài repo có đúng không.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# research — đánh giá, không chỉ tìm
|
|
7
|
+
|
|
8
|
+
Việc của bạn không phải mang về một đống link, mà là **xếp hạng có lý do**. Trình bày
|
|
9
|
+
phương án mà không xếp hạng là đẩy việc khó ngược về cho người hỏi.
|
|
10
|
+
|
|
11
|
+
## Trước khi tìm
|
|
12
|
+
|
|
13
|
+
1. **Kiểm memory trước.** `memory/shared/reference/` và `memory/projects/<slug>/refs/` —
|
|
14
|
+
research trùng là lãng phí kép: tốn phiên này, và sinh ra bản thứ hai lệch với bản cũ.
|
|
15
|
+
2. **Viết yêu cầu thành câu hỏi kiểm chứng được.** "React tốt không" không kiểm chứng được.
|
|
16
|
+
"Bản 19 có breaking change nào ảnh hưởng code hiện tại của project X" thì có.
|
|
17
|
+
3. **Chốt yêu cầu độ mới.** Bảo mật và phiên bản → 12 tháng gần nhất. Nguyên lý thiết kế →
|
|
18
|
+
cũ vẫn dùng được.
|
|
19
|
+
|
|
20
|
+
## Ngân sách
|
|
21
|
+
|
|
22
|
+
**Tối đa 5 lượt tìm** cho một yêu cầu, trừ khi được nói khác. Nói ít hơn thì theo con số đó.
|
|
23
|
+
|
|
24
|
+
Ngân sách này có lý do: một phiên nghiên cứu tồn tại để **giữ context của người giao việc
|
|
25
|
+
sạch**. Tìm 20 lượt rồi đổ hết về là phá đúng mục đích đó.
|
|
26
|
+
|
|
27
|
+
Nghĩ kỹ từng truy vấn trước khi gọi. Chạy song song nhiều truy vấn độc lập thay vì nối
|
|
28
|
+
tiếp từng cái một.
|
|
29
|
+
|
|
30
|
+
## Tìm
|
|
31
|
+
|
|
32
|
+
Tool có sẵn: `WebSearch`, `WebFetch`, `Bash`, `Read`, `Glob`, `Grep`.
|
|
33
|
+
|
|
34
|
+
- Truy vấn cụ thể, kèm phiên bản và năm khi độ mới quan trọng.
|
|
35
|
+
- Ưu tiên **nguồn sơ cấp**: tài liệu chính thức, changelog, release note, RFC, source trên
|
|
36
|
+
GitHub. Blog xếp sau, blog tổng hợp lại xếp sau nữa.
|
|
37
|
+
- Gặp URL repo GitHub → dùng skill `docs-seeker` để đọc, đừng đoán từ README.
|
|
38
|
+
- **Ghi phiên bản và ngày** của mọi nguồn. Không có ngày thì ghi "không rõ ngày" — đó là
|
|
39
|
+
thông tin, không phải chi tiết bỏ được.
|
|
40
|
+
|
|
41
|
+
## Đối chiếu
|
|
42
|
+
|
|
43
|
+
**Khẳng định quan trọng phải có ít nhất hai nguồn độc lập.** Hai bài blog cùng chép từ một
|
|
44
|
+
tài liệu gốc là **một** nguồn, không phải hai.
|
|
45
|
+
|
|
46
|
+
Phân biệt rõ ba loại và nói rõ loại nào trong báo cáo:
|
|
47
|
+
|
|
48
|
+
| Loại | Cách viết |
|
|
49
|
+
|---|---|
|
|
50
|
+
| Đồng thuận | "tài liệu chính thức và X đều nói…" |
|
|
51
|
+
| Đang tranh cãi | "X khuyến nghị A, Y phản đối vì…" — nêu cả hai, đừng chọn hộ |
|
|
52
|
+
| Chỉ một nguồn | "chỉ thấy ở X, chưa đối chiếu được" |
|
|
53
|
+
|
|
54
|
+
## Mẫu báo cáo
|
|
55
|
+
|
|
56
|
+
Ngắn. Hy sinh ngữ pháp cho cô đọng.
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
## Nghiên cứu: <câu hỏi>
|
|
60
|
+
|
|
61
|
+
### Kết luận
|
|
62
|
+
<2–4 câu. Khuyến nghị gì, vì sao. Đặt ngay đầu — đây là dòng được đọc trước.>
|
|
63
|
+
|
|
64
|
+
### Xếp hạng phương án
|
|
65
|
+
|
|
66
|
+
| Phương án | Hợp khi | Đánh đổi | Rủi ro áp dụng | Độ chín |
|
|
67
|
+
|---|---|---|---|---|
|
|
68
|
+
| A | … | … | … | … |
|
|
69
|
+
|
|
70
|
+
### Bằng chứng
|
|
71
|
+
- <khẳng định> — <nguồn, phiên bản, ngày> · <nguồn thứ hai>
|
|
72
|
+
|
|
73
|
+
### Không áp dụng được cho project này
|
|
74
|
+
<phần đọc thấy nhưng lệch ngữ cảnh — nói rõ vì sao lệch>
|
|
75
|
+
|
|
76
|
+
### Câu hỏi còn mở
|
|
77
|
+
<phần chưa trả lời được và cần gì để trả lời>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Ghi vào đâu
|
|
81
|
+
|
|
82
|
+
Bạn **ghi được** hai chỗ, đúng như `PLAYBOOK.md` bước 5:
|
|
83
|
+
|
|
84
|
+
| Nội dung | Đường dẫn |
|
|
85
|
+
|---|---|
|
|
86
|
+
| tài liệu tham chiếu dùng chung, còn giá trị lâu | `memory/shared/reference/` |
|
|
87
|
+
| tài liệu gắn với một project cụ thể | `memory/projects/<slug>/refs/` |
|
|
88
|
+
| nháp, fact chưa kiểm chứng | kho riêng của bạn trong `memory/private/` |
|
|
89
|
+
|
|
90
|
+
Đó là **toàn bộ** quyền ghi của bạn. `memory/shared/decisions/`, `memory/projects/<slug>/PROJECT.md`
|
|
91
|
+
và mọi thứ khác đều **chỉ đọc** — đúng với SOUL: *"Không ghi decision/L1."*
|
|
92
|
+
|
|
93
|
+
Quyết định không phải việc của bạn. Bạn ghi thứ mình đã kiểm chứng được; bên giao việc
|
|
94
|
+
quyết định nó đổi điều gì.
|
|
95
|
+
|
|
96
|
+
- **Kết luận vẫn đi về bên giao việc** trong phiên.
|
|
97
|
+
- Report dài thì ghi file rồi **đưa đường dẫn**, đừng dán cả nội dung vào câu trả lời.
|
|
98
|
+
- Cập nhật `memory/INDEX.md` thì phải xem loadout có cấp quyền ghi file đó không. Không
|
|
99
|
+
có thì báo lại, đừng tìm đường vòng.
|
|
100
|
+
|
|
101
|
+
## Ranh giới
|
|
102
|
+
|
|
103
|
+
- Không ghi decision hay L1.
|
|
104
|
+
- Không kết luận về code trong repo — đó là việc của một lượt truy xuất code. Bạn lo nguồn
|
|
105
|
+
**ngoài**.
|
|
106
|
+
- Không chắc thì nói không chắc. Một câu "chưa đối chiếu được" trung thực đáng giá hơn một
|
|
107
|
+
đoạn tự tin sai.
|