Files
mtusi2026lab3/bench/k6/explain.js
T
ricoromaandClaude Opus 5.5 af4bca08c9 feat: carry lab 2 over and add X-Instance-Id and idempotency keys
- carry the lab 2 solution over and plan lab 3 (PLAN.md, OpenSpec
  change instance-id-idempotency)
- rename the compose project to mtusi-lab3 and the image to :lab3
- add X-Instance-Id to every response and instance_id to every log
  record ([app] instance_id, hostname by default)
- require Idempotency-Key on POST messages: keys table in Postgres,
  key and message in one transaction, replay returns the same 201,
  another body gets 409, TTL from [idempotency] ttl_seconds
- send the key from student-tests, k6 scenarios and the skill driver;
  add idempotency, X-Instance-Id, key race and fault tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 19:42:36 +03:00

42 lines
1.7 KiB
JavaScript

// Этап плана: страницы истории из plan_pages.json подряд, пока в Postgres
// стенда включён auto_explain. Для читаемого чата и первого чата каждого
// фонового уровня — первая, средняя и последняя полная страница (у
// короткого чата — первая). Порядок запросов = порядок планов в журнале:
// оркестратор сопоставляет их по нему.
import http from "k6/http";
import { check, fail } from "k6";
import { API, PAGE_LIMIT, WORK_DIR, authHeaders } from "./lib.js";
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
const pages = JSON.parse(open(`${WORK_DIR}/plan_pages.json`));
export const options = {
vus: 1,
iterations: 1,
};
export default function () {
const params = { headers: authHeaders(fixture.tokens[fixture.readerId]) };
for (const page of pages) {
const name = `${page.chat} ${page.page}`;
const query = page.cursor === null
? `?limit=${PAGE_LIMIT}`
: `?limit=${PAGE_LIMIT}&cursor=${encodeURIComponent(page.cursor)}`;
const res = http.get(`${API}/chats/${page.chat_id}/messages${query}`, params);
const ok = check(res, {
[`${name} 200`]: (r) => r.status === 200,
[`${name} ${page.items} items`]: (r) =>
r.status === 200 && r.json("items.#") === page.items,
});
if (!ok) {
fail(`explain page ${name}: ${res.status}`);
}
}
}
// итог не нужен: планы оркестратор берёт из журнала Postgres
export function handleSummary() {
return {};
}