feat: sync codex thread goals
This commit is contained in:
20
tests/fixtures/codex-app-server-runtime.mjs
vendored
20
tests/fixtures/codex-app-server-runtime.mjs
vendored
@@ -671,6 +671,26 @@ rl.on("line", (line) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.method === "thread/goal/set") {
|
||||
send({
|
||||
id: message.id,
|
||||
result: {},
|
||||
});
|
||||
send({
|
||||
method: "thread/goal/updated",
|
||||
params: {
|
||||
threadId: message.params?.threadId,
|
||||
goal: {
|
||||
objective: message.params?.objective,
|
||||
status: message.params?.status,
|
||||
tokenBudget: message.params?.tokenBudget,
|
||||
internalGoalSecret: "thread-goal-secret-should-not-leak",
|
||||
},
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.method === "thread/read") {
|
||||
send({
|
||||
id: message.id,
|
||||
|
||||
@@ -1646,6 +1646,38 @@ test("codex app-server runner renames a thread without starting a normal turn",
|
||||
assert.doesNotMatch(JSON.stringify(result), /thread-name-secret-should-not-leak/);
|
||||
});
|
||||
|
||||
test("codex app-server runner syncs a thread goal without starting a normal turn", async () => {
|
||||
const runnerConfig = getCodexAppServerRunnerConfig(process.env, {
|
||||
codexAppServerEnabled: true,
|
||||
codexAppServerCommand: process.execPath,
|
||||
codexAppServerArgs: ["tests/fixtures/codex-app-server-runtime.mjs"],
|
||||
codexAppServerWorkdir: repoRoot,
|
||||
codexAppServerTimeoutMs: 5000,
|
||||
});
|
||||
|
||||
const result = await executeCodexAppServerTask(runnerConfig, {
|
||||
taskId: "task-thread-goal-sync",
|
||||
taskType: "conversation_reply",
|
||||
intentCategory: "thread_goal_sync",
|
||||
targetCodexThreadRef: "019d-app-server-thread",
|
||||
targetCodexFolderRef: repoRoot,
|
||||
threadGoalObjective: "完成 App Server 线程目标双向同步。",
|
||||
threadGoalStatus: "active",
|
||||
threadGoalTokenBudget: 120000,
|
||||
executionPrompt: "同步 Codex 线程目标。",
|
||||
});
|
||||
|
||||
assert.equal(result.status, "completed");
|
||||
assert.equal(result.threadId, "019d-app-server-thread");
|
||||
assert.equal(result.turnControl, "goal_sync");
|
||||
assert.equal(result.threadGoal?.objective, "完成 App Server 线程目标双向同步。");
|
||||
assert.equal(result.threadGoal?.status, "active");
|
||||
assert.equal(result.threadGoal?.tokenBudget, 120000);
|
||||
assert.match(result.replyBody, /已同步 Codex 线程目标/);
|
||||
assert.equal(result.turnId, undefined);
|
||||
assert.doesNotMatch(JSON.stringify(result), /thread-goal-secret-should-not-leak/);
|
||||
});
|
||||
|
||||
test("codex app-server runner stays disabled unless feature flag is explicit", () => {
|
||||
const runnerConfig = getCodexAppServerRunnerConfig(process.env, {
|
||||
codexAppServerCommand: process.execPath,
|
||||
|
||||
125
tests/thread-goal-sync-route.test.ts
Normal file
125
tests/thread-goal-sync-route.test.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
let runtimeRoot = "";
|
||||
let postRoute: (typeof import("../src/app/api/v1/projects/[projectId]/goals/route"))["POST"];
|
||||
let createAuthSession: (typeof import("../src/lib/boss-data"))["createAuthSession"];
|
||||
let readState: (typeof import("../src/lib/boss-data"))["readState"];
|
||||
let writeState: (typeof import("../src/lib/boss-data"))["writeState"];
|
||||
let AUTH_SESSION_COOKIE = "";
|
||||
|
||||
async function setup() {
|
||||
if (runtimeRoot) return;
|
||||
runtimeRoot = await mkdtemp(path.join(os.tmpdir(), "boss-thread-goal-sync-"));
|
||||
process.env.BOSS_RUNTIME_ROOT = runtimeRoot;
|
||||
process.env.BOSS_STATE_FILE = path.join(runtimeRoot, "boss-state.json");
|
||||
|
||||
const [route, data, auth] = await Promise.all([
|
||||
import("../src/app/api/v1/projects/[projectId]/goals/route.ts"),
|
||||
import("../src/lib/boss-data.ts"),
|
||||
import("../src/lib/boss-auth.ts"),
|
||||
]);
|
||||
postRoute = route.POST;
|
||||
createAuthSession = data.createAuthSession;
|
||||
readState = data.readState;
|
||||
writeState = data.writeState;
|
||||
AUTH_SESSION_COOKIE = auth.AUTH_SESSION_COOKIE;
|
||||
}
|
||||
|
||||
test.after(async () => {
|
||||
if (runtimeRoot) {
|
||||
await rm(runtimeRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test.beforeEach(async () => {
|
||||
await setup();
|
||||
await rm(runtimeRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
async function createAuthedRequest(projectId: string, body: unknown) {
|
||||
const session = await createAuthSession({
|
||||
account: "krisolo",
|
||||
role: "highest_admin",
|
||||
displayName: "Boss 超级管理员",
|
||||
loginMethod: "password",
|
||||
});
|
||||
return new NextRequest(`http://127.0.0.1:3000/api/v1/projects/${projectId}/goals`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
cookie: `${AUTH_SESSION_COOKIE}=${session.sessionToken}`,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
}
|
||||
|
||||
function buildThreadProject() {
|
||||
return {
|
||||
id: "goal-sync-project",
|
||||
name: "目标同步线程",
|
||||
pinned: false,
|
||||
systemPinned: false,
|
||||
deviceIds: ["mac-studio"],
|
||||
preview: "",
|
||||
updatedAt: "2026-06-03T12:30:00+08:00",
|
||||
lastMessageAt: "2026-06-03T12:30:00+08:00",
|
||||
isGroup: false,
|
||||
threadMeta: {
|
||||
projectId: "goal-sync-project",
|
||||
threadId: "goal-sync-thread",
|
||||
threadDisplayName: "目标同步线程",
|
||||
folderName: "boss",
|
||||
codexFolderRef: "/Users/kris/code/boss",
|
||||
codexThreadRef: "codex-goal-sync-thread",
|
||||
updatedAt: "2026-06-03T12:30:00+08:00",
|
||||
},
|
||||
groupMembers: [],
|
||||
createdByAgent: false,
|
||||
collaborationMode: "development" as const,
|
||||
approvalState: "not_required" as const,
|
||||
unreadCount: 0,
|
||||
riskLevel: "low" as const,
|
||||
messages: [],
|
||||
goals: [],
|
||||
versions: [],
|
||||
};
|
||||
}
|
||||
|
||||
test("POST /goals creates a Boss goal and queues Codex thread goal sync", async () => {
|
||||
const state = await readState();
|
||||
const project = buildThreadProject();
|
||||
state.projects = [
|
||||
...state.projects.filter((item) => item.id === "master-agent"),
|
||||
project,
|
||||
];
|
||||
await writeState(state);
|
||||
|
||||
const response = await postRoute(
|
||||
await createAuthedRequest(project.id, {
|
||||
text: "完成 App Server 线程目标双向同步。",
|
||||
}),
|
||||
{ params: Promise.resolve({ projectId: project.id }) },
|
||||
);
|
||||
const payload = await response.json();
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal(payload.ok, true);
|
||||
assert.equal(payload.goal.text, "完成 App Server 线程目标双向同步。");
|
||||
assert.equal(payload.codexThreadGoalTask.intentCategory, "thread_goal_sync");
|
||||
assert.equal(payload.codexThreadGoalTask.threadGoalObjective, "完成 App Server 线程目标双向同步。");
|
||||
assert.equal(payload.codexThreadGoalTask.threadGoalStatus, "active");
|
||||
assert.equal(payload.codexThreadGoalTask.targetCodexThreadRef, "codex-goal-sync-thread");
|
||||
|
||||
const persisted = (await readState()).masterAgentTasks.find(
|
||||
(task) => task.taskId === payload.codexThreadGoalTask.taskId,
|
||||
);
|
||||
assert.equal(persisted?.status, "queued");
|
||||
assert.equal(persisted?.intentCategory, "thread_goal_sync");
|
||||
assert.equal(persisted?.threadGoalObjective, "完成 App Server 线程目标双向同步。");
|
||||
assert.equal(persisted?.threadGoalStatus, "active");
|
||||
});
|
||||
Reference in New Issue
Block a user