严格核对发布正文与协议并拒绝复用错误历史确认

This commit is contained in:
pptg 2026-09-12 06:22:11 +08:00
parent f77dd43e6e
commit ff816dc11b
3 changed files with 56 additions and 4 deletions

View File

@ -117,7 +117,15 @@ export class Gitea {
eventId: string = id(),
) {
this.validateBody(body);
if (this.store.published(taskId).some((e) => e.id === eventId)) return eventId;
const published = this.store.published(taskId).find((e) => e.id === eventId);
if (published) {
if (published.repository !== this.repository || published.number !== number || published.kind !== kind)
throw new Error("发布记录归属不匹配");
const comments = await this.pages(`/issues/${number}/comments`);
if (!comments.some((c) => this.matchesPublication(c, published)))
throw new Error("历史发布确认缺少匹配的远端正文,保留证据并停止复用");
return eventId;
}
const meta = {
protocol_version: 1,
event_id: eventId,
@ -149,19 +157,25 @@ export class Gitea {
this.flushing = undefined;
}
}
matchesPublication(comment: any, action: any) {
if (typeof comment.body !== "string" || comment.body !== action.body) return false;
const meta = marker(comment.body);
return meta?.protocol_version === 1 && meta.event_id === action.id &&
meta.task_id === action.taskId && meta.kind === action.kind;
}
private async drain() {
for (const a of this.store
.pending()
.filter((a) => a.repository === this.repository)) {
const comments = await this.pages(`/issues/${a.number}/comments`);
const match = comments.find((c) =>
c.body?.includes(`"event_id":"${a.id}"`),
);
const match = comments.find((c) => this.matchesPublication(c, a));
const c =
match ??
(await this.api(`/issues/${a.number}/comments`, "POST", {
body: a.body,
}));
if (!this.matchesPublication(c, a))
throw new Error("发布响应正文或协议不匹配,保留 outbox 等待核对");
this.store.confirmPublished(a.id, c.html_url);
this.store.event(a.taskId, a.kind, a.body, null, c.html_url, a.id);
this.store.ack(a.id);

View File

@ -452,3 +452,31 @@ test("trusted failure rework survives lost response and restart without duplicat
assert.equal(posts, publishedCount);
store.db.close();
});
test("publication requires exact body and binding; old false confirmation fails closed", async () => {
const { Gitea } = await import("../src/gitea.js");
const { store } = setup();
const g = Object.create(Gitea.prototype);
Object.assign(g, { store, repository: "https://example.test/owner/repo" });
const id = "stable";
let comments: any[] = [{ body: '普通引用 "event_id":"stable"', html_url: "https://example.test/fake" }];
let posts = 0;
g.pages = async () => comments;
g.api = async (_path: string, _method: string, payload: any) => {
posts++;
const c = { body: payload.body, html_url: "https://example.test/real" };
comments.push(c); return c;
};
await g.publish("t", 1, "revision_request", "真实返工正文", { goal_revision: 1 }, id);
assert.equal(posts, 1);
await g.publish("t", 1, "revision_request", "不同重试说明不替换原文", { goal_revision: 1 }, id);
assert.equal(posts, 1);
const action = store.published("t").find((e) => e.id === id)!;
assert.equal(g.matchesPublication({ body: action.body.replace('"goal_revision":1', '"goal_revision":2') }, action), false);
assert.equal(g.matchesPublication({ body: "篡改正文" + action.body }, action), false);
comments = comments.slice(0, 1);
await assert.rejects(g.publish("t", 1, "revision_request", "真实返工正文", {}, id), /历史发布确认/);
assert.equal(posts, 1);
assert.equal(store.published("t").find((e) => e.id === id)!.body, action.body);
store.db.close();
});

View File

@ -125,3 +125,13 @@ P2:tick 继续观测 failed/cancelled/blocked 根任务的未收敛运行。
编排提示区分attempt/修正轮次和goal revision;决定正文增加控制面权威版本与修正轮次,分配正文仍绑定实际revision。完整模型原始消息和说明保留,不篡改其错误文字,不宣称提示绝对约束模型。
typecheck/build、23项测试、原20故障及32独立边界通过。新增实际Engine/Store/Gitea路径(远端明确注入)覆盖可信失败→丢响应→SQLite重开→重复处理→一次开发派发、串行拒绝和旧revision不触发;未运行真实模型业务或升级4497/4498。日志在本clone .ppanel/rework-*.log。后续由独立CR及新版本真实QA验证A03完整链,旧验收任务未补事件。
## #47 返工事件发布确认信任修复
固定5d3665ea4f90dc3636f5f0d51df80f043a1f8d4d的25案例原样运行:旧版20通过5失败;本版21通过4失败。确定阻塞(仅引用可预测event_id被当成发布)已修复,余下四个为原审查标注的直接注入head/base/budget/active变化条件性风险,不宣称通过。
Gitea对账现在要求远端完整正文与原outbox逐字一致,且合法末尾marker的protocol_version/event_id/task_id/kind一致;完整正文包含所有版本/角色绑定。POST成功响应也执行该检查,不匹配保留outbox,真实丢响应仍从原正文去重。复用published前校验仓库/Issue/kind并重新查询远端匹配正文;旧错误确认或远端已删改时失败关闭,保留原记录,不自动补发历史或绕过失败。
原始25程序不变。typecheck/build、24单测、20故障、32独立边界通过。新增正负对账测试覆盖普通引用、正文/版本篡改、合法重试原文保留、旧确认远端不匹配拒绝。完整日志在本clone .ppanel/rework47。
条件性风险分析:现有单tick busy和SDK sequential排除另一调度轮并发修改head/base或分派active;返工前串行要求无活跃角色,迟到worker报告有状态门禁;用户取消/revision修改是可达写入,已有current检查及固定负例通过。四项测试直接写Store,尚无对应生产单tick写入者证据,按Issue要求本修复未引入分布式事务,也未删除失败断言。未来增加并行调度须重审。未修改#63记录,未升级4497/4498;真实新版本A03仍需独立验收。