Files
Netcatty/infrastructure/ai/cattyAgent/shellReadiness.unknownState.test.ts
T
GOUKI9999and陈大猫 0a4ff8875f feat(ai): make unrecognized shell prompts an actionable unknown state instead of a terminal block (#4198)
* feat(ai): make unrecognized shell prompts an actionable unknown state instead of a terminal block

Composes #3935 (advisory semantics), #4110 (OSC 133 marker authority + pending-input guards) and #4195 (asymmetric harm / state-model proposal). An unrecognized prompt on a live shell now yields a non-terminal SHELL_READINESS_UNKNOWN result with a read-only/confirm viable path; PROVEN-busy states keep the exact hard SHELL_NOT_READY block. Never blind-types into unknown; never claims ready without evidence.

* fix(ai): propagate unknown readiness code through the active Catty SDK path

---------

Co-authored-by: 陈大猫 <16399091+binaricat@users.noreply.github.com>
2026-11-15 01:27:43 +08:00

77 lines
2.7 KiB
TypeScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { createToolExecutor, type NetcattyBridge, type ExecutorContext } from './executor';
// Mirrors SHELL_READINESS_UNKNOWN_MESSAGE from
// electron/bridges/ai/shellReadinessState.cjs (kept inline to avoid a
// renderer -> electron import in this harness test).
const UNKNOWN_HINT = [
'Shell readiness unknown (SHELL_READINESS_UNKNOWN): the terminal connection is',
'alive but the prompt could not be recognized. The command was NOT sent — never',
'blind-type. Read-only next steps: call get_environment or terminal_read_context,',
're-check after the user presses Enter, reuse another idle session, or ask the',
'user to confirm the prompt before retrying.',
].join(' ');
function makeBridge(result: Record<string, unknown>): NetcattyBridge {
return { aiExec: async () => result } as unknown as NetcattyBridge;
}
const context: ExecutorContext = {
sessions: [
{
sessionId: 's1',
hostId: 'h1',
hostname: 'host',
label: 'tab',
protocol: 'ssh',
connected: true,
},
],
};
function call(command = 'echo OK') {
return { id: 'call-1', name: 'terminal_execute', arguments: { sessionId: 's1', command } };
}
describe('Catty Agent terminal_execute surfaces SHELL_READINESS_UNKNOWN as non-fatal (#4195)', () => {
it('returns the actionable read-only hint WITHOUT isError (agent is not bricked)', async () => {
const bridge = makeBridge({
ok: false,
error: UNKNOWN_HINT,
code: 'SHELL_READINESS_UNKNOWN',
stdout: '',
stderr: '',
exitCode: -1,
});
const execute = createToolExecutor(bridge, context, [], 'auto');
const result = await execute(call());
assert.notEqual(result.isError, true);
assert.match(result.content, /read-only/i);
assert.match(result.content, /NOT sent/i);
assert.match(result.content, /get_environment|terminal_read_context/);
});
it('a proven-busy SHELL_NOT_READY verdict is still a hard error', async () => {
const bridge = makeBridge({
ok: false,
error: 'Shell prompt is not ready; no command was sent',
code: 'SHELL_NOT_READY',
stdout: '',
stderr: '',
exitCode: -1,
});
const execute = createToolExecutor(bridge, context, [], 'auto');
const result = await execute(call());
assert.equal(result.isError, true);
});
it('a normal successful command is unaffected', async () => {
const bridge = makeBridge({ ok: true, stdout: 'OK', stderr: '', exitCode: 0 });
const execute = createToolExecutor(bridge, context, [], 'auto');
const result = await execute(call());
assert.notEqual(result.isError, true);
assert.match(result.content, /OK/);
});
});