Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .claude/skills/issue-contract-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ script は各 VC 実行結果を以下の category で分類(classify_result
| `unsupported_shell_syntax` | `$(...)` / backtick / `${...}` を含む、または shlex parse 失敗 | blocked | 実行前静的遮断。run_command() を呼ばない |
| `unsafe_command` | `bash`, `sh`, `python -c`, `python3 -c`, `curl`, `wget`, `rm`, `mv`, `git push`, `git commit` 等の危険コマンド | blocked | 実行前静的遮断。run_command() を呼ばない |
| `command_not_allowed` | allowlist 外のコマンド(default blocked)、`gh api`, `pnpm add`, `npm install` 等 | blocked | 実行前静的遮断。run_command() を呼ばない |
| `trivially_pass` | `match-ssot.sh` / `match_ssot.py` 等の **repository-local discovery script** が `--keywords` と `--paths` を**同時使用**している。directory mapping により `--paths` 指定パスが keyword 不在でも `matched_documents` に強制 include される構造 | blocked | 実行前静的遮断。`--keywords` + `--paths` 併用は VC baseline fail の証拠にならない |
| `file_not_found_expected` | `test -f` / `test -d` + exit 1 | go | 期待通り baseline fail |
| `file_not_found_unrunnable` | `No such file or directory` stderr + 実行対象 missing | blocked | 想定外の missing |
| `env_missing_dep` | stderr に `No module named` / `ModuleNotFoundError` / `command not found` / `Permission denied` 等 or exit 126/127 | blocked | 環境不備 |
Expand All @@ -164,6 +165,7 @@ script は各 VC 実行結果を以下の category で分類(classify_result
c. denied command(bash, sh, curl 等) → `unsafe_command` / blocked
d. git/gh/pnpm mutation subcommand → `unsafe_command` / `command_not_allowed` / blocked
e. allowlist 外コマンド → `command_not_allowed` / blocked
f. discovery script(`match-ssot.sh` / `match_ssot.py`)の `--keywords` + `--paths` 同時使用 → `trivially_pass` / blocked(denied-command 検出より先に実施 — `bash match-ssot.sh ...` が `bash` の denied-command 判定より前に正確なカテゴリで捕捉される)
1. compound command 検出 → `compound_command_disallowed` / blocked
2. timeout 検出 → `timeout` / blocked
3. exit_code = 0 → `unexpected_pass` / blocked
Expand Down Expand Up @@ -292,6 +294,15 @@ gh issue view <番号> --json body --jq '.body' | grep -A 20 "Runtime Verificati

1 つでも fail → BLOCKED。`issue-refinement-loop` を提案。

#### discovery 系スクリプトの `--paths` 強制 include パターン

`match-ssot.sh` / `match_ssot.py` 等の **repository-local discovery script** が `--paths` を `--keywords` と同時使用すると、directory mapping により指定パスが keyword 不在でも `matched_documents` に強制 include される。これは **AC 単独の証拠にならない**。

- `--keywords` + `--paths` の両方を含む discovery script 呼び出しは `baseline_vc_preflight.py` が `category: trivially_pass` / `decision: blocked` と判定する
- 同じ path が `--keywords` のみ(`--paths` なし)のクエリでも返ることを追加 VC として要求する
- `--paths` forced include は VC の差分性(baseline fail → 実装後 pass)を担保しないため、AC の証拠能力がない
- 注意: `rg` / `grep` には `--paths` オプションは**存在しない**。rg はポジショナル PATH 引数と `-g/--glob` でパス指定する。rg/grep のポジショナル path 引数は forced-include ではなく trivially_pass ではない

### 6. Worktree / Branch 命名 preflight

```bash
Expand Down
132 changes: 132 additions & 0 deletions .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,117 @@ def _is_negated_search_command(command: str) -> bool:
return any(rest.startswith(util) for util in ["rg", "grep"])


def _is_discovery_script(argv: List[str]) -> bool:
"""
Detect if a command invokes a repository-local ssot-discovery script.

Discovery scripts are identified by:
- basename being 'match-ssot.sh' or 'match_ssot.py'
- OR the script path containing 'ssot-discovery/scripts/'

Handles invocation forms:
- bash .claude/skills/ssot-discovery/scripts/match-ssot.sh ...
- .claude/skills/ssot-discovery/scripts/match-ssot.sh ... (direct)
- python3 .../match_ssot.py ...
- uv run python3 .../match_ssot.py ...
"""
if not argv:
return False

# Unwrap 'bash' / 'sh' prefix: argv[0] is shell, look for script in rest
leading = argv[0]
script_candidates = []

cmd_basename = Path(leading).name
if cmd_basename in ("bash", "sh", "zsh"):
# Script is first non-option argument after shell invocator
script_candidates = [a for a in argv[1:] if not a.startswith("-")]
elif cmd_basename in ("python", "python3"):
# python3 .../match_ssot.py ... or python3 -m <module>
# For file-based invocation, script is first non-option positional arg
script_candidates = [a for a in argv[1:] if not a.startswith("-")]
elif cmd_basename == "uv":
# uv run [options] python3 .../match_ssot.py ...
# Unwrap uv run options
unwrapped = _strip_uv_run_options(argv)
if unwrapped and Path(unwrapped[0]).name in ("python", "python3"):
script_candidates = [a for a in unwrapped[1:] if not a.startswith("-")]
elif unwrapped:
script_candidates = [unwrapped[0]]
else:
# Direct invocation: check argv[0] itself
script_candidates = [leading]

for candidate in script_candidates:
bname = Path(candidate).name
if bname in ("match-ssot.sh", "match_ssot.py"):
return True
if "ssot-discovery/scripts/" in candidate:
return True

return False


def _has_arg(argv: List[str], flag: str) -> bool:
"""
Check if flag (e.g. '--keywords' or '--paths') appears in argv,
either as a standalone argument or as the key in '--flag=value' form.
"""
for arg in argv:
if arg == flag or arg.startswith(flag + "="):
return True
return False


def _is_trivially_pass_command(command: str) -> bool:
"""
Detect trivially-pass VC patterns: repository-local ssot-discovery scripts
called with BOTH --keywords and --paths options simultaneously.

Root cause (Issue #201):
match-ssot.sh / match_ssot.py implements a directory mapping that forces
--paths targets into matched_documents at low relevance, regardless of
whether --keywords actually appear in that path. When both --keywords and
--paths are supplied, the VC can return the target path (exit 0) even
when the keywords are absent — making the VC trivially-passing.

Detection logic:
- The command invokes a discovery script (match-ssot.sh / match_ssot.py /
any script under ssot-discovery/scripts/)
- AND the argument list contains BOTH --keywords (or --keywords=...) AND
--paths (or --paths=...)

Only the combination of --keywords + --paths creates the trivially-pass
structure. --keywords alone or --paths alone does not trigger this.

Note: rg/grep have no '--paths' option. rg uses positional PATH arguments
and -g/--glob for path filtering. Positional paths in rg/grep are not
forced-includes and are NOT trivially-pass. The previous implementation
that flagged rg/grep + '--paths' was based on an incorrect premise and
caused false positives for queries like 'rg -e "--paths" file' or
'rg -- "--paths" file'. That logic has been removed.

Returns True if the command is a trivially-pass pattern, False otherwise.
"""
try:
argv = shlex.split(command)
except ValueError:
return False

if not argv:
return False

# Step 1: Identify whether this is a discovery script invocation
if not _is_discovery_script(argv):
return False

# Step 2: Check for --keywords AND --paths both present
# Only the combination creates the forced-include trivially-pass structure.
has_keywords = _has_arg(argv, "--keywords")
has_paths = _has_arg(argv, "--paths")
return has_keywords and has_paths


def has_command_substitution(command: str) -> bool:
"""
B3: Detect command substitution patterns: $(...), `...`, ${...}
Expand Down Expand Up @@ -723,6 +834,26 @@ def classify_static_command(
"baseline_fail_expected",
)

# 3.5. Trivially-pass detection: discovery script with --keywords + --paths.
# NOTE: This check runs BEFORE denied-command detection (step 4) so that
# 'bash match-ssot.sh --keywords ... --paths ...' is reported as
# category: trivially_pass rather than category: unsafe_command.
# Both results are classification: blocked / decision: blocked / exit_code: None
# (neither is executed), so moving this check earlier is a category-label
# correction, not a safety relaxation.
if _is_trivially_pass_command(raw_command):
return (
"blocked",
"trivially_pass",
"blocked",
"Discovery script (match-ssot.sh / match_ssot.py) is called with both "
"--keywords and --paths; the directory mapping in match-ssot forces --paths "
"targets into matched_documents regardless of keyword presence, making the VC "
"trivially pass. Use --keywords only (without --paths) and verify the same path "
"appears in results to confirm keyword presence.",
"baseline_fail_expected",
)

# 4. Check denied commands (unsafe, AC2)
if cmd_basename in _DENIED_COMMANDS:
return (
Expand Down Expand Up @@ -1030,6 +1161,7 @@ def compute_confidence(category: str) -> str:
"env_missing_dep",
"file_not_found_unrunnable",
"vc_no_tests_collected",
"trivially_pass",
}
medium_confidence = {"timeout", "unexpected_pass"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,173 @@ def test_pytest_no_tests_exit5_in_preflight():
assert classification == "blocked"
assert category == "vc_no_tests_collected"
assert decision == "blocked"


# ---------------------------------------------------------------------------
# trivially_pass: ssot-discovery script --keywords + --paths detection (#201)
# ---------------------------------------------------------------------------

def test_match_ssot_with_keywords_and_paths_is_trivially_pass_blocked():
"""AC1(#201): bash match-ssot.sh --keywords ... --paths ... → blocked / trivially_pass

Regression test for the original failing case from Issue #201 background section.
"""
body = """## Verification Commands

```bash
# AC1
$ bash .claude/skills/ssot-discovery/scripts/match-ssot.sh --keywords "milestone,github-milestone" --paths "docs/dev/milestone-ops.md"
```
"""
data = run_preflight(body)
results = data["results"]
assert len(results) == 1
r = results[0]
assert r["classification"] == "blocked", f"Expected blocked, got {r['classification']}"
assert r["category"] == "trivially_pass", f"Expected trivially_pass, got {r['category']}"
assert r["decision"] == "blocked", f"Expected decision=blocked, got {r['decision']}"
# Must not be executed (static classification before denied-command check)
assert r["exit_code"] is None, f"Expected exit_code=None (not executed), got {r['exit_code']}"
assert r["confidence"] == "high", f"Expected confidence=high, got {r['confidence']}"


def test_match_ssot_direct_invocation_is_trivially_pass_blocked():
"""AC1(#201): direct execution of match-ssot.sh → blocked / trivially_pass"""
body = """## Verification Commands

```bash
# AC1
$ .claude/skills/ssot-discovery/scripts/match-ssot.sh --keywords "foo" --paths "docs/dev/bar.md"
```
"""
data = run_preflight(body)
results = data["results"]
assert len(results) == 1
r = results[0]
assert r["classification"] == "blocked"
assert r["category"] == "trivially_pass"
assert r["decision"] == "blocked"
assert r["exit_code"] is None


def test_match_ssot_py_via_python3_is_trivially_pass_blocked():
"""AC1(#201): python3 .../match_ssot.py --keywords ... --paths ... → blocked / trivially_pass"""
body = """## Verification Commands

```bash
# AC1
$ python3 .claude/skills/ssot-discovery/scripts/match_ssot.py --keywords "foo,bar" --paths "docs/dev/baz.md"
```
"""
data = run_preflight(body)
results = data["results"]
assert len(results) == 1
r = results[0]
assert r["classification"] == "blocked"
assert r["category"] == "trivially_pass"
assert r["decision"] == "blocked"
assert r["exit_code"] is None


def test_match_ssot_keywords_only_is_not_trivially_pass():
"""AC1(#201): match-ssot.sh --keywords only (no --paths) → NOT trivially_pass"""
body = """## Verification Commands

```bash
# AC1
$ bash .claude/skills/ssot-discovery/scripts/match-ssot.sh --keywords "milestone,github-milestone"
```
"""
data = run_preflight(body)
results = data["results"]
assert len(results) == 1
r = results[0]
# --keywords alone does not create a trivially-pass structure
assert r["category"] != "trivially_pass", (
f"Expected NOT trivially_pass for --keywords only, got {r['category']}"
)


def test_match_ssot_paths_only_is_not_trivially_pass():
"""AC1(#201): match-ssot.sh --paths only (no --keywords) → NOT trivially_pass"""
body = """## Verification Commands

```bash
# AC1
$ bash .claude/skills/ssot-discovery/scripts/match-ssot.sh --paths "docs/dev/milestone-ops.md"
```
"""
data = run_preflight(body)
results = data["results"]
assert len(results) == 1
r = results[0]
# --paths alone does not create the trivially-pass structure
assert r["category"] != "trivially_pass", (
f"Expected NOT trivially_pass for --paths only, got {r['category']}"
)


def test_rg_without_paths_is_not_trivially_pass():
"""AC1(#201): rg without discovery script → NOT trivially_pass"""
body = """## Verification Commands

```bash
# AC1
$ rg -n "some_new_function" .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
```
"""
data = run_preflight(body)
results = data["results"]
assert len(results) == 1
r = results[0]
# Normal rg search is NOT trivially_pass regardless of path arguments
assert r["category"] != "trivially_pass", f"Expected not trivially_pass, got {r['category']}"


def test_rg_literal_paths_pattern_is_not_trivially_pass():
"""AC1(#201): rg searching for '--paths' as a literal string must NOT be flagged as trivially_pass.

False positive guard: 'rg -e "--paths" file' and 'rg -- "--paths" file' are
legitimate VC searches for the literal text '--paths' and must not be blocked
as trivially_pass (rg has no --paths option; this is a search pattern argument).
"""
from baseline_vc_preflight import _is_trivially_pass_command
# Searching for the text "--paths" with -e flag
assert _is_trivially_pass_command('rg -n -e "--paths" docs/dev/dor.md') is False
# Using -- to separate pattern from file arguments
assert _is_trivially_pass_command('rg -n -- "--paths" docs/dev/dor.md') is False
# Plain grep searching for --paths text
assert _is_trivially_pass_command('grep -n "--paths" docs/dev/dor.md') is False


def test_is_trivially_pass_unit_direct():
"""Unit tests for _is_trivially_pass_command directly."""
from baseline_vc_preflight import _is_trivially_pass_command

# Trivially pass patterns: discovery script + --keywords + --paths
assert _is_trivially_pass_command(
"bash .claude/skills/ssot-discovery/scripts/match-ssot.sh --keywords foo --paths bar.md"
) is True
assert _is_trivially_pass_command(
".claude/skills/ssot-discovery/scripts/match-ssot.sh --keywords=foo --paths=bar.md"
) is True
assert _is_trivially_pass_command(
"python3 .claude/skills/ssot-discovery/scripts/match_ssot.py --keywords foo --paths bar"
) is True

# NOT trivially pass: discovery script with only one of the flags
assert _is_trivially_pass_command(
"bash .claude/skills/ssot-discovery/scripts/match-ssot.sh --keywords foo"
) is False
assert _is_trivially_pass_command(
"bash .claude/skills/ssot-discovery/scripts/match-ssot.sh --paths bar.md"
) is False

# NOT trivially pass: rg/grep are not discovery scripts
assert _is_trivially_pass_command("rg -n 'pattern' src/") is False
assert _is_trivially_pass_command("rg 'pattern' --paths=some/file.py") is False
assert _is_trivially_pass_command("grep -n 'pattern' --paths some/file.py") is False

# NOT trivially pass: unrelated commands
assert _is_trivially_pass_command("pnpm lint") is False
assert _is_trivially_pass_command("test -f somefile") is False
10 changes: 10 additions & 0 deletions docs/dev/dor.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ VC は「実装前 baseline で fail し、実装後に pass に変化する」
- **使用不可**: 既存コードにすでに存在する文字列・パス・シンボルへの `rg` / `grep`(baseline で exit 0 となり `baseline_fail_expected` にならないため VC として機能しない)
- この場合は `# preflight-scope: pr_review_only` に振るか、実装後にのみ存在するパターンに変更する

#### trivially-pass 禁止

`match-ssot.sh` / `match_ssot.py` 等の **repository-local discovery script** で `--keywords` と `--paths` を**同時使用**することは、**VC baseline fail の証拠とならない**。

- discovery script の directory mapping は `--paths` 指定パスを keyword 不在でも `matched_documents` に強制 include するため、実装前でも後でも同じパスが返りうる
- この構造は VC の差分性(baseline fail → 実装後 pass)を破壊する「trivially-pass」パターンである
- `baseline_vc_preflight.py` は discovery script に `--keywords` + `--paths` を同時使用するコマンドを `category: trivially_pass` / `decision: blocked` と判定する(呼び出し形態 `bash match-ssot.sh` / 直接実行 / `python3 match_ssot.py` / `uv run python3 match_ssot.py` すべて対象)
- 修正方法: `--paths` を除去し `--keywords` のみで目的のパスが返ることを確認する追加 VC を設ける
- 注意: `rg` / `grep` には `--paths` オプションは**存在しない**。rg はポジショナル PATH 引数と `-g/--glob` でパス指定する。rg/grep のポジショナル path 指定は forced-include ではなく trivially-pass に該当しない

#### `rg` / `grep` exit code の意味

| exit code | 意味 | VC としての扱い |
Expand Down
Loading