Merge branch 'main' into task/pep-284
All checks were successful
All checks were successful
This commit is contained in:
commit
3bef77100e
@ -72,25 +72,32 @@ export function summarizeChecks(configured: string[], runs: RunLike[], sha: stri
|
||||
|
||||
/** Stores a CI result (one row per project/commit/check). `changed` — the state is new. */
|
||||
export async function upsertCheckRun(db: Db, project: Project, taskId: number | null, r: CheckReport): Promise<{ run: CheckRun; changed: boolean }> {
|
||||
const [prev] = await db
|
||||
.select()
|
||||
.from(checkRuns)
|
||||
.where(and(eq(checkRuns.projectId, project.id), eq(checkRuns.sha, r.sha), eq(checkRuns.check, r.check)));
|
||||
const values = {
|
||||
taskId: taskId ?? prev?.taskId ?? null,
|
||||
branch: r.branch ?? prev?.branch ?? null,
|
||||
prNumber: r.prNumber ?? prev?.prNumber ?? null,
|
||||
state: r.state,
|
||||
runUrl: r.runUrl ?? prev?.runUrl ?? null,
|
||||
// A poll carries no log: keep the one the CI step sent.
|
||||
logTail: r.logTail ?? prev?.logTail ?? null,
|
||||
durationSec: r.durationSec ?? prev?.durationSec ?? null,
|
||||
source: r.source ?? "report",
|
||||
};
|
||||
const [run] = prev
|
||||
? await db.update(checkRuns).set(values).where(eq(checkRuns.id, prev.id)).returning()
|
||||
: await db.insert(checkRuns).values({ projectId: project.id, sha: r.sha, check: r.check, ...values }).returning();
|
||||
return { run: run!, changed: prev?.state !== r.state };
|
||||
// PEP-313: one transaction (the write lock is taken first). The CI step's report (web) and the
|
||||
// watchdog's poll write the same check of the same commit at the same moment: read apart from the
|
||||
// write, both saw no row, the second insert failed on the unique index, and the report with the
|
||||
// log was lost with a 500 (27.11.2026). In turn each sees what the other stored.
|
||||
return db.transaction((tx) => {
|
||||
const prev = tx
|
||||
.select()
|
||||
.from(checkRuns)
|
||||
.where(and(eq(checkRuns.projectId, project.id), eq(checkRuns.sha, r.sha), eq(checkRuns.check, r.check)))
|
||||
.get();
|
||||
const values = {
|
||||
taskId: taskId ?? prev?.taskId ?? null,
|
||||
branch: r.branch ?? prev?.branch ?? null,
|
||||
prNumber: r.prNumber ?? prev?.prNumber ?? null,
|
||||
state: r.state,
|
||||
runUrl: r.runUrl ?? prev?.runUrl ?? null,
|
||||
// A poll carries no log: keep the one the CI step sent.
|
||||
logTail: r.logTail ?? prev?.logTail ?? null,
|
||||
durationSec: r.durationSec ?? prev?.durationSec ?? null,
|
||||
source: r.source ?? "report",
|
||||
};
|
||||
const run = prev
|
||||
? tx.update(checkRuns).set(values).where(eq(checkRuns.id, prev.id)).returning().get()
|
||||
: tx.insert(checkRuns).values({ projectId: project.id, sha: r.sha, check: r.check, ...values }).returning().get();
|
||||
return { run: run!, changed: prev?.state !== r.state };
|
||||
});
|
||||
}
|
||||
|
||||
/** PR number of a task's pr_url when it points at the project's repo. */
|
||||
|
||||
@ -85,6 +85,32 @@ describe("Вкладка «Код»", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// PEP-313 (27.11.2026): the CI step's report and the watchdog's poll wrote the same check at once —
|
||||
// «UNIQUE constraint failed: check_runs.project_id, check_runs.sha, check_runs.check», the report was lost.
|
||||
describe("Результат проверки пишут двое сразу", () => {
|
||||
test("Отчёт шага и опрос статусов одновременно — одна запись, журнал отчёта цел, «изменилось» — один раз", async () => {
|
||||
const p = await tabsProject("MTRACE", { "README.md": "# R" }, { ".peppa/project.json": JSON.stringify({ key: "MTRACE", checks: { test: "pnpm test" } }) });
|
||||
const ref = await core.createTask(db, { projectId: p.id, title: "Гонка отчётов" });
|
||||
const sha = "c".repeat(40);
|
||||
const [a, b] = await Promise.all([
|
||||
core.upsertCheckRun(db, p, ref.task.id, { sha, check: "test", state: "failure", logTail: "✖ упал один тест", source: "report" }),
|
||||
core.upsertCheckRun(db, p, null, { sha, check: "test", state: "failure", source: "poll" }),
|
||||
]);
|
||||
assert.equal(a.run.id, b.run.id, "one row for the commit and the check");
|
||||
assert.deepEqual([a.changed, b.changed], [true, false], "the red check is news once");
|
||||
assert.equal(b.run.logTail, "✖ упал один тест", "the poll keeps the log the CI step sent");
|
||||
assert.equal(b.run.taskId, ref.task.id);
|
||||
// The other order: the poll first, the report with the log second.
|
||||
const sha2 = "d".repeat(40);
|
||||
const [c, d] = await Promise.all([
|
||||
core.upsertCheckRun(db, p, null, { sha: sha2, check: "test", state: "success", source: "poll" }),
|
||||
core.upsertCheckRun(db, p, ref.task.id, { sha: sha2, check: "test", state: "success", logTail: "ok", source: "report" }),
|
||||
]);
|
||||
assert.equal(c.run.id, d.run.id);
|
||||
assert.equal(d.run.logTail, "ok");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Вкладка «PR»", () => {
|
||||
test("Scenario: PR стори — ключ стори и «Проверки: 2 из 2 пройдены»; PR без стори — без проверок", async () => {
|
||||
const p = await tabsProject("MTPR", { "README.md": "# PR" }, { ".peppa/project.json": JSON.stringify({ key: "MTPR", checks: { test: "pnpm test", build: "pnpm build" } }) });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user