feat: surface codex account runtime notices

This commit is contained in:
AI Bot
2026-06-01 17:40:03 +08:00
parent 26b5e97614
commit defa3da185
11 changed files with 505 additions and 5 deletions

View File

@@ -581,6 +581,67 @@ rl.on("line", (line) => {
},
});
}
if (process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_ACCOUNT_NOTICE_EVENTS === "1") {
send({
method: "account/updated",
params: {
authMode: "chatgpt",
planType: "team",
},
});
send({
method: "account/rateLimits/updated",
params: {
rateLimits: {
limitId: "codex",
limitName: "Codex",
primary: {
usedPercent: 88,
windowDurationMins: 180,
resetsAt: 1770003600,
},
secondary: null,
credits: {
hasCredits: true,
unlimited: false,
balance: "120.5",
},
planType: "team",
rateLimitReachedType: null,
},
},
});
send({
method: "model/verification",
params: {
threadId: message.params?.threadId,
turnId: "turn-fixture",
verifications: ["trustedAccessForCyber"],
},
});
send({
method: "warning",
params: {
threadId: message.params?.threadId,
message: "模型切换提醒 token=sk-secret-should-not-leak",
},
});
send({
method: "configWarning",
params: {
summary: "项目配置已忽略",
details: "openai_base_url 不能放在项目配置里",
path: "/Users/kris/code/boss/.codex/config.toml",
},
});
send({
method: "deprecationNotice",
params: {
summary: "on-failure 已废弃",
details: "请改用 on-request",
},
});
}
send({
method: "item/agentMessage/delta",
params: {

View File

@@ -529,6 +529,72 @@ test("codex app-server runner maps thread goal, settings, and compaction events
}
});
test("codex app-server runner maps account, quota, verification, and notices without leaking config paths", async () => {
const previous = process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_ACCOUNT_NOTICE_EVENTS;
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_ACCOUNT_NOTICE_EVENTS = "1";
try {
const runnerConfig = getCodexAppServerRunnerConfig(process.env, {
codexAppServerEnabled: true,
codexAppServerCommand: process.execPath,
codexAppServerArgs: ["tests/fixtures/codex-app-server-runtime.mjs"],
codexAppServerWorkdir: repoRoot,
codexAppServerTimeoutMs: 5000,
masterAgentModel: "gpt-5.4",
});
const result = await executeCodexAppServerTask(runnerConfig, {
taskId: "task-app-server-account-notices",
taskType: "conversation_reply",
targetCodexThreadRef: "019d-app-server-thread",
targetCodexFolderRef: repoRoot,
executionPrompt: "同步账号与告警状态",
});
assert.equal(result.status, "completed");
assert.deepEqual(result.executionProgress.accountStatus, {
authMode: "chatgpt",
planType: "team",
limitId: "codex",
limitName: "Codex",
usedPercent: 88,
windowDurationMins: 180,
resetsAt: 1770003600,
creditsBalance: "120.5",
hasCredits: true,
unlimitedCredits: false,
});
assert.deepEqual(result.executionProgress.modelVerification, {
verifications: ["trustedAccessForCyber"],
});
assert.deepEqual(result.executionProgress.warnings, [
{
id: "codex-warning-1",
message: "模型切换提醒 token=[redacted]",
severity: "warning",
},
{
id: "config-warning-2",
message: "项目配置已忽略openai_base_url 不能放在项目配置里",
severity: "warning",
},
{
id: "deprecation-notice-3",
message: "on-failure 已废弃:请改用 on-request",
severity: "info",
},
]);
const serialized = JSON.stringify(result.executionProgress);
assert.equal(serialized.includes("/Users/kris"), false);
assert.equal(serialized.includes("sk-secret-should-not-leak"), false);
} finally {
if (previous === undefined) {
delete process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_ACCOUNT_NOTICE_EVENTS;
} else {
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_ACCOUNT_NOTICE_EVENTS = previous;
}
}
});
test("codex app-server runner bridges source thread context into target thread through inject_items", async () => {
const previous = process.env.BOSS_CODEX_APP_SERVER_FIXTURE_INTER_THREAD;
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_INTER_THREAD = "1";

View File

@@ -370,3 +370,80 @@ test("POST task progress preserves Codex thread goal, settings, and compaction s
assert.equal(serialized.includes("/Users/kris"), false);
assert.equal(serialized.includes("turn-secret-should-not-persist"), false);
});
test("POST task progress preserves Codex account, quota, verification, and notice summaries", async () => {
const task = await data.queueMasterAgentTask({
taskId: "route-progress-account-notices-task",
projectId: "group-progress-test",
taskType: "dispatch_execution",
requestMessageId: "msg-route-progress-account-notices",
requestText: "让目标线程同步账号和告警",
executionPrompt: "让目标线程同步账号和告警",
requestedBy: "krisolo",
requestedByAccount: "krisolo",
deviceId: "mac-studio",
targetProjectId: "master-agent",
targetThreadId: "master-agent-thread",
});
await data.claimNextMasterAgentTask("mac-studio");
const response = await postProgress(
new NextRequest(`http://127.0.0.1:3000/api/v1/master-agent/tasks/${task.taskId}/progress`, {
method: "POST",
headers: {
"content-type": "application/json",
"x-boss-device-token": "boss-mac-studio-token",
},
body: JSON.stringify({
deviceId: "mac-studio",
status: "running",
executionProgress: {
steps: [{ text: "同步 Codex 账号运行态", status: "running" }],
accountStatus: {
authMode: "chatgpt",
planType: "team",
limitId: "codex",
limitName: "Codex",
usedPercent: 88,
windowDurationMins: 180,
resetsAt: 1770003600,
creditsBalance: "120.5",
hasCredits: true,
unlimitedCredits: false,
accessToken: "sk-secret-should-not-persist",
},
modelVerification: {
verifications: ["trustedAccessForCyber"],
turnId: "turn-secret-should-not-persist",
},
warnings: [
{
id: "config-warning-1",
message: "项目配置已忽略openai_base_url 不能放在项目配置里",
severity: "warning",
path: "/Users/kris/code/boss/.codex/config.toml",
},
],
},
}),
}),
{ params: Promise.resolve({ taskId: task.taskId }) },
);
assert.equal(response.status, 200);
const state = await data.readState();
const progress = state.projects
.find((project) => project.id === "master-agent")
?.messages.find((message) => message.executionProgress?.taskId === task.taskId)
?.executionProgress;
assert.equal(progress?.accountStatus?.authMode, "chatgpt");
assert.equal(progress?.accountStatus?.planType, "team");
assert.equal(progress?.accountStatus?.usedPercent, 88);
assert.equal(progress?.modelVerification?.verifications?.[0], "trustedAccessForCyber");
assert.equal(progress?.warnings?.[0]?.message, "项目配置已忽略openai_base_url 不能放在项目配置里");
const serialized = JSON.stringify(progress);
assert.equal(serialized.includes("/Users/kris"), false);
assert.equal(serialized.includes("sk-secret-should-not-persist"), false);
assert.equal(serialized.includes("turn-secret-should-not-persist"), false);
});