Harden read-only thread handling and refresh Android releases
This commit is contained in:
@@ -212,3 +212,133 @@ test("discoverCodexProjectCandidates prefers Codex sqlite indexes and session na
|
||||
assert.equal(yuandiSession?.threadDisplayName, "Epicurus");
|
||||
assert.equal(yuandiSession?.codexFolderRef, "/Users/kris/code/yuandi");
|
||||
});
|
||||
|
||||
test("discoverCodexProjectCandidates excludes read-only threads even when they are the newest primary thread", async () => {
|
||||
await setup();
|
||||
|
||||
const codexRoot = path.join(runtimeRoot, ".codex-readonly");
|
||||
const now = new Date("2026-04-05T12:00:00+08:00");
|
||||
await mkdir(codexRoot, { recursive: true });
|
||||
const stateDbPath = path.join(codexRoot, "state_5.sqlite");
|
||||
const logsDbPath = path.join(codexRoot, "logs_1.sqlite");
|
||||
const sessionIndexPath = path.join(codexRoot, "session_index.jsonl");
|
||||
const globalStatePath = path.join(codexRoot, ".codex-global-state.json");
|
||||
|
||||
const stateDb = new DatabaseSync(stateDbPath);
|
||||
stateDb.exec(`
|
||||
CREATE TABLE threads (
|
||||
id TEXT PRIMARY KEY,
|
||||
rollout_path TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
source TEXT NOT NULL,
|
||||
model_provider TEXT NOT NULL,
|
||||
cwd TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
sandbox_policy TEXT NOT NULL,
|
||||
approval_mode TEXT NOT NULL,
|
||||
tokens_used INTEGER NOT NULL DEFAULT 0,
|
||||
has_user_event INTEGER NOT NULL DEFAULT 0,
|
||||
archived INTEGER NOT NULL DEFAULT 0,
|
||||
archived_at INTEGER,
|
||||
git_sha TEXT,
|
||||
git_branch TEXT,
|
||||
git_origin_url TEXT,
|
||||
cli_version TEXT NOT NULL DEFAULT '',
|
||||
first_user_message TEXT NOT NULL DEFAULT '',
|
||||
agent_nickname TEXT,
|
||||
agent_role TEXT,
|
||||
memory_mode TEXT NOT NULL DEFAULT 'enabled',
|
||||
model TEXT,
|
||||
reasoning_effort TEXT,
|
||||
agent_path TEXT
|
||||
);
|
||||
`);
|
||||
const insertThread = stateDb.prepare(`
|
||||
INSERT INTO threads (
|
||||
id, rollout_path, created_at, updated_at, source, model_provider, cwd, title,
|
||||
sandbox_policy, approval_mode, tokens_used, has_user_event, archived,
|
||||
cli_version, first_user_message, agent_nickname, agent_role, memory_mode, model, reasoning_effort
|
||||
) VALUES (?, ?, ?, ?, 'desktop', 'openai', ?, ?, ?, 'never', 0, 1, 0, '0.118.0', '', '', '', 'enabled', 'gpt-5.4', 'medium')
|
||||
`);
|
||||
insertThread.run(
|
||||
"019d-boss-writable",
|
||||
path.join(codexRoot, "sessions/2026/04/05/rollout-boss-writable.jsonl"),
|
||||
1775322000,
|
||||
1775322060,
|
||||
"/Users/kris/code/boss",
|
||||
"Boss 可写线程",
|
||||
'{"type":"workspace-write"}',
|
||||
);
|
||||
insertThread.run(
|
||||
"019d-boss-readonly",
|
||||
path.join(codexRoot, "sessions/2026/04/05/rollout-boss-readonly.jsonl"),
|
||||
1775322120,
|
||||
1775322180,
|
||||
"/Users/kris/code/boss",
|
||||
"Boss 只读线程",
|
||||
'{"type":"read-only"}',
|
||||
);
|
||||
stateDb.close();
|
||||
|
||||
const logsDb = new DatabaseSync(logsDbPath);
|
||||
logsDb.exec(`
|
||||
CREATE TABLE logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ts INTEGER NOT NULL,
|
||||
ts_nanos INTEGER NOT NULL,
|
||||
level TEXT NOT NULL,
|
||||
target TEXT NOT NULL,
|
||||
feedback_log_body TEXT,
|
||||
module_path TEXT,
|
||||
file TEXT,
|
||||
line INTEGER,
|
||||
thread_id TEXT,
|
||||
process_uuid TEXT,
|
||||
estimated_bytes INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
`);
|
||||
const insertLog = logsDb.prepare(`
|
||||
INSERT INTO logs (ts, ts_nanos, level, target, thread_id, estimated_bytes)
|
||||
VALUES (?, 0, 'info', 'codex', ?, 0)
|
||||
`);
|
||||
insertLog.run(1775322060, "019d-boss-writable");
|
||||
insertLog.run(1775322180, "019d-boss-readonly");
|
||||
logsDb.close();
|
||||
|
||||
await writeFile(
|
||||
sessionIndexPath,
|
||||
[
|
||||
JSON.stringify({
|
||||
id: "019d-boss-writable",
|
||||
thread_name: "Boss 可写线程",
|
||||
updated_at: "2026-04-05T04:21:00.000000Z",
|
||||
}),
|
||||
JSON.stringify({
|
||||
id: "019d-boss-readonly",
|
||||
thread_name: "Boss 只读线程",
|
||||
updated_at: "2026-04-05T04:23:00.000000Z",
|
||||
}),
|
||||
].join("\n") + "\n",
|
||||
"utf8",
|
||||
);
|
||||
await writeFile(
|
||||
globalStatePath,
|
||||
JSON.stringify({ "thread-workspace-root-hints": {} }, null, 2),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const discovered = await discoverCodexProjectCandidates({
|
||||
stateDbPath,
|
||||
logsDbPath,
|
||||
sessionIndexPath,
|
||||
globalStatePath,
|
||||
lookbackHours: 24,
|
||||
now,
|
||||
});
|
||||
|
||||
assert.deepEqual(discovered.projects, ["boss"]);
|
||||
assert.equal(discovered.projectCandidates.length, 1);
|
||||
assert.equal(discovered.projectCandidates[0]?.threadId, "019d-boss-writable");
|
||||
assert.equal(discovered.projectCandidates[0]?.threadDisplayName, "Boss 可写线程");
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ async function createCodexStateDb(threads) {
|
||||
id, rollout_path, created_at, updated_at, source, model_provider, cwd, title,
|
||||
sandbox_policy, approval_mode, tokens_used, has_user_event, archived,
|
||||
cli_version, first_user_message, agent_nickname, agent_role, memory_mode, model, reasoning_effort
|
||||
) VALUES (?, ?, ?, ?, 'desktop', 'openai', ?, ?, 'workspace-write', 'never', 0, 1, 0, '0.118.0', '', '', '', 'enabled', 'gpt-5.4', 'medium')
|
||||
) VALUES (?, ?, ?, ?, 'desktop', 'openai', ?, ?, ?, 'never', 0, 1, 0, '0.118.0', '', '', '', 'enabled', 'gpt-5.4', 'medium')
|
||||
`);
|
||||
for (const thread of threads) {
|
||||
insertThread.run(
|
||||
@@ -73,6 +73,7 @@ async function createCodexStateDb(threads) {
|
||||
1774845618,
|
||||
thread.cwd,
|
||||
thread.title ?? thread.id,
|
||||
thread.sandboxPolicy ?? '{"type":"workspace-write"}',
|
||||
);
|
||||
}
|
||||
db.close();
|
||||
@@ -283,3 +284,37 @@ test("conversation reply preflight fails closed when target cwd mismatches the l
|
||||
assert.match(result.error.message, /LOCAL_AGENT_CODEX_THREAD_BINDING_MISMATCH/);
|
||||
assert.match(result.error.message, /project-live/);
|
||||
});
|
||||
|
||||
test("conversation reply preflight fails closed when target Codex thread is read-only", async () => {
|
||||
const root = await ensureRuntimeRoot();
|
||||
const readonlyCwd = path.join(root, "project-readonly");
|
||||
await mkdir(readonlyCwd, { recursive: true });
|
||||
const stateDbPath = await createCodexStateDb([
|
||||
{
|
||||
id: "019d-thread-readonly",
|
||||
cwd: readonlyCwd,
|
||||
title: "Read-only thread",
|
||||
sandboxPolicy: '{"type":"read-only"}',
|
||||
},
|
||||
]);
|
||||
|
||||
const result = await prepareCodexTaskExecution(
|
||||
{
|
||||
masterAgentWorkdir: "/Users/kris/code/boss",
|
||||
masterAgentSandbox: "workspace-write",
|
||||
codexStateDbPath: stateDbPath,
|
||||
},
|
||||
{
|
||||
taskType: "conversation_reply",
|
||||
executionPrompt: "请继续开发",
|
||||
targetCodexThreadRef: "019d-thread-readonly",
|
||||
targetCodexFolderRef: readonlyCwd,
|
||||
},
|
||||
"/tmp/reply.txt",
|
||||
);
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.error.code, "LOCAL_AGENT_CODEX_THREAD_READ_ONLY");
|
||||
assert.match(result.error.message, /LOCAL_AGENT_CODEX_THREAD_READ_ONLY/);
|
||||
assert.match(result.error.message, /read-only/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user