[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled

This commit is contained in:
2026-09-13 18:24:01 +08:00
commit 3c72efcb7f
3255 changed files with 907009 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
onCodexAppServerInteraction,
replayPendingCodexAppServerInteractions,
respondCodexUserInput,
setupCodexAppServerInteractionBridge,
type CodexAppServerInteraction,
} from './codexAppServerInteractions';
import {
clearAllPendingApprovals,
onApprovalRequest,
replayPendingApprovals,
resolveApproval,
type ApprovalRequest,
} from './approvalGate';
test('Codex App Server interaction gate replays requests and forwards typed responses', async () => {
let requestListener: ((payload: CodexAppServerInteraction) => void) | undefined;
let clearedListener: ((payload: { interactionIds: string[] }) => void) | undefined;
const responses: Record<string, unknown>[] = [];
const previousWindow = globalThis.window;
Object.defineProperty(globalThis, 'window', {
configurable: true,
value: {
netcatty: {
onCodexAppServerInteractionRequest: (listener: typeof requestListener) => {
requestListener = listener;
return () => {};
},
onCodexAppServerInteractionCleared: (listener: typeof clearedListener) => {
clearedListener = listener;
return () => {};
},
respondCodexAppServerInteraction: async (payload: Record<string, unknown>) => {
responses.push(payload);
return { ok: true };
},
},
},
});
const teardown = setupCodexAppServerInteractionBridge();
const received: CodexAppServerInteraction[] = [];
const approvals: ApprovalRequest[] = [];
const unsubscribe = onCodexAppServerInteraction((interaction) => received.push(interaction));
const unsubscribeApprovals = onApprovalRequest((approval) => approvals.push(approval));
requestListener?.({
interactionId: 'approval-1',
source: 'codex-app-server',
kind: 'command',
requestId: 'request-1',
chatSessionId: 'chat-1',
toolName: 'codex.command',
args: { command: 'npm test' },
availableDecisions: ['accept', 'decline', 'cancel'],
});
assert.equal(received.length, 0);
assert.equal(approvals[0].source, 'codex-app-server');
assert.equal(approvals[0].allowSession, false);
const replayedApprovals: ApprovalRequest[] = [];
replayPendingApprovals((approval) => replayedApprovals.push(approval));
assert.equal(replayedApprovals[0].toolCallId, 'approval-1');
resolveApproval('approval-1', { approved: true, scope: 'once' });
await new Promise((resolve) => setImmediate(resolve));
assert.deepEqual(responses[0], { interactionId: 'approval-1', decision: 'once' });
requestListener?.({
interactionId: 'approval-session',
source: 'codex-app-server',
kind: 'command',
requestId: 'request-1',
chatSessionId: 'chat-1',
toolName: 'codex.command',
args: { command: 'npm test' },
availableDecisions: ['accept', 'acceptForSession', 'decline', 'cancel'],
});
assert.equal(approvals[1].allowSession, true);
resolveApproval('approval-session', { approved: true, scope: 'session' });
await new Promise((resolve) => setImmediate(resolve));
assert.deepEqual(responses[1], { interactionId: 'approval-session', decision: 'session' });
requestListener?.({
interactionId: 'approval-stop',
source: 'codex-app-server',
kind: 'file-change',
requestId: 'request-1',
chatSessionId: 'chat-1',
toolName: 'codex.file_change',
args: { reason: 'write files' },
});
clearAllPendingApprovals('chat-1');
await new Promise((resolve) => setImmediate(resolve));
assert.deepEqual(responses[2], { interactionId: 'approval-stop', decision: 'cancel' });
requestListener?.({
interactionId: 'input-1',
source: 'codex-app-server',
kind: 'user-input',
requestId: 'request-1',
chatSessionId: 'chat-1',
questions: [],
});
assert.equal(received[0].interactionId, 'input-1');
const replayedInputs: CodexAppServerInteraction[] = [];
replayPendingCodexAppServerInteractions((interaction) => replayedInputs.push(interaction));
assert.equal(replayedInputs[0].interactionId, 'input-1');
await respondCodexUserInput('input-1', { mode: { answers: ['safe'] } });
assert.deepEqual(responses[3], {
interactionId: 'input-1',
answers: { mode: { answers: ['safe'] } },
});
clearedListener?.({ interactionIds: ['missing'] });
unsubscribe();
unsubscribeApprovals();
teardown();
Object.defineProperty(globalThis, 'window', { configurable: true, value: previousWindow });
});
test('Codex App Server interaction bridge is ref-counted across setup/teardown', () => {
let subscribeCount = 0;
let unsubscribeCount = 0;
const previousWindow = globalThis.window;
Object.defineProperty(globalThis, 'window', {
configurable: true,
value: {
netcatty: {
onCodexAppServerInteractionRequest: () => {
subscribeCount += 1;
return () => {
unsubscribeCount += 1;
};
},
onCodexAppServerInteractionCleared: () => () => {},
},
},
});
const first = setupCodexAppServerInteractionBridge();
const second = setupCodexAppServerInteractionBridge();
assert.equal(subscribeCount, 1, 'nested setup must not stack ipc listeners');
first();
assert.equal(unsubscribeCount, 0, 'first teardown while second still live keeps the bridge');
second();
assert.equal(unsubscribeCount, 1);
Object.defineProperty(globalThis, 'window', { configurable: true, value: previousWindow });
});