Repository navigation
fix(delivery-gate): honor stop_hook_active and match Claude Code project dir encoding #3575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jwcastillo
wants to merge
3
commits into
affaan-m:main
from
jwcastillo:fix/delivery-gate-stop-hook-active
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
a1385c4
fix(delivery-gate): honor stop_hook_active and match Claude Code proj…
jwcastillo fe861f8
test(delivery-gate): select an interpreter only if it runs Python 3
jwcastillo 353cfa2
docs(delivery-gate): document that a missing memory directory only warns
jwcastillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /** | ||
| * Subprocess tests for skills/delivery-gate/hooks/quality-gate.py. | ||
| * | ||
| * Run with: node tests/skills/delivery-gate-quality-gate.test.js | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const path = require('path'); | ||
| const { spawnSync } = require('child_process'); | ||
|
|
||
| const SCRIPT = path.join(__dirname, '..', '..', 'skills', 'delivery-gate', 'hooks', 'quality-gate.py'); | ||
|
|
||
| function findPython() { | ||
| const candidates = [ | ||
| { command: process.env.PYTHON, args: [] }, | ||
| { command: 'python3', args: [] }, | ||
| { command: 'python', args: [] }, | ||
| { command: 'py', args: ['-3'] }, | ||
| ].filter(candidate => candidate.command); | ||
|
|
||
| // Probe for Python 3 itself: a Python 2 `--version` also exits 0, but the | ||
| // driver below needs importlib.util. | ||
| for (const candidate of candidates) { | ||
| const result = spawnSync(candidate.command, [...candidate.args, '-c', 'import sys; sys.exit(sys.version_info[0] != 3)'], { | ||
| encoding: 'utf8', | ||
| timeout: 5000, | ||
| }); | ||
| if (result.status === 0) { | ||
| return candidate; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| const PYTHON = findPython(); | ||
|
|
||
| // Load the hyphenated hook file as a module and pin the disk check (free GB in | ||
| // argv[2]), so the result does not depend on the test machine's free space. | ||
| const DRIVER = [ | ||
| 'import importlib.util, sys', | ||
| 'spec = importlib.util.spec_from_file_location("quality_gate", sys.argv[1])', | ||
| 'm = importlib.util.module_from_spec(spec)', | ||
| 'spec.loader.exec_module(m)', | ||
| 'm.check_disk = lambda: int(sys.argv[2])', | ||
| 'm.main()', | ||
| ].join('\n'); | ||
|
|
||
| function test(name, fn) { | ||
| try { | ||
| fn(); | ||
| console.log(` ✓ ${name}`); | ||
| return true; | ||
| } catch (err) { | ||
| console.log(` ✗ ${name}`); | ||
| console.log(` Error: ${err.message}`); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function setup() { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), 'delivery-gate-')); | ||
| const home = path.join(root, 'home'); | ||
| const project = path.join(root, 'My Project_v1.2'); | ||
| fs.mkdirSync(project, { recursive: true }); | ||
|
|
||
| // Claude Code maps every non-alphanumeric character to '-'. | ||
| const encoded = project.replace(/[^A-Za-z0-9]/g, '-'); | ||
| const memDir = path.join(home, '.claude', 'projects', encoded, 'memory'); | ||
| fs.mkdirSync(memDir, { recursive: true }); // present, but no learning libs | ||
|
|
||
| const transcript = path.join(root, 'transcript.jsonl'); | ||
| fs.writeFileSync(transcript, [1, 2, 3] | ||
| .map(i => JSON.stringify({ type: 'tool_use', name: 'Edit', input: { file_path: `f${i}.js` } })) | ||
| .join('\n'), 'utf8'); | ||
|
|
||
| return { root, home, project, memDir, transcript }; | ||
| } | ||
|
|
||
| function runHook(ctx, payload, diskFreeGb = 100) { | ||
| return spawnSync(PYTHON.command, [...PYTHON.args, '-c', DRIVER, SCRIPT, String(diskFreeGb)], { | ||
| input: JSON.stringify({ transcript_path: ctx.transcript, ...payload }), | ||
| encoding: 'utf8', | ||
| timeout: 30000, | ||
| env: { ...process.env, HOME: ctx.home, USERPROFILE: ctx.home, CLAUDE_PROJECT_DIR: ctx.project }, | ||
| }); | ||
| } | ||
|
|
||
| function runTests() { | ||
| console.log('\n=== Testing delivery-gate quality-gate.py ===\n'); | ||
|
|
||
| if (!PYTHON) { | ||
| console.log(' - skipped: python not found'); | ||
| console.log('\nPassed: 0'); | ||
| console.log('Failed: 0'); | ||
| return; | ||
| } | ||
|
|
||
| let passed = 0; | ||
| let failed = 0; | ||
| const ctx = setup(); | ||
|
|
||
| try { | ||
| if (test('finds the memory dir of a project path with spaces and punctuation', () => { | ||
| const result = runHook(ctx, {}); | ||
| assert.strictEqual(result.status, 2, `expected block, got ${result.status}: ${result.stderr}`); | ||
| assert.match(result.stderr, /learning libs stale/); | ||
| assert.ok(!result.stderr.includes('No project memory directory found'), result.stderr); | ||
| })) passed++; else failed++; | ||
|
|
||
| if (test('blocks on critical disk space when stop_hook_active is absent', () => { | ||
| const result = runHook(ctx, {}, 1); | ||
| assert.strictEqual(result.status, 2, `expected block, got ${result.status}: ${result.stderr}`); | ||
| assert.match(result.stderr, /Blocked: disk space/); | ||
| })) passed++; else failed++; | ||
|
|
||
| if (test('does not block again when stop_hook_active is true', () => { | ||
| const result = runHook(ctx, { stop_hook_active: true }, 1); | ||
| assert.strictEqual(result.status, 0, `expected exit 0, got ${result.status}: ${result.stderr}`); | ||
| })) passed++; else failed++; | ||
| } finally { | ||
| fs.rmSync(ctx.root, { recursive: true, force: true }); | ||
| } | ||
|
|
||
| console.log(`\nPassed: ${passed}`); | ||
| console.log(`Failed: ${failed}`); | ||
| process.exitCode = failed > 0 ? 1 : 0; | ||
| } | ||
|
|
||
| runTests(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Document the
stop_hook_activeexception in the disk threshold row.quality-gate.pyexits 0 whenstop_hook_activeistrue, before the disk check. Therefore, “on every Stop” is inaccurate and can mislead users about repeated Stop behavior.Suggested fix
</verification_result
📝 Committable suggestion
🧰 Tools
🪛 SkillSpector (2.12.0)
[error] 48: [AS1] Agent Config Directory Access: Skill reads from agent configuration directories (.claude/, .codex/, .gemini/). These directories may contain API keys, personal settings, and other credentials that the skill has no legitimate need to access.
Remediation: Remove all code or instructions that access agent configuration directories (.claude/, .codex/, .gemini/). If configuration values are needed, pass them explicitly as parameters or environment variables — never read the agent's own config files.
(Agent Snooping (AS1))
[warning] 29: [RA2] Session Persistence: Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.
Remediation: Remove any persistence mechanisms (cron jobs, startup scripts, state files). Skills should not maintain state across sessions without explicit user consent.
(Rogue Agent (RA2))
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
quality-gate.pyexits 0 whenstop_hook_activeistrue, before the disk check, so the threshold row should read "on every Stop, except a Stop that a hook already continued (stop_hook_active)". It is a doc-only change and does not affect behaviour; I can fold it in if the maintainers want it in this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jwcastillo That wording makes the
stop_hook_activeexception clear. This is a documentation-only correction; no hook behavior change is needed.You are interacting with an AI system.