fix: port hook session and dashboard safety fixes

Ports suggest-compact session_id isolation and dashboard terminal/document launch safety onto current main.
This commit is contained in:
Affaan Mustafa
2026-05-11 02:53:28 -04:00
committed by GitHub
parent 27508842b1
commit 1abc3fb381
5 changed files with 111 additions and 26 deletions

View File

@@ -1178,6 +1178,47 @@ async function runTests() {
passed++;
else failed++;
if (
await asyncTest('reads session_id from stdin JSON (Claude Code wire format)', async () => {
const sessionId = 'test-stdin-' + Date.now();
const stdinJson = JSON.stringify({ session_id: sessionId, tool_name: 'Edit' });
const result = await runScript(path.join(scriptsDir, 'suggest-compact.js'), stdinJson, {});
assert.strictEqual(result.code, 0, `Exit code should be 0, got ${result.code}`);
const counterFile = path.join(os.tmpdir(), `claude-tool-count-${sessionId}`);
assert.ok(fs.existsSync(counterFile), `Counter file should be created from stdin session_id at ${counterFile}`);
const count = parseInt(fs.readFileSync(counterFile, 'utf8').trim(), 10);
assert.strictEqual(count, 1, `Counter should be 1, got ${count}`);
fs.unlinkSync(counterFile);
})
)
passed++;
else failed++;
if (
await asyncTest('stdin session_id takes precedence over env CLAUDE_SESSION_ID', async () => {
const stdinSession = 'stdin-wins-' + Date.now();
const envSession = 'env-loses-' + Date.now();
const stdinJson = JSON.stringify({ session_id: stdinSession });
const result = await runScript(path.join(scriptsDir, 'suggest-compact.js'), stdinJson, {
CLAUDE_SESSION_ID: envSession
});
assert.strictEqual(result.code, 0);
const stdinCounter = path.join(os.tmpdir(), `claude-tool-count-${stdinSession}`);
const envCounter = path.join(os.tmpdir(), `claude-tool-count-${envSession}`);
assert.ok(fs.existsSync(stdinCounter), 'Stdin session counter must exist');
assert.ok(!fs.existsSync(envCounter), 'Env session counter must NOT exist when stdin provides session_id');
fs.unlinkSync(stdinCounter);
})
)
passed++;
else failed++;
// evaluate-session.js tests
console.log('\nevaluate-session.js:');

View File

@@ -79,13 +79,27 @@ argv, kwargs = module.build_terminal_launch(r'C:\\\\Users\\\\user\\\\proj & del
print(json.dumps({'argv': argv, 'kwargs': kwargs}))
`);
const parsed = JSON.parse(output);
assert.deepStrictEqual(parsed.argv.slice(0, 4), ['cmd.exe', '/k', 'cd', '/d']);
assert.strictEqual(parsed.argv[4], parsed.kwargs.cwd);
assert.ok(parsed.argv[4].includes('proj & del'), 'path should remain a literal argv entry');
assert.ok(parsed.argv[4].includes('C:'), 'windows drive prefix should be preserved');
assert.deepStrictEqual(parsed.argv, ['cmd.exe']);
assert.ok(parsed.kwargs.cwd.includes('proj & del'), 'path should remain a literal cwd value');
assert.ok(parsed.kwargs.cwd.includes('C:'), 'windows drive prefix should be preserved');
assert.ok(Object.prototype.hasOwnProperty.call(parsed.kwargs, 'creationflags'));
})) passed++; else failed++;
if (test('launch_terminal rejects missing or non-directory paths', () => {
const output = runPython(`
import importlib.util, json
spec = importlib.util.spec_from_file_location("ecc_dashboard_runtime", r"""${runtimeHelpersPath}""")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
try:
module.launch_terminal('/definitely/not/a/real/ecc/path')
except ValueError as exc:
print(json.dumps({'error': str(exc)}))
`);
const parsed = JSON.parse(output);
assert.ok(parsed.error.includes('Path is not a valid directory'));
})) passed++; else failed++;
if (test('maximize_window falls back to Linux zoom attribute when zoomed state is unsupported', () => {
const output = runPython(`
import importlib.util, json